Exercises · Python lambdas + Z3 · Topics: predicates, universal quantifier ∀, existential quantifier ∃, negation of quantifiers, nested quantifiers, region membership
Pr. Zouhair el Hadiq
Define a predicate $P(x)$: "$x$ is even" as a Python lambda over the domain $\{1, 2, \ldots, 10\}$.
Check whether $\forall x \in D,\; P(x)$ holds by testing every element of the domain $D = \{1, 2, 3, 4, 5\}$.
all(P(x) for x in domain) and next(x for x in domain if not P(x)).Check whether $\exists x \in D,\; P(x)$ holds over the domain $D = \{-5, -4, \ldots, 5\}$.
any(P(x) for x in domain) and next(x for x in domain if P(x), None).Use Z3 to reason about universal quantification over the real numbers.
z3.prove(ForAll([x], x**2 >= 0)).Solver.model.Use Z3 to determine the satisfiability of $\exists x,\; x^2 = 2$ in two different domains:
z3.Real('x') — expected result: sat (since $x = \sqrt{2}$).z3.Int('x') — expected result: unsat (no integer solution).What does this demonstrate about the importance of the domain in quantified statements?