CSS342: Propositions
Professor: Munehiro Fukuda
CSS342: Propositions
1
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)
CSS342: Propositions
2
Propositions
•
Examples:
–
In math
1.
2.
–
In history
1.
2.
–
The only positive integers that divide 7 are 1 and 7 itself: (true)
For every positive integer n, there is a prime number larger than n:
(true)
Alfred Hitchcock won an Academy Award in 1940 for directing
“Rebecca”: (false, he has never won one for directing)
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
CSS342: Propositions
3
Compound propositions
• Conjunction of p and q
– notations: p ^ q, p && q
– True only if both p and q are true
– truth table
p
q
p^q
F
F
F
F
T
F
T
F
F
T
T
T
p
q
pvq
F
F
F
F
T
T
T
F
T
T
T
T
• Disjunction of p or q
– Notations: p v q, p || q
– True if either p or q or both are true
– truth table
CSS342: Propositions
4
Binary Expressions in C++ Part1
• How do you examine the behavior of if-else?
– if ( a > = 1 && a <= 100 )
• true if 1 ≤ a ≤ 100
condition
proposition
a<1
1 <= a <= 100 100 < a
a >= 1
false
true
true
a <= 100
true
true
false
– if ( a >= 1 || a <= 100 )
• always true
condition
proposition
a<1
1 <= a <= 100 100 < a
a >= 1
false
true
true
a <= 100
true
true
false
CSS342: Propositions
5
Negation
• The negation of p
– Notations: p, not p, ¬p !p
– Truth table:
• Example:
P
!p
F
T
T
F
– P: 1 + 1 = 3 (false)
– !p: !(1 + 1 = 3) ≡ 1 + 1 ≠ 3 (true)
CSS342: Propositions
6
Boolean Algebra (Axioms)
When T = true and F = false:
1. If p ≠ F then p = T,
If p ≠ T then p = F
2. F &&F = F,
T || T = T
3. T && T = T,
F || F = F
4. F && T = T && F = F
5. F || T = T || F = T
6. !T = F,
!F = T
CSS342: Propositions
7
Boolean Algebra (Theorems)
When T = true and F = false:
•
•
•
•
•
•
•
•
•
•
Commutative Law
p && q = q && p,
Associative Law
(p && q) && r = p && (q && r),
Distributive Law
(p || q) && (p || r) = p || q && r,
p && F = F,
p && T = p,
Complement Law
p && !p = F,
Square Law
p && p = p,
Absorption Law
p && (p || q) = p,
Double Negation
!(!p) = p
Consensus Law
p + q && !p = p + q
p || q = q || p
(p || q ) || r = p || (q || r)
p && q || p && r = p && (q || r)
p || T = T
p || F = p
p || !p = T
p || p = p
p || p && q = p
CSS342: Propositions
8
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 )
d1.feet
d2.feet
<
<
<
=
=
=
>
>
>
d1.inches
d2.inches
<
=
>
<
=
>
<
=
>
d1 < d2
true
true
true
true
false
false
false
false
false
CSS342: Propositions
p: d1.feet < d2.feet
q: d1.feet == d2.feet
a: d1.inches < d2.inches
b: d1.inches == d2.inches
c: d1.inches > d2.inches
9
Binary Expressions in C++ Part2
(Cont’d)
p: d1.feet < d2.feet
q: d1.feet == d2.feet
a: d1.inches < d2.inches
b: d1.inches == d2.inches
c: 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)
bool Distance::operator < ( const Distance& d2 ) const {
return ( feet < d2.feet ) || (feet == d2.feet) && (inches < d2.inches);
}
CSS342: Propositions
10
Conditional Propositions
• Given two propositions such as p and q,
If p then q
or
p→q
is called a conditional proposition.
q
p
– 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.
CSS342: Propositions
11
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→q
T
T
T
T
F
F
F
T
T
F
F
T
CSS342: Propositions
12
Binary Expressions in C++ Part3
• Two propositions:
P: 1 > 2
Q: 4 < 8
• According to the truth table,
p → q is true, while q → p is false.
• C++ program:
void main( ) {
bool result1;
• 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
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;
• It depends on how result1 was
}
initialized.
• In math, we consider all initialized in true.
CSS342: Propositions
13
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
CSS342: Propositions
14
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
CSS342: Propositions
15
Biconditional Propositions
• Given two propositions such as p and q,
p if and only if q
or p ↔ q
p iff q
is called a conditional proposition.
• P: a necessary and sufficient condition for Q
• Q: a necessary and sufficient condition for P
p
T
T
q
T
F
p↔q
T
F
F
F
T
F
F
T
CSS342: Propositions
16
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
CSS342: Propositions
17
Contrapositive
• !q →!p
– The contrapositive of p → q
– Logically equivalent
p
T
T
F
F
q
T
F
T
F
p→q
T
F
T
T
!q
F
T
F
T
CSS342: Propositions
!p
F
F
T
T
!q →!p
T
F
T
T
18
© Copyright 2026 Paperzz