1import FeedbackChannel.LatticeJoin
2
3/-!
4# Propositions 1 and 2: the data-processing law on the channel lattice; category leakage is an
5order embedding
6
7Source: `paper/evaluation_feedback_lattice.md` (version 0.6), §1 and §2.
8
9A deterministic channel is a function `f : X → Y` on a finite record set `X`; its partition is the
10kernel of `f`. In the note's order `p ≤ q` when `q` refines `p`, written here `Refines g f`
11(`g` refines `f`: `g x = g y → f x = f y`). The total variation through `f` is the largest
12`|P(U) - Q(U)|` over unions `U` of blocks of `f`, i.e. preimages `f⁻¹ S`. `P, Q` are arbitrary
13rational weights on records (in particular distributions).
14-/
15
16namespace FeedbackChannel.LatticeOrder
17
18open Finset FeedbackChannel.LatticeJoin
19
20section Prop1
21
22variable {X Y Z : Type*} [Fintype X] [DecidableEq X] [Fintype Y] [DecidableEq Y]
23 [Fintype Z] [DecidableEq Z]
24
25/-- `g` refines `f` (the note's `f ≤ g`). -/
26def Refines (g : X → Z) (f : X → Y) : Prop := ∀ x y, g x = g y → f x = f y
27
28/-- `TV(f_# P, f_# Q) = max_U |P(U) - Q(U)|` over unions `U = f⁻¹ S` of blocks of `f`. -/
29def tvThrough (f : X → Y) (P Q : X → ℚ) : ℚ :=
30 (univ : Finset (Finset Y)).sup' ⟨∅, mem_univ _⟩
31 fun S => |∑ x ∈ univ.filter (fun x => f x ∈ S), (P x - Q x)|
32
33/-- **Proposition 1 (lattice data-processing law).** If `g` refines `f`, the total variation
34through `f` is at most the total variation through `g`, for all `P, Q`. -/
35theorem prop1_mono (f : X → Y) (g : X → Z) (h : Refines g f) (P Q : X → ℚ) :
36 tvThrough f P Q ≤ tvThrough g P Q := by
37 unfold tvThrough
38 apply Finset.sup'_le
39 intro S _
40 set T : Finset Z := (univ.filter fun x => f x ∈ S).image g
41 have hset : (univ.filter fun x => f x ∈ S) = univ.filter fun x => g x ∈ T := by
42 ext x
43 simp only [mem_filter, mem_univ, true_and, T, mem_image]
44 constructor
45 · intro hx; exact ⟨x, hx, rfl⟩
46 · rintro ⟨x', hx', hg⟩
47 rw [← h x' x hg]; exact hx'
48 rw [hset]
49 exact Finset.le_sup' (fun T => |∑ x ∈ univ.filter (fun x => g x ∈ T), (P x - Q x)|) (mem_univ T)
50
51/-- Point mass. -/
52def delta (x : X) : X → ℚ := fun z => if z = x then 1 else 0
53
54lemma sum_delta_diff {W : Type*} [DecidableEq W] (k : X → W) (S : Finset W) (x y : X) :
55 ∑ z ∈ univ.filter (fun z => k z ∈ S), (delta x z - delta y z) =
56 (if k x ∈ S then 1 else 0) - (if k y ∈ S then 1 else 0) := by
57 rw [Finset.sum_sub_distrib]
58 simp [delta, Finset.sum_ite_eq']
59
60/-- **Proposition 1 (converse).** If `g` does not refine `f`, two point masses have total
61variation `1` through `f` and `0` through `g`. -/
62theorem prop1_converse (f : X → Y) (g : X → Z) (h : ¬ Refines g f) :
63 ∃ x y, tvThrough f (delta x) (delta y) = 1 ∧ tvThrough g (delta x) (delta y) = 0 := by
64 unfold Refines at h
65 push Not at h
66 obtain ⟨x, y, hg, hf⟩ := h
67 refine ⟨x, y, ?_, ?_⟩
68 · unfold tvThrough
69 apply le_antisymm
70 · apply Finset.sup'_le
71 intro S _
72 rw [sum_delta_diff]
73 split_ifs <;> norm_num
74 · refine le_trans (le_of_eq ?_) (Finset.le_sup' _ (mem_univ {f x}))
75 rw [sum_delta_diff]
76 simp [Ne.symm hf]
77 · unfold tvThrough
78 apply le_antisymm
79 · apply Finset.sup'_le
80 intro T _
81 rw [sum_delta_diff, hg, sub_self, abs_zero]
82 · exact le_trans (abs_nonneg _) (Finset.le_sup'
83 (fun T => |∑ z ∈ univ.filter (fun z => g z ∈ T), (delta x z - delta y z)|) (mem_univ ∅))
84
85end Prop1
86
87section Prop2
88
89variable {ι R R' : Type*} [Fintype ι] [DecidableEq ι] [Fintype R] [DecidableEq R]
90 [Fintype R'] [DecidableEq R']
91
92lemma rowCount_decomp (γ : ι → R) (γ' : ι → R') (h : ∀ i j, γ' i = γ' j → γ i = γ j)
93 (r : ι → Bool) (a : R) :
94 rowCount γ r a = ∑ a', if (∃ j, γ' j = a' ∧ γ j = a) then rowCount γ' r a' else 0 := by
95 unfold rowCount
96 rw [card_eq_sum_card_fiberwise (f := γ') (t := univ) (by intro i _; simp)]
97 refine Finset.sum_congr rfl fun a' _ => ?_
98 split_ifs with hex
99 · obtain ⟨j, hj1, hj2⟩ := hex
100 congr 1
101 ext i
102 simp only [mem_filter, mem_univ, true_and]
103 constructor
104 · rintro ⟨⟨_, hr⟩, hi⟩; exact ⟨hi, hr⟩
105 · rintro ⟨hi, hr⟩
106 exact ⟨⟨(h i j (hi.trans hj1.symm)).trans hj2, hr⟩, hi⟩
107 · rw [card_eq_zero, filter_eq_empty_iff]
108 intro i hi hia'
109 simp only [mem_filter, mem_univ, true_and] at hi
110 exact hex ⟨i, hia', hi.1⟩
111
112lemma filter_ne_erase {W : Type*} [DecidableEq W] (κ : ι → W) (w : W) (t : ι) :
113 (univ.filter fun k => κ k = w ∧ decide (k ≠ t) = true) = (univ.filter fun k => κ k = w).erase t := by
114 ext k
115 simp only [mem_filter, mem_univ, true_and, mem_erase, decide_eq_true_eq]
116 tauto
117
118lemma card_ne_erase {s : Finset ι} {i : ι} (hi : i ∈ s) : (s.erase i).card ≠ s.card := by
119 rw [card_erase_of_mem hi]
120 have : 0 < s.card := card_pos.2 ⟨i, hi⟩
121 omega
122
123/-- **Proposition 2 (category leakage is an order embedding).** For category maps `γ, γ'`, the
124per-category pass counts `Φ(γ')` refine `Φ(γ)` (equal `γ'`-counts force equal `γ`-counts on every
125pair of records) iff `γ'` refines `γ`. -/
126theorem prop2 (γ : ι → R) (γ' : ι → R') :
127 (∀ r s : ι → Bool, rowCount γ' r = rowCount γ' s → rowCount γ r = rowCount γ s) ↔
128 (∀ i j, γ' i = γ' j → γ i = γ j) := by
129 constructor
130 · intro hΦ
131 by_contra hγ
132 push Not at hγ
133 obtain ⟨i, j, h', hne⟩ := hγ
134 let r : ι → Bool := fun k => decide (k ≠ i)
135 let s : ι → Bool := fun k => decide (k ≠ j)
136 have h1 : rowCount γ' r = rowCount γ' s := by
137 funext a'
138 unfold rowCount
139 simp only [r, s]
140 rw [filter_ne_erase, filter_ne_erase]
141 by_cases ha : γ' i = a'
142 · rw [card_erase_of_mem (by simp [ha]), card_erase_of_mem (by simp [← h', ha])]
143 · rw [erase_eq_of_notMem (by simp [ha]), erase_eq_of_notMem (by simp [← h', ha])]
144 have h2 := congrFun (hΦ r s h1) (γ i)
145 unfold rowCount at h2
146 simp only [r, s] at h2
147 have hj : j ∉ univ.filter (fun k => γ k = γ i) := by simp [Ne.symm hne]
148 rw [filter_ne_erase, filter_ne_erase, erase_eq_of_notMem hj] at h2
149 exact card_ne_erase (by simp) h2
150 · intro hγ r s hrs
151 funext a
152 rw [rowCount_decomp γ γ' hγ r a, rowCount_decomp γ γ' hγ s a, hrs]
153
154/-- The top endpoint: with singleton categories (`γ = id`) the counts are the item outcomes, so
155`Φ(singletons)` is item-level feedback. -/
156theorem prop2_item_level (r s : ι → Bool) : rowCount (id : ι → ι) r = rowCount id s ↔ r = s := by
157 constructor
158 · intro h
159 funext i
160 have := congrFun h i
161 unfold rowCount at this
162 have e : ∀ t : ι → Bool, (univ.filter fun k => id k = i ∧ t k = true) =
163 if t i = true then {i} else ∅ := by
164 intro t
165 ext k
166 split_ifs with ht <;> simp only [mem_filter, mem_univ, true_and, id, mem_singleton,
167 Finset.notMem_empty, iff_false, not_and] <;> [exact ⟨fun h => h.1, fun h => ⟨h, h ▸ ht⟩⟩;
168 exact fun hk => hk ▸ ht]
169 rw [e, e] at this
170 cases hr : r i <;> cases hs : s i <;> simp_all
171 · rintro rfl; rfl
172
173end Prop2
174
175end FeedbackChannel.LatticeOrder