# 15-317 Constructive Logic Recitation 9: Homework 5, Prolog Lists, Cuts

Today in recitation, we went over some common mistakes on Homework 5 having to do with conventional associativities of connectives. Remember, conjunction and disjunction bind more tightly than implication, and implication is right-associative. So:

A ∧ B ⊃C means (A ∧ B) ⊃ C
A ∨ B ⊃ C means (A ∨ B) ⊃ C
A ⊃ B ⊃ C means A ⊃ (B ⊃ C)

Then we did some more Prolog programming, writing the predicates `prefix` and `suffix` that say when one list is a prefix or suffix of another. These can be used to enumerate prefixes and suffixes of a given list (`?- prefix(X, [1, 2, 3]).`) or to show that a non-empty list is not a prefix or suffix of the empty list (```?- prefix([_|_], []).```). They can also both be written using `append` with appropriate arguments, demonstrating some of the inherent flexibility of logic programming.

Finally, we ended with a brief discussion of green cuts and red cuts. Green cuts do not affect the meaning of a program; they merely prune needless search. A typical example of a green cut is one that commits to a clause after solving a subgoal that makes all other clauses inapplicable. We saw this in the minimum example whose clauses had disjoint preconditions -- adding a cut prunes search, but only search that would have failed. Red cuts, on the other hand, do prune search that might succeed, and in this way they change the meaning of the logic program. We saw this in the (incorrect!) minimum example which omitted the second clause's precondition: the cut changed the meaning of the program by ensuring that the second clause was never entered once the first clause's precondition succeeded.

All examples were taken from Lecture Notes 14.

References:

(Recall that to load a file `file.pl` into Prolog, you give the query `['file.pl'].` at the `?-` prompt.)

fp@cs
Frank Pfenning