First Order Logic: Dr. Shachi Natu
First Order Logic: Dr. Shachi Natu
102
A Predicate Logic Example
103
Three Ways of Representing
Class Membership
105
Another Predicate Logic Example
7. It is now 1991.
108
Translating English to FOL
Every gardener likes the sun.
x gardener(x) likes(x,Sun)
You can fool some of the people all of the time.
x t person(x) time(t) can-fool(x,t)
You can fool all of the people some of the time.
x t (person(x) time(t) can-fool(x,t))
x (person(x) t (time(t) can-fool(x,t)))
Equivalent
All purple mushrooms are poisonous.
x (mushroom(x) purple(x)) poisonous(x)
No purple mushroom is poisonous.
x purple(x) mushroom(x) poisonous(x)
x (mushroom(x) purple(x)) poisonous(x) Equivalent
There are exactly two purple mushrooms.
x y mushroom(x) purple(x) mushroom(y) purple(y) ^ (x=y) z
(mushroom(z) purple(z)) ((x=z) (y=z))
Clinton is not tall.
tall(Clinton)
X is above Y iff X is on directly on top of Y or there is a pile of one or more other
objects directly on top of one another starting with X and ending with Y.
x y above(x,y) ↔ (on(x,y) z (on(x,z) above(z,y)))
Example knowledge base
... it is a crime for an American to sell weapons to hostile nations:
American(x) Weapon(y) Sells(x,y,z) Hostile(z) Criminal(x)
Nono … has some missiles
x Owns(Nono,x) Missile(x)
Missile(x) Weapon(x)
An enemy of America counts as "hostile“:
Enemy(x,America) Hostile(x)
West, who is American …
American(West)
The country Nono, an enemy of America …
Enemy(Nono,America)
What is Unification?
• Unification is a process of making two different logical atomic expressions identical by
finding a substitution. Unification depends on the substitution process.
• It takes two literals as input and makes them identical using substitution.
• Let Ψ1 and Ψ2 be two atomic sentences and 𝜎 be a unifier such that, Ψ1𝜎 = Ψ2𝜎, then it
can be expressed as UNIFY(Ψ1, Ψ2).
• Example: Find the MGU for Unify{King(x), King(John)}
• Let Ψ1 = King(X), Ψ2 = King(John),
• Substitution θ = {John/x} is a unifier for these atoms and applying this substitution, and
both expressions will be identical.
• The UNIFY algorithm is used for unification, which takes two atomic sentences and
returns a unifier for those sentences (If any exist).
• Unification is a key component of all first-order inference algorithms.
• It returns fail if the expressions do not match with each other.
• The substitution variables are called Most General Unifier or MGU.
Conditions for Unification
• 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.
For each pair of the following atomic sentences
find the most general unifier (If exist).
• 1. Find the MGU of {p(f(a), g(Y)) and p(X, X)}
• Sol: S0 => Here, Ψ1 = p(f(a), g(Y)), and Ψ2 = p(X, X)
SUBST θ= {f(a) / X}
S1 => Ψ1 = p(f(a), g(Y)), and Ψ2 = p(f(a), f(a))
SUBST θ= {f(a) / g(y)}, Unification failed.
• 2. Find the MGU of {p(b, X, f(g(Z))) and p(Z, f(Y), f(Y))}
• Here, Ψ1 = p(b, X, f(g(Z))) , and Ψ2 = p(Z, f(Y), f(Y))
S0 => { p(b, X, f(g(Z))); p(Z, f(Y), f(Y))}
SUBST θ={b/Z}
• S1 => { p(b, X, f(g(b))); p(b, f(Y), f(Y))}
SUBST θ={f(Y) /X}
• S2 => { p(b, f(Y), f(g(b))); p(b, f(Y), f(Y))}
SUBST θ= {g(b) /Y}
• S2 => { p(b, f(g(b)), f(g(b)); p(b, f(g(b)), f(g(b))} Unified Successfully.
And Unifier = { b/Z, f(Y) /X , g(b) /Y}.
• 3. Find the MGU of {p (X, X), and p (Z, f(Z))}
• Here, Ψ1 = {p (X, X), and Ψ2 = p (Z, f(Z))
S0 => {p (X, X), p (Z, f(Z))}
SUBST θ= {Z/X}
S1 => {p (Z, Z), p (Z, f(Z))}
SUBST θ= {f(Z) / Z}, Unification Failed.
Resolution in FOL
• Resolution is a theorem proving technique that proceeds by building
refutation proofs, i.e., proofs by contradictions. It was invented by a
Mathematician John Alan Robinson in the year 1965.
• Resolution is used, if there are various statements are given, and we
need to prove a conclusion of those statements. Unification is a key
concept in proofs by resolutions. Resolution is a single inference rule
which can efficiently operate on the conjunctive normal form or
clausal form.
• Clause: Disjunction of literals (an atomic sentence) is called a clause.
It is also known as a unit clause.
Example:
A B C D J E G
Conversion to CNF
P (Q R)
• ¬ food(x) V likes(John, x)
• food(Apple)
• food(vegetables)
• ¬ eats(y, z) V killed(y) V food(z)
• eats (Anil, Peanuts)
• alive(Anil)
• ¬ eats(Anil, w) V eats(Harry, w)
• killed(g) V alive(g)
• ¬ alive(k) V ¬ killed(k)
• likes(John, Peanuts).
Using Resolution in First order logic Prove the given Sentence
6. Distribute over :
[Animal(F(x)) Loves(G(x),x)] [Loves(x,F(x)) Loves(G(x),x)]
FOL
CNF
Resolution Proof (who kill the cat?)
Forward chaining
• 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. The first inference
engine was part of the expert system. Inference engine commonly
proceeds in two modes, which are:
• Forward chaining
• Backward chaining
• Horn clause and definite clause are the forms of sentences, which enables
knowledge base to use a more restricted and efficient inference algorithm.
Logical inference algorithms use forward and backward chaining
approaches, which require KB in the form of the first-order definite clause.
• Definite clause: A clause which is a disjunction of literals with exactly one
positive literal is known as a definite clause or strict horn clause.
• Horn clause: A clause which is a disjunction of literals with at most one
positive literal is known as horn clause. Hence all the definite clauses are
horn clauses.
• Example: (¬ p V ¬ q V k). It has only one positive literal k.
• It is equivalent to p ∧ q → k.
• Forward chaining is also known as a forward deduction or forward
reasoning method when using an inference engine. 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.
• The Forward-chaining algorithm starts from known facts, triggers all
rules whose premises are satisfied, and add their conclusion to the
known facts. This process repeats until the problem is solved.
• Properties of Forward-Chaining:
• 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 knowledge base
• The law says that it is a crime for an American 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 American.
•
1. Forward chaining starts from known facts and Backward chaining starts from the goal and works backward
applies inference rule to extract more data unit it through inference rules to find the required facts that support
reaches to the goal. the goal.
3. Forward chaining is known as data-driven inference Backward chaining is known as goal-driven technique as we
technique as we reach to the goal using the start from the goal and divide into sub-goal to extract the
available data. facts.
4. Forward chaining reasoning applies a breadth-first Backward chaining reasoning applies a depth-first search
search strategy. strategy.
5. Forward chaining tests for all the available rules Backward chaining only tests for few required rules.
6. Forward chaining is suitable for the planning, Backward chaining is suitable for diagnostic, prescription, and
monitoring, control, and interpretation application. debugging application.
7. Forward chaining can generate an infinite number of Backward chaining generates a finite number of possible
possible conclusions. conclusions.
9. Forward chaining is aimed for any conclusion. Backward chaining is only aimed for the required data.