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) &lt;- Q(w,x,y), NOT R(w,x,y), x &lt; y

&lt;(1, 2). &lt;(1, 3). &lt;(2, 3). Query(x, y) :- &lt;(x, y), &lt;(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) &lt;- Movies(t,y,,,,), y &gt;= 1990.

OldMovie(t,y) &lt;- Movies(t,y,,,,), NOT NewMovie(t,y).

Pair(1,2).

Pair(2,3).

Pair(1,3).

Select(x,y) &lt;- Pair(x,y), y &gt; 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)&lt;- K(x,y). P(x,y)&lt;- R(x,y), Not Q(x,y). P(0,1) &lt;-. P(1,2) &lt;-. P(2,3) &lt;-. P(3,4) &lt;-. Greater(x, y) &lt;- P(_,y) y&gt;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 &gt;= 3

(1,2).

(1,3).

(2,3).

Query(x, y) :- Pair(x, y), y &gt; 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

&lt;nowiki&gt; Give an example of a rule involving negation and an arithmetic atom which is safe.

a(x,y) &lt;- b(x,y), NOT c(x,y), x &gt; y.

Express ordered pairs where 0&lt;x&lt;y&lt;4 as a collection of datalog facts, then express the query which selects pair where y&gt;2.

op(1,2) &lt;-. op(1,3) &lt;-. op(2,3) &lt;-. select(x,y) &lt;- op(x,y), y &gt; 2. &lt;/nowiki&gt;

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&gt;1

A collection of datalog facts that represent 0&lt;x&lt;y&lt;4 would be: &lt;(1,2). &lt;(1,3). &lt;(2,3). Then, to query for all pairs y&gt;2: greaterThanTwo(x,y) := &lt;(x,y), &lt;(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) &lt;- Q(w,x,y), NOT R(w,x,y), x&lt;y 2.pairs (1,2); (1,3);(2,3); select(x,y) &lt;- pairs(x,y), y&gt;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) &lt;- B(x,y), NOT C(x,y), x &lt; y

Ordered Pairs: pair(1,2) , pair(2,3), pair(1,3)

Find(x,y) :- pair(x,y) , y &gt; 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