CS345 Solutions #1
- (25 pts.)
needs(F,P) := create(F,P,G)
needs(F,P) :- includes(F,G) & needs(G,P)
needs(F,P) :- create(F,Q,G) & needs(G,P)
It was also possible to define the IDB req (given as an example in
class), and use it in needs.
- (25 pts.)
(a)-
int(0) :-
int(s(X)) :- int(X)
move(state(s(I),J,K), state(I,J,K) :- int(I) & int(J) & int(K)
move(state(s(s(I)),J,K), state(I,J,K) :- int(I) & int(J) & int(K)
move(state(I,s(J),K), state(I,J,K) :- int(I) & int(J) & int(K)
move(state(I,s(s(J)),K), state(I,J,K) :- int(I) & int(J) & int(K)
move(state(I,J,s(K)), state(I,J,K) :- int(I) & int(J) & int(K)
move(state(I,J,s(s(K))), state(I,J,K) :- int(I) & int(J) & int(K)
win(S) :- move(S,T) & NOT win(T)
It is necessary to define int so that the rules for move will be
safe.
(b)-
No, the program is not stratifed. If the dependency graph is
drawn, there is a negative arc win -> win. Thus, there is a
cycle involving negation, and the program cannot be stratified.
(c)-
Yes, the program is locally stratified. In any dependency graph for
the program, the only negative edges would be win(state(I,J,K)) ->
win(state(X,Y,Z)). However, (I+J+K) > (X+Y+Z) must hold, since
the only valid moves remove one or two tokens from a row. Thus, all
win -> win dependencies are acyclic. Other dependencies are win ->
move, move -> int, and int -> int (where for int(X) -> int(Y), X>Y),
which don't cause dependency cycles.
There are no cycles involving negation in the graph, so the program
is locally stratified.
- (25 pts.)
(a)-
Initialize: P = DELTA(P) = Q
Iterate until DELTA(P) = NULL:
1. DELTA(P) := PI_(1,4) ((P JOIN P JOIN DELTA(P))
UNION (P JOIN DELTA(P) JOIN P)
UNION (DELTA(P) JOIN P JOIN P))
2. DELTA(P): = DELTA(P) - P
3. P := P UNION DELTA(P)
(b)-
p represents all paths of odd length.
- (25 pts.)
(a)-
There are twelve minimal models.
- p0(a) must be in the model. q(a) is in the EDB, so the body
of the first rule (p0(X) :- q(X)) is true, thus p0(a)
must true.
- A minimal model cannot contain p's with argument other than
a. The only EDB fact is q(a), so such an IDB fact could always
be removed, and we would still have a model.
- p_i(a) and p_(i+1)(a) can't both be
false. (i = {1,2,...,8}) If p_i(a) is
false, then the (i+1)th rule
(p_(i+1)(X) :- q(X) & NOT p_i(X))
will have a true body, forcing p_(I+1)(a) to be true.
- p_i(a), p_(i+1)(a), and p_(i+2)(a) can't all be true. (i =
{0,1,...7}) If all three were true, we could drop p_(i+1) and
still have a model.
- If p8(a) is true, then p9(a) is false. If both p8(a) and
p9(a) were true, we could drop p9(a) and still have a model.
(b)-
The stratified model is {q(a), p0(a), p2(a), p4(a), p6(a), p8(a)}.