Skip to main content

eqtheory

A Python library for equational theories over magmas: given two equations in one binary operation ◇, decide whether the first implies the second — and hand back a Lean 4 certificate either way.

  • term rewriting with a ground Knuth–Bendix order, one-way matching, unification,
  • a proof-producing e-graph (congruence closure with a proof forest, shortest shared explanations) and equality saturation,
  • ordered completion and goal-directed superposition with replayed proof chains, interreduction and node budgets,
  • finite countermodels: symbolic linear families, structured tables, a complete propagating cell search and a CDCL SAT search with symmetry breaking (exhaustion verdicts are proofs),
  • infinite countermodels on ℕ for Austin pairs (true in every finite magma, false in general),
  • Lean 4 certificates for every answer, in the shapes accepted by the SAIR Stage-2 judge, with an optional compile check,
  • an optional, hygienic LLM stage with a configurable prompt,
  • a CLI with e-graph and proof visualisation (SVG/PNG/DOT).

The algorithms are those of the SAIR Stage-2 solver (800/800 practice, see the paper in osick/SAIR-callenges), re-packaged with a clean API. Pure Python 3.11+, no required dependencies.

pip install -e .            # from this directory
pip install -e ".[viz,dev]" # graphviz bindings, pytest

Quick start

from eqtheory import Problem, solve

p = Problem.parse("x = y ◇ (x ◇ y)", "x = (x ◇ y) ◇ x")
ans = solve(p)
print(ans.verdict, ans.stage)   # "true" / "false", which engine decided
print(ans.code)                 # the Lean 4 certificate

Each engine is a plain function:

from eqtheory import prove_by_superposition, find_countermodel, residue_affine_countermodel, prove_goal
from eqtheory.lean import certs

pr = prove_by_superposition(p.hypothesis, p.goal)       # lemma + instantiation + derived set
cm = find_countermodel(p.hypothesis, p.goal, time_budget=60)   # Countermodel(n, table) or None
nm = residue_affine_countermodel(p.hypothesis, p.goal)  # ℕ model for Austin pairs
eg, l, r = prove_goal(p.hypothesis, p.goal)             # e-graph with the goal sides merged
lemmas, chain = eg.explain(l, r)                        # shared proof, replayable
eg.render("egraph.svg", highlight=(l, r))               # picture

Command line

eqtheory solve "x = y ◇ (x ◇ y)" "x = (x ◇ y) ◇ x"                # full ladder, prints certificate
eqtheory solve --lean --json ...                                # certificate compiled with Lean
eqtheory prove ...                                              # superposition only
eqtheory model --infinite --cert ...                            # countermodels, finite then ℕ
eqtheory egraph --render egraph.svg --lemmas ...                # saturate and draw the e-graph
eqtheory viz-proof --out proof.dot ...                          # the extracted proof as a graph
eqtheory cert --table "[[0,1],[1,0]]" ...                       # wrap a table as a certificate

--lean needs EQTHEORY_LEAN_BIN (a Lean 4.33 binary) and EQTHEORY_JUDGE_ROOT (a built checkout of the Stage-2 judge library) or EQTHEORY_LEAN_PATH. --llm needs OPENROUTER_API_KEY.

Documentation

  • User guide — the pipeline, budgets, composing your own ladder
  • Mathematical background — the theory behind each engine, with references
  • Certificates — the Lean shapes and the proof-policy lessons
  • API overview
  • Limitations — theoretical and pragmatic
  • Releasing — moving to its own repository, CI, tags, PyPI
  • examples/single_file_solver.py — a complete solver in 60 lines
  • artifacts/ — sample renderings and benchmark reports

Status

Version 0.1.0 (2026-09-01). Tests: python -m pytest (70 tests; the Lean end-to-end test is skipped unless Lean is configured). Benchmark (2026-09-01, 200-problem Stage-2 stress set, every certificate compiled with Lean, LLM never needed): 200/200 correct — see artifacts/bench-stress-2026-09-01/REPORT.md.

Limitations (short form)

Implication between magma laws is undecidable; every engine is budgeted, so "no answer" is not a verdict. Finite search is complete per size but cannot see infinite-only countermodels beyond the ℕ residue-class family; table certificates stop at Fin 10 (affine models go further); grind certificates are Lean-version-sensitive; the compile check is not the competition judge; the LLM stage adds hygiene, not reach. Details and measurements: docs/limitations.md.

License: MIT.

Metadata

Release files for eqtheory 0.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for eqtheory 0.1.0
File Size Uploaded
eqtheory-0.1.0.tar.gz 57.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for eqtheory 0.1.0
File Interpreter ABI Platform
eqtheory-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 110.4 kB

Release files / eqtheory-0.1.0.tar.gz

Download URL eqtheory-0.1.0.tar.gz
Size 57.0 kB
Tags Source
SHA-256 checksum
How to use checksums
867e4cbde043deb8320c826e28b1b9045f3f6983ece1643e0202b851012893cf
BLAKE2b-256 checksum
How to use checksums
76b5f18f808ce8f229cf5505397778f25effdbeb4c55d9c00cae769a5d6f63c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

Release files / eqtheory-0.1.0-py3-none-any.whl

Download URL eqtheory-0.1.0-py3-none-any.whl
Size 53.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bebedc60ded0b7e299b46521e46391dbe6175c8f98ab772feb1edf6d4f8284d0
BLAKE2b-256 checksum
How to use checksums
8391ab5c51995192847f03d4b6a71b88f559f9443697db9e011b80cbafd1acec
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 1, 2026.

Transparency log

Release history Release notifications | RSS feed

0.3.1

2 release files

0.3.0

2 release files

0.2.0

2 release files

This release

0.1.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page