CS345 Midterm Solutions

  1. (48 pts.)

    Scoring: Each part was worth 6 points. Getting the right class was worth 2 points, and getting the model(s) right was worth 4.

    The correct answer is D; it's modularly stratified. However, many people were not aware of the fact that different rules for the same predicate could appear in different modules, as long as the flow of values among modules is acyclic (i.e., all recursions are within modules, rather than across modules). Thus, we accepted E for full credit.

    In this case, the second rule is in a lower module and the first (recursive) rule is in the upper module.

    Once you ``evaluate'' the lower module and discover p(1) and p(2), the cyclicity that makes the instantiated rules not be locally stratified goes away. You have only p(1) :- a(1,2,3) & p(2) & NOT p(3). Since all three subgoals are true, you infer p(1) (again). The model is {p(1), p(2)}.

    C; {p(1), p(2)}.

    F: {p(1), NOT p(2)}. There is no stable model. We expected people to tell whether there was a stable model in case F, but many people did not and we assumed silence implied you believed there was none. Here is the table for the WF alternating fixpoint:

    Don't forget, as some did, that p(1) is true from the basis rule.

    C; {p(1), p(2), p(3), q(1), q(3)}.

    F; the well-founded model is empty, and there is no stable model. Here is the WF alternating fixpoint.

    B; {r,s}. p and q are in stratum 0; r and s are in stratum 1. The LFP for stratum 0 gives us no true propositions. Thus, we assume p and q are false when we evaluate stratum 1. Thus, the third rule lets us infer r, and after that the last rule lets us infer s.

    F; The WF model is empty, but there is a unique stable model, p. The alternating fixpoint for the WF model looks just like that for (e). The surprise is that there is only one stable model --- check it out. In principle, you had to examine all eight possible stable models, although some simplifications are possible; e.g., if q were in the model, r could not be.

    A; {p, q, r, t}.

  2. (15 pts.)
    Yes, Q1 is contained in Q2. Containment mapping from Q2 -> Q1: X->X, Y->Y, V->A, W->A, U->A

    -2 no containment mapping

    No, Q2 is not contained in Q1. A counterexample database is D = {a(0,1), a(1,2), a(0,3), a(3,3), a(3,4), a(4,2)}. Q2(D) doesn't contain the frozen head of Q1, which is p(0,1).

    -2 No counterexample database given.

    p(X,Y) :- a(X,A) & a(A,A) & a(A,Y)

  3. (28 pts.)
    There are three canonical databases:

    D1: {a(0,0} X->0, Y->0
    D2: {a(a(0,1)} X->0, Y->1
    D2: {a(1,0)} X->1, Y->0

    -1 Missing one, -3 missing 2.

    {a(0,1)} produces the head of P2.

    No. Only D2 = {a(0,1)} produces the head of P2. Applying P1 to D2, to statisfy the first subgoal, we must map X->0 and Z->1; the second subgoal is then of the form a(1,?), but there is no a(1,?) in D2. Thus, P1(D) doesn't contain the head of P2.

    P1: panic :- a(X,Z) & a(A,Y) & a(B,C) & X<Z & Z<Y & A=Z & B=Y & C=X P2: panic :- a(X,B) & A<B -2 missing one.

    The three containment mappings are:

      m1: A->X, B->Z
      m2: A->A, B->Y
      m3: A->B, B->C

    f)"&" represents "and", and "|" represents "or".

    (X<Z & Z<Y & A=Z & B=Y & C=Y) => m1(A<B) | m2(A<B) | m3(A<B)

    (X<Z & Z<Y & A=Z & B=Y & C=Y) => (X<Z) | (A<Y) | (B<C)

    -2 for missing either side.

    g) True. (X<Z) and some other facts are on the left hand side of the implication, thus (X<Z) is true, and so (X<Z) or some other facts is also true.

  4. (9 pts.)There are two minimal solutions: ans(X,Y) :- v1(X,A) & v1(A,B) & v1(B,Y) ans(X,Y) :- v2(X,A) & v2(A,Y)