Block 1
Block 1
Block 1
SOCIS FACULTY
Prof. P. Venkata Suresh, Director, SOCIS, IGNOU Prof. V.V. Subrahmanyam, SOCIS, IGNOU
Prof. Sandeep Singh Rawat, SOCIS, IGNOU Prof. Divakar Yadav, SOCIS, IGNOU
Dr. Akshay Kumar, Associate Professor, SOCIS, IGNOU Dr. Sudhansh Sharma, Assistant Professor, SOCIS, IGNOU
Dr. M.P. Mishra, Associate Professor, SOCIS, IGNOU
PREPARATION TEAM
BLOCK 1 & BLOCK-2 BLOCK 3 & BLOCK-4
Prof Ela Kumar (Content Editor- Block 1 & 2) Prof Anjana Gosain (Content Editor – Block 3 & 4)
Department of Computers & Engg. IGDTUW, Delhi USICT-GGSIPU, Delhi
Prof.Parmod Kumar (Language Editor- Block 1 & 2) Dr. Rajesh Kumar (Language Editor – Block 3 & 4)
SOH, IGNOU, New Delhi SOH, IGNOU, New Delhi
Dr. Sudhansh Sharma, (Writer- Unit 1) Dr. Venu Gopal,(Writer- Unit 9)
Assistant Professor SOCIS, IGNOU General Manager,Sify Technologies, Noida,U.P
(Unit-1 : Partially Adapted from MCSE003 Artificial Dr. Sudhansh Sharma, (Writer – Unit 10)
Intelligence & Knowledge Management) Assistant Professor, SOCIS, IGNOU
Dr. Anant Kumar Jayswal, (Unit-10 : Partially Adapted from MCS 043
(Writer – Unit 2 & Unit 3) Advanced Database Management Systems)
Assistant Professor,Amity School of Engineering & Technology Dr. Parmod Kumar Sagar, (Writer-Unit 11)
Prof. Arvind (Writer Unit-4) Assistanr Professor(Sr.G)Department of Computer Applications,
Department of Mathematics, Hansraj College SRM Institute of Science and Technology,
University of Delhi Delhi NCR Campus Modinagar, U.P.
Dr. Sudhansh Sharma, (Writer- Unit 5 & Unit 6) Prof. Sachin Kumar (Writer-Unit 12)
Assistant Professor, SOCIS, IGNOU Department of Computer Science and Engineering
(Writer- Unit 5,6)-(Partially Adapted from MCSE003 Artificial Ajay Kumar Garg Engineering College, Ghaziabad, U.P.
Intelligence & Knowledge Management) Dr. Sudhansh Sharma, (Writer- Unit 13)
Dr. Manish Kumar, (Writer- Unit 7) Assistant Professor, SOCIS, IGNOU
Assistant Professor, SOCIS, IGNOU Ms. Divya Kwatra, (Writer Unit 14)
(Writer- Unit 7 Partially Adapted from AST-01) Assistant Professor, Department of Computer Science
Dr. Sudhansh Sharma, (Writer- Unit 8) Hansraj College, University of Delhi
Assistant Professor, SOCIS, IGNOU Ms. Sofia Goel, (Writer Unit 15)
(Writer- Unit 8)-(Partially Adapted from MCSE003 Research Scholar, SOCIS, IGNOU
Artificial Intelligence & Knowledge Management)
Ms. Sanyukta Kesharwani (Writer - Unit 16)
Director(Reserach), Scholastic Seed Inc., Delhi
COURSE COORDINATOR
Dr. Sudhansh Sharma
Assistant Professor, SOCIS, IGNOU
PRINT PRODUCTION
Mr. Sanjay Aggarwal
Assistant Registrar,MPDD, IGNOU, New Delhi
August, 2023
© Indira Gandhi National Open University, 2023
ISBN: 978-93-5568-926-9
All rights reserved. No part of this work may be reproduced in any form, by mimeograph or any other means, without
permission in writing from the Indira Gandhi National Open University.
2 Print at: M/s Educational Stores, S-5 Bulandshahar Road Industrail Area, Site-1, Ghaziabad (UP)-201009
COURSE INTRODUCTION
This course MCS-224 Titled “Artificial Intelligence and Machine Learning” is
a 4 credit course and it relates to the conceptual understanding of the Artificial
Intelligence and Machine Learning. Generally, Artificial Intelligence (AI) is
considered as the discipline, to deal with the solution of the hard and insolvable
problems using reasonable amount of time, by exploiting the knowledge of
the problem domain. In view of the significance of knowledge in AI, in this
course, a number of knowledge representation formalisms are introduced. The
formalisms discussed include Propositional Logic, First Order Predicate Logic,
Rule-based systems, Semantic Networks and Frames. Further, the course
introduces the various concepts of Machine learning, Viz. Supervised learning,
Unsupervised Learning and their respective application areas. Currently these
two fields i.e. Artificial Intelligence and Machine Learning are in high demand,
the course will help the learners to build the understanding of these fields.
In order to be well versed with this course you need to have some understanding
of Discrete Mathematics, and Python as a programming language. The course
is comprised of four blocks, in all covering 16 units. The entire coverage is
divided in a manner that Block-1 and Block-2 covers the understanding of
Artificial Intelligence, i.e. Unit 1 to 8 relates to Artificial Intelligence. Whereas,
the Block-3 and Block-4 (i.e. unit 9 to 16) covers the fundamentals of Machine
Learning.
The concise structure of this course is given below :
Block-1 Artificial Intelligence - Introduction:
• Unit-1 Introduction to Artificial Intelligence
• Unit-2 Problem Solving using Search
• Unit-3 Uninformed and Informed Search
• Unit-4 Predicate and Propositional Logic
Block-2 Artificial Intelligence - Knowledge Representation
• Unit-5 First Order Logic
• Unit-6 Rule based Systems and other formalism
• Unit-7 Probabilistic Reasoning
• Unit-8 Fuzzy and Rough Set
Block-3 Machine Learning - I:
• Unit-9 Introduction to Machine Learning Methods
• Unit-10 Classification
• Unit-11 Regression
• Unit-12 Neural Networks and Deep Learning:
Block-4 Machine Learning - II:
• Unit-13 Feature selection and Extraction
• Unit-14 Association Rules
• Unit-15 Clustering
• Unit-16 Machine Learning Programming using Python
After going through the content of this course MCS-224 Titled “Artificial
Intelligence and Machine Learning”, you will be in the position to begin your
journey in this upcoming and promising field of Artificial Intelligence and
3
Machine Learning.
4
Block
1
ARTIFICIAL INTELLIGENCE –
INTRODUCTION
Unit 1
Introduction to Artificial Intelligence 09
Unit 2
Problem Solving using Search 39
Unit 3
Uninformed and Informed Search 85
Unit 4
Predicate and Propositional Logic 137
5
PROGRAMME DESIGN COMMITTEE
Prof. (Retd.) S.K. Gupta , IIT, Delhi Sh. Akshay Kumar, Associate Professor, SOCIS, IGNOU
Prof. Ela Kumar, IGDTUW, Delhi Dr. P. Venkata Suresh, Associate Professor, SOCIS, IGNOU
Prof. T.V. Vijay Kumar JNU, New Delhi Dr. V.V. Subrahmanyam,Associate Professor,SOCIS, IGNOU
Prof. Gayatri Dhingra, GVMITM, Sonipat Sh. M.P. Mishra, Assistant Professor, SOCIS, IGNOU
Mr.Milind Mahajan,Impressico Business Solutions, Dr. Sudhansh Sharma, Assistant Professor, SOCIS, IGNOU
New Delhi
Sh.Shashi Bhushan Sharma, Associate Professor,
SOCIS, IGNOU
COURSE DESIGN COMMITTEE
Prof. T.V. Vijay Kumar JNU, New Delhi Sh. Akshay Kumar, Associate Professor, SOCIS, IGNOU
Prof. S.Balasundaram, JNU, New Delhi Dr.P.Venkata Suresh,Associate Professor,SOCIS, IGNOU
Prof D.P. Vidyarthi, JNU, New Delhi Dr.V.V.Subrahmanyam,Associate Professor,SOCIS, IGNOU
Prof. Anjana Gosain, USICT, GGSIPU, New Delhi Sh. M.P. Mishra, Assistant Professor, SOCIS, IGNOU
Ayesha Choudhary, JNU, New Delhi Dr. Sudhansh Sharma, Assistant Professor, SOCIS, IGNOU
Sh.Shashi Bhushan Sharma, Associate Professor,
SOCIS, IGNOU
SOCIS FACULTY
Prof. P. Venkata Suresh, Director, SOCIS, IGNOU
Prof. Sandeep Singh Rawat, SOCIS, IGNOU Prof. Divakar Yadav, SOCIS, IGNOU
Dr. Akshay Kumar, Associate Professor, SOCIS, IGNOU Dr. Sudhansh Sharma, Assistant Professor, SOCIS, IGNOU
Dr. M.P. Mishra, Associate Professor, SOCIS, IGNOU
PREPARATION TEAM
Dr.Sudhansh Sharma, (Writer- Unit 1) Prof Ela Kumar (Content Editor)
Assistant Professor SOCIS, IGNOU Department of Computers & Engg. IGDTUW, Delhi
(Unit-1 : Partially Adapted from MCSE003
Prof.Parmod Kumar (Language Editor)
SOH, IGNOU, New Delhi
Dr. Anant Kumar Jayswal, (Writer – Unit 2 & Unit 3)
Assistant Professor
Amity School of Engineering and Technology
COURSE COORDINATOR
Dr. Sudhansh Sharma
Assistant Professor, SOCIS, IGNOU
PRINT PRODUCTION
Mr. Sanjay Aggarwal
Assistant Registrar,MPDD, IGNOU, New Delhi
August, 2023
© Indira Gandhi National Open University, 2023
ISBN: 978-93-5568-926-9
All rights reserved. No part of this work may be reproduced in any form, by mimeograph or any other means, without
permission in writing from the Indira Gandhi National Open University.
6
BLOCK INTRODUCTION
The Block-1 Titled “Artificial Intelligence – Introduction” is comprised of four
units, the details are as follows :
• Unit-1 Introduction to Artificial Intelligence
• Unit-2 Problem Solving using Search
• Unit-3 Uninformed and Informed Search
• Unit-4 Predicate and Propositional Logic
In Unit 1 – “Introduction to Artificial Intelligence”, we will give an overview
of the discipline of AI in terms of some general concepts and definitions and
through enumeration (without any detailed discussion) of tools and techniques
of AI that help in solving problems requiring non-symbolic representations and
non-algorithmic processes for solutions. In this context, we mentioned that
knowledge of the problem domain plays an important role in solving difficult
problems.
Unit-2 – “Problem Solving using Search “ and Unit-3 – “Uninformed and
Informed Search “ Covers the various searching techniques, involved in the
field of Artificial Intelligence.
Finally, Unit-4 - “Predicate and Propositional Logic” discusses the fundamentals
of predicate and propositional logic. Here, we discuss Propositional Logic (PL)
as a vehicle for knowledge representation, for making inferences and for solving
problems, the concepts you learn in this units helps to establish your connect
with next Block i.e. Block no. 2 of this course.
7
8
UNIT 1 INTRODUCTION TO ARTIFICIAL
INTELLIGENCE
Structure
1.1 Introduction
1.2 Objectives
1.3 Basics of Artificial Intelligence (AI)?
1.4 Brief history of Artificial Intelligence
1.5 Components of Intelligence
1.6 Approaches to Artificial Intelligence
1.7 Comparison between Artificial Intelligence (AI), Machine Learning
(ML) and DeepLearning (DL).
1.8 Application Areas of Artificial Intelligence Systems
1.9 Intelligent Agents
1.9.1 Stimulus - Response Agents
1.10 Summary
1.11 Solutions/Answers
1.12 Further Readings
1.1 INTRODUCTION
Today, artificial intelligence is used in a wide variety of applications, including
engineering, technology, the military, opinion mining, sentiment analysis,
and many more. It is also used in more advanced domains, such as language
processing and applications for aerospace.
AI is everywhere in today's world, and people are gradually becoming accustomed
to its presence. It is utilised in systems that recognise both voices and faces.
In addition to this, it can provide you with shopping recommendations that
are tailored to your own purchasing preferences. Finding spam and preventing
fraudulent use of credit cards is made much easier when you have this skill. The
most cutting-edge technology currently on the market are virtual assistants like
Apple's Siri, Amazon's Alexa, Microsoft's Cortana, and Google's own Google
Assistant. It's possible that you're already familiar with the technology involved
in artificial intelligence (AI). Are you?
AI has become very popular all over the world today. It imitates human
intelligence in machines by programming them to do the same things people do.
As a technology, AI is going to have a bigger impact on how people live their
daily lives. Everyone wants to connect to Artificial Intelligence as a technology
these days. Before we can understand AI, we need to know and talk about
some basic things. For example, what is the difference between knowledge and
intelligence? The key to starting this unit is the answer to this question.
9
Artificial Intelligence The accumulation of information and abilities that a person has gained through
– Introduction their life experiences is known as knowledge. While intelligence refers to one's
capacity to put one's knowledge into practise. To put it simply, knowledge is
what we have learned over the years, and it expands as time passes. Because
of this, it represents the culmination of everything that we have realised over
the course of our lives. It is important to highlight that having information does
not automatically make one intelligent; rather, intelligence is what makes one
smart.
There is a well-known proverb that says "marks are not the measure of
intelligence." This is due to the fact that intelligence is not a measurement of
how much information one possesses. In fact, it is the measure of how much
we comprehend and put into practise. People who are knowledgeable may gain
a lot of information, but an intelligent person understands how to comprehend,
analyze, and use the information. You could have a lot of knowledge but still
be the least intelligent person in the room. Knowledge and intelligence are
inextricably linked, and each contributes to the other's development. Knowledge
enables one to learn the understandings that others have of things, whereas
intelligence is the foundation for one's ability to grasp the things themselves.
Now that we have an understanding of the distinction between intelligence and
knowledge, our next issue is: what exactly is artificial intelligence? Incorporating
intelligence into a machine is related to the field of Artificial Intelligence, whereas
both concepts, namely the representation of knowledge and its engineering, are
the basis of traditional AI research. This topic will be discussed in section 1.3
of this unit, but in a nutshell, incorporating intelligence into a machine is related
to the field of Artificial Intelligence. Knowledge engineering is a subfield of
artificial intelligence (AI) that applies rules to data in order to simulate the way
in which an expert would think about the information. It does this by analysing
the structure of a job or a decision in order to figure out how one arrives at a
conclusion.
The subsequent units of this course, you will learn about some of the concepts
that are essential for knowledge representation, such as frames, scripts, and
other related topics. In addition, this course will address the issues that are
associated with the knowledge representation for uncertain situations, such
as employing the method of fuzzy logic, rough sets, and the Dempster Shafer
theory, among other relevant topics.
Some of the prerequisites to get started with this subject.
a) Strong understanding of Basic concepts of Mathematics viz. Algebra,
Calculus, probability andStatistics.
b) Experience in programming using Python or Java.
c) A good understanding of algorithms.
d) Reasonably good data analytics skills.
e) Fundamental knowledge in discrete mathematics.
f) Finally, internal will to learn
10
1.2 OBJECTIVES Introduction to
Artificial Intelligence
After going through this unit, you will be able to:
• Understand the difference between knowledge and intelligence
• Answer – what is AI?
• Identify various approaches of AI
• Compare Artificial Intelligence (AI), Machine Learning (ML) & Deep
Learning (DL).
• Understand the concept of agents in AI
11
Artificial Intelligence According to the concepts presented earlier, there are four distinct objectives
– Introduction that might be pursued in the field of artificial intelligence. These objectives are
as follows:
• The creation of systems that think in the same way as people do.
• The creation of systems that are capable of logical thought.
• The creation of machines that can mimic human behaviour.
• The creation of systems that behave in a logical manner
In addition, we discovered through our conversation in the earlier section 1.1 of
this Unit, that Artificial Intelligence (AI) is the intelligence that is incorporated
into machines; in other words, AI is the ability of a machine to display human-
like capabilities such as reasoning, learning, planning, and creativity. We learned
this information because AI is the ability of a machine to display human-like
capabilities. Taking into mind the Emerging AI technologies to sense, interpret,
and act according to the circumstances, relevant exemplary solutions are
summarised in Figure 1, which attempts to encapsulate the understanding of
the question "What is Artificial Intelligence?"
Identify
Analytics
Machine Learning
Act Data
Visualization
Expert Systems
The applications of artificial intelligence (AI) that are shown in figure-1 do not
all require the same kinds of AI. In a general sense, one may say that AI can be
categorised into the following levels:
• software level (i.e., Embodied AI). Where, the software level consists of
things like search engines, virtual assistants, speech and facial recognition
systems, picture analysis tools, and other things like that.
• Hardware level (Embedded) includes Robots, autonomous vehicles, drones,
the Internet of Things, and other technologies fall under the category of
embedded artificial intelligence (AI).
On the basis of the functionalities the AI can be classified based on Type 1 and
Type 2
12
Introduction to
Artificial Intelligence
Strong
AI
Here’s a brief introduction the first type of AI i.e., Type 1 AI. Following are the
three stages of Type 1 - Artificial Intelligence:
a) Artificial Narrow Intelligence-(ANI)
b) Artificial General Intelligence-(AGI)
c) Artificial Super Intelligence-(ASI)
14
In the 1800s, George Boole came up with a number system called "binary Introduction to
algebra" that showed (some) "laws of thought." Artificial Intelligence
For the purpose of the test, There are three rooms that will be used for the test.
In one of the rooms, there is a computer system that is said to be smart. In each
of the other two rooms, there is one person sitting. One of the people, who we'll
call C, is supposed to ask questions of the computer and the other person, who
we'll call B, without knowing who each question is for and, of course, with
the goal of figuring out who the computer is. On the other hand, the computer
would reply in a way that would keep C from finding out who it is.
The only way for the three of them to talk to each other is through computer
terminals. This means that the identity of the computer or person B can only be
determined by how intelligent or not the responses are, not by any other human
or machine traits. If C can't figure out who the computer is, then the computer
must be smart. More accurately, the computer is smart if it can hide its identity
from C.
21
Artificial Intelligence Note that for a computer to be considered smart, it should be smart enough not
– Introduction to answer too quickly, at least not in less than a hundredth of a second, even if
it can do something like find the sum of two numbers with more than 20 digits
each.
Criticism to Turing Test: There have been a number of criticisms of the Turing
test as a machine intelligence test. The Chinese Room Test, developed by John
Searle, is one of the most well-known Criticism. The crux of the Chinese
Room Test, which we'll discuss below, is that convincing a system, say A, that
it possesses qualities of another system, say B, does not suggest that system
A actually possesses those qualities. For example, a male human's ability to
persuade people that he is a woman does not imply that he is capable of bearing
children like a woman.
The scenario for the Chinese Room Test takes place in a single room with two
windows. A Shakespeare scholar who knows English but not Chinese is sitting
in the room with a kind of Shakespeare encyclopaedia. The encyclopaedia is
printed so that for every pair of pages next to each other, one page is written in
Chinese characters and the other page is an English translation of the Chinese
page. Through one of the windows, Chinese characters with questions about
Shakespeare's writing are sent to the person inside. The person looks through
the encyclopaedia and, when he or she finds the exact copy of the sequence of
characters sent in, reads the English translation, thinks of the answer, and writes
it down in English for his or her own understanding. The person then looks in the
encyclopaedia for the corresponding sequence of Chinese characters and sends
the sequence of Chinese characters through the other window. Now, Searle says
that even though the scholar acts as though he or she knows Chinese, this is not
the case. Just because a system can mimic a quality doesn't mean that it has that
quality.
Thinking humanly: It is the cognitive modeling approach to thinking like a
human, from this point of view, the Artificial Intelligence model is based on
Human Cognition, which is the core of the human mind. This is done through
three approaches, which are as follows:
• Introspection, which means to look at our own thoughts and use those
thoughts to build a model.
• Psychological Experiments, which means running tests on people and
looking at how they act.
• Brain imaging, which means to use an MRI to study how the brain works in
different situations and then copy that through code.
Thinking rationally i.e. The laws of thought approach: This approach Relates
to use the laws of thought to think logically: The Laws of Thought are a long
list of logical statements that tell our minds how to work. This method, called
"Thinking Rationally," is based on these laws. By putting in place algorithms
for artificial intelligence, these laws can be written down and made to work. But
solving a problem by following the law is very different from solving a problem
in the real world. Here are the biggest problems with this approach.
22
Acting rationally i.e. The rational agent approach: In every situation, a Introduction to
rational agent approach tries to find the best possible outcome. This means that Artificial Intelligence
it tries to make the best decision it can given the circumstances. It means that
the agent approach is much more flexible and open to change. The Laws of
Thought approach, on the other hand, says that a thing must act in a way that
makes sense. But there are some situations where there is no logically right
thing to do and there are more than one way to solve the problem, each with
different results and trade-offs. At that point, the rational agent method works
well.
☞ Check Your Progress 2
Q4 Briefly discuss the various components of intelligence
.....................................................................................................................
.....................................................................................................................
.....................................................................................................................
Q5 How do we measure if Artificial Intelligence is making a machine to behave
or act or perform like human being or not?”
.....................................................................................................................
.....................................................................................................................
.....................................................................................................................
Q6 What is Turing Test? What is the Criticism to the Turing Test?
.....................................................................................................................
.....................................................................................................................
.....................................................................................................................
23
Artificial Intelligence
– Introduction
25
Artificial Intelligence Q8 Compare Descriptive, Predictive and Prescriptive analytics performed
– Introduction under Machine Learning.
.....................................................................................................................
.....................................................................................................................
.....................................................................................................................
All of the stages of the agricultural value chain indicated above in figure 5 have
the potential for the application of artificial intelligence and other associated
technologies to have an impact on the levels of production and efficiency at
those stages.
c) Smart Mobility, including Transports and Logistics: Autonomous fleets for
ride sharing, semi-autonomous features such as driver assistance, and predictive
engine monitoring and maintenance are all possible use cases for smart mobility,
which includes transportation and logistics. Other areas where AI can have a
positive impact include self-driving trucks and delivery, as well as better traffic
control.
d) Retail: The retail industry was one of the first to use AI solutions. For
example, personalised suggestions, browsing based on user preferences, and
image-based product search have all been used to improve the user experience.
Other use cases include predicting what customers will want, keeping track of
inventory better, and managing deliveries more efficiently.
e) Manufacturing: AI-based solutions are expected to help the manufacturing
industry the most. This will make possible the "Factory of the Future" by
allowing flexible and adaptable technical systems to automate processes and
machinery that can respond to new or unexpected situations by making smart
decisions. Impact areas include engineering (AI for R&D), supply chain
management (predicting demand), production (AI can cut costs and increase
efficiency), maintenance (predictive maintenance and better use of assets),
quality assurance (e.g., vision systems with machine learning algorithms
to find flaws and differences in product features), and in-plant logistics and
warehousing.
f) Energy: In the energy sector, possible use cases include modelling and
forecasting the energy system to make it less unpredictable and make balancing
27
Artificial Intelligence and using power more efficient. In renewable energy systems, AI can help store
– Introduction energy through smart metres and intelligent grids. It can also make photovoltaic
energy more reliable and less expensive. AI could also be used to predict
maintenance of grid infrastructure, just like it is in manufacturing.
g) Smart Cities: Integrating AI into newly built smart cities and infrastructure
could also help meet the needs of a population that is moving to cities quickly
and improve the quality of life for those people. Some possible use cases include
controlling traffic to reduce traffic jams and managing crowds better to improve
security.
h) Education and Skilling: Quality and access problems in the education
sector might be fixed by AI. Possible uses include adding to and improving the
learning experience through personalized learning, automating and speeding
up administrative tasks, and predicting when a student needs help to keep them
from dropping out or to suggest vocational training.
i) Financial industry: The financial industry also uses AI. For example, it helps
the fraud department of a bank find and flag suspicious banking and finance
activities like unusual debit card use and large account deposits. AI is also used
to make trading easier and more efficient. This is done by making it easier to
figure out how many securities are being bought and sold and how much they
cost.
Top Used Applications of Artificial Intelligence
• Tools and checkers for plagiarism
• Recognizing faces;
• Putting an AI autopilot on commercial planes
• Applications for sharing rides (E.g.: Uber, Lyft)
• E-mail spam filters; voice-to-text features; search suggestions
• Google's predictions based on AI (E.g.: Google Maps)
• Protecting against and stopping fraud.
• Smart personal assistants (E.g.: Siri, Alexa)
There are various ways to use artificial intelligence. The technology can be used
in different industries and sectors, but the adoption of AI by different sectors has
been affected by technical and regulatory challenges, but the biggest factor has
been how it will affect business.
In order to further have an idea about what a computer agent is, let us consider
one of the first definitions of agent, which was coined by John McCarthy and
his friends at MIT.
A software agent is a system which, when given a goal to be achieved, could
carry out the details of the appropriate (computer) operations and further, in
case it gets stuck, it can ask for advice and can receive it from humans, may
even evaluate the appropriateness of the advice and then act suitably.
Essentially, a computer agent is a computer software that additionally has the
following attributes:
(i) it has autonomous control i.e., it operates under its own control
(ii) it is perceptive, i.e., it is capable of perceiving its own environment
(iii) it persists over a long period of time
(iv) it is adaptive to changes in the environment and
(v) it is capable of taking over others’ goals.
As the concept of Intelligent Agents is of relatively new, different pioneers and
other experts have been conceiving and using the term in different ways. There
are two distinct but related approaches for defining an agent. The first approach
treats an agent as an ascription i.e., the perception of a person (which includes
expectations and points of view) whereas the other approach defines an agent
on the basis of the description of the properties that the agent to be designed is
expected to possess.
Let us first discuss the definition of agent according to first approach. Among
the people who consider an agent as an ascription, a popular slogan is “Agent
is that agent does”. In everyday context, an agent is expected to act on behalf
of someone to carry out a particular task, which has been delegated to it. But to
perform its task successfully, the agent must have knowledge about the domain in
which it is operating and also about the properties of its current user in question.
In the course of normal life, we hire different agents for different jobs based on
the required expertise for each job. Similarly, a non-human intelligent agent
also is imbedded with required expertise of the domain as per requirements of
the job under consideration. For example, a football-playing agent would be
different from an email-managing agent, although both will have the common
attribute of modeling their user.
According to the second approach, an agent is defined as an entity, which
functions continuously and autonomously, in a particular environment, which
may have other agents also. By continuity and autonomy of an agent, it is
meant that the agent must be able to carry out its job in a flexible and intelligent
fashion and further is expected to adapt to the changes in its environment
without requiring constant human guidance or intervention. Ideally, an agent
that functions continuously in an environment over a long period of time would
also learn from its experience. In addition, we expect an agent, which lives in a
29
Artificial Intelligence multi-agent environment, to be able to communicate and cooperate with them,
– Introduction and perhaps move from place to place in doing so.
According to the second approach to defining agent, an agent is supposed to
possess some or all of the following properties:
Reactivity: The ability of sensing the environment and then acting
accordingly.
Autonomy: The ability of moving towards its goal, changing its moves or
strategy, if required, without much human intervention.
Communicating ability: The ability to communicate with other agents and
humans.
Ability to coexist by cooperating: The ability to work in a multi-agent
environment to achieve a common goal.
Ability to adapt to a new situation: Ability to learn, change and adapt to the
situations in the world around it.
Ability to draw inferences: The ability to infer or conclude facts, which
may be useful, but are not available directly.
Temporal continuity: The ability to work over long periods of time.
Personality: Ability to impersonate or simulate someone, on whose behalf
the agent is acting.
Mobility: Ability to move from one environment to another.
Task environments or problem environments are the environments, which
include all the elements involved in the problems for which agents are thought
of as solutions. Task environments will vary with every new task or problem
for which an agent is being designed. Specifying the task environment is a
long process which involves looking at different measures or parameters.
Next, we discuss a standard set of measures or parameters for specifying a task
environment under the heading PEAS.
PEAS (Performance, Environment, Actuators, Sensors)
For designing an agent, the first requirement is to specify the task environment
to the maximum extent possible. The task environment for an agent to solve
one type of problems, may be described by the four major parameters namely,
performance (which is actually the expected performance), environment (i.e.,
the world around the agent), actuators (which include entities through which the
agent may perform actions) and sensors (which describes the different entities
through which the agent will gather information about the environment).
The four parameters may be collectively called as PEAS. We explain these
parameters further, through an example of an automated agent, which we will
preferably call automated public road transport driver. This is a much more
complex agent than the simple boundary following robot which we have already
discussed.
Example (An Automated Public Road Transport Driver Agent)
30
We describe the task environment of the agent on the basis of PEAS. Introduction to
Artificial Intelligence
Performance Measures: Some of the performance measures which can easily be
perceived of an automated public road transport driver would be:
Maximizing safety of passengers
Maximizing comfort of passengers
Ability to reach correct destination
Ability to minimize the time to reach the destination Obeying traffic rules
Causing minimum discomfort or disturbance to other agents
Minimizing costs, etc.
Environment (or the world around the agent) We must remember that the
environment or the world around the agent is extremely uncertain or open ended.
There are unlimited combinations of possibilities of the environment situations,
which such an agent could face. Let us enumerate some of the possibilities or
circumstances which an agent might face:
Variety of roads e.g., from 12-lane express-ways, freeways to dusty rural
bumpy roads; different road rules including the ones requiring left-hand
drive in some parts of the world and right-hand drive-in other parts.
The degree of knowledge of various places through which and to which
driving is to be done.
Various kinds of passengers, including high cultured to almost ruffians etc.
All kind of other traffic possibly including heavy vehicles, ultra-modern
cars, three-wheelers and even bullock carts.
Actuators: These include the following:
Handling steering wheel, brakes, gears and accelerator
Understanding the display screen
A device or devices for all communication required
Sensors: The agent acting as automated public road transport driver must
have some way of sensing the world around it i.e., the traffic around it, the
distance between the automobile and the automobiles ahead of it and its speed,
the speeds of neighboring vehicles, the condition of the road, any turn ahead
etc. It may use sensors like odometer, speedometer, sensors telling the different
parameters of the engine, Global Positioning System (GPS) to understand its
current location and the path ahead. Also, there should be some sort of sensors
to calculate its distance from other vehicles etc.
We must remember that the agent example the automated public road transport
driver, which we have considered above, is quite difficult to implement.
However, there are many other agents, which operate in comparatively simpler
and less dynamic environments, e.g., a game playing robot, an assembly line
robot control, and an image processing agent etc.
31
Artificial Intelligence In respect of the design and development of intelligent agents, with the passage
– Introduction of time, the momentum seems to have shifted from hardware to software, the
letter being thought of as a major source of intelligence. But, obviously, some
sort of hardware is essentially needed as a home to the intelligent agent.
There are two parts of an agent or its structure:
• A (hardware) device with sensors and actuators in which that agent will
reside, called the architecture of the agent.
• An agent program that will convert or map the percepts in to actions.
Also, the agent program and its architecture are related in the sense that for a
different agent architecture a different type of agent program is required and
vice-versa. For example, in case of a boundary following robot, if the robot
does not have the capability of sensing adjacent cells to the right, then the agent
program for the robot has to be changed.
Next, we discuss different categories of agents, which are differentiated from
each other on the basis of their agent programs. Capability to write efficient
agent programs is the key to the success for developing efficient rational agents.
Although the table driven approach (in which an agent acts on the basis of the
set of all possible percepts by storing these percepts in tables) to design agents
is possible yet the approach of developing equivalent agent programs is found
much more efficient.
Next, we discuss some of the general categories of agents based on their agents’
programs, Agents can be grouped into five classes based on their degree of
perceived intelligence and capability. All these agents can improve their
performance and generate better action over the time. These are given below:
SR (Simple Reflex) agents
Model Based reflex agents
Goal-based agents
Utility based agents
Stimulus-Response Agents
Learning agents
SR (Simple Reflex) agents: These are the agents or machines that have no
internal state (i.e., the don’t remember anything) and simply react to the current
percepts in their environments. An interesting set of agents can be built, the
behaviour of the agents in which can be captured in the form of a simple set
of functions of their sensory inputs. One of the earliest implemented agents of
this category was called Machina Speculatrix. This was a device with wheels,
motor, photo cells and vacuum tubes and was designed to move in the direction
of light of less intensity and was designed to avoid the direction of the bright
light. A boundary following robot is also an SR agent. For an automobile-
driving agent also, some aspects of its behavior like applying brakes immediately
on observing either the vehicle immediately ahead applying brakes or a human
being coming just in front of the automobile suddenly, show the simple reflex
32
capability of the agent. Such a simple reflex action in the agent program of the Introduction to
agent can be implemented with the help of simple condition-action rules. Artificial Intelligence
It will allow the goal to be achieved more efficiently. Such an agent will be more
useful, i.e., will have more utility. A utility-based agent uses a utility function,
which maps each of the world states of the agent to some degree of success.
If it is possible to define the utility function accurately, then the agent will
be able to reach the goal quite efficiently. Also, a utility-based agent is able to
make decisions in case of conflicting goals, generally choosing the goal with
higher success rating or value. Further, in environments with multiple goals, the
utility-based agent quite likely chooses the goal with least cost or higher utility
goal out of multiple goals.
Stimulus-Response Agents: A stimulus response agent (or a reactive agent)
take input from the world through sensors, and then take action based on
those inputs through actuators. Between the stimulus and response, there is a
processing unit that can be arbitrarily complex. An example of such an agent is
one that controls a vehicle in a racing game: the agent “looks” at the road and
nearby vehicles, and then decides how much to turn and break. Such Agents
(Stimulus-Response Agents are the Reactive agents) represents a special
category of agents, which do not possess internal, symbolic models of their
environments; instead, they act/respond in a stimulus-response manner to the
present state of the environment in which they are embedded. These agents are
relatively simple and they interact with other agents in basic ways. Nevertheless,
complex patterns of behavior emerged from the interactions when the ensemble
of agents is viewed globally
Learning Agents: It is not possible to encode all the knowledge in advance,
required by a rational agent for optimal performance during its lifetime. This
is especially true of the real life, and not just theoretical, environments. These
environments are dynamic in the sense that the environmental conditions
change, not only due to the actions of the agents under considerations, but due
to other environmental factors also. For example, all of a sudden, a pedestrian
comes just in front of the moving vehicle, even when there is green signal for
the vehicle. In a multi-agent environment, all the possible decisions and actions
an agent is required to take, are generally unpredictable in view of the decisions
taken and actions performed simultaneously by other agents. Hence, the
ability of an agent to succeed in an uncertain and unknown environment
depends on its learning capability i.e., its capability to change approximately
its knowledge of the environment. For an agent with learning capability, some
initial knowledge is coded in the agent program and after the agent starts
operating, it learns from its actions the evolving environment, the actions of
its competitors or adversaries etc. so as to improve its performance in ever-
changing environment. If approximate learning component is incorporated in
the agent, then the knowledge of the agent gradually increases after each action
starting from its initial knowledge which was manually coded into it at the start.
Conceptually the learning agent consists of four components:
(i) Learning Component: It is the component of the agent, which on the basis
of the percepts and the feedback from the environment, gradually improves
the performance of the agent. 35
Artificial Intelligence (ii) Performance Component: It is the component from which all actions
– Introduction originate on the basis of external percepts and the knowledge provided by
the learning component.
The design of learning component and the design of performance element
are very much related to each other because a learning component is of no
use unless the performance component can be designed to convert the newly
acquired knowledge into better useful actions.
(iii) Critic Component: This component finds out how well the agent is
doing with respect to a certain fixed performance standard and it is also
responsible for any future modifications in the performance component.
The critic is necessary to judge the agent’s success with respect to the chosen
performance standard, especially in a dynamic environment. Forexample,
in order to check whether a certain job is accomplished, the critic will not
depend on external percepts only but it will also compare the current state
to the state, which indicates the completion of that task.
(iv) Problem Generator Component: This component is responsible for
suggesting actions (some of which may not be optimal) in order to gain
some fresh and innovative experiences. Thus, this component allows the
agent to experiment a little by traversing sometimes uncharted territories by
choosing some new and suboptimal actions. This may be useful, because
the actions which may seem suboptimal in a short run, may turn out to be
much better in the long run.
In the case of an automobile driver agent, this agent would be of little use if it
does not have learning capability, as the environment in which it has to operate
is totally dynamic and unpredictable in nature. Once the automobile driver
agent starts operating, it keeps on learning from its experiences, both
positive and negative. If faced with a totally new and previously unknown
situation, e.g., encountering a vehicle coming from the opposite direction on
a one-way road, the problem generator component of the driver agent might
suggest some innovative action to tackle this new situation. Moreover, the
learning becomes more difficult in the case of an automobile driver agent,
because the environment is only partially observable.
Different Forms of Learning in Agents: The purpose of embedding learning
capability in an agent is that it should not depend totally on the knowledge
initially encoded in it and on the external percepts for its actions. The agent
learns by evaluating its own decisions and/or making observations of new
situations it encounters in the ever-changing environment.
There may be various criteria for developing learning taxonomies. The criteria
may be based on –
• The type of knowledge learnt, e.g., concepts, problem-solving or game
playing,
• The type of representation used, e.g., predicate calculus, rules or frames,
• The area of application, e.g., medical diagnosis, scheduling or prediction.
36
☞ Check Your Progress 4 Introduction to
Artificial Intelligence
Q9 What are Intelligent agents in AI? Briefly discuss the properties of Agents.
.....................................................................................................................
.....................................................................................................................
.....................................................................................................................
Q10 What are Task environments? Briefly discuss the standard set of measures
or parameters for specifying a task environment under the heading PEAS.
.....................................................................................................................
.....................................................................................................................
.....................................................................................................................
1.10 SUMMARY
In this unit we learned about the difference between knowledge and intelligence
and also pointed out the meaning of Artificial Intelligence (AI), along with the
application of AI systems in various fields. The unit also covers the historical
development of the field of AI systems. Along with the development of the AI
as a discipline, the need of classification of AI systems was felt, and hence the
unit discussed the classification of the AI systems in detail. Further, the unit
discussed about the concepts of Artificial Intelligence (AI), Machine Learning
(ML) and Deep Learning (DL). Finally, the unit discussed the components
of Intelligence, which was extended for the understanding of the concepts of
Intelligent Agents, with special emphasis on Stimulus - Response Agents
1.11 SOLUTIONS/ANSWERS
☞ Check Your Progress 1
Q1 How Knowledge differs from intelligence? What do you understand by the
term Artificial Intelligence (AI) ? List the various technologies and their
corresponding illustrative solutions.
Sol- Refer section 1.3
Q2 Classify AI on the basis of the functionalities of AI
Sol- Refer section 1.3
Q3 Compare ANI, AGI and ASI, in context of AI
Sol- Refer section 1.3
☞ Check Your Progress 2
Q4 Briefly discuss the various components of intelligence
Sol – Refer Section 1.5
37
Artificial Intelligence Q5 How do we measure if Artificial Intelligence is making a machine to behave
– Introduction or act or perform like human being or not ?”
Sol – Refer Section 1.6
Q6 What is Turing Test? What is the Criticism to the Turing Test ?
Sol – Refer Section 1.6
☞ Check Your Progress 3
Q7 Compare Artificial Intelligence (AI), Machine Learning (ML), and Deep
Learning (DL).
Sol – Refer Section 1.7
Q8 Compare Descriptive, Predictive and Prescriptive analytics performed
under Machine Learning.
Sol – Refer Section 1.7
☞ Check Your Progress 4
Q9 What are Intelligent agents in AI? Briefly discuss the properties of Agents.
Sol – Refer Section 1.9
Q10 What are Task environments? Briefly discuss the standard set of measures
or parameters for specifying a task environment under the heading PEAS.
Sol – Refer Section 1.9
38
UNIT 2 PROBLEM SOLVING USING SEARCH Introduction to
Artificial Intelligence
Structure
2.0 Introduction
2.1 Objectives
2.2 Introduction to State Space Search
2.2.1 Problem Formulation
2.8 Summary
2.9 Solutions/Answers
2.10 Further readings
2.0 INTRODUCTION
Many AI-based applications need to figure out how to solve problems. In the
world, there are two types of problems. First, the problem which can be solved
by using deterministic procedure and the success is guaranteed. But most real-
world problems can be solved only by searching a solution. AI is concerned
with these second types of problems solving.
39
Artificial Intelligence To build a system to solve a problem, we need to
– Introduction
Define the problem precisely-find initial and final configuration for
acceptable solution to the problem.
Analyse 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 it to the particular
problem.
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.
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 than one goal states.
d) Defining a set of rules for the actions (operators) that can be taken.
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. All Al problems are formulated as search
problems.
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 shown
in example below.
40
A tree is a graph in which any two vertices are connected by exactly one path. Problem Solving using
Alternatively, any connected graph with no cycles is a tree. Search
So, State space is the one of the methods to represent the problem in AI. A set
of all possible states reachable from the initial state by taking some sequence of
action (using some operator) for a given problem is known as the state space of
the problem. A state space represents a problem in terms of states and operators
that change states”.
In this unit we examine the concept of a state space and the different search
process that can be used to explore the search space in order to find a solution
(Goal) state. In the worst case, search explores all possible paths between the
initial state and the goal state.
For better understanding of these definitions describe above, consider the
following 8-puzzle problem:
Eight-Puzzle problem Formulation from AI perspectives
initial state: some configuration of the 8-tiles on a 9-cell board.
operators (Action): it’s easier if we focus on the blank. There are 4 operators
that is, “Moving the blank” : UP, DOWN, LEFT and RIGHT.
Uniformed/Blind 1 2 Move 3 2
3 the
4 5 blank 4 1 5
6 7 8 up 6 7 8
1 2
3 4 5
6 7 8
2.1 OBJECTIVES
After studying this unit, you should be able to:
• Understand the state space search
• Formulate the problems in the form of state space
• Understand how implicit state space can be unfolded during search
• Explain State space search representation for Water-Jug, 8-puzzle and
N-Queen’s problem.
• Solve N Queen’s Problem using Backtracking approach
• Understand adversarial search (two agent search)
• Differentiate between Minimax and Alpha-beta pruning search algorithm.
42
2.2 INTRODUCTION TO STATE SPACE SEARCH Problem Solving using
Search
It is necessary to represent an AI problem in the form of a state space before it
can be solved. A state space is the set of all states reachable from the initial state.
A state space forms a graph in which the nodes are states and the arcs between
nodes are actions. In state space, a path is a sequence of states connected by a
sequence of actions.
43
Artificial Intelligence of a left side that determines the applicability of the rule and a right side that
– Introduction describes the action to be performed, if the rule is applied.
G: Set of Goal state, G∈S.
The sequence of actions (or operators) is called a solution path. It is a path
from the initial state to a goal state. This sequence of actions leads to a number
of states, starting from initial state to a goal state, as {s0,s1,s2,……,sn∈G}. A
sequence of state is called a path. The cost of a path is a positive number. In
most of the cases the path cost is computed as the sum of the costs of each
action.
The following figure 3 shows a search process in a given state space.
We need to identify a sequence of actions that will turn the initial state s_0 into
the desired goal state G. State space is commonly defined as a directed graph or
as a tree in which each node is a state and each arc represents the application of
an operator transforming a state to a successor state.
The state space or production rule of this problem can be defined as a collection
of ordered pairs of integers (x,y) where x=0,1,2,3,4and y= 0,1,2,or 3.
In the order pair (x,y), x is the amount of water in four-gallon jug and y is the
amount of water in the three-gallon jug.
State space: all possible combination of (x,y)
The start state is (0,0) and
Goalstate is (2,n),where n=0,1,2,3
The following table-1 shows the set of production rules (actions) that can be
used to change one state to another.
Table-1 : Production rules for Water Jug problem
Production Rules
Rule No Production Meaning
R1 (x,y │ x<4)→(4,y) Fill 4-gallon jug
R2 (x,y │ y<3)→(x,3) Fill 3-gallon jug
R3 (x,y │ x>0)→(0,y) Empty 4-gallon jug
R4 (x,y │ y>0)→(x,0) Empty 3-gallon jug
R5 (x,y│x+y≥4 and y>0) Pour water from 3-gallon jug
→(4,y-(4-x)) into 4-gallon jug until 4-gallon
jug is full
R6 (x,y│x+y≥3 and x>0) Pour water from 4-gallon jug
→(x-(3-y),3) into 3-gallon jug until 3-gallon
jug is full 45
Artificial Intelligence
– Introduction
R7 (x,y│x+y≤4 and y>0)→(x+y,0) Pour all water from 3-gallon
jug into 4-gallon jug.
R8 (x,y│x+y≤3 and x>0)→(0,x+y) Pour all water from 4-gallon
jug into 3-gallon jug.
R9 (x,y │ x>0)→(x-d,y) Pure some water d out from
4-gallon jug
R10 (x,y │ y>0)→(x,y-d) Pure some water d out from
3-gallon jug
The following 2 solutions are found for the problem “how can you get exactly 2
gallons of water into 4-gallon jug”, as shown in Table-2 and in Table-3.
Solution-1:
Table-2Getting exactly 2 gallons of water into 4-gallon jug (solution1)
Solution-2
Table-3Getting exactly 2 gallons of water into 4-gallon jug (solution2)
A state space tree for WJP with all possible solution is shown in figure 7.
46
Problem Solving using
[0,0] Search
[4,0] [0,3]
[1,0] [3,3]
[0,1] [4,2]
[4,1] [0,2]
[2,3] [2,0]
Path Cost: Sum of the cost of each path from initial state to goal state. Here
cost of each action (blank move) = 1, so cost of a sequence of actions= the
number of actions. A optimal solution is one which has a lowest cost path.
Performing State-Space Search: Basic idea:
If the initial state is a goal state, return it.
If not, apply the operators to generate all states that are one step from the initial
state (its successors)
3 1 2 3 2 3 1 2 3 1 2 3 1 2
4 5 4 1 5 3 7 5 4 5 4 5
6 7 8 6 7 8 6 8 6 7 8 6 7 8
initial state Its successors
Fig 7 All possible successors for a given initial state
Consider the successor (and their successors…) until you find a goal state.
Different search strategies consider the state in different orders. They may use
different data structures to store the states that have yet to be considered.
State-Space Search Tree for 8-Puzzle problem:
The predecessor reference connects the search nodes, creating a data structure
known as a tree.
3 1 2
4 5 Initial state
6 7 8
3 2 3 1 2 3 1 2 3 1 2
4 1 5 4 7 5 4 5 4 5
6 7 8 6 2 6 7 8 6 7 8
. . . . . . . . .
1 2 3 1 2 3 1 2
3 4 5 6 4 5 4 5
6 7 8 7 8 6 7 8
Fig 8 Tracing a tree bottom-up form Goal state to initial sate
48
When we reach a goal, we trace up the tree to get the solution i.e., the sequence Problem Solving using
of actions from the initial state to the goal. Search
Q.1 Find the minimum cost path for the 8-puzzle problem, where the start and
goal state are given as follows:
The N Queen’s problem was originally proposed in 1848 by the chess player
Max Bazzel, and over the years, many mathematicians, including Gauss have
49
Artificial Intelligence worked on this puzzle. In 1874, S. Gunther proposed a method of finding
– Introduction solutions by using determinants, and J.W.L. Glaisher refined this approach.
The solutions that differ only by summary operations (rotations and reflections)
of the board are counted as one. For 4 queen’s problems, there are 16c4 possible
arrangements on a 4×4 chessboard and there are only 2 possible solutions for 4
Queen’s problem. Note that,there are only 1 unique solution, out of 2 possible
solutions as second solution is just a mirror image of the first solution
Similarly, the one possible solution for 8-queen’s problem is shown in figure
11.
The 8-queen problem is computationally very expensive since the total number
of possible arrangements of queen on a 8×8 chessboard is 64c8= 64!/(56! x 8!)
≈4.4×109. Note that, 8-Queens problem has 92 distinct solutions and 12 unique
solutions, as shown in table-5
8-tuple = (4, 6, 8, 2, 7, 1, 3, 5)
The following table-4 summarizes the both distinct and unique solution for
the problem of 1-Queen to 26 Queens problem. In general, there is no known
formula to find the exact number of solutions for N queen’s problem.
Table-4 Solution of N Queen’s problem for N=1 to N=26, both
Unique and Distinct
Fig 12 State-space tree showing all possible ways to place a queen on a 4x4 chess board
So, to reduce the size (not anywhere on chess board, since there are (_4^16)C
Possibilities), we place queen row-by-row, and no Queen in same column.This
tree is called a permutation tree (here we avoid same row or same columns but
allowing diagonals)
Total nodes=1+4+4×3+4×3×2+4×3×2×1=65
The edges are labeled by possible values of xi. Edges from level 1 to level 2
nodes specify the values for x1. Edges from level i to level i+1 are labeled with
the values of xi.
The solution space is defined by all paths from root node to leaf node. There are
4! = 24 leaf nodes are in the tree Nodes are numbered as depth first Search. The
state space tree for 4-Queen’s problem (avoid same row or same columns but
allowing diagonals) is shown in figure 13.
Fig13 State space tree for 4 queen’s problems (allowing same diagonal but not same
row and same column)
52
The two solutions are found in the tree, as Problem Solving using
Search
(x1,x2,x3,x4 )=(2,4,1,3) and
(x1,x2,x3,x4 )=(3,1,4,2), which is shown in figure-14
Note that the second solution is just a mirror image of the first solution.
We can further reduce the search space, as shown in figure 6 by avoiding
diagonal also. Now you can avoid the same row, avoid same columns and
avoid same diagonals, while placing any queen. In this case, the state space
tree is look like as shown in figure 15.
Fig 15 State space tree for 4 queen’s problem (avoiding same row, columns, and
diagonal)
Note that Queens are placed row-by-row, that is,Q_1in row 1, Q_2 in row
2 and so on. In a tree, node (1,1) is a promising node (no queen attack) as
Q_1 is placed in 1st row and 1st column. Node (2,1) is non promising node,
because we cannot place Q_2in the same column (as Q_1 is already placed
in column 1). Note that nonpromising node is marked as ×. So, we try (2,2)
again nonpromising (due to same column), next try (2,3), it’s a promising
node, so proceed and try to place 3rd queen on 3rd row. But in 3rd row, all 53
Artificial Intelligence positions (3,1),(3,2),(3,3) and (3,4) are non promising and we cannot place the
– Introduction Q_3 in any of this position. So, we backtrack to (1,1) and try for (2,4) and so
on.Backtracking approach gives “all possible solution”. Figure 7 shows one
possible solution for 4-Queen’s problem as {(1,2),(2,4),(3,1),(4,3)}. This can
also be written as (x_1,x_2,x_3,x_4 )=(2,4,1,3). There are 2 possible solution
of 4-Queen’s problem. Another solution is (x_1,x_2,x_3,x_4 )=(3,1,4,2), which
is a mirror image of 1st solution.
Suppose two queen’s are placed at position (i,j) and (k,l) then they are on the
same diagonal if and only if:
(i-j)=(k-l) or (j-l)=(i-k) -----------(1) [left diagonal]
(i+j)=(k+l) or (j-l)=(k-i) ----------- (2) [right diagonal]
From equation (1) and (2), we can combine and write a one condition to check
diagonal as: abs(j-l)=abs(i-k).
54
Problem Solving using
Algorithm NQueen(k,n)
Search
// This procedure prints all possible placement of n queen’s on n×n
//chessboard so that they are non-attacking.
{
1. for i=1 to n do
2. {
3. if place(k,i) then
4. {
5. x[k]=i;
6. if (k==n) then print(x[1….n])
7. else
8. NQueen(k+1,n);
9. }
10. }
11. }
Algorithm place(k,i)
// This algorithm return true, if a queen can be placed in kth row ith
//column. Else it return false. X[] is a global array. Abs® returns
//absolute value of r.
1. {
2. for j=1 to k-1 do
3. {
4.if(x[j]=i) // in the same column
5.Or (abs(x[j]-i)==abs(j-k))// in the
//same diagonal
6. Return false;
7. }
8. Return true;
9. }
55
Artificial Intelligence ☞ Check Your Progress 1
– Introduction
Q.1 What are the various factors need to be taken into consideration when
developing a statespace representation?
Q.2 Consider the following Missionaries and cannibal problem:
Three missionaries and three cannibals are side of a river, along with a
boat that can hold one or two people. Find a way to get everyone to the
other side, without ever leaving a group of missionaries outnumbered by
cannibals.
a) Formulate the missionaries and cannibal problem.
b) Solve the problem formulated in part (a)
c) Draw the state- space search graph for solving this problem.
Q.3 Draw a state space tree representation to solve Tower of Hanoi problem.
(Hint: You can take number of disk n=2 or 3).
Q.4 Draw the state space tree for the following 8-puzzle problem, where the
start and goal state are given below. Also Find the minimum cost path for
this 8-puzzle problem. Each blank move is having cost=1.
In the above figure 2, the two players MAX and MIN are there. MAX starts
the game by choosing one path and propagating all the nodes of that path. Now,
MAX will backtrack to the initial node and choose the best path where his
utility value will be the maximum. After this, its MIN chance. MIN will also
propagate through a path and again will backtrack, but MIN will choose the
path which could minimize MAX winning chances or the utility value.
So, if the level is minimizing, the node will accept the minimum value from the
successor nodes. If the level is maximizing, the node will accept the maximum
value from the successor.
In other word we can say that - Minimax is a decision rule algorithm, which is
represented as a game-tree. It has applications in decision theory, game theory,
statistics and philosophy. Minimax is applied in two player games. The one is
the MIN and the other is the MAX player. By agreement the root of the game-
tree represents the MAX player. It is assumed that each player aims to do the
best move for himself and therefore the worst move for his opponent in order
to win the game. The question may arise “How to deal with the contingency
problem?” The answer is:
• Assuming that the opponent is rational and always optimizes its behaviour
(opposite to us) we consider the best response. opponent's
• Then the minimax algorithm determines the best move
60
2.6.2 Working of Minimax Algorithm: Problem Solving using
Search
Minimax is applicable for decision making for two agent systems participating
in competitive environment. These two players P1 and P2, also known as
MIN and MAX player, maximizes and minimizes utility value of heuristics
function. Algorithm uses recursion to search through game tree and compute
minimax decision for current state. We traverse the complete game tree in
a depth-first search (DFS) manner to explore the node. MAX player always
select the maximum value and MIN always select the minimum value from its
successor’s node. The initial value of MAX and MIN is set to as MAX=-∞ and
MIN=+∞. This is a worst value assigned initially and as the algorithm progress
these values are changes and finally, we get the optimal value.
Example1: Let’s take an example of two-player game tree search (shown in
figure 19a) to understand the working of Minimax algorithm.
The initial value of MAX and MIN is set to as MAX=-∞ and MIN=+∞. The
tree is traversed in a DFS manner. So, we start from node A, then move to node
B and then D.
Now at node D[MAX=-∞]. Now, at D, it first checks the left child (which is
a terminal node) with value-1. This node returns a value of MAX=(-∞,-1)=-1.
So,modified value at node D is [MAX=-1]. Next, we proceedfor right child of
Node D (which has terminal value 8) and compare this value (8) with previous
value at node D. that is MAX=max(-1,8)=8. So final value at node D is 8.
Similarly,
the value at node E (which is a Max node) is MAX=max(-∞,-3)=-3,then max(-
3,-1)=-1.
So, at node B, which is at MIN level, select the minimum value from its
successor node D and E as MIN=min(8,-1)=-1
Similarly, the value at node F (which is also Max node) is MAX=max(-
∞,2)=2,then max(2,1)=2, and
The value at node G (which is also MAX node) is
61
Artificial Intelligence MAX=max(-∞,-3)=-3,and thenmax(-3,4)=4.
– Introduction
Thus, at node C, which is also at MIN level, select the minimum value from its
successor node F and G as MIN=min(2,4)=2.
Now, the value at node B and C is -1 and 2 respectively.
Thus, finally, the value at node A, which is at MAX level, is
MAX=max(-1,2)=2.
The final game tree with max or min value at each node and optimal path, with
shaded line A→C→F→2, is shown in the following figure 19(b).
Fig 19(b) Game tree with final value at each node with optimal path
Example2 Consider the following two-player game tree search. The working
of Minimax algorithmis illustrated from fig (a)-fig(k)
Fig (f)
63
Artificial Intelligence
– Introduction
2.7 ALPHA-BETA PRUNING
The drawback of Minimax strategy is that it explores each node in the tree
deeply to provide the best path among all the paths. This increases its time
complexity. If b is the branching factor and d is the depth of the tree, then
time complexity of MINIMAX algorithm is O(b^d ) that is exponential. But as
we know, the performance measure is the first consideration for any optimal
algorithm. Alpha-beta pruning is a method to reduce (prone) search space. Using
Alpha-Beta pruning, the Minimax algorithm is modified. Therefore, alpha-beta
pruning reduces this drawback of minimax strategy by less exploring the nodes
of the search tree.
The method used in alpha-beta pruning is that its cut-off the search by exploring
a smaller number of nodes. It makes the same moves as a minimax algorithm
does, but it prunes the unwanted branches using the pruning technique (discussed
in adversarial search). Alpha-beta pruning works on two threshold values, i.e.,
α (alpha) and β (beta).
• α : It is the best highest value; a MAX player can have. The initial value of
α is set to negative infinity value, that is
α=-∞. As the algorithm progress its value may change and finally get the
best (highest) value.
• β : It is the best lowest value; a MIN player can have. The initial value of β
is set to positive infinity value, that is
β=+∞. As the algorithm progress its value may change and finally get the
best (lowest) value.
So, each MAX node has α-value, which never decreases, and each MIN node has
β-value, which never increases. The main condition which required for alpha-
beta pruning is α ≥ β, that is if α ≥ β, then prune (cut) the branches otherwise
proceed.
Note: Alpha-beta pruning technique can be applied to trees of any depth, and it
is possible to prune the entire sub-trees easily.
64
While backtracking the tree, the node values will be passed to upper node Problem Solving using
instead of values of αandβ. Search
Before going to next branch of the node in a tree, we check the value of
αandβ. If the value ofα≥ β, then prune (cut) the next (unnecessary) branches
(i.e., no need to search the remaining branches where the condition α≥ βis
satisfied) else search continued.
Consider the below example of a game tree where P and Q are two players.
The game will be played alternatively, i.e., chance by chance. Let, P be the
player who will try to win the game by maximizing its winning chances. Q is
the player who will try to minimize P’s winning chances. Here, α will represent
the maximum value of the nodes, which will be the value for P as well. β will
represent the minimum value of the nodes, which will be the value of Q.
• Any one player will start the game. Following the DFS order, the player
will choose one path and will reach to its depth, i.e., where he will find the
TERMINAL value.
• If the game is started by player P, he will choose the maximum value in
order to increase its winning chances with maximum utility value.
• If the game is started by player Q, he will choose the minimum value in
order to decrease the winning chances of A with the best possible minimum
utility value.
• Both will play the game alternatively.
• The game will be started from the last level of the game tree, and the value
will be chosen accordingly.
• Like in the figure 5, the game is started by player Q. He will pick the leftmost
value of the TERMINAL and fix it for beta (β). Now, the next TERMINAL
value will be compared with the β-value. If the value will be smaller than or
equal to the β-value, replace it with the current β-value otherwise no need
to replace the value.
65
Artificial Intelligence • After completing one part, move the achieved β-value to its upper node and
– Introduction fix it for the other threshold value, i.e.,α.
• Now, its P turn, he will pick the best maximum value. P will move to explore
the next part only after comparing the values with the current α-value. If
the value is equal or greater than the current α-value, then only it will be
replaced otherwise we will prune the values.
• The steps will be repeated unless the result is not obtained.
• So, number of pruned nodes in the above example are four and MAX wins
the game with the maximum UTILITY value, i.e.,3.
The rule which will be followed is: “Explore nodes, if necessary, otherwise
prune the unnecessary nodes.”
Note: It is obvious that the result will have the same UTILITY value that we
may get from the MINIMAX strategy.
Alpha beta cut-off (or pruning):
1. for each node store limit [α,β].
2. Update [α,β],
where α is the lower bound at max node; it can’t decrease.
β is the upper bound at min node; it can’t increase.
3. If α value of a max node is greater than β value of its parent (α≥β),
thesubtree of that max node need not be evaluated (i.e., pruned).
4. If β value of a min node is lesser than α value of its parent (β≤α), the
subtree of that min node need not be evaluated (i.e., pruned).
Example1: Let’s take an example of two-player search tree (Figure 21) to
understand the working of alpha-beta pruning.
We initially start the search by setting the initial value of α=-∞andβ=+∞to root
node A.
66
Problem Solving using
Note the following important point to apply the Alpha-beta pruning: Search
We will only pass the αandβvalue from top to bottom (that is from any
parent to child node), but never from child to parent node.
While backtracking the tree (from bottom to top node), the node values
will be passed to upper node instead of values of αandβ.
Before exploring the next branch in a tree, we check α≥ β. If YES, then
prune (cut) the next (unnecessary) branches (i.e., no need to search the
remaining branches where the condition α≥ βis satisfied) else search
continued.
The MAX player will only update the value ofα(on MAX level) and the
MIN player will only update the value of β(on MIN level).
Step1: We traverse the tree in a depth-first search (DFS) manner and assign
(pass) this value of αandβdown to subsequent nodesB and then to nodeDas [α=-
∞; β=+∞].
Now at node D [α=-∞,β=+∞], Since node D is at MAX level, so only αvalue
will be changed. Now, at D, it first checks the left child (which is a terminal
node) with value 2. This node returns a value of 2. Now, the value of α at node
D is calculated asα=max(-∞,2)=2. So modified value at node D is [α=2,β=+∞].
To decide whether it’s worth looking at its right node or not, we check α ≥ β.
The answer in NO since 2≱+∞. So, proceed and search is continued for right
child of Node D.
The value of right child (terminal node with value=3) of D returns a value
3. Now at D, the value of αis compared with terminal node value 3, that is,
α=max(2,3)=3.Now the value of Node(D)=3, and the final values of α and βis
updated at node D as[α=3,β=+∞] as shown in figure 21(a).
∝ = −∞
A β = +∞
∝ = −∞
β = +∞ B
∝=3 D 3
β = +∞
2 3
Fig
Fig21(a)
21(a)
∝ = −∞
β= 3 B 3
∝=3 D 3
β = +∞
2 3
Fig21(b)
Fig21(b)
Step 3. B now calls E, we pass the αandβvalue from top node B to bottom node
E as [α=-∞,β=3]. Since, node E is at MAX level, so only αvalue will be change.
Now, at E, it first checks the left child (which is a terminal node) with value5.
This node returns a value of 5.
Now, the value of α at node E is calculated as α=max(-∞,5)=5, so value of
Node(E)=5 and modified value of αandβ at node Eis [α=5,β=3]. To decide
whether it’s worth looking at its right node or not, we check α≥ β. The answer
isYES, since 5≥3. So,we prune (cut) the right branch of E, as shown in figure
21(c).
A
∝ = −∞
β= 3 B 3
∝=3 ∝=5 5
D E
β = +∞ β=3
2 3 2 9
Fig21(c)
Fig21(c)
Step 4. We backtrack from node E to B. Note that, while backtracking, the node
values of E(=5) will be passed to upper node B, instead of values of αandβ. E
return a value 5 to B.Since B is at MIN level, so onlyβvalue will be changed.
Previously, at node B [α=-∞,β=3], but nowβ=min(3,5)=3, so, there is no change
in β value and value of node(B) is still 3. Thus finally, modified value at node
B is[α=-∞,β=3].
We backtrack from node B to A. Again, note that, while backtracking the tree,
the value of node(B)=3 will be passed to upper node A, instead of values of
αandβ. Now value of Node(A)=3.
Since A is at MAX level, so onlyαvalue will be changed. Previously, at node
A [α=-∞,β=+∞] and after comparing value of node(B)=3 with old value of α at
68 node A, that is α=max(-∞,3)=3. Thus finally, at node A [α=3,β=+∞] and value
of Node(A)=3. we check α≥ β, it is False, so proceed on right side. Now, we Problem Solving using
completed the left sub tree of A and proceed towards right subtree, as shown in Search
figure 21(d).
∝= 3
β = +∞ A 3
∝ = −∞
β= 3 B 3
∝=3 ∝=5 5
D β=3 E
β = +∞
2 3 5 9
Fig21(d)
Fig21(d)
Step 5.
Now at node C, we pass the αandβvalue from top node A to bottom node C as
[α=3,β=+∞]. Check,α≥ β. The answer in NO. So, search is continued. Now pass
the αandβvalue from top node C to bottom node F as [α=3,β=+∞]. Since F is at
MAX level, so onlyαvalue will be changed.
Now, at F, it first checks the left child (which is a terminal node) with value0.
This node returns a value of 0. Now, the value of α at node F is calculated
asα=max(3,0)=3. So modified value at node Fis [α=3,β=+∞]. To decide whether
it’s worth looking at its right node or not, we check α≥ β. The answer in NO
since 3≱+∞. So, proceed and search is continued for right child of Node F.
The value of right child (terminal node with value=1) of F returns a value 1, so
finally, value of node(F)=1. Now at F, the value of α is compared with terminal
node value 1, that is, α=max(3,1)=3, and the final values of α and β is updated
at node F as[α=3,β=+∞] as shown in figure 21(e).
∝= 3 A 3 MAX
β = +∞
∝ = −∞ ∝=3 MIN
B 3 C
β= 3 β = +∞
2 3 2 8 0 1 Terminal Node
Fig21(e)
Fig21(e)
69
Artificial Intelligence 6. We backtrack from node F to C. Note that, while backtracking the tree,
– Introduction the node values of F(=3) will be passed to upper node C. Now the value of
node(C)=node(F)=1.
Since C is at MIN level, so only βvalue will be changed. Previously, at
node C [α=3,β=+∞]. Now, old value of β=+∞ is compared with value of
node(F)=node(C)=1. That is, β=min(+∞,1)=1. Thus finally, at node B [α=3,β=1].
Now we check,α≥ β. It is TRUE, so we prune (cut) the right branch of node C.
That is node G will be pruned and algorithm stop searching on right subtree of
node C.
Thus finally, we backtrack from node C to A and node C return the value 1 to
node A. Since A is a MAX node, so onlyαvalue will be changed.
Previously, at node A [α=3,β=+∞] and after comparing value of node(C)=1
with old value of α at node A, that is α=max(3,1)=3. Thus finally, at node A
[α=3,β=+∞] and value of Node(A)=3. Now, we completed the right sub tree of
A also.
Following is the final game tree, showing the nodes which are computed and
nodes which are pruned (cut) during search process of Alpha-beta pruning.
Here the optimal value for the maximizer is 3 and there are 3 terminal nodes are
pruned (9, 7 and 5). The optimal search path is A→B→D→3.
3 MAX
∝= 3 A
β = +∞
B ∝=3 C 1 MIN
β=1
∝=3
D E β = +∞ F 1 MAX
2 3 5 9 0 1 Terminal Node
Fig 21(f)
Example2: Consider the following game tree (figure 22) in which root is
maximizing node and children are visited from left to right. Find which nodes
are pruned by the Alpha-beta pruning.
∝ = −∞ ∝ = −∞
β = +3 B 3 MIN β= 3 B 3 MIN
Fig22(a)
Fig22(a) Fig 22(b) Fig22(b)
Step 3: Now at node C, we pass the αandβvalue from top node A to bottom
node C as [α=3,β=+∞]. Check,α≥ β. The answer in NO. So, continue the search
on right side. Since C is at MIN level, so onlyβvalue will be changed.
Now, we first check the left child (terminal) of node C, that is G=2. So, we
compare the old value of β at node C with this terminal node value 2, that is
β=min(+∞,2)=2. So value of Node(C)=2 and modified value of αandβatnodeC
71
Artificial Intelligence is[α=3,β=2]. Now, before proceed next, we again checkα≥ β. The answer is
– Introduction YES. So,we prune (cut) the right branch of node C. That is node H and I will be
pruned (cut) and algorithm stop searching on right subtree of node C, as shown
in figure 22(c).
∝= 3 A MAX
β = +∞
∝= 3
∝ = −∞
B 3 2 C β= 2 MIN
β= 3
D E F G H I Terminal Node
3 12 8 2 15 6
Fig22(c)
Fig22(c)
Step 4: Finally, we backtrack from node C to A. Note that, while backtracking
the node in a tree, the node values of C(=2) will be passed to upper node A,
instead of values of αandβ.The previous node(A)=3 value is compared with this
new node(C)=2 value. The best value at node(A)=α=max(3,2)=3.
The previous α and β value at node A[α=3,β=+∞]. Since A is at MAX level so
only α value is change. So, we compare old α=3 value with value at node(C)=2.
That is α=max(3,2)=3. Thus, there is no change in α value as well.
Thus finally, αandβvalue at node A is[α=3,β=+∞] and value of Node(A)=3. So,
optimal value for the maximizer is 3 and there are 2 terminal nodes are pruned
(H and I). The optimal search path is A→B→D (as shown in figure 22(d)).
∝= 3
3 A β = +∞ MAX
∝= 3
∝ = −∞
B 3 2 C β= 2 MIN
β= 3
D E F G H I Terminal
3 12 8 2 15 6
Fig 22(d)
Fig 22(d)
2.7.2 Move ordering of Alpha-beta pruning
The effectiveness of Alpha-beta pruning is highly dependent on the order in
which each node is examined. Move order is an important aspect of alpha-beta
pruning. We have two types of move ordering:
Worst case ordering: In some cases, alpha-beta pruning algorithm does not
prune any of the leaves of the tree and works exactly as MiniMax algorithm.
In this case, it consumes more time because of alpha-beta factors, such a move
of pruning is called a worst ordering. The time complexity for such an order is
72 O(b^m)where b: Branching Factor and m is the depth of the tree.
Best (ideal) case ordering: The ideal ordering for alpha-beta pruning occurs Problem Solving using
when lots of pruning happens in the tree, and best move occur at the left side of Search
the tree. We apply DFS hence it first search left of the tree and go deep twice as
minimax algorithm in the same amount of time. The time complexity for best
case order is O(b^(m/2)) (since we search only left sub tree, not a right subtree).
Note that pruning does not affect the final result. Good move ordering improves
the effectiveness of pruning. With ideal case ordering, time complexity is
O(b^(m/2))
In Alpha-beta pruning:
- α value can never decrease and β value can never increase. Search can be
discontinued at anode if:
-It is a Max node and α≥β it is beta cutoff
-It is a Min node and β≤α it is a alpha cutoff.
☞ Check Your Progress 2
Q.1 Compare the MINIMAX and Alpha-Beta Pruning algorithm with respect to
Time complexity.
Q.2 Consider the following Minimax game tree search in which root is
maximizing node and children are visited from left to right. Find the value
of the root node of the game tree?
Q.3 Apply Alpha-Beta pruning algorithm on the following graph and find which
node(s) are pruned?
73
Artificial Intelligence Q.4 Consider the following Minimax game tree search (figure1) in which root
– Introduction is maximizing node and children are visited from left to right.
A
MAXX
MIN B C D
MAX E F G H I J K
Terminal 4 3 6 2 2 1 4 5 3 1 5 4 7 5
Node
Figure1(a)
Figure1(a)
(a) Find the value of the root node of the game tree?
(b) Find all the nodes pruned in the tree?
(c) Find the optimal path for the maximizer in a tree?
Q.5 Consider the following Minimax game tree search in which root is
maximizing node and children are visited from left to right. Find what will
be the value propagated at the root?
Q.6 Consider the following Minimax game tree search in which root is
maximizing node and children are visited from left to right. Find the value
of the root node of the game tree?
A. 14 B. 17 C. 111 D. 112
2.8 SUMMARY
Before an AI problem can be solved it must be represented as a state space.
Among all possible states, there are two special states called initial state
(the start point) and final state (the goal state).
A successor function (a set of operators)is used to change the state. It is
used to move from one state to another.
A state space is set of all possible states of a problem.
A state space essentially consists of a set of nodes representing each state
of the problem, arcs between nodes representing the legal moves from one
state to another, an initial state, and a goal state. Each state space takes the
form of a tree or a graph.
The process of searching means a sequence of action that take you from an
initial state to a goal state.
search is fundamental to the problem-solving process. Search means
the problem is solved by using the rules, in combination with an
appropriatecontrol strategy, to move through the problem space until a path
from an initial state to a goal state is found.
A problem space is represented by a directed graph, where nodes represent
search stateand pathsrepresent the operators applied to change the state.
In general, a state space is represented by 4 tuples as follows:Ss: [S,s0,O,G],
Where S: Set of all possible states (possibly infinite), s0: start state (initial
configuration) of the problem, s0∈S. O: Set of production rules (or set of
state transition operator) used to change the state from one state to another.
It is the set of arcs (or links) between nodes.
Adversarial search is a game-playing technique where the agents are
surrounded by a competitive environment. A conflicting goal is given to
the agents (multiagent). These agents compete with one another and try to
defeat one another in order to win the game. Such conflicting goals give rise
to the adversarial search.
75
Artificial Intelligence In a normal search, we follow a sequence of actions to reach the goal or to
– Introduction finish the game optimally. But in an adversarial search, the result depends
on the players which will decide the result of the game. It is also obvious
that the solution for the goal state will be an optimal solution because the
player will try to win the game with the shortest path and under limited
time.
There are 2 types of adversarial search: Minimax Algorithm and Alpha-
beta Pruning.
Minimax is a two-player (namely MAX and MIN) game strategy where
if one wins, the other lose the game. This strategy simulates those games
that we play in our day-to-day life. Like, if two persons are playing chess,
the result will be in favour of one player and will go against the other one.
MIN: Decrease the chances of MAX to win the game and MAX: Increases
his chances of winning the game. They both play the game alternatively,
i.e., turn by turn and following the above strategy, i.e., if one wins, the other
will definitely lose it. Both players look at one another as competitors and
will try to defeat one-another, giving their best.
In minimax strategy, the result of the game or the utility value is generated
by a heuristic function by propagating from the initial node to the root
node. It follows the backtracking technique and backtracks to find the best
choice. MAX will choose that path which will increase its utility value and
MIN will choose the opposite path which could help it to minimize MAX’s
utility value.
The drawback of minimax strategy is that it explores each node in the tree
deeply to provide the best path among all the paths. This increases its time
complexity.
If b is the branching factor and d is the depth of the tree, then time complexity
of MINIMAX algorithm is O(bd ) that is exponential.
Alpha-beta pruning is an advance version of MINIMAX algorithm.
Therefore, alpha-beta pruning reduces the drawback of minimax strategy
by less exploring the nodes of the search tree.
The alpha-beta pruning method cut-off the search by exploring a smaller
number of nodes. It makes the same moves as a minimax algorithm does,
but it prunes the unwanted branches using the pruning technique.
Alpha-beta pruning works on two threshold values, i.e., α (alpha) and β
(beta).α : It is the best highest value; a MAX player can have. The initial
value of α is set to negative infinity value, that is α=-∞. As the algorithm
progress its value may change and finally get the best (highest) value. β : It
is the best lowest value; a MIN player can have. The initial value of β is set
to positive infinity value, that is β=+∞. As the algorithm progress its value
may change and finally get the best (lowest) value.
So, each MAX node has α value, which never decreases, and each MIN node
has β value, which never increases. The main condition which required for
alpha-beta pruning is α ≥ β, that is if α ≥ β, then prune (cut) the branches
76 otherwise search is continued.
As we know there are two-parameter is defined for Alpha-beta pruning, Problem Solving using
namely alpha (α)and beta(β). The initial value of alpha and beta is set to Search
as α=-∞ and β=+∞.As the algorithm progresses its values are changes
accordingly. Note that in Alpha-beta pruning (cut), at any node in a tree, if
α ≥ β, then prune (cut) the next branch else search is continued.
The effectiveness of Alpha-beta pruning is highly dependent on the order in
which each node is examined.
Worst case ordering: In some cases, alpha-beta pruning algorithm does
not prune any of the leaves of the tree and works exactly as MiniMax
algorithm. In this case, the time complexity is O(bm)where b: Branching
Factor and m is the depth of the tree.
Best (ideal) case ordering: The ideal ordering for alpha-beta pruning
occurs when lots of pruning happens in the tree, and best move occur at the
left side of the tree. The time complexity for best case order is O(bm/2) (since
we search only left sub tree, not a right subtree).
2.9 SOLUTIONS/ANSWERS
Check your progress 1:
Answer1: A number of factors need to be taken into consideration when
developing a statespace representation. Factors that must be addressed are:
• What is the goal to be achieved?
• What are the legal moves or actions?
• What knowledge needs to be represented in the state description?
• Type of problem - There are basically three types of problems. Some
problems only need a representation, e.g., crossword puzzles. Other
problems require a yes or no response indicating whether a solution can be
found or not. Finally, the last type problem are those that require a solution
path as an output e.g., mathematical theorems Towers of Hanoi. In these
cases we know the goal state and we need to know how to attain this state
• Best solution vs. Good enough solution - For some problems a good enough
solutionis sufficient. For example: theorem proving eight squares.
However, some problems require a best or optimal solution, e.g., the
traveling salesman problem.
Answer 2
(a) Formulation of Missionaries and Cannibal problem:
State: (#M,#C,0/1)
Where #M represents Number of missionaries in the left side bank (i.e., left side
of the river)
#C : represents the number of cannibals in the left side bank (i.e., left side of
the river)
77
Artificial Intelligence 0/1 : indicate the boat position of the boat. 0 indicates the boat is on the left side
– Introduction of the river and 1 indicate the boat is on the right side.
Start state: (3,3,0)
Goal State: (0,0,1)
Operator: Sate will be changed by moving missionaries and (or) cannibals
from one side to another using boat. So, it can be represented as number of
persons on the either side of the river. Note that the boat can carries maximum
2 persons.
Boat carries: (1,0) or (0,1) or (1,1) or (2,0) or (0,2).Here in (i,j), i represents
number of missionaries and j means number of cannibals.
(b) Solution of Missionaries and Cannibal problem:
Start state: (3,3,0)
Goal State: (0,0,1)
78
A state space tree for this problem is shown below: Problem Solving using
Search
Figure: A state space tree showing all possible solution of missionaries and
cannibal problem.
79
Artificial Intelligence Answer 3: Towers Hanoi A possible state space representation of the Towers
– Introduction Hanoi problem using a graph is indicated in Figure 1.
The legal moves in this state space involve moving one ring from one pole to
another, moving one ring at a time, and ensuring that a larger ring is not placed
on a smaller ring.
Answer 4:
2 18
x2=4
x2=2 x2=3 x2=4
3 8 13 19 24 29
B B B x3=1
30
9 11 14 16 x4=3
B B B
31
15
81
Artificial Intelligence B denotes the Dead Node (nonpromising node). The figure 1 shows the Implicit
– Introduction tree for 4 queen problem for solution <2,4,1,3>. The Root represents an
initial state. The Nodes reflect the specific choices made for the components
of a solution. Explore The state space tree using depth-first search. "Prune"
non-promising nodesdfs stops exploring subtree rooted at nodes leading to no
solutions and then backtracks to its parent node
Check your progress 2
Answer1:
Solution: Alpha-beta pruning is an advance version of MINIMAX algorithm.
The drawback of minimax strategy is that it explores each node in the tree
deeply to provide the best path among all the paths. This increases its time
complexity. If b is the branching factor and d is the depth of the tree, then time
complexity of MINIMAX algorithm is O(bd ) that is exponential.
Alpha-Beta pruning is a way of finding the optimal Minimax solution while
avoiding searching subtrees of moves which won’t be selected. The effectiveness
of Alpha-beta pruning is highly dependent on the order in which each node
is examined. The ideal ordering for alpha-beta pruning occurs when lots of
pruning happens in the tree, and best move occur at the left side of the tree. We
apply DFS hence it first search left of the tree and go deep twice as minimax
algorithm in the same amount of time. The time complexity for best case order
is O(bm/2) (since we search only left sub tree, not a right subtree).
Answer 2: The final game tree with max and min value at each node is shown
in the following figure.
Answer3:
Solution: Solve the question as sown in Example1
The initial call starts from A. We initially start the search by setting the initial
value of α=-∞andβ=+∞for root node A. These values are passed down to
subsequent nodes in the tree. At A the maximizer must choose max of B and C,
so A calls B first. At B it the minimizer must choose min of D and E and hence
calls D first. At D, it looks at its left child which is a leaf node. This node returns
a value of 3. Now the value of alpha at D is max( -∞, 3) which is 3. To decide
whether it’s worth looking at its right node or not, it checks the condition α≥ β.
This is false since β=+∞ and ∞= 3. So, it continues the search.
82
D now looks at its right child which returns a value of 5. At D, alpha = max(3, Problem Solving using
5) which is 5. Now the value of node D is 5. Value at node D=5, move up to Search
node B(=5). Now at node B, β value will be modified as
β=min(+∞,5)=5.
B now calls E, we pass the αandβvalue from top node B to bottom node E as
[α=-∞,β=5]. Since, node E is at MAX level, so only αvalue will be change.
Now, at E, it first checks the left child (which is a terminal node) with value 6.
This node returns a value of 6.
Now, the value of α at node E is calculated as α=max(-∞,6)=6, so value of
Node(E)=6 and modified value of αandβ at node E is [α=6,β=5]. To decide
whether it’s worth looking at its right node or not, we check α≥ β. The answer is
YES, since 6≥5. So, we prune (cut) the right branch of E, as shown in figure (a).
Figure (a) game tree after applying alpha-beta pruning on left side of node A
Similarly, we solve for right sub tree for Node A [refer the example 1 and solve
for right sub tree part]. The final tree with node value at every node is shown in
the figure(b).
Thus finally, αandβvalue at node A is[α=5,β=+∞] and best value at Node(A)=max
(5,2)=5. So, optimal value for the maximizer is 5 and there are 3 terminal nodes
are pruned (9, 0 and -1). The optimal search path is A→B→D→5 , as shown
in figure (b).
Figure (b) Final tree with node value on every node with prune branches
Answer4:
∝ = −4
4 A β = +∞ MAX
∝= 4
∝= ∞ ∝= 4
MIN
β = +4 B 4 2 C β = +2 5 D β= 5
∝= 4 ∝= 6 ∝= 5 ∝= 7
5 J K β= 5 MAX
β = +∞ E 4 6 F β= 4 G 2 H I β = +∞
7
4 3 6 2 2 1 4 5 3 1 5 4 7 5 Term Node
83
Artificial Intelligence Answer5: 5
– Introduction
Answer6: 7
Answer 7: Option (B) 17
84
UNIT 3 UNINFORMED & INFORMED SEARCH Problem Solving using
Search
Structure
3.0 Introduction
3.1 Objectives
3.2 Formulating search in state space
3.2.1 Evaluation of search Algorithm
3.8 A* Algorithm
3.8.1 Working of A* algorithm
3.12 Summary
3.13 Solutions/Answers
3.14 Further readings
3.0 INTRODUCTION
Before an AI problem can be solved it must be represented as a state space. In
AI, a wide range of problems can be formulated as search problem. The process
of searching means a sequence of action that take you from an initial state to a
goal state as sown in the following figure 1.
In the unit 2 we have already examined the concept of a state space and
adversarial (game playing) search strategy. In many applications there might be
multiple agents or persons searching for solutions in the same solution space. In
adversarial search, we need a path to take action towards the winning direction
and for finding a path we need different type of search algorithms.
Search algorithms are one of the most important areas of Artificial Intelligence.
This unit will explain all about the search algorithms in AI which explore the
search space to find a solution.
In Artificial Intelligence, Search techniques are universal problem-solving
methods. Rational agents or Problem-solving agents in AI mostly used these
search strategies or algorithms to solve a specific problem and provide the
best result. Problem-solving agents are the goal-based agents and use atomic
representation.
One disadvantage of state space representation is that it is not possible to
visualize all states for a given problem. Also, the resources of the computer
system are limited to handle huge state space representation. But many problems
in AI take the form of state-space search.
Many problems in Al take the form of state-space search.
The states might be legal board configurations in a game, towns and cities
in some sort of route map, collections of mathematical propositions, etc.
86
The state-space is the configuration of the possible states and how they Uninformed &
connect to each other e.g., the legal moves between states. Informed Search
Informed search is also called as Heuristic (or guided) search. These are the
search techniques where additional information about the problem is provided
informed search:
informed
88
Uninformed &
Examples are: Examples are: Informed Search
Depth First Search, Best first search
Breadth First Search, Greedy search
Depth limited search, A* search
Iterative Deepening DFS,
Bi-directional search
3.1 OBJECTIVES
After studying this unit, you should be able to:
• Differentiate the Uninformed and informed search algorithm
• Formulate the search problem in the form of state space
• Explain the differences between various uninformed search approaches
such as BFS, DFS, IDDFS, Bi-directional search.
• Evaluate the various Uninformed search algorithm with respect to Time,
space and Optimality/Admissibility criteria.
• Explain Informed search such as Best-First search and A* algorithm.
• Differentiate between advantages and disadvantages of heuristic search: A*
and AO* algorithm
• Differentiate between memory bound search: Iterative Deepening A* and
Recursive Best-First Search.
90
Uninformed &
Modified search algorithm to saving the explicit space Informed Search
1. Initialize: Set OPEN={s},CLOSED={ }.
2. Fail: If OPEN={ }, terminate with failure.
3. Select: Select a state, n, from OPEN and save n in CLOSED
4. Terminate: If n∈Goal node, terminate with success
5. Expand: Generate the successor of n using operator O
For each successor, m, insert m in OPEN,only if m∉(OPEN∪CLOSED)
6. LOOP: Goto Step 2.
Here the OPEN and CLOSED list are used as follows:
OPEN: Nodes are yet to be visited.
CLOSED: Keeps track of all the nodes visited already
Note that initially OPEN list initializes with start state of G (e.g.,OPEN={s})
and CLOSED list as empty (e.g.,CLOSED={}).
Insertion or removal of any node in OPEN depends on specific search strategy.
A B C
D E F G
Goal Node
92 Fig 2 Search tree for BFS
Fig 2 Search tree for BFS
Note that BFS is a brute-search, so it generates all the nodes tor identifying the Uninformed &
goal and note that we are using the convention that the alternatives are tried in Informed Search
the left-to-right order.
A BFS algorithm uses a data structure-queue that works on FIFO principle.
This queue will hold all generated but still unexplored nodes. Please remember
that the order in which nodes are placed on the queue or removal and
exploration determines the type of search.
We can implement it by using two lists called OPEN and CLOSED. The OPEN
list contains those states that are to be expanded and CLOSED list keeps track
of state already expanded. Here OPEN list is used as a queue.
BFS is effective when the search tree has a low branching factor.
Breath-First Search (BFS) Algorithm
1. Initialize: Set ={s} , where s is a start state.
2. Fail: If OPEN={ }, terminate with failure.
3. Select: Remove a left most state (say a) from OPEN.
4. Terminate: If a∈Goal node, terminate with success, else
5. Expend: Generate the successor of node a, discard the successors of a if
it’s already in OPEN, Insert only remaining successors on right end of
OPEN [i.e., QUEUE]
6. LOOP: Goto Step 2
Let us take an example to see how this algorithm works.
Example1: Consider the following graph in fig-1 and its corresponding state space tree
representation in fig-2. Note that A is a start state and G is a Goal state.
E A
B
B C
A D E H C
D E D G
C F B F
C
G
G G H E G H
A A
B C B C
C
D E D G C
D E D G
C F B F C F B F
G G H E G H G G H E G H
A
B C
B C
C
D E D G
C
D E D G
C F B F
C F B F
G G H E G H G G H E G H
A
B C
B C
C
D E D G
C
D E D G
C F B F
C F B F
G G H E G H G G H E G H
C
D E D G
C
D E D G Goal!
C F B F
C F B F
G G H E G H G G H E G H
1 b
2 b^2
d b^d
95
Artificial Intelligence
– Introduction
S (Root)
A B
c D E F
(Goal Node)
Fig.Fig. 5 Searchtree
5 Search treefor
for DFS
DFS
Example1:
After searching root node S, then A and C, the search backtracks and tries
another path from A. Nodes are explored in the order S,A,C,D,B,E,F.
Here again we use the list OPEN as a STACK to implement DFS. If we found
that the first element of OPEN is the Goal state, then the search terminates
successfully.
96
Uninformed &
Depth-First Search (DFS) Algorithm
Informed Search
1. Initialize: Set ={s} , where s is a start state.
2. Fail: If OPEN={ }, terminate with failure.
3. Select: Remove a left most state (say a) from OPEN.
4. Terminate: If a∈Goal node, terminate with success, else
5. Expend: Generate the successor of node a, discard the successors of a if
it’s already in OPEN, Insert remaining successors on left end of OPEN
[i.e., STACK]
6. LOOP: Goto Step 2
Note: The only difference between BFS and DFS is in Expend (step 5). In
BFS, we always insert the generated successors at the right end of OPEN list,
whereas in DFS at the left end of OPEN list.
Properties of DFS Algorithm:
Supposeb(branching factor), that is Maximum number of successors of any
node and M: maximum depth of a leaf node, then
Number of nodes generated (in worst case): 1+b+b^2+⋯+bm = O(bm)
97
Artificial Intelligence Example1: Consider the following graph in fig-1 and its corresponding state space tree
– Introduction representation in fig-2. Note that A is a start state and G is a Goal state.
E A
B
B C
A D E H C
D E D G
C F B F
C
G
G G H E G H
A A
B C B C
C
D E D G C
D E D G
C F B F C F B F
G G H E G H G G H E G H
B C
B C
C
D E D G
C
D E D G
C F B F C F B F
G G H E G H G G H E G H
B C
B C
C
D E D G
C
D E D G
C F B F C F B F
G G H E G H G G H E G H
0 node to be searched
Path followed by a
DFS
1 2
3 4 5 6
DFS: The problem with this approach is, if there is a node close to root, but not
in first few subtrees explored by DFS, then DFS reaches that node very late.
Also, DFS may not find shortest path to a node (in terms of number of edges).
Suppose, we want to find node- ‘2’ of the given infinite undirected graph/tree. A
DFS starting from node-0 will dive left, towards node 1 and so on.
Whereas, the node 2 is just adjacent to node 1.
Hense, a DFS wastes a lot of time in coming back to node 2.
An Iteratie Deepenign Depth First Search overcomes this andquickly find the
required node.
B C
D E F
G
H I J K L M N O
Limit = 0
Iterative Deepening search L=1
A A A
B C B C C
Limit = 1
100
Iterative Deepening search L=2 Uninformed &
Informed Search
A A
A A
B C B C B C B C
D E F G D E F G D E F G E F G
Limit = 2
A
A A
C
C C
F G F G G
B C B C B C B C
D E F G D E F G D E F G D E F G
Limit =3 H I J K L M N O H I J K L M N O H I J K L M N O H I J K L M N O
A A A A A
B C B C B C B C B C
D E F G E F G E F G E F G F G
I J K L M N O J K L M N O J K L M N O K L M N O L M N O
A A A
C B C B C
F G F G F G
L M N O L M N O M N O
Root node
1 Bidirectional
13
4 Search 11
2 14
8 9 10
3 15
6 Intersection 12
Node
5 16
Goal node
d/2
103
Artificial Intelligence
– Introduction
3.6 COMPARISON OF UNINFORMED SEARCH
STRATEGIES
The following table-1compare the efficiency of uninformed search algorithms.
These are the measure to evaluate the performance of the search algorithms:
Table -1 Performance of uninformed search algorithm
Were
b=branching factor
d=depth of shallowest goal state
m=Maximum depth of the search space
☞ Check Your Progress 1
Q.1 Apply BFS and DFS algorithm on the following graph, clearly show the
contents of OPEN and CLOSE list.
2 3 4
6 5 7
9 8
Goal State
104
Q.3 Apply BFS algorithm on the following graph. Uninformed &
Informed Search
E
B
A D F H
C
G
State Space
Initial state
actions
Goal State
We need to find a sequence of actions which transform the agent from the initial
sate s0 to Goal state G. State space is commonly defined as a directed graph or
as a tree in which each node is a state and each arc represents the application of
an operator transforming a state to a successor state.
Thus, the problem is solved by using the rules (operators), in combination with
an appropriate control strategy, to move through the problem space until a path
from initial state to a goal state is found. This process is known as search. A
solution path is a path in state space from s0(initial sate) to G (Goal state).
We have already seen an OPEN list is used to implement an uninformed (Blind)
search (section 3.2). But the problem with using only one list OPEN is that, it
is not possible to keep track of the node which is already visited. That is “how
we can maintain a part of the state space that is already visited”. To save the
explicit space, we maintained another list called CLOSED. Now we can select
a node from OPEN and save it in CLOSED. Now, when we generate successor
node from CLOSED, we check whether it is already in (OPEN∪CLOSED). If
it is already in (OPEN∪CLOSED), we will not insert in OPEN again, otherwise
insert.
A 7 D
11 14 25
B C 10
F
8 20
15
9 10 G
E
H
Let heuristic function value h(n) for each node n to goal node G is defined as
109
Artificial Intelligence Straight line distance
– Introduction
A→G=h(A)=40
B→G=h(B)=32
C→G=h(C)=25
D→G=h(D)=35
E→G=h(E)=19
F→G=h(F)=17
H→G=h(H)=10
G→G=h(G)=0
h(n)= straight line distance from node n to G
Note that h(G)=0
The nodes added/deleted from OPEN and CLOSED list using Best-First Search
algorithm are shown below.
OPEN CLOSED
[A] []
[C,B,D] [A]
B,D A,C
F,E,B,D A,C
G.E.B.D A,C,F
E,B,D A,C,F,G
110
Uninformed &
S node h(n) Informed Search
3 2
A 12
A B B 4
4 1 3 1 C 7
D 3
C D E F E 8
F 2
5 2 3 H 4
I 9
H I G S 13
G 0
Here, we are using two lists which are OPEN and CLOSED Lists. Following
are the iteration for traversing the above example.
13 S
4
12 A B
9
8 E F
I G 2
0
111
Artificial Intelligence Example3: Apply Greedy Best-First Search algorithm on the following graph
– Introduction (L is a goal node).
Evaluation
10
function D
Start
E
node 2 8
A
F
6 13
s
B G
14 1
5 I K
5 0 Goal
C 7 L Node
H
6
J 2 M
112
Uninformed &
5. H (I:5), (J:6) (D:10), (E:8), (I:5) Informed Search
(F:13), (G:14),
(I:5), (J:6)
6. I (K:1), (L:0), (D:10), (E:8), Goal node is
(M:2) (H:7), (F:13), found. So, search
(G:14), (J:6), stops now
(K:1), (L:0), (M:2)
3.8 A* ALGORITHM
A* search is the most commonly known form of best-first search. It uses
heuristic function h(n), and cost to reach the node n from the start state g(n).
It has combined features of uniform cost search (UCS) and greedy best-first
search, by which it solves the problem efficiently. A* search algorithm finds the
shortest path through the search space using the heuristic function. This search
algorithm expands less search tree and provides optimal result faster.
In A* search algorithm, we use search heuristic as well as the cost to reach the
node. Hence, we can combine both costs as following, and this sum is called as
a fitness number (Evaluation Function).
Estimated cost of the Cost to reach node n Cost to reach from node
cheapest solution. from start state. n to goal node.
g(n)
n f(n) = g(n)+h(n)
Algorithm A*
1. Initialize: Set OPEN = (s), CLOSED = {}, g(s) = 0, f(s) = h(s)
2. Fail: If OPEN = { }, Terminate & fail
3. Select : Select the minimum cost state, n, from OPEN, Save
n in CLOSED.
4. Terminate: If n ∈ G, terminate with success, and return f(n)
5. Expand: For each successor, m, of n
If m ∉ [OPEN ∪ CLOSED]
Set g(m) = g(n) + C(n,m)
Set f(m) = g(m) +h(m)
Insert m in OPEN
If m ∈ [OPEN ∪ CLOSED]
Set g(m) = min {min {g(m), g(n) + C(n,m)}
Set f(m) = g(m) + h(m)
If f(m) has decreased and m ∈ CLOSED,
move m to OPEN
In step5, we generate a successor of n (say m) and for each successor m, if it
does not belong to OPEN or CLOSED that is m∉[OPEN∪CLOSED], then we
insert it in OPEN with the cost g(n)+C(n,m) i.e., cost up to n and additional cost
from n→m.
114
If m∈[OPEN∪CLOSED] then we set g(m) with original cost and new cost Uninformed &
[g(n)+C(n,m)]. If we arrive at some state with another path which has less cost Informed Search
from original one, then we replace the existing cost with this minimum cost.
If we find f(m) is decreased (if larger then ignore) and m ∈ CLOSED then move
m from CLOSED to OPEN.
Note that, the implementation of A* Algorithm involves maintaining two lists-
OPEN and CLOSED. The list OPEN contains those nodes that have been
evaluated by the heuristic function but have not expanded into successors yet
and the list CLOSED contains those nodes that have already been visited.
See the following steps for working of A* algorithm:
Step-1: Define a list OPEN. Initially, OPEN consists of a single node, the
start node S.
Step-2: If the list is empty, return failure and exit.
Step-3: Remove node n with the smallest value of f(n) from OPEN and
move it to list CLOSED.
If node n is a goal state, return success and exit.
Step-4: Expand node n.
Step-5: If any successor to n is the goal node, return success and the solution
by tracing the path from goal node to S.
Otherwise, go to Setp-6.
Step-6: For each successor node,
Apply the evaluation function f to the node.
If the node has not been in either list, add it to OPEN.
Step-7: Go back to Step-2.
5 3
E
3 5 J
115
Artificial Intelligence Step-1:
– Introduction
We start with node A. Node B and Node F can be reached from node A. A*
Algorithm calculates f(B) and f(F). Estimated Cost f(n) = g(n) +h(n) for Node
B and Node F is:
f(B) = 6+8=14
f(F) = 3+6=9
Since f(F) < f(F), so it decides to go to node F.
→ Closed list (F)
Path- A →F
Step-2: Node G and Node H can be reached from node F.
A* Algorithm calculates f(G) and f(H).
f(G) = (3+1)=5=9
f(H) = (3+7) +5=13
Since f(G) < f(H), so it decides to go to node G.
→ Closed list (G)
Path- A→F→G
Step-3: Node I can be reached from node G.
A* Algorithm calculates f(I).
f(I)=(3+1+3)+1=8; It decides to go to node I.
→ Closed list (I).
Path- A→F→G→I
Step-4: Node E, Node H and Node J can be reached from node I.
A* Algorithm calculates f(E), f(H), f(J).
f(E) = (3+1+3+5) + 3 =15
f(H) = (3+1+3+2) + 3 = 12
f(J) = (3+1+3+3) +0 = 10
Since f(J) is least, so it decides to go to node J.
→ Closed list (J)
Shortest Path - A→F→G→I→J
Path Cost is 3+1+3+3=10
Example 2: Consider the following graph and apply A* algorithm and find the
most cost-effective path to reach from start state S to final stateG. The heuristic
function value of each node n is defined in the table given.
116
Uninformed &
State h(n) Informed Search
S 5
A 3
B 4
C 2
D 6
G 0
Solution:
S→A=1+3=4
S→G=10+0=10
S→A→B=1+2+4=7
S→A→C=1+1+2=4
S→A→C→D=1+1+3+6=11
S→A→C→G=1+1+4=6
S→A→B→D=1+2+5+6=14
S→A→C→D→G=1+1+3+2=7
S→A→B→D→G=1+2+5+2=10
118
3.8.4 Properties of heuristic Algorithm: Uninformed &
Informed Search
1. Admissibility condition: Algorithm A is admissible if it guarantees to
return an optimal solution when one exists. A heuristic function h is called
admissive if many general estimates., we always have h(n)≤h^* (n)
2. Completeness condition: Algorithm A is complete if it always terminates
with a solution when one exists.
3. Dominance property: If A1 and A2 are two Admissible versions of
Algorithm A such that A is more informed than A2 h1(n) > h2(n).
4. Optimal Property: Algorithm A is optimal over a class of Algorithms If a
dominates all members of the class.
119
Artificial Intelligence
– Introduction Goal = Get a bike
AND Arc
AND
OR
Fig 11AND-OR graph
7 A 12 B C 13
1 1 1 1
5 D E 6 5 F G 7
Note that, the graph given in fig 2, there are two paths for solution from start
state S: either S-A-B or S-C. To calculate the cost of the path we use the formula
f(n)=g(n)+h(n) [note that here g(n) value is 1 for every edge].
Path1: f(S-A-B)=1+1+7+12=21
Path2: f(S-C)=1+13=14
Since min(21,14)=14; so, we select successor node C, as its cost is minimum,
so it indicates best path for solution.
Note that C is a AND node; so, we consider both the successor node of C. The
cost of node C is f(C-F-G)=1+1+5+7=14; so, the revised cost of node C is 14
and now the revised cost of node S is f(S-C)=1+14=15 (revised).
Note that once the cost (that is f value) of any node is revised, we propagate
this change backward through the graph to decide the current best path.
Now let us explore another path and check whether we are getting lessor cost as
compared to this cost or not.
F(A-D)=1+5=6 and f(A-E)=1+6=7; since A is an OR node so best successor
node is D since min(6,7)=6. So revised cost of Node A will be 6 instead of
7, that is f(A)=6 (revised). Now next selected node is D and D is having only
one node H so f(D-H)=1+2=3, so the revised cost of node D is 3, so now the
revised cost of node A, that is f(A-D-H)=4. This path is better than f(A-E)=7.
So, the final revised cost of node A is 4. Now the final revised cost of f(S-
A-B)=1+1+4+12=18 (revised).
121
Artificial Intelligence Thus, the final revised cost for
– Introduction
Path1: f(S-A-B)=18 and
Path2: f(S-C)=15
So optimal cost is 15.
Example2:
Consider the following AND-OR Graph with estimated heuristic cost at every
node. Note that A,D,E are AND node and B, C are OR node. Edge cost (i.e.,
g(n) value) is also given.
Apply AO* algorithm and find the optimal cost path using AO* algorithm.
A h=7
2 1 A,D,E → AND Node
B,C → OR Node
h=4 B C
2 1 0 0
h=2 D E 6 9 F G 7
1 0 0 0
3 H 10 I J 4 K 3
Heuristic (Estimated) cost at every Node is given. For example, heuristic cost
at node A is h=7, which means at least 7-unit cost required to find a solution.
Since A is AND Node, so we have to solve Both of its successor Node B and C.
Cost of Node A i.e., f(A-B-C) = (2+4) + (1+3) = 10
We perform cost revision in Bottom-up fashion.
A h=10 i.e., heuristic value of Node A will
2 1 be 10.
h=4 B C h=3
h=4 B C h=7
0 0
9 F G 7
Advantage of IDA* is: It is optimal and complete like breadth first search and
modest memory requirement like depth-first search.
IDA* algorithm
1. Set C= f(s)
2. Perform DFBB with cut-off C
Expand a state, n, only if its f-value is less than or equal to C
If a goal is selected for expansion, then return C and terminate
3. Update C to the minimum f-value which exceeded C among states which
were examined and Go TO Step 2.
f1
f2
f3
f4
A B C
f=120 f=130 f=120
D G E F
f=140 f=125 f=140 f=125
125
Artificial Intelligence f-limited, f-bound f-new =
– Introduction = 120 S 125
f=100
A B C
f=120 f=130 f=120
D G E F
f=140 f=125 f=140 f=125
f-limited, f-bound
= 125 P
f=100
A B C
f=120 f=130 f=120
D G E F
f=140 f=125 f=140 f=125
SUCC
ESS
S
F* = optimal path cost to a goal
B = branching factor 𝑓𝑓 ∗ b
G
126
3.10.4 Comparison of A* and IDA* algorithm: Uninformed &
Informed Search
Iterative Deepening Search (IDS) is nothing but BFS plus DFS for tree
search.
IDA* algorithm is “complete and Optimal” algorithm.
BFA and A* is good for optimality, but not memory.
DFS: good for memory O(bd), but not optimality
In the worst case, only one new state is expanded in each iteration
(IDA*). If A* expands N states, then IDA* can expand:
1+2+3+…+N=O(N2)
12 10 16 15
2 1 2
1 2 3 4
1 3 3 1
7 11
12 5 6 7 8 15
5 5
1 4 10 0 15
0
12 9 10 11 12 0
8 3 1
4
5
1
3 2
4 2 3 23
4 3
4 2
1
5 3
20
6 0
128
Q.3 Differentiate between the A* and AO* algorithm. Uninformed &
Informed Search
Q.4 Apply AO* algorithm on the following graph. Heuristic value is also given
at every node and assume the edge cost value of each node is 1.
9
A
1 1 1
3 B 4 C D 5
1 1 1 1
5 E F 7 4 G H 4
Q.5 Apply AO* algorithm on the following graph. Heuristic value is also given
at every node and assume the edge cost value of each node is 1.
P
\ \
\
5 q r 11 s 8
\ \ \
\ \
4 t u v w x
7 1 3 3
\
y
1
Example 6: Given the 3 matrices A1, A2, A3 with their dimensions
(3×4),(4×10),(10×1). Consider the problem of solving this chain matrix
multiplication. Apply the concept of AND-OR graph and find a minimum cost
solution tree.
(Multiple choice Questions)
Q.6 A* algorithm always to find an optimal solution if
A. h’ is always 0
B. g is always 1
C. h’ never overestimates h
D. h’ never underestimate h
Q.7 A* algorithm uses f^*=g+h^* to estimate the cost of getting from the initial
state to the goal state, where g is a measure of cost getting from initial state
to the current node and the function h^* is an estimate of the cost of getting
from the current node to the goal state. To find a path involving the fewest
number of steps, we should test,
A. g=1
B. g=0
C. h^*=0
D. h^*=1 129
Artificial Intelligence
– Introduction
3.12 SUMMARY
As the name ‘Uninformed Search’ means the machine blindly follows the
algorithm regardless of whether right or wrong, efficient or in-efficient.
These algorithms are brute force operations, and they don’t have extra
information about the search space; the only information they have is on
how to traverse or visit the nodes in the tree. Thus, uninformed search
algorithms are also called blind search algorithms.
The search algorithm produces the search tree without using any domain
knowledge, which is a brute force in nature. They don’t have any background
information on how to approach the goal or whatsoever. But these are the
basics of search algorithms in AI.
The different types of uninformed search algorithms are as follows:
• Depth First Search
• Breadth-First Search
• Depth Limited Search
• Uniform Cost Search
• Iterative Deepening Depth First Search
• Bidirectional Search (if applicable)
The following terms are frequently used in any search algorithms:
State: It provides all the information about the environment.
Goal State: The desired resulting condition in a given problem and the
kind of search algorithm we are looking for.
Goal Test: The test to determine whether a particular state is a goal
state.
Path/Step Cost: These are integers that represent the cost to move
from one node to another node.
To evaluate and compare the efficiency of any search algorithm, the
following 4 properties are used:
• Completeness: A search algorithm is said to be complete if it guarantees
to return a solution, if exist.
• Optimality/Admissibility: If a solution found for an algorithm is
guaranteed to be the best solution (lowest path cost) among all other
solutions, then such a solution for is said to be an optimal solution.
• Space Complexity: A function describing the amount of space(memory)
an algorithm takes in terms of input to the algorithm. That is how much
space is used by the algorithm? Usually measured in terms of the
maximum number of nodes in memory at a time.
130
• Time Complexity: A function describing the amount of time the Uninformed &
algorithm takes in terms of input to the algorithm. That is, how long Informed Search
(worst or average case) does it take to find a solution?
Time and space complexity are measured in terms of:‘b‘ – maximum
branching factor (Max number of successor (child) of any node) in a tree,
‘d‘ – the depth of the shallowest goal node, and ‘m‘ – maximum depth of
the search tree (maybe infinity).
The following table summarizes the 4 properties(Completeness, Optimality/
Admissibility,SpaceComplexity, Time Complexity) of the search algorithm.
3.13 SOLUTIONS/ANSWERS
Check your progress 1:
Answer 1:
Table 1: Open and closed list for BFS
132
Table 2: Open and closed list for DFS Uninformed &
Informed Search
OPEN LIST CLOSED LIST
1 1
4,3,2 2
4,3,6 6
4,3 3
4,5 5
4,7 7
4,8-Goal State -
Answer 2
1. open = [A]; closed = [ ] B is not the goal.
2. open = [B,C,D]; closed = [A] Put his children onto the queue.
3. open = [C,D,E,F}; closed = [B,A] Put him in closed. He is done.
4. open = [D,E,F,G,H]; closed =[C,B,A] Items between red bard are
siblings.
5. open = [E,F,G,H,I,J]; closed = [D,C,B,A]
6. open = [F,G,H,I,J,K,L]; closed = [E,D,C,B,A]
7. open = [G,H,I,J,K,L,M,N] (as L is already on open);
closed = [G,F,E,D,C,B,A]
8. open = [H,I,J,K,L,M,N]; closed = [G,F,E,D,C,B,A]
9. and so on until either goal is reached or open is empty.
Answer 3: Refer BFS section for solution.
Answer 4
133
Artificial Intelligence CLOSED
– Introduction
1(12) 2(12) 6(12) 5(13) 10(13) 11(13) 12(13)
OPEN
1(12)
2(12) 5(13)
5(13) 3(14) 6(12)
5(13) 3(14) 7(17) 10(13)
3(19) 7(17) 10(13)
3(19) 7(17) 10(13) 9(14)
3(19) 7(17) 9(14) 11(13)
3(19) 7(17) 9(14) 12(13)
Note that only 6 nodes are expended to reach to a goal node. Optimal cost to
reach from start state (1) to goal node (12) is 13.
Note: If all the edge cost is positive then Uniform cost search (UCS) algorithm
is same as Dijkstra’s algorithm. Dijkstra algorithm fails if graph is having a
negative weight cycle. A* algorithm allows negative weight also. It means A*
algorithm work for negative (-ve) edge cost also. If some edge cost is negative,
then at any point of successive iteration, we cannot say till that node we have
optimum cost (because of the negative cost). So, in this case (-ve edge cost),
nodes come back from CLOSED to OPEN.
Let us see one example (Example 2) having negative edge cost and you can also
see how nodes come back from CLOSED to OPEN.
Answer 2:
The OPEN and CLOSED list are shown below. Node with their f(n) values are
inserted in OPEN list and that node will be expended next whose f(n) value is
minimum.
CLOSED
OPEN
1(15)
2(7) 3(25)
3(25) 4(9)
3(25) 5(11)
3(25) 6(28) This is goal Node, but we can’t Pick this
4(7) 6(28) because better cost/path may exist.
Cost of 4 is decreased from 9 →7
so bring 4 from close →open 5(9) 6(28) (Note: In open 6(28) is Not min. cost ∴ we do not
pick them).
∴4(9) 6(26) 6(28)
Same Logic Goal (optimal cost is 26)
Optimal cost to reach from start state (1) to goal node (6) is 26.
134
Answer 3: An A* algorithm represents an OR graph algorithm that is used Uninformed &
to find a single solution (either this or that), but an AO* algorithm represents Informed Search
an AND-OR graph algorithm that is used to find more than one solution by
ANDing more than one branch.
Answer 4 :
9
A
1 1 1
3 B 4 C D 5
1 1 1 1
5 E F 7 4 G H 4
9 12
A
1 1 1
B 4 C D 10
1 1 1 1
5 E F 7 4 G H 4
[5×10]
[3×5] [3×6] [3×10]
A1 A2 A3 A1 A2 A3
(0) (300) (90) (0)
In this AND-OR graph, parent (root) node indicates the given problem for
multiplying A1A2A3. Next level of the tree (2 successors node) indicates the 2
choices (or ways) of multiplying (or parenthesizing) the A1A2A3; first way is
A1×(A2×A3) and another way is (A1×A2)×A3. Since out of these two choices,
anyone will be the solution so there is a OR node for this. In an OR node, we
always mark the current best successor node. Next level we have an AND node.
For any AND node we must add the cost of both the successor node.
Cost of multiplying (A2×A3)=5×6×10=300 and dimension of A2×A3 is (5×10).
Since the dimension of A1 is (3×5) and the dimension of A2×A3 is (5×10), so
the cost of multiplying A1×(A2×A3)=3×5×10=150. Thus the total cost will be
300+150=450. Similarly,
The cost of multiplying (A1×A2)=3×5×6=90 and dimension of A1×A2 will
be (3×6). Since the dimension of A1×A2 is (3×6) and the dimension of A3
is (6×10), so the cost of multiplying (A1×A2)×A3=3×6×10=180. Thus the
total cost will be 90+180=270. So, the best way to multiplying A1×A2×A3 is
(A1×A2)×A3 and the minimum cost of multiplying A1×A2×A3
is 270.
Multiple Choice Questions
Answer 6: Option C
Answer 7: Option A
4.5.2 Disjunction
4.5.3 Negation
4.5.4 Implication
4.5.5 Bi-Conditional
4.6 Semantics
4.6.1 Negation Truth Table
4.7.4 Addition
4.7.5 Simplification
4.7.6 Conjunction
4.7.8 Absorption
4.15 Answers/Solutions
4.16 Further Readings
4.1 INTRODUCTION
Logic is the study and analysis of the nature of the valid argument, the
reasoning tool by which valid inferences can be drawn from a given set of
facts and premises. It is the basis on which all the sciences are built, and this
mathematical theory of logic is called symbolic logic. The English mathematician
George Boole (1815-1864) seriously studied and developed this theory, called
symbolic logic.
The reason why the subject-matter of the study is called Symbolic Logic is that
symbols are used to denote facts about objects of the domain and relationships
between these objects. Then the symbolic representations and not the original
facts and relationships are manipulated in order to make conclusions or to solve
problems.
The basic building blocks of arguments in symbolic logic are declarative
sentences, called propositions or statements. In MCS – 212 i.e., Discrete
Mathematics you learned about predicates and propositions and ways of
combining them to form more complex propositions. Also, you learned about
the propositions that contain the quantifiers ‘for All’ and ‘there exists’. In
symbolic logic, the goal is to determine which propositions are true and which
are false. Truth table a tool to find out all possible outcome of a proposition’s
truth value was also discussed in MCS-212.
Logical rules have the power to give accuracy to mathematical statements.
These rules come to rescue when there is a need to differentiate between valid
and invalid mathematical arguments. Symbolic logic may be thought of as a
formal language for representing facts about objects and relationships between
objects of a problem domain along with a precise inferencing mechanism for
reasoning and deduction.
Using symbolic logic, we can formalize our arguments and logical reasoning in
a manner that can easily show if the reasoning is valid, or is a fallacy. How we
symbolize the reasoning is what is presented in this unit.
4.2 OBJECTIVES
After going through this unit, you should be able to:
• Understand the meaning of propositional logic.
• Differentiate between atomic and compound propositions.
• Know different types of connectives, their associated semantics and
corresponding truth tables.
138
• Define propositional rules of inference and replacement. Predicate
Andpropositional
• Differentiate between valid and satisfiable arguments. Logic
4.5.1 Conjunction
A proposition “A ∧ B”with connective ∧ is known as conjunction of A and B.
It is a proposition (or operation) which is true only when both the constituent
propositions are true. Even if one of the input propositions is false then the 141
Artificial Intelligence output is also false. It is also referred to as AND-ing the propositions. Example:
– Introduction
Ram is a playful boy and he loves to play football. It can be written as:
A = Ram is a playful boy.
B = Ram loves to play football.
A ∧ B = Ram is a playful boy and he loves to play football.
4.5.2 Disjunction
A proposition “A ∨ B”with connective ∨ is known as disjunction of A and B. It
is a proposition (or operation) which is true when at least one of the constituent
propositions are true. The output is false only when both the input propositions
are false. It is also referred to as OR-ing the propositions. Example:
I will go to her house or she will come to my house. It can be written as:
A = I will go to her house.
B = She will come to my house.
A ∨ B = I will go to her house or she will come to my house.
4.5.3 Negation
The proposition ¬ A (or ~A) with ¬ (or ~) connective is known as negation
of A. The purpose of negation is to negate the logic of given proposition. If
A is true, its negation will be false, and if A is false, its negation will be true.
Example:
University is closed. It can be written as:
A = University is closed.
¬ A = University is not closed.
4.5.4 Implication
The proposition A → B with → connective is known as A implies B. It is also
called if-then proposition. Here, the second proposition is a logical consequence
of the first proposition. For example, “If Mary scores good in examinations, I
will buy a mobile phone for her”. In this case, it means that if Mary scores good,
she will definitely get the mobile phone but it doesn’t mean that if she performs
bad, she won’t get the mobile phone. In set notation, we can also say that A ⊆
B i.e., if something exists in the set A, then it necessarily exists in the set B.
Another example:
If you score above 90%, you will get a mobile phone.
A = You score above 90%.
B = You will get a mobile phone.
A → B = If you score above 90%, you will get a mobile phone.
142
4.5.5 Bi-conditional Predicate
Andpropositional
A proposition A ⟷ B with connective ⟷ is known as a biconditional or if- Logic
and-only-if proposition. It is true when both the atomic propositions are true or
both are false. A classic example of biconditional is “A triangle is equivalent if
and only if all its angles are 60° each”. This statement means that if a triangle
is an equivalent triangle, then all of its angles are 60° each. There is one more
associated meaning with this statement which means that if all the interior
angles of a triangle are of 60° each then it's an equivalent triangle. Example:
You will succeed in life if and only if you work hard.
A = You will succeed in life.
B = You work hard.
A ⟷ B = You will succeed in life if and only if you work hard.
☞ Check Your Progress 2
Which of the following propositions are atomic and which are compound?
1. The first battle of Panipat was fought in 1556.
2. Jack either plays cricket or football.
3. Posthumously, at the age of 22, Neerja Bhanot became the youngest
recipient of the Ashok Chakra award which is India's highest peacetime
gallantry decoration.
4. Chandigarh is the capital of the Indian states Haryana and Punjab.
5. Earth takes 365 days, 5 hours, 59 minutes and 16 seconds to complete one
revolution around the Sun.
6. Dermatology is the branch of medical science which deals with the skin.
7. Indian sportspersons won 7 medals at the 2020 Summer Olympics and 19
medals at the 2020 Summer Paralympics both held at the Japanese city of
Tokyo.
8. Harappan civilization is considered to be the oldest human civilization and
it lies in the parts of present-day India, Pakistan and Afghanistan.
9. IGNOU is a central university and offers courses through the distance
learning mode.
10. Uttarakhand was carved out of the Indian state of Uttar Pradesh in the year
2000.
4.6 SEMANTICS
You had already learned various of the concepts to be covered in this unit, in
MCS-212 i.e., Discrete Mathematics, here is a quick revision to those concepts
and we will extend our discussion to the advanced concepts, which are useful
for our field of work i.e., Artificial Intelligence. In MCS – 212 i.e., Discrete
143
Artificial Intelligence Mathematics you learned that Propositions are the declarative sentence or
– Introduction statements which is either true or false, but not both, such sentences can either
be universally true or universally false.
On the other hand, consider the declarative sentence ‘Women are more intelligent
than men’. Some people may think it is true while others may disagree. So, it is
neither universally true nor universally false. Such a sentence is not acceptable
as a statement or proposition in mathematical logic.
Note that a proposition should be either uniformly true or uniformly false.
In propositional logic, as mentioned earlier also, symbols are used to denote
propositions. For instance, we may denote the propositions discussed above as
follows:
P : The sun rises in the west,
Q : Sugar is sweet,
R : Ram has a Ph.D. degree.
The symbols, such as P, Q, and R, that are used to denote propositions, are
called atomic formulas, or atoms., in this case, the truth-value of P is False,
the truth-value of Q is True and the truth-value of R, though not known yet, is
exactly one of ‘True’ or ‘False’, depending on whether Ram is actually a Ph.
D or not.
At this stage, it may be noted that once symbols are used in place of given
statements in, say, English, then the propositional system, and, in general, a
symbolic system is aware only of symbolic representations, and the associated
truth values. The system operates only on these representations. And, except
for possible final translation, is not aware of the original statements, generally
given in some natural language, say, English.
When you’re talking to someone, do you use very simple sentences only? Don’t
you use more complicated ones which are joined by words like ‘and’, ‘or’, etc?
In the same way, most statements in mathematical logic are combinations of
simpler statements joined by words and phrases like ‘and’. ‘or’, ‘if … then’.
‘If and only if’, etc. We can build, from atoms, more complex propositions,
sometimes called compound propositions, by using logical connectives,
The Logical Connectives are used to frame compound propositions, and they
are as follows:
a) Disjunction The disjunction of two propositions p and q is the compound
statement por q, denoted by p ∨ q.
The exclusive disjunction of two propositions p and q is the statement
‘Either of the two (i.e. p or q) can be true, but both can’t be true’. We
denote this by p ⊕ q .
b) Conjunction We call the compound statement ‘p and q’ the conjunction
of the statements p and q. We denote this by p ∧ q.
144
c) Negation The negation of a proposition p is ‘not p’, denoted by ~p. Predicate
Andpropositional
d) Implication (Conditional Connectives) Given any two propositions p and Logic
q, we denote the statement ‘If p, then q’ by p → q. We also read this as
‘p implies q’. or ‘p is sufficient for q’, or ‘p only if q’. We also call p the
hypothesis and q the conclusion. Further, a statement of the form p → q is
called a conditional statement or a conditional proposition.
Let p and q be two propositions. The compound statement (p → q) ∧ (q → p)
is the bi-conditional of p and q. We denote it by p ↔ q, and read it as ‘p if and
only q’
Note: The two connectives → and ↔ are called conditional connectives
The rule of precedence: The order of preference in which the connectives are
applied in a formula of propositions that has no brackets is
i) ~
ii) ∧
iii) ∨ and ⊕
iv) → and ↔
Note that the ‘inclusive or’ and ‘exclusive or’ are both third in the order of
preference. However, if both these appear in a statement, we first apply the left
most one. So, for instance, in p ∨ q ⊕ ~ p, we first apply ∨ and then ⊕. The
same applies to the ‘implication’ and the ‘biconditional’, which are both fourth
in the order of preference.
Let’s see the working of the various concepts learned above, with the help of
truth tables. In the following truth table, we write every TRUE value as Tand
every FALSE value as F.
145
Artificial Intelligence
– Introduction 4.6.3 Conjunction and Disjunction with three variables
α_1 α_2 α_3 (α_1 (α_2 (α_1 (α_2 (α_1 (α_1
∧α_2) ∧α_3) ∨α_2) ∨α_3) ∧α_2) ∨α_2)
∧α_3 ∨α_3
or or
α_1 ∧ α_1 ∨
(α_2 (α_2
∧α_3) ∨α_3)
_T(1)_ _T(1)_ _T(1)_ _T(1)_ _T(1)_ _T(1)_ _T(1)_ _T(1)_ _T(1)_
_T(1)_ _T(1)_ _F(0)_ _T(1)_ _F(0)_ _T(1)_ _T(1)_ _F(0)_ _T(1)_
_T(1)_ _F(0)_ _T(1)_ _F(0)_ _F(0)_ _T(1)_ _T(1)_ _F(0)_ _T(1)_
_T(1)_ _F(0)_ _F(0)_ _F(0)_ _F(0)_ _T(1)_ _F(0)_ _F(0)_ _T(1)_
_F(0)_ _T(1)_ _T(1)_ _F(0)_ _T(1)_ _T(1)_ _T(1)_ _F(0)_ _T(1)_
_F(0)_ _T(1)_ _F(0)_ _F(0)_ _F(0)_ _T(1)_ _T(1)_ _F(0)_ _T(1)_
_F(0)_ _F(0)_ _T(1)_ _F(0)_ _F(0)_ _F(0)_ _T(1)_ _F(0)_ _T(1)_
_F(0)_ _F(0)_ _F(0)_ _F(0)_ _F(0)_ _F(0)_ _F(0)_ _F(0)_ _F(0)_
Using these logical connectives, we can transform any sentence in to its equivalent
mathematical representation in Symbolic Logic and that representation is
referred as Well Form Formula (WFF), you had already learned a lot about
WFF in MCS-212, lets briefly discuss it here also, as it has wide applications in
Artificial Intelligence also.
A Well-formed formula, or wff or formula in short, in the propositional logic is
defined recursively as follows:
1. An atom is a wff.
2. If A is a wff, then (~A) is a wff.
3. If A and B are wffs, then each of (A ∧ B), (A ∨ B), (A → B), and (A ↔ B)
is a wff.
4. Any wff is obtained only by applying the above rules.
From the above recursive definition of a wff it is not difficult to see that
expression:
(( P → ( Q ∧ ( ~ R))) ↔ S) is a wff; because , to begin with, each of P, Q , ( ~
R) and S, by definitions is a wff. Then, by recursive application, the expression:
(Q ∧ ( ~ R)) is a wff. Again, by another recursive application, the expression:
(P → (Q ∧ ( ~ R))) is a wff. And, finally the expression given initially is a wff.
Further, it is easy to see that according to the recursive definition of a wff, each
of the expressions: (P → (Q ∧ )) and (P ( Q ∧ R )) is not a wff.
146 Some pairs of parentheses may be dropped, for simplification. For example,
A ∨ B and A → B respectively may be used instead of the given wffs ( A ∨ B) Predicate
and (A → B), respectively. We can omit the use of parentheses by assigning Andpropositional
Logic
priorities in increasing order to the connectives as follows:
↔, →, ∨, ∨, ~.
Thus, ‘↔’ has least priority and ‘~’ has highest priority. Further, if in an
expression, there are no parentheses and two connectives between three atomic
formulas are used, then the operator with higher priority will be applied first
and the other operator will be applied later.
For example: Let us be given the wff P → Q ∧ ~ R without parenthesis. Then
among the operators appearing in wff, the operator ‘~’ has highest priority.
Therefore, ~ R is replaced by (~R). The equivalent expression becomes P →
Q ∧ (~ R). Next, out of the two operators viz ‘→’ and ‘∧’, the operators ‘∧’
has higher priority. Therefore, by applying parentheses appropriately, the new
expression becomes P → (Q ∧ (~ R)). Finally, only one operator is left. Hence
the fullyparenthesized expression becomes (P → (Q ∧ (~ R)))
Following are the rules of finding the truth value or meaning of a wff, when
truth values of the atoms appearing in the wff are known or given.
1. The wff ~ A is True when A is False, and ~ A is False when A is true. The
wff ~ A is called the negation of A.
2. The wff (A ∧ B) is True if A and B are both True; otherwise, the wff A ∧ B
is False. The wff (A ∧ B) is called the conjunction of A and B.
3. The wff (A ∨ B) is true if at least one of A and B is True; otherwise, (A ∨
B) is False. (A ∨ B) is called the disjunction of A and B.
4. The wff (A → B) is False if A is True and B is False; otherwise, (A → B)
is True. The wff (A → B) is read as “If A, then B,” or “A implies B.” The
symbol ‘→’ is called implication.
5. The wff (A ↔ B) is True whenever A and B have the same truth values;
otherwise (A ↔ B) is False. The wff (A ↔ B) is read as “A if and only if
B.”
☞ Check Your Progress 3
Q1. Draw the truth table for the following:
a) α_2⟷(~ α_1 → (α_1∨α_2))
b) (~α_1⟷ (α_2↔α_3) ) ∨ (α_3 ∧α_2)
c) ((α_1 ∧α_2) → α_3) ∨ ~α_4
d) ((α_1 → ~ α_2) ⟷α_3) → ~ (α_1 V α_1)
Q2. Verify the De Morgan’s Laws using Truth Tables
Q3. Write WFF for the following statements:
a) Every Person has Mother
b) There is a woman and she is mother of Siya 147
Artificial Intelligence
– Introduction
4.7 PROPOSITIONAL RULES OF INFERENCE
We need intelligent computers based on the concept of artificial intelligence
which are able to infer new “knowledge” or logic from the existing logic using
the theory of inference. Inference rules help us to infer new propositions and
conclusions based on existing propositions and logic. They act as templates
to generate new arguments from the premises or predicates. We deduce new
statements from the statements whose truthfulness is already known. These
rules come to the rescue when we need to prove something logically. In
general, inference rules preserve the truth. Depending on the problem, some or
all of these rules may be applied to infer new propositions. The procedure of
determining whether a proposition is a conclusion of the given propositions is
known as inferring a proposition. The inference rules are described below.
4.7.4 Addition
The rule states that if a proposition is true, then its disjunction with any other
proposition is also true.
Rule 1: α_1=>α_1∨α_2
Rule 2: α_2=>α_1 ∨α_2
4.7.5 Simplification
Simplification means that if we have a conjunction, then both the constituent
propositions are also true.
148
Rule 1:α_1 ∧α_2 =>α_1 Predicate
Andpropositional
Rule 2:α_1 ∧α_2 =>α_2 Logic
4.7.6 Conjunction
Conjunction states if two propositions are true, then their conjunction is also
true. It is written as:
α_1, α_2 =>α_1 ∧α_2
4.7.8 Absorption
The rule states that if the literal α_1 conditionally implies another literal α_2
i.e.,α_1 → α_2 is true, then α_1 → (α_1 ∧α_2) also holds.
α_1 → α_2 =>α_1 → (α_1 ∧α_2)
149
Artificial Intelligence
Replacement Rule Proposition Equivalent
– Introduction
Tautology α_1 ∧α_1 α_1
(Conjunction of a statement with
itself always implies the statement)
153
Artificial Intelligence This is a contradiction, because our premises say that A and B are both truth-
– Introduction tellers.
∴ The assumption we started with is false.
∴ A always tells lies.
∴ What A has told you is lie.
∴ B always tells lies.
∴ A and B are of the same type, i.e., both of them always lie.
Let us now consider the problem of showing that a statement is false. I.e.,
Counter examples : A common situation in which we look for counterexamples
is to disprove statements of the form p → q needs to be an example where p
∧ ~ q. Therefore, a counterexample to p → q needs to be an example where
p ∧ ~ q is true, i.e., p is true and ~ q is true, i.e., the hypothesis p holds but the
conclusion q does not hold.
For instance, to disprove the statement ‘If n is an odd integer, then n is prime.’,
we need to look for an odd integer which is not a prime number. 15 is one such
integer. So, n = 15 is a counterexample to the given statement.
Notice that a counter example to a statement p proves that p is false, i.e., ~
p is true.
Example: Following statements are to be Symbolized and thereafter construct
a proof for the following valid argument:
(i) If the BOOK_X is literally true, then the Earth was made in six days.
(ii) If the Earth was made in six days, then carbon dating is useless and
Scientists/Researchers are liars.
(iii) Scientists/Researchers are not liars.
(iv) The BOOK_X is literally true, Hence
(v) God does not exist.
Solution: Let us symbolize as follows:
B : BOOK_X is literally true
E : The Earth was created in six days
C : Carbon_dating techniques are useless
S : Scientists/Researchers are frauds
G : God exists
Therefore, the statements in the given arguments are symbolically represented
as :
(i) B
(ii) E
154
(iii) ~ S Predicate
Andpropositional
(iv) B Logic
160
i) Operator: (β1Vβ2Vβ3V.….Vβm)=>{β1,β2,β3,…. βm} Predicate
Andpropositional
(β1∧ β2∧ β3∧….∧ βm)=>{ β1},{ β2},{β3},….,{βm} Logic
ii) Negation: same as Double Negation and De Morgan’s Law in section 4.8
iii) Distribution: as in sub-section 4.8
iv) Implications: as Material implication and Material Equivalence (section
4.8)
Example 1: Convert A ∧ (B->C) to clausal expression.
Step 1: A ∧ (~B V C) (using rule Material Implication to eliminate ->)
Step 2: {A}, {~B V C} (using rule Operator to eliminate ∧)
Example 2: Derive the Clausal form or Conjunctive normal form of X <-> Y.
Step 1: Replace bi-condition using Material equivalence rule:
(X → Y) ∧ (Y → X)
Step 2: Use Material Implication replacement rule to replace the implication:
(¬ X ∨ Y) ∧ (¬ Y ∨ X)
Example 3: Derive the CNF of ~Z∧~((~X) ->( ~Y))
Step 1: Replace implication using Material Implication(MI):
~(~Z ∧ (~(~X) ∨~Y))
Step 2: Use double negation (DN):
~(~Z∧ (X ∨~Y))
Step 3: Apply DeMorgan’s Law:
~~Z ∨ ~(X ∨~Y)
Step 4: Apply Double Negation:
Z ∨~(X∨~Y)
Step 5: Apply DeMorgan’s Law again:
Z ∨ (~X ∧~~Y)
Step 6: Apply Double Negation on ~~Y:
Z ∨ (~X ∧Y)
Step 7: Lastly, apply Distributive law to obtain CNF:
(Z∨ ~X) ∧ (Z ∨ Y), which is the AND of OR’s form.
(Z∨ ~X), (Z ∨ Y) are the clausal forms for the given expression.
161
Artificial Intelligence 4.14.2 Determining Unsatisfiability
– Introduction
If the obtained set of clauses is not satisfiable, then one can derive an empty
clause using resolution principle as described above. In other words, to determine
whether a set of propositions or premises {P} logically entails a conclusion C,
write P ∨ {¬C} in clausal form and try to derive the empty clause as explained
in examples below.
Example 1: Given a set of propositions : X -> Y, Y -> Z. Prove X -> Z.
Proof: To prove the conclusion, we add the negation of conclusion i.e ~(X ->
Z) to the set of premises, and derive an empty clause.
Step 1: X -> Y (Premise)
Step 2: ~X ∨ Y (Premise, Material Implication)
Step 3: Y -> Z (Premise)
Step 4: ~Y ∨ Z (Premise, Material Implication)
Step 5: ~(X -> Z) (Premise, Negated Conclusion)
Step 6: ~(~X ∨ Z) (Premise, Material Implication)
Step 7: X ∧ ~Z (Premise, DeMorgans)
Step 8: X (Clausal form, Operator)
Step 9: ~Z (Clausal form, Operator)
Step 10: Y (Resolution rule on Premises in Step 2 and Step 8)
Step 11: Z (Resolution rule on Step 10 and Step 4)
Step 12: {} (Conjunction on Step 11 and Step 9)
Thus, the given set of premises entail the conclusion.
Example 2: Use propositional resolution to derive the goal from the given
knowledge base.
a) Either it is a head, or Lisa wins.
b) If Lisa wins, then Mary will go.
c) If it is a head, then the game is over.
d) The game is not over.
Conclusion: Mary will go.
Proof: First consider propositions to represent each of the statement in
knowledge base.
Let H: It is a head
L: Lisa wins
M: Mary will go
b) L -> M
c) H -> G
d) ~G
Conclusion: M
Step 1: H∨L (Premise)
Step 2: L -> M (Premise)
Step 3: ~L ∨ M (Step 4, Material Implication)
Step 4: H -> G (Premise)
Step 5: ~H ∨ G (Step 4, Material Implication)
Step 6: ~G (Premise)
Step 7: ~M (Negated conclusion as Premise)
Step 8: H ∨ M (Resolution principle on Step 1 and 3)
Step 9: M ∨ G (Resolution principle on Step 8 and 5)
Step 10: M (Resolution principle on Step 9 and 6)
Step 11: {} (Sep 10 and 7)
After applying Proof by Refutation i.e., contradicting the conclusion, the
problem is terminated with an empty clause ({}). Hence, the conclusion is
derived.
Example 3: Show that ~S1 follows from S1 -> S2 and ~(S1 ∧ S2).
Proof:
Step 1: S1 -> S2 (Premise)
Step 2: ~S1 ∨ S2 (Material Implication, Step 1)
Step 3: ~(S1 ∧ S2) (Premise)
Step 4: ~S1 ∨~S2 (De Morgan’s, Step 3)
Step 5: ~S1 (Resolution, Step 2, 4)
The resolution mechanism in PL is not used until after the given statements or
wffs have been converted into clausal forms. To obtain the clasual form of a
wff, one must first convert the wff into the Conjuctive Normal Form (CNF). We
are already familiar with the fact that a phrase is a formula (and only a formula)
of the form: A1∨ A2∨……..∨ An ,where Ai might be either any atomic formula
or its negation.
163
Artificial Intelligence The method of resolution is actually generalization of Modus Ponens, whose
– Introduction
P, P → Q
expression is which can be written in the equivalent form as
Q
P, ~ P ∨ Q
(i.e. by using the relation P→Q => ~P∨ Q).
Q
If we are provided that both P and ~ P ∨ Q are true, then we may safely assume
that Q is also true. This is a straightforward application of a general resolution
principle that will be covered in more detail in this unit.
The construction of a truth table can be used to demonstrate the validity of a
resolution process (generally). In order to talk about the resolution process, we
will first talk about some of the applications of that method.
Example: Let C1:Q∨R and C2: ~Q∨S be two given clauses, so that, one of the
literals i.e., Q occurs in one of the clauses (in this case C1)and its negation (~Q)
occurs in the other clause C2. Then application of resolution method in this case
tells us to take disjunction of the remaining parts of the given clause C1 and C2,
i.e., to take C3:R∨S as deduction from C1 and C2. Then C3 is called a resolvent
of C1 and C2.
The two literals Q and (~Q) which occur in two different clauses are called
complementary literals.
In order to illustrate resolution method, we consider another example.
Example: Let us be given the clauses C1:~S∨~Q∨R and C2:~P∨Q.
In this case, complementary pair of literals viz. Q and ~Q occur in the two
clause C1 and C2.
Hence, the resolution method states: ConcludeC3:~S∨R∨(~P)
Example: Let us be given the clauses C1:~Q∨R and C2:~Q∨S
Then, in this case, the clauses do not have any complementary pair of literals
and hence, resolution method cannot be applied.
Example: Consider a set of three clauses
C 1: R
C2: ~R∨S
C3: ~S
Then, from C1 and C2 we conclude, through resolution:
C4: S
From C3 and C4, we conclude,
C5: FALSE
164
However, a resolvent FALSE can be deduced only from anunstatisfiable set of Predicate
clauses. Hence, the set of clauses C1, C2 and C3 is an unsatisfiable set of clauses. Andpropositional
Logic
Example: Consider the set of clauses
C1: R∨S
C2: ~R∨S
C3: R∨~S
C4: ~R∨~S
Then, from clauses C1 and C2 we get the resolvent
C5: S∨S=S
From C3 and C4 we get the resolvent
C6: ~S
From C5 and C6 we get the resolvent
C7: FALSE
Thus, again the set of clauses C1, C2, C3 and C4 is unsatisfiable.
Note: We could have obtained the resolvent FALSE from only two clauses, viz.,
C2 and C3. Thus, out of the given four clauses, even set of only two clauses viz, C2
and C3 is unsatisfiable. Also, a superset of any unsatisfiable set is unsatisfiable.
Example: Show that the set of clauses:
C1: R∨S
C2: ~S∨W
C3: ~R∨S
C4: ~W is unsatisfiable.
From clauses C1 and C3 we get the resolvent
C7: S
From the clauses C7 and C2 we get the resolvent
C8: W
From the clauses C8 and C4 we get
C9: FALSE
Hence, the given set of clauses is unsatisfiable.
Solution of the Problem Using the Resolution Method As was discussed
before, the resolution process can also be understood as a refutation approach.
The following is an example of a proving technique that can be used to solve
problems:
165
Artificial Intelligence After the symbolic representation of the issue at hand, an additional premise
– Introduction in the form of the negation of the wff, which stands for conclusion, should be
added. You can infer either false or a contradiction from this improved set of
premises and axioms. If we are able to get to the conclusion that the statement
is not true, then the conclusion that was required to be formed is correct, and
the issue has been resolved. If, despite our best efforts, we are unable to arrive
at the conclusion that the hypothesis is false, then we are unable to determine
whether or not the conclusion is correct. As a result, the predicament cannot be
solved using the axioms that have been provided and the conclusion that has
been drawn.
Let's go on to the next step and apply Resolution Method to the issues we
discussed earlier.
Example: If the interest rate goes up, the stock prices might go down. Also,
let's say that most people are unhappy when the price of stocks goes down. Let's
say that the rate of interest goes up. Show that most people are unhappy and that
we can draw that conclusion.
To show the above conclusion, let us denote the statements as follows:
• A : Interest rate goes up,
• S : Stock prices go down
• U : Most people are unhappy
The problem has the following four statements
1) If the interest rate goes up, stock prices go down.
2) If stock prices go down, most people are unhappy.
3) The interest rate goes up.
4) Most people are unhappy. (to conclude)
These statements are first symbolized as wffs of PL as follows:
(1′) A→S
(2′) S→U
(3′) A
(4′) U(to conclude)
Converting to clausal form, we get
(i) ~A∨S
(ii) ~S∨U
(iii) A
(iv) U (to be concluded)
As per resolution method, assume (iv) as false, i.e., assume ~U as initially given
166 statement, i.e., an axiom.
Thus, the set of axioms in clasual form is: Predicate
Andpropositional
(i) ~A∨S Logic
(ii) ~S∨U
(iii) A
(iv) ~U
Then from (i) and (iii), through resolution, we get the clause
(v) S.
From (ii) and (iv), through resolution, we get the clause
(vi)~S
From (vi) and (v), through resolution we get,
(viii) FALSE
Hence, the conclusion, i.e., (iv) U: Most people are unhappy is valid.
From the above solution using the resolution method, we might have noticed
that clausal conversion is a major step that takes a lot of time after translation
to wffs. Most of the time, once the clause form is known, proof is easy to see,
at least by a person.
☞ Check Your Progress 4
Ques1. Prove that given set of premises are unsatisfiable:
a) {X, Y}, {~X, Z}, {~X,~Z}, {X, ~Y}
Ques 2. Consider the given knowledge base to prove the conclusion.
KB1. If Mary goes to school, then Mary eats lunch.
KB 2. If it is Friday, then Mary goes to school or eats lunch.
Conclusion: If it is Friday, then Mary eats lunch.
4.15 ANSWERS/SOLUTIONS
Check Your Progress 1
α_1 α_2 α_1 ∨α_2 ~ α_1 → (α_1 ∨α_2) (~α_1 → (α_1 ∨α_2))
↔α_2
_F(0)_ _F(0)_ _F(0)_ _F(0)_ _T(1)_
_F(0)_ _T(1)_ _T(1)_ _T(1)_ _T(1)_
_T(1)_ _F(0)_ _T(1)_ _T(1)_ _F(0)_
_T(1)_ _T(1)_ _T(1)_ _T(1)_ _T(1)_
169
Artificial Intelligence 2. First introduce notation set for the given knowledge base as:
– Introduction
S: Mary goes to school
L: Mary eats lunch
F: It is Friday
Corresponding knowledge base is:
KB1: S -> L
KB2:F -> (S V L)
Conclusion: F -> L
Proof: Step 1: ~S V L (Premise, Material Implication)
Step 2: ~F V (S V L) (Premise, Material Implication)
Step 3: F (Negated conclusion)
Step 4: ~L (Negated conclusion)
Step 5: (S V L) (Resolution on Step 2 and 3)
Step 6: L (Resolution on Step 1 and 5)
Step 7:{}(Resolution on Step 4 and 6)
170