Impact
LogicVerifier.prove_theorem returns VERIFIED ("theorem proved") for statements that are false. A true statement of the same kind is BLOCKED. The cause is that numeric literals are evaluated by Python before Z3 sees them:
1/3becomes the float0.333...;0.1 + 0.2becomes0.30000000000000004;7/2becomes3.5.
Meanwhile, the same operator applied to a Z3 variable stays exact (Real) or integer division (Int). The two sides of one formula therefore use different arithmetic.
| Call | 8.0.0 | Correct |
|---|---|---|
prove_theorem({"x": "Real"}, ["x == 1/3"], "3 * x != 1") |
VERIFIED | false over the reals |
prove_theorem({"x": "Real"}, ["x == 0.1 + 0.2"], "x != 0.3") |
VERIFIED | false over the reals |
prove_theorem({"x": "Int"}, ["x == 7"], "x / 2 != 7 / 2") |
VERIFIED | false under any single definition of / |
prove_theorem({"x": "Real"}, ["3 * x == 1"], "x == 1/3") |
BLOCKED (counterexample x = 1/3) |
true |
The DSL compiler used by POST /verify/logic has the same mismatch: (AND (EQ x 7) (NEQ (DIV x 2) (DIV 7 2))) compiles to And(x == 7, ToReal(x/2) != 7/2), which is satisfiable, so a contradictory constraint set is reported as consistent.
This is the same class as GHSA-mfh5-3c8f-975p (Python semantics silently replacing Z3 semantics) with a different root cause.
The integer-division semantics themselves (Z3 is Euclidean, so -7/2 == -4) are a documented-behaviour question tracked publicly in #537. This advisory is about the inconsistency inside one formula, which proves false statements under any semantics.
Affected
qwed (PyPI) through 8.0.0. Reproduced on main @ 10f5627 (unchanged since 8.0.0).
Reachable from:
- the
LogicVerifierPython API:prove_theoremreturns the falseVERIFIEDresults above; - the DSL path of
POST /verify/logic; - consensus logic checks (
ConsensusVerifierusesLogicVerifier).
The same mismatch makes check_equivalence({"x": "Real"}, "3 * x == 1", "x == 1/3") return BLOCKED (not equivalent) and verify_logic({"x": "Real"}, ["x == 1/3", "3 * x == 1"]) return UNVERIFIABLE (unsatisfiable). Both answers are wrong, but they fail closed.
Reproduction
from qwed_new.core.logic_verifier import LogicVerifier
lv = LogicVerifier()
for variables, premises, conclusion in [
({"x": "Real"}, ["x == 1/3"], "3 * x != 1"),
({"x": "Real"}, ["x == 0.1 + 0.2"], "x != 0.3"),
({"x": "Int"}, ["x == 7"], "x / 2 != 7 / 2"),
({"x": "Real"}, ["3 * x == 1"], "x == 1/3"),
]:
print(conclusion, lv.prove_theorem(variables, premises, conclusion).status.value)
# VERIFIED, VERIFIED, VERIFIED, BLOCKED
Details
src/qwed_new/core/safe_evaluator.py, line 176: the validated AST is evaluated with Pythoneval. Sub-expressions made only of Python numbers are computed by Python (true division and binary floating point) before any Z3 object is involved. Only sub-expressions containing a Z3 variable become Z3 terms.src/qwed_new/core/dsl/compiler.py, around lines 298 and 410:DIVon two numeric literals produces a Python or Z3 rational, whileDIVon anIntvariable produces Z3 integer division, which is then coerced withToReal.
Patches
Fixed in 9.0.0 (88b9330). Upgrade to 9.0.0 or later.
- Number literals no longer go through Python floats. A decimal literal is the exact value written (
0.1is1/10), and/,%and**on numbers are computed exactly. - Next to
Intvariables, a division of two numbers whose result is not whole is refused, since it is unclear whether integer or real division was meant. AnIntterm is never divided by aRealterm or coerced withToReal; the formula is refused instead. Arithmetic on a Boolean is refused. - In the DSL,
DIVof two integer literals is integer division, likeDIVof anIntvariable.
On 9.0.0 the first two rows of the table are BLOCKED, the third is refused (Division of two numbers is not whole next to Int variables), and the true statement in the fourth row is VERIFIED. The DSL constraint set above compiles to an unsatisfiable formula.
Integer division and modulo keep Z3's Euclidean semantics (see #537).
Source
Internal correctness audit (October 2026). Not previously disclosed.
