Top Banner
ICS 220: Artificial Intelligence Programming 1 Propositional Calculus
38

1 - propositional calculus

Mar 28, 2015

Download

Documents

morris_muthomi
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 1

Propositional Calculus

Page 2: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 2

Propositional Calculus Knowledge base agents can form representations about the world

Use inference to derive new representations about the world

Use new representations to deduce what to do

The central component of knowledge based agents is a knowledge

base KB

A KB is a set of sentences

Each sentence is expressed in the knowledge representation

language and represents some assertion about the world

There must be away to add new sentences to the knowledge base

(TELL) and a way to query the knowledge base (ASK)

Page 3: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 3

Propositional Calculus Knowledge bases consists of sentences

These sentences are expressed according to the syntax of the

representation language

The syntax specifies all the sentences that are well formed

A logic must also define the semantics of the language

Semantics has to do with the meaning of the sentences

In logic the semantics define the truth of each sentence with

respect to each possible world

In logic, every sentence is either true or false

Page 4: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 4

Logical Reasoning This involves the idea of logical entailment between sentences The idea that a sentence logically follows from another

sentence We use the symbol |= to indicate entailment We have |=, means that logically entails |= iff in every model in which is true, is also true Model here refers to a possible world. For instance in the 8-puzzle, any of the possible states of the

board is a model of the board Logical inference – the formal process of deriving conclusion

given a model

Page 5: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 5

Logical Reasoning An inference algorithm that derives only entailed conclusion is said

to be sound or truth preserving any unsound inference algorithm makes up things as it goes along An inference algorithm is complete if it can derive any sentence that

is logically entailed.Grounding

The connection between logical reasoning processes and the real environment in which the agent exists

How do we know that the KB is true in the real world? Assume the sensors (which create the connection) are accurate Other general rules in the KB derived from conclusions based on

experience e.g. humans are mortal These conclusions could be wrong but usually generally

accepted

Page 6: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 6

Propositional Calculus Syntax Syntax – defines the allowable sentences

The atomic sentences (Propositional Symbols) consists of

indivisible strings of characters beginning with an uppercase

letter e.g. P, Q, Raining, On_A_B

Each atomic sentence stands for a proposition that can either

be true or false

The other two atomic sentences are True and False

Complex sentences are constructed from simpler sentences

using logical connectives

Page 7: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 7

Propositional Calculus Syntax We have five connectives

1) (not) A sentence such as W is a negation of W A literal is either an atomic sentence ( a positive literal) or a

negated atomic sentence (a negative literal)

2) (and) A sentence of the form W1W2 also called a conjunction. W1 and W2 are the conjuncts

3) (or) A sentence of the form W1W2 is called a disjunction W1 and W2 are the disjuncts

Page 8: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 8

Propositional Calculus Syntax4) (implies)

A sentence of the form W1W2 is called an implication

W1 is called the premise or antecedent, W2 is called the consequent

or conclusion

Implications are also known as rules or if-then statements

5) (if and only if)

A sentence of the form W1W2 is called a biconditional

Read as w1 iff w2

Page 9: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 9

Propositional Calculus Syntax The following is the definition of a well formed formulas

1) an atom is a wff, e.g. P, P3 …2) if w1and w2 are well formed formulas then so are 3) w1 w24) w1 w25) w1 w26) w1w27) w1There are no other wffs

Sentences constructed with binary connectives should be enclosed in parentheses.

This ensures that the syntax is completely unambiguous The order of precedence in propositional logic is , , , ,

Page 10: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 10

Propositional Calculus Semantics The semantics define the rules for determining the truth of a

sentence in respect to a particular model

In propositional logic, a model simply fixes the truth of every

propositional symbol (atomic sentence)

For instance with three propositions, there are 23 possible models

The rules for determining the truth of a sentence formed using any

of the connectives can be summarized in a truth table as shown

below

Truth table specifies the truth value of a complex sentence for each

possible assignment of truth values to its components

Page 11: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 11

Propositional Calculus SemanticsP Q pq

True True True

True False False

False True False

False False False

Fig 1: Truth table for connective

P Q pq

True True True

True False True

False True True

False False False

Fig 2: Truth table for connective

Page 12: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 12

Propositional Calculus Semantics

Fig 3: Truth table for connective

Fig 4: Truth table for connective

P Q pq

True True True

True False False

False True True

False False True

P Q pq

True True True

True False False

False True False

False False True

Page 13: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 13

Propositional Calculus Inference rules If there five sentences in the knowledge base say R1 to R5, it can

also be considered as a single sentence, the conjunction of R1 to

R5 i.e. R1R2 R3R4R5 because it asserts all the individual

sentences are true

The aim of inference is to decide if KB |=

One way to determine entailment is to enumerate all models

(assignments of values to the atoms) which KB is true, and check

if is true for every model in which KB is true.

With n atoms, there are 2n possible models to consider

Thus such an algorithm would have exponential complexity

Page 14: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 14

Propositional Calculus Inference rulesEnumeration of Models (First Algorithm) Enumerate all models and check that is true in all models in

which KB is true Example algorithm TT-Entails (Russell and Norvig, 2003, pg.

209) Algorithm is sound because it implements directly the

definition if entailment. Checking for models in which KB is true, and then checking if is true

The algorithm is complete because it works for any KB and and always terminates

Must test 2n models when n is the number of symbols

Page 15: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 15

Propositional Calculus Inference rulesEquivalence

Two sentences and are logically equivalent if they are true in

the same set of models

This is written as

An alternative definition is

Two sentences and

|= and |=

Page 16: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 16

Propositional Calculus Inference rules Some common equivalents

1. – Commutativity of 2. – Commutativity of 3. (() ) (() ) – Associativity of 4. (() ) ( () ) – Associativity of 5. () double negation elimination

6. – Contraposition

7. – Implication elimination

8. ()() Biconditional elimination

9. ()( ) – De Morgan’s Law

10. ()( ) – De Morgan’s Law

11. (() ) ()( ) – Distributivity of over 12. (() ) () ( ) – Distributivity of over

Page 17: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 17

Propositional Calculus Inference rulesValidity

A sentence is valid if it is true in all the models e.g. PP Valid sentences are also known as tautologies

Satisfiability A sentence is satisfiable if it is true in some model If a sentence is true in a model m, we say that m satisfies or

that m is a model of . is valid iff is unsatisfiable is satisfiable iff is not valid |= iff the sentence () is unsatisfiable Proving from by checking the unsatisfiability of () is called

proof by refutation or contradiction. One assumes that sentence is false and shows that this leads to

contradiction with known axioms

Page 18: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 18

Propositional Calculus Inference rulesInference Rulesmethods used to derives new sentences (conclusions) from existing sentences.

Modus Ponens, And-Elimination – infer any of the conjuncts

The equivalences given earlier can also be used as inference rules()()

Some equivalences can also be used backward like the ones above or

Page 19: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 19

Propositional Calculus Inference rules The process of derivation of a new sentence by application of

inference rules is called a proof. For example given the axioms

RainingMuddy

Sunny Raining

Sunny

Then we can try to derive the sentence Muddy as follows

SunnyRaining

Sunny Raining (from equivalence)

Raining (using modus ponens, , then )

Muddy (using modus ponens )

Page 20: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 20

Propositional Calculus Inference rules Example 2

Given the knowledgebase (A(BC))ADerive B

Using Biconditional elimination(A(BC)) (BC)A)Using and elimination(BC)AUsing logical equivalence for contrapositivesA(BC)Using Modus Ponens(BC)Using de Morgan’s rulesBCUsing and elimination B

Page 21: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 21

Propositional Calculus Inference rules Finding proofs is exactly like finding solutions to search problems If the successor function is defined to generate all possible

applications of inference rules, then search algorithms can be used to find proofs

Thus searching is an alternative to enumerating models. The goal is the sentence to be derived The alternative paths are the alternative inference rules to be used

to generate new sentences Finding a proof can be made efficient by ignoring irrelevant

propositions e.g. by considering only the sentences that contain the goal proposition

These inference algorithms are complete iff the rules are adequate to produce all the necessary intermediate conclusions to reach the desired goal

Page 22: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 22

Resolution Resolution

Is an inference rule

Yields a complete inference algorithm when coupled with any

complete search algorithm

Resolution applies to a special format of wffs called clauses

A clause is a disjunction of literals

e.g. AB C

Resolution works as follows

Page 23: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 23

Resolution Assume P means it is raining in Mombasa Q means it is raining in Nairobi Assume R means that it is raining in Nakuru If we have the clause PQR , and Q then we can infer PR This means that if it is raining in either Nairobi or Mombasa or

Nakuru, and we know that it is not raining in Nairobi, then it must be raining in either Mombasa or Nakuru

I.e. given

PQR, and Q infer

PR This is known as unit resolution inference rule

Page 24: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 24

Resolution If we have complementary literals in the two clauses in the previous

case Q and Q This rule takes a disjunction of literals (a clause) and a clause which

contains a complimentary literal in the clause and produces another clause, where the complimentary literal has been eliminated

We have the general inference rule which works when we have two clauses as shown below

PQR, AQB

PRAB This takes two clauses that contain complimentary literals and

produces another clause that contains all literals except the complimentary literals

Page 25: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 25

Resolution The resulting literal should contain only one copy of each of the

literals. This is called factoring. For instance

PQR, AQR

PRAR which is factored to

PRA The resulting Clause is called the resolvent

Resolution is sound, we can see this by considering

and

If is true, then is false hence is true

If is true then is false hence is true

So whatever the value of , then () is true because either of or is true or both

Page 26: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 26

Resolution Resolution used by itself is not complete For instance given

PR|=(PR) But we cannot infer PR using resolution on the clause P R because

there is nothing that can be resolved. Therefore we cannot use resolution directly to decide all logical

entailments. However, we can show by resolution that the negation of PR is

inconsistent with the set {P, R} hence use proof by contradiction to show PR|=(PR)

The process is illustrated belowWe have the clauses P and R written {P, R}we negate PR to get ( PR), which is equivalent to (PR) two clause {P,R}

Page 27: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 27

Resolution we can then resolve combine these clauses into one set {P, R,

P,R}

We resolve the clauses with complementary literals resulting

in an empty clause

resolve P and P to get nil which is equivalent to false

This makes the whole set false since it consists of

conjunctions) therefore one false clause, makes the whole set

false which is a contradiction hence we have indirectly

established PR|=(PR)

Page 28: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 28

ResolutionConjunctive Normal Form

Resolution applies only to disjunctions of literals So it would seem relevant only to knowledge bases and queries

consisting only of such disjunctions. However, every sentence in propositional logic can be converted

to a conjunction of clauses (disjunctions of literals) Such a sentence is said to be in conjunctive normal form (CNF)

e.g.(AB) (C AB).

This would be equivalent to a knowledge base containing the clauses (AB), (C AB).

Page 29: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 29

Resolution The negation of the query can also be converted to CNF form

The clauses in the Query in CNF can the be resolved with the

clauses in the KB,

if we get an empty clause in the process, then we have

succeeded in proving the query is entailed by the DB by

refutation.

Page 30: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 30

ResolutionExample; Converting a wff to conjunctive normal form(PQ)(RP)

Eliminate the implication symbol by using the equivalent(PQ)(RP)

Eliminate the scope of using De Morgan’s law and double-negation elimination(PQ) (RP)

Convert to CNF by using the associative and distributive rules(PRP) (QRP)(PR) (Q RP)

A conjunction of clauses in CNF form is usually expressed as a set of clauses, with the conjunction of clauses implied{(PR), (QRP) }

Page 31: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 31

Resolution In general, a resolution refutation for proving an arbitrary wff, w,

from a set of wffs, proceeds as follows

1. convert the wffs in to clause form, A conjunction of clauses

2. convert the negation of w to clause form

3. combine the clauses resulting from step 1 add 2 into a single set

4. iteratively apply resolution to the clauses in and the results into until there are no more resolvents that can be added or until the empty clause is generated

5. if the procedure completes with an empty clause then |= w

6. else does not entail w

Page 32: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 32

ResolutionAnother Example

Given the following KB, Prove R using resolutionP(PQ)R(ST)QT

Convert the wffs into clause form1) P P2) (PQ)R P QR3) (ST)Q (SQ)

(TQ)4) T T

Page 33: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 33

Resolution

P Q R R

P QP

QT Q

TT

Nil

Fig 5: A Resolution Refutation tree to prove R given the preceding axioms

Page 34: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 34

Forward and Backward Chaining The completeness of resolution makes it a very important inference method In many practical situations, the full power of resolution is not needed Real-World Knowledge bases often contain clauses of a restricted form called Horn Clauses. A horn clause is a disjunction of literals with at most one positive literal

e.g. ABPQ Every horn clause can be written as an implication whose premise is a conjunction of positive literals and whose conclusion is a single positive literal For example the horn clause ABPQ can be written as

ABPQ

Page 35: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 35

Forward and Backward Chaining Such a horn clause is usually called a definite clause The positive literal is called the head of the clause while the negative literals are called the body of the clause. Such a clause is also called a rule A definite clause with no negative literals simply asserts a given proposition and is sometimes called a fact A horn clause with no positive literals can be written as an implication whose conclusion is the literal false. For example PQ can be written as PQfalse Such sentences are called integrity constraints on the data and they are used to signal errors in the data.

Page 36: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 36

Forward and Backward Chaining Inference with horn clause can be done via backward chaining

and forward chaining

Forward chaining works by trying to infer the goal either from

the facts or using the rules

Backward chaining works by trying to prove the literals in the

body of a rule that contains the goal

Page 37: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 37

Forward Chaining AlgorithmPL-FC-Entails?(KB,q): returns true or false

inputs: KB (The Knowledge base in horn clause form)

q: The query in horn, a propositional symbol

local variables: count (a table indexed by a clause, initially

the number of premises)

inferred: A table indexed by symbols. Each entry

initially is false

agenda: A list of symbols, initially, the symbols

known to be true in KB

Page 38: 1 - propositional calculus

ICS 220: Artificial Intelligence Programming 38

Forward Chaining Algorithmwhile agenda is not empty

pPOP(agenda)unless inferred[p]

inferred[p] trueforeach horn clause c in which p appears

decreament count[c] by oneif count[c]=0

if Head[c]=q return true

PUSH(HEAD[c], agenda)return false

Fig 6: The forward chaining algorithm (Adapted from Artificial Intelligence by Russell and Norvig)