Unit-3 (AI NOTES)
Unit-3 (AI NOTES)
KNOWLEDGE REPRESENTATION
First Order Predicate Logic (FOPL)
The syntax of FOL determines which collection of symbols is a logical expression in first-order logic. The
basic syntactic elements of first-order logic are symbols. We write statements in short-hand notation in
FOL.
Variables x, y, z, a, b,....
Connectives 𝖠, 𝗏, ¬, ⇒, ⇔
Equality ==
Quantifier ∀, ∃
Atomic sentences:
o Atomic sentences are the most basic sentences of first-order logic. These sentences are formed from
a predicate symbol followed by a parenthesis with a sequence of terms.
o We can represent atomic sentences as Predicate (term1, term2, ...... , term n).
Complex Sentences:
o Complex sentences are made by combining atomic sentences using connectives.
Consider the statement: "x is an integer.", it consists of two parts, the first part x is the subject of the
statement and second part "is an integer," is known as a predicate.
Integer(X)
Universal quantifier is a symbol of logical representation, which specifies that the statement within its range
is true for everything or every instance of a particular thing.
o For all x
o For each x
o 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:
Biscuit(marigold)
Biscuit(oreo)
Existential Quantifier:
Existential quantifiers are the type of quantifiers, which express that the statement within its scope is true
for at least one instance of something.
It is denoted by the logical operator ∃, which resembles as inverted E. When it is used with a predicate
variable then it is called as an existential quantifier.
If x is a variable, then existential quantifier will be ∃x or ∃(x). And it will be read as:
Example:
Points to remember:
o The main connective for universal quantifier ∀ is implication →.
o The main connective for existential quantifier ∃ is and 𝖠.
Properties of Quantifiers:
o In universal quantifier, ∀x∀y is similar to ∀y∀x.
o In Existential quantifier, ∃x∃y is similar to ∃y∃x.
o ∃x∀y is not similar to ∀y∃x.
Free Variable: A variable is said to be a free variable in a formula if it occurs outside the scope of the
quantifier.
Bound Variable: A variable is said to be a bound variable in a formula if it occurs within the scope of the
quantifier.
Negation Rule:
~∀x F(x)=∃(x)~F(x)
~∃(x)F(x) = ∀x ~F(x)
∀x ((E(x) ^ GE(i(x),1400))T(x))
∃(y) (E(y)S(y))
∀xy (E(x) ^ P(y)) ~GE(i(x), i(y))
∀x food(x)like(mary,x)
Food(rice) ^ food(banana)
∀x eat(sue,x)eat(ram,x)
Exercises:
Man (Marcus).
Pompeian (Marcus).
∀x Pompeian(X)Roman(X)
Ruler (Caesar)
It is now 1991.
Now=1991
Clausal Conversion
1. ~(course(x) ^ easy(x)) v like (ram, x)
~course(x) v ~easy(x) v like (ram, x) ------ (i)
2. ~(course(x) ^ engg (x)) v hard (x)
~course(x) v ~ engg (x) v hard (x) ----------- (ii)
3. ~(course(x) ^ art (x)) v easy(x)
~course(x) v ~art (x) v easy(x) -------------- (iii)
4. Course (AR04) (iv)
art (AR04) (v)
Skolemization: procedure for systematic elimination of the existential quantifiers in a first-order formula in
a prenex form, by introducing new constant and functional symbols, called Skolem constants and Skolem
functions, in the formula.
Step VI: Putting the resulting expression in conjunctive normal form (CNF):
For example, if the original expression is in the from P 𝗏 (Q 𝖠 R), then replace it by (P 𝗏 Q) 𝖠 (Q 𝖠 R).
In the present context, the resulting expression corresponding to expression (3) being in CNF, we need not
do any operation at this step.
Original Expression:
After writing one clause per line, the resulting expression become as follow:
The above statements can be represented in FOL using two qualities X and Y.
1. Biscuit (coconut-crunchy)
Unification
o Unification is a process of making two different logical atomic expressions identical by finding a
substitution. Unification depends on the substitution process.
o It takes two literals as input and makes them identical using substitution.
o Any substitution that makes two or more expressions equal is called a unifier for that expression.
o Given two expressions that are unifiable, such as expressions C1& C2 with a unifier β with C1β= C2,
we say β is the most general unifier (mgu) if any other unifier α is an instance of β.
For e.g., Two unifiers for literals P(u,b,v) and P(w,x,y) are: α = {u/w, b/x, v/y} and β = {s/u, s/w, b/x,
c/v, c/y}. Here α is the mgu and β is an instance of α.
Substitution {John/x} is a unifier for these atoms and applying this substitution, and both expressions will
be identical.
o The UNIFY algorithm is used for unification, which takes two atomic sentences and returns a unifier
for those sentences (If any exist).
o Unification is a key component of all first-order inference algorithms.
o It returns fail if the expressions do not match with each other.
o The substitution variables are called Most General Unifier or MGU.
E.g. Let's say there are two different expressions, P(x, y), and P(a, f(z)).
In this example, we need to make both above statements identical to each other. For this, we will perform
the substitution.
o Substitute x with a, and y with f(z) in the first expression, and it will be represented as a/x and f(z)/y.
o With both the substitutions, the first expression will be identical to the second expression and the
substitution set will be: [a/x, f(z)/y].
o Predicate symbol must be same, atoms or expression with different predicate symbol can never be
unified.
o Number of Arguments in both expressions must be identical.
o Unification will fail if variable occurs in terms.
x, f(x, a)
x, h(w)
Unification Algorithm:
Algorithm:
For each pair of the following atomic sentences find the most general unifier (If exist).
σ0 = ε
D0= {a,z}
={a/z, h(a,w)/x}
K=k+1 = 2
D3= NULL
Hence σ3 is mgu.
Topper(X)
Topper(john)
Other Examples:
σ0 = ε
D0= {a, z}
K=k+1 = 1
K=k+1 = 2
D2= {g(a), y}
K=k+1 = 3
Nancy/X
John/Z
Consider Sentences:
1. The members of St. bridge club are Joe, Sally, Bill and Ellen.
2. Joe is married to Sally.
3. Bill is Ellen‟s brother.
4. The spouse of every married person in club is also in club.
5. The last meeting of club was at Joe‟s House.
P Q
Q R
PR
∀X human(X)intelligent(X)
∀X intelligent(X) succeed(X)
X human(X) succeed(X)
∀X human(X)intelligent(X)
human(john) john/X
∀X human(john)intelligent(john)
Intelligent(john)
∀X dog(X)faithful(X)
∀X dog(X)has_tail(X)
Dog(tommy)
Tommy/X
dog(tommy)faithful(tommy)
dog(tommy)has_tail(tommy)
Dog(tommy)
New Facts:
Faithful(tommy)
Has_tail(tommy)
Tommy/X
~dog(tommy) dog(tommy)
[]
black(tommy)
Negate :
~black(tommy) ~dog(X) V faithful(X)
Tommy/X
~dog(tommy) V faithful(X) V ~black(tommy) dog(tommy)
If we have set of clauses C1, C2, C3, … Cn and we wish to prove or deduce clause D, ( D is logical
consequence of C1, C2, C3, … Cn) then first negate D and add ~D to set of clauses C1, C2, C3, … Cn.
Then using resolution together with factoring, we can show that the set is unsatisfiable by deducing a
contradiction. Such a proof is called a proof of refutation, which if successful, yields empty clause denoted
by [ ].
Given two clauses C1 and C2 with no variables in common. If there is a literal l1 in C1 which is a
complement of literal l2 in C2 then both l1 and l2 are deleted and a disjuncted C is formed from remaining
deduced clauses. The new clause C is called the resolvent of C1 and C2.
We write
~PVQ, ~QVR
~PVR
Several types of resolution are possible depending upon number and types of parents.
Binary Resolution:
Is ~P(b, a) V R(b)
Substitution mgu= {sue/x, joe/y, bill/z} is used results in unit clause ~mother (sue, bill).
Linear Resolution:
When each resolved clause Ci is parent to clause Ci+1 (i= 1,2, …, n-1)
e.g., C0 with some clause B0 to get C1 and then C1 with some clause B1 to get C2 and so on until Cn has been
derived.
C0 and B0
C1and B1
C2
If one of the parents in linear resolution is always from original set of clauses (Bi).
Let C0 = P V Q
Choosing B0 = ~P V Q from set S and resolving this with C0 we obtain resolvent Q = C1.
B1 must now be chosen from S and the resolvent of C1 and B1 becomes C2 and so on.
Let C0 = P V QB0 = ~P V Q
QVQ=Q
C1= Q B1 = P V ~Q
C2 = P B2 = ~P V ~ Q
C3 = ~Q
Consider sentences again:
Clausal Conversion
AR04/x
~art (AR04) v like (Ram, AR04) (v)
Peanuts/x
Peanuts/x
Bill/y
Killed(Bill) alive(x) killed(x)
Bill/x
alive(Bill) alive(Bill)
[]
likes(john, peanuts)
Food (peanuts)
5,7 bill/y
NIL
peanuts/x
eats (sue, peanuts)
Consider Sentences:
1. The members of St. bridge club are Joe, Sally, Bill and Ellen.
2. Joe is married to Sally.
3. Bill is Ellen‟s brother.
4. The spouse of every married person in club is also in club.
5. The last meeting of club was at Joe‟s House.
6. The spouse lives in same house.
Represent these facts in predicate logic. Construct the resolution proof to demonstrate the truth of
each of the statement given by facts listed above. Do so if possible. Otherwise add the facts you
need and then construct the proof.
1. Member (joe)
2. Member(sally)
3. Member(bill)
4. Member(ellen).
5. Married(joe, sally)
6. Brother(bill, ellen).
7. ~married (x, y) V ~ member(x) V member(y)
8. Meeting(last)
9. house(joe)
10. ~married (x, y) V ~house(x) V house(y)
To Prove:
Meeting (last) ^ house (sally)
sally/y
Joe/x
[]
~married (Ellen, y)
married (Ellen, y) ~married (x, y) V ~ member(x) V member(y)
Ellen/x
Member(y)
Y can be sally, bill or joe but joe is married to sally and bill is ellen‟s brother. Therefore, we reach
contradiction and hence ellen is not married.
P ^ Q ~R
~P V ~Q V ~R
P ^ R ~Q
~P V ~R V ~Q
Forward Chaining System and Backward Chaining System (Goal Driven approach)
Facts
P
Q
R
Rules
P ^ R S
P ^ ST
S
T
Data Driven Approach.
In Artificial intelligence, the purpose of the search is to find the path through a problem space. There are
two ways to pursue such a search that are forward and backward reasoning. The significant difference
between both of them is that forward reasoning starts with the initial data towards the goal. Conversely,
backward reasoning works in opposite fashion where the purpose is to determine the initial facts and
information with the help of the given results.
The same set of rules can be used for forward and backward reasoning, but it is useful to define two classes
of rules, each of which encodes a particular kind of knowledge:
1. Forward rules, encode knowledge about how to respond to certain input configurations.
2. Backward rules, encode knowledge about how to achieve particular goals.
We can separate these rules into two classes: Hence there are two kinds of rule systems:
In forward chaining system, we start with initial facts and keep using the rules to draw new conclusions. In
backward chaining system, we start with some hypothesis (or goal), we are trying to prove and keep looking
for the rules that would allow us to conclude that hypothesis.
Forward Chaining systems are data Driven while backward chaining systems are goal driven.
The facts in system are represented in working memory, which is continually updated. Rules in system
represent possible actions to take, sometimes also called condition action rules. The conditions are usually
patterns that must match items in working memory, which actions usually involve adding or deleting items
from working memory.
The interpreter controls the application of rules. It first checks to find all the rules whose condition matches
with the current state of memory then selects one and performs action in action part of the rule. The action
will result in new working memory and cycle begins again. This cycle will be repeated until either no rules
fire or some specified goal is satisfied.
The solution of a problem generally includes the initial data and facts in order to arrive at the solution.
These unknown facts and information is used to deduce the result. For example, while diagnosing a patient
the doctor first check the symptoms and medical condition of the body such as temperature, blood pressure,
pulse, eye colour, blood, etcetera. After that, the patient symptoms are analysed and compared against the
predetermined symptoms. Then the doctor is able to provide the medicines according to the symptoms of
the patient. So, when a solution employs this manner of reasoning, it is known as forward reasoning.
The inference engine explores the knowledge base with the provided information for constraints whose
precedence matches the given current state.
In the first step, the system is given one or more than one constraints.
Then the rules are searched in the knowledge base for each constraint. The rules that fulfil the
condition are selected(i.e., IF part).
Now each rule is able to produce new conditions from the conclusion of the invoked one. As a
result, THEN part is again included in the existing one.
The added conditions are processed again by repeating step 2. The process will end if there is
no new conditions exist.
The backward reasoning is inverse of forward reasoning in which goal is analysed in order to deduce the
rules, initial facts and data. We can understand the concept by the similar example given in the above
definition, where the doctor is trying to diagnose the patient with the help of the inceptive data such as
symptoms. However, in this case, the patient is experiencing a problem in his body, on the basis of which
the doctor is going to prove the symptoms. This kind of reasoning comes under backward reasoning.
In this type of reasoning, the system chooses a goal state and reasons in the backward direction. Now, let‟s
understand how does it happens and what steps are followed.
Firstly, the goal state and the rules are selected where the goal state reside in the THEN part as
the conclusion.
From the IF part of the selected rule the subgoals are made to be satisfied for the goal state to
be true.
Set initial conditions important to satisfy all the subgoals.
Verify whether the provided initial state matches with the established states. If it fulfils the
condition then the goal is the solution otherwise other goal state is selected.
Facts:
Month February
Year 1993
Prove:
Bad mood X?
X= alison
?-Lecturing X.
2. The process starts with new data and facts in the forward reasoning. Conversely, backward reasoning
begins with the results.
3. Forward reasoning aims to determine the result followed by some sequences. On the other hand,
backward reasoning emphasis on the acts that support the conclusion.
4. The forward reasoning is an opportunistic approach because it could produce different results. As
against, in backward reasoning, a specific goal can only have certain predetermined initial data which
makes it restricted.
5. The flow of the forward reasoning is from the antecedent to consequent while backward reasoning
works in reverse order in which it starts from conclusion to incipient.
Ontological Engineering
Ontology refers to organizing everything in the world into hierarch of categories.
Representing the abstract concepts such as Actions, Time, Physical Objects, and Beliefs is called
Ontological Engineering.
Ques: How categories are useful in Knowledge representation?
Taxonomy
Subclass relations organize categories into a taxonomy, or taxonomic hierarchy. Taxonomies have been
used explicitly for centuries in technical fields. For example, systematic biology aims to provide a
taxonomy of all living and extinct species; library science has developed a taxonomy of all fields of
knowledge, encoded as the Dewey Decimal system; and tax authorities and other government departments
have developed extensive taxonomies of
occupations and commercial products. Taxonomies are also an important aspect of general commonsense
knowledge.
First-order logic makes it easy to state facts about categories, either by relating objects to categories or by
quantifying over their members:
Ontology of Situation calculus.
Situations are logical terms consisting of the initial situation (usually called So) and all situations that are
generated by applying an action to a situation. The function Result(a, s) (sometimes called Do) names the
situation that results when action a is executed in situation s
Fluents are functions and predicates that vary from one situation to the next, such as the location of the
agent or the aliveness of the wumpus. The dictionary says a fluent is something that fllows, like a liquid. In
this use, it means flowing or changing across situations. By convention, the situation is always the last
argument of a fluent. For
example, lHoldzng(G1, So) says that the agent is not holding the gold GI in the initial situation So. Age(
Wumpus, So) refers to the wumpus's age in So.
Atemporal or eternal predicates and functions are also allowed. Examples include the predicate Gold (GI)
and the function LeftLeg Of ( Wumpus).
Time and event calculus
Situation calculus works well when there is a single agent performing instantaneous, discrete actions. When
actions have duration and can overlap with each other, situation calculus becomes somewhat awkward.
Therefore, we will cover those topics with an alternative for- EVENTCALCULUS malism known as event
calculus, which is based on points in time rather than on situations.
(The terms "event7' and "action" may be used interchangeably. Informally, "event" connotes a wider class
of actions, including ones with no explicit agent. These are easier to handle in event calculus than in
situation calculus.)
In event calculus, fluents hold at points in time rather than at situations, and the calculus is designed to
allow reasoning over intervals of time. The event calculus axiom says that a fluent is true at a point in time
if the fluent was initiated by an event at some time in the past and was not terminated by an intervening
event. The Initiates and Terminates relations play a role similar to the Result relation in situation calculus;
Initiates(e, f , t) means that the occurrence of event e at time t causes fluent f to become true, while
Terminates (w , f, t) means that f ceases to be true. We use Happens(e, t) to mean that event e happens at
time t,.
Semantic networks
Semantic networks are capable of representing individual objects, categories of objects, and relation among
objects. Objects or Ctegory names are represented in ovals and are connected by labeled arcs.
Semantic network example