Z3 encode
opulse.solver.z3_encode ¶
Encode operators as z3 terms following docs/reference/semantics.md (exact mode).
A value is a pair :class:ZVal (defined, value): defined is a z3 Bool
that is false exactly when the spec gives NaN, value a term of the
operator's result sort that matters only when defined holds.
Division and remainder truncate toward zero
(z3's own / and % are Euclidean and must not be used directly).
Every base operation is encodable when the semantics has a bound B: all
values then lie in [-B, B], so @ (reverse), & (digit sum) and $
(popcount) are encoded exactly by a fixed number of decimal digits / bits,
each a division by a constant. Without a bound only + - * / % neg # are
encoded; :meth:Z3Encoder.expressible says which operators qualify.
Recursion is unrolled. By the termination argument of spec section 4.1 a
template-A operator unfolds at most m - 1 times and a template-B operator
at most T times, so unrolling one level further than that is exact; the
tests compare the encoding with the reference interpreter to confirm it.
Z3Encoder ¶
recursion_control ¶
recursion_control(
definition: Definition,
) -> tuple[str, ast.Expr, int | None]
(loop variable, control expression, span of the control value) for the two templates.
recursion_depth ¶
recursion_depth(definition: Definition) -> int
Maximum number of self-calls for the two recursive templates (spec 4.1).
evaluate_concrete ¶
evaluate_concrete(
encoder: Z3Encoder, operator: Operator, args: tuple
) -> object
Evaluate an expressible encoding on concrete typed inputs.