leanprover-community / leanprover-community/mathlib4
simps generates wrong lemma for OrderIso symm_apply
Nobody has claimed this yet.
- Dominant language
- Lean
- Stars
- 4.2k
- Forks
- 1.7k
- PR merge metrics
- No merged PRs in 30d
Description
Since OrderIso is defined as an abbrev of RelIso, @[simps!] automatically uses RelIso.symm for the symm_apply projection, so in the code below the automatically generated lemma foo_symm_apply actually has type (RelIso.symm foo) a✝ = f a✝, which is undesirable (and doesn't use OrderIso.symm.
Unfortunately, there are no easy ways to fix this, since we have 52 automatically generated lemmas involving RelIso.symm _ _ = _ and 59 manually proved lemmas involving e.symm _ = _.
The possible solutions are:
- Go through each of the 52 lemmas generated by
simps, manually remove them and prove theOrderIso.symmversion, and then add a linter against using@[simps!]onOrderIso. Resistance: the smallest. - Remove
OrderIso.symmentirely, and just useRelIso.symm. Resistance: this is still defeq abuse, and the resulting term would not have the correct type, i.e. the resulting term will have typeRelIsoinstead ofOrderIso. - Allow
simpsto be configured on definitions, not just structure. Resistance: probably will take a long time until this actually happens. - Have a simp lemma
e.symm x = RelIso.symm e x. Resistance: this will break the 59 simp lemmas above. - Have a simp lemma
RelIso.symm e x = e.symm x. Resistance: this doesn't actually fix the problem, because@[simps!]will still generate the wrong lemma.
For now, 1. seems to be the least of the evils.
import Mathlib
axiom f : ℕ → ℕ
axiom f_eq {n} : f n = n
@[simps!] noncomputable def foo : ℕ ≃o ℕ where
toFun := f
invFun := f
left_inv _ := by simp [f_eq]
right_inv _ := by simp [f_eq]
map_rel_iff' := by simp [f_eq]
#check foo_symm_apply -- (RelIso.symm foo) a✝ = f a✝
example (n) : foo.symm n = sorry := by simp -- no progress
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the minimal reproduction using @[simps!] on the OrderIso definition and inspect the generated foo_symm_apply type. Review the 52 generated RelIso.symm lemmas and 59 manual OrderIso.symm lemmas mentioned in the issue, then determine which listed approach keeps the affected lemmas consistent and makes the reproduction use OrderIso.symm.
Written by the indexing model from the issue text.
Assessment
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 28/100