First-Order Logic
Inference in First Order Logics
What is First-Order Logic?(VIMP)
• First order Logics is a type of representative language that forms
expressions that represent statements that are either true or false.
• Another definition of First Order Logics is that it is a logical language that
allows us to represent relationships between objects and make deductions
about them using inference rules.
• It extends the Propositional logic by including quantifiers and predicates.
• In order to understand any representative language there are some terms
that we need to understand first
Terms to Understand FOL
• Basically, representative languages consists of elements like objects,
relations and functions
• Objects: Objects are what make the subject of a statement
Eg- people, houses, numbers, theories, Ronald McDonald, colors,
baseball games, wars, centuries etc
• Relations: These are properties of the objects, also known as
predicates
Eg- red, round, bogus, prime, multistoried etc
• Functions: These are relationships
Eg- father of, best friend, third inning of, one more than, beginning of
etc
EXAMPLES OF STATEMENT INVOLVING OBJECTS, RELATIONS AND
FUNCTIONS
1. “One plus two equals three.”
Object- one, two three, relation- equals, function- plus
2. “Evil King John ruled England in 1200.”
Objects: John, England, 1200; function: ruled during; predicate: evil,
king.
Models for First order Logic
• The model of First Order Logic is nothing but the domain.
• It consists of all the elements that need to be considered
• A domain is a set of all objects under consideration
• It is required for a domain to be non-empty
• The objects within that domain may or may not be related
Atomic and Complex Sentences
• Atomic Sentences: Atomic sentences are combinations of objects and predicates to state
facts. Eg-
Brother(Richard, John), Richard is the brother of John
Married(Father(Richard),Mother(John)), father of Richard is married to the mother of John
• Complex Sentences: Combination of two or more atomic sentences are called complex
sentences. Eg-
Brother(Richard, John) ∧ Brother(John, Richard)
King(Richard) ∨ King(John)
Quantifiers
• In First Order Logic, quantifiers help in making statements about all or some
elements of a domain. There are two types of quantifiers-
• The Universal quantifier (∀) – it reads as “for all”
Eg- ∀x King(x) ⇒ Person(x)
• The Existential quantifier (∃)- It reads “there exists..” or “for some..”
Eg- ∃x Crown(x)∧ OnHead(x,John)
Inference Rules for Quantifiers(VIMP)
• FOL inference rules for quantifiers allow us to make inferences about statements
involving quantifiers. These rules are based on the laws of logic and are used to
derive new statements from existing ones.
• There are four main inference rules for quantifiers:
1. The Universal Instantiation (UI) rule allows us to infer a specific instance of a
universally quantified statement. That means, we can substitute the universal
variable with any other element from the domain.
Eq- ∀x(bird(x) → has_feathers(x)), here x can be replaced with penguin,
bird(penguin) → has_feathers(penguin)
2. The Existential Instantiation (EI) rule allows us to infer the existence of a
particular instance of an existentially quantified statement. That is, it allows us to
substitute the existentially quantified variable with a single instance.
Eq- ∃x(bird(x) ∧ can_fly(x)), we can use the EI rule to infer that there exists a
specific bird, such as eagle, that satisfies both bird(eagle) and can_fly(eagle)
3. The Universal Generalization (UG) rule allows us to generalize from specific
instances of a statement to a universally quantified statement.
For example, if we know that bird(penguin) → has_feathers(penguin) and
bird(eagle) → has_feathers(eagle), we can use the UG rule to infer ∀x(bird(x) →
has_feathers(x)).
4. The Existential Generalization (EG) rule allows us to generalize from a specific
instance of a statement to an existentially quantified statement. For example, if we
know that bird(eagle) ∧ can_fly(eagle), we can use the EG rule to infer ∃x(bird(x) ∧
can_fly(x)).
Reduction of FOL to Propositional Logic(VIMP)
• The first idea is that, just as an existentially quantified sentence can be replaced by one
instantiation, a universally quantified sentence can be replaced by the set of all possible
instantiations.
For example, suppose our knowledge base contains just the sentences-
∀x King(x)∧ Greedy(x) ⇒ Evil(x)
King(John)
Greedy(John)
Brother(Richard, John).
and that the only objects are John and Richard. We apply UI to the first sentence using all
possible substitutions, {x/John} and {x/Richard}, {x/father of Richard}
D1- Richard, John, Father of Richard
• King(John)∧ Greedy(John) ⇒ Evil(John)
• King(Richard)∧ Greedy(Richard) ⇒ Evil(Richard).
• Now we have atomic sentences like Evil(John), Evil(Richard), King(John),
Greedy(John), Brother(John, Richard)
Now, all these atomic sentences can be considered as propositional sentences by
replacing the predicates with proposition symbols, for eg- John is greedy, John is
evil, Richard is evil, John is king etc.
However, if the sentences contain a function, such as father, then there can be then
infinitely many nested terms such as Father(Father(Father(John))) can be
constructed
Unification and Lifting
• The Generalized Modus Ponens Rule- For atomic sentences pi , pi ′ ,
and q, where there is a substitution θ such that
Theta, θ = {x/Richard}
𝑝1 ′ ,𝑝2 ′ ,…,𝑝𝑛 ′ ,(𝑝1 ∧ 𝑝2 ∧⋯∧ 𝑝𝑛 ⇒ 𝑞)
• SUBST(θ, pi′ )=SUBST(θ, pi), for all i,
SUBST(θ,q)
• p1 ′ is King(John) p1 is King(x)
• p2 ′ is Greedy(y) p2 is Greedy(x)
• θ is {x/John,y/John}, q is Evil(x), SUBST(θ,q) is Evil(John)
• It is easy to show that Generalized Modus Ponens is a sound inference
rule. First, we observe
• that, for any sentence p (whose variables are assumed to be
universally quantified) and for
• any substitution θ,
• p |= SUBST(θ, p)
is true by Universal Instantiation. It is true in particular for a θ that
satisfies the conditions of
the Generalized Modus Ponens rule. Thus, from p1′,..., pn′ we can infer
• SUBST(θ, p1′)∧...∧ SUBST(θ, pn′)
and from the implication p1 ∧...∧ pn ⇒ q we can infer
SUBST(θ, p1)∧...∧ SUBST(θ, pn) ⇒ SUBST(θ,q)
• Now, θ in Generalized Modus Ponens is defined so that
SUBST(θ, pi′)=SUBST(θ, pi), for all I
Generalized Modus Ponens is a lifted version of Modus Ponens—it
raises Modus Ponens Lifting from ground (variable-free) propositional
logic to first-order logic.
Unification(IMP)
• The UNIFY algorithm takes two logical atomic sentences and returns a unifier for
Unifier them (a substitution) if one exists such that-
𝑈𝑁𝐼𝐹𝑌(𝑝, 𝑞) = 𝜃 𝑤ℎ𝑒𝑟𝑒 𝑆𝑈𝐵𝑆𝑇(𝜃, 𝑝) = 𝑆𝑈𝐵𝑆𝑇(𝜃, 𝑞)
𝑈𝑁𝐼𝐹𝑌 𝐾𝑛𝑜𝑤𝑠 𝐽𝑜ℎ𝑛, 𝑥 , 𝐾𝑛𝑜𝑤𝑠 𝐽𝑜ℎ𝑛, 𝐽𝑎𝑛𝑒
𝑈𝑁𝐼𝐹𝑌 𝐾𝑛𝑜𝑤𝑠 𝐽𝑜ℎ𝑛, 𝑥 , 𝐾𝑛𝑜𝑤𝑠 𝑦, 𝐵𝑖𝑙𝑙
𝑈𝑁𝐼𝐹𝑌(𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥), 𝐾𝑛𝑜𝑤𝑠(𝑦, 𝑀𝑜𝑡ℎ𝑒𝑟(𝑦)))
𝐾𝑛𝑜𝑤𝑠 𝐽𝑜ℎ𝑛, 𝑥 Jane = x, Knows(John, x)
𝐾𝑛𝑜𝑤𝑠 𝐽𝑜ℎ𝑛, 𝑥 MGU
Following are some basic conditions for unification:
• Predicate symbol must be same, atoms or expression with different
predicate symbol can never be unified.
• Number of Arguments in both expressions must be identical.
• Unification will fail if there are two similar variables present in the same
expression.
𝑈𝑁𝐼𝐹𝑌(𝐾𝑛𝑜𝑤𝑠(𝐽𝑜ℎ𝑛, 𝑥), 𝐾𝑛𝑜𝑤𝑠(𝑥, 𝐸𝑙𝑖𝑧𝑎𝑏𝑒𝑡ℎ))
Most General Unifier (MGU)
• Now suppose, the MGU for Unify{King(x), King(John)}-
• Substitution θ = {John/x} is a unifier for these atoms and applying
this substitution, and both expressions will be identical.
• Substituting a ground term with a variable makes MGU
• X= John, King(John), King(John)
• John= x, king(x), King(x)
Storage and Retrieval
• STORE(s) is the function of storing a sentence s into the knowledge
base while,
• FETCH(q) returns all unifiers such that the query q unifies with some
sentence in the knowledge base.
• Suppose, we want to find sentences that unify with Knows(John,x),
we are fetching
• One of the ways to implement STORE and FETCH is to keep all the
facts in one long list and unify each query against every element of
the list. Such a process is inefficient, but it works.
• Another simple scheme called predicate indexing puts all the Knows
facts in one bucket and all the Brother facts in another. The buckets
can be stored in a hash table for efficient access.
Inference Engine(VIMP)
• The inference engine is the component of the intelligent system in
artificial intelligence, which applies logical rules to the knowledge
base to infer new information from known facts.
Inference engine commonly proceeds in two modes, which are:
• Forward chaining
• Backward chaining
Forward Chaining
• Forward chaining is a form of reasoning which start with atomic
sentences in the knowledge base and applies inference rules (Modus
Ponens) in the forward direction to extract more data until a goal is
reached.
• Properties of Forward chaining are:
• It is a down-up approach, as it moves from bottom to top.
• It is a process of making a conclusion based on known facts or
data, by starting from the initial state and reaches the goal
state.
• Forward-chaining approach is also called as data-driven as we reach
to the goal using available data.
• Forward -chaining approach is commonly used in the expert system,
such as CLIPS, business, and production rule systems.
• Example- "As per the law, it is a crime for an American to sell
weapons to hostile nations. Country A, an enemy of America, has
some missiles, and all the missiles were sold to it by Robert, who is an
American citizen.“ Prove that Robert is a criminal
It is a crime for an American to sell weapons to hostile nations. (Let's say p, q, and r are variables)
American (Robert) ∧ weapon(T1) ∧ sells (Robert, T1, A) ∧ hostile(A) → Criminal(Robert) ...(1)
Country A has some missiles.
Owns(A, T1) ......(2)
Missile(T1) .......(3)
All of the missiles were sold to country A by Robert.
Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
Missile(T1) Owns(A, T1) Sell(Robert, T1, A)
Missiles are weapons.
Missile(p) → Weapons (p) .......(5)
P=T1, Missile(T1)= Weapon(T1)
Enemy of America is known as hostile.
Enemy(p, America) →Hostile(p) ........(6)
• Country A is an enemy of America.
• Enemy (A, America) .........(7)
• Robert is American
• American(Robert). ..........(8)
• Forward chaining-
• we will start with the known facts and will choose the sentences which do
not have implications, such as: American(Robert), Enemy(A, America),
Owns(A, T1), and Missile(T1).
• At the second step, we will see those facts which infer from available facts
and with satisfied premises.
• Rule-(4) satisfy with the substitution {p/T1}, so Sells (Robert, T1, A) is
added, which infers from the conjunction of Rule (2) and (3).
• That is, 4th equation is-
Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
Rule-(6) is satisfied with the substitution(p/A), so Hostile(A) is added and
which infers from Rule-(7).
That is, Enemy(p, America) →Hostile(p) ........(6)
Becomes- Enemy(A, America) →Hostile(A)
Now, from (1), making substitutions {p/Robert, q/T1, r/A}
American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p) ...(1)
this proves that Robert is a criminal
Backward Chaining
• A backward chaining algorithm is a form of reasoning, which starts with the goal
and works backward, chaining through rules to find known facts that support the
goal.
• Properties of Backward Chaining are:
• It is known as a top-down approach.
• Backward-chaining is based on modus ponens inference rule.
• In backward chaining, the goal is broken into sub-goal or sub-goals to
prove the facts true.
• It is called a goal-driven approach, as a list of goals decides which rules are
selected and used.
• Backward -chaining algorithm is used in game theory, automated theorem
proving tools, inference engines, proof assistants, and various AI applications.
• Going for the same example to prove by backward chaining:
• We rewrite all the equations here
• American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p) ...(1)
• Owns(A, T1) ........(2)
• Missile(T1)
• Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
• Missile(p) → Weapons (p) .......(5)
• Enemy(p, America) →Hostile(p) ........(6)
• Enemy (A, America) .........(7)
• American(Robert). ..........(8)
• Backward Chaining Proof-
• In Backward chaining, we will start with our goal predicate, which is
Criminal(Robert), and then infer further rules.
• At the first step, we will take the goal fact. And from the goal fact, we
will infer other facts, and at last, we will prove those facts true. So our
goal fact is "Robert is Criminal," so following is the predicate of it.
Fact- Criminal(Robert)
Substituting in Eq (1)
• American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p) ...(1)
• Here, {P/Robert}, the equation becomes-
• American(Robert) ∧ weapon(q) ∧ sells (Robert, q, r) ∧ hostile(r) →
Criminal(Robert)
• As the next step, we will extract further fact Missile(q) which infer from
Weapon(q), as it satisfies Rule-(5). Weapon (q) is also true with the substitution
of a constant T1 at q.
• Missile(T1)
• Missile(p) → Weapons (p) .......(5)
• Now, eq 1 becomes-
American(Robert) ∧ weapon(T1) ∧ sells (Robert, T1, r) ∧ hostile(r) →
Criminal(Robert)
• As the next step, we can infer facts which satisfies the Rule- 4,
Missiles(p) ∧ Owns (A, p) → Sells (Robert, p, A) ......(4)
with the substitution of A in place of r, inferred from
• Enemy(p, America) →Hostile(p) ........(6)
• Enemy (A, America) .........(7)
So these two statements are proved here.
So now, eq 1 becomes-
American(Robert) ∧ weapon(T1) ∧ sells (Robert, T1, A) ∧ hostile(A) → Criminal(Robert)
Hence, proved!
Thank YOU