File size: 3,241 Bytes
8d22f23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b905a79
8d22f23
9bd7529
 
8d22f23
 
9bd7529
 
 
 
 
 
 
 
8d22f23
9bd7529
8d22f23
 
 
9bd7529
 
 
 
 
 
 
 
8d22f23
 
 
 
9bd7529
8d22f23
 
bc4173e
9bd7529
bc4173e
9bd7529
 
 
 
8d22f23
9bd7529
 
8d22f23
 
 
 
 
 
 
 
 
 
 
 
 
 
9bd7529
 
 
8d22f23
 
 
 
 
 
9bd7529
8d22f23
 
 
 
 
b905a79
8d22f23
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
---
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