File size: 6,498 Bytes
8d22f23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b905a79
8d22f23
0531579
9bd7529
8d22f23
 
0531579
9bd7529
0531579
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8d22f23
9bd7529
8d22f23
 
 
0531579
 
 
9bd7529
 
 
 
 
8d22f23
 
 
 
9bd7529
8d22f23
0531579
bc4173e
0531579
bc4173e
9bd7529
 
 
0531579
8d22f23
0531579
 
8d22f23
0531579
 
 
 
 
8d22f23
 
 
0531579
8d22f23
 
 
0531579
9bd7529
0531579
8d22f23
 
 
 
 
 
9bd7529
0531579
8d22f23
 
0531579
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
---
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. Lean version: `v4.28.0-rc1`.

## Files

### Core data (v1)

| File | Rows | Description |
|------|------|-------------|
| `mathlib_nodes.csv` | 317,655 (308,129 unique) | Mathlib declarations (name, kind, module) |
| `mathlib_edges.csv` | 8,436,366 | Mathlib dependencies (source, target, is_explicit, is_simplifier) |
| `nodes.csv` | 633,364 | Full environment (Lean + Std + Mathlib) |
| `edges.csv` | 10,889,011 | Full environment edges |
| `mechanisms.ndjson` | — | Lean language mechanism extractions |
| `tactic_usage.ndjson` | — | Tactic usage profiles |

### Enriched data (v2)

| File | Rows | Description |
|------|------|-------------|
| `v2/mathlib_nodes_enriched.csv` | 308,129 | Deduplicated nodes with 8 precomputed metric columns |
| `v2/mathlib_modules.csv` | 7,564 | Per-module (source file) metrics |
| `v2/mathlib_namespaces_k2.csv` | 10,097 | Per-namespace (depth-2) metrics |
| `v2/mathlib_summary.json` | — | Headline statistics for all three graph levels |

> **Note:** `mathlib_nodes.csv` contains 9,526 duplicate name rows from `@[to_additive]` mirroring. The v2 enriched file is deduplicated to **308,129 unique declarations**.

## Statistics (308,129 unique Mathlib declarations)

| Kind | Count | % |
|------|-------|---|
| theorem | 251,642 | 79.2% |
| definition | 50,156 | 15.8% |
| abbrev | 6,784 | 2.1% |
| 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

# Load enriched nodes (v2, deduplicated, with metrics)
nodes = load_dataset("MathNetwork/MathlibGraph",
                     data_files="v2/mathlib_nodes_enriched.csv", split="train").to_pandas()
edges = load_dataset("MathNetwork/MathlibGraph",
                     data_files="mathlib_edges.csv", split="train").to_pandas()

print(f"Declarations: {len(nodes):,}, Edges: {len(edges):,}")
# Declarations: 308,129, Edges: 8,436,366

# Top 10 by PageRank
print(nodes.nlargest(10, "pagerank")[["name", "kind", "in_degree", "pagerank"]])

# Load module-level data
modules = load_dataset("MathNetwork/MathlibGraph",
                       data_files="v2/mathlib_modules.csv", split="train").to_pandas()
print(f"Modules: {len(modules):,}")
```

## Schema

### mathlib_nodes.csv (v1)

| Column | Type | Description |
|--------|------|-------------|
| name | string | Fully qualified declaration name |
| kind | string | `theorem`, `definition`, `abbrev`, `inductive`, `constructor`, `opaque`, `axiom`, `quotient` |
| module | string | Parent namespace of the declaration |

### mathlib_edges.csv

| Column | Type | Description |
|--------|------|-------------|
| source | string | Dependent declaration |
| target | string | Dependency (premise) |
| is_explicit | bool | Appears in explicit arguments (25.8% of edges) |
| is_simplifier | bool | Used by simplifier |

### v2/mathlib_nodes_enriched.csv

All columns from `mathlib_nodes.csv` plus:

| Column | Type | Description |
|--------|------|-------------|
| namespace_depth2 | string | Depth-2 namespace (e.g., `Mathlib.Algebra`) |
| namespace_depth3 | string | Depth-3 namespace (e.g., `Mathlib.Algebra.Group`) |
| in_degree | int | Number of declarations that depend on this one |
| out_degree | int | Number of declarations this one depends on |
| pagerank | float | PageRank score (alpha=0.85) |
| betweenness | float | Betweenness centrality (sampled, k=500, seed=42) |
| community_id | int | Louvain community ID (resolution=1.0, seed=42) |
| dag_layer | int | Topological depth in DAG (-1 if in a cycle; 5,732 nodes) |

### v2/mathlib_modules.csv

One row per Mathlib source file (7,564 modules).

| Column | Type | Description |
|--------|------|-------------|
| module | string | Dotted module name (e.g., `Mathlib.Algebra.Group.Defs`) |
| decl_count | int | Declarations in this module (from jixia extraction, 235K coverage) |
| in_degree | int | Modules that import this module |
| out_degree | int | Modules this module imports |
| pagerank | float | PageRank on module import graph |
| betweenness | float | Betweenness centrality (exact, no sampling) |
| dag_layer | int | Topological depth in module DAG |
| community_id | int | Louvain community ID |
| cohesion | float | internal_edges / (internal + external) |
| import_utilization_median | float | Median fraction of imported declarations actually used |

### v2/mathlib_namespaces_k2.csv

One row per depth-2 namespace (10,097 namespaces).

| Column | Type | Description |
|--------|------|-------------|
| namespace | string | Depth-2 namespace (e.g., `Mathlib.Algebra`) |
| decl_count | int | Declarations in this namespace |
| in_degree | int | Unweighted in-degree in namespace graph |
| out_degree | int | Unweighted out-degree in namespace graph |
| edge_weight_sum | int | Weighted degree (sum of declaration-level edges) |
| pagerank | float | PageRank (weighted, alpha=0.85) |
| betweenness | float | Betweenness centrality (k=300, seed=42, weighted) |
| community_id | int | Louvain community ID (weighted undirected) |
| cross_ns_ratio | float | Fraction of this namespace's edges that cross namespace boundaries |

### v2/mathlib_summary.json

Headline statistics including: snapshot metadata (commit, date, Lean version), declaration/module/namespace graph metrics (node/edge counts, modularity, NMI, DAG depth, power-law exponents), and edge decomposition ratios.

## Extraction Pipeline

- **Nodes**: [lean4export](https://github.com/leanprover/lean4export)
- **Edges**: [lean-training-data premises](https://github.com/kim-em/lean-training-data)
- **Module graph**: [importGraph](https://github.com/leanprover-community/importGraph)
- **Enrichment**: NetworkX (PageRank, betweenness, Louvain, DAG layers)
- **Code**: [MathlibGraph on GitHub](https://github.com/MathNetwork/MathlibGraph)

## Citation

Part of the [MathlibGraph](https://github.com/MathNetwork/MathlibGraph) project — network analysis of formalized mathematics.

## License

Apache 2.0