Skip to main content

DiracULA

Develop quantum algorithms without fixing the size or dimensionality of the machine. Write an algorithm once, in Dirac notation, for n qudits of dimension d, and get its states, measurement statistics and identities as closed forms that hold for every n and every d at once.

PyPI Python 3.12+ License: Apache 2.0 Results certified in Lean 4 Status: beta

DiracULA, the Dirac Universal Language for Algorithm, is a programming language for quantum algorithms whose register size and qudit dimension are symbols. Its values are symbolic path sums: applying a gate is substitution, and measurement is a Born distribution derived in closed form. Nothing is ever enumerated, sampled or simulated, so every result has the same shape for every size.

Example: Deutsch–Jozsa for every n

examples/deutsch_jozsa.ula, a balanced oracle on an n-qubit register, with n never given a value:

var n
gate U_f = |x>|y> -> |x>|y xor bit(x, 0)>
|psi> = |0>^@n @ |1>
show(|psi>)
(H^@n @ H)|psi>
show(|psi>)
U_f|psi>
show(|psi>)
(H^@n @ I)|psi>
show(|psi>)
var z = floor(measure|psi>/2)
show(z)
show(|psi>)
$ diracula --unicode examples/deutsch_jozsa.ula
|ψ⟩ = |0⟩^⊗n ⊗ |1⟩
|ψ⟩ = 2^(-n/2 - 1/2) Σ_{y=0}^{1} Σ_{x=0}^{2^n - 1} (-1)^y |x⟩ ⊗ |y⟩
|ψ⟩ = 2^(-n/2 - 1/2) Σ_{y=0}^{1} Σ_{x=0}^{2^n - 1} (-1)^y |x⟩ ⊗ |(y ⊕ bit(x, 0))⟩
|ψ⟩ = 2^(-n - 1/2) Σ_{y=0}^{1} Σ_{x=0}^{2^n - 1} Σ_{x'=0}^{2^n - 1} (-1)^(y + x⊙x') |x'⟩ ⊗ |(y ⊕ bit(x, 0))⟩
z = [(1, 1)]
|ψ⟩⟨ψ| = 1/2 Σ_{k1=0}^{1} |1⟩⟨1| ⊗ |k1⟩⟨k1|

The measurement is a Born distribution derived symbolically: outcome 1 with probability 1, so the oracle is balanced, for every register size. The post-measurement state is the mixed state on the last line. Any state can also be drawn as a ZX diagram (--zx), where the register is a bang box of multiplicity n - 1 rather than n copies:

ZX diagram of the Deutsch–Jozsa state before measurement, with the register as a bang box of multiplicity n - 1

What it does

  • Symbolic size. Register count, qudit dimension and loop bounds can stay symbols. |0>^@n is one term, not n kets, and a concrete value is substituted into the closed form at the end at no cost in its size.
  • Exact arithmetic. Amplitudes are exact expressions over rationals, roots of unity and the size symbols; no global factor is ever dropped.
  • Closed-form measurement. measure returns the Born distribution over every outcome as one expression, together with the post-measurement state, mixed where it has to be.
  • Certified results. certify writes a Lean 4 file proving that the value the program computes equals the printed closed form, for every value of its size symbols.
  • A whole language. Variables, gates defined by their action on basis kets, sums, matrix comprehensions, measurement, control flow, assumptions and assertions, and f-strings; run as scripts or interactively, and embeddable in Python and Jupyter.

Install

Python ≥ 3.12. numpy and sympy are the only runtime dependencies. With matplotlib installed, output is typeset and ZX diagrams are drawn as images in terminals that show them; without it, both fall back to Unicode text.

pip install DiracULA             # or 'DiracULA[viz]' to add matplotlib
diracula                         # interactive shell
diracula script.ula              # run a program

Quickstart

The .ula language

var n
gate F = |x>_d -> 1/sqrt(d) sum(y in 0..d){ e^(2*pi*i*x*y/d) |y>_d }
|psi> = H^@n |0>^@n
var z = measure|psi>
show(z, |psi>)
print(f"z = {z}")

Output styles are --render (default, typeset images), --unicode, --ascii and --latex; several style flags print every output in each style, and --order groups the output by style at the end. --zx, --both and --raw switch between Dirac notation and ZX diagrams, and --images DIR saves every rendered image as a PNG.

examples/learn_ula.ula is a guided tour of the whole language, ending in Deutsch–Jozsa for every n; the complete reference is docs/LANGUAGE.txt.

From Python

from diracula import ula                 # a shared Program; diracula.Program() for a fresh one

ula("var n")
ula.psi = ula.H ** ula.n | ula.ket(0) ** ula.n      # |psi> = H^@n |0>^@n
ula["|phi>"] = ula["|psi> - 2 |0><0|psi>"]
ula.phi       # |φ⟩ = 2^(-n/2) Σ_{x=0}^{2^n - 1} |x⟩ - 2^(1 - n/2) |0⟩^⊗n
ula.phi.latex()                          # also rendered by Jupyter

y = ula.measure | ula.psi
y             # [(k, 2^(-n)) : k ∈ {0,…,2^n - 1}]

examples/learn_ula.py is the same tour from Python.

Certifying a result

var n
|psi> = H^@n |0>^@n
certify psi
$ diracula --certify out/ program.ula
lean: wrote out/program_psi.lean (0 axioms: none)

The file states the program's meaning, built from its syntax, and proves it equal to the printed closed form for every n, using a verified normaliser of symbolic sums. #print axioms lists only Lean's standard axioms. Assumptions made with assume become hypotheses of the theorem.

Documentation

The full reference documentation is in docs/:

Document Contents
INDEX.txt Index of the documentation, conventions and reading order
OVERVIEW.txt What the language is, its guarantees and its limits
INSTALL.txt Installation, the Lean library, configuration and environment variables
LANGUAGE.txt The .ula language reference
SHELL.txt The diracula command: flags, views, styles, meta-commands, exit codes
PYTHON_API.txt The Python embedding
ZX_VIEW.txt How states become ZX diagrams and how they are drawn
LEAN.txt Certificates: the Lean semantics of programs and the symbolic-sum normaliser

How it relates to ArchytasZX

DiracULA is self-contained: it computes on its own symbolic path-sum core, draws ZX diagrams with its own copy of the qufinite ZXW diagram model, and checks certificates against its own Lean library over Mathlib. A ZX diagram is only a view of a DiracULA state; no result is computed through it. ArchytasZX, a qufinite ZXW diagram-rewriting engine by the same author, is the separate tool for proving identities between ZX diagrams; the two projects share their origin, not their code at run time.

Status

In beta and under active development: the language and the API are unstable and change between releases. Known limits:

  • An assert whose condition does not reduce to a truth value counts as undecided, and fails.
  • Programs using rand, a branch on a value that is not concrete, normalise, floating-point format specs or states assigned from Python cannot be certified; nor can results that need an identity the normaliser does not prove yet.
  • An amplitude outside the ZX scalar and phase grammar, such as cos(t) of a real symbol, has no ZX view.

Development

git clone https://github.com/Arhip-Dmitriev/DiracULA.git
cd DiracULA
python -m venv .venv && source .venv/bin/activate
pip install -e '.[dev]'

python -m pytest -n 8
ruff format . && ruff check . && mypy diracula

Citation

If you use DiracULA in academic work, please cite it via CITATION.cff, or:

@software{dmitriev_diracula,
  author  = {Dmitriev, Arkhip Alekseyevich},
  title   = {{DiracULA}: Dirac Universal Language for Algorithm},
  year    = {2026},
  url     = {https://github.com/Arhip-Dmitriev/DiracULA},
  license = {Apache-2.0}
}

Contributing

Bug reports, wrong closed forms and questions about the mathematics are the most useful contributions; a program whose printed result is wrong for some size is the most valuable report of all. See CONTRIBUTING.md.

References

Full reference list

Dirac notation and quantum foundations

  • Dirac, A new notation for quantum mechanics, Math. Proc. Camb. Phil. Soc. 35 (1939) — doi:10.1017/S0305004100021162
  • Born, Zur Quantenmechanik der Stoßvorgänge, Z. Phys. 37 (1926), the Born rule — doi:10.1007/BF01397477
  • Nielsen & Chuang, Quantum Computation and Quantum Information (2010), density matrices, measurement, the quantum Fourier transform — doi:10.1017/CBO9780511976667
  • Gottesman, Fault-tolerant quantum computation with higher-dimensional systems (1999), qudits — arXiv:quant-ph/9802007

Path sums and exact symbolic sums

  • Amy, Towards large-scale functional verification of universal quantum circuits, EPTCS 287 (2019) — arXiv:1805.06908
  • Vilmart, The structure of sum-over-paths, its consequences, and completeness for Clifford, FoSSaCS 2021 — arXiv:2003.05678
  • Berndt, Evans & Williams, Gauss and Jacobi Sums (1998), quadratic Gauss sums and their sign
  • Richardson, Some undecidable problems involving elementary functions of a real variable, J. Symb. Logic 33 (1968) — doi:10.2307/2271358

ZX view

  • Wang, Qufinite ZX-calculus: a unified framework of qudit ZX-calculi — arXiv:2104.06429
  • Carette & Lemonnier, Large-scale quantum diagrammatic reasoning tools, !-boxes vs. scalable notations — arXiv:2204.11702

Lean formalisation

Algorithms in the examples

  • Deutsch & Jozsa, Rapid solution of problems by quantum computation, Proc. R. Soc. A 439 (1992) — doi:10.1098/rspa.1992.0167
  • Grover, A fast quantum mechanical algorithm for database search, STOC 1996 — arXiv:quant-ph/9605043
  • Shor, Polynomial-time algorithms for prime factorization and discrete logarithms on a quantum computer, SIAM J. Comput. 26 (1997) — arXiv:quant-ph/9508027
  • Coppersmith, An approximate Fourier transform useful in quantum factoring (1994) — arXiv:quant-ph/0201067

Software

Verification of quantum programs and related tools

  • Chareton, Bardin, Bobot, Perrelle & Valiron, An automated deductive verification framework for circuit-building quantum programs (QBricks), ESOP 2021 — arXiv:2003.05841
  • Hietala, Rand, Hung, Li & Hicks, Proving quantum programs correct (SQIR), ITP 2021 — arXiv:2010.01240
  • Xu, Barthe & Zhou, Automating equational proofs in Dirac notation (DiracDec), POPL 2025 — arXiv:2411.11617
  • Xu, Zhou & Barthe, D-Hammer: efficient equational reasoning for labelled Dirac notation, CAV 2025 — arXiv:2505.08633
  • Chareton, Bardin, Lee, Valiron, Vilmart & Xu, Formal methods for quantum programs: a survey — arXiv:2109.06493

License

Apache License 2.0 — see LICENSE.

Metadata

Release files for DiracULA 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 DiracULA 0.1.0
File Size Uploaded Provenance Actions
diracula-0.1.0.tar.gz 306.0 kB Without provenance Details for diracula-0.1.0.tar.gz

Built distribution (wheel)

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

Total release size: 607.4 kB

Release files / diracula-0.1.0.tar.gz

Download URL diracula-0.1.0.tar.gz
Size 306.0 kB
Tags Source
SHA-256 checksum
How to use checksums
5ddfd55d765a80e4b9bb5c2f5caa113a698b58f2e9682254b28d46c458e51c51
BLAKE2b-256 checksum
How to use checksums
811fd71cc5decea8d1c82a69bae219f1992dfa3a2a6501581dc511e3fed3bda8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

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

Download URL diracula-0.1.0-py3-none-any.whl
Size 301.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e6b48ffb40709a2fb5fa0fea9d47ae2a10d4a2e7a2b68ecc62496cc0698ad0f
BLAKE2b-256 checksum
How to use checksums
7ee058d18fe32ae5be89407c5f3f2c3f285780d1bb3f7e5eaa4faf5fcef15e7f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.14.8

Security for DiracULA 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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