CoolFace
Datasetpublic

jajostrains/Mathlib-Normalized-Sexpr

Mathlib Normalized S-Expressions Lean 4 proof states from Mathlib, paired with the tactic applied at each step, in three representations extracted directly from the Lean kernel: Source-faithful S-expressions of the goal and every hypothesis, as Lean elaborated them. Normalized S-expressions of the same state, with stable local-context indices suitable for model input. Annotated tactic syntax -- the original tactic's syntax tree with identifier leaves resolved to the constants… See the full description on the dataset page: https://huggingface.co/datasets/jajostrains/Mathlib-Normalized-Sexpr.

sourceHugging Faceapache-2.0updated 26d agoView on Hugging Face
0likes78downloads
Dataset Card

Mathlib Normalized S-Expressions

Lean 4 proof states from Mathlib, paired with the tactic applied at each step, in three representations extracted directly from the Lean kernel:

  1. 1.Source-faithful S-expressions of the goal and every hypothesis, as Lean elaborated them.
  2. 2.Normalized S-expressions of the same state, with stable local-context indices suitable for model input.
  3. 3.Annotated tactic syntax -- the original tactic's syntax tree with identifier leaves resolved to the constants and hypotheses they refer to.

Row identity follows `cat-searcher/leandojo-benchmark-4-random`, so split and row_index join directly against it and the val/test splits remain comparable to published results on that benchmark.

Unlike pretty-printed proof states, S-expressions carry the elaborated term structure: implicit arguments, instance resolution, and binder structure are all explicit, which is what makes graph- and pointer-based models possible.

Loading

python
from datasets import load_dataset
import json

ds = load_dataset("jajostrains/Mathlib-Normalized-Sexpr", split="train")
row = ds[0]
print(row["model_goal_sexp"])

# Nested payloads are JSON strings; see the schema note below.
syntax_tree = json.loads(row["source_syntax"])
context = json.loads(row["local_context"])

Coverage

Read this before training on the `train` split.

splitrows publishedupstream rowscoverage
test4,3924,50697.47%
train218,727250,81487.21%
val4,1574,26097.58%
total227,276259,58087.56%

A row is published only when all three representations were extracted and validated for it. Rows are missing for two distinct reasons, and the difference matters:

  • Environment limits -- a source file that did not elaborate within the timeout. These rows are absent for incidental reasons and are, in principle, recoverable. Their absence is close to random.
  • Extractor limits and row data -- most importantly goal_cardinality: this extractor records states with exactly one pending goal, so every tactic invoked against multiple goals is excluded. Their absence is systematic.

Known bias

The train split is not a uniform random subsample of its upstream split. Because multi-goal invocations are excluded by construction, single-goal proof states are over-represented relative to the full benchmark, as are the tactics that tend to be applied to them. Any comparison against a model trained on all upstream rows should account for this.

The val and test splits are near-complete, so evaluation numbers computed on them remain comparable with published results.

Per-split failure taxonomy

test -- 114 rows not published
phaserowskindreason
file_compile59environmentLean could not elaborate the source file within the timeout, or the REPL exited while compiling it. Retryable.
goal_cardinality25extractor limitThe tactic was invoked against multiple pending goals. This extractor records single-goal states only, so these rows are absent by design.
invocation_alignment24row dataThe dataset's tactic text could not be matched to any invocation recorded by Lean in that file.
ambiguous_invocation6row dataThe tactic text matched more than one invocation, so the proof state could not be attributed unambiguously.
train -- per-phase breakdown unavailable

This split was extracted over several runs, and the manifest left on disk covers only 3,000 of its 250,814 rows. Rather than report phase counts measured on that fraction as if they described the split, they are omitted. The aggregate coverage above is measured from the published rows themselves and is exact; the causes listed under Coverage all apply here, goal_cardinality and file_compile foremost, but their relative sizes for this split are not established.

val -- 103 rows not published
phaserowskindreason
file_compile53environmentLean could not elaborate the source file within the timeout, or the REPL exited while compiling it. Retryable.
goal_cardinality24extractor limitThe tactic was invoked against multiple pending goals. This extractor records single-goal states only, so these rows are absent by design.
invocation_alignment18row dataThe dataset's tactic text could not be matched to any invocation recorded by Lean in that file.
ambiguous_invocation4row dataThe tactic text matched more than one invocation, so the proof state could not be attributed unambiguously.
theorem_identity4environmentThe theorem's compilation unit could not be identified in the file. Retryable.

Schema

All three representations for a row ship in that same row, so nothing needs to be joined across files. Recursive payloads (source_syntax, local_context, the hypothesis lists) are stored as JSON strings: their shape varies per tactic, and a typed nested column would force either schema inference failures or a lowest-common-denominator union. Call json.loads on them.

columndescription
datasetUpstream dataset name the row came from.
splitUpstream split: train, val, or test.
row_indexRow index within the upstream split. Stable join key.
theoremFully qualified Mathlib theorem name.
file_pathMathlib source path, relative to the repository root.
repo_urlMathlib repository URL.
repo_commitMathlib commit the state was extracted at.
tacticThe tactic text applied at this step.
text_statePretty-printed goal before the tactic, as Lean printed it.
text_target_statePretty-printed goal after the tactic.
raw_goal_sexpSource-faithful S-expression of the goal type.
raw_hyp_sexpsJSON string: list of {name, sexp} for each hypothesis, source-faithful.
model_goal_sexpNormalized S-expression of the goal type.
model_hyp_sexpsJSON string: list of {name, internal_name, context_index, binder_role, is_instance, is_let, sexp}.
source_syntaxJSON string: the tactic's original syntax tree, with identifier leaves annotated by Lean-resolved references. This is the generation target.
syntax_argsJSON string: normalized argument slots of the tactic syntax.
term_rangesJSON string: source ranges of elaborated tactic terms.
local_contextJSON string: the local context with stable indices, for pointer-style argument supervision.
unit_indexIndex of the compilation unit within the file.
invocation_indexIndex of the matched invocation within the unit.
alignment_kindHow the dataset tactic text was matched to the invocation.
target_state_matches_invocationTrue when Lean's post-tactic goal matches the dataset's target state. A useful filter for strict agreement with upstream.
pending_goal_countPending goals at the invocation. Always 1; see coverage.
hypothesis_countNumber of hypotheses in the local context.
hypothesis_names_matchTrue when Lean's hypothesis names match those parsed from the upstream pretty-printed state.
raw_schema_versionSchema version of the source-faithful record.
raw_extractor_versionExtractor version that produced the raw record.
model_schema_versionSchema version of the normalized sidecar.
model_normalizationNormalization identifier applied to model S-expressions.
trace_schema_versionSchema version of the action trace.
trace_extractor_versionExtractor version that produced the action trace.
pantograph_commitPantograph commit used for raw extraction.
model_pantograph_commitPantograph commit used for normalization.
raw_record_sha256Digest binding the sidecars to the raw record. Retained for audit; consumers need not check it, since all three targets ship in one row.
state_sha256SHA-256 of the upstream state text.
tactic_sha256SHA-256 of the upstream tactic text.
target_state_sha256SHA-256 of the upstream target-state text.

Provenance

  • Mathlib commit: 29dcec074de168ac2bf835a77ef68bbe069194c5
  • Upstream dataset: cat-searcher/leandojo-benchmark-4-random
  • Extraction: each Mathlib source file is elaborated with a patched Pantograph REPL, and the proof state Lean records at each matched tactic invocation is captured. States are read from Lean, never parsed back from pretty-printed text.
  • test: extractor lean-action-trace-v3, raw schema v3, Pantograph unknown
  • train: extractor lean-action-trace-v3, raw schema v3, Pantograph unknown
  • val: extractor lean-action-trace-v3, raw schema v3, Pantograph unknown

Limitations

  • Single-goal states only; see Coverage.
  • train coverage is partial and biased; val/test are near-complete.
  • S-expressions are large. Expect the goal and hypothesis columns to dominate memory; select only the representation you need.
  • Normalized and source-faithful S-expressions are different representations of the same state, not alternatives of equal fidelity. Train on model_*; use raw_* when you need exactly what Lean emitted.

License and attribution

This dataset is released under apache-2.0. It is derived work, and both upstream licenses continue to apply to the material they cover:

  • Mathlib 4 is licensed Apache-2.0. Theorem names, tactic text, file paths, and every elaborated term in the S-expression columns derive from Mathlib at commit 29dcec074de168ac2bf835a77ef68bbe069194c5. See <https://github.com/leanprover-community/mathlib4/blob/master/LICENSE>.
  • LeanDojo is licensed MIT. The row selection and the split / row_index assignment are inherited unchanged from the LeanDojo benchmark, so its notice is reproduced below as MIT requires.
MIT License

Copyright (c) 2023 LeanDojo Team

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

Citation

Please cite both upstreams alongside this dataset: Mathlib for the mathematical content, and LeanDojo for the benchmark this dataset's row identity follows.