You are on page 1of 47

Chapter 8

First order logic


Unit-4
Pros and Cons of Propositional Logic
• Propositional logic is declarative: pieces of syntax correspond
to facts and knowlegde and inference are separate.
• Propositional logic allows for partial / disjunctive / negated
information (unlike most data structures and DB)
• Propositional logic is compositional: the meaning of B11 ^ P12 is
derived from the meaning of B11 and P12
• Meaning of propositional logic is context independent: (unlike
natural language, where the meaning depends on the
context)
• Propositional logic has very limited expressive power: (unlike
natural language)
– E.g. cannot say Pits cause Breezes in adjacent squares except by
writing one sentence for each square
Pros of First-Order Logic
• First-Order Logic assumes that the world contains:
– Objects
• E.g. pits,wumpus,people, houses, numbers, theories, colors,
football games, wars, centuries, …
– Relations among objects/can be unary relations/properties
• E.g. is breezy, is adjacent, red, round, prime, bogus, multistoried,
brother of, bigger than, inside, part of, has color, occurred after,
owns, comes between, …
– Functions-relation return one value for a given input
• E.g. father of, best friend, third quarter of, one more than,
beginning of, …

March 2, 2006 AI: Chapter 8: First-Order Logic 3


Logics in General
Language Ontological Epistemological
Commitment Commitment
(What exist in real (What agent
world) believes about
facts)
Propositional Logic Facts True / False /
Unknown
First-Order Logic Fact, objects, relations True / False /
Unknown
Temporal Logic Facts, objects, True / False /
relations, times Unknown
Probability Theory Facts Degree of belief 
[0,1]
Fuzzy Logic Degree of truth  Known interval value
[0,1]
March 2, 2006 AI: Chapter 8: First-Order Logic 4
Syntax and semantics of FOL
models for FOL
• The domain of a model is the set of objects it
contains and these objects are sometimes called
domain elements.
• The model has five objects.
• The "brother" and "on head" relations are binary
relations-that is, they relate pairs of objects.
• The model also contains unary relations, or
properties: the "person" property is true of both
Richard and John; the "king" property is true only
of John (presumably because Richard is dead at
this point); and the "crown" property is true only
of the crown.
• One function-left leg
Symbols and interpretations
• The basic syntactic elements of first-order logic
are the symbols that stand for :-
1)Objects- constant symbols eg:- Richard and John
2)Relations- predicate symbols eg:-Brother,
OnHead, Person, King, and Crown
3)functions –functions symbols eg:- LeftLeg
• Predicate and Function have arity
• Symbols have an interpretation
BNF
Components of First-Order Logic
• Term=object
– Constant symbols, e.g. Red
– Function (term) e.g. Color(Block1),leftleg(john)
• Atomic Sentence
– Predicate symbol (list of terms/objects)
• Brother (John, Richard)
-Atomic sentences can have complex terms as arguments
• Married (Mother(John), Father(John))
• Complex Sentences
– Atomic sentences + logical connectives
• Brother (Richard,John) Brother (John, Richard)
• Brother (John, Richard) Brother (John, Father(John))

March 2, 2006 AI: Chapter 8: First-Order Logic 9


Components of First-Order Logic
• Quantifiers
– Each quantifier defines a variable for the duration of the
following expression, and indicates the truth of the
expression…
• Universal quantifier “for all” 
– The expression is true for every possible value of the
variable.
– All kings are persons->
– x is a variable/lowercase, term with no variable is ground
term
– universal quantifier appears with” =>” or “<=>”
• Existential quantifier “there exists” 
– The expression is true for at least one value of the variable
March 2, 2006 AI: Chapter 8: First-Order Logic 10
Truth in First-Order Logic
• Sentences are true with respect to a model and an
interpretation
• Model contains >= 1 object (domain elements) and relations
among them
• Interpretation specifies referents for
– constant symbols -> objects
– predicate symbols -> relations
– function symbols -> functional relations

• An atomic sentence predicate( term1,…,termn) is true iff the


objects referred to by term1,…,termn are in the relation
referred to by predicate

March 2, 2006 AI: Chapter 8: First-Order Logic 11


Examples
• Everyone likes McDonalds
– x, likes(x, McDonalds)

• Someone likes McDonalds


– x, likes(x, McDonalds)

• All children like McDonalds


– x, child(x)  likes(x, McDonalds)

• Everyone likes McDonalds unless they are allergic to it


– x, likes(x, McDonalds)  allergic(x, McDonalds)
– x, allergic (x, McDonalds)  likes(x, McDonalds)

March 2, 2006 AI: Chapter 8: First-Order Logic 12


Nested quantifiers:
Properties of Quantifiers
• x y is the same as y x
• x y is the same as y x
• x y is not the same as y x
– x y Loves(x, y)
• “There is a person who loves everyone in the world”
– y x Loves(x, y)
• “Everyone in the world is loved by at least one person”

March 2, 2006 AI: Chapter 8: First-Order Logic 13


Connection between and 
duality
• The two quantifiers are actually intimately connected with each other, through
negation.

• "Everyone likes ice cream" means that “there is no one who does not like ice cream”
Examples
• Quantifier Duality
– Not everyone like McDonalds
(x, likes(x, McDonalds))
x, likes(x, McDonalds)

– No one likes McDonalds


(x, likes(x, McDonalds))
x, likes(x, McDonalds)

March 2, 2006 AI: Chapter 8: First-Order Logic 15


Fun with Sentences
• All Brothers are siblings
x,y Brother(x,y)  Sibling(x, y)

• Sibling is “symmetric”
x,y Sibling(x,y)  Sibling(y, x)

March 2, 2006 AI: Chapter 8: First-Order Logic 16


Equality
• We can use the equality symbol to make statements to
the effect that two terms refer to the same object. For
example,
• Father( John) = Henry
• says that the object referred to by Father(John) and the
object referred to by Henry are the same.
• Use equality with negation to insist two terms are not
same object
Numbers, sets, and lists
• We need a predicate NatNum that will be true of
natural numbers; we need one constant symbol,
0; and we need one function symbol, S (successor).

• The Peano axioms-define natural numbers and


additions
Using FOPL
1)Assertions and Queries in FOL
• Sentences are added to kb using ASK and TELL.
• Tell are “assertions”

Questions asked are called “queries” or goals


Such queries are solved by getting such
an x.
Procedure of Getting such an x happens
by substitution or Binding List, which is a
set of variables or terms
Kinship Domain-family relationship
• This kind of domain include facts such as:
• “ Indira Gandhi is Mother of Rajiv Gandhi”
• “ Rajiv Gandhi is father of Rahul Gandhi”
• Consider “ One’s Grandmother is the mother
of one’s parent”
• Objects in this domain are people.
• Consider two Unary Predicates: Male &
Female
Kinship Domain
• Kinship Relationships:
– Parenthood, Brotherhood, Marriage, etc… can be
represented by binary predicates: Parent, Sibling,
Brother, Sister, Child, Daughter,…… etc will use
functions for Mother & Father.
• Eg one’s mother is one’s female parent.
• " m, c Mother (c) = m  Female(m)∧Parent(m,c)
• One’s husband is one’s male spouse:
• " w, h Husband(h,w)  Male(h) ∧ Spouse(h,w)
• Male & female are disjoint categories:
" x Male(x)  ~Female(x)
Parent & Child are inverse reln:
" p, c Parent(p, c)  Child(c, p)
A grandparent is a parent of one’s parent:
" g, c Grandparent(g, c) $ p Parent(g, p) ∧ Parent (p, c)
A sibling is another child of one’s parent:
x, y sibling(x, y)  x ≠ y p Parent(p, x) ∧ Parent(p, y)
" $

Each of the above sentences can be viewed as an axiom of the kinship domain.
Axioms and theorems
• Axioms: basic facts about the domain, our “initial”
knowledge base.
• The kinship axioms are definitions
• Theorems: statements that are logically derived
from axioms
The Wumpus world

• A typical Percept sequence is:


• Percept([Stench, breeze, glitter, none, none],5)

Binary Predicate All are constants placed on a list


• The above percept sequence includes percept as well as time at
which it has occurred.
• The actions in the wumpus world can be represented by logical
terms:
• Turn(Right), Turn(left), Forward, shoot, Grab, Release etc
• To determine which is best, the agent program constructs a query
such as $ a Bestaction(a, 5)
• ASK should solve this query & return a binding
list such as { a/Grab}.
• Agent Program can return Grab as the action
to take.
• But it must TELL its KB that it is performing
Grab.
• Simple Reflex behavior can be implemented as
follows:
• " t Glitter(t)=> Bestaction(Grab, t)
• Eg Bestaction( Grab, 5) can be the conclusion
of previous percepts- ie Grab is the right thing
to do.
• Synchronic-sentences dealing with same time
• Diachronic-sentences dealing across time.
Adjacency of two rooms can be defined as:
• " x, y, a, b Adjacent([x,y],[a,b])[a,b]Î {[x+1,y],[x-1,y],[x,y+1],[x, y-
1]}
Some more examples
• At(Agent,s,t) means the agent is at square s at
time t.
• If the agent is at a square and perceives a
breeze, then the square is breezy:
• " s, t At(agent, s, t) ∧ Breeze(t)=> Breezy(s)
How agent deduces that there are pits or
wumpus?

• There are 2 types of rules that allow such


deductions:
– 1. Diagnostic rules
– 2. Causal rules
• Diagnostic Rules:
– Lead from observed effects to hidden causes.
– Eg for finding pits, the obvious diagnostic rules say
that if a square is breezy , some adj sq must
contain a pit.
– " s Breezy(s)=>$r Adjacent(r,s) ∧ Pit(r)
– If a sq is not Breezy, no adjacent sq contains a pit:
– " s ~Breezy(s) => ~ r Adjacent (r, s) ∧ Pit(r)
$
– Combining above 2:
– " s Breezy(s) $ r Adjacent (r, s) ∧ Pit (r)
Causal Rules:
• Some hidden properties of the world causes
certain percepts to be generated.
• Eg A pit causes all adjacent sq to be breezy.
• " r Pit (r) => [" s Adjacent(r,s)=> Breezy(s)]
• If all sq adj to a given sq are pitless, the sq will not be
breezy.
• " s [" r Adjacent(r,s) => ~ Pit ( r)] =>~Breezy(s)
• It can be Proved that above 2 sentences are logically
equivalent to
• " s Breezy(s)  $r Adjacent (r, s) ∧ Pit (r)
• Systems that reason with causal rules are
termed as Model based reasoning systems
• Bcoz causal rules form a model of how
environment works.
Knowlegde Engineering in FOPL
General process of kb construction-KE
KE process:
• Identify the task
• Assemble the relevant knowlegde->knowlegde acquistion
• Decide on a vocabulary(predicate,function,terms)
• Encode
• Encode a decription
• Pose queries
• Debug the kb
The electronic circuits domain-extended
example

Identify the task: There are many reasoning tasks associated with digital circuits. timing delays,
circuit area, power consumption, production cost, and so on. Each of these levels would
require additional knowledge
Assemble the relevant knowlegde
• What do vie know about digital circuits?
• For our purposes, they are composed of wires and gates.
• Signals flow along wires to the input terminalls of gates, and each gate
produces a signal on the output terminal that flows along another wire.
To determine what these signalswill be, we need to know how the gates
transform their input signals.
• There are four types of gates: AND, OR, and XOR gates have two input
terminals, and NOT gates have one.
• All gates have one output terminal.
• Circuits, like gates, have input and output terminals.
• To reason about functionality and connectivity, vlre do not need to talk
about the wires themselves, the paths the wires take, or the junctions
where two wires come together
Decide on vocabulary
• naming gates with constants: X I , X2,
• Type(Xl7 XOR), or several individual type
predicates, such as XOR(X1)
• Functions:In (1, X I ),out
Encode general knowledge of the domain
Encode the specific problem instance
Chapter-9/unit-4

INFERENCE IN FIRST ORDER LOGIC


UNIFICATION AND LIFTING
Pl vs fopl

• Inference rules for quantifiers:-


Inference in fopl
Universal instantiation
Existential instantiation

In logic, the new name is called a Skolem constant. Existential Instantiation is a


special case of a more general process called skolemization,
propositionalization
• We can infer nonquantified sentences from
quantified sentences.
• We have sketched an approach to first-order
inference via propositionalization that is
complete-that is, any entailed sentence can be
proved.
This is a major achievement, given
that the space of possible models is infinite.
First order inference rule: LIFTING
Generalized modus ponen is a lifted version of modus ponen from PL.
It is a sound inference rule.
unification
The UNIFY algorithm takes two sentences and returns a unifier for them if one exists:
Unification algorithm

You might also like