Hi Everyone,
Post your solutions to the Oct 31 In-Class Exercise to this thread.
Best, Chris
P(x, y) <- R(a, x, y), NOT S(a, x, y), x < y
Ordered Pairs: Ordered(1, 2). Ordered(1, 3). Ordered(2, 3).
Express query which selects pair where y > 2: Pairs(x, y) :- Ordered(x,y), y > 2.
(Edited: 2018-10-31)P(x,y) <- Q(w,x,y), NOT R(w,x,y), x < y
<(1, 2). <(1, 3). <(2, 3). Query(x, y) :- <(x, y), <(2, y).
NewMovie(t,y) <- Movies(t,y,,,,), y >= 1990.
OldMovie(t,y) <- Movies(t,y,,,,), NOT NewMovie(t,y).
Pair(1,2).
Pair(2,3).
Pair(1,3).
Select(x,y) <- Pair(x,y), y > 2.
(Edited: 2018-10-31)Q(x,y)<- K(x,y). P(x,y)<- R(x,y), Not Q(x,y). P(0,1) <-. P(1,2) <-. P(2,3) <-. P(3,4) <-. Greater(x, y) <- P(_,y) y>2.
(1,2).
(1,3).
(2,3).
Query(x, y) :- Pair(x, y), y > 2
(Edited: 2018-10-31)Student name: Alexander Duong
<nowiki> Give an example of a rule involving negation and an arithmetic atom which is safe.
a(x,y) <- b(x,y), NOT c(x,y), x > y.
Express ordered pairs where 0<x<y<4 as a collection of datalog facts, then express the query which selects pair where y>2.
op(1,2) <-. op(1,3) <-. op(2,3) <-. select(x,y) <- op(x,y), y > 2. </nowiki>
A rule which uses negation and an arithmetic atom but is still safe: A(x,y) := B(x,y), NOT y>1
A collection of datalog facts that represent 0<x<y<4 would be: <(1,2). <(1,3). <(2,3). Then, to query for all pairs y>2: greaterThanTwo(x,y) := <(x,y), <(2,y).
1.P(x,y) <- Q(w,x,y), NOT R(w,x,y), x<y 2.pairs (1,2); (1,3);(2,3); select(x,y) <- pairs(x,y), y>2 student: Hongbin Zheng
A(x,y) <- B(x,y), NOT C(x,y), x < y
Ordered Pairs: pair(1,2) , pair(2,3), pair(1,3)
Find(x,y) :- pair(x,y) , y > 2