|
| 1 | +/- |
| 2 | +Copyright (c) 2024 Rémy Degenne. All rights reserved. |
| 3 | +Released under Apache 2.0 license as described in the file LICENSE. |
| 4 | +Authors: Rémy Degenne |
| 5 | +-/ |
| 6 | +import Mathlib.Data.Set.Finite |
| 7 | + |
| 8 | +/-! |
| 9 | +# Partitions based on membership of a sequence of sets |
| 10 | +
|
| 11 | +Let `f : ℕ → Set α` be a sequence of sets. For `n : ℕ`, we can form the set of points that are in |
| 12 | +`f 0 ∪ f 1 ∪ ... ∪ f (n-1)`; then the set of points in `(f 0)ᶜ ∪ f 1 ∪ ... ∪ f (n-1)` and so on for |
| 13 | +all 2^n choices of a set or its complement. The at most 2^n sets we obtain form a partition |
| 14 | +of `univ : Set α`. We call that partition `memPartition f n` (the membership partition of `f`). |
| 15 | +For `n = 0` we set `memPartition f 0 = {univ}`. |
| 16 | +
|
| 17 | +The partition `memPartition f (n + 1)` is finer than `memPartition f n`. |
| 18 | +
|
| 19 | +## Main definitions |
| 20 | +
|
| 21 | +* `memPartition f n`: the membership partition of the first `n` sets in `f`. |
| 22 | +* `memPartitionSet`: `memPartitionSet f n x` is the set in the partition `memPartition f n` to |
| 23 | + which `x` belongs. |
| 24 | +
|
| 25 | +## Main statements |
| 26 | +
|
| 27 | +* `disjoint_memPartition`: the sets in `memPartition f n` are disjoint |
| 28 | +* `sUnion_memPartition`: the union of the sets in `memPartition f n` is `univ` |
| 29 | +* `finite_memPartition`: `memPartition f n` is finite |
| 30 | +
|
| 31 | +-/ |
| 32 | + |
| 33 | +open Set |
| 34 | + |
| 35 | +variable {α : Type*} |
| 36 | + |
| 37 | +/-- `memPartition f n` is the partition containing at most `2^(n+1)` sets, where each set contains |
| 38 | +the points that for all `i` belong to one of `f i` or its complement. -/ |
| 39 | +def memPartition (f : ℕ → Set α) : ℕ → Set (Set α) |
| 40 | + | 0 => {univ} |
| 41 | + | n + 1 => {s | ∃ u ∈ memPartition f n, s = u ∩ f n ∨ s = u \ f n} |
| 42 | + |
| 43 | +@[simp] |
| 44 | +lemma memPartition_zero (f : ℕ → Set α) : memPartition f 0 = {univ} := rfl |
| 45 | + |
| 46 | +lemma memPartition_succ (f : ℕ → Set α) (n : ℕ) : |
| 47 | + memPartition f (n + 1) = {s | ∃ u ∈ memPartition f n, s = u ∩ f n ∨ s = u \ f n} := |
| 48 | + rfl |
| 49 | + |
| 50 | +lemma disjoint_memPartition (f : ℕ → Set α) (n : ℕ) {u v : Set α} |
| 51 | + (hu : u ∈ memPartition f n) (hv : v ∈ memPartition f n) (huv : u ≠ v) : |
| 52 | + Disjoint u v := by |
| 53 | + revert u v |
| 54 | + induction n with |
| 55 | + | zero => |
| 56 | + intro u v hu hv huv |
| 57 | + simp only [Nat.zero_eq, memPartition_zero, mem_insert_iff, mem_singleton_iff] at hu hv |
| 58 | + rw [hu, hv] at huv |
| 59 | + exact absurd rfl huv |
| 60 | + | succ n ih => |
| 61 | + intro u v hu hv huv |
| 62 | + rw [memPartition_succ] at hu hv |
| 63 | + obtain ⟨u', hu', hu'_eq⟩ := hu |
| 64 | + obtain ⟨v', hv', hv'_eq⟩ := hv |
| 65 | + rcases hu'_eq with rfl | rfl <;> rcases hv'_eq with rfl | rfl |
| 66 | + · refine Disjoint.mono (inter_subset_left _ _) (inter_subset_left _ _) (ih hu' hv' ?_) |
| 67 | + exact fun huv' ↦ huv (huv' ▸ rfl) |
| 68 | + · exact Disjoint.mono_left (inter_subset_right _ _) Set.disjoint_sdiff_right |
| 69 | + · exact Disjoint.mono_right (inter_subset_right _ _) Set.disjoint_sdiff_left |
| 70 | + · refine Disjoint.mono (diff_subset _ _) (diff_subset _ _) (ih hu' hv' ?_) |
| 71 | + exact fun huv' ↦ huv (huv' ▸ rfl) |
| 72 | + |
| 73 | +@[simp] |
| 74 | +lemma sUnion_memPartition (f : ℕ → Set α) (n : ℕ) : ⋃₀ memPartition f n = univ := by |
| 75 | + induction n with |
| 76 | + | zero => simp |
| 77 | + | succ n ih => |
| 78 | + rw [memPartition_succ] |
| 79 | + ext x |
| 80 | + have : x ∈ ⋃₀ memPartition f n := by simp [ih] |
| 81 | + simp only [mem_sUnion, mem_iUnion, mem_insert_iff, mem_singleton_iff, exists_prop, mem_univ, |
| 82 | + iff_true] at this ⊢ |
| 83 | + obtain ⟨t, ht, hxt⟩ := this |
| 84 | + by_cases hxf : x ∈ f n |
| 85 | + · exact ⟨t ∩ f n, ⟨t, ht, Or.inl rfl⟩, hxt, hxf⟩ |
| 86 | + · exact ⟨t \ f n, ⟨t, ht, Or.inr rfl⟩, hxt, hxf⟩ |
| 87 | + |
| 88 | +lemma finite_memPartition (f : ℕ → Set α) (n : ℕ) : Set.Finite (memPartition f n) := by |
| 89 | + induction n with |
| 90 | + | zero => simp |
| 91 | + | succ n ih => |
| 92 | + rw [memPartition_succ] |
| 93 | + have : Finite (memPartition f n) := Set.finite_coe_iff.mp ih |
| 94 | + rw [← Set.finite_coe_iff] |
| 95 | + simp_rw [setOf_exists, ← exists_prop, setOf_exists, setOf_or] |
| 96 | + refine Finite.Set.finite_biUnion (memPartition f n) _ (fun u _ ↦ ?_) |
| 97 | + rw [Set.finite_coe_iff] |
| 98 | + simp |
| 99 | + |
| 100 | +instance instFinite_memPartition (f : ℕ → Set α) (n : ℕ) : Finite (memPartition f n) := |
| 101 | + Set.finite_coe_iff.mp (finite_memPartition _ _) |
| 102 | + |
| 103 | +open Classical in |
| 104 | +/-- The set in `memPartition f n` to which `a : α` belongs. -/ |
| 105 | +def memPartitionSet (f : ℕ → Set α) : ℕ → α → Set α |
| 106 | + | 0 => fun _ ↦ univ |
| 107 | + | n + 1 => fun a ↦ if a ∈ f n then memPartitionSet f n a ∩ f n else memPartitionSet f n a \ f n |
| 108 | + |
| 109 | +@[simp] |
| 110 | +lemma memPartitionSet_zero (f : ℕ → Set α) (a : α) : memPartitionSet f 0 a = univ := by |
| 111 | + simp [memPartitionSet] |
| 112 | + |
| 113 | +lemma memPartitionSet_succ (f : ℕ → Set α) (n : ℕ) (a : α) [Decidable (a ∈ f n)] : |
| 114 | + memPartitionSet f (n + 1) a |
| 115 | + = if a ∈ f n then memPartitionSet f n a ∩ f n else memPartitionSet f n a \ f n := by |
| 116 | + simp [memPartitionSet] |
| 117 | + |
| 118 | +lemma memPartitionSet_mem (f : ℕ → Set α) (n : ℕ) (a : α) : |
| 119 | + memPartitionSet f n a ∈ memPartition f n := by |
| 120 | + induction n with |
| 121 | + | zero => simp [memPartitionSet] |
| 122 | + | succ n ih => |
| 123 | + classical |
| 124 | + rw [memPartitionSet_succ, memPartition_succ] |
| 125 | + refine ⟨memPartitionSet f n a, ?_⟩ |
| 126 | + split_ifs <;> simp [ih] |
| 127 | + |
| 128 | +lemma mem_memPartitionSet (f : ℕ → Set α) (n : ℕ) (a : α) : a ∈ memPartitionSet f n a := by |
| 129 | + induction n with |
| 130 | + | zero => simp [memPartitionSet] |
| 131 | + | succ n ih => |
| 132 | + classical |
| 133 | + rw [memPartitionSet_succ] |
| 134 | + split_ifs with h <;> exact ⟨ih, h⟩ |
| 135 | + |
| 136 | +lemma memPartitionSet_eq_iff {f : ℕ → Set α} {n : ℕ} (a : α) {s : Set α} |
| 137 | + (hs : s ∈ memPartition f n) : |
| 138 | + memPartitionSet f n a = s ↔ a ∈ s := by |
| 139 | + refine ⟨fun h ↦ h ▸ mem_memPartitionSet f n a, fun h ↦ ?_⟩ |
| 140 | + by_contra h_ne |
| 141 | + have h_disj : Disjoint s (memPartitionSet f n a) := |
| 142 | + disjoint_memPartition f n hs (memPartitionSet_mem f n a) (Ne.symm h_ne) |
| 143 | + refine absurd h_disj ?_ |
| 144 | + rw [not_disjoint_iff_nonempty_inter] |
| 145 | + exact ⟨a, h, mem_memPartitionSet f n a⟩ |
| 146 | + |
| 147 | +lemma memPartitionSet_of_mem {f : ℕ → Set α} {n : ℕ} {a : α} {s : Set α} |
| 148 | + (hs : s ∈ memPartition f n) (ha : a ∈ s) : |
| 149 | + memPartitionSet f n a = s := |
| 150 | + (memPartitionSet_eq_iff a hs).mpr ha |
0 commit comments