Вы находитесь на странице: 1из 68

Artificial Intelligence

Master of Computer Applications

GVR & S College of Engineering and Technology

Budampadu, Guntur
Affiliated to Acharya Nagarjuna University

A.Rakesh Babu M.C.A., M.Tech 1

Artificial Intelligence

Artificial Intelligence(AI) is the key technology in many of today’s Novell
applications, ranging from banking system that detect attempted credit card framed, to
telephone systems that understand speech, to s/w systems that notice when you are having
problems and offer appropriate advice. These technologies would not exist today without
the sustained federal of fundamental AI research over the past 3 decades.

There is no clear definition of A.I .even the name is controversial, some people
prefer to call the subject of “computational Intelligence”.

The term A.I was coined in 1957 at a conference at Dartmouth New Hampshire
convened to discuss the possibilities of simulating human intelligence and thinking in

Today, AI is a well-established, natural and scaling branch of computer science.

A.I is the part of computer science concerned with designing intelligent computer
systems, that is, computer systems that exhibit the characteristics we associate with
intelligence in human behavior understanding language, learning, reasoning and solving
problems. The study of AI by considering a number of alternative definitions.

1) AI is the study of how to make computers do things which at the moment people
do better. It refers to the current state of computer science and if excludes a major
area of problems that can not be solved well either by computers or by people at
the moment.

2) AI is a field of study that encompasses computational techniques for performing

tasks that apparently require intelligence when performed by humans.

3) AI is about generating representations and procedures that automatically solve

problems which can be solved by humans.

4) AI is the part of computer science concerned with designing intelligent computer

systems that is computer systems that exhibit the characteristics we associate with
intelligence in human behavior-understanding language, learning, reasoning and
solving problems.

In practical terms, intelligence of a computer system provides:-

 Ability to automatically perform tasks that currently requires human operators.

A.Rakesh Babu M.C.A., M.Tech 2

Artificial Intelligence

 More autonomy in computer systems, less requirement for human intervention or


 Feasibility in dealing with variability in the environment in an appropriate manner.

 Ability to understand what the user wants from limited instructions.

 Increase in the performance by learning from experience.

AI problems
Intelligence does not imply perfect understanding: every intelligent being has
limited perception, memory, and computation. AI seeks to understand the computations
required from intelligent behavior and to produce computer systems that exhibit
intelligence. Aspects of intelligence studied by AI include perception, motor control, and
communication using human languages, reasoning, planning, learning and memory.
Various AI problems are as follows.

Mundane Tasks

 Perception

---Machine vision

---Speech understanding

 Natural language processing

--- Natural language understanding

---Language generation

---Machine translation

 Commonsense reasoning
 Robot control

Formal tasks

 Games



A.Rakesh Babu M.C.A., M.Tech 3

Artificial Intelligence


 Mathematics



---Integral calculus

---Proving properties of programs.

Expert tasks

 Engineering


---Fault finding

---Manufacturing planning

 Scientific analysis
 Medical diagnosis
 Financial analysis


Machine vision:-

Accurate machine vision opens up a new world of computer applications. These

applications include mobile robot navigation, complex manufacturing tasks, analysis of
satellite images, and medical image processing.

Perception of the world around us is crucial to our survival. Animals with much less
intelligence than people are capable of more sophisticated visual perception than are
current machines.

If it easy to interface a TV camera to a computer and an image into memory. The

problem is understanding what the image represents vision takes lots of computation.

Speech understanding:

Spoken language is a more natural form of communication in many human

computer interfaces. Speech understanding is available now on personal computers. These
A.Rakesh Babu M.C.A., M.Tech 4

Artificial Intelligence

systems must be trained for the individual user and require pauses between words.
Understanding continuous speech with a larger vocabulary is harder.

The ability to use language to communicate a wide variety of ideas is perhaps the
most important thing that separates human from other animals.

Natural Language Processing:

Natural Language understanding:-

Natural languages are human languages such as English. Making computers

understand English allows non- program mess to use them with little training.

Natural language generation:-

Making computers to generate human or natural languages can be called as natural

language generation. It is much easier than natural language understanding

Machine Translation:-

A text written in one language and then generate it in another language by means of
computers can be called as machine Translation. It is important for organizations that
operate in many countries.

Common Sense Reasoning:-

A computer program that interacts with real world must be able to reason about
things like time, space and materials. As a fundamental and commonsensical as these
concepts may be modeling them turns out to present some problems.

Robot Control:-

Robots can process visual and auditory information, and they can also be equipped
with more special sensors, such as laser range finders, speedometers and radar. Although
industrial robots to date have been expensive, robot hardware can be cheap. What is needed
is perception and intelligence to tell robot effectors what to do; “bling” robots are limited
to very well-structured tasks like spray painting car bodies.


Planning attempts to order the application of resources to achieve goals planning

applications include logistics; manufacturing scheduling planning steps in manufacturing is
to construct a desired product.

A.Rakesh Babu M.C.A., M.Tech 5

Artificial Intelligence

Expert Systems:-
Expert systems attempt to capture the knowledge of human expert and make it
available through a computer program.

Machine Learning:-

Learning has remained a challenging area of AI. Expert systems may perform costly
computations to solve problem. Unlike human beings it can’t remember the solution, if it is
given the same problem for second time one of the solutions for these problems for
programs is to learn on their own either from experience examples or analogy.

AI Technique:-
There AI techniques are:

1. Search
2. Use of knowledge
3. Abstraction

Search programs find a solution for a problem by trying different sequences of
actions/operators until a solution is found.

The advantage of search is, to solve a program using search, it is only necessary to
code the operators that can be used: search will find the sequence of actions that will
provide the desired result. For example a program can be written to play chess using search
if one knows the rules of chess if is not necessary to know how to play good chess.

The disadvantage of search is, most problems have search so large that it is
impossible to search the whole space. Chess has been estimated to have 1020 possible
Use of Knowledge:-
Use of knowledge provides a way of solving complex problems by exploiting of the
objects that are involved. Games can be good models of competitive situations, so
principles discovered in games playing programs may be applicable to practical problems.


Abstraction provides a way of separating important features and variations from the
many unimportant ones that would otherwise overwhelm any process.


A.Rakesh Babu M.C.A., M.Tech 6

Artificial Intelligence

To build a system to solve a particular problem, for that we need to do four things

1) Define the problem exactly. The definition must include precise specification of
what the initial situation will be as well as what final situations constitute
acceptable solutions to the problem.
2) Analyze the problem a few very important features can have an immense impact on
the appropriateness of various possible techniques for solving the problem.
3) Isolate and represent the task knowledge that is necessary to solve the problem.
4) Choose the best problem solving techniques and apply it to the particular problem.

Defining problem as a state space search

A state space represents a problem in terms of states and operators that change states

A state space consists of:

1) A representation of the states the system can be in. in a chess game, for example,
any board position represents the current state of the game.
2) A set of operators that can change one state into another state. In chess game, the
operators are the legal moves from any given state. Often the operators are
representation to represent the new state.
3) An initial state.
4) A set of final states, some of these may be desirable others are undesirable this sets
often represented implicitly by a program that deletes terminal states.
Tic-tac-toe as a state space

State space is good representations for board games such as tic-tac-toe the state of a
game can be described by the contents of the board and the player whose turn is next. The
board can be represented as an array of 9 cells, each of which may contain a X or O or be


 Play to move next X or O.

 Board configuration.

A.Rakesh Babu M.C.A., M.Tech 7

Artificial Intelligence



Operators: Change an empty cell to X or O.

Start state: Board empty, X’s turn

Terminal states: Three X’s in arrow there O’s in arrow all the cells full.

Search tree: The sequence of states formed by possible moves is called a search tree each
level of the tree is called a play.



A.Rakesh Babu M.C.A., M.Tech 8

Artificial Intelligence

Since the same state may be reachable by different sequence of moves the state
space may be in a general graph it may be as a tree for simplicity at the cost of duplicating

Solving problems using search:

Given an informal description of the problem construct a formal description as a state


 Define a data structure to represent the state.

 Make a representation for the initial state from the given data.
 Write programs to represent operators that change a given state representation to
new state representations.
 Write programs to delete terminal state.

Choose an appropriate search technique based on the following quires:

1) How large is the search space?

2) How well structured is the domain?
3) What knowledge about the domain can be used to guide the search?

Evaluating search strategies:

Completeness: Guarantees finding a solution when ever one exits.

Time Complexity: How long (worst or average case) does it take to find a solution?
Usually measured in terms of the number of nodes expanded. Big O notation used for
measuring time complexity.

Space Complexity: How much space is used by the algorithm? Usually measured in term
of the maximum size that nodes list becomes during the search.

Optimality: If a solution is found is it guaranteed to be an optimal one? That is the one

with minimum cost?

A.Rakesh Babu M.C.A., M.Tech 9

Artificial Intelligence

Water jug problem:

There are two jugs a 4-Gallon one and 3-Gallon one. Neither has any measuring
marker on it. There is a pump that can be used to fill the jugs with water how can you get
exactly 2- Gallon water into the 4- Gallon jug?
The state space for this problem can be described as the set of ordered pairs of
integers(x, y) such that x=0, 1, 2, 3, 4 and y=0, 1, 2, 3.
X represents the number of gallons of water in the 4- Gallon jug.
Y represents the number of gallons of water in the 3- Gallon jug.
The state space is (0, 0).
The goal state is (2, n) for any value of n.

The operators to be used to solve the problem can be described as follows.

1. (x, y) (4,y) fill the 4-g jug
If x<4

2. (x, y) (x, 3) fill the 3-g jug

If y<3
3. (x, y) (x-d, y) pour some water out of the 4-g jug
If x>0
4. (x, y) (x, y-d) pour some water out of the 3-g jug
If y>0
5. (x, y) (0, y) empty the 4-g jug on the ground

If x>0
6. (x, y) (x,0) empty the 3-g jug on the ground
If y>0
7. (x, y) (4,y-(4-x)) pour water from the 3-g jug into

If x + y >= 4 and y>0 the 4-g jug until the 4-g jug is full

8. (x, y) (x,-3(3-y),3) pour water from the 4-g jug into

A.Rakesh Babu M.C.A., M.Tech 10

Artificial Intelligence

If x + y>3 & x>0 the 3-g jug until the 3-g jug is full

9. (x, y) (x+y,0) pour all the water from 3-g jug into

If x + y<=4 and y>0 4-g jug

10. (x, y) (0,x+y) pour all the water from the 4-g jug

If x + y<=3 & x>0 into the 3-g jug

11. (0, 2) (2, 0) pour the 2-g from 3-g jug into 4-g


12. (2, y) (0, y) empty the 2-g in the 4-g jug on

the ground.

Solution to the water jug problem:

Gallon in the 4-g jug Gallon in the 3-g jug Rule Applied

0 0

0 3

3 0

3 3

4 2


0 2

1 0

A.Rakesh Babu M.C.A., M.Tech 11

Artificial Intelligence

Production Systems:
The search forms the basic intelligent process it is useful to structure. A.I programs
in a way that facilities describing and performing the search process. Production system
provides such structures.

A production system consist of

1) A set of rules, each consisting on the left side that determines the applicability of the
rule and on a right side that describe the operation to be performed if the rule is applied.
2) One/more knowledge /database that contain what ever information is appropriate for
the particular task. a production system has two memories
a) A production memory or long-term memory contains the production rules.
b) A working memory or short-term memory containing data about the current
3) A control strategy that specifies the order in which the rules will be compared to the
database and a way of resolving conflicts that arise when several rules match at once.
4) A rule applier.
The production rules operate on the knowledge base/database. Each rule has a
precondition that is either satisfied by the knowledge base. If the precondition is satisfied,
the rule can be applied. Application of the rule changes knowledge base. The control
system chooses which applicable rule should be applied and causes computation when a
termination condition on the knowledge base.

Give an initial configuration of 8 numbered tiles on a 3X3 board, move the files in
such a way so as to produce a desired goal configuration of the tiles.

State: 3 X 3 array configuration of the file on the board.

Operators: move blank square left, right, up or down.

Initial state: a particular configuration of the board.

Goal: a particular configuration of the board.

A.Rakesh Babu M.C.A., M.Tech 12

Artificial Intelligence

2 1 3 1 2 3

7 8 9 4 5 6

4 7 7 8

Initial State Goal State

The traveling sales man problem:

Sales man has a list of cities, each of which he must visit exactly once. Three are
direct roads b/w each pair of cities on the list. Find the route the salesman should follows
for the shortest possible round trip that both starts and finishes at any of the cities.

Heuristic search:
A heuristic search is a technique that improves the efficiency of search process. One
example of a good general-purpose heuristic search that is useful for a variety of
combinational problems is the nearest heuristic. Applying it to the traveling salesman
problem. Then we produce the following procedure.

1) Arbitrarily select a starting city.

2) Select the next city, look at all cities not yet visited and select the one closet to the
current city go to it next
3) Repeat step2 until all cities have been visited.

Problem characteristics:
Heuristic search is very general method applicable to a large class of problems. It
encompasses a variety of specific techniques, each of which is particularly effective for a
small class of problems in order to choose the most appropriate method for a particular
problem. It is necessary to analyze the problem along several key dimensions. The
following characteristics are nothing but problem characteristics:

1) Is the problem decomposable into a set of smaller sub problems?

2) Can solution steps be ignored or undone if they do not move towards a solution?
3) Is the problem universe predictable?
4) Can we find a good solution to the problem with out comparing to all other possible
5) Is the desired solution is path/state?
A.Rakesh Babu M.C.A., M.Tech 13

Artificial Intelligence

6) Is a large amount of knowledge required to solve the problem to constrain the

7) Can a system return the solution/will the solution of the problem require interaction
between the system and a person?

Is the problem decomposable into subprograms?

Suppose we want to solve a problem of computing the expression

∫(x3+x2+2x+3sinx) dx

This problem can be solved by breaking it into 4 smaller problems, each of which we can
solve by using a small collection of specific rules:

∫ (x3+x2+2x+3sinx) dx

∫ x3 dx ∫ x2dx ∫2x dx ∫ 3sinxdx

x4/4 x3/3 2 ∫ x dx 3 ∫ sin x dx

2x2/2 -3cosx

Fig: A Decomposable Problem

Using the technique of problem decomposition, we can solve very large problems,
very easily. This can be considered as one of the intelligent behaviors.

A.Rakesh Babu M.C.A., M.Tech 14

Artificial Intelligence

Can solution steps to be ignored or undone?

Suppose we are trying to prove a mathematical theorem. We may precede by first a

lemma that will be useful. Later we may realize that the lemma is not at all useful. We may
start with another one to prove the theorem here we can simply ignore the first method we
have adopted to find the solution.

Consider the 8-puzzel problem in attempting to solve the 8-puzzel, we might make
a stupid move and realize that mistake and found we have done wrong step. But still
mistakes can be recovered it may be as easy as in the theorem proving problem here the
control strategy must keep track of all the moves. so that we can backtrack to the initial
state and start with some new move.

Consider the problem of playing chess. Here once we make move we can never
recover from that step.

These three problems, i.e. theorem proving, 8-puzzel, chess illustrate the differences
b/w three important classes of problems.

1) Ignorable: In which solution steps can ignore.

Ex: Theorem proving

2) Recoverable: In which solution step can be undone.

Ex: 8-puzzle

3) Irrecoverable: In which solution steps can not be undone.

Ex: chess

Is the problem universe predictable?

Consider 8-puzzle problem. Every time we make a move .we knows exactly what will
happen. This means that it is possible to plan an entire sequence of moves and be confident
what the resulting state will be. We can backtrack to undone moves if they prove unwise.

Suppose we want to play bridge. Here we need to plan the entire hand before making
the first play. But we can not play with certainty. The outcome in this game is very
uncertain. In case of 8-puzzlethe outcome is very certain. To solve uncertain outcome
problems we need to allow for a process of plan revision to tale place as the plan is carried
out and the necessary feedback is provided. The disadvantage is that the planning in these
cases is often very expensive.

A.Rakesh Babu M.C.A., M.Tech 15

Artificial Intelligence

Is a good solution absolute/relative?

Consider the problem of answering questions based on a database of simple facts, such
as the following:

1) Marcus was a man.

2) Marcus was a Pompeian.

3) Marcus was born in 40 A.D.
4) All means are mortal.
5) All Pompeian’s died when the volcano erupted in 79 A.D.
6) No mortal lives longer than 150yers.
7) It is now 1991 A.D.

Suppose the question is “is Marcus alive”? By representing each of these facts in a
formal language, such as predicate logic, and then using formal inference methods, we can
easily derive an answer to the question. In fact we can use either of two methods to give
answer to the question, which as shown below.

1) Marcus was a man.

2) All men are mortal.
3) Marcus is mortal.
4) Marcus was born in 40 A.D.
5) It is now 1991A.D.
6) Marcus age is 1951 years.
7) No mortal lives longer than 150 years.
8) Marcus id dead.

1) It is now 1991 A.D.

2) All Pompeian’s died in 79 A.D.
3) All Pompeian’s are dead now.
4) Marcus was Pompeian.

5) Marcus is dead.

Since we are interested in the answer of the question it does not matter which path we
follow. If we follow one path successfully, to the answer, there is no reason to go back and
A.Rakesh Babu M.C.A., M.Tech 16

Artificial Intelligence

see if some other path might also lead to a solution. Now, consider the traveling salesman
problem our goal is to find the shortest route that visits each city exactly once. Suppose the
cities to be visited and the distance b/w they are as shown below.

Boston New York Miami Dallas S.F

Boston 250 1450 1700 3000

New York 250 1200 1500 2900

Miami 1450 1200 1600 3300

Dallas 1700 1500 1600 1700

S.F 3000 2900 3300 1700

Fig: An instance of the traveling salesman problem

Once place the sales person could start is Boston. In that case, one path might be
followed as shown below.





1450 Total=8850

Fig: One path among the cities

Here the total distance is 8850kms.but this may not be a solution to the problem, may
be other paths may give shortest route.
A.Rakesh Babu M.C.A., M.Tech 17

Artificial Intelligence

These toe examples illustrate the difference b/w any path problems and best-path
problems. Any path problems can often be solved in a reasonable amount of time by using
heuristic techniques that give good solution to explore.

Is the desired solution a path /state?

Different problem domains represent their goal in different ways such as states/paths.
Consider water jug problem, whose solution is a desired state and traveling salesman
problems solution is the shortest path. At one level the difference can be ignored and all
can be formulated as ones in which only a state is required to be reported as a solution.

The role of knowledge:

The knowledge require to solve a particular problem is depending upon the problem it
self. for example take playing chess, for this we need acknowledge of legal moves and
some simple control mechanism that implements an appropriate search procedure on the
other side, take a problem of design a robot have the knowledge about the source and
destination, car driving rules, operating knowledge of car, weather knowledge and so on.
These two problems illustrate the difference b/w problems for which a lot of knowledge is
important only to constrain the search for a solution.

Does the problem require interaction with a person?

If the level of interaction b/w the computer and its human users is problem-in-solution-
out then we can program computers to solve problems into the ways that majority of people
additional input and additional reassurance then we need to go for progress that interacts
with people.

When computers move into the areas of human lives like medical diagnosis people will
not blindly accept the systems solution. They need to interact with it. This we can
distinguish two kinds of problems.

1) Solitary: Here computer is given a problem description and it produces the answer
with out any intermediate interaction.
2) Conversational: Here intermediate interaction between the user and a computer is
necessary either to provide additional assistance to the computer or to provide
additional information to the user.

A.Rakesh Babu M.C.A., M.Tech 18

Artificial Intelligence

Production system characteristics:

Production system provide us with a good set of production rules, by using which we
can solve the problems. Two questions may a raise at this point of time.

1) Can production systems, be described by a set of characteristics?

2) Can we draw any relationship between the problem types and the types of
production systems suited to solve the problems?
There are four categories of production systems:

1) A monotonic production system is a production system in which the application of a

rule never prevents the later application of another rule that could have been applied at
the time the first rule is selected.
2) A non monotonic production system is one in which the application of a rule prevents
the later application of another rule that would have been applied at the time the first
rule was selected.
3) A partially commutative production system is a production system with the property
that if the application of a particular sequence of rules transforms state p into state q.
then any permutation of those rules is allowable also transforms state p into state q.
4) A commutative production system is production system that is both monotonic and
partially commutative.


Monotonic Non monotonic

Theorem proving Robot navigation


Production system/
Chemical analysis Bridge
Non partially


Fig: The 4-categories of Production Systems.

A.Rakesh Babu M.C.A., M.Tech 19

Artificial Intelligence


Generate and Test:-

The Generate and test strategy is the simplest of all approaches.


i. Generate a possible solution.

ii. Text to see if this is actually a solution by comparing with goal.
iii. If solution has been found quit otherwise return to step1.

The Generate and text algorithm is a DFS procedure since complete solution must be
generated before they can be tested. In this form it is also known as British museum
algorithm a reference to method for finding an object in British museum by wandering


Hill Climbing is a variant of generate and test in which feedback from the test
procedure is used to help the generator decide, which direction to move in the search space.
Hill Climbing is often used when a good Heuristic Function is available for
evaluating states but when no other useful knowledge is available.
For example, suppose you are in an unfamiliar city without a map and you want to
get down town you simply aim for the tall buildings. The Heuristic Function is just distance
between the current locations of the tall buildings. Absolute solutions exist whenever it is
possible to recognize a goal state by just examining it.

Simple Hill Climbing:-


i. Evaluate the initial state. If it is also a goal state, then return it and quit. Otherwise
continue with the initial state as the current state.
ii. Loop until a solution is found (or) until there are no new operators left to be applied
in the current state.
a) Select an operator that has not yet been applied to the current static and apply it to
produce a new state.

A.Rakesh Babu M.C.A., M.Tech 20

Artificial Intelligence

b) Evaluate the new state

 If it is a goal state, then return it and quit
 If it is not a goal state but better than the current state, then make it the
current state.
 If it is not better than the current state, then continue in the loop.




Steepest-Ascent Hill Climbing:-


i. Evaluate the initial state. If it is also goal state, then return it and quit otherwise
continue with the initial state as the current state.
ii. Loop until a solution is found(or) until a complete iteration produces no change to
current state
a) Let succ be a state such that any possible successor of the current state will be better
than succ.
b) For each operator that applies to the current state do:
o Apply the operator and generate a new state.
o Evaluate the new state. If it is a goal state, then return it and & quit. If not,
compare it to succ. If it is better than set succ to this state. If it is not better
leave succ alone.
o If the succ is better than current state, then set current state to succ.
Both basic and steepest-ascent Hill Climbing fail to find a solution.

 Local maximum is a state that is better that all its neighbors but is not better than some
other states further away.

A.Rakesh Babu M.C.A., M.Tech 21

Artificial Intelligence


2 6

 Plateau is a flat area of the search space in which a whole set of neighboring states has
the same value.


 Ridge is a special kind of local maximum. It is an area of the search space that is higher
than the surrounding areas & itself has a slope.

It means better but having slope.

There are some ways of dealing with these problems

i. Back track to some earlier node and try going to different direction.
ii. Make a big jump in some direction to try. To get a new section of the search
iii. Apply two (or) more rules before doing the test suppose we use the following
heuristic function operators:
 Pick up one put it on the table
 Pick up one it on the other

A.Rakesh Babu M.C.A., M.Tech 22

Artificial Intelligence

Simulated annealing:-

Simulated annealing is a variation of hill climbing and we describe it valley

descending. Here we use the term objective function which aims at minimizing the value
simulated annealing is patterned after the physical process of annealing in which physical
substances such as metals are melted and then gradually cooled until some solid state is
reached. The goal is to produce a minimal energy final state.
There is some portability that a transition to a higher state will occur the probability
is given by

∆E = Positive change in the energy level.

T= temperature
The rate at which the system is cooled is called the “Annealing schedule”.


i. Evaluate the initial state. If it is a goal state, then return it and quit. Otherwise
continue with the initial state as the current state.
ii. Initialize BEST-SO-FAR to the current state.
iii. Initialize T according to the annealing schedule.
iv. Loop until a solution is found or until no new operators are left to be applied.
a. Select an operator that has not yet been applied to the current state and apply
it to get a new state.
b. Evaluate this new state, compute
∆E = value of current state – value of new state.
o If the new state is a goal state, then return it & quit
o If it is not a goal state but is better than the current state, then make
it the current state. Also set BEST-SO-FAR to this new state.
o If the new state is not better than the current state, then make it the
current state with probability P`
o Revise T as necessary
v. return BEST-SO-FAR as the answer:

Here we need to do enough exploration of the whole space early so that the final
solution is relatively insensitive to the starting state. These lower the chances of getting
caught at a local maximum, a plateau or a ridge.

A.Rakesh Babu M.C.A., M.Tech 23

Artificial Intelligence


Best first search combines the advantage of both depth-first and breadth first search
methods. It selects the most promising node at each step by applying an approximate
heuristic function the successors of this node are generated using applicable rules if one of
them is a solution, we quit if not all these new nodes are added to the nodes. So far
generated, and the process continues.
Figure shows the beginning of a Best- First search procedure.

4 6
2 3 4 2

7 7
5 5 6 7

9 10

Best-first search tree

To implement such a graph-search procedure, we will need to use two lists of nodes.
Open is actually a priority queue in which the elements with the highest priority are
those with the most promising value of the heuristic function.
Nodes that have been already been examined. We need to keep these nodes in
memory if we want to search a graph rather than a tree.

A.Rakesh Babu M.C.A., M.Tech 24

Artificial Intelligence

Algorithm: Best-First search:-

1. State with open containing just the initial state

2. Until a goal is found or there are no nodes left on open do:
a) Pick the best node on open
b) Generate its successors
c) For each success do:
 If it has not been generated before, evaluate it add it to
OPEN, and record its parent.
 If it has been generated before, change the parent if this new
path is better than the previous one.

The A* provides general guidelines with which to estimate goal distances for the
search graphs. The A* algorithm generates all successor nodes and computes an estimate of
the distance from the start node to the goal through each of the successors. It chooses the
successor with the shortest estimated distances for further expansion. The successors or this
node are then generated, their distances estimated and this process continues until a goal is
found or the search ends in a failure. The form of heuristic function for A* is
F*(n)-g*(n) +h*(n)
Where g*(n) =h*(n) =estimates of the cost (or) distances from the start node to node n and
the distances from node n a goal node

1. Set SUCCESSOR to point back to BESTNODE.(Back links will help to recover

the path).
2. Compute g(SUCCESSOR) = g( BESTNODE) cost of getting from BESTNODE to
3. If SUCCESSOR is same as any node to OPEN, call that node OLD and add OLD
g(SUCCESSOR) is cheaper then rest OLD’S parent link to point to BESTNODE.
Update g (OLD) and f’ (OLD).
4. If SUCCESSOR was not on OPEN, see if it is on CLOSED. If so call the node
CLOSED OLD, and better as earlier and set the parent link and g and f’ values
5. If SUCCESSOR was not already on earlier OPEN or CLOSED, then put it on
OPEN and add it to the list of BESTNODE’S successors.


A.Rakesh Babu M.C.A., M.Tech 25

Artificial Intelligence


Problem reduction is a basic problem solving technique of AI. It involves reducing a

problem to a set of easier sub problems whose solutions, if found, can be combined to form
a solution, to the hard problem, the procedure is as follows.

1) If the given problem is a primitive sub problem return the solution to it.
2) Otherwise, try breaking the given problem into sets of simpler sub problems, and call
the program recursively to try to solve the sub-problems.
3) If a set of sub problems is found such that all the sub problems. Can be solved,
combine the sub problem solutions in an appropriate way to form the solution to the
current problem.
The given problem is reduced to a set of simpler sub problems, the solution of which
will allow the original problem to be solved.
This reduction applied recursively until permissive sub problems which are
immediately solvable are reached. The resulting is called an AND/OR graph.

AND node:-

All sub problems must be solved in order to solve the main problem. An arc is
drawn across branches of an and node

OR node:-

Solution of any sub-problem will solve the main problem. A state space search
graph consists entirely of OR nodes.

A.Rakesh Babu M.C.A., M.Tech 26

Artificial Intelligence

AND / OR Graph Example:

Go from JNTU, Hyderabad


JNU, New Delhi


Go to Hyderabad Airport Fly to New Delhi Go from New Delhi Airport

to JNU

Drive Take a bus Take a taxi

Drive Take a taxi
Take a

Call a taxi Get Money

Steal a car
Rent a car

Look UP Dial Ask for

number Phone Taxi

Terminal nodes

Solution to an AND/OR Graph:-

1) A successful terminal node is a solved node

2) If a non terminal OR node has any solved successors, then it is a solved node.
3) If all of the successors of a non terminal AND node are solved, then it is a
solved node.
4) The problem is solved if the start node is solved.
5) A solution graph is a sub graph of solved nodes that demonstrates that the start
node is solved.

Search of an AND/OR Graph:-

An AND|OR graph is searched recursively until the root node is solved, to solve a
node, attempt to solve each successor of a non terminal node sequentially.

i. If any successor of an AND node fails, the AND node fails immediately.
A.Rakesh Babu M.C.A., M.Tech 27

Artificial Intelligence

ii. If any successor of an OR node succeeds, the OR node succeeds immediately.

The search time may be improve by ordering consideration of the nodes:
 To solve an AND node try first to solve those successors that are most likely
to fail.
 To solve an OR node try first to solve those successors that are most likely
to succeed.


I. Let graph consists only one of the node representing the initial state compute
II. Until INIT is labeled solved or hi (INIT) and become greater than FUTILITY,
repeat the following procedure.
a. Trace the marked arcs from INIT and select an unbounded node NODE.
b. Generate the successors of NODE if there are no successors then assign
FUTILITY. As h` (NODE). This means that NODE is not solvable. If there
are successors then for each one called successor, that is not also an ancestor
of NODE do the following.
 Add successor to graph G.
 If successor is not a terminal node, mark it solved and assign zero to its
h value.
 Propagate the newly discovered information up the graph by doing the
following. Let S be a set of nodes that have been marked SOLVED.
Initialize S to NODE. Until S is empty repeat the following procedure.
a) Select a node from S call if CURRENT and remove it from S.
b) Compute h` of each of arcs emerging from CURRENT, assign
minimum h` to CURRENT.
c) Mark the minimum cost path a S the best out of CURRENT.


Many problems in AI can be considered as problems of constraint satisfaction, in

which the goal satisfies a given set of constraint satisfaction problems can be solved by
using any of the search strategies.


1. Propagate available constraints. To do this, first see OPEN to the set of all objects
that must have values assigned to then in a complete solution. Then do until an
inconsistency is detected or until OPEN is empty.

A.Rakesh Babu M.C.A., M.Tech 28

Artificial Intelligence

a) Select an object OB from OPEN. String then as possible the set of

constraints that apply to OB.
b) If this set is different from the set that was assigned. The last time OB was
examined or if this is the first time OB has been examined, then adds to
OPEN all objects that share any constraints with OB.
c) Remove OB from OPEN.

2) If the union of the constraints discovered above defines a solution, they quit and report
the solution.

3) If the union of the constraints discovered above defines a contradiction, they return

4) If the union of the above occurs, there it is necessary to make a guess at something in
order to proceed. To do this, loop until a solution is found or all possible solutions have
been eliminated.

a. Select an object whose value is not yet determined and select a way of
strengthening the constraints on that object.

b. Recursively invoke constraints satisfaction with the current set of constraints

augmented by the strengthening constraint just selected.

Consider The Crypt Arithmetic Problem:





A.Rakesh Babu M.C.A., M.Tech 29

Artificial Intelligence


 No two letters have the same value.

 The sum of the digits must be as shown in the problem.

 Any of search technique may be used.

 Only single digit number can assign to a letter (0-9).

Initial state:

M =? O =? R=? E=? S=? N=? D=? Y=? C1=? C2=?

C1, C2, C3 stands for the carry variables respectively.

Goal State:

The digits to the letters must be assigned in such a manner so that the sum is satisfied.

Solution Process:

 Initially, rules for propagating constraints generate the following additional


 M=1, since two single digit numbers plus a carry cannot total more than 19.

 S=8 or 9.Since S+M+C3>9 and M=1, S+1+C3 >9, S+C3>8 and C3 is at most 1.

 O=0, since S+M (1) +C3 (<=1) must be at least 10 to generate a carry and it can be
at most 11.But M is already 1, so O must be 0.

 N=E or E+1, depending on the value of C2.But N cannot have the same as E. So
N=E+1 and C2 is 1.

 In order for C2 to be 1, the sum of N+R+C1 must be greater than 9, So N+R must
be greater than 8.

 N+R cannot be greater than 18, even with a carry, So E cannot be 9.

A.Rakesh Babu M.C.A., M.Tech 30

Artificial Intelligence

Suppose E is assigned to the value 2.now in the next cycle the constraint propagator
observes that.

 N=3 since N=E+1.

 R=8 or 9, since R+N (3) +C1 (1 or 0) =2 or12. But N is already 3; the sum of these
non negative numbers cannot be less than 3. Thus R+3+ (0 or 1) =12 and R=8 or 9.

 2+D=Y or 2+D=10+Y from the sum in the right most column.

Like this, we continue for further cycles we will get the solutions. Finally the values
can be assigned to the letters are as follows in the solutions state.
M =1 O=0 R=8 E=5 S=9 N=6 D=7 Y=2

For solving any problem we can approach two methods. One is forward searching
(Initial state- Goal state.) and second one is backward searching (Goal state to initial
State).But sometimes we need combination of these two techniques. It first solves the
major parts of a problem and then solves the small problems. Such type of technique is

The MEANS-ENDS ANALYSIS process is depending upon the direction of

differences between the current state and the goal state. In backward chaining the operator
are selected and then sub goals are setup to establish the preconditions of operators is called
operator subgoaling. The main aim of means-ends analysis is apply the operator’s
recursively, which will reduce the difference between current states to goal state.

1. Compare CURRENT to GOAL. If there is no difference between them then return.
2. Otherwise, select the most important difference and reduce it by doing the following
until success or failure is signaled.
a) Select an untried operator O that is applicable to the current difference. If there are
no operators then single failure.

A.Rakesh Babu M.C.A., M.Tech 31

Artificial Intelligence

b) Select an operator O that is applicable to the current difference. if there are no

operators O to current. Generate two description O-START, a state in while O’s
preconditions are satisfied and O-RESULT that results when O is applied to O-


(O-RESULT, GOAL)) are successful, then signal success and return the result of
concatenating FIRST-PART, O, and LAST-PART.


Consider that there is a robot, which can walk, push objects etc... All the operations can be
performed by the robot are given as follows.


PUSH (obj.loc) at (robot, obj) ^large (obj) ^ at (obj, loc) ^

Clear (obj) ^arm empty at (robot, loc)

CARRY (obj, loc) at (robot, obj) ^ at (obj, loc) ^

Small (obj) at (robot, loc)

WALK (loc) none at (robot, loc)

PICKUP (obj) at (robot, obj) holding (obj)

PUTDOWN (obj) holding (obj) ~holding (obj)

PLACE (obj1, obj2) at (robot, obj2) ^ on (obj1, obj2)

Holding (obj1)

A.Rakesh Babu M.C.A., M.Tech 32

Artificial Intelligence

Suppose that a problem of moving a desk with two things on it from one place to
another place is given to the robot. In order to move the desk the robot can use either the
PUSH operation or the CARRY operation. In the CARRY operation the preconditions we
have objects that should be small. We need to remove two things on the desk. So first
robot walk to desk, then remove the two things, then PUSH the desk to the location we
want and then place two things back on the desk.

Initially, we use the WALK operator for it to move to the desk. Then we use
PICKUP & PUTDOWN to remove the two things on the desk, then PUSH operator
followed by WALK in order to go back to the two things, now use PICKUP and CARRY
to carry the things to the desk and use PLACE operator to place it on the table. The
progress of MEANS-ENDS ANALYSIS is as follows.



A.Rakesh Babu M.C.A., M.Tech 33

Artificial Intelligence

To solve complex problems in A.I, we needs

i. Large amount of knowledge is required.

ii. Mechanism for manipulating the knowledge is found a solution to the problem.
There are many ways of representing of knowledge, in any representation there are
two different kinds of entities:

a) Facts: truths in some relevant world.

b) Representation of facts in some logic
To structure the above two entities has two levels.

 The knowledge level, at which facts are described.

 The symbol level, at which representation of objects in terms of symbols.

The mapping between facts representation are shown in the below figure. The
mappings that are having the links in the program are called as representation mappings.
Facts Internal
Reasoning programs

English understanding English generation


Fig. mapping b/w facts and representation

In the above figure there are two representations.

i. Forward: - The forward representation explains logic facts to logic.

ii. Backward: - The backward representation explains logic to facts.

A.Rakesh Babu M.C.A., M.Tech 34

Artificial Intelligence

Apart from these representations English representation is also required to

understand easily.

Example: - consider the English sentence.

Spot is a dog.
The fact is represented by English sentence can also be represented in logic as

Dog (Spot).
Suppose consider another fact as
All dogs have tails.

X: dog(x)  has tail(x).

From above two facts which are represented in logic. We can write as

Has tail (spot).

Using backward mapping we could generate the English sentence.

Spot has tail.

The above explanation is clearer with following diagram.

Desired real reasoning

Initial Initial
facts -- facts

Forward Backward

* Represent Represent *

Mapping Mapping

Internal Internal
representation representation
of initial facts of final facts
Operation of program

Fig - Representation of facts

A.Rakesh Babu M.C.A., M.Tech 35

Artificial Intelligence

In the figure there is a dotted line originating from initial facts to final facts. This is
an abstraction. In order to get final facts firstly, the initial facts are to be represented in
some logic done on this logic. And some reasoning has to be done on this logic. That gives
final fact in logic. Now using backward representation we convert the final facts, which are
in logic in the understandable way.


A good system for the representation of knowledge in a particular domain it should
contain following properties.
i. Representational Adequacy: - The ability of representation all kinds of
knowledge that are needed in that domain.
ii. Inferential Adequacy: - The ability to manipulated the representational structures
in such a way we can derive new structure from old.
iii. Inferential Efficiency: - The ability to add a new info the database to work in best
iv. Acquisition Efficiency: - The ability acquires new information easily.

Knowledge Representation Mechanism:

Simple Relational Knowledge:
The simple way to represent the facts is as a set of relations as we do in the

Player Height Weight Bats-Throws

Hank Aaron 6.0" 180 right-right

Willie Mays 5.10" 170 right-right

Babe Ruth 6.2" 215 left-left

Ted Williams 6.3" 205 left-right

Fig: Simple Relational Knowledge:

Representing the facts in this way is simple but it provides weak inference
capability because even if cannot answer a simple questions like “Who is a heaviest
player?” In order get the answer for this question we need to add some another procedure.
A.Rakesh Babu M.C.A., M.Tech 36

Artificial Intelligence

Inheritable Knowledge:-

It is not possible in referential representation to represent objects, attributes and their

values. But inheritable knowledge representation allows this type of representation.

The following figure about baseball domain.

Person Right

Male 5-10

Height 6-1

Equal to bats
Handed player batting-avg


Isa Isa

.106 Pitcher Fielder

Instance Instance

Team Pee-wee- Team Brooklyn-

Chicago Three-finger-
cubs brown Reese dodgers

Fig: Inheritable knowledge.

 Lines represent attributes

 Boxed nodes represent objects and values.

A.Rakesh Babu M.C.A., M.Tech 37

Artificial Intelligence

The structure shown in figure is called slot-and-filter structures. It may also call as
“semantic network” or “collection of frames”. Two important attributes that we use in
the figure are
i. Isa: - used to show “class inclusion”, which means that which class is
derived from which class.
ii. Instance: - used to show “class membership”. That can be used to create an
object to a particular class. The following are the attributes for a base-ball
Isa: Adult male
Instance: (Equal, Handed)
Height: 6-1”
Batting-avgas: 252.

To retrieve value ‘V’ for instance A of an instance object ‘O’
1) Find ‘O’ in knowledge base.
2) If there is a value for the attribute A, report that value.
3) Otherwise, see if there is a value for the attribute instance. If not, then fail
4) Otherwise, move to the node corresponding to that value and look for a value for
the attribute A. if one is found, report it.
5) Otherwise, do until there is no value for the “Is a” attribute or until an answer is
a) Get the value “Isa” attribute and move to the node.
b) See if there is no value for the attribute A. if there is a report.
If we apply this procedure to the base-ball example knowledge base to derive
answer to the following queries:
Team (pee-wee-Reese) = Brooklyn dodgers
This attribute value is directly obtained from the attribute team. This attribute has
a value stored explicit in the knowledge base.

Team (pee-finger-brown) = .106

Because there is no value for batting average stored explicitly for three-finger-
brown. We have to follow the attribute instance to obtain the value of that attribute.
A.Rakesh Babu M.C.A., M.Tech 38

Artificial Intelligence

Height (pee-wee-Reese) = 6-1

Because there is no explicit value for height we have to follow the value. So we
follow attribute ‘is a’ to obtained the value
Bats (three-finger-brown) =right
Because there is no value for data stores explicitly for the three-finger-brown we
have to follow the attribute instance to obtained the value of that attribute and there is ‘Is a’
to obtained value. This algorithm is so simple and we concentrate on only default values.

Inferential Knowledge:-
Property of inheritance is a powerful from of inference but it is not only
the useful from some times the traditional logic like predicate logic is also used to derive
new facts from old facts.
Example: x, y batter(x) ^ batted (x, y) ^infield-fly (y)out(x)

Procedural knowledge:-
We can represent the knowledge in a procedural way also. Production rules are the
best techniques to represent the knowledge in a procedural ways.
Example: Water jug problem
If x < 4 then fill x.
If x < 3 then fill y.


To represent varies kinds of real –world knowledge. We need to discuss several
issues. They are as follows.
1) Important attributes.
2) Relationship among attributes.
3) Choosing the granularity of representation.

4) Representing set of objects.

5) Finding the right structure as needed.

Important attributes:
Isa and instance attributes are important because they are present in almost every
problem domain. These attributes are important because they support property inheritance.

A.Rakesh Babu M.C.A., M.Tech 39

Artificial Intelligence

Relationship among Attributes:

The four properties of attributes are:

 Inverse.

 Existence in an Isa hierarchy.

 Techniques for reasoning about values.

 Single value attributes.

Inverse: -
We can represent the relationship between entities in two ways.
a) The first is to represent both the relationship in a single representation.
Ex: team (pee-wee, Brooklyn dodgers).
b) Here we use attributes that focus on a single entity but use them in a pairs. One
is the inverse of the other. For example,
One associated with pee-wee-Reese

Team = Brooklyn-dodgers.
One associated with Brooklyn-dodgers
Team-members = pee-wee-Reese
As our primitives in a series of situations.
Existence in an isa hierarchy:
There are attributes and specification of attributes. For example the attribute height
is a specialized of general attribute physical size which is in turn a specialization of
physical attribute. This generalization-specialization relationship supports property
Techniques for Reasoning About values:
The reasoning system must reason about values that are not given explicitly.
Information that helps us in reasoning includes.

a. Information regarding a type of value

Example: Length must be a number.
b. Constraints on the value
A.Rakesh Babu M.C.A., M.Tech 40

Artificial Intelligence

Example: Age of a person cannot be greater than the age of the person’s

c. Rule for computing the value whenever it is required. They cannot be backward
rules or they can also be forward rules.

Single value attributes:

A specific attribute may sometime take unique value. For example, a base ball
player can be in only one team at one time. Similarly another example, a person can have
only one height at a given time.

Choosing the Granularity of Representation:

We can break the details into lower level primitives. For example, john spotted sue
can be represented as
Spotted ((john)) object (sue) this may give answer to the question.
Who spotted sue?

But it cannot be answer: Did john see sue?

The obvious answer that may give is ‘yes’
But for A.I to reason it out we need to add fact.
Spotted (x, y)  saw (x, y)
The rules that are used to derive inferences from that knowledge must be written only
in the form of primitives rather than in the form of many other ways.
 Simple high level facts may requires a lot of storage when broken down into low
level primitives.
Example: john punched Mary and Mary punched john.
 Substantial work must be done to reduce the knowledge into primitive’s form, if
knowledge I in high level form.
 In many domains, it is not clear what the low level primitives should be
Example: john broke the window.

A.Rakesh Babu M.C.A., M.Tech 41

Artificial Intelligence

Representing Sets of Objects:-

We need to represent sets of object because there may be some properties which are
true of sets but are not true of individual members and also to see that if a property is true
of all elements of a set, then it is more efficient to associate it once with the set rather than
to associate it explicitly with every element of set.

There are two ways to define a set and its elements.

Extensional definition: - This definition deals with listing the members.
Intentional definition: - It provides a rule such that, when a particular object is evaluated,
returns true or false depending on weather the object s belong to the set or not.

Ex: an extensional definition of the set of our sun’s planets on which people live is [earth]
an intentional description is given as

{X: sun-planet(x) ^ human-inhabited (x)}

An extensional definition and intentional definition may not correspond one to one
with each other. In the above example the extensionally defined set {earth} may have any
intentional definitions.

The advantages that an intentional definition has over extensional definition are….
a. Intentional representations’, can be describe infinite sets and sets not all of
whose elements are explicitly know.
Ex: Sets of prime numbers or kings of England.

Intentional definition allows us to depend on parameters that can be change with time or
Ex: “The president of U.S used to be pemcrot”.

Finding the right structures as needed:

In order to access the right structure for describing a situation, we need to solve the
following problems:
i. How to perform an initial selection of the most current structure?
ii. How to fill in the details?
iii. If the one chosen doesn’t turn out to be appropriate, then how do we go for a better
iv. What to do if none of the structures that are available is appropriate?
v. When we can go for a new structure?

A.Rakesh Babu M.C.A., M.Tech 42

Artificial Intelligence

In order to solve the problems given above, there are two methods.

 Selecting an initial structure:

There are two important structures for selection of an initial structure.
a. Index structure directly by specific English words.

Ex: john flew to New York.

b. Consider a major concept as a pointer to all of the structure
Ex: the concept steak might point to two scripts, one for restaurant and other
for super script.

c. Locate one major clue and use that to select an initial structure.

 Revising the choice when necessary:-

Once we find a structure and if it doesn’t seem to be appropriate then we would opt
another choice. The different ways in which this can be done are:

 Choose the best one.

 Refer to specify links between the structures in order to follow new directions to

Frame problem is a problem of representing the facts that change as well as
those that do not change. For example, consider a table with a plant on it under a window.
Suppose we move it to the centre of the room. Here we must infer that plant is now in the
centre but the window id not.
Frame axioms are used to describe all the things that do not change operator
is applied in state to go to another state say n+1.

A.Rakesh Babu M.C.A., M.Tech 43

Artificial Intelligence

The logical formalism is used to derive new knowledge from old. i.e., we called
mathematical deduction.

For representation of knowledge using logic symbols, such are

“----” Material Implication


“v” or

“^” and

For all

There exits


The use of propositional logic is used to represent the world knowledge.
Propositional logic is simple to deal a decision procedure for the facts. We can easily
represent real-world facts as logical propositions can be written as well-formed formulas
(wff’s) in Propositional logic. Some simple facts in propositional logic as follows.

It is raining
It is sunny.
It is windy.

If it is raining, then it is not, sunny.

A.Rakesh Babu M.C.A., M.Tech 44

Artificial Intelligence

Suppose we want to represent the fact by the classical sense.

Socrates is a man.
We could write as

Plato is a man.
The above facts can be represent as much better as

Man (Socrates)
Man (Plato)
But that representation is fails to capture the relationship between and individual
being a man and that individual being a mortal. We need variables and quantifiers to
represent logic. In predicate logic, we can represent real-world facts as statements
written as wff’s. So now we explore the use of predicate logic as a way of representing
knowledge by a specific example.

Consider the following set of sentence:

1. Marcus was a man

2. Marcus was a Pompeian
3. All Pompeian’s were Romans
4. Caesar was a ruler
5. All Romans were either loyal to Caesar or hated him
6. Everyone is loyal to someone.
7. People only try to assassinate ruler they are not loyal to
8. Marcus tried to assassinate Caesar

The above facts can be represented as a set of wff’s in predicate logic as follows.

1. Man (Marcus)
2. Pompeian (Marcus)
3. x: Pompeian(x)->roman(x)
4. Ruler (Caesar)
5. x: Roman(x) ->loyal to(x, Caesar) V hate(x, Caesar)
6. x: y: loyal to(x, y)
7. x: y: Person(x) ^ruler(y) ^ try assassinate(x, y)
8. Loyal to(x, y)
9. Tryasssainate (Marcus, Caesar)

A.Rakesh Babu M.C.A., M.Tech 45

Artificial Intelligence

Now suppose that we want to use these statements to answer the question.

Was Marcus loyal to Caesar?

Now let’s try to produce a formal proof, reasoning backward from the desired goal.

loyalto (Marcus, Caesar)

^ (7)

Person (Marcus) ^ ruler (Caesar) ^ tryassasinate (Marcus, Caeser)

^ (4)

Person (Marcus)

Try assassinating (Marcus, Caesar)

^ (8)

Person (Marcus)


The specific attributes instance and is a plays an important role in a particularly
useful form of reasoning, property inheritance. The predicate instance is a binary one,
whose first argument is an object and whose second argument is a class to which the object
belongs. But these representations don’t use an explicit is a predicate.

The three ways of representing class membership is as follows.

1. Man (Marcus)
2. Pompeian (Marcus)
3. x: Pompeian(x) ->roman(x)
4. Ruler (Caesar)
5. x: Roman(x) ->loyal to(x, Caesar) V hate(x, Caesar)

1. Instance (Marcus, man)

2. Instance (Marcus, Pompeian)
3. x: instance(x, Pompeian) instance(x, Roman).
4. Instance (Caesar, ruler)
5. x: instance(x, Roman) loyalto(x, Caeser)V hate(x, Caeser)

A.Rakesh Babu M.C.A., M.Tech 46

Artificial Intelligence

1. Instance (Marcus, Man)

2. Instance (Marcus, Pompeian)
3. Isa (Pompeian, Roman)
4. Instance (Caesar, ruler)
5. x: instance(x, roman)loyalto(x, Caesar) V hate(x, Caesar).

The class and super class membership are important facts that need to be represented,
those membership need not to be represented with predicates instance and Isa.


In predicate calculus it is often useful to have computable a functions and
computable predicates for this we want to express simple facts. Such as the following
greater than and less than relationships:

gt(1,0) lt(0,1)

gt(2,1) lt(1,2)

gt(3,2) lt(2,3)

| |

| | . .

For example the simple fact (2+3)>1 might be represented as gt(2+3,1).to calculate
the truth of gt(2+3,1) the value of the plus function is evaluated first and then the
arguments 2+3(=5) and 1 are sent to the computable predicate gt.The use of computable
functions and predicates is illustrated below.

Consider the following set of facts and their representations.

1. Marcus was a man

Man (Marcus)

2. Marcus was a Pompeian

Pompeian (Marcus)

3. Marcus was born in 40 A.D

Born (Marcus, 40 A.D)

4. All men are mortal

x: Men(x) mortal(x)

A.Rakesh Babu M.C.A., M.Tech 47

Artificial Intelligence

5. All Pompeian’s died when volcano erupted in 79 A.D

Erupted (volcano, 79) ^ x :{ Pompeian(x) died(x, 79)}

6. No mortal lives longer than 150 years

x: t1: t2: mortal(x) ^ born(x, t1) ^ gt (t2-t1, 150) ->dead(x, t2)

7. It is now 1991

8. Alive means not dead

x: t: alive (x, t) ->&dead(x, t) ^ [ dead(x, t) ->alive(x,t)]

9. If someone dies then he is died at all later times.

x: t1: t2:died(x,t1) ^gt(t2,t1)->dead(x,t2)

The above predicates can be represented as set of facts as follows.

1. Man (Marcus)
2. Pompeian (Marcus)
3. Born (marcus,40)
4. x: men(x)mortal(x)
5. x: Pompeian(x)died(x,79)
6. Erupted (volcano, 79)
7. x: t1: t2: mortal(x)^born(x, t1)^ gt(t2-t1,150)died(x,t2)
8. Now=1991
9. x: t:[alive(x, t) dead(x, t)]^[ dead(x,t)alive(x, t)]
10. x: t1: t2:died(x,t1)^ gt(t2,t1)dead(x,t2)

A.Rakesh Babu M.C.A., M.Tech 48

Artificial Intelligence

Now let’s attempt to answer the question “Is Marcus alive?” By proving

alive(Marcus, now)

alive(Marcus, now)


Dead (Marcus, now)


Died (Marcus, t1) ^ (gt (now, t1)


Pompeian (Marcus) ^ gt(now,79)


gt (now, 79)


gt (1991, 79)

(Compute gt)


From looking at the proof we have just shown, two things should be clear.

- Even a sample conclusion requires many steps to prove

- A variety of processes such as matching, substitution and application modus
pones are involved in the production of proof.

(Modus ponenes is an important inference rule. it is the operation that produces the wff w2
from wff of the form w1 and w1->w2)

The term nil at the end of the proof indicates that the list of conditions remaining to
be proved to be approved is empty and so the proof has succeeded.

A.Rakesh Babu M.C.A., M.Tech 49

Artificial Intelligence

Resolution is a procedure to prove a statement. It specifies the proof procedure by
first converting the statements into a clause form (convenient standard form).Further it
produces proofs by “refutation” i.e., it attempts to show that the negation of the statement
produces a contradiction with the known statements.

Conversion to clause form:

Resolution can be applied to certain class of wff’s called “clauses.” a clause is
defined as a wff’s consisting of a disjunction of literals. The resolution process when it is
applicable is applied to as pair of parent clauses to produce a derived clause.

Suppose that there are two parent clauses in the system.

Winter V summer

~Winter V cold

In these two clauses either winter or ~winter is going to be true at any point. If
winter is true then cold must be true to guarantee the truth of the second clause. If ~winter
is true, then the summer must be true to guarantee the truth of the first clause. Thus from
these two clauses we can deduce the resolve.

Summer V cold

Resolution procedure operates by taking two clauses that each contains the same
literal. The literal must occur in positive from in one clause and in negative form in the
order. The resolving is obtained by combining all of the literals of the two parent clauses
except the ones that cancel. If the clause that is produced is

An empty clause, then a contradiction has been found.


1. Eliminate , using the fact that ab is equivalent to a v b. Perform this

transformation on the well formed formula, then the formula will becomes as,
x: [Roman(x) ^ know(x, Marcus)] v
[ hate(x, Caesar) v ( y: ( y: hate(y, z)] v think crazy (x, y))]
2. Reduce the scope of search of each (negation) to a single term, using facts,

A.Rakesh Babu M.C.A., M.Tech 50

Artificial Intelligence

( p) = p

(a ^ b) = av b

(a v b) = a^ b

x: a(x) = x: a(x)

x: a(x) = x: a(x)

Perform these transformations on the well formed formula, then it becomes,

x: [ roman(x) v know(x ,Marcus)] v
[hate (x, Caesar) v ( y: z: hate(y, z) v thinkcrazy(x, y))]
3. Standardize variable so that each quantifier binds a unique variable. for example, the
x: P (a) v a: Q (a) will be converted to

x: p (a) v b: Q(b)

This step can be used in the next step.

4. Move all quantifiers to the left of the formula without changing their relative order.
performing this operation on the formula of step 2, gives

x: y: z: [ Roman(x) v know(x, Marcus)] v

[hate (x, Caesar)v( hate (y ,z)v think crazy(x, y))]
5. Eliminate existential qualifiers. for example the formula
y: President(y)
Can be transformed into the formula,
President (S1)
Where S1 is a function with no arguments that somehow produces a value that satisfies
6. Drop the prefix .the formula produced in step 4 will become as,
[ Roman(x) v know(x, Marcus)] v
[ hate(x, Caesar) v ( hate(y,z) v thinkcrazy(x, y))]

A.Rakesh Babu M.C.A., M.Tech 51

Artificial Intelligence

7. Convert the matrix into a conjunction of disjoints the formula produced in step(6) will
become as (here we can remove the brackets)
Roman(x) v know (x, Marcus) v
hate(x, Caesar) v hate(y, z)v thinkcrazy(x, y).
( we applied [a v (b v c) = (a v b) v c] (associative property))
It is also frequently necessary to exploit the distributive property
i.e. (a ^ b) v c = (a v c) ^ (b v c)
[winter v (summer ^ wearing sandals) ]
^ [wearing boots v (summer ^ wearing sandals)]
8. Create a separate clause corresponding to each conjunct.
9. Standardize apart the variables in the set of clauses which are generated in step (8).

Resolution in proposition logic:

In proposition logic, the procedure to produce a proof by resolution of preposition P
with respect to a set of axioms f is the following:

1. Convert all the proposition of f to clause form

2. Negate p and convert the result to clause form add it to the set of clauses obtained in

3. Repeat until either a contradiction is found or no progress can be made:

a. Select two clauses. Call these the parent clauses,

b. Resolve them together. The resulting clause, called the resolving, will be the
disjunction of all the literals of both of the parent clauses.

c. If the resolving is the empty clause, then a contradiction has been found. If it is
not, then add it to the set of clauses available to the procedure.

A.Rakesh Babu M.C.A., M.Tech 52

Artificial Intelligence


Given axioms Converted to clause form

P P (1)

(P ^ Q)->R Pv Q^R (2)

(S^ T)->Q SVQ (3)

TVQ (4)

T T (5)

Fig: A few facts in proposition logic

The following figure shows the generation of the sequence of resolvents.

Pv qvR R




{ }

Fig: Resolution in propositional logic

A.Rakesh Babu M.C.A., M.Tech 53

Artificial Intelligence

In propositional logic, it is easy to determine that two literals cannot both be true at
the same time. Simply look for L and L. In predicate logic, this matching process is more
complicated since the arguments of the predicates must be considered. For example,
man (john) and man (john) is a contradiction, while man (john) and man (spot) is not.
To determine these contradictions, we need a matching procedure that compares two
literals and discovers whether there exists a set of substitutions that makes them identical.
There is a straight forward recursive procedure that does this matching. It is called
unification algorithm.

To unify two literals, we first check if their initial predicate symbols are the same. If
same, we proceed. Otherwise there is no way they can be unified. For example two literals

tryassasinate (Marcus, Caesar)

hate (Marcus, Caesar)

Cannot be unified. If the predicate symbols are match, then we check the arguments, one
pair at a time.

The matching rules are:

1. Different constants, functions or predicates cannot match, where as identical ones

2. A variable can match another variable, any constants or a function or predicate
expression, subject to the condition that function must not contain any instance of
variable being matched.
3. The substitution must be consisting. substitute y for x now and then z for x later is
inconsistent(a substitution y for x written as y/x)

The unification procedure UNIFY (L1, L2), which returns a list

representing a composition of the substitutions that were performed that a match was found
any substitutions .if the list unification procedure failed.


UNIFY (L1, L2)

1. If L1 or L2 are both variables or constants, then:

a) If L1 and L2 are identical, then return NIL

A.Rakesh Babu M.C.A., M.Tech 54

Artificial Intelligence

b) Else if L1 is a variable, then if L1 occurs in L2 then return {FAIL}, else return


c) Else if L2 is a variable, then if L2 occurs in L1 then return {FAIL}, else return


d) Else return {FAIL]

2. If the initial predicate symbols in L1 and L2 are not identical, then return {FAIL}.

3. If L1 and L2 have a different number of arguments, then return {FAIL}.

4. Set SUBST to NIL. (At the end of this procedure, SUBST will contain all the
substitutions used to Unify L1 and L2.

5. For i 1 to number of arguments in L1:

th th
a) Call Unify with the i argument of L1 and the i argument of L2, putting
result in S.

b) If S contains FAIL then return {FAIL}.

c) If S is not equal to NIL then:

1. Apply s to the reminder of both L1 & L2.


6. Return SUBST.

Resolution in Predicate Logic:

Two literals are contradictory if one can be unified with the negation of the other.
for example man(x) and &man(spot) are contradictory, since man(x) and man(spot) can be
unified .in predicate logic unification algorithm is used to locate pairs of literals that cancel
out. if is important that of two instances of the same variable occur, they must be given
identical substitutions. The resolution algorithm for predicate logic as follows.

Let us assume a set of give statements F and a statement to be proved P.

A.Rakesh Babu M.C.A., M.Tech 55

Artificial Intelligence


1. Convert all the statements to F to clause form

2. Negate P and convert the result to clause form add it to the set of clauses obtained in

3. Repeat until either a contradiction is found, no progress can be made.

a) Select two clauses. Call these two parent clauses.

b) Remove them together. The resulting clause, called the resolvent, will be the
disjunction of all the literals of both of the parent clauses. If there is a pair of literals T1 and
T2 such that one parent clauses contains T1 and other contains T2 and if T1 and T2 are
unifable, then neither T1 nor T2 complementary literals.

c) If the resolving is the empty clause, then a contradiction has been found. If it is
not, then add it to the set of clauses available to the procedure.

Using resolution to produce proof is illustrated in the following clause forms:

1. Man (Marcus)

2. Pompeian (Marcus)

3. Pompeian(x1) ->roman(x1)

4. Ruler (Caesar)

5. Roman(x2) V loyal to(x2, Caesar) hate(x2, Caesar)

6. loyalto(x3, f1(x3))

7. Man(x4) v ruler (y1) v try assassinate(x4, y1) V loyalto (x4, y1).

8. tryasssainate (Marcus, Caesar)

A.Rakesh Babu M.C.A., M.Tech 56

Artificial Intelligence

Prove: hate (Marcus, Caesar)

hate (Marcus, Caesar) 5


3 Roman (Marcus) v loyalto (Marcus, Caesar)


Pompeian (Marcus) V loyalto (Marcus, Caesar) 2

Loyal to (Marcus, Caesar) 7

Marcus/x4, Caeser/y1

1 man (Marcus) V (ruler (Caesar) V tryassasiante (Marcus, Caesar)

ruler (Caesar) V tryassasinate (Marcus, Caesar) 4

8 tryassasinate(marcus,Caeser)

{ }

A.Rakesh Babu M.C.A., M.Tech 57

Artificial Intelligence

Natural Deduction
The disadvantage of Predicate logic is i.e., it is not having any inference programs. So we
have to make use of a resolution outcome, but the resolution is in clause form. By using
clause form, the original meaning be destroyed or changed.

Ex: If we consider the statement ab means that b is depending only on existing of a. i.e.,
b is dependent on a. But as we convert the system into clause form we can has a v b. The
symbol “v” (OR) is we have to prove either a as true. i.e., the statement is true. The
whole statement is considered as b is not depends on a. So, this statement is reverse of the
first statement (a b).Suppose we represent the statement into natural deduction the
meaning of the sentence may not be changed.

A.Rakesh Babu M.C.A., M.Tech 58

Artificial Intelligence

We have to represent the knowledge in two ways. They are

1. Declarative knowledge

2. Procedural knowledge

In the declarative knowledge, how to make use of knowledge is not to specify.

In the procedural knowledge, how to make use of knowledge can be embedded in

the representation itself.

Procedural knowledge is PROLOG (programming logic) and it follows backward

chaining method.

Ex: consider the following statements.

1. Man (Caesar)

2. Man (Marcus)

3. person (Cleopatra)

4. x: man(x)  person(x)

The above statements converted into PROLOG programs are:

1. Man (Caesar)

2. Man (Marcus)

3. Person (Cleopatra)

4. x: man(x)  person(x)

A predicate logic statement is always explicitly quantified and PROLOG programs

are always implicitly quantified.

A.Rakesh Babu M.C.A., M.Tech 59

Artificial Intelligence

Convert the following statements (Predicate logic) into PROLOG

1. x: pet(x) ^ small(x) apartment(x)

2. x: cat(x) ^ dog(x)  pet(x)

3. x: poodle(x)  dog(x) ^ small(x)

4. Poodle (fluffy)

The predicate logic forms can be converted into PROLOG programs as follows

1. Apartment (x): - pet (x), small (x)

2. a) pet(x):- cat(x)

b)Pet(x):- dog(x)

3. a)dog(x) :- poodle(x)

b)Small(x):- poodle(x)

4. Poodle (fluffy)

The following constrains can be used to convert the predicate logic statements into
PROLOG programs

(i) ab = b: -a
(ii) Implication before ^ => put, (comma)
(iii) Implication after ^ => write as 2 stmts
(iv) Implication before v => write as 2 stmts
(v) Implication after v => put , (comma)

Convert the following predicate logical stmts into PROLOG programs

1. x: y : Cat(x) ^ Fish(y)  Likes(x, y)

2. x: Calico(x)  Cat(x)

3. x: Tuna (x)  Fish(x)

4. Tuna (Charley)

5. Tuna (Herb)

6. Calico (Pussy)

A.Rakesh Babu M.C.A., M.Tech 60

Artificial Intelligence

PROLOG programs:

1. Likes (x, y): - cat (x), fish (y)

2. Cat(x) :- calico (x)
3. Fish (x): - tuna (x)
4. Tuna (charley)
5. Tuna (herb)
6. Calico (pussy)

Using backward chaining find “what does pussy likes to eat?” for this consider

likesto(x, y)

Likesto (pussy, x) (1)

Cat(x), fish(y)

(2) Cat (pussy), fish(x)

(6) Calico (pussy), fish(x)

Fish(x) (3)

Tuna(x) (4)

{ } x= charley

--Pussy likes to charley .

A.Rakesh Babu M.C.A., M.Tech 61

Artificial Intelligence

Consider the following stmts

1. John likes all kinds of food

2. Apples are food
3. Chicken is a food
4. Anything anyone eats and is not killed by his food
5. Bill eats peanuts and is still alive
6. Sue eats everything bill eats

The stmt’s in predicate logic are as follows:

1. x: food (x)  likes (John, x)

2. food (Apples)
3. foods (Chicken)
4. x : y : eats (x, y) ^ killed (x, y) food(x)
5. a) eats (Bill, Peanuts)
b) killed (bill, peanuts)
6. x : eats (Bill, x)  eats (Sue, x)

PROLOG programs:

1. likes (John, x) :- food(x)

2. food (Apples)
3. food (Chicken)
4. food(x) :- eats (x, y), killed(x ,y)
5. a) eats (Bill, Peanuts)
b) killed (Bill, peanuts)
6. eats(Sue, x) :- eats (Bill, x)

Horn clause
The logical assertion in the PROLOG language is the set of horn clauses. A positive
literal is called horn.

a v b, a v b, a v b, ab => horn clauses.

a v b => not horn clause

In the PROLOG statements, there is no logical assertion. The only assertion is horn
clause. In this stmts, the variables can be referred in capital letters and the constants are
denoted to small letters.

1. x : pet (x) ^ small (x) apartment(x)

2. x : cat(x) ^ dog(x) pet(x)
A.Rakesh Babu M.C.A., M.Tech 62

Artificial Intelligence

3. x : poodle(x)  dog(x) ^ small(x)

4. poodle (fluffy)

Find the variable x.

Convert the above statements into horn clause

Apartment(x) (1)

2(a) pet(x), small(x)

3(a) dog(x), cat(x) small(x) 3(b)

(4) Poodle(x) it is dead end poodle(x) (4)

{ } x=fluffy x=fluffy { }

In the above example we get 2 alternatives pelf(x), small(x). First we start with the
first sub goal pet(x). It again contains 2 sub goals dog(x), cat(x). If we go on proceeding
with cat(x) we get a dead end. PROLOG programming starts with root node.

It finds a fact (or) the left hands of the rules to match with the root node, if a rule is
found the R.H.S will be the resolvent.

In the above example three are 2 sub goals pet(x) and small(x) in the resolvent. If
both of the sub goals are true then a value for a variable ‘y’ can be found. Consider a sub
goal pet(y) with has 2 alternatives with

Pet(x):- cat(x) and

Pet(x); - dog(x)

A.Rakesh Babu M.C.A., M.Tech 63

Artificial Intelligence

A PROLOG tries with the first alternative until a dead end is reached or a solution
is found. The first alternative leads to a dead end in the above example and ‘y’ is bounded
to a value fluffy when second alternative is explores.

The aim of search procedure is to discover a path through a problem space from an
initial configuration to a goal state. There are actually 2 directions in which a search colud

a) Forward Reasoning
b) Backward Reasoning
a). Forward Reasoning:

When we have set of input to prove current situation. Those are applied on the
initial state. The forward rules encode the knowledge when certain input conditions are

Ex. Water jug problem

b). Backward reasoning:

These rules are used to sub goals-backward rules are the rules which encode the
knowledge when sub goals are true.

Eg. Whether Marcus is alive or not ?

The following factors that influence the question of whether it is better to reason
forward or backward.

i) Are there more possible start states or goal state?

We prefer to move from the smaller set of states to the largest set of states.
ii) In which directions is the branching factor greater?
(Branch Factor: - the average no of nodes that can be reached directly from a single node.)
We refer to proceed in the direction with the lower process to a user.
iii) Will be program be asked to justify its reasoning process to a user?
It is important proceed in the direction that corresponds more closely with the way
the user will think.
iv) What kind of event is going to trigger a problem solving proceeds?

The forward reason makes sense if it is a query to which a response is desired

backward reasoning is more natural.

A.Rakesh Babu M.C.A., M.Tech 64

Artificial Intelligence

Backward chaining rule systems :

They are good for goal directed problem solving. For example a query system would
probably use backward chaining to reason about answer user questions.

Examples of these systems are PROLOG and MYCIN.

Forward-chaining rule systems:

Forward chaining rule system left sides of rules are matched against the state description.
Rules that match dump their right hand side assertion into the state, and process repeats.
Matching is typically more complex chaining system that backward once .

Matching is a process of comparing two or more structures to discover their
difference or similarities. Matching is used to the best of a no of alternatives or retrieves
items from a database or knowledgebase. Different matching processes are,

 Indexing
 Matching with variables
 Complex and approximate matching
 Conflict resolution


In indexing the correct state is used as an index into the rules in order to select the
matching once. For example in chess, we assign a no to each board position. Then we use a
hosting function to treat the no as an index into the rules.

Matching with variables:

In this case we will match many rules against many elements in the state description
simultaneously. One efficient algorithm RETE, which gains efficiency from three major

I. The temporal nature of data:

Whenever we apply a rule on the current state. Some properties will be added
and some other properties are deleted and some times the rule will not be applicable.
If no rule will not be applicable to the problem, the RETE process will tell
which rule applicable to the pre-state is not applicable to the current state.

A.Rakesh Babu M.C.A., M.Tech 65

Artificial Intelligence

II. Structural similarities in rules:

In the similarities of the rules, data can be considered as

i) Tiger(x)  mammal(x) ^ stripes(x) ^ carnivorous(x)

ii) Jaguar(x) mammal(x) ^ sports (x) ^ carnivorous(x)

Eg. For this consider

Frame-I frameII
Similarities similarities
Mammal(x) stripes(x)
Carnivorous(x) sports(x)
In RETE process , first we have to verify the dissimilarities rules and after that we
verify the similar rules and also we have to identify which rule have less no of sub goals
and which rule has more no of sub goals.

III. Persistence in binding up of variables:-

There may be variable binding conflicts that prevent the rule from firing. For
example, consider the following facts.
Son (john, David)

Son (bill, Ellen) and we can compare to son(x,y) and son(y,z)

The individual preconditions of the rule is
x: y : son(x, y) ^ son(y, z)grandparent(y, z).
Where x=John and y=David.
For this first time, x, y has initial values after the completion of first predicate here
x,y are binded variables.
For the second time, if y=bill which is not accepted because ‘y’ has already a value is
given. So, we can not give another value ‘y’. Therefore, ‘y’ is a binding up variable.
The RETE takes the binding up of variables to the problem solving.

A.Rakesh Babu M.C.A., M.Tech 66

Artificial Intelligence

Complex and Approximate Matching :

An approximate matching is one which used, when the pre conditions
approximately match the current situation.
One of the complex problem, we can take as a speech understanding. It understand
the word and proceedings the matching. If that time it takes appropriate words.
The conversion between ELIZA, an A.I problem and the user. Here ELIZA will try
to match the left side of the rule against the sentence and use the correct right side rule to
generate a response. Let us considering the following ELIZA rules.
(x me y)(X you y)
(I remember x)(Why do remember x just now?)
(My family –member is y)(Who else is your family is y?)
Suppose the use say “I remember Mary”. How ELIZA will try to match the above
response to the left hand side of the given rules. It finds that it matches to the first rule and
now it take the right hand side ask, “Why do remember Mary just now?” This is the why
how the conversion proceeds taking into consideration the approximate matching.

Conflict Resolution:
The conflict resolution is a strategy in which we incorporate the decision making
into the matching process. We have three basic approaches.

a) Preference based on rules:

Here we consider the rule in the order they are given or we given some priority
to special case rules.

b) Performance based on object:

Here we use key words to match into the rules. Consider the example of

c) Performance based on states:

In this case we consider all rules that are waiting, which gives some states.
Here a heuristic function we can decide which state is the best.

Control Knowledge:
Knowledge about which paths are most likely to lead quickly to a goal state is often
called, search control knowledge. It can take many forms.

 knowledge about which states are more preferable to others

 Knowledge about which rule to apply in given situation.
 Knowledge about the order in which to achieve sub goals
 Knowledge about useful sequence of0 rules to apply
A.Rakesh Babu M.C.A., M.Tech 67

Artificial Intelligence

Control knowledge is also called as Meta knowledge that is knowledge about

knowledge. Two systems which represent control knowledge with rules are SOAR and

a) Long-term memory:
It contains all the set of productions or rules.

b) Short-term memory:
It is also called as working memory. In this the facts are deducted by rules.
c) All problems solving activity takes place as a state space traversal i.e. which rule to
be applied.
d) It keeps track of all the intermediate and the final result.

A.Rakesh Babu M.C.A., M.Tech 68