% In a relational database, relations are tables, have names, and each
% column in the table also has a name.
% In Prolog, the table names are predicate names. The number of
% columns of the table is the number of arguments of the predicate. 
% Columns in Prolog have no name. We identify only their position:
% first argument, second argument etc.
% A subset of Prolog implements deductive databases: Datalog.
% In plain Datalog (without extensions), the following constructions
% are not allowed:
% p(X,Y) :- r(X). 
   % it does not make sense to ask for a tuple of a relation that has
   % just one column. Besides, this may lead to an infinite number of
   % solutions, because Y can be an infinite set of values (loop).
% p(X,Y) :- X > Y. 
   % This may also return an infinite number of answers, since the
   % predicate p/2 does not query any table in particular. The
   % following construction is thus valid:
% p(X,Y) :- r(X,Y), X > Y. % this is a selection. In a database this
% would be read as:
% select X,Y from r where X > Y

% Assume binary relations R and S

% intersection of R and S
intersection(X,Y) :-
   r(X,Y),
   s(X,Y).

% union of R and S
union(X,Y) :-
   r(X,Y);
   s(X,Y).

% projection in X
projection(X) :-
   r(X,Y).

% selection with condition
selection(X,Y) :-
   r(X,Y),
   X > Y.
   
% difference R\S
difference(X,Y) :-
   r(X,Y),
   \+ s(X,Y).

% Read additional material available under the Recommended Reading
% title in the discipline web page-
