0% found this document useful (0 votes)
9 views42 pages

AI Lecture 05 FOL

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

AI Lecture 05 FOL

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

COSC2129

Semester 3, 2024

Artificial Intelligence

First-Order Logic
(Predicate Calculus)
Road Map for Today
Revision of propositional logic

First-order logic (predicate calculus)


Models
Syntax and semantics
Knowledge representation in a simple domain

Inference in first-order logic


Conversion from first-order to propositional inference
Unification and lifted inference rules
Forward and backward chaining algorithms
Fundamental Concepts of Logic

Syntax and semantics

Models and possible worlds

Logical entailment (KB ╞ α ) and logical inference

Model checking

Soundness and completeness of an inference


algorithm
Propositional Logic: Syntax
Proposition symbols P, Q, R, … are atomic sentences
T and F are atomic sentences
If P is a sentence, so is (P) and [P]
If P is a sentence, so is ¬P
If P and Q are sentences, so are
P∧Q (conjunction)
P∨Q (disjunction)
P⇒Q (implication) a.k.a. rules or if-then statement
P⇔Q (biconditional)

A literal is a atomic sentence either positive (P) or negative (¬P).


Propositional Logic: Semantics
Inferences in Propositional Logic
Equivalence

Validity
KB ╞ α if and only if (KB ⇒ α) is valid (Deduction Theorem)

Satisfiability
KB ╞ α if and only if (KB ∧¬α) is unsatisfiable (proof by contradiction)
Inferences Rules

α ⇒ β ,α
Modus Ponens:
β

α ∧β
And-Elimination:
α

Logical equivalence

Resolution:
li ∨… ∨ lk, m1 ∨ … ∨ mn
li ∨ … ∨ li-1 ∨ li+1 ∨ … ∨ lk ∨ m1 ∨ … ∨ mj-1 ∨ mj+1 ∨... ∨ mn
Inferences Algorithms

Model checking

Forward chaining and backward chaining

AND-OR graph

Resolution-based theory proving


Propositional Logic: Pros and Cons
☺ Propositional logic illustrates all the basic concepts of logic, and
comes with well-developed inference techniques.
☺ Propositional logic is declarative.
– Unlike data structures (in programs)

☺ Propositional logic allows partial information.


– Unlike data structures (in programs)

☺ Propositional logic is compositional:


– The meaning of B1,1 ∧ P1,2 is a function of the meaning of B1,1 and of P1,2

☺ Meaning in propositional logic is context-independent and


unambiguous.
– Unlike natural language
Propositional Logic: Pros and Cons (cont’d)
Propositional logic (PL) has very limited expressive power.
Consider the following two facts:
1: The wumpus is dead; 2: The wumpus is smelly.
In PL, these must be represented as different propositional symbols. There is no indication that these two assertions
are for the same object.

Consider the following two facts:


1: The wumpus is dead; 2: Elvis is dead.
In PL, these must be represented as different propositional symbols as well. There is no indication that these are
the same property of different individuals.

In the wumpus world, we have to represent “Squares adjacent to pits are breezy” for each square:
B1,1 ⇔ (P1,2 ∨ P2,1 ) Pits cause breezes in adjacent squares.
B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1) Pits cause breezes in adjacent squares.
B1,2 …
B2,2 …

PL lacks the expressive power to describe a complex world in a concise way.


First-Order Logic
First-order logic (FOL) is more expressive than PL, building on the foundation
of PL while borrowing some useful representational ideas (objects, relations,
functions) from nature language.
Objects: people, houses, numbers, colors, baseball games, wars, …
Relations: red, round, prime, brother of, bigger than, part of, comes between, …
Functions: father of, best friend, one more than, plus, …

Almost any assertion can be regarded as referring to objects and relations.


FOL can express facts about some or all of the objects in the university so that
it can represent general laws or rules.
The primary difference between PL and FOL is the assumption on the nature
of reality (ontological commitment).
PL assumes the world consists of facts that do or do not hold.
FOL assumes the world consists of objects with certain relations among them that do or do
not hold.

The possible states of knowledge for each fact (epistemological commitment):


True, False and Unknown (PL and FOL)
First-Order Logic: Models
Models are the formal structures that constitutes the possible worlds under
consideration, which link the vocabulary of logical sentences to the elements
of possible worlds.

Basic elements of a model:


Objects: the domain of a model is the set of objects it contains (non-empty).
Relations: the set of tuples of objects that are related.
-- Tuple: a collection of objects arranged in a fixed order (<object1, object2>)
-- Binary relation: relating pairs of objects
-- Unary relation (or property): property of an object
Functions: a given object must be related to exactly one object.

Another essential part of a model is the link between these elements and the
vocabulary of the logical sentences (syntax).
First-Order Logic: An Example Model
Five objects:
Richard the Lioheart (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
Crown

Relations:
Binary: “brother”, “on head”

Unary: “person”, “king”, “crown” Binary relation examples:


-- “brother”
{<Richard the Lionheart, King John>, < King John , Richard the Lionheart >}
Functions: -- “on head”
<the crown, King John>
“left leg”
Function examples:
-- “left leg”: <King John> -> King John’s leg
First-Order Logic: Syntax
Basic syntactic elements of FOL:
• Constant symbols: KingJohn, 2, ...
• Predicate symbols: Brother, >, ...
• Function symbols: Sqrt, LeftLegOf, ...
Predicate and function symbols come with arity fixing the number of arguments.

A model in FOL consists of objects, relations and functions as well as an interpretation


that maps constant symbols to objects, predicate symbols to relations on those objects,
and function symbols to functions on those objects.

One possible interpretation with respect to the previous example model (intended
interpretation):
-- Richard: Richard the Lionheart; John: the evil King John
-- Brother: “brother” relation; OnHead: “on head” relation; Person, King, and Crown:
the set of objects that are persons, kings and crowns.
-- Leftleg: “left leg” function Model checking is not feasible in FOL!
First-Order Logic: Syntax (cont’d)
Other syntactic elements of FOL:
• Variables x, y, a, b,...
• Connectives ¬, ⇒, ∧, ∨, ⇔
• Equality =
• Quantifiers ∀, ∃

Terms: a logical expression that refers to an object


Constant symbols
Variables
Complex term: a function symbol followed by a parenthesized list of terms
-- the object that is the value of the function applied to augments
-- Just a complicated kind of name, not “a subroutine call” that “returns a value”
Ground term: a (complex) term with no variables
First-Order Logic: Sentences
Two kinds of sentences: atomic sentences and complex sentences
Terms for referring to objects and predicate symbols for referring to relations can be put together to
make atomic sentences (atoms) that state facts.

An atomic sentence is formed from a predicate symbol followed by a parenthesized list of terms,
e.g., Brother(Richard, John) , stating that under the intended interpretation Richard the Lionheart is
the brother of King John.

Atomic sentences can have complex arguments, e.g., Married(Father(Richard), Mother(John)).

[Semantics]: 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 augments.

Complex sentences are made from atomic sentences using connectives, e.g.,
Brother(Richard, John) ⇒ Sibling(John, Richard) ; ¬ Brother(Father(Richard), John);
Brother(Richard, John) ∧ Brother(John, Richard)
First-Order Logic: Quantifiers
FOL allows objects. To express properties of entire sets of objects, quantifiers can be used instead
of enumerating the objects by name.

Two standard quantifiers in FOL: Universal Quantifier (∀) and Existential Quantifier (∃)

General form of Universal Quantifier:


∀ <variable> <sentence>

It means the sentence is true for every possible value of the variable (i.e., every object), e.g.,
∀x P(x) - for all x, P is true.
∀x Red(x) - all objects are red.
∀x Likes(x, AI) - everyone likes AI.

∀x Study(x, AI) ⇒ Smart(x) - everyone studying AI is smart.

[Semantics]: ∀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 specifics
a domain element to which x refers.
First-Order Logic: Quantifiers (cont’d)
General form of Existential Quantifier
∃ <variable> <sentence>

It means the sentence is true for some possible value of the variable (i.e., some object), e.g.,
∃ x P(x)
It means that there exists an x such that P(x) is true or for some x P(x) is true.

∃ x Red(x) - at least one object is red.


∃ x Likes(x, Apple) - someone likes apple.
∃ x Study(x, Laws) ∧ Smart(x) - someone studying laws is smart.

[Semantics]: ∃ 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.

Next, we show some common mistakes when using quantifiers.


Common Mistakes for Quantifiers
Typically, ⇒ is the natural connective to use with ∀, while ∧ is with ∃

Common mistakes:
using ∧ as the connective with ∀, using ⇒ as the connective with ∃

∀ x Study(x, AI) ∧ Smart(x)


- It does not mean “everyone studying AI is smart”
- It means “everyone studies AI and everyone is smart”.

∃ x Study(x, Laws) ⇒ Smart(x)


- This sentence can be true if there is someone who does not study laws
- Because if Study(x, Laws) is false, the implication is true.
Multiple Quantifiers
Multiple quantifiers are used to express more complex sentences, such as

∀x ∀y Brother(x, y) ⇒ Sibling(x, y) means “Brothers are siblings”

Consecutive quantifiers of the same type can be written as one quantifier with several variables.

∀x, y Brother(x, y) ⇒ Sibling(x, y) is same to ∀x ∀y Brother(x, y) ⇒ Sibling(x, y)

If there are mixtures, the order of quantifiers is very important.

∀x ∃y Loves(x, y)
- means “Everybody has someone he/she loves”
∃y ∀x Loves(x, y)
- means “There is someone who is loved by everyone”

Parentheses can make it clearer. ∀x ( ∃y Loves(x, y )) and ∃y (∀x Loves(x, y ))


Connection between ∀ and ∃
1. ∀x ¬P ≡ ¬∃x P
E.g., ∀x ¬Likes(x, Parsnips) is same as ¬∃x Likes(x, Parsnips)
(Everyone dislikes parsnips or no one likes parsnips)

2. ∀x P ≡ ¬∃x ¬P
E.g., ∀x Likes(x, IceCream) is same as ¬∃x ¬Likes(x, IceCream)
(Everyone likes ice cream or no one dislikes ice cream)

3. ¬∀x P ≡ ∃x ¬P
E.g., ¬∀x Likes(x, Curry) is same as ∃x ¬Likes(x, Curry)
(Not everyone likes curry or someone dislikes curry)

4. ¬∀x ¬P ≡ ∃x P
E.g., ¬∀x ¬Likes(x, Garlic) is same as ∃x Likes(x, Garlic)
(Not everyone dislikes garlic or someone likes garlic)
Equality

FOL includes one more way to make atomic sentences, i.e., using equality
symbols to signify that two terms refer to the same object.

[Semantics]: equality sentence term1 = term2 is true under an intended interpretation if


and only if term1 and term2 refer to the same object.

Equality symbols can be used to state facts about a given function, e.g., Father(John) =
Henry. It can also be used with negation to insist that two terms are not the same object.

E.g., to say that Richard has at least two brothers:

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


Knowledge Representation in FOL
A domain in knowledge representation is some part of the world which we wish to express some
knowledge.

A set of constants, predicates and functions needs to be determined to fit the domain. (We assume they
have been determined for the early and later examples of predicates/functions)

E.g., in the Wumpus domain

∀s Breezy(s) ⇒ ∃r Adjacent(r,s) ∧ Pit(r)

Predicates Breezy, Adjacent, etc. are determined for this domain.

The use of constants, predicates and functions must be consistent within a domain, e.g. don’t use
Adjacent sometime but NextTo or Adjac next time.

There is currently no general set of predicates and functions that can be used in any domain. Whether
we can find such a set remains a major research topic.
Kinship Domain
Express some knowledge in the domain of family relationships, or kinship.
Objects in this domain are people; two unary predicates; many binary predicates representing
various kinship relations; two functions
∀x Male(x) ⇔ ¬Female(x) Male and female are disjoint.
∀x, y Parent(x, y) ⇔ Child(y, x) Parent and child are inverse relations.
∀x, y Mother(x, y) ⇔ Female(x) ∧ Parent(x, y) One’s mother is one’s female parent.
∀x, y Husband(x, y) ⇔ Male(x) ∧ Spouse(x, y) One’s husband is one’s male spouse.
∀x, y GrandParent(x, y) ⇔ ∃z Parent(x, z) ∧ Parent(z, y)
A grandparent is a parent of one’s parent.
∀x, y Sibling(x, y) ⇔ ¬(x = y) ∧ ∃z Parent(z, x) ∧ Parent(z, y)
A sibling is another child of one’s parent.
∀x, y Sibling(x,y) ⇔ ¬(x=y) ∧ ∃m, f ¬(m=f) ∧ Parent(m, x) ∧ Parent(m, y) ∧ Parent(f, x) ∧ Parent(f, y)
Definition of full sibling (same father and mother)!!

The above sentences are axioms of the kinship domain, and also definitions based on primitive
predicates.
Theorems are entailed from axioms, essential to reduce computational costs of deriving sentences.
Kinship Domain (cont’d)
Axioms are not always definitions, sometimes just providing more information
about certain predicates, e.g., ∀x Person(x) ⇔ ?

FOL allows predicates to be used without completely defining them.

Axioms can be “just plain facts”:


- Parent(Mary, John)
- Parent(George, John)
- Spouse(Mary, George)
- Male(George)
- Female(Mary)
- Parent (John, Henry)
- …
Then we could answer queries like:
- Who is the husband of Mary?
- Is George Henry’s grandparent?
Fun with FOL Sentences
FOL is quite expressive, and can be fun.

There is a big dog next door


∃x ( Big(x) ∧ Dog(x) ∧ NextDoor(x) )

Jim ate a big cake


∃x ( Big(x) ∧ Cake(x) ∧ ate(Jim, x) )

Everybody loves Raymond


∀x ( Person(x) ⇒ Loves(x, Raymond) )

The lord of the rings


∃x ∀y Lord(x, y) ∧ Ring(y)

Mission Impossible
¬∃x, y Mission(x) ∧ Solution(x, y)
Inference in FOL
Can we prove “Socrates is mortal” based on the following knowledge base?
1. ∀x Man(x) ⇒ Mortal (x), 2. Man(Socrates)

We can instantiate sentence 1, then get


3. Man(Socrates) ⇒ Mortal (Scorates)

Man(x) ⇒ Mortal (x) is true for all x, so is true for any instance of x such as Socrates, John,
Richard ……
[Universal Instantiation]: we can infer any sentence obtained by substituting a ground
term for the variable. Here, Substitution is {x/Scorates}.

α ⇒ β ,α
We apply Modus Ponens on sentences 3 & 2, then we get
β
4. Mortal(Socrates)
So, we prove “Socrates is mortal”.
Universal Instantiation
Every instantiation of a universally quantified sentence is entailed by it:
∀v α
SUBST({v/g}, α)
for any variable v and ground term g

Substitution θ is written as: { <variable> / <instantiation>}.

SUBST (θ, α) denotes the result of applying the substitution θ to the


sentence α.

E.g., ∀x King(x) ∧ Greedy(x) ⇒ Evil(x) yields:


King(John) ∧ Greedy(John) ⇒ Evil(John)
King(Richard) ∧ Greedy(Richard) ⇒ Evil(Richard)
King(Father(John)) ∧ Greedy(Father(John)) ⇒ Evil(Father(John))
.
.
Existential Instantiation
For any sentence α, variable v, and constant symbol k that does not appear
elsewhere in the knowledge base:
∃v α
Subst({v/k}, α)

The variable is replaced a single new constant symbol.

E.g., ∃x Crown(x) ∧ OnHead(x, John) yields:

Crown(C1) ∧ OnHead(C1, John)

provided C1 is a new constant symbol, called a Skolem constant

Existential sentence says that there is some object satisfying a condition,


and applying the existential instantiation just gives a name to that object.
Propositionalization
Inference in FOL is an extension of inference in PL.

We can reduce FOL inference to propositional inference via propositionalization.


(Need to deal with substitutions and quantifiers)

The basic idea


-- A variable of sentences with existential quantifier can be substituted by one
instantiation.
-- A variable of sentences with universal quantifier can be substituted by the set of all
possible instantiations.

Substitution is written as: { <variable> / <instantiation> }.


E.g., ∀x Man(x) ⇒ Mortal (x), Substitutions: {x/Socrates }, {x/John }, {x/Richard }, …

∃ x Man(x) ∧ Mortal (x), Substitution: {x/M1 }


Generalized Modus Ponens
Modus Ponens can be extended (lifted) for inference in FOL – Generalized
Modus Ponens.
p '1 , p '2 ,..., p 'n , ( p1 ∧ p2 ∧ ... ∧ pn ) ⇒ q
SUBST (θ , q )

where θ is a substitution such that for all i , SUBST (θ , p ' i ) = SUBST (θ , p i )

There are n+1 premises to this rule: the n atomic sentences p'i and the one implication.

It is basically modus ponens + to find a substitution for the variables in sentences.


Generalized Modus Ponens (cont’d)
Example of Generalized Modus Ponens (GMP) - to prove “Socrates is mortal”
1. ∀x Man(x) ⇒ Mortal (x) 2. Man(Socrates)

p '1 is Man (Socrates), p1is Man (x) , q is Mortal (x)

We can find a substitution θ of x to make: SUBST (θ , p '1 ) = SUBST (θ , p1 )

SUBST (θ , Man (Socrates) ) = SUBST (θ , Man (x) )

The right substitution θ is {x/Socrates}

so, SUBST (θ , q) = SUBST (θ , Mortal (x)) = Mortal (Socrates)

Now we can apply the modus ponens rule:


Man( Socrates) Man( x) ⇒ Mortal ( x)
Mortal ( Socrates)
Therefore, “Socrates is mortal” is proved.
Unification
Finding substitutions is a key component in FOL inference. The process is called unification.

A unification algorithm takes two sentences and returns a unifier (substitution) for them if one exists.

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

Examples:
Sentence 1 Sentence 2 θ
1 p(John) p(x) {x/John}
2 p(John) p(Richard) Failure
3 p(John, x) p(y, Mary) {y/John, x/Mary}
4 p(x, x) p(John,y) {x/John, y/John}
5 p(x, x) p(John, Richard) Failure
6 p(x) p(y) {x/y}
Unification (cont’d)
As the result of a unification:
-- Some variables are replaced with constant symbols (e.g., 1, 3 of previous examples)

-- Some (two or more) variables are made identical (e.g., 4, 6 of previous examples)

When a variable would need to be bound to two distinct values, unification returns failure (e.g.,
example 5)

Once a variable is given a value via unification, that value cannot be replaced.

There could be more than one substitution being returned. E.g., θ for p(x) and p(y) is {x/y} .
However {x/John, y/John}, {x/Mary, y/Mary} … can also make p(x) = p(y).

Unification should only return the most general one, which makes the least commitment to
constants. It is called most general unifier (MGU).

The algorithm for computing MGUs can be found in the textbook.


Example of Inference in FOL
American law says that is a crime for Americans 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 Colonel West, who is an American. Prove that Colonel West is a criminal.

The approach is:

1. decide predicates and functions

2. construct a knowledge base

3. search for a proof


By forward-chaining:
-- starts with known facts and infer new ones until reaching the goal
Or by backward-chaining:
-- starts with the goal, and work backwards until hitting known facts
Example of Inference in FOL (cont’d)
Based on the story and common sense, a knowledge base can be set as:

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


... it is a crime for an American to sell weapons to hostile nations:
2. Owns(Nono,M1)

3. Missile(M1)
Nono … has some missiles,
4. ∀x Missile(x) ∧ Owns(Nono, x) ⇒ Sells(West, x, Nono)
… all of its missiles were sold to it by Colonel West
5. ∀x Missile(x) ⇒ Weapon(x)
Missiles are weapons
6. ∀x Enemy(x, America) ⇒ Hostile(x)
An enemy of America counts as “hostile”
7. American(West)
West, who is American …
8. Enemy(Nono, America)
The country Nono, an enemy of America …
Proof by Forward Chaining

AND-OR Graph

-- Start from known facts:


2. Owns(Nono, M1) 3. Missile(M1) 7. American(West) 8. Enemy(Nono, America)

-- Infer new facts by applying sentences 4, 5, 6:


Missile(M1) ∧ Owns(Nono, M1) ⇒ Sells(West, M1, Nono) 9
Missile(M1) ⇒ Weapon(M1) 10
Enemy(Nono, America) ⇒ Hostile(Nono) 11

-- Infer the conclusion by applying 1, 7, 9, 10, 11


American(West) ∧ Weapon(M1) ∧ Sells(West, M1, Nono) ∧ Hostile(Nono) ⇒ Criminal(West)
Proof by Backward Chaining
Backward chaining starts from the goal - Criminal(West)

The backward chaining process can be represented as a proof tree. The tree should
constructed depth-first, left to right (recursively).

The arc across branches mean that each branch must be proved.

A proof branch terminates at an atomic sentence which has no variables.


Proof by Backward Chaining (cont’d)
The goal is Criminal(West).

This can be established by rule 1 under substitution {x/West }


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

Now each of the following (one branch in the proof tree) must be established:
- American(West)
- Weapon(y)
- Sells(West, y, z)
- Hostile(z)

Some of these are in the knowledge base, e.g., American(West), and others requires
further backward chaining, e.g., Weapon(y) .

To establish Weapon(y), we need establish Missile(y) (rule 5)


Proof by Backward Chaining (cont’d)
Missile(y) can be established under substitution {y/M1} - already in the knowledge base

Next we will establish Sells(West, M1, z). Note y in Sells(West, y, z) is already M1.

Sells(West, M1, z) can be established under substitution {z/Nono} by Missile(M1) and


Owns(Nono,M1) -- already in the knowledge base.

Now we need to establish Hostile(Nono).

It is true because Enemy(x, America) ⇒ Hostile(x) and Enemy(Nono, America) (GMP)

Each predicate required to prove Criminal(West) are proved.

So Colonel West is a criminal.


Drawbacks of Logic
Logical consequence (for First-Order Logic) is only semi-decidable.
-- Algorithms exist that say yes to every entailed sentence, but no algorithm
exists that also says no to every non-entailed sentence.

Logical proofs can be computationally prohibitive.


-- Problems in Propositional Logic are NP-complete.

Logic does not deal well with uncertainty and default rules.
Tomorrow maybe a sunny day.
Birds fly.

Logic does not provide enough “structure” to the knowledge base creation
process.
Conclusion
Revision of propositional logic

First-order logic
Models
Syntax and semantics
Knowledge representation in a simple domain

Inference in first-order logic


Conversion from first-order to propositional inference
Unification and lifted inference rules
Forward and backward chaining algorithms

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy