math / data /lean /OAI /Computability /DirectedFeedback /Probability /DescentProbability.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
35.5 kB
import Mathlib
import OAI.Computability.DirectedFeedback.Games.Harmonic
namespace OAI
namespace DFVSGames.Gadget.DescentProbability
open Harmonic Descent
universe u v
variable {k : Type u} {B I X : Type v} [Field k]
variable [AddCommGroup B] [Module k B] [Finite B] [FiniteDimensional k B]
variable [Fintype I] [DecidableEq I] [Nonempty I]
variable [AddCommGroup X] [Module k X]
variable (J : I β†’ B β†’β‚—[k] X Γ— B) (hJ : Function.Surjective (aggregate J)) (Q : X β†’ B)
noncomputable instance noiseFintype (n : β„•) : Fintype (Stage.iterate J hJ Q n).Noise := by
induction n with
| zero => exact Fintype.ofFinite B
| succ n ih =>
exact inferInstanceAs (Fintype (I Γ— (Stage.iterate J hJ Q n).Noise))
noncomputable def terminalPotential (n : β„•) (S : Submodule k (B β†’β‚—[k] k))
(L : Lift (Stage.iterate J hJ Q n) S) : β„š :=
average (fun t => DFVSGames.Gadget.Harmonic.harmonic (leafRank J hJ Q n S L t))
omit [FiniteDimensional k B] in
@[simp] theorem terminalPotential_zero (S : Submodule k (B β†’β‚—[k] k))
(L : Lift (Stage.iterate J hJ Q 0) S) :
terminalPotential J hJ Q 0 S L = DFVSGames.Gadget.Harmonic.harmonic (Module.finrank k S) := by
change average (fun _ : (Stage.iterate J hJ Q 0).Noise =>
DFVSGames.Gadget.Harmonic.harmonic (Module.finrank k S)) = _
exact average_const _
omit [FiniteDimensional k B] in
theorem terminalPotential_succ (n : β„•) (S : Submodule k (B β†’β‚—[k] k))
(L : Lift (Stage.iterate J hJ Q (n + 1)) S) :
terminalPotential J hJ Q (n + 1) S L =
average (fun i => terminalPotential J hJ Q n
(childDomain J hJ Q (Stage.iterate J hJ Q n) S L i)
(childLift J hJ Q (Stage.iterate J hJ Q n) S L i)) := by
unfold terminalPotential average
change Finset.univ.expect (fun t : I Γ— (Stage.iterate J hJ Q n).Noise =>
DFVSGames.Gadget.Harmonic.harmonic (leafRank J hJ Q n
(childDomain J hJ Q (Stage.iterate J hJ Q n) S L t.1)
(childLift J hJ Q (Stage.iterate J hJ Q n) S L t.1) t.2)) = _
rw [← Finset.univ_product_univ, Finset.expect_product]
theorem expected_terminal_loss
(bad : Submodule k (B β†’β‚—[k] k) β†’ Prop) [DecidablePred bad]
(rβ‚€ : β„•) (C ΞΈ Ξ΅ : β„š) (hC : 0 ≀ C) (hΞΈ : 0 ≀ ΞΈ) (hsmall : C * Ξ΅ ≀ 1)
(hstep : βˆ€ (s : Stage k B) (S : Submodule k (B β†’β‚—[k] k))
(L : Lift (Stage.next J hJ Q s) S), Module.finrank k S ≀ rβ‚€ β†’
average (fun i => DFVSGames.Gadget.Harmonic.harmonic (Module.finrank k S) -
DFVSGames.Gadget.Harmonic.harmonic (Module.finrank k (childDomain J hJ Q s S L i))) ≀
3 * ΞΈ + C * ΞΈ * if bad S then 1 else 0)
(hfresh : βˆ€ (s : Stage k B) (S : Submodule k (B β†’β‚—[k] k))
(L : Lift (Stage.next J hJ Q s) S), Module.finrank k S ≀ rβ‚€ β†’
probability (fun i => bad (childDomain J hJ Q s S L i)) ≀ Ξ΅)
(n : β„•) (S : Submodule k (B β†’β‚—[k] k)) (L : Lift (Stage.iterate J hJ Q n) S)
(hcap : Module.finrank k S ≀ rβ‚€) :
DFVSGames.Gadget.Harmonic.harmonic (Module.finrank k S) - terminalPotential J hJ Q n S L ≀
4 * n * ΞΈ + C * ΞΈ * if bad S then 1 else 0 := by
induction n generalizing S with
| zero =>
simp only [terminalPotential_zero, sub_self, Nat.cast_zero, mul_zero, zero_mul,
zero_add]
split <;> simp_all [mul_nonneg]
| succ n ih =>
let s := Stage.iterate J hJ Q n
let Sc := childDomain J hJ Q s S L
let Lc := childLift J hJ Q s S L
have hchild : average (fun i => DFVSGames.Gadget.Harmonic.harmonic (Module.finrank k (Sc i)) -
terminalPotential J hJ Q n (Sc i) (Lc i)) ≀
4 * n * ΞΈ + C * ΞΈ * probability (fun i => bad (Sc i)) := by
calc
_ ≀ average (fun i => 4 * n * ΞΈ + C * ΞΈ * if bad (Sc i) then 1 else 0) := by
apply average_mono
intro i
exact ih (Sc i) (Lc i) ((child_rank_le J hJ Q s S L i).trans hcap)
_ = _ := by rw [average_add, average_const, average_mul_left]; rfl
have hdrop := hstep s S L hcap
have hbad := hfresh s S L hcap
have hbad' := mul_le_mul_of_nonneg_left hbad (mul_nonneg hC hΞΈ)
have hsmall' := mul_le_mul_of_nonneg_right hsmall hΞΈ
rw [terminalPotential_succ]
rw [average_sub] at hchild
rw [average_sub, average_const] at hdrop
change DFVSGames.Gadget.Harmonic.harmonic (Module.finrank k S) -
average (fun i => terminalPotential J hJ Q n (Sc i) (Lc i)) ≀ _
push_cast
nlinarith
end DFVSGames.Gadget.DescentProbability
namespace DFVSGames.Gadget.LeafDetection
open Harmonic Descent DescentProbability
universe v
variable {B I X : Type v}
variable [AddCommGroup B] [Module (ZMod 2) B] [Finite B] [FiniteDimensional (ZMod 2) B]
variable [Fintype I] [DecidableEq I] [Nonempty I]
variable [AddCommGroup X] [Module (ZMod 2) X]
variable (J : I β†’ B β†’β‚—[ZMod 2] X Γ— B)
variable (hJ : Function.Surjective (aggregate J)) (Q : X β†’ B)
noncomputable def survivalProbability (n : β„•)
(S : Submodule (ZMod 2) (B β†’β‚—[ZMod 2] ZMod 2))
(L : Lift (Stage.iterate J hJ Q n) S) : β„š :=
probability (fun t => 0 < leafRank J hJ Q n S L t)
noncomputable def detectionProbability (n : β„•)
(S : Submodule (ZMod 2) (B β†’β‚—[ZMod 2] ZMod 2))
(L : Lift (Stage.iterate J hJ Q n) S) : β„š := by
classical
exact probability (fun t => βˆƒ z : S, L.family z ((Stage.iterate J hJ Q n).noise t) β‰  0)
omit [FiniteDimensional (ZMod 2) B] in
theorem detectionProbability_nonneg (n : β„•)
(S : Submodule (ZMod 2) (B β†’β‚—[ZMod 2] ZMod 2))
(L : Lift (Stage.iterate J hJ Q n) S) :
0 ≀ detectionProbability J hJ Q n S L := by
classical
exact probability_nonneg _
omit [FiniteDimensional (ZMod 2) B] in
theorem detectionProbability_restrict_le (n : β„•)
(S T : Submodule (ZMod 2) (B β†’β‚—[ZMod 2] ZMod 2)) (hST : S ≀ T)
(L : Lift (Stage.iterate J hJ Q n) T) :
detectionProbability J hJ Q n S (L.restrict hST) ≀
detectionProbability J hJ Q n T L := by
classical
apply probability_mono
rintro t ⟨z, hz⟩
exact ⟨Submodule.inclusion hST z, hz⟩
omit [FiniteDimensional (ZMod 2) B] in
theorem detectionProbability_zero_of_rank_pos
(S : Submodule (ZMod 2) (B β†’β‚—[ZMod 2] ZMod 2))
(L : Lift (Stage.iterate J hJ Q 0) S) (hrank : 0 < Module.finrank (ZMod 2) S) :
(1 / 2 : β„š) ≀ detectionProbability J hJ Q 0 S L := by
classical
let : Fintype B := Fintype.ofFinite B
let : Nontrivial S := Module.nontrivial_of_finrank_pos hrank
obtain ⟨z, hz⟩ := exists_ne (0 : S)
have hzval : z.val β‰  0 := by
intro he
exact hz (Subtype.ext he)
have hex : βˆƒ b : B, z.val b β‰  0 := by
by_contra h
apply hzval
ext b
by_contra hb
exact h ⟨b, hb⟩
obtain ⟨b, hb⟩ := hex
have hagree : L.family z b = z.val b := L.agrees z b
have hχ : L.family z b ≠ 0 := by rwa [hagree]
change (1 / 2 : β„š) ≀ probability (fun b : B => βˆƒ z : S, L.family z b β‰  0)
exact binary_family_detection_ge_half _ (L.family z).toAddMonoidHom b hχ
(fun b hb => ⟨z, hb⟩)
omit [FiniteDimensional (ZMod 2) B] in
@[simp] theorem survivalProbability_zero
(S : Submodule (ZMod 2) (B β†’β‚—[ZMod 2] ZMod 2))
(L : Lift (Stage.iterate J hJ Q 0) S) :
survivalProbability J hJ Q 0 S L =
if 0 < Module.finrank (ZMod 2) S then 1 else 0 := by
change average (fun _ : (Stage.iterate J hJ Q 0).Noise =>
if 0 < Module.finrank (ZMod 2) S then (1 : β„š) else 0) = _
exact average_const _
omit [FiniteDimensional (ZMod 2) B] in
theorem survivalProbability_succ (n : β„•)
(S : Submodule (ZMod 2) (B β†’β‚—[ZMod 2] ZMod 2))
(L : Lift (Stage.iterate J hJ Q (n + 1)) S) :
survivalProbability J hJ Q (n + 1) S L =
average (fun i => survivalProbability J hJ Q n
(childDomain J hJ Q (Stage.iterate J hJ Q n) S L i)
(childLift J hJ Q (Stage.iterate J hJ Q n) S L i)) := by
unfold survivalProbability
change probability (fun t : I Γ— (Stage.iterate J hJ Q n).Noise =>
0 < leafRank J hJ Q n
(childDomain J hJ Q (Stage.iterate J hJ Q n) S L t.1)
(childLift J hJ Q (Stage.iterate J hJ Q n) S L t.1) t.2) = _
exact probability_product _
omit [FiniteDimensional (ZMod 2) B] in
theorem average_child_detection_le (n : β„•)
(S : Submodule (ZMod 2) (B β†’β‚—[ZMod 2] ZMod 2))
(L : Lift (Stage.iterate J hJ Q (n + 1)) S) :
average (fun i => detectionProbability J hJ Q n
(childDomain J hJ Q (Stage.iterate J hJ Q n) S L i)
(childLift J hJ Q (Stage.iterate J hJ Q n) S L i)) ≀
detectionProbability J hJ Q (n + 1) S L := by
classical
unfold detectionProbability
change _ ≀ probability (fun t : I Γ— (Stage.iterate J hJ Q n).Noise =>
βˆƒ z : S, L.family z ((Stage.iterate J hJ Q (n + 1)).noise t) β‰  0)
rw [probability_product]
apply average_mono
intro i
apply probability_mono
intro t hdetect
exact child_detection J hJ Q (Stage.iterate J hJ Q n) S L i t hdetect
omit [FiniteDimensional (ZMod 2) B] in
theorem half_survival_le_detection (n : β„•)
(S : Submodule (ZMod 2) (B β†’β‚—[ZMod 2] ZMod 2))
(L : Lift (Stage.iterate J hJ Q n) S) :
(1 / 2 : β„š) * survivalProbability J hJ Q n S L ≀
detectionProbability J hJ Q n S L := by
induction n generalizing S with
| zero =>
rw [survivalProbability_zero]
split_ifs with hrank
Β· simpa only [mul_one] using detectionProbability_zero_of_rank_pos J hJ Q S L hrank
Β· simpa only [mul_zero] using detectionProbability_nonneg J hJ Q 0 S L
| succ n ih =>
rw [survivalProbability_succ, ← average_mul_left]
calc
_ ≀ average (fun i => detectionProbability J hJ Q n
(childDomain J hJ Q (Stage.iterate J hJ Q n) S L i)
(childLift J hJ Q (Stage.iterate J hJ Q n) S L i)) := by
apply average_mono
intro i
exact ih _ _
_ ≀ detectionProbability J hJ Q (n + 1) S L :=
average_child_detection_le J hJ Q n S L
theorem quarter_detection_of_terminal_potential (n : β„•)
(S : Submodule (ZMod 2) (B β†’β‚—[ZMod 2] ZMod 2))
(L : Lift (Stage.iterate J hJ Q n) S)
(hrank : 0 < Module.finrank (ZMod 2) S)
(hpotential : DFVSGames.Gadget.Harmonic.harmonic (Module.finrank (ZMod 2) S) / 2 ≀
terminalPotential J hJ Q n S L) :
(1 / 4 : β„š) ≀ detectionProbability J hJ Q n S L := by
have hsurv : (1 / 2 : β„š) ≀ survivalProbability J hJ Q n S L :=
survival_probability_ge_half_of_potential (leafRank J hJ Q n S L)
(Module.finrank (ZMod 2) S) hrank (leafRank_le J hJ Q n S L) hpotential
have hdet := half_survival_le_detection J hJ Q n S L
linarith
theorem quarter_detection_of_restricted_terminal_potential (n : β„•)
(S T : Submodule (ZMod 2) (B β†’β‚—[ZMod 2] ZMod 2)) (hST : S ≀ T)
(L : Lift (Stage.iterate J hJ Q n) T)
(hrank : 0 < Module.finrank (ZMod 2) S)
(hpotential : DFVSGames.Gadget.Harmonic.harmonic (Module.finrank (ZMod 2) S) / 2 ≀
terminalPotential J hJ Q n S (L.restrict hST)) :
(1 / 4 : β„š) ≀ detectionProbability J hJ Q n T L :=
(quarter_detection_of_terminal_potential J hJ Q n S (L.restrict hST)
hrank hpotential).trans (detectionProbability_restrict_le J hJ Q n S T hST L)
end DFVSGames.Gadget.LeafDetection
namespace DFVSGames.Gadget.BaseDetection
open Quadratic OrientedBlockKernel BlockDescent Harmonic
open Descent DescentProbability LeafDetection
open scoped Classical
noncomputable section
variable {F : Type*} [Field F] [Fintype F] [CharP F 2] [Algebra (ZMod 2) F]
variable [DecidableEq (BlockOrientationIndex F)] [Nonempty (BlockOrientationIndex F)]
def logicalCharacters (S : Submodule (ZMod 2) (Vec F)) :
Submodule (ZMod 2) (BinaryDual (F := F)) :=
S.map traceDualEquiv.toLinearMap
omit [CharP F 2] [DecidableEq (BlockOrientationIndex F)] [Nonempty (BlockOrientationIndex F)] in
theorem traceSpace_logicalCharacters (S : Submodule (ZMod 2) (Vec F)) :
traceSpace (logicalCharacters S) = S := by
exact (Submodule.map_symm_eq_iff traceDualEquiv).mpr rfl
omit [CharP F 2] [DecidableEq (BlockOrientationIndex F)] [Nonempty (BlockOrientationIndex F)] in
theorem logicalCharacters_finrank (S : Submodule (ZMod 2) (Vec F)) :
Module.finrank (ZMod 2) (logicalCharacters S) = Module.finrank (ZMod 2) S :=
traceDualEquiv.finrank_map_eq S
omit [CharP F 2] [Algebra (ZMod 2) F] [DecidableEq (BlockOrientationIndex F)] [Nonempty (BlockOrientationIndex F)] in
theorem theta_pos : 0 < fieldLineTheta F := by
have hc : (0 : β„š) < Nat.card (FieldLine F) := by
exact_mod_cast (card_FieldLine_pos (F := F))
exact inv_pos.mpr hc
theorem full_lift_detection :
let J : BlockOrientationIndex F β†’ Vec F β†’β‚—[ZMod 2] Vec F Γ— Vec F :=
orientedBlockLinear
βˆ€ (hJ : Function.Surjective (aggregate J))
(rβ‚€ : β„•) (Ξ΅ : β„š) (_hrβ‚€ : 0 < rβ‚€)
(_hbudget : badRankCoefficient rβ‚€ * Ξ΅ ≀ 1)
(_hgeneric : βˆ€ r : β„•, r ≀ rβ‚€ β†’ nongenericFraction F r ≀ Ξ΅)
(Sβ‚€ : Submodule (ZMod 2) (Vec F))
(_hrank : Module.finrank (ZMod 2) Sβ‚€ = rβ‚€) (_hSβ‚€ : IsGeneric Sβ‚€)
(L : Lift (Stage.iterate J hJ Q (depth rβ‚€ (fieldLineTheta F)))
(⊀ : Submodule (ZMod 2) (BinaryDual (F := F)))),
(1 / 4 : β„š) ≀ detectionProbability J hJ Q
(depth rβ‚€ (fieldLineTheta F)) ⊀ L := by
intro J hJ rβ‚€ Ξ΅ hrβ‚€ hbudget hgeneric Sβ‚€ hrank hSβ‚€ L
classical
let S := logicalCharacters Sβ‚€
have hSrank : Module.finrank (ZMod 2) S = rβ‚€ :=
(logicalCharacters_finrank Sβ‚€).trans hrank
have hSgeneric : IsGeneric (traceSpace S) := by
simpa only [S, traceSpace_logicalCharacters] using hSβ‚€
let Lβ‚€ := L.restrict (show S ≀ ⊀ from le_top)
have hdrop := DescentProbability.expected_terminal_loss J hJ Q
(fun T => Β¬ IsGeneric (traceSpace T)) rβ‚€ (badRankCoefficient rβ‚€)
(fieldLineTheta F) Ξ΅ (badRankCoefficient_nonneg rβ‚€) (le_of_lt theta_pos) hbudget
(by
intro s T L' hT
exact OutgoingHarmonic.descendant_harmonic_loss_le hJ Q s T L' rβ‚€ hT)
(by
intro s T L' hT
have hf := FreshGenericity.descendant_bad_le hJ Q s T L' rβ‚€ Ξ΅ hT hgeneric
refine (le_of_eq ?_).trans hf
apply Finset.expect_congr rfl
intro i _
by_cases hi : IsGeneric (traceSpace (childDomain J hJ Q s T L' i))
· simp only [FreshGenericity.bad, J] at hi ⊒
simp only [hi, not_true_eq_false, ite_false]
· simp only [FreshGenericity.bad, J] at hi ⊒
simp only [hi, not_false_eq_true, ite_true])
(depth rβ‚€ (fieldLineTheta F)) S Lβ‚€ hSrank.le
have hdepth := depth_budget rβ‚€ (fieldLineTheta F) theta_pos
have hpotential : DFVSGames.Gadget.Harmonic.harmonic (Module.finrank (ZMod 2) S) / 2 ≀
terminalPotential J hJ Q (depth rβ‚€ (fieldLineTheta F)) S Lβ‚€ := by
simp only [hSgeneric, not_true_eq_false, ite_false, mul_zero, add_zero, hSrank] at hdrop ⊒
linarith
exact quarter_detection_of_restricted_terminal_potential J hJ Q
(depth rβ‚€ (fieldLineTheta F)) S ⊀ le_top L (hSrank.symm β–Έ hrβ‚€) hpotential
end
end DFVSGames.Gadget.BaseDetection
namespace DFVSGames.Gadget.Quotient
variable {π•œ P B : Type*} [Ring π•œ]
variable [AddCommGroup P] [Module π•œ P] [AddCommGroup B] [Module π•œ B]
def shiftKernel (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) : Submodule π•œ P :=
(LinearMap.ker lam).map R.subtype
abbrev Space (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) := P β§Έ shiftKernel R lam
def projection (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) :
P β†’β‚—[π•œ] Space R lam := (shiftKernel R lam).mkQ
theorem projection_surjective (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) :
Function.Surjective (projection R lam) := (shiftKernel R lam).mkQ_surjective
theorem mem_shiftKernel (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) (x : P) :
x ∈ shiftKernel R lam ↔ βˆƒ h : R, lam h = 0 ∧ (h : P) = x := Iff.rfl
theorem projection_eq_zero (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) (h : R) :
projection R lam (h : P) = 0 ↔ lam h = 0 := by
change (Submodule.Quotient.mk (h : P) : Space R lam) = 0 ↔ _
rw [Submodule.Quotient.mk_eq_zero, mem_shiftKernel]
constructor
· rintro ⟨k, hk, hkh⟩
have : k = h := Subtype.ext hkh
simpa [this] using hk
Β· intro hh
exact ⟨h, hh, rfl⟩
def quotientShift (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) :
(R β§Έ LinearMap.ker lam) β†’β‚—[π•œ] Space R lam :=
(LinearMap.ker lam).liftQ ((projection R lam).comp R.subtype) (by
intro h hh
exact (projection_eq_zero R lam h).mpr hh)
@[simp] theorem quotientShift_mk (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) (h : R) :
quotientShift R lam (Submodule.Quotient.mk h) = projection R lam (h : P) := rfl
noncomputable def logicalShift (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) : B β†’β‚—[π•œ] Space R lam :=
(quotientShift R lam).comp (lam.quotKerEquivOfSurjective hlam).symm.toLinearMap
@[simp] theorem logicalShift_lambda (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) (h : R) :
logicalShift R lam hlam (lam h) = projection R lam (h : P) := by
simp [logicalShift, LinearMap.quotKerEquivOfSurjective_symm_apply]
theorem logicalShift_injective (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) : Function.Injective (logicalShift R lam hlam) := by
intro a b hab
obtain ⟨h, rfl⟩ := hlam a
obtain ⟨k, rfl⟩ := hlam b
rw [logicalShift_lambda, logicalShift_lambda] at hab
have hz : projection R lam ((h - k : R) : P) = 0 := by
change projection R lam ((h : P) - (k : P)) = 0
rw [map_sub, hab, sub_self]
have := (projection_eq_zero R lam (h - k)).mp hz
exact sub_eq_zero.mp (by simpa only [map_sub] using this)
def Equivariant (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) (C : P β†’ B) : Prop :=
βˆ€ (u : P) (h : R), C (u + (h : P)) = C u + lam h
theorem difference_shift (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(C : P β†’ B) (hC : Equivariant R lam C) (u a : P) (h : R) :
C (u + (h : P) + a) - C (u + (h : P)) = C (u + a) - C u := by
have he : u + (h : P) + a = (u + a) + (h : P) := by
simp only [add_assoc, add_comm (h : P) a]
rw [he, hC, hC, add_sub_add_right_eq_sub]
def conditionedShiftEquiv (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(C : P β†’ B) (hC : Equivariant R lam C) (D : P β†’ Prop)
(hD : βˆ€ (u : P) (h : R), D (u + (h : P)) ↔ D u) (b : B) (h : R) :
{u : P // C u = b ∧ D u} ≃ {u : P // C u = b + lam h ∧ D u} where
toFun u := ⟨u.val + (h : P), by
exact ⟨(hC u.val h).trans (congrArg (fun x => x + lam h) u.property.1),
(hD u.val h).mpr u.property.2⟩⟩
invFun u := ⟨u.val + ((-h : R) : P), by
constructor
Β· rw [hC u.val (-h), u.property.1, map_neg, add_neg_cancel_right]
· exact (hD u.val (-h)).mpr u.property.2⟩
left_inv u := Subtype.ext (by simp)
right_inv u := Subtype.ext (by simp)
noncomputable def conditionedFiberEquiv (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) (C : P β†’ B) (hC : Equivariant R lam C)
(D : P β†’ Prop) (hD : βˆ€ (u : P) (h : R), D (u + (h : P)) ↔ D u)
(b c : B) : {u : P // C u = b ∧ D u} ≃ {u : P // C u = c ∧ D u} := by
classical
let h : R := Classical.choose (hlam (c - b))
have hh : lam h = c - b := Classical.choose_spec (hlam (c - b))
have he : b + lam h = c := by rw [hh, add_comm, sub_add_cancel]
simpa only [he] using conditionedShiftEquiv R lam C hC D hD b h
theorem conditioned_fiber_card (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) (C : P β†’ B) (hC : Equivariant R lam C)
(D : P β†’ Prop) (hD : βˆ€ (u : P) (h : R), D (u + (h : P)) ↔ D u)
(b c : B) :
Nat.card {u : P // C u = b ∧ D u} = Nat.card {u : P // C u = c ∧ D u} :=
Nat.card_congr (conditionedFiberEquiv R lam hlam C hC D hD b c)
theorem output_fiber_card (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) (C : P β†’ B) (hC : Equivariant R lam C)
(b c : B) : Nat.card {u : P // C u = b} = Nat.card {u : P // C u = c} := by
simpa only [and_true] using conditioned_fiber_card R lam hlam C hC
(fun _ => True) (fun _ _ => Iff.rfl) b c
theorem difference_fiber_card (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) (C : P β†’ B) (hC : Equivariant R lam C)
(a : P) (d b c : B) :
Nat.card {u : P // C u = b ∧ C (u + a) - C u = d} =
Nat.card {u : P // C u = c ∧ C (u + a) - C u = d} := by
apply conditioned_fiber_card R lam hlam C hC
intro u h
rw [difference_shift R lam C hC]
def conditionedSigmaEquiv (C : P β†’ B) (D : P β†’ Prop) :
{u : P // D u} ≃ Ξ£ b : B, {u : P // C u = b ∧ D u} where
toFun u := ⟨C u.val, ⟨u.val, rfl, u.property⟩⟩
invFun u := ⟨u.2.val, u.2.property.2⟩
left_inv _ := rfl
right_inv := by rintro ⟨b, u, hu, hD⟩; cases hu; rfl
noncomputable def conditionedProductEquiv (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) (C : P β†’ B) (hC : Equivariant R lam C)
(D : P β†’ Prop) (hD : βˆ€ (u : P) (h : R), D (u + (h : P)) ↔ D u) (b : B) :
{u : P // D u} ≃ B Γ— {u : P // C u = b ∧ D u} :=
((conditionedSigmaEquiv C D).trans
(Equiv.sigmaCongrRight (fun c => conditionedFiberEquiv R lam hlam C hC D hD c b))).trans
(Equiv.sigmaEquivProd _ _)
@[simp] theorem conditionedProductEquiv_fst (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) (C : P β†’ B) (hC : Equivariant R lam C)
(D : P β†’ Prop) (hD : βˆ€ (u : P) (h : R), D (u + (h : P)) ↔ D u) (b : B)
(u : {u : P // D u}) :
(conditionedProductEquiv R lam hlam C hC D hD b u).1 = C u.val := rfl
theorem conditioned_card_factorization [Finite P] [Finite B]
(R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) (C : P β†’ B) (hC : Equivariant R lam C)
(D : P β†’ Prop) (hD : βˆ€ (u : P) (h : R), D (u + (h : P)) ↔ D u) (b : B) :
Nat.card {u : P // D u} = Nat.card B * Nat.card {u : P // C u = b ∧ D u} := by
rw [← Nat.card_prod]
exact Nat.card_congr (conditionedProductEquiv R lam hlam C hC D hD b)
theorem difference_card_factorization [Finite P] [Finite B]
(R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) (C : P β†’ B) (hC : Equivariant R lam C)
(a : P) (d b : B) :
Nat.card {u : P // C (u + a) - C u = d} =
Nat.card B * Nat.card {u : P // C u = b ∧ C (u + a) - C u = d} := by
apply conditioned_card_factorization R lam hlam C hC
intro u h
rw [difference_shift R lam C hC]
theorem output_constant_on_fibers (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(C : P β†’ B) (hC : Equivariant R lam C) (x y : P)
(hxy : projection R lam x = projection R lam y) : C x = C y := by
have hm : x - y ∈ shiftKernel R lam := (Submodule.Quotient.eq _).mp hxy
obtain ⟨h, hh, hval⟩ := (mem_shiftKernel R lam _).mp hm
have he : y + (h : P) = x := by rw [hval, add_comm, sub_add_cancel]
simpa only [he, hh, add_zero] using hC y h
def output (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(C : P β†’ B) (hC : Equivariant R lam C) : Space R lam β†’ B :=
_root_.Quotient.lift C (fun _ _ h =>
output_constant_on_fibers R lam C hC _ _ (_root_.Quotient.sound h))
@[simp] theorem output_projection (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(C : P β†’ B) (hC : Equivariant R lam C) (u : P) :
output R lam C hC (projection R lam u) = C u := rfl
theorem output_equivariant (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) (C : P β†’ B) (hC : Equivariant R lam C)
(x : Space R lam) (b : B) :
output R lam C hC (x + logicalShift R lam hlam b) = output R lam C hC x + b := by
obtain ⟨u, rfl⟩ := projection_surjective R lam x
obtain ⟨h, rfl⟩ := hlam b
rw [logicalShift_lambda, ← map_add, output_projection, output_projection]
exact hC u h
theorem change_iff (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(C : P β†’ B) (hC : Equivariant R lam C) (u a : P) :
(output R lam C hC (projection R lam u + projection R lam a) β‰ 
output R lam C hC (projection R lam u)) ↔ C (u + a) β‰  C u := by
rw [← map_add, output_projection, output_projection]
theorem character_pullback_shift (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(hlam : Function.Surjective lam) (g : Space R lam β†’β‚—[π•œ] π•œ) (h : R) :
(g.comp (projection R lam)) (h : P) =
(g.comp (logicalShift R lam hlam)) (lam h) := by
simp only [LinearMap.comp_apply, logicalShift_lambda]
theorem detection_iff {I : Type*} (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B)
(family : I β†’ Space R lam β†’β‚—[π•œ] π•œ) (a : P) :
(βˆƒ i, family i (projection R lam a) β‰  0) ↔
βˆƒ i, (family i).comp (projection R lam) a β‰  0 := Iff.rfl
def fiberMap (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) (a : P) :
shiftKernel R lam β†’ {u : P // projection R lam u = projection R lam a} :=
fun h => ⟨a + (h : P), by
have hh : projection R lam (h : P) = 0 :=
(Submodule.Quotient.mk_eq_zero _).mpr h.property
rw [map_add, hh, add_zero]⟩
theorem fiberMap_bijective (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) (a : P) :
Function.Bijective (fiberMap R lam a) := by
constructor
Β· intro h k he
apply Subtype.ext
exact add_left_cancel (congrArg Subtype.val he)
Β· intro u
have hm : u.val - a ∈ shiftKernel R lam :=
(Submodule.Quotient.eq _).mp u.property
refine ⟨⟨u.val - a, hm⟩, Subtype.ext ?_⟩
change a + (u.val - a) = u.val
rw [add_comm, sub_add_cancel]
theorem fiber_card (R : Submodule π•œ P) (lam : R β†’β‚—[π•œ] B) (x : Space R lam) :
Nat.card {u : P // projection R lam u = x} = Nat.card (shiftKernel R lam) := by
obtain ⟨a, rfl⟩ := projection_surjective R lam x
exact (Nat.card_congr (Equiv.ofBijective _ (fiberMap_bijective R lam a))).symm
end DFVSGames.Gadget.Quotient
namespace DFVSGames.Gadget.StageQuotient
universe u v
variable {k : Type u} {B : Type v} [CommRing k]
variable [AddCommGroup B] [Module k B]
def shifts (s : Stage k B) : Submodule k s.Input := LinearMap.range s.embed
noncomputable def shiftEquiv (s : Stage k B) : s.Shift ≃ₗ[k] shifts s :=
LinearEquiv.ofInjective s.embed s.embed_injective
@[simp] theorem shiftEquiv_coe (s : Stage k B) (h : s.Shift) :
((shiftEquiv s h : shifts s) : s.Input) = s.embed h := rfl
@[simp] theorem embed_shiftEquiv_symm (s : Stage k B) (h : shifts s) :
s.embed ((shiftEquiv s).symm h) = (h : s.Input) :=
LinearEquiv.ofInjective_symm_apply s.embed h
noncomputable def logical (s : Stage k B) : shifts s β†’β‚—[k] B :=
s.logical.comp (shiftEquiv s).symm.toLinearMap
@[simp] theorem logical_shiftEquiv (s : Stage k B) (h : s.Shift) :
logical s (shiftEquiv s h) = s.logical h := by
simp [logical]
theorem logical_surjective (s : Stage k B) : Function.Surjective (logical s) := by
intro b
obtain ⟨h, hh⟩ := s.logical_surjective b
exact ⟨shiftEquiv s h, (logical_shiftEquiv s h).trans hh⟩
theorem equivariant (s : Stage k B) :
Quotient.Equivariant (shifts s) (logical s) s.output := by
intro u h
have he := s.equivariant u ((shiftEquiv s).symm h)
simpa only [embed_shiftEquiv_symm, logical, LinearMap.comp_apply,
LinearEquiv.coe_coe] using he
abbrev Space (s : Stage k B) := Quotient.Space (shifts s) (logical s)
noncomputable def projection (s : Stage k B) : s.Input β†’β‚—[k] Space s :=
Quotient.projection (shifts s) (logical s)
theorem projection_surjective (s : Stage k B) : Function.Surjective (projection s) :=
Quotient.projection_surjective (shifts s) (logical s)
instance spaceFinite (s : Stage k B) : Finite (Space s) :=
Finite.of_surjective (projection s) (projection_surjective s)
noncomputable def shift (s : Stage k B) : B β†’β‚—[k] Space s :=
Quotient.logicalShift (shifts s) (logical s) (logical_surjective s)
theorem shift_injective (s : Stage k B) : Function.Injective (shift s) :=
Quotient.logicalShift_injective (shifts s) (logical s) (logical_surjective s)
@[simp] theorem shift_logical (s : Stage k B) (h : s.Shift) :
shift s (s.logical h) = projection s (s.embed h) := by
rw [← logical_shiftEquiv s h]
exact Quotient.logicalShift_lambda (shifts s) (logical s) (logical_surjective s)
(shiftEquiv s h)
noncomputable def output (s : Stage k B) : Space s β†’ B :=
Quotient.output (shifts s) (logical s) s.output (equivariant s)
@[simp] theorem output_projection (s : Stage k B) (u : s.Input) :
output s (projection s u) = s.output u := rfl
theorem output_equivariant (s : Stage k B) (x : Space s) (b : B) :
output s (x + shift s b) = output s x + b :=
Quotient.output_equivariant (shifts s) (logical s) (logical_surjective s)
s.output (equivariant s) x b
noncomputable def noise (s : Stage k B) : s.Noise β†’ Space s :=
fun t => projection s (s.noise t)
theorem noise_change_iff (s : Stage k B) (u : s.Input) (t : s.Noise) :
(output s (projection s u + noise s t) β‰  output s (projection s u)) ↔
s.output (u + s.noise t) β‰  s.output u :=
Quotient.change_iff (shifts s) (logical s) s.output (equivariant s) u (s.noise t)
theorem character_logical (s : Stage k B) (g : Space s β†’β‚—[k] k) (h : s.Shift) :
(g.comp (projection s)) (s.embed h) = (g.comp (shift s)) (s.logical h) := by
simp only [LinearMap.comp_apply, shift_logical]
theorem noise_detection_iff {I : Type*} (s : Stage k B)
(family : I β†’ Space s β†’β‚—[k] k) (t : s.Noise) :
(βˆƒ i, family i (noise s t) β‰  0) ↔
βˆƒ i, (family i).comp (projection s) (s.noise t) β‰  0 := Iff.rfl
noncomputable def toStage [Finite B] (s : Stage k B) : Stage k B where
Input := Space s
Shift := B
Noise := s.Noise
embed := shift s
embed_injective := shift_injective s
logical := LinearMap.id
logical_surjective := Function.surjective_id
output := output s
equivariant := output_equivariant s
noise := noise s
end DFVSGames.Gadget.StageQuotient
namespace DFVSGames.Gadget.DetectionBridge
open Harmonic
variable {K B V E Ξ© : Type*} [Field K]
variable [AddCommGroup B] [Module K B] [AddCommGroup V] [Module K V]
variable [AddCommGroup E] [Module K E] [Fintype Ξ©]
def IsFullLift (ΞΉ : B β†’β‚—[K] V)
(ψ : Module.Dual K B β†’β‚—[K] Module.Dual K V) : Prop :=
βˆ€ (z : Module.Dual K B) (b : B), ψ z (ΞΉ b) = z b
noncomputable def characterDetection (noise : Ξ© β†’ V)
(ψ : Module.Dual K B β†’β‚—[K] Module.Dual K V) : β„š := by
classical
exact probability (fun Ο‰ => βˆƒ z : Module.Dual K B, ψ z (noise Ο‰) β‰  0)
theorem exists_leftInverse_of_logical_injective (ΞΉ : B β†’β‚—[K] V)
(T : V β†’β‚—[K] E) (hinjective : Function.Injective (T.comp ΞΉ)) :
βˆƒ l : E β†’β‚—[K] B, l.comp (T.comp ΞΉ) = LinearMap.id :=
(T.comp ΞΉ).exists_leftInverse_of_injective (LinearMap.ker_eq_bot.mpr hinjective)
theorem fullLift_of_leftInverse (ΞΉ : B β†’β‚—[K] V) (T : V β†’β‚—[K] E)
(l : E β†’β‚—[K] B) (hleft : l.comp (T.comp ΞΉ) = LinearMap.id) :
IsFullLift ΞΉ (l.comp T).dualMap := by
intro z b
change z (l (T (ΞΉ b))) = z b
have hb : l (T (ΞΉ b)) = b := LinearMap.congr_fun hleft b
rw [hb]
theorem target_detection_of_full_lift_bound [DecidableEq E]
(noise : Ξ© β†’ V) (ΞΉ : B β†’β‚—[K] V) (T : V β†’β‚—[K] E) (q : β„š)
(hfull : βˆ€ ψ : Module.Dual K B β†’β‚—[K] Module.Dual K V,
IsFullLift ΞΉ ψ β†’ q ≀ characterDetection noise ψ)
(hinjective : Function.Injective (T.comp ΞΉ)) :
q ≀ probability (fun Ο‰ => T (noise Ο‰) β‰  0) := by
classical
obtain ⟨l, hl⟩ := exists_leftInverse_of_logical_injective ι T hinjective
calc
q ≀ characterDetection noise (l.comp T).dualMap :=
hfull _ (fullLift_of_leftInverse ΞΉ T l hl)
_ ≀ probability (fun Ο‰ => T (noise Ο‰) β‰  0) := by
unfold characterDetection
apply probability_mono
rintro Ο‰ ⟨z, hz⟩ hzero
apply hz
change z (l (T (noise Ο‰))) = 0
simp [hzero]
theorem target_detection_of_retraction_bound [DecidableEq B] [DecidableEq E]
(noise : Ξ© β†’ V) (ΞΉ : B β†’β‚—[K] V) (T : V β†’β‚—[K] E) (q : β„š)
(hretract : βˆ€ L : V β†’β‚—[K] B, L.comp ΞΉ = LinearMap.id β†’
q ≀ probability (fun Ο‰ => L (noise Ο‰) β‰  0))
(hinjective : Function.Injective (T.comp ΞΉ)) :
q ≀ probability (fun Ο‰ => T (noise Ο‰) β‰  0) := by
obtain ⟨l, hl⟩ := exists_leftInverse_of_logical_injective ι T hinjective
have hcomp : (l.comp T).comp ΞΉ = LinearMap.id := by
simpa only [LinearMap.comp_assoc] using hl
calc
q ≀ probability (fun Ο‰ => (l.comp T) (noise Ο‰) β‰  0) := hretract _ hcomp
_ ≀ probability (fun Ο‰ => T (noise Ο‰) β‰  0) := by
apply probability_mono
intro Ο‰ h hzero
apply h
simp [hzero]
end DFVSGames.Gadget.DetectionBridge
namespace DFVSGames.Gadget.QuotientDetection
open Harmonic DetectionBridge
open scoped Classical
universe u v
variable {k : Type u} {B : Type v} [Field k]
variable [AddCommGroup B] [Module k B] [Finite B]
noncomputable def pullbackFullLift (s : Stage k B)
(ψ : Module.Dual k B β†’β‚—[k] Module.Dual k (StageQuotient.Space s))
(hψ : IsFullLift (StageQuotient.shift s) ψ) :
Lift s (⊀ : Submodule k (Module.Dual k B)) where
family :=
{ toFun z := (ψ z.val).comp (StageQuotient.projection s)
map_add' := by intros; ext; simp
map_smul' := by intros; ext; simp }
agrees := by
intro z h
change ψ z.val (StageQuotient.projection s (s.embed h)) = z.val (s.logical h)
rw [← StageQuotient.shift_logical]
exact hψ z.val (s.logical h)
omit [Finite B] in
theorem pullback_detection_iff (s : Stage k B)
(ψ : Module.Dual k B β†’β‚—[k] Module.Dual k (StageQuotient.Space s))
(hψ : IsFullLift (StageQuotient.shift s) ψ) (n : s.Noise) :
(βˆƒ z, (pullbackFullLift s ψ hψ).family z (s.noise n) β‰  0) ↔
βˆƒ z, ψ z (StageQuotient.noise s n) β‰  0 := by
constructor
· rintro ⟨z, hz⟩
exact ⟨z.val, hz⟩
· rintro ⟨z, hz⟩
exact ⟨⟨z, Submodule.mem_top⟩, hz⟩
omit [Finite B] in
theorem full_detection_after_quotient (s : Stage k B) [Fintype s.Noise] (q : β„š)
(hfull : βˆ€ L : Lift s (⊀ : Submodule k (Module.Dual k B)),
q ≀ probability (fun n => βˆƒ z, L.family z (s.noise n) β‰  0))
(ψ : Module.Dual k B β†’β‚—[k] Module.Dual k (StageQuotient.Space s))
(hψ : IsFullLift (StageQuotient.shift s) ψ) :
q ≀ characterDetection (StageQuotient.noise s) ψ := by
classical
have h := hfull (pullbackFullLift s ψ hψ)
simpa only [characterDetection, pullback_detection_iff] using h
omit [Finite B] in
theorem target_detection_after_quotient (s : Stage k B) [Fintype s.Noise]
{E : Type*} [AddCommGroup E] [Module k E] [DecidableEq E]
(T : StageQuotient.Space s β†’β‚—[k] E) (q : β„š)
(hfull : βˆ€ L : Lift s (⊀ : Submodule k (Module.Dual k B)),
q ≀ probability (fun n => βˆƒ z, L.family z (s.noise n) β‰  0))
(hinj : Function.Injective (T.comp (StageQuotient.shift s))) :
q ≀ probability (fun n => T (StageQuotient.noise s n) β‰  0) := by
exact target_detection_of_full_lift_bound (StageQuotient.noise s)
(StageQuotient.shift s) T q (full_detection_after_quotient s q hfull) hinj
end DFVSGames.Gadget.QuotientDetection
end OAI