Python# Predicate: (x + 2 > 4) => (x + 3 < 4)
pred = Implies(x + 2 > 4, x + 3 < 4)
# Evaluate for x = 2 and x = 3
results = [pred.subs(x, v) for v in [2, 3]]
print(results) # [True, False]
3 / 10
Example: Pythagorean Triple
Consider the proposition $p:\; x^2 + y^2 = z^2$
Python# Define the predicate as a Python lambda
p = lambda x, y, z: x**2 + y**2 == z**2
# What is the truth value for x=5, y=12, z=13?
print(p(5, 12, 13)) # True
# What is the truth value for x=160, y=241, z=290?
print(p(160, 241, 290)) # False
To learn more about this equation, read about Pythagorean triples.
4 / 10
Universal Quantifier $\forall$
Universal quantification is the proposition: "$P(x)$ is true for all values of $x$."
No one is perfect.
$$\neg\,\exists x\;\mathrm{Perfect}(x)$$
Not all propositions are contradictions.
$$\neg\,\forall x\;\mathrm{Contradiction}(x)$$
In my second-year class, only one person knew Java, SQL and Python.
$$\exists!\,x\;\bigl(\mathrm{Java}(x) \wedge \mathrm{SQL}(x) \wedge \mathrm{Python}(x)\bigr)$$
9 / 10
Summary
Predicates are propositional functions with parameters.
There are three quantifiers: Universal ($\forall$), Existence ($\exists$) and Uniqueness ($\exists!$).
Z3 directly mirrors ForAll, Exists:
Universal: prove(ForAll([x], ...))
Existence: Solver().check() → sat / unsat
So far, propositions were taken as is.
The next lesson allows for analysis of propositions through rules of inference.
Python — key imports for this lessonfrom sympy import symbols, Implies # propositional predicates
from z3 import Real, Reals, ForAll, Exists, And, Not, Implies as Imp
from z3 import Solver, prove # quantifiers