"""Executable examples for Chapters 9 and 10 (SymPy and Z3). Run from the repository root with the locked environment: uv run python content/examples/math/tool-chapters/ch09_10_sympy_z3_demo.py Illustrative teaching script. It is not an evidence-bundle producer; the engine's recorded results come from src/math_engine/adapters/. """ import sympy import z3 from sympy import expand, factor, simplify, sqrt, symbols, together print("sympy", sympy.__version__, "z3", z3.get_version_string()) # --- Chapter 9: SymPy ------------------------------------------------------- v = symbols("v", real=True) gamma = 1 / sqrt(1 - v**2) residual = simplify(together(gamma**2 * (1 - v**2) - 1)) print("ch9 gamma residual (symbolic v):", residual) print("ch9 same residual at v=2 (outside |v|<1):", simplify(residual.subs(v, 2))) print("ch9 gamma^2(1-v^2)-1 at v=2 directly:", simplify((gamma**2 * (1 - v**2) - 1).subs(v, 2))) t, x, g = symbols("t x gamma", real=True) boost = expand((g * (t - v * x)) ** 2 - (g * (x - v * t)) ** 2 - (t**2 - x**2)) print("ch9 algebraic residual, factored:", factor(boost)) tt, xx, vv = symbols("t x v", real=True) print("ch9 shear residual, factored:", factor(tt**2 - (xx + vv * tt) ** 2 - (tt**2 - xx**2))) # --- Chapter 10: Z3 --------------------------------------------------------- T, X, V, G = z3.Reals("t x v gamma") goal_negation = (G * (T - V * X)) ** 2 - (G * (X - V * T)) ** 2 != T * T - X * X with_hyp = z3.Solver() with_hyp.add(G * G * (1 - V * V) == 1) with_hyp.add(goal_negation) print("ch10 negation WITH gamma hypothesis:", with_hyp.check()) no_hyp = z3.Solver() no_hyp.add(goal_negation) print("ch10 negation WITHOUT gamma hypothesis:", no_hyp.check()) print("ch10 model:", no_hyp.model())