leanprover-community / mathlib4

The math library of Lean 4
https://leanprover-community.github.io/mathlib4_docs
Apache License 2.0
1.55k stars 341 forks source link

Create a backbone of `Defs.lean` files #19253

Open Vierkantor opened 3 hours ago

Vierkantor commented 3 hours ago

The import hierarchy in Mathlib is quite messy. A concrete issue we can focus on is that lot of files in Mathlib are structured around introducing a definition and then following up with a large collection of lemmas. This means that importing a definition often means also pulling in many unrelated definitions that interact with the intended result. Not only does this clustering make Mathlib slower to build after changes, it also means harder minimization of examples.

Ideally we'd maintain a stable "backbone" of Defs files, where each only contains definitions and the bare minimum of theory to get to the next level in the backbone. These could then be paired with Lemmas files that can be imported to get the full complement of results that would currently be imported alongside the defs.

Studying the import graph for a file can be a very useful tool in figuring out which bits of theory should be unnecessary for a definition.

Vierkantor commented 3 hours ago

Here's an overview of existing Defs files in Mathlib alongside a quick assessment of their import graph.

Clean Defs files

(including open PRs, as of 2024-11-15) These files only have definitions and very basic results, and contain only reasonable imports:

Nearly clean defs

These files are not definitions-only: