| --- |
| license: apache-2.0 |
| task_categories: |
| - graph-ml |
| language: |
| - en |
| tags: |
| - mathematics |
| - lean4 |
| - mathlib |
| - dependency-graph |
| - formal-verification |
| size_categories: |
| - 100K<n<1M |
| --- |
| |
| # MathlibGraph: Mathlib Dependency Graph Dataset |
|
|
| Dependency graph of [Mathlib](https://github.com/leanprover-community/mathlib4) (commit [`534cf0b`](https://github.com/leanprover-community/mathlib4/commit/534cf0b), 2 Feb 2026), the largest formal mathematics library for Lean 4. |
|
|
| ## Files |
|
|
| | File | Rows | Unique entries | Description | |
| |------|------|----------------|-------------| |
| | `mathlib_nodes.csv` | 317,655 | 308,129 declarations | Mathlib declarations (name, kind, module) | |
| | `mathlib_edges.csv` | 8,436,366 | 8,436,366 edges | Mathlib dependencies (source, target, is_explicit) | |
| | `nodes.csv` | 633,364 | — | Full environment (Lean + Std + Mathlib) | |
| | `edges.csv` | 10,889,011 | — | Full environment edges | |
| |
| > **Note:** `mathlib_nodes.csv` contains 9,526 duplicate name rows produced by `@[to_additive]` mirroring. After deduplication, there are **308,129 unique declarations** — the figure used throughout the paper. |
| |
| ## Statistics (308,129 unique Mathlib declarations) |
| |
| | Kind | Count | % | |
| |------|-------|---| |
| | theorem | 243,725 | 79.1% | |
| | definition | 48,664 | 15.8% | |
| | abbrev | 6,667 | 2.2% | |
| | constructor | 4,755 | 1.5% | |
| | inductive | 3,813 | 1.2% | |
| | opaque | 499 | 0.2% | |
| | quotient | 3 | <0.1% | |
| | axiom | 3 | <0.1% | |
| |
| ## Quick Start |
| |
| ```python |
| from datasets import load_dataset |
| import pandas as pd |
|
|
| nodes = load_dataset("MathNetwork/MathlibGraph", |
| data_files="mathlib_nodes.csv", split="train").to_pandas() |
| edges = load_dataset("MathNetwork/MathlibGraph", |
| data_files="mathlib_edges.csv", split="train").to_pandas() |
|
|
| # Deduplicate nodes (9,526 @[to_additive] mirrors) |
| nodes = nodes.drop_duplicates(subset="name", keep="first") |
|
|
| print(f"Declarations: {len(nodes):,}, Edges: {len(edges):,}") |
| # Output: Declarations: 308,129, Edges: 8,436,366 |
| ``` |
| |
| ## Extraction Pipeline |
| |
| - **Nodes**: [lean4export](https://github.com/leanprover/lean4export) (official leanprover tool) |
| - **Edges**: [lean-training-data premises](https://github.com/kim-em/lean-training-data) (Kim Morrison, Mathlib maintainer) |
| - **Filtering**: premises whitelist method — `lake exe premises Mathlib` outputs only Mathlib declarations, which we use to filter the full lean4export output |
| |
| ## Schema |
| |
| ### mathlib_nodes.csv |
| |
| | Column | Type | Description | |
| |--------|------|-------------| |
| | name | string | Fully qualified declaration name (e.g., `CategoryTheory.Functor.comp_id`) | |
| | kind | string | `theorem`, `definition`, `abbrev`, `inductive`, `constructor`, `opaque`, `axiom`, `quotient` | |
| | module | string | Lean module (e.g., `CategoryTheory.Functor`) | |
| |
| ### mathlib_edges.csv |
| |
| | Column | Type | Description | |
| |--------|------|-------------| |
| | source | string | Dependent declaration | |
| | target | string | Dependency (premise) | |
| | is_explicit | bool | Appears in explicit arguments | |
| | is_simplifier | bool | Used by simplifier | |
| |
| ## Citation |
| |
| Part of the [MathlibGraph](https://github.com/MathNetwork/MathlibGraph) project — network analysis of formalized mathematics. |
| |
| ## License |
| |
| Apache 2.0 |
| |