Propositional Logic
Propositional Logic studies:
- Propositions
- Logical connectives that build larger propositions from smaller ones
Logic allows us to determine if a large proposition is true
or false
based on
how it is constructed and the truth value of the smaller pieces.
Proposition
A proposition is a statement that is either true
or false
.
Examples of propositions:
- "I like Dan" is
true
. - "All humans are mortal" is
true
. - is
false
.
Atomic and Compound Propositions
Compound propositions are composed of two or more atomic propositions. Atomic proposition cannot be broken down.
- "It is raining" is atomic.
- "It is raining and cloudy" is a compound proposition. It contains two propositions "It is raining" and "It is cloudy".
- "If I hit my head then it will hurt" is compound. It contains the propositions "I hit my head" and "my head will hurt".
Logical Operators
Compound propositions can be built by atomic propositions and logical operators (also called logical connectives). Some common operators:
Operator | Symbol |
---|---|
NOT | |
AND | |
OR | |
XOR | |
IF...THEN | |
IF AND ONLY IF |
IF..THEN
" implies " stands for "if then ".
is logically equivalent to .
Use vending machine example to memorize this truth table.
- is the 💵.
- is the 🍗.
IF AND ONLY IF
is a shorthand for
If both operands are the same then it is true
. Otherwise it is false
.
Formula
To find the truth value of a formula:
- Fill in the truth value for all variables.
- Evaluate logical connectives from innermost parentheses outwards.
When and
Formula Classification
Classification | Always true | Sometimes true | Always false |
---|---|---|---|
Tautology | ✅ | ❌ | ❌ |
Contradiction | ❌ | ❌ | ✅ |
Contingent | ❌ | ✅ | ❌ |
Satisfiable | ✅ | ✅ | ❌ |
def classify(func):
propositions = [True, False]
results = []
for p in propositions:
for q in propositions:
results.append(func(p, q))
num_elements = len(results)
num_T = 0
num_F = 0
for result in results:
if result == True:
num_T += 1
else:
num_F += 1
if num_T == num_elements:
# if all True -> Tautology
return "Tautology"
elif num_F == num_elements:
# if all False -> Contradiction
return "Contradiction"
else:
# can be T or F -> Contingent
return "Contingent"
Tautology
Always true
. And also satisfiable.
Contradiction
Always false
. NOT satisfiable.
Contingent
Can be true
or false
depending on the variables. Also satisfiable.
Have a look at the truth table of .
Satisfiable
Satisfiable formulas are either tautologies or contingent formulas.
Logical Equivalence
Some formulas are logically equivalent meaning that they are always the same given any variables.
In other words, two statements are logically equivalent if, and only if, their resulting truth tables are identical for each variation of variables.
e.g. is logically equivalent to .
So we can write .
Saying is the same as saying that is a tautology.
def test_logical_equivalence(func_1, func_2):
propositions = [True, False]
for p in propositions:
for q in propositions:
if func_1(p, q) != func_2(p, q):
print("Not logically equivalent")
return False
print("Logically equivalent")
return True