10/29

Prolog rules

  • Implication
    • x :- y. Prolog
      • X <- y Logical Notation
      • x is implied by y OR if y, then x. Sentence
    • y. => makes x True
    • x :- y, z. => in prolog, comma is AND
      • x <- ( y ^ z ) Logical Notation
    • x :- y ; z. => semicolon is OR, but semicolon is consider bad form in Prolog
      • harder to read
      • instead, use the following:
        x :- y.
        x :- z.

 

father_of (john, todd).

parent (C, P) :- father_of (C, P). //variable are in uppercase

 

 

 

family.pl

 

 

sibling (A, B) :-

parent_of(P, A),

parent_of(P, B),

A = B.

 

*There is a P such that there are a parent of both A and B

 

 

full_sibling (A, B) :-

father_of (F, A), father_of (F, B),

mother_of(M, A), mother_of(M, A),

A = B.

 

Orphan (C) :- + parent_of(_, C).

-> C is an orphan if Prolog cannot prove the statement parent_of(_,C) for any value.

 

” Negation as failure: not is equivalent to not being able to prove something.

  • Vital for expression and effectiveness of prolog as a programming language.
  • But a design choice from a logical perspective

 

monotonic logic -> if you add statement or rule, it cannot contradict anything that previously existed.

Prolog is non-monotonic logic.

 

Recursive rules

ancestor_of( A, D) :-

parent_of (A, P).

ancestor_of (P, D).

ancestor_of (P, C) :- -|

parent_of (P, C). | either of these can be a base case.

ancestor_of (P, P). -|

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Advertisements