introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
36.5 kB
import Mathlib
import OAI.Computability.DirectedFeedback.Probability.DescentProbability
namespace OAI
namespace DFVSGames.Gadget.Enlargement
open scoped BigOperators Classical
noncomputable section
def probability {Ξ© : Type*} [Fintype Ξ©] (p : Ξ© β†’ Prop) : β„š :=
(Nat.card {x : Ξ© // p x} : β„š) / (Nat.card Ξ© : β„š)
theorem probability_exists_le_sum {Ξ© I : Type*} [Fintype Ξ©] [Fintype I]
(p : I β†’ Ξ© β†’ Prop) :
probability (fun x => βˆƒ i, p i x) ≀ βˆ‘ i, probability (p i) := by
classical
have heq : (Finset.univ.filter fun x => βˆƒ i, p i x) =
Finset.univ.biUnion (fun i => Finset.univ.filter (p i)) := by
ext x
simp
unfold probability
simp only [Nat.card_eq_fintype_card, Fintype.card_subtype]
rw [heq, ← Finset.sum_div]
apply div_le_div_of_nonneg_right _ (Nat.cast_nonneg _)
exact_mod_cast (Finset.card_biUnion_le (s := (Finset.univ : Finset I))
(t := fun i => Finset.univ.filter (p i)))
theorem probability_preimage_of_fibers {Ξ© T : Type*} [Fintype Ξ©] [Fintype T]
[Nonempty Ξ©] [Nonempty T] (f : Ξ© β†’ T)
(hf : βˆ€ x y : T, Nat.card {a : Ξ© // f a = x} = Nat.card {a : Ξ© // f a = y})
(p : T β†’ Prop) : probability (fun a => p (f a)) = probability p := by
classical
let tβ‚€ : T := Classical.choice inferInstance
let c := (Finset.univ.filter fun a => f a = tβ‚€).card
have hfc (x : T) : (Finset.univ.filter fun a => f a = x).card = c := by
simpa only [Nat.card_eq_fintype_card, Fintype.card_subtype] using hf x tβ‚€
have hΞ© : Fintype.card Ξ© = Fintype.card T * c := by
calc
Fintype.card Ξ© = βˆ‘ t : T, (Finset.univ.filter fun a => f a = t).card :=
Finset.card_eq_sum_card_fiberwise (fun _ _ => Finset.mem_univ _)
_ = Fintype.card T * c := by simp_rw [hfc]; simp
have hp : (Finset.univ.filter fun a => p (f a)).card =
(Finset.univ.filter p).card * c := by
calc
_ = βˆ‘ t ∈ Finset.univ.filter p,
(Finset.univ.filter fun a => f a = t).card := by
symm
simpa using Finset.sum_card_fiberwise_eq_card_filter
(Finset.univ : Finset Ξ©) (Finset.univ.filter p) f
_ = _ := by simp_rw [hfc]; simp
have hc : (c : β„š) β‰  0 := by
have : c β‰  0 := by
intro hc
have := Fintype.card_pos (Ξ± := Ξ©)
simp [hc] at hΞ©
exact_mod_cast this
unfold probability
simp only [Nat.card_eq_fintype_card, Fintype.card_subtype]
rw [hp, hΞ©]
push_cast
exact mul_div_mul_right _ _ hc
theorem exists_equiv_map_nonzero {F V : Type*} [Field F]
[AddCommGroup V] [Module F V] (x y : V) (hx : x β‰  0) (hy : y β‰  0) :
βˆƒ e : V ≃ₗ[F] V, e x = y := by
let ex := LinearEquiv.toSpanNonzeroSingleton F V x hx
let ey := LinearEquiv.toSpanNonzeroSingleton F V y hy
obtain ⟨e, he⟩ := Submodule.exists_linearEquiv_restrict_eq (ex.symm.trans ey)
refine ⟨e, ?_⟩
have h := (he (ex 1)).symm
simp only [LinearEquiv.trans_apply, LinearEquiv.symm_apply_apply] at h
simpa [ex, ey] using h
abbrev LinearInjection (F B K : Type*) [Field F] [AddCommGroup B]
[Module F B] [AddCommGroup K] [Module F K] :=
{L : B β†’β‚—[F] K // Function.Injective L}
theorem linearInjection_nonempty_of_finrank_le {F B K : Type*} [Field F]
[AddCommGroup B] [Module F B] [FiniteDimensional F B]
[AddCommGroup K] [Module F K] [FiniteDimensional F K]
(h : Module.finrank F B ≀ Module.finrank F K) :
Nonempty (LinearInjection F B K) := by
obtain ⟨L, hL⟩ := finrank_le_iff_exists_linearMap.mp h
exact ⟨⟨L, hL⟩⟩
def postcompose {F B K : Type*} [Field F] [AddCommGroup B] [Module F B]
[AddCommGroup K] [Module F K] (e : K ≃ₗ[F] K) :
LinearInjection F B K ≃ LinearInjection F B K where
toFun L := ⟨e.toLinearMap.comp L.1, e.injective.comp L.2⟩
invFun L := ⟨e.symm.toLinearMap.comp L.1, e.symm.injective.comp L.2⟩
left_inv L := by
apply Subtype.ext
ext x
exact e.symm_apply_apply (L.1 x)
right_inv L := by
apply Subtype.ext
ext x
exact e.apply_symm_apply (L.1 x)
theorem injection_eval_ne_zero {F B K : Type*} [Field F] [AddCommGroup B]
[Module F B] [AddCommGroup K] [Module F K]
(L : LinearInjection F B K) {b : B} (hb : b β‰  0) : L.1 b β‰  0 := by
intro h
apply hb
apply L.2
simpa using h
theorem exists_injection_hitting_nonzero {F B K : Type*} [Field F]
[AddCommGroup B] [Module F B] [FiniteDimensional F B]
[AddCommGroup K] [Module F K] [FiniteDimensional F K]
(h : Module.finrank F B ≀ Module.finrank F K)
(b : B) (hb : b β‰  0) (x : K) (hx : x β‰  0) :
βˆƒ L : LinearInjection F B K, L.1 b = x := by
obtain ⟨L⟩ := linearInjection_nonempty_of_finrank_le h
obtain ⟨e, he⟩ := exists_equiv_map_nonzero (F := F) (L.1 b) x
(injection_eval_ne_zero L hb) hx
exact ⟨postcompose e L, he⟩
def productShift {F B K : Type*} [Field F] [AddCommGroup B] [Module F B]
[AddCommGroup K] [Module F K] [Fintype (LinearInjection F B K)] :
(LinearInjection F B K β†’ B) β†’β‚—[F] K where
toFun b := βˆ‘ L : LinearInjection F B K, L.1 (b L)
map_add' b c := by simp [map_add, Finset.sum_add_distrib]
map_smul' t b := by simp [map_smul, Finset.smul_sum]
theorem productShift_surjective {F B K : Type*} [Field F]
[AddCommGroup B] [Module F B] [FiniteDimensional F B]
[AddCommGroup K] [Module F K] [FiniteDimensional F K]
[Fintype (LinearInjection F B K)]
(h : Module.finrank F B ≀ Module.finrank F K)
(b : B) (hb : b β‰  0) :
Function.Surjective (productShift (F := F) (B := B) (K := K)) := by
intro x
by_cases hx : x = 0
Β· subst x
exact ⟨0, map_zero _⟩
· obtain ⟨L, hL⟩ := exists_injection_hitting_nonzero h b hb x hx
refine ⟨fun L' => if L' = L then b else 0, ?_⟩
simpa [productShift, apply_ite] using hL
def enlargedOutput {F B K V : Type*} [Field F]
[AddCommGroup B] [Module F B] [AddCommGroup K] [Module F K]
[Fintype (LinearInjection F B K)] (C : V β†’ B)
(x : LinearInjection F B K β†’ V) : K := βˆ‘ L : LinearInjection F B K, L.1 (C (x L))
theorem enlargedOutput_shift {F B K V : Type*} [Field F]
[AddCommGroup B] [Module F B] [AddCommGroup K] [Module F K]
[AddCommGroup V] [Module F V] [Fintype (LinearInjection F B K)]
(C : V β†’ B) (i : B β†’β‚—[F] V)
(hC : βˆ€ x b, C (x + i b) = C x + b)
(x : LinearInjection F B K β†’ V) (b : LinearInjection F B K β†’ B) :
enlargedOutput C (fun L => x L + i (b L)) =
enlargedOutput C x + productShift b := by
simp [enlargedOutput, productShift, hC, map_add, Finset.sum_add_distrib]
theorem enlargedOutput_update {F B K V : Type*} [Field F]
[AddCommGroup B] [Module F B] [AddCommGroup K] [Module F K]
[Fintype (LinearInjection F B K)] (C : V β†’ B)
(x : LinearInjection F B K β†’ V) (L : LinearInjection F B K) (y : V) :
enlargedOutput C (Function.update x L y) =
enlargedOutput C x + L.1 (C y - C (x L)) := by
classical
have hfun : (fun J => J.1 (C (Function.update x L y J))) =
Function.update (fun J : LinearInjection F B K => J.1 (C (x J))) L (L.1 (C y)) := by
funext J
by_cases h : J = L
Β· subst J
simp
Β· simp [h]
unfold enlargedOutput
rw [hfun, Finset.sum_update_of_mem (Finset.mem_univ L)]
rw [Finset.sum_eq_add_sum_sdiff_singleton_of_mem (Finset.mem_univ L)]
rw [map_sub]
abel
theorem enlargedOutput_update_ne_iff {F B K V : Type*} [Field F]
[AddCommGroup B] [Module F B] [AddCommGroup K] [Module F K]
[Fintype (LinearInjection F B K)] (C : V β†’ B)
(x : LinearInjection F B K β†’ V) (L : LinearInjection F B K) (y : V) :
enlargedOutput C (Function.update x L y) β‰  enlargedOutput C x ↔ C y β‰  C (x L) := by
rw [enlargedOutput_update, ne_eq, add_eq_left, map_eq_zero_iff _ L.2,
sub_eq_zero, ne_eq]
theorem injection_eval_uniform {F B K : Type*} [Field F] [AddCommGroup B]
[Module F B] [AddCommGroup K] [Module F K]
[Fintype K] [Fintype (LinearInjection F B K)]
[Nonempty (LinearInjection F B K)] (b : B) (hb : b β‰  0)
(p : {x : K // x β‰  0} β†’ Prop) :
probability (fun L : LinearInjection F B K =>
p ⟨L.1 b, injection_eval_ne_zero L hb⟩) = probability p := by
classical
let : Nonempty {x : K // x β‰  0} :=
⟨⟨(Classical.choice inferInstance : LinearInjection F B K).1 b,
injection_eval_ne_zero _ hb⟩⟩
let f : LinearInjection F B K β†’ {x : K // x β‰  0} :=
fun L => ⟨L.1 b, injection_eval_ne_zero L hb⟩
apply probability_preimage_of_fibers f
intro x y
obtain ⟨e, he⟩ := exists_equiv_map_nonzero (F := F) x.1 y.1 x.2 y.2
let ee : {L : LinearInjection F B K // f L = x} ≃
{L : LinearInjection F B K // f L = y} :=
(postcompose e).subtypeEquiv (fun L => by
change f L = x ↔ f (postcompose e L) = y
constructor
Β· intro h
apply Subtype.ext
change e (L.1 b) = y.1
rw [show L.1 b = x.1 from congrArg Subtype.val h, he]
Β· intro h
apply Subtype.ext
apply e.injective
exact (congrArg Subtype.val h).trans he.symm)
exact Nat.card_congr ee
theorem pullback_ne_top_iff {F B K : Type*} [Field F] [AddCommGroup B]
[Module F B] [FiniteDimensional F B] [AddCommGroup K] [Module F K]
(L : B β†’β‚—[F] K) (S : Submodule F (Module.Dual F K)) :
S.map L.dualMap β‰  ⊀ ↔ βˆƒ b : B, b β‰  0 ∧ L b ∈ S.dualCoannihilator := by
let W := S.map L.dualMap
have hann : W.dualCoannihilator = S.dualCoannihilator.comap L := by
ext b
simp only [Submodule.mem_dualCoannihilator, Submodule.mem_comap,
]
constructor
Β· intro h z hz
exact h (z.comp L) ⟨z, hz, rfl⟩
· intro h z ⟨w, hw, hwz⟩
subst z
exact h w hw
constructor
Β· intro hW
have hn : W.dualCoannihilator β‰  βŠ₯ := by
intro hz
have hh := Subspace.dualCoannihilator_dualAnnihilator_eq (W := W)
rw [hz, Submodule.dualAnnihilator_bot] at hh
exact hW hh.symm
obtain ⟨b, hb, hb0⟩ := (Submodule.ne_bot_iff _).1 hn
exact ⟨b, hb0, by simpa [hann] using hb⟩
· rintro ⟨b, hb0, hb⟩ htop
have hz : b ∈ W.dualCoannihilator := by simpa [hann] using hb
change b ∈ (S.map L.dualMap).dualCoannihilator at hz
rw [htop] at hz
have hall : βˆ€ z : Module.Dual F B, z b = 0 := by
simpa only [Submodule.mem_dualCoannihilator, Submodule.mem_top,
forall_true_left] using hz
obtain ⟨z, hz'⟩ := Module.Projective.exists_dual_ne_zero F hb0
exact hz' (hall z)
theorem nonzero_density_le (d r : β„•) (h : 0 < d + r) :
((2 : β„š) ^ d - 1) / ((2 : β„š) ^ (d + r) - 1) ≀ 1 / (2 : β„š) ^ r := by
have hpow : 1 < (2 : β„š) ^ (d + r) := one_lt_powβ‚€ (by norm_num) (by omega)
have hr : (1 : β„š) ≀ 2 ^ r := one_le_powβ‚€ (by norm_num)
rw [div_le_div_iffβ‚€ (by linarith) (by positivity)]
rw [pow_add]
nlinarith
theorem card_nonzero_binary (K : Type*) [AddCommGroup K] [Module (ZMod 2) K]
[Fintype K] :
Nat.card {x : K // x β‰  0} = 2 ^ Module.finrank (ZMod 2) K - 1 := by
rw [Nat.card_eq_fintype_card]
rw [Fintype.card_subtype_compl (fun x : K => x = 0), Fintype.card_subtype_eq]
rw [Module.card_eq_pow_finrank (K := ZMod 2), ZMod.card]
theorem probability_nonzero_subspace (K : Type*) [AddCommGroup K]
[Module (ZMod 2) K] [Fintype K] (W : Submodule (ZMod 2) K) :
probability (fun x : {x : K // x β‰  0} => x.1 ∈ W) =
((2 : β„š) ^ Module.finrank (ZMod 2) W - 1) /
((2 : β„š) ^ Module.finrank (ZMod 2) K - 1) := by
classical
let : Fintype W := Fintype.ofFinite _
let e : {x : {x : K // x β‰  0} // x.1 ∈ W} ≃ {x : W // x β‰  0} :=
{ toFun := fun x => ⟨⟨x.1.1, x.2⟩, by
intro h
exact x.1.2 (congrArg Subtype.val h)⟩
invFun := fun x => ⟨⟨x.1.1, by
intro h
apply x.2
exact Subtype.ext h⟩, x.1.2⟩
left_inv := fun _ => rfl
right_inv := fun _ => rfl }
unfold probability
rw [Nat.card_congr e,
card_nonzero_binary W, card_nonzero_binary K]
rw [Nat.cast_sub (Nat.one_le_pow _ _ (by decide)),
Nat.cast_sub (Nat.one_le_pow _ _ (by decide))]
push_cast ; rfl
theorem probability_annihilator_le (K : Type*) [AddCommGroup K]
[Module (ZMod 2) K] [Fintype K] [FiniteDimensional (ZMod 2) K]
(S : Submodule (ZMod 2) (Module.Dual (ZMod 2) K))
(hK : 0 < Module.finrank (ZMod 2) K) :
probability (fun x : {x : K // x β‰  0} => x.1 ∈ S.dualCoannihilator) ≀
1 / (2 : β„š) ^ Module.finrank (ZMod 2) S := by
rw [probability_nonzero_subspace]
have hr := Subspace.finrank_add_finrank_dualCoannihilator_eq S
rw [← hr, add_comm (Module.finrank (ZMod 2) S)]
apply nonzero_density_le
omega
theorem union_bound_le_quarter (b r : β„•) (hr : b + 2 ≀ r) :
((2 : β„š) ^ b - 1) / (2 : β„š) ^ r ≀ 1 / 4 := by
have hpow : (2 : β„š) ^ (b + 2) ≀ (2 : β„š) ^ r :=
pow_le_pow_rightβ‚€ (by norm_num) hr
rw [pow_add] at hpow
norm_num at hpow
apply (div_le_iffβ‚€ (by positivity : (0 : β„š) < 2 ^ r)).2
nlinarith [show (0 : β„š) ≀ 2 ^ b by positivity]
theorem pullback_failure_probability_le {B K : Type*}
[AddCommGroup B] [Module (ZMod 2) B] [Fintype B]
[FiniteDimensional (ZMod 2) B]
[AddCommGroup K] [Module (ZMod 2) K] [Fintype K]
[FiniteDimensional (ZMod 2) K]
[Fintype (LinearInjection (ZMod 2) B K)]
[Nonempty (LinearInjection (ZMod 2) B K)]
(S : Submodule (ZMod 2) (Module.Dual (ZMod 2) K))
(hK : 0 < Module.finrank (ZMod 2) K) :
probability (fun L : LinearInjection (ZMod 2) B K => S.map L.1.dualMap β‰  ⊀) ≀
((2 : β„š) ^ Module.finrank (ZMod 2) B - 1) /
(2 : β„š) ^ Module.finrank (ZMod 2) S := by
classical
calc
_ = probability (fun L : LinearInjection (ZMod 2) B K =>
βˆƒ b : {b : B // b β‰  0}, L.1 b.1 ∈ S.dualCoannihilator) := by
congr 1
funext L
apply propext
rw [pullback_ne_top_iff]
exact ⟨fun ⟨b, hb, h⟩ => ⟨⟨b, hb⟩, h⟩,
fun ⟨b, h⟩ => ⟨b.1, b.2, h⟩⟩
_ ≀ βˆ‘ b : {b : B // b β‰  0}, probability
(fun L : LinearInjection (ZMod 2) B K => L.1 b.1 ∈ S.dualCoannihilator) :=
probability_exists_le_sum _
_ ≀ βˆ‘ _b : {b : B // b β‰  0},
1 / (2 : β„š) ^ Module.finrank (ZMod 2) S := by
apply Finset.sum_le_sum
intro b _
rw [injection_eval_uniform b.1 b.2
(fun x : {x : K // x β‰  0} => x.1 ∈ S.dualCoannihilator)]
exact probability_annihilator_le K S hK
_ = _ := by
simp only [Finset.sum_const, Finset.card_univ, nsmul_eq_mul]
rw [← Nat.card_eq_fintype_card, card_nonzero_binary B,
Nat.cast_sub (Nat.one_le_pow _ _ (by decide))]
push_cast
ring
theorem pullback_failure_probability_le_quarter {B K : Type*}
[AddCommGroup B] [Module (ZMod 2) B] [Fintype B]
[FiniteDimensional (ZMod 2) B]
[AddCommGroup K] [Module (ZMod 2) K] [Fintype K]
[FiniteDimensional (ZMod 2) K]
[Fintype (LinearInjection (ZMod 2) B K)]
[Nonempty (LinearInjection (ZMod 2) B K)]
(S : Submodule (ZMod 2) (Module.Dual (ZMod 2) K))
(hr : Module.finrank (ZMod 2) B + 2 ≀ Module.finrank (ZMod 2) S) :
probability (fun L : LinearInjection (ZMod 2) B K => S.map L.1.dualMap β‰  ⊀) ≀
1 / 4 := by
have hdim := Subspace.finrank_add_finrank_dualCoannihilator_eq S
exact (pullback_failure_probability_le S (by omega)).trans
(union_bound_le_quarter _ _ hr)
theorem probability_not {Ξ© : Type*} [Fintype Ξ©] [Nonempty Ξ©]
(p : Ξ© β†’ Prop) : probability (fun x => Β¬ p x) = 1 - probability p := by
classical
have h := Finset.card_filter_add_card_filter_not (s := (Finset.univ : Finset Ξ©)) p
have h' : ((Finset.univ.filter p).card : β„š) +
((Finset.univ.filter fun x => Β¬p x).card : β„š) = Fintype.card Ξ© := by
exact_mod_cast h
have hcard : (Fintype.card Ξ© : β„š) β‰  0 := by
exact_mod_cast Fintype.card_ne_zero
unfold probability
simp only [Nat.card_eq_fintype_card, Fintype.card_subtype]
apply (eq_sub_iff_add_eq).2
rw [← add_div, add_comm, h', div_self hcard]
theorem average_detection_lower_bound {Ξ© : Type*} [Fintype Ξ©] [Nonempty Ξ©]
(bad : Ξ© β†’ Prop) (detected : Ξ© β†’ β„š)
(hnonneg : βˆ€ x, 0 ≀ detected x)
(hgood : βˆ€ x, Β¬bad x β†’ 1 / 4 ≀ detected x) :
(1 - probability bad) * (1 / 4) ≀
(βˆ‘ x, detected x) / (Fintype.card Ξ© : β„š) := by
classical
have hs : βˆ‘ x : Ξ©, (if bad x then (0 : β„š) else 1 / 4) ≀ βˆ‘ x, detected x := by
apply Finset.sum_le_sum
intro x _
by_cases hx : bad x
Β· simpa [hx] using hnonneg x
Β· simpa [hx] using hgood x hx
have heq : βˆ‘ x : Ξ©, (if bad x then (0 : β„š) else 1 / 4) =
((Finset.univ.filter fun x => Β¬bad x).card : β„š) * (1 / 4) := by
rw [Finset.sum_ite]
simp
rw [heq] at hs
have hd := div_le_div_of_nonneg_right hs (Nat.cast_nonneg (Fintype.card Ξ©) :
(0 : β„š) ≀ Fintype.card Ξ©)
rw [← probability_not]
unfold probability
simp only [Nat.card_eq_fintype_card, Fintype.card_subtype]
simpa only [div_mul_eq_mul_div] using hd
theorem detection_constants {bad detected : β„š} (hbad : bad ≀ 1 / 4)
(hdetected : (1 - bad) * (1 / 4) ≀ detected) :
3 / 16 ≀ detected ∧ 1 / 8 ≀ detected := by
constructor <;> linarith
theorem enlarged_detection {B K : Type*}
[AddCommGroup B] [Module (ZMod 2) B] [Fintype B]
[FiniteDimensional (ZMod 2) B]
[AddCommGroup K] [Module (ZMod 2) K] [Fintype K]
[FiniteDimensional (ZMod 2) K]
[Fintype (LinearInjection (ZMod 2) B K)]
[Nonempty (LinearInjection (ZMod 2) B K)]
(S : Submodule (ZMod 2) (Module.Dual (ZMod 2) K))
(hr : Module.finrank (ZMod 2) B + 2 ≀ Module.finrank (ZMod 2) S)
(detected : LinearInjection (ZMod 2) B K β†’ β„š)
(hnonneg : βˆ€ L, 0 ≀ detected L)
(hbase : βˆ€ L, S.map L.1.dualMap = ⊀ β†’ 1 / 4 ≀ detected L) :
3 / 16 ≀ (βˆ‘ L, detected L) / (Fintype.card (LinearInjection (ZMod 2) B K) : β„š) ∧
1 / 8 ≀ (βˆ‘ L, detected L) / (Fintype.card (LinearInjection (ZMod 2) B K) : β„š) := by
apply detection_constants (pullback_failure_probability_le_quarter S hr)
apply average_detection_lower_bound _ detected hnonneg
intro L hL
exact hbase L (not_not.mp hL)
end
end DFVSGames.Gadget.Enlargement
noncomputable section
namespace DFVSGames.Gadget.EnlargementConstruction
open scoped BigOperators Classical
open Enlargement
theorem probability_equiv {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ]
(e : Ξ© ≃ Ξ) (p : Ξ β†’ Prop) :
probability (fun x : Ξ© => p (e x)) = probability p := by
classical
unfold probability
rw [Nat.card_congr (Equiv.subtypeEquivOfSubtype (p := p) e), Nat.card_congr e]
theorem probability_eq_sum_indicator {Ξ© : Type*} [Fintype Ξ©]
(p : Ξ© β†’ Prop) :
probability p =
(βˆ‘ x : Ξ©, if p x then (1 : β„š) else 0) / (Fintype.card Ξ© : β„š) := by
classical
simp only [probability, Nat.card_eq_fintype_card, Fintype.card_subtype,
Finset.card_filter, Nat.cast_sum, Nat.cast_ite,
Nat.cast_one, Nat.cast_zero]
theorem probability_prod_average {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ]
(p : Ξ© β†’ Ξ β†’ Prop) :
probability (fun z : Ξ© Γ— Ξ => p z.1 z.2) =
(βˆ‘ x : Ξ©, probability (p x)) / (Fintype.card Ξ© : β„š) := by
classical
simp_rw [probability_eq_sum_indicator]
simp only [Fintype.card_prod, Nat.cast_mul, Fintype.sum_prod_type,
← Finset.sum_div, div_div]
congr 1
exact mul_comm _ _
theorem probability_prod_average_right {Ω Ξ : Type*} [Fintype Ω] [Fintype Ξ]
(p : Ξ© β†’ Ξ β†’ Prop) :
probability (fun z : Ξ© Γ— Ξ => p z.1 z.2) =
(βˆ‘ y : Ξ, probability (fun x : Ξ© => p x y)) /
(Fintype.card Ξ : β„š) := by
classical
simp_rw [probability_eq_sum_indicator]
simp only [Fintype.card_prod, Nat.cast_mul, Fintype.sum_prod_type_right,
← Finset.sum_div, div_div]
theorem probability_coordinate {I X : Type*} [Fintype I] [Fintype X]
(i : I) (p : X β†’ Prop) :
probability (fun g : I β†’ X => p (g i)) = probability p := by
classical
cases isEmpty_or_nonempty X with
| inl hX =>
let : IsEmpty X := hX
let : IsEmpty (I β†’ X) := ⟨fun g => isEmptyElim (g i)⟩
simp [probability]
| inr hX =>
let : Nonempty X := hX
let : Nonempty (I β†’ X) := ⟨fun _ => Classical.choice hX⟩
apply probability_preimage_of_fibers (fun g : I β†’ X => g i)
intro x y
let e : (I β†’ X) ≃ (I β†’ X) :=
Equiv.piCongrRight (fun _ : I => Equiv.swap x y)
let ee : {g : I β†’ X // g i = x} ≃
{g : I β†’ X // g i = y} :=
e.subtypeEquiv (fun g => by
change g i = x ↔ Equiv.swap x y (g i) = y
constructor
Β· intro h
rw [h, Equiv.swap_apply_left]
Β· intro h
apply (Equiv.swap x y).injective
exact h.trans (Equiv.swap_apply_left x y).symm)
exact Nat.card_congr ee
theorem probability_coordinate_prod {I X N : Type*}
[Fintype I] [Fintype X] [Fintype N] (i : I) (p : X β†’ N β†’ Prop) :
probability (fun z : (I β†’ X) Γ— N => p (z.1 i) z.2) =
probability (fun z : X Γ— N => p z.1 z.2) := by
rw [probability_prod_average_right (fun (g : I β†’ X) n => p (g i) n),
probability_prod_average_right p]
congr 1
apply Finset.sum_congr rfl
intro n _
exact probability_coordinate i (fun x => p x n)
theorem probability_prod_reorder {Ξ© I N : Type*}
[Fintype Ξ©] [Fintype I] [Fintype N] (p : Ξ© β†’ I β†’ N β†’ Prop) :
probability (fun z : Ξ© Γ— (I Γ— N) => p z.1 z.2.1 z.2.2) =
probability (fun z : I Γ— (Ξ© Γ— N) => p z.2.1 z.1 z.2.2) := by
let e : (Ξ© Γ— (I Γ— N)) ≃ (I Γ— (Ξ© Γ— N)) :=
{ toFun := fun z => (z.2.1, z.1, z.2.2)
invFun := fun z => (z.2.1, z.1, z.2.2)
left_inv := fun _ => rfl
right_inv := fun _ => rfl }
exact probability_equiv e (fun z => p z.2.1 z.1 z.2.2)
theorem probability_prod_eq_of_const {Ω Ξ : Type*}
[Fintype Ω] [Fintype Ξ] [Nonempty Ω]
(p : Ξ© β†’ Ξ β†’ Prop) (q : β„š) (h : βˆ€ x, probability (p x) = q) :
probability (fun z : Ξ© Γ— Ξ => p z.1 z.2) = q := by
rw [probability_prod_average]
simp_rw [h]
rw [Finset.sum_const, Finset.card_univ, nsmul_eq_mul]
have hcard : (Fintype.card Ξ© : β„š) β‰  0 := by
exact_mod_cast Fintype.card_ne_zero
exact mul_div_cancel_leftβ‚€ q hcard
theorem enlarged_single_copy_probability {F B K V N : Type*} [Field F]
[AddCommGroup B] [Module F B] [AddCommGroup K] [Module F K]
[AddCommGroup V] [Fintype V] [Fintype N]
[Fintype (LinearInjection F B K)]
(C : V β†’ B) (a : N β†’ V) (L : LinearInjection F B K) :
probability (fun z : (LinearInjection F B K β†’ V) Γ— N =>
enlargedOutput C (Function.update z.1 L (z.1 L + a z.2)) β‰ 
enlargedOutput C z.1) =
probability (fun z : V Γ— N => C (z.1 + a z.2) β‰  C z.1) := by
calc
_ = probability (fun z : (LinearInjection F B K β†’ V) Γ— N =>
C (z.1 L + a z.2) β‰  C (z.1 L)) := by
congr 1
funext z
exact propext (enlargedOutput_update_ne_iff C z.1 L (z.1 L + a z.2))
_ = _ := probability_coordinate_prod L (fun x n => C (x + a n) β‰  C x)
theorem enlarged_random_copy_probability {F B K V N : Type*} [Field F]
[AddCommGroup B] [Module F B] [AddCommGroup K] [Module F K]
[AddCommGroup V] [Fintype V] [Fintype N]
[Fintype (LinearInjection F B K)] [Nonempty (LinearInjection F B K)]
(C : V β†’ B) (a : N β†’ V) :
probability (fun z : (LinearInjection F B K β†’ V) Γ—
(LinearInjection F B K Γ— N) =>
enlargedOutput C
(Function.update z.1 z.2.1 (z.1 z.2.1 + a z.2.2)) β‰ 
enlargedOutput C z.1) =
probability (fun z : V Γ— N => C (z.1 + a z.2) β‰  C z.1) := by
rw [probability_prod_reorder (fun x L n =>
enlargedOutput C (Function.update x L (x L + a n)) β‰  enlargedOutput C x)]
apply probability_prod_eq_of_const (fun L (z : (LinearInjection F B K β†’ V) Γ— N) =>
enlargedOutput C (Function.update z.1 L (z.1 L + a z.2)) β‰  enlargedOutput C z.1)
intro L
exact enlarged_single_copy_probability C a L
universe u
variable {B K V N : Type u}
variable [AddCommGroup B] [Module (ZMod 2) B] [Fintype B]
variable [FiniteDimensional (ZMod 2) B]
variable [AddCommGroup K] [Module (ZMod 2) K] [Fintype K]
variable [FiniteDimensional (ZMod 2) K]
variable [AddCommGroup V] [Module (ZMod 2) V] [Fintype V]
variable [Fintype N] [Nonempty N]
abbrev Copies (B K : Type u) [AddCommGroup B] [Module (ZMod 2) B]
[AddCommGroup K] [Module (ZMod 2) K] := LinearInjection (ZMod 2) B K
@[instance_reducible]
noncomputable def copiesFintype : Fintype (Copies B K) :=
Fintype.ofInjective (fun L : Copies B K => (L.1 : B β†’ K)) (by
intro L M h
apply Subtype.ext
exact LinearMap.ext (congrFun h))
local instance enlargementCopiesFintype : Fintype (Copies B K) := copiesFintype
def productEmbed (i : B β†’β‚—[ZMod 2] V) :
(Copies B K β†’ B) β†’β‚—[ZMod 2] (Copies B K β†’ V) where
toFun b L := i (b L)
map_add' b c := by ext L; exact map_add i (b L) (c L)
map_smul' t b := by ext L; exact map_smul i t (b L)
omit [Fintype B] [FiniteDimensional (ZMod 2) B] [Fintype K] [FiniteDimensional (ZMod 2) K] [Fintype V] in
theorem productEmbed_injective (i : B β†’β‚—[ZMod 2] V)
(hi : Function.Injective i) : Function.Injective (productEmbed (K := K) i) := by
intro b c h
funext L
apply hi
exact congrFun h L
def productStage (i : B β†’β‚—[ZMod 2] V) (hi : Function.Injective i)
(C : V β†’ B) (hC : βˆ€ x b, C (x + i b) = C x + b) (noise : N β†’ V)
(hdim : Module.finrank (ZMod 2) B ≀ Module.finrank (ZMod 2) K)
(bβ‚€ : B) (hbβ‚€ : bβ‚€ β‰  0) : Stage (ZMod 2) K := by
letI : Nonempty (Copies B K) := linearInjection_nonempty_of_finrank_le hdim
exact
{ Input := Copies B K β†’ V
Shift := Copies B K β†’ B
Noise := Copies B K Γ— N
embed := productEmbed i
embed_injective := productEmbed_injective i hi
logical := productShift
logical_surjective := productShift_surjective hdim bβ‚€ hbβ‚€
output := enlargedOutput C
equivariant := enlargedOutput_shift C i hC
noise := fun t => Pi.single t.1 (noise t.2) }
def build (i : B β†’β‚—[ZMod 2] V) (hi : Function.Injective i)
(C : V β†’ B) (hC : βˆ€ x b, C (x + i b) = C x + b) (noise : N β†’ V)
(hdim : Module.finrank (ZMod 2) B ≀ Module.finrank (ZMod 2) K)
(bβ‚€ : B) (hbβ‚€ : bβ‚€ β‰  0) : Stage (ZMod 2) K :=
StageQuotient.toStage (productStage i hi C hC noise hdim bβ‚€ hbβ‚€)
private theorem update_canonical {A B : Type*} (d : DecidableEq A) (f : A β†’ B) (a : A) (b : B) :
@Function.update A (fun _ => B) d f a b =
@Function.update A (fun _ => B) (Classical.typeDecidableEq A) f a b := by
cases Subsingleton.elim d (Classical.typeDecidableEq A : DecidableEq A)
rfl
private theorem probability_pointwise {A : Type*} (i j : Fintype A) (p q : A β†’ Prop)
(h : βˆ€ a, p a ↔ q a) : @probability A i p = @probability A j q := by
unfold probability
have he : p = q := funext (fun a => propext (h a))
rw [he]
omit [FiniteDimensional (ZMod 2) B] [Fintype K] [FiniteDimensional (ZMod 2) K] [Module (ZMod 2) V] [Fintype V] in
theorem add_single_eq_update (x : Copies B K β†’ V) (L : Copies B K) (a : V) :
x + Pi.single L a = Function.update x L (x L + a) := by
funext J
by_cases h : J = L
Β· subst J
simp
Β· simp [h]
theorem change_iff (i : B β†’β‚—[ZMod 2] V) (hi : Function.Injective i)
(C : V β†’ B) (hC : βˆ€ x b, C (x + i b) = C x + b) (noise : N β†’ V)
(hdim : Module.finrank (ZMod 2) B ≀ Module.finrank (ZMod 2) K)
(bβ‚€ : B) (hbβ‚€ : bβ‚€ β‰  0) (x : Copies B K β†’ V) (L : Copies B K) (n : N) :
let s := productStage i hi C hC noise hdim bβ‚€ hbβ‚€
StageQuotient.output s (StageQuotient.projection s x + StageQuotient.noise s (L, n)) β‰ 
StageQuotient.output s (StageQuotient.projection s x) ↔
C (x L + noise n) β‰  C (x L) := by
dsimp only
refine (StageQuotient.noise_change_iff
(productStage i hi C hC noise hdim bβ‚€ hbβ‚€) x (L, n)).trans ?_
change enlargedOutput C (x + Pi.single L (noise n)) β‰  enlargedOutput C x ↔ _
rw [add_single_eq_update]
have h := enlargedOutput_update_ne_iff C x L (x L + noise n)
simp only [update_canonical] at h ⊒
exact h
def copyObserver {E : Type*} [AddCommGroup E] [Module (ZMod 2) E]
(i : B β†’β‚—[ZMod 2] V) (hi : Function.Injective i)
(C : V β†’ B) (hC : βˆ€ x b, C (x + i b) = C x + b) (noise : N β†’ V)
(hdim : Module.finrank (ZMod 2) B ≀ Module.finrank (ZMod 2) K)
(bβ‚€ : B) (hbβ‚€ : bβ‚€ β‰  0)
(T : StageQuotient.Space (productStage i hi C hC noise hdim bβ‚€ hbβ‚€) β†’β‚—[ZMod 2] E)
(L : Copies B K) : V β†’β‚—[ZMod 2] E :=
T.comp ((StageQuotient.projection (productStage i hi C hC noise hdim bβ‚€ hbβ‚€)).comp
(LinearMap.single (R := ZMod 2) (Ο† := fun _ : Copies B K => V) L))
theorem copyObserver_shift {E : Type*} [AddCommGroup E] [Module (ZMod 2) E]
(i : B β†’β‚—[ZMod 2] V) (hi : Function.Injective i)
(C : V β†’ B) (hC : βˆ€ x b, C (x + i b) = C x + b) (noise : N β†’ V)
(hdim : Module.finrank (ZMod 2) B ≀ Module.finrank (ZMod 2) K)
(bβ‚€ : B) (hbβ‚€ : bβ‚€ β‰  0)
(T : StageQuotient.Space (productStage i hi C hC noise hdim bβ‚€ hbβ‚€) β†’β‚—[ZMod 2] E)
(L : Copies B K) :
(copyObserver i hi C hC noise hdim bβ‚€ hbβ‚€ T L).comp i =
(T.comp (StageQuotient.shift (productStage i hi C hC noise hdim bβ‚€ hbβ‚€))).comp L.1 := by
ext b
let s := productStage i hi C hC noise hdim bβ‚€ hbβ‚€
have he : s.embed (Pi.single L b) = Pi.single L (i b) := by
funext J
change i ((Pi.single L b : Copies B K β†’ B) J) =
(Pi.single L (i b) : Copies B K β†’ V) J
by_cases h : J = L
Β· subst J
simp
Β· simp [h]
have hl : s.logical (Pi.single L b) = L.1 b := by
change (βˆ‘ J : Copies B K, J.1 ((Pi.single L b : Copies B K β†’ B) J)) = L.1 b
simp [Pi.single_apply, apply_ite]
have hh := congrArg T (StageQuotient.shift_logical s (Pi.single L b))
rw [he, hl] at hh
exact hh.symm
omit [Fintype B] [FiniteDimensional (ZMod 2) B] [Fintype K] [FiniteDimensional (ZMod 2) K] in
theorem dual_pullback_eq_top_iff {E : Type*} [AddCommGroup E] [Module (ZMod 2) E]
(A : K β†’β‚—[ZMod 2] E) (L : B β†’β‚—[ZMod 2] K) :
(LinearMap.range A.dualMap).map L.dualMap = ⊀ ↔ Function.Injective (A.comp L) := by
rw [← LinearMap.range_comp, LinearMap.dualMap_comp_dualMap,
LinearMap.range_eq_top, LinearMap.dualMap_surjective_iff]
theorem detection_average {E : Type*} [AddCommGroup E] [Module (ZMod 2) E]
(i : B β†’β‚—[ZMod 2] V) (hi : Function.Injective i)
(C : V β†’ B) (hC : βˆ€ x b, C (x + i b) = C x + b) (noise : N β†’ V)
(hdim : Module.finrank (ZMod 2) B ≀ Module.finrank (ZMod 2) K)
(bβ‚€ : B) (hbβ‚€ : bβ‚€ β‰  0)
(hbase : βˆ€ U : V β†’β‚—[ZMod 2] E, Function.Injective (U.comp i) β†’
1 / 4 ≀ probability (fun n : N => U (noise n) β‰  0))
(T : StageQuotient.Space (productStage i hi C hC noise hdim bβ‚€ hbβ‚€) β†’β‚—[ZMod 2] E)
(hr : Module.finrank (ZMod 2) B + 2 ≀ Module.finrank (ZMod 2)
(LinearMap.range (T.comp (StageQuotient.shift
(productStage i hi C hC noise hdim bβ‚€ hbβ‚€))))) :
1 / 8 ≀
(βˆ‘ L : Copies B K, probability (fun n : N =>
copyObserver i hi C hC noise hdim bβ‚€ hbβ‚€ T L (noise n) β‰  0)) /
(Fintype.card (Copies B K) : β„š) := by
let : Nonempty (Copies B K) := linearInjection_nonempty_of_finrank_le hdim
let A := T.comp (StageQuotient.shift (productStage i hi C hC noise hdim bβ‚€ hbβ‚€))
apply (enlarged_detection (LinearMap.range A.dualMap)
(by simpa only [LinearMap.finrank_range_dualMap_eq_finrank_range] using hr)
(fun L => probability (fun n : N =>
copyObserver i hi C hC noise hdim bβ‚€ hbβ‚€ T L (noise n) β‰  0))
(fun _ => by unfold probability; positivity) ?_).2
intro L hL
apply hbase
rw [copyObserver_shift]
exact (dual_pullback_eq_top_iff A L.1).1 hL
omit [Fintype K] [FiniteDimensional (ZMod 2) K] in
theorem probability_projection (s : Stage (ZMod 2) K)
[Fintype s.Input] [Fintype (StageQuotient.Space s)]
(p : StageQuotient.Space s β†’ Prop) :
probability (fun x : s.Input => p (StageQuotient.projection s x)) = probability p := by
apply probability_preimage_of_fibers (StageQuotient.projection s)
intro x y
have h := (Quotient.fiber_card (StageQuotient.shifts s) (StageQuotient.logical s) x).trans
(Quotient.fiber_card (StageQuotient.shifts s) (StageQuotient.logical s) y).symm
exact h
omit [Fintype K] [FiniteDimensional (ZMod 2) K] in
theorem probability_projection_prod (s : Stage (ZMod 2) K)
[Fintype s.Input] [Fintype (StageQuotient.Space s)]
{A : Type*} [Fintype A] (p : StageQuotient.Space s β†’ A β†’ Prop) :
probability (fun z : s.Input Γ— A => p (StageQuotient.projection s z.1) z.2) =
probability (fun z : StageQuotient.Space s Γ— A => p z.1 z.2) := by
rw [probability_prod_average_right (fun x a => p (StageQuotient.projection s x) a),
probability_prod_average_right p]
congr 1
apply Finset.sum_congr rfl
intro a _
exact probability_projection s (fun x => p x a)
theorem change_probability (i : B β†’β‚—[ZMod 2] V) (hi : Function.Injective i)
(C : V β†’ B) (hC : βˆ€ x b, C (x + i b) = C x + b) (noise : N β†’ V)
(hdim : Module.finrank (ZMod 2) B ≀ Module.finrank (ZMod 2) K)
(bβ‚€ : B) (hbβ‚€ : bβ‚€ β‰  0)
[Fintype (StageQuotient.Space (productStage i hi C hC noise hdim bβ‚€ hbβ‚€))] :
let s := productStage i hi C hC noise hdim bβ‚€ hbβ‚€
probability (fun z : StageQuotient.Space s Γ— (Copies B K Γ— N) =>
StageQuotient.output s (z.1 + StageQuotient.noise s z.2) β‰  StageQuotient.output s z.1) =
probability (fun z : V Γ— N => C (z.1 + noise z.2) β‰  C z.1) := by
dsimp only
let : Nonempty (Copies B K) := linearInjection_nonempty_of_finrank_le hdim
let s := productStage i hi C hC noise hdim bβ‚€ hbβ‚€
let : Fintype s.Input := Fintype.ofFinite _
have hp := probability_projection_prod s (fun q (t : Copies B K Γ— N) =>
StageQuotient.output s (q + StageQuotient.noise s t) β‰  StageQuotient.output s q)
calc
_ = probability (fun z : s.Input Γ— (Copies B K Γ— N) =>
StageQuotient.output s (StageQuotient.projection s z.1 + StageQuotient.noise s z.2) β‰ 
StageQuotient.output s (StageQuotient.projection s z.1)) := hp.symm
_ = probability (fun z : (Copies B K β†’ V) Γ— (Copies B K Γ— N) =>
enlargedOutput C
(Function.update z.1 z.2.1 (z.1 z.2.1 + noise z.2.2)) β‰  enlargedOutput C z.1) := by
apply probability_pointwise
intro z
have h₁ := change_iff i hi C hC noise hdim bβ‚€ hbβ‚€ z.1 z.2.1 z.2.2
have hβ‚‚ := enlargedOutput_update_ne_iff C z.1 z.2.1 (z.1 z.2.1 + noise z.2.2)
simp only [update_canonical] at h₁ hβ‚‚ ⊒
have hc := h₁.trans hβ‚‚.symm
erw [update_canonical] at hc
exact hc
_ = _ := by
have hh := enlarged_random_copy_probability (F := ZMod 2) (K := K) C noise
simp only [update_canonical] at hh ⊒
unfold probability at hh ⊒
exact hh
theorem detection_probability {E : Type*} [AddCommGroup E] [Module (ZMod 2) E]
(i : B β†’β‚—[ZMod 2] V) (hi : Function.Injective i)
(C : V β†’ B) (hC : βˆ€ x b, C (x + i b) = C x + b) (noise : N β†’ V)
(hdim : Module.finrank (ZMod 2) B ≀ Module.finrank (ZMod 2) K)
(bβ‚€ : B) (hbβ‚€ : bβ‚€ β‰  0)
(hbase : βˆ€ U : V β†’β‚—[ZMod 2] E, Function.Injective (U.comp i) β†’
1 / 4 ≀ probability (fun n : N => U (noise n) β‰  0))
(T : StageQuotient.Space (productStage i hi C hC noise hdim bβ‚€ hbβ‚€) β†’β‚—[ZMod 2] E)
(hr : Module.finrank (ZMod 2) B + 2 ≀ Module.finrank (ZMod 2)
(LinearMap.range (T.comp (StageQuotient.shift
(productStage i hi C hC noise hdim bβ‚€ hbβ‚€))))) :
1 / 8 ≀ probability (fun t : Copies B K Γ— N =>
T (StageQuotient.noise (productStage i hi C hC noise hdim bβ‚€ hbβ‚€) t) β‰  0) := by
change 1 / 8 ≀ probability (fun t : Copies B K Γ— N =>
copyObserver i hi C hC noise hdim bβ‚€ hbβ‚€ T t.1 (noise t.2) β‰  0)
rw [probability_prod_average (fun L n =>
copyObserver i hi C hC noise hdim bβ‚€ hbβ‚€ T L (noise n) β‰  0)]
exact detection_average i hi C hC noise hdim bβ‚€ hbβ‚€ hbase T hr
end DFVSGames.Gadget.EnlargementConstruction
end
end OAI