2018-10-31

Oct 31 In-Class Exercise.

Hi Everyone,
Post your solutions to the Oct 31 In-Class Exercise to this thread.
Best, Chris
Hi Everyone, Post your solutions to the Oct 31 In-Class Exercise to this thread. Best, Chris

-- Oct 31 In-Class Exercise
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) <- 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.

-- Oct 31 In-Class Exercise
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).
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).

-- Oct 31 In-Class Exercise
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)
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.

-- Oct 31 In-Class Exercise
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.
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.

-- Oct 31 In-Class Exercise
1) NewSong(artist, duration) :- song(artist, duration, _, _, _) AND duration >= 3
2)
(1,2).
(1,3).
(2,3).
Query(x, y) :- Pair(x, y), y > 2
(Edited: 2018-10-31)
1) NewSong(artist, duration) :- song(artist, duration, _, _, _) AND duration >= 3 2) (1,2). (1,3). (2,3). Query(x, y) :- Pair(x, y), y > 2

-- Oct 31 In-Class Exercise
Student name: Alexander Duong
Give an example of a rule involving negation and an arithmetic atom which is safe. a(x,y) y. Express ordered pairs where 0
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>

-- Oct 31 In-Class Exercise
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).
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).

-- Oct 31 In-Class Exercise
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
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

-- Oct 31 In-Class Exercise
 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
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
[ Next ]
X