Programming Paradigms CSI2120: Jochen Lang EECS, University of Ottawa Canada
Programming Paradigms CSI2120: Jochen Lang EECS, University of Ottawa Canada
Programming Paradigms CSI2120: Jochen Lang EECS, University of Ottawa Canada
Paradigms
CSI2120
Jochen Lang
EECS, University of Ottawa
Canada
Logic Programming in Prolog
• Predicate calculus
– Predicates
– Horn clauses
– Proof by Contradiction: Resolution
• Search Trees
– Backtracking
• ← ∧ ∧ ⋯∧
– All terms , , … , in the body of the predicate have to be
true for the head to be true. Or, , , … , being true,
implies b is true.
• ←
– This is a fact because truth is always implied.
• ←
– Without a head, it is goal for which correctness still needs to
be proven. This may be considered a question in logic
programming in Prolog. Proofing correctness requires
deductive reasoning.
• Consider
( ∨ ∨ ) and and
• Proof by contradiction, i.e., assume
( ∨ ∨ ) and and and
• Simplify by resolution
(( ∧ ∨ ∨ )) and and
∨ ) and and
(( ∧ ∨ ) and
and which is a contradiction
– Goals are ordered from left to right following the order in the
rules. Goals are stated in a node.
– Leaf nodes which contain one or several goals are failure
nodes. The first (left-most) goal caused the failure.
– Empty leaf nodes are success nodes. The path from the root
to the leaf node contains the unifications and steps
necessary for the proof. These can be found on the edges.
?- voter(Y).
Building categories:
parent(building,farmbuilding).
parent(farmbuilding,barn).
parent(farmbuilding,silo).
parent(farmbuilding,house).
parent(barn,horsebarn).
parent(barn,cowbarn).
typeof(X,Y):- parent(Z,X),typeof(Z,Y).
typeof(X,Y):- parent(Y,X).
?- typeof(cowbarn,A).
likes(peter,jane).
likes(paul,jane).
conflict(X,Y) :- likes(X,Z),likes(Y,Z).
?- conflict(X,Y).
• Predicate calculus
– Predicates
– Horn clauses
– Proof by Contradiction: Resolution
• Search Trees
– Backtracking