A formalization of universal algebra in Agda, built on the Agda standard library. The library defines algebras, homomorphisms, congruences, terms, varieties, and the equational logic that underlies them, with a fully constructive proof of Birkhoff's HSP theorem at the centre. It is being developed both as a working substrate for research in universal algebra and as a high-quality training corpus of Agda proofs for machine learning on formal mathematics.
Status. Version 3.0 is under active reconstruction on
master. The library currently targets Agda 2.8.0 and standard-library 2.3. Expect breaking changes until 3.0 is released; seedocs/GITHUB_PROJECT.mdfor the milestone plan andCHANGELOG.mdfor what has landed so far.
The previous version (called UALib, built against TypeTopology) is no longer maintained but remains available:
From a clean checkout to a green build, assuming Nix with flakes enabled (see INSTALL.md for installation and flake-activation instructions):
git clone https://github.com/ualib/agda-algebras.git
cd agda-algebras
nix develop # pins Agda 2.8.0 + standard-library 2.3 automatically
make check # type-check the entire library
make html # (optional) build clickable HTML under ./html/The first nix develop downloads and builds the pinned Agda and standard library; subsequent entries into the shell are essentially instantaneous. Non-Nix installation paths (Agda's PyPI package, prebuilt binaries, cabal from source) are documented in INSTALL.md.
- Rendered clickable HTML of the library: https://ualib.org.
- Installation guide:
INSTALL.md. - Contributor's guide:
CONTRIBUTING.md. - Style guide:
docs/STYLE_GUIDE.md. - Roadmap and milestone plan:
docs/GITHUB_PROJECT.md. - Changelog:
CHANGELOG.md. - Architecture decision records roadmap:
docs/GITHUB_PROJECT.md(ADR scaffolding tracked in M1-6). - Code of conduct:
CODE_OF_CONDUCT.md.
The 3.0 reconstruction organizes the source tree around a canonical foundation with optional layers built on top of it.
src/Setoid/is the canonical development tree for 3.0. Algebras are sets-with-equivalence (setoids) carrying a signature interpretation that respects the equivalence; homomorphisms preserve both the operations and the equivalence. Definitions are stated in terms of theAlgebra.Domainequivalence rather than propositional equality, which makes the eventual port to Cubical Agda largely mechanical.src/Classical/(planned, M3) builds specific algebraic theories — semigroups, monoids, groups, lattices, rings — on the universal-algebra foundation. Core structures are Σ-typed for mathematical elegance, with parallel record-typed bundle views inClassical/Bundles/for stdlib interop.src/Cubical/(planned, v4.0, tracked in M5) is the long-term canonical target: cubical-Agda counterparts of theSetoid/andClassical/developments, using the structure identity principle in place of setoid equivalence.src/Base/holds the pre-reconstruction development and shared foundations still in use during the 3.0 transition. M2-1 will move the frozen portions tosrc/Legacy/Base/; new contributions do not land inBase/(or later inLegacy/Base/).src/Overture/holds the small set of definitions shared acrossSetoid/,Classical/, and (eventually)Cubical/.src/Demos/holds self-contained pedagogical presentations of marquee results.src/Demos/HSPis a single-file rendition of Birkhoff's variety theorem suitable for teaching; the canonical proof lives insrc/Setoid/Varieties/HSP.agda(canonicality to be formalized in M2-4).
The contributor's guide gives more detail on which tree a new piece of work belongs in; when in doubt, please open an issue with the design-discussion label.
The recommended development environment is Nix (Option 1 in INSTALL.md):
nix developinside a clone of the repository. This pins Agda 2.8.0 and standard-library 2.3 automatically, writes a project-local Agda library configuration under .agda/, and bypasses any Agda or standard-library versions registered elsewhere on the host machine.
For contributors who cannot or prefer not to use Nix, INSTALL.md walks through three alternative paths: Agda's official Python installer (pipx install agda==2.8.0), a prebuilt binary from the Agda 2.8.0 release page, and a cabal build from source. All three require manually installing standard-library 2.3 and registering it in ~/.config/agda/libraries.
- Agda 2.8.0 (released 2025-07)
- standard-library 2.3 (released 2025-08)
- GNU Make
Older versions of either component are not supported on the master branch. To work against the v2.0.1 archival release (which targets Agda 2.6.2 / stdlib 1.7), check out the v2.0.1 tag.
Contributions are welcome — bug reports, design discussions, pull requests, and documentation improvements alike. Before contributing code, please read
CONTRIBUTING.md— development workflow, branching, and review expectations;docs/STYLE_GUIDE.md— file format, naming, notation, proof style, and the library-as-training-corpus considerations that shape how we write proofs;docs/GITHUB_PROJECT.md— the 3.0 milestone roadmap (check whether your contribution fits an existing track before opening a fresh issue);CODE_OF_CONDUCT.md— community standards.
For questions about mathematical content or larger design changes, please open a GitHub issue with the design-discussion label before writing code.
agda-algebras is dual-licensed to match the dual nature of the project.
- Source code (under
src/) is licensed under the Apache License 2.0, a permissive industry-standard software license compatible with essentially all other open-source licenses and with commercial use. - Documentation, papers, and tutorials (under
docs/) are licensed under the Creative Commons Attribution 4.0 International License, the standard license for academic-style written material; it permits sharing and adaptation with attribution.
If you are redistributing or building on agda-algebras, please respect both licenses for their respective parts of the repository.
The archival reference is the v2.0.1 Zenodo deposit, made for the TYPES 2021 submission:
@misc{ualib_v2.0.1,
author = {De{M}eo, William and Carette, Jacques},
title = {{T}he {A}gda {U}niversal {A}lgebra {L}ibrary (agda-algebras)},
year = 2021,
note = {{D}ocumentation available at https://ualib.org},
version = {2.0.1},
doi = {10.5281/zenodo.5765793},
howpublished = {{G}it{H}ub.com},
note = {{V}er.~2.0.1; source code: \href{https://zenodo.org/record/5765793/files/ualib/agda-algebras-v.2.0.1.zip?download=1}{agda-algebras-v.2.0.1.zip}, {G}it{H}ub repo: \href{https://github.com/ualib/agda-algebras}{github.com/ualib/agda-algebras}},
}While the 3.0 reconstruction is in development, please cite the GitHub repository directly and pin a commit hash for reproducibility. A new Zenodo DOI will be minted at the v3.0 release.
To cite the formalization of Birkhoff's HSP theorem:
@article{DeMeo:2021,
author = {De{M}eo, William and Carette, Jacques},
title = {A {M}achine-checked {P}roof of {B}irkhoff's {V}ariety {T}heorem
in {M}artin-{L}\"of {T}ype {T}heory},
journal = {CoRR},
volume = {abs/2101.10166},
year = {2021},
eprint = {2101.10166},
archivePrefix = {arXiv},
primaryClass = {cs.LO},
url = {https://arxiv.org/abs/2101.10166},
note = {Source code: \href{https://github.com/ualib/agda-algebras/blob/master/src/Demos/HSP.agda}{https://github.com/ualib/agda-algebras/blob/master/src/Demos/HSP.agda}}
}The current canonical setoid-based formalization of Birkhoff's theorem is in the Setoid.Varieties.HSP module, with the proof anchor in the rendered HTML at https://ualib.org/Setoid.Varieties.HSP.html#proof-of-the-hsp-theorem.
The agda-algebras library is developed and maintained by the agda-algebras development team:
We thank Andreas Abel, Jeremy Avigad, Andrej Bauer, Clifford Bergman, Venanzio Capretta, Martín Escardó, Ralph Freese, Hyeyoung Shin, and Siva Somayyajula for helpful discussions, corrections, advice, inspiration, and encouragement. Most of the mathematical results formalized in agda-algebras are well known; the novelty is in the formalization itself, which is mainly due to the contributors and acknowledgees listed above.
The following Agda documentation and tutorials informed the development of agda-algebras:
- Escardó, Introduction to Univalent Foundations of Mathematics with Agda
- Wadler, Programming Languages Foundations in Agda
- Bove and Dybjer, Dependent Types at Work
- Gunther, Gadea, Pagano, Formalization of Universal Algebra in Agda
- Norell and Chapman, Dependently Typed Programming in Agda
The official Agda Wiki, Agda User's Manual, Agda Language Reference, and the open-source Agda Standard Library source code are also indispensable.