← Latest papers
💻 computer science

ZFLean: a framework for set-level mathematics in Lean

The paper introduces ZFLean, a Lean 4 library that integrates core ZFC set theory into the Mathlib ecosystem with improved ergonomics, canonical constructions, and bridges to native types to facilitate mixed set-level and typed proofs.

Original authors: Vincent Trélat

Published 2026-04-28
📖 5 min read🧠 Deep dive

Original authors: Vincent Trélat

Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer

Imagine you are trying to build a house. You have two different sets of blueprints and tools:

  1. The "Typed" Tools (Lean's Native System): These are like high-tech, laser-guided robotic arms. They are incredibly precise, but they only work if every brick is perfectly labeled with its specific type (e.g., "Red Brick," "Blue Brick"). If you try to use a "Red Brick" where a "Blue Brick" is required, the robot stops and refuses to work. This is great for safety, but sometimes math feels like it needs to be more flexible.
  2. The "Set" Tools (ZFC): These are like a giant, messy pile of raw clay. In this world, everything is just "stuff." You can mold a piece of clay into a cup, a ball, or a square, and it's all just "clay." This is how traditional mathematicians often think about sets: everything is an element of a collection, and you can mix and match freely.

The Problem:
For a long time, if you wanted to do math using the "Set" tools inside the "Typed" robot workshop, it was a nightmare. You had to constantly translate your clay shapes into robot-friendly labels, prove that your translation was correct, and then translate the results back. It was slow, boring, and prone to errors. Most people just avoided the clay pile entirely and stuck to the robots.

The Solution: ZFLean
Vincent Trélat created ZFLean, which is like building a universal translator and a set of custom tools right inside the robot workshop.

Here is how it works, using simple analogies:

1. The "Clay" Workshop (The ZFC Model)

ZFLean sets up a special zone inside the robot workshop where the "clay" rules apply. Here, you can define sets, relations, and functions just like a traditional mathematician would, without worrying about the strict "types" the robot usually demands. It's a safe space where you can say, "This is a set of numbers," without the robot asking, "Is it a Nat or an Int?"

2. The "Smart Translator" (The Relational Calculus)

The biggest headache in the old days was the "boilerplate"—the repetitive, boring paperwork required to prove that your clay shapes were actually valid.

  • The Old Way: You had to manually prove, "Yes, this relation is a function," and "Yes, this domain is valid," for every single step.
  • The ZFLean Way: The framework comes with smart little assistants (called tactics like zrel, zpfun, and zfun). Think of these as auto-fill forms. When you write a proof, these assistants automatically check the boring details and fill in the paperwork for you. You write the math; the assistants handle the administrative burden.

3. The "Bridge" (Interoperability)

This is the magic part. Usually, the "clay" world and the "robot" world were separate. ZFLean builds bridges between them.

  • If you build a set of natural numbers in the clay world, ZFLean can instantly say, "Hey, this is actually the same as the robot's Nat type."
  • This means you can do your messy, flexible set-theory math, and then seamlessly cross the bridge to use the robot's powerful, pre-built tools (like algebra solvers) to finish the job. You don't have to choose one or the other; you can use both in the same proof.

4. The "Lego Kit" (Canonical Constructions)

To make life easier, ZFLean comes with a pre-built kit of standard Lego pieces.

  • Need a set of True/False values? Here is a Boolean set.
  • Need a set of counting numbers? Here is a Natural Number set.
  • Need a way to handle "maybe" values (like an option)? Here is an Option set.
    These aren't just raw clay; they are pre-molded, tested, and come with instructions on how to use them (like "how to add two numbers" or "how to flip a switch").

5. The "Test Drive" (The Case Study)

To prove this system works, the author tested it with a classic math puzzle called the Currying Isomorphism.

  • Imagine this: You have a machine that takes two inputs at once (like a sandwich maker taking bread and meat). "Currying" is the process of turning that into a machine that takes one input (bread) and then gives you a new machine that takes the second input (meat).
  • The author used ZFLean to prove that these two ways of thinking about the machine are actually the same thing. The proof script looked almost exactly like a human mathematician writing it on a chalkboard, with the "smart assistants" quietly handling all the technical glitches in the background.

The Bottom Line

ZFLean is a framework that lets mathematicians work in the flexible, intuitive style of traditional set theory (the "clay") while living inside a modern, rigorous computer proof system (the "robots"). It removes the friction of translation, automates the boring paperwork, and builds bridges so you can use the best tools from both worlds without getting stuck in the middle.

The result is a library of about 8,300 lines of code that makes doing "set-level" math in Lean feel as natural and smooth as writing it on paper.

Drowning in papers in your field?

Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.

Try Digest →