Zulip Chat Archive

Stream: mathlib4

Topic: to_additive align failures


Johan Commelin (Jan 18 2023 at 19:27):

Thanks to Mario:

import Mathlib

open Lean

#eval show MetaM _ from do
  let m := Mathlib.Prelude.Rename.getRenameMap ( getEnv)
  for (fr, to') in ToAdditive.translations.getState ( getEnv) do
    match m.toLean3.contains fr, m.toLean3.contains to' with
    | true, false => println! "❌ {to'} <- ✅ {fr}"
    | false, true => println! "❌ {fr} -> ✅ {to'}"
    | _, _ => pure ()

Johan Commelin (Jan 18 2023 at 19:27):

Output: https://gist.github.com/jcommelin/1299f6a0b10e823c96bb251902f209ef

Johan Commelin (Jan 18 2023 at 19:30):

I think that together with mathlib3, we can auto-generate the missing #align statements

Johan Commelin (Jan 18 2023 at 19:33):

:check: Con.instPowQuotientToMulToMulOneClassNat -> :cross_mark: AddCon.Quotient.nsmul

How did that ever become a to_additive pair?

Mario Carneiro (Jan 18 2023 at 19:39):

actually the :cross_mark: is on the left in both cases

Mario Carneiro (Jan 18 2023 at 19:40):

the arrow indicates which one is the multiplicative and which is the additive

Johan Commelin (Jan 18 2023 at 19:40):

oops, contravariance is hard

Johan Commelin (Jan 18 2023 at 19:42):

Fixed the code above, and updated the gist

Johan Commelin (Jan 24 2023 at 14:56):

!4#1816 fixes 1020 of these

Reid Barton (Jan 24 2023 at 15:07):

merge conflict already :)

Johan Commelin (Jan 24 2023 at 15:10):

Fixed

Reid Barton (Jan 24 2023 at 15:16):

Is it ready for review?

Johan Commelin (Jan 24 2023 at 15:16):

I think so.

Johan Commelin (Jan 24 2023 at 15:16):

Let's find out whether CI agrees

Reid Barton (Jan 24 2023 at 15:24):

How automatically-generated is this PR? Maybe it would be better to proceed with !4#1502 first?

Johan Commelin (Jan 24 2023 at 15:24):

It is pretty automatically generated

Reid Barton (Jan 24 2023 at 15:25):

oh, 1502 is actually not as big as I feared

Johan Commelin (Jan 24 2023 at 15:26):

I'm fixing its conflicts

Reid Barton (Jan 24 2023 at 15:26):

On 1502, or 1816?

Johan Commelin (Jan 24 2023 at 15:27):

1502

Reid Barton (Jan 24 2023 at 15:28):

OK, I will look over 1816 then.

Johan Commelin (Jan 24 2023 at 15:29):

@Reid Barton !4#1502 is mergable without conflicts

Reid Barton (Jan 24 2023 at 15:31):

I'm lost

Reid Barton (Jan 24 2023 at 15:31):

Are we merging 1502 first, or 1816?

Johan Commelin (Jan 24 2023 at 15:31):

I think 1502

Johan Commelin (Jan 24 2023 at 15:31):

Because afaik it's ready to go

Reid Barton (Jan 24 2023 at 15:32):

Presumably 1816 will have merge conflicts after that, and you will fix them?

Johan Commelin (Jan 24 2023 at 15:32):

Yeps

Reid Barton (Jan 24 2023 at 15:33):

I'm going to merge master into 1502 manually first, I don't really trust what github thinks

Reid Barton (Jan 24 2023 at 15:34):

Because I think I probably modified some of the Lean 3 names in these #align statements.
So for reviewing at least it would be good to be looking at the correct thing

Reid Barton (Jan 24 2023 at 15:36):

Right so now the first diff is

-@[to_additive (attr := simp)]
+-- todo: should nat power be called `nsmul` here?
+@[to_additive (attr := simp) smul_right]
 theorem pow_right (h : Commute a b) (n : ℕ) : Commute a (b ^ n) :=
   SemiconjBy.pow_right h n
 #align commute.pow_right Commute.pow_rightₓ
 #align add_commute.nsmul_right AddCommute.smul_rightₓ
 -- `MulOneClass.toHasMul` vs. `MulOneClass.toMul`

Reid Barton (Jan 24 2023 at 15:36):

I assume we actually want the name AddCommute.nsmul_right now

Reid Barton (Jan 24 2023 at 15:38):

OK, then I will try to update these

Johan Commelin (Jan 24 2023 at 15:38):

@Reid Barton I'm confused. When I locally try to merge master, I don't get any conflicts.

Reid Barton (Jan 24 2023 at 15:38):

Indeed there are no conflicts as detected by git

Johan Commelin (Jan 24 2023 at 15:38):

Ooh, ok

Reid Barton (Jan 24 2023 at 15:38):

but there are logical conflicts

Johan Commelin (Jan 24 2023 at 15:38):

gotcha

Reid Barton (Jan 24 2023 at 15:39):

e.g. why have add_commute.nsmul_right translated to AddCommute.smul_right

Johan Commelin (Jan 24 2023 at 15:39):

yes, understood. I should have stared at the diff a bit more

Reid Barton (Jan 24 2023 at 16:01):

OK I think I updated 1502, though there's a chance of a build failure

Johan Commelin (Jan 24 2023 at 16:01):

I think/hope that !4#1816 now compiles

Johan Commelin (Jan 24 2023 at 16:02):

I discovered some to_additive clashes that already exist in ml3.

Johan Commelin (Jan 24 2023 at 16:04):

https://github.com/leanprover-community/mathlib/blob/b69c9a770ecf37eb21f7b8cf4fa00de3b62694ec/src/algebra/order/hom/basic.lean#L118
clashes with the decl above it.
The two decls below it also clash.

Johan Commelin (Jan 24 2023 at 16:24):

Pushed more fixes

Reid Barton (Jan 24 2023 at 16:43):

@Floris van Doorn do you have anything to add to !4#1502? I think it is ready to go

Reid Barton (Jan 24 2023 at 16:43):

I added a note to "nat smul lemmas" that were called smul in mathlib3 to rename them.

I think these were bad guesses by porters, and in most cases the lemmas were really called nsmul in mathlib3 as well.

Floris van Doorn (Jan 24 2023 at 16:50):

I'm happy for it to be merged, I'm still catching up on the rest of this thread.

Floris van Doorn (Jan 24 2023 at 16:50):

It seems good to fix all the names that I marked. I was just being conservative.

Reid Barton (Jan 24 2023 at 16:50):

OK, the rest of this thread is really unrelated, except that it will probably have merge conflicts.

Reid Barton (Jan 24 2023 at 16:51):

I put 1502 on the queue then.

Floris van Doorn (Jan 24 2023 at 16:51):

I updated the commit message of !4#1502

Floris van Doorn (Jan 24 2023 at 16:54):

Johan Commelin said:

I discovered some to_additive clashes that already exist in ml3.

Sometimes you have two operations in a lemma statement that each can be multiplicative or additive independently of each other, which gives 4 possible lemmas. However, additivizing any of them will give you the "fully additive" one, so multiple multiplicative lemmas can have the same additivized version. I think this is probably usefully used in some places of mathlib3.

Floris van Doorn (Jan 24 2023 at 16:55):

I delegated !4#1816 btw, but you should merge with master first after !4#1502 is merged


Last updated: Dec 20 2023 at 11:08 UTC