Ai Chap 2
Ai Chap 2
KNOWLEDGE REPRESENTATION
Game playing – Knowledge representation, Knowledge representation using Predicate logic,
Introduction to predicate calculus, Resolution, Use of predicate calculus, Knowledge
representation using other Logic-Structured representation of Knowledge - Prolog
Programming.
Game playing
Game playing was one of the first tasks undertaken in Artificial Intelligence. Game theory
has its history from 1950, almost from the days when computers became programmable. The
very first game that is been tackled in AI is chess. Initiators in the field of game theory in AI
were Konard Zuse (the inventor of the first programmable computer and the first
programming language), Claude Shannon (the inventor of information theory), Norbert
Wiener (the creator of modern control theory), and Alan Turing. Since then, there has been a
steady progress in the standard of play, to the point that machines have defeated human
champions (although not every time) in chess and backgammon, and are competitive in many
other games.
Types of Game
1.Perfect Information Game: In which player knows all the possible moves of
himself and opponent and their results.
E.g. Chess.
2 Imperfect Information Game: In which player does not know all the
possible moves of the opponent.
E.g. Bridge since all the cards are not visible to player.
Definition
Game playing is a search problem defined by following components:
Initial state: This defines initial configuration of the game and identifies first player to move.
Successor function: This identifies which are the possible states that can be achieved from the
current state. This function returns a list of (move, state) pairs, each indicating a legal move
and the resulting state.
Goal test: Which checks whether a given state is a goal state or not. States where the game
ends are called as terminal states.
Path cost / utility / payoff function: Which gives a numeric value for the terminal states? In
chess, the outcome is win, loss or draw, with values +1, -1, or 0. Some games have wider
range of possible outcomes.
Characteristics of game playing
1
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Unpredictable Opponent: Generally, we cannot predict the behaviour of the opponent. Thus
we need to find a solution which is a strategy specifying a move for every possible opponent
move or every possible state.
Time Constraints: Every game has a time constraint. Thus it may be infeasible to find the best
move in this time.
Typical structure of the game in the AI is:
2- person game
Players alternate moves
Zero-sum game: one player’s loss is the other’s gain
Perfect information: both players have access to complete information about the state
of the game. No information is hidden from either player.
No chance (e. g. using dice) involved.
E.g. Tic- Tac- Toe, Checkers, Chess, Go, Nim, Othello
For dealing with such types of games, consider all the legal moves you can make from the
current position. Compute the new position resulting from each move. Evaluate each
resulting position and determine which is best for you. Make that move. Wait for your
opponent to move and repeat the procedure. But for this procedure the main problem is how
to evaluate the position? Evaluation function or static evaluator is used to evaluate the
‘goodness’ of a game position. The zero- sum assumption allows us to use a single evaluation
function to describe the goodness of a position with respect to both players.
Lets consider, f(n) is the evaluation function of the position ‘n’. Then,
– f(n) >> 0: position n is good for me and bad for you
– f(n) << 0: position n is bad for me and good for you
– f(n) near 0: position n is a neutral position
e.g. evaluation function for Tic- Tac- Toe:
f( n) = [# of 3- lengths open for me] - [# of 3- lengths open for you]
where a 3- length is a complete row, column, or diagonal
The most common search technique in game playing is Minimax search procedure. It is
depth-first depth-limited search procedure. It is used for games like chess and tic-tac-toe.
Mini-Max Algorithm in Artificial Intelligence
2
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
o Min-Max algorithm is mostly used for game playing in AI. Such as Chess, Checkers,
tic-tac-toe, go, and various tow-players game. This Algorithm computes the minimax
decision for the current state.
o In this algorithm two players play the game, one is called MAX and other is called
MIN.
o Both the players fight it as the opponent player gets the minimum benefit while they
get the maximum benefit.
o Both Players of the game are opponent of each other, where MAX will select the
maximized value and MIN will select the minimized value.
o The minimax algorithm performs a depth-first search algorithm for the exploration of
the complete game tree.
o The minimax algorithm proceeds all the way down to the terminal node of the tree,
then backtrack the tree as the recursion.
3
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Initial call:
Minimax(node, 3, true)
o The working of the minimax algorithm can be easily described using an example.
Below we have taken an example of game-tree which is representing the two-player
game.
o In this example, there are two players one is called Maximizer and other is called
Minimizer.
o Maximizer will try to get the Maximum possible score, and Minimizer will try to get
the minimum possible score.
o This algorithm applies DFS, so in this game-tree, we have to go all the way through
the leaves to reach the terminal nodes.
o At the terminal node, the terminal values are given so we will compare those value
and backtrack the tree until the initial state occurs. Following are the main steps
involved in solving the two-player game tree:
Step-1: In the first step, the algorithm generates the entire game-tree and apply the utility
function to get the utility values for the terminal states. In the below tree diagram, let's take A
is the initial state of the tree. Suppose maximizer takes first turn which has worst-case initial
value =- infinity, and minimizer will take next turn which has worst-case initial value =
+infinity.
4
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Step 2: Now, first we find the utilities value for the Maximizer, its initial value is -∞, so we
will compare each value in terminal state with initial value of Maximizer and determines the
higher nodes values. It will find the maximum among the all.
35.6K
Drone Racing World Champs Turn To A.I.
Step 3: In the next step, it's a turn for minimizer, so it will compare all nodes value with +∞,
and will find the 3rd layer node values.
5
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Step 4: Now it's a turn for Maximizer, and it will again choose the maximum of all nodes
value and find the maximum value for the root node. In this game tree, there are only 4
layers, hence we reach immediately to the root node, but in real games, there will be more
than 4 layers.
That was the complete workflow of the minimax two player game.
6
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
o Time complexity- As it performs DFS for the game-tree, so the time complexity of
Min-Max algorithm is O(bm), where b is branching factor of the game-tree, and m is
the maximum depth of the tree.
o Space Complexity- Space complexity of Mini-max algorithm is also similar to DFS
which is O(bm).
The main drawback of the minimax algorithm is that it gets really slow for complex games
such as Chess, go, etc. This type of games has a huge branching factor, and the player has lots
of choices to decide. This limitation of the minimax algorithm can be improved from alpha-
beta pruning which we have discussed in the next topic.
Alpha-Beta Pruning
a. Alpha: The best (highest-value) choice we have found so far at any point
along the path of Maximizer. The initial value of alpha is -∞.
b. Beta: The best (lowest-value) choice we have found so far at any point along
the path of Minimizer. The initial value of beta is +∞.
o The Alpha-beta pruning to a standard minimax algorithm returns the same move as
the standard algorithm does, but it removes all the nodes which are not really
7
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
affecting the final decision but making algorithm slow. Hence by pruning these nodes,
it makes the algorithm fast.
1. α>=β
8
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Let's take an example of two-player search tree to understand the working of Alpha-beta
pruning
Step 1: At the first step the, Max player will start first move from node A where α= -∞ and
β= +∞, these value of alpha and beta passed down to node B where again α= -∞ and β= +∞,
and Node B passes the same value to its child D.
Step 2: At Node D, the value of α will be calculated as its turn for Max. The value of α is
compared with firstly 2 and then 3, and the max (2, 3) = 3 will be the value of α at node D
and node value will also 3.
Keep Watching
9
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Step 3: Now algorithm backtrack to node B, where the value of β will change as this is a turn
of Min, Now β= +∞, will compare with the available subsequent nodes value, i.e. min (∞, 3)
= 3, hence at node B now α= -∞, and β= 3.
In the next step, algorithm traverse the next successor of Node B which is node E, and the
values of α= -∞, and β= 3 will also be passed.
Step 4: At node E, Max will take its turn, and the value of alpha will change. The current
value of alpha will be compared with 5, so max (-∞, 5) = 5, hence at node E α= 5 and β= 3,
where α>=β, so the right successor of E will be pruned, and algorithm will not traverse it, and
the value at node E will be 5.
10
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Step 5: At next step, algorithm again backtrack the tree, from node B to node A. At node A,
the value of alpha will be changed the maximum available value is 3 as max (-∞, 3)= 3, and
β= +∞, these two values now passes to right successor of A which is Node C.
At node C, α=3 and β= +∞, and the same values will be passed on to node F.
Step 6: At node F, again the value of α will be compared with left child which is 0, and
max(3,0)= 3, and then compared with right child which is 1, and max(3,1)= 3 still α remains
3, but the node value of F will become 1.
Step 7: Node F returns the node value 1 to node C, at C α= 3 and β= +∞, here the value of
beta will be changed, it will compare with 1 so min (∞, 1) = 1. Now at C, α=3 and β= 1, and
again it satisfies the condition α>=β, so the next child of C which is G will be pruned, and the
algorithm will not compute the entire sub-tree G.
11
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Step 8: C now returns the value of 1 to A here the best value for A is max (3, 1) = 3.
Following is the final game tree which is the showing the nodes which are computed and
nodes which has never computed. Hence the optimal value for the maximizer is 3 for this
example.
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.
o Worst 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 also
consumes more time because of alpha-beta factors, such a move of pruning is called
worst ordering. In this case, the best move occurs on the right side of the tree. The
time complexity for such an order is O(bm).
o Ideal ordering: The ideal ordering for alpha-beta pruning occurs when lots of
pruning happens in the tree, and best moves 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. Complexity in ideal ordering is O(bm/2).
12
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
ITERATIVE DEEPENING
Depth first search was efficient in terms of space but required some cutoff depth in order to
force backtracking when a solution was not found. Breadth first search was guaranteed to find the
shortest solution path but required inordinate amount of space because all leaf nodes had to be kept in
memory. An algorithm called depth first iterative deepening (DFID) combines the best aspects of
depth-first and breadth-first search.
To avoid the infinite depth problem of DFS, we can decide to only search until depth L, i.e.
we don’t expand beyond depth L. This is called Depth-Limited Search. Suppose if the solution is
deeper than L, then increase L iteratively. This is known as Iterative Deepening Search. This iterative
deepening search inherits the memory advantage of Depth-First search.
13
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Algorithm
1. Set SEARCH-DEPTH=1.
2. Conduct a depth-first search to a depth of SEARCH-DEPTH. If a solution path is found, then return
it.
3. Otherwise, increment SEARCH-DEPTH by 1 and go to step2.
Disadvantage
Iterative deepening looks inefficient because so many states are expanded multiple times. In
practice this is not that bad, because by far most of the nodes are at the bottom level.
For a branching factor b of 2, this might double the search time.
For a branching factor b of 10, this might add 10% to the search time.
Advantage
Avoids the problem of choosing cutoffs without sacrificing efficiency.
DFID is the optimal algorithm for uniformed search.
Performance Analysis
Completeness - Yes
Time Complexity- (d+1)b0 + d b1 + (d-1)b2 + … + bd = O(bd)
Space Complexity - O(bd)
Optimality - Yes, if step cost = 1 or increasing function of depth.
ITERATIVE DEEPENING A*
1. Set THRESHOLD=the heuristic evaluation of the start state.
2. Conduct a depth-first search, pruning any branch when its total cost function (g+h) exceeds a
THRESHOLD. If a solution path is found during the search, return it.
3. Otherwise, Increment THRESHOLD by the minimum amount. It was exceeded during the previous
step, and the go to step 2.
Iterative Deepening A* is guaranteed to find optimal solution, provided that h is a n
admissible heuristic. Because of its depth-first search technique, IDA* is very efficient with respect to
space. IDA* is the first heuristic search algorithm to find optimal paths within reasonable time and
space constraints.
14
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Knowledge representation
Humans are best at understanding, reasoning, and interpreting knowledge. Human knows
things, which is knowledge and as per their knowledge they perform various actions in the
real world. But how machines do all these things comes under knowledge representation
and reasoning. Hence we can describe Knowledge representation as following:
What to Represent:
o Object: All the facts about objects in our world domain. E.g., Guitars contains
strings, trumpets are brass instruments.
o Events: Events are the actions which occur in our world.
o Performance: It describe behavior which involves knowledge about how to do
things.
o Meta-knowledge: It is knowledge about what we know.
o Facts: Facts are the truths about the real world and what we represent.
o Knowledge-Base: The central component of the knowledge-based agents is the
knowledge base. It is represented as KB. The Knowledgebase is a group of the
15
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Sentences (Here, sentences are used as a technical term and not identical with the
English language).
Types of knowledge
1. Declarative Knowledge:
2. Procedural Knowledge
16
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
3. Meta-knowledge:
4. Heuristic knowledge:
5. Structural knowledge:
Knowledge of real-worlds plays a vital role in intelligence and same for creating artificial
intelligence. Knowledge plays an important role in demonstrating intelligent behaviour in AI
agents. An agent is only able to accurately act on some input when he has some knowledge or
experience about that input.
Let's suppose if you met some person who is speaking in a language which you don't know,
then how you will able to act on that. The same thing applies to the intelligent behaviour of
the agents.
As we can see in below diagram, there is one decision maker which act by sensing the
environment and using knowledge. But if the knowledge part will not present then, it cannot
display intelligent behaviour.
17
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
AI knowledge cycle:
An Artificial intelligence system has the following components for displaying intelligent
behavior:
o Perception
o Learning
o Knowledge Representation and Reasoning
o Planning
o Execution
The above diagram is showing how an AI system can interact with the real world and what
components help it to show intelligence. AI system has Perception component by which it
retrieves information from its environment. It can be visual, audio or another form of sensory
input. The learning component is responsible for learning from data captured by Perception
18
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
comportment. In the complete cycle, the main components are knowledge representation and
Reasoning. These two components are involved in showing the intelligence in machine-like
humans. These two components are independent with each other but also coupled together.
The planning and execution depend on analysis of Knowledge representation and reasoning.
There are mainly four approaches to knowledge representation, which are givenbelow:
o It is the simplest way of storing facts which uses the relational method, and each fact
about a set of the object is set out systematically in columns.
o This approach of knowledge representation is famous in database systems where the
relationship between different entities is represented.
o This approach has little opportunity for inference.
Player1 65 23
Player2 58 18
Player3 75 24
2. Inheritable knowledge:
o In the inheritable knowledge approach, all data must be stored into a hierarchy of
classes.
o All classes should be arranged in a generalized form or a hierarchal manner.
o In this approach, we apply inheritance property.
o Elements inherit values from other members of a class.
19
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
3. Inferential knowledge:
a. Marcus is a man
b. All men are mortal
Then it can represent as;
man(Marcus)
∀x = man (x) ----------> mortal (x)s
4. Procedural knowledge:
20
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
o Procedural knowledge approach uses small programs and codes which describes how
to do specific things, and how to proceed.
o In this approach, one important rule is used which is If-Then rule.
o In this knowledge, we can use various coding languages such as LISP
language and Prolog language.
o We can easily represent heuristic or domain-specific knowledge using this approach.
o But it is not necessary that we can represent all cases in this approach.
1. Representational Accuracy:
KR system should have the ability to represent all kind of required knowledge.
2. Inferential Adequacy:
KR system should have ability to manipulate the representational structures to produce
new knowledge corresponding to existing structure.
3. Inferential Efficiency:
The ability to direct the inferential knowledge mechanism into the most productive
directions by storing appropriate guides.
4. Acquisitional efficiency- The ability to acquire the new knowledge easily using
automatic methods.
There are mainly four ways of knowledge representation which are given as follows:
1. Logical Representation
2. Semantic Network Representation
3. Frame Representation
4. Production Rules
21
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
1. Logical Representation
Logical representation is a language with some concrete rules which deals with propositions
and has no ambiguity in representation. Logical representation means drawing a conclusion
based on various conditions. This representation lays down some important communication
rules. It consists of precisely defined syntax and semantics which supports the sound
inference. Each sentence can be translated into logics using syntax and semantics.
Syntax:
o Syntaxes are the rules which decide how we can construct legal sentences in the logic.
o It determines which symbol we can use in knowledge representation.
o How to write those symbols.
Semantics:
o Semantics are the rules by which we can interpret the sentence in the logic.
o Semantic also involves assigning a meaning to each sentence.
a. Propositional Logics
b. Predicate logics
22
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Example: Following are some statements which we need to represent in the form of nodes
and arcs.
Statements:
a. Jerry is a cat.
b. Jerry is a mammal
c. Jerry is owned by Priya.
d. Jerry is brown colored.
e. All Mammals are animal.
23
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
In the above diagram, we have represented the different type of knowledge in the form of
nodes and arcs. Each object is connected with another object by some relation.
3. Frame Representation
A frame is a record like structure which consists of a collection of attributes and its values to
describe an entity in the world. Frames are the AI data structure which divides knowledge
24
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Facets: The various aspects of a slot is known as Facets. Facets are features of frames which
enable us to put constraints on the frames. Example: IF-NEEDED facts are called when data
of any particular slot is needed. A frame may consist of any number of slots, and a slot may
include any number of facets and facets may have any number of values. A frame is also
known as slot-filter knowledge representation in artificial intelligence.
Frames are derived from semantic networks and later evolved into our modern-day classes
and objects. A single frame is not much useful. Frames system consist of a collection of
frames which are connected. In the frame, knowledge about an object or event can be stored
together in the knowledge base. The frame is a type of technology which is widely used in
various applications including Natural language processing and machine visions.
Example: 1
Slots Filters
Year 1996
Page 1152
Example 2:
25
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Let's suppose we are taking an entity, Peter. Peter is an engineer as a profession, and his age
is 25, he lives in city London, and the country is England. So following is the frame
representation for this:
Slots Filter
Name Peter
Profession Doctor
Age 25
Weight 78
4. Production Rules
Production rules system consist of (condition, action) pairs which mean, "If condition then
action". It has mainly three parts:
26
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
In production rules agent checks for the condition and if the condition exists then production
rule fires and corresponding action is carried out. The condition part of the rule determines
which rule may be applied to a problem. And the action part carries out the associated
problem-solving steps. This complete process is called a recognize-act cycle.
The working memory contains the description of the current state of problems-solving and
rule can write knowledge to the working memory. This knowledge match and may fire other
rules.
If there is a new situation (state) generates, then multiple production rules will be fired
together, this is called conflict set. In this situation, the agent needs to select a rule from these
sets, and it is called a conflict resolution.
Example:
o IF (at bus stop AND bus arrives) THEN action (get into the bus)
o IF (on the bus AND paid AND empty seat) THEN action (sit down).
o IF (on bus AND unpaid) THEN action (pay charges).
o IF (bus arrives at destination) THEN action (get down from the bus).
27
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Predicate: It tells something about the subject. Sentence involving the predicates that
describe the property of objects are denoted by P(x) where
P – The Predicate
Symbols:
28
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
4. Constants: It is fixed value term. They are individual symbols which are names of objects
like 1, 2, 3, etc.
6. Logical Operators: There are five type of logical operators such as – not(~), and (^), or(v),
implication, equivalence.
29
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
– We could state that for all values of X where X is a day of the week, the statement
weather(X, rain) is true
– Relations: red, round, prime, brother of, bigger than, part of, comes between, …
Symbols-Terms-Sentences:
2. Constant symbols are symbol expressions having the first character lowercase.
4. Function symbols are symbol expressions having the first character lowercase.
Functions have an attached arity indicating the number of elements of the domain
mapped onto each element of the range.
A function expression consists of a function constant of arity n, followed by n terms,
t 1, t 2,, t n, enclosed in parentheses and separated by commas.
A term is either a constant, variable, or function expression
30
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Terms
Predicates-Atomic Sentences
Syntactic Rules
Semantics
31
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Quantifiers:
Universal, Existential
Universal Quantifier: ∀
The sentence is true for all constants that can be substituted for the variable under
the intended interpretation.
In this case, the variable is said to be universally quantified.
Existential Quantifier: Ǝ
The sentence containing the variable is said to be true for at least one substitution
from the domain of definition.
3. The value of a function expression is that element of D obtained by evaluating the function
for the parameter values assigned by the interpretation.
6. The value of the negation of a sentence is T if the value of the sentence is F and is F if the
value of the sentence is T.
7. The value of the conjunction of two sentences is T if the value of both sentences is T and is
F otherwise.
8.-10. The truth value of expressions using v, =>, and = is determined from the value of their
operands as defined propositional calculus.
32
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Resolution
Resolution is a procedure used in proving that arguments which are expressible in predicate logic are
correct. Resolution is a procedure that produces proofs by refutation or contradiction. Resolution leads
to refute a theorem-proving technique for sentences in propositional logic and first order logic.
Resolution is a rule of inference
Resolution is a computerized theorem prover
33
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Equilateral(ABC) Equilateral(ABC)
None
34
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Example 2
1. Mammals drink milk.
2. Man is mortal.
3. Man is mammal.
4. Tom is a man.
Prove “Tom drinks milk” and Prove “Tom is mortal”
Propositional Logic
1. Mammal(Tom)drink(Tom, Milk)
2. Man(Tom)Mortal(Tom)
3. Man(Tom)Mammal(Tom)
4. Man(Tom)
Convert to clausal form
1. Mammal(Tom) drink(Tom, Milk)
2. Man(Tom) Mortal(Tom)
3. Man(Tom) Mammal(Tom)
4. Man(Tom)
To prove ” Tom drinks milk”
Let us disprove “Not Tom drinks milk”“Drink (Tom, Milk)”
Mammal(Tom) drink(Tom, Milk) . Drink (Tom, Milk)
Man(Tom) Man(Tom)
None
Thus we proved “Tom drinks Milk”
ii) To prove ” Tom is Mortal”Mortal(Tom)
Let us disprove “Not Tom is Mortal” Mortal(Tom)
Man(Tom) Man(Tom)
None
Thus we proved “Tom is Mortal”
Disadvantages of propositional logic
35
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
36
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
3. graduating(name1)
4. ∀w smile(w)
(vi) Eliminate ∀
1. graduating(x) happy(x)
2. happy(y) smile(y)
3. graduating(name1)
4. smile(w)
(vii) Convert to conjunct of disjuncts form.
(viii) Make each conjunct a separate clause.
(ix) Standardize variables apart again.
. graduating(name1) graduating(x)
None
Thus, we proved someone is smiling.
37
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Problem 2
Explain the unification algorithm used for reasoning under predicate logic with an example.
Consider the following facts
a. Team India
b. Team Australia
c. Final match between India and Australia
d. India scored 350 runs, Australia scored 350 runs, India lost 5 wickets, Australia
lost 7 wickets.
e. The team which scored the maximum runs wins.
f. If the scores are same the team which lost minimum wickets wins the match.
Represent the facts in predicate, convert to clause form and prove by resolution “India wins the
match”.
Solution:
Convert in to predicate Logic
(a) team(India)
(b) team(Australia)
(c) team(India) team(Australia)final_match(India, Australia)
(d) score(India,350) score(Australia,350) wicket(India,5) wicket(Australia,7)
(e) ∃x team(x) wins(x)score(x, max_runs))
(f) ∃xy score(x,equal(y)) wicket(x, min) final_match(x,y)win(x)
Convert to clausal form
(i) Eliminate the sign
(a) team(India)
(b) team(Australia)
(c) (team(India) team(Australia)) final_match(India, Australia)
(d) score(India,350) score(Australia,350) wicket(India,5) wicket(Australia,7)
(e) ∃x (team(x) wins(x)) score(x, max_runs))
(f) ∃xy (score(x,equal(y)) wicket(x, min) final_match(x,y)) win(x)
(ii) Reduce the scope of negation
(a) team(India)
(b) team(Australia)
(c) team(India) team(Australia) final_match(India, Australia)
(d) score(India,350) score(Australia,350) wicket(India,5) wicket(Australia,7)
(e) ∃x team(x) wins(x) score(x, max_runs))
(f) ∃xy score(x,equal(y)) wicket(x, min_wicket) final_match(x,y)) win(x)
(iii) Standardize variables apart
(iv) Move all quantifiers to the left
(v) Eliminate ∃
(a) team(India)
(b) team(Australia)
(c) team(India) team(Australia) final_match(India, Australia)
(d) score(India,350) score(Australia,350) wicket(India,5) wicket(Australia,7)
(e) team(x) wins(x) score(x, max_runs))
(f) score(x,equal(y)) wicket(x, min_wicket) final_match(x,y)) win(x)
(vi) Eliminate ∀
(vii) Convert to conjunct of disjuncts form.
38
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Disprove: win(India)
team(India)
team(India) team(Australia)
score(x,equal(y))wicket(x,
min_wicket)
None
Thus, proved India wins match.
Problem 3
Consider the following facts and represent them in predicate form:
F1. There are 500 employees in ABC company.
F2. Employees earning more than Rs. 5000 pay tax.
F3. John is a manager in ABC company.
F4. Manager earns Rs. 10,000.
Convert the facts in predicate form to clauses and then prove by resolution: “John pays tax”.
39
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Solution:
Convert in to predicate Logic
1. company(ABC) employee(500,ABC)
2. x company(ABC) employee(x, ABC) earns(x,5000)pays(x, tax)
3. manager(John, ABC)
4. x manager(x, ABC)earns(x,10000)
Convert to clausal form
(i) Eliminate the sign
1. company(ABC) employee(500,ABC)
2. x (company(ABC) employee(x, ABC) earns(x,5000)) pays(x, tax)
3. manager(John, ABC)
4. x manager(x, ABC) earns(x, 10000)
(ii) Reduce the scope of negation
1. company(ABC) employee(500,ABC)
2. x company(ABC) employee(x, ABC) earns(x,5000) pays(x, tax)
3. manager(John, ABC)
4. x manager(x, ABC) earns(x, 10000)
(iii) Standardize variables apart
1. company(ABC) employee(500,ABC)
2. x company(ABC) employee(x, ABC) earns(x,5000) pays(x, tax)
3. manager(John, ABC)
4. y manager(x, ABC) earns(y, 10000)
(iv) Move all quantifiers to the left
(v) Eliminate ∃
1. company(ABC) employee(500,ABC)
2. company(ABC) employee(x, ABC) earns(x,5000) pays(x, tax)
3. manager(John, ABC)
4. manager(x, ABC) earns(y, 10000)
(vi) Eliminate ∀
(vii) Convert to conjunct of disjuncts form.
(viii) Make each conjunct a separate clause.
1. (a)company(ABC)
(b)employee(500,ABC)
2. company(ABC) employee(x, ABC) earns(x,5000) pays(x, tax)
3. manager(John, ABC)
4. manager(x, ABC) earns(y, 10000)
(ix) Standardize variables apart again.
Prove :pays(John, tax)
Disprove: pays(John, tax)
40
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
None
Thus, proved john pays tax.
Problem 4
If a perfect square is divisible by a prime p then it is also divisible by square of p.
Every perfect square is divisible by some prime.
36 is a perfect square.
Convert in to predicate Logic
1. ∀xy perfect_sq(x) prime(y) divides(x,y)divides(x,square(y))
2. ∀x∃y perfect_sq(x) prime(y) divides(x,y)
3. perfect_sq(36)
Problem 5
1. Marcus was a man
man(Marcus)
2. Marcus was a Pompeian
Pompeian(Marcus)
3. All Pompeians were Romans
∀x (Pompeian(x) Roman(x))
4. Caesar was a ruler
ruler(Caesar)
5. All Romans were either loyal to Caesar or hated him
∀x (Roman(x) loyalto(x,Caesar) hate(x,Caesar))
6. Everyone is loyal to someone
∀x y (person(x) person(y) loyalto(x,y))
7. People only try to assassinate rulers they are not loyal to
∀x ∀y (person(x) ruler(y) tryassassinate(x,y) ¬loyalto(x,y))
8. Marcus tried to assassinate Caesar
tryassassinate(Marcus, Caesar)
9. All men are persons
∀x (man(x) person(x))
41
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Semantic Network
A semantic net (or semantic network) is a knowledge representation technique used for
propositional information. So it is also called a propositional net. Semantic nets convey
meaning. They are two dimensional representations of knowledge. Mathematically a semantic
net can be defined as a labelled directed graph.
Semantic nets consist of nodes, links (edges) and link labels. In the semantic network
diagram, nodes appear as circles or ellipses or rectangles to represent objects such as physical
objects, concepts or situations. Links appear as arrows to express the relationships between
objects, and link labels specify particular relations. Relationships provide the basic structure
for organizing knowledge. The objects and relations involved need not be so concrete. As
nodes are associated with other nodes semantic nets are also referred to as associative nets.
Tom is a cat.
Tom caught a bird.
Tom is owned by John.
Tom is ginger in colour.
Cats like cream.
The cat sat on the mat.
A cat is a mammal.
A bird is an animal.
All mammals are animals.
Mammals have fur
It is argued that this form of representation is closer to the way humans structure knowledge
by building mental links between things than the predicate logic we considered earlier.Note
In particular how all the information about a particular object is concentrated on the node
Representing that object, rather than scattered around several clauses in logic.There is,
however, some confusion here which stems from the imprecise nature of semantic nets.A
particular problem is that we haven’t distinguished between nodes representing classes of
things,and nodes representing individual objects. So, for example, the node labelled Cat
represents both the single (nameless) cat who sat on the mat, and the whole class of cats to
which Tom belongs, which are mammals and which like cream. The is_alink has two
different meanings – it can mean that one object is an individual item from a class, for
example Tom is a member of the class of cats,or that one class is a subset of another, for
example, the class of cats is a subset of the class of mammals. This confusion does not occur
in logic, where the use of quantifiers, names and predicates makes it clear what we mean so:
Tom is a catis represented by
Cat(Tom)
42
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
∀x(Cat(X)→Mammal(x))
principle of looking beyond the immediate surface structure of a sentence to find its deep
structure.
Note that where we had an unnamed member of some class, we have had to introduce a node with an
invented name to represent a particular member of the class. This is a proces ssimilar to the
Skolemisation we considered previously as a way of dealing with existential quantifiers. For example,
“Tom caught a bird” would be represented in logic by ∃x(bird(x)∧caught(Tom,x))which would be
Skolemised by replacing the x with a Skolem constant; the same thing was done above where bird1
was the name given to the individual bird that Tom caught.There are still plenty of issues to be
resolved if we really want to represent what is meant by the English phrases, or to be really clear
about what the semantic net means, but we are getting towards a notation that can be used practically
(one example of a thing we have skated over is how to deal with mass nouns like “fur” or “cream”
which refer to things that come in amounts rather than individual objects).
43
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
– Frames
– Conceptual Dependency
– Scripts
– CYC
(i) Semantic Networks
In semantic net, information is represented as a set of nodes connected to each other by a set
of labelled arcs, which represent relationship among the nodes. In this network, inheritance is used to
derive the additional relation.
Eg has_part(Pee-Wee-Reesse, nose)
Intersection search
To find the relationship among objects by spreading activation out from each of two nodes and seeing
where the activation function met. This process is called intersection search.
Example:
What is the connection between the Brooklyn dodger and blue?
The answer is Pee-Wee-Reese
Representing non binary predicates
Semantic nets are a natural way to represent relationships that would appear as binary predicates.
instance(pee-Wee-Reese, Person)
team(Pee-Wee-Reese, Brooklyn-Dodger)
Unary predicates can also be represented as binary predicates
Unary Predicate: man(Marcus)
Binary Predicate: instance(Marcus, man)
(ii) Frame
A frame is a collection of attributes and associated values that describe some entity in the
world. Sometimes a frame describes an entity in some absolute sense; sometimes it represents the
entity from a particular point of view. A single frame taken alone is rarely useful. Instead build frame
systems out of collections of frames that are connected to each other by a virtue of the fact that the
value of an attribute of one frame may be another frame. Frame system can be used to encode
knowledge and support reasoning. Each frame represents either a class or an instance.
Example of a frame
Pee-wee-Reese
instance: :Fielder
height :5.10
bats :Right
batting-average :0.309
team :Brooklyn Dodger
uniform color :Blue
ML-Baseball-Team
isa :Team
cardinality :26
team-size :24
44
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Conceptual dependency has been implemented in variety of programs that read and understand natural
language text. Unlike semantic nets, which provide only a structure in to which nodes representing
information at any level can be placed, conceptual dependency provides both a structure and a
specific set of primitives, at a particular level of granularity, out of which representations of particular
pieces of information can be constructed.
(iv) Scripts
Script is a structure that describes a stereotyped sequence of events in a particular context. A
script consists of a set of slots. Associated with each slot some information about what kind of values
it may contain as well as a default value to be used if no other information is available. The important
components of the scripts are
Entry conditions-Conditions that must be satisfied before the events described in a script can
occur.
Result- Event happened after the script has occurred
Props- Objects involved in the event
Roles-People who are involved in the event
Track-The specific variation on a general more pattern
Scenes-The actual sequence of events that occur
Example: Restaurant
Track- Coffee Shop
Prop- Table, Menu, food, Money
Roles- S Customer
W Waiter
C cook
M Cashier
O Owner
Entry Condition
S is hungry
S has money
Results
S has less money
O has more money
S is not hungry
Scene-Eating
45
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
C ATRANS F to W
W WATRANS F to S
S INGEST F
(v) CYC
CYC is a very large knowledge base project aimed at capturing human common sense
knowledge. The goal of CYC is to encode the large body of knowledge. Such a knowledge base could
then be combined with specialized knowledge bases to produce systems.
CYC contains representations of events and objects. CYC is particularly concerned with the
issue of scale, that is, what happens when we build knowledge bases that contain millions of objects.
Prolog Programming
Prolog is a logic programming language. It has important role in artificial intelligence. Unlike
many other programming languages, Prolog is intended primarily as a declarative
programming language. In prolog, logic is expressed as relations (called as Facts and Rules).
Core heart of prolog lies at the logic being applied. Formulation or Computation is carried out
by running a query over these relations.
In prolog, We declare some facts. These facts constitute the Knowledge Base of the system.
We can query against the Knowledge Base. We get output as affirmative if our query is
already in the knowledge Base or it is implied by Knowledge Base, otherwise we get output
as negative. So, Knowledge Base can be considered similar to database, against which we can
query. Prolog facts are expressed in definite pattern. Facts contain entities and their relation.
Entities are written within the parenthesis separated by comma (, ). Their relation is expressed
at the start and outside the parenthesis. Every fact/rule ends with a dot (.). So, a typical prolog
fact goes as follows :
Example :
friends(raju, mahesh).
singer(sonu).
odd_number(5).
46
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Explanation :
sonu is a singer.
5 is an odd number.
Key Features :
1. Unification : The basic idea is, can the given terms be made to represent the same
structure.
2. Backtracking : When a task fails, prolog traces backwards and tries to satisfy previous task.
Running queries :
Query 1 : ?- singer(sonu).
Output : Yes.
Query 2 : ?- odd_number(7).
Output : No.
Advantages :
3. It has built in list handling. Makes it easier to play with any algorithm involving lists.
47
191AIC403T - ARTIFICIAL INTELLIGENCEUnit-II
Disadvantages :
1. LISP (another logic programming language) dominates over prolog with respect to I/O
features.
48