chapter 7 logical agents 2

Upload: mahendra-bilagi

Post on 03-Jun-2018

233 views

Category:

Documents


0 download

TRANSCRIPT

  • 8/12/2019 Chapter 7 Logical Agents 2

    1/98

    Logical Agents 2Propositional Logic

    1

  • 8/12/2019 Chapter 7 Logical Agents 2

    2/98

    Outline: Propositional logic

    Syntax of propositional logic : defines the allowable sentences Semantics - the way in which the truth of sentences is

    determined

    Entailment-the relation between a sentence and anothersentence

    Algorithm for logical inference

    2

  • 8/12/2019 Chapter 7 Logical Agents 2

    3/98

    Propositional logic

    Propositional logic is the simplest logicillustrates basic ideas

    Definition: Aproposition is a statement that can be either true or

    false; it must be one or the other, and it cannot be both.

    The following are propositions:

    the reactor is on;

    the wing-flaps are up;

    The following are not:are you going out somewhere?

    2+3

    A good test for a proposition is to ask Is it true that. . . ?. If that makes sense, it is a proposition

    3

  • 8/12/2019 Chapter 7 Logical Agents 2

    4/98

    Propositional logic : Syntax

    Propositional logic consists of: The logical values trueand false(Tand F) Propositions: Sentences, which

    Either atomic(that is, they must be treated as indivisible units,with no internal structure), and

    Have a single logical value, either trueor false OrComplex sentences Operators, both unary and binary; when applied to logical values, yield

    logical values

    4

  • 8/12/2019 Chapter 7 Logical Agents 2

    5/98

    A BNF (Backus-Naur Form) grammar of sentences inpropositional logic

    The atomic sentencesconsist of a single proposition symbol

    that can be true or false. Symbols that start with an uppercase letter and may contain

    other letters or subscripts

    Ex: P, Q, R, W1,a

    Symbol -> P| Q | R| . . 5

  • 8/12/2019 Chapter 7 Logical Agents 2

    6/98

    A BNF (Backus-Naur Form) grammar of sentences inpropositional logic

    Complex sentences are constructed from simpler sentences,

    using parentheses and logical connectives

    6

  • 8/12/2019 Chapter 7 Logical Agents 2

    7/98

    Propositional logic: Syntax Five Logical connectives

    The proposition symbols S1, S2etc are sentences If S is a sentence, S is a sentence (negation)

    If S1and S2are sentences, S1S2is a sentence (conjunction)

    If S1and S2are sentences, S1S2is a sentence (disjunction)

    If S1and S2are sentences, S1S2is a sentence (implication) premise or antecedent is S1 and its conclusion or consequent is S2 Implications are also known as rules or if-then statements

    If S1and S2are sentences, S1S2is a sentence (biconditional) Biconditional means if and only if.

    7

  • 8/12/2019 Chapter 7 Logical Agents 2

    8/98

    Operator precedences from highest to lowest

    Operator precedences from highest to lowest:, ,, , ,are associative, but ,are not.

    8

  • 8/12/2019 Chapter 7 Logical Agents 2

    9/98

    Semantics

    The semanticsdefines the rules for determining the truth ofa sentence with respect to a particular model. In propositional logic, a model simply fixes the truth value-

    true or false-for every proposition symbol.

    Ex: if the sentences in the knowledge base make use of theproposition symbols P1,2, P2,2, and P3,1 Then one possible model is m1 = { P1,2 =false, P2,2 =false, P3,1 = true} With three proposition symbols, there are 23= 8 possible models

    Note: Models are purely mathematical objects with noconnection to wumpus worlds. P1,2 might mean "there is apit in [1 ,2]" or "I'm in AI class now"

    9

  • 8/12/2019 Chapter 7 Logical Agents 2

    10/98

    Semantics

    The semantics for propositional logic must specify how tocompute the truth value of any sentence, given a model

    How to compute the truth of atomic sentences

    a. True is true in every model and False is false in everymodel.

    b. The truth value of every proposition symbol must be

    specified directly in the model.

    Ex: In the model m1, P1,2 is false.

    10

  • 8/12/2019 Chapter 7 Logical Agents 2

    11/98

    Semantics

    How to compute the truth of complex sentences

    Five rules which hold for any sub sentences P and Q in anymodel m (here "iff" means "if and only if''):

    11

  • 8/12/2019 Chapter 7 Logical Agents 2

    12/98

    Propositional logic: Semantics

    Rules for evaluating truth with respect to a model m:

    1. P is true iff P is false in m

    2. P Q is true iff P is true and Q is true in m

    3. P Q is true iff P is true or Q is true in m

    4. PQ is true iff P is false or Q is true in mi.e., is false iff P is true and Qis false in m

    5. P Qis true iff PQ is true and QP is true in mi.e., iff P and Q are both true or both false in m.

    12

  • 8/12/2019 Chapter 7 Logical Agents 2

    13/98

    Propositional logic: Semantics

    Truth Tables

    The rules can also be expressed with truth tables that specifythe truth value of a complex sentence for each possibleassignment of truth values to its components.

    Truth tables for the five connectives are given.

    13

  • 8/12/2019 Chapter 7 Logical Agents 2

    14/98

    Truth tables for five logical connectives

    14

  • 8/12/2019 Chapter 7 Logical Agents 2

    15/98

    Propositional logic: Semantics

    Truth Tables

    From these tables, the truth value of any sentence s can becomputed with respect to any model m by a simple recursiveevaluation

    Simple recursive process evaluates an arbitrary sentence,Ex: The sentence P1,2(P2,2P3,1) in m1 is evaluated as

    P1,2(P2,2P3,1) = true (false true) = true true =

    true

    Here m1 = { P1,2 =false, P2,2 =false, P3,1 = true}

    15

  • 8/12/2019 Chapter 7 Logical Agents 2

    16/98

    TT for Implication

    The truth table "P implies Q or "if P then Q"

    is material implication: the antecedent does not have to be inany way relevant or a cause for the consequent

    Ex1: The sentence "5 is odd implies Tokyo is the capital of Japan is atrue sentence of propositional logic even though it is a odd sentenceof English.

    Any implication is true whenever its antecedent is false. Ex2: "5 is even implies Sam is smart" is true regardless of whether

    Sam is smart.

    So, we should treat as "If P is true, then I am claiming that Q istrue. Otherwise I am making no claim."

    The only way for this sentence to be false is if P is true but Q is false.

    16

  • 8/12/2019 Chapter 7 Logical Agents 2

    17/98

    TT for Biconditional The truth table for "P if and only if Q"

    The biconditional, P Q, is true whenever both P Q and Q P aretrue. Many of the rules of the wumpus world are best written using Ex: a square is breezy if a neighboring square has a pit, and a square is

    breezy only if a neighboring square has a pit.

    Implication: The one-way implication B1,1(P1,2 v P2,1) is true in thewumpus world, but incomplete.

    It does not rule out models in which B1,1 is false and P1,2 is true, whichwould violate the rules of the wumpus world.

    Biconditional: B1,1 (P1,2 v P2,1) where B1,1 means that there is abreeze in [1 ,1].

    Implication vs. Biconditional: implication requires the presence of pits ifthere is a breeze, whereas the biconditional also requires the absence ofpits if there is no breeze.

    So we need a biconditional here

    17

  • 8/12/2019 Chapter 7 Logical Agents 2

    18/98

    Knowledge base

    It is known that a knowledge base consists of a set ofsentences.

    We can now see that a knowledge base is a conjunction of

    those sentences. That is, if we start with an empty KB and do TELL(KB; S1) . . . TELL(KB; Sn) then we have KB = S1 ^ . . . ^ Sn.

    This means that we can treat knowledge bases and

    sentences interchangeably.

    18

  • 8/12/2019 Chapter 7 Logical Agents 2

    19/98

    Constructing a knowledge

    base for the wumpus world

    19

  • 8/12/2019 Chapter 7 Logical Agents 2

    20/98

    Constructing a knowledgebase for the wumpus world

    we will deal only with pits (the wumpus itself is left as anexercise)

    Steps:

    1. First, choose the vocabulary of proposition symbolsconstruct a knowledge base

    2. Provide enough knowledge in step 1 so that inference canbe carried out - provide an inference procedure

    20

  • 8/12/2019 Chapter 7 Logical Agents 2

    21/98

    1. A simple Knowledge base

    Assumptions: We focus first on the immutable aspects of the wumpus

    world (the mutable aspects dealt later)

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

    Observations:breeze in [2,1] and nothing in [1,1]Rules:perceive breeze in squares directly adjacent to a pit Problem: Find relevant KB after starting in [1,1] and moving

    to [2,1].

    21

  • 8/12/2019 Chapter 7 Logical Agents 2

    22/98

    A simple Knowledge base

    DeriveP1,2: there is no pit in [ 1 ,2] (note: derive the same way as done informally using logic before)

    Label each sentence Ri so that we can refer to them:1. There is no pit in [1,1]: R1 : P1,1

    2. 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:

    R2 : B1,1 (P1,2P2,1)

    R3: B2,1 (P1,1P2,2P3,1)

    The preceding sentences are true in all wumpus worlds.3. Now include the breeze percepts for the first two squares visited in thespecific world the agent is in

    R4 : B1,1

    R5 : B2,1

    22

  • 8/12/2019 Chapter 7 Logical Agents 2

    23/98

    A simple Knowledge base

    The knowledge base, then, consists of sentences R1 throughR5.

    It can also be considered as a single sentence the conjunction R1 ^ R2 ^ R3 ^ R4 ^ R5

    because it asserts that all the individual sentences are true.

    23

  • 8/12/2019 Chapter 7 Logical Agents 2

    24/98

    2. A simple Inference Procedure

    Recall that the aim of logical inference is to decide whetherKB for some sentence

    Ex: Is P2,2 entailed? Our first algorithm for inference will be a direct

    implementation of the definition of entailment: enumerate the models, and check that is true in every model in

    which KB is true.

    For propositional logic, models are assignments of true or false toevery proposition symbol.

    24

  • 8/12/2019 Chapter 7 Logical Agents 2

    25/98

    2. A simple Inference Procedure

    Ex: Is P2,2 entailed? 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 27=128 possible models;

    in three of these, KB is true 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 pitin [2,2].

    25

  • 8/12/2019 Chapter 7 Logical Agents 2

    26/98

    Truth tables for inference - KB

    Here KB |= B2,1 26

  • 8/12/2019 Chapter 7 Logical Agents 2

    27/98

    Truth tables for inference KB and

    27

  • 8/12/2019 Chapter 7 Logical Agents 2

    28/98

    Algorithm for Entailment

    TT-ENTAILS? (KB, ,) RETURNS TRUE OR FALSE PL-TRUE?(KB, model) : returns true if a sentence holds

    within a model.

    The variable model represents a partial model- anassignment to some of the symbols. The keyword "and" is used here as a logical operation on its

    two arguments, returning true or false

    28

  • 8/12/2019 Chapter 7 Logical Agents 2

    29/98

    Algorithm for Entailment

    TT-CHECK-ALL(KB, , symbols, model) So TT-CHECK-ALL checks that for eachmodel (each possible

    assignment of 'true' or 'false' to the different symbols) thatis consistent with the KB, the query evaluates to true:

    For each model: PL-TRUE?(KB, model) -> PL-TRUE?(query,model) when passing the KB we would not pass R1 and R2 and ... R5 but symbols such as (not P_1,1) and (B1,1 (P1,2 or P2,1)) and ... and

    (B2,1). Essentially enumerates at truth table checking that when KB

    is true ais true

    29

  • 8/12/2019 Chapter 7 Logical Agents 2

    30/98

    Algorithm for Entailment

    TT-CHECK-ALL(KB, a, symbols, []) returns true

    if KB is false in model or if KB is true and ais true in the model. Recall checking that KB entails a, when KB is false acan be true or false, only

    must be true when KB is true.

    PL-TRUE?(KB, model) returns true if KB is true in the model PL-TRUE?(a, model) returns true if ais true in the model

    30

  • 8/12/2019 Chapter 7 Logical Agents 2

    31/98

    Inference by enumeration

    a recursive enumeration of a finite space of assignment to symbols enumeration of a finite space of assignments to symbols enumeration of a finite space of assignments to symbols

    31

  • 8/12/2019 Chapter 7 Logical Agents 2

    32/98

    Algorithm Trace

    The first part of TT-CHECK-ALL: Executed when all the symbols have been given a value in

    the model

    checks whether the given model, e.g. [P=true, Q=false], is

    consistent with the knowledge base (PL-TRUE?(KB, model)). These models correspond to the lines in the truth table,

    which have a true in the KB column.

    For those, the algorithm then checks whether the query

    evaluates to true (PL-TRUE?(query, model)). All other models, that are inconsistent with the KB in the

    first place, are not considered

    returning true, is the neutral element of conjugation.

    32

  • 8/12/2019 Chapter 7 Logical Agents 2

    33/98

    Algorithm Trace

    Else part of TT-CHECK-ALL: recursively constructs a hugeconjunction for all the possible

    assignments for the symbols occurring in the knowledgebase and the query

    Ex: TT-CHECK-ALL(KB, a, [P, Q], []) will evaluate to TT-CHECK-ALL(KB, a, [], [P=true, Q=true]) and TT-CHECK-ALL(KB, a, [], [P=true, Q=false]) and

    TT-CHECK-ALL(KB, a, [], [P=false, Q=true]) and TT-CHECK-ALL(KB, a, [], [P=false, Q=false])

    33

  • 8/12/2019 Chapter 7 Logical Agents 2

    34/98

    Evaluation of Algorithm

    time complexity space complexity Soundness

    Completeness

    34

  • 8/12/2019 Chapter 7 Logical Agents 2

    35/98

    Inference by enumerationEvaluation ofAlgorithm

    For nsymbols, time complexity is O(2n), space complexity is O(n)

    35

  • 8/12/2019 Chapter 7 Logical Agents 2

    36/98

    Evaluation of Algorithm

    Soundness The algorithm is sound because it implements directly the definition

    of entailment

    Completeness

    complete because it works for any KB and query and alwaysterminates- there are only finitely many models to examine. If KB and a contain n symbols in all, then there are 2nmodels. Time complexity of the algorithm is O(2n). Space complexity is only O(n) because of depth first enumeration Note: propositional entailment is co-NP-complete (i.e., probably no

    easier than NP-complete)

    Every known inference algorithm for propositional logic has a worst-case complexity that is exponential in the size of the input.

    36

  • 8/12/2019 Chapter 7 Logical Agents 2

    37/98

    Summary so far:

    Logical agents apply inference to a knowledge base toderive new information and make decisions

    Basic concepts of logic: syntax: formal structure of sentences

    semantics: truth of sentences wrt models entailment: necessary truth of one sentence given another inference: deriving sentences from other sentences soundness: derivations produce only entailed sentences

    completeness: derivations can produce all entailedsentences

    37

  • 8/12/2019 Chapter 7 Logical Agents 2

    38/98

    Truth Tables for inference

    1. Recall that KB |= a if and only if M(KB) M(a). We illustrated this graphicallyfor the Wumpus World in Logic in

    General.

    2. we can determine if M(KB) M() using truth tables. write out every possible combination of truth values for the

    atomic propositions. Enumerate all the models.

    If KB is true in row, check that a is also true.

    If this is the case, then M(KB) M(a) and so KB |= a

    38

  • 8/12/2019 Chapter 7 Logical Agents 2

    39/98

    Proposition Logic Sentences

    39

  • 8/12/2019 Chapter 7 Logical Agents 2

    40/98

    Propositional Theorem

    Proving

    40

  • 8/12/2019 Chapter 7 Logical Agents 2

    41/98

    Inference by Theorem Proving

    entailment by model checking So far, we have shown how to determine entailment bymodel checking:

    enumerating models

    and showing that the sentence must hold in all models. entailment by theorem proving applying rules of inference directly to the sentences in our

    knowledge base

    to construct a proof of the desired sentence withoutconsulting models. If the number of models is large but the length of the proof

    is short, then theorem proving can be more efficient thanmodel checking.

    41

  • 8/12/2019 Chapter 7 Logical Agents 2

    42/98

    Inference by Theorem Proving

    Given: A set of sentences in the KB: the premises A sentence to be proved: the conclusion

    A set of sound rulesApply a rule to an appropriate sentenceAdd the resulting sentence to the KB

    Stop if we have added the conclusion to the KB

    Essentially a search problem Better than model-based many models, short proofs

    42

  • 8/12/2019 Chapter 7 Logical Agents 2

    43/98

    Inference by Theorem Proving

    Rather than enumerate all possible models, we can apply inferencerules to the current sentences in the KB to derive new sentences

    A proof consists of a chain of rules beginning with known sentences(premises) and ending with the sentence we want to prove

    (conclusion)

    43

  • 8/12/2019 Chapter 7 Logical Agents 2

    44/98

    Additional Concepts- properties oflogical systems

    1. Logical Equivalence

    2. Validity

    Deduction theorem

    3. Satisfiability

    44

  • 8/12/2019 Chapter 7 Logical Agents 2

    45/98

    1. Logical Equivalence

    two sentences and are logically equivalent if they aretrue in the same set of models. We write this as Ex: we can easily show (using truth tables) that P ^ Q and Q

    ^ P are logically equivalent; Equivalences play the same role in logic as arithmeticidentities do in ordinary mathematics.

    An alternative definition of equivalence

    any two sentences and are equivalent only if each ofthem entails the other: iff and

    45

  • 8/12/2019 Chapter 7 Logical Agents 2

    46/98

    Logical equivalence

    Two sentences are logically equivalentiff true in same

    models: iff and

    Note: The contrapositiveof the statement has its antecedent and consequent inverted and

    flipped which is is ( ) . The inverse is ( ) . The converseof is

    46

  • 8/12/2019 Chapter 7 Logical Agents 2

    47/98

    2. Validity

    A sentence is valid if it is true in all models.

    Ex1: the sentence P VP is valid. Ex2: True Ex3: AA Ex4: (A (AB))B

    Valid sentences are also known as tautologiesthey are

    necessarily true.

    Because the sentence True is true in all models, every validsentence is logically equivalent to True.

    Ex: Logical Equivalences are universal tautologies they willalways be true in all possible models.

    Note: the above sentences are true solely because of theirown logical form, regardless of how the world(s) happen to be

    47

  • 8/12/2019 Chapter 7 Logical Agents 2

    48/98

    Validity

    Validity is connected to inference via the Deduction Theorem:

    For any sentences KBand , KB if and only if thesentence (KB) is valid

    Hence, we can decide if KB

    by checking that (KB) is

    true in every model

    Conversely, the deduction theorem states that every validimplication sentence describes a legitimate inference

    Note: Recall inference algorithm TT-ENTAILS? (KB, ,) whichessentially does the same or by proving that (KB) isequivalent to True

    48

  • 8/12/2019 Chapter 7 Logical Agents 2

    49/98

    3. Satisfiability

    A sentence is satisfiableif it is true in, or satisfied by, somemodel.

    Ex1: KB = R1 ^ R2 ^ R3 ^ R4 ^ R5 is satisfiable because there arethree models in which it is true

    Ex2: AB

    Satisfiability can be checked by enumerating the possiblemodels until one is found that satisfies the sentence. The problem of determining the satisfiability of sentences in

    propositional logic is known as the SAT problem

    SAT problem is the first problem proved to be NP-complete.

    Many problems in computer science are really satisfiability problems A sentence is unsatisfiableif it is true in nomodels

    Ex: AA

    Note: SAT as a search problem, try to assign true or false to the symbol s in in such away that becomes true.

    49

  • 8/12/2019 Chapter 7 Logical Agents 2

    50/98

    Validity and satisfiability

    Validity and satisfiability are connected: is valid iff is unsatisfiable; contrapositively, is satisfiable iff is not valid.

    Satisfiability is connected to inference via the following:KB if and only if (KB) is unsatisfiable

    Proving from KB by checking the unsatisfiability of (KB) corresponds exactly to the standard mathematicalproof technique of proof by refutation or proof bycontradiction. Assume a sentence to be false and shows that this leads to a

    contradiction with known axioms KB. This contradiction is exactly what is meant by saying that the

    sentence (KB) is unsatisfiable

    50

  • 8/12/2019 Chapter 7 Logical Agents 2

    51/98

    7.5.1Inference and proofs

    51

  • 8/12/2019 Chapter 7 Logical Agents 2

    52/98

    Inference

    One can use equivalance to convert one formula to another.

    Equivalance is not strong enough to be able to prove (some)new statements.

    Inference rules can generate new statements

    52

  • 8/12/2019 Chapter 7 Logical Agents 2

    53/98

    Syntax of Inference Rules

    Premises above the line list all that must hold before thisrule can be applied.

    Conclusion below the line gives what can then be inferred. An inference rule can be read: if I have already inferred these premises, then I can infer

    this conclusion too. or

    If premises are proved then conclusion is proved

    53

  • 8/12/2019 Chapter 7 Logical Agents 2

    54/98

    Inference rules

    inference rules can be applied to derive a proof-a chain ofconclusions that leads to the desired goal.

    1. The best-known rule is called Modus Ponens (Latin formode that affirms) (Implication Elimination)

    The notation means that, whenever any sentences of theform AB and A are given, then the sentence B can be

    inferred. Ex: If I know If the Jets won, they qualified for the playoffs,

    and I learn The Jets won, then I can conclude The Jetsqualified for the playoffs

    54

  • 8/12/2019 Chapter 7 Logical Agents 2

    55/98

    Inference rules

    2. Another useful inference rule is And-Elimination, whichsays that, from a conjunction, any of the conjuncts can beinferred

    Ex: If we are told The Jets won and the Giants won, thenwe know The Jets won and we know The Giants won.

    Note: By considering the possible truth values of and , itis possible to show that Modus Ponens and And-Eliminationare sound

    These rules can then be used generating sound inferenceswithout the need for enumerating models

    55

  • 8/12/2019 Chapter 7 Logical Agents 2

    56/98

    Inference rules

    3. All of the logical equivalences can be used as inferencerules.

    Ex: the equivalence for biconditional elimination yields thetwo inference rules

    56

  • 8/12/2019 Chapter 7 Logical Agents 2

    57/98

  • 8/12/2019 Chapter 7 Logical Agents 2

    58/98

    Inference rules - Problem

    Starting with the knowledge base containing R1 through R5 show how to

    prove

    P(1,2) : there is no pit in [1,2] using the technique of inferencerules

    What are R1. . . R5? Choose the Background Sentence R2: B1,1 P1,2 P2,1

    58

  • 8/12/2019 Chapter 7 Logical Agents 2

    59/98

    A simple Knowledge base

    DeriveP1,2: there is no pit in [ 1 ,2] (note: derive the same way as done informally using logic before)

    Label each sentence Ri so that we can refer to them:1. There is no pit in [1,1]: R1 : P1,12. 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:

    R2 : B1,1 (P1,2P2,1)

    R3: B2,1 (P1,1P2,2P3,1)

    The preceding sentences are true in all wumpus worlds.3. Now include the breeze percepts for the first two squares visited in thespecific world the agent is in

    R4 : B1,1

    R5 : B2,1

    59

    I f l P bl

  • 8/12/2019 Chapter 7 Logical Agents 2

    60/98

    Inference rules - Problem

    Starting with the knowledge base containing R1 through R5 show how toproveP(1,2) : there is no pit in [1,2] using the technique of inferencerules

    Background Sentence R2: B1,1 P1,2 P2,1 -elimination to R2 R6: (B1,1 P1,2 P2,1) (P1,2 P2,1 B1,1)

    -elimination to R6 R7: P1,2 P2,1B1,1 Apply logical equivalence for contraposition to R7 R8:B1,1(P1,2 P2,1)

    Apply Modus Ponens rule to R8 and the percept R4:

    B1,1 R9:(P1,2 P2,1) Apply de Morgan rule to R9 R10:P1,2 P2,1So, [1,2] and [2,1] have no pits

    60

  • 8/12/2019 Chapter 7 Logical Agents 2

    61/98

    Inference rules - Problem

    Proof by Hand: Starting with the knowledge base containing R1 through R5

    we have shown how to prove P(1,2) : there is no pit in[1,2]

    Instead of proof by hand method, any of the searchalgorithms (Chapter 3) can be applied to find a sequence ofsteps that constitutes a proof.

    Defining a proof problem ?

    61

  • 8/12/2019 Chapter 7 Logical Agents 2

    62/98

    Proofs

    Proof:a sequence of application of inference rules. Finding a proof is a search problem.

    Initial state ?

    Goal Statement ? Result ( or Successor Function) ? Actions?

    62

  • 8/12/2019 Chapter 7 Logical Agents 2

    63/98

    Inference rules - Problem

    Defining a proof problem INITIAL STATE: the initial knowledge base.

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

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

    GOAL: the goal is a state that contains the sentence we aretrying to prove.

    63

  • 8/12/2019 Chapter 7 Logical Agents 2

    64/98

    Inference rules

    Proof vs. Enumerating models: finding a proof can be more efficient because the proof can ignore

    irrelevant propositions Ex: the proof leading to P1,2 ^ P2,1

    does not mention the propositions B2,1 . P1,1, P2,2, or P3,1 They can be ignored because the goal proposition, P1,2, appears only

    in sentence R2;

    the other propositions in R2 appear only in R4 and R2; so R1, R3, and R5 have no bearing on the proof.

    The same would hold even if a million more sentences are there inthe knowledge base;

    truth-table algorithm exponential explosion of models

    64

  • 8/12/2019 Chapter 7 Logical Agents 2

    65/98

    7.5.2 Proof by resolution

    65

  • 8/12/2019 Chapter 7 Logical Agents 2

    66/98

    Proof by resolution

    Inference rulesshown to be sound

    What about completeness for the inference algorithms thatuse them?

    completeness for Search algorithms

    Search algorithms are complete if they will find anyreachable goal completeness for the inference algorithms if the available inference rules are inadequate, then the goal

    is not reachable

    Ex: if the biconditional elimination rule is removed then theprevious proof fails

    66

  • 8/12/2019 Chapter 7 Logical Agents 2

    67/98

    Proof by resolution Resolution: definition

    a single inference rule, that yields a complete inferencealgorithm when coupled with any complete searchalgorithm.

    Observation: the agent returns from [2, 1] to [1, 1 ] and thengoes to [1 ,2], where it perceives a stench, but no breeze.

    We add the following facts to the knowledge base. R11:B1,2 R12 : B1,2 (P1,1 v P2,2 v P1,3)

    Problem:From R12, derive that there is no pit at [1,3], [2,2] Solution: By the same process that led to R10, we can derive

    that there is no pit at [1,3], [2,2] from R12. (we alreadyadded [1,1] is pitless by R1)

    R13 : P2, 2 R14 : P1, 3 , R1: P1,167

  • 8/12/2019 Chapter 7 Logical Agents 2

    68/98

  • 8/12/2019 Chapter 7 Logical Agents 2

    69/98

  • 8/12/2019 Chapter 7 Logical Agents 2

    70/98

    The general Idea of Resolution- Example

    70

    Modus ponens with R5: B2,1

    Resolution with R1: P1,1

    Resolution with R13: P2,2

    So, there is pit at [3,1]

    Background Sentence R3: B2,1 P1,1 P2,2v P3,1-elimination to R3

    (B2,1 P1,1 P2,2v P3,1) ^ (P1,1 P2,2 V P3,1 B2,1)

    -elimination

    B2,1 P1,1 P2,2v P3,1

  • 8/12/2019 Chapter 7 Logical Agents 2

    71/98

    The general Idea of Resolution

    71

    Using a proof system P with many rules is fine for humans.

    For a computer, the less rules P has the simpler the

    corresponding search algorithm gets.

    Just one rule called resolution turns out to be enough

    if we

    1. first rewrite our KB into a certain fixed form

    2. then seek refutation proofs

  • 8/12/2019 Chapter 7 Logical Agents 2

    72/98

    The general Idea of Resolution

    if the same disjunct occurrs both positively (= outside ) in one disjunction and negatively (= inside ) in another disjunction

    then we can combine these two disjunctions into oneresolvent and drop their common .

    72

  • 8/12/2019 Chapter 7 Logical Agents 2

    73/98

    The general Idea of Resolution

    In both of these two resolution steps, the common disjunctis just a single Symbol . We are going to rewrite our KB so that this will always be the case. The reason is that an unmodified KB would not contain very many

    possible choices for .

    The form into which we are going to rewrite our KB can bedefined as follows: Literal is Symbol orSymbol . Clause is a (possibly empty) disjunction of literals.

    Then KB is in Conjunctive Normal Form (CNF) if it is aconjunction of clauses.

    73

  • 8/12/2019 Chapter 7 Logical Agents 2

    74/98

    The general rule of Resolution

    The full resolution rule takes the form you can form the resolvent of two clauses if the same

    Symbol X occurrs positively in one of them and negatively inthe other

    By the associativity and commutativity of this commonsymbol X can appear anywhere inside these two clauses.

    74

  • 8/12/2019 Chapter 7 Logical Agents 2

    75/98

    Conjunctive normal form

    75

    CNF

  • 8/12/2019 Chapter 7 Logical Agents 2

    76/98

    CNF

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

    So it is relevant to knowledge bases and queries consisting ofclauses.

    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.

    A sentence expressed as a conjunction of clauses is said to

    be in conjunctive normal form or CNF

    76

    Conversion to CNF for R2: B1 1 (P1 2 v P2 1)

  • 8/12/2019 Chapter 7 Logical Agents 2

    77/98

    Conversion to CNF for R2: B1,1 (P1,2 v P2,1)

    A given formula can be converted into CNF with thefollowing 4 steps:

    1. Replace each occurrence of with the correspondingtwo occurrences of

    (B1,1P1,2 P2,1) (P1,2 P2,1B1,1)

    2. Replace each occurrence of with the equivalent

    (B1,1P1,2 P2,1) ((P1,2 P2,1)B1,1)

    3. Move each towards the Symbol

    (B1,1 P1,2 P2,1) ((P1,2P2,1) B1,1)

    77

    Conversion to CNF for R2: B1 1 (P1 2 v P2 1)

  • 8/12/2019 Chapter 7 Logical Agents 2

    78/98

    Conversion to CNF for R2: B1,1 (P1,2 v P2,1)

    4. Finally move each from under any by using their

    distibutivity, which permits replacing ( ) with ( ) ( )

    (B1,1 P1,2 P2,1) (P1,2B1,1) (P2,1B1,1)

    If we now undo step 2, then we see that above sentencedoes indeed say the same thing as the original sentence butin a different way:

    (B1,1P1,2 P2,1) (P1,2B1,1) (P2,1B1,1).

    Now CNF form is used as input to a resolution procedure

    78

    C i t CNF S

  • 8/12/2019 Chapter 7 Logical Agents 2

    79/98

    Conversion to CNF Summary

    B1,1(P1,2P2,1)

    1. Eliminate , replacing with ( )().

    (B1,1(P1,2P2,1)) ((P1,2P2,1) B1,1)

    2. Eliminate , replacing with .

    (B1,1P1,2P2,1) ((P1,2P2,1) B1,1)

    3. Move inwards using de Morgan's rules and double-negation:

    (B1,1P1,2P2,1) ((P1,2P2,1) B1,1)

    4. Apply distributivity law (over ) and flatten:

    (B1,1P1,2P2,1) (P1,2B1,1) (P2,1B1,1)

    79

  • 8/12/2019 Chapter 7 Logical Agents 2

    80/98

    Resolution Rule Summary

    Conjunctive Normal Form(CNF) : conjunctionof disjunctionsof literalsclauses

    E.g., (A B) (B C D)

    Resolutioninference rule (for CNF):

    li lk, m1 mn

    li li-1li+1 lkm1 mj-1mj+1... mn

    where liand mjare complementary literals.

    E.g., P1,3P2,2, P2,2

    P1,3

    Resolution is sound and complete for propositional logic

    80

    A grammar for CNF Horn clauses and

  • 8/12/2019 Chapter 7 Logical Agents 2

    81/98

    A grammar for CNF, Horn clauses anddefinite clauses

    81

  • 8/12/2019 Chapter 7 Logical Agents 2

    82/98

    A resolution algorithm

    82

    A resolution algorithm

  • 8/12/2019 Chapter 7 Logical Agents 2

    83/98

    A resolution algorithm

    Inference procedures based on resolution work by using theprinciple of proof by contradiction That is, to show that KB , we show that KB is

    unsatisfiable

    We do this by proving a contradiction.

    83

  • 8/12/2019 Chapter 7 Logical Agents 2

    84/98

    Resolution algorithm

    Proof by contradiction, i.e., show KB unsatisfiable

    84

    Resolution algorithm Trace for Example

  • 8/12/2019 Chapter 7 Logical Agents 2

    85/98

    Resolution algorithmTrace for Example

    KB = R2 ^ R4 R2= (B1,1(P1,2P2,1)) R4 = B1,1

    =P1,2 Method: we can derive using Proof by contradiction, i.e.,

    show KB unsatisfiable

    Steps:

    1. Convert KB into CNF form 2. Take 2 clauses at a time and resolve as per Resolution

    algorithm

    85

    R l ti l ith T f E l

  • 8/12/2019 Chapter 7 Logical Agents 2

    86/98

    Resolution algorithmTrace for Example

    Then, the resolution rule is applied to the resulting clauses.Each pair that contains complementary literals is resolved toproduce 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 doesnot entail or, two clauses resolve to yield the empty clause, in which case KB

    entails

    The empty clause is a disjunction of no disjuncts

    and is equivalent to False because a disjunction is true only if at least one ofits disjuncts is true. Another way to see that an empty clause represents a contradiction because

    it arises only from resolving two complementary unit clauses such as P andP.

    86

  • 8/12/2019 Chapter 7 Logical Agents 2

    87/98

    Resolution algorithmTrace for Example

    KB= (B1,1(P1,2P2,1)) B1,1 =P1,2

    87

    Top row:clauses after CNF conversion

    Denoted as clausesin the algorithmSecond row:

    clauses obtained by resolving pairs in the first row

    Denoted as newin the algorithm

  • 8/12/2019 Chapter 7 Logical Agents 2

    88/98

    Resolution algorithmTrace for Example

    Inspection of trace reveals that many resolution steps are pointless. Ex: the clause B1,1 V B1,1 V P1,2

    is equivalent to True V P1,2

    which is equivalent to True.

    Deducing that True is true is not very helpful. Therefore, any clause in which two complementary literals appear

    can be discarded

    88

    Completeness of resolution

  • 8/12/2019 Chapter 7 Logical Agents 2

    89/98

    Completeness of resolution

    why PL-RESOLUTION is complete To do this, introduce the resolution closure RC ( S) of a set of

    clauses S

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

    The resolution closure is what PL-RESOLUTION computes asthe final value of the variable clauses.

    It is easy to see that RC ( S) must be finite, because there areonly finitely many distinct clauses that can be constructed

    out of the symbols P1 , . . . , Pk that appear in S. (Notice that the factoring step removes multiple copies of

    literals)

    Hence, PL-RESOLUTION always terminates.89

    Completeness of resolution

  • 8/12/2019 Chapter 7 Logical Agents 2

    90/98

    Completeness of resolution

    why PL-RESOLUTION is complete The completeness theorem for resolution in propositional

    logic is called the ground resolution theorem:

    If a set of clauses is unsatisfiable, then the resolution closureof those clauses contains the empty clause.

    90

  • 8/12/2019 Chapter 7 Logical Agents 2

    91/98

    7.5.3 Horn clauses and

    definite clauses

    91

    Horn clauses and definite clauses

  • 8/12/2019 Chapter 7 Logical Agents 2

    92/98

    Horn clauses and definite clauses

    The completeness of resolution makes it a very importantinference method. In many practical situations, however, the full power of

    resolution is not needed.

    Some real-world knowledge bases satisfy certain restrictionson the form of sentences they contain which enables them to use a more restricted and efficient inference

    algorithm.

    Horn clauses and definite clauses: restricted clause forms

    92

    Horn clauses and definite clauses

  • 8/12/2019 Chapter 7 Logical Agents 2

    93/98

    Horn clauses and definite clauses

    definite clause One such restricted form is the definite clause, which is adisjunction of literals of which exactly one is positive.

    Ex: the clause (L1,1 V Breeze V B1,1) is a definite clause(B1, 1 V P1 , 2 V P2, 1) is not.

    Horn clause Slightly more general form 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 withno positive literals; these are called goal clauses

    93

    A grammar for CNF, Horn clauses and

  • 8/12/2019 Chapter 7 Logical Agents 2

    94/98

    g ,definite clauses

    94

  • 8/12/2019 Chapter 7 Logical Agents 2

    95/98

  • 8/12/2019 Chapter 7 Logical Agents 2

    96/98

    Forward chaining (FC)

    Given a problem

    Fire any rule whose premises are satisfied in the KB Add its conclusion to the KB until query is resolved

    96

  • 8/12/2019 Chapter 7 Logical Agents 2

    97/98

    Backward chaining (BC)

    Idea: work backwards from the query To answer / prove query

    Is q already known in KB Otherwise prove by BC all premises that conclude q

    Avoid loops by checking is subgoal already in KB

    97

  • 8/12/2019 Chapter 7 Logical Agents 2

    98/98

    Forward vs. backward chaining

    FC is data-driven, automatic, unconscious processing, e.g., object recognition, routine decisions

    May do lot of work that is irrelevant to the goal

    BC is goal-driven, appropriate for problem-solving, e.g., Where are my keys? How do I get into a PhD program?

    Complexity of BC can be much less than linear in size of KB