0% found this document useful (0 votes)
13 views33 pages

20-Inference in First-Order Logic (FOL), Unification-05!03!2024

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views33 pages

20-Inference in First-Order Logic (FOL), Unification-05!03!2024

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 33

First Order Logic

Artificial Intelligence: First Order Logic


Wittgenstein: Tractatus Logico-Philosophicus 1

1. The world is everything that is the case.

2. What is the case (a fact) is the existence of states of affairs.

3. A logical picture of facts is a thought.

4. A thought is a proposition with a sense.

5. A proposition is a truth-function of elementary propositions. (An


elementary proposition is a truth-function of itself.)

6. The general form of a proposition is the general form of a truth function, which
is: [p¯, ξ¯, N (ξ¯)]. This is the general form of a proposition.

7. Whereof one cannot speak, thereof one must be silent.

Artificial Intelligence: First Order Logic 29 February 2024


Outline 2

● Why first order logic?

● Syntax and semantics of first order logic

● Fun with sentences

● Wumpus world in first order logic

Artificial Intelligence: First Order Logic 29 February 2024


3

why?

Artificial Intelligence: First Order Logic 29 February 2024


Pros and Cons of Propositional Logic 4

● PRO: Propositional logic is declarative: pieces of syntax correspond to facts

● PRO: Propositional logic allows partial/disjunctive/negated information


(unlike most data structures and databases)

● PRO: Propositional logic is compositional:


meaning of B 1 , 1 ∧ P 1 , 2 is derived from meaning of B 1 , 1 and of P 1 , 2

● PRO: Meaning in propositional logic is context-independent


(unlike natural language, where meaning depends on context)

● CON: 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

Artificial Intelligence: First Order Logic 29 February 2024


First-Order Logic 5

● Propositional logic: world contains facts

● First-order logic: the world contains objects, relations, and functions

● Objects: people, houses, numbers, theories, Ronald McDonald, colors, baseball


games, wars, centuries . . .

● Relations: red, round, bogus, prime, multistoried . . .,


brother of, bigger than, inside, part of, has color, occurred after, owns, comes
between, . . .

● Functions: father of, best friend, third inning of, one more than, end of . . .

Artificial Intelligence: First Order Logic 29 February 2024


More Logics 6

Language Ontological Epistemological


Commitment Commitment
Propositional logic facts true/false/unknown
First-order logic facts, objects, relations true/false/unknown
Temporal logic facts, objects, relations, times true/false/unknown
Probability theory facts degree of belief
Fuzzy logic facts + degree of truth known interval value

Higher-order logic:
relations and functions operate not only on objects,
but also on relations and functions

Artificial Intelligence: First Order Logic 29 February 2024


7

syntax and semantics

Artificial Intelligence: First Order Logic 29 February 2024


Syntax of FOL: Basic Elements 8

● Constants: K i n g J o h n , 2, U C B , . . .
● Predicates: B r other, >, . . .
● Functions: Sqrt, L e ft L e g O f, . . .
● Variables: x, y, a, b, . .
● .
Connectives: ∧ ∨ ¬ =⇒ ⇔

● Quantifiers:
∀∃

Artificial Intelligence: First Order Logic 29 February 2024


Atomic Sentences 9

● Atomic sentence = predicate(term 1 , . . . ,


term n ) or term 1 = term 2

= f uncti on(term 1 , . . . , termn )


● Term or constant or variable

B rother(KingJohn, RichardTheLionheart)
● E.g., >(
L e n g t h ( L eft L e g O f (Richard)), L e n g t h ( L eft L e g O f ( K i n g J o h n ) ) )

Artificial Intelligence: First Order Logic 29 February 2024


Complex Sentences 10

● Complex sentences are made from atomic sentences using connectives

¬S, S1 ∧ S2 , S1 ∨ S2 , S1 = ⇒ S2 , S1 ⇔ S2

● For instance

Sibling (K ingJ ohn, Richard) = ⇒ Sibling(Richard, K i n g J o h n )

Artificial Intelligence: First Order Logic 29 February 2024


Truth in First-Order Logic 11

● Sentences are true with respect to a model and an interpretation

● Model contains ≥ 1 objects (domain elements) and relations among them

● Interpretation specifies referents for


– constant symbols → objects
– predicate symbols → relations
– function symbols → functional relations

● An atomic sentence predicate(term 1, . . . , termn ) is


true
iff the objects referred to by term 1 , . . . , term n
are in the relation referred to by predicate

Artificial Intelligence: First Order Logic 29 February 2024


Models for FOL: Example 12

Artificial Intelligence: First Order Logic 29 February 2024


Truth Example 13

● Object symbols
– Richard → Richard the Lionheart
– J o h n → the evil King John

● Predicat symbol
– Brother → the brotherhood relation

● Atomic sentence
– B r other(R ichard, J ohn)
true iff Richard the Lionheart and the evil King John
are in the brotherhood relation in the model

Artificial Intelligence: First Order Logic 29 February 2024


Models for FOL: Lots! 14

● Entailment in propositional logic can be computed by enumerating models

● We can enumerate the FOL models for a given KB vocabulary:

● For each number of domain elements n from 1 to ∞


For each k-ary predicate P k in the vocabulary
For each possible k-ary relation on n objects
For each constant symbol C in the
vocabulary
For each choice of referent for C from n
objects . . .

● Computing entailment by enumerating FOL


models is not easy!
Artificial Intelligence: First Order Logic 29 February 2024
Universal Quantification 15

● Syntax: ∀ ⟨variables⟩ ⟨sentence⟩

● E veryone at J H U is smart:

x At (x, J H U ) = ⇒ S mart(x )

●∀ x P is true in a model m iff P


is true with x being
each possible object in the model

● Roughly speaking, equivalent to the


conjunction of instantiations of P


At (K ing J ohn, J H U )
( Artificial Intelligence: First Order Logic 29 February 2024
=⇒
A Common Mistake to Avoid 16

● Typically ” = ⇒ ” is the main connective with ∀

● Common mistake: using ”∧” as the main connective with ∀:

∀ x At (x, J H U ) ∧ S mart(x )

means “Everyone is at J H U and everyone is smart”

● Correct
∀ ( ) =⇒ ( )
x At x, J H U

Smar t x

means “For everyone, if she is at JHU, then she is smart”


Artificial Intelligence: First Order Logic 29 February 2024
Existential Quantification 17

● Syntax: ∃ ⟨variables⟩ ⟨sentence⟩

● Someone at J H U is smart:
∃ x At (x, J H U ) ∧ S mart(x )

●∃ x P is true in a model m iff P is true with x being


some possible object in the model

● Roughly speaking, equivalent to the disjunction of instantiations of P

At (K ing J ohn, J H U ) ∧
∨ (
S mart(K ing J ohn))
At (R ichard, J H U ) ∧
∨ (
S mart(R ichard))
Artificial Intelligence: (J H
AtFirst U, Logic
Order JHU ) ∧ S mart(J H29UFebruary 2024

Another Common Mistake to Avoid 18

● Typically ”∧” is the main connective with ∃

● Common mistake: using ” = ⇒ ” as the main connective with ∃:

∃ x At (x, J H U ) = ⇒ S mart(x )

is true if there is anyone who is not at J H U

● Correct
∃ ( )∧ ( )
x At x, J H U

Smar t x

is true if there is someone who is at J H U and smart

Artificial Intelligence: First Order Logic 29 February 2024


Properties of Quantifiers 19

●∀ 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 Lov es(x, y)
“There is a person who loves everyone in the world”

●∀ y ∃ x Lov es(x, y)
“Everyone in the world is loved by at least one person”

● Quantifier duality: each can be expressed using the other

● ∀ x L i k es(x, I ceC r eam) ¬∃ x ¬L i k es(x,


I ceC r eam)

● ∃ x L i k es(x, B r occoli ) ¬∀ x ¬L i k es(x, B r occoli )

Artificial Intelligence: First Order Logic 29 February 2024


Equality 20

● term 1 = term 2 is true under a given


interpretation
if and only if term 1 and term 2 refer to the same object

● For instance
– 1 = 2 and ∀ x ×(S qr t(x ), S qr t(x )) = x are satisfiable
– 2 = 2 is true
(note: syntax does not imply anything about the semantics of 1, 2, Sqrt(x), etc.)

● Definition of (full) Sibling in terms of Parent


∀ x, y S ibling (x, y) ⇔ [¬(x = y) ∧ ∃ m, f ¬(m = f ) ∧
P arent(m, x ) ∧ P arent(f , x ) ∧ P arent(m, y) ∧ P arent(f , y)]

Artificial Intelligence: First Order Logic 29 February 2024


Fun with Sentences 22

● Brothers are siblings

∀ x, y B r other(x, y) = ⇒ S ibling (x, y)

● “Sibling” is symmetric

∀ x, y S ibling (x, y) ⇔ S ibling (y, x )

● One’s mother is one’s female parent

∀ x, y M other(x, y) ⇔ (F emale(x ) ∧ P arent(x, y))

● A first cousin is a child of a parent’s sibling

∀ x, y F i r st C o u s i n ( x , y) ⇔ ∃ p, ps Parent(p, x) ∧ Sibling(ps, p) ∧
Parent(ps, y)

Artificial Intelligence: First Order Logic 29 February 2024


Lincoln Quote 23

You can fool all the people some of the time,


and some of the people all the time,
but you cannot fool all the people all the
time.

∀ p ∃ t F ool(p, t)

∃ p ∀ t F ool(p, t)

¬ ∀ p ∀ t F ool(p, t)
Artificial Intelligence: First Order Logic 29 February 2024
26

wampus world

Artificial Intelligence: First Order Logic 29 February 2024


Knowledge Base for the Wumpus World 27

● “Perception”: at current square, three perceptions expressed as variables


– s either Smell or ¬Smell
– b either B r eeze or ¬B r eeze
– g either Glitt er or ¬Glitt er
P ercept([s, b, g], t)
● Shorthands
– ∀ b, g, t P ercept([S mell, b, g], t) = ⇒ S melt(t)
– ∀ s, b, t P ercept([s, b, G litt er], t) = ⇒ AtGold(t)
● Reflex: ∀ t AtGold(t) = ⇒ Acti on(Grab, t)

● R eflex with internal state: do we have the gold already?



t AtGold(t) ∧ ¬Holding(Gold, t) = ⇒ Acti on(Grab, t)

● Holdin g(Gold, t) cannot be observed



keeping track of change isArtificial
essential Intelligence: First Order Logic 29 February 2024
Deducing Hidden Properties 28

● P roperties of locations:

x, t At (Ag ent, x, t) ∧ S melt(t) = ⇒ S melly(x )

x, t At (Ag ent, x, t) ∧ B r eeze(t) = ⇒
B r eezy(x )

● Squares are breezy near a pit


● Causal rule—infer effect from cause
● Diagno∀stic
x, yrule—infer
P it(x ) ∧ Acause from effect
dj acent(x, y) = ⇒
∀ r eezy(y)
B
B r eezy(y) = ⇒
y these is complete—e.g.,
● Neither of the∃causal
x P it(x ) doesn’t say whether squares
rule
far away from pits can∧ Abedj acent(x,
breezy y)

● Definition for the Breezy predicate:


∀ y Breezy(y) ⇔ [∃ x P i t ( x ) ∧ Adjacent(x,
y)]
Artificial Intelligence: First Order Logic 29 February 2024
States and Fluents 29

● By acting, the agent moves through a sequence of situations s

● Fluents: aspects of the world that may change


– current position
– having an arrow
– holding the gold

● Taking actions requires updates to the fluents

Artificial Intelligence: First Order Logic 29 February 2024


Keeping Track of Change 30

● Facts hold in situations, rather than eternally


E.g., H olding(Gold, N ow) rather than just H olding(Gold)

● Situation calculus is one way to represent change in FOL:


Adds a situation argument to each non-eternal predicate E.g.,
Now in Holding(Gold, Now) denotes a situation

● Situations are connected by the Result function


s ′ = Result(a, s) is the situation that results from doing a in s

Artificial Intelligence: First Order Logic 29 February 2024


Describing Actions 31

● “Effect” axiom—describe changes due to action


∀ s At G old(s) = ⇒ H olding(Gold, R esult(G r ab,
s))
● “Frame” axiom—describe non-changes due to action
∀ s HaveArrow(s) = ⇒ HaveArrow(Result(Grab, s))

● Frame problem: find an elegant way to handle non-change


(a) representation: too many frame axioms
(b) inference: too many repeated “copy-overs” to keep track of state

● Qualification problem: true descriptions of real actions require endless caveats—


what if gold is slippery or nailed down or . . .

● Ramification problem: real actions have many secondary consequences—what


about the dust on the gold, wear and tear on gloves, . . .

Artificial Intelligence: First Order Logic 29 February 2024


Describing Actions 32

● Successor-state axioms solve the representational frame problem

● Each axiom is “about” a predicate (not an action per se):

P true afterwards ⇔ [an action made P

true

∀ a, s H olding(Gold, a, s)) ⇔
● ForRholding
esult( the gold:
[ (a = G r ab ∧ AtGold(s))
∨ (
H olding(Gold, s) ∧ a ≠
R elease)]

Artificial Intelligence: First Order Logic 29 February 2024


Making Plans 33

● Initial condition in KB:


At (Ag ent, [1, 1], S 0 )
At (Gold, [1, 2], S 0 )

● Query: A s k ( K B , ∃ s Holding(Gold, s))


i.e., in what situation will I be holding the gold?

● Answer: {s/Result(Grab, Result(Forward, S 0 ))}


i.e., go forward and then grab the gold

● This assumes that the agent is interested in plans starting at S 0 and that S 0 is the
only situation described in the KB

Artificial Intelligence: First Order Logic 29 February 2024


Making Plans: A Better Way 34

● Represent plans as action sequences [a1 , a2 , . . . , an ]

● PlanResult(p, s) is the result of executing p in s

● Then the query A s k ( K B , ∃ p Holding(Gold, PlanResult(p, S 0 )))


has the solution { p/[F orward, G r ab]}

● Defi nition of PlanResult in terms of Result:



s P la n R esult([ ], s) = s

a, p, s PlanResult([a|p], s) = PlanResult(p, Result(a, s))

● Planning systems are special-purpose reasoners designed to do this type of


inference more efficiently than a general-purpose reasoner

Artificial Intelligence: First Order Logic 29 February 2024


Summary 35

● First-order logic
– objects and relations are semantic primitives
– syntax: constants, functions, predicates, equality, quantifiers

● Increased expressive power: sufficient to define wumpus world

● Situation calculus
– conventions for describing actions and change in FOL
– can formulate planning as inference on a situation calculus KB

Artificial Intelligence: First Order Logic 29 February 2024

You might also like