Using Datalog, express the “bill of materials” query described in Exercise 13.21.

What will be an ideal response?


Here the student needs to explore the arithmetic operators of Datalog. We use the usual operator is, which evaluates arithmetic expressions.


PrimitiveSubpartCounts(?P,?Sub,?Qty) :-
PartL i s t(?P,?Sub,?Qty), Primitive(?Sub).
PartL i s t(?P,?Sub,?Qty) :- Subpart(?P,?Sub,?Qty).
PartL i s t(?P,?Sub,?Qty) :-
Subpart(?P,?Sub1,?Qty1),
PartList(?Sub1,?Sub,?Qty2),
?Qty is ?Qty1 * ?Qty2.
Primitive(?P) :- Subpart(?P,NULL,?Q).


There is no standard set of aggregate operators for Datalog. Some implementations have very powerful sets of such operators and some have none. Stronger students might explore Prolog’s fundall operator here. For others, the instructor can just ask to
use something like this: sum(AggrVar,GroupByVar,Query).So, the required view predicate will then look like this:

PartListCount(?P,?Qty) :
?Qty= sum(?Q,?P,PrimitiveSubpartCounts(?P,?Sub,?Q)).

Computer Science & Information Technology

You might also like to view...

What type of exception would occur in the IA-32 architecture if a process attempts to divide by zero?

a) fault b) trap c) abort d) any of the above could occur

Computer Science & Information Technology

Microsoft Exchange Online is a messaging platform based in the ________

Fill in the blank(s) with correct word

Computer Science & Information Technology

Describe a network printer.

What will be an ideal response?

Computer Science & Information Technology

A(n) ________ chart to compare values across geographical regions.

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

Computer Science & Information Technology