Reference no: EM132210545
Question
Write a program in Prolog with the set of facts:
supp(s1,'Smith',20,'London').
supp(s2,'Jones',10,'Paris').
supp(s3,'Blake',30,'Paris').
supp(s4,'Clark',20,'London').
supp(s5,'Adams',30,'Athens').
part(p1, 'Nut', 'Red', 12, 'London').
part(p2, 'Bolt', 'Green', 17, 'Paris').
part(p3, 'Screw', 'Blue', 17, 'Oslo').
part(p4, 'Screw', 'Red', 14, 'London').
part(p5, 'Cam', 'Blue', 12, 'Paris').
part(p6, 'Cog', 'Red', 19, 'London').
proj(j1, 'Sorter', 'Paris').
proj(j2, 'Display', 'Rome').
proj(j3, 'OCR', 'Athens').
proj(j4, 'Console', 'Athens').
proj(j5, 'RAID', 'London').
proj(j6, 'EDS', 'Oslo').
proj(j7, 'Tape', 'London').
sppj(s1, p1, j1, 200).
sppj(s1, p1, j4, 700).
sppj(s2, p2, j1, 400).
sppj(s2, p2, j2, 200).
sppj(s2, p2, j3, 200).
sppj(s2, p2, j4, 500).
sppj(s2, p2, j5, 600).
sppj(s2, p2, j6, 400).
sppj(s2, p2, j7, 800).
sppj(s2, p5, j2, 100).
sppj(s3, p2, j1, 200).
sppj(s3, p4, j2, 500).
sppj(s4, p6, j3, 300).
sppj(s4, p6, j7, 300).
sppj(s5, p2, j2, 200).
sppj(s5, p2, j4, 100).
sppj(s5, p5, j5, 500).
sppj(s5, p5, j7, 100).
sppj(s5, p6, j2, 200).
sppj(s5, p1, j4, 100).
sppj(s5, p2, j4, 200).
sppj(s5, p4, j4, 800).
sppj(s5, p5, j4, 400).
sppj(s5, p6, j4, 500).
Requirements:
Given the database of tables (i.e., lists in Scheme and facts in Prolog), you must now write queries (i.e., functions in Scheme and rules in Prolog) for each of the following:
When given a pair of projects, find all suppliers who supply both projects. Return the entire entry (i.e., S#, Sname, Status, City) for the supplier.
When given a city, find all parts supplied to any project in that city. Once again, return the entire entry for the part. Find all parts supplied to any project by a supplier in the same city. In this case, results are organized by all parts for every city in the database.
Find all projects supplied by at least one supplier not in the same city.
Find all suppliers that supply at least one part supplied by at least one supplier who supplies at least one red part.
Find all pairs of city values such that a supplier in the first city supplies a project in the second city.
Find all triples of city, part#, city, such that a supplier in the first city supplies the specified part to a project in the second city, and the two city values are different.
When given a supplier, find all projects supplied entirely by that supplier.
One possible approach to the problem would be to write functions (rules) that perform the basic operations of selection (finding appropriate rows of tables), projections (printing out an entire row of a table), and join (merging two tables on a column-basis, similar to a Cartesian product).
These three basic operations can then be combined to answer the queries posed above. A second approach would be to write functions (rules) specifically to answer each of the queries.