AI Lecture 3
AI Lecture 3
p q
ɕ
knows(john , x) knows(john , Jane) { x| Jane}
knows(John , x) knows(y , Oj) {x|Oj, y|John}
knows(John , x) knows(y , mother(y)) {y|John, x|mother(y)}
• Ex. foo(X, a, g(Y))
P=q
P=foo(X, a, g(Y))
Q1=foo(fred,a,g(z)) p=q1 foo(X, a, g(Y)) = foo(fred,a,g(z))
Q2=foo(w,a,g(jack)) p=q1 foo(X, a, g(Y)) = foo(w,a,g(jack))
Q3=foo(z,a,g(moo(z)) p=q1 foo(X, a, g(Y)) = foo(z,a,g(moo(z))
Unification algorithm
• Basic idea: can replace variables by:
• other variables
• constants
• function expressions
• High level algorithm:
• Represent the expression as a list
• Process the list one by one
– Determine a substitution (if necessary)
– Apply to the rest of the list before proceeding
Examples with the algorithm
• Unify p(a,X) and p(a,b)
• (p a X) (p a b)
• Unify p(a,X) and p(Y, f(Y))
• (p a X) (p Y (f Y))
• Unify parents(X, father(X), mother(bill)) and
• parents(bill, father(bill), Y)
• (parents X (father X) (mother bill))
• (parents bill (father bill) Y)
function unify code
Processed example
• (parents X (father X) (mother bill)), (parents bill (father bill) Y)
• parents =? Parents yes
• return nil
• (X (father X) (mother bill)), (bill (father bill) Y)
• X =? bill no, substitute
• return {bill/X}
• (bill (father bill) (mother bill)), (bill (father bill) Y)
• bill =? bill yes
• return nil
Processed example (cont’d)
• ( (father bill) (mother bill)), ( (father bill) Y)
• bill =? bill yes
• return nil
• (father bill), (father bill)
• father =? father yes
• return nil
• (bill) (bill)
• bill =? bill yes
• return nil
Processed example (cont’d)
• (mother bill), Y
• (mother bill) =? Y no, substitute
• return {(mother bill) / Y}
• The set of unifying substitutions for
• (parents X (father X) (mother bill)), (parents bill (father bill) Y)
• The result is
• {bill / X, (mother bill) / Y}.
• The result is
• (parents bill (father bill) (mother bill))
Inference rules
Modus Tollens
The form of that argument...
If X, then Y
not-Y
So not-X
(2) Validity & Soundness
Example
•(S1) If John paid the electricity bill today, then
we do not have enough money to pay the gas
bill.
•(S2) If we do not have enough money to pay
the gas bill, Lisa will be angry.
•(S3) So if John paid the electricity bill today,
then Lisa will be angry.
Summary
• Propositional calculus: no variables or
functions
• Predicate calculus: allows quantified variables
as parameters of predicates or functions
• Higher order logics: allows predicates to be
variables (might be needed to describe
mathematical properties such as “every
proposition implies itself” or “there are
decidable propositions.)