Zulip Chat Archive
Stream: mathlib4
Topic: Two `List.LE` instances?
Violeta Hernández (Feb 02 2025 at 08:56):
The latest version of Mathlib seems to have introduced an unfortunate phenomenon: there are now two instances docs#List.instLE and docs#List.LE', and they're not def-eq:
import Mathlib.Data.List.Lex
/-
type mismatch
List.cons_le_cons_iff
has type
@LE.le (List ?m.48) List.instLE (?m.55 :: ?m.57) (?m.56 :: ?m.58) ↔
?m.55 < ?m.56 ∨ ?m.55 = ?m.56 ∧ ?m.57 ≤ ?m.58 : Prop
but is expected to have type
@LE.le (List ℕ) List.LE' (a :: l) (b :: m) ↔ a < b ∨ a = b ∧ l ≤ m : Prop
-/
example (a b : ℕ) (l m : List ℕ) : a :: l ≤ b :: m ↔ a < b ∨ a = b ∧ l ≤ m :=
List.cons_le_cons_iff
Violeta Hernández (Feb 02 2025 at 08:58):
@Kim Morrison
Violeta Hernández (Feb 02 2025 at 09:12):
I think the fix is to set the correct def-eq in docs#List.instLinearOrder, and remove the docs#List.LE' override (along with docs#List.LT' while we're at it, though that's not problematic since both instances are def-eq)
Violeta Hernández (Feb 02 2025 at 09:17):
Although, I think a better fix might be not to define docs#List.le to begin with. It doesn't mean what you'd expect when the list type isn't linearly ordered, and when it is, we should probably go through the linear order instance instead.
Violeta Hernández (Feb 02 2025 at 09:21):
(While we're at it, something I find unfortunate with the new List.Lex
file is that it uses the Std
relation classes instead of those defined in Mathlib. Unifying these would be a worthwhile endeavor.)
Violeta Hernández (Feb 02 2025 at 09:46):
I've opened #21339 which provides a quick and dirty fix
Eric Wieser (Feb 02 2025 at 12:19):
I don't think we should touch the override instance in mathlib; rather, we should ensure any downstream instances are compatible with the override.
Violeta Hernández (Feb 02 2025 at 20:38):
Keeping the override makes any of the new List.le
theorems in code unusable in Mathlib.
Eric Wieser (Feb 02 2025 at 20:58):
I think that's fine, don't we have all those theorems for List.Lex anyway?
Violeta Hernández (Feb 02 2025 at 21:01):
I think we upstreamed a lot of them to core. In fact, I updated my personal project to v4.16 precisely to be able to use these theorems (and ended up not being able to...)
Violeta Hernández (Feb 02 2025 at 21:02):
For instance I can't find Mathlib variants of docs#List.nil_le or docs#List.cons_le_cons_iff
Violeta Hernández (Feb 02 2025 at 21:52):
I'd like Kim to comment on this, I think they're the one who added List.le
in the latest release.
Last updated: May 02 2025 at 03:31 UTC