Simplifying Conditionals
if i or not o:
if not (o and q):
C1
else:
if o and not q:
C2
else:
C3
else:
C4
Truth table:
i | o | q | Action |
---|---|---|---|
T | T | T | C3 |
T | T | F | C1 |
T | F | T | C1 |
T | F | F | C1 |
F | T | T | C4 |
F | T | F | C4 |
F | F | T | C1 |
F | F | F | C1 |
C2 is never executed. It's dead code.
To prove that it's dead code, we can use a Transformational Proof.
C2 is executed when
Proof
Prove:
proof
Since it's a contradiction, the set of conditions leading to C2 is inconsistent.
Simplified code:
if i and o and q
C3
else:
if (not i and o):
C4
else:
C1