-
Notifications
You must be signed in to change notification settings - Fork 444
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
incorrect functional induction principle #5347
Comments
Thanks for the report! I'll investigate. If I'm lucky then #4149 might already fix it, we'll see. I was hoping that two separate |
I tried nested match statements but that can cause another problem: #2962 |
A quick test confirms my worry that the [Meta.FunInd] Goal before cleanup:
case hyp
motive : Nat → Prop
t : Nat
f : Nat.ibelow t
k x✝² : Nat
x✝¹ : _root_.f t = some k
x✝ : Nat.ibelow x✝²
⊢ motive x✝²
[Meta.FunInd] Goal after cleanup (toClear := [f, x✝]) (toPreserve := []):
case hyp
motive : Nat → Prop
x✝ : Nat
⊢ motive x✝ But if I put too much stuff into
This may need more careful thought, or a possibly a completely different approach. (Maybe instead of the blunt |
Ah, here is a partial work-around for you: If you put def f (x: Nat): Option Nat :=
if x > 10 then some 0 else none
def test (x: Nat): Nat :=
match f x, h : x with
| some k, _ => k
| none, 0 => 0
| none, n + 1 => test n
/--
info: test.induct (motive : Nat → Prop) (case1 : ∀ (k x : Nat), f x = some k → motive x) (case2 : motive 0)
(case3 : ∀ (n : Nat), f n.succ = none → motive n → motive n.succ) (x : Nat) : motive x
-/
#guard_msgs in
#check test.induct But yes, this is not satisfactory. |
A round of clean-up for the context of the functional induction principle cases. * Already previously, with `match e with | p => …`, functional induction would ensure that `h : e = p` is in scope, but it wouldn’t work in dependent cases. Now it introduces heterogeneous equality where needed (fixes #4146) * These equalities are now added always (previously we omitted them when the discriminant was a variable that occurred in the goal, on the grounds that the goal gets refined through the match, but it’s more consistent to introduce the equality in any case) * We no longer use `MVarId.cleanup` to clean up the goal; it was sometimes too aggressive (fixes #5347) * Instead, we clean up more carefully and with a custom strategy: * First, we substitute all variables without a user-accessible name, if we can. * Then, we substitute all variable, if we can, outside in. * As we do that, we look for `HEq`s that we can turn into `Eq`s to substitute some more * We substitute unused `let`s. **Breaking change**: In some cases leads to a different functional induction principle (different names and order of assumptions, for example).
Prerequisites
Please put an X between the brackets as you perform the following steps:
https://github.com/leanprover/lean4/issues
Avoid dependencies to Mathlib or Batteries.
https://live.lean-lang.org/#project=lean-nightly
(You can also use the settings there to switch to “Lean nightly”)
Description
On the following example,
test.induct
is incorrect.It looks like this:
and
case1
is missing an assumption likef x = some k
.Steps to Reproduce
Run lean on the example.
Expected behavior:
Something like this:
Actual behavior:
Wrong induction principle.
Versions
"4.11.0"
Impact
Add 👍 to issues you consider important. If others are impacted by this issue, please ask them to add 👍 to it.
The text was updated successfully, but these errors were encountered: