ARTIFICAL INTELLIGENCE
(R18 III(II Sem))
Department of computer science and
engineering (AI/ML)
Session 22
by
Asst.Prof.M.Gokilavani
VITS
4/25/2023 Dpaertment of CSE ( AL & ML) 1
TEXTBOOK:
• Artificial Intelligence A modern Approach, Third
Edition, Stuart Russell and Peter Norvig, Pearson
Education.
REFERENCES:
• Artificial Intelligence, 3rd Edn, E. Rich and K.Knight
(TMH).
• Artificial Intelligence, 3rd Edn, Patrick Henny
Winston, Pearson Education.
• Artificial Intelligence, Shivani Goel, Pearson
Education.
• Artificial Intelligence and Expert Systems- Patterson,
Pearson Education.
4/25/2023 Dpaertment of CSE ( AL & ML) 2
Topics covered in session 22
4/25/2023 Dpaertment of CSE ( AL & ML) 3
Logic and Knowledge Representation
First-Order Logic: Representation, Syntax and
Semantics of First-Order Logic, Using First-Order Logic,
Knowledge Engineering in First-Order Logic.
Inference in First-Order Logic: Propositional vs. First-
Order Inference, Unification and Lifting, Forward
Chaining, Backward Chaining, Resolution.
Knowledge Representation: Ontological Engineering,
Categories and Objects, Events. Mental Events and
Mental Objects, Reasoning Systems for Categories,
Reasoning with Default Information.
Propositional vs. First-Order Inference
Propositional logic
• Propositional logic(PL) is a statement made by
propositions.
• It is a simple form of logic.
• Propositions are declarative statements which are
either true or false.
• PL is a technique often used in logical and
mathematical form.
• When we study PL, we usually start with formal
natural language arguments, but they can also be
expressed mathematically.
4/25/2023 4
Dpaertment of CSE ( AL & ML)
• Propositional logic is based on formal logic, deductive reason
and Boolean logic.
• We use symbolic variables to represent the logic. Often true
and false can be symbolized by 1 and 0.
• Propositional logic also consists of an object, relations or
function, and logical connectives.
4/25/2023 5
Dpaertment of CSE ( AL & ML)
First order logic
4/25/2023 6
Dpaertment of CSE ( AL & ML)
• First-order logic(FOL), Predicate logic or First-order
predicate logic is an extension to propositional logic.
• First-order logic expresses information about objects and
expresses relationships between those objects in a more
functional way in comparison to propositional logic.
• First-order logic is more concise than propositional logic.
• In First-order logic, the statements are divided into two
parts: the subject and the predicate.
• The predicate is not a proposition.
• It is neither true nor false.
• Predicates use variables and objects like people, colors,
numbers, letters or ideas.
• They can also represent relationships and functions
• Both syntax and semantics are important to first-
order logic.
• Symbols are the basic syntax of FOL and can be
written in shorthand.
• Syntax is the structure of the logical statements.
Semantics gives meaning to the statements.
Examples:
• Every man has a heart = ∀x man(x) → have (x,
heart).
• Some men are mean = ∃x: man(x) ∧ mean(x).
4/25/2023 7
Dpaertment of CSE ( AL & ML)
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).
4/25/2023 8
Dpaertment of CSE ( AL & ML)
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.
4/25/2023 9
Dpaertment of CSE ( AL & ML)
Example: Let's say there are two different
expressions, P(x, y), and P(a, f(z)).
In this example, we need to make both above
statements identical to each other.
For this, we will perform the substitution.
P(x, y)......... (i)
P(a, f(z))......... (ii)
• Substitute x with a, and y with f(z) in the first
expression, and it will be represented as a/x and
f(z)/y.
• With both the substitutions, the first expression
will be identical to the second expression and the
substitution set will be: [a/x, f(z)/y].
4/25/2023 10
Dpaertment of CSE ( AL & ML)
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.
4/25/2023 11
Dpaertment of CSE ( AL & ML)
Algorithm
4/25/2023 12
Dpaertment of CSE ( AL & ML)
Implementation of the Algorithm
• Step 1: Begin by making the substitute set empty.
Step 2: Unify atomic sentences in a recursive manner:
a. Check for expressions that are identical.
b. If one expression is a variable vΨi, and the other
is a term ti which does not contain variable vi, then:
i. Substitute ti / vi in the existing substitutions
ii. Add ti / vi to the substitution set list.
Iii. If both the expressions are functions, then
function name must be similar, and the number of
arguments must be the same in both the expression.
c. Find the most general unifier for each pair of the
following atomic statements (If exist).
4/25/2023 13
Dpaertment of CSE ( AL & ML)
Example 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.
Unification is not possible for these expressions.
4/25/2023 14
Dpaertment of CSE ( AL & ML)
Example 2
Find the MGU of {p(b, X, f(g(Z))) and p(Z, f(Y), f(Y))}
Sol: Here, Ψ1 = p(b, X, f(g(Z)))
Ψ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}.
4/25/2023 15
Dpaertment of CSE ( AL & ML)
Example 3
Find the MGU of {p (X, X), and p (Z, f(Z))}
Sol: Here, Ψ1 = {p (X, X)
Ψ2 = p (Z, f(Z))
S0 => {p (X, X), p (Z, f(Z))}
SUBST θ= {X/Z}
S1 => {p (Z, Z), p (Z, f(Z))}
SUBST θ= {f(Z) / Z},
Unification Failed.
Therefore, unification is not possible for
these expressions.
4/25/2023 16
Dpaertment of CSE ( AL & ML)
Example 4
UNIFY(knows(Richard, x), knows(Richard, John))
Sol: Here, Ψ1 = knows(Richard, x)
Ψ2 = knows(Richard, John)
S0 => { knows(Richard, x); knows(Richard, John)}
S SUBST θ= {John/x}
S1 => { knows(Richard, John); knows(Richard,
John)},
Successfully Unified.
Unifier: {John/x}.
4/25/2023 17
Dpaertment of CSE ( AL & ML)
Topics to be covered in next session 23
• Resolution in First Order Logic (FOL)
Thank you!!!
4/25/2023 Dpaertment of CSE ( AL & ML) 18

AI_session 22 inference and unification.pptx

  • 1.
    ARTIFICAL INTELLIGENCE (R18 III(IISem)) Department of computer science and engineering (AI/ML) Session 22 by Asst.Prof.M.Gokilavani VITS 4/25/2023 Dpaertment of CSE ( AL & ML) 1
  • 2.
    TEXTBOOK: • Artificial IntelligenceA modern Approach, Third Edition, Stuart Russell and Peter Norvig, Pearson Education. REFERENCES: • Artificial Intelligence, 3rd Edn, E. Rich and K.Knight (TMH). • Artificial Intelligence, 3rd Edn, Patrick Henny Winston, Pearson Education. • Artificial Intelligence, Shivani Goel, Pearson Education. • Artificial Intelligence and Expert Systems- Patterson, Pearson Education. 4/25/2023 Dpaertment of CSE ( AL & ML) 2
  • 3.
    Topics covered insession 22 4/25/2023 Dpaertment of CSE ( AL & ML) 3 Logic and Knowledge Representation First-Order Logic: Representation, Syntax and Semantics of First-Order Logic, Using First-Order Logic, Knowledge Engineering in First-Order Logic. Inference in First-Order Logic: Propositional vs. First- Order Inference, Unification and Lifting, Forward Chaining, Backward Chaining, Resolution. Knowledge Representation: Ontological Engineering, Categories and Objects, Events. Mental Events and Mental Objects, Reasoning Systems for Categories, Reasoning with Default Information.
  • 4.
    Propositional vs. First-OrderInference Propositional logic • Propositional logic(PL) is a statement made by propositions. • It is a simple form of logic. • Propositions are declarative statements which are either true or false. • PL is a technique often used in logical and mathematical form. • When we study PL, we usually start with formal natural language arguments, but they can also be expressed mathematically. 4/25/2023 4 Dpaertment of CSE ( AL & ML)
  • 5.
    • Propositional logicis based on formal logic, deductive reason and Boolean logic. • We use symbolic variables to represent the logic. Often true and false can be symbolized by 1 and 0. • Propositional logic also consists of an object, relations or function, and logical connectives. 4/25/2023 5 Dpaertment of CSE ( AL & ML)
  • 6.
    First order logic 4/25/20236 Dpaertment of CSE ( AL & ML) • First-order logic(FOL), Predicate logic or First-order predicate logic is an extension to propositional logic. • First-order logic expresses information about objects and expresses relationships between those objects in a more functional way in comparison to propositional logic. • First-order logic is more concise than propositional logic. • In First-order logic, the statements are divided into two parts: the subject and the predicate. • The predicate is not a proposition. • It is neither true nor false. • Predicates use variables and objects like people, colors, numbers, letters or ideas. • They can also represent relationships and functions
  • 7.
    • Both syntaxand semantics are important to first- order logic. • Symbols are the basic syntax of FOL and can be written in shorthand. • Syntax is the structure of the logical statements. Semantics gives meaning to the statements. Examples: • Every man has a heart = ∀x man(x) → have (x, heart). • Some men are mean = ∃x: man(x) ∧ mean(x). 4/25/2023 7 Dpaertment of CSE ( AL & ML)
  • 8.
    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). 4/25/2023 8 Dpaertment of CSE ( AL & ML)
  • 9.
    Example: Find theMGU 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. 4/25/2023 9 Dpaertment of CSE ( AL & ML)
  • 10.
    Example: Let's saythere are two different expressions, P(x, y), and P(a, f(z)). In this example, we need to make both above statements identical to each other. For this, we will perform the substitution. P(x, y)......... (i) P(a, f(z))......... (ii) • Substitute x with a, and y with f(z) in the first expression, and it will be represented as a/x and f(z)/y. • With both the substitutions, the first expression will be identical to the second expression and the substitution set will be: [a/x, f(z)/y]. 4/25/2023 10 Dpaertment of CSE ( AL & ML)
  • 11.
    Conditions for Unification Followingare 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. 4/25/2023 11 Dpaertment of CSE ( AL & ML)
  • 12.
  • 13.
    Implementation of theAlgorithm • Step 1: Begin by making the substitute set empty. Step 2: Unify atomic sentences in a recursive manner: a. Check for expressions that are identical. b. If one expression is a variable vΨi, and the other is a term ti which does not contain variable vi, then: i. Substitute ti / vi in the existing substitutions ii. Add ti / vi to the substitution set list. Iii. If both the expressions are functions, then function name must be similar, and the number of arguments must be the same in both the expression. c. Find the most general unifier for each pair of the following atomic statements (If exist). 4/25/2023 13 Dpaertment of CSE ( AL & ML)
  • 14.
    Example 1 Find theMGU 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. Unification is not possible for these expressions. 4/25/2023 14 Dpaertment of CSE ( AL & ML)
  • 15.
    Example 2 Find theMGU of {p(b, X, f(g(Z))) and p(Z, f(Y), f(Y))} Sol: Here, Ψ1 = p(b, X, f(g(Z))) Ψ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}. 4/25/2023 15 Dpaertment of CSE ( AL & ML)
  • 16.
    Example 3 Find theMGU of {p (X, X), and p (Z, f(Z))} Sol: Here, Ψ1 = {p (X, X) Ψ2 = p (Z, f(Z)) S0 => {p (X, X), p (Z, f(Z))} SUBST θ= {X/Z} S1 => {p (Z, Z), p (Z, f(Z))} SUBST θ= {f(Z) / Z}, Unification Failed. Therefore, unification is not possible for these expressions. 4/25/2023 16 Dpaertment of CSE ( AL & ML)
  • 17.
    Example 4 UNIFY(knows(Richard, x),knows(Richard, John)) Sol: Here, Ψ1 = knows(Richard, x) Ψ2 = knows(Richard, John) S0 => { knows(Richard, x); knows(Richard, John)} S SUBST θ= {John/x} S1 => { knows(Richard, John); knows(Richard, John)}, Successfully Unified. Unifier: {John/x}. 4/25/2023 17 Dpaertment of CSE ( AL & ML)
  • 18.
    Topics to becovered in next session 23 • Resolution in First Order Logic (FOL) Thank you!!! 4/25/2023 Dpaertment of CSE ( AL & ML) 18