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

Unit IV - Knowledge Agents

The document describes a knowledge-based agent and its components. A knowledge-based agent has two main parts: a knowledge base and an inference system. The knowledge base stores facts about the world in a knowledge representation language. The inference system reasons over the knowledge base to determine actions. The document then discusses the Wumpus world environment, where the agent's goal is to navigate a cave to find gold without being eaten or falling in pits. The agent can perceive features of nearby rooms to help with navigation and reasoning.

Uploaded by

Muthukumaran C
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)
49 views42 pages

Unit IV - Knowledge Agents

The document describes a knowledge-based agent and its components. A knowledge-based agent has two main parts: a knowledge base and an inference system. The knowledge base stores facts about the world in a knowledge representation language. The inference system reasons over the knowledge base to determine actions. The document then discusses the Wumpus world environment, where the agent's goal is to navigate a cave to find gold without being eaten or falling in pits. The agent can perceive features of nearby rooms to help with navigation and reasoning.

Uploaded by

Muthukumaran C
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

AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

UNIT IV – LOGICAL AGENTS

Knowledge-Based Agent in Artificial intelligence:

• An intelligent agent needs knowledge about the real world for taking decisions
and reasoning to act efficiently.
• Knowledge-based agents are those agents who have the capability
of maintaining an internal state of knowledge, reason over that knowledge,
update their knowledge after observations and take actions.
• Knowledge-based agents are composed of two main parts:
o Knowledge-base and
o Inference system.

Architecture of knowledge-based agent:

• The above diagram is representing a generalized architecture for a knowledge-


based agent. The knowledge-based agent (KBA) take input from the environment
by perceiving the environment. The input is taken by the inference engine of the
agent and which also communicate with KB to decide as per the knowledge store
in KB. The learning element of KBA regularly updates the KB by learning new
knowledge.
• Knowledge base: Knowledge-base is a central component of a knowledge-based
agent, it is also known as KB. It is a collection of sentences (here 'sentence' is a
technical term and it is not identical to sentence in English). These sentences are
expressed in a language which is called a knowledge representation language. The
Knowledge-base of KBA stores fact about the world.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 1


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Operations Performed by KBA:


1. TELL: This operation tells the knowledge base what it perceives from the
environment.
2. ASK: This operation asks the knowledge base what action it should perform.
3. Perform: It performs the selected action.

A generic knowledge-based agent:

function KB-AGENT(percept):
persistent: KB, a knowledge base
t, a counter, initially 0, indicating time
TELL(KB, MAKE-PERCEPT-SENTENCE(percept, t))
Action = ASK(KB, MAKE-ACTION-QUERY(t))
TELL(KB, MAKE-ACTION-SENTENCE(action, t))
t=t+1
return action

Each time when the function is called, it performs its three operations:

o First, it TELLs the KB what it perceives.


o Second, it asks KB what action it should take
o Third, agent program TELLS the KB that which action was chosen.

The MAKE-PERCEPT-SENTENCE generates a sentence as setting that the agent


perceived the given percept at the given time.

The MAKE-ACTION-QUERY generates a sentence to ask which action should be


done at the current time.

MAKE-ACTION-SENTENCE generates a sentence which asserts that the chosen


action was executed.

Levels of knowledge-based agent:

A knowledge-based agent can be viewed at different levels which are given below:

1. Knowledge level

Knowledge level is the first level of knowledge-based agent, and in this level, we need
to specify what the agent knows, and what the agent goals are. With these
specifications, we can fix its behavior. For example, suppose an automated taxi agent

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 2


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

needs to go from a station A to station B, and he knows the way from A to B, so this
comes at the knowledge level.

2. Logical level:

At this level, we understand that how the knowledge representation of knowledge is


stored. At this level, sentences are encoded into different logics. At the logical level,
an encoding of knowledge into logical sentences occurs. At the logical level we can
expect to the automated taxi agent to reach to the destination B.

3. Implementation level:

This is the physical representation of logic and knowledge. At the implementation level
agent perform actions as per logical and knowledge level. At this level, an automated
taxi agent actually implement his knowledge and logic so that he can reach to the
destination.

Approaches to designing a knowledge-based agent:

There are mainly two approaches to build a knowledge-based agent:

1. Declarative approach: We can create a knowledge-based agent by


initializing with an empty knowledge base and telling the agent all the sentences
with which we want to start with. This approach is called Declarative approach.

2. Procedural approach: In the procedural approach, we directly encode


desired behavior as a program code. Which means we just need to write a
program that already encodes the desired behavior or agent.

Wumpus world:

• The Wumpus world is a cave which has 4/4 rooms connected with passageways.
So there are total 16 rooms which are connected with each other. We have a
knowledge-based agent who will go forward in this world.
• The cave has a room with a beast which is called Wumpus, who eats anyone who
enters the room. The Wumpus can be shot by the agent, but the agent has a single
arrow. In the Wumpus world, there are some Pits rooms which are bottomless, and
if agent falls in Pits, then he will be stuck there forever.
• The exciting thing with this cave is that in one room there is a possibility of finding
a heap of gold.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 3


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

• So the agent goal is to find the gold and climb out the cave without fallen into Pits
or eaten by Wumpus. The agent will get a reward if he comes out with gold, and he
will get a penalty if eaten by Wumpus or falls in the pit.

Components which can help the agent to navigate the cave:

The rooms adjacent to the Wumpus room are smelly, so that it would have some
stench.
a. The room adjacent to PITs has a breeze, so if the agent reaches near to PIT,
then he will perceive the breeze.
b. There will be glitter in the room if and only if the room has gold.
c. The Wumpus can be killed by the agent if the agent is facing to it, and Wumpus
will emit a horrible scream which can be heard anywhere in the cave.

PEAS description:

Performance measure:

• +1000 reward points if the agent comes out of the cave with the gold.
• -1000 points penalty for being eaten by the Wumpus or falling into the pit.
• -1 for each action, and -10 for using an arrow.
• The game ends if either agent dies or came out of the cave.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 4


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Environment:

• A 4*4 grid of rooms.


• The agent initially in room square [1, 1], facing toward the right.
• Location of Wumpus and gold are chosen randomly except the first square [1,1].
• Each square of the cave can be a pit with probability 0.2 except the first square.

Actuators:

• Left turn,
• Right turn
• Move forward
• Grab
• Release
• Shoot.

Sensors:

• The agent will perceive the stench if he is in the room adjacent to the Wumpus.
(Not diagonally).
• The agent will perceive breeze if he is in the room directly adjacent to the Pit.
• The agent will perceive the glitter in the room where the gold is present.
• The agent will perceive the bump if he walks into a wall.
• When the Wumpus is shot, it emits a horrible scream which can be perceived
anywhere in the cave.
• These percepts can be represented as five element list, in which we will have
different indicators for each sensor.
• Example if agent perceives stench, breeze, but no glitter, no bump, and no
scream then it can be represented as:
[Stench, Breeze, None, None, None].

Properties:

• Partially observable: The Wumpus world is partially observable because the


agent can only perceive the close environment such as an adjacent room.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 5


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

• Deterministic: It is deterministic, as the result and outcome of the world are


already known.
• Sequential: The order is important, so it is sequential.
• Static: It is static as Wumpus and Pits are not moving.
• Discrete: The environment is discrete.
• One agent: The environment is a single agent as we have one agent only and
Wumpus is not considered as an agent.

Exploring the Wumpus world:

Now we will explore the Wumpus world and will determine how the agent will find its
goal by applying logical reasoning.

Step1:

Initially, the agent is in the first room or on the square [1,1], and we already know that
this room is safe for the agent, so to represent on the below diagram (a) that room is
safe we will add symbol OK. Symbol A is used to represent agent, symbol B for the
breeze, G for Glitter or gold, V for the visited room, P for pits, W for Wumpus.

At Room [1,1] agent does not feel any breeze or any Stench which means the adjacent
squares are also OK.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 6


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Step2:

Now agent needs to move forward, so it will either move to [1, 2], or [2,1]. Let's suppose
agent moves to the room [2, 1], at this room agent perceives some breeze which
means Pit is around this room. The pit can be in [3, 1], or [2,2], so we will add symbol
P? to say that, is this Pit room?

Now agent will stop and think and will not make any harmful move. The agent will go
back to the [1, 1] room. The room [1,1], and [2,1] are visited by the agent, so we will
use symbol V to represent the visited squares.

Step3:

At the third step, now agent will move to the room [1,2] which is OK. In the room [1,2]
agent perceives a stench which means there must be a Wumpus nearby. But Wumpus
cannot be in the room [1,1] as by rules of the game, and also not in [2,2] (Agent had
not detected any stench when he was at [2,1]). Therefore agent infers that Wumpus is
in the room [1,3], and in current state, there is no breeze which means in [2,2] there is
no Pit and no Wumpus. So it is safe, and we will mark it OK, and the agent moves
further in [2,2].

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 7


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Step4:

At room [2,2], here no stench and no breezes present so let's suppose agent decides
to move to [2,3]. At room [2,3] agent perceives glitter, so it should grab the gold and
climb out of the cave.

Propositional logic:

• Propositional logic (PL) is the simplest form of logic where all the statements are
made by propositions. A proposition is a declarative statement which is either true
or false. It is a technique of knowledge representation in logical and mathematical
form.

Example:
a) It is Sunday.
b) The Sun rises from West (False proposition)
c) 3+3= 7(False proposition)
d) 5 is a prime number.

Following are some basic facts about propositional logic:

1. Propositional logic is also called Boolean logic as it works on 0 and 1.


2. In propositional logic, we use symbolic variables to represent the logic, and we can
use any symbol for a representing a proposition, such A, B, C, P, Q, R, etc.
3. Propositions can be either true or false, but it cannot be both.
4. Propositional logic consists of an object, relations or function, and logical
connectives and these connectives are also called logical operators.
5. A proposition formula which is always true is called tautology, and it is also called
a valid sentence.
6. A proposition formula which is always false is called Contradiction.
7. A proposition formula which has both true and false values is called Consistent.
8. Statements which are questions, commands, or opinions are not propositions such
as "Where is Rohini", "How are you", "What is your name", are not propositions.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 8


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Syntax:

• The syntax of propositional logic defines the allowable sentences for the knowledge
representation. There are two types of Propositions:

1. Atomic Sentences - The atomic sentences consist of a single proposition symbol.


Each such symbol stands for a proposition that can be true or false.
Example:
(a) 2+2 is 4, it is an atomic proposition as it is a true fact.
(b) "The Sun is cold" is also a proposition as it is a false fact.
2. Compound Sentences : Compound sentences are constructed by combining
simpler or atomic propositions, using parenthesis and logical connectives.

Example:

a) "It is raining today, and street is wet."


b) "Ankit is a doctor, and his clinic is in Mumbai."

Logical Connectives:

Logical connectives are used to connect two simpler propositions or representing a


sentence logically. We can create compound propositions with the help of logical
connectives. There are mainly five connectives, which are given as follows:

1. Negation: A sentence such as ¬ P is called negation of P. A literal can be either


positive literal or negative literal.
2. Conjunction: A sentence which has ∧ connective such as, P ∧ Q is called a
conjunction.
Example: “Rohan is intelligent and hardworking”
It can be written as,
P= Rohan is intelligent,
Q= Rohan is hardworking. → P∧ Q.

3. Disjunction: A sentence which has ∨ connective, such as P ∨ Q is called


disjunction, where P and Q are the propositions.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 9


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Example: "Ritika is a doctor or Engineer"


Here P= Ritika is Doctor, Q= Ritika is Doctor, so we can write it as P ∨ Q.
4. Implication: A sentence such as P => Q, is called an implication. Implications are
also known as if-then rules.
Example: “If it is raining, then the street is wet”
Let P= It is raining, and Q= Street is wet, so it is represented as P => Q
5. Biconditional: A sentence such as P⇔ Q is a Biconditional sentence,
Example: “If I am breathing, then I am alive”
P= I am breathing, Q= I am alive, it can be represented as P ⇔ Q.

Precedence of Operators : ¬, ∧,∨,=>,

Semantics:

• The semantics defines the rules for determining the truth of a sentence with
respect to a particular model. In propositional logic, a model simply fixes the truth
value—true or false—for every proposition symbol.

AND OR Conditional Bi-conditional


P Q
P∧Q P∨Q P⇒Q P⇔Q

T T T T T T

T F F T F F

F T F T T F

F F F F T T

• Atomic sentences are easy: True is true in every model and False is false in
every model.
• For complex sentences, we have five rules, which hold for any subsentences P
and Q in any model m :
• ¬P is true iff P is false in m.

• P ∧ Q is true iff both P and Q are true in m.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 10


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

• P ∨ Q is true iff either P or Q is true in m.


• P ⇒ Q is true unless P is true and Q is false in m.

• P ⇔ Q is true iff P and Q are both true or both false in m.

Logical Equivalences:

• (P ∧ Q) ≡ (Q ∧ P) commutativity of ∧
(P ∨ Q) ≡ (Q ∨ P) commutativity of ∨
• ((P ∧ Q) ∧ R) ≡ (P ∧ (Q ∧ R)) associativity of ∧
((P ∨ Q) ∨ R) ≡ (P ∨ (Q ∨ R)) associativity of ∨
1. ¬(¬P) ≡ P double-negation elimination

2. (P ⇒ Q) ≡ (¬Q ⇒ ¬P) contraposition

(P ⇒ Q) ≡ (¬P ∨ Q) implication elimination

3. (P ⇔ Q) ≡ ((P ⇒ Q) ∧ (Q ⇒ P)) biconditional elimination


4. ¬ (P ∧ Q) ≡ (¬P∨ ¬Q) De Morgan

¬ (P ∨ Q) ≡ (¬P∧ ¬Q) De Morgan

5. (P ∧ (Q ∨ R)) ≡ ((P ∧ Q) ∨ (P ∧ R)) distributivity of ∧ over ∨

(P ∨ (Q ∧ R)) ≡ ((P ∨ Q) ∧ (P ∨ R)) distributivity of ∨ over ∧

Propositional Theorem Proving:

• Applying rules of inference directly to the sentences in our knowledge base to


construct a proof of the desired sentence without consulting models. If the number
of models is large but the length of the proof is short, then theorem proving can be
more efficient than model checking.
• Logical equivalence : Two sentences P and Q are logically equivalent if they are
true in the same set of models. We write this as P = Q. For example, we can easily
show (using truth tables) that P ∧ Q and Q ∧ P are logically equivalent.
• Validity: A sentence is valid if it is true in all models. For example, the sentence P
∨ ¬P is valid. Valid sentences are also known as tautologies—they are necessarily
true.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 11


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

• Satisfiability: A sentence is satisfiable if it is true in or satisfied by some model.


For example, the knowledge base given earlier, (R1 ∧ R2 ∧R3 ∧ R4 ∧ R5), is
satisfiable because there are three models in which it is true.

Inference Rules:
• Modus Ponens Rule:

The Modus Ponens rule states that if P and and P → Q is true, then we can infer
that Q will be true. It can be represented as:

• And-Elimination:
And–Elimination rule state that if P∧ Q is true, then Q or P will also be true. It can
be represented as:

Propositional Logic (PL) into Conjunctive Normal Form (CNF):

Conjunctive Normal Form (CNF): A sentence represented as a conjunction of


clauses is said to be Conjunctive Normal Form or CNF.

Example: (PVQ) ∧ ( ¬PVQ) ∧ ….....

Steps to convert PL into CNF:

• Eliminate ⇔, replacing P ⇔ Q with (P ⇒ Q) ∧ (Q ⇒ P).


• Eliminate ⇒, replacing P ⇒ Q with ¬P ∨ Q

• Move ¬ inwards by,


o ¬(¬P) ≡ P (double-negation elimination)
o ¬(P ∧ Q) ≡ (¬P ∨ ¬Q) (De Morgan)
o ¬(P ∨ Q) ≡ (¬P ∧ ¬Q) (De Morgan)

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 12


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

• Apply distributive law,


• (P ∧ (Q ∨ R)) ≡ ((P ∧ Q) ∨ (P ∧ R)) distributivity of ∧ over ∨
• (P ∨ (Q ∧ R)) ≡ ((P ∨ Q) ∧ (P ∨ R)) distributivity of ∨ over ∧

Resolution in PL:
A resolution algorithm is to first, (KB ∧ ¬P) is converted into CNF. Then, the resolution

rule is applied to the resulting clauses. Each pair that contains complementary literals
is resolved to produce a new clause, which is added to the set if it is not already
present. The process continues until one of two things happens:
• there are no new clauses that can be added, in which case KB does not entail P; or,
• two clauses resolve to yield the empty clause, in which case KB entails P.

Algorithm:

Steps for Resolution:

1. Conversion of facts into Propositional Logic.


2. Convert PL statements into CNF
3. Negate the statement which needs to prove (proof by contradiction)
4. Draw resolution graph (unification).

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 13


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

First Order Logic:

• In propositional logic, we can only represent the facts, which are either true or false.
PL is not sufficient to represent the complex sentences or natural language
statements. The propositional logic has very limited expressive power. Consider
the following sentence, which we cannot represent using PL logic.
1. "Some humans are intelligent"
• To represent the above statements, PL logic is not sufficient, so we required some
more powerful logic, such as first-order logic.
• First-order logic is also known as Predicate logic or First-order predicate logic.
• To develops information about the objects in an easier way and can also express
the relationship between those objects.
• First-order logic (like natural language) does not only assume that the world
contains facts like propositional logic but also assumes the following things in the
world:
o Objects: A, B, people, numbers, colors, wars, theories, squares, pits,
wumpus, ......
o Relations: It can be unary relation such as: red, round, is adjacent, or n-
any relation such as: the sister of, brother of, has color, comes between
o Function: Father of, best friend, third inning of, end of, ......

Syntax and Semantics of FOL:

• The syntax of FOL determines which collection of symbols is a logical


expression in first-order logic. The basic syntactic elements of first-order logic
are symbols. We write statements in short-hand notation in FOL.

Basic Elements of First-order logic:


Constant 1, 2, A, John, Mumbai, Cat, X1……

Variables x, y, z, a, b……

Predicates True, False, After, Loves, Raining….

Function Mother, sqrt, LeftLegOf, ....

Connectives ∧, ∨, ¬, ⇒, ⇔

Quantifier ∀, ∃

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 18


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Terms :

• A term is a logical expression that refers to an object.

Example : Delhi is a city. We can write the sentence as,

City(Delhi)

Atomic sentences:
• Atomic sentences are the most basic sentences of first-order logic. These
sentences are formed from a predicate symbol followed by a parenthesis with
a sequence of terms.
• We can represent atomic sentences as Predicate (term1, term2, ......, term n).

Example: Ravi and Ajay are brothers.

Brothers(Ravi, Ajay).

Complex Sentences:
• Complex sentences are made by combining atomic sentences using
connectives.

Example: (P^Q) => (QVR)

Quantifiers:

• A quantifier is a language element which generates quantification, and


quantification specifies the quantity of specimen in the universe of discourse.
• These are the symbols that permit to determine or identify the range and scope
of the variable in the logical expression. There are two types of quantifiers:

a. Universal Quantifier, (for all, everyone, everything)

b. Existential quantifier, (for some, at least one).

Universal Quantifier:

• Universal quantifier is a symbol of logical representation, which specifies that the


statement within its range is true for everything or every instance of a particular
thing.
• The Universal quantifier is represented by a symbol ∀,

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 19


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

• If x is a variable, then ∀x is read as:

• For all x
• For each x
• For every x.

Example:

All man drink coffee.

Let a variable x which refers to a cat so all x can be represented as,

∀x man(x) → drink (x, coffee).

It will be read as: There are all x where x is a man who drink coffee.

Existential Quantifier:

• Existential quantifiers are the type of quantifiers, which express that the statement
within its scope is true for at least one instance of something.
• It is denoted by the logical operator ∃, which resembles as inverted E. When it is
used with a predicate variable then it is called as an existential quantifier.
• If x is a variable, then existential quantifier will be ∃x or ∃(x). And it will be read as:

• There exists a 'x.'


• For some 'x.'
• For at least one 'x.'

Example:

Some boys are intelligent.

∃x: boys(x) ∧ intelligent(x)

It will be read as: There are some x where x is a boy who is intelligent.

Properties of Quantifiers:

1. In universal quantifier, ∀x∀y = ∀y∀x.


2. In Existential quantifier, ∃x∃y = ∃y∃x.
3. ∃x∀y ≠∀y∃x.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 20


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Examples of FOL:

1. All birds fly.

∀x bird(x) →fly(x).

2. Every man respects his parent.

∀x man(x) → respects (x, parent).

3. Some boys play cricket.

∃x boys(x) → play(x, cricket).

4. Not all students like both Mathematics and Science.

¬∀ (x) [ student(x) → like(x, Mathematics) ∧ like(x, Science)]

Steps to Convert FOL into CNF:

1. Eliminate biconditionals and implications:


• Eliminate ⇔, replacing P ⇔ Q with (P ⇒ Q) ∧ (Q ⇒ P).
• Eliminate ⇒, replacing P ⇒ Q with ¬P ∨ Q

2. Move ¬ inwards by,

• ¬(∀ x p) ≡ ∃ x ¬p
• ¬(∃ x p) ≡ ∀ x ¬p
• ¬(¬P) ≡ P (double-negation elimination)

• ¬(P ∧ Q) ≡ (¬P ∨ ¬Q) (De Morgan)

• ¬(P ∨ Q) ≡ (¬P ∧ ¬Q) (De Morgan)

3. Standardize variables apart by renaming them: each quantifier should use a


different variable.
4. Skolemize: each existential variable is replaced by a Skolem constant or Skolem
function of the enclosing universally quantified variables.
• For instance, ∃x Rich(x) becomes Rich(G1) where G1 is a new Skolem
constant

5. Drop universal quantifiers

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 21


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

• For instance, ∀ x Person(x) becomes Person(x).

6. Apply distributive law,


• (P ∧ (Q ∨ R)) ≡ ((P ∧ Q) ∨ (P ∧ R)) distributivity of ∧ over ∨
• (P ∨ (Q ∧ R)) ≡ ((P ∨ Q) ∧ (P ∨ R)) distributivity of ∨ over ∧

Resolution in FOL:

1. Conversion of facts into First Order Logic.


2. Convert FOL statements into CNF
3. Negate the statement which needs to prove (proof by contradiction)
4. Draw resolution graph (unification).

Inferences in FOL:

1. Let us begin with Suppose our knowledge base contains the standard folkloric
axiom stating that all greedy kings are evil:
∀ x King(x) ∧ Greedy(x) ⇒ Evil(x)
2. Universal Instantiation :

The rule of Universal Instantiation (UI for short) says that we can infer any sentence
obtained by substituting a ground term (a term without variables) for the variable. Let
SUBST(θ,α) denote the result of applying the substitution θ to the sentence α. Then
the rule is written as,

3. Existential Instantiation:

The variable is replaced by a single new constant symbol. The formal statement is as
follows: for any sentence α, variable v, and constant symbol k that does not appear
elsewhere in the knowledge base,

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 22


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

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: 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.

E.g. Let's say there are two different expressions, P(x, y), and P(a, f(z)).

• 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:

• 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.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 31


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Algorithm:

Example :

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 32


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Forward Chaining:

• 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.

Algorithm:

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 33


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Backward Chaining:

Backward-chaining is also known as a backward deduction or backward reasoning


method when using an inference engine. 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:

• 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.
• The backward-chaining method mostly used a depth-first search strategy for
proof.

Algorithm:

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 34


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

Knowledge Engineering in First-order logic:

• The process of constructing a knowledge-base in first-order logic is called as


knowledge- engineering. In knowledge-engineering, someone who investigates a
particular domain, learns important concept of that domain, and generates a formal
representation of the objects, is known as knowledge engineer. This approach is
mainly suitable for creating special-purpose knowledge base.

Knowledge-engineering process steps:

Following are some main steps of the knowledge-engineering process. Using these
steps, we will develop a knowledge base which will allow us to reason about digital
circuit (One-bit full adder) which is given below:

1. Identify the task:

The first step of the process is to identify the task, and for the digital circuit, there are
various reasoning tasks.

At the first level or highest level, we will examine the functionality of the circuit:

• Does the circuit add properly?


• 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:

• Which gate is connected to the first input terminal?


• Does the circuit have feedback loops?

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 39


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

2. Assemble the relevant knowledge:

In the second step, we will assemble the relevant knowledge which is required for
digital circuits. So for digital circuits, we have the following required knowledge:

• Logic circuits are made up of wires and gates.


• Signal flows through wires to the input terminal of the gate, and each gate
produces the corresponding output which flows further.
• In this logic circuit, there are four types of gates used: AND, OR, XOR, and
NOT.
• All these gates have one output terminal and two input terminals (except NOT
gate, it has one input terminal).

3. Decide on vocabulary:

• The next step of the process is to select functions, predicate, and constants to
represent the circuits, terminals, signals, and gates. Firstly we will distinguish the
gates from each other and from other objects. Each gate is represented as an
object which is named by a constant, such as, Gate(X1). The functionality of each
gate is determined by its type, which is taken as constants such as AND, OR, XOR,
or NOT. Circuits will be identified by a predicate: Circuit (C1).

For the terminal, we will use predicate: Terminal(x).

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.

The connectivity between gates can be represented by predicate Connect(Out(1, X1),


In(1, X1)).

We use a unary predicate On (t), which is true if the signal at a terminal is on.

4. Encode general knowledge about the domain:

To encode the general knowledge about the logic circuit, we need some following
rules:

• If two terminals are connected then they have the same input signal, it can be
represented as:

∀ t1, t2 Terminal (t1) ∧ Terminal (t2) ∧ Connect (t1, t2) → Signal (t1) = Signal (2)

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 40


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

• Signal at every terminal will have either value 0 or 1, it will be represented as:

∀ t Terminal (t) →Signal (t) = 1 ∨Signal (t) = 0.


• Connect predicates are commutative:

∀ t1, t2 Connect(t1, t2) → Connect (t2, t1).


• Representation of types of gates:

∀ g Gate(g) ∧ r = Type(g) → r = OR ∨r = AND ∨r = XOR ∨r = NOT.

• Output of AND gate will be zero if and only if any of its input is zero.

∀ g Gate(g) ∧ Type(g) = AND →Signal (Out(1, g))= 0 ⇔ ∃n Signal (In(n, g))= 0.

• Output of OR gate is 1 if and only if any of its input is 1:

∀ g Gate(g) ∧ Type(g) = OR → Signal (Out(1, g))= 1 ⇔ ∃n Signal (In(n, g))= 1


• Output of XOR gate is 1 if and only if its inputs are different:

∀ g Gate(g) ∧ Type(g) = XOR → Signal (Out(1, g)) = 1 ⇔ Signal (In(1, g)) ≠ Sign
al (In(2, g)).
• Output of NOT gate is invert of its input:

∀ g Gate(g) ∧ Type(g) = NOT → Signal (In(1, g)) ≠ Signal (Out(1, g)).


• All the gates in the above circuit have two inputs and one output (except NOT gate).

∀ g Gate(g) ∧ Type(g) = NOT → Arity(g, 1, 1)


∀ g Gate(g) ∧ r =Type(g) ∧ (r= AND ∨r= OR ∨r= XOR) → Arity (g, 2, 1).
• All gates are logic circuits:

∀ g Gate(g) → Circuit (g).

5. Encode a description of the problem instance:

• Now we encode problem of circuit C1, firstly we categorize the circuit and its gate
components. This step is easy if ontology about the problem is already thought.
This step involves the writing simple atomics sentences of instances of concepts,
which is known as ontology.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 41


AD8402 – ARTIFICIAL INTELLIGENCE I II AI&DS / IV SEM

For the given circuit C1, we can encode the problem instance in atomic sentences as
below:

Since in the circuit there are two XOR, two AND, and one OR gate so atomic sentences
for these gates will be:

1. For XOR gate: Type(x1)= XOR, Type(X2) = XOR


2. For AND gate: Type(A1) = AND, Type(A2)= AND
3. For OR gate: Type (O1) = OR.

And then represent the connections between all the gates.

6. Pose queries to the inference procedure and get answers:

In this step, we will find all the possible set of values of all the terminal for the adder
circuit. The first query will be:

What should be the combination of input which would generate the first output of circuit
C1, as 0 and a second output to be 1?

∃ i1, i2, i3 Signal (In(1, C1))=i1 ∧ Signal (In(2, C1))=i2 ∧ Signal (In(3, C1))= i3 ∧ Si
gnal (Out(1, C1)) =0 ∧ Signal (Out(2, C1))=1

7. Debug the knowledge base:

Now we will debug the knowledge base, and this is the last step of the complete
process. In this step, we will try to debug the issues of knowledge base.

In the knowledge base, we may have omitted assertions like 1 ≠ 0.

PREPARED BY: C.MUTHUKUMARAN, AP/CSE 42

You might also like