File size: 6,652 Bytes
e5a97c6 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 | import OAI.Combinatorics.MatrixRemoval.Host
import OAI.Combinatorics.MatrixRemoval.ThreeSeedSampling
namespace OAI
/-!
The canonical host projections and protected-cell sampling bridge.
Three seeds give the cellwise sampling bound.
-/
namespace Problem348.Construction.HostSampling
open Problem348.TreeSampling
/-- Anchor and dummy positions use their independent axis seed. -/
def sampleDepth {h : ℕ} : Position h → Option (Fin (h + 1))
| Sum.inl _ => none
| Sum.inr (Sum.inl v) => some ⟨depth v, Nat.lt_succ_of_le (depth_le v)⟩
| Sum.inr (Sum.inr _) => none
/-- The coordinate within the size-`2^h` class of a raw host position. -/
def offset {h : ℕ} : Position h → Fin (2 ^ h)
| Sum.inl (_, _, x) => x
| Sum.inr (Sum.inl v) => v.2
| Sum.inr (Sum.inr x) => x
/-- The selected coordinate in the class containing a given position. -/
def coordinate {h : ℕ} (z u : Fin (2 ^ h)) : Position h → Fin (2 ^ h)
| Sum.inl _ => u
| Sum.inr (Sum.inl v) => atLevel h (depth v) (depth_le v) z u
| Sum.inr (Sum.inr _) => u
/-- Whether both positions of a fixed raw cell are selected. -/
def Selected {h : ℕ} (s : Seeds (2 ^ h)) (r c : Position h) : Prop :=
(coordinate s.1 s.2.1 r, coordinate s.1 s.2.2 c) = (offset r, offset c)
instance {h : ℕ} (s : Seeds (2 ^ h)) (r c : Position h) :
Decidable (Selected s r c) := inferInstanceAs (Decidable (_ = _))
/-- Protected cells: at least one anchor/dummy position, or two root positions. -/
def Protected {h : ℕ} (r c : Position h) : Prop :=
sampleDepth r = none ∨ sampleDepth c = none ∨
sampleDepth r = some ⟨0, by omega⟩ ∧ sampleDepth c = some ⟨0, by omega⟩
@[simp] theorem protected_anchor_left {h : ℕ} (a : AnchorPosition h)
(c : Position h) : Protected (Sum.inl a) c := by
simp [Protected, sampleDepth]
@[simp] theorem protected_anchor_right {h : ℕ} (r : Position h)
(a : AnchorPosition h) : Protected r (Sum.inl a) := by
simp [Protected, sampleDepth]
@[simp] theorem protected_dummy_left {h : ℕ} (x : Fin (2 ^ h))
(c : Position h) : Protected (Sum.inr (Sum.inr x)) c := by
simp [Protected, sampleDepth]
@[simp] theorem protected_dummy_right {h : ℕ} (r : Position h)
(x : Fin (2 ^ h)) : Protected r (Sum.inr (Sum.inr x)) := by
simp [Protected, sampleDepth]
theorem protected_roots {h : ℕ} (v w : VariablePosition h)
(hv : depth v = 0) (hw : depth w = 0) :
Protected (Sum.inr (Sum.inl v)) (Sum.inr (Sum.inl w)) := by
simp [Protected, sampleDepth, hv, hw]
/-- Concrete host protected-cell events all have exactly `2^h` seed preimages. -/
theorem selected_fiber_card {h : ℕ} (r c : Position h) (hp : Protected r c) :
Fintype.card {s : Seeds (2 ^ h) // Selected s r c} = 2 ^ h := by
rcases r with ⟨t, u, x⟩ | (v | x) <;>
rcases c with ⟨t', u', y⟩ | (w | y)
· exact card_both_fiber x y
· exact card_atLevel_column_fiber h (depth w) (depth_le w) x w.2
· exact card_both_fiber x y
· exact card_atLevel_row_fiber h (depth v) (depth_le v) v.2 y
· have hd : depth v = 0 ∧ depth w = 0 := by
simpa [Protected, sampleDepth, Fin.ext_iff] using hp
have he : ∀ s : Seeds (2 ^ h), Selected s (Sum.inr (Sum.inl v))
(Sum.inr (Sum.inl w)) ↔ s.2 = (v.2, w.2) := by
intro s
simp [Selected, coordinate, offset, hd.1, hd.2]
calc
_ = Fintype.card {s : Seeds (2 ^ h) // s.2 = (v.2, w.2)} :=
Fintype.card_congr (Equiv.subtypeEquivRight he)
_ = _ := card_both_fiber v.2 w.2
· exact card_atLevel_row_fiber h (depth v) (depth_le v) v.2 y
· exact card_both_fiber x y
· exact card_atLevel_column_fiber h (depth w) (depth_le w) x w.2
· exact card_both_fiber x y
/-- Fraction-free marginal equality, directly consumable by finite avoidance. -/
theorem selected_fiber_card_mul {h : ℕ} (r c : Position h) (hp : Protected r c) :
Fintype.card {s : Seeds (2 ^ h) // Selected s r c} * (2 ^ h) ^ 2 =
Fintype.card (Seeds (2 ^ h)) := by
rw [selected_fiber_card r c hp, card_seeds]
ring
/-- The same marginal in the `Finset.filter` form used by the union bound. -/
theorem selected_filter_card {h : ℕ} (r c : Position h) (hp : Protected r c) :
(Finset.univ.filter fun s : Seeds (2 ^ h) => Selected s r c).card = 2 ^ h := by
simpa only [Fintype.card_subtype] using selected_fiber_card r c hp
/-- A subset of the protected event has at most the same frequency. -/
theorem protected_event_card_le {h : ℕ} (r c : Position h)
(event : Finset (Seeds (2 ^ h)))
(hevent : ∀ s ∈ event, Protected r c ∧ Selected s r c) :
event.card ≤ 2 ^ h := by
classical
rcases event.eq_empty_or_nonempty with hempty | ⟨s, hs⟩
· simp [hempty]
· have hp := (hevent s hs).1
calc
event.card ≤ (Finset.univ.filter fun s => Selected s r c).card := by
apply Finset.card_le_card
intro t ht
simp only [Finset.mem_filter, Finset.mem_univ, true_and]
exact (hevent t ht).2
_ = _ := selected_filter_card r c hp
/-- Guard-cell containment in the protected selected-cell event implies
the union-bound frequency estimate for each fixed raw cell. -/
theorem guard_frequency {h : ℕ}
(guards : Seeds (2 ^ h) → Finset (Position h × Position h))
(hguards : ∀ s rc, rc ∈ guards s →
Protected rc.1 rc.2 ∧ Selected s rc.1 rc.2)
(rc : Position h × Position h) :
(Finset.univ.filter fun s => rc ∈ guards s).card * (2 ^ h) ^ 2 ≤
Fintype.card (Seeds (2 ^ h)) := by
classical
have hb := protected_event_card_le rc.1 rc.2
(Finset.univ.filter fun s => rc ∈ guards s)
(fun s hs => hguards s rc (Finset.mem_filter.mp hs).2)
rw [card_seeds]
calc
_ ≤ 2 ^ h * (2 ^ h) ^ 2 := Nat.mul_le_mul_right _ hb
_ = (2 ^ h) ^ 3 := by ring
/-- Independent row and column reindexings preserve the protected-cell bound. -/
theorem transported_guard_frequency {h n : ℕ}
(row col : Position h ≃ Fin n)
(guards : Seeds (2 ^ h) → Finset (Fin n × Fin n))
(hguards : ∀ s rc, rc ∈ guards s →
Protected (row.symm rc.1) (col.symm rc.2) ∧
Selected s (row.symm rc.1) (col.symm rc.2))
(rc : Fin n × Fin n) :
(Finset.univ.filter fun s => rc ∈ guards s).card * (2 ^ h) ^ 2 ≤
Fintype.card (Seeds (2 ^ h)) := by
classical
have hb := protected_event_card_le (row.symm rc.1) (col.symm rc.2)
(Finset.univ.filter fun s => rc ∈ guards s)
(fun s hs => hguards s rc (Finset.mem_filter.mp hs).2)
rw [card_seeds]
calc
_ ≤ 2 ^ h * (2 ^ h) ^ 2 := Nat.mul_le_mul_right _ hb
_ = (2 ^ h) ^ 3 := by ring
end Problem348.Construction.HostSampling
end OAI
|