Sri Krishna Arts and Science Computer Technology: Course Coordinator Dr. V. S. Anita Sofia Prof. & Head
Sri Krishna Arts and Science Computer Technology: Course Coordinator Dr. V. S. Anita Sofia Prof. & Head
Sri Krishna Arts and Science Computer Technology: Course Coordinator Dr. V. S. Anita Sofia Prof. & Head
Computer Technology
Course Coordinator
Dr. V. S. Anita Sofia
Prof. & Head
SKASC 1
Agenda
• Knowledge Engineering in First-order logic
• Unification
• Resolution in FOL
• At the first level or highest level, we will examine the functionality of the circuit:
• What will be the output of gate A2, if all the inputs are high?
• At the second level, we will examine the circuit structure details such as:
• Firstly distinguish the gates from each other and from other objects.
• For gate input, we will use the function In(1, X1) for denoting the first input
terminal of the gate, and for output terminal we will use Out (1, X1).
• The function Arity(c, i, j) is used to denote that circuit c has i input, j output.
∀ g Gate(g) → Circuit (g).
Encode a description of the problem instance
• For the given circuit C1, we can encode the problem instance in atomic
sentences
Encode a description of the problem instance
• In this step, we will find all the possible set of values of all
the terminal for the adder circuit.
• Debug the knowledge base, and this is the last step of the
complete process.
• It can be represented as
• This rule can be used if we want to show that every element has a similar property.
• Example: Let's represent, P(c): "A byte contains 8 bits", so for ∀ x P(x) "All bytes
contain 8 bits.", it will also be true.
Universal Instantiation
• Universal instantiation is also called as universal elimination or UI is a valid
inference rule. It can be applied multiple times to add new sentences.
• As per UI, we can infer any sentence obtained by substituting a ground term
for the variable.
• The UI rule state that we can infer any sentence P(c) by substituting a ground term
c (a constant within domain x) from ∀ x P(x) for any object in the universe of
discourse.
• It can be represented as
Universal Instantiation
• Example:1.
• "All kings who are greedy are Evil." So let our knowledge base contains this detail
as in the form of FOL: ∀x king(x) ∧ greedy (x) → Evil (x),
• So from this information, we can infer any of the following statements using
Universal Instantiation:
• The new KB is not logically equivalent to old KB, but it will be satisfiable if old KB was
satisfiable.
• This rule states that one can infer P(c) from the formula given in the form of ∃x P(x) for a
new constant symbol c.
• The restriction with this rule is that c used in the rule must be a new term for which P(c )
is true.
• This rule states that if there is some element c in the universe of discourse which has a
property P, then we can infer that there exists something in the universe which has the property
P.
• It can be represented as
• Example:
• 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).
Unification
• Example: Find 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.
• The UNIFY algorithm is used for unification, which takes two atomic sentences and returns
a unifier for those sentences (If any exist).
• E.g. Let's say there are two different expressions, P(x, y), and P(a, f(z)).
Unification
• In this example, we need to make both above statements identical to each other.
For this, we will perform the substitution.
• 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].
Conditions for Unification
c) Else if Ψ2 is a variable,
a) Call Unify function with the ith element of Ψ1 and ith element of Ψ2, and put the result into S.
• If one expression is a variable vi, and the other is a term ti which does not contain
variable vi, then:
• 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.
Implementation of the Algorithm
• For each pair of the following atomic sentences find the most general unifier
(If exist).
• Here, Ψ1 = Q(a, g(x, a), f(y)), and Ψ2 = Q(a, g(f(b), a), x)
S0 => {Q(a, g(x, a), f(y)); Q(a, g(f(b), a), x)}
SUBST θ= {f(b)/x}
S1 => {Q(a, g(f(b), a), f(y)); Q(a, g(f(b), a), f(b))}
• SUBST θ= {b/y}
S1 => {Q(a, g(f(b), a), f(b)); Q(a, g(f(b), a), f(b))}, Successfully Unified.
• Resolution is used, if there are various statements are given, and we need to prove a conclusion of
those statements.
• Resolution is a single inference rule which can efficiently operate on the conjunctive normal form
or clausal form.
• Step-1: Conversion of
Facts into FOL
• likes(John, Peanuts).
Steps for Resolution
• Move negation (¬)inwards and rewrite • Rename variables or standardize variables
• ¬ food(x) V likes(John, x)
• food(Apple)
• food(vegetables)
• alive(Anil)
• ¬ eats(Anil, w) V eats(Harry, w)
• killed(g) V alive(g)
• ¬ alive(k) V ¬ killed(k)
• likes(John, Peanuts).
Steps for Resolution
• Distribute conjunction ∧ over disjunction ¬.
This step will not make any change in this problem.
• In the third step of the resolution graph, ¬ eats(y, Peanuts) and eats (Anil, Peanuts) get
resolved by substitution {Anil/y}, and we are left with Killed(Anil) .
• Inference engine:
• The first inference engine was part of the expert system. Inference engine
commonly proceeds in two modes, which are:
• Forward chaining
• Backward chaining
Forward Chaining and backward chaining
• It is equivalent to p ∧ q → k.
Forward Chaining
• Forward chaining is also known as a forward deduction or forward
reasoning method when using an inference engine.
• The Forward-chaining algorithm starts from known facts, triggers all rules
whose premises are satisfied, and add their conclusion to the known facts.
• "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."
• To solve the above problem, first, we will convert all the above facts into
first-order definite clauses, and then we will use a forward-chaining
algorithm to reach the goal.
Facts Conversion into FOL
• It is a crime for an American to sell weapons to hostile nations. (Let's say p, q, and r are
variables)
American (p) ∧ weapon(q) ∧ sells (p, q, r) ∧ hostile(r) → Criminal(p) ...(1)
• Country A has some missiles. ?p Owns(A, p) ∧ Missile(p). It can be written in two definite
clauses by using Existential Instantiation, introducing new Constant T1.
Owns(A, T1) ......(2)
Missile(T1) .......(3)
• Robert is American
American(Robert). ..........(8)
Backward Chaining
• 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.
• In backward-chaining, we will use the same above example, and will rewrite all the rules.
• Missile(T1)
• American(Robert). ..........(8)
Difference between backward chaining and forward chaining
S. No Forward Chaining Backward Chaining
1 Forward chaining starts from known facts and Backward chaining starts from the goal and works
applies inference rule to extract more data unit it backward through inference rules to find the required
reaches to the goal. facts that support the goal.
2 It is a bottom-up approach It is a top-down approach
3 Forward chaining is known as data-driven Backward chaining is known as goal-driven technique as
inference technique as we reach to the goal using we start from the goal and divide into sub-goal to extract
the available data. the 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,
monitoring, control, and interpretation application. and debugging application.
7 Forward chaining can generate an infinite number Backward chaining generates a finite number of possible
of possible conclusions. conclusions.
8 It operates in the forward direction. It operates in the backward direction.
9 Forward chaining is aimed for any conclusion. Backward chaining is only aimed for the required data.
Example: The Kinship Domain
• An example KB includes things like:
• Fact:
• Rules:
• Object: people