Zulip Chat Archive

Stream: mathlib4

Topic: finding `simps` lemmas


Jireh Loreaux (Jan 30 2023 at 20:41):

In mathlib 3 I could do @[simps?] to see the lemmas that simps was generating. What can I do in Lean 4?

Reid Barton (Jan 30 2023 at 20:50):

autocompletion I guess?

Gabriel Ebner (Jan 30 2023 at 21:13):

There's also whatsnew in @[simps] def foo := ... (which works for all commands).

Floris van Doorn (Jan 30 2023 at 21:31):

Did you try @[simps?] in Lean 4?

Jireh Loreaux (Jan 30 2023 at 21:34):

Yes, and that gave me nothing. Actually, whatsnew complains too, because of the syntax (it wants to see the def immediately, not the @[attrs...])

Jireh Loreaux (Jan 30 2023 at 21:34):

So I still don't have a solution to this.

Floris van Doorn (Jan 30 2023 at 21:40):

Jireh Loreaux said:

Yes, and that gave me nothing.

#mwe?

The code

import Mathlib.Tactic.Simps.Basic

@[simps?]
def foo : Nat × Nat := (1, 2)

gives

[simps.verbose] [simps] > generating projection information for structure Prod.

[simps.verbose] [simps] > generated projections for Prod:
            > Projection fst: fun α β x => x.fst
            > Projection snd: fun α β x => x.snd

[simps.verbose] [simps] > adding projection foo_fst:
            > foo.fst = 1

[simps.verbose] [simps] > adding projection foo_snd:
            > foo.snd = 2

It's a linter trace message. Did you turn anything like that off?

Jireh Loreaux (Jan 30 2023 at 22:04):

I confirm that your mwe works for me. However, if you want to see where it was failing for me, pull !4#1949 and have a look at the first @[simps apply] (line 143). There are lots of errors in the file, but they all occur after that declaration. I didn't turn off any linting (at least not consciously). I would troubleshoot, but I need to go teach.

Kevin Buzzard (Jan 30 2023 at 22:12):

whatsnew in works for me, and says that

whatsnew in
/-- `finsupp.map_range` as an equiv. -/
@[simps apply]
def mapRange.equiv (f : M  N) (hf : f 0 = 0) (hf' : f.symm 0 = 0) : (α →₀ M)  (α →₀ N)
    where
  toFun := (mapRange f hf : (α →₀ M)  α →₀ N)
...

produces Finsupp.mapRange.equiv, Finsupp.mapRange.equiv.proof_1 and Finsupp.mapRange.equiv.proof_2. One appealing conclusion consistent with everything is that @[simps apply] creates 0 lemmas. I've never understood @[simps] properly. What's it supposed to produce?

Jireh Loreaux (Jan 30 2023 at 22:15):

oops, I apologize, whatsnew does work for me on that declaration. It didn't work later in the file, but that may have been because of various errors that showed up earlier.

Jireh Loreaux (Jan 30 2023 at 22:16):

simps? doesn't though.

Kevin Buzzard (Jan 30 2023 at 22:18):

What I'm saying is that according to whatsnew, simps is creating 0 new lemmas, and this is consistent with simps? printing out nothing.

Kevin Buzzard (Jan 30 2023 at 22:18):

And what I'm asking is what lemmas you're expecting it to produce, because I don't understand simps.

Jireh Loreaux (Jan 30 2023 at 22:25):

oh, sorry, I understand. Normally simps produces the definitional lemmas associated to data-carrying structure projections (although in mathlib 3 at least it can sometimes do other things too, but sometimes this causes it to timeout). In this case, I think I would be expecting it to make a slightly different lemma:

lemma mapRange.equiv_apply (f : M  N) (hf : f 0 = 0) (hf' : f.symm 0 = 0) (g : α →₀ M) : mapRange.equiv f hf hf' g = mapRange f hf g := rfl

I think it is supposed to make this lemma because of an initialize_simps_projection (since it's not exactly just the structure projection), but I could be wrong.

Floris van Doorn (Jan 30 2023 at 22:34):

This is caused by noncomputable section on line 48. It seems to disable all attributes (including @[simp] or @[simps]) with applicationTime := .afterCompilation. This is a bug in core.
Note: @[simps?] always prints something, even if there are 0 lemmas generated.

Floris van Doorn (Jan 30 2023 at 22:36):

@Gabriel Ebner shall I open an issue in the lean4 repo?

Gabriel Ebner (Jan 30 2023 at 22:38):

Yes please. If you know, can you also please explain why simps should be afterCompilation (i.e., why it can't be afterTypeChecking).

Floris van Doorn (Jan 30 2023 at 22:41):

This is left-over from Lean 3 behavior. simps had to be run after to_additive, to_additive had to be run after simp and simp is afterCompilation. I think this is all unnecessary since !4#1314. I'll try to remove these application times and see if everything is ok.

Floris van Doorn (Jan 30 2023 at 22:58):

lean4#2077

Jireh Loreaux (Jan 30 2023 at 23:55):

Thanks @Floris van Doorn!


Last updated: Dec 20 2023 at 11:08 UTC