Lesson 1 of 15
Propositional Logic
The Algebra of True and False
Propositional logic is the foundation of mathematical reasoning. A proposition is any statement that is either true or false. We combine propositions using logical connectives:
| Symbol | Name | Meaning |
|---|---|---|
| Negation | not p | |
| Conjunction | p and q | |
| Disjunction | p or q | |
| Implication | if p then q | |
| Biconditional | p iff q |
A tautology is a formula that is true for every assignment of truth values. A contradiction is always false. A satisfiable formula is true for at least one assignment.
De Morgan's Laws are fundamental:
# Check De Morgan's first law
def check_tautology(expr):
for p in [True, False]:
for q in [True, False]:
if not expr(p, q):
return False
return True
demorgan = lambda p, q: (not (p and q)) == (not p or not q)
print(check_tautology(demorgan)) # True
Your Task
Implement:
check_tautology(expr)— returnsTrueif the 2-variable boolean function is a tautologycount_satisfying(expr, n_vars)— returns how many truth assignments satisfyexpr
Pyodide loading...
Loading...
Click "Run" to execute your code.