CoolFace
Datasetpublic

MathNetwork/MathlibGraph

MathlibGraph: The Multinetwork of Mathlib Dependency graph of Mathlib (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)… See the full description on the dataset page: https://huggingface.co/datasets/MathNetwork/MathlibGraph.

sourceHugging Faceapache-2.0updated 6mo agoView on Hugging Face
0likes368downloads
Dataset Card

MathlibGraph: The Multinetwork of Mathlib

Dependency graph of Mathlib (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

DeclarationsModulesNamespaces (k=2)
Nodes308,1297,56410,097
Edges8,436,36620,881332,081 (weighted)
DAG depth831547 (after SCC condensation)
Louvain modularity0.4780.6100.270
Synthesized edges74.2%
In cycles5,732 nodes0 (DAG)6,055 nodes (38 SCCs)

Files

Raw Data (v1)

FileRowsDescription
mathlib_edges.csv8,436,366Declaration dependency edges
mathlib_nodes.csv317,655Declarations before deduplication
nodes.csv / edges.csv633K / 10.9MFull environment (Lean + Std + Mathlib)
mechanisms.ndjsonLean language mechanism extractions
tactic_usage.ndjsonPer-declaration tactic usage profiles

Three-Layer Graphs (v2)

Each layer has nodes.csv, edges.csv, and metrics.csv:

FolderNodesEdgesMetricsDescription
v2/declaration/308,129(use root mathlib_edges.csv)308,129 x 11Theorems, definitions, and other named constants
v2/module/7,56420,8817,564 x 10Source files linked by import statements
v2/namespace/10,097332,08110,097 x 11Depth-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).

ColumnTypeDescription
namestrFully qualified declaration name
kindstrtheorem, definition, abbrev, inductive, constructor, opaque, axiom, or quotient
modulestrParent namespace (null for 30,944 Lean core declarations)

v2/declaration/metrics.csv

All columns from nodes.csv plus:

ColumnTypeDescription
namespace_depth2strFirst 2 dot-separated components (e.g., Mathlib.Algebra)
namespace_depth3strFirst 3 dot-separated components
in_degreeintDeclarations that depend on this one
out_degreeintDeclarations this one depends on
pagerankfloatPageRank (alpha=0.85)
betweennessfloatBetweenness centrality (k=500, seed=42)
community_idintLouvain community
dag_layerintTopological depth; -1 for 5,732 nodes in cycles
file_modulestrSource file module (from Lean environment, 278K coverage)
istacticproofboolWhether the proof uses tactics (78,315 declarations)
tactic_countintNumber of tactics used in the proof
top_tacticstrMost frequently used tactic in this proof
is_instanceboolWhether this is a typeclass instance (26,415 declarations)
instance_classstrWhich typeclass this instance implements
is_coercionboolWhether this is a coercion (241 declarations)
toadditivepairstrName of the corresponding additive/multiplicative variant
def_heightfloatDefinitional height in the kernel (42,935 declarations)

v2/module/nodes.csv

ColumnTypeDescription
modulestrDotted module name (e.g., Mathlib.Algebra.Group.Defs)
decl_countintDeclarations defined in this source file

v2/module/edges.csv

ColumnTypeDescription
sourcestrImporting module
targetstrImported module
is_exportedboolWhether this is a public import (20,699 of 20,881)

v2/module/metrics.csv

ColumnTypeDescription
modulestrModule name
decl_countintDeclarations in this module (full decl_module mapping, 499K coverage)
in_degreeintModules that import this one
out_degreeintModules this one imports
pagerankfloatPageRank on module import graph
betweennessfloatBetweenness centrality (exact)
dag_layerintTopological depth in module DAG
community_idintLouvain community
cohesionfloatFraction of declaration edges staying within module
importutilizationmedianfloatMedian fraction of imported declarations used

v2/namespace/nodes.csv

ColumnTypeDescription
namespacestrDepth-2 namespace (e.g., Mathlib.Algebra)
decl_countintDeclarations in this namespace
in_cycleboolTrue if this namespace is in a strongly connected component
scc_idintSCC identifier (-1 if not in a cycle)

v2/namespace/edges.csv

ColumnTypeDescription
sourcestrSource namespace
targetstrTarget namespace
weightintNumber of declaration-level edges between these namespaces

v2/namespace/metrics.csv

ColumnTypeDescription
namespacestrDepth-2 namespace
decl_countintDeclarations in this namespace
in_degreeintUnweighted in-degree
out_degreeintUnweighted out-degree
edgeweightsumintTotal declaration edges involving this namespace
pagerankfloatWeighted PageRank (alpha=0.85)
betweennessfloatWeighted betweenness (k=300, seed=42)
community_idintLouvain community (weighted undirected)
crossnsratiofloatFraction of edges crossing namespace boundaries
in_cycleboolIn a strongly connected component (6,055 of 10,097)
scc_idintSCC 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)

Hold-Out Experiments

We validate the premise retrieval results with two levels of hold-out experiments to assess information leakage. In the original experiment, all network features (degree, PageRank, betweenness, community, DAG layer) are precomputed on the full graph. Hold-out experiments recompute features on a reduced graph to test whether full-graph computation inflates AUC.

Edge-level hold-out

  • Randomly remove 20% of edges, recompute all features on remaining 80% graph
  • Tests whether full-graph feature computation inflates AUC

Declaration-level hold-out

  • Split theorems 80/20, remove ALL edges (incoming and outgoing) of test theorems from training graph
  • Test theorems have zero degree in training graph
  • Simulates the real scenario: predicting premises for a brand new theorem

Results (Split 1, seed=42)

MethodAUC (original)AUC (edge hold-out)AUC (decl hold-out)
Random0.4990.4970.500
Same module0.5630.5620.563
Same namespace0.5900.5900.592
Same community0.7680.7550.500
Network features0.9910.9880.978
All features0.9940.9920.984

The community feature drops to random (0.500) in declaration-level hold-out because test declarations become isolated nodes with unique community IDs. Despite this, the combined network feature model retains AUC=0.978, confirming that degree, PageRank, and DAG position carry genuine predictive signal independent of information leakage.

Full 5-split results with mean and std are in experiments/holdout_decl_level.json (updated incrementally).

Experiment Files

FileDescription
experiments/premise_retrieval_results.jsonOriginal experiment: 6 methods, 4 metrics, 95% CI
experiments/premise_retrieval_hard_negatives.jsonHard negatives (same-community) variant
experiments/holdout_edge_level.jsonEdge-level hold-out (1 split)
experiments/holdout_decl_level.jsonDeclaration-level hold-out (5 splits, incremental)

License

Apache 2.0