Zulip Chat Archive

Stream: new members

Topic: mathlib4 build error


Palalansoukî (Feb 05 2023 at 19:56):

I tried to use mathlib4 in lean4 but I cannot use it with the following error. What should I do? When I run lake build I get a message including the following:

error: stdout:
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:55:19: error: failed to synthesize instance
  AddZeroClass 
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:56:18: error: type mismatch
  add_le_add_left zero_le_one 1
has type
  1 + 0  @HAdd.hAdd    (@instHAdd  AddZeroClass.toAdd) 1 1 : Prop
but is expected to have type
  1 + 0  @HAdd.hAdd    (@instHAdd  instAddNat) 1 1 : Prop
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:56:34: error: failed to synthesize instance
  ZeroLEOneClass 
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:56:18: error: failed to synthesize instance
  CovariantClass   (fun x x_1  x + x_1) fun x x_1  x  x_1
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:62:19: error: failed to synthesize instance
  AddZeroClass 
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:63:18: error: type mismatch
  add_le_add_right zero_le_one 1
has type
  0 + 1  @HAdd.hAdd    (@instHAdd  AddZeroClass.toAdd) 1 1 : Prop
but is expected to have type
  0 + 1  @HAdd.hAdd    (@instHAdd  instAddNat) 1 1 : Prop
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:63:35: error: failed to synthesize instance
  ZeroLEOneClass 
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:63:18: error: failed to synthesize instance
  CovariantClass   (swap fun x x_1  x + x_1) fun x x_1  x  x_1

Lean4 and mathlib4 are both the latest. (lean4: nightly-2023-02-04, mathlib4 revision: 25e6049. I tried several other revisions with the same result)

Kevin Buzzard (Feb 05 2023 at 20:26):

The latest mathlib4 doesn't use the latest lean4, that is probably your problem.

Kevin Buzzard (Feb 05 2023 at 20:27):

If you want to use mathlib, you should be on Lean version 4.0.0-nightly-2023-01-29, commit 38a0d1e3733e, Release, the version mathlib4 is using.

Palalansoukî (Feb 07 2023 at 00:01):

Thank you!

Shreyas Srinivas (Feb 07 2023 at 18:24):

Kevin Buzzard said:

The latest mathlib4 doesn't use the latest lean4, that is probably your problem.

This sounds like an issue for which there should be better solutions. Typically build tools (I have cabal and cargo in mind) have valid library ranges and vice versa. Incompatible versions throw errors.

Eric Wieser (Feb 07 2023 at 18:32):

Well, the version above did throw an error...

Ruben Van de Velde (Feb 07 2023 at 18:35):

Maybe a more explicit one

Reid Barton (Feb 07 2023 at 18:42):

I'm not actually sure how you would build mathlib4 with the wrong lean4 version without realizing it

Reid Barton (Feb 07 2023 at 18:43):

I guess maybe if you don't have elan installed?

Shreyas Srinivas (Feb 08 2023 at 10:00):

Akaho Akane said:

I tried to use mathlib4 in lean4 but I cannot use it with the following error. What should I do? When I run lake build I get a message including the following:

error: stdout:
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:55:19: error: failed to synthesize instance
  AddZeroClass 
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:56:18: error: type mismatch
  add_le_add_left zero_le_one 1
has type
  1 + 0  @HAdd.hAdd    (@instHAdd  AddZeroClass.toAdd) 1 1 : Prop
but is expected to have type
  1 + 0  @HAdd.hAdd    (@instHAdd  instAddNat) 1 1 : Prop
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:56:34: error: failed to synthesize instance
  ZeroLEOneClass 
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:56:18: error: failed to synthesize instance
  CovariantClass   (fun x x_1  x + x_1) fun x x_1  x  x_1
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:62:19: error: failed to synthesize instance
  AddZeroClass 
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:63:18: error: type mismatch
  add_le_add_right zero_le_one 1
has type
  0 + 1  @HAdd.hAdd    (@instHAdd  AddZeroClass.toAdd) 1 1 : Prop
but is expected to have type
  0 + 1  @HAdd.hAdd    (@instHAdd  instAddNat) 1 1 : Prop
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:63:35: error: failed to synthesize instance
  ZeroLEOneClass 
./lake-packages/mathlib/././Mathlib/Algebra/Order/Monoid/NatCast.lean:63:18: error: failed to synthesize instance
  CovariantClass   (swap fun x x_1  x + x_1) fun x x_1  x  x_1

Lean4 and mathlib4 are both the latest. (lean4: nightly-2023-02-04, mathlib4 revision: 25e6049. I tried several other revisions with the same result)

This error message does not immediately tell me I am using the wrong version of mathlib

Shreyas Srinivas (Feb 08 2023 at 10:01):

This version check sounds like a check that needs to happen before the compilation of these files even begins

Reid Barton (Feb 08 2023 at 11:08):

I don't agree. The package already knows what version of lean it is supposed to be compiled with, and elan will automatically use the correct version, even if the user doesn't have it installed yet.
Trying to use a different version of Lean--which might differ only in performance for instance--is not an error. This matters to package maintainers and, especially, those working on Lean itself.

Reid Barton (Feb 08 2023 at 11:09):

What we should try to prevent is users accidentally not using elan.

Shreyas Srinivas (Feb 08 2023 at 17:36):

Reid Barton said:

I don't agree. The package already knows what version of lean it is supposed to be compiled with, and elan will automatically use the correct version, even if the user doesn't have it installed yet.
Trying to use a different version of Lean--which might differ only in performance for instance--is not an error. This matters to package maintainers and, especially, those working on Lean itself.

I don't understand. Suppose I have a series of nightlies, say 1,2,3,4,5 and mathlib4 is currently on 3. Suppose I call lake new <project_name> math, are you saying lake will choose the correct toolchain? What happens if mathlib is manually added as a dependency in the lakefile with a require line

Reid Barton (Feb 08 2023 at 17:41):

I have no idea what lake will do in this situation, I'm just talking about building mathlib itself

Shreyas Srinivas (Feb 08 2023 at 18:37):

If this is purely about building mathlib, isn't lake build going to choose the toolchain in the lean-toolchain file, regardless of what elan is used to set as the default toolchain (outside the folder)?

Reid Barton (Feb 09 2023 at 00:00):

Well, you can use elan override to pick a different toolchain (for testing purposes say), but otherwise yes.


Last updated: Dec 20 2023 at 11:08 UTC