MathlibGraph / README.md
Xinze-Li-Moqian's picture
Upload README.md with huggingface_hub
5d71d48 verified
|
raw
history blame
7.12 kB
---
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), each with nodes, edges, and 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 (weighted) |
| DAG depth | 83 | 154 | 7 (after SCC condensation) |
| Louvain modularity | 0.478 | 0.610 | 0.270 |
| Synthesized edges | 74.2% | — | — |
| In cycles | 5,732 nodes | 0 (DAG) | 6,055 nodes (38 SCCs) |
## Files
### Raw Data (v1)
| File | Rows | Description |
|------|------|-------------|
| `mathlib_edges.csv` | 8,436,366 | Declaration dependency edges |
| `mathlib_nodes.csv` | 317,655 | Declarations before deduplication |
| `nodes.csv` / `edges.csv` | 633K / 10.9M | Full environment (Lean + Std + Mathlib) |
| `mechanisms.ndjson` | — | Lean language mechanism extractions |
| `tactic_usage.ndjson` | — | Per-declaration tactic usage profiles |
### Three-Layer Graphs (v2)
Each layer has `nodes.csv`, `edges.csv`, and `metrics.csv`:
| Folder | Nodes | Edges | Metrics | Description |
|--------|-------|-------|---------|-------------|
| `v2/declaration/` | 308,129 | (use root `mathlib_edges.csv`) | 308,129 x 11 | Theorems, definitions, and other named constants |
| `v2/module/` | 7,564 | 20,881 | 7,564 x 10 | Source files linked by `import` statements |
| `v2/namespace/` | 10,097 | 332,081 | 10,097 x 11 | Depth-2 dotted-name prefixes, weighted edges |
`v2/summary.json` contains headline statistics for all three levels.
## Quick Start
```python
from datasets import load_dataset
# Declaration level
decl = load_dataset("MathNetwork/MathlibGraph",
data_files="v2/declaration/metrics.csv", split="train").to_pandas()
edges = load_dataset("MathNetwork/MathlibGraph",
data_files="mathlib_edges.csv", split="train").to_pandas()
# Module level
mod_nodes = load_dataset("MathNetwork/MathlibGraph",
data_files="v2/module/nodes.csv", split="train").to_pandas()
mod_edges = load_dataset("MathNetwork/MathlibGraph",
data_files="v2/module/edges.csv", split="train").to_pandas()
# Namespace level
ns_nodes = load_dataset("MathNetwork/MathlibGraph",
data_files="v2/namespace/nodes.csv", split="train").to_pandas()
ns_edges = load_dataset("MathNetwork/MathlibGraph",
data_files="v2/namespace/edges.csv", split="train").to_pandas()
```
## Schema
### v2/declaration/nodes.csv
Deduplicated from `mathlib_nodes.csv` (317,655 to 308,129 rows; 9,526 `@[to_additive]` mirrors removed).
| Column | Type | Description |
|--------|------|-------------|
| name | str | Fully qualified declaration name |
| kind | str | theorem, definition, abbrev, inductive, constructor, opaque, axiom, or quotient |
| module | str | Parent namespace (null for 30,944 Lean core declarations) |
### v2/declaration/metrics.csv
All columns from `nodes.csv` plus:
| Column | Type | Description |
|--------|------|-------------|
| namespace_depth2 | str | First 2 dot-separated components (e.g., `Mathlib.Algebra`) |
| namespace_depth3 | str | First 3 dot-separated 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 (k=500, seed=42) |
| community_id | int | Louvain community |
| dag_layer | int | Topological depth; -1 for 5,732 nodes in cycles |
### v2/module/nodes.csv
| Column | Type | Description |
|--------|------|-------------|
| module | str | Dotted module name (e.g., `Mathlib.Algebra.Group.Defs`) |
| decl_count | int | Declarations defined in this source file |
### v2/module/edges.csv
| Column | Type | Description |
|--------|------|-------------|
| source | str | Importing module |
| target | str | Imported module |
### v2/module/metrics.csv
| Column | Type | Description |
|--------|------|-------------|
| module | str | Module name |
| decl_count | int | Declarations (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) |
| dag_layer | int | Topological depth in module DAG |
| community_id | int | Louvain community |
| cohesion | float | Fraction of declaration edges staying within module |
| import_utilization_median | float | Median fraction of imported declarations used |
### v2/namespace/nodes.csv
| Column | Type | Description |
|--------|------|-------------|
| namespace | str | Depth-2 namespace (e.g., `Mathlib.Algebra`) |
| decl_count | int | Declarations in this namespace |
| in_cycle | bool | True if this namespace is in a strongly connected component |
| scc_id | int | SCC identifier (-1 if not in a cycle) |
### v2/namespace/edges.csv
| Column | Type | Description |
|--------|------|-------------|
| source | str | Source namespace |
| target | str | Target namespace |
| weight | int | Number of declaration-level edges between these namespaces |
### v2/namespace/metrics.csv
| Column | Type | Description |
|--------|------|-------------|
| namespace | str | Depth-2 namespace |
| decl_count | int | Declarations in this namespace |
| in_degree | int | Unweighted in-degree |
| out_degree | int | Unweighted out-degree |
| edge_weight_sum | int | Total declaration edges involving this namespace |
| pagerank | float | Weighted PageRank (alpha=0.85) |
| betweenness | float | Weighted betweenness (k=300, seed=42) |
| community_id | int | Louvain community (weighted undirected) |
| cross_ns_ratio | float | Fraction of edges crossing namespace boundaries |
| in_cycle | bool | In a strongly connected component (6,055 of 10,097) |
| scc_id | int | SCC identifier (-1 if acyclic) |
## Methodology
- **Extraction**: lean4export (nodes) + lean-training-data (edges) + importGraph (module graph) + jixia (metadata)
- **Deduplication**: by name, 317,655 to 308,129 rows (9,526 `@[to_additive]` mirrors)
- **Self-loops**: 4,755 constructor self-references filtered
- **PageRank**: alpha=0.85, max_iter=100, tol=1e-6
- **Betweenness**: declaration k=500, namespace k=300, module exact; seed=42
- **Communities**: Louvain, resolution=1.0, random_state=42, undirected projection
- **DAG layers**: Kahn's algorithm; cycle nodes get layer=-1; namespace graph condensed via SCC
- **Namespace cycles**: 6,055 of 10,097 namespaces in 38 SCCs (largest: 5,899 nodes)
## License
Apache 2.0