File size: 2,582 Bytes
8d22f23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b905a79
8d22f23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b905a79
 
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
---
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) (v4.28.0-rc1), the largest formal mathematics library for Lean 4.

## Files

| File | Rows | Description |
|------|------|-------------|
| `mathlib_nodes.csv` | 347,356 | Mathlib declarations (name, kind, module) |
| `mathlib_edges.csv` | 10,417,589 | Mathlib dependencies (source, target, is_explicit) |
| `nodes.csv` | 633,364 | Full environment (Lean + Std + Mathlib) |
| `edges.csv` | 10,889,011 | Full environment edges |

## Statistics (Mathlib only)

| Kind | Count | % |
|------|-------|---|
| theorem | 273,767 | 78.8% |
| definition | 55,671 | 16.0% |
| abbrev | 7,490 | 2.2% |
| constructor | 5,436 | 1.6% |
| inductive | 4,297 | 1.2% |
| other | 695 | 0.2% |

## Quick Start

```python
from huggingface_hub import hf_hub_download
import pandas as pd

nodes = pd.read_csv(hf_hub_download("Xinze-Li-Moqian/MathlibGraph", "mathlib_nodes.csv", repo_type="dataset"))
edges = pd.read_csv(hf_hub_download("Xinze-Li-Moqian/MathlibGraph", "mathlib_edges.csv", repo_type="dataset"))

print(f"Nodes: {len(nodes)}, Edges: {len(edges)}")
# Output: Nodes: 347356, Edges: 10417589
```

## 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 | Declaration name (e.g., `CategoryTheory.Functor.comp_id`) |
| kind | string | `theorem`, `definition`, `abbrev`, `inductive`, `constructor`, etc. |
| module | string | Lean namespace (e.g., `CategoryTheory.Functor`) |

### mathlib_edges.csv

| Column | Type | Description |
|--------|------|-------------|
| source | string | Dependent declaration |
| target | string | Dependency |
| 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