| 1 | module |
| 2 | |
| 3 | public import Mathlib |
| 4 | |
| 5 | @[expose] public section |
| 6 | |
| 7 | /-! |
| 8 | # Chain: packing helpers for `chain_core` |
| 9 | |
| 10 | `Packed U S`: the translates `p + U`, `p ∈ S`, are pairwise disjoint. Such a set in `[0, L]` has at |
| 11 | most `3 / c1` elements (`packed_card_le`). `exists_maximal_packing` takes one of maximal size: every |
| 12 | `x ∈ [0, L]` lies in some cell `packCell L U p = {y ∈ [0, L] | y - p ∈ U - U}`, `p ∈ S`. |
| 13 | -/ |
| 14 | |
| 15 | set_option linter.style.header false |
| 16 | open Finset MeasureTheory |
| 17 | open scoped Pointwise |
| 18 | |
| 19 | namespace E424 |
| 20 | |
| 21 | /-- The translates `p + U`, `p ∈ S`, are pairwise disjoint. -/ |
| 22 | def Packed (U : Set ℝ) (S : Finset ℝ) : Prop := |
| 23 | ∀ p ∈ S, ∀ q ∈ S, p ≠ q → ∀ u ∈ U, ∀ u' ∈ U, p + u ≠ q + u' |
| 24 | |
| 25 | /-- The cell of `p`: points of `[0, L]` within `U - U` of `p`. Closed when `U` is compact. -/ |
| 26 | def packCell (L : ℝ) (U : Set ℝ) (p : ℝ) : Set ℝ := |
| 27 | {y | y ∈ Set.Icc 0 L ∧ y - p ∈ U - U} |
| 28 | |
| 29 | lemma mem_packCell {L : ℝ} {U : Set ℝ} {p y : ℝ} : |
| 30 | y ∈ packCell L U p ↔ y ∈ Set.Icc 0 L ∧ y - p ∈ U - U := Iff.rfl |
| 31 | |
| 32 | /-- `U - U` is compact: the image of `U ×ˢ U` under subtraction. -/ |
| 33 | lemma isCompact_sub_self {U : Set ℝ} (hU : IsCompact U) : IsCompact (U - U) := by |
| 34 | have h := (hU.prod hU).image (continuous_fst.sub continuous_snd) |
| 35 | convert h using 1 |
| 36 | ext z |
| 37 | simp only [Set.mem_sub, Set.mem_image, Prod.exists] |
| 38 | constructor |
| 39 | · rintro ⟨a, ha, b, hb, rfl⟩ |
| 40 | exact ⟨a, b, ⟨ha, hb⟩, rfl⟩ |
| 41 | · rintro ⟨a, b, ⟨ha, hb⟩, rfl⟩ |
| 42 | exact ⟨a, ha, b, hb, rfl⟩ |
| 43 | |
| 44 | lemma isClosed_packCell {L : ℝ} {U : Set ℝ} (hU : IsCompact U) (p : ℝ) : |
| 45 | IsClosed (packCell L U p) := |
| 46 | isClosed_Icc.inter ((isCompact_sub_self hU).isClosed.preimage (continuous_id.sub continuous_const)) |
| 47 | |
| 48 | lemma volume_translate (p : ℝ) (U : Set ℝ) : |
| 49 | volume ((fun u => p + u) '' U) = volume U := by |
| 50 | rw [Set.image_add_left] |
| 51 | exact measure_preimage_add _ _ _ |
| 52 | |
| 53 | /-- A packing of `[0, L]` has at most `3 / c1` translates, since they all lie in `[a, a + 3L]`. -/ |
| 54 | lemma packed_card_le {a L c1 : ℝ} (hL : 0 < L) {U : Set ℝ} (hU : IsCompact U) |
| 55 | (hUa : U ⊆ Set.Icc a (a + 2 * L)) (hvol : c1 * L ≤ (volume U).toReal) |
| 56 | {S : Finset ℝ} (hS : (S : Set ℝ) ⊆ Set.Icc 0 L) (hP : Packed U S) : |
| 57 | (S.card : ℝ) * c1 ≤ 3 := by |
| 58 | have hfin : volume U ≠ ⊤ := |
| 59 | ne_top_of_le_ne_top measure_Icc_lt_top.ne (measure_mono hUa) |
| 60 | have hmeas : ∀ p ∈ S, MeasurableSet ((fun u => p + u) '' U) := fun p _ => |
| 61 | (hU.image (continuous_const.add continuous_id)).isClosed.measurableSet |
| 62 | have hdisj : (S : Set ℝ).PairwiseDisjoint (fun p => (fun u => p + u) '' U) := by |
| 63 | intro p hp q hq hpq |
| 64 | refine Set.disjoint_left.2 ?_ |
| 65 | rintro _ ⟨u, hu, rfl⟩ ⟨u', hu', h⟩ |
| 66 | exact hP p hp q hq hpq u hu u' hu' h.symm |
| 67 | have hsub : (⋃ p ∈ S, (fun u => p + u) '' U) ⊆ Set.Icc a (a + 3 * L) := by |
| 68 | intro x hx |
| 69 | simp only [Set.mem_iUnion, Set.mem_image] at hx |
| 70 | obtain ⟨p, hp, u, hu, rfl⟩ := hx |
| 71 | have hp' := hS hp |
| 72 | have hu' := hUa hu |
| 73 | constructor <;> linarith [hp'.1, hp'.2, hu'.1, hu'.2] |
| 74 | have hsum : (volume (⋃ p ∈ S, (fun u => p + u) '' U)).toReal |
| 75 | = S.card * (volume U).toReal := by |
| 76 | rw [measure_biUnion_finset hdisj hmeas, ENNReal.toReal_sum] |
| 77 | · simp only [volume_translate, Finset.sum_const, nsmul_eq_mul] |
| 78 | · intro p _ |
| 79 | rw [volume_translate] |
| 80 | exact hfin |
| 81 | have hle : (volume (⋃ p ∈ S, (fun u => p + u) '' U)).toReal ≤ 3 * L := by |
| 82 | have h := ENNReal.toReal_mono (measure_Icc_lt_top (μ := volume) (a := a) (b := a + 3 * L)).ne |
| 83 | (measure_mono (μ := volume) hsub) |
| 84 | rw [Real.volume_Icc, ENNReal.toReal_ofReal (by linarith)] at h |
| 85 | linarith |
| 86 | have hcard : (0 : ℝ) ≤ S.card := Nat.cast_nonneg _ |
| 87 | have h1 : (S.card : ℝ) * (c1 * L) ≤ S.card * (volume U).toReal := |
| 88 | mul_le_mul_of_nonneg_left hvol hcard |
| 89 | have h2 : (S.card : ℝ) * c1 * L ≤ 3 * L := by nlinarith |
| 90 | exact le_of_mul_le_mul_right h2 hL |
| 91 | |
| 92 | /-- A maximal packing of `[0, L]`: a set of centres `S ⊆ [0, L]` with `Packed U S` of largest size. |
| 93 | Maximality gives: every `x ∈ [0, L]` lies in the cell of some `p ∈ S`. -/ |
| 94 | lemma exists_maximal_packing {a L c1 : ℝ} (hL : 0 < L) (hc1 : 0 < c1) {U : Set ℝ} |
| 95 | (hU : IsCompact U) (hUne : U.Nonempty) |
| 96 | (hUa : U ⊆ Set.Icc a (a + 2 * L)) (hvol : c1 * L ≤ (volume U).toReal) : |
| 97 | ∃ S : Finset ℝ, (S : Set ℝ) ⊆ Set.Icc 0 L ∧ Packed U S ∧ |
| 98 | ∀ x ∈ Set.Icc 0 L, ∃ p ∈ S, x - p ∈ U - U := by |
| 99 | classical |
| 100 | obtain ⟨u0, hu0⟩ := hUne |
| 101 | let N : Set ℕ := {n | ∃ S : Finset ℝ, (S : Set ℝ) ⊆ Set.Icc 0 L ∧ Packed U S ∧ S.card = n} |
| 102 | have hbdd : BddAbove N := by |
| 103 | refine ⟨⌊3 / c1⌋₊, ?_⟩ |
| 104 | rintro n ⟨S, hS, hP, rfl⟩ |
| 105 | refine Nat.le_floor ?_ |
| 106 | rw [le_div_iff₀ hc1] |
| 107 | exact packed_card_le hL hU hUa hvol hS hP |
| 108 | have hne : N.Nonempty := ⟨0, ∅, by simp, fun p hp => by simp at hp, rfl⟩ |
| 109 | obtain ⟨S, hS, hP, hcard⟩ := Nat.sSup_mem hne hbdd |
| 110 | refine ⟨S, hS, hP, ?_⟩ |
| 111 | intro x hx |
| 112 | by_contra hno |
| 113 | push_neg at hno |
| 114 | by_cases hxS : x ∈ S |
| 115 | · exact hno x hxS (Set.mem_sub.2 ⟨u0, hu0, u0, hu0, by ring⟩) |
| 116 | · have hins : ((insert x S : Finset ℝ) : Set ℝ) ⊆ Set.Icc 0 L := by |
| 117 | rw [Finset.coe_insert] |
| 118 | exact Set.insert_subset_iff.2 ⟨hx, hS⟩ |
| 119 | have hPins : Packed U (insert x S) := by |
| 120 | intro p hp q hq hpq u hu u' hu' hEq |
| 121 | rcases Finset.mem_insert.1 hp with hp' | hp' <;> |
| 122 | rcases Finset.mem_insert.1 hq with hq' | hq' |
| 123 | · exact hpq (hp'.trans hq'.symm) |
| 124 | · rw [hp'] at hEq |
| 125 | exact hno q hq' (Set.mem_sub.2 ⟨u', hu', u, hu, by linarith⟩) |
| 126 | · rw [hq'] at hEq |
| 127 | exact hno p hp' (Set.mem_sub.2 ⟨u, hu, u', hu', by linarith⟩) |
| 128 | · exact hP p hp' q hq' hpq u hu u' hu' hEq |
| 129 | have hmem : S.card + 1 ∈ N := |
| 130 | ⟨insert x S, hins, hPins, Finset.card_insert_of_notMem hxS⟩ |
| 131 | have hle := le_csSup hbdd hmem |
| 132 | rw [← hcard] at hle |
| 133 | omega |
| 134 | |
| 135 | end E424 |
| 136 | |