Zulip Chat Archive

Stream: mathlib4

Topic: coe confusion


Moritz Firsching (Sep 07 2023 at 12:36):

In #7010, having the following lemma is useful:

lemma coe_toMonoidHom {R R' : Type} [CommMonoid R] [CommMonoidWithZero R'] (χ : MulChar R R')
(x : R) : χ.toMonoidHom x = χ x := by rfl

When looking into if it would be a good idea to add this to NumberTheory/LegendreSymbol/MulCharacter.lean, I noticed that there are many lemmas like this which are potentially useful, like

@[simp]
lemma toMonoidHom_coe (χ : MulChar R R') : χ.toMonoidHom = χ := by
  rfl

@[simp]
lemma toMonoidHom_coe' (χ : MulChar R R') (x : R) : χ.toMonoidHom x = χ x := by
  rfl

@[simp]
lemma toMonoidHom_toFun_coe (χ : MulChar R R') : χ.toMonoidHom.toFun = χ := by
  rfl

@[simp]
lemma toMonoidHom_toFun_coe' (χ : MulChar R R') (x : R) : χ.toMonoidHom.toFun x = χ x := by
  rfl

Which of them should be added and what are the good canonical names for these?

Eric Wieser (Sep 07 2023 at 15:39):

Doesn't the simpNF linter complain there?

Yury G. Kudryashov (Sep 07 2023 at 20:50):

Which function is behind the coercion?

Yury G. Kudryashov (Sep 07 2023 at 20:51):

In any case, you should use rfl, not by rfl to make these lemmas useful for dsimp (or did it change in Lean 4?)

Moritz Firsching (Sep 08 2023 at 05:57):

Eric Wieser said:

Doesn't the simpNF linter complain there?

No, #lint does not complain about that, see #7026. But does this mean all of those lemmas are useful/needed?

Yury G. Kudryashov (Sep 08 2023 at 06:31):

I'm surprised that lemmas No 3 and 4 have LHS in the simp normal form.

Eric Wieser (Sep 08 2023 at 08:28):

Are we missing docs#MonoidHom.toFun_eq_coe ?

Eric Wieser (Sep 08 2023 at 08:29):

Yep, looks like it lost its simp attribute during the port

Eric Wieser (Sep 08 2023 at 08:29):

This is pretty unpleasant:

image.png

Yaël Dillies (Sep 08 2023 at 08:30):

I have a PR in the works to fix this

Eric Wieser (Sep 08 2023 at 08:30):

How?

Eric Wieser (Sep 08 2023 at 08:30):

I don't understand why src#MonoidHom.toMulHom_coe is simpNF

Eric Wieser (Sep 08 2023 at 08:31):

(I also have a PR to fix this (the first of which is #7016), by using flat structures for morphisms so that f.toFun is not syntax for one (but only one) of f.toMulHom.toFun or f.toOneHom.toFun)

Yaël Dillies (Sep 08 2023 at 08:32):

I'm currently worried about lattice homs. I'll move onto algebra homs once I'm done.

Moritz Firsching (Sep 08 2023 at 13:25):

Yury G. Kudryashov said:

In any case, you should use rfl, not by rfl to make these lemmas useful for dsimp (or did it change in Lean 4?)

That's good to know. Is #7039 then a useful change?

Moritz Firsching (Sep 14 2023 at 05:57):

Yaël Dillies said:

I have a PR in the works to fix this

Did you finish the work on this PR or was this is same as @Eric Wieser's #7016? In #7026, I still don't get simpNF lint errors

Yaël Dillies (Sep 14 2023 at 06:27):

Not yet, but my yet-to-be PR is currently only concerned about lattice homs, which I assume are not the ones you use.

Moritz Firsching (Oct 09 2023 at 08:05):

Eric Wieser said:

(I also have a PR to fix this (the first of which is #7016), by using flat structures for morphisms so that f.toFun is not syntax for one (but only one) of f.toMulHom.toFun or f.toOneHom.toFun)

Did you continue making more changes in that direction? ("the first of which" sounds like you might have planned a second one?)

Eric Wieser (Oct 09 2023 at 08:06):

I still haven't fixed the long tail of CI failures in that PR

Eric Wieser (Oct 09 2023 at 08:07):

(oh, that's not the PR I thought it was)

Eric Wieser (Oct 09 2023 at 08:08):

#6791 is the one where I make things flat


Last updated: Dec 20 2023 at 11:08 UTC