5. First-Order-Logic
5. First-Order-Logic
and
Reasoning
Deepak Khemani
Plaksha University
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)
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/
Knowledge Representation and Reasoning Deepak Khemani, Plaksha University
Relations on a Domain
A Domain D or a Universe of Discourse is the ”world” of First Order Logic
Mortal Men
Socrates is mortal
X
Aristotle Rocks
Predicates
Socrates
Unary relations
Man(Socrates)
Man(Aristotle)
Man(X)
Dog(Ted)
Binary relations
Teacher(Socrates, Aristotle)
Pet(Socrates,Ted)
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) ∈ ℑ
If α ∈ ℱ then ¬α ∈ ℱ
If α, β ∈ ℱ then (α∧β) ∈ ℱ
If α, β ∈ ℱ then (α∨β) ∈ ℱ
If α, β ∈ ℱ then (α⊃β) ∈ ℱ
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.
Knowledge Representation and Reasoning Deepak Khemani, Plaksha University
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
bound free
(Man(Socrates) Ù Mortal(Socrates))
$x (Man(x) Ù Mortal(x))
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
P(a) ⊃ Q(a)
MP
P(a) Q(a)
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
Thus if
α = (Sport(tennis) ∧ Likes(Alice, tennis))
β⊃δ = (Sport(?y) ∧ Likes(?x, ?y)) ⊃ Watches(?x, ?y)
Bypassing Conjunction
Pa,?z) ∧ R(?z)
Most general
conclusion
(SmallerOrEqual 0 ?x)
(SmallerOrEqual 0 7)
(GreaterOrEqual ?x 0)
(GreaterOrEqual ?z 0)
Unify(arg1, arg2)
Return SubUnify(arg1, arg2, ( ))
*Occurs check: Should not be able to unify ?x with (plus ?x 1), for example
Unify(α, β) à SubUnify(α, β, ( ))
Both α and β are lists of length 3 à Call SubUnify with each element
1. SubUnify(and, and, ( )) à identical constants àθ=()
2. SubUnify((Sport tennis), (Sport ?y), ( )) à both are lists of length 2 à 2 recursive calls
1. SubUnify(Sport, Sport, ( )) à identical constants àθ=()
2. SubUnify(tennis, ?y, ( )) à Call VarUnify(?y, tennis, θ) à θ = (<?y, tennis>)
3. SubUnify((Likes Alice tennis), (Likes ?x, ?y), (<?y, tennis>)) à both are lists of length 3 à 3 recursive calls
1. SubUnify(Likes, Likes, (<?y, tennis>)) à identical constants à θ = (<?y, tennis>)
2. SubUnify(Alice, ?x, (<?y, tennis>)) à Call VarUnify(?x, Alice, θ) à θ = (<?y, tennis>, <?x, Alice>)
3. SubUnify(tennis, ?y, (<?y, tennis>, <?x, Alice>))
à Call VarUnify(?y, tennis, θ) à ?y has a value <?y, tennis) ∈ θ
à SubUnify(tennis, tennis, (<?y, tennis>, <?x, Alice>)) à identical constants
Return θ = (<?y, tennis>, <?x, Alice>)
Knowledge Representation and Reasoning Deepak Khemani, Plaksha University
Unification: another example
From α = (not (CanSee ?z ?z))
and β⊃δ = (if (not (CanSee ?x (feet ?x)) (MustExercise ?x))
Can we conclude (MustExercise ?x)?
Unify(α, β) à SubUnify(α, β, ( ))
Both α and β are lists of length 2 à Call SubUnify with each element
1. SubUnify(not, not, ( )) à identical constants àθ=()
Return NIX
Knowledge Representation and Reasoning Deepak Khemani, Plaksha University
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)))
Knowledge Representation and Reasoning Deepak Khemani, Plaksha University
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))))
In the 1980’s the idea that you can capture the knowledge of a human
expert in the form of rules led to the development of Expert Systems. Rule
Based Systems or Production Systems have been used in general to
decompose a problem and address it in parts. In its most abstract form a
rule or a production is a statement of the form,
in which the computation flows from the left hand side to the right hand
side, that is Forward Chaining
Pattern à Action
where the pattern is in the given database. Thus a rule based system looks
at a part of a state, and triggers some action when a pattern is matched.
Usually the actions are to make some changes in the database describing
the state.
XCON is a forward chaining rule based system that worked from requirements towards
configurations, without backtracking. It needed two kinds of knowledge (Jackson, 1986),
• knowledge about components, for example voltage, amperage, pinning-type and number of
ports, and
• knowledge about constraints, that is, rules for forming partial configurations of equipment and
then extending them successfully.
[1]McDermott's 1980 paper on R1 won the AAAI Classic Paper Award in 1999. According to
legend, the name of R1 comes from McDermott, who supposedly said as he was writing it,
"Three years ago I wanted to be a knowledge engineer, and today I are one." -
http://en.wikipedia.org/wiki/Xcon
RK611*
CLASS: UNIBUS MODULE
TYPE: DISK DRIVE
SUPPORTER: YES
PRIORITY LEVEL: BUFFERED NPR
TRASFER RATE: 12 ...
DISTRIBUTE-MB-DEVICES-3
IF the most current active context is distributing massbus devices
& there is a single port disk drive that has not been assigned to a massbus
& there is no unassigned dual port disk drives
& the number of devices that each massbus should support is known
& there is a massbus that has been assigned at least one disk drive and that
should support additional disk drives
& the type of cable needed to connect the disk drive to the previous device on
the disk drive is known
THEN
assign the disk drive to the massbus
q = {<?x, a>}
P(a) Goal: P(a) Goal: Q(a)
q = {<?x, a>}
P(a) Goal: P(a) Goal: Q(a)
Backward Chaining
Forward Chaining
¬P(a) ¬Q(a)
q = {<?x, ?z>}
q = {<?z, Plato>}
Man(Plato) Goal: Man(?z) Goal: Mortal(?z)
Man(Aristotle)
q = {<?z, Aristotle>}
Then the given facts are, (P ∧ Q), (P ⊃ R), ((R∧ S) ⊃ T), (~Q ∨ S), (~U ∧ ~V)
Rules
Rule2
Rule1
(square ?x)
OR OR OR
Rule2
Rule1
(square ?x)
(circle C) (circle E)
outing(X) likes(friend,X)
outing(mall)
likes(friend, bhuvanShome) likes(friend,saravanaBhavan)
likes(friend, theMatrix)
outing(beach)
restaurant(pizzaHut) Facts
movie(theMatrix)
movie(sevenSamurai)
movie(artificialIIntelligence)
restaurant(saravanaBhavan)
likes(friend, beach) movie(bhuvanShome)
outing(X) likes(friend,X)
outing(mall)
likes(friend, bhuvanShome) likes(friend,saravanaBhavan)
likes(friend, theMatrix)
outing(beach)
restaurant(pizzaHut)
movie(theMatrix)
movie(sevenSamurai)
movie(artificialIIntelligence)
restaurant(saravanaBhavan)
likes(friend, beach) movie(bhuvanShome)