- The paper introduces ZFLean, which integrates extensional set-level mathematics with Lean’s type theory, enabling proofs up to extensional equality.
- It employs a relational calculus with specialized automation tactics, significantly reducing the manual overhead of quotient reasoning in set theory.
- The framework provides canonical constructions for key number systems and bridges set-theoretic objects with Lean’s native types.
ZFLean: A Framework for Set-Level Mathematics in Lean
Overview and Motivation
ZFLean is an advanced Lean 4 library that enables researchers to conduct rigorous, ergonomic, and extensible set-level mathematics directly inside a model of Zermelo-Fraenkel set theory with Choice (ZFC), leveraging and extending the capabilities of Mathlib’s ZFC implementation. The framework systematically addresses several friction points faced when formalizing extensional, set-theoretic mathematics within a predominantly intensional, type-theoretic proof assistant. While Mathlib’s ZFC model validates the necessary foundational axioms, ZFLean innovates at the interface and usability layers: it provides a rewriting-friendly relational calculus, canonical set-theoretic constructions (Booleans, naturals, integers, sums/options), lightweight automation, and explicit bridges between ZFC-level sets and Lean’s native types.
The key motivation behind ZFLean is to enable Lean users to do mathematics "up to extensional equality", encode partiality using relations, and carry out constructions purely in set theory, without abandoning the ergonomic and automated features available to Mathlib users working in Lean's type-theoretic core. ZFLean neither replaces nor duplicates Mathlib’s native algebraic structures; instead, it provides complementary infrastructure for developments that benefit from or require principled set-theoretic reasoning.
Foundational Architecture
ZFLean is built atop Mathlib’s ZFC model, which defines an inductive hierarchy of pre-sets (PSet), quotiented by extensional equivalence to form bona fide sets (ZFSet). Pre-set membership, extensional equality, and subsequent lifting of operations (product, union, powerset) are handled via native Lean quotient support. The framework rigorously maintains the distinction between intensional and extensional equality—a central issue when formalizing set theory in intensional type theory—and localizes all extensional reasoning at the set level.
Crucially, ZFLean alleviates the boilerplate associated with repeated quotient lifting by ensuring all theorems and definitions are formulated and manipulated at the ZFSet interface, hiding the internal intensional machinery and allowing users to reason externally in terms of ZFC objects.
Relational Calculus and Automation
A core innovation in ZFLean is its relational calculus, designed for efficient and scalable manipulation of relations and (partial/total) functions in set theory. The calculus defines standard operations such as identity, converse, composition, domain, range, and image. Distinctions between total and partial functions are made explicit, with corresponding predicates and operations. For instance, totality and partiality are witnessed by IsFunc and IsPFunc, respectively, in direct analogy with the functional and relational approaches in mathematics.
ZFLean offers three specialized automation tactics: zrel, zpfun, and zfun, orchestrated to recursively discharge side-conditions related to well-formedness of relations, partial functions, and total functions, respectively. These tactics are implemented via attributes attached to relevant theorems, which are discoverable during proof automation. This design enables users to operate at the semantic level of mathematics, with explicit proof obligations for functional or relational well-formedness elided by automation except in genuinely nontrivial cases. The tactics are compositional, maintainable, and extensible, thereby supporting the growth of large-scale formal set-theoretic developments.
Furthermore, the calculus constitutes a uniform interface for set-level constructs, making full use of Lean's rewrite and simplification mechanisms through tagged lemmas. Equational reasoning, image computation, and relational rewriting mirror standard mathematical practice while remaining computationally tractable within the Lean environment.
Canonical Constructions and Universal Properties
ZFLean develops canonical set-level constructions for Booleans (B), natural numbers (N), integers (Z), rationals (Q), function spaces, (co-)products, and option types, all inside ZFC. Each comes with its full algebraic, order, and universal properties, and is implemented so as to be compatible with Lean's algebraic hierarchies.
- Booleans: B={∅,{∅}} with corresponding operations (conjunction, disjunction, negation) and Lean subtype exposure via
ZFBool.
- Naturals: Defined as the smallest inductive set (least intersection over inductive subsets), with von Neumann encoding and full recursion/induction machinery. Standard arithmetic and ordering are implemented with proofs that coincide with their Lean analogues.
- Integers: Constructed as quotient types over N×N under an equivalence relation, with set-level representatives and a full commutative ring structure.
- Rationals: Formed as quotients over pairs of integers (excluding zero in the denominator), including all expected field operations.
- (Co-)Products/Options: Precise set-theoretic encodings, together with canonical injections and case analyses.
Explicit "bridges" are provided to show formal isomorphisms between ZFC objects and Lean’s native types (Bool, Nat, Int, Option, etc.), enabling seamless transport of properties and reasoning steps between the foundations. This allows leveraging the rich automation, tactic support, and algebraic infrastructure of Mathlib for results stated at the set level.
Isomorphisms, Embeddings, and Transport
ZFLean packages precise definitions and theorems for set-level embeddings (↪) and isomorphisms (≅), with correctness theorems (e.g., verification that ≅ is an equivalence relation, proof of the Cantor-Schröder-Bernstein theorem). The framework supports construction and recognition of canonical isomorphisms, and enables transport of definitions, theorems, and algebraic structures across these isomorphisms.
Bridges between ZFC and Lean-level types facilitate transport via isomorphisms, allowing practitioners to conflate "proofs up to isomorphism" (a common technique in category-theoretic or extensional mathematics) with rigorous, type-theoretic formalization in Lean.
Case Study: Currying Isomorphism
A principal demonstration of the framework is the formalized proof of the currying isomorphism: CA×B≅(CB)A. This construction exercises all layers of the framework: canonical function construction, mutual inverse definition of curry/uncurry, use of relational calculus automation, application of extensionality and N0-abstraction, and deployment of pointwise functional equality. All well-formedness obligations—arising from composition, abstraction, and function evaluation—are automatically discharged. The result highlights the efficacy and expressiveness of ZFLean for large-scale, extensional set-level mathematics within Lean.
Practical and Theoretical Implications
ZFLean provides a robust foundation for formalizing traditional mathematics, especially in domains where extensionality, partiality, and isomorphism are central. The framework reduces the traditional overhead of set-level formalization in type theory, effectively integrates with typed developments, and delivers practical automation formerly unattainable for such tasks. This opens avenues for formalization projects in algebra, analysis, category theory, and other areas where set-theoretic reasoning and manipulation are required.
From a theoretical perspective, ZFLean exemplifies the productive interaction between set-theoretic and type-theoretic foundations. Its design highlights how dependently typed assistants can serve as practical environments for extensional, set-level mathematics with minimized cognitive and proof engineering costs.
Directions for Future Development
Future work includes expansion toward canonical constructions of the real numbers (via Cauchy sequences and Dedekind cuts), increased automation for routine proof obligations, and scaling the development to encompass broad swathes of classical mathematics (e.g., measure theory, topology) entirely within the ZFC layer. Further improvements may involve deeper integration of categorical perspectives (e.g., elementary topos theory) and extended bridges for richer classes of Lean/Mathlib types.
Conclusion
ZFLean offers a sophisticated and comprehensive approach to set-level formalization in Lean, blending the full expressivity of ZFC with the ergonomic and automated support of modern dependently typed proof assistants. Its infrastructural advances in relational calculus, automation, and interoperability provide both a model for similar frameworks in other assistants and a powerful toolkit for researchers formalizing extensional mathematics in Lean.
Reference: "ZFLean: a framework for set-level mathematics in Lean" (2604.24195)