0% found this document useful (0 votes)
69 views

AI-KRR 4 (First Order Logic)

This document discusses first order logic and its components. It defines key concepts like predicates, terms, formulas and sentences in first order logic. It also explains logical connectives, quantifiers, rules of inference and provides examples to illustrate various concepts in first order logic like predicates, relations, terms and quantified statements.

Uploaded by

mohit21102
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
69 views

AI-KRR 4 (First Order Logic)

This document discusses first order logic and its components. It defines key concepts like predicates, terms, formulas and sentences in first order logic. It also explains logical connectives, quantifiers, rules of inference and provides examples to illustrate various concepts in first order logic like predicates, relations, terms and quantified statements.

Uploaded by

mohit21102
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 59

Artificial Intelligence:

Knowledge Representation and Reasoning

First Order Logic

Deepak Khemani
Department of Computer Science & Engineering
IIT Madras
Sentences, Denotation, and Truth
• A logic is a formal language that defines a set of sentences
{𝛂, 𝛃, 𝛄 …}
• Each sentence has a meaning, ascribed from outside.
• Each sentence has a truth value, ascribed from outside
• Compound sentences have truth values that are determined
completely by its constituents and logical operators
• Logic has a notion of Entailment
• Logic also has Rules of Inference
• Logic has a machinery or algorithms for producing new
sentences from old by applying the rules of inference
• The goal of building the machinery is to mechanically produce
all and only the true sentences (conclusions) – given a set of
true sentences (axioms, premises)

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Deconstructing Sentences
Deduction is possible because of connections
between constituents of sentences

(α ⊃ β) All men are mortal


α
β Socrates is a man
Modus Ponens Socrates is mortal

The form of the argument captures the connections

Propositional Logic cannot make these connections


Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
Aristotelian Logic: Categories and Individuals
Aristotle was concerned with making statements about categories
- Universal Affirmation: All S are P All Men are Mortal
- Particular Affirmation: Some S are P Some Children are Tall
- Universal Denial: No S is P No Priest is Immortal
- Particular Denial: Some S are not P Some Birds are not Priests

Individuals could belong to categories. For example, “X is a P”

The Socratic Argument is one of the fourteen valid forms of the Syllogism
All Men are Mortal
Socrates is a Man
Therefore, Socrates is Mortal

See https://plato.stanford.edu/entries/aristotle-logic/
Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
Relations on a Domain
A Domain D or a Universe of Discourse is the ”world” of First Order Logic

Mortal Men

All men are mortal


Socrates is a man Socrates

Socrates is mortal

Categories are unary relations or subsets of D

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


First Order Logic / Predicate Calculus
• The meaning or semantics in PL was externally defined.
• The semantics of First Order Logic (FOL) is defined over a domain.
• The domain D is a set and has individuals
• Individuals may be named and identified
• Individuals maybe unknown or variables
• FOL is also called Predicate Calculus because of the use of predicates.
• Unary predicates are interpreted as subsets of the domain D
• Binary predicates are binary relations. Subsets of DxD.
• FOL is a logic that breaks down a sentence into constituents and relations
between them.
• FOL also has the vocabulary to talk of “all” and “some”

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Predicates and Individuals Dogs
Mortal
Individuals
Ted
Constants (named) – Aristotle
Variables (unknown) – X Men

X
Aristotle Rocks
Predicates
Socrates
Unary relations
Man(Socrates)
Man(Aristotle)
Man(X)
Dog(Ted)
Binary relations
Teacher(Socrates, Aristotle)
Pet(Socrates,Ted)

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


First Order Logic (FOL): Syntax
The logical part of the vocabulary
• Symbols that stand for connectives or operators
• “∧”, “∨”, “¬”, and “⊃”…
• Brackets “(“, “)”, “{“, “}”…
• The constant symbols “⊥” and “⊤”.

• A set of variable symbols V = {v1, v2, v3, … }


• commonly used {x, y, z, x1, y1, z1, …}
•Quantifiers: “"” read as “for all”, and “$” read as “there exists”.
The former is the universal quantifier and
the latter the existential quantifier.
• The symbol “=” read as “equals”.

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


FOL Syntax (contd)
The non-logical part of FOL vocabulary constitutes of three sets.

• A set of predicate symbols P = {P1, P2, P3, …}. We also use the symbols {P,
Q, R, …}. More commonly we use words like “Man”, “Mortal”, “GreaterThan”.
Each symbol has an arity associated with it.
• A set of function symbols F = {f1, f2, f3, …}. We commonly used the symbols
{f, g, h…} or words like “Successor” and “Sum”. Each function symbol has an
arity that denotes the number of argument it takes.
• A set of constant symbols C = {c1, c2, c3, …}. We often used symbols like “0”,
or “Socrates”, or “Darjeeling” that are meaningful to us.

The three sets define a language L(P,F,C) or L(R,F,C)

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Terms of L(P,F,C)

The basic constituents of FOL expressions are terms. The set of terms ℑ
of L(P,F,C) is defined as follows. The constants and the variables are
terms by definition. More terms are defined using the function symbols.

If t ∈ V then t ∈ ℑ
If t ∈ C then t ∈ ℑ
If t1, t2, …, tn ∈ ℑ and f ∈ F is an n-place function symbol
then f(t1,t2, …,tn) ∈ ℑ

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Atomic Formulas of L(P,F,C)
The set of formulas is defined using terms and predicate symbols. By default
the logical symbols “⊥” and “⊤” are also formulas. The set of well formed
formulas F of L(P,F,C) is defined as follows.
Atomic formulas A
⊥∈A
⊤∈A
If t1, t2 ∈ ℑ then (t1=t2) ∈ A
If t1, t2, …, tn∈ ℑ
and P ∈ P is an n-place predicate symbol
then P(t1,t2,…,tn) ∈ A
Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
Formulas of L(P,F,C)
The set of formulas of L(P,F,C) ℱ is defined as follows
If α ∈ A then α ∈ ℱ

If α ∈ ℱ then ¬α ∈ ℱ
If α, β ∈ ℱ then (α∧β) ∈ ℱ
If α, β ∈ ℱ then (α∨β) ∈ ℱ
If α, β ∈ ℱ then (α⊃β) ∈ ℱ

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Universal and Existential Quantifiers
If α ∈ ℱ and x ∈ V then "x (α) ∈ ℱ
"x (α) is read as “for all x (α)”

If α ∈ ℱ and x ∈ V then $x (α) ∈ ℱ


$x (α) is read as “there exists x (α)”

We will also use the notation (forall (x) (α)) and (exists (x) (α))
as given in the book Artificial Intelligence by Eugene
Charniak and Drew McDermott.
Makes representation for use in programs simpler.
Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
List notation
Standard mathematical notation
1. "x (Man(x) É Human(x)) : all men are human beings
2. Happy(suresh) Ú Rich(suresh) : Suresh is rich or happy
3. "x (CitrusFruit(x) É ¬Human(x)) : all citrus fruits are non-human
4. $x (Man(x) Ù Bright(x)) : some men are bright

List notation (a la Charniak & McDermott, “Artificial Intelligence”)


1.(forall (x) (if (man x) (human x)))
2.(or (happy suresh) (rich suresh))
3.(forall (x) (if (citrusFruit x) (not (human x))))
4.(exists (x) (and (man x) (bright x)))
Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
Sentences of L(P,F,C)

A variable within the scope of a a quantified is said to be bound.

If a variable is not bound then it is free.

Example: (forall (x) (and (exists (y) (loves-to-read x y)) (book y))

bound free

A formula of L(P,F,C) without free variables


is a sentence of L(P,F,C)
Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
FOL: Rules of Inference
The propositional logic rules we saw earlier are valid in FOL as well. In addition we need
new rules to handle quantified statements. The two commonly used rules of inference are,

"x P(x) where a ∈ C Universal Instantiation (UI)


P(a)

P(a) where a ∈ C Generalization


$x P(x)

Examples: "x (Man(x) ⊃ Mortal(x))


(Man(Socrates) ⊃ Mortal(Socrates))

(Man(Socrates) ⊃ Mortal(Socrates))
$x (Man(x) ⊃ Mortal(x))

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


FOL: Rules of Substitution

The following rules of substitution are also useful,

¬"x α ≡ $x ¬α DeMorgan’s law


¬$x α ≡ "x ¬α DeMorgan’s law
"x "y α ≡ "y "x α
$x $y α ≡ $y $x α

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Semantics (First Order Logic)
Difficult to express universal statements meaningfully in Propositional Logic.
Consider,
Alice likes mathematics and she likes stories. If she likes mathematics she likes
algebra. If she likes algebra and likes physics she will go to college. …
The statements in red colour are specific to Alice. We often want to make these
as general statements - If SOMEONE likes mathematics she likes algebra. If
SOMEONE likes algebra and likes physics she will go to college.
To make such general statements and reason with them we need the notion of
variables that FOL gives us, and the universal and existential quantifiers.
The variables take values from a domain, and thus we have the notion of
Interpretations in FOL where we choose a domain and interpret the language
L(P,F,C) over the domain.

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Semantics: Interpretations for L(P,F,C)
An Interpretation ϑ = <D, I> of a FOL language L(P,F,C)
constitutes of a domain (or Universe of Discourse) D and a
mapping I from the language L to the domain D.
Each of the elements of the sets P, F and C are interpreted
over D. Each of them is understood or gets meaning from the
domain D.
Predicate symbols are mapped to relations on D
Function symbols are mapped to functions on D
Constant symbols are mapped to individuals in D
Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
Interpretation ϑ = <D,I> of L(P,F,C)
For every predicate symbol Q ∈ P of arity N,
I(Q) = QI where QI is the image of Q and QI Í DxDx…xD

For every function symbol f ∈ F of arity N,


I(f) = fI where fI is the image of f and fI: DxDx…xD à D

For every constant symbol c ∈ C


I(c) = cI where cI is the image of c and cI ∈ D

In addition we have an assignment A: V à D


from the set of variables of L(P,F,C) to the domain.
A(v) = vA where vA ∈ D

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Interpretation of Terms of L(P,F,C)
Terms in FOL denote elements in the domain.
A term t ∈ ℑ mapped to the element of the domain D as follows.
If t ∈ V then tIA = tA
If t ∈ C then tIA = tI
If t = f(t1,t2, …,tn) and f ∈ F then tIA = fI(t1IA, t2IA, … , tnIA)
Variables are mapped by the assignment A.
For example, x à 12
Constants are interpreted by the mapping I.
For example, sifar à 0
Functions denote elements too.
For example, plus(3,8) à 11
Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
Interpretations
Consider the following KB

{(O A B), (O B C), (not (M A)), (M C)}

Where O is a binary predicate symbol


M is a unary predicate symbol
A, B and C are constant symbols

What is the above KB describing?


Observe that we have not used helpful names!
Remember – meaning lies in the mind of the beholder

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Interpretation 1 {(O A B), (O B C), (not (M A)), (M C)}
Domain: Blocks World

Predicate symbols A is not maroon


A is on B
O à On
M à Maroon
B
B is on C
C is maroon
Constant Symbols
A, B, C à blocks

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Interpretation 2 {(O A B), (O B C), (not (M A)), (M C)}
Domain: People Betty is looking at Cuthbert
Archie is looking at Betty
Predicate symbols
O à LookingAt
M à Married
Cuthbert Betty Archie
Constant Symbols
A à Archie is married is not married
B à Betty
C à Cuthbert

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Truth Assignment to Atomic Formulas of FOL
A valuation function Val: ℱ à {true, false}
Val(⊤) = true
Val(⊥) = false
Val(t1=t2) IA = true iff t1IA= t2IA
Val(Q(t1,t2,…,tn)) IA = true iff <t1IA, t2IA, … , tnIA> ∈ QI

For example,
• colour(lily) = white is true iff both refer to the same colour
• president(usa) = commander(us_army) is true iff both are the same person
• LessThan(5,17) is true iff <5,17> ∈ < relation on Natural Numbers
• Brother(suresh, ramesh) is true iff
<suresh,ramesh> ∈ Brother relation on the set of people

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Truth Assignment to Formulas of FOL
Logical connectives are interpreted in the standard way
If Val(α) = true then Val(¬α) = false
If Val(α) = false then Val(¬α) = true

If Val(α) = false and Val(β) = false then Val(α∨β) = false


else Val(α∨β) = true
If Val(α) = true and Val(β) = false then Val(α⊃β) = false
else Val(α⊃β) = true
If Val(α) = true and Val(β) = true then Val(α∧β) = true
else Val(α∧β) = false

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Truth Assignment to Quantified Formulas of FOL
A formula of the form $x(α) is true if there is some value of x for which the
formula is true. A universally quantified formula "x (α) is true for all possible
values of x. Formally,
($x (α)) IA = true iff αIB is true for some assignment B that is an x-variant of A.
In other words the formula α is true for some value of x.
("x (α)) IA = true iff αIB is true for all assignments B that are x-variants of A.
In other words the formula α is true for all values of x.

An assignment B is said to be an x-variant of an assignment A


if they agree on the value of all variables except x.

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Truth Assignment to Sentences of FOL
• A sentence in FOL is a formula without any free variables.
• This means that all variables in the formula are quantified.
• As a consequence the sentences are true or false independent of the
assignment mapping.

The meaning of the terms and sentences of a set of FOL sentences is


given by an interpretation ϑ = <D, I>, where D is a domain and I is an
interpretation mapping.

An interpretation M = <D, I> of set of sentences


or a theory in a language L(P,F,C) is a model
if all the sentences in the set are true in the interpretation.

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Tautologies, Satisfiable and Unsatisfiable formulas

• A tautology is a formula of L(P,F,C) that is true in all interpretations.


• For example Happy(suresh) Ú ¬ Happy(suresh)

• A formula of L(P,F,C) is satisfiable iff it is true in at least one


interpretation.
• For example "x (Man(x) É Human(x))
(depends on the meaning of Man and Human)

• A formula of L(P,F,C) is unsatisfiable iff it is true in no interpretation.


• For example Happy(suresh) Ù ¬ Happy(suresh)

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Proofs

(in First Order Logic)

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


FOL: Will Alice go top college?
Let us rephrase our example (Alice) problem in first order terminology.
• Alice likes mathematics and she likes stories.
• If someone likes mathematics she likes algebra[1].
• If someone likes algebra and likes physics she will go to college.
• Alice does not like stories or she likes physics.
• Alice does not like chemistry and history.”

We can formalize the statements in FOL as follows.


1. likes(Alice, Math) ∧ likes(Alice, stories)
2.∀x(likes(x, Math) ⊃ likes(x, Algebra))
3.∀x((likes(x, Algebra) ∧ likes(x, Physics)) ⊃ goesTo(x, College))
4.¬likes(Alice, stories) ∨ likes(Alice, Physics)
5.¬likes(Alice, Chemistry) ∧ ¬likes(Alice, History)
[1] Here we must emphasize that she stands for both she and he.
Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
The FOL Proof
1. likes(Alice, Math) ∧ likes(Alice, stories)
2. ∀x(likes(x, Math) ⊃ likes(x, Algebra))
3. ∀x((likes(x, Algebra) ∧ likes(x, Physics)) ⊃ goesTo(x, College))
4. ¬likes(Alice, stories) ∨ likes(Alice, Physics)
5. ¬likes(Alice, Chemistry) ∧ ¬likes(Alice, History)
We can now generate a proof that is analogous to the proof in propositional logic.
6. likes(Alice, Math) 1, simplification
7. likes(Alice, stories) 1, simplification
8. (likes(Alice, Math) ⊃ likes(Alice, Algebra)) 2, UI
9. likes(Alice, Algebra)) 6, 8, modus ponens
10. likes(Alice, Physics) 4, 7, disjunctive syllogism
11. ((likes(Alice, Algebra) ∧ likes(Alice,Physics)) 9, 10, conjunction
12. ((likes(Alice, Algebra) ∧ likes(Alice,Physics)) ⊃ goesTo(Alice,College))
3, UI
13. goesTo(Alice, College) 12, 11, modus ponens

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Forward Chaining in FOL

"x (P(x) ⊃ Q(x)) How does one guess


the value for x in UI
UI at this stage?

P(a) ⊃ Q(a)

MP
P(a) Q(a)

Forward chaining in FOL is a two step process.


The use of Implicit Quantifier Notation
collapses this two step inference into one step.

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Implicit Quantifier notation
Prefix universally quantified variables with a “?”. Replace existentially quantified
variables not in the scope of a universal quantified with a Skolem constant (named
after the mathematician Thoralf Skolem)
1. Man(?x) É Human(?x) : all men are human beings
2. Happy(suresh) Ú Rich(suresh) : Suresh is rich or happy
3. CitrusFruit(?x) É ¬Human(?x) : all citrus fruits are non-human
4. Man(sk-11) Ù Bright(sk-11)) : some men are bright

List notation
1. (if (man ?x) (human ?x))
2. (or (happy suresh) (rich suresh))
3. (if (citrusFruit ?x) (not (human ?x)))
4. (and (man sk-11) (bright sk-11))

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Unifier: Substitution
A substitution q is a set of <variable, value> pairs each
denoting the value to be substituted for the variable.
When we apply the substitution to a formula α
the new formula is denoted by αq
A unifier for two formulas α and β is a substitution that makes
the two formulas identical. We say that α unifies with β.
A unifier q unifies a set of formulas {α1, α2, …, αN} if,
α1 q = α 2 q = … = α N q = φ
We call the common reduced form φ the factor.
Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
Modified Modus Ponens (MMP)
MPP: From (a É g) and b infer gq where q is a unifier* for a and b and gq is
the formula obtained by applying the substitution q to g.

For example,
P(?x) ⊃ Q(?x)
MMP q = {<?x, a>}
P(a) Q(a)

*A substitution q is a unifier for two (or more)


formulas a and b if when applied it makes the two
formulas identical. That is, aq =bq

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


MPP: an example

Thus if
α = (Sport(tennis) ∧ Likes(Alice, tennis))
β⊃δ = (Sport(?y) ∧ Likes(?x, ?y)) ⊃ Watches(?x, ?y)

then α unifies with β


with the substitution θ = {<?x, Alice>, <?y, tennis>}
and one can infer
δθ = Watches(?x, ?y)θ = Watches(Alice, tennis)

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Modified Modus Ponens (MMP) From α
and β .
(P(?x,?y) ∧ R(?y)) ⊃ Q(?x)
Q(a) Infer α∧β
P(a,?z) ∧ R(?z) Conjunction (C)
q = {<?x, a>, <?y,?z>}
P(a,?z) R(?z)

Bypassing Conjunction
P(?x,?y) ∧ R(?y)

(P(?x,?y) ∧ R(?y)) ⊃ Q(?x)


P(a,?z) Q(a)
R(?z) q = {<?x, a>, <?y,?z>}
Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
A shorter proof with Modified Modus Ponens

1. likes(Alice, Math) ∧ likes(Alice, stories)


2. likes(?x, Math) ⊃ likes(?x, Algebra)
3. (likes(?x, Algebra) ∧ likes(?x, Physics)) ⊃ goesTo(?x, College)
4. ¬likes(Alice, stories) ∨ likes(Alice, Physics)
5. ¬likes(Alice, Chemistry) ∧ ¬likes(Alice, History)

6. likes(Alice, Math) 1, simplification


7. likes(Alice, stories) 1, simplification
8. likes(Alice, Algebra) 6, 2, MPP
9. likes(Alice, Physics) 4, 7, disjunctive syllogism
10. goesTo(Alice, College) 3, 8, 9, MPP

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


More general and more specific sentences
We say that a sentence α is more general than sentence β if there exists a non-empty
substitution λ such that αλ = β.

Everyone loves a good teacher (good-teacher ?x) É (loves ?y ?x)


is more general than
Everyone’s dad loves a good teacher (good-teacher ?x) É (loves (dad ?y) ?x)
and
Suresh loves a good a teacher (good-teacher ?x) É (loves suresh ?x)

A more general sentence entails a


less general one (generalized UI)

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


General Inferences and Specific Inferences
(if (GreaterOrEqual ?y ?z) (SmallerOrEqual ?z ?y))

Most General Unifier


q = {<?y, ?x>, <?z, 0>} (MGU)
(GreaterOrEqual ?x 0)

Most general
conclusion
(SmallerOrEqual 0 ?x)

q = {<?x, 7>, <?y, 7>, <?z, 0>}


UI

(SmallerOrEqual 0 7)

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


The Unification Algorithm
• The unification algorithm takes two or more formulas and finds the most
general unifier for the formulas
• In the list notation for formulas there are three kinds of elements
• lists
• constants
• variables
• Two constants can only unify (match) if identical
• Two lists are unified element-by-element building up the substitution as
we scan the lists.
• A variable can match another variable, or a constant, or a list not
containing the variable

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Standardizing variables apart
Consider the two formulas

(if (GreaterOrEqual 7 ?x) (SmallerOrEqual ?x 7))

(GreaterOrEqual ?x 0)

Clearly one cannot substitute ?x with both 0 and 7


Solution: Rename variables differently in each formula.

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Standardizing variables apart

Solution: Rename variables differently in each formula.

(if (GreaterOrEqual 7 ?x) (SmallerOrEqual ?x 7))

(GreaterOrEqual ?z 0)

q = {<?z, 7>, <?x, 0>}

… and one can now derive the conclusion (SmallerOrEqual 0 7)

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


The Unification Algorithm
Algorithm Unify returns the MGU for arg1 and arg2

Unify(arg1, arg2)
Return SubUnify(arg1, arg2, ( ))

Call an auxiliary function SubUnify adding a third argument.


- to build the substitution q piece by piece
- initially q is the empty list

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Algorithm SubUnify (arg1, arg2, q)

1. If arg1 and arg2 are both constants then they must be


equal (else return NIX)
2. If arg1 is a variable, call VarUnify(arg1, arg2, q)
3. If arg2 is a variable, call VarUnify(arg2, arg1, q)
/* at this point both must be lists */
4. If Length(arg1) ≠ Length(arg2) return NIX
5. For each corresponding element in arg1 and arg2
Call SubUnify recursively building up the substitution q

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Algorithm VarUnify(var, arg, q)

1. If var exists* in arg return NIX


2. If var has a value <var, pat> in q
return SubUnify(pat, arg)
3. If var = arg return q
4. Augment q ß {<var, arg>} È q and return q

*Should not be able to unify ?x with (plus ?x 1) for example

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Skolemization: existentially quantified variables
When the existential quantifier is not in the scope of any universal
quantifier, then the variable it quantifies is replaced by a Skolem constant.
For example the statements,
(exists (z) (and (Student z) (Bright z))
∃z(Student(z) ∧ Bright(z))
(exists (y) (and (Girl y) (forall (x) (if (Boy x) (Likes x y)
∃y(Girl(y) ∧ ∀x(Boy(x) ⊃ Likes(x, y))
are skolemized as,
(and (Student sk1) (Bright sk1))
(Student(sk1) ∧ Bright(sk1))
(and (Girl sk2) (if (Boy ?x) (Likes ?x sk2))
((Girl sk2) ∧ ((Boy ?x) ⊃ (Likes ?x, sk2)))
Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning
Skolemization: existential variables within universal quantifiers
When the existential quantifier is in the scope of one or more universal quantifiers
then the existentially quantified variable is a Skolem function of the corresponding
universally quantified variables.
For example the statements,
(forall (x y) (exists (z) (and ((LessThan x z) (LessThan y z))))
∀x ∀y ∃z (LessThan(x, z) ∧ LessThan(y, z))
(forall (x) (if (Boy x) (exists (y) (and (Girl y) (Likes x y))
∀x (Boy(x) ⊃ ∃y(Girl(y) ∧ Likes(x, y))
are skolemized as,
(and (LessThan ?x (sk57 ?x ?y)) (LessThan ?y (sk57 ?x ?y)))
LessThan(?x sk57(?x ?y)) ∧ LessThan(?y sk57(?x ?y))
(if (Boy ?x) ( and (Girl (sk16 ?x)) (Likes ?x (sk16 ?x))))
(Boy ?x) ⊃ (Girl(sk16 ?x) ∧ Likes (?x (sk16 ?x))

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


FOL: Rules of Substitution Recap

The following rules of substitution are also useful,


Moving a negation operator inside changes the quantifier

¬"x α ≡ $x ¬α DeMorgan’s law


¬$x α ≡ "x ¬α DeMorgan’s law
Two quantifiers of the same type are commutative

"x "y α ≡ "y "x α


$x $y α ≡ $y $x α

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


The real nature of a variable
Whether a variable is universally quantified or existentially quantified has to be decided
carefully. One must keep in mind that a negation sign influences the nature of the quantifier.
Consider the formalization of “An
immortal man does not exist” which is another way
of saying that all men are mortal.

¬∃x (Man(x) ∧ ¬Mortal(x))


What is the nature of the variable x?
On the surface it is bound by an existential quantifier so one might mistakenly skolemize
it as ¬((Man sk11) ∧ ¬(Mortal sk11)) but that only talks of a specific, albeit unspecified,
individual or individuals. The correct way to skolemize a formula is to first push the
negation sign inside. That gives us the form,
∀x¬(Man(x) ∧ ¬Mortal(x))

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


The real nature of a variable
The following sentence reads “If there exists a number that is even and odd then the
Earth is flat” and is formalized as,
∃x (Number(x) ∧ Even(x) ∧ Odd(x))) ⊃ Flat(Earth)
However if we rewrite the equivalent formulas as,

¬(∃x (Number(x) ∧ Even(x) ∧ Odd(x))) ∨ Flat(Earth)


≡ "x(¬(Number(x) ∧ Even(x) ∧ Odd(x))) ∨ Flat(Earth)
≡ "x(¬(Number(x) ∧ Even(x) ∧ Odd(x)) ∨ Flat(Earth))
≡ "x((Number(x) ∧ Even(x) ∧ Odd(x)) ⊃ Flat(Earth))

We can see that x is really universally quantified variable.

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


The real nature of a variable
The following example that asserts “A detective who has a sidekick is successful”
also illustrates the point that a quantifier in the antecedent part of an implication
statement is masquerading as the other quantifier.
∀x (Detective(x) ∧ ∃y Sidekick(y,x)) ⊃ Successful(x))
≡ ∀x (¬Detective(x) ∨ ¬∃y Sidekick(y,x) ∨ Successful(x))
≡ ∀x (¬Detective(x) ∨ ∀y ¬Sidekick(y,x) ∨ Successful(x))
≡ ∀x ∀y (¬Detective(x) ∨ ¬Sidekick(y,x) ∨ Successful(x))
≡ ∀x ∀y (¬(Detective(x) ∧ Sidekick(y,x)) ∨ Successful(x))
≡ ∀x ∀y (¬(Detective(x) ∧ Sidekick(y,x)) ⊃ Successful(x))

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Inference with a Skolem constant
In the unification algorithm the Skolem constants are simply treated as constants.
From $x Even(x)
And "x (Even(x) ⊃ ¬Odd(x))
Infer $x ¬Odd(x)
When we skolemize the premises we get,
Even (SomeEvenNumber)
Even (?x) ⊃ ¬Odd(?x)
With the substitution {?x= SomeEvenNumber } we can infer
¬Odd(SomeEvenNumber).
A constant can also be thought of as a function of arity 0.

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


Inference with a Skolem function
In the unification algorithm the Skolem functions are simply treated as functions.
From "x $y Loves(x,y) Everyone loves someone
And ∀x ∀y (Loves(x,y) ⊃ CaresFor(x,y))
If someone loves somebody then they care for them
Infer "x $y CaresFor(x,y) Everyone cares for someone
When we skolemise the premises we get,
Loves (?x (sk7 ?x))
Loves (?z ?y) ⊃ CaresFor (?z ?y)

Applying the substitution {?z=?x, ?y=(sk7 ?x)} we get the conclusion,

CaresFor (?x (sk7 ?x))

Deepak Khemani Artificial Intelligence: Knowledge Representation and Reasoning


NPTEL AI KRR 2023

Skolemization Example
Version 2.4
How to skolemize a formula?
   
∃t∀u∀x ∃y P(t, u, x) ∧ Q(x, y) ⊃ ∃y R(u, x, y)

1. Make quantified variables unique: if a variable name is reused by


multiple quantifiers then replace each duplicate usage by a new
name that does not occur anywhere in the whole formula.
Variable y is bound twice, so change the 2nd binding to z:
   
∃t∀u∀x ∃y P(t, u, x) ∧ Q(x, y) ⊃ ∃ z R(u, x, z )
2. Rewrite the formula to contain only { ∧, ∨, ¬ } connectives.
   
∃t∀u∀x ¬ ∃y P(t, u, x) ∧ Q(x, y) ∨ ∃z R(u, x, z)
3. Push negation inside.
   
∃t∀u∀x ∀ y ¬ P(t, u, x) ∧ Q(x, y) ∨ ∃z R(u, x, z)
   
∃t∀u∀x ∀y ¬ P(t, u, x) ∨ ¬ Q(x, y) ∨ ∃z R(u, x, z)
4. Push quantifiers closer to their sub-formulas.
  
∃t∀u∀x ¬P(t, u, x) ∨ ∀y ¬Q(x, y) ∨ ∃z R(u, x, z)
 
∃t∀u∀x ¬P(t, u, x) ∨ ∀y¬Q(x, y) ∨ ∃z R(u, x, z) (simplify)
5. Remove ∃-quantifiers that do not nest under ∀-quantifiers and re-
place each existential variable with a new skolem constant.
Remove ∃t and replace every t with sk1 .
 
∀u∀x ¬P( sk1 , u, x) ∨ ∀y ¬Q(x, y) ∨ ∃z R(u, x, z)
6. Remove ∃-quantifiers that nest under ∀-quantifiers. Replace each
existential variable with a new skolem function who’s arguments
are the variables of the ∀-quantifiers.
∃z is nesting under ∀u∀x. Remove ∃z and replace z with sk2(u, x) .
 
∀u∀x ¬P(sk1, u, x) ∨ ∀y ¬Q(x, y) ∨ R(u, x, sk2(u, x) )
7. Move ∀-quantifiers to the left to generate the skolem form:
 
∀u∀x ∀y ¬P(sk1, u, x) ∨ ¬Q(x, y) ∨ R(u, x, sk2(u, x))
8. Optionally, rewrite the formula to resemble its original structure.
  
∀u∀x∀y P(sk1, u, x) ∧ Q(x, y) ⊃ R(u, x, sk2(u, x))

S. Baskaran Page 1/4


NPTEL AI KRR 2023

Quantifier Free Form

9. Remove ∀-quantifiers and add ‘ ? ’ prefix to ∀-quantified variables.


 
P(sk1, ?u , ?x ) ∧ Q( ?x , ?y ) ⊃ R( ?u , ?x , sk2( ?u , ?x ))

Summary
   
FOL formula ∃t∀u∀x ∃y P(t, u, x) ∧ Q(x, y) ⊃ ∃y R(u, x, y)

 
Skolem form ∀u∀x∀y ¬P(sk1, u, x) ∨ ¬Q(x, y) ∨ R(u, x, sk2(u, x))
  
Skolem form ∀u∀x∀y P(sk1, u, x) ∧ Q(x, y) ⊃ R(u, x, sk2(u, x))

Quantifier free form ¬P(sk1, ?u, ?x) ∨ ¬Q(?x, ?y) ∨ R(?u, ?x, sk2(?u, ?x))
 
Quantifier free form P(sk1, ?u, ?x) ∧ Q(?x, ?y) ⊃ R(?u, ?x, sk2(?u, ?x))

In the rules given below, P and Q as placeholders for FOL formulas.

Rewrite connectives
         
P⊃Q ≡ ¬P ∨ Q ; P≡Q ≡ P⊃Q ∧ Q⊃P ;

Push negation closer to sub-formulas


   
¬∀x P ≡ ∃x ¬P; ¬ P∧Q ≡ ¬P ∨ ¬Q ; ¬¬P ≡ P;
   
¬∃x P ≡ ∀x ¬P; ¬ P∨Q ≡ ¬P ∧ ¬Q ;

Rearrange quantifiers

∀x∀y P ≡ ∀y∀x P; ∃x∃y P ≡ ∃y∃x P;

Push quantifiers closer to sub-formulas


Here, x is a free variable in Q and x is either absent or not free in P.
         
∃x P ≡ P; ∃x P ∧ Q ≡ P ∧ ∃x Q ; ∃x P ∨ Q ≡ P ∨ ∃x Q ;
         
∀x P ≡ P; ∀x P ∧ Q ≡ P ∧ ∀x Q ; ∀x P ∨ Q ≡ P ∨ ∀x Q ;

S. Baskaran Page 2/4


NPTEL AI KRR 2023

How to skolemize a formula? R takes only 2 parameters.


   
∃t∀u∀x ∃y P(t, u, x) ∧ Q(x, y) ⊃ ∃y R(x, y)

1. Make quantified variable names unique.


Variable y is bound twice, so change the 2nd binding to z to get:
   
∃t∀u∀x ∃y P(t, u, x) ∧ Q(x, y) ⊃ ∃ z R(x, z )
2. Rewrite the formula to contain only { ∧, ∨, ¬ } connectives.
   
∃t∀u∀x ¬ ∃y P(t, u, x) ∧ Q(x, y) ∨ ∃z R(x, z)
3. Push negation inside.
   
∃t∀u∀x ∀ y ¬ P(t, u, x) ∧ Q(x, y) ∨ ∃z R(x, z)
   
∃t∀u∀x ∀y ¬ P(t, u, x) ∨ ¬ Q(x, y) ∨ ∃z R(x, z)
4. Push quantifiers closer to their sub-formulas.
  
∃t∀x ∀u ¬P(t, u, x) ∨ ∀y ¬Q(x, y) ∨ ∃z R(x, z)
   
∃t∀x ∀u ¬P(t, u, x) ∨ ∀y¬Q(x, y) ∨ ∃z R(x, z)
  
∃t∀x ∀u ¬P(t, u, x) ∨ ∀y¬Q(x, y) ∨ ∃z R(x, z)
 
∃t∀x ∀u ¬P(t, u, x) ∨ ∀y ¬Q(x, y) ∨ ∃z R(x, z) (simplify)
5. Remove ∃-quantifiers that do not nest under ∀-quantifiers.
Remove ∃t and replace every t with sk1 .
 
∀x ∀u¬P( sk1 , u, x) ∨ ∀y¬Q(x, y) ∨ ∃z R(x, z)
6. Remove ∃-quantifiers that nest under ∀-quantifiers.
∃z is nesting under ∀x. Remove ∃z and replace z with sk2(x) .
 
∀x ∀u¬P(sk1, u, x) ∨ ∀y¬Q(x, y) ∨ R(x, sk2(x) )
7. Move ∀-quantifiers to the left to generate the skolem form:
 
∀x ∀u∀y ¬P(sk1, u, x) ∨ ¬Q(x, y) ∨ R(x, sk2(x))
8. Optionally, rewrite the formula to resemble its original structure.
  
∀x∀u∀y P(sk1, u, x) ∧ Q(x, y) ⊃ R(x, sk2(x))
9. Quantifier free form: remove ∀-quantifiers and add ‘ ? ’ prefix to variables
 
P(sk1, ?u , ?x ) ∧ Q( ?x , ?y ) ⊃ R( ?x , sk2( ?x )) from (8)
¬P(sk1, ?u , ?x ) ∨ ¬Q( ?x , ?y ) ∨ R( ?x , sk2( ?x )) from (7)

S. Baskaran Page 3/4


NPTEL AI KRR 2023

Bound Variables are Dummy Variables


Consider these equivalent definitions:
f(x) = x2 + x + 1
f(t) = t2 + t + 1

double f(double x) { return x*x + x + 1; }


double f(double t) { return t*t + t + 1; }

From high school we know that function parameters like x and t are
dummy variables, i.e., the parameter names do not determine the mean-
ing of a function.
Similarly, in FOL, the bound variables are dummy variables:
∀x[ P(x) ⊃ Q(x) ]
∀t[ P(t) ⊃ Q(t) ]
Therefore, we can rename the dummy variables as long as the original
meaning of the expression is preserved.
g(x) = m ∗ x + c; given function
g(t) = m ∗ t + c; acceptable name change: x → t
g(m) = m ∗ m + c; unacceptable name change: x → m
Renaming x to t preserves the meaning of g, it is an acceptable change,
but renaming x to m changes the meaning, so it is not acceptable.
During skolemization we can rename dummy variables as long as the
original meaning of the expression is preserved.
Also, after skolemization we can rename dummy variables, and there-
fore, the original formula and the skolemized version may carry com-
pletely different variables.
FOL formula: ∃x∀y P(x, y)
Skolem form: P(sk, ?y)
Skolem form: P(sk, ?t)
Skolem form: P(sk, ?x)

Bound variables are dummy variables.

S. Baskaran Page 4/4

You might also like