18
CSS342: Propositions 1 CSS342: Propositions Professor: Munehiro Fukuda

CSS342: Propositions1 Professor: Munehiro Fukuda

Embed Size (px)

DESCRIPTION

CSS342: Propositions3 Propositions Examples: –In math 1.The only positive integers that divide 7 are 1 and 7 itself: (true) 2.For every positive integer n, there is a prime number larger than n: (true) –In history 1.Alfred Hitchcock won an Academy Award in 1940 for directing “Rebecca”: (false, he has never won one for directing) 2.Seattle held the World’s Fair, Expo 62: (true ) –In programming languages 1.Boolean expressions in if-else, while, and for statements for ( index = 0; index < 100; index++ ) { …….; } A proposition Not a proposition

Citation preview

Page 1: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 1

CSS342: Propositions

Professor: Munehiro Fukuda

Page 2: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 2

Introduction• Propositional logic is useful in CS to analyze such behavior

of code portions.• Proposition: a statement that is either true or false, but not

both• Logic: reasoning whether a consequence of given statements

is correct, but not whether each statement is true.• Example:

– Proposition p:All mathematicians wear sandals. (A → B)– Proposition q:Anyone who wears sandals is an algebraist (B → C)– From p and q:All mathematicians are algebraists. (A → C)

Page 3: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 3

Propositions• Examples:

– In math1. The only positive integers that divide 7 are 1 and 7 itself: (true)2. For every positive integer n, there is a prime number larger than n:

(true)– In history

1. Alfred Hitchcock won an Academy Award in 1940 for directing “Rebecca”: (false, he has never won one for directing)

2. Seattle held the World’s Fair, Expo 62: (true )– In programming languages

1. Boolean expressions in if-else, while, and for statementsfor ( index = 0; index < 100; index++ ) {

…….;}

A proposition

Not a proposition

Page 4: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 4

Compound propositions• Conjunction of p and q

– notations: p ^ q, p && q– True only if both p and q are true– truth table

• Disjunction of p or q– Notations: p v q, p || q– True if either p or q or both are true– truth table

p q p ^ q

F F F

F T F

T F F

T T T

p q p v q

F F F

F T T

T F T

T T T

Page 5: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 5

Binary Expressions in C++ Part1• How do you examine the behavior of if-else?

– if ( a > = 1 && a <= 100 )• true if 1 ≤ a ≤ 100

– if ( a >= 1 || a <= 100 )• always true

a < 1 1 <= a <= 100 100 < a

a >= 1

a <= 100

false

true

true

true

true

false

conditionproposition

a < 1 1 <= a <= 100 100 < a

a >= 1

a <= 100

false

true

true

true

true

false

conditionproposition

Page 6: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 6

Negation

• The negation of p– Notations: p, not p, ¬p !p– Truth table:

• Example:– P: 1 + 1 = 3 (false)– !p: !(1 + 1 = 3) ≡ 1 + 1 ≠ 3 (true)

P !p

F T

T F

Page 7: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 7

Boolean Algebra (Axioms)

When T = true and F = false:1. If p ≠ F then p = T, If p ≠ T then p = F2. F &&F = F, T || T = T3. T && T = T, F || F = F4. F && T = T && F = F5. F || T = T || F = T6. !T = F, !F = T

Page 8: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 8

Boolean Algebra (Theorems)When T = true and F = false:• p && q = q && p, p || q = q || p• (p && q) && r = p && (q && r), (p || q ) || r = p || (q || r)• (p || q) && (p || r) = p || q && r, p && q || p && r = p && (q ||

r)• p && F = F, p || T = T• p && T = p, p || F = p• p && !p = F, p || !p = T• p && p = p, p || p = p• p && (p || q) = p, p || p && q = p• !(!p) = p• p + q && !p = p + q

Commutative Law

Associative Law

Distributive Law

Complement Law

Double Negation

Absorption Law

Square Law

Consensus Law

Page 9: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 9

Binary Expressions in C++ Part2• How do you examine the behavior of if-else

statements?– Given two distance objects, d1 and 2, if ( d1 < d2 )

p: d1.feet < d2.feetq: d1.feet == d2.feeta: d1.inches < d2.inchesb: d1.inches == d2.inchesc: d1.inches > d2.inches

false

false

false

false

false

true

true

true

true

d1 < d2d2.inchesd1.inchesd2.feetd1.feet

<<

<

<

<

<=

==

=

==>>>

>

>

>

Page 10: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 10

Binary Expressions in C++ Part2(Cont’d)

bool Distance::operator < ( const Distance& d2 ) const {return ( feet < d2.feet ) || (feet == d2.feet) && (inches < d2.inches);

}

p: d1.feet < d2.feetq: d1.feet == d2.feeta: d1.inches < d2.inchesb: d1.inches == d2.inchesc: d1.inches > d2.inches

p && a || p && b || p && c || q && a Distributive Law= p && (a || b || c ) || q && a !a = b || c= p && (a || !a ) || q && a Complement Law= p && T || q && a Theorem 6= p || q && a= ( d1.feet < d2.feet ) || ( d1.feet == d2.feet ) && (d1.inches < d2.inches)

Page 11: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 11

Conditional Propositions• Given two propositions such as p and q,

If p then q or p → q

is called a conditional proposition.– P: hypothesis, antecedent, or sufficient condition– Q: conclusion, consequent, or necessary condition

• if p then q ≡ p only if q: called logically equivalent.– John may take CSS342 only if he advances to CSS343.– If John takes CSS342, he advances to CSS343.

qp

Page 12: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 12

Truth Table of Conditional Propositions

• Chair statement: if CSS gets an additional $80,000, it will hire one new faculty member.

• P: CSS gets an additional $80,000.• Q: CSS will hire one new faculty member.• If both p and q are true, the chair said a correct statement.• If p is true but q is false, the chair said a wrong statement.• If p is false, the chair is not responsible for his statement. We

should regard it as true. p q p → qT T TT F FF T TF F T

Page 13: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 13

• Two propositions: P: 1 > 2 Q: 4 < 8

• According to the truth table, p → q is true, while q → p is false.

• C++ program:• What’s the execution result?

– Linux:• 1 > 2 -> 4 < 8: 8• 4 < 8 -> 1 < 2: 0

– Goodall• 1 > 2 -> 4 < 8: 0• 4 < 8 -> 1 < 2: 0

• It depends on how result1 wasinitialized.

• In math, we consider all initialized in true.

Binary Expressions in C++ Part3

void main( ) { bool result1; if ( 1 > 2 ) result1 = 4 < 8; cout << "1 > 2 -> 4 < 8: " << result1 << endl;

bool result2; if ( 4 < 8 ) result2 = 1 > 2; cout << "4 < 8 -> 1 > 2: " << result2 << endl;}

Page 14: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 14

Logical Equivalence• If two different compound propositions have the same

truth values no matter what truth values their constituent propositions have, they are called: – logically equivalent

• Example:– !(p || q) ≡ !p && !q (De Morgan’s Laws)

p q p || q !(p || q) !p !q !p && !q

T T T F F F F

T F T F F T F

F T T F T F F

F F F T T T T

Page 15: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 15

De Morgan’s Laws

• !(p || q) ≡ !p && !q– Proved by the truth page on the previous page.

• !(p && q) ≡ !p || !q

p q p && q !(p && q) !p !q !p || !q

T T T F F F F

T F F T F T T

F T F T T F T

F F F T T T T

Page 16: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 16

Biconditional Propositions• Given two propositions such as p and q,

p if and only if q p iff q or p ↔ qis called a conditional proposition.

• P: a necessary and sufficient condition for Q• Q: a necessary and sufficient condition for P

p q p ↔ qT T TT F FF T FF F T

Page 17: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 17

Biconditional Propositions Proof of the Truth Table

p q p → q q → p (p → q) && (q → p) p ↔ q

T T T T T T

T F F T F F

F T T F F F

F F T T T T

Page 18: CSS342: Propositions1 Professor: Munehiro Fukuda

CSS342: Propositions 18

Contrapositive

• !q →!p– The contrapositive of p → q– Logically equivalent

p q p → q !q !p !q →!pT T T F F TT F F T F FF T T F T TF F T T T T