-
Notifications
You must be signed in to change notification settings - Fork 432
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This PR replaces `List.lt` with `List.Lex`, from Mathlib, and adds the new `Bool` valued lexicographic comparatory function `List.lex`. This subtly changes the definition of `<` on Lists in some situations. `List.lt` was a weaker relation: in particular if `l₁ < l₂`, then `a :: l₁ < b :: l₂` may hold according to `List.lt` even if `a` and `b` are merely incomparable (either neither `a < b` nor `b < a`), whereas according to `List.Lex` this would require `a = b`. When `<` is total, in the sense that `¬ · < ·` is antisymmetric, then the two relations coincide. Mathlib was already overriding the order instances for `List α`, so this change should not be noticed by anyone already using Mathlib. We simultaneously add the boolean valued `List.lex` function, parameterised by a `BEq` typeclass and an arbitrary `lt` function. This will support the flexibility previously provided for `List.lt`, via a `==` function which is weaker than strict equality.
- Loading branch information
Showing
22 changed files
with
716 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
We replace the inductive predicate `List.lt` with an upstreamed version of `List.Lex` from Mathlib. | ||
(Previously `Lex.lt` was defined in terms of `<`; now it is generalized to take an arbitrary relation.) | ||
This subtely changes the notion of ordering on `List α`. | ||
|
||
`List.lt` was a weaker relation: in particular if `l₁ < l₂`, then | ||
`a :: l₁ < b :: l₂` may hold according to `List.lt` even if `a` and `b` are merely incomparable | ||
(either neither `a < b` nor `b < a`), whereas according to `List.Lex` this would require `a = b`. | ||
|
||
When `<` is total, in the sense that `¬ · < ·` is antisymmetric, then the two relations coincide. | ||
|
||
Mathlib was already overriding the order instances for `List α`, | ||
so this change should not be noticed by anyone already using Mathlib. | ||
|
||
We simultaneously add the boolean valued `List.lex` function, parameterised by a `BEq` typeclass | ||
and an arbitrary `lt` function. This will support the flexibility previously provided for `List.lt`, | ||
via a `==` function which is weaker than strict equality. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
/- | ||
Copyright (c) 2024 Lean FRO. All rights reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Author: Kim Morrison | ||
-/ | ||
prelude | ||
import Init.Data.Array.Basic | ||
import Init.Data.Nat.Lemmas | ||
import Init.Data.Range | ||
|
||
namespace Array | ||
|
||
/-- | ||
Lexicographic comparator for arrays. | ||
`lex as bs lt` is true if | ||
- `bs` is larger than `as` and `as` is pairwise equivalent via `==` to the initial segment of `bs`, or | ||
- there is an index `i` such that `lt as[i] bs[i]`, and for all `j < i`, `as[j] == bs[j]`. | ||
-/ | ||
def lex [BEq α] (as bs : Array α) (lt : α → α → Bool := by exact (· < ·)) : Bool := Id.run do | ||
for h : i in [0 : min as.size bs.size] do | ||
-- TODO: `omega` should be able to find this itself. | ||
have : i < min as.size bs.size := Membership.get_elem_helper h rfl | ||
if lt as[i] bs[i] then | ||
return true | ||
else if as[i] != bs[i] then | ||
return false | ||
return as.size < bs.size | ||
|
||
end Array |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.