You are on page 1of 34

Artificial Intelligence

First Order Predicate Logic


unknown

RL

known
deterministic stochastic
atomic
SEARCH MDPs

factored Bayes
LOGIC
nets

structured First-order
logic
Outline
1. Limitation of Propositional Logic
2. Introduction to FOL
▪ Syntax and semantics
3. Knowledge Representation in FOL
4. Logical inference in FOL
5. First-order logic
Limitation of Propositional Logic
▪ Propositional logic has limited expressive power.
▪ We cannot represent relations like ALL, some, or none with propositional
logic. Example:
▪ Statements about similar objects, relations
▪ Statements referring to groups of objects
▪ All the animals are intelligent.
▪ Some apples are sweet.
▪ We cannot describe statements in terms of their properties or logical
relationships.
Example
▪ Statements referring to groups of objects ▪ Statements about objects and relations
▪ Example: ▪ Example:
▪ Assume we want to express: “Every student ▪ Seniority of people domain
likes vacation” ▪ John is older than Mary
▪ Require to include statements about every ▪ Mary is older than Paul
student ▪ To derive: John is older than Paul
John likes vacation ∧ John is older than Mary ∧ Mary is older than Paul ⇒
Mary likes vacation ∧ John is older than Paul
Ann likes vacation ∧ ….. ▪ Assume we add another fact:
Jane is older than Mary
▪ To derive:
Jane is older than Mary ∧ Mary is older than Paul ⇒
Jane is older than Paul

▪ Problem: KB grows large


▪ Solution: ?
Example
▪ Example: ▪ Example:
▪ Assume we want to express: “Every student ▪ Seniority of people domain
likes vacation” ▪ John is older than Mary
▪ Require to include statements about every ▪ Mary is older than Paul
student ▪ To derive: John is older than Paul
John likes vacation ∧ John is older than Mary ∧ Mary is older than Paul ⇒
Mary likes vacation ∧ John is older than Paul
Ann likes vacation ∧ ….. ▪ Assume we add another fact:
Jane is older than Mary
▪ To derive:
Jane is older than Mary ∧ Mary is older than Paul ⇒
Jane is older than Paul

▪ Possible solution: ▪ Possible solution: introduce variables


▪ Allow quantification in statements A is older than B ∧ B is older than C ⇒ A is older than C
First Order Logic
▪ Another way of knowledge representation in artificial intelligence.
▪ FOL is sufficiently expressive to represent the natural language statements
▪ More expressive than propositional logic

▪ Eliminates deficiencies of PL by: ▪ Terminology:


▪ Representing objects, their properties, relations ▪ Constant symbols: represent specific objects
▪ Introducing variables that refer to an arbitrary John, France, car89
objects ▪ Variables: represent objects of a certain type
▪ Introducing quantifiers allowing us to make x, y, z
statements over groups objects ▪ Functions: applied to one or more terms
father-of (John) father-of(father-of(John))
First Order Logic: Syntax
▪ All birds fly.
▪ The predicate is "fly(bird).“
▪ ∀x bird(x) →fly(x)
▪ Every man respects his parent.
▪ The predicate is "respect(x, y)," where
x=man, and y= parent.
▪ ∀x man(x) → respects (x, parent)
▪ Some boys play cricket.
▪ In this question, the predicate is "play(x, y),"
where x= boys, and y= game.
▪ ∃x boys(x) → play(x, cricket)
Some examples of FOL sentences

▪ How expressive is FOL?


▪ Some examples from natural language
▪ Every gardener likes the sun.
▪ x gardener(x) => likes (x, Sun)
▪ You can fool some of the people all of the time
▪ x (person(x) ∧ ( t) (time(t) => can-fool(x,t)))
▪ You can fool all of the people some of the time.
▪ x (person(x) => ( t) (time(t) ∧ can-fool(x,t)))
▪ No purple mushroom is poisonous.
▪ ~ x purple(x) ∧ mushroom(x) ∧ poisonous(x)
▪ or, equivalently,
x (mushroom(x) ∧ purple(x)) => ~poisonous(x)
Knowledge engineering in FOL
▪ Identify the problem/task you want to solve.
▪ Assemble the relevant knowledge.
▪ Decide on a vocabulary of predicates, functions, and constants.
▪ Encode general knowledge about the domain.
▪ Encode a description of the specific problem instance.
▪ Pose queries to the inference procedure and get answers.
▪ Debug the knowledge base.
Representing knowledge in FOL
Example: Kinship domain
▪ Objects: people
John, Mary, Jane, …
▪ Properties: gender
Male(x), Female(x)
▪ Relations: parenthood, brotherhood, marriage
Parent ( x, y ), Brother ( x, y), Spouse ( x, y )
▪ Functions: mother-of (one for each person x)
MotherOf ( x)
Representing knowledge in FOL
Relations between predicates and functions: write down what we know about them; how
relate to each other.
▪ Male and female are disjoint categories
∀x Male ( x) ⇔ ¬Female ( x)
▪ Parent and child relations are inverse
∀x, y Parent ( x, y ) ⇔ Child ( y, x)
▪ A grandparent is a parent of parent
∀g, c Grandparent(g, c) ⇔ ∃p Parent(g, p) ∧ Parent( p, c)
▪ A sibling is another child of one’s parents
∀x, y Sibling ( x, y) ⇔ ( x ≠ y) ∧ ∃p Parent ( p, x) ∧ Parent ( p, y)
▪ And so on …
Logical inference in FOL
Logical inference problem:

▪ Given a knowledge base KB (a set of sentences) and a sentence , does the KB


semantically entail α?
KB ╞ α ?
▪ In other words: In all interpretations in which sentences in the KB are true, is also true α?

▪ Logical inference problem in the first-order logic is undecidable !!!.


▪ No procedure that can decide the entailment for all possible input sentences in a finite
number of steps.
Logical inference in FOL
▪ Logical Inference in PL ▪ Truth-table approach a viable ▪ Inference rule approach a
KB ╞ α ? for the FOL? viable for the FOL?
▪ Three approaches: ▪ NO! ▪ Yes.
▪ Truth-table approach ▪ It would require us to ▪ The inference rules
▪ Inference rules enumerate and list all represent sound inference
▪ Resolution-refutation possible interpretations I patterns one can apply to
▪ I = (assignments of symbols to sentences in the KB
objects, predicates to ▪ What is derived follows from
relations and functions to the KB
relational mappings) ▪ Caveat: Need to add rules for
▪ Simply there are too many handling quantifiers
interpretations ▪ Must involve variable
substitutions
Variable Substitutions
▪ Variables in the sentences can be substituted with terms.
(terms = constants, variables, functions)
▪ Substitution: Is a mapping from variables to terms
{x1/t1, x2/t2, …..}

▪ Application of the substitution to sentences


SUBST({x/Sam, y/Pam}, Likes(x, y)) = Likes(Sam,Pam)

SUBST({ x/z , y/fatherof(John)}, Likes(x, y)) = Likes(z, fatherof(John))


Inference Rules for Quantifiers
Universal elimination Existential elimination
∀𝑥 ∅ 𝑥 ∀𝑥 ∅ 𝑥
a is constant
∅ 𝑎 ∅ 𝑎

▪ Substitutes a variable with a constant ▪ Substitutes a variable with a constant


symbol symbol that does not appear elsewhere
in the KB
▪ Example: ▪ Example:
∀x Likes(x, IceCream) ∃x Kill(x, Victim)

Likes(Ben, IceCream) Kill(Murderer,Victim)


Reduction to Propositional Inference
▪ Suppose the KB contains just the following:
∀x King(x) ∧ Greedy(x) ⇒ Evil(x)
King(John)
Greedy(John)
Brother(Richard, John)
▪ Instantiating the universal sentence in all possible ways, we have:
King(John) ∧ Greedy(John) ⇒ Evil(John)
King(Richard) ∧ Greedy(Richard) ⇒ Evil(Richard)
King(John)
Greedy(John)
Brother(Richard, John)
▪ The new KB is propositionalized: proposition symbols are
King(John), Greedy(John), Evil(John), King(Richard), etc.
Reduction to Propositional Inference
▪ Every FOL KB can be propositionalized so as to preserve entailment
▪ A ground sentence is entailed by new KB iff it is entailed by the original KB
▪ Idea of the inference:
▪ Propositionalize KB and query, apply resolution, return result
▪ Problem:
▪ With function symbols, there are infinitely many ground terms
▪ E.g., Father(Father(Father(John)))

▪ Theorem: Herbrand (1930)


▪ If a sentence α is entailed by an FOL KB, it is entailed by a finite subset of the propositionalized KB
▪ Idea: For n = 0 to ∞ do
▪ Create a propositional KB by instantiating with depth-n terms
▪ See if α is entailed by this KB
▪ Problem: works if α is entailed, loops if α is not entailed
Problems with Propositionalization
▪ Propositionalization seems to generate lots of irrelevant sentences
▪ E.g., from:
∀x King(x) ∧ Greedy(x) ⇒ Evil(x)
King(John)
∀y Greedy(y)
Brother(Richard,John)
▪ It seems obvious that Evil(John), but propositionalization produces lots of facts such as
Greedy(Richard) that are irrelevant
▪ With p k-ary predicates and n constants, there are p·nk instantiations
Unification
▪ Takes two similar sentences and computes the substitution that makes them look the
same, if it exists
▪ Use substitutions of “similar” sentences in KB
UNIFY ( p, q) = σ such that SUBST( σ, p) = SUBST (σ , q)

▪ Examples:
UNIFY (Knows(John, x), Knows(John, Jane)) = {x/Jane}
UNIFY(Knows(John, x),Knows(y, Ann)) = {x/Ann, y/John}
UNIFY(Knows(John, x),Knows(y, Motherof(y))) = {x/Motherof(John), y/John }
UNIFY (Knows(John, x), Knows(x, Elizabeth )) = fail
Unification

▪ To unify Knows(John,x) and Knows(y,z),

σ = {y/John, x/z } or σ = {y/John, x/John, z/John}

▪ The first unifier is more general than the second.

▪ There is a single most general unifier (MGU) that is unique up to renaming of variables.

MGU = { y/John, x/z }


Generalized Inference Rules
▪ Use substitutions that let us make inferences
▪ Example: Modus Ponens
▪ If there exists a substitution σ such that
SUBST( σ, Ai) = SUBST (σ , Ai) For all i = 1, 2, 3, …, n

(𝐴1 ∧ 𝐴2 ∧ . . . . 𝐴𝑛 ⇒ 𝐵, 𝐴1′ , 𝐴′2 , . . . 𝐴′𝑛 )


𝑆𝑈𝐵𝑆𝑇(𝜎, 𝐵)
▪ Substitution that satisfies the generalized inference rule can be build via unification
process
Generalized Inference Rules
SUBST( σ, Ai) = SUBST (σ , Ai) For all i = 1, 2, 3, …, n

(𝐴1 ∧ 𝐴2 ∧ . . . . 𝐴𝑛 ⇒ 𝐵, 𝐴1′ , 𝐴′2 , . . . 𝐴′𝑛 )


𝑆𝑈𝐵𝑆𝑇(𝜎, 𝐵)
Example:
∀x King(x) ∧ Greedy(x) ⇒ Evil(x)
King(John)
∀y Greedy(y)
Brother(Richard, John)
A1' is King(John) A1 is King(x)
A2' is Greedy(y) A2 is Greedy(x)
σ is {x/John, y/John} B is Evil(x)
SUBS(σ, B) = Evil(John)
Resolution inference rule
▪ Recall: Resolution inference rule is sound and complete (refutation-complete) for the
propositional logic and CNF

▪ Generalized resolution rule is sound and refutation complete for the first-order logic
and CNF w/o equalities (if unsatisfiable the resolution will find the contradiction)

▪ Example
Inference with Resolution Rule
▪ Proof by refutation:
▪ Prove that KB, ¬ α is unsatisfiable
▪ Resolution is refutation-complete

▪ Main procedure (steps):


1. Convert to CNF with ground terms and universal variables only
2. Apply repeatedly the resolution rule while keeping track and consistency of
substitutions
3. Stop when empty set (contradiction) is derived or no more new resolvents
(conclusions) follow
Conversion to CNF
1. Eliminate implications, equivalences

2. Move negations inside (DeMorgan’s Laws, double negation)

3. Standardise variables (Rename duplicate variables)

4. Move all quantifiers left (no invalid capture possible )


Conversion to CNF
5. Skolemization (removal of existential quantifiers through elimination)
▪ If no universal quantifier occurs before the existential quantifier, replace the variable with a new
constant symbol

▪ If a universal quantifier precede the existential quantifier replace the variable with a function of the
“universal” variable

F (x) - a Skolem function

6. Drop universal quantifiers (all variables are universally quantified)

7. Convert to CNF using the distributive laws


Resolution Example
KB ¬α
¬P(w) ∨ Q(w) ¬Q(y) ∨ S (y) P(x) ∨ R x) ¬R(z) ∨ S (z), ¬S(A)

{y / w}

¬P(w) ∨ S (w)
{x / w}

S(w) ∨ R(w)
{z / w}

S (w)
{w / A}

{}
KB ╞ α Contradiction
KB in Restricted Forms
▪ The sentences in the KB are restricted to some special forms
▪ Horn form (Horn normal form)
(A ∨ ¬B) ∧ (¬ A ∨ ¬C ∨ D) Also be written as: (A ⇒ B) ∧ ( A ∧ C) ⇒ D)

▪ A disjunction of literals with at most one positive, i.e. unnegated, literal.

▪ Not all sentences in propositional logic can be converted into the Horn form

▪ Two inference rules that are sound and complete with respect to propositional symbols
for KBs in the Horn normal form:
▪ Resolution (positive unit resolution)
▪ Modus ponens
Horn normal form in FOL
▪ First-order logic (FOL)
▪ Adds variables, works with terms
▪ Generalized modus ponens rule:

▪ Generalized modus ponens:


▪ Is sound and complete for definite clauses and no functions
▪ In general it is semidecidable
▪ Not all first-order logic sentences can be expressed in the HNF form
Entailment with Horn Clause

▪ Deciding entailment with Horn clauses can be done in time that is linear in
the size of the knowledge base
▪ Forward Chaining:
▪ Idea: Whenever the premises of a rule are satisfied, infer the conclusion. Continue with rules
that became satisfied.

▪ Backward Chaining:
▪ Idea: To prove the fact that appears in the conclusion of a rule prove the premises of the rule.
Continue recursively
Forward and Backward Chaining
▪ Work forward from KB to query α: ▪ Work backwards from the query α to KB:
▪ Fire any rule whose premises are satisfied in the KB ▪ Check if α is known already, or
▪ Add its conclusion to the KB, until query α is found ▪ Prove by BC all premises of some rule concluding α

▪ Assume the KB with the following rules and facts


▪ KB: R1: Steamboat (x) ∧ Sailboat ( y) ⇒ Faster (x, y) α = Faster (Titanic , PondArrow )
R2: Sailboat ( y) ∧ RowBoat (z) ⇒ Faster ( y, z)
R3: Faster (x, y) ∧ Faster ( y, z) ⇒ Faster (x, z)
F1: Steamboat (Titanic )
F2: Sailboat (Mistral )
F3: RowBoat(PondArrow)
Forward and Backward Chaining
▪ Assume the KB with the following rules and facts
▪ KB: R1: Steamboat (x) ∧ Sailboat ( y) ⇒ Faster (x, y) α = Faster (Titanic , PondArrow )
R2: Sailboat ( y) ∧ RowBoat (z) ⇒ Faster ( y, z)
R3: Faster (x, y) ∧ Faster ( y, z) ⇒ Faster (x, z)
F1: Steamboat (Titanic )
F2: Sailboat (Mistral )
F3: RowBoat(PondArrow)
Forward and Backward Chaining
▪ Assume the KB with the following rules and facts
▪ KB: R1: Steamboat (x) ∧ Sailboat ( y) ⇒ Faster (x, y) α = Faster (Titanic , PondArrow )
R2: Sailboat ( y) ∧ RowBoat (z) ⇒ Faster ( y, z)
R3: Faster (x, y) ∧ Faster ( y, z) ⇒ Faster (x, z)
F1: Steamboat (Titanic )
F2: Sailboat (Mistral )
F3: RowBoat(PondArrow)
Summary
▪ First-order logic:
▪ objects and relations are semantic primitives
▪ syntax: constants, functions, predicates, equality, quantifiers
▪ Increased expressive power: sufficient to express real-world problems
▪ Resolution is complete for propositional logic
Forward, backward chaining are linear-time, complete for Horn clauses

▪ Problems:
▪ Handling human conceptual categories, uncertainty and dynamics
▪ Next week: Planning with FOL

You might also like