Documentation

CslibFrontier.Foundations.Data.List.Lex

Prefixes and intervals in the lexicographic order on lists #

A prefix of a list is lexicographically at most that list (List.isPrefix_le), and the extensions of any prefix form an order-convex interval under the lexicographic order (List.IsPrefix.of_le_of_le, List.IsPrefix.of_prefix_of_le_of_le). Lists of equal length keep a strict comparison when anything is appended to them (List.append_lt_append_of_lt_of_length_eq), and truncating two lists to a common length preserves their order (List.take_le_take_of_le).

Mathlib's lexicographic LinearOrder on lists replaces core's ≤ on lists, so core's List.cons_le_cons_iff does not apply to it; List.cons_le_cons_iff' is its counterpart.

Main results #

theorem List.cons_le_cons_iff' {α : Type u} [LinearOrder α] {a b : α} {l l' : List α} :
a :: l ≤ b :: l' ↔ a < b ∨ a = b ∧ l ≤ l'

Comparing lists with heads: compare the heads, and the tails when the heads agree.

theorem List.append_lt_append_of_lt_of_length_eq {α : Type u} [LinearOrder α] {a b : List α} (h : a < b) (hlen : a.length = b.length) (c d : List α) :
a ++ c < b ++ d

A strict comparison between lists of the same length survives appending anything to them: it is decided at a position inside both.

theorem List.isPrefix_le {α : Type u} [LinearOrder α] {a b : List α} (h : a <+: b) :
a ≤ b

A list is lexicographically at most every list it is a prefix of.

theorem List.IsPrefix.of_le_of_le {α : Type u} [LinearOrder α] {p b c : List α} (hb : p <+: b) (hpc : p ≤ c) (hcb : c ≤ b) :
p <+: c

A list lexicographically between a prefix p of b and b itself also has p as a prefix.

theorem List.IsPrefix.of_prefix_of_le_of_le {α : Type u} [LinearOrder α] {p a b c : List α} (ha : p <+: a) (hb : p <+: b) (hac : a ≤ c) (hcb : c ≤ b) :
p <+: c

Lists with a common prefix form a lexicographic interval.

theorem List.take_le_take_of_le {α : Type u} [LinearOrder α] {a b : List α} (h : a ≤ b) (n : ℕ) :
take n a ≤ take n b

Truncating two lists to a common length preserves their lexicographic order.