You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Universe level normalization has associativity of max backwards from parsing associativity #5695
Reacted by Eric Wieser, Christian Merten, Junyan Xu, Sebastien Gouezel, damiano, Matthew Robert Ballard, Kevin Buzzard, Violeta Hernández Palacios, Jireh Loreaux, Bryan Gin-ge Chen and 2 more
Related, Mario noted in #2689 (before I changed the PR description):
PS: Level.normalize also differs from level::normalize: the lean function left associates max expressions and the C++ function right associates. I suspect this could also lead to different behaviors in edge cases, although I don't yet have an example. Is it worth making them agree here?
Still low priority, but maybe changing the elaborator to associate the other way is a simple fix that will make users happy here. If someone feels like giving it a shot to see if it goes through without notable breakage, it’ll likely get merged.
Alternatively you could change the pretty printer to completely ignore max associativity and just flatten things regardless of whether it is left or right associated. Lean is very good at not making the association matter in practice so this seems like a good way to just avoid it being something to call attention to.
Yes, it might (or might not) be the case that the phenomenon being discussed in this issue is behind timeouts in algebraic geometry in mathlib (which we'll need for FLT, but not urgently). For example the hacky mathlib PR leanprover-community/mathlib4#21129 changes the names of universes so that they are in a different alphabetical order, in order to resolve timeouts and get a big speedup on a file. Example: if some universes are called a,b,c then a file (involving other universes u,v) compiles, but if a,b,c are renamed to x,y,z then the file does not compile because of timeouts, see here for instance. Universe normalization depends on alphabetical order, and changing alphabetical order enables the end user to manipulate the normalization algorithm; this has become important in algebraic geometry formalization because we need to work around the phenomenon explained here in #lean4 on Zulip where the kernel takes a very long time with a rfl which the elaborator was fine with. The conjecture is that the kernel only found itself in this situation in the first place (in the actual algebraic geometry file) because of this issue. NB I don't think this is to do with algebraic geometry per se, I think it might just be to do with situations where there are many different universe variables in complex terms.
I don't know whether the solution to this issue is as simple as "fix the line mentioned here".
It would be possible to make a mathlib-free minimisation of the example in the Zulip chat but the naive approach would be a few hours' work and the resulting minimisation would be of the form "copy out a huge chunk of the algebra hierarchy and then do something which is two lines long with it".
Stumbled over this again. Did anyone ever try to make the Lean normalize function right-associate the max’es, to match the kernel’s and the parsing associativity?
Activity
kmill commentedon Nov 19, 2024
Related, Mario noted in #2689 (before I changed the PR description):
maxsuboptimally #6760 as a duplicate of this issuenomeata commentedon Jan 28, 2025
Still low priority, but maybe changing the elaborator to associate the other way is a simple fix that will make users happy here. If someone feels like giving it a shot to see if it goes through without notable breakage, it’ll likely get merged.
digama0 commentedon Jan 28, 2025
Alternatively you could change the pretty printer to completely ignore max associativity and just flatten things regardless of whether it is left or right associated. Lean is very good at not making the association matter in practice so this seems like a good way to just avoid it being something to call attention to.
sgouezel commentedon Jan 28, 2025
It looks like the association matters a lot for kernel typechecking performance (see the Zulip thread, e.g. https://leanprover.zulipchat.com/#narrow/channel/287929-mathlib4/topic/JacobiZariski.20is.20slow.2E/near/496348891), so hiding that under the rug just by fixing the pretty-printing is probably not a good idea!
sgouezel commentedon Jan 28, 2025
(And given the performance issue, I'd raise the priority, also :-)
kbuzzard commentedon Jan 30, 2025
Yes, it might (or might not) be the case that the phenomenon being discussed in this issue is behind timeouts in algebraic geometry in mathlib (which we'll need for FLT, but not urgently). For example the hacky mathlib PR leanprover-community/mathlib4#21129 changes the names of universes so that they are in a different alphabetical order, in order to resolve timeouts and get a big speedup on a file. Example: if some universes are called a,b,c then a file (involving other universes u,v) compiles, but if a,b,c are renamed to x,y,z then the file does not compile because of timeouts, see here for instance. Universe normalization depends on alphabetical order, and changing alphabetical order enables the end user to manipulate the normalization algorithm; this has become important in algebraic geometry formalization because we need to work around the phenomenon explained here in #lean4 on Zulip where the kernel takes a very long time with a
rflwhich the elaborator was fine with. The conjecture is that the kernel only found itself in this situation in the first place (in the actual algebraic geometry file) because of this issue. NB I don't think this is to do with algebraic geometry per se, I think it might just be to do with situations where there are many different universe variables in complex terms.I don't know whether the solution to this issue is as simple as "fix the line mentioned here".
It would be possible to make a mathlib-free minimisation of the example in the Zulip chat but the naive approach would be a few hours' work and the resulting minimisation would be of the form "copy out a huge chunk of the algebra hierarchy and then do something which is two lines long with it".
nomeata commentedon Apr 19, 2025
Not wanting to necessarily stir up a new discussion of a P-low issue, but still worth recording this here:
There is the extra complication that
imaxisn’t even associative:and at least as long we have the syntax
imax a b cit really has to meanimax a (imax b c), the other associativity would be very confusing.So for
imaxthe parsing and pretty-printing associativity is necessarily right-associative.Then it seems reasonable for
maxto use the same. This could be a stronger reason than consistency with the normalization procedure.So maybe there is no bug here, but just a unavoidable consequence of other reasonable decisions.
nomeata commentedon Jun 25, 2025
Stumbled over this again. Did anyone ever try to make the Lean
normalizefunction right-associate themax’es, to match the kernel’s and the parsing associativity?