introduction to artificial intelligence lecture 8 : first order logic
DESCRIPTION
Introduction to Artificial Intelligence LECTURE 8 : First Order Logic. Motivation for First Order Logic (FOL) FOL syntax Quantifiers FOL semantics Building KB in FOL Inference rules for FOL. History. First Order Logic (FOL) was essentially developed by Gottlob Frege around 1879. - PowerPoint PPT PresentationTRANSCRIPT
![Page 1: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/1.jpg)
Intro to AI Fall 2004 © L. Joskowicz 1
Introduction to Artificial Intelligence LECTURE 8: First Order Logic
• Motivation for First Order Logic (FOL)
• FOL syntax
• Quantifiers
• FOL semantics
• Building KB in FOL
• Inference rules for FOL
![Page 2: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/2.jpg)
Intro to AI Fall 2004 © L. Joskowicz 2
History
• First Order Logic (FOL) was essentially developed by Gottlob Frege around 1879.
• The goal was to create a sound and complete system from which all logical truths could be derived.
• In 1930, Kurt Godel showed that such a system does not exist (Godel’s completeness theorem).
![Page 3: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/3.jpg)
Intro to AI Fall 2004 © L. Joskowicz 3
First-order logic -- rationale (1)• Extended language to express general
statements of the form: “every person has a father and a
mother” without explicitly listing all instances
• The extension requires:– variables: X, Y, … that can refer to specific objects – relations: father(X,Y), mother(Z,Y)– quantifiers: for all , there exists, to specify the
scope of the variablesX Y Z father(Y,X) and mother(Z,X)
– syntax, semantics, and deduction rules
![Page 4: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/4.jpg)
Intro to AI Fall 2004 © L. Joskowicz 4
First order logic -- rationale (2)• First order logic (FOL) and its properties have
been widely studied in Mathematics and Logic
• FOL can express anything that can be programmed
• Issues for knowledge representation:– how to effectively represent the world -- many
ontologies possible KB design.– how to make sound, complete, and computationally
effective deductions with it.
![Page 5: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/5.jpg)
Intro to AI Fall 2004 © L. Joskowicz 5
Elements of First Order Logic (1)Terms are primitive objects: they are built out of
individual variables and function symbols (and individual constants).
• individual constants: name of a single object in the world: sarah, 55, blue (True, False)
• individual variables: place holder for objects:X, Y
• function symbols: they are just symbols but will be interpreted as operations on objects -- return an object
father(sarah), father(X), color(block), sarah(), father(block)
![Page 6: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/6.jpg)
Intro to AI Fall 2004 © L. Joskowicz 6
Elements of First Order Logic (2)Predicate symbols will be interpreted as
relations between objects: they act on termsfather_of 2-place father_of(sarah,
moshe) color_of 2-place color_of(block123, blue),
color 1-place color(blue)bird 1-place bird(Tweety)
Functions: father(sarah) = mosheAtomic Formulas
![Page 7: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/7.jpg)
Intro to AI Fall 2004 © L. Joskowicz 7
Elements of First Order Logic (3) Formulas are built out of atomic formulas with
propositional connectives (/\, \/, ~, =>, <=>) and quantifiers: (universal) and (existential):
father_of(sarah, husband(tal))
father(sarah) = husband(tal)
( X = father(sarah) ) /\ (X = husband(tal))
X (X = father(sarah) => X = moshe)
X Y father_of(X, Y)
Y X father_of(X, Y)
![Page 8: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/8.jpg)
Intro to AI Fall 2004 © L. Joskowicz 8
Elements of First Order Logic (4)
• A sentence is a formula in which all variables are quantified (no free variable)
• KB is a set of sentences on(a,b) /\ on(b,c)clear(a) color_of(a, blue)
c
ab
![Page 9: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/9.jpg)
Intro to AI Fall 2004 © L. Joskowicz 9
First Order Logic -- SyntaxFormula ----> Atomic_Formula |
Formula Connective Formula | Quantifier Variable Formula | (Formula) | ~Formula
Atomic_Formula ----> PredicateS( Term, ..., Term) | Term = Term
Term ----> Constant | Variable |FunctionS( Term, …, Term)
Connective ----> /\ | \/ | => | <=> Quantifier ----> | Constant ----> sara, 55, blue,... (lower case letters)Variable -----> X, Y, …. (upper case letters)PredicateS ----> before(_,_) …. (n-ary relation)FunctionS ----> mother(_,_), >, ..(n-ary function)
![Page 10: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/10.jpg)
Intro to AI Fall 2004 © L. Joskowicz 10
Terminology• A literal is an atomic formula or its negation• A clause is a disjunction of literals• A term without variables is called a ground
term. • A clause without variables is called a ground
clausefather_of(sarah, moshe) \/ father (lea, moshe)
• Our convention: – ground terms start with lower case letters– uninstantiated variables start with capital letters
![Page 11: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/11.jpg)
Intro to AI Fall 2004 © L. Joskowicz 11
Universal Quantifier• States that a sentence is true for all objects in
the world being modeled. X ( block(X) => color_of(X,red))
is used to claim that every object in the world that is a block is red.
X (X = a \/ X = b \/ X = c ) says that there are at most three objects in the world and that they are denoted by a, b, c. It is only in such a world that X ( block(X) => color_of(X,red)) is equivalent to:
block(a) => color_of(a,red) /\ block(b) => color_of(b,red) /\ block(c) => color_of(c,red)
![Page 12: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/12.jpg)
Intro to AI Fall 2004 © L. Joskowicz 12
Existential Quantifier• States that a sentence is true for some objects in
the world being modeled. X block(X) /\ color_of(X,red) is equivalent to block(a) /\ color_of(a,red) \/ block(b) /\ color_of(b,red) \/ block(c) /\ color_of(c,red) in a world with at most three objects named by a,b,c. Otherwise there may be a red block that is not a, b or c.
![Page 13: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/13.jpg)
Intro to AI Fall 2004 © L. Joskowicz 13
Expressiveness• How can we say that the only objects in the
world are a, b and c?
X (X = a) \/ (X = b) \/ (X = c)
~(a = b) /\ ~(a = c) /\ ~(b = c)
![Page 14: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/14.jpg)
Intro to AI Fall 2004 © L. Joskowicz 14
Quantifiers scope• Scope: in X S the scope of the quantifier is the
whole formula S.X [block(X) => color_of(X,red)] \/ on(a,Y)
• Order: existential quantifiers commute and universal quantifiers commute X (Y (Sentence)) equivalent to Y (X (Sentence))
X (Y(Sentence)) equivalent toY(X (Sentence))
• Mixed quantifiers do NOT commute X Y loves(X,Y) vs. Y X loves(X,Y)
everybody loves somebody vs. somebody is loved by everybody
![Page 15: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/15.jpg)
Intro to AI Fall 2004 © L. Joskowicz 15
Relations between quantifiers• Existential and universal quantifiers are
related to each other through negation • DeMorgan’s laws for quantifiers
X ~P ~ X P ~P /\ ~ Q ~(P \/ Q) ~X P X ~ P ~(P Q) ~P ~Q X P ~X ~ P P Q ~(~P ~Q) X P ~ X ~ P P Q ~ (~P ~Q)
• Example: every person has a father there is no person that does not have a father
![Page 16: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/16.jpg)
Intro to AI Fall 2004 © L. Joskowicz 16
Equality and its use• The equality symbol indicates that two terms
refer to the same objectfather(sarah) = moshe
indicates that the object refered to by father(sarah) and by moshe are the same
• Equality can be viewed as the identity relation=(sarah,sarah), …
• Used to distinguish between objects X Y sister_of(sarah, X) /\ sister(sarah, Y) /\ ~(X=Y) to specify that sarah has two sisters (at least)
![Page 17: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/17.jpg)
Intro to AI Fall 2004 © L. Joskowicz 17
First Order Logic – Semantics (1)• We define the meaning of terms and
formulas in structures with the help of an assignment for the individual variables.
• A structure consists of a non-empty domain, A, a suitable function: An A for every n-place function symbol of , a subset of An for every n-place predicate symbol.
• An variable assignment associates an element of A with each individual variable.
![Page 18: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/18.jpg)
Intro to AI Fall 2004 © L. Joskowicz 18
First Order Logic – Semantics (2)Every term is interpreted as an element of the
domain A:
• individual variables using the variable assignment
• complex terms by applying the function corresponding to the function symbol to the interpretations of the arguments.
![Page 19: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/19.jpg)
Intro to AI Fall 2004 © L. Joskowicz 19
First Order Logic – Semantics (3)• Truth value of formulas is defined
recursively from the truth value of atomic formulas, as in Propositional Logic
• Atomic formula: using the interpretation of the predicate symbol and the interpretations of the terms: father_of(sarah, moshe) is true iff the pair < sarah, moshe > of interpretations is in the interpretation father_of.
• _father_of is a subset of A2
![Page 20: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/20.jpg)
Intro to AI Fall 2004 © L. Joskowicz 20
First Order Logic – Semantics (4)• Formulas such as A \/ B, A /\ B, ~A, A=>B are
interpreted as in propositional calculus
X S is true iff there is some element w of the domain A, such that S gets the value True, when one uses not the original variable assignment but the modified assignment in which X gets associated with w.
X S is true iff S gets the value true with all variable assignments that differ from the original one only in the value associated with X.
![Page 21: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/21.jpg)
Intro to AI Fall 2004 © L. Joskowicz 21
Variable assignement and satisfiability• A sentence S is satisfied by a variable
assignment U when the ground sentence S[U] is valid
|= S[U] for U ={X/a, Y/b, ….}
• The satisfiability of logical sentences is determined by the logical connective
|=(S1/\ S2 /\ … /\ Sn)[U] iff |= Si[U] for all i = 1 .. n |=(S1 \/ S2 \/ … \/ Sn)[U] iff |= Si[U] for some i = 1 .. n
![Page 22: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/22.jpg)
Intro to AI Fall 2004 © L. Joskowicz 22
Expressing knowledge in FOL• Given a world or domain, identify and define
constant objects, functions, and relation predicates
• Define relevant domain knwoledge stated informally in English as a set of FOL sentences
• KB usually has two types of statements– statements about the specific objects -- – statements about general relationships -- axioms
• Many possible ways of defining the KB! aim for parsimony and soundness
![Page 23: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/23.jpg)
Intro to AI Fall 2004 © L. Joskowicz 23
Example: family relations domain
• Objects: members of the family• Functions: father, mother• Relations: male, female, parent_of,
sibling_of, brother_of, sister_of, child_of, daughter_of, son_of, spouse_of, wife_of, husband_of, ….
• statements about the specific familyfemale(sarah), father(sarah) = moshe
• statements about family relationships X Y : (Z = father(X) /\ Z = mother(X) ) => sibling(X, Y)
![Page 24: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/24.jpg)
Intro to AI Fall 2004 © L. Joskowicz 24
Some family relationships rules • A mother is a female parent M C mother(M)
= C <=> female(C) /\ parent_of(M,C)
• A grandparent is a parent of one’s parent G C grandparent_of(G,C) <=>
P parent_of(G,P) /\ parent_of(P,C)
• Parent and child are inverse relations P C parent_of(P,C) <=> child_of(C,P)
• A sibling is another child of one’s parentsX Y sibling_of(X,Y) <=> X Y /\ P parent_of(P,X) /\ parent_of(P,Y)
![Page 25: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/25.jpg)
Intro to AI Fall 2004 © L. Joskowicz 25
Inference in First Order Logic• As for propositional logic, will work only on the
syntactic form of the sentences• Extend the rules of propositional logic to deal with
quantifiers and variables. The rules will deal with variable assignment, using (syntactic) substitutions.
• You have seen, in Mathematical Logic I, a list of axioms and rules of inference that make a sound and complete proof system for FOL (Godel’s Completeness Theorem). This is not the best system for automatic inferencing.
![Page 26: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/26.jpg)
Intro to AI Fall 2004 © L. Joskowicz 26
Inference Rules: examples (1)
From KB:
1. M C mother(C) = M <=> female(M) /\ parent(M,C)
2. mother(sarah) = ruth
Deduce: female(ruth) /\ parent(ruth,sarah)
![Page 27: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/27.jpg)
Intro to AI Fall 2004 © L. Joskowicz 27
Inference Rules: examples (2)From KB = 1. X father_of(Y, X) \/ husband_of(mother(Y), X)2. husband_of(mother(Y), Z)Deduce: father_of(Y, Z)
From KB = {X R(Y, X) \/ ~P(f(Y), X) P(f(Y), Z)}Deduce: R(Y, Z)
![Page 28: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/28.jpg)
Intro to AI Fall 2004 © L. Joskowicz 28
Substitution• Substitution is a syntactic operation that takes a
formula and replaces a variable everywhere it appears by a term.
• Subst(,S) is the result of replacing the variables X, Y, …. by the terms t1, t2, …respectively in a formula S. The result is denoted S[ ]. ={X/t1, Y/t2, …}
• For example father_of(X, Y)[ X/sarah, Y/moshe ] is father_of(sarah, moshe)
Substitution is syntactic, variable assignment is semantic.
![Page 29: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/29.jpg)
Intro to AI Fall 2004 © L. Joskowicz 29
Other rules: good and bad
• Universal Elimination: X S for any t S[X/t]
In particular: X S S
• Universal Introduction: S X S
If KB does not
mention the
variable X
![Page 30: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/30.jpg)
Intro to AI Fall 2004 © L. Joskowicz 30
FOL -- Inference Rules for quantifiers• Substitution operation
Subst(,S) is the result of applying the variable assignement ={X/x, Y/y, …} to S, i.e, S[ ]
• Universal and Existential Elimination
• Existential Introduction
)},/({
xXSubstX
)},/({
xXSubstX
)},/({
xXSubstX
![Page 31: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/31.jpg)
Intro to AI Fall 2004 © L. Joskowicz 31
Example of a proof “It is a crime for an American to sell weapons
to hostile nations. North Korea is an enemy of America, has some missiles, and all of its missiles were sold to it by Coronel West, who is American.”
Prove that Coronel West is a criminal!
![Page 32: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/32.jpg)
Intro to AI Fall 2004 © L. Joskowicz 32
Formalization1. X,Y,Z american(X) /\ weapon(Y) /\ nation(Z) /\
hostile(Z) /\ sells(X,Z,Y) => criminal(X)
2. X missile(X) /\ owns(nkorea,X)
3. X missile(X)/\ owns(nkorea,X) => sells(west,nkorea,X)
4. X missile(X) => weapon(X)
5. X enemy(X,america) => hostile(X)
6. american(west)
7. nation(nkorea)
8. enemy(nkorea,america)
9. nation(america)
![Page 33: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/33.jpg)
Intro to AI Fall 2004 © L. Joskowicz 33
Proof (1) 2. and Existential elimination
10. missile(m) /\ owns(nkorea,m) X/m 10. and And-Elimination 11. owns(nkorea,m)12. missile(m)
4. And Universal Elimination13. missile(m) => weapon(m) X/m 12, 13 and Modus Ponens14. weapon(m)
3 and Universal Elimination15. missile(m) /\ owns(nkorea,m) => sells(west,nkorea,m)
![Page 34: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/34.jpg)
Intro to AI Fall 2004 © L. Joskowicz 34
Proof (2) 15, 10 and Modus Ponens16. sells(west, nkorea,m) 1 and Universal Elimination (three times) 17. american(west) /\ weapon(m) /\
nation(nkorea) /\ hostile(nkorea) /\ sells(west,nkorea,m) => criminal(west)
5 and Universal Elimination18. enemy(nkorea,america) => hostile(nkorea) 8, 18 and Modus Ponens
![Page 35: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/35.jpg)
Intro to AI Fall 2004 © L. Joskowicz 35
Proof (3)
19. hostile(nkorea)
6, 7, 14, 16, 19 and And-Introduction
20. american(west) /\ weapon(m) /\ nation(nkorea) /\ hostile(nkorea) /\ sells(west,nkorea,m)
17, 20 and Modus Ponens 21. criminal(west)
![Page 36: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/36.jpg)
Intro to AI Fall 2004 © L. Joskowicz 36
FOL inferences
• Soundness: Rules for propositional logic are sound.
• Godel proposed a system R and proved in 1931 that in FOL any sentence that logically follows from a KB can be proven: if KB |= S then KB |=R S
• Robinson developed in 1965 a mechanizable proof procedure based on resolution -- we will study it in detail next.
![Page 37: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/37.jpg)
Intro to AI Fall 2004 © L. Joskowicz 37
Main differences with propositional logic
• There are infinitely many possible models: we cannot just enumerate all the models to see whether a sentence is satisfied in all models.
• There still exist refutation-complete rules• Godel’s incompleteness theorem says that we
cannot hope for the application of these rules to terminate always when the formula C is not entailed by KB.
![Page 38: Introduction to Artificial Intelligence LECTURE 8 : First Order Logic](https://reader036.vdocuments.mx/reader036/viewer/2022062305/568151eb550346895dc02493/html5/thumbnails/38.jpg)
Intro to AI Fall 2004 © L. Joskowicz 38
Key issues in developing an effective inference procedure
• Have as few inference rules as possible to reduce the search’s branching factor
• The complexity is still exponential in the number of atomic sentences
• More efficient procedures for restricted forms of logic sentences (Horn clauses)