Lectures 2
Lectures 2
Lectures 2
Search
Solving Problems by Searching
1
What is Intelligence
• The ability of a system to calculate,
reason, perceive relationships and
analogies, learn from experience, store
and retrieve information from memory,
solve problems, comprehend complex
ideas, use natural language fluently,
classify, generalize, and adapt new
situations.
2
Types of Intelligence
3
Types….
4
What is Intelligence Composed Of?
5
Reasoning
6
Learning
8
Types of Learning
9
Problem Solving
11
Linguistic Intelligence
12
AI Involved in….
13
What’s Involved in AI
14
Searching
• In which we see how an agent can find a sequence of
actions that achieves its goals when no single action will do
• This chapter describes one kind of goal-based agent called a
problem-solving agent.
• Problem-solving agents use atomic representations, as that
is, states of the world are considered as wholes, with no
internal structure visible to the problemsolving algorithms.
• Goal-based agents that use more advanced factored or
structured representations are usually called planning
agents
15
Problem formulation
• Problem formulation is the process of deciding
what actions and states to consider, given a
goal.
• A search algorithm takes a problem as input
and returns a solution in the form of an action
sequence.
• Execution Once a solution is found, the actions
it recommends can be carried out. This is called
execution
16
Well Defined Problem & Solutions
• A problem can be defined formally by five
components
• The initial state
• Actions
• Transition Model
• Path
• Goal Test
17
Types of Searching
• Informed Searching
Informed search algorithms can do quite well given
some guidance on where to look for solutions
• Uninformed Searching
• Uninformed search algorithms are given no
information about the problem other than its
definition
18
Search
• Search permeates all of AI
• What choices are we searching through?
– Problem solving
Action combinations (move 1, then move 3, then move 2...)
– Natural language
Ways to map words to parts of speech
– Computer vision
Ways to map features to object model
– Machine learning
Possible concepts that fit examples seen so far
– Motion planning
Sequence of moves to reach goal destination
• An intelligent agent is trying to find a set or sequence of actions to
achieve a goal
• This is a goal-based agent
19
20
Uninformed/Blind Search:
23
Example
24
Breadth First Search
• Example:
• In the below tree structure, we have shown the
traversing of the tree using BFS algorithm from
the root node S to goal node K. BFS search
algorithm traverse in layers, so it will follow the
path which is shown by the dotted arrow, and
the traversed path will be:
1.S---> A--->B---->C--->D---->G--->H--->E----
>F---->I---->K
25
Depth-first Search
26
Advantages/Disadvantages
• Advantage:
• DFS requires very less memory as it only needs to store a
stack of the nodes on the path from root node to the current
node.
• It takes less time to reach to the goal node than BFS algorithm
(if it traverses in the right path).
• Disadvantage:
• There is the possibility that many states keep re-occurring, and
there is no guarantee of finding the solution.
• DFS algorithm goes for deep down searching and sometime it
may go to the infinite loop.
27
Example
28
Example
• In the above search tree, we have shown the flow of
depth-first search, and it will follow the order as:
• Root node--->Left node ----> right node.
• It will start searching from root node S, and traverse
A, then B, then D and E, after traversing E, it will
backtrack the tree as E has no other successor and
still goal node is not found. After backtracking it
will traverse node C and then G, and here it will
terminate as it found goal node.
29
Depth-Limited Search Algorithm:
30
Advantages/Disadvantages
• Advantages:
• Depth-limited search is Memory efficient.
• Disadvantages:
• Depth-limited search also has a disadvantage
of incompleteness.
• It may not be optimal if the problem has more
than one solution.
31
Example
32
Uniform-cost Search Algorithm:
33
• Advantages:
• Uniform cost search is optimal because at every
state the path with the least cost is chosen.
• Disadvantages:
• It does not care about the number of steps
involve in searching and only concerned about
path cost. Due to which this algorithm may be
stuck in an infinite loop
34
Example
35
Iterative deepening depth-first Search:
36
• Advantages:
• It combines the benefits of BFS and DFS
search algorithm in terms of fast search and
memory efficiency.
• Disadvantages:
• The main drawback of IDDFS is that it repeats
all the work of the previous phase.
37
Example
38
Example
• 1'st Iteration-----> A
2'nd Iteration----> A, B, C
3'rd Iteration------>A, B, D, E, C, F, G
4'th Iteration------>A, B, D, H, I, E, C, F, K, G
In the fourth iteration, the algorithm will find
the goal node.
39
Informed Search Algorithms
40
Heuristic is a function
• Heuristic is a function which is used in Informed Search,
and it finds the most promising path. It takes the current
state of the agent as its input and produces the estimation
of how close agent is from the goal.
• The heuristic method, however, might not always give the
best solution, but it guaranteed to find a good solution in
reasonable time. Heuristic function estimates how close a
state is to the goal. It is represented by h(n), and it
calculates the cost of an optimal path between the pair of
states. The value of the heuristic function is always
positive.
41
Pure Heuristic Search:
42
Best-first Search Algorithm (Greedy Search):
43
Best first search algorithm:
44
Advantages
• Best first search can switch between BFS and
DFS by gaining the advantages of both the
algorithms.
• This algorithm is more efficient than BFS and
DFS algorithms.
45
Example
46
Disadvantages:
47
• Example:
• Consider the below search problem, and we
will traverse it using greedy best-first search.
At each iteration, each node is expanded using
evaluation function f(n)=h(n) , which is given
in the below table.
48
A* Algorithm
• A* search is the most commonly known form of best-
first search.
• 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.
49
50
Algorithm
• Step1: Place the starting node in the OPEN list.
• Step 2: Check if the OPEN list is empty or not,
if the list is empty then return failure and stops.
• Step 3: Select the node from the OPEN list
which has the smallest value of evaluation
function (g+h), if node n is goal node then
return success and stop, otherwise
51
Algo…..
• Step 4: Expand node n and generate all of its
successors, and put n into the closed list. For each
successor n', check whether n' is already in the
OPEN or CLOSED list, if not then compute
evaluation function for n' and place into Open list.
• Step 5: Else if node n' is already in OPEN and
CLOSED, then it should be attached to the back
pointer which reflects the lowest g(n') value.
• Step 6: Return to Step 2.
52
Advantages:
53
Disadvantages:
54
Example
55
Hill Climbing Algorithm
56
Hill ….
• A node of hill climbing algorithm has two
components which are state and value.
• Hill Climbing is mostly used when a good
heuristic is available.
• In this algorithm, we don't need to maintain
and handle the search tree or graph as it only
keeps a single current state.
57
Features of hill climbing Algo
• Generate and Test variant: Hill Climbing is the
variant of Generate and Test method. The Generate
and Test method produce feedback which helps to
decide which direction to move in the search space.
• Greedy approach: Hill-climbing algorithm search
moves in the direction which optimizes the cost.
• No backtracking: It does not backtrack the search
space, as it does not remember the previous states.
58
State-space Diagram for Hill Climbing:
60
• Local Maximum: Local maximum is a state which is better
than its neighbor states, but there is also another state which is
higher than it
• Global Maximum: Global maximum is the best possible state
of state space landscape. It has the highest value of objective
function.
• Current state: It is a state in a landscape diagram where an
agent is currently present.
• Flat local maximum: It is a flat space in the landscape where
all the neighbor states of current states have the same value.
• Shoulder: It is a plateau region which has an uphill edge.
61
Types of Hill Climbing Algorithm:
62
Simple hill climbing
• Simple hill climbing is the simplest way to implement a
hill climbing algorithm. It only evaluates the
neighbor node state at a time and selects the first
one which optimizes current cost and set it as a
current state. It only checks it's one successor state,
and if it finds better than the current state, then move
else be in the same state. This algorithm has the
following features:
• Less time consuming
• Less optimal solution and the solution is not guaranteed
63
Algorithm for Simple Hill Climbing:
65
• Step 1: Evaluate the initial state, if it is goal state then return
success and stop, else make current state as initial state.
• Step 2: Loop until a solution is found or the current state
does not change.
• Let SUCC be a state such that any successor of the current state
will be better than it.
• For each operator that applies to the current state:
• Apply the new operator and generate a new state.
• Evaluate the new state.
• If it is goal state, then return it and quit, else compare it to the SUCC.
• If it is better than SUCC, then set new state as SUCC.
• If the SUCC is better than the current state, then set current state to SUCC
66
Stochastic hill climbing:
67
Adversarial Search
69
Types of AI Games
•Games are modeled as a Search problem and heuristic evaluation function, and
these are the two main factors which help to model and solve games in AI.
70
• Perfect information: A game with the perfect
information is that in which agents can look into the
complete board. Agents have all the information
about the game, and they can see each other moves
also. Examples are Chess, Checkers, Go, etc.
• Imperfect information: If in a game agents do not
have all information about the game and not aware
with what's going on, such type of games are called
the game with imperfect information, such as tic-tac-
toe, Battleship, blind, Bridge, etc.
71
• Deterministic games: Deterministic games are those
games which follow a strict pattern and set of rules for
the games, and there is no randomness associated with
them. Examples are chess, Checkers, Go, tic-tac-toe, etc.
• Non-deterministic games: Non-deterministic are those
games which have various unpredictable events and has
a factor of chance or luck. This factor of chance or luck
is introduced by either dice or cards. These are random,
and each action response is not fixed. Such games are
also called as stochastic games.
72
Mini-Max Algorithm in Artificial Intelligence
75
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.
76
77
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.
78
79
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.
80
81
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.
82
83
Disadvantages
• 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.
84
Alpha-Beta Pruning
85
• Alpha-beta pruning can be applied at any depth of a tree, and
sometimes it not only prune the tree leaves but also entire sub-tree.
• The two-parameter can be defined as:
• 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 -∞.
• 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 +∞.
• 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 affecting the final decision but
making algorithm slow. Hence by pruning these nodes, it makes
the algorithm fast.
• Condition for Alpha-beta pruning:
• The main condition which required for alpha-beta pruning is:
1.α>=β
86
Key points about alpha-beta pruning:
88
89
• 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.
• 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.
90
91
• 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.
92
93
• 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.
94
95
• 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.
96
97
• 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.
98
99
Constraint Satisfaction Problems
• We have seen so many techniques like Local
search, Adversarial search to solve different
problems. The objective of every problem-
solving technique is one, i.e., to find a solution
to reach the goal.
• Although, in adversarial search and local
search, there were no constraints on the agents
while solving the problems and reaching to its
solutions.
100
• Constraint satisfaction is a technique where a
problem is solved when its values satisfy certain
constraints or rules of the problem. Such type of
technique leads to a deeper understanding of the
problem structure as well as its complexity.
• Constraint satisfaction depends on three
components, namely:
• X: It is a set of variables.
• D: It is a set of domains where the variables reside.
There is a specific domain for each variable.
• C: It is a set of constraints which are followed by
the set of variables.
101
Solving Constraint Satisfaction Problems
102
• An assignment of values to a variable can be done in three
ways:
• Consistent or Legal Assignment: An assignment which does
not violate any constraint or rule is called Consistent or legal
assignment.
• Complete Assignment: An assignment where every variable is
assigned with a value, and the solution to the CSP remains
consistent. Such assignment is known as Complete assignment.
• Partial Assignment: An assignment which assigns values to
some of the variables only. Such type of assignments are called
Partial assignments.
103
Types of Domains in CSP
105
106
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
107
• Knowledge representation and reasoning (KR, KRR) is the part of
Artificial intelligence which concerned with AI agents thinking and
how thinking contributes to intelligent behavior of agents.
• It is responsible for representing information about the real world so
that a computer can understand and can utilize this knowledge to
solve the complex real world problems such as diagnosis a medical
condition or communicating with humans in natural language.
• It is also a way which describes how we can represent knowledge in
artificial intelligence. Knowledge representation is not just storing
data into some database, but it also enables an intelligent machine
to learn from that knowledge and experiences so that it can behave
intelligently like a human.
108
What to Represent:
109
110
Declarative Knowledge:
• Declarative knowledge is to know about
something.
• It includes concepts, facts, and objects.
• It is also called descriptive knowledge and
expressed in declarative sentences.
• It is simpler than procedural language.
111
Procedural Knowledge
114
The relation between knowledge and intelligence:
115
• 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 behavior 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 behavior.
116
117
AI knowledge cycle:
118
AI knowledge cycle:
119
• 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 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.
120
Approaches to knowledge representation:
122
2. Inheritable knowledge:
123
124
3. Inferential knowledge:
man(Marcus)
∀x = man (x) ----------> mortal (x)s
125
4. Procedural knowledge:
126
Requirements for knowledge Representation system:
127
Techniques of knowledge representation
128
129
1. Logical Representation
130
• Syntax:
• Syntaxes are the rules which decide how we can construct legal
sentences in the logic.
• It determines which symbol we can use in knowledge representation.
• How to write those symbols.
• Semantics:
• Semantics are the rules by which we can interpret the sentence in the
logic.
• Semantic also involves assigning a meaning to each sentence.
• Logical representation can be categorised into mainly two logics:
1.Propositional Logics
2.Predicate logics
131
• Advantages of logical representation:
1.Logical representation enables us to do logical reasoning.
2.Logical representation is the basis for the programming
languages.
• Disadvantages of logical Representation:
1.Logical representations have some restrictions and are
challenging to work with.
2.Logical representation technique may not be very
natural, and inference may not be so efficient.
132
2. Semantic Network Representation
134
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. 135
Drawbacks in Semantic representation:
136
Advantages of Semantic network:
137
3. Frame Representation
139
Examples:
1.a) It is Sunday.
2.b) The Sun rises from West (False proposition)
3.c) 3+3= 7(False proposition)
4.d) 5 is a prime number.
140
Following are some basic facts about
propositional logic:
• Propositional logic is also called Boolean logic as it works on
0 and 1.
• In propositional logic, we use symbolic variables to represent
the logic, and we can use any symbol for a representing a
proposition, such A, B, C, P, Q, R, etc.
• Propositions can be either true or false, but it cannot be both.
• Propositional logic consists of an object, relations or function,
and logical connectives.
• These connectives are also called logical operators.
• The propositions and connectives are the basic elements of the
propositional logic.
141
Cont…..
• Connectives can be said as a logical operator which connects
two sentences.
• A proposition formula which is always true is
called tautology, and it is also called a valid sentence.
• A proposition formula which is always false is
called Contradiction.
• A proposition formula which has both true and false values is
called
• Statements which are questions, commands, or opinions are
not propositions such as "Where is Rohini", "How are you",
"What is your name", are not propositions.
142
• Syntax of propositional logic:
• The syntax of propositional logic defines the
allowable sentences for the knowledge
representation. There are two types of
Propositions:
1.Atomic Propositions
2.Compound propositions
143
Atomic Proposition:
• Atomic propositions are the simple
propositions. It consists of a single proposition
symbol. These are the sentences which must
be either true or false.
a) 2+2 is 4, it is an atomic proposition as it is a tr
ue fact.
b) "The Sun is cold" is also a proposition as it is
a false fact
144
Compound proposition:
• Compound propositions are constructed by
combining simpler or atomic propositions,
using parenthesis and logical connectives.
• Example:
a) "It is raining today, and street is wet."
b) "Ali is a doctor, and his clinic is in Mansehra.
"
145
Logical Connectives:
146
Negation: A sentence such as ¬ P is called
negation of P. A literal can be either Positive
literal or negative literal.
Conjunction: A sentence which has ∧ connective
such as, P ∧ Q is called a conjunction.
Example: Rohan is intelligent and hardworking.
It can be written as,
P=Rohan is intelligent,
Q= Rohan is hardworking. → P∧ Q.
147
Disjunction: A sentence which has ∨ connective, such as P ∨
Q. is called disjunction, where P and Q are the propositions.
Example: "Ritika is a doctor or Engineer",
Here P= Ritika is Doctor. Q= Ritika is Doctor, so we can write
it as P ∨ Q.
Implication: A sentence such as P → Q, is called an
implication. Implications are also known as if-then rules. It
can be represented as
If it is raining, then the street is wet.
Let P= It is raining, and Q= Street is wet, so it is
represented as P → Q
148
• Biconditional: A sentence such as P⇔ Q is a
Biconditional sentence, example If I am
breathing, then I am alive
P= I am breathing, Q= I am alive, it
can be represented as P ⇔ Q.
149
Propositional Logic Connectives:
150
Cont….
151
152
153
Rules of Inference in Artificial intelligence
154
Inference rules:
• Inference rules are the templates for generating valid arguments. Inference
rules are applied to derive proofs in artificial intelligence, and the proof is a
sequence of the conclusion that leads to the desired goal.
• In inference rules, the implication among all the connectives plays an
important role. Following are some terminologies related to inference rules:
• Implication: It is one of the logical connectives which can be represented as P
→ Q. It is a Boolean expression.
• Converse: The converse of implication, which means the right-hand side
proposition goes to the left-hand side and vice-versa. It can be written as Q →
P.
• Contrapositive: The negation of converse is termed as contrapositive, and it
can be represented as ¬ Q → ¬ P.
• Inverse: The negation of implication is called inverse. It can be represented as
¬ P → ¬ Q.
155
Types of Inference rules:
• 1. Modus Ponens:
• The Modus Ponens rule is one of the most
important rules of inference, and it states that
if P and P → Q is true, then we can infer that
Q will be true. It can be represented as:
156
Example:
• Statement-1: "If I am sleepy then I go to bed"
==> P→ Q
Statement-2: "I am sleepy" ==> P
Conclusion: "I go to bed." ==> Q.
Hence, we can say that, if P→ Q is true and P
is true then Q will be true.
157
2. Modus Tollens:
158
Example
• Statement-1: "If I am sleepy then I go to bed"
==> P→ Q
Statement-2: "I do not go to the bed."==> ~Q
Statement-3: Which infers that "I am not
sleepy" => ~P
159
3. Hypothetical Syllogism:
161
Example:
162
First-Order Logic in Artificial intelligence
163
• To represent the above statements, PL logic is not
sufficient, so we required some more powerful logic,
such as first-order logic.
• First-Order logic:
• First-order logic is another way of knowledge
representation in artificial intelligence. It is an extension
to propositional logic.
• FOL is sufficiently expressive to represent the natural
language statements in a concise way.
• First-order logic is also known as Predicate logic or
First-order predicate logic. First-order logic is a
powerful language that develops information about the
objects in a more easy way and can also express the
relationship between those objects.
164
• First-order logic (like natural language) does not only assume
that the world contains facts like propositional logic but also
assumes the following things in the world:
• Objects: A, B, people, numbers, colors, wars, theories, squares, pits,
wumpus, ......
• Relations: It can be unary relation such as: red, round, is
adjacent, or n-any relation such as: the sister of, brother of, has
color, comes between
• Function: Father of, best friend, third inning of, end of, ......
• As a natural language, first-order logic also has two main parts:
• Syntax
• Semantics
165
Syntax of First-Order logic:
166
Basic Elements of First-order logic:
167
Constant 1, 2, A, John, Mumbai, cat,....
Variables x, y, z, a, b,....
Connectives ∧, ∨, ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
168
Atomic sentences:
170
Quantifiers in First-order logic:
171
Universal Quantifier:
172
• If x is a variable, then ∀x is read as:
• For all x
• For each x
• For every x.
• Example:
• All man drink coffee.
• Let a variable x which refers to a cat so all x
can be represented in UOD as below
173
∀x man(x) → drink (x, coffee).
It will be read as: There are all x where x is a man who drink coffee.
174
Existential Quantifier:
175
• If x is a variable, then existential quantifier
will be ∃x or ∃(x). And it will be read as:
• There exists a 'x.'
• For some 'x.'
• For at least one 'x.
176
∃x: boys(x) ∧ intelligent(x)
It will be read as: There are some x where x is a boy who is intelligent.
177
• Points to remember:
• The main connective for universal quantifier ∀ is
implication →.
• The main connective for existential quantifier ∃ is
and ∧.
• Properties of Quantifiers:
• In universal quantifier, ∀x∀y is similar to ∀y∀x.
• In Existential quantifier, ∃x∃y is similar to ∃y∃x.
• ∃x∀y is not similar to ∀y∃x.
178
Some Examples of FOL using quantifier:
180
• 4. Not all students like both Mathematics
and Science.
In this question, the predicate is "like(x, y),"
where x= student, and y= subject.
Since there are not all students, so we will
use ∀ with negation, so following
representation for this:
¬∀ (x) [ student(x) → like(x,
Mathematics) ∧ like(x, Science)].
181
• 5. Only one student failed in Mathematics.
In this question, the predicate is "failed(x, y),"
where x= student, and y= subject.
Since there is only one student who failed in
Mathematics, so we will use following
representation for this:
∃(x) [ student(x) → failed (x,
Mathematics) ∧∀ (y) [¬(x==y) ∧ student(y)
→ ¬failed (x, Mathematics)].
182
Free and Bound Variables:
183
Knowledge Engineering in First-order logic
184
• In this topic, we will understand the Knowledge
engineering process in an electronic circuit domain, which
is already familiar. This approach is mainly suitable for
creating special-purpose knowledge base
• The knowledge-engineering process:
• Following are some main steps of the knowledge-
engineering process. Using these steps, we will develop a
knowledge base which will allow us to reason about digital
circuit (One-bit full adder) which is given below
185
186
Steps of Knowledge Engineering
• 1. Identify the task:
• The first step of the process is to identify the task, and for the
digital circuit, there are various reasoning tasks.
• At the first level or highest level, we will examine the
functionality of the circuit:
• Does the circuit add properly?
• What will be the output of gate A2, if all the inputs are high?
• At the second level, we will examine the circuit structure details
such as:
• Which gate is connected to the first input terminal?
• Does the circuit have feedback loops?
187
• 2. Assemble the relevant knowledge:
• In the second step, we will assemble the relevant
knowledge which is required for digital circuits. So for
digital circuits, we have the following required
knowledge:
• Logic circuits are made up of wires and gates.
• Signal flows through wires to the input terminal of the
gate, and each gate produces the corresponding output
which flows further.
• In this logic circuit, there are four types of gates
used: AND, OR, XOR, and NOT.
• All these gates have one output terminal and two input
terminals (except NOT gate, it has one input terminal).
188
• 3. Decide on vocabulary:
• The next step of the process is to select functions, predicate, and constants
to represent the circuits, terminals, signals, and gates. Firstly we will
distinguish the gates from each other and from other objects. Each gate is
represented as an object which is named by a constant, such as, Gate(X1).
The functionality of each gate is determined by its type, which is taken as
constants such as AND, OR, XOR, or NOT. Circuits will be identified by
a predicate: Circuit (C1).
• For the terminal, we will use predicate: Terminal(x).
• For gate input, we will use the function In(1, X1) for denoting the first
input terminal of the gate, and for output terminal we will use Out (1, X1).
• The function Arity(c, i, j) is used to denote that circuit c has i input, j
output.
• The connectivity between gates can be represented by
predicate Connect(Out(1, X1), In(1, X1)).
• We use a unary predicate On (t), which is true if the signal at a terminal is
on.
189
• 4. Encode general knowledge about the domain:
• To encode the general knowledge about the logic circuit, we need
some following rules:
• If two terminals are connected then they have the same input signal,
it can be represented as:
1. ∀ t1, t2 Terminal (t1) ∧ Terminal (t2) ∧ Connect (t1, t2) → Signal (t
1) = Signal (2).
• Signal at every terminal will have either value 0 or 1, it will be
represented as:
1. ∀ t Terminal (t) →Signal (t) = 1 ∨Signal (t) = 0.
• Connect predicates are commutative:
1. ∀ t1, t2 Connect(t1, t2) → Connect (t2, t1).
• Representation of types of gates:
1. ∀ g Gate(g) ∧ r = Type(g) → r = OR ∨r = AND ∨r = XOR ∨r = N
OT
190
• 5. Encode a description of the problem instance:
• Now we encode problem of circuit C1, firstly we
categorize the circuit and its gate components. This
step is easy if ontology about the problem is already
thought. This step involves the writing simple
atomics sentences of instances of concepts, which is
known as ontology.
• For the given circuit C1, we can encode the problem
instance in atomic sentences as below:
• Since in the circuit there are two XOR, two AND,
and one OR gate so atomic sentences for these gates
will be:
191
1.For XOR gate: Type(x1)= XOR, Type(X2) = X
OR
2.For AND gate: Type(A1) = AND, Type(A2)=
AND
3.For OR gate: Type (O1) = OR.
192
• 6. Pose queries to the inference procedure and get
answers:
• In this step, we will find all the possible set of values of all
the terminal for the adder circuit. The first query will be:
• What should be the combination of input which would
generate the first output of circuit C1, as 0 and a second
output to be 1?
1. ∃ i1, i2, i3 Signal (In(1, C1))=i1 ∧ Signal (In(2, C1))=i2
∧ Signal (In(3, C1))= i3
2. ∧ Signal (Out(1, C1)) =0 ∧ Signal (Out(2, C1))=1
193
• 7. Debug the knowledge base:
• Now we will debug the knowledge base, and this
is the last step of the complete process. In this
step, we will try to debug the issues of knowledge
base.
• In the knowledge base, we may have omitted
assertions like 1 ≠ 0.
194