You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Reduced the issue to a self-contained, reproducible test case.
Description
In Lean 3, simp works in the following snippet while in Lean 4 it doesn't. This is maybe due to simp using rw instead of subst internally?
example (q : p → Prop) (h : p = True)
(h' : ∀(q : True → Prop), (∀ x, q x) ↔ q True.intro) :
(∀ h', q h') ↔ q (h.symm ▸ trivial) := by
simp only [h, h'] -- no change in goal in Lean 4-- rw [h] -- motive not type correct :-/
subst h
simp [h'] -- works fine now
This example above has been over-minimised: simp only [h, h'] does not make progress in Lean 3 either, without any imports. There are examples on Zulip which involve mathlib imports; I'll try and make an example which is mathlib-free.
OK so what is actually going on in this example is that in Lean 3, the congr attribute can apparently change the behaviour of simp only, and there are lemmas which are tagged @[congr] in Lean 3 which right now can't be tagged @[congr] in Lean 4. Here is Lean 3 code and Lean 4 code exhibiting the difference:
-- lean 3@[simp]lemmaforall_true_left (p : true → Prop) : (∀ x, p x) ↔ p true.intro :=
sorryexample (p : Prop) (q : p → Prop) (h : p) :
(∀ (h2 : p), q h2) ↔ q h :=
by simp only [h, forall_true_left] -- fails@[congr]lemmaforall_prop_congr' {p p' : Prop} {q q' : p → Prop}
(hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : (∀ h, q h) = ∀ h : p', q' (hp.2 h) :=
sorryexample (p : Prop) (q : p → Prop) (h : p) :
(∀ (h2 : p), q h2) ↔ q h :=
by simp only [h, forall_true_left] -- works
-- Lean 4theoremforall_true_left : ∀ (p : True → Prop), (∀ (x : True), p x) ↔ p True.intro := sorrytheoremforall_prop_congr' {p p' : Prop} {q q' : p → Prop}
(hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : (∀ h, q h) = ∀ h : p', q' (hp.2 h) :=
sorry--attribute [congr] forall_prop_congr'/-invalid 'congr' theorem, equality left/right-hand sides must be applications of the same function (∀ (h : ?p), ?q h) = ∀ (h : ?p'), ?q' (_ : ?p)-/example (p : Prop) (q : p → Prop) (h : p) :
(∀ (h2 : p), q h2) ↔ q h :=
by simp only [h, forall_true_left] -- fails
Stepping back a bit, what is really happening is this. In the mathlib port, sometimes ported simp proofs don't work (there are other examples on the Zulip), and what we are trying to understand right now is whether we should just be fixing the proofs up and pressing on or whether we should be asking questions about the divergence in behaviour and trying to re-align. In short, is Lean 4 simp supposed to be at least as good as Lean 3 simp, or is it just supposed to be different? Furthermore, is @[congr] supposed to be working the way it did in Lean 3?
I ran into this again today while trying to remove some duplication in leanprover-community/mathlib4#7608; it's so annoying to rewrite binders that we end up just proving things from scratch.
Here's a workaround that suggests this limitation is easy to fix:
-- this is in mathlib, but can't be marked `@[congr]` because the head symbol is not a functiontheoremforall_prop_congr' {p p' : Prop} {q q' : p → Prop}
(hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : (∀ h, q h) = ∀ h : p', q' (hp.2 h) :=
sorry-- an alias for `∀` to thwart checks that complain that `∀` is not a functiondefForall {α} (β : α → Sort _) := ∀ a, β a
-- now that we use this alias, `congr` is happy@[congr]theoremForall_prop_congr' {p p' : Prop} {q q' : p → Prop}
(hq : ∀ h, q h ↔ q' h) (hp : p ↔ p') : (Forall fun h => q h) = Forall fun h : p' => q' (hp.2 h) :=
forall_prop_congr' hq hp
example (A B : Prop) (f : A → Nat) (h : A ↔ B) :
∀ h : A, f h = 0 := by
rw [←Forall]
simp [h]
rw [Forall]
-- goal is changed!sorry
Activity
kbuzzard commentedon Dec 8, 2022
This example above has been over-minimised:
simp only [h, h']does not make progress in Lean 3 either, without any imports. There are examples on Zulip which involve mathlib imports; I'll try and make an example which is mathlib-free.kbuzzard commentedon Dec 8, 2022
OK so what is actually going on in this example is that in Lean 3, the
congrattribute can apparently change the behaviour ofsimp only, and there are lemmas which are tagged@[congr]in Lean 3 which right now can't be tagged@[congr]in Lean 4. Here is Lean 3 code and Lean 4 code exhibiting the difference:Stepping back a bit, what is really happening is this. In the mathlib port, sometimes ported
simpproofs don't work (there are other examples on the Zulip), and what we are trying to understand right now is whether we should just be fixing the proofs up and pressing on or whether we should be asking questions about the divergence in behaviour and trying to re-align. In short, is Lean 4simpsupposed to be at least as good as Lean 3simp, or is it just supposed to be different? Furthermore, is@[congr]supposed to be working the way it did in Lean 3?kbuzzard commentedon Dec 14, 2022
This came up again on the Zulip https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/Data.2ERat.2EDefs/near/315861983 .
eric-wieser commentedon Mar 2, 2023
And again on Zulip: https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/simp.20on.20binders/near/339224450, with example
feat: port Algebra.Algebra.Operations (#2568)
feat: port LinearAlgebra.CliffordAlgebra.Grading (#5349)
feat: port LinearAlgebra.CliffordAlgebra.Grading (#5349)
feat: port LinearAlgebra.CliffordAlgebra.Grading (#5349)
feat: port LinearAlgebra.CliffordAlgebra.Grading (#5349)
feat: port LinearAlgebra.CliffordAlgebra.Grading (#5349)
eric-wieser commentedon Oct 12, 2023
I ran into this again today while trying to remove some duplication in leanprover-community/mathlib4#7608; it's so annoying to rewrite binders that we end up just proving things from scratch.
eric-wieser commentedon Oct 12, 2023
Here's a workaround that suggests this limitation is easy to fix:
feat: use `forall_prop_domain_congr` in `simp` tactic