Pythonexpr = And(Implies(have, eat), have)
print(simplify_logic(expr)) # eat & have
for vals, result in truth_table(expr, [have, eat]):
print(list(vals), '->', result)
have
eat
eat ∧ have
True
True
True
True
False
False
False
True
False
False
False
False
3 / 11
Limits of Truth Tables
Simplification through equivalences is often insufficient to obtain conclusive results:
Python — imports (run once)from sympy import symbols, Or, And, simplify_logic
from sympy.logic.boolalg import truth_table
from itertools import combinations
Pythona, b, c, d, e = symbols('a b c d e')
# BooleanCountingFunction[2, 5]: at least 2 of 5 are True
expr = Or(*[And(x, y) for x, y in combinations([a,b,c,d,e], 2)])
simplified = simplify_logic(expr)
print(simplified) # still complex
# Truth table: 2^5 = 32 rows — too large to inspect by hand
for vals, result in truth_table(simplified, [a, b, c, d, e]):
print(list(vals), '->', result)
With 5 variables a truth table has $2^5 = 32$ rows. Rules of inference provide a structured shortcut.
4 / 11
Rules of Inference
Each rule is written as a natural-deduction fraction: premises above the bar, conclusion below. Unlike equivalence, the conclusion is weaker than the premises.
$\dfrac{p,\;\; p \to q}{q}$
Modus Ponens
$\dfrac{\neg q,\;\; p \to q}{\neg p}$
Modus Tollens
3.$\dfrac{\neg p \to \neg q,\;\; q}{p}$Modus Tollens (H$_1$, 2)
4.$\dfrac{\neg p \vee r,\;\; p}{r}$Disjunctive Syllogism (H$_3$, 3)
5.$r$, i.e. $\exists x\, E(x)$conclusion $\square$
Python — entailment checkfrom sympy import symbols, And, Or, Not, Implies
from sympy.logic.inference import satisfiable
# Propositional abstractions of the existentials
p, q, r = symbols('p q r')
premises = And(
Implies(Not(p), Not(q)), # H1 : ¬p → ¬q
q, # H2 → q (after Existential Generalization on D(o))
Or(Not(p), r), # H3 : ¬p ∨ r
)
goal = r
# premises ⊨ goal iff premises ∧ ¬goal is unsatisfiable
print(satisfiable(And(premises, Not(goal))) is False) # True
10 / 11
Summary
The main rules of inference are modus ponens, modus tollens,
hypothetical syllogism, disjunctive syllogism,
addition, simplification,
conjunction and resolution.
Quantified rules of inference are universal instantiation,
universal generalization, existential instantiation
and existential generalization.
These rules make it easy to extract useful conclusions out of compound propositions.
You should now have a good understanding of logic.
The next lesson goes beyond true/false values — onward with sets.