Write each of the queries of Datalog . You should use only safe rules, but you m
ID: 3820523 • Letter: W
Question
Write each of the queries of Datalog. You should use only safe rules, but you may wish to use several IDB predicates corresponding to subexpressions of complicated relational-algebra expressions
Product(maker, model, type)
PC(model, speed, ram, hd, price)
Laptop(model, speed, ram, hd, screen, price)
Printer(model, color, type, price)
c) Find the model number and price of all products (of any type) made by manufacturer B.
e) Find those manufacturers that sell Laptops, but not PC’s.
g) Find those pairs of PC models that have both the same speed and RAM. A pair should be listed only once; e.g., list (i, j) but not (j, i)
Explanation / Answer
Database schema:
Product(maker, model, type)
PC(model, speed, ram, hd, price)
Laptop(model, speed, ram, hd, screen, price)
Printer(model, color, type, price)
reational atom:
Product(mk,m,t)
PC(m,sp,r,hd,pr)
Laptop(m,sp,r,hd,sc,pr)
Printer(m,c,t,pr)
c)
ProductB(m) <- Product(mk,m,t) AND mk="B"
AnswerPC(m,pr) <- ProductB(m) AND PC(m,sp,r,hd,pr)
AnswerLaptop(m,pr) <- ProductB(m) AND Laptop(m,sp,r,hd,sc,pr)
AnswerPrinter(m,pr) <- ProductB(m) AND Printer(m,c,t,pr)
e)
PrLaptop(mk) <- Product(mk,m,t) AND Laptop(m,sp,r,hd,sc,pr)
PrPC(mk) <- Product(mk,m,t) AND PC(m,sp,r,hd,pr)
Answer(mk) <- PrLaptop(mk) AND NOT PrPC(mk)
g)
PCA(m,sp,r,hd,pr) <- PC(m,sp,r,hd,pr)
Answer(PCA.m,PC.m) <- PCA(m,sp,r,hd,pr) AND PC(m,sp,r,hd,pr) AND PCA.m!=PC.m
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.