2019-10-29

Oct 30 In-Class Exercise Thread .

Post your solution to the Oct 30 In-Class Exercise to this thread.

Best,

Chris

Post your solution to the Oct 30 In-Class Exercise to this thread. Best, Chris
2019-10-30

-- Oct 30 In-Class Exercise Thread
  1. WindowsDesktop(x) <- Computer(x), NOT Mac(x), NOT Linux(x), x > 100.
  2. GreaterThanOne(2).

GreaterThanOne(3). GreaterThanOne(4). GreaterThanOne(5).

GreaterThan(5, 4). GreaterThan(4, 3). GreaterThan(3, 2). GreaterThan(2, 1). GreaterThan(1, 0).

LessThanFive(4). LessThanFive(3). LessThanFive(2). LessThanFive(1). LessThanFive(0).

OrderPair(x, y) <- GreaterThanOne(x), GreaterThan(x, y), LessThanFive(y).

  1. SelectPairs(x, y) <- OrderPair(x, y), y > 3.
(Edited: 2019-10-30)
1) WindowsDesktop(x) <- Computer(x), NOT Mac(x), NOT Linux(x), x > 100. 2) GreaterThanOne(2). GreaterThanOne(3). GreaterThanOne(4). GreaterThanOne(5). GreaterThan(5, 4). GreaterThan(4, 3). GreaterThan(3, 2). GreaterThan(2, 1). GreaterThan(1, 0). LessThanFive(4). LessThanFive(3). LessThanFive(2). LessThanFive(1). LessThanFive(0). OrderPair(x, y) <- GreaterThanOne(x), GreaterThan(x, y), LessThanFive(y). 3) SelectPairs(x, y) <- OrderPair(x, y), y > 3.

-- Oct 30 In-Class Exercise Thread
  1. P(x,y) &lt;- Q(x,y), x &lt; y, not Q(y, x).
  1. relation Ordered contains such pairs

Number(2). Number(3). Number(4). MoreThanOne(x) &lt;- Number(x), 1&lt;x. LessThanFive(x) &lt;- Number(x), x&lt;5. Ordered(x, y) &lt;- MoreThanOne(x), LessThanFive(y), x&lt;y.

or

Ordered(2, 3). Ordered(2, 4). Ordered(3, 4).

  1. relation Pair contains such pairs (also using previous rule)

Pair(x, y) &lt;- Ordered(x, y), y&gt;3.

(Edited: 2019-10-30)
1. P(x,y) <- Q(x,y), x < y, not Q(y, x). 2. relation Ordered contains such pairs Number(2). Number(3). Number(4). MoreThanOne(x) <- Number(x), 1<x. LessThanFive(x) <- Number(x), x<5. Ordered(x, y) <- MoreThanOne(x), LessThanFive(y), x<y. or Ordered(2, 3). Ordered(2, 4). Ordered(3, 4). 3. relation Pair contains such pairs (also using previous rule) Pair(x, y) <- Ordered(x, y), y>3.

-- Oct 30 In-Class Exercise Thread
  1. A(x, y) &lt;- B(x, y, z) , NOT C(y, b) , x +1 &gt;y.
  2. D(x, y) &lt;- 1&lt;x, 5&gt;y, x&lt;y.
  3. E(x, y) &lt;- 1&lt;x, 5&gt;y, x&lt;y, y&gt;3.
(Edited: 2019-10-30)
1. A(x, y) <- B(x, y, z) , NOT C(y, b) , x +1 >y. 2. D(x, y) <- 1<x, 5>y, x<y. 3. E(x, y) <- 1<x, 5>y, x<y, y>3.

-- Oct 30 In-Class Exercise Thread

Age(&#039;John&#039;, 17) Age(&#039;Mark&#039;, 22)

Adult(Y) &lt;- Age(Y, Z), NOT Z &lt; 18

Smaller(1, 2) Smaller(3, 4) Smaller(4, 5)

Bigger(Y, Z) &lt;- Smaller(Y, D) AND Y &gt; Z

(Edited: 2019-10-30)
1. Age('John', 17) Age('Mark', 22) Adult(Y) <- Age(Y, Z), NOT Z < 18 2. Smaller(1, 2) Smaller(3, 4) Smaller(4, 5) 3. Bigger(Y, Z) <- Smaller(Y, D) AND Y > Z

-- Oct 30 In-Class Exercise Thread

P(x,y) &lt;- Q(x, y, z), z &gt; 1, NOT R(y)

P(x, y) &lt;- x &gt; 1, y &gt; x, 5 &gt; y.

P(x, y) &lt;- Q(x,y), y &gt; 3

1. P(x,y) <- Q(x, y, z), z > 1, NOT R(y) 2. P(x, y) <- x > 1, y > x, 5 > y. 3. P(x, y) <- Q(x,y), y > 3

-- Oct 30 In-Class Exercise Thread

1.) P(x,y) &lt;- Q(x,z), NOT R(x)

2.) OrderedPairs(2,3) &lt;-. OrderedPairs(2,4) &lt;-. OrderedPairs(3,4) &lt;-.

3.) GreaterOrderedPairs(x, y) &lt;- OrderedPairs(x, y), y &gt; 3

1.) P(x,y) <- Q(x,z), NOT R(x) 2.) OrderedPairs(2,3) <-. OrderedPairs(2,4) <-. OrderedPairs(3,4) <-. 3.) GreaterOrderedPairs(x, y) <- OrderedPairs(x, y), y > 3

-- Oct 30 In-Class Exercise Thread
  1. studentsRecord(ID, GRADE) &lt;- Students(ID, GRADE, GPA, _, _, _) AND GPA &gt; 3.0, NOT Record(ID, GRADE).

This rule is safe because ID and GRADE appear safely in the first two subgoal and an arithmetic atom with GPA &gt; 3.0.

  1. Ordered Pair.

OrderedPairs(2, 3) &lt;-.

OrderedPairs(2, 4) &lt;-.

OrderedPairs(3, 4) &lt;-.

  1. GreaterPairs(x, y) &lt;- OrderedPairs(x, y) , y &gt; 3
(Edited: 2019-10-30)
1. studentsRecord(ID, GRADE) <- Students(ID, GRADE, GPA, _, _, _) AND GPA > 3.0, NOT Record(ID, GRADE). This rule is safe because ID and GRADE appear safely in the first two subgoal and an arithmetic atom with GPA > 3.0. 2. Ordered Pair. OrderedPairs(2, 3) <-. OrderedPairs(2, 4) <-. OrderedPairs(3, 4) <-. 3. GreaterPairs(x, y) <- OrderedPairs(x, y) , y > 3

-- Oct 30 In-Class Exercise Thread
  1. MoreThanOneMultiple(x, y) &lt;- BiggerOrEqual(x, y), x % y = 0, NOT Same(x, y).
  2. Smaller(x, y) &lt;- x &lt; y. BIggerThanOne(1, x) &lt;- x &gt; 1. SmallerThanFive(y, 5) &lt;- y &lt; 5.

Note: #2 is not a Datalog

Pair(x, y) &lt;- Smaller(x, y), y &gt; 3.

(Edited: 2019-10-30)
1. MoreThanOneMultiple(x, y) <- BiggerOrEqual(x, y), x % y = 0, NOT Same(x, y). 2. Smaller(x, y) <- x < y. BIggerThanOne(1, x) <- x > 1. SmallerThanFive(y, 5) <- y < 5. Note: #2 is not a Datalog 3. Pair(x, y) <- Smaller(x, y), y > 3.

-- Oct 30 In-Class Exercise Thread

1.)

isPhone(X) &lt;- isHandy(X) , NOT( isLaptop(X) ) , X &gt;0

isHandy(X) &lt;- X&lt; 100 isLaptop(X) &lt;- X&gt; 2000

  1. coordinates(3,4)

coordinates(2,4)

  1. selectCoordinates(X,Y) &lt;- isValid(X), isValid(Y), Y&gt;3

isValid(X) &lt;- X&gt;0

(Edited: 2019-10-30)
1.) isPhone(X) <- isHandy(X) , NOT( isLaptop(X) ) , X >0 isHandy(X) <- X< 100 isLaptop(X) <- X> 2000 2. coordinates(3,4) coordinates(2,4) 3. selectCoordinates(X,Y) <- isValid(X), isValid(Y), Y>3 isValid(X) <- X>0
[ Next ]
X