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

Module 3 Notes_Part2

Module 3_Part 2 of BAD402 Artificial Intelligence covers informed search strategies, logical agents, and propositional logic, focusing on the Wumpus world. It discusses constructing a knowledge base, inference procedures, and various inference rules such as Modus Ponens and resolution, emphasizing their soundness and completeness. The module also explores concepts like logical equivalence, validity, and satisfiability, providing a framework for reasoning in artificial intelligence.

Uploaded by

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

Module 3 Notes_Part2

Module 3_Part 2 of BAD402 Artificial Intelligence covers informed search strategies, logical agents, and propositional logic, focusing on the Wumpus world. It discusses constructing a knowledge base, inference procedures, and various inference rules such as Modus Ponens and resolution, emphasizing their soundness and completeness. The module also explores concepts like logical equivalence, validity, and satisfiability, providing a framework for reasoning in artificial intelligence.

Uploaded by

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

BAD402 Artificial Intelligence Module 3_Part 2

• Syllabus: Informed Search Strategies: Heuristic functions, Greedy


best first search, A*search. Heuristic Functions

Logical Agents: Knowledge–based agents, The Wumpus world, Logic,


Propositional logic, Reasoning patterns in Propositional Logic.

• Text book 1: Chapter 4 – 4.1, 4.2 Chapter 7- 7.1, 7.2, 7.3, 7.4, 7.5

7.4.3: A simple knowledge base

• Now that we have defined the semantics for propositional logic, we can
construct a knowledge base for the wumpus world.

• We focus first on the immutable aspects of the wumpus world, leaving


the mutable aspects for a later section.

• For now, we need the following symbols for each [x, y] location:

• Px,y is true if there is a pit in [x, y].

• Wx,y is true if there is a wumpus in [x, y], dead or alive.

• Bx,y is true if the agent perceives a breeze in [x, y].

• Sx,y is true if the agent perceives a stench in [x, y].

• The sentences we write will suffice to derive ¬P1,2 (there is no pit in


[1,2]), as was done informally in Section 7.3. We label each sentence

• Ri so that we can refer to them:

• There is no pit in [1,1]:

• A square is breezy if and only if there is a pit in a neighboring square.


This has to be stated for each square; for now, we include just the
relevant squares:
BAD402 Artificial Intelligence Module 3_Part 2

• R2 : B1,1 ⇔ (P1,2 ∨ P2,1) .

• R3 : B2,1 ⇔ (P1,1 ∨ P2,2 ∨ P3,1) .

• The preceding sentences are true in all wumpus worlds. Now we


include the breeze percepts for the first two squares visited in the
specific world the agent is in, leading up to the situation in Figure
7.3(b).

• R4 : ¬B1,1 .

• R5 : B2,1 .

7.4.4 A simple inference procedure

• Our goal now is to decide whether KB |= α for some sentence α. For


example, is ¬P1,2 entailed by our KB?

• Our first algorithm for inference is a model-checking approach that is a


direct implementation of the definition of entailment: enumerate the
models, and check that α is true in every model in which KB is true.

• Models are assignments of true or false to every proposition symbol.


BAD402 Artificial Intelligence Module 3_Part 2

• Returning to our wumpus-world example, the relevant proposition


symbols are B1,1, B2,1, P1,1, P1,2, P2,1, P2,2, and P3,1.

• With seven symbols, there are = 128 possible models; in three of


these, KB is true (Figure 7.9).

• In those three models, ¬P1,2 is true, hence there is no pit in [1,2].

• On the other hand, P2,2 is true in two of the three models and false in
one, so we cannot yet tell whether there is a pit in [2,2].

• Figure 7.9 reproduces in a more precise form the reasoning illustrated in


Figure 7.5.

• A general algorithm for deciding entailment in propositional logic is


shown in Figure 7.10.

• The algorithm is sound because it implements directly the definition of


entailment, and complete because it works for any KB and α and
always terminates—there are only finitely many models to examine.

• Of course, ―finitely many‖ is not always the same as ―few.‖ If KB and α


contain n symbols in all, then there are 2^n models. Thus, the time
complexity of the algorithm is O( ).

• (The space complexity is only O(n) because the enumeration is depth-


first.)

• so every known inference algorithm for propositional logic has a worst-


case complexity that is exponential in the size of the input.
BAD402 Artificial Intelligence Module 3_Part 2
BAD402 Artificial Intelligence Module 3_Part 2

7.5 Propositional Theorem Proving

• In this section, we show how entailment can be done by theorem


proving—applying rules of inference directly to the sentences in our
knowledge base to construct a proof of the desired sentence without
consulting models.

• If the number of models is large but the length of the proof is short, then
theorem proving can be more efficient than model checking.

• Before we plunge into the details of theorem-proving algorithms, we will


need some additional concepts related to entailment.

• The first concept is logical equivalence: two sentences α and β are


logically equivalent if they are true in the same set of models.
BAD402 Artificial Intelligence Module 3_Part 2

• We write this as α ≡ β. For example, we can easily show (using truth


tables) that P ∧ Q and Q ∧ P are logically equivalent; other
equivalences are shown in Figure 7.11.

• These equivalences play much the same role in logic as arithmetic


identities do in ordinary mathematics.

• An alternative definition of equivalence is as follows: any two sentences


α and β are equivalent only if each of them entails the other:

• α ≡ β if and only if α |= β and β |= α .

• The second concept we will need is validity. A sentence is valid if it is


true in all models.

• For example, the sentence P ∨ ¬P is valid. Valid sentences are also


known as tautologies—they are necessarily true. Because the sentence
True is true in all models, every valid sentence is logically equivalent to
True.

• What good are valid sentences? From our definition of entailment, we


can derive the deduction theorem, which was known to the ancient
Greeks:

• For any sentences α and β, α |= β if and only if the sentence (α ⇒ β) is


valid.

• Hence, we can decide if α |= β by checking that (α ⇒ β) is true in


every model—which is essentially what the inference algorithm in
Figure 7.10 does—or by proving that (α ⇒ β) is equivalent to True.

• Conversely, the deduction theorem states that every valid implication


sentence describes a legitimate inference.
BAD402 Artificial Intelligence Module 3_Part 2

• The final concept we will need is satisfiability. A sentence is satisfiable


if it is true in, or satisfied by, some model.

• For example, the knowledge base given earlier, (R1 ∧ R2 ∧ R3 ∧ R4 ∧


R5), is satisfiable because there are three models in which it is true,
as shown in Figure 7.9.

• Satisfiability can be checked by enumerating the possible models until


one is found that satisfies the sentence.

• Validity and satisfiability are of course connected: α is valid iff ¬α is


unsatisfiable; contrapositively, α is satisfiable iff ¬α is not valid.

• We also have the following useful result: α |= β if and only if the


sentence (α ∧ ¬β) is unsatisfiable.

• Proving β from α by checking the unsatisfiability of (α ∧ ¬β) corresponds


exactly to the standard mathematical proof technique of reductio ad
absurdum (literally, ―reduction to an absurd thing‖).

• It is also called proof by refutation or proof by contradiction.

• One assumes a sentence β to be false and shows that this leads to a


contradiction with known axioms α.

• This contradiction is exactly what is meant by saying that the sentence

(α ∧ ¬β) is unsatisfiable.

7.5.1 Inference and proofs

• This section covers inference rules that can be applied to derive a proof—
a chain of conclusions that leads to the desired goal.

• The best-known rule is called Modus Ponens (Latin for mode that
affirms) and is written
BAD402 Artificial Intelligence Module 3_Part 2

• The notation means that, whenever any sentences of the form α ⇒ β and α
are given, then the sentence β can be inferred.

• For example, if (WumpusAhead ∧WumpusAlive) ⇒ Shoot and


(WumpusAhead ∧ WumpusAlive) are given, then Shoot can be
inferred.

• 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:

• 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.

• Another useful inference rule is And-Elimination, which says that,


from a conjunction, any of the conjuncts can be inferred:
BAD402 Artificial Intelligence Module 3_Part 2

• For example, from (WumpusAhead ∧ WumpusAlive), WumpusAlive can


be inferred.

• By considering the possible truth values of α and β, one can show easily
that Modus Ponens and And-Elimination are sound once and for all.

• These rules can then be used in any particular instances where they
apply, generating sound inferences without the need for enumerating
models.

• All of the logical equivalences in Figure 7.11 can be used as inference


rules. For example, the equivalence for biconditional elimination yields
the two inference rules

• Not all inference rules work in both directions like this.

• For example, we cannot run Modus Ponens in the opposite direction to


obtain α ⇒ β and α from β.

• Let us see how these inference rules and equivalences can be used in the
wumpus world. We start with the knowledge base containing R1 through
R5 and show how to prove ¬P1,2, that is, there is no pit in [1,2].

• First, we apply biconditional elimination to R2 to obtain

• R6 : (B1,1 ⇒ (P1,2 ∨ P2,1)) ∧ ((P1,2 ∨ P2,1) ⇒ B1,1) .

• Then we apply And-Elimination to R6 to obtain

• R7 : ((P1,2 ∨ P2,1) ⇒ B1,1) .

• Logical equivalence for contrapositives gives:


BAD402 Artificial Intelligence Module 3_Part 2

• R8 : (¬B1,1 ⇒ ¬(P1,2 ∨ P2,1)) .

• Now we can apply Modus Ponens with R8 and the percept R4 (i.e.,
¬B1,1), to obtain

• R9 : ¬(P1,2 ∨ P2,1) . Finally, we apply De Morgan’s rule, giving the


conclusion

• R10 : ¬P1,2 ∧ ¬P2,1 . That is, neither [1,2] nor [2,1] contains a pit.

• We found this proof by hand, but we can apply any of the search
algorithms in Chapter 3 to find a sequence of steps that constitutes a
proof.

• We just need to define a proof problem as follows:

• INITIAL STATE: the initial knowledge base.

• ACTIONS: the set of actions consists of all the inference rules applied to
all the sentences that match the top half of the inference rule.

• RESULT: the result of an action is to add the sentence in the bottom half
of the inference rule.

• GOAL: the goal is a state that contains the sentence we are trying to
prove.

• Thus, searching for proofs is an alternative to enumerating models.

• In many practical cases finding a proof can be more efficient because the
proof can ignore irrelevant propositions, no matter how many of them
there are.

• One final property of logical systems is monotonicity, which says that the
set of entailed sentences can only increase as information is added to the
knowledge base.
BAD402 Artificial Intelligence Module 3_Part 2

• For any sentences α and β,

• if KB |= α then KB ∧ β |= α .

• For example, suppose the knowledge base contains the additional


assertion β stating that there are exactly eight pits in the world.

• This knowledge might help the agent draw additional conclusions, but it
cannot invalidate any conclusion α already inferred—such as the
conclusion that there is no pit in [1,2].

7.5.2 Proof by resolution

• We have argued that the inference rules covered so far are sound, but we
have not discussed the question of completeness for the inference
algorithms that use them.

• Search algorithms such as iterative deepening search (page 89) are


complete in the sense that they will find any reachable goal, but if the
available inference rules are inadequate, then the goal is not
reachable—no proof exists that uses only those inference rules.

• For example, if we removed the biconditional elimination rule, the


proof in the preceding section would not go through.

• The current section introduces a single inference rule, resolution, that


yields a complete inference algorithm when coupled with any
complete search algorithm.

• We begin by using a simple version of the resolution rule in the wumpus


world.

• Let us consider the steps leading up to Figure 7.4(a): the agent returns
from [2,1] to [1,1] and then goes to [1,2], where it perceives a stench,
but no breeze. We add the following facts to the knowledge base:
BAD402 Artificial Intelligence Module 3_Part 2

• R11 : ¬B1,2 .

• R12 : B1,2 ⇔ (P1,1 ∨ P2,2 ∨ P1,3) .

• By the same process that led to R10 earlier, we can now derive the
absence of pits in [2,2] and [1,3] (remember that [1,1] is already
known to be pitless):

• R13 : ¬P2,2 .

• R14 : ¬P1,3 .

• We can also apply biconditional elimination to R3, followed by Modus


Ponens with R5, to obtain the fact that there is a pit in [1,1], [2,2], or
[3,1]:

• R15 : P1,1 ∨ P2,2 ∨ P3,1 .


BAD402 Artificial Intelligence Module 3_Part 2

• Now comes the first application of the resolution rule: the literal ¬P2,2 in
R13 resolves with the literal P2,2 in R15 to give the resolvent R16 :
P1,1 ∨ P3,1 .

• In English; if there’s a pit in one of [1,1], [2,2], and [3,1] and it’s not in
[2,2], then it’s in [1,1] or [3,1].

• Similarly, the literal ¬P1,1 in R1 resolves with the literal P1,1 in R16 to
give R17 : P3,1 .

• In English: if there’s a pit in [1,1] or [3,1] and it’s not in [1,1], then
it’s in [3,1].

• These last two inference steps are examples of the unit resolution
inference rule,

of the other).

Thus, the unit resolution rule takes a clause—a disjunction of


literals—and a literal and produces a new clause.

Note that a single literal can be viewed as a disjunction of UNIT


CLAUSE one literal, also known as a unit clause.

The unit resolution rule can be generalized to the full resolution rule,
BAD402 Artificial Intelligence Module 3_Part 2

• where li and mj are complementary literals. This says that resolution


takes two clauses and produces a new clause containing all the literals of
the two original clauses except the two complementary literals.

• For example, we have

• There is one more technical aspect of the resolution rule: the resulting
clause should contain only one copy of each literal.

• The removal of multiple copies of literals is called factoring.

• For example, if we resolve (A ∨ B) with (A ∨ ¬B), we obtain (A ∨ A),


which is reduced to just A.

Conjunctive normal form

• The resolution rule applies only to clauses (that is, disjunctions of


literals),

• so it would seem to be relevant only to knowledge bases and queries


consisting of clauses. How, then, can it lead to a complete inference
procedure for all of propositional logic?

• The answer is that every sentence of propositional logic is logically


equivalent to a conjunction of clauses.
BAD402 Artificial Intelligence Module 3_Part 2

• A sentence expressed as a conjunction of clauses is said to be in


conjunctive normal form or CNF (see Figure 7.14).

• We now describe a procedure for converting to CNF. We illustrate

• the procedure by converting the sentence B1,1 ⇔ (P1,2 ∨ P2,1) into


CNF. The steps are as follows:

• The original sentence is now in CNF, as a conjunction of three


clauses.

• It is much harder to read, but it can be used as input to a resolution


procedure.
BAD402 Artificial Intelligence Module 3_Part 2

A resolution algorithm

• Inference procedures based on resolution work by using the principle of


proof by contradiction introduced on page 250.

• That is, to show that KB |= α, we show that (KB ∧ ¬α) is unsatisfiable.


We do this by proving a contradiction.

• A resolution algorithm is shown in Figure 7.12. First, (KB ∧ ¬α) is


converted into CNF.

• Then, the resolution rule is applied to the resulting clauses.

• Each pair that contains complementary literals is resolved to produce


a new clause, which is added to the set if it is not already present.

• The process continues until one of two things happens:

• there are no new clauses that can be added, in which case KB does not
entail α; or,

• two clauses resolve to yield the empty clause, in which case KB


entails α.

• The empty clause—a disjunction of no disjuncts—is equivalent to


False because a disjunction is true only if at least one of its disjuncts is
true.

• Another way to see that an empty clause represents a contradiction is to


observe that it arises only from resolving two complementary unit
clauses such as P and ¬P.

• We can apply the resolution procedure to a very simple inference in the


wumpus world.
BAD402 Artificial Intelligence Module 3_Part 2

• When the agent is in [1,1], there is no breeze, so there can be no pits


in neighboring squares. The relevant knowledge base is
BAD402 Artificial Intelligence Module 3_Part 2

Completeness of resolution

• To conclude our discussion of resolution, we now show why PL-


RESOLUTION is complete.

• To do this, we introduce the resolution closure RC (S) of a set of


clauses S, which is the set of all clauses derivable by repeated
application of the resolution rule to clauses in S or their derivatives.

• The resolution closure is what PL-RESOLUTION computes as the


final value of the variable clauses.

• It is easy to see that RC (S) must be finite, because there are only finitely
many distinct clauses that can be constructed out of the symbols
P1,...,Pk that appear in S.

• (Notice that this would not be true without the factoring step that removes
multiple copies of literals.)

Hence, PL-RESOLUTION always terminates.

• The completeness theorem for resolution in propositional logic is


called the ground resolution theorem:

• If a set of clauses is unsatisfiable, then the resolution closure of those


clauses contains the empty clause.

• This theorem is proved by demonstrating its contrapositive: if the closure


RC(S) does not contain the empty clause, then S is satisfiable. In fact,
we can construct a model for S with suitable truth values for
P1,...,Pk.

• The construction procedure is as follows:


BAD402 Artificial Intelligence Module 3_Part 2

• For i from 1 to k, – If a clause in RC(S) contains the literal ¬Pi and all
its other literals are false under the assignment chosen for P1,...,Pi−1,
then assign false to Pi. – Otherwise, assign true to Pi.

• This assignment to P1,...,Pk is a model of S. To see this, assume the


opposite—that, at some stage i in the sequence, assigning symbol Pi
causes some clause C to become false.

• For this to happen, it must be the case that all the other literals in C
must already have been falsified by assignments to P1,...,Pi−1.

• Thus, C must now look like either (false ∨ false ∨ ··· false∨Pi) or like
(false∨false∨··· false∨¬Pi).

• If just one of these two is in RC(S), then the algorithm will assign the
appropriate truth value to Pi to make C true, so C can only be
falsified if both of these clauses are in RC(S).

• Now, since RC(S) is closed under resolution, it will contain the


resolvent of these two clauses, and that resolvent will have all of its
literals already falsified by the assignments to P1,...,Pi−1.

• This contradicts our assumption that the first falsified clause appears at
stage i.

• Hence, we have proved that the construction never falsifies a clause


in RC(S); that is, it produces a model of RC(S) and thus a model of S
itself (since S is contained in RC(S)).

7.5.3 Horn clauses and definite clauses

• Some real-world knowledge bases satisfy certain restrictions on the


form of sentences they contain, which enables them to use a more
restricted and efficient inference algorithm.
BAD402 Artificial Intelligence Module 3_Part 2

• One such restricted form is the definite clause, which is a disjunction


of literals of which exactly one is positive.

• For example, the clause (¬L1,1 ∨ ¬Breeze ∨ B1,1) is a definite clause,


whereas (¬B1,1 ∨ P1,2 ∨ P2,1) is not.

• Slightly more general is the Horn clause, which is a disjunction of


literals of which at most one is positive.

• So all definite clauses are Horn clauses, as are clauses with no positive
literals; these are called goal clauses.

• Horn clauses are closed under resolution: if you resolve two Horn
clauses, you get back a Horn clause.

• Knowledge bases containing only definite clauses are interesting for


three reasons:

• Every definite clause can be written as an implication whose premise is


a conjunction of positive literals and whose conclusion is a single
positive literal.

• (See Exercise 7.13.)

• For example, the definite clause (¬L1,1 ∨ ¬Breeze ∨ B1,1) can be


written as the implication (L1,1 ∧ Breeze) ⇒ B1,1.

• In the implication form, the sentence is easier to understand: it says that


if the agent is in [1,1] and there is a breeze, then [1,1] is breezy.

• In Horn form, the premise is called the body and the conclusion is called
the head.
BAD402 Artificial Intelligence Module 3_Part 2

• A sentence consisting of a single positive literal, such as L1,1, is called


a fact.

• It too can be written in implication form as True ⇒ L1,1, but it is


simpler to write just L1,1.

• Inference with Horn clauses can be done through the forward-chaining


and backward chaining algorithms, which we explain next.

• Both of these algorithms are natural, in that the inference steps are
obvious and easy for humans to follow.

• This type of inference is the basis for logic programming, which is


discussed in Chapter 9.3.

• Deciding entailment with Horn clauses can be done in time that is linear
in the size of the knowledge base—a pleasant surprise.
BAD402 Artificial Intelligence Module 3_Part 2

7.5.4 Forward and backward chaining

• The forward-chaining algorithm PL-FC-ENTAILS?(KB, q) determines


if a single proposition symbol q—the query—is entailed by a knowledge
base of definite clauses.

• It begins from known facts (positive literals) in the knowledge base.

• If all the premises of an implication are known, then its conclusion is


added to the set of known facts.

• For example, if L1,1 and Breeze are known and (L1,1 ∧ Breeze) ⇒
B1,1 is in the knowledge base, then B1,1 can be added.
BAD402 Artificial Intelligence Module 3_Part 2

• This process continues until the query q is added or until no further


inferences can be made.

• The detailed algorithm is shown in Figure 7.15; the main point to


remember is that it runs in linear time

• The best way to understand the algorithm is through an example and a


picture.

• Figure 7.16(a) shows a simple knowledge base of Horn clauses with A


and B as known facts.

• Figure 7.16(b) shows the same knowledge base drawn as an AND–


OR graph (see Chapter 4).

• In AND–OR graphs, multiple links joined by an arc indicate a


conjunction—every link must be proved—while multiple links without
an arc indicate a disjunction—any link can be proved.

• It is easy to see how forward chaining works in the graph. The known
leaves (here, A and B) are set, and inference propagates up the graph as
far as possible.

• Wherever a conjunction appears, the propagation waits until all the


conjuncts are known before proceeding.

• The reader is encouraged to work through the example in detail.


BAD402 Artificial Intelligence Module 3_Part 2

• It is easy to see that forward chaining is sound: every inference is


essentially an application of Modus Ponens.

• Forward chaining is also complete: every entailed atomic sentence


will be derived.

• The easiest way to see this is to consider the final state of the inferred
table (after the algorithm reaches a fixed point where no new inferences
are possible).

• The table contains true for each symbol inferred during the process, and
false for all other symbols.

• We can view the table as a logical model; moreover, every definite clause
in the original KB is true in this model.

• To see this, assume the opposite, namely that some clause

a1∧...∧ak ⇒ b is false in the model.


BAD402 Artificial Intelligence Module 3_Part 2

• Then a1 ∧ ... ∧ ak must be true in the model and b must be false in


the model.

• But this contradicts our assumption that the algorithm has reached a
fixed point! We can conclude, therefore, that the set of atomic
sentences inferred at the fixed point defines a model of the original
KB.

• Furthermore, any atomic sentence q that is entailed by the KB must be


true in all its models and in this model in particular. Hence, every entailed
atomic sentence q must be inferred by the algorithm.

• Forward chaining is an example of the general concept of data-driven


reasoning—that is, reasoning in which the focus of attention starts with
the known data.

• It can be used within an agent to derive conclusions from incoming


percepts, often without a specific query in mind.

• For example, the wumpus agent might TELL its percepts to the
knowledge base using an incremental forward-chaining algorithm in
which new facts can be added to the agenda to initiate new
inferences.

• In humans, a certain amount of data-driven reasoning occurs as new


information arrives.

• For example, if I am indoors and hear rain starting to fall, it might


occur to me that the picnic will be canceled.

• Yet it will probably not occur to me that the seventeenth petal on the
largest rose in my neighbor’s garden will get wet; humans keep forward
BAD402 Artificial Intelligence Module 3_Part 2

chaining under careful control, lest they be swamped with irrelevant


consequences.

• The backward-chaining algorithm, as its name suggests, works


backward from the query.

• If the query q is known to be true, then no work is needed. Otherwise,


the algorithm finds those implications in the knowledge base whose
conclusion is q.

• If all the premises of one of those implications can be proved true (by
backward chaining), then q is true.

• When applied to the query Q in Figure 7.16, it works back down the
graph until it reaches a set of known facts, A and B, that forms the basis
for a proof.

• The algorithm is essentially identical to the AND-OR-GRAPH-


SEARCH algorithm in Figure 4.11.

• As with forward chaining, an efficient implementation runs in linear


time.

• Backward chaining is a form of goal-directed reasoning.

• It is useful for answering specific questions such as ―What shall I do


now?‖ and ―Where are my keys?‖

• Often, the cost of backward chaining is much less than linear in the
size of the knowledge base, because the process touches only relevant
facts.

You might also like