ArchytasZX
Prove identities of quantum algorithms without fixing the size or dimensionality of the
machine. Write a circuit once as a ZX diagram, for n qudits of dimension d, and get
rewrites, decisions of equality and proofs that hold for every n and every d at once.
ArchytasZX is a symbolic engine for the qufinite ZX(W)-calculus. Qudit count, dimension and multiplicities are symbols, so nothing is ever enumerated, sampled or simulated: every rewrite, decision and proof holds for every size at once. Its rules contain the complete ZXW axiomatisations of Poór et al. and Wang et al., and its proofs are exported to Lean 4 as theorems about the diagrams themselves, so the engine is untrusted: Lean re-checks every proof it exports. To write algorithms in Dirac notation instead of diagrams, see its sister project DiracULA.
Reproducing the paper
ArchytasZX: Certified ZXW Rewriting with Symbolic Size and Dimension uses GHZ-state preparation
as its running example. Both forms of Figure 1 are in examples/:
$ pip install 'archytaszx>=2.0'
$ git clone https://github.com/Arhip-Dmitriev/ArchytasZX.git && cd ArchytasZX
$ archytaszx --unicode examples/ghz_proof.azx # native script, about 2 s
...
decide: equal by normal_form: normal forms agree; no oracle mismatch in 16 sample(s)
proof: re-checkable; certificate kernel / certificate lean
emitted certificate: kernel theorem, 16 inferences
...
lean: tensor-network semantics, every step proved
lean: wrote ghz.lean
$ python examples/ghz_proof.py # Python library, same verdict and proof
To re-check ghz.lean in Lean, install elan, then build
the bundled library once (prebuilt Mathlib is downloaded) and check the file:
$ cd archytaszx/lean && lake exe cache get && lake build
$ lake env lean ../../ghz.lean # no output and exit code 0 mean the proof checks
The other examples prove the qudit Deutsch–Jozsa and Bernstein–Vazirani circuits
(deutsch_jozsa_proof.azx, bernstein_vazirani_proof.azx), prove a family by induction
(copy_induction.azx) and refute false claims with Lean counterexamples (refutations.azx).
Example: Deutsch–Jozsa for every n and every d
examples/deutsch_jozsa_proof.azx
writes the qudit Deutsch–Jozsa circuit as ZXW diagrams, with the register a bang box of
symbolic multiplicity, and proves that it returns e^{2πi c/d} |0⟩^⊗n ⊗ F†|1⟩ for the constant
oracle and |0⟩^⊗(n-1) ⊗ |1⟩ ⊗ F†|1⟩ for the balanced one:
$ archytaszx --unicode examples/deutsch_jozsa_proof.azx
...
decide: equal by symbolic_contraction: symbolic contractions agree: entries are exactly equal with d formal
proof: re-checkable; certificate kernel / certificate lean
lean: tensor-network semantics, the normal form computed by the Lean kernel
lean: wrote deutsch_jozsa_constant.lean
...
decide: equal by symbolic_contraction: symbolic contractions agree: entries are exactly equal with d formal
...
lean: wrote deutsch_jozsa_balanced.lean
Both equalities hold for every n and every d, and both are written out as Lean 4 files.
What it does
- Symbolic size. Qudit count, dimension and multiplicities stay symbols.
|0>^@30is one leg under a bang box, not thirty, and a concrete value is substituted into the closed form at the end at no cost in its size. - Exact arithmetic. Scalars are tracked exactly (roots of unity, character sums, Gauss sums); no global factor is ever dropped, so results are equalities, not proportionalities.
- Proofs for all
n. Diagram rewriting, a normal-form procedure, equality saturation and proof search decide equalities; induction over bang-box multiplicities proves whole families. - A complete rule set. Every axiom of qudit ZXW (Poór et al., LICS 2023) and qufinite ZXW
(Wang, Poór & Shaikh, 2023) is a rule, with Z spiders carrying phases or arbitrary complex
weights. Any two bang-box-free diagrams at concrete dimensions that denote the same map are
joined by a derivation, and
prove exhaustivefinds it, given enough time (docs/COMPLETENESS.txt). - Independent checking. Every proof emits a replayable certificate, is re-checked by a small proof kernel, and is exported to Lean 4 and Mathlib, where it is checked again from scratch.
Install
Python ≥ 3.12. numpy and sympy are the only runtime dependencies. With matplotlib
installed, ZX diagrams are drawn as images in terminals that show them; without it, they fall
back to Unicode text.
pip install archytaszx # or 'archytaszx[viz]' to add matplotlib
archytaszx # interactive shell
archytaszx commands.azx # run a command file
Quickstart
The shell
$ archytaszx --unicode -c 'load sum_{k=0}^{3-1} |k>^{30}; copy'
loaded dirac input
Σ_{k0,k1=0}^{d-1} [k0 = k1] |k0⟩^{n} |k1, k1⟩
at d = 3, n = 29: Σ_{k0,k1=0}^{3-1} [k0 = k1] |k0⟩^{29} |k1, k1⟩
The DSL reads as a circuit: declare nodes, then connect them with arrows.
$ archytaszx --unicode -c 'a = Z(0 -> 2) phase{1: alpha}; b = Z(1 -> 2); a -> b' \
-c 'apply spider_fusion'
loaded dsl input
Σ_{k0,k1=0}^{d-1} e^{2 π i (alpha [k0=1])} [k0 = k1] |k0, k1, k1⟩
step: spider_fusion (consumed n0, n1, new n2, scalar 1)
result:
Z_{0->3}(1: alpha) = Σ_{k=0}^{d-1} e^{2 π i (alpha [k=1])} |k, k, k⟩
A command file spans a diagram over indented lines;
examples/deutsch_jozsa_proof.azx
writes n data qudits as repeat n: X(0 -> 1) -> F^4.
Diagrams are loaded in a DSL, in Dirac notation or as a graph listing, then rewritten,
normalised, decided and proved with commands such as apply, normalize, decide, prove,
prove exhaustive and induct; help lists them all. --zx, --both and --raw switch between Dirac notation
and ZX drawings. The reference is
docs/ENGINE_COMMANDS.txt.
From Python
azx builds diagrams with Python operators and runs the engine on them. The qudit
Deutsch–Jozsa circuit with a constant oracle, proved for every n and d:
from archytaszx import azx
n, d = azx.count("n"), azx.d
data = (azx.F ^ 4 | azx.X(0, 1)) ** n # a !-box of n data qudits
target = azx.X(2, 1) | azx.F ^ 3 | azx.X(0, 1, phase="-k/d") # the target through U_f
circuit = data @ target * d ** (-n / 2)
goal = (azx.X(0, 1) ** n @ azx.Z(0, 1, phase="-k/d") @ azx.Z(1, 0, phase="k/d")) \
* d ** (-(n + 1) / 2)
azx.decide(circuit, goal).verdict # 'equal'
azx.lean("deutsch_jozsa.lean") # the Lean 4 theorem
a | b feeds b into a, @ is the tensor product, ** n repeats a piece in a !-box, ^ k
puts k copies in series and * scales. azx("...") runs any engine command.
The engine objects can also be used directly. Build two Z spiders over a symbolic dimension d, fuse them, check the rewrite, and prove it for
every count at once.
from archytaszx.algebra.dimension import Dim
from archytaszx.diagram.generators import Z_SPIDER
from archytaszx.diagram.graph import Diagram, Direction, PortRef
from archytaszx.rewrite.match import find_matches
from archytaszx.rewrite.engine import apply
from archytaszx.rewrite.rules_library import SPIDER_FUSION
d = Dim.symbol("d")
g = Diagram()
a = g.add_node(Z_SPIDER, input_dims=[], output_dims=[d, d])
b = g.add_node(Z_SPIDER, input_dims=[d], output_dims=[d, d])
g.add_wire(PortRef(a, Direction.OUTPUT, 0), PortRef(b, Direction.INPUT, 0))
g.set_boundary_outputs([
PortRef(a, Direction.OUTPUT, 1),
PortRef(b, Direction.OUTPUT, 0),
PortRef(b, Direction.OUTPUT, 1),
])
result = apply(g, SPIDER_FUSION, find_matches(g)[0])
len(result.diagram.nodes) # 1 -- two spiders became one
len(result.diagram.boundary_outputs) # 3 -- the boundary is unchanged
result.diagram.scalar # Scalar(1) -- exact, never discarded
A certificate records the derivation; verify replays it step by step, and tampering with any
recorded field (scalar, rule, consumed wire, side condition, multiplicity) fails the replay.
from archytaszx.semantics.check import compare
from archytaszx.semantics.certificate import certify, verify
compare(g, result.diagram, {"d": 5}).matched # True -- numeric oracle at d = 5
certificate = certify(g, [result], label="fuse A into B")
verify(certificate, {"d": 3}).verified # True
Wrap the graph in a bang box of multiplicity m and prove the fusion for every m, with d
still symbolic:
from archytaszx.diagram.bangbox import abstract_subgraph_count
from archytaszx.semantics.induction import prove_by_induction
boxed, box_id, mult = abstract_subgraph_count(g, frozenset({a, b}), 1, stem="m")
fused = apply(boxed, SPIDER_FUSION, find_matches(boxed)[0]).diagram
proof = prove_by_induction(boxed, fused, witness={"d": 2})
proof.proved # True
proof.verdict # Verdict.PROVED_UNIFORM -- for all m, not a finite schema check
proof.index # 'm'
proof.discharge # StepDischarge.UNIFORM_REWRITE -- the tier that settled the step
proof.held_symbolic # frozenset({'d'}) -- what stayed universally quantified
Concrete numbers typed by the user are abstracted back into symbols, with the values kept for
output; prefix a numeral with literal to keep it concrete:
from archytaszx.repl.parser import parse_dirac_source
p = parse_dirac_source("sum_{k=0}^{3-1} |k>^{30}; copy")
dict(p.parameters) # {'d': 3, 'n': 29}
Documentation
The full reference documentation is in docs/:
| Document | Contents |
|---|---|
INDEX.txt |
Index of the documentation, conventions and reading order |
OVERVIEW.txt |
What the engine is, its guarantees and its limits |
INSTALL.txt |
Installation, the Lean library, configuration and environment variables |
SHELL.txt |
The archytaszx command: flags, views, shell commands, exit codes |
ENGINE_COMMANDS.txt |
The : engine commands and the diagram input forms |
PYTHON_API.txt |
The engine import map and a worked example |
ALGEBRA.txt |
Layer A: dimensions, phases, exact scalars |
DIAGRAM.txt |
Layer B: generators, diagrams, bang boxes, scalable notation, validation |
REWRITE.txt |
Layer C: rules, matching, strategies, normal form, e-graph, tactics |
RULES.txt |
Every rewrite rule with its scalar and side conditions |
SEMANTICS.txt |
Layer D: denotation, contraction, the oracle |
PROOFS.txt |
Deciding equality, proof search, induction, certificates, the kernel |
COMPLETENESS.txt |
The ZXW axioms as rules, the completeness argument, exhaustive search |
LEAN.txt |
The Lean 4 library and the export of proofs and refutations |
ERRORS.txt |
The exception hierarchy of every module |
GLOSSARY.txt |
Definitions of the terms used throughout |
Formal proofs in Lean
Proofs found by the engine are exported to Lean 4 (:certificate lean proof.lean) against a
Mathlib library bundled in archytaszx/lean, in which a diagram is a tensor network over ℂ and
every rewrite rule is a lemma proved once. Families over multiplicities become Lean
inductions, equalities the rewriter cannot reach are closed by a verified normaliser of
symbolic sums, and verdicts that two diagrams differ export a Lean refutation.
The final theorem of every export is stated over the engine's diagrams as data, with their
meaning defined directly in Lean, and, for diagrams written in a command file, over the text of
that file, parsed and elaborated inside Lean. Python only proposes: if it builds a wrong network
or a wrong diagram, Lean rejects the file. #print axioms lists only propext,
Classical.choice and Quot.sound. The trusted base is the Lean kernel, Mathlib, and the Lean
definitions of the generators, of diagram evaluation and bang-box expansion, and of the
command-file parser.
cd archytaszx/lean && lake exe cache get && lake build # once
lake env lean /path/to/proof.lean
docs/LEAN.txt has the
semantics, the trust boundary, the normaliser and the refutation method.
Architecture
Four engine layers, depending strictly downward, with the shell on top:
| Layer | Package | Contents |
|---|---|---|
| A | algebra |
Dimension expressions with one canonical form and a unifier; phase and complex-weight vectors tied to d; exact scalars over roots of unity with a character-sum simplifier |
| B | diagram |
Qufinite ZXW generators (Z, X, Fourier box, triangle, W, dimension binder/splitter) with per-port dimensions; bang boxes and scalable sheet wires; validation |
| C | rewrite |
Rule library with the qudit and qufinite ZXW axioms as rules, matcher and engine with provenance; normal form; diagram-level e-graph; tactics, bidirectional and exhaustive proof search |
| D | semantics |
Symbolic and numeric contraction; the decide_equal ladder; induction; certificates, proof kernel and Lean export |
| — | repl |
Diagram parser and printer, ZX drawing, engine commands, shell |
The package and sub-package __init__.py files export nothing, so engine objects are imported
by full module path. Each module raises only its own
<Area>Error hierarchy: <Area>GrammarError for a wrong call and <Area>DomainError for a case
not implemented yet.
Status
In beta and under active development: the API is unstable and changes between
releases. The automatic decision procedure is sound but not complete, so decide and prove
can answer "unknown"; prove exhaustive is guaranteed to terminate only on equal inputs in the
complete fragment (no bang boxes, concrete dimensions), and has no depth or time cap. Known
limits:
- Symbolic contraction slows sharply as the number of phased spiders grows.
- Symbolic contraction refuses a bang box wired to a node outside it, and a port box over two W nodes.
- The dimension unifier reports
DEFERREDwhere an equation has several solution branches (d1*d2 == 6,d**n == d**m); deferred dimensions are recorded as assumptions and appear in certificates and Lean theorems as hypotheses. - A rule restricted to prime
drefuses to fire at a symbolicd. compare_symbolichas three outcomes (equal, unequal, indeterminate); read.reasonwhen it does not match.- Every rule is a proved Lean lemma. A few verdicts reached only by symbolic contraction (evaluated quadratic Gauss sums, phases with a symbolic coefficient, scalars outside the exact model) have no Lean proof path.
Development
git clone https://github.com/Arhip-Dmitriev/ArchytasZX.git
cd ArchytasZX
python -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]'
python -m pytest -n 8 # default tier
python -m pytest -m slow # fuzz sweeps and oracle differentials
ruff format . && ruff check . && mypy archytaszx
CI runs both tiers (pytest -m "" -n auto) on Python 3.12, 3.13 and 3.14. On 2026-10-30 every
version gave 14,399 passed and 294 skipped, with no failures. ruff format is
authoritative for layout; mypy runs in strict mode.
Citation
If you use ArchytasZX in academic work, please cite it via
CITATION.cff, or:
@software{dmitriev_archytaszx,
author = {Dmitriev, Arkhip Alekseyevich},
title = {{ArchytasZX}: Certified {ZXW} Rewriting with Symbolic Size and Dimension},
year = {2026},
url = {https://github.com/Arhip-Dmitriev/ArchytasZX},
license = {Apache-2.0}
}
Contributing
Bug reports, counterexamples and questions about the mathematics are the most useful
contributions; a soundness bug (a rewrite that changes the denoted map, scalar included) is the
most valuable report of all. See
CONTRIBUTING.md.
References
ArchytasZX builds chiefly on the qufinite ZX-calculus of Wang
(arXiv:2104.06429), the ZXW completeness results of Poór,
Wang et al. (arXiv:2302.12135,
arXiv:2309.13014), and bang boxes and scalable notation
(arXiv:2204.11702). Full BibTeX is in
REFERENCES.bib.
Full reference list
ZX-calculus, W node, qufinite ZX/ZXW
- Coecke & Duncan, Interacting quantum observables: categorical algebra and diagrammatics, NJP 13 (2011) — arXiv:0906.4725
- van de Wetering, ZX-calculus for the working quantum computer scientist — arXiv:2012.13966
- Hadzihasanovic, A diagrammatic axiomatisation for qubit entanglement, LICS 2015, the W node — arXiv:1501.07082
- Wang, Qufinite ZX-calculus: a unified framework of qudit ZX-calculi, the generator set, triangle, Fourier box and dimension connectives — arXiv:2104.06429
- Poór, Wang, Shaikh, Yeh, Yeung & Coecke, Completeness for arbitrary finite dimensions of ZXW-calculus, LICS 2023 — arXiv:2302.12135
- Wang, Poór & Shaikh, Completeness of qufinite ZXW calculus — arXiv:2309.13014
Bang boxes and scalable notation
- Dixon & Duncan, Graphical reasoning in compact closed categories for quantum computation, AMAI 56 (2009) — doi:10.1007/s10472-009-9141-x
- Kissinger, Merry & Soloviev, Pattern graph rewrite systems, EPTCS 143 (2014) — arXiv:1204.6695
- Kissinger & Quick, A first-order logic for string diagrams, CALCO 2015, !-box induction — arXiv:1505.00343
- Carette, Horsman & Perdrix, SZX-calculus: scalable graphical quantum reasoning, MFCS 2019 — arXiv:1905.00041
- Carette & Lemonnier, Large-scale quantum diagrammatic reasoning tools, !-boxes vs. scalable notations — arXiv:2204.11702
Exact symbolic sums and contraction
- Berndt, Evans & Williams, Gauss and Jacobi Sums (1998), quadratic Gauss sums and their sign
- Landsberg, Zur Theorie der Gaussschen Summen…, J. reine angew. Math. 111 (1893), Landsberg–Schaar reciprocity — doi:10.1515/crll.1893.111.234
- Dechter, Bucket elimination, Artif. Intell. 113 (1999), contraction by variable elimination — doi:10.1016/S0004-3702(99)00059-4
Rewriting and equality saturation
- Tate, Stepp, Tatlock & Lerner, Equality saturation, LMCS 7 (2011) — arXiv:1012.1802
- Willsey et al., egg: fast and extensible equality saturation, POPL 2021 — arXiv:2004.03082
- Nelson & Oppen, Fast decision procedures based on congruence closure, JACM 27 (1980) — doi:10.1145/322186.322198
- Tarjan, Efficiency of a good but not linear set union algorithm, JACM 22 (1975) — doi:10.1145/321879.321884
Lean formalisation
- de Moura & Ullrich, The Lean 4 theorem prover and programming language, CADE-28 (2021) — doi:10.1007/978-3-030-79876-5_37
- The mathlib Community, The Lean mathematical library, CPP 2020 — arXiv:1910.09336
Algorithms in the examples
- Greenberger, Horne & Zeilinger, Going beyond Bell's theorem (1989), the GHZ state — arXiv:0712.0921
- Deutsch & Jozsa, Rapid solution of problems by quantum computation, Proc. R. Soc. A 439 (1992) — doi:10.1098/rspa.1992.0167
- Fan, A generalization of the Deutsch–Jozsa algorithm to multi-valued quantum logic, ISMVL 2007 — doi:10.1109/ISMVL.2007.3
- Bernstein & Vazirani, Quantum complexity theory, SIAM J. Comput. 26 (1997) — doi:10.1137/S0097539796300921
- Krishna, Makwana & Suresh, A generalization of Bernstein–Vazirani algorithm to qudit systems (2016) — arXiv:1609.03185
Software
- Kissinger & van de Wetering, PyZX, EPTCS 318 (2020) — arXiv:1904.04735
- ZXLive — github.com/zxcalc/zxlive
- Harris et al., Array programming with NumPy, Nature 585 (2020) — doi:10.1038/s41586-020-2649-2
- Meurer et al., SymPy, PeerJ Comput. Sci. 3 (2017) — doi:10.7717/peerj-cs.103
Diagrammatic proof assistants and their formalisation
- Kissinger & Zamdzhiev, Quantomatic: a proof assistant for diagrammatic reasoning, CADE-25 (2015) — arXiv:1503.01034
- Kissinger, Chyp: composing hypergraphs, proving theorems, ACT 2023 — github.com/akissinger/chyp
- Lehmann, Caldwell, Shah, Spencer & Rand, VyZX: formal verification of a graphical quantum language — arXiv:2311.11571
- Shah, Spencer, Zielinski, Caldwell, Lehmann & Rand, ViCAR: visualizing categories with automated rewriting in Coq, EPTCS 429 (2025) — arXiv:2404.08163
- Caldwell, Spencer, Kissinger & Rand, TensorRocq: enabling diagrammatic reasoning in Rocq (2026) — arXiv:2604.17592
- Duve, zxLean — github.com/tannerduve/zxLean
- Poór, Booth, Carette, van de Wetering & Yeh, The qupit stabiliser ZX-travaganza, EPTCS 384 (2023), with the DiZX library — arXiv:2306.05204, github.com/jvdwetering/dizx
Verification of quantum programs and parameterized families
- Hietala, Rand, Hung, Li & Hicks, Proving quantum programs correct (SQIR), ITP 2021 — arXiv:2010.01240
- Zhou, Barthe, Strub, Liu & Ying, CoqQ: foundational verification of quantum programs, POPL 2023 — arXiv:2207.11350
- Chareton, Bardin, Bobot, Perrelle & Valiron, An automated deductive verification framework for circuit-building quantum programs (QBricks), ESOP 2021 — arXiv:2003.05841
- Abdulla et al., Parameterized verification of quantum circuits, POPL 2026 — arXiv:2511.19897
License
Apache License 2.0 — see
LICENSE.
Metadata
Release files for ArchytasZX 2.0.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| archytaszx-2.0.2.tar.gz | 1.0 MB | Without provenance | Details for archytaszx-2.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| archytaszx-2.0.2-py3-none-any.whl | Python 3 | none | any | Details for archytaszx-2.0.2-py3-none-any.whl |
Total release size: 1.7 MB
Release files / archytaszx-2.0.2.tar.gz
| Download URL | archytaszx-2.0.2.tar.gz |
|---|---|
| Size | 1.0 MB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
56ab5733cc9a8cc8ef00c917164a9978f3f5d09c2ed4c0cc780eae458d17ef4f
|
|
BLAKE2b-256 checksum How to use checksums |
e7711877969fbcc54b9f41cb0a487a6f6e83fc5539aad20b4bfeb2257bed68f0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Release files / archytaszx-2.0.2-py3-none-any.whl
| Download URL | archytaszx-2.0.2-py3-none-any.whl |
|---|---|
| Size | 694.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
3cca9a0ef220f94b306719774eff8eec4f020b240786244c2405b311a59ea5a1
|
|
BLAKE2b-256 checksum How to use checksums |
ec0e135d51409876748e513ee1c9306a9c45a7a1f1979751770a30fa99dc4f75
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.14.8
|
Security for ArchytasZX 2.0.2
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.