Implementation:2akouwu Reverify prove expr equiv
| Knowledge Sources | |
|---|---|
| Domains | Formal_Verification, SMT_Solving |
| Last Updated | 2026-10-24 12:00 GMT |
Overview
Concrete tool for proving two integer expressions equal for all inputs using Z3 bit-vector logic, returning "proven", "refuted" with counterexample, or "inconclusive", provided by the Reverify library.
Description
The prove_expr_equiv function translates two integer expressions into Z3 bit-vector terms and asks the solver to check if they can differ. If the inequality is UNSAT, the expressions are proven equivalent for all inputs. If SAT, the solver model is a concrete counterexample. If the solver returns unknown, the result is inconclusive. Requires Z3 (pip install z3-solver).
Usage
Import this function when you need to:
- Prove two integer expressions are equivalent for all inputs (not just a sample).
- Get a concrete counterexample when expressions differ.
- Run the
reverify equivCLI subcommand for proof-grade checks.
Code Reference
Source Location
- Repository: Reverify
- File: reverify/behavior.py
- Lines: L331-361
Signature
def prove_expr_equiv(
expr_a: str,
expr_b: str,
nvars: Optional[int] = None,
bits: int = 64,
) -> Dict[str, Any]:
"""Prove two integer expressions equal for ALL inputs using Z3.
Returns {status: 'proven'|'refuted'|'inconclusive', counterexample?, detail}."""
Import
from reverify.behavior import prove_expr_equiv
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| expr_a | str | Yes | First integer expression (over x0, x1, ...) |
| expr_b | str | Yes | Second integer expression |
| nvars | int | No | Number of variables (default: auto-detected) |
| bits | int | No | Bit width (default 64) |
Outputs
| Name | Type | Description |
|---|---|---|
| status | str | "proven" / "refuted" / "inconclusive" |
| counterexample | Dict | On refuted: {x0: val, x1: val, ...} |
| detail | str | Human-readable summary |
Usage Examples
Prove Commutativity
from reverify.behavior import prove_expr_equiv
result = prove_expr_equiv("x0 + x1", "x1 + x0")
print(result["status"]) # "proven" — equivalent for all inputs
Find a Counterexample
result = prove_expr_equiv("x0 - x1", "x1 - x0")
if result["status"] == "refuted":
print(f"Counterexample: {result['counterexample']}")
# e.g. {'x0': '0x0', 'x1': '0x1'}
CLI Usage
reverify equiv --prove "x0*x1" "x1*x0"
# Prints "proven"; exits 0