30
Propositional Logic

Propositional Logic. Propositions Any statement that is either True (T) or False (F) is a proposition Propositional variables: a variable that can assume

Embed Size (px)

Citation preview

Propositional Logic

Propositions

• Any statement that is either True (T) or False (F) is a proposition

• Propositional variables: a variable that can assume a value of T or F

• Propositional constants: T or F• Atomic proposition: A proposition consisting of

only a single propositional variable or constant• Logical connectives: logical operators

Truth Table

• Gives the values of a proposition under all possible assignments of its variables

• Used to define connectives

P P

T F

F T

FF

TF

FT

TT

QP

T

F

F

T

P Q

Biconditional

“equivalent”

T

T

F

T

P Q

Conditional

“implies”

F

T

T

T

P Q

Disjunction

“or”

F

F

F

T

P Q

Conjunction

“and”

Connectives

P implies Q

if P then Q

Q if P (e.g., Q :- P)

P only if Q

P is sufficient for Q

Q is necessary for P

P is equivalent to Q

P if and only if Q

P is necessary and sufficient for Q

P iff Q

Compound Propositions

• Also called logical expressions, formulas, and well-formed formulas (wffs)

• Well-formed formulas are defined inductively:– Basis:

T and F are wffs (these are the constants)

P, Q, … are wffs (these are the variables)

– Induction: if A and B are wffs, then so are:(A)

(A B), (A B), (A B), (A B)

Parentheses• Well-formed formulas are fully parenthesized:

((((P Q)) ((P) Q)) R)• We can remove some parentheses:– Outside parentheses can be removed– Use precedence:

– Use associativity always left associative

Evaluating Logical Expressions

F

T

T

T

T

T

F

F

FF

TF

FT

TT

((P) Q)QP

P Q

T

T

T

T

T

T

F

T

6

F

F

T

T

F

F

F

F

4

T

T

T

T

F

F

F

F

2

T

T

T

T

T

T

F

F

5

F

F

F

F

F

F

T

T

1

T

T

T

T

T

T

F

F

3

FFF

TFF

FTF

TTF

FFT

TFT

FTT

TTT

R QP) PQ(RQP

(P Q) P Q R

Evaluating Logical Expressions

• In general…– To evaluate expressions using truth tables with k variables

and n operations is O(2kn).– If we have one operator (n = 1) and if we can substitute in

T or F and evaluate in 1 sec, then• k time• 30 20 minutes• 40 14 days• 50 40 years• 60 40,000 years!

• Not practical to use truth tables for “large” k!

Evaluating with Truth Tables

Logical Expressions

• Tautology – a logical expression that is true for all variable assignments– The symbol |= (read “entails”) denotes that what follows

holds or is true, so long as what precedes it is true– Since tautologies are always true, we sometimes write “|=

B” to denote that B is a tautology independent of what precedes it

• Contradiction – a logical expression that is false for all variable assignments

• Contingent – a logical expression that is neither a tautology nor a contradiction

F

F

T

T

T

F

F

T

(P P)P PPP

T

T

T

T

T

T

T

F

F

F

F

T

FF

TF

FT

TT

(P Q) Q(P Q)P QQP

Sample Tautologies

Sound Reasoning• A logical argument has the form:

A1 A2 … An B

and is sound if when Ai = T for all i, B = T

(i.e., if the premises are all true, then the conclusion is also true)

• This happens when A1 A2 … An B is a tautology

Logical Arguments

• Consider the following statements

1. if you study then you succeed2. you study3. you succeed

• These three statements create a logical argument– Lines 1 and 2 are the premises– Line 3 is the conclusion

• This logical argument is sound… 1. If P then Q2. P------------------3. Q

( ( P Q ) P ) Q

Modus Ponens

T

T

T

T

F

F

F

T

T

T

F

T

FF

TF

FT

TT

((A B) A) B(A B) A (A B)BA

A B A BT ? T

Hence, modus ponens is sound!

A BA

B

Important!

• We are dealing with the validity of an argument, NOT with the validity of the result!

• In logic, it doesn’t matter if a logical statement makes sense or not

• What does matter is that:– IF the premises are correct– THEN so is the conclusion

1. If P then Q2. P------------------3. Q

• P: I study hardQ: I do well on my exam

• P: cows give milkQ: doors open

• P: I obeyQ: I am happy

• P: I sail past the end of the worldQ: I will fall off

Makes sense

Doesn’t make sense

Makes sense

Doesn’t make sense

Valid Logical Arguments

Disjunctive Syllogism

T

T

F

F

T

T

T

T

F

T

F

F

F

T

T

T

A

FF

TF

FT

TT

(A B) A B(A B) A A BBA

Hence, disjunctive syllogism is sound!

A BAB

Logical Implication• If A and B are two logical expressions and if A

B is a tautology, we say that A logically implies B, and we write A > B

• > is a meta-symbol to say a logical argument is sound

(P Q) P > Q(P Q) P > Q

If A B is a tautology, then A > B

Modus ponens

Disjunctive syllogism

Logical Equivalence• If A and B are two logical expressions and if A and B

always have the same truth value, then A and B are said to be logically equivalent, and we write A B

• is a meta-symbol to say that A B is a tautology.

T

T

F

T

F

T

AA AA Thus, A A A

Which means, you can replace A A with A.

A B if and only if A B is a tautology

Laws of , , and

Excluded middle law

Contradiction law

P P TP P F

NameLaw

Identity lawsP F PP T P

Domination lawsP T TP F F

Idempotent lawsP P PP P P

Double-negation law(P) P

Commutative lawsP Q Q PP Q Q P

NameLaw

Associative laws(P Q) R P (Q R)

(P Q) R P (Q R)

Distributive laws(P Q) (P R) P (Q R)

(P Q) (P R) P (Q R)

De Morgan’s laws(P Q) P Q(P Q) P Q

Absorption lawsP (P Q) PP (P Q) P

Can prove all laws by truth tables…

T

F

T

F

T

T

T

F

T

T

F

F

T

T

T

T

F

F

F

T

T

T

T

F

FF

TF

FT

TT

QP(P Q)QP

De Morgan’s law holds!

Two Other Useful Laws

• Law of implication– P Q P Q

• Law of contrapositive– P Q Q P

• Note that the converse of P Q is Q P, and the two are NOT equivalent

Duals• To create the dual of a logical expression

1) swap propositional constants T and F2) swap connective operators and

P P T Excluded Middle P P F Contradiction

• The dual of a law is always a law!• Thus, most laws come in pairs pairs of duals

Normal Forms

• Normal forms are standard forms, sometimes called canonical or accepted forms

• A logical expression is said to be in disjunctive normal form (DNF) if it is written as a disjunction, in which all terms are conjunctions of literals

• Similarly, a logical expression is said to be in conjunctive normal form (CNF) if it is written as a conjunction of disjunctions of literals

• Disjunctive Normal Form (DNF)( .. .. .. ) ( .. .. .. ) … ( .. .. )

Term Literal, i.e. P or P

• Conjunctive Normal Form (CNF)

( .. .. .. ) ( .. .. .. ) … ( .. .. )

Examples: (P Q) (P Q)

P (Q R)

DNF and CNF

Examples: (P Q) (P Q)

P (Q R)

Converting Expressionsto DNF or CNF

The following procedure converts an expression to DNF or CNF:

1. Remove all and

2. Move inside (use De Morgan’s law)

3. Use distributive laws to get proper form

Simplify as you go (e.g., double-neg., idemp., comm., assoc.)

CNF Conversion Example( .. .. .. ) ( .. .. .. ) … ( .. .. )

((P Q) R (P Q)) ((P Q) R (P Q)) impl. (P Q) R (P Q) deM. (P Q) R (P Q) deM. (P Q) R (P Q) double neg. (P Q) (P Q) R comm. (P Q) R

idemp. (P R) (Q R) distr.

(DNF)

(CNF)

DNF Expression Generation

F

T

F

F

F

T

T

F

FFF

TFF

FTF

TTF

FFT

TFT

FTT

TTT

RQP

(P Q R)

(P Q R)

(P Q R)

¦ (P Q R) (P Q R) (P Q R)

minterms

The only definition of is the truth table

CNF Expression Generation1. Find .2. Find the DNF of .3. Then, use De Morgan’s law to get the

CNF of (i.e. () )

T

F

T

F

FFF

TTF

FFT

TTT

QP

(P Q) (P Q)

(P Q) (P Q)

(P Q) (P Q) DNF of f ((P Q) (P Q)) (P Q) (P Q) DeM.

(P Q) (P Q) DeM., double neg.

max terms

} Form a conjunction of max terms