Skip to content

fix: make theorem workspace generation robust to source context - #509

Merged
kim-em merged 5 commits into
leanprover:mainfrom
kim-em:codex/robust-statement-extraction
Aug 9, 2026
Merged

fix: make theorem workspace generation robust to source context#509
kim-em merged 5 commits into
leanprover:mainfrom
kim-em:codex/robust-statement-extraction

Conversation

@kim-em

@kim-em kim-em commented Aug 6, 2026

Copy link
Copy Markdown
Collaborator

This PR makes theorem workspace generation robust to the shape of the source declaration, so a problem module can use the constructs that Total variation estimate for hyperbolic systems does without the generated workspace coming out wrong.

Accept direct := sorry bodies and bodies with trivia between := and by, and ignore body-like text in comments and strings. The body marker is the candidate whose body is a sorry running to the end of the declaration, so a statement that opens a tactic block of its own (substInv_X_sub_X_sq_eq_catalan contains a top-level haveI … := by …) is not mistaken for the body.

Preserve scoped notation, syntax and macro commands, and keep the precise inter-declaration context that trusted helpers need: ChallengeDeps.lean deletes only a declaration's own .ilean range rather than everything up to the next declaration, so an intervening variable or local notation survives. Removals still extend back over set_option … in and similar prefixes, which sit outside the range they scope onto.

Pass outer variable parameters through the generated Solution delegation. Which of them Lean retained is read off the elaborated declaration: a hole's body is a sorry, so its value carries exactly one lambda per signature binder, and counting those separates the signature from binders belonging to the statement. The result is reconciled with the source signature and the re-emitted variable commands before use, and generation fails rather than emit a delegation that under-applies. include and omit are carried through as well, since they decide which of those binders the declaration takes.

Validation: lake exe test_generate (49 passed); lake exe lean-eval generate reproduces main's tree apart from blank lines in 20 ChallengeDeps.lean files, all of which typecheck; and the hyperbolic_viscosity workspace from #499 generates and builds.

🤖 Prepared with Claude Code

kim-em and others added 5 commits August 6, 2026 03:33
The elaborated parameter list continues past the signature into the
statement's own binders, so `bvp_comparison` delegated with the `x` bound by
`∀ x ∈ Set.Icc 0 1` and `Solution.lean` failed to compile. Count the leading
lambdas of the elaborated value instead — a hole's body is a `sorry`, so there
is one per signature binder — and reconcile that list with the source
signature and the re-emitted `variable` commands before using it, failing
rather than under-applying when the two views cannot be lined up. Carry
`include` and `omit` into the generated files too, since they decide which of
those binders the declaration takes.

Fix two further regressions in the same reconstruction. A statement can open a
tactic block of its own (`substInv_X_sub_X_sq_eq_catalan`), so take the body
marker to be the candidate whose body is a `sorry` running to the end of the
declaration, and refuse to guess when there is no such candidate and more than
one tactic block. And a `set_option … in` prefixing a removed declaration sits
outside its `.ilean` range (`honeycomb_connective_constant`), so extend
removals back over such prefixes, bounded by the end of the previous
declaration.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CGyHZAhLAv6PVnV9vsqbxd
`by intro x; sorry` also elaborates to a lambda over `sorryAx`, so counting
lambdas separates the signature from the statement only when the source body
is a bare `sorry`. Decide that from the source text, which the body-marker scan
already establishes, and report the parameters as `none` rather than `#[]` when
the extractor cannot read them, so a declaration that takes no explicit
parameters is distinguishable from one we know nothing about.

Reject every disagreement between the elaborated parameters and the source
signature instead of quietly replaying the source binders: the disagreement is
itself evidence that one of the two is wrong, and delegating on either emits a
workspace that does not compile. With no parameters reported and a `variable`
in scope, fail for the same reason.

Track block comments when walking back over `set_option … in` prefixes, so a
comment between the prefix and its declaration no longer strands the prefix.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CGyHZAhLAv6PVnV9vsqbxd
@kim-em
kim-em merged commit ce6f2a2 into leanprover:main Aug 9, 2026
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant