Repository navigation
Description
Prerequisites
Please put an X between the brackets as you perform the following steps:
- Check that your issue is not already filed:
https://github.com/leanprover/lean4/issues - Reduce the issue to a minimal, self-contained, reproducible test case.
Avoid dependencies to Mathlib or Batteries. - Test your test case against the latest nightly release, for example on
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
Using set_option bootstrap.inductiveCheckResultingUniverse false allows the creation of inductive types in Sort u that support primitive projections to types in Sort u, yet with a recursor that only allows eliminating into Prop. This means that primitive projections are currently not conservative over recursors.
Context
Steps to Reproduce
set_option bootstrap.inductiveCheckResultingUniverse false in
set_option genSizeOf false in
set_option genInjectivity false in
inductive Wrap (α : Sort u) : Sort u
| wrap (unwrap : α)
abbrev Wrap.unwrap {α : Sort u} (self : Wrap α) : α := self.1
/--
info: Wrap.rec.{u} {α : Sort u} {motive : Wrap α → Prop} (wrap : ∀ (unwrap : α), motive (Wrap.wrap unwrap)) (t : Wrap α) :
motive t
-/
#guard_msgs in
#check Wrap.recThe recursor for Wrap can only eliminate into Prop since the argument unwrap : α to the constructor is not a Prop. However, primitive projection is allowed since Wrap α : Prop only when α : Prop, and projecting a Prop field is valid. This means that the projection Wrap.unwrap cannot be expressed using the recursor Wrap.rec.
Versions
Lean 4.19.0-nightly-2025-03-22
Additional Information
There seem to be two ways to fix this discrepency between the strength of recursors and projections.
One is to disallow projections for such types, weakening projections to match the existing recursors, and the other is to allow subsingleton elimination for such types, strengthening recursors to match the existing projections.
I have implemented the latter at 0194f05, where the subsingleton elimination check in elim_only_at_universe_zero is modified to check that the fields live in Prop for level assignments that result in the inductive type being in Prop. In the example above, this causes Wrap.rec to support non-Prop motives. This change would also allow structures like PProd and PSigma to avoid having max 1 in their sort level, which could potentially simplify metaprogramming code:
set_option bootstrap.inductiveCheckResultingUniverse false in
structure PProd' (α : Sort u) (β : Sort v) : Sort (max u v) where
fst : α
snd : βImpact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
Activity
kmill commentedon Mar 22, 2025
Quoting @digama0 on Zulip:
cppio commentedon Aug 11, 2025
There are a couple of other potential fixes I missed, so I'll list them all here:
Wrap) from being accepted. Specifically, the kernel should reject non-predicateinductives that do not support large elimination. This fixes the issue since it prevents the recursor from ever being too weak. The inductive types that currently have overly conservative recursors are, aside from this bug, useless, so nothing is lost from this change.Wrapto have large elimination. Specifically, the checks for the constructor arguments should be done after substituting the levels that make the resulting type live inProp. This fixes the issue since it strengthens the recursor in the cases where projection is possible. This is the change I previously suggested and implemented in 0194f05. This change has the added benefit of allowing for more general structures likePProd (α : Sort u) (β : Sort v) : Sort (max u v)andPULift.{r, s} (α : Sort s) : Sort (max s r), which could simplify meta code.Prop. This fixes the issue by having, by definition, the projections never be stronger than the recursor. This change also has the effect of enabling projections forAcc, sinceAccsupports large elimination and the constructor contains the index as a field. Givenh : @Acc α r a, we would haveh.1 : αandh.2 : ∀ y, r y h.1 → Acc r y. Ideally,h.1would reduce toa, so thath.2is equivalent to the currentAcc.inv h, but that would require a special reduction rule for projections that avoids reducing the proof term in situations like these.Propinstead of the current check of whether the current type is aProp. This is a more conservative version of option 3 that avoids the impact of allowing projections forAcc.EDIT: For options 3 and 4, there also needs to be a change in the recursor reduction to prevent eta expansion from occurring.
cppio commentedon Aug 13, 2025
I have just discovered that nested inductives can be used to create stronger recursors:
This behavior is unrelated to projections:
I believe these recursors are still sound, but I'm guessing this behavior is unintentional. Option 1 from my previous list of fixes also fixes this issue.
eric-wieser commentedon Jun 3, 2026
There is a related discussion at #lean4 > PSigma and universe levels @ 💬
Name the upstream issue the lost projections come from
Gather the unsettled tests into a corner-cases group (#171)