jajostrains's picture
Upload folder using huggingface_hub
f44841f verified
|
Raw History Blame Contribute Delete
12 kB
metadata
license: apache-2.0
language:
  - en
pretty_name: Mathlib Normalized S-Expressions
task_categories:
  - text-generation
tags:
  - lean4
  - mathlib
  - theorem-proving
  - s-expressions
  - formal-mathematics
size_categories:
  - 100K<n<1M
configs:
  - config_name: default
    data_files:
      - split: test
        path: test/test-*.parquet
      - split: train
        path: train/train-*.parquet
      - split: val
        path: val/val-*.parquet
dataset_info:
  splits:
    - name: test
      num_examples: 4392
    - name: train
      num_examples: 218727
    - name: val
      num_examples: 4157

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. Source-faithful S-expressions of the goal and every hypothesis, as Lean elaborated them.
  2. Normalized S-expressions of the same state, with stable local-context indices suitable for model input.
  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

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.

split rows published upstream rows coverage
test 4,392 4,506 97.47%
train 218,727 250,814 87.21%
val 4,157 4,260 97.58%
total 227,276 259,580 87.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

phase rows kind reason
file_compile 59 environment Lean could not elaborate the source file within the timeout, or the REPL exited while compiling it. Retryable.
goal_cardinality 25 extractor limit The tactic was invoked against multiple pending goals. This extractor records single-goal states only, so these rows are absent by design.
invocation_alignment 24 row data The dataset's tactic text could not be matched to any invocation recorded by Lean in that file.
ambiguous_invocation 6 row data The 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

phase rows kind reason
file_compile 53 environment Lean could not elaborate the source file within the timeout, or the REPL exited while compiling it. Retryable.
goal_cardinality 24 extractor limit The tactic was invoked against multiple pending goals. This extractor records single-goal states only, so these rows are absent by design.
invocation_alignment 18 row data The dataset's tactic text could not be matched to any invocation recorded by Lean in that file.
ambiguous_invocation 4 row data The tactic text matched more than one invocation, so the proof state could not be attributed unambiguously.
theorem_identity 4 environment The 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.

column description
dataset Upstream dataset name the row came from.
split Upstream split: train, val, or test.
row_index Row index within the upstream split. Stable join key.
theorem Fully qualified Mathlib theorem name.
file_path Mathlib source path, relative to the repository root.
repo_url Mathlib repository URL.
repo_commit Mathlib commit the state was extracted at.
tactic The tactic text applied at this step.
text_state Pretty-printed goal before the tactic, as Lean printed it.
text_target_state Pretty-printed goal after the tactic.
raw_goal_sexp Source-faithful S-expression of the goal type.
raw_hyp_sexps JSON string: list of {name, sexp} for each hypothesis, source-faithful.
model_goal_sexp Normalized S-expression of the goal type.
model_hyp_sexps JSON string: list of {name, internal_name, context_index, binder_role, is_instance, is_let, sexp}.
source_syntax JSON string: the tactic's original syntax tree, with identifier leaves annotated by Lean-resolved references. This is the generation target.
syntax_args JSON string: normalized argument slots of the tactic syntax.
term_ranges JSON string: source ranges of elaborated tactic terms.
local_context JSON string: the local context with stable indices, for pointer-style argument supervision.
unit_index Index of the compilation unit within the file.
invocation_index Index of the matched invocation within the unit.
alignment_kind How the dataset tactic text was matched to the invocation.
target_state_matches_invocation True when Lean's post-tactic goal matches the dataset's target state. A useful filter for strict agreement with upstream.
pending_goal_count Pending goals at the invocation. Always 1; see coverage.
hypothesis_count Number of hypotheses in the local context.
hypothesis_names_match True when Lean's hypothesis names match those parsed from the upstream pretty-printed state.
raw_schema_version Schema version of the source-faithful record.
raw_extractor_version Extractor version that produced the raw record.
model_schema_version Schema version of the normalized sidecar.
model_normalization Normalization identifier applied to model S-expressions.
trace_schema_version Schema version of the action trace.
trace_extractor_version Extractor version that produced the action trace.
pantograph_commit Pantograph commit used for raw extraction.
model_pantograph_commit Pantograph commit used for normalization.
raw_record_sha256 Digest binding the sidecars to the raw record. Retained for audit; consumers need not check it, since all three targets ship in one row.
state_sha256 SHA-256 of the upstream state text.
tactic_sha256 SHA-256 of the upstream tactic text.
target_state_sha256 SHA-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.