feat: add @[reducible_proj] for selective projection unfolding#13562
Draft
kim-em wants to merge 5 commits into
Draft
feat: add @[reducible_proj] for selective projection unfolding#13562kim-em wants to merge 5 commits into
kim-em wants to merge 5 commits into
Conversation
Collaborator
|
Reference manual CI status:
|
|
Mathlib CI status (docs):
|
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
Apr 29, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
Apr 29, 2026
6f8f160 to
8f03161
Compare
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
May 8, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
May 8, 2026
When `whnfCore` reduces a projection `s.field` at low transparency (e.g. `.instances`, used during implicit-arg `isDefEq` when `backward.isDefEq.respectTransparency = true`), it can get stuck if the structure argument `s` is produced by a `[semireducible]` definition. `@[reducible_proj]` opts in a single projection function to trigger a one-time bump to `.default` transparency for the structure-argument WHNF when the configured projection strategy fails to expose a constructor. This mirrors the existing class-field bump machinery (`unfoldProjInst?` / `backward.whnf.reducibleClassField`). Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
The original PR placed the transparency bump only in `whnfCore`'s `.proj` arm. Callers that reduce projection-function applications via `reduceProj?` (grind's `Sym.canon`, `simp`, `cbv`, vcgen, and `unfoldProjInst?` itself) bypass that arm and so never see the bump. Concretely, `attribute [reducible_proj] Functor.obj` in mathlib's CategoryTheory breaks many `grind` proofs because canon short-circuits `whnfCore.proj` and the bump never fires. This commit extracts a `tryReducibleProjBump?` helper next to `reduceProj?` and calls it from both `reduceProj?` and `whnfCore`'s `.proj` arm, so every projection-reduction site honors the attribute uniformly. Three secondary improvements ride along: - Use `withAtLeastTransparency .default` instead of `withTransparency .default`, so the bump only raises transparency. The old code would downgrade from `.all` to `.default`. - The attribute validator now rejects class-field projections, which already have orthogonal support via `unfoldProjInst?` / `backward.whnf.reducibleClassField`. - The `reducibleProjAttr` docstring points at the shared helper. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
`Sym.canon.reduceProjFn?` unfolds the projection function, then re-applies arguments after reducing the kernel projection. The re-application used `mkAppN` without subsequent `.headBeta`. When the structure is a concrete constructor (so the projected field is a lambda), the result was an unbeta'd `(fun x => body) y`, which is a distinct term from `body[y]` in the e-graph. This was latent: before `[reducible_proj]`, `reduceProj?` would only return `Some` for fully evaluated constructors that rarely appear in canon's input, so the bug had no observable effect. With the bump in `reduceProj?` (previous commit), projection-function applications like `Functor.obj (F⋙G) X` now reduce to `(fun X => G.obj (F.obj X)) X` and the missing `.headBeta` becomes visible — `grind`'s ematch fails to recognize the term. Mirrors the `.headBeta` already used in `unfoldProjInst?`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Extends `tests/elab/reducibleProj.lean` with: - A `grind`-driven natural-transformation `hcomp` regression. Without the preceding two fixes, ematch fires `Functor.comp_obj` but canon collapses the asserted equality without recording an eqc edge, and `NatTrans.naturality` never fires on `(F ⋙ H).map f ≫ β.app (F.obj Y)`. With the fixes, `grind` discharges naturality. - A validator test rejecting class-field projections. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
8f03161 to
b5854c5
Compare
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/batteries
that referenced
this pull request
May 12, 2026
mathlib-nightly-testing Bot
pushed a commit
to leanprover-community/mathlib4-nightly-testing
that referenced
this pull request
May 12, 2026
leanprover-bot
added a commit
to leanprover/reference-manual
that referenced
this pull request
May 12, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
When
whnfCorereduces a projections.fieldat low transparency (e.g..instances, used during implicit-argisDefEqwhenbackward.isDefEq.respectTransparency = true), it can get stuck ifsis produced by a[semireducible]definition.Concrete case in Mathlib (
CategoryTheory.Whiskering,CategoryTheory.EssentialImage, and ~588 other CategoryTheory files):Currently the only workarounds are:
Functor.comp)[implicit_reducible]— heavy hammer; affects all uses.backward.isDefEq.respectTransparency falselocally — restores old globally permissive behavior.@[reducible_proj]opts a single projection function (e.g.Functor.obj) into a one-time transparency bump for the structure-argument WHNF when the configured projection strategy fails to expose a constructor. The bump is local to the projection reduction; it does not change the transparency of surroundingisDefEqwork.This is the structure-projection analogue of the existing class-field machinery (
unfoldProjInst?/backward.whnf.reducibleClassField), which does exactly the same thing for[reducible]class fields whose underlying instance is[implicit_reducible].🤖 Prepared with Claude Code