Part-2: Propositional Logic By Dr. Syed Noman Hasany.

69
Part-2: Propositional Logic By Dr. Syed Noman Hasany

description

Knowledge Pyramid Noise Data Information Knowledge Meta- Knowledge Knowledge – the integration of the information into a knowledge base to be effectively utilized Data Data – collected symbols and artifacts Information Information – the interpretation of artifacts in some context Interpretation in Context Integration and Usage raw digital material Data - raw digital material or the “ artifacts which exist as a vehicle for conveying information ” interpreted data Information - interpreted data “ within a context set by a priori knowledge and the current environment ” purposeto information Knowledge - assigns a purpose and/or action to information

Transcript of Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Page 1: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Part-2: Propositional Logic

ByDr. Syed Noman Hasany

Page 2: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

“The beginning of knowledge is the discovery of something that we do not understand.”

–Frank Herbert

Page 3: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Knowledge Pyramid

Noise

Data

Information

Knowledge

Meta- KnowledgeKnowledgeKnowledge – the integration of the information into a knowledge base to be effectively utilized

DataDataData – collected symbols and artifacts

InformationInformationInformation – the interpretation of artifacts in some context

Interpretation in ContextInterpretation in Context

Integration and UsageIntegration and Usage

Data - raw digital materialraw digital material or the “artifacts which exist as a vehicle for conveying information”

Information - interpreted datainterpreted data “within a context set by a priori knowledge and the current environment”

Knowledge - assigns a purposepurpose and/or action to informationto information

Page 4: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Knowledge bases

• Knowledge base = set of sentences in a formal language

Page 5: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Knowledge-base System

Sys

KB

percept

ask/resulttell

Knowledge level

Logical level

Implementation level

What it knows

Knowledge implementation

How it knows

Describing a KB...

sentences

inferenceengine

Page 6: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Propositional Logic

• The syntax of propositional logic is made up of propositions and connectives.

Page 7: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Proposition• A statement in some language that can be evaluated to

either true or false (but it cannot be both).Example propositions:• It is raining.• 5 + 5 = 10.• Turkey is in Asia.• Riyadh is the capital of KSA.

Not propositions:• Where are you?• Oh no!• Liverpool is not.

Page 8: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Propositions• Of the valid propositions, each can be evaluated

to either true or false.

• e.g. It is true that it is raining• e.g. It is false that Turkey is in Asia.

• An easy way to determine whether or not a statement is a proposition is to see if you can prefix it with “it is true that” or “it is false that”; and if it subsequently still makes sense.

Page 9: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Propositions• we represent propositions using the

propositional variables p, q, r etc.

• The previous examples of propositions are all atomic. We can combine these atomic propositions to form compound propositions…

Page 10: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Connectives• Propositions are combined through connectives.

The main connectives of propositional logic are:

• Conjunction (and): Λ • Disjunction (or): v • Negation (not): ¬ • Implication (if..then): → • Equivalence (if and only if): ↔

Page 11: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Material Implication

• For the implication truth table, p → q is false only when p is true and q is false.

• The last two cases, where p is false, we cannot say whether q will be true, but as we cannot say it will definitely be false, then we evaluate these cases to true.

Page 12: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

ImplicationExample: Using the implication

connective we can express that if “you give me your mobile phone” then “I will be your best friend”, as:

p → qwhere p represents the

proposition “you give me your mobile phone” and q represents the proposition “I will be your best friend”.

p q p → q

TTFF

TFTF

TFTT

Truth Table

Page 13: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Implication• We need to be careful with → as it may not

quite capture our intuitions about implication.• In particular (taking the previous example),

p → q is true in the following situations:– I study hard and I get rich; or– I don't study hard and I get rich; or– I don't study hard and I don't get rich.

• Note the last two situations, where the implication is true regardless of the truth of p.

• The one thing we can say is that if I've studied hard but failed to become rich then the proposition is clearly false.

Page 14: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Equivalence OR Bi-implicationExample: Using the equivalence

connective we can express that “Asim will get a first class degree” iff “his average is higher than 70%”, as:

p ↔ qwhere p represents the

proposition “Asim will get a first class degree” and q represents the proposition “his average is higher than 70%”.

p q p ↔ q

TTFF

TFTF

TFFT

Truth Table

Page 15: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Compound Statements• Connectives can be combined to form

compound statements or formulae.• e.g.: ¬(p Λ ¬ q)

p Λ q ↔ r

Page 16: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

ExampleThe truth table for ¬(p Λ ¬q) is as follows:

p q

TTFF

TFTF

¬q (p Λ ¬q) ¬(p Λ ¬q)

FTFT

F TFF

TFTT

Page 17: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Example

This table is derived by a number of steps:

p q

TTFF

TFTF

¬q (p Λ ¬q) ¬(p Λ ¬q)

FTFT

F TFF

TFTT

Page 18: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Tautologies and Contradictions• For the truth tables of some formulae we find only Ts in

the last column. Such formulae are called “tautologies” (or valid formulae).

• Conversely, the truth tables of other formulae contain only Fs in the last column. Such formulae are called “contradictions” (or unsatisfiable formulae).

• Negation of a tautology is a contradiction, and vice versa.

• A formula that is neither a tautology nor a contradiction (i.e. contains both Fs and Ts in the last column) is known as a “contingency” (or a satisfiable formula).

Page 19: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Tautology Example

The truth table for: p → (p V q), is a tautology, as shown below.

p q

TTFF

TFTF

(p V q)

TTTF

p → (p V q)TTTT

Page 20: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Contradiction Example

The truth table for: (p V q) Λ (¬p Λ ¬q), is a contradiction, as shown below.

p q

TTFF

TFTF

TTTF

(p V q) ¬p ¬q

FFTT

FTFT

¬p Λ ¬q

FFFT

(p V q) Λ (¬p Λ ¬q)

FFFF

Page 21: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Contingency Example

The truth table for: (p Λ q) → ¬p , is a contingency, as shown below.

p q

TTFF

TFTF

(p Λ q)

TFFF

¬p

FFTT

(p Λ q) → ¬p

FTTT

Page 22: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Equivalences• It is worth noting that there are a number of equivalences

between the logical connectives.

Thus: p q is equivalent to ¬p V qp Λ q is equivalent to ¬(¬p V ¬q)p V q is equivalent to ¬p q

• The symbol we use to denote equivalence is: ≡

e.g. p q ≡ ¬p V q etc.

Page 23: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Equivalencesp q p → qTTFF

TFTF

TFTT

p q ¬p ¬p V qTTFF

TFTF

FFTT

TFTT

•We can check to see if these statements are equivalent by examining the appropriate truth tables

Page 24: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Equivalence Laws• There are a number of laws that state equivalence

relations. The following are a few of the most popular ones:

• Associative laws:(p V q) V r ≡ p V (q V r) (p Λ q) Λ r ≡ p Λ (q Λ r)

• Commutative laws:p V q ≡ q V p p Λ q ≡ q Λ p

• Involution law:¬¬p ≡ p

Page 25: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Equivalence Laws• Distributive laws:

p V (q Λ r) ≡ (p V q) Λ (p V r) p Λ (q V r) ≡ (p Λ q) V (p Λ r)

• DeMorgan’s laws:¬(p V q) ≡ ¬p Λ ¬q ¬(p Λ q) ≡ ¬p V ¬q

• All these laws can be verified by checking the appropriate truth tables to see that the statements are equivalent.

Page 26: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Syntax semantics

Page 27: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Wumpus World description

Page 28: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Exploring the Wumpus World

1. The KB initially contains the rules of the environment.

2. (a) [1,1] The first percept is [none, none,none,none,none], Move to safe cell e.g. 2,1

3. (b) [2,1] Breeze indicates that there is a pit in [2,2] or [3,1]Return to [1,1] to try next safe cell

Page 29: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Exploring the Wumpus World

4. [1,2] Stench in cell: wumpus is in [1,3] or [2,2]YET … not in [1,1]Thus … not in [2,2] or stench would have been detected in [2,1]Thus … wumpus is in [1,3]Thus … [2,2] is safe because of lack of breeze in [1,2]Thus … pit in [3,1]

Move to next safe cell [2,2]

Page 30: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Exploring the Wumpus World

5. [2,2] Detect nothing Move to unvisited safe cell e.g. [2,3]

6. [2,3] Detect glitter , smell, breezeThus… pick up goldThus… pit in [3,3] or [2,4]

Page 31: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Logic in general

Page 32: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

A Formal Approach• Any logic comes in three parts:

• syntax: what are the well-formed formulae (wffs)?

• semantics: what do formulae mean, how do we interpret them?

• deduction: how to mechanically formulate formulae, giving us for instance, the valid ones? Or is concerned with manipulating formulae according to certain rules (Also called the proof theory)

Page 33: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Propositional logic grammar

S := <Sentence> ;<Sentence> := <AtomicSentence> |

<ComplexSentence> ;<AtomicSentence> := "TRUE" | "FALSE" | "P" | "Q" | "S" ;<ComplexSentence> := "(" <Sentence> ")" | <Sentence> <Connective> <Sentence>

|"NOT" <Sentence> ;<Connective> := "NOT" | "AND" | "OR" |

"IMPLIES" | "EQUIVALENT" ;

Page 34: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Argument and Proof in Propositional Logic

• An argument is a relationship between a set of propositions called premises and another proposition called the conclusion.

• Proof is intended to show deductively that an argument is sound (or valid). – An argument is sound iff it cannot be the case that its premises are

true and its conclusion is false.• An argument that is not sound is called a fallacy

• In addition to using truth tables, other forms of proof can be used, such as derivation rules (or proof rules).

Page 35: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Entailment and Proof• To clarify the difference between entailment and proof:

• Entailment: if we have a set of formulae which are true, then as a logical consequence of this, some particular formula must also be true.

• Proof: a formula is provable (derivable) in some logical system if there are rules of inference that allow the formula to be derived by performing some operations on the formulae.

• Entailment is concerned with the semantics of formulae, proof is concerned with syntax only.

Page 36: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

EntailmentExample: {¬q, p q} ╞ ¬p

means that ¬p is true, iff both ¬q and p q are true. Thus, the premises entail the conclusion. p q

TTFF

TFTF

FFTT

FTFT

TFTT

(p q)¬p ¬q

Truth Table

Page 37: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Entailment

• Lines 1, 2 and 3 all have false truth assignments so we disregard them.

• This means that we are left with one assignment, where all assignments for the formula are true. – i.e. ¬q is true, p q is true and ¬p is true.

• Therefore, ¬p is entailed by {¬q, p q} , or more formally: {¬q, p q} ╞ ¬p

Page 38: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Modus Ponens• (Latin term means) Affirming the antecedent • One particularly important derivation rule is

modus ponens, as shown on the previous slide.

• This takes the following form:p → q, p ╞ q

• Essentially, this argument states that given the premise p → q, and the premise p then we must conclude q.

Page 39: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Modus Ponens Example• An example argument of the form modus

ponens:

Premises: - If it is raining then ground is wet (p → q),- It is raining (p),

Conclusion:- Therefore, the ground is wet (q).

Page 40: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Modus Tollens• Denying the consequent• Another important derivation rule is modus tollens

(also known as the contraposition) have the following form:p → q, ¬q ╞ ¬p

• Example:

Premises: - If it is raining then the ground is wet (p → q),- The ground is not wet (¬q)

Conclusion:- Therefore, it is not raining (¬p).

Page 41: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Exercise

• Can we entail otherwise in modus tollens?

Page 42: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Soundness and Completeness• Two important properties to consider in

inference systems are soundness and completeness.

• A “logic is sound”, with respect to its semantics, if only true formulae are derivable under the inference rules, from premises which themselves are all true. (i.e. the inference rules are correct)

• A “logic is complete” if all the true formulae are provable from the rules of the logic. (i.e. no other rules are required)

Page 43: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Proof System

• A proof system PS is a set of inference rules.• A proof is a sequence of sentences where each

sentence can be inferred from a previous sentence using one of the inference rules.

• A ├ PS B means that there exists a proof starting with A (which might be a set of sentences), ending with B, using the proof system PS.

Page 44: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Logical equivalence• Two sentences are logically equivalent iff they are true in

same models: α ≡ ß iff α╞ β and β╞ α

Page 45: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Entailment• Entailment means that one thing follows from

another:KB ╞ α

• Knowledge base KB entails sentence α if and only if α is true in all worlds where KB is true

Page 46: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Entailment in the wumpus world

Situation after detecting nothing in [1,1], moving right, breeze in [2,1]

Consider possible models for KB assuming only pits

3 Boolean choices 8 possible models

Page 47: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Wumpus models

Page 48: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Wumpus models

• KB = wumpus-world rules + observations

Page 49: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Wumpus models

• KB = wumpus-world rules + observations• α1 = "[1,2] is safe", KB ╞ α1, proved by model checking

Page 50: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Wumpus models

• KB = wumpus-world rules + observations

Page 51: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Wumpus models

• KB = wumpus-world rules + observations• α2 = "[2,2] is safe", KB ╞ α2

Page 52: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Inference

• KB ├i α = sentence α can be derived from KB by procedure i

• Soundness: i is sound if whenever KB ├i α, it is also true that KB╞ α

• Completeness: i is complete if whenever KB╞ α, it is also true that KB ├i α

Page 53: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

A simple knowledge base: Wumpus world sentences

Let Pi,j be true if there is a pit in [i, j].Let Bi,j be true if there is a breeze in [i, j].α1: Is P1,2 entailed?α2: Is P2,2 entailed?

R1: P1,1

R4: B1,1

R5: B2,1

• "Pits cause breezes in adjacent squares"R2: B1,1 (P1,2 P2,1)R3: B2,1 (P1,1 P2,2 P3,1)

(Question: what if instead of ? ) ( R1 ^ R2 ^ R3 ^ R4 ^ R5 ) is the State of the Wumpus World

Page 54: Part-2: Propositional Logic By Dr. Syed Noman Hasany.
Page 55: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Truth tables for inference

KB is true if R1 through R5 are true, which is true in just 3 of 128 rows. In all 3 rows, P1,2 is false, so there is no pit in [1,2]. On the other hand, there might (or might not) be a pit in [2,2]. Why not sure?All True means “Yes”; All False means “No”; Contingent means “Un-known”

Page 56: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Inference Examples• KB is true when the rules hold—only for three

rows in the table– The three rows are models of KB

• Consider the value of P1,2 for these 3 rows– P1,2 is false in all rows

(the rows are models of α1 = P1,2)– Thus, there is no pit in room [1,2]

• Consider the value of P2,2 for these 3 rows– P2,2 false in one row, true for 2 rows– Thus, there may be a pit in room [2,2]

Page 57: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Resolution Inference Rule

The rule is established (when both are true, result is true)

Page 58: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Inference Rules for propositional logicInference Rules for propositional logic1. Modus Ponens or Implication-Elimination: (From an implication

and the premise of the implication, you can infer the conclusion.)

2. And-Elimination: (From a conjunction, you can infer any of the conjuncts.)

3. And-Introduction: (From a list of sentences, you can infer their conjunction.)

4. Or-Introduction: (From a sentence, you can infer its disjunction with anything else at all.)

5. Double-Negation Elimination: (From a doubly negated sentence, you can infer a positive sentence.)

6. Unit Resolution: (From a disjunction, if one of the disjuncts is false, then you can infer the other one is true.)

=> ,

i 1 2 … n

1 2 … n

1, 2, …, n

1 2 … n i

,

,

=>

=> , =>

7. Resolution: (Because cannot be both true and false, one of the other disjuncts must be true in one of the premises. Equivalently, implication is transitive. a=b, b=c -> a=c)

or equivalently

Page 59: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Suppose my knowledge base consists of the facts S T (P R)S TRAnd I need to prove that P is entailed. I can use the rules of inference to do this..

S T (P R) , S , T, R And-IntroductionS T (P R) , S T, R Double Negation Elimination S T (P R) , (S T), R Modus ponens(P R), R Apply negation P R , R Unit ResolutionP Double Negation Elimination P So, P is entailed from the knowledge base.

Page 60: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Example: Proof

Page 61: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Prove?

Page 62: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Proving things• The last sentence is the theorem (also called goal or query)

that we want to prove.• Example for the “weather problem”:

1 Hu Premise “It is humid”

2 HuHo Premise “If it is humid, it is hot”

3 Ho Modus Ponens(1,2) “It is hot”

4 (HoHu)R Premise “If it’s hot & humid, it’s raining”

5 HoHu And Introduction(1,2) “It is hot and humid”

6 R Modus Ponens(4,5) “It is raining”

Page 63: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Logical equivalence• Two sentences are logically equivalent iff they are true in

same models: α ≡ ß iff α╞ β and β╞ α

Page 64: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

A simple knowledge base: Wumpus world sentences

Let Pi,j be true if there is a pit in [i, j].Let Bi,j be true if there is a breeze in [i, j].α1: Is P1,2 entailed?α2: Is P2,2 entailed?

R1: P1,1

R4: B1,1

R5: B2,1

• "Pits cause breezes in adjacent squares"R2: B1,1 (P1,2 P2,1)R3: B2,1 (P1,1 P2,2 P3,1)

(Question: what if instead of ? ) ( R1 ^ R2 ^ R3 ^ R4 ^ R5 ) is the State of the Wumpus World

Page 65: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Back to Wumpus World• KB = ( R1 ^ R2 ^ R3 ^ R4 ^ R5 )• Prove P2,1

Apply Bi-conditional Elim

R6: (B1,1 => (P1,2 V P2,1 )) ^ ( (P1,2 V P2,1 ) => B1,1 )Apply And ElimR7: ( (P1,2 V P2,1 ) => B1,1 )ContrapositiveR8: ( B1,1 => (P1,2 V P2,1 ))Apply Modus Ponens with R4 ( B1,1 )R9: (P1,2 V P2,1 )Apply De MorgansR10: P1,2 ^ P2,1

Page 66: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

proved?

• Finally?– Which rule?

Page 67: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Assign: Q.1Syntax. Say whether each of the following is a sentence of Propositional Logic.

Page 68: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Assign: Q.2Validity, Satisfiability, Unsatisfiability. For each of the following sentences, Indicate whether it is valid, satisfiable, or unsatisfiable..

Page 69: Part-2: Propositional Logic By Dr. Syed Noman Hasany.

Assign: Q.3• Prove

CBBAAC },,{