Docsity

Prolog Proof - Organization of Programming Languages - Lecture Notes, Study notes of Programming Languages

Partial preview of the text

Download Prolog Proof - Organization of Programming Languages - Lecture Notes and more Study notes Programming Languages in PDF only on Docsity!

Today ...

  • Quiz 8
  • Prolog Proof Trees

Proof trees

A proof tree is a way to view query evaluation (Prolog computation)

  • specifies a “trace” of a Prolog program
  • follows evaluation order (with unification and resolution)

The KB:

  1. r(a).
  2. s(X) :- r(X).

solve [s(a)]

nothing solve [r(a)]

solve [] nothing

One child per program clause!

Finished with clauses

to solve (success!)!

Result of resolution step!

List of goals

to “solve”!

Another example

The KB:

  1. p(X) :- q(X), r(X).
  2. q(a).
  3. q(b).
  4. r(a).

?- p(X).

The proof tree:

solve [p(X)]

solve [q(X), r(X)] nothing nothing nothing

nothing solve [r(a)] solve [r(b)] nothing

nothing nothing nothing solve [] nothing nothing nothing nothing

  • Note we often put bindings on the edges (e.g., X = a)
  • Prolog evaluation performs a depth-first left-to-right search

And another example

The KB:

  1. p(X) :- p(X), q(X).
  2. q(a).
  3. p(a).

?- p(X).

Q: See a potential problem?

The proof tree:

solve [p(X)]

solve [p(X),q(X)] nothing (^) solve []

solve [p(X),q(X),q(X)] nothing solve [q(a)]

… nothing solve [] nothing

Prolog evaluates depth- first, left-to-right …!

So this branch will be followed infinitely, without any proofs

  • Creates an infinite proof tree!

More examples:

  • “Joins”

r(a,b). s(b,c). q(X,Z) :- r(X,Y), s(Y,Z). ?- q(a,Y).

  • Transitive closure

e(a,b). e(b,c). tc(X,Y) :- e(X,Y). tc(X,Y) :- e(X,Z), tc(Z,Y). ?- tc(a,Y). % what is reachable from a?

Notes:

  • Prolog and proof techniques ...
    • Deductive closure: derive all inferences from knowledge-base (axioms), check if goal is one of them
    • Refutation (contradiction): negate goal and see if it leads to a contra- diction (thus, goal is a logical consequence of the kb)
  • Bottom-up (deductive closure) versus Top-down evaluation (refutation)
    • e.g., p(X) :- p(X), q(X).
    • In prolog, prove that ¬P(X) leads to a contradiction.
    • In top-down, find all answers to P(X) starting with base facts, until we reach a fixed point (can’t derive anything new)