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).
 3) 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) <- 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.
(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) <- 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.
(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
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
(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
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
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) <- 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
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) <- 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
(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) <- 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.
(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) <- 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
(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