[ Prev ]
2019-10-30

-- Oct 30 In-Class Exercise Thread
 1. Give an example of a rule involving negation and an arithmetic atom which is safe.
 P(x, y) <- x < y, NOT Q(x, y)
 2. Express ordered pairs where 1 < x < y < 5 as a collection of Datalog facts.
 P(x) <- 1 < x
 P(x, y) <- x < y
 P(y) <- y < 5
 Result(x, y) <- P(x), P(x, y), P(y)
 3. Express the query that selects pairs where y > 3.
 R(y) <- Result(_, y), y > 3
(Edited: 2019-10-30)
1. Give an example of a rule involving negation and an arithmetic atom which is safe. P(x, y) <- x < y, NOT Q(x, y) 2. Express ordered pairs where 1 < x < y < 5 as a collection of Datalog facts. P(x) <- 1 < x P(x, y) <- x < y P(y) <- y < 5 Result(x, y) <- P(x), P(x, y), P(y) 3. Express the query that selects pairs where y > 3. R(y) <- Result(_, y), y > 3

-- Oct 30 In-Class Exercise Thread
 1. StoreItems(a) <- Shirts(a), Pants(a), NOT hat(a), a>= 500.
 2. Pairs(a,b) <-.
    Pairs(b,c) <-.
    Pairs(a,c) <-.
 3. FinalResults(x,y) <- Results(x,y), y>3
(Edited: 2019-10-30)
1. StoreItems(a) <- Shirts(a), Pants(a), NOT hat(a), a>= 500. 2. Pairs(a,b) <-. Pairs(b,c) <-. Pairs(a,c) <-. 3. FinalResults(x,y) <- Results(x,y), y>3

-- Oct 30 In-Class Exercise Thread
1. iPhone(X) <- useiOS(x), NOT useAndroid(x), x>100
2. 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.
3. R(x,y) <- T(x,y), y >3
1. iPhone(X) <- useiOS(x), NOT useAndroid(x), x>100 2. 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. 3. R(x,y) <- T(x,y), y >3

-- Oct 30 In-Class Exercise Thread
1) A(x, y) <- B(x, y), NOT C(x, y), x > 0
2) A(2, 3)
A(3, 4)
A(2, 4)
3) A(y) <- y > 3
(Edited: 2019-10-30)
1) A(x, y) <- B(x, y), NOT C(x, y), x > 0 2) A(2, 3) A(3, 4) A(2, 4) 3) A(y) <- y > 3

-- Oct 30 In-Class Exercise Thread
1. R(x) <- S(x), NOT T(x), x > 100.
2. R(1, x) <- .
R(x, y) <- .
R(y, 5) <- .
3. S(x, y) <- R(x, y), y > 3
1. R(x) <- S(x), NOT T(x), x > 100. 2. R(1, x) <- . R(x, y) <- . R(y, 5) <- . 3. S(x, y) <- R(x, y), y > 3

-- Oct 30 In-Class Exercise Thread
1. Q(x,z) and A(x,y,z) , Not B(z) when x>y
2. Ordered Pair(2,3) <-
    Ordered Pair(3,4) <-
3. pair(x,y) where y>3
    pair(x,1)
    pair(x,2)
1. Q(x,z) and A(x,y,z) , Not B(z) when x>y 2. Ordered Pair(2,3) <- Ordered Pair(3,4) <- 3. pair(x,y) where y>3 pair(x,1) pair(x,2)

-- Oct 30 In-Class Exercise Thread
1. Height('david',4.7) Height ('Mary', 5.8")
 Adult(Y) <- Height(Y, Z), NOT Z < 5.8
2.
 shorter(1, 2)
 shorter(3, 4)
 shorter(4, 5)
3.
 Taller(Y, Z) <- Shorter(Y, D) AND Y > Z
(Edited: 2019-10-30)
1. Height('david',4.7) Height ('Mary', 5.8") Adult(Y) <- Height(Y, Z), NOT Z < 5.8 2. shorter(1, 2) shorter(3, 4) shorter(4, 5) 3. Taller(Y, Z) <- Shorter(Y, D) AND Y > Z

-- Oct 30 In-Class Exercise Thread
1. B(X, Y) <- Q(X, Y), NOT(R(Y)), X > Y
2. XCoor(X) <- 2
XCoor(X) <- 3
XCoor(X) <- 4
YCoor(Y) <- 2
YCoor(Y) <- 3
YCoor(Y) <- 4
Points(X, Y) <- XCoor(X), YCoor(Y)
Pairs(X, Y) <- Points(X, Y), 1 < X, X < Y, Y < 5
Ideally: Points(X,Y) <- X and Y are arbitrary numbers
3. Select(X, Y) <- Pairs(X, Y), Y > 3
(Edited: 2019-10-30)
1. B(X, Y) <- Q(X, Y), NOT(R(Y)), X > Y 2. XCoor(X) <- 2 XCoor(X) <- 3 XCoor(X) <- 4 YCoor(Y) <- 2 YCoor(Y) <- 3 YCoor(Y) <- 4 Points(X, Y) <- XCoor(X), YCoor(Y) Pairs(X, Y) <- Points(X, Y), 1 < X, X < Y, Y < 5 Ideally: Points(X,Y) <- X and Y are arbitrary numbers 3. Select(X, Y) <- Pairs(X, Y), Y > 3

-- Oct 30 In-Class Exercise Thread
1. S(x, y) <- R(x, z) AND R(z, y) AND NOT R(x, y) AND x < y
2 R(x, y) <- S(x, y, _) AND x > 1 AND y < 5 AND x < y
3. SELECT y FROM R WHERE y > 3
(Edited: 2019-10-30)
1. S(x, y) <- R(x, z) AND R(z, y) AND NOT R(x, y) AND x < y 2 R(x, y) <- S(x, y, _) AND x > 1 AND y < 5 AND x < y 3. SELECT y FROM R WHERE y > 3

-- Oct 30 In-Class Exercise Thread
1. P(x,y) <- Q(x,z), NOT R(x) 2. coordinates(3,4) coordinates(2,4) 3. GreaterOrderedPairs(x, y) <- OrderedPairs(x, y), y > 3
1. P(x,y) <- Q(x,z), NOT R(x) 2. coordinates(3,4) coordinates(2,4) 3. GreaterOrderedPairs(x, y) <- OrderedPairs(x, y), y > 3
[ Next ]
X