|
| 1 | +/- |
| 2 | +Copyright (c) 2025 Oliver Nash. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Kevin Buzzard, Bhavik Mehta, Oliver Nash |
| 5 | +-/ |
| 6 | +import Mathlib.Data.Fintype.Order |
| 7 | +import Mathlib.Data.Nat.Lattice |
| 8 | +import Mathlib.Data.Int.ConditionallyCompleteOrder |
| 9 | +import Mathlib.Data.Int.Interval |
| 10 | +import Mathlib.Data.Int.SuccPred |
| 11 | + |
| 12 | +/-! |
| 13 | +# Order-connected subsets of linear orders |
| 14 | +
|
| 15 | +In this file we provide some results about order-connected subsets of linear orders, together with |
| 16 | +some convenience lemmas for characterising closed intervals in certain concrete types such as `ℤ`, |
| 17 | +`ℕ`, and `Fin n`. |
| 18 | +
|
| 19 | +## Main results: |
| 20 | + * `Set.ordConnected_iff_disjoint_Ioo_empty`: a characterisation of `Set.OrdConnected` for |
| 21 | + locally-finite linear orders. |
| 22 | + * `Set.Nonempty.ordConnected_iff_of_bdd`: a characterisation of closed intervals for locally-finite |
| 23 | + conditionally complete linear orders. |
| 24 | + * `Set.Nonempty.ordConnected_iff_of_bdd'`: a characterisation of closed intervals for |
| 25 | + locally-finite complete linear orders (convenient for `Fin n`). |
| 26 | + * `Set.Nonempty.eq_Icc_iff_nat`: characterisation of closed intervals for `ℕ`. |
| 27 | + * `Set.Nonempty.eq_Icc_iff_int`: characterisation of closed intervals for `ℤ`. |
| 28 | +-/ |
| 29 | + |
| 30 | +variable {α : Type*} {I : Set α} |
| 31 | + |
| 32 | +lemma Set.Nonempty.ordConnected_iff_of_bdd |
| 33 | + [ConditionallyCompleteLinearOrder α] [LocallyFiniteOrder α] |
| 34 | + (h₀ : I.Nonempty) (h₁ : BddBelow I) (h₂ : BddAbove I) : |
| 35 | + I.OrdConnected ↔ I = Icc (sInf I) (sSup I) := |
| 36 | + have h₄ : I.Finite := h₁.finite_of_bddAbove h₂ |
| 37 | + ⟨fun _ ↦ le_antisymm (subset_Icc_csInf_csSup h₁ h₂) |
| 38 | + (I.Icc_subset (h₀.csInf_mem h₄) (h₀.csSup_mem h₄)), fun h₃ ↦ h₃ ▸ ordConnected_Icc⟩ |
| 39 | + |
| 40 | +/-- A version of `Set.Nonempty.ordConnected_iff_of_bdd` for complete linear orders, such as `Fin n`, |
| 41 | +in which the explicit boundedness hypotheses are not necessary. -/ |
| 42 | +lemma Set.Nonempty.ordConnected_iff_of_bdd' [ConditionallyCompleteLinearOrder α] |
| 43 | + [OrderTop α] [OrderBot α] [LocallyFiniteOrder α] |
| 44 | + (h₀ : I.Nonempty) : |
| 45 | + I.OrdConnected ↔ I = Icc (sInf I) (sSup I) := |
| 46 | + h₀.ordConnected_iff_of_bdd (OrderBot.bddBelow I) (OrderTop.bddAbove I) |
| 47 | + |
| 48 | +/- TODO The `LocallyFiniteOrder` assumption here is probably too strong (e.g., it rules out `ℝ` |
| 49 | +for which this result holds). However at the time of writing it is not clear what weaker |
| 50 | +assumption(s) should replace it. -/ |
| 51 | +lemma Set.ordConnected_iff_disjoint_Ioo_empty [LinearOrder α] [LocallyFiniteOrder α] : |
| 52 | + I.OrdConnected ↔ ∀ᵉ (x ∈ I) (y ∈ I), Disjoint (Ioo x y) I → Ioo x y = ∅ := by |
| 53 | + simp_rw [← Set.subset_compl_iff_disjoint_right] |
| 54 | + refine ⟨fun h' x hx y hy hxy ↦ ?_, fun h' ↦ ordConnected_of_Ioo fun x hx y hy hxy z hz ↦ ?_⟩ |
| 55 | + · suffices ∀ z, x < z → y ≤ z by ext z; simpa using this z |
| 56 | + intro z hz |
| 57 | + suffices z ∉ Ioo x y by aesop |
| 58 | + exact fun contra ↦ hxy contra <| h'.out hx hy <| mem_Icc_of_Ioo contra |
| 59 | + · by_contra hz' |
| 60 | + obtain ⟨x', hx', hx''⟩ := |
| 61 | + ((finite_Icc x z).inter_of_right I).exists_le_maximal ⟨hx, le_refl _, hz.1.le⟩ |
| 62 | + have hxz : x' < z := lt_of_le_of_ne hx''.1.2.2 (ne_of_mem_of_not_mem hx''.1.1 hz') |
| 63 | + obtain ⟨y', hy', hy''⟩ := |
| 64 | + ((finite_Icc z y).inter_of_right I).exists_minimal_le ⟨hy, hz.2.le, le_refl _⟩ |
| 65 | + have hzy : z < y' := lt_of_le_of_ne' hy''.1.2.1 (ne_of_mem_of_not_mem hy''.1.1 hz') |
| 66 | + have h₃ : Ioc x' z ⊆ Iᶜ := fun t ht ht' ↦ hx''.not_gt (⟨ht', le_trans hx' ht.1.le, ht.2⟩) ht.1 |
| 67 | + have h₄ : Ico z y' ⊆ Iᶜ := fun t ht ht' ↦ hy''.not_lt (⟨ht', ht.1, le_trans ht.2.le hy'⟩) ht.2 |
| 68 | + have h₅ : Ioo x' y' ⊆ Iᶜ := by |
| 69 | + simp only [← Ioc_union_Ico_eq_Ioo hxz hzy, union_subset_iff, and_true, h₃, h₄] |
| 70 | + exact eq_empty_iff_forall_not_mem.1 (h' x' hx''.prop.1 y' hy''.prop.1 h₅) z ⟨hxz, hzy⟩ |
| 71 | + |
| 72 | +lemma Set.Nonempty.eq_Icc_iff_nat {I : Set ℕ} |
| 73 | + (h₀ : I.Nonempty) (h₂ : BddAbove I) : |
| 74 | + I = Icc (sInf I) (sSup I) ↔ ∀ᵉ (x ∈ I) (y ∈ I), Disjoint (Ioo x y) I → y ≤ x + 1 := by |
| 75 | + simp [← h₀.ordConnected_iff_of_bdd (OrderBot.bddBelow I) h₂, ordConnected_iff_disjoint_Ioo_empty] |
| 76 | + |
| 77 | +lemma Set.Nonempty.eq_Icc_iff_int {I : Set ℤ} |
| 78 | + (h₀ : I.Nonempty) (h₁ : BddBelow I) (h₂ : BddAbove I) : |
| 79 | + I = Icc (sInf I) (sSup I) ↔ ∀ᵉ (x ∈ I) (y ∈ I), Disjoint (Ioo x y) I → y ≤ x + 1 := by |
| 80 | + simp [← h₀.ordConnected_iff_of_bdd h₁ h₂, ordConnected_iff_disjoint_Ioo_empty, Int.succ] |
0 commit comments