Xinze-Li-Moqian commited on
Commit
0531579
·
verified ·
1 Parent(s): 28d06e8

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +98 -26
README.md CHANGED
@@ -16,26 +16,39 @@ size_categories:
16
 
17
  # MathlibGraph: Mathlib Dependency Graph Dataset
18
 
19
- 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.
20
 
21
  ## Files
22
 
23
- | File | Rows | Unique entries | Description |
24
- |------|------|----------------|-------------|
25
- | `mathlib_nodes.csv` | 317,655 | 308,129 declarations | Mathlib declarations (name, kind, module) |
26
- | `mathlib_edges.csv` | 8,436,366 | 8,436,366 edges | Mathlib dependencies (source, target, is_explicit) |
27
- | `nodes.csv` | 633,364 | — | Full environment (Lean + Std + Mathlib) |
28
- | `edges.csv` | 10,889,011 | — | Full environment edges |
29
 
30
- > **Note:** `mathlib_nodes.csv` contains 9,526 duplicate name rows produced by `@[to_additive]` mirroring. After deduplication, there are **308,129 unique declarations** — the figure used throughout the paper.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
31
 
32
  ## Statistics (308,129 unique Mathlib declarations)
33
 
34
  | Kind | Count | % |
35
  |------|-------|---|
36
- | theorem | 243,725 | 79.1% |
37
- | definition | 48,664 | 15.8% |
38
- | abbrev | 6,667 | 2.2% |
39
  | constructor | 4,755 | 1.5% |
40
  | inductive | 3,813 | 1.2% |
41
  | opaque | 499 | 0.2% |
@@ -46,35 +59,34 @@ Dependency graph of [Mathlib](https://github.com/leanprover-community/mathlib4)
46
 
47
  ```python
48
  from datasets import load_dataset
49
- import pandas as pd
50
 
 
51
  nodes = load_dataset("MathNetwork/MathlibGraph",
52
- data_files="mathlib_nodes.csv", split="train").to_pandas()
53
  edges = load_dataset("MathNetwork/MathlibGraph",
54
  data_files="mathlib_edges.csv", split="train").to_pandas()
55
 
56
- # Deduplicate nodes (9,526 @[to_additive] mirrors)
57
- nodes = nodes.drop_duplicates(subset="name", keep="first")
58
-
59
  print(f"Declarations: {len(nodes):,}, Edges: {len(edges):,}")
60
- # Output: Declarations: 308,129, Edges: 8,436,366
61
- ```
62
 
63
- ## Extraction Pipeline
 
64
 
65
- - **Nodes**: [lean4export](https://github.com/leanprover/lean4export) (official leanprover tool)
66
- - **Edges**: [lean-training-data premises](https://github.com/kim-em/lean-training-data) (Kim Morrison, Mathlib maintainer)
67
- - **Filtering**: premises whitelist method — `lake exe premises Mathlib` outputs only Mathlib declarations, which we use to filter the full lean4export output
 
 
68
 
69
  ## Schema
70
 
71
- ### mathlib_nodes.csv
72
 
73
  | Column | Type | Description |
74
  |--------|------|-------------|
75
- | name | string | Fully qualified declaration name (e.g., `CategoryTheory.Functor.comp_id`) |
76
  | kind | string | `theorem`, `definition`, `abbrev`, `inductive`, `constructor`, `opaque`, `axiom`, `quotient` |
77
- | module | string | Lean module (e.g., `CategoryTheory.Functor`) |
78
 
79
  ### mathlib_edges.csv
80
 
@@ -82,9 +94,69 @@ print(f"Declarations: {len(nodes):,}, Edges: {len(edges):,}")
82
  |--------|------|-------------|
83
  | source | string | Dependent declaration |
84
  | target | string | Dependency (premise) |
85
- | is_explicit | bool | Appears in explicit arguments |
86
  | is_simplifier | bool | Used by simplifier |
87
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
88
  ## Citation
89
 
90
  Part of the [MathlibGraph](https://github.com/MathNetwork/MathlibGraph) project — network analysis of formalized mathematics.
 
16
 
17
  # MathlibGraph: Mathlib Dependency Graph Dataset
18
 
19
+ 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`.
20
 
21
  ## Files
22
 
23
+ ### Core data (v1)
 
 
 
 
 
24
 
25
+ | File | Rows | Description |
26
+ |------|------|-------------|
27
+ | `mathlib_nodes.csv` | 317,655 (308,129 unique) | Mathlib declarations (name, kind, module) |
28
+ | `mathlib_edges.csv` | 8,436,366 | Mathlib dependencies (source, target, is_explicit, is_simplifier) |
29
+ | `nodes.csv` | 633,364 | Full environment (Lean + Std + Mathlib) |
30
+ | `edges.csv` | 10,889,011 | Full environment edges |
31
+ | `mechanisms.ndjson` | — | Lean language mechanism extractions |
32
+ | `tactic_usage.ndjson` | — | Tactic usage profiles |
33
+
34
+ ### Enriched data (v2)
35
+
36
+ | File | Rows | Description |
37
+ |------|------|-------------|
38
+ | `v2/mathlib_nodes_enriched.csv` | 308,129 | Deduplicated nodes with 8 precomputed metric columns |
39
+ | `v2/mathlib_modules.csv` | 7,564 | Per-module (source file) metrics |
40
+ | `v2/mathlib_namespaces_k2.csv` | 10,097 | Per-namespace (depth-2) metrics |
41
+ | `v2/mathlib_summary.json` | — | Headline statistics for all three graph levels |
42
+
43
+ > **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**.
44
 
45
  ## Statistics (308,129 unique Mathlib declarations)
46
 
47
  | Kind | Count | % |
48
  |------|-------|---|
49
+ | theorem | 251,642 | 79.2% |
50
+ | definition | 50,156 | 15.8% |
51
+ | abbrev | 6,784 | 2.1% |
52
  | constructor | 4,755 | 1.5% |
53
  | inductive | 3,813 | 1.2% |
54
  | opaque | 499 | 0.2% |
 
59
 
60
  ```python
61
  from datasets import load_dataset
 
62
 
63
+ # Load enriched nodes (v2, deduplicated, with metrics)
64
  nodes = load_dataset("MathNetwork/MathlibGraph",
65
+ data_files="v2/mathlib_nodes_enriched.csv", split="train").to_pandas()
66
  edges = load_dataset("MathNetwork/MathlibGraph",
67
  data_files="mathlib_edges.csv", split="train").to_pandas()
68
 
 
 
 
69
  print(f"Declarations: {len(nodes):,}, Edges: {len(edges):,}")
70
+ # Declarations: 308,129, Edges: 8,436,366
 
71
 
72
+ # Top 10 by PageRank
73
+ print(nodes.nlargest(10, "pagerank")[["name", "kind", "in_degree", "pagerank"]])
74
 
75
+ # Load module-level data
76
+ modules = load_dataset("MathNetwork/MathlibGraph",
77
+ data_files="v2/mathlib_modules.csv", split="train").to_pandas()
78
+ print(f"Modules: {len(modules):,}")
79
+ ```
80
 
81
  ## Schema
82
 
83
+ ### mathlib_nodes.csv (v1)
84
 
85
  | Column | Type | Description |
86
  |--------|------|-------------|
87
+ | name | string | Fully qualified declaration name |
88
  | kind | string | `theorem`, `definition`, `abbrev`, `inductive`, `constructor`, `opaque`, `axiom`, `quotient` |
89
+ | module | string | Parent namespace of the declaration |
90
 
91
  ### mathlib_edges.csv
92
 
 
94
  |--------|------|-------------|
95
  | source | string | Dependent declaration |
96
  | target | string | Dependency (premise) |
97
+ | is_explicit | bool | Appears in explicit arguments (25.8% of edges) |
98
  | is_simplifier | bool | Used by simplifier |
99
 
100
+ ### v2/mathlib_nodes_enriched.csv
101
+
102
+ All columns from `mathlib_nodes.csv` plus:
103
+
104
+ | Column | Type | Description |
105
+ |--------|------|-------------|
106
+ | namespace_depth2 | string | Depth-2 namespace (e.g., `Mathlib.Algebra`) |
107
+ | namespace_depth3 | string | Depth-3 namespace (e.g., `Mathlib.Algebra.Group`) |
108
+ | in_degree | int | Number of declarations that depend on this one |
109
+ | out_degree | int | Number of declarations this one depends on |
110
+ | pagerank | float | PageRank score (alpha=0.85) |
111
+ | betweenness | float | Betweenness centrality (sampled, k=500, seed=42) |
112
+ | community_id | int | Louvain community ID (resolution=1.0, seed=42) |
113
+ | dag_layer | int | Topological depth in DAG (-1 if in a cycle; 5,732 nodes) |
114
+
115
+ ### v2/mathlib_modules.csv
116
+
117
+ One row per Mathlib source file (7,564 modules).
118
+
119
+ | Column | Type | Description |
120
+ |--------|------|-------------|
121
+ | module | string | Dotted module name (e.g., `Mathlib.Algebra.Group.Defs`) |
122
+ | decl_count | int | Declarations in this module (from jixia extraction, 235K coverage) |
123
+ | in_degree | int | Modules that import this module |
124
+ | out_degree | int | Modules this module imports |
125
+ | pagerank | float | PageRank on module import graph |
126
+ | betweenness | float | Betweenness centrality (exact, no sampling) |
127
+ | dag_layer | int | Topological depth in module DAG |
128
+ | community_id | int | Louvain community ID |
129
+ | cohesion | float | internal_edges / (internal + external) |
130
+ | import_utilization_median | float | Median fraction of imported declarations actually used |
131
+
132
+ ### v2/mathlib_namespaces_k2.csv
133
+
134
+ One row per depth-2 namespace (10,097 namespaces).
135
+
136
+ | Column | Type | Description |
137
+ |--------|------|-------------|
138
+ | namespace | string | Depth-2 namespace (e.g., `Mathlib.Algebra`) |
139
+ | decl_count | int | Declarations in this namespace |
140
+ | in_degree | int | Unweighted in-degree in namespace graph |
141
+ | out_degree | int | Unweighted out-degree in namespace graph |
142
+ | edge_weight_sum | int | Weighted degree (sum of declaration-level edges) |
143
+ | pagerank | float | PageRank (weighted, alpha=0.85) |
144
+ | betweenness | float | Betweenness centrality (k=300, seed=42, weighted) |
145
+ | community_id | int | Louvain community ID (weighted undirected) |
146
+ | cross_ns_ratio | float | Fraction of this namespace's edges that cross namespace boundaries |
147
+
148
+ ### v2/mathlib_summary.json
149
+
150
+ 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.
151
+
152
+ ## Extraction Pipeline
153
+
154
+ - **Nodes**: [lean4export](https://github.com/leanprover/lean4export)
155
+ - **Edges**: [lean-training-data premises](https://github.com/kim-em/lean-training-data)
156
+ - **Module graph**: [importGraph](https://github.com/leanprover-community/importGraph)
157
+ - **Enrichment**: NetworkX (PageRank, betweenness, Louvain, DAG layers)
158
+ - **Code**: [MathlibGraph on GitHub](https://github.com/MathNetwork/MathlibGraph)
159
+
160
  ## Citation
161
 
162
  Part of the [MathlibGraph](https://github.com/MathNetwork/MathlibGraph) project — network analysis of formalized mathematics.