First Order Logic
First Order Logic
First-Order Logic
Chapter 8.1-8.3
First-order logic
• First-order logic (FOL) models the world in terms of
– Objects, which are things with individual identities
– Properties of objects that distinguish them from other objects
– Relations that hold among sets of objects
– Functions, which are a subset of relations where there is only one
“value” for any given “input”
• Examples:
– Objects: Students, lectures, companies, cars ...
– Relations: Brother-of, bigger-than, outside, part-of, has-color,
occurs-after, owns, visits, precedes, ...
– Properties: blue, oval, even, large, ...
– Functions: father-of, best-friend, second-half, one-more-than ...
The primary difference between propositional and first-order logic
lies in the ontological commitment made by each language—that is,
what it assumes about the nature of reality.
For example, propositional logic assumes that there are facts that
either hold or do not hold in the world. Each fact can be in one
of two states: true or false, and each model assigns true or false
to each proposition symbol.
In this figure, Richard and John are brothers. This is shown using a binary
relation called "brother". A binary relation connects two objects.
• <Richard, John>
• <John, Richard>
Another binary relation in the model is "on head", which connects the
crown to John. This shows that the crown is on King John’s head:
• <crown, John>
Unary Relations (Properties)
Some relations are only about one object. These are called
unary relations, or properties. In this model:
• The "person" property is true for Richard and John.
• The "king" property is true only for John (because Richard
is not ruling anymore).
• The "crown" property is true only for the crown.
Functions in the Model
Some relationships are better shown as functions. A function
links one object to exactly one other object.
In this model, every person has one left leg. This is a unary
function called "left-leg". It includes:
• Richard → Richard’s left leg
• John → John’s left leg
Symbols and Interpretations in
First-Order Logic
• In First-Order Logic (FOL), we use symbols to represent
the things in the world we are reasoning about. These
symbols help us talk about objects, relations, and
functions.
Three Main Types of Symbols
•Constant Symbols
These represent specific objects in the model.
Example: Richard, John
•Predicate Symbols
These represent relations between objects.
Example: Brother, OnHead, Person, King, Crown
•Function Symbols
These represent functions, which give one output for each
input object.
Example: LeftLeg
What Is an Interpretation?
An interpretation tells us what each symbol actually means
in a specific model. It connects:
• Constant symbols to real objects (like people),
• Predicate symbols to actual relationships between objects
(like being brothers),
• Function symbols to mappings (like assigning a left leg to
a person).
Example Interpretation for the
Model
Example 1:
Brother(Richard, John)
This means that Richard the Lionheart is the brother of King
John, according to the interpretation we’ve defined earlier.
•If the model says Richard and John are brothers, then
Brother(Richard, John) i true.
s
•If the model does not contain that relation, then the sentence is
false.
Quantifiers in First-Order Logic
What Are Quantifiers?
Quantifiers allow us to make general or specific statements
about a set of objects rather than listing them one by one.
There are two main types:
• Universal Quantifier (∀) – "For all..."
• Existential Quantifier (∃) – "There exists..."
A. Universal Quantification (∀)
Syntax:
∀x P(x)
Means: “For every object x, the property P(x) holds.”
Example:
“All kings are persons”
∀x King(x) ⇒ Person(x)
•This means that if x is a king, then x must be a person.
Key Points:
•Variables (e.g., x) are written in lowercase.
•A variable can be an argument of a function: e.g., LeftLeg(x)
•A ground term contains no variables.
•The quantified statement is true if it holds for every object in
the domain.
Example Interpretations:
x → Richard, x → King John, x → crown...
∀x King(x) ⇒ Person(x) is true only if the implication is true for
all these cases.
B. Existential Quantification (∃)
Syntax:
∃x P(x)
Means: “There exists at least one object x such that P(x) is
true.”
Example:
“King John has a crown on his head”
∃x Crown(x) ∧ OnHead(x, John)
•This means at least one object x satisfies both being a
crown and being on John's head.
•Existential quantification uses the logical AND (∧).
•Only one valid case is needed for the statement to be true.
C. Nested Quantifiers
• Quantifiers can be nested to form complex logical
statements.
Same-Type Nesting:
“Brothers are siblings”
∀x ∀y Brother(x, y) ⇒ Sibling(x, y)
Can be written as:
∀x, y Brother(x, y) ⇒ Sibling(x, y)
D. Connection Between ∀ and ∃
• They are interconnected through negation, following De
Morgan’s Laws
• Equivalences:
• .Expression Equivalent Form
∀x ¬P(x) ¬∃x P(x)
¬∀x P(x) ∃x ¬P(x)
∃x ¬P(x) ¬∀x P(x)
∀x P(x) ¬∃x ¬P(x)
∃x P(x) ¬∀x ¬P(x)
FOL Provides
• Variable symbols
– E.g., x, y, foo
• Connectives
– Same as in PL: not (), and (), or (), implies (→), if
and only if (biconditional )
• Quantifiers
– Universal x or (Ax)
– Existential x or (Ex)
Sentences are built from terms and atoms
Cast
– Sir Bedevere the Wise, master of (odd) logic
– King Arthur
– Villager 1, witch-hunter
– Villager 2, ex-newt
– Villager 3, one-line wonder
– All, the rest of you scoundrels, mongrels, and
nere-do-wells.
An example from Monty Python
by way of Russell & Norvig
• FIRST VILLAGER: We have found a witch. May we burn
her?
• ALL: A witch! Burn her!
• BEDEVERE: Why do you think she is a witch?
• SECOND VILLAGER: She turned me into a newt.
• B: A newt?
• V2 (after looking at himself for some time): I got better.
• ALL: Burn her anyway.
• B: Quiet! Quiet! There are ways of telling whether she is a
witch.
Monty Python cont.
• B: Tell me… what do you do with witches?
• ALL: Burn them!
• B: And what do you burn, apart from witches?
• Third Villager: …wood?
• B: So why do witches burn?
• V2 (after a beat): because they’re made of wood?
• B: Good.
• ALL: I see. Yes, of course.
Monty Python cont.
• B: So how can we tell if she is made of wood?
• V1: Make a bridge out of her.
• B: Ah… but can you not also make bridges out of stone?
• ALL: Yes, of course… um… er…
• B: Does wood sink in water?
• ALL: No, no, it floats. Throw her in the pond.
• B: Wait. Wait… tell me, what also floats on water?
• ALL: Bread? No, no no. Apples… gravy… very small
rocks…
• B: No, no, no,
Monty Python cont.
• KING ARTHUR: A duck!
• (They all turn and look at Arthur. Bedevere looks up, very
impressed.)
• B: Exactly. So… logically…
• V1 (beginning to pick up the thread): If she… weighs the
same as a duck… she’s made of wood.
• B: And therefore?
• ALL: A witch!
Monty Python Fallacy #1
• x witch(x) → burns(x)
• x wood(x) → burns(x)
• -------------------------------
• z witch(x) → wood(x)
• p→q
• r→q
• ---------
• p→r Fallacy: Affirming the conclusion
Monty Python Near-Fallacy #2
• wood(x) → can-build-bridge(x)
• -----------------------------------------
• can-build-bridge(x) → wood(x)
• B: Ah… but can you not also make bridges out of stone?
Monty Python Fallacy #3
• x wood(x) → floats(x)
• x duck-weight (x) → floats(x)
• -------------------------------
• x duck-weight(x) → wood(x)
• p→q
• r→q
• -----------
• r→p
Monty Python Fallacy #4
• z light(z) → wood(z)
• light(W)
• ------------------------------
• wood(W) ok…………..
S(x) is a P(x)
necessary (x) P(x) => S(x)
S(x)
condition of P(x)
S(x) is a S(x)
sufficient (x) P(x) <= S(x)
P(x)
condition of P(x)
S(x) is a P(x)
necessary and (x) P(x) <=> S(x)
sufficient S(x)
condition of P(x)
Higher-order logic
• FOL only allows to quantify over variables, and variables
can only range over objects.
• HOL allows us to quantify over relations
• Example: (quantify over functions)
“two functions are equal iff they produce the same value for all
arguments”
f g (f = g) (x f(x) = g(x))
• Example: (quantify over predicates)
r transitive( r ) → (xyz) r(x,y) r(y,z) → r(x,z))
• More expressive, but undecidable. (there isn’t an effective
algorithm to decide whether all sentences are valid)
– First-order logic is decidable only when it uses predicates with only one
argument.
Expressing uniqueness
• Sometimes we want to say that there is a single, unique
object that satisfies a certain condition
• “There exists a unique x such that king(x) is true”
– x king(x) y (king(y) → x=y)
– x king(x) y (king(y) xy)
– ! x king(x)
• “Every country has exactly one ruler”
– c country(c) → ! r ruler(c,r)
• Iota operator: “ x P(x)” means “the unique x such that p(x)
is true”
– “The unique ruler of Freedonia is dead”
– dead( x ruler(freedonia,x))
Notational differences
• Different symbols for and, or, not, implies, ...
– •
– p v (q ^ r)
– p + (q * r)
– etc
• Prolog
cat(X) :- furry(X), meows (X), has(X, claws)
• Lispy notations
(forall ?x (implies (and (furry ?x)
(meows ?x)
(has ?x claws))
(cat ?x)))
Logical agents for the Wumpus World