Show how to express the relational operators of projection, selection, Cartesian product, natural join, union, and set-di?erence using Datalog.

What will be an ideal response?


Projection on the ?rst and third arguments of relation Rel with four attributes:


Projection(?A,?C) :- Rel(?A,?B,?C,?D).


Selection on the second attribute of the form ?B=1 and ?B > 12:

Selection1(?A,1,?C,?D) :- Rel(?A,1,?C,?D).
Selection2(?A,?B,?C,?D) :- Rel(?A,?B,?C,?D), ?B > 12.


Cartesian product and natural join (for join, we assume that the second attribute of Rel1 has the same name as the ?rst attribute of Rel2:

Product(?A,?B,?X,?Y,?Z) :- Rel1(?A,?B), Rel2(?X,?Y,?Z).
Join(?A,?B,?Y,?Z) :- Rel1(?A,?B), Rel2(?B,?Y,?Z).


Union and set-di?erence:

Union(?A,?B) :- Rel1(?A,?B) ; Rel2(?A,?B).
Difference(?A,?B) :- Rel1(?A,?B), not Rel2(?A,?B).

Computer Science & Information Technology

You might also like to view...

The Collection class or interface that allows only unique elements is the ___________ class or interface.

(a) List (b) Set (c) Vector (d) all of the above

Computer Science & Information Technology

In digital video, each bitmap image is referred to as a(n) __________.

Fill in the blank(s) with the appropriate word(s).

Computer Science & Information Technology

32 What Windows command can be used to copy entire directories, including subdirectories?

A. xcompact B. xcomp C. xcmd D. xcopy

Computer Science & Information Technology

With _____, a software engineer drags and drops graphical objects such as buttons and menus onto an application form.

A. assembly language
B. machine code
C. visual programming
D. fourth generation language

Computer Science & Information Technology