File size: 7,080 Bytes
8d22f23
 
 
 
 
 
 
 
 
 
 
 
7bb6da6
8d22f23
 
 
 
7bb6da6
8d22f23
7bb6da6
 
 
 
 
 
 
 
 
 
 
 
 
 
9bd7529
8d22f23
 
7bb6da6
9bd7529
0531579
 
7bb6da6
 
 
0531579
 
7bb6da6
0531579
871b4ae
 
 
 
 
 
 
 
 
 
0531579
7bb6da6
 
 
871b4ae
 
7bb6da6
8d22f23
 
 
 
9bd7529
8d22f23
bc4173e
0531579
bc4173e
9bd7529
 
 
7bb6da6
0531579
8d22f23
 
 
871b4ae
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0531579
 
 
 
7bb6da6
 
 
 
 
 
 
 
0531579
7bb6da6
 
0531579
 
 
 
 
7bb6da6
 
 
 
0531579
 
 
7bb6da6
 
0531579
 
 
 
 
 
7bb6da6
0531579
 
7bb6da6
 
 
 
 
 
0531579
 
 
7bb6da6
0531579
7bb6da6
0531579
7bb6da6
 
 
 
 
 
 
0531579
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
168
169
170
171
172
173
---
license: apache-2.0
task_categories:
  - graph-ml
language:
  - en
tags:
  - mathematics
  - lean4
  - mathlib
  - dependency-graph
  - formal-verification
  - network-analysis
size_categories:
  - 100K<n<1M
---

# MathlibGraph: The Multinetwork of Mathlib

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 (`v4.28.0-rc1`).

Three dependency layers (declarations, modules, namespaces) with precomputed network metrics.

## Quick Stats

| | Declarations | Modules | Namespaces (k=2) |
|---|---|---|---|
| Nodes | 308,129 | 7,564 | 10,097 |
| Edges | 8,436,366 | 20,881 | 332,081 |
| DAG depth | 83 | 154 | 7 |
| Louvain modularity | 0.478 | 0.610 | 0.270 |
| Synthesized edges | 74.2% | — | — |
| Cross-namespace edges | — | — | 85.8% |

## Files

### Raw Graph Data

| File | Rows | Description |
|------|------|-------------|
| `mathlib_nodes.csv` | 317,655 | Declarations before deduplication (name, kind, module) |
| `mathlib_edges.csv` | 8,436,366 | Declaration dependencies (source, target, is_explicit, is_simplifier) |
| `nodes.csv` | 633,364 | Full environment including Lean core and Std |
| `edges.csv` | 10,889,011 | Full environment edges |
| `mechanisms.ndjson` | — | Lean language mechanism extractions |
| `tactic_usage.ndjson` | — | Per-declaration tactic usage profiles |

### Module and Namespace Graphs (v2)

| File | Rows | Description |
|------|------|-------------|
| `v2/mathlib_module_nodes.csv` | 7,564 | Module (source file) list with decl_count |
| `v2/mathlib_module_edges.csv` | 20,881 | Module import edges (source, target) |
| `v2/mathlib_namespace_nodes_k2.csv` | 10,097 | Depth-2 namespace list with decl_count |
| `v2/mathlib_namespace_edges_k2.csv` | 332,081 | Namespace edges with weight (aggregated from declaration edges) |

### Enriched Metrics (v2)

| File | Rows | Columns | Description |
|------|------|---------|-------------|
| `v2/mathlib_nodes_enriched.csv` | 308,129 | 11 | Deduplicated declarations with network metrics |
| `v2/mathlib_modules.csv` | 7,564 | 10 | Per-module precomputed metrics |
| `v2/mathlib_namespaces_k2.csv` | 10,097 | 9 | Per-namespace precomputed metrics |
| `v2/mathlib_summary.json` | — | — | Headline statistics for all three graph levels |

## Quick Start

```python
from datasets import load_dataset

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):,}")
print(nodes.nlargest(5, "pagerank")[["name", "kind", "in_degree", "pagerank"]])
```

## Schema

### v2/mathlib_module_nodes.csv

| Column | Type | Description |
|--------|------|-------------|
| module | str | Dotted module name (e.g., `Mathlib.Algebra.Group.Defs`) |
| decl_count | int | Number of declarations defined in this module |

### v2/mathlib_module_edges.csv

| Column | Type | Description |
|--------|------|-------------|
| source | str | Importing module |
| target | str | Imported module |

### v2/mathlib_namespace_nodes_k2.csv

| Column | Type | Description |
|--------|------|-------------|
| namespace | str | Depth-2 namespace (e.g., `Mathlib.Algebra`) |
| decl_count | int | Declarations in this namespace |

### v2/mathlib_namespace_edges_k2.csv

| Column | Type | Description |
|--------|------|-------------|
| source | str | Source namespace |
| target | str | Target namespace |
| weight | int | Number of declaration-level edges between these namespaces |

### v2/mathlib_nodes_enriched.csv

| Column | Type | Description |
|--------|------|-------------|
| name | str | Fully qualified declaration name |
| kind | str | One of: theorem, definition, abbrev, inductive, constructor, opaque, axiom, quotient |
| module | str | Parent namespace of the declaration (null for 30,944 Lean core declarations) |
| namespace_depth2 | str | First 2 dot-separated name components (e.g., `Mathlib.Algebra`) |
| namespace_depth3 | str | First 3 dot-separated name components |
| in_degree | int | Declarations that depend on this one |
| out_degree | int | Declarations this one depends on |
| pagerank | float | PageRank (alpha=0.85) |
| betweenness | float | Betweenness centrality (sampled, k=500, seed=42) |
| community_id | int | Louvain community assignment |
| dag_layer | int | Topological depth; -1 for 5,732 nodes in cycles |

### v2/mathlib_modules.csv

| Column | Type | Description |
|--------|------|-------------|
| module | str | Dotted module name (e.g., `Mathlib.Algebra.Group.Defs`) |
| decl_count | int | Declarations in this module (235K jixia coverage) |
| in_degree | int | Modules that import this one |
| out_degree | int | Modules this one 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 assignment |
| cohesion | float | Fraction of edges that stay within the module |
| import_utilization_median | float | Median fraction of imported declarations actually used |

### v2/mathlib_namespaces_k2.csv

| Column | Type | Description |
|--------|------|-------------|
| namespace | str | 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 |
| edge_weight_sum | int | Sum of declaration-level edges involving this namespace |
| pagerank | float | Weighted PageRank (alpha=0.85) |
| betweenness | float | Weighted betweenness (k=300, seed=42) |
| community_id | int | Louvain community on weighted undirected graph |
| cross_ns_ratio | float | Fraction of edges crossing namespace boundaries |

### v2/mathlib_summary.json

Top-level keys: `snapshot` (commit, date, Lean version), `declaration_graph`, `module_graph`, `namespace_graph_k2` (node/edge counts, modularity, NMI, DAG depth, power-law exponents), `edge_decompositions` (proof-only/statement-only ratios), `kind_distribution`.

## Methodology

- **Extraction**: lean4export (nodes) + lean-training-data (edges) + importGraph (module graph) + jixia (declaration metadata)
- **Deduplication**: by name, 317,655 to 308,129 rows (9,526 `@[to_additive]` mirrors removed)
- **Self-loops**: 4,755 constructor self-references filtered from graph construction
- **PageRank**: alpha=0.85, max_iter=100, tol=1e-6
- **Betweenness**: declaration k=500, namespace k=300, module exact; all with seed=42
- **Communities**: Louvain (python-louvain), resolution=1.0, random_state=42, on undirected projection
- **DAG layers**: Kahn's algorithm; 5,732 declaration nodes in cycles assigned layer=-1; namespace graph condensed via SCC

## License

Apache 2.0