Zulip Chat Archive

Stream: mathlib4

Topic: bump to 2023-02-06


Johan Commelin (Feb 06 2023 at 11:31):

This bump will bring https://github.com/leanprover/lean4/pull/2093 to mathlib.

First error is in Data.Rat.Defs:

instance isDomain : IsDomain  :=
  NoZeroDivisors.to_isDomain _
-- failed to synthesize
--   NoZeroDivisors ℚ
-- (deterministic) timeout at 'typeclass', maximum number of heartbeats (20000) has been reached (use 'set_option
-- synthInstance.maxHeartbeats <num>' to set the limit)

Eric Wieser (Feb 06 2023 at 11:34):

Do you have a branch/PR for this already?

Johan Commelin (Feb 06 2023 at 11:35):

!4#2105 -- bump-2023-02-06

Eric Wieser (Feb 06 2023 at 11:39):

I'll have a look once the cache is ready

Johan Commelin (Feb 06 2023 at 11:44):

Failing trace:

[Meta.synthInstance]  Ring  

[Meta.isDefEq]  ?m.28264 =?= CommRing.toRing 

[Meta.synthInstance]  Nontrivial  

[Meta.isDefEq]  ?m.28265 =?= CommGroupWithZero.toNontrivial 

[Meta.synthInstance] 💥 NoZeroDivisors  
  [] new goal NoZeroDivisors  
  []  apply @CanonicallyOrderedCommSemiring.toNoZeroDivisors to NoZeroDivisors  
  []  apply @LinearOrderedRing.noZeroDivisors to NoZeroDivisors  

[Meta.isDefEq]  IsDomain  =?= IsDomain  

[Meta.synthInstance] 💥 NoZeroDivisors  
  [] new goal NoZeroDivisors  
  []  apply @CanonicallyOrderedCommSemiring.toNoZeroDivisors to NoZeroDivisors  
  []  apply @LinearOrderedRing.noZeroDivisors to NoZeroDivisors  

[Meta.isDefEq]  IsDomain  =?= IsDomain 

Start of succesful trace (with maxHeartbeats):

[Meta.synthInstance]  Ring  

[Meta.isDefEq]  ?m.28264 =?= CommRing.toRing 

[Meta.synthInstance]  Nontrivial  

[Meta.isDefEq]  ?m.28265 =?= CommGroupWithZero.toNontrivial 

[Meta.synthInstance]  NoZeroDivisors  
  [] new goal NoZeroDivisors  
  []  apply @CanonicallyOrderedCommSemiring.toNoZeroDivisors to NoZeroDivisors  
    [tryResolve]  NoZeroDivisors   NoZeroDivisors ?m.29337 
      [isDefEq]  NoZeroDivisors  =?= NoZeroDivisors ?m.29337 
        []   =?= ?m.29337 
        [synthInstance]  CanonicallyOrderedCommSemiring  
          [] no instances for CanonicallyOrderedCommSemiring  
            [instances] #[]
        []  NonUnitalNonAssocRing.toMul =?= CanonicallyOrderedCommSemiring.toMul 
          []  NonAssocRing.toNonUnitalNonAssocRing.2 =?= ?m.29338.2 
            []  NonAssocRing.toNonUnitalNonAssocRing =?= ?m.29338 
              [] NonAssocRing.toNonUnitalNonAssocRing [nonassignable] =?= ?m.29338 [assignable]
              []  CanonicallyOrderedCommSemiring  =?= NonUnitalNonAssocRing  
                []  CanonicallyOrderedCommSemiring =?= NonUnitalNonAssocRing
                [onFailure]  CanonicallyOrderedCommSemiring  =?= NonUnitalNonAssocRing 
                [onFailure]  CanonicallyOrderedCommSemiring  =?= NonUnitalNonAssocRing 
              []  CanonicallyOrderedCommSemiring  =?= NonUnitalNonAssocRing 
            []  NonUnitalNonAssocSemiring.toMul =?= ?m.29338.2 
              []  NonUnitalSemiring.toNonUnitalNonAssocSemiring.2 =?= ?m.29338.2 
                []  NonUnitalSemiring.toNonUnitalNonAssocSemiring =?= ?m.29338 
                  [] NonUnitalSemiring.toNonUnitalNonAssocSemiring [nonassignable] =?= ?m.29338 [assignable]
                  []  CanonicallyOrderedCommSemiring  =?= NonUnitalNonAssocSemiring  
                    []  CanonicallyOrderedCommSemiring =?= NonUnitalNonAssocSemiring
                    [onFailure]  CanonicallyOrderedCommSemiring  =?= NonUnitalNonAssocSemiring 
                    [onFailure]  CanonicallyOrderedCommSemiring  =?= NonUnitalNonAssocSemiring 
                  []  CanonicallyOrderedCommSemiring  =?= NonUnitalNonAssocSemiring 
                []  { mul := fun x x_1 => x * x_1 } =?= ?m.29338.2 
                  []  Mul  =?= Mul  
                    []   =?= 
                  []  Mul.mul =?= fun x x_1 => x * x_1 
                    []  fun x x_1 => x * x_1 =?= fun a => Mul.mul a 
                      []   =?= 
                      []  fun x => x * x =?= Mul.mul x 
                        []  fun x => x * x =?= fun a => Mul.mul x a 
                          []   =?= 
                          []  x✝¹ * x =?= Mul.mul x✝¹ x 
                            []  Mul.mul x✝¹ x =?= Mul.mul x✝¹ x 
                              []  x✝¹ =?= x✝¹
                              []  x =?= x
                              []   =?= 
                              []  Rat.instMulRat =?= ?m.29338.2 
                                []  { mul := Rat.mul } =?= ?m.29338.2 
                                  []  Mul  =?= Mul  
                                  []  Mul.mul =?= Rat.mul 
                                    []  ?m.29338.2.1 =?= Rat.mul 
                                      [onFailure]  ?m.29338.2.1 =?= Rat.mul
                                  [onFailure]  { mul := Rat.mul } =?= ?m.29338.2
                              []  Rat.instMulRat.1 x✝¹ x =?= ?m.29338.2.1 x✝¹ x 
                                []  Rat.mul x✝¹ x =?= ?m.29338.2.1 x✝¹ x 
                                  []  Rat.mul =?= ?m.29338.2.1 
                                    [onFailure]  Rat.mul =?= ?m.29338.2.1
                                  [onFailure]  Rat.mul x✝¹ x =?= ?m.29338.2.1 x✝¹ x
                                  [onFailure]  Rat.mul x✝¹ x =?= ?m.29338.2.1 x✝¹ x
                  [onFailure]  { mul := fun x x_1 => x * x_1 } =?= ?m.29338.2
        [onFailure]  NoZeroDivisors  =?= NoZeroDivisors ?m.29337
        [onFailure]  NoZeroDivisors  =?= NoZeroDivisors ?m.29337
  []  apply @LinearOrderedRing.noZeroDivisors to NoZeroDivisors  
    [tryResolve]  NoZeroDivisors   NoZeroDivisors ?m.29351 
      [isDefEq]  NoZeroDivisors  =?= NoZeroDivisors ?m.29351 
        []   =?= ?m.29351 
          []  [nonassignable] =?= ?m.29351 [assignable]
          []  Type ?u.29335 =?= Type
        []  NonUnitalNonAssocRing.toMul =?= NonUnitalNonAssocRing.toMul 
          []   =?= 
          []  NonAssocRing.toNonUnitalNonAssocRing =?= NonAssocRing.toNonUnitalNonAssocRing 
            []   =?= 
            []  Ring.toNonAssocRing =?= Ring.toNonAssocRing 
              []   =?= 
              []  CommRing.toRing =?= StrictOrderedRing.toRing 
                []  Rat.commRing.1 =?= LinearOrderedRing.toStrictOrderedRing.1 
                  []  Rat.commRing =?= LinearOrderedRing.toStrictOrderedRing 
                    []  CommRing.mk Rat.mul_comm =?= LinearOrderedRing.toStrictOrderedRing 
                      []  StrictOrderedRing  =?= CommRing  
                        []  StrictOrderedRing =?= CommRing
                        [onFailure]  StrictOrderedRing  =?= CommRing 
                        [onFailure]  StrictOrderedRing  =?= CommRing 
                      []  CommRing.mk Rat.mul_comm =?= ?m.29352.1 
                        []  StrictOrderedRing  =?= CommRing  
                          []  StrictOrderedRing =?= CommRing
                          [onFailure]  StrictOrderedRing  =?= CommRing 
                          [onFailure]  StrictOrderedRing  =?= CommRing 
                        [onFailure]  CommRing.mk Rat.mul_comm =?= ?m.29352.1
                  []  Ring.mk zsmulRec Rat.add_left_neg =?= LinearOrderedRing.toStrictOrderedRing.1 
                    []  Ring  =?= Ring 
                    []  Ring.toSemiring =?= Semiring.mk Rat.one_mul Rat.mul_one npowRec 
                      []  Semiring  =?= Semiring 
                      []  Semiring.toNonUnitalSemiring =?= NonUnitalSemiring.mk Rat.mul_assoc 
                        []  NonUnitalSemiring  =?= NonUnitalSemiring 
                        []  NonUnitalSemiring.toNonUnitalNonAssocSemiring =?= NonUnitalNonAssocSemiring.mk Rat.mul_add Rat.add_mul Rat.zero_mul
                              Rat.mul_zero 
                          []  NonUnitalNonAssocSemiring  =?= NonUnitalNonAssocSemiring 
                          []  NonUnitalNonAssocSemiring.toAddCommMonoid =?= AddCommMonoid.mk Rat.add_comm 
                            []  AddCommMonoid  =?= AddCommMonoid 
                            []  AddCommMonoid.toAddMonoid =?= AddMonoid.mk Rat.zero_add Rat.add_zero nsmulRec 
                              []  AddMonoid  =?= AddMonoid 
                              []  AddMonoid.toAddSemigroup =?= AddSemigroup.mk Rat.add_assoc 
                                []  AddSemigroup  =?= AddSemigroup 
                                []  AddSemigroup.toAdd =?= { add := fun x x_1 => x + x_1 } 
                                  []  Add  =?= Add 
                                  []  Add.add =?= fun x x_1 => x + x_1 
                                  []  AddMonoid.toAddSemigroup.1 =?= { add := fun x x_1 => x + x_1 } 

Johan Commelin (Feb 06 2023 at 11:44):

I don't if this is now 2003 kicking in?

Eric Wieser (Feb 06 2023 at 11:57):

I was able to fix one of the 8 timeouts by locally bumping the set_option synthInstance.maxHeartbeat setting; maybe that's a reasonable thing to do while waiting for lean4#2003

Johan Commelin (Feb 06 2023 at 12:09):

I'm doing that in a score of files now

Johan Commelin (Feb 06 2023 at 12:10):

$ git diff --stat
 Mathlib/Algebra/Module/Basic.lean            | 1 +
 Mathlib/Algebra/Module/LinearMap.lean        | 3 +++
 Mathlib/Algebra/Order/Archimedean.lean       | 4 ++++
 Mathlib/Algebra/PUnitInstances.lean          | 1 +
 Mathlib/Algebra/Ring/Prod.lean               | 1 +
 Mathlib/Algebra/Star/SelfAdjoint.lean        | 2 ++
 Mathlib/Data/Fin/Basic.lean                  | 4 ++++
 Mathlib/Data/Int/AbsoluteValue.lean          | 1 +
 Mathlib/Data/Int/GCD.lean                    | 1 +
 Mathlib/Data/Int/Parity.lean                 | 4 ++++
 Mathlib/Data/Multiset/Basic.lean             | 1 +
 Mathlib/Data/Nat/Bitwise.lean                | 2 ++
 Mathlib/Data/Nat/ModEq.lean                  | 1 +
 Mathlib/Data/Rat/Defs.lean                   | 3 ++-
 Mathlib/Data/ZMod/Defs.lean                  | 1 +
 Mathlib/GroupTheory/GroupAction/ConjAct.lean | 1 +
 Mathlib/RingTheory/Congruence.lean           | 3 +++
 Mathlib/Tactic/Abel.lean                     | 1 +
 Mathlib/Tactic/Linarith/Parsing.lean         | 3 +++
 Mathlib/Tactic/Positivity/Basic.lean         | 1 +
 20 files changed, 38 insertions(+), 1 deletion(-)

Johan Commelin (Feb 06 2023 at 12:11):

But this is clearly not sustainable.

Johan Commelin (Feb 06 2023 at 12:11):

I don't think we should merge this PR with all those maxHeartbeats.

Eric Wieser (Feb 06 2023 at 12:18):

I'd argue that having slow typeclass resolution is better than having typeclass resolution that never works in some cases (as in mathlib4 master); so if it unblocks the port, I think adding these while waiting for 2003 is reasonable

Johan Commelin (Feb 06 2023 at 12:18):

theorem _root_.MulAut.conjNormal_apply {H : Subgroup G} [H.Normal] (g : G) (h : H) :
    (MulAut.conjNormal g h) = g * h * g⁻¹ :=
/-
function expected at
  ↑MulAut.conjNormal g
term has type
  (fun x => MulAut { x // x ∈ ?m.294870 }) g
-/

Johan Commelin (Feb 06 2023 at 12:18):

:up: is not solved by increasing heartbeats

Eric Wieser (Feb 06 2023 at 12:18):

docs4#MulAut.conjNormal

Eric Wieser (Feb 06 2023 at 12:20):

Does (MulAut.conjNormal g : MulAut H) h work in place of MulAut.conjNormal g h?

Johan Commelin (Feb 06 2023 at 12:20):

yes it does, and it's quite fast

Johan Commelin (Feb 06 2023 at 12:20):

do you understand why this change is needed by the bump?

Eric Wieser (Feb 06 2023 at 12:21):

I would guess that it found a different instance to the one it did before, and the new one is less helpful for unification

Eric Wieser (Feb 06 2023 at 12:21):

And that somehow, that unification failure is preventing the CoeFun instance from firing; maybe because the metavariable wasn't filled in

Eric Wieser (Feb 06 2023 at 12:22):

We have similar problems in mathlib3 where sometimes map_mul F x y fails but map_mul (F : some_annotation) x y works

Eric Wieser (Feb 06 2023 at 12:22):

It hasn't happened for has_coe_to_fun in Lean3, but Lean4 is sufficiently different that it wouldn't be too surprising for a similar thing to occur there

Johan Commelin (Feb 06 2023 at 12:24):

I pushed a commit that changes 24 files. It doesn't look like I'm almost done.

Johan Commelin (Feb 06 2023 at 12:24):

This looks like serious problems to me.

Eric Wieser (Feb 06 2023 at 12:26):

Can we change the default hearbeats globally?

Johan Commelin (Feb 06 2023 at 12:28):

I don't like that idea. mathlib 4 shouldn't be slower than mathlib 3.

Johan Commelin (Feb 06 2023 at 12:28):

I think we should fix these problems before pouring more person-weeks into the port.

Eric Wieser (Feb 06 2023 at 12:28):

The default hearbeat limit in lean4 is 5x smaller than the value in Lean3 I think

Eric Wieser (Feb 06 2023 at 12:29):

Johan Commelin said:

I think we should fix these problems before pouring more person-weeks into the port.

My worry is that if we don't make these workarounds, people will make worse workaround when porting that are harder to undo

Johan Commelin (Feb 06 2023 at 12:55):

Order.Partition.Finpartition is really bad, around L525. With

set_option maxHeartbeats 0 in -- Porting note: this is too slow
set_option synthInstance.maxHeartbeats 0 in -- Porting note: this is too slow

it just sits there and blankly stares you in the face.

Eric Wieser (Feb 06 2023 at 12:57):

Is there a wiki page on diagnosing these timeouts (what trace options to set, how to expand the tree view entirely, etc...)

Johan Commelin (Feb 06 2023 at 12:59):

Not that I know of

Reid Barton (Feb 06 2023 at 13:15):

I think what's happening is the version bump is allowing TC synthesis to explore some options that it previously couldn't, and then other TC issues is making these branches very expensive

Johan Commelin (Feb 06 2023 at 13:21):

Order.Partition.Finpartition has now been staring blankly in my face for > 20 minutes.

Johan Commelin (Feb 06 2023 at 13:21):

So this PR is very non-mergeable.

Johan Commelin (Feb 06 2023 at 13:39):

Yuchai!

set_option synthInstance.maxHeartbeats 0 in -- Porting note: this is too slow
open Classical in -- Porting note: haha

works!

Johan Commelin (Feb 06 2023 at 13:41):

$ git diff master... --stat
 Mathlib/Algebra/BigOperators/Finsupp.lean     |  2 +-
 Mathlib/Algebra/BigOperators/Intervals.lean   |  2 ++
 Mathlib/Algebra/DirectSum/Basic.lean          |  2 ++
 Mathlib/Algebra/GeomSum.lean                  |  2 ++
 Mathlib/Algebra/Module/Basic.lean             |  1 +
 Mathlib/Algebra/Module/LinearMap.lean         |  7 +++++++
 Mathlib/Algebra/Module/Submodule/Basic.lean   |  2 ++
 Mathlib/Algebra/Module/ULift.lean             |  4 ++++
 Mathlib/Algebra/Order/Archimedean.lean        |  4 ++++
 Mathlib/Algebra/PUnitInstances.lean           |  1 +
 Mathlib/Algebra/Periodic.lean                 |  4 ++++
 Mathlib/Algebra/Quandle.lean                  |  2 ++
 Mathlib/Algebra/Ring/Prod.lean                |  1 +
 Mathlib/Algebra/Star/SelfAdjoint.lean         |  2 ++
 Mathlib/Data/Fin/Basic.lean                   |  4 ++++
 Mathlib/Data/Finsupp/Order.lean               |  2 ++
 Mathlib/Data/Int/AbsoluteValue.lean           |  1 +
 Mathlib/Data/Int/GCD.lean                     |  1 +
 Mathlib/Data/Int/Parity.lean                  |  4 ++++
 Mathlib/Data/Multiset/Basic.lean              |  1 +
 Mathlib/Data/Nat/Bitwise.lean                 |  2 ++
 Mathlib/Data/Nat/ModEq.lean                   |  1 +
 Mathlib/Data/Rat/Defs.lean                    |  3 ++-
 Mathlib/Data/Real/Basic.lean                  |  1 +
 Mathlib/Data/Sign.lean                        |  6 ++++++
 Mathlib/Data/UInt.lean                        |  2 ++
 Mathlib/Data/ZMod/Defs.lean                   |  1 +
 Mathlib/GroupTheory/GroupAction/ConjAct.lean  | 10 +++++++---
 Mathlib/GroupTheory/Subgroup/Pointwise.lean   |  1 +
 Mathlib/GroupTheory/Submonoid/Pointwise.lean  |  2 ++
 Mathlib/Order/Partition/Finpartition.lean     | 16 ++++++++++------
 Mathlib/RingTheory/Congruence.lean            |  3 +++
 Mathlib/RingTheory/Subsemiring/Pointwise.lean |  3 ++-
 Mathlib/Tactic/Abel.lean                      |  1 +
 Mathlib/Tactic/Linarith/Parsing.lean          |  3 +++
 Mathlib/Tactic/Positivity/Basic.lean          |  1 +
 lean-toolchain                                |  2 +-
 37 files changed, 94 insertions(+), 13 deletions(-)

Johan Commelin (Feb 06 2023 at 13:41):

This branch now builds.... :turtle: :turtle: :turtle:

Johan Commelin (Feb 06 2023 at 13:49):

cc @Gabriel Ebner you might be interested in !4#2105 (aka bump-2023-02-06). It is the mathlib fallout of the eta for structures PR.

Johan Commelin (Feb 06 2023 at 14:44):

Ooh noes! CI is now complaining about a lot of linting failures because of timeouts.
https://github.com/leanprover-community/mathlib4/actions/runs/4104664586/jobs/7080448378

Kevin Buzzard (Feb 06 2023 at 14:47):

Do you dare try merging master into 2003 and seeing if it helps?

Johan Commelin (Feb 06 2023 at 14:47):

Do you mean merging 2003 into the bump branch?

Johan Commelin (Feb 06 2023 at 14:48):

I would have to figure out how to build my own Lean 4.

Kevin Buzzard (Feb 06 2023 at 14:48):

Yeah I mean maybe 2003 helps

Kevin Buzzard (Feb 06 2023 at 14:48):

I'm just an optimist

Reid Barton (Feb 06 2023 at 14:49):

I think there is a decent chance, because there were some failures from 2003 which might be fixed by the new patch.

Johan Commelin (Feb 06 2023 at 14:49):

I'll see if I can convince my computer to build 2003 (after merging master into it) and then convince elan to use that build

Johan Commelin (Feb 06 2023 at 14:50):

Merging master into leanprover/lean4#2003 should be done anyway, right?

Kevin Buzzard (Feb 06 2023 at 14:50):

Oh I guess

Johan Commelin (Feb 06 2023 at 15:00):

/me doesn't have a working cmake :sad:

Reid Barton (Feb 06 2023 at 15:06):

I can give it a shot.

Johan Commelin (Feb 06 2023 at 15:06):

nix-shell -A nix seems to work (-;

Johan Commelin (Feb 06 2023 at 15:22):

Ok, I have a local build of (2003 + lean4 master). How should I instruct elan to use that build to build mathlib 4?

Jannis Limperg (Feb 06 2023 at 15:24):

# set up the Lean 4 toolchain
elan toolchain link lean4-master build/release/stage1
# use the toolchain as an override in the mathlib4 directory
elan override set lean4-master

Johan Commelin (Feb 06 2023 at 15:25):

aha, thanks!

Johan Commelin (Feb 06 2023 at 15:26):

hmm, nix probably has different ideas about where stage1 ends up

Jannis Limperg (Feb 06 2023 at 15:36):

Ah yes, sorry, I was assuming the cmake build.

Jannis Limperg (Feb 06 2023 at 15:39):

I can't find instructions in the manual for using a Nix-based Lean 4 build to build a project. However, you might be able to get a working cmake via nix-shell.

Johan Commelin (Feb 06 2023 at 15:41):

anyway, 2003 seems to build fine after merging master. But the PR is from Gabriel's fork, so I can't update the PR anyways.

Johan Commelin (Feb 06 2023 at 15:41):

And it's about time I start catching a train, so I don't think I can do a mathlib build with that local toolchain today either.

Reid Barton (Feb 06 2023 at 17:22):

There are still the same errors.

Reid Barton (Feb 06 2023 at 17:24):

I think they are likely related to #2055

Reid Barton (Feb 06 2023 at 17:36):

hmm, actually probably not

Johan Commelin (Feb 06 2023 at 17:46):

ftr leanprover/lean4#2055

Kevin Buzzard (Feb 06 2023 at 18:23):

@Gabriel Ebner is there any way I can help making lean4#2055 easier to diagnose at the dev end?

Reid Barton (Feb 06 2023 at 18:26):

What's going on in Data.Rat.Defs:

  1. We are trying to process instance isDomain : IsDomain ℚ := NoZeroDivisors.to_isDomain _
  2. So we need lemma NoZeroDivisors.to_isDomain [Ring α] [h : Nontrivial α] [NoZeroDivisors α] : IsDomain α := [...]
  3. So we need Nontrivial ℚ.
  4. Now we try out instance [AddMonoidWithOne α] [CharZero α] : Nontrivial α := [...]. Note: Of course ℚ actually does have characteristic zero, but we don't know that at this point of Data.Rat.Defs.
  5. Next we try instance (priority := 100) StrictOrderedSemiring.to_charZero [StrictOrderedSemiring α] : CharZero α. Note however that CharZero has type class CharZero (R) [AddMonoidWithOne R] : Prop, so it has an implicit instance argument derived from the StrictOrderedSemiring one. At this point we also don't know anything about the compatibility of the ring structure and ordering of ℚ.
  6. To apply this instance we unify @CharZero ℚ (AddMonoidWithOne instance for ℚ) =?= @CharZero ?t (... (?i : StrictOrderedSemiring ℚ)). We deduce ?t = ℚ and then try to make some more reductions but eventually realize we need to synthesize ?i.
  7. This fails quickly because we don't have this instance yet. But, that doesn't cause the defeq problem we were working on to fail.
  8. Now it spends a huge amount of time trying to solve a failing defeq problem for some reason.

Reid Barton (Feb 06 2023 at 18:30):

There is probably a lot of room for improvement here but I think the most unexpected thing here is in 7

Kevin Buzzard (Feb 06 2023 at 18:49):

Is it hard to minimise 7 and 8?

Eric Wieser (Feb 06 2023 at 19:08):

What instance are we expecting to find here?

Reid Barton (Feb 06 2023 at 19:13):

It never gets that far, so I don't know, but I trust that it follows from CommGroupWithZero somehow.

Reid Barton (Feb 06 2023 at 19:15):

Kevin Buzzard said:

Is it hard to minimise 7 and 8?

class A (α : Type) where
  a : α  α  α

class B (α : Type) extends A α where
  b :  x y, a x y = a y x

class A' (α : Type) where
  a' : α  α  α

instance {α : Type} [A' α] : A α where
  a x y := id (A'.a' (id x) (id y))

class C (α : Type) [A α] where
  c : α  α  α

instance I {α : Type} [B α] : C α where
  c x _y := x

theorem T (α : Type) [A α] [C α] (x : α) : x = x := rfl

set_option pp.all true in
set_option trace.Meta.isDefEq true in
set_option trace.Meta.synthInstance true in
theorem U (α : Type) [i : A' α] (x : α) : x = x := T α x

Relevant section of trace output

Johan Commelin (Feb 06 2023 at 19:23):

So this is unrelated to lean4#2003, right?

Johan Commelin (Feb 06 2023 at 19:23):

Is it one of the other issues that Kevin has created over the past few weeks?

Johan Commelin (Feb 06 2023 at 19:24):

Or is it something new altogether?

Reid Barton (Feb 06 2023 at 19:37):

I don't recognize it as an existing issue

Gabriel Ebner (Feb 06 2023 at 19:38):

From what I can tell this is a somewhat unfortunate collaboration with the 2003 issue.

  1. Due to 2003, we get lots of unification problems like (... : StrictOrderedRing ℚ).1 =?= Ring.mk ...
  2. Structure eta then thinks "maybe we can solve it by adding another projection" and generates the new problem (... : StrictOrderedRing ℚ).1.toSemiring =?= ...
  3. Note that .1 is a primitive projection and .toRing is a definition, so this cleverly disables caching.

Reid Barton (Feb 06 2023 at 19:40):

Well, it probably has something similarity to 2055 because that one also involves a failing defeq test doing a lot of work.

Kevin Buzzard (Feb 06 2023 at 19:56):

I was inspired by this conversation to try and minimise 2055 a bit more, and think I succeeded. I've also posted on github; hopefully this new version is much easier to grok. Reid can you minimise even further? I don't know how to remove simp but maybe you do.

class A1 (M : Type u) extends Mul M

class A2 (M : Type u) extends A1 M

class A3 (M : Type u) extends A2 M

class A4 (M : Type u) extends A3 M

class B1 (M : Type u) extends Mul M

class CommRing (M : Type u) extends B1 M, A4 M

-- given `CommRing R` there are two distinct routes to `Mul R`:
-- CommRing -> B1 -> Mul
-- CommRing -> A4 -> A3 -> A2 -> A1 -> Mul

-- random extra bad class plus simp lemma which causes all the trouble
class BadClass (M : Type u) extends A4 M
@[simp] theorem mul_right_eq_self {M : Type u} [inst : BadClass M] {a b c : M} :
    a * b = a  b = c := sorry

set_option trace.Meta.synthInstance true

variable {R : Type _} [i : CommRing R] (a b c : R)
example :
  -- use the two multiplications to say a * b = c ↔ a * b = c
  (@HMul.hMul R R R
    (@instHMul R (@A1.toMul R (@A2.toA1 R (@A3.toA2 R (@A4.toA3 R (@CommRing.toA4 R i))))))
    a b) = c 
  (@HMul.hMul R R R
    (@instHMul R (@B1.toMul R (@CommRing.toB1 R i)))
    a b) = c := by
  -- ⊢ a * b = c ↔ a * b = c
  -- exact Iff.rfl -- works
  simp
/-
[Meta.synthInstance] ❌ BadClass R ▶

[Meta.synthInstance] ❌ BadClass R ▶

[Meta.synthInstance] ❌ BadClass R ▶

[Meta.synthInstance] ❌ BadClass R ▶

[Meta.synthInstance] ❌ BadClass R ▶

[Meta.synthInstance] ❌ BadClass R ▶

[Meta.synthInstance] ❌ BadClass R ▶
...
307 times
-/

Reid Barton (Feb 06 2023 at 19:57):

I still think it is surprising that we get to step 8 at all. It breaks the conception of the TC system as a little Prolog language. In addition to the facts that are added as instances, there's whatever facts Lean can "deduce" by unification.

Johan Commelin (Feb 06 2023 at 19:58):

@Gabriel Ebner Are you saying that adding 2003 to the current situation is only going to make things worse :fear: ?

Kevin Buzzard (Feb 06 2023 at 19:58):

I spent a lot of time trying to game the numbers. Increasing the B string does very little. Increasing the A string does lots. The optimal (in the sense that it makes the number of failures largest) place to put the bad class is coming off the last A class. No idea if this helps.

Reid Barton (Feb 06 2023 at 19:58):

@Kevin Buzzard Did you try using mul_right_eq_self as the whole proof?

Gabriel Ebner (Feb 06 2023 at 19:58):

Johan Commelin said:

Gabriel Ebner Are you saying that adding 2003 to the current situation is only going to make things worse :fear: ?

No completely the opposite.

Reid Barton (Feb 06 2023 at 19:59):

My messages this evening are with the patch for 2003 applied on top of current master.

Johan Commelin (Feb 06 2023 at 19:59):

Ah, then my interpretation of your use of the word "unfortunate" was somewhat unfortunate.

Reid Barton (Feb 06 2023 at 20:00):

If we don't have eta for classes then the failing TC problems will fail faster. Here, that's good.

Reid Barton (Feb 06 2023 at 20:00):

Or not even "the failing TC problems", but rather any sort of failing unification

Johan Commelin (Feb 06 2023 at 20:01):

Ooh, aha. So you're saying that yesterday's PR is making the 2003 situation worse?

Johan Commelin (Feb 06 2023 at 20:01):

Or not even that?

Gabriel Ebner (Feb 06 2023 at 20:01):

Yes, the two issues have great synergies.

Gabriel Ebner (Feb 06 2023 at 20:01):

Or at least, the issue which would be fixed by 2003 makes yesterday's PR much worse.

Reid Barton (Feb 06 2023 at 20:04):

I will test but I think the issue with Data.Rat.Defs discussed here is basically the same whether or not 2003 is included.

Kevin Buzzard (Feb 06 2023 at 20:04):

I feel like we're making progress in our understanding though, which is great.

Reid Barton (Feb 06 2023 at 20:05):

The tricky thing about these issues is that there are many opportunities to do better on each one, but also each change we could make to Lean affects many other things.

Reid Barton (Feb 06 2023 at 20:08):

Currently, in Lean 4, if you apply a lemma that has an [instance] argument, does Lean insist on TC synthesizing the argument, or can it solve for it by unification?

Thomas Murrills (Feb 06 2023 at 20:41):

I believe it insists on TC, at least based on the fact that changing [Foo] to {_ : Foo} changes whether some simp lemmas are able to be applied (TC fails but unification succeeds) (assuming no recent lean 4 PR’s have changed this, and assuming this is not actually a property of simp)

Reid Barton (Feb 06 2023 at 21:24):

In that case it really doesn't make sense to me that the TC synthesis failure in step 7 doesn't end the defeq test immediately.

Reid Barton (Feb 07 2023 at 15:13):

I looked at 2055 more closely and actually it is the same as what we are seeing here.

Gabriel Ebner (Feb 09 2023 at 19:52):

Thank you all and Johan in particular for all the effort in adapting mathlib to the change. It was very helpful to see where things break. I have reverted lean4#2093 for the moment so that we can continue to deploy other bugfixes.


Last updated: Dec 20 2023 at 11:08 UTC