0% found this document useful (0 votes)
17 views

Artificial Intelligence

ai document

Uploaded by

Rushikesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Artificial Intelligence

ai document

Uploaded by

Rushikesh
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 51

ARTIFICIAL INTELLIGENCE

What is Artificial Intelligence?

It is a branch of Computer Science that pursues creating the computers or machines as intelligent

as human beings.

It is the science and engineering of making intelligent machines, especially intelligent computer

programs.

It is related to the similar task of using computers to understand human intelligence, but AI does

not have to confine itself to methods that are biologically observable

Definition: Artificial Intelligence is the study of how to make computers do things, which, at the

moment, people do better.

According to the father of Artificial Intelligence, John McCarthy, it is “The science and

engineering of making intelligent machines, especially intelligent computer programs”.

Artificial Intelligence is a way of making a computer, a computer-controlled robot, or a

software think intelligently, in the similar manner the intelligent humans think.

AI is accomplished by studying how human brain thinks and how humans learn, decide, and

work while trying to solve a problem, and then using the outcomes of this study as a basis of

developing intelligent software and systems.

It has gained prominence recently due, in part, to big data, or the increase in speed, size and

variety of data businesses are now collecting. AI can perform tasks such as identifying patterns

in the data more efficiently than humans, enabling businesses to gain more insight out of

their data.

From a business perspective AI is a set of very powerful tools, and methodologies for using

those tools to solve business problems.

From a programming perspective, AI includes the study of symbolic programming, problem

solving, and search.

AI Vocabulary

Intelligence relates to tasks involving higher mental processes, e.g. creativity, solving problems,

pattern recognition, classification, learning, induction, deduction, building analogies,

optimization, language processing, knowledge and many more. Intelligence is the computational

part of the ability to achieve goals.

Intelligent behaviour is depicted by perceiving one’s environment, acting in complex


environments, learning and understanding from experience, reasoning to solve problems and

discover hidden knowledge, applying knowledge successfully in new situations, thinking

abstractly, using analogies, communicating with others and more.

Science based goals of AI pertain to developing concepts, mechanisms and understanding

biological intelligent behaviour. The emphasis is on understanding intelligent behaviour.

Engineering based goals of AI relate to developing concepts, theory and practice of building

intelligent machines. The emphasis is on system building.

AI Techniques depict how we represent, manipulate and reason with knowledge in order to

solve problems. Knowledge is a collection of ‘facts’. To manipulate these facts by a program, a

suitable representation is required. A good representation facilitates problem solving.

Learning means that programs learn from what facts or behaviour can represent. Learning

denotes changes in the systems that are adaptive in other words, it enables the system to do the

same task(s) more efficiently next time.

Applications of AI refers to problem solving, search and control strategies, speech recognition,

natural language understanding, computer vision, expert systems, etc.

Problems of AI:

Intelligence does not imply perfect understanding; every intelligent being has limited perception,

memory and computation. Many points on the spectrum of intelligence versus cost are viable,

from insects to humans. AI seeks to understand the computations required from intelligent

behaviour and to produce computer systems that exhibit intelligence. Aspects of intelligence

studied by AI include perception, communicational using human languages, reasoning, planning,

learning and memory.

The following questions are to be considered before we can step forward:

1. What are the underlying assumptions about intelligence?

2. What kinds of techniques will be useful for solving AI problems?

3. At what level human intelligence can be modelled?

4. When will it be realized when an intelligent program has been built?

AI Technique:

Artificial Intelligence research during the last three decades has concluded that Intelligence

requires knowledge. To compensate overwhelming quality, knowledge possesses less desirable


properties.

A. It is huge.

B. It is difficult to characterize correctly.

C. It is constantly varying.

D. It differs from data by being organized in a way that corresponds to its application.

E. It is complicated.

An AI technique is a method that exploits knowledge that is represented so that:

 The knowledge captures generalizations that share properties, are grouped

together, rather than being allowed separate representation.

 It can be understood by people who must provide it—even though for many

programs bulk of the data comes automatically from readings.

 In many AI domains, how the people understand the same people must supply the

knowledge to a program.

 It can be easily modified to correct errors and reflect changes in real conditions.

 It can be widely used even if it is incomplete or inaccurate.

 It can be used to help overcome its own sheer bulk by helping to narrow the range

of possibilities that must be usually considered.

In order to characterize an AI technique let us consider initially OXO or tic-tac-toe and use a

series of different approaches to play the game.

The programs increase in complexity, their use of generalizations, the clarity of their

knowledge and the extensibility of their approach. In this way they move towards being

representations of AI techniques.

Example-1: Tic-Tac-Toe

1.1 The first approach (simple)

The Tic-Tac-Toe game consists of a nine element vector called BOARD; it represents the

numbers 1 to 9 in three rows.

An element contains the value 0 for blank, 1 for X and 2 for O. A MOVETABLE vector consists
of 19,683 elements (39) and is needed where each element is a nine element vector. The contents

of the vector are especially chosen to help the algorithm.

The algorithm makes moves by pursuing the following:

1. View the vector as a ternary number. Convert it to a decimal number.

2. Use the decimal number as an index in MOVETABLE and access the vector.

3. Set BOARD to this vector indicating how the board looks after the move. This approach is

capable in time but it has several disadvantages. It takes more space and requires stunning

effort to calculate the decimal numbers. This method is specific to this game and cannot be

completed.

1.2 The second approach

The structure of the data is as before but we use 2 for a blank, 3 for an X and 5 for an O.

A variable called TURN indicates 1 for the first move and 9 for the last. The algorithm consists

of three actions:

MAKE2 which returns 5 if the centre square is blank; otherwise it returns any blank non

corner square, i.e. 2, 4, 6 or 8. POSSWIN (p) returns 0 if player p cannot win on the next move

and otherwise returns the number of the square that gives a winning move.

It checks each line using products 3*3*2 = 18 gives a win for X, 5*5*2=50 gives a win

for O, and the winning move is the holder of the blank. GO (n) makes a move to square n setting

BOARD[n] to 3 or 5.

This algorithm is more involved and takes longer but it is more efficient in storage which

compensates for its longer time. It depends on the programmer’s skill.

1.3 The final approach

The structure of the data consists of BOARD which contains a nine element vector, a list of

board positions that could result from the next move and a number representing an estimation of
how

the board position leads to an ultimate win for the player to move.

This algorithm looks ahead to make a decision on the next move by deciding which the most

promising move or the most suitable move at any stage would be and selects the same.

Consider all possible moves and replies that the program can make. Continue this process for

as long as time permits until a winner emerges, and then choose the move that leads to the
computer
program winning, if possible in the shortest time.

Actually this is most difficult to program by a good limit but it is as far that the technique can

be extended to in any game. This method makes relatively fewer loads on the programmer in terms

of the game technique but the overall game strategy must be known to the adviser.

Example-2: Question Answering

Let us consider Question Answering systems that accept input in English and provide

answers also in English. This problem is harder than the previous one as it is more difficult to

specify the problem properly. Another area of difficulty concerns deciding whether the answer

obtained is correct, or not, and further what is meant by ‘correct’. For example, consider the

following situation:

2.1 Text

Rani went shopping for a new Coat. She found a red one she really liked.

When she got home, she found that it went perfectly with her favourite dress.

2.2 Question

1. What did Rani go shopping for?

2. What did Rani find that she liked?

3. Did Rani buy anything?

LEVEL OF THE AI MODEL

‘What is our goal in trying to produce programs that do the intelligent things that people do?’

Are we trying to produce programs that do the tasks the same way that people do?

OR

Are we trying to produce programs that simply do the tasks the easiest way that is

possible?

Programs in the first class attempt to solve problems that a computer can easily solve and

do not usually use AI techniques. AI techniques usually include a search, as no direct method is

available, the use of knowledge about the objects involved in the problem area and abstraction on

which allows an element of pruning to occur, and to enable a solution to be found in real time;

otherwise, the data could explode in size. Examples of these trivial problems in the first class,

which are now of interest only to psychologists are EPAM (Elementary Perceiver and

Memorizer) which memorized garbage syllables.

The second class of problems attempts to solve problems that are non-trivial for a computer and
use AI techniques. We wish to model human performance on these:

1. To test psychological theories of human performance. Ex. PARRY [Colby, 1975] – a

program to simulate the conversational behavior of a paranoid person.

2. To enable computers to understand human reasoning – for example, programs that

answer questions based upon newspaper articles indicating human behavior.

3. To enable people to understand computer reasoning. Some people are reluctant to accept

computer results unless they understand the mechanisms involved in arriving at the

results.

4. To exploit the knowledge gained by people who are best at gathering information. This

persuaded the earlier workers to simulate human behavior in the SB part of AISB

simulated behavior. Examples of this type of approach led to GPS (General Problem

Solver).

Questions for Practice:

1. What is intelligence? How do we measure it? Are these measurements useful?

2. When the temperature falls and the thermostat turns the heater on, does it act because it

believes the room to be too cold? Does it feel cold? What sorts of things can have beliefs

or feelings? Is this related to the idea of consciousness?

3. Some people believe that the relationship between your mind (a non-physical thing) and

your brain (the physical thing inside your skull) is exactly like the relationship between a

computational process (a non-physical thing) and a physical computer. Do you agree?

4. How good are machines at playing chess? If a machine can consistently beat all the best

human chess players, does this prove that the machine is intelligent?

5. What is AI Technique? Explain Tic-Tac-Toe Problem using AI Technique.


2nd unit

PROBLEMS, PROBLEM SPACES AND SEARCH

To solve the problem of building a system you should take the following steps:

1. Define the problem accurately including detailed specifications and what constitutes a

suitable solution.

2. Scrutinize the problem carefully, for some features may have a central affect on the

chosen method of solution.

3. Segregate and represent the background knowledge needed in the solution of the

problem.

4. Choose the best solving techniques for the problem to solve a solution.

Problem solving is a process of generating solutions from observed data.

• a ‘problem’ is characterized by a set of goals,

• a set of objects, and

• a set of operations.

These could be ill-defined and may evolve during problem solving.

• A ‘problem space’ is an abstract space.

 A problem space encompasses all valid states that can be generated by the

application of any combination of operators on any combination of objects.

 The problem space may contain one or more solutions. A solution is a

combination of operations and objects that achieve the goals.

• A ‘search’ refers to the search for a solution in a problem space.

 Search proceeds with different types of ‘search control strategies’.

 The depth-first search and breadth-first search are the two common search

strategies.

2.1 AI - General Problem Solving

Problem solving has been the key area of concern for Artificial Intelligence.

Problem solving is a process of generating solutions from observed or given data. It is however

not always possible to use direct methods (i.e. go directly from data to solution). Instead,

problem solving often needs to use indirect or modelbased methods.


General Problem Solver (GPS) was a computer program created in 1957 by Simon and Newell

to build a universal problem solver machine. GPS was based on Simon and Newell’s theoretical

work on logic machines. GPS in principle can solve any formalized symbolic problem, such as

theorems proof and geometric problems and chess playing. GPS solved many simple problems,

such as the Towers of Hanoi, that could be sufficiently formalized, but GPS could not solve any

real-world problems.

To build a system to solve a particular problem, we need to:

 Define the problem precisely – find input situations as well as final situations for an

acceptable solution to the problem

 Analyze the problem – find few important features that may have impact on the

appropriateness of various possible techniques for solving the problem

 Isolate and represent task knowledge necessary to solve the problem

 Choose the best problem-solving technique(s) and apply to the particular problem

Problem definitions

A problem is defined by its ‘elements’ and their ‘relations’. To provide a formal description of a

problem, we need to do the following:

a. Define a state space that contains all the possible configurations of the relevant objects,

including some impossible ones.

b. Specify one or more states that describe possible situations, from which the problem

solving process may start. These states are called initial states.

c. Specify one or more states that would be acceptable solution to the problem.

These states are called goal states.

Specify a set of rules that describe the actions (operators) available.

The problem can then be solved by using the rules, in combination with an appropriate control

strategy, to move through the problem space until a path from an initial state to a goal state is

found. This process is known as ‘search’. Thus:

 Search is fundamental to the problem-solving process.

 Search is a general mechanism that can be used when a more direct

method is not known.

 Search provides the framework into which more direct methods for

solving subparts of
a problem can be embedded. A very large number of

AI problems are formulated as search problems.

 Problem space

A problem space is represented by a directed graph, where nodes represent search state and paths

represent the operators applied to change the state.

To simplify search algorithms, it is often convenient to logically and programmatically represent

a problem space as a tree. A tree usually decreases the complexity of a search at a cost. Here, the

cost is due to duplicating some nodes on the tree that were linked numerous times in the graph,

e.g. node B and node D.

A tree is a graph in which any two vertices are connected by exactly one path. Alternatively, any

connected graph with no cycles is a tree.

• Problem solving: The term, Problem Solving relates to analysis in AI. Problem solving may be

characterized as a systematic search through a range of possible actions to reach some predefined

goal or solution. Problem-solving methods are categorized as special purpose and general

purpose.

• A special-purpose method is tailor-made for a particular problem, often exploits very specific

features of the situation in which the problem is embedded.


• A general-purpose method is applicable to a wide variety of problems. One General-purpose

technique used in AI is ‘means-end analysis’: a step-bystep, or incremental, reduction of the

difference between current state and final goal.

2.3 DEFINING PROBLEM AS A STATE SPACE SEARCH

To solve the problem of playing a game, we require the rules of the game and targets for winning

as well as representing positions in the game. The opening position can be defined as the initial

state and a winning position as a goal state. Moves from initial state to other states leading to the

goal state follow legally. However, the rules are far too abundant in most games— especially in

chess, where they exceed the number of particles in the universe. Thus, the rules cannot be

supplied accurately and computer programs cannot handle easily. The storage also presents

another problem but searching can be achieved by hashing.

The number of rules that are used must be minimized and the set can be created by expressing

each rule in a form as possible. The representation of games leads to a state space representation

and it is common for well-organized games with some structure. This representation allows for

the formal definition of a problem that needs the movement from a set of initial positions to one

of a set of target positions. It means that the solution involves using known techniques and a

systematic search. This is quite a common method in Artificial Intelligence.

2.3.1 State Space Search

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

A state space consists of:

 A representation of the states the system can be in. For example, in a

board game, the board represents the current state of the game.

 A set of operators that can change one state into another state. In a board

game, the operators are the legal moves from any given state. Often the

operators are represented as programs that change a state representation to

represent the new state.

 An initial state.

 A set of final states; some of these may be desirable, others undesirable.

This set is often represented implicitly by a program that detects terminal

states.

2.3.2 The Water Jug Problem


In this problem, we use two jugs called four and three; four holds a maximum of four gallons of

water and three a maximum of three gallons of water. How can we get two gallons of water in

the four jug?

The state space is a set of prearranged pairs giving the number of gallons of water in the pair of

jugs at any time, i.e., (four, three) where four = 0, 1, 2, 3 or 4 and three = 0, 1, 2 or 3.

The start state is (0, 0) and the goal state is (2, n) where n may be any but it is limited to three

holding from 0 to 3 gallons of water or empty. Three and four shows the name and numerical

number shows the amount of water in jugs for solving the water jug problem. The major

production rules for solving this problem are shown below:

Initial condition Goal comment

1. (four, three) if four < 4 (4, three) fill four from tap

2. (four, three) if three< 3 (four, 3) fill three from tap

3. (four, three) If four > 0 (0, three) empty four into drain

4. (four, three) if three > 0 (four, 0) empty three into drain

5. (four, three) if four + three<4 (four + three, 0) empty three into

four

6. (four, three) if four + three<3 (0, four + three) empty four into

three

7. (0, three) If three > 0 (three, 0) empty three into four

8. (four, 0) if four > 0 (0, four) empty four into three

9. (0, 2) (2, 0) empty three into four

10. (2, 0) (0, 2) empty four into three

11. (four, three) if four < 4 (4, three-diff) pour diff, 4-four, into

four from three

12. (three, four) if three < 3 (four-diff, 3) pour diff, 3-three, into

three from four and a solution is

given below four three rule

(Fig. 2.2 Production Rules for the Water Jug Problem)

Gallons in Four Jug Gallons in Three Jug Rules Applied


0 0 -

0 3 2

3 0 7

3 3 2

4 2 11

0 2 3

2 0 10

(Fig. 2.3 One Solution to the Water Jug Problem)

The problem solved by using the production rules in combination with an appropriate control

strategy, moving through the problem space until a path from an initial state to a goal state is

found. In this problem solving process, search is the fundamental concept. For simple problems

it is easier to achieve this goal by hand but there will be cases where this is far too difficult.

2.4 PRODUCTION SYSTEMS

Production systems provide appropriate structures for performing and describing search

processes. A production system has four basic components as enumerated below.

 A set of rules each consisting of a left side that determines the applicability of the

rule and a right side that describes the operation to be performed if the rule is

applied.

 A database of current facts established during the process of inference.

 A control strategy that specifies the order in which the rules will be compared

with facts in the database and also specifies how to resolve conflicts in selection

of several rules or selection of more facts.

 A rule firing module.

The production rules operate on the knowledge database. Each rule has a precondition—that is,

either satisfied or not by the knowledge database. If the precondition is satisfied, the rule can be

applied. Application of the rule changes the knowledge database. The control system chooses
which applicable rule should be applied and ceases computation when a termination condition on

the knowledge database is satisfied.

Example: Eight puzzle (8-Puzzle)

The 8-puzzle is a 3 × 3 array containing eight square pieces, numbered 1 through 8, and

one empty space. A piece can be moved horizontally or vertically into the empty space, in effect

exchanging the positions of the piece and the empty space. There are four possible moves, UP

(move the blank space up), DOWN, LEFT and RIGHT. The aim of the game is to make a

sequence of moves that will convert the board from the start state into the goal state:

Example: Missionaries and Cannibals

The Missionaries and Cannibals problem illustrates the use of state space search for planning

under constraints:

Three missionaries and three cannibals wish to cross a river using a two person boat. If

at any time the cannibals outnumber the missionaries on either side of the river, they will eat the

missionaries. How can a sequence of boat trips be performed that will get everyone to the other

side of the river without any missionaries being eaten?

State representation:

1. BOAT position: original (T) or final (NIL) side of the river.

2. Number of Missionaries and Cannibals on the original side of the river.

3. Start is (T 3 3); Goal is (NIL 0 0).

Operators:
CHARACTERISTICS OF PRODUCTION SYSTEMS

Production systems provide us with good ways of describing the operations that can be

performed in a search for a solution to a problem.

At this time, two questions may arise:

1. Can production systems be described by a set of characteristics? And how can they be

easily implemented?

2. What relationships are there between the problem types and the types of production

systems well suited for solving the problems?

To answer these questions, first consider the following definitions of classes 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 also have been

applied at the time the first rule was selected.

2. A non-monotonic production system is one in which this is not true.

3. A partially communicative 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 combination of those rules that is allowable also transforms state P

into state Q.

4. A commutative production system is a production system that is both monotonic and

partially commutative.
Is there any relationship between classes of production systems and classes of problems?

For any solvable problems, there exist an infinite number of production systems that show how

to find solutions. Any problem that can be solved by any production system can be solved by a

commutative one, but the commutative one is practically useless. It may use individual states to

represent entire sequences of applications of rules of a simpler, non-commutative system. In the

formal sense, there is no relationship between kinds of problems and kinds of production systems

Since all problems can be solved by all kinds of systems. But in the practical sense, there is

definitely such a relationship between the kinds of problems and the kinds of systems that lend

themselves to describing those problems.

Partially commutative, monotonic productions systems are useful for solving ignorable

problems. These are important from an implementation point of view without the ability to

backtrack to previous states when it is discovered that an incorrect path has been followed. Both

types of partially commutative production systems are significant from an implementation point;

they tend to lead to many duplications of individual states during the search process. Production

systems that are not partially commutative are useful for many problems in which permanent

HEURISTIC SEARCH TECHNIQUES:

Search Algorithms

Many traditional search algorithms are used in AI applications. For complex problems, the

traditional algorithms are unable to find the solutions within some practical time and space

limits. Consequently, many special techniques are developed, using heuristic functions.

The algorithms that use heuristic functions are called heuristic algorithms.

• Heuristic algorithms are not really intelligent; they appear to be intelligent because they

achieve better performance.

• Heuristic algorithms are more efficient because they take advantage of feedback from the data

to direct the search path.


• Uninformed search algorithms or Brute-force algorithms, search through the search space all

possible candidates for the solution checking whether each candidate satisfies the problem’s

statement.

• Informed search algorithms use heuristic functions that are specific to the problem, apply

them to guide the search through the search space to try to reduce the amount of time spent in

searching.

A good heuristic will make an informed search dramatically outperform any uninformed search:

for example, the Traveling Salesman Problem (TSP), where the goal is to find is a good solution

instead of finding the best solution.

In such problems, the search proceeds using current information about the problem to predict

which path is closer to the goal and follow it, although it does not always guarantee to find the

best possible solution. Such techniques help in finding a solution within reasonable time and

space (memory). Some prominent intelligent search algorithms are stated below:

1. Generate and Test Search

2. Best-first Search

3. Greedy Search

4. A* Search

5. Constraint Search

6. Means-ends analysis

There are some more algorithms. They are either improvements or combinations of these.

• Hierarchical Representation of Search Algorithms: A Hierarchical representation of most

search algorithms is illustrated below. The representation begins with two types of search:

• Uninformed Search: Also called blind, exhaustive or brute-force search, it uses no

information about the problem to guide the search and therefore may not be very efficient.

• Informed Search: Also called heuristic or intelligent search, this uses information about the

problem to guide the search—usually guesses the distance to a goal state and is therefore

efficient, but the search may not be always possible.


The first requirement is that it causes motion, in a game playing program, it moves on the board

and in the water jug problem, filling water is used to fill jugs. It means the control strategies

without the motion will never lead to the solution.

The second requirement is that it is systematic, that is, it corresponds to the need for global

motion as well as for local motion. This is a clear condition that neither would it be rational to

fill a jug and empty it repeatedly, nor it would be worthwhile to move a piece round and round

on the board in a cyclic way in a game. We shall initially consider two systematic approaches for

searching. Searches can be classified by the order in which operators are tried: depth-first,

breadth-first, bounded depth-first.


Breadth-first search

A Search strategy, in which the highest layer of a decision tree is searched completely before

proceeding to the next layer is called Breadth-first search (BFS).

• In this strategy, no viable solutions are omitted and therefore it is guaranteed that an optimal

solution is found.

• This strategy is often not feasible when the search space is large.

Algorithm

1. Create a variable called LIST and set it to be the starting state.

2. Loop until a goal state is found or LIST is empty, Do

a. Remove the first element from the LIST and call it E. If the LIST is empty, quit.

b. For every path each rule can match the state E, Do


(i) Apply the rule to generate a new state.

(ii) If the new state is a goal state, quit and return this state.

(iii) Otherwise, add the new state to the end of LIST.

Advantages

1. Guaranteed to find an optimal solution (in terms of shortest number of steps

to reach the goal).

2. Can always find a goal node if one exists (complete).

Disadvantages

1. High storage requirement: exponential with tree depth.

Depth-first search

A search strategy that extends the current path as far as possible before backtracking to the last

choice point and trying the next alternative path is called Depth-first search (DFS).

• This strategy does not guarantee that the optimal solution has been found.

• In this strategy, search reaches a satisfactory solution more rapidly than breadth first, an

advantage when the search space is large.

Algorithm

Depth-first search applies operators to each newly generated state, trying to drive directly toward

the goal.

1. If the starting state is a goal state, quit and return success.

2. Otherwise, do the following until success or failure is signalled:

a. Generate a successor E to the starting state. If there are no more successors, then signal failure.

b. Call Depth-first Search with E as the starting state.

c. If success is returned signal success; otherwise, continue in the loop.

Advantages

1. Low storage requirement: linear with tree depth.

2. Easily programmed: function call stack does most of the work of maintaining state of the

search.

Disadvantages

1. May find a sub-optimal solution (one that is deeper or more costly than the best solution).

2. Incomplete: without a depth bound, may not find a solution even if one exists.
2.4.2.3 Bounded depth-first search

Depth-first search can spend much time (perhaps infinite time) exploring a very deep path that

does not contain a solution, when a shallow solution exists. An easy way to solve this problem is

to put a maximum depth bound on the search. Beyond the depth bound, a failure is generated

automatically without exploring any deeper.

Problems:

1. It’s hard to guess how deep the solution lies.

2. If the estimated depth is too deep (even by 1) the computer time used is dramatically

increased, by a factor of bextra.

3. If the estimated depth is too shallow, the search fails to find a solution; all that computer time

is wasted.

Heuristics

A heuristic is a method that improves the efficiency of the search process. These are like tour

guides. There are good to the level that they may neglect the points in general interesting

directions; they are bad to the level that they may neglect points of interest to particular

individuals. Some heuristics help in the search process without sacrificing any claims to entirety

that the process might previously had. Others may occasionally cause an excellent path to be

overlooked. By sacrificing entirety it increases efficiency. Heuristics may not find the best

solution every time but guarantee that they find a good solution in a reasonable time. These are

particularly useful in solving tough and complex problems, solutions of which would require

infinite time, i.e. far longer than a lifetime for the problems which are not solved in any other

way.

Heuristic search

To find a solution in proper time rather than a complete solution in unlimited time we use

heuristics. ‘A heuristic function is a function that maps from problem state descriptions to

measures of desirability, usually represented as numbers’. Heuristic search methods use

knowledge about the problem domain and choose promising operators first. These heuristic

search methods use heuristic functions to evaluate the next state towards the goal state. For

finding a solution, by using the heuristic technique, one should carry out the following steps:

1. Add domain—specific information to select what is the best path to continue searching along.

2. Define a heuristic function h(n) that estimates the ‘goodness’ of a node n.


Specifically, h(n) = estimated cost(or distance) of minimal cost path from n to a goal state.

3. The term, heuristic means ‘serving to aid discovery’ and is an estimate, based on domain

specific information that is computable from the current state description of how close we are to

a goal.

Finding a route from one city to another city is an example of a search problem in which

different search orders and the use of heuristic knowledge are easily understood.

1. State: The current city in which the traveller is located.

2. Operators: Roads linking the current city to other cities.

3. Cost Metric: The cost of taking a given road between cities.

4. Heuristic information: The search could be guided by the direction of the goal city from the

current city, or we could use airline distance as an estimate of the distance to the goal.

Heuristic search techniques

For complex problems, the traditional algorithms, presented above, are unable to find the

solution within some practical time and space limits. Consequently, many special techniques are

developed, using heuristic functions.

• Blind search is not always possible, because it requires too much time or Space (memory).

Heuristics are rules of thumb; they do not guarantee a solution to a problem.

• Heuristic Search is a weak technique but can be effective if applied correctly; it requires

domain specific information.

Characteristics of heuristic search

• Heuristics are knowledge about domain, which help search and reasoning in its domain.

• Heuristic search incorporates domain knowledge to improve efficiency over blind search.

• Heuristic is a function that, when applied to a state, returns value as estimated merit of state,

with respect to goal.

 Heuristics might (for reasons) underestimate or overestimate the merit of a state with

respect to goal.

 Heuristics that underestimate are desirable and called admissible.

• Heuristic evaluation function estimates likelihood of given state leading to goal state.

• Heuristic search function estimates cost from current state to goal, presuming function is

efficient.

36
Heuristic search compared with other search

The Heuristic search is compared with Brute force or Blind search techniques below:

Comparison of Algorithms

Brute force / Blind search

Can only search what it has knowledge

about already

No knowledge about how far a node

node from goal state

Example: Travelling salesman

Heuristic search

Estimates ‘distance’ to goal state

through explored nodes

Guides search process toward goal

Prefers states (nodes) that lead

close to and not away from goal

state

A salesman has to visit a list of cities and he must visit each city only once. There are different

routes between the cities. The problem is to find the shortest route between the cities so that the

salesman visits all the cities at once.

Suppose there are N cities, then a solution would be to take N! possible combinations to find the

shortest distance to decide the required route. This is not efficient as with N=10 there are

36,28,800 possible routes. This is an example of combinatorial explosion.

There are better methods for the solution of such problems: one is called branch and bound.

First, generate all the complete paths and find the distance of the first complete path. If the next

path is shorter, then save it and proceed this way avoiding the path when its length exceeds the

saved shortest path length, although it is better than the previous method.

Generate and Test Strategy

Generate-And-Test Algorithm

Generate-and-test search algorithm is a very simple algorithm that guarantees to find a solution if

done systematically and there exists a solution.

Algorithm: Generate-And-Test
1.Generate a possible solution.

2.Test to see if this is the expected solution.

3.If the solution has been found quit else go to step 1.

Potential solutions that need to be generated vary depending on the kinds of problems. For some

problems the possible solutions may be particular points in the problem space and for some

problems, paths from the start state.

Figure: Generate And Test

Generate-and-test, like depth-first search, requires that complete solutions be generated for

testing. In its most systematic form, it is only an exhaustive search of the problem space.

Solutions can also be generated randomly but solution is not guaranteed. This approach is what is

known as British Museum algorithm: finding an object in the British Museum by wandering

randomly.

Systematic Generate-And-Test

While generating complete solutions and generating random solutions are the two extremes there

exists another approach that lies in between. The approach is that the search process proceeds

systematically but some paths that unlikely to lead the solution are not considered. This
evaluation is performed by a heuristic function.

Depth-first search tree with backtracking can be used to implement systematic generate-and-test

procedure. As per this procedure, if some intermediate states are likely to appear often in the

tree, it would be better to modify that procedure to traverse a graph rather than a tree.

Generate-And-Test And Planning

Exhaustive generate-and-test is very useful for simple problems. But for complex problems even

heuristic generate-and-test is not very effective technique. But this may be made effective by

combining with other techniques in such a way that the space in which to search is restricted. An

AI program DENDRAL, for example, uses plan-Generate-and-test technique. First, the planning

process uses constraint-satisfaction techniques and creates lists of recommended and

contraindicated substructures. Then the generate-and-test procedure uses the lists generated and

required to explore only a limited set of structures. Constrained in this way, generate-and-test

proved highly effective. A major weakness of planning is that it often produces inaccurate

solutions as there is no feedback from the world. But if it is used to produce only pieces of

solutions then lack of detailed accuracy becomes unimportant.

Hill Climbing

Hill Climbing is heuristic search used for mathematical optimization problems in the field of

Artificial Intelligence .

Given a large set of inputs and a good heuristic function, it tries to find a sufficiently good

solution to the problem. This solution may not be the global optimal maximum.

 In the above definition, mathematical optimization problems implies that hill climbing

solves the problems where we need to maximize or minimize a given real function by

choosing values from the given inputs. Example-Travelling salesman problem where we

need to minimize the distance traveled by salesman.

 ‘Heuristic search’ means that this search algorithm may not find the optimal solution to

the problem. However, it will give a good solution in reasonable time.

 A heuristic function is a function that will rank all the possible alternatives at any

branching step in search algorithm based on the available information. It helps the

algorithm to select the best route out of possible routes.

Features of Hill Climbing

1. Variant of generate and test algorithm : It is a variant of generate and test algorithm. The
generate and test algorithm is as follows :

1. Generate a possible solutions.

2. Test to see if this is the expected solution.

3. If the solution has been found quit else go to step 1.

Hence we call Hill climbing as a variant of generate and test algorithm as it takes the feedback

from test procedure. Then this feedback is utilized by the generator in deciding the next move in

search space.

2. Uses the Greedy approach : At any point in state space, the search moves in that direction

only which optimizes the cost of function with the hope of finding the optimal solution at

the end.

Types of Hill Climbing

1. Simple Hill climbing : It examines the neighboring nodes one by one and selects the first

neighboring node which optimizes the current cost as next node.

Algorithm for Simple Hill climbing :

Step 1 : Evaluate the initial state. If it is a goal state then stop and return success. Otherwise,

make initial state as current state.

Step 2 : Loop until the solution state is found or there are no new operators present which can be

applied to current state.

a) Select a state that has not been yet applied to the current state and apply it to produce a new

state.

b) Perform these to evaluate new state

i. If the current state is a goal state, then stop and return success.

ii. If it is better than the current state, then make it current state and proceed further.

iii. If it is not better than the current state, then continue in the loop until a solution is found.

2. Steepest-Ascent Hill climbing : It first examines all the neighboring nodes and then

selects the node closest to the solution state as next node.

Step 1 : Evaluate the initial state. If it is goal state then exit else make the current state as initial

state

Step 2 : Repeat these steps until a solution is found or current state does not change

i. Let ‘target’ be a state such that any successor of the current state will be better than it;

ii. for each operator that applies to the current state


a. apply the new operator and create a new state

b. evaluate the new state

c. if this state is goal state then quit else compare with ‘target’

d. if this state is better than ‘target’, set this state as ‘target’

e. if target is better than current state set current state to Target

Step 3 : Exit

3. Stochastic hill climbing : It does not examine all the neighboring nodes before deciding

which node to select .It just selects a neighboring node at random, and decides (based on

the amount of improvement in that neighbor) whether to move to that neighbor or to

examine another.

State Space diagram for Hill Climbing

State space diagram is a graphical representation of the set of states our search algorithm can

reach vs the value of our objective function(the function which we wish to maximize).

X-axis : denotes the state space ie states or configuration our algorithm may reach.

Y-axis : denotes the values of objective function corresponding to to a particular state.

The best solution will be that state space where objective function has maximum value(global

maximum).

Different regions in the State Space Diagram

1. Local maximum : It is a state which is better than its neighboring state however there

exists a state which is better than it(global maximum). This state is better because here
value of objective function is higher than its neighbors.

2. Global maximum : It is the best possible state in the state space diagram. This because at

this state, objective function has highest value.

3. Plateua/flat local maximum : It is a flat region of state space where neighboring states

have the same value.

4. Ridge : It is region which is higher than its neighbours but itself has a slope. It is a special

kind of local maximum.

5. Current state : The region of state space diagram where we are currently present during

the search.

6. Shoulder : It is a plateau that has an uphill edge.

Problems in different regions in Hill climbing

Hill climbing cannot reach the optimal/best state(global maximum) if it enters any of the

following regions :

1. Local maximum : At a local maximum all neighboring states have a values which is

worse than than the current state. Since hill climbing uses greedy approach, it will not

move to the worse state and terminate itself. The process will end even though a better

solution may exist.

To overcome local maximum problem : Utilize backtracking technique. Maintain a list of

visited states. If the search reaches an undesirable state, it can backtrack to the previous

configuration and explore a new path.

2. Plateau : On plateau all neighbors have same value . Hence, it is not possible to select the

best direction.

To overcome plateaus : Make a big jump. Randomly select a state far away from current state.

Chances are that we will land at a non-plateau region

3. Ridge : Any point on a ridge can look like peak because movement in all possible

directions is downward. Hence the algorithm stops when it reaches this state.

To overcome Ridge : In this kind of obstacle, use two or more rules before testing. It

implies moving in several directions at once.

Issues in the Design of Search Programs


Each search process can be considered to be a tree traversal. The object of the search is to find a

path from the initial state to a goal state using a tree. The number of nodes generated might be

huge; and in practice many of the nodes would not be needed. The secret of a good search

routine is to generate only those nodes that are likely to be useful, rather than having a precise

tree. The rules are used to represent the tree implicitly and only to create nodes explicitly if they

are actually to be of use.

The following issues arise when searching:

• The tree can be searched forward from the initial node to the goal state or backwards from the

goal state to the initial state.

• To select applicable rules, it is critical to have an efficient procedure for matching rules against

states.

• How to represent each node of the search process? This is the knowledge representation

problem or the frame problem. In games, an array suffices; in other problems, more complex

data structures are needed.

Finally in terms of data structures, considering the water jug as a typical problem do we use a

graph or tree? The breadth-first structure does take note of all nodes generated but the depth-first

one can be modified.

Check duplicate nodes

1. Observe all nodes that are already generated, if a new node is present.

2. If it exists add it to the graph.

3. If it already exists, then

a. Set the node that is being expanded to the point to the already existing node

corresponding to its successor rather than to the new one. The new one can be thrown

away.

b. If the best or shortest path is being determined, check to see if this path is better or

worse than the old one. If worse, do nothing.

Better save the new path and work the change in length through the chain of successor nodes if

necessary.

Example: Tic-Tac-Toe

State spaces are good representations for board games such as Tic-Tac-Toe. The position of a

game can be explained 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 an X or O or be empty.

• State:

 Player to move next: X or O.

 Board configuration:

• Operators: Change an empty cell to X or O.

• Start State: Board empty; X’s turn.

• Terminal States: Three X’s in a row; Three O’s in a row; All 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 ply.

Since the same state may be reachable by different sequences of moves, the state space may in

general be a graph. It may be treated as a tree for simplicity, at the cost of duplicating states.

Solving problems using search

• Given an informal description of the problem, construct a formal description as a state space:

 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 a new

state representation.

 Write a program to detect terminal states.

• Choose an appropriate search technique:

 How large is the search space?

 How well structured is the domain?

 What knowledge about the domain can be used to guide the search?

Best First Search (Informed Search)

In BFS and DFS, when we are at a node, we can consider any of the adjacent as next

node. So both BFS and DFS blindly explore paths without considering any cost function. The

idea of Best First Search is to use an evaluation function to decide which adjacent is most

promising and then explore. Best First Search falls under the category of Heuristic Search or

Informed Search.

We use a priority queue to store costs of nodes. So the implementation is a variation of BFS, we

just need to change Queue to PriorityQueue.

Algorithm:

Best-First-Search(Grah g, Node start)

1) Create an empty PriorityQueue

PriorityQueue pq;

2) Insert "start" in pq.

pq.insert(start)

3) Until PriorityQueue is empty

u = PriorityQueue.DeleteMin

If u is the goal

Exit

Else

Foreach neighbor v of u

If v "Unvisited"

Mark v "Visited"

pq.insert(v)
Mark v "Examined"

End procedure

Let us consider below example.

We start from source "S" and search for

goal "I" using given costs and Best

First search.

pq initially contains S

We remove s from and process unvisited

neighbors of S to pq.

pq now contains {A, C, B} (C is put

before B because C has lesser cost)

We remove A from pq and process unvisited

neighbors of A to pq.

pq now contains {C, B, E, D}

We remove C from pq and process unvisited

neighbors of C to pq.

pq now contains {B, H, E, D}

We remove B from pq and process unvisited

neighbors of B to pq.
pq now contains {H, E, D, F, G}

We remove H from pq. Since our goal

"I" is a neighbor of H, we return.

Analysis :

 The worst case time complexity for Best First Search is O(n * Log n) where n is number

of nodes. In worst case, we may have to visit all nodes before we reach goal. Note that

priority queue is implemented using Min(or Max) Heap, and insert and remove

operations take O(log n) time.

 Performance of the algorithm depends on how well the cost or evaluation function is

designed.

CONSTRAINT SATISFACTION:-

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

state satisfies a given set of constraint. constraint satisfaction problems can be solved by using

any of the search strategies. The general form of the constraint satisfaction procedure is as

follows:

Until a complete solution is found or until all paths have led to lead ends, do

1. select an unexpanded node of the search graph.

2. Apply the constraint inference rules to the selected node to generate all possible new

constraints.

3. If the set of constraints contains a contradiction, then report that this path is a dead end.

4. If the set of constraints describes a complete solution then report success.

5. If neither a constraint nor a complete solution has been found then apply the rules to generate

new partial solutions. Insert these partial solutions into the search graph.

Example: consider the crypt arithmetic problems.

SEND

+ MORE ----------

MONEY ----------

Assign decimal digit to each of the letters in such a way that the answer to the problem is correct

to the same letter occurs more than once , it must be assign the same digit each time . no two

different letters may be assigned the same digit. Consider the crypt arithmetic problem.

SEND
+ MORE -----------

MONEY -----------

CONSTRAINTS:-

1. no two digit can be assigned to same letter.

2. only single digit number can be assign to a letter.

1. no two letters can be assigned same digit.

2. Assumption can be made at various levels such that they do not contradict each other.

3. The problem can be decomposed into secured constraints. A constraint satisfaction approach

may be used.

4. Any of search techniques may be used.

5. Backtracking may be performed as applicable us applied search techniques.

6. Rule of arithmetic may be followed.

Initial state of problem.

D=?

E=?

Y=?

N=?

R=?

O=?

S=?

M=?

C1=?

C2=?

C1 ,C 2, 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:

We are following the depth-first method to solve the problem.

1. initial guess m=1 because the sum of two single digits can generate at most a carry '1'.

2. When n=1 o=0 or 1 because the largest single digit number added to m=1 can generate the
sum of either 0 or 1 depend on the carry received from the carry sum. By this we conclude that
o=0 because m is already 1 hence we cannot assign same digit another letter(rule no.)
3. We have m=1 and o=0 to get o=0 we have s=8 or 9, again depending on the carry received
from the earlier sum.

The same process can be repeated further. The problem has to be composed into various
constraints. And each constraints is to be satisfied by guessing the possible digits that the letters
can be assumed that the initial guess has been already made . rest of the process is being shown
in the form of a tree, using depth-first search for the clear understandability of the solution
process.
MEANS - ENDS ANALYSIS:-
Most of the search strategies either reason forward of backward however, often a mixture o the

two directions is appropriate. Such mixed strategy would make it possible to solve the major

parts of problem first and solve the smaller problems the arise when combining them together.

Such a technique is called "Means - Ends Analysis".

The means -ends analysis process centers around finding the difference between current state and

goal state. The problem space of means - ends analysis has an initial state and one or more goal

state, a set of operate with a set of preconditions their application and difference functions that

computes the difference between two state a(i) and s(j). A problem is solved using means - ends

analysis by

1. Computing the current state s1 to a goal state s2 and computing their difference D12.

2. Satisfy the preconditions for some recommended operator op is selected, then to reduce the

difference D12.

3. The operator OP is applied if possible. If not the current state is solved a goal is created and

means- ends analysis is applied recursively to reduce the sub goal.

4. If the sub goal is solved state is restored and work resumed on the original problem.

( the first AI program to use means - ends analysis was the GPS General problem solver)

means- ends analysis I useful for many human planning activities. Consider the example of

planing for an office worker. Suppose we have a different table of three rules:

1. If in out current state we are hungry , and in our goal state we are not hungry , then either the

"visit hotel" or "visit Canteen " operator is recommended.

2. If our current state we do not have money , and if in your goal state we have money, then the

"Visit our bank" operator or the "Visit secretary" operator is recommended.

3. If our current state we do not know where something is , need in our goal state we do know,

then either the "visit office enquiry" , "visit secretary" or "visit co worker " operator is

recommended.
3rd chaper

KNOWLEDGE REPRESENTATION

KNOWLEDGE REPRESENTATION:-

For the purpose of solving complex problems c\encountered in AI, we need both a large amount

of knowledge and some mechanism for manipulating that knowledge to create solutions to new

problems. A variety of ways of representing knowledge (facts) have been exploited in AI

programs. In all variety of knowledge representations , we deal with two kinds of entities.

A. Facts: Truths in some relevant world. These are the things we want to represent.

B. Representations of facts in some chosen formalism . these are things we will

actually be able to manipulate.

One way to think of structuring these entities is at two levels : (a) the knowledge level, at which

facts are described, and (b) the symbol level, at which representations of objects at the

knowledge level are defined in terms of symbols that can be manipulated by programs.

The facts and representations are linked with two-way mappings. This link is called

representation mappings. The forward representation mapping maps from facts to

representations. The backward representation mapping goes the other way, from representations

to facts.

One common representation is natural language (particularly English) sentences. Regardless of

the representation for facts we use in a program , we may also need to be concerned with an

English representation of those facts in order to facilitate getting information into and out of the

system. We need mapping functions from English sentences to the representation we actually use

and from it back to sentences.

Representations and Mappings

 In order to solve complex problems encountered in artificial intelligence, one needs both

a large amount of knowledge and some mechanism for manipulating that knowledge to

create solutions.

 Knowledge and Representation are two distinct entities. They play central but

distinguishable roles in the intelligent system.

 Knowledge is a description of the world. It determines a system’s competence by what it

knows.

 Moreover, Representation is the way knowledge is encoded. It defines a system’s


performance in doing something.

 Different types of knowledge require different kinds of representation.

The Knowledge Representation models/mechanisms are often based on:

 Logic

 Rules

 Frames

 Semantic Net

Knowledge is categorized into two major types:

1. Tacit corresponds to “informal” or “implicit“

 Exists within a human being;

 It is embodied.

 Difficult to articulate formally.

 Difficult to communicate or share.

 Moreover, Hard to steal or copy.

 Drawn from experience, action, subjective insight

2. Explicit formal type of knowledge, Explicit

 Explicit knowledge

 Exists outside a human being;

 It is embedded.

 Can be articulated formally.

 Also, Can be shared, copied, processed and stored.

 So, Easy to steal or copy


 Drawn from the artifact of some type as a principle, procedure, process, concepts.

A variety of ways of representing knowledge have been exploited in AI programs.

There are two different kinds of entities, we are dealing with.

1. Facts: Truth in some relevant world. Things we want to represent.

2. Also, Representation of facts in some chosen formalism. Things we will actually be able

to manipulate.

These entities structured at two levels:

1. The knowledge level, at which facts described.

2. Moreover, The symbol level, at which representation of objects defined in terms of

symbols that can manipulate by programs

Framework of Knowledge Representation

 The computer requires a well-defined problem description to process and provide a well

defined acceptable solution.

 Moreover, To collect fragments of knowledge we need first to formulate a description in

our spoken language and then represent it in formal language so that computer can

understand.

 Also, The computer can then use an algorithm to compute an answer.

So, This process illustrated as,

The steps are:

 The informal formalism of the problem takes place first.

 It then represented formally and the computer produces an output.

 This output can then represented in an informally described solution that user understands

or checks for consistency.


The Problem solving requires,

 Formal knowledge representation, and

 Moreover, Conversion of informal knowledge to a formal knowledge that is the

conversion of implicit knowledge to explicit knowledge.

Mapping between Facts and Representation

 Knowledge is a collection of facts from some domain.

 Also, We need a representation of “facts“ that can manipulate by a program.

 Moreover, Normal English is insufficient, too hard currently for a computer program to

draw inferences in natural languages.

 Thus some symbolic representation is necessary.

A good knowledge representation enables fast and accurate access to knowledge and

understanding of the content.

A knowledge representation system should have following properties.

1. Representational Adequacy

 The ability to represent all kinds of knowledge that are needed in that domain.

2. Inferential Adequacy

 Also, The ability to manipulate the representational structures to derive new

structures corresponding to new knowledge inferred from old.

3. Inferential Efficiency

 The ability to incorporate additional information into the knowledge structure that

can be used to focus the attention of the inference mechanisms in the most

promising direction.

4. Acquisitional Efficiency

 Moreover, The ability to acquire new knowledge using automatic methods

wherever possible rather than reliance on human intervention.

USING PREDICATE LOGIC

Representation of Simple Facts in Logic

Propositional logic is useful because it is simple to deal with and a decision procedure for it

exists.

Also, In order to draw conclusions, facts are represented in a more convenient way as,

1. Marcus is a man.
 man(Marcus)

2. Plato is a man.

 man(Plato)

3. All men are mortal.

 mortal(men)

But propositional logic fails to capture the relationship between an individual being a man
and

that individual being a mortal.

 How can these sentences be represented so that we can infer the third sentence from the

first two?

 Also, Propositional logic commits only to the existence of facts that may or may not be

the case in the world being represented.

 Moreover, It has a simple syntax and simple semantics. It suffices to illustrate the process

of inference.

 Propositional logic quickly becomes impractical, even for very small worlds.

Predicate logic

First-order Predicate logic (FOPL) models the world in terms of

 Objects, which are things with individual identities

 Properties of objects that distinguish them from other objects

 Relations that hold among sets of objects

 Functions, which are a subset of relations where there is only one “value” for any given

“input”

First-order Predicate logic (FOPL) provides

 Constants: a, b, dog33. Name a specific object.

 Variables: X, Y. Refer to an object without naming it.

 Functions: Mapping from objects to objects.

 Terms: Refer to objects

 Atomic Sentences: in(dad-of(X), food6) Can be true or false, Correspond to propositional

symbols P, Q.

A well-formed formula (wff) is a sentence containing no “free” variables. So, That is, all

variables are “bound” by universal or existential quantifiers.


(∀x)P(x, y) has x bound as a universally quantified variable, but y is free.

Quantifiers

Universal quantification

 (∀x)P(x) means that P holds for all values of x in the domain associated with that variable

 E.g., (∀x) dolphin(x) → mammal(x)

Existential quantification

 (∃ x)P(x) means that P holds for some value of x in the domain associated with that

variable

 E.g., (∃ x) mammal(x) ∧ lays-eggs(x)

Also, Consider the following example that shows the use of predicate logic as a way of

representing knowledge.

1. Marcus was a man.

2. Marcus was a Pompeian.

3. All Pompeians were Romans.

4. Caesar was a ruler.

5. Also, All Pompeians were either loyal to Caesar or hated him.

6. Everyone is loyal to someone.

7. People only try to assassinate rulers they are not loyal to.

8. Marcus tried to assassinate Caesar.

The facts described by these sentences can be represented as a set of well-formed formulas (wffs)

as follows:

1. Marcus was a man.

 man(Marcus)

2. Marcus was a Pompeian.

 Pompeian(Marcus)

3. All Pompeians were Romans.

 ∀x: Pompeian(x) → Roman(x)

4. Caesar was a ruler.

 ruler(Caesar)

5. All Pompeians were either loyal to Caesar or hated him.


inclusive-or

 ∀x: Roman(x) → loyalto(x, Caesar) ∨ hate(x, Caesar)

 exclusive-or

 ∀x: Roman(x) → (loyalto(x, Caesar) ∧¬ hate(x, Caesar)) ∨

 (¬loyalto(x, Caesar) ∧ hate(x, Caesar))

6. Everyone is loyal to someone.

 ∀x: ∃y: loyalto(x, y)

7. People only try to assassinate rulers they are not loyal to.

 ∀x: ∀y: person(x) ∧ ruler(y) ∧ tryassassinate(x, y)

 →¬loyalto(x, y)

8. Marcus tried to assassinate Caesar.

 tryassassinate(Marcus, Caesar)

Now suppose if we want to use these statements to answer the question: Was Marcus loyal to

Caesar?

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

Ioyalto(Marcus, Caesar)

In order to prove the goal, we need to use the rules of inference to transform it into another goal

(or possibly a set of goals) that can, in turn, transformed, and so on, until there are no unsatisfied

goals remaining.

 The problem is that, although we know that Marcus was a man, we do not have any way

to conclude from that that Marcus was a person. Also, We need to add the representation

of another fact to our system, namely: ∀ man(x) → person(x)


 Now we can satisfy the last goal and produce a proof that Marcus was not loyal to

Caesar.

 Moreover, From this simple example, we see that three important issues must be

addressed in the process of converting English sentences into logical statements and then

using those statements to deduce new ones:

1. Many English sentences are ambiguous (for example, 5, 6, and 7 above).

Choosing the correct interpretation may be difficult.

2. Also, There is often a choice of how to represent the knowledge. Simple

representations are desirable, but they may exclude certain kinds of reasoning.

3. Similalry, Even in very simple situations, a set of sentences is unlikely to contain

all the information necessary to reason about the topic at hand. In order to be able

to use a set of statements effectively. Moreover, It is usually necessary to have

access to another set of statements that represent facts that people consider too

obvious to mention.

Representing Instance and ISA Relationships

 Specific attributes instance and isa play an important role particularly in a useful form of

reasoning called property inheritance.

 The predicates instance and isa explicitly captured the relationships they used to express,

namely class membership and class inclusion.

 4.2 shows the first five sentences of the last section represented in logic in three different

ways.

 The first part of the figure contains the representations we have already discussed. In

these representations, class membership represented with unary predicates (such as

Roman), each of which corresponds to a class.

 Asserting that P(x) is true is equivalent to asserting that x is an instance (or element) of P.

 The second part of the figure contains representations that use the instance predicate

explicitly.
 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 do not use an explicit isa predicate.

 Instead, subclass relationships, such as that between Pompeians and Romans, described

as shown in sentence 3.

 The implication rule states that if an object is an instance of the subclass Pompeian then it

is an instance of the superclass Roman.

 Note that this rule is equivalent to the standard set-theoretic definition of the subclass

superclass relationship.

 The third part contains representations that use both the instance and isa predicates

explicitly.

 The use of the isa predicate simplifies the representation of sentence 3, but it requires that

one additional axiom (shown here as number 6) be provided.

Computable Functions and Predicates

 To express simple facts, such as the following greater-than and less-than relationships:

gt(1,O) It(0,1) gt(2,1) It(1,2) gt(3,2) It( 2,3)

 It is often also useful to have computable functions as well as computable predicates.

Thus we might want to be able to evaluate the truth of gt(2 + 3,1)


 To do so requires that we first compute the value of the plus function given the arguments

2 and 3, and then send the arguments 5 and 1 to gt.

Consider the following set of facts, again involving Marcus:

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)

4) All men are mortal.

x: man(x) → mortal(x)

5) All Pompeians died when the 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: At2: mortal(x) born(x, t1) gt(t2 – t1,150) → died(x, t2)

7) It is now 1991.

now = 1991

So, Above example shows how these ideas of computable functions and predicates can be useful.

It also makes use of the notion of equality and allows equal objects to be substituted for each

other whenever it appears helpful to do so during a proof.

 So, Now suppose we want to answer the question “Is Marcus alive?”

 The statements suggested here, there may be two ways of deducing an answer.

 Either we can show that Marcus is dead because he was killed by the volcano or we can

show that he must be dead because he would otherwise be more than 150 years old,

which we know is not possible.

 Also, As soon as we attempt to follow either of those paths rigorously, however, we

discover, just as we did in the last example, that we need some additional knowledge. For

example, our statements talk about dying, but they say nothing that relates to being alive,

which is what the question is asking.

So we add the following facts:

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 dead at all later times.

x: t1: At2: died(x, t1) gt(t2, t1) → dead(x, t2)

So, Now let’s attempt to answer the question “Is Marcus alive?” by proving: ¬ alive(Marcus,

now)

Resolution

Propositional Resolution

1. Convert all the propositions of F to clause form.

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

step 1.

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

1. Select two clauses. Call these the parent clauses.

2. Resolve them together. The resulting clause, called the resolvent, will be the

disjunction of all of the literals of both of the parent clauses with the following

exception: If there are any pairs of literals L and ¬ L such that one of the parent

clauses contains L and the other contains ¬L, then select one such pair and

eliminate both L and ¬ L from the resolvent.

3. If the resolvent is the empty clause, then a contradiction has been found. If it is

not, then add it to the set of classes available to the procedure.

The Unification Algorithm

 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 the man(John) and

¬man(Spot) is not.

 Thus, in order to determine 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 straightforward recursive procedure, called the unification algorithm, that does

it.
Algorithm: Unify(L1, L2)

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

1. If L1 and L2 are identical, then return NIL.

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

(L2/L1).

3. Also, Else if L2 is a variable, then if L2 occurs in L1 then return {FAIL}, else

return (L1/L2). d. Else return {FAIL}.

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

3. If LI 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 the number of arguments in L1 :

1. Call Unify with the ith argument of L1 and the ith argument of L2, putting the

result in S.

2. If S contains FAIL then return {FAIL}.

3. If S is not equal to NIL then:

2. Apply S to the remainder of both L1 and L2.

3. SUBST: = APPEND(S, SUBST).

6. Return SUBST.

Resolution in Predicate Logic

We can now state the resolution algorithm for predicate logic as follows, assuming a set of given

statements F and a statement to be proved P:

Algorithm: Resolution

1. Convert all the statements of F to clause form.

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

3. Repeat until a contradiction found, no progress can make, or a predetermined amount of

effort has expanded.

1. Select two clauses. Call these the parent clauses.

2. Resolve them together. The resolvent will the disjunction of all the literals of both

parent clauses with appropriate substitutions performed and with the following

exception: If there is one pair of literals T1 and ¬T2 such that one of the parent
clauses contains T2 and the other contains T1 and if T1 and T2 are unifiable, then

neither T1 nor T2 should appear in the resolvent. We call T1 and T2

Complementary literals. Use the substitution produced by the unification to create

the resolvent. If there is more than one pair of complementary literals, only one

pair should omit from the resolvent.

3. If the resolvent is an empty clause, then a contradiction has found. Moreover, If it

is not, then add it to the set of classes available to the procedure.

Resolution Procedure

 Resolution is a procedure, which gains its efficiency from the fact that it operates on

statements that have been converted to a very convenient standard form.

 Resolution produces proofs by refutation.

 In other words, to prove a statement (i.e., to show that it is valid), resolution attempts to

show that the negation of the statement produces a contradiction with the known

statements (i.e., that it is unsatisfiable).

 The resolution procedure is a simple iterative process: at each step, two clauses, called

the parent clauses, are compared (resolved), resulting in a new clause that has inferred

from them. The new clause represents ways that the two parent clauses interact with each

other. Suppose that there are two clauses in the system:

winter V summer

¬ winter V cold

 Now we observe that precisely one of winter and ¬ winter will 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 summer must be true to guarantee the truth of the first clause.

 Thus we see that from these two clauses we can deduce summer V cold

 This is the deduction that the resolution procedure will make.

 Resolution operates by taking two clauses that each contains the same literal, in this

example, winter.

 Moreover, The literal must occur in the positive form in one clause and in negative form

in the other. The resolvent obtained by combining all of the literals of the two parent

clauses except the ones that cancel.

 If the clause that produced is the empty clause, then a contradiction has found.
For example, the two clauses

Winter

¬ winter

will produce the empty clause.

You might also like