An agentic AI system autonomously autoformalises Nielsen & Chuang into a Lean 4 library built on a Mathlib fork, with grounding linters enforcing a postulate layer.
Abstract
Formalisation in a proof assistant gives mathematics machine-checked rigour, and artificial intelligence (AI) now performs this autoformalisation at scale. Physics has seen far less of this progress, although it arguably has more to gain. A formal physics library would trace every result back to its foundations, expose the assumptions and approximations that informal derivations leave implicit, catch errors reliably, and give AI-generated physics a verifier that checks not only its mathematics but its consistency with physical principles. Autoformalising a physics library requires more than certifying the mathematical correctness of individual results, as in the recent autoformalisation of new proofs of mathematical conjectures. It must also ensure that the mathematics captures the physical meaning of the source text, distinguish between a physical concept and its mathematical representation, and support practical use cases. We present an agentic AI system that, given only the source text, a mathematical foundation and the postulates of quantum mechanics, autonomously plans, writes, reviews and repairs a Lean 4 library of finite-dimensional quantum mechanics, coordinating its agents through live knowledge graphs. As a proof of concept, we applied the system to the textbook of Nielsen & Chuang. Without human intervention in the content of any item, it formalised 505 of the 509 items within its scope and corrected 24 errors in the book. The same library then served as the foundation for formalising research results beyond the book, including three research papers and 28 landmark theorems. To our knowledge, this is the first fully autonomous, textbook-scale autoformalisation of a field of physics, and the first physics library with a formally enforced postulate layer separating physics from mathematics. The system could be applied to any field of physics with a core of formal postulates.
Problem
Formal physics libraries are far less developed than formal mathematics libraries. Autoformalising physics must certify mathematical correctness, preserve physical meaning, and separate physical concepts from their mathematical representations.
Approach
A physicist first formalises the six postulates of quantum mechanics in Lean 4, extending a fork of Mathlib to support density operators. AI agents then extract and classify the textbook items, build an informal knowledge graph linking concepts to Lean declarations, and autoformalise and review each item under a deterministic parallel orchestrator. Lean linters, called grounding linters, enforce a postulate layer that distinguishes physics declarations from mathematics. Lean also checks that no proof contains sorry and that only standard axioms are used.
Figure 2: The library’s layers, shown for one item. Everything that Exercise 9.12 depends on, arranged in layers from the textbook (top) to Mathlib (bottom). Outlined dots are the exercise’s three headline declarations. The other 54 dots are the definitions and theorems they rely on, directly or indirectly, and lines show the connections. A single exercise thus draws on every layer. The crossed ar
Results
Of the 509 in-scope items from Nielsen & Chuang, 505 were formalised without human intervention in their content, and 24 errors in the book were corrected. A strict audit found 433 items captured in full, 56 in part and 16 borderline. The library was then used to formalise three research papers and 28 landmark theorems.
Figure 1: The verified library as a network. Each dot is one definition or theorem (9,742) from the textbook and each line joins a result to one it uses (64,955). Results that use one another heavily are drawn close together and share a colour. These groups were found from the links alone, without reference to the book’s chapters (Methods). Recognisable topics in quantum information arise as clust