Buckets:
| import Mathlib | |
| import OAI.Computability.DirectedFeedback.Games.KMSBasisComparisonRetention | |
| namespace OAI | |
| namespace DFVSGames.Inverse.ShortcodeFromGrassmann | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| open Shortcode MatrixChart | |
| theorem relativeDensity_filter_eq_expect {Ω : Type*} [Fintype Ω] [DecidableEq Ω] | |
| (S : Finset Ω) (P : Ω → Prop) [DecidablePred P] : | |
| KMS.relativeDensity S (Finset.univ.filter P) = | |
| 𝔼 x : {x : Ω // P x}, if x.val ∈ S then (1 : ℝ) else 0 := by | |
| unfold KMS.relativeDensity | |
| rw [Fintype.expect_eq_sum_div_card] | |
| rw [← Finset.sum_subtype (Finset.univ.filter P) (by simp) | |
| (fun x => if x ∈ S then (1 : ℝ) else 0)] | |
| rw [Finset.sum_boole, Fintype.card_subtype] | |
| have hsets : S ∩ Finset.univ.filter P = | |
| (Finset.univ.filter P).filter (fun x => x ∈ S) := by | |
| ext x | |
| simp only [Finset.mem_inter, Finset.mem_filter, Finset.mem_univ, true_and] | |
| exact and_comm | |
| rw [hsets] | |
| theorem retention_image {X : Type*} [DecidableEq X] {n ell : ℕ} | |
| (S : Finset X) (e : X → KMS.Vertex n ell) (he : Function.Injective e) : | |
| KMS.retention (S.image e) = | |
| S.expect fun x => KMS.relativeDensity (S.image e) (KMS.neighbors (e x)) := by | |
| have h : KMS.retention (S.image e) = | |
| (S.image e).expect fun L => KMS.relativeDensity (S.image e) (KMS.neighbors L) := by | |
| rw [Finset.expect_eq_sum_div_card] | |
| rfl | |
| rw [h] | |
| exact Finset.expect_image he.injOn | |
| theorem relativeDensity_neighbors_eq_nonzero_average_half {ell m : ℕ} | |
| (f : Mat ell m → Vector ell) (y : Vector ell) (M : Mat ell m) : | |
| KMS.relativeDensity (liftedFiber f y) (KMS.neighbors (matrixVertex M)) = | |
| (𝔼 p : NonzeroVectorFactors ell m, | |
| if f (M + rankOne p.1.val p.2.val) = y then (1 : ℝ) else 0) / 2 := by | |
| let C := KMS.neighbors (matrixVertex M) ∩ matrixChart ell m | |
| have hC : C = Finset.univ.filter (fun L : KMS.Vertex (ell + m) ell => | |
| KMS.Adjacent (matrixVertex M) L ∧ L ∈ matrixChart ell m) := by | |
| ext L | |
| simp [C, KMS.neighbors] | |
| have hcardC : C.card = (2 ^ ell - 1) * (2 ^ m - 1) := by | |
| rw [hC] | |
| have h := card_matrixVertexChartNeighbors M | |
| simpa only [MatrixVertexChartNeighbors, Nat.card_eq_fintype_card, | |
| Fintype.card_subtype] using h | |
| have hcard : (KMS.neighbors (matrixVertex M)).card = 2 * C.card := by | |
| rw [hcardC] | |
| exact card_full_neighbors_twice M | |
| have hnumerator : liftedFiber f y ∩ C = | |
| liftedFiber f y ∩ KMS.neighbors (matrixVertex M) := | |
| KMS.inter_chart_eq _ _ _ (liftedFiber_subset_chart f y) | |
| have hhalf : KMS.relativeDensity (liftedFiber f y) | |
| (KMS.neighbors (matrixVertex M)) = | |
| KMS.relativeDensity (liftedFiber f y) C / 2 := by | |
| unfold KMS.relativeDensity | |
| rw [hcard, ← hnumerator, Nat.cast_mul, Nat.cast_ofNat, | |
| mul_comm (2 : ℝ), div_mul_eq_div_div] | |
| rw [hhalf] | |
| congr 1 | |
| rw [hC] | |
| trans (𝔼 L : MatrixVertexChartNeighbors M, | |
| if L.val ∈ liftedFiber f y then (1 : ℝ) else 0) | |
| · exact relativeDensity_filter_eq_expect (liftedFiber f y) | |
| (fun L => KMS.Adjacent (matrixVertex M) L ∧ L ∈ matrixChart ell m) | |
| symm | |
| apply Fintype.expect_equiv (vectorFactorsEquivMatrixVertexChartNeighbors M) | |
| intro p | |
| simp only [vectorFactorsEquivMatrixVertexChartNeighbors_apply, | |
| matrixVertex_mem_liftedFiber] | |
| theorem liftedFiber_retention_eq_half {ell m : ℕ} | |
| (f : Mat ell m → Vector ell) (y : Vector ell) : | |
| KMS.retention (liftedFiber f y) = | |
| (𝔼 M ∈ matrixFiber f y, 𝔼 p : NonzeroVectorFactors ell m, | |
| if f (M + rankOne p.1.val p.2.val) = y then (1 : ℝ) else 0) / 2 := by | |
| unfold liftedFiber | |
| rw [retention_image _ _ matrixVertex_injective] | |
| change (𝔼 M ∈ matrixFiber f y, | |
| KMS.relativeDensity (liftedFiber f y) (KMS.neighbors (matrixVertex M))) = _ | |
| simp_rw [relativeDensity_neighbors_eq_nonzero_average_half] | |
| exact (Finset.expect_div _ _ _).symm | |
| end | |
| end DFVSGames.Inverse.ShortcodeFromGrassmann | |
| namespace DFVSGames.Inverse.EqualityFiber | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| open DFVSGames.Foundations.Information | |
| variable {X Y : Type*} [Fintype X] [Fintype Y] | |
| def fiberMass (p : X → ℝ) (f : X → Y) (y : Y) : ℝ := by | |
| classical | |
| exact ∑ x, if f x = y then p x else 0 | |
| def fiberFlow (p : X → ℝ) (k : X → X → ℝ) (f : X → Y) (y : Y) : ℝ := by | |
| classical | |
| exact ∑ x, p x * ∑ x', k x x' * if f x = y ∧ f x' = y then 1 else 0 | |
| def equalityAcceptance (p : X → ℝ) (k : X → X → ℝ) (f : X → Y) : ℝ := by | |
| classical | |
| exact ∑ x, p x * ∑ x', k x x' * if f x = f x' then 1 else 0 | |
| theorem sum_fiberMass (p : X → ℝ) (f : X → Y) : | |
| ∑ y, fiberMass p f y = ∑ x, p x := by | |
| classical | |
| unfold fiberMass | |
| rw [Finset.sum_comm] | |
| simp | |
| omit [Fintype Y] in | |
| theorem fiberMass_nonneg (p : X → ℝ) (hp : ∀ x, 0 ≤ p x) | |
| (f : X → Y) (y : Y) : 0 ≤ fiberMass p f y := by | |
| classical | |
| apply Finset.sum_nonneg | |
| intro x _ | |
| split | |
| · exact hp x | |
| · exact le_rfl | |
| omit [Fintype Y] in | |
| theorem fiberFlow_nonneg (p : X → ℝ) (k : X → X → ℝ) | |
| (hp : ∀ x, 0 ≤ p x) (hk : ∀ x x', 0 ≤ k x x') | |
| (f : X → Y) (y : Y) : 0 ≤ fiberFlow p k f y := by | |
| classical | |
| apply Finset.sum_nonneg | |
| intro x _ | |
| apply mul_nonneg (hp x) | |
| apply Finset.sum_nonneg | |
| intro x' _ | |
| apply mul_nonneg (hk x x') | |
| split <;> norm_num | |
| omit [Fintype Y] in | |
| theorem fiberFlow_le_mass (p : X → ℝ) (k : X → X → ℝ) | |
| (hp : ∀ x, 0 ≤ p x) (hk : ∀ x, IsProbability (k x)) | |
| (f : X → Y) (y : Y) : fiberFlow p k f y ≤ fiberMass p f y := by | |
| classical | |
| apply Finset.sum_le_sum | |
| intro x _ | |
| by_cases h : f x = y | |
| · simp only [h, true_and, ite_true] | |
| have hinner : (∑ x', k x x' * if f x' = y then 1 else 0) ≤ 1 := by | |
| calc | |
| _ ≤ ∑ x', k x x' := by | |
| apply Finset.sum_le_sum | |
| intro x' _ | |
| split <;> simp [(hk x).1 x'] | |
| _ = 1 := (hk x).2 | |
| simpa using mul_le_mul_of_nonneg_left hinner (hp x) | |
| · simp [h] | |
| private theorem sum_sameFiber_indicator_inline_EqualityFiber (a b : Y) : | |
| (∑ y, if a = y ∧ b = y then (1 : ℝ) else 0) = | |
| if a = b then 1 else 0 := by | |
| classical | |
| by_cases h : a = b | |
| · subst b | |
| simp | |
| · rw [ite_eq_right h] | |
| apply Finset.sum_eq_zero | |
| intro y _ | |
| have h' : ¬ (a = y ∧ b = y) := fun hy => h (hy.1.trans hy.2.symm) | |
| simp [h'] | |
| theorem sum_fiberFlow (p : X → ℝ) (k : X → X → ℝ) (f : X → Y) : | |
| ∑ y, fiberFlow p k f y = equalityAcceptance p k f := by | |
| classical | |
| unfold fiberFlow equalityAcceptance | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| rw [← Finset.mul_sum, Finset.sum_comm] | |
| congr 1 | |
| apply Finset.sum_congr rfl | |
| intro x' _ | |
| rw [← Finset.mul_sum, sum_sameFiber_indicator_inline_EqualityFiber] | |
| theorem exists_positive_mass_le_flow (mass flow : Y → ℝ) | |
| (hmass : IsProbability mass) (_hflow : ∀ y, 0 ≤ flow y) | |
| (hzero : ∀ y, mass y = 0 → flow y = 0) | |
| {η : ℝ} (haccept : η ≤ ∑ y, flow y) : | |
| ∃ y, 0 < mass y ∧ η * mass y ≤ flow y := by | |
| classical | |
| by_contra hnone | |
| have hless (y : Y) (hy : 0 < mass y) : flow y < η * mass y := by | |
| apply lt_of_not_ge | |
| intro h | |
| exact hnone ⟨y, hy, h⟩ | |
| have hle (y : Y) : flow y ≤ η * mass y := by | |
| rcases eq_or_lt_of_le (hmass.1 y) with hz | hz | |
| · simp [← hz, hzero y hz.symm] | |
| · exact (hless y hz).le | |
| have hex : ∃ y, 0 < mass y := by | |
| by_contra hn | |
| have hall (y : Y) : mass y = 0 := le_antisymm (le_of_not_gt (fun hy => hn ⟨y, hy⟩)) | |
| (hmass.1 y) | |
| have := hmass.2 | |
| simp [hall] at this | |
| obtain ⟨y, hy⟩ := hex | |
| have hstrict : (∑ y, flow y) < ∑ y, η * mass y := by | |
| exact Finset.sum_lt_sum (fun y _ => hle y) ⟨y, Finset.mem_univ y, hless y hy⟩ | |
| rw [← Finset.mul_sum, hmass.2, mul_one] at hstrict | |
| exact (not_lt_of_ge haccept) hstrict | |
| theorem exists_fiber_retention (p : X → ℝ) (k : X → X → ℝ) | |
| (hp : IsProbability p) (hk : ∀ x, IsProbability (k x)) | |
| (f : X → Y) {η : ℝ} (haccept : η ≤ equalityAcceptance p k f) : | |
| ∃ y, 0 < fiberMass p f y ∧ η ≤ fiberFlow p k f y / fiberMass p f y := by | |
| have hmass : IsProbability (fiberMass p f) := | |
| ⟨fiberMass_nonneg p hp.1 f, (sum_fiberMass p f).trans hp.2⟩ | |
| have hflow := fiberFlow_nonneg p k hp.1 (fun x => (hk x).1) f | |
| have hzero (y : Y) (hy : fiberMass p f y = 0) : fiberFlow p k f y = 0 := by | |
| apply le_antisymm _ (hflow y) | |
| simpa [hy] using fiberFlow_le_mass p k hp.1 hk f y | |
| obtain ⟨y, hy, hret⟩ := exists_positive_mass_le_flow (fiberMass p f) | |
| (fiberFlow p k f) hmass hflow hzero (by simpa [sum_fiberFlow] using haccept) | |
| exact ⟨y, hy, (le_div_iff₀ hy).2 hret⟩ | |
| theorem nonzero_retention_ge_half {η p₀ R : ℝ} | |
| (hη : 0 < η) (hη1 : η < 1) (hp₀ : 0 ≤ p₀) (hp₀η : p₀ ≤ η / 2) | |
| (haccept : η ≤ p₀ + (1 - p₀) * R) : η / 2 ≤ R := by | |
| have hp₀1 : p₀ < 1 := by linarith | |
| have hden : 0 < 1 - p₀ := by linarith | |
| have hprod : η / 2 * (1 - p₀) ≤ (1 - p₀) * R := by nlinarith | |
| nlinarith | |
| theorem chart_retention_ge_quarter {η R : ℝ} (h : η / 2 ≤ R) : η / 4 ≤ R / 2 := by | |
| linarith | |
| end | |
| end DFVSGames.Inverse.EqualityFiber | |
| namespace DFVSGames.Inverse.Shortcode | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| open DFVSGames.Foundations.Information | |
| def matrixWeight {ell m : ℕ} (_ : Mat ell m) : ℝ := | |
| (Fintype.card (Mat ell m) : ℝ)⁻¹ | |
| theorem matrixWeight_probability (ell m : ℕ) : | |
| IsProbability (matrixWeight (ell := ell) (m := m)) := by | |
| constructor | |
| · intro M | |
| exact inv_nonneg.mpr (Nat.cast_nonneg _) | |
| · have hcard : (Fintype.card (Mat ell m) : ℝ) ≠ 0 := by | |
| exact_mod_cast Fintype.card_ne_zero | |
| simp [matrixWeight, hcard] | |
| def matrixKernel {ell m : ℕ} (M N : Mat ell m) : ℝ := | |
| 𝔼 a : Vector ell, 𝔼 l : Vector m, | |
| if N = M + rankOne a l then 1 else 0 | |
| theorem matrixKernel_nonneg {ell m : ℕ} (M N : Mat ell m) : | |
| 0 ≤ matrixKernel M N := by | |
| apply Finset.expect_nonneg | |
| intro a _ | |
| apply Finset.expect_nonneg | |
| intro l _ | |
| split <;> norm_num | |
| theorem matrixKernel_probability {ell m : ℕ} (M : Mat ell m) : | |
| IsProbability (matrixKernel M) := by | |
| refine ⟨matrixKernel_nonneg M, ?_⟩ | |
| unfold matrixKernel | |
| rw [← Finset.expect_sum_comm] | |
| have hpoint (a : Vector ell) : | |
| (∑ N : Mat ell m, 𝔼 l : Vector m, | |
| if N = M + rankOne a l then (1 : ℝ) else 0) = 1 := by | |
| rw [← Finset.expect_sum_comm] | |
| simp | |
| simp only [hpoint] | |
| simp | |
| theorem matrixKernel_equality {ell m : ℕ} (f : Mat ell m → Vector ell) | |
| (M : Mat ell m) : | |
| (∑ N, matrixKernel M N * if f M = f N then (1 : ℝ) else 0) = | |
| 𝔼 a, 𝔼 l, if f M = f (M + rankOne a l) then 1 else 0 := by | |
| simp only [matrixKernel, Finset.expect_mul] | |
| rw [← Finset.expect_sum_comm] | |
| apply Finset.expect_congr rfl | |
| intro a _ | |
| rw [← Finset.expect_sum_comm] | |
| apply Finset.expect_congr rfl | |
| intro l _ | |
| simp only [ite_mul, one_mul, zero_mul, Finset.sum_ite_eq', Finset.mem_univ, ite_true] | |
| theorem equalityAcceptance_eq_kernel {ell m : ℕ} (f : Mat ell m → Vector ell) : | |
| equalityAcceptance f = EqualityFiber.equalityAcceptance matrixWeight matrixKernel f := by | |
| calc | |
| equalityAcceptance f = ∑ M, matrixWeight M * | |
| (𝔼 a, 𝔼 l, if f M = f (M + rankOne a l) then (1 : ℝ) else 0) := by | |
| unfold equalityAcceptance matrixWeight | |
| rw [Fintype.expect_eq_sum_div_card] | |
| simp only [div_eq_mul_inv, ← Finset.mul_sum, mul_comm] | |
| _ = EqualityFiber.equalityAcceptance matrixWeight matrixKernel f := by | |
| unfold EqualityFiber.equalityAcceptance | |
| apply Finset.sum_congr rfl | |
| intro M _ | |
| congr 1 | |
| convert (matrixKernel_equality f M).symm using 1 | |
| apply Finset.sum_congr rfl | |
| intro N _ | |
| by_cases h : f M = f N <;> simp [h] | |
| theorem exists_output_fiber {ell m : ℕ} (f : Mat ell m → Vector ell) | |
| {η : ℝ} (haccept : η ≤ equalityAcceptance f) : | |
| ∃ y : Vector ell, 0 < EqualityFiber.fiberMass matrixWeight f y ∧ | |
| η ≤ EqualityFiber.fiberFlow matrixWeight matrixKernel f y / | |
| EqualityFiber.fiberMass matrixWeight f y := by | |
| apply EqualityFiber.exists_fiber_retention matrixWeight matrixKernel | |
| (matrixWeight_probability ell m) matrixKernel_probability f | |
| rwa [← equalityAcceptance_eq_kernel] | |
| end | |
| end DFVSGames.Inverse.Shortcode | |
| namespace DFVSGames.Inverse.FactorSampling | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| open DFVSGames.Foundations.Information | |
| variable {A B : Type*} [Fintype A] [Fintype B] [Zero A] [Zero B] | |
| def fullAverage (p : A → ℝ) (q : B → ℝ) (h : A → B → ℝ) : ℝ := | |
| ∑ a, ∑ b, p a * q b * h a b | |
| def nonzeroFlow (p : A → ℝ) (q : B → ℝ) (h : A → B → ℝ) : ℝ := | |
| ∑ a, ∑ b, p a * q b * if a ≠ 0 ∧ b ≠ 0 then h a b else 0 | |
| def zeroMass (p : A → ℝ) (q : B → ℝ) : ℝ := | |
| p 0 + q 0 - p 0 * q 0 | |
| omit [Fintype A] [Fintype B] in | |
| private theorem boundary_indicator_inline_FactorSampling (a : A) (b : B) : | |
| (if a = 0 ∨ b = 0 then (1 : ℝ) else 0) = | |
| (if a = 0 then 1 else 0) + (if b = 0 then 1 else 0) - | |
| (if a = 0 then 1 else 0) * (if b = 0 then 1 else 0) := by | |
| by_cases ha : a = 0 <;> by_cases hb : b = 0 <;> simp [ha, hb] | |
| theorem boundary_mass (p : A → ℝ) (q : B → ℝ) | |
| (hp : IsProbability p) (hq : IsProbability q) : | |
| fullAverage p q (fun a b => if a = 0 ∨ b = 0 then 1 else 0) = zeroMass p q := by | |
| unfold fullAverage zeroMass | |
| simp_rw [boundary_indicator_inline_FactorSampling, mul_sub, mul_add] | |
| simp only [Finset.sum_sub_distrib, Finset.sum_add_distrib] | |
| have h₁ : (∑ a, ∑ b, p a * q b * if a = 0 then 1 else 0) = p 0 := by | |
| calc | |
| _ = ∑ a, p a * (∑ b, q b) * if a = 0 then 1 else 0 := by | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| rw [← Finset.sum_mul, ← Finset.mul_sum] | |
| _ = p 0 := by simp [hq.2, mul_ite] | |
| have h₂ : (∑ a, ∑ b, p a * q b * if b = 0 then 1 else 0) = q 0 := by | |
| simp only [mul_ite, mul_one, mul_zero, Finset.sum_ite_eq', Finset.mem_univ, ite_true] | |
| rw [← Finset.sum_mul, hp.2, one_mul] | |
| have h₃ : (∑ a, ∑ b, p a * q b * | |
| ((if a = 0 then 1 else 0) * (if b = 0 then 1 else 0))) = p 0 * q 0 := by | |
| simp [mul_ite] | |
| rw [h₁, h₂, h₃] | |
| theorem fullAverage_eq_zeroMass_add_nonzeroFlow (p : A → ℝ) (q : B → ℝ) | |
| (hp : IsProbability p) (hq : IsProbability q) (h : A → B → ℝ) | |
| (hleft : ∀ b, h 0 b = 1) (hright : ∀ a, h a 0 = 1) : | |
| fullAverage p q h = zeroMass p q + nonzeroFlow p q h := by | |
| have hpoint (a : A) (b : B) : h a b = | |
| (if a = 0 ∨ b = 0 then 1 else 0) + | |
| (if a ≠ 0 ∧ b ≠ 0 then h a b else 0) := by | |
| by_cases ha : a = 0 | |
| · subst a | |
| simp [hleft] | |
| · by_cases hb : b = 0 | |
| · subst b | |
| simp [hright] | |
| · simp [ha, hb] | |
| calc | |
| fullAverage p q h = | |
| fullAverage p q (fun a b => if a = 0 ∨ b = 0 then 1 else 0) + | |
| nonzeroFlow p q h := by | |
| unfold fullAverage nonzeroFlow | |
| simp only [← Finset.sum_add_distrib] | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| apply Finset.sum_congr rfl | |
| intro b _ | |
| simpa only [mul_add] using congrArg (fun z : ℝ => p a * q b * z) (hpoint a b) | |
| _ = _ := by rw [boundary_mass p q hp hq] | |
| def conditionedRetention (p : A → ℝ) (q : B → ℝ) (h : A → B → ℝ) : ℝ := | |
| nonzeroFlow p q h / (1 - zeroMass p q) | |
| theorem fullAverage_eq_mixture (p : A → ℝ) (q : B → ℝ) | |
| (hp : IsProbability p) (hq : IsProbability q) (h : A → B → ℝ) | |
| (hleft : ∀ b, h 0 b = 1) (hright : ∀ a, h a 0 = 1) | |
| (hzero : zeroMass p q < 1) : | |
| fullAverage p q h = zeroMass p q + | |
| (1 - zeroMass p q) * conditionedRetention p q h := by | |
| rw [fullAverage_eq_zeroMass_add_nonzeroFlow p q hp hq h hleft hright] | |
| unfold conditionedRetention | |
| have hne : 1 - zeroMass p q ≠ 0 := by linarith | |
| field_simp | |
| theorem conditionedRetention_ge_half (p : A → ℝ) (q : B → ℝ) | |
| (hp : IsProbability p) (hq : IsProbability q) (h : A → B → ℝ) | |
| (hleft : ∀ b, h 0 b = 1) (hright : ∀ a, h a 0 = 1) | |
| {η : ℝ} (hη : 0 < η) (hη1 : η < 1) | |
| (hzero : 0 ≤ zeroMass p q) (hzeroη : zeroMass p q ≤ η / 2) | |
| (haccept : η ≤ fullAverage p q h) : η / 2 ≤ conditionedRetention p q h := by | |
| apply EqualityFiber.nonzero_retention_ge_half hη hη1 hzero hzeroη | |
| rw [← fullAverage_eq_mixture p q hp hq h hleft hright (by linarith)] | |
| exact haccept | |
| omit [Fintype A] [Fintype B] in | |
| theorem zeroMass_binary_uniform (p : A → ℝ) (q : B → ℝ) (ell m : ℕ) | |
| (hp0 : p 0 = ((2 : ℝ) ^ ell)⁻¹) (hq0 : q 0 = ((2 : ℝ) ^ m)⁻¹) : | |
| zeroMass p q = ((2 : ℝ) ^ ell)⁻¹ + ((2 : ℝ) ^ m)⁻¹ - ((2 : ℝ) ^ (ell + m))⁻¹ := by | |
| unfold zeroMass | |
| rw [hp0, hq0, pow_add, mul_inv] | |
| end | |
| end DFVSGames.Inverse.FactorSampling | |
| namespace DFVSGames.Inverse.ShortcodeFromGrassmann | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| open Shortcode DFVSGames.Foundations.Information | |
| theorem matrixKernel_average {ell m : ℕ} (M : Mat ell m) (g : Mat ell m → ℝ) : | |
| (∑ N, matrixKernel M N * g N) = 𝔼 a, 𝔼 l, g (M + rankOne a l) := by | |
| simp only [matrixKernel, Finset.expect_mul] | |
| rw [← Finset.expect_sum_comm] | |
| apply Finset.expect_congr rfl | |
| intro a _ | |
| rw [← Finset.expect_sum_comm] | |
| apply Finset.expect_congr rfl | |
| intro l _ | |
| simp [ite_mul] | |
| theorem fiberMass_eq_card {ell m : ℕ} (f : Mat ell m → Vector ell) | |
| (y : Vector ell) : | |
| EqualityFiber.fiberMass matrixWeight f y = | |
| ((matrixFiber f y).card : ℝ) / Fintype.card (Mat ell m) := by | |
| unfold EqualityFiber.fiberMass | |
| calc | |
| _ = ∑ M ∈ matrixFiber f y, matrixWeight M := by | |
| rw [matrixFiber, Finset.sum_filter] | |
| apply Finset.sum_congr rfl | |
| intro M _ | |
| by_cases h : f M = y <;> simp [h] | |
| _ = _ := by simp [matrixWeight, div_eq_mul_inv] | |
| theorem fiberMass_pos_iff {ell m : ℕ} (f : Mat ell m → Vector ell) | |
| (y : Vector ell) : | |
| 0 < EqualityFiber.fiberMass matrixWeight f y ↔ (matrixFiber f y).Nonempty := by | |
| rw [fiberMass_eq_card] | |
| have hcard : (0 : ℝ) < Fintype.card (Mat ell m) := by | |
| exact_mod_cast Fintype.card_pos | |
| rw [div_pos_iff_of_pos_right hcard, Nat.cast_pos, Finset.card_pos] | |
| def fiberFactorRetention {ell m : ℕ} (f : Mat ell m → Vector ell) | |
| (y : Vector ell) (a : Vector ell) (l : Vector m) : ℝ := | |
| (matrixFiber f y).expect fun M => if f (M + rankOne a l) = y then 1 else 0 | |
| theorem fiberFlow_eq {ell m : ℕ} (f : Mat ell m → Vector ell) | |
| (y : Vector ell) : | |
| EqualityFiber.fiberFlow matrixWeight matrixKernel f y = | |
| (∑ M ∈ matrixFiber f y, | |
| 𝔼 a, 𝔼 l, if f (M + rankOne a l) = y then (1 : ℝ) else 0) / | |
| Fintype.card (Mat ell m) := by | |
| unfold EqualityFiber.fiberFlow | |
| simp_rw [matrixKernel_average] | |
| rw [div_eq_mul_inv, Finset.sum_mul] | |
| rw [matrixFiber, Finset.sum_filter] | |
| apply Finset.sum_congr rfl | |
| intro M _ | |
| by_cases h : f M = y | |
| · simp [h, matrixWeight, mul_comm] | |
| · simp [h] | |
| theorem fiber_retention_eq_factor_average {ell m : ℕ} | |
| (f : Mat ell m → Vector ell) (y : Vector ell) : | |
| EqualityFiber.fiberFlow matrixWeight matrixKernel f y / | |
| EqualityFiber.fiberMass matrixWeight f y = | |
| 𝔼 a, 𝔼 l, fiberFactorRetention f y a l := by | |
| rw [fiberFlow_eq, fiberMass_eq_card] | |
| have hcard : (Fintype.card (Mat ell m) : ℝ) ≠ 0 := by | |
| exact_mod_cast Fintype.card_ne_zero | |
| have hswap : (𝔼 a, 𝔼 l, fiberFactorRetention f y a l) = | |
| (matrixFiber f y).expect (fun M => | |
| 𝔼 a, 𝔼 l, if f (M + rankOne a l) = y then (1 : ℝ) else 0) := by | |
| unfold fiberFactorRetention | |
| calc | |
| _ = 𝔼 a, (matrixFiber f y).expect (fun M => | |
| 𝔼 l, if f (M + rankOne a l) = y then (1 : ℝ) else 0) := by | |
| apply Finset.expect_congr rfl | |
| intro a _ | |
| rw [Finset.expect_comm] | |
| _ = _ := Finset.expect_comm _ _ _ | |
| rw [hswap, Finset.expect_eq_sum_div_card] | |
| simp [div_div_div_cancel_right₀ hcard] | |
| theorem fiberFactorRetention_zero_left {ell m : ℕ} | |
| (f : Mat ell m → Vector ell) (y : Vector ell) | |
| (hne : (matrixFiber f y).Nonempty) (l : Vector m) : | |
| fiberFactorRetention f y 0 l = 1 := by | |
| unfold fiberFactorRetention | |
| have hpoint (M : Mat ell m) (hM : M ∈ matrixFiber f y) : | |
| (if f (M + rankOne (0 : Vector ell) l) = y then (1 : ℝ) else 0) = 1 := by | |
| have hy := (Finset.mem_filter.mp hM).2 | |
| simp [hy] | |
| rw [Finset.expect_congr rfl hpoint, Finset.expect_const hne] | |
| theorem fiberFactorRetention_zero_right {ell m : ℕ} | |
| (f : Mat ell m → Vector ell) (y : Vector ell) | |
| (hne : (matrixFiber f y).Nonempty) (a : Vector ell) : | |
| fiberFactorRetention f y a 0 = 1 := by | |
| unfold fiberFactorRetention | |
| have hpoint (M : Mat ell m) (hM : M ∈ matrixFiber f y) : | |
| (if f (M + rankOne a (0 : Vector m)) = y then (1 : ℝ) else 0) = 1 := by | |
| have hy := (Finset.mem_filter.mp hM).2 | |
| simp [hy] | |
| rw [Finset.expect_congr rfl hpoint, Finset.expect_const hne] | |
| theorem exists_output_fiber_factor_retention {ell m : ℕ} | |
| (f : Mat ell m → Vector ell) {η : ℝ} (haccept : η ≤ equalityAcceptance f) : | |
| ∃ y, (matrixFiber f y).Nonempty ∧ η ≤ 𝔼 a, 𝔼 l, fiberFactorRetention f y a l := by | |
| obtain ⟨y, hy, hret⟩ := Shortcode.exists_output_fiber f haccept | |
| exact ⟨y, (fiberMass_pos_iff f y).mp hy, | |
| by simpa only [fiber_retention_eq_factor_average] using hret⟩ | |
| end | |
| end DFVSGames.Inverse.ShortcodeFromGrassmann | |
| namespace DFVSGames.Inverse.ShortcodeFromGrassmann | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| open Shortcode | |
| theorem uniform_pair_mixture {A B : Type*} [Fintype A] [Fintype B] | |
| [Zero A] [Zero B] (h : A → B → ℝ) | |
| (hleft : ∀ b, h 0 b = 1) (hright : ∀ a, h a 0 = 1) : | |
| (𝔼 a, 𝔼 b, h a b) = | |
| (Fintype.card A : ℝ)⁻¹ + (Fintype.card B : ℝ)⁻¹ - | |
| (Fintype.card A : ℝ)⁻¹ * (Fintype.card B : ℝ)⁻¹ + | |
| (1 - ((Fintype.card A : ℝ)⁻¹ + (Fintype.card B : ℝ)⁻¹ - | |
| (Fintype.card A : ℝ)⁻¹ * (Fintype.card B : ℝ)⁻¹)) * | |
| (𝔼 p : {a : A // a ≠ 0} × {b : B // b ≠ 0}, h p.1.val p.2.val) := by | |
| let R : ℝ := 𝔼 p : {a : A // a ≠ 0} × {b : B // b ≠ 0}, | |
| h p.1.val p.2.val | |
| have : Nonempty A := ⟨0⟩ | |
| have : Nonempty B := ⟨0⟩ | |
| have hA : (Fintype.card A : ℝ) ≠ 0 := by | |
| exact_mod_cast Fintype.card_ne_zero | |
| have hB : (Fintype.card B : ℝ) ≠ 0 := by | |
| exact_mod_cast Fintype.card_ne_zero | |
| have hNA : (Fintype.card {a : A // a ≠ 0} : ℝ) = | |
| (Fintype.card A : ℝ) - 1 := by | |
| have hs := Fintype.sum_eq_add_sum_subtype_ne (fun _ : A => (1 : ℝ)) 0 | |
| simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one] at hs | |
| linarith | |
| have hNB : (Fintype.card {b : B // b ≠ 0} : ℝ) = | |
| (Fintype.card B : ℝ) - 1 := by | |
| have hs := Fintype.sum_eq_add_sum_subtype_ne (fun _ : B => (1 : ℝ)) 0 | |
| simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one] at hs | |
| linarith | |
| have hNZ : (∑ a : {a : A // a ≠ 0}, ∑ b : {b : B // b ≠ 0}, h a.val b.val) = | |
| (Fintype.card {a : A // a ≠ 0} : ℝ) * | |
| (Fintype.card {b : B // b ≠ 0} : ℝ) * R := by | |
| simpa only [Fintype.card_prod, Nat.cast_mul, Fintype.sum_prod_type] using | |
| (Fintype.card_mul_expect | |
| (fun p : {a : A // a ≠ 0} × {b : B // b ≠ 0} => h p.1.val p.2.val)).symm | |
| have hinner (a : A) : (∑ b : B, h a b) = | |
| 1 + ∑ b : {b : B // b ≠ 0}, h a b.val := by | |
| rw [Fintype.sum_eq_add_sum_subtype_ne _ 0, hright] | |
| have hsum : (∑ a : A, ∑ b : B, h a b) = | |
| (Fintype.card B : ℝ) + (Fintype.card {a : A // a ≠ 0} : ℝ) + | |
| (Fintype.card {a : A // a ≠ 0} : ℝ) * | |
| (Fintype.card {b : B // b ≠ 0} : ℝ) * R := by | |
| rw [Fintype.sum_eq_add_sum_subtype_ne (fun a : A => ∑ b : B, h a b) 0] | |
| simp only [hleft, Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one] | |
| simp_rw [hinner] | |
| rw [Finset.sum_add_distrib, hNZ] | |
| simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul, mul_one] | |
| ring | |
| have hfull : (Fintype.card A : ℝ) * (Fintype.card B : ℝ) * | |
| (𝔼 a, 𝔼 b, h a b) = ∑ a, ∑ b, h a b := by | |
| calc | |
| _ = (Fintype.card B : ℝ) * | |
| ((Fintype.card A : ℝ) * (𝔼 a, 𝔼 b, h a b)) := by ring | |
| _ = (Fintype.card B : ℝ) * (∑ a, 𝔼 b, h a b) := by | |
| rw [Fintype.card_mul_expect] | |
| _ = _ := by | |
| rw [Finset.mul_sum] | |
| simp_rw [Fintype.card_mul_expect] | |
| have hbalance : (Fintype.card A : ℝ) * (Fintype.card B : ℝ) * | |
| (𝔼 a, 𝔼 b, h a b) = | |
| (Fintype.card A : ℝ) + (Fintype.card B : ℝ) - 1 + | |
| ((Fintype.card A : ℝ) - 1) * ((Fintype.card B : ℝ) - 1) * R := by | |
| rw [hfull, hsum, hNA, hNB] | |
| ring | |
| apply mul_left_cancel₀ (mul_ne_zero hA hB) | |
| rw [hbalance] | |
| change _ = (Fintype.card A : ℝ) * (Fintype.card B : ℝ) * | |
| ((Fintype.card A : ℝ)⁻¹ + (Fintype.card B : ℝ)⁻¹ - | |
| (Fintype.card A : ℝ)⁻¹ * (Fintype.card B : ℝ)⁻¹ + | |
| (1 - ((Fintype.card A : ℝ)⁻¹ + (Fintype.card B : ℝ)⁻¹ - | |
| (Fintype.card A : ℝ)⁻¹ * (Fintype.card B : ℝ)⁻¹)) * R) | |
| field_simp [hA, hB] | |
| ring | |
| private theorem vector_card_real_inline_ShortcodeFiberConditioning (n : ℕ) : | |
| (Fintype.card (Vector n) : ℝ) = (2 : ℝ) ^ n := by | |
| simp [Shortcode.Vector, F2] | |
| private theorem binary_zero_mass_nonneg_inline_ShortcodeFiberConditioning (ell m : ℕ) : | |
| 0 ≤ ((2 : ℝ) ^ ell)⁻¹ + ((2 : ℝ) ^ m)⁻¹ - | |
| ((2 : ℝ) ^ (ell + m))⁻¹ := by | |
| have ha : 0 ≤ ((2 : ℝ) ^ ell)⁻¹ := by positivity | |
| have hb : 0 ≤ ((2 : ℝ) ^ m)⁻¹ := by positivity | |
| have hb1 : ((2 : ℝ) ^ m)⁻¹ ≤ 1 := | |
| inv_le_one_of_one_le₀ (one_le_pow₀ (by norm_num)) | |
| rw [pow_add, mul_inv] | |
| nlinarith [mul_nonneg ha (sub_nonneg.mpr hb1)] | |
| theorem conditioned_output_fiber {ell m : ℕ} | |
| (f : Mat ell m → Vector ell) {η : ℝ} (hη : 0 < η) (hη1 : η < 1) | |
| (hzero : ((2 : ℝ) ^ ell)⁻¹ + ((2 : ℝ) ^ m)⁻¹ - | |
| ((2 : ℝ) ^ (ell + m))⁻¹ ≤ η / 2) | |
| (haccept : η ≤ equalityAcceptance f) : | |
| ∃ y, (matrixFiber f y).Nonempty ∧ | |
| η / 2 ≤ (matrixFiber f y).expect (fun M => | |
| 𝔼 p : {a : Vector ell // a ≠ 0} × {l : Vector m // l ≠ 0}, | |
| if f (M + rankOne p.1.val p.2.val) = y then (1 : ℝ) else 0) := by | |
| obtain ⟨y, hy, hret⟩ := exists_output_fiber_factor_retention f haccept | |
| refine ⟨y, hy, ?_⟩ | |
| have hmix := uniform_pair_mixture (fiberFactorRetention f y) | |
| (fiberFactorRetention_zero_left f y hy) (fiberFactorRetention_zero_right f y hy) | |
| simp only [vector_card_real_inline_ShortcodeFiberConditioning, ← mul_inv, ← pow_add] at hmix | |
| have hconditioned := EqualityFiber.nonzero_retention_ge_half hη hη1 | |
| (binary_zero_mass_nonneg_inline_ShortcodeFiberConditioning ell m) hzero (hmix ▸ hret) | |
| apply hconditioned.trans | |
| apply le_of_eq | |
| unfold fiberFactorRetention | |
| rw [Finset.expect_comm] | |
| apply Finset.expect_congr rfl | |
| intro M _ | |
| apply Finset.expect_congr (by ext p; simp) | |
| intro p _ | |
| rfl | |
| end | |
| end DFVSGames.Inverse.ShortcodeFromGrassmann | |
| namespace DFVSGames.Inverse.ShortcodeFromGrassmann | |
| noncomputable section | |
| open scoped BigOperators Classical | |
| open Shortcode MatrixChart | |
| theorem chartFiberRetention : ChartFiberRetention := by | |
| intro ell m _hell _hm η hη hη1 hzero f haccept | |
| obtain ⟨y, hnonempty, hretention⟩ := | |
| conditioned_output_fiber f hη hη1 hzero haccept | |
| refine ⟨y, ?_, ?_⟩ | |
| · exact Finset.image_nonempty.mpr hnonempty | |
| · rw [liftedFiber_retention_eq_half] | |
| have h : η / 2 ≤ (𝔼 M ∈ matrixFiber f y, 𝔼 p : NonzeroVectorFactors ell m, | |
| if f (M + rankOne p.1.val p.2.val) = y then (1 : ℝ) else 0) := hretention | |
| linarith | |
| theorem inversePrinciple_of_expansion (hKMS : KMS.ExpansionPrinciple) : | |
| Shortcode.InversePrinciple := | |
| inversePrinciple_of_expansion_and_chart hKMS chartFiberRetention | |
| end | |
| end DFVSGames.Inverse.ShortcodeFromGrassmann | |
| namespace DFVSGames.Inverse.ShortcodeTheorem | |
| noncomputable section | |
| theorem inversePrinciple : Shortcode.InversePrinciple := | |
| ShortcodeFromGrassmann.inversePrinciple_of_expansion KMSExpansion.kms_expansion | |
| end | |
| end DFVSGames.Inverse.ShortcodeTheorem | |
| namespace DFVSGames.Decoder.MatrixGap | |
| theorem exists_parameters (p : ℚ) (hp : 0 < p) : Nonempty (Parameters p) := | |
| parameters_of_inverse Inverse.ShortcodeTheorem.inversePrinciple p hp | |
| end DFVSGames.Decoder.MatrixGap | |
| end OAI | |
Xet Storage Details
- Size:
- 28.6 kB
- Xet hash:
- f2f11ebe8d8d757cb2b588488d234264c8c8a89e8b7c2c348af439c32c1aa242
·
Xet efficiently stores files, intelligently splitting them into unique chunks and accelerating uploads and downloads. More info.