@@ -9,8 +9,12 @@ import Mathlib.Tactic.Common
99/-!
1010# Lexicographic order on Pi types
1111
12- This file defines the lexicographic order for Pi types. `a` is less than `b` if `a i = b i` for all
13- `i` up to some point `k`, and `a k < b k`.
12+ This file defines the lexicographic and colexicographic orders for Pi types.
13+
14+ * In the lexicographic order, `a` is less than `b` if `a i = b i` for all `i` up to some point
15+ `k`, and `a k < b k`.
16+ * In the colexicographic order, `a` is less than `b` if `a i = b i` for all `i` above some point
17+ `k`, and `a k < b k`.
1418
1519 ## Notation
1620
@@ -33,7 +37,10 @@ variable {ι : Type*} {β : ι → Type*} (r : ι → ι → Prop) (s : ∀ {i},
3337namespace Pi
3438
3539/-- The lexicographic relation on `Π i : ι, β i`, where `ι` is ordered by `r`,
36- and each `β i` is ordered by `s`. -/
40+ and each `β i` is ordered by `s`.
41+
42+ The `<` relation on `Lex (∀ i, β i)` is `Pi.Lex (· < ·) (· < ·)`, while the `<` relation on
43+ `Colex (∀ i, β i)` is `Pi.Lex (· > ·) (· < ·)`. -/
3744protected def Lex (x y : ∀ i, β i) : Prop :=
3845 ∃ i, (∀ j, r j i → x j = y j) ∧ s (x i) (y i)
3946
@@ -57,7 +64,7 @@ theorem lex_lt_of_lt_of_preorder [∀ i, Preorder (β i)] {r} (hwf : WellFounded
5764 ⟨i, fun j hj => ⟨h'.1 j, not_not.1 fun h => hl j (lt_of_le_not_ge (h'.1 j) h) hj⟩, hi⟩
5865
5966theorem lex_lt_of_lt [∀ i, PartialOrder (β i)] {r} (hwf : WellFounded r) {x y : ∀ i, β i}
60- (hlt : x < y) : Pi.Lex r (@ fun _ => ( · < ·) ) x y := by
67+ (hlt : x < y) : Pi.Lex r (· < ·) x y := by
6168 simp_rw [Pi.Lex, le_antisymm_iff]
6269 exact lex_lt_of_lt_of_preorder hwf hlt
6370
@@ -78,7 +85,10 @@ theorem isTrichotomous_lex [∀ i, IsTrichotomous (β i) s] (wf : WellFounded r)
7885 Or.inr <| Or.inr <| ⟨i, fun j hj => (hri j hj).symm, hi.resolve_left hne⟩] }
7986
8087instance [LT ι] [∀ a, LT (β a)] : LT (Lex (∀ i, β i)) :=
81- ⟨Pi.Lex (· < ·) @fun _ => (· < ·)⟩
88+ ⟨Pi.Lex (· < ·) (· < ·)⟩
89+
90+ instance [LT ι] [∀ a, LT (β a)] : LT (Colex (∀ i, β i)) :=
91+ ⟨Pi.Lex (· > ·) (· < ·)⟩
8292
8393instance Lex.isStrictOrder [LinearOrder ι] [∀ a, PartialOrder (β a)] :
8494 IsStrictOrder (Lex (∀ i, β i)) (· < ·) where
@@ -90,16 +100,28 @@ instance Lex.isStrictOrder [LinearOrder ι] [∀ a, PartialOrder (β a)] :
90100 ⟨N₁, fun j hj => (lt_N₁ _ hj).trans (lt_N₂ _ hj), a_lt_b.trans b_lt_c⟩,
91101 ⟨N₂, fun j hj => (lt_N₁ _ (hj.trans H)).trans (lt_N₂ _ hj), (lt_N₁ _ H).symm ▸ b_lt_c⟩]
92102
103+ instance Colex.isStrictOrder [LinearOrder ι] [∀ a, PartialOrder (β a)] :
104+ IsStrictOrder (Colex (∀ i, β i)) (· < ·) :=
105+ Lex.isStrictOrder (ι := ιᵒᵈ)
106+
93107instance [LinearOrder ι] [∀ a, PartialOrder (β a)] : PartialOrder (Lex (∀ i, β i)) :=
94108 partialOrderOfSO (· < ·)
95109
96- /-- `Πₗ i, α i` is a linear order if the original order is well-founded. -/
97- noncomputable instance [LinearOrder ι] [WellFoundedLT ι] [∀ a, LinearOrder (β a)] :
98- LinearOrder (Lex (∀ i, β i)) :=
110+ instance [LinearOrder ι] [∀ a, PartialOrder (β a)] : PartialOrder (Colex (∀ i, β i)) :=
111+ partialOrderOfSO (· < ·)
112+
113+ /-- `Lex (∀ i, α i)` is a linear order if the original order has well-founded `<`. -/
114+ noncomputable instance Lex.linearOrder [LinearOrder ι] [WellFoundedLT ι]
115+ [∀ a, LinearOrder (β a)] : LinearOrder (Lex (∀ i, β i)) :=
99116 @linearOrderOfSTO (Πₗ i, β i) (· < ·)
100117 { trichotomous := (isTrichotomous_lex _ _ IsWellFounded.wf).1 } (Classical.decRel _)
101118
102- section PartialOrder
119+ /-- `Colex (∀ i, α i)` is a linear order if the original order has well-founded `>`. -/
120+ noncomputable instance Colex.linearOrder [LinearOrder ι] [WellFoundedGT ι]
121+ [∀ a, LinearOrder (β a)] : LinearOrder (Colex (∀ i, β i)) :=
122+ Lex.linearOrder (ι := ιᵒᵈ)
123+
124+ section Lex
103125
104126variable [LinearOrder ι] [WellFoundedLT ι] [∀ i, PartialOrder (β i)] {x : ∀ i, β i} {i : ι}
105127 {a : β i}
@@ -151,21 +173,64 @@ theorem le_toLex_update_self_iff : toLex x ≤ toLex (update x i a) ↔ x i ≤
151173theorem toLex_update_le_self_iff : toLex (update x i a) ≤ toLex x ↔ a ≤ x i := by
152174 simp_rw [le_iff_lt_or_eq, toLex_update_lt_self_iff, toLex_inj, update_eq_self_iff]
153175
154- end PartialOrder
176+ end Lex
177+
178+ section Colex
179+
180+ variable [LinearOrder ι] [WellFoundedGT ι] [∀ i, PartialOrder (β i)] {x : ∀ i, β i} {i : ι}
181+ {a : β i}
182+
183+ open Function
184+
185+ theorem toColex_monotone : Monotone (@toColex (∀ i, β i)) :=
186+ toLex_monotone (ι := ιᵒᵈ)
187+
188+ theorem toColex_strictMono : StrictMono (@toColex (∀ i, β i)) :=
189+ toLex_strictMono (ι := ιᵒᵈ)
190+
191+ @[simp]
192+ theorem lt_toColex_update_self_iff : toColex x < toColex (update x i a) ↔ x i < a :=
193+ lt_toLex_update_self_iff (ι := ιᵒᵈ)
194+
195+ @[simp]
196+ theorem toColex_update_lt_self_iff : toColex (update x i a) < toColex x ↔ a < x i :=
197+ toLex_update_lt_self_iff (ι := ιᵒᵈ)
198+
199+ @[simp]
200+ theorem le_toColex_update_self_iff : toColex x ≤ toColex (update x i a) ↔ x i ≤ a :=
201+ le_toLex_update_self_iff (ι := ιᵒᵈ)
202+
203+ @[simp]
204+ theorem toColex_update_le_self_iff : toColex (update x i a) ≤ toColex x ↔ a ≤ x i :=
205+ toLex_update_le_self_iff (ι := ιᵒᵈ)
206+
207+ end Colex
155208
156209instance [LinearOrder ι] [WellFoundedLT ι] [∀ a, PartialOrder (β a)] [∀ a, OrderBot (β a)] :
157210 OrderBot (Lex (∀ a, β a)) where
158211 bot := toLex ⊥
159212 bot_le _ := toLex_monotone bot_le
160213
214+ instance [LinearOrder ι] [WellFoundedGT ι] [∀ a, PartialOrder (β a)] [∀ a, OrderBot (β a)] :
215+ OrderBot (Colex (∀ a, β a)) where
216+ bot := toColex ⊥
217+ bot_le _ := toColex_monotone bot_le
218+
161219instance [LinearOrder ι] [WellFoundedLT ι] [∀ a, PartialOrder (β a)] [∀ a, OrderTop (β a)] :
162220 OrderTop (Lex (∀ a, β a)) where
163221 top := toLex ⊤
164222 le_top _ := toLex_monotone le_top
165223
224+ instance [LinearOrder ι] [WellFoundedGT ι] [∀ a, PartialOrder (β a)] [∀ a, OrderTop (β a)] :
225+ OrderTop (Colex (∀ a, β a)) where
226+ top := toColex ⊤
227+ le_top _ := toColex_monotone le_top
228+
166229instance [LinearOrder ι] [WellFoundedLT ι] [∀ a, PartialOrder (β a)]
167- [∀ a, BoundedOrder (β a)] : BoundedOrder (Lex (∀ a, β a)) :=
168- { }
230+ [∀ a, BoundedOrder (β a)] : BoundedOrder (Lex (∀ a, β a)) where
231+
232+ instance [LinearOrder ι] [WellFoundedGT ι] [∀ a, PartialOrder (β a)]
233+ [∀ a, BoundedOrder (β a)] : BoundedOrder (Colex (∀ a, β a)) where
169234
170235instance [Preorder ι] [∀ i, LT (β i)] [∀ i, DenselyOrdered (β i)] :
171236 DenselyOrdered (Lex (∀ i, β i)) :=
@@ -181,6 +246,10 @@ instance [Preorder ι] [∀ i, LT (β i)] [∀ i, DenselyOrdered (β i)] :
181246 · rw [Function.update_of_ne hj.ne a]
182247 · rwa [Function.update_self i a]⟩
183248
249+ instance [Preorder ι] [∀ i, LT (β i)] [∀ i, DenselyOrdered (β i)] :
250+ DenselyOrdered (Colex (∀ i, β i)) :=
251+ inferInstanceAs (DenselyOrdered (Lex (∀ i : ιᵒᵈ, β (OrderDual.toDual i))))
252+
184253theorem Lex.noMaxOrder' [Preorder ι] [∀ i, LT (β i)] (i : ι) [NoMaxOrder (β i)] :
185254 NoMaxOrder (Lex (∀ i, β i)) :=
186255 ⟨fun a => by
@@ -189,23 +258,42 @@ theorem Lex.noMaxOrder' [Preorder ι] [∀ i, LT (β i)] (i : ι) [NoMaxOrder (
189258 exact ⟨Function.update a i b, i, fun j hj =>
190259 (Function.update_of_ne hj.ne b a).symm, by rwa [Function.update_self i b]⟩⟩
191260
261+ theorem Colex.noMaxOrder' [Preorder ι] [∀ i, LT (β i)] (i : ι) [NoMaxOrder (β i)] :
262+ NoMaxOrder (Colex (∀ i, β i)) :=
263+ Lex.noMaxOrder' (ι := ιᵒᵈ) i
264+
192265instance [LinearOrder ι] [WellFoundedLT ι] [Nonempty ι] [∀ i, PartialOrder (β i)]
193266 [∀ i, NoMaxOrder (β i)] : NoMaxOrder (Lex (∀ i, β i)) :=
194267 ⟨fun a =>
195268 let ⟨_, hb⟩ := exists_gt (ofLex a)
196269 ⟨_, toLex_strictMono hb⟩⟩
197270
271+ instance [LinearOrder ι] [WellFoundedGT ι] [Nonempty ι] [∀ i, PartialOrder (β i)]
272+ [∀ i, NoMaxOrder (β i)] : NoMaxOrder (Colex (∀ i, β i)) :=
273+ inferInstanceAs (NoMaxOrder (Lex (∀ i : ιᵒᵈ, β (OrderDual.toDual i))))
274+
198275instance [LinearOrder ι] [WellFoundedLT ι] [Nonempty ι] [∀ i, PartialOrder (β i)]
199276 [∀ i, NoMinOrder (β i)] : NoMinOrder (Lex (∀ i, β i)) :=
200277 ⟨fun a =>
201278 let ⟨_, hb⟩ := exists_lt (ofLex a)
202279 ⟨_, toLex_strictMono hb⟩⟩
203280
281+ instance [LinearOrder ι] [WellFoundedGT ι] [Nonempty ι] [∀ i, PartialOrder (β i)]
282+ [∀ i, NoMinOrder (β i)] : NoMinOrder (Colex (∀ i, β i)) :=
283+ inferInstanceAs (NoMinOrder (Lex (∀ i : ιᵒᵈ, β (OrderDual.toDual i))))
284+
204285/-- If we swap two strictly decreasing values in a function, then the result is lexicographically
205286smaller than the original function. -/
206287theorem lex_desc {α} [Preorder ι] [DecidableEq ι] [LT α] {f : ι → α} {i j : ι} (h₁ : i ≤ j)
207288 (h₂ : f j < f i) : toLex (f ∘ Equiv.swap i j) < toLex f :=
208289 ⟨i, fun _ hik => congr_arg f (Equiv.swap_apply_of_ne_of_ne hik.ne (hik.trans_le h₁).ne), by
209290 simpa only [Pi.toLex_apply, Function.comp_apply, Equiv.swap_apply_left] using h₂⟩
210291
292+ /-- If we swap two strictly increasing values in a function, then the result is colexicographically
293+ smaller than the original function. -/
294+ theorem colex_asc {α} [Preorder ι] [DecidableEq ι] [LT α] {f : ι → α} {i j : ι} (h₁ : i ≤ j)
295+ (h₂ : f i < f j) : toColex (f ∘ Equiv.swap i j) < toColex f := by
296+ rw [Equiv.swap_comm]
297+ exact lex_desc (ι := ιᵒᵈ) h₁ h₂
298+
211299end Pi
0 commit comments