You are on page 1of 53

First Order Logic (FOL)

First Order Logic


• Properties of propositional logic:

• its semantics is based on a truth relation between sentences and possible


worlds

• has sufficient expressive power to deal with partial information, using


disjunction and negation

• Compositionality:the meaning of a sentence is a function of the meaning of


its parts

• propositional logic lacks the expressive power to concisely describe an


environment with many objects
Natural language semantics
• Objects: Nouns and noun phrases
• Ex: squares, pits, wumpuses, people, houses, numbers, theories, Ronald McDonald, colors, baseball games, wars, centuries . . .

• Relations: Verbs and verb phrases


• these can be unary relations or properties such as red, round, bogus, prime, multistoried . . ., or more general
n-ary relations such as brother of, bigger than, inside,
• part of, has color, occurred after, owns, comes between, . . .

• Ex: is breezy, is adjacent to, shoots

• Functions: relations in which there is only one “value” for a given “input”
• Ex: father of, best friend, third inning of, one more than, beginning of . . .
Examples
• “Squares neighboring the wumpus are smelly.”
• Objects: wumpus, squares;

• Property: smelly;

• Relation: neighboring

• “Evil King John ruled England in 1200.”


• Objects: John, England, 1200;

• Relation: ruled;

• Properties: evil, king


Formal languages and their ontological and epistemological commitments
SYNTAX AND SEMANTICS OF FIRST-ORDER LOGIC
• Models for First order logic:
• Contains the objects

• The domain of a model is the set of objects or domain elements it contains

• The domain should be nonempty

• Relations:
• Binary

• Unary
Objects:
Richard the Lionheart, King of England from 1189 to 1199; his
younger brother, the evil King John, who ruled from 1199 to
1215;
the left legs of Richard and John;
and a crown
The brotherhood relation in this model is the set:
{< Richard the Lionheart, King John>, <King John,
Richard the Lionheart> }
Onhead relation:
<the crown, King John>

A model containing five objects, two binary the model has a unary “left leg” function that includes the
relations, three unary relations (indicated by following mappings:
labels on the objects), and one unary function, Richard the Lionheart → Richard’s left leg
left-leg. King John → John’s left leg .
Symbols
• constant symbols: which stand for objects

• predicate symbols: which stand for relations

• function symbols: which stand for functions

• Interpretation: Specifying exactly how objects, relations and functions are referred by different
symbols

• Intended interpretation:
• Richard refers to Richard the Lionheart and John refers to the evil King John.

• Brother refers to the brotherhood relation; OnHead refers to the “on head” relation that holds between the crown and King
John; Person, King, and Crown refer to the sets of objects that are persons, kings, and crowns.

• LeftLeg refers to the “left leg” function, that is, the mapping given in Equation
BNF of First order logic
Sentence → AtomicSentence | ComplexSentence
AtomicSentence → Predicate | Predicate(Term, . . .) | Term = Term
ComplexSentence → ( Sentence ) | [ Sentence ]
| ¬Sentence
| Sentence ∧ Sentence
| Sentence ∨ Sentence
| Sentence ⇒ Sentence
| Sentence ⇔ Sentence
| Quantifier Variable, . . . Sentence
Term → Function(Term, . . .)
| Constant
| Variable
Quantifier → ∀| ∃
Constant → A | X1 | John | ・ ・ ・
Variable → a | x | s | ・・・
Predicate → True | False | After | Loves | Raining | ・・・
Function → Mother | LeftLeg | ・ ・ ・
OPERATOR PRECEDENCE : ¬,=, ∧, ∨,⇒,⇔
• Term:
• A logical expression that refers to an object
• Represented by constant symbols
• Complex term :formed by a function symbol followed by a parenthesized list of terms as arguments to the function symbol
• Ex: LeftLeg(John)

• Atomic Sentences:
• Formed by a predicate symbol optionally followed by a parenthesized list of terms
• Brother (Richard , John)

• Can also have complex terms as arguments


• Married(Father (Richard),Mother (John))

• An atomic sentence is true in a given model if the relation referred to by the predicate symbol holds among the objects referred to by
the arguments.
• Complex Sentences:
• Use logical connectives to construct complex sentences

• The following four sentences are true in the given model under intended interpretation

¬Brother (LeftLeg(Richard), John)

Brother (Richard , John) ∧ Brother (John,Richard)

King(Richard ) ∨ King(John)

¬King(Richard) ⇒ King(John)
Quantifiers
• Used to express the properties of entire collection of objects, instead of
enumerating the objects by name

• Universal quantification (∀):


• “All kings are persons”

• ∀ x King(x) ⇒ Person(x)

• “For all x, if x is a king, then x is a person.”

• The symbol x is called a variable

• A term with no variables is called a ground term.

• ∀x P is true in a given model if P is true in all possible extended interpretations constructed from the
interpretation given in the model, where each extended interpretation specifies a domain element to
which x refers
• The objects in the intended interpretation are:
• Richard the Lionheart, King John, Richard’s left leg, Jon’s left leg, the crown

• One can extend the interpretation in five ways:


x → Richard the Lionheart,
x → King John,
x → Richard’s left leg,
x → John’s left leg,

x → the crown.

• The universally quantified sentence ∀ x King(x) ⇒ Person(x) is true in the original model if
the sentence King(x) ⇒ Person(x) is true under each of the five extended interpretations.
Extended interpretation
Richard the Lionheart is a king ⇒ Richard the Lionheart is a person.

King John is a king ⇒ King John is a person.

Richard’s left leg is a king ⇒ Richard’s left leg is a person.

John’s left leg is a king ⇒ John’s left leg is a person.

The crown is a king ⇒ the crown is a person

• Common mistake: Using conjunction instead of implication


• ∀ x King(x) ∧ Person(x)
Existential quantification (∃)
• make a statement about some object in the universe without naming it

• For example:
• King John has a crown on his head

• ∃ x Crown(x) ∧ OnHead(x, John)

• ∃x is pronounced “There exists an x such that . . .” or “For some x . . .”.

• the sentence ∃x P says that P is true for at least one object x.

• ∃x P is true in a given model if P is true in at least one extended interpretation that assigns x to a domain
element
Richard the Lionheart is a crown ∧ Richard the Lionheart is on John’s head;
King John is a crown ∧ King John is on John’s head;
Richard’s left leg is a crown ∧ Richard’s left leg is on John’s head;
John’s left leg is a crown ∧ John’s left leg is on John’s head;
The crown is a crown ∧ the crown is on John’s head.
Nested quantifiers
• “Brothers are siblings”
• ∀ x ∀ y Brother (x, y) ⇒ Sibling(x, y)

• “siblinghood is a symmetric relationship”


• ∀ x, y Sibling(x, y) ⇔ Sibling(y, x)

• “Everybody loves somebody”


• ∀ x ∃ y Loves(x, y)

• “There is someone who is loved by everyone”


• ∃ y ∀ x Loves(x, y)

• ∀ x (Crown(x) ∨ (∃ x Brother (Richard, x)))


Connections between ∀ and ∃

∀ 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


• Equality
• To signify that two terms refers to the same object

• Father (John)=Henry

• The equality symbol can be used to state facts about a given function

• For example, “Richard has at least two brothers”

• ∃ x, y Brother (x,Richard ) ∧ Brother (y,Richard ) ∧¬(x=y)

• The sentence ∃ x, y Brother (x,Richard ) ∧ Brother (y,Richard ) does not have the intended
meaning.
• “Richard has two brothers, John and Geoffrey”

• Brother (John,Richard ) ∧ Brother (Geoffrey,Richard) ∧ John =


Geoffrey ∧ ∀x Brother (x,Richard ) ⇒ (x=John ∨ x=Geoffrey)
Assertions and queries
• TELL: Used to add the sentences to the knowledge base (KB)
• Such sentences are called assertions
• we can assert that John is a king, Richard is a person, and all kings are persons:
• TELL(KB, King(John)) .
• TELL(KB, Person(Richard)) .
• TELL(KB, ∀ x King(x) ⇒ Person(x))
• ASK: To ask the questions of the Knowledge base
• ASK(KB, King(John))
• ASK(KB, ∃ x Person(x))-return True which is not helpful
• ASKVARS(): which yields a stream of values
• ASKVARS(KB, Person(x)): returns two answers {x/John},{x/Richard}
• This is called a substitution or binding list
• ASKVARS() is usually reserved for knowledge bases consisting of Horn clauses
• because in such knowledge bases every way of making the query true will bind the variables to specific values
Kinship domain
• Objects: People

• Unary predicates: Male, Female

• Kinship relations: Parent, Sibling, Brother , Sister , Child , Daughter, Son, Spouse,
Wife, Husband, Grandparent , Grandchild , Cousin, Aunt, and Uncle

• Functions: Mother, Father


• one’s mother is one’s female parent
• ∀ m, c Mother (c)=m ⇔ Female(m) ∧ Parent(m, c)
Each of these sentences can be viewed as
• One’s husband is one’s male spouse an axiom of the kinship domain
• ∀ w, h Husband(h,w) ⇔ Male(h) ∧ Spouse(h,w) .
• Male and female are disjoint categories
• ∀ x Male(x) ⇔ ¬Female(x) Theorems— They are entailed by the axioms
Consider the assertion :
• Parent and child are inverse relations
“siblinghood is symmetric”
• ∀ p, c Parent(p, c) ⇔ Child (c, p) ∀ x, y Sibling(x, y) ⇔ Sibling(y, x)
• A grandparent is a parent of one’s parent Is this an axiom or a theorem?
• ∀ 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)
The wumpus world
• The percept sentence can be:
• Percept ([Stench, Breeze, Glitter , None, None], 5)

• Actions in wumpus world can be represented by:


• Turn(Right ), Turn(Left ), Forward , Shoot , Grab, Climb

• Adjacency of any two squares can be defined as


• ∀ x, y, a, b Adjacent ([x, y], [a, b]) ⇔ (x = a ∧ (y = b − 1 ∨ y = b + 1)) ∨ (y = b ∧ (x = a − 1 ∨ x = a + 1))

• At(Agent, s, t) to mean that the agent is at square s at time t.

• objects can only be at one location at a time:

• ∀ x, s1, s2, t At(x, s1, t) ∧ At(x, s2, t) ⇒ s1 = s2 .


• ∀ s Breezy(s) ⇔ ∃r Adjacent (r, s) ∧ Pit(r)

• ∀ t HaveArrow(t + 1) ⇔ (HaveArrow(t) ∧¬Action(Shoot, t))


• “The law says that it is a crime for an American to sell weapons to
hostile nations. The country Nono and the enemy of America, has
some missiles, and all of its missiles were sold to it by Colonel West,
who is an American”
Terms:

• American(x)- x is an American

• Weapon(y)- y is a weapon

• Hostile(z)- z is a hostile nation

• Sells(x,y,z)- x sells y to z

• Criminal(x)-x is a criminal

• Missile(x)-x is a missile

• Owns(x,y)-x owns y

• Enemy(x,y)- x is an enemy of y
• American(x) Weapon(y)  Hostile(z)  Sells(x,y,z) Criminal(x)

• Nano owns some missiles


• Owns(Nano,M1)
• Missile(M1)

• A missile is a weapon
• Missile(x) Weapon(x)

• All missiles sold by West


• x Missiles(x) Owns(Nano,x)  Sells(West,x,Nano)
• Enemies of America are hostile
• x Enemy(America,x) Hostile(x)

• West is an American
• American(West)

• Nano is enemy of America


• Enemy(Nano, America)
Translate the following sentences into FOL

• Everyone loves everyone except himself

• Every student except George smiles

• Elder Gods do not like Hello Kitty

• Sister-in-law(Spouse sister)

• Blue databases are better than other databases

• Every child who has a Chinpokomon card is cool


• Jack owns a dog. Every dog owner is an animal lover. No animal lover kills an animal. Either Jack or
curiosity killed the cat, who is named Tuna.
Inference rules for quantifiers
• Universal Instantiation(UI):
• We can infer any sentence by substituting the ground term
• Let SUBST(θ,α) denote the result of applying the substitution θ to the sentence α.
• The rule is written as:

• For any variable v and ground term g


∀ x King(x) ∧ Greedy(x) ⇒ Evil(x)

King(John) ∧ Greedy(John) ⇒ Evil(John)

King(Richard ) ∧ Greedy(Richard) ⇒ Evil(Richard)

King(Father (John)) ∧ Greedy(Father (John)) ⇒ Evil(Father (John)) .

...
• Existential Instantiation,

• the variable is replaced by a single new constant symbol.

• For any sentence α, variable v, and constant symbol k that does not appear
elsewhere in the knowledge base

∃ x Crown(x) ∧ OnHead(x, John)

Crown(C1) ∧ OnHead(C1, John), as long as C1 does not appear elsewhere in the knowledge base.

Skolem constant and skolemization

Inferentially equivalent
∀ x King(x) ∧ Greedy(x) ⇒ Evil(x)

King(John)

Greedy(John)

∀ y Greedy(y)
Generalized Modus Ponens
• For atomic sentences pi, pi’, and q, where there is a substitution θ such that
SUBST(θ, pi)= SUBST(θ, pi), for all i,

• There are n+1 premises to this rule: the n atomic sentences pi and the one implication. The
conclusion is the result of applying the substitution θ to the consequent q.
Inference
Unification
• Generalized Modus Ponens is a lifted version of Modus Ponens—it raises Modus
Ponens from ground (variable-free) propositional logic to first-order logic.

• Lifted inference rules require finding substitutions that make different logical
expressions look identical. This process is called unification and is a key
component of all first-order inference algorithms.

• The UNIFY algorithm takes two sentences and returns a unifier for them if one
exists:

UNIFY(p, q)=θ where SUBST(θ, p)= SUBST(θ, q)


UNIFY(Knows(John, x), Knows(John, Jane)) = {x/Jane}

UNIFY(Knows(John, x), Knows(y, Bill )) = {x/Bill, y/John}

UNIFY(Knows(John, x), Knows(y,Mother (y))) = {y/John, x/Mother (John)}

UNIFY(Knows(John, x), Knows(x, Elizabeth)) = fail

standardizing apart: Renaming variables to avoid name clashes


• There could be more than one unifier

• UNIFY(Knows(John, x), Knows(y, z)) could return {y/John, x/z} or {y/John, x/John, z/John}

• The first unifier gives Knows(John, z) as the result of unification, whereas the second gives
Knows(John, John).

• The second result could be obtained from the first by an additional substitution {z/John}

• the first unifier is more general than the second, because it places fewer restrictions on the values
of the variables.

• for every unifiable pair of expressions, there is a single most general unifier (or MGU) that is
unique up to renaming and substitution of variables
Subsumption Lattice
• The interesting properties of subsumption lattice are:

• The child of any node in the lattice is obtained from its parent by a single
substitution

• The “highest” common descendant of any two nodes is the result of applying
their most general unifier

• The portion of the lattice above any ground fact can be constructed
systematically
• Employs(IBM ,Richard) Does IBM employ Richard?
• Employs(x,Richard ) Who employs Richard?
• Employs(IBM , y) Whom does IBM employ?
• Employs(x, y) Who employs whom?

Subsumption lattice with the repeated


Subsumption lattice for the given
constsnt
example
First –order definite clauses
• A definite clause either is atomic or is an implication whose antecedent is a
conjunction of positive literals and whose consequent is a single positive literal.

• The following are first-order definite clauses:

King(x) ∧ Greedy(x) ⇒ Evil(x) .

King(John) .

Greedy(y)

• Unlike propositional literals, first-order literals can include variables, in which


case those variables are assumed to be universally quantified.
• The law says that it is a crime for an American to sell weapons to hostile nations.
The country Nono, an enemy of America, has some missiles, and all of its missiles
were sold to it by ColonelWest, who is American.

• Represent these facts as first-order definite clauses:

• “. . . it is a crime for an American to sell weapons to hostile nations”:

American(x) ∧Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(z) ⇒ Criminal (x)


• “Nono . . . has some missiles.”

∃ x Owns(Nono, x)∧Missile(x)

Applying Existential instantiation, this sentence is transformed to two definite clauses.


Introduce a new variable M1

Owns(Nono,M1)

Missile(M1)

“All of its missiles were sold to it by Colonel West”:

Missile(x) ∧ Owns(Nono, x) ⇒ Sells(West, x, Nono)


• missiles are weapons

Missile(x) ⇒ Weapon(x)

• an enemy of America counts as “hostile”:

Enemy(x,America) ⇒ Hostile(x)

• “West, who is American . . .”:

American(West)

• “The country Nono, an enemy of America . . .”:

Enemy(Nono,America)
Simple forward Chaining Algorithm
A backward-chaining algorithm
Resolution
• Conjunctive normal form for first-order logic

• first-order resolution requires that sentences be in conjunctive normal form (CNF)—that is, a
conjunction of clauses, where each clause is a disjunction of literals

• Literals can contain variables, which are assumed to be universally quantified

• For example, the sentence

∀ x American(x) ∧Weapon(y) ∧ Sells(x, y, z) ∧ Hostile(z) ⇒ Criminal (x)

becomes, in CNF,

¬American(x) ∨ ¬Weapon(y) ∨ ¬Sells(x, y, z) ∨ ¬Hostile(z) ∨ Criminal (x)


• Every sentence of first-order logic can be converted into an inferentially equivalent CNF sentence
Procedure to eliminate existential quantifiers
• “Everyone who loves all animals is loved by someone”

∀ x [∀ y Animal(y) ⇒ Loves(x, y)] ⇒ [∃ y Loves(y, x)]

• Eliminate implications:

∀ x [¬∀ y ¬Animal(y) ∨ Loves(x, y)] ∨ [∃ y Loves(y, x)]

• Move ¬ inwards:

In addition to the usual rules for negated connectives, we need rules for negated quantifiers.
Thus, we have

¬∀x p becomes ∃ x ¬p

¬∃x p becomes ∀ x ¬p
• The sentence goes through the following transformations:

∀ x [∃ y ¬(¬Animal(y) ∨ Loves(x, y))] ∨ [∃ y Loves(y, x)] .

∀ x [∃ y ¬¬Animal(y) ∧ ¬Loves(x, y)] ∨ [∃ y Loves(y, x)] .

∀ x [∃ y Animal (y) ∧¬Loves(x, y)] ∨ [∃ y Loves(y, x)]

• Standardize variables: For sentences like (∃xP(x))∨(∃xQ(x)) which use the same variable name
twice, change the name of one of the variables. This avoids confusion later when we drop the
quantifiers. Thus, we have

∀ x [∃ y Animal (y) ∧¬Loves(x, y)] ∨ [∃ z Loves(z, x)]

You might also like