math / data /lean /OAI /Computability /DirectedFeedback /Games /FinalParameters.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
34.2 kB
import Mathlib
import OAI.Computability.DirectedFeedback.Games.ActualAdviceStochasticBridge
namespace OAI
namespace DFVSGames.Integration.FinalParameters
open DFVSGames.Soundness.RepetitionUpper
def rho (r s : Nat) : β„š := (1 / 2 : β„š) ^ (s - (r + 1))
def levelConstant (r : Nat) : β„š := (r + 1 : β„š) * 2 ^ (30 * r ^ 2)
def alpha (Ξ΄ : β„š) (s : Nat) : β„š := Ξ΄ / (8 * (2 : β„š) ^ s * 2 ^ (s ^ 2))
def beta (r s : Nat) : β„š := rho r s / 2 * (1 / 2 : β„š) ^ (r * s)
def theta (Ξ΄ : β„š) (r s : Nat) : β„š := alpha Ξ΄ s * beta r s
def repetitionRate : β„š := 1 - 1 / (100000 * 192 ^ 3)
theorem levelConstant_pos (r : Nat) : 0 < levelConstant r := by
unfold levelConstant
positivity
theorem rho_pos (r s : Nat) : 0 < rho r s := by
unfold rho
positivity
theorem theta_pos {Ξ΄ : β„š} (hΞ΄ : 0 < Ξ΄) (r s : Nat) : 0 < theta Ξ΄ r s := by
unfold theta alpha beta
have := rho_pos r s
positivity
theorem repetitionRate_bounds : 0 ≀ repetitionRate ∧ repetitionRate < 1 := by
norm_num [repetitionRate]
theorem exists_symbol_dimension (r : Nat) {Ξ΄ : β„š} (hΞ΄ : 0 < Ξ΄) :
βˆƒ s : Nat, r + 1 < s ∧ βˆƒ u : β„š,
0 < u ∧ u ^ 4 = rho r s ∧ levelConstant r * u ≀ Ξ΄ / 8 := by
have hA := levelConstant_pos r
have ht : 0 < Ξ΄ / (8 * levelConstant r) := by positivity
obtain ⟨n, hn, hsmall⟩ := exists_power_lt (1 / 2 : β„š)
(Ξ΄ / (8 * levelConstant r)) (by norm_num) (by norm_num) ht
refine ⟨r + 1 + 4 * n, by omega, (1 / 2 : β„š) ^ n, by positivity, ?_, ?_⟩
Β· unfold rho
rw [Nat.add_sub_cancel_left, ← pow_mul]
congr 1
omega
Β· have hbound : (1 / 2 : β„š) ^ n * (8 * levelConstant r) < Ξ΄ :=
(lt_div_iffβ‚€ (by positivity)).mp hsmall
linarith
theorem exists_repetition_and_dimension (L q : Nat) {ΞΈ : β„š}
(hΞΈ : 0 < ΞΈ) (hq : 0 < q) :
βˆƒ t k : Nat, 0 < t ∧ t ≀ k ∧
(1 - zeroProbability L * (1 - repetitionRate)) ^ t < decoderThreshold θ q ∧
16 * (t : β„š) ^ 2 * 2 ^ (t * L) ≀ (k : β„š) * ΞΈ ^ 2 := by
obtain ⟨t, ht, hrep⟩ := exists_repetition_length L q repetitionRate θ
repetitionRate_bounds.1 repetitionRate_bounds.2 hΞΈ hq
let B : β„š := 16 * (t : β„š) ^ 2 * 2 ^ (t * L)
obtain ⟨n, hn, hlarge⟩ := exists_pos_nat_gt (B / θ ^ 2)
refine ⟨t, t + n, ht, by omega, hrep, ?_⟩
have hnlarge : B < (n : β„š) * ΞΈ ^ 2 :=
(div_lt_iffβ‚€ (by positivity)).mp hlarge
have ht0 : 0 ≀ (t : β„š) * ΞΈ ^ 2 := by positivity
dsimp [B] at hnlarge
simp only [Nat.cast_add]
nlinarith
def gamma (Ξ΅ : β„š) (k : Nat) : β„š := Ξ΅ / (4 * (k : β„š))
theorem gamma_bounds {Ξ΅ : β„š} {k : Nat}
(hΞ΅ : 0 < Ξ΅) (hΞ΅half : Ξ΅ < 1 / 2) (hk : 0 < k) :
0 < gamma Ρ k ∧ gamma Ρ k < 1 / 8 := by
have hk1 : (1 : β„š) ≀ k := by exact_mod_cast (show 1 ≀ k by omega)
unfold gamma
constructor
Β· positivity
Β· apply (div_lt_iffβ‚€ (by positivity)).2
linarith
theorem exists_source_error {Ξ³ : β„š} (hΞ³ : 0 < Ξ³) :
βˆƒ n : Nat, 0 < n ∧ 0 < (1 / 2 : β„š) ^ n ∧
(1 / 2 : β„š) ^ n ≀ 1 / 16 ∧ (1 / 2 : β„š) ^ n ≀ Ξ³ / 4 := by
have hm : 0 < min (1 / 16 : β„š) (Ξ³ / 4) := by positivity
obtain ⟨n, hn, hs⟩ := exists_power_lt (1 / 2 : β„š)
(min (1 / 16 : β„š) (Ξ³ / 4)) (by norm_num) (by norm_num) hm
exact ⟨n, hn, by positivity, le_of_lt (lt_min_iff.mp hs).1,
le_of_lt (lt_min_iff.mp hs).2⟩
theorem exists_parameters (r : Nat) {Ξ΅ Ξ΄ : β„š}
(hΞ΅ : 0 < Ξ΅) (hΞ΅half : Ξ΅ < 1 / 2) (hΞ΄ : 0 < Ξ΄) :
βˆƒ s : Nat, r + 1 < s ∧ βˆƒ u : β„š,
0 < u ∧ u ^ 4 = rho r s ∧ levelConstant r * u ≀ Ξ΄ / 8 ∧
βˆ€ L : Nat, βˆƒ t k n : Nat,
0 < t ∧ t ≀ k ∧
(1 - zeroProbability L * (1 - repetitionRate)) ^ t <
decoderThreshold (theta δ r s) (2 ^ s) ∧
16 * (t : β„š) ^ 2 * 2 ^ (t * L) ≀ (k : β„š) * (theta Ξ΄ r s) ^ 2 ∧
0 < gamma Ρ k ∧ gamma Ρ k < 1 / 8 ∧
0 < n ∧ 0 < (1 / 2 : β„š) ^ n ∧
(1 / 2 : β„š) ^ n ≀ 1 / 16 ∧
(1 / 2 : β„š) ^ n ≀ gamma Ξ΅ k / 4 := by
obtain ⟨s, hs, u, hu, hroot, hlevel⟩ := exists_symbol_dimension r hδ
refine ⟨s, hs, u, hu, hroot, hlevel, ?_⟩
intro L
obtain ⟨t, k, ht, htk, hrep, hcomp⟩ :=
exists_repetition_and_dimension L (2 ^ s) (theta_pos hΞ΄ r s) (by positivity)
have hk : 0 < k := lt_of_lt_of_le ht htk
have hΞ³ := gamma_bounds hΞ΅ hΞ΅half hk
obtain ⟨n, hn, hξ, hξ16, hξγ⟩ := exists_source_error hγ.1
exact ⟨t, k, n, ht, htk, hrep, hcomp, hγ.1, hγ.2, hn, hξ, hξ16, hξγ⟩
theorem completeness_budget {Ξ΅ : β„š} {k : Nat} (hk : 0 < k) :
(k : β„š) * gamma Ξ΅ k + (Ξ΅ / 2) / 2 = Ξ΅ / 2 := by
have hk0 : (k : β„š) β‰  0 := by exact_mod_cast (Nat.ne_of_gt hk)
unfold gamma
field_simp
ring
end DFVSGames.Integration.FinalParameters
namespace DFVSGames.Gadget.ActualGadget
abbrev F2 := ZMod 2
structure Data (C : Type) [AddCommGroup C] [Module F2 C] where
Ambient : Type
[ambientAddCommGroup : AddCommGroup Ambient]
[ambientModule : Module F2 Ambient]
[ambientFintype : Fintype Ambient]
embed : C β†’β‚—[F2] Ambient
embed_injective : Function.Injective embed
f : Ambient β†’ C
equivariant : βˆ€ x c, f (x + embed c) = f x + c
NoiseIndex : Type
[noiseFintype : Fintype NoiseIndex]
[noiseNonempty : Nonempty NoiseIndex]
noise : NoiseIndex β†’ Ambient
attribute [instance] Data.ambientAddCommGroup Data.ambientModule Data.ambientFintype
attribute [instance] Data.noiseFintype Data.noiseNonempty
variable {C : Type} [AddCommGroup C] [Module F2 C]
noncomputable def failureIndicator (g : Data C) (sample : g.Ambient Γ— g.NoiseIndex) : β„š := by
classical
exact if g.f (sample.1 + g.noise sample.2) = g.f sample.1 then 0 else 1
noncomputable def stabilityError (g : Data C) : β„š :=
Finset.univ.expect (failureIndicator g)
noncomputable def kernelIndicator (g : Data C) {P : Type}
[AddCommGroup P] [Module F2 P] (S : g.Ambient β†’β‚—[F2] P) (i : g.NoiseIndex) : β„š := by
classical
exact if S (g.noise i) = 0 then 1 else 0
noncomputable def kernelError (g : Data C) {P : Type}
[AddCommGroup P] [Module F2 P] (S : g.Ambient β†’β‚—[F2] P) : β„š :=
Finset.univ.expect (kernelIndicator g S)
theorem stabilityError_nonneg (g : Data C) : 0 ≀ stabilityError g := by
classical
apply Finset.expect_nonneg
intro sample _
unfold failureIndicator
split <;> decide
theorem stabilityError_le_one (g : Data C) : stabilityError g ≀ 1 := by
classical
apply Finset.expect_le Finset.univ_nonempty
intro sample _
unfold failureIndicator
split <;> decide
theorem kernelError_nonneg (g : Data C) {P : Type}
[AddCommGroup P] [Module F2 P] (S : g.Ambient β†’β‚—[F2] P) : 0 ≀ kernelError g S := by
classical
apply Finset.expect_nonneg
intro i _
unfold kernelIndicator
split <;> decide
theorem kernelError_le_one (g : Data C) {P : Type}
[AddCommGroup P] [Module F2 P] (S : g.Ambient β†’β‚—[F2] P) : kernelError g S ≀ 1 := by
classical
apply Finset.expect_le Finset.univ_nonempty
intro i _
unfold kernelIndicator
split <;> decide
def leaf (C : Type) [AddCommGroup C] [Module F2 C] [Fintype C] : Data C where
Ambient := C
embed := LinearMap.id
embed_injective := Function.injective_id
f := id
equivariant := by intro x c; rfl
NoiseIndex := C
noise := id
def Satisfies (g : Data C) (ΞΆ Ξ½ : β„š) (r : Nat) : Prop :=
stabilityError g ≀ ΞΆ ∧
βˆ€ (P : Type) [AddCommGroup P] [Module F2 P] (S : g.Ambient β†’β‚—[F2] P),
r ≀ Module.finrank F2 (S.comp g.embed).range β†’ kernelError g S ≀ Ξ½
def StableNonlinearDispersion : Prop :=
βˆ€ ΞΆ Ξ½ : β„š, 0 < ΞΆ β†’ ΞΆ < 1 β†’ 0 < Ξ½ β†’ Ξ½ < 1 β†’
βˆƒ r : Nat, 1 ≀ r ∧
βˆ€ s : Nat, r ≀ s β†’
βˆƒ g : Data (DFVSGames.Integration.BinaryLinear.Vector s), Satisfies g ΞΆ Ξ½ r
end DFVSGames.Gadget.ActualGadget
namespace DFVSGames.Reduction.ActualSource
open DFVSGames.Integration.BinaryLinear
structure Source where
Β«variablesΒ» : Nat
occurrences : Nat
nonempty : 0 < occurrences
equation : Fin occurrences β†’ CloneGap.Equation (Fin Β«variablesΒ»)
def Source.sourceList (S : Source) : List (CloneGap.Equation (Fin S.Β«variablesΒ»)) :=
List.ofFn S.equation
def Source.ofList {n : Nat} (es : List (CloneGap.Equation (Fin n)))
(hne : es β‰  []) : Source where
Β«variablesΒ» := n
occurrences := es.length
nonempty := List.length_pos_iff.mpr hne
equation := es.get
@[simp] theorem Source.sourceList_ofList {n : Nat}
(es : List (CloneGap.Equation (Fin n))) (hne : es β‰  []) :
(Source.ofList es hne).sourceList = es := by
exact List.ofFn_getElem
@[simp] theorem Source.sourceList_length (S : Source) :
S.sourceList.length = S.occurrences := by simp [Source.sourceList]
theorem Source.sourceList_nonempty (S : Source) : S.sourceList β‰  [] := by
intro h
have hp := S.nonempty
have hn := S.sourceList_length
rw [h] at hn
simp only [List.length_nil] at hn
omega
instance sourceIndexNonempty (S : Source) : Nonempty (Fin S.occurrences) :=
⟨⟨0, S.nonempty⟩⟩
def Source.satisfied (S : Source) (A : Fin S.Β«variablesΒ» β†’ Bool)
(i : Fin S.occurrences) : Bool := CloneGap.satisfied (S.equation i) A
def Source.failure (S : Source) (A : Fin S.Β«variablesΒ» β†’ Bool) : β„š :=
Finset.univ.expect (fun i => if S.satisfied A i then (0 : β„š) else 1)
def Source.DistinctNames (S : Source) : Prop :=
βˆ€ i, (S.equation i).first β‰  (S.equation i).second ∧
(S.equation i).first β‰  (S.equation i).third ∧
(S.equation i).second β‰  (S.equation i).third
abbrev Alphabet (s : Nat) := DFVSGames.Integration.BinaryLinear.Vector s
abbrev Ambient (s d : Nat) := Alphabet s Γ— DFVSGames.Integration.BinaryLinear.Vector d
def alphabetEmbedding (s d : Nat) : Alphabet s β†’β‚—[F2] Ambient s d :=
LinearMap.inl F2 (Alphabet s) (DFVSGames.Integration.BinaryLinear.Vector d)
@[simp] theorem alphabetEmbedding_apply (s d : Nat) (c : Alphabet s) :
alphabetEmbedding s d c = (c, 0) := rfl
structure SplitGadget (s d : Nat) where
f : Ambient s d β†’ Alphabet s
equivariant : βˆ€ (x : Ambient s d) (c : Alphabet s), f (x + (c, 0)) = f x + c
NoiseIndex : Type
noiseFintype : Fintype NoiseIndex
noiseNonempty : Nonempty NoiseIndex
noise : NoiseIndex β†’ Ambient s d
attribute [instance] SplitGadget.noiseFintype SplitGadget.noiseNonempty
def SplitGadget.stabilityError {s d : Nat} (g : SplitGadget s d) : β„š :=
Finset.univ.expect (fun xv : Ambient s d Γ— g.NoiseIndex =>
if g.f (xv.1 + g.noise xv.2) = g.f xv.1 then (0 : β„š) else 1)
def SplitGadget.kernelError {s d p : Nat} (g : SplitGadget s d)
(S : Ambient s d β†’β‚—[F2] DFVSGames.Integration.BinaryLinear.Vector p) : β„š :=
Finset.univ.expect (fun i => if S (g.noise i) = 0 then (1 : β„š) else 0)
theorem SplitGadget.stabilityError_nonneg {s d : Nat} (g : SplitGadget s d) :
0 ≀ g.stabilityError := by
apply Finset.expect_nonneg
intro x _
split <;> norm_num
theorem SplitGadget.stabilityError_le_one {s d : Nat} (g : SplitGadget s d) :
g.stabilityError ≀ 1 := by
apply Finset.expect_le Finset.univ_nonempty
intro x _
split <;> norm_num
end DFVSGames.Reduction.ActualSource
namespace DFVSGames.Integration.SplitGadget
open BinaryLinear
variable {R : Type} [AddCommGroup R] [Module F2 R] [FiniteDimensional F2 R]
theorem exists_split_equiv {s : Nat} (e : Vector s β†’β‚—[F2] R)
(he : Function.Injective e) :
βˆƒ d : Nat, βˆƒ Ο† : R ≃ₗ[F2] (Vector s Γ— Vector d),
βˆ€ c, Ο† (e c) = (c, 0) := by
obtain ⟨U, hU⟩ := e.range.exists_isCompl
let er := LinearEquiv.ofInjective e he
let eu := (Module.finBasis F2 U).equivFun
let split := e.range.prodEquivOfIsCompl U hU
refine ⟨Module.finrank F2 U, split.symm.trans (er.symm.prodCongr eu), ?_⟩
intro c
change (er.symm.prodCongr eu) (split.symm (e c)) = (c, 0)
have hc : split.symm (e c) = (er c, 0) :=
e.range.prodEquivOfIsCompl_symm_apply_left U hU (er c)
rw [hc]
simp
open DFVSGames.Gadget.ActualGadget (Data stabilityError failureIndicator kernelError Satisfies)
open DFVSGames.Reduction.ActualSource
noncomputable def kernelProbability {s d : Nat} (g : SplitGadget s d)
{P : Type} [AddCommGroup P] [Module F2 P]
(S : Ambient s d β†’β‚—[F2] P) : β„š := by
classical
exact Finset.univ.expect (fun i => if S (g.noise i) = 0 then (1 : β„š) else 0)
theorem kernelProbability_eq_kernelError {s d p : Nat} (g : SplitGadget s d)
(S : Ambient s d β†’β‚—[F2] Vector p) :
kernelProbability g S = g.kernelError S := by
unfold kernelProbability SplitGadget.kernelError
congr 1
funext i
by_cases h : S (g.noise i) = 0 <;> simp_all
noncomputable def transport {s d : Nat} (g : Data (Vector s))
(Ο† : g.Ambient ≃ₗ[F2] Ambient s d)
(he : βˆ€ c, Ο† (g.embed c) = (c, 0)) : SplitGadget s d where
f x := g.f (Ο†.symm x)
equivariant x c := by
have hc : Ο†.symm (c, 0) = g.embed c := by rw [← he c]; simp
rw [map_add, hc]
exact g.equivariant (Ο†.symm x) c
NoiseIndex := g.NoiseIndex
noiseFintype := g.noiseFintype
noiseNonempty := g.noiseNonempty
noise i := Ο† (g.noise i)
theorem transport_stabilityError {s d : Nat} (g : Data (Vector s))
(Ο† : g.Ambient ≃ₗ[F2] Ambient s d)
(he : βˆ€ c, Ο† (g.embed c) = (c, 0)) :
(transport g Ο† he).stabilityError = stabilityError g := by
classical
apply Fintype.expect_equiv (Ο†.symm.toEquiv.prodCongr (Equiv.refl g.NoiseIndex))
intro x
simp [transport, failureIndicator, map_add]
theorem transport_kernelError {s d p : Nat} (g : Data (Vector s))
(Ο† : g.Ambient ≃ₗ[F2] Ambient s d)
(he : βˆ€ c, Ο† (g.embed c) = (c, 0))
(S : Ambient s d β†’β‚—[F2] Vector p) :
(transport g Ο† he).kernelError S = kernelError g (S.comp Ο†.toLinearMap) := by
unfold SplitGadget.kernelError kernelError Gadget.ActualGadget.kernelIndicator
congr 1
funext i
by_cases h : S (Ο† (g.noise i)) = 0 <;> simp_all [transport]
theorem transport_symbol_map {s d : Nat} (g : Data (Vector s))
(Ο† : g.Ambient ≃ₗ[F2] Ambient s d)
(he : βˆ€ c, Ο† (g.embed c) = (c, 0))
{P : Type} [AddCommGroup P] [Module F2 P]
(S : Ambient s d β†’β‚—[F2] P) :
(S.comp Ο†.toLinearMap).comp g.embed = S.comp (alphabetEmbedding s d) := by
apply LinearMap.ext
intro c
change S (Ο† (g.embed c)) = S (c, 0)
rw [he]
theorem transport_kernelProbability {s d : Nat} (g : Data (Vector s))
(Ο† : g.Ambient ≃ₗ[F2] Ambient s d)
(he : βˆ€ c, Ο† (g.embed c) = (c, 0))
{P : Type} [AddCommGroup P] [Module F2 P]
(S : Ambient s d β†’β‚—[F2] P) :
kernelProbability (transport g Ο† he) S =
kernelError g (S.comp Ο†.toLinearMap) := by
rfl
theorem transport_satisfies {s d : Nat} (g : Data (Vector s))
(Ο† : g.Ambient ≃ₗ[F2] Ambient s d)
(he : βˆ€ c, Ο† (g.embed c) = (c, 0))
{ΞΆ Ξ½ : β„š} {r : Nat} (hg : Satisfies g ΞΆ Ξ½ r) :
(transport g Ο† he).stabilityError ≀ ΞΆ ∧
βˆ€ p (S : Ambient s d β†’β‚—[F2] Vector p),
r ≀ Module.finrank F2 (S.comp (alphabetEmbedding s d)).range β†’
(transport g Ο† he).kernelError S ≀ Ξ½ := by
constructor
Β· rw [transport_stabilityError]
exact hg.1
Β· intro p S hS
rw [transport_kernelError g Ο† he S]
apply hg.2 (Vector p) (S.comp Ο†.toLinearMap)
rwa [transport_symbol_map g Ο† he S]
theorem exists_split_gadget {s : Nat} (g : Data (Vector s))
{ΞΆ Ξ½ : β„š} {r : Nat} (hg : Satisfies g ΞΆ Ξ½ r) :
βˆƒ d : Nat, βˆƒ h : SplitGadget s d,
h.stabilityError ≀ ΞΆ ∧
βˆ€ p (S : Ambient s d β†’β‚—[F2] Vector p),
r ≀ Module.finrank F2 (S.comp (alphabetEmbedding s d)).range β†’
h.kernelError S ≀ Ξ½ := by
obtain ⟨d, Ο†, he⟩ := exists_split_equiv g.embed g.embed_injective
exact ⟨d, transport g Ο† he, transport_satisfies g Ο† he hg⟩
theorem exists_split_gadget_general {s : Nat} (g : Data (Vector s))
{ΞΆ Ξ½ : β„š} {r : Nat} (hg : Satisfies g ΞΆ Ξ½ r) :
βˆƒ d : Nat, βˆƒ h : SplitGadget s d,
h.stabilityError ≀ ΞΆ ∧
βˆ€ (P : Type) [AddCommGroup P] [Module F2 P]
(S : Ambient s d β†’β‚—[F2] P),
r ≀ Module.finrank F2 (S.comp (alphabetEmbedding s d)).range β†’
kernelProbability h S ≀ Ξ½ := by
obtain ⟨d, Ο†, he⟩ := exists_split_equiv g.embed g.embed_injective
refine ⟨d, transport g Ο† he, ?_, ?_⟩
Β· rw [transport_stabilityError]
exact hg.1
Β· intro P _ _ S hS
rw [transport_kernelProbability g Ο† he S]
apply hg.2 P (S.comp Ο†.toLinearMap)
rwa [transport_symbol_map g Ο† he S]
end DFVSGames.Integration.SplitGadget
namespace DFVSGames.Integration.RealBounds
open BinaryLinear FinalParameters
theorem rho_eq_two_div_pow {r s : Nat} (hs : r + 1 ≀ s) :
rho r s = 2 / (2 : β„š) ^ (s - r) := by
have hn : s - r = (s - (r + 1)) + 1 := by omega
unfold rho
rw [hn, pow_succ, div_pow, one_pow]
field_simp
theorem rho_real_eq_two_div_pow {r s : Nat} (hs : r + 1 ≀ s) :
(rho r s : ℝ) = 2 / (2 : ℝ) ^ (s - r) := by
simpa using congrArg (fun q : β„š => (q : ℝ)) (rho_eq_two_div_pow hs)
theorem beta_eq_div (r s : Nat) :
beta r s = rho r s / (2 * (2 : β„š) ^ (r * s)) := by
unfold beta
rw [div_pow, one_pow]
ring
theorem theta_real_product (Ξ΄ : β„š) (r s : Nat) :
(theta Ξ΄ r s : ℝ) =
((Ξ΄ : ℝ) / (8 * (2 : ℝ) ^ s * 2 ^ (s * s))) *
((rho r s : ℝ) / (2 * (2 : ℝ) ^ (r * s))) := by
simp [theta, alpha, beta_eq_div, pow_two]
theorem fourth_root_as_rpow {u ρ : β„š} (hu : 0 < u) (hfour : u ^ 4 = ρ) :
(ρ : ℝ) ^ (1 / 4 : ℝ) = (u : ℝ) := by
have hpow : (u : ℝ) ^ 4 = (ρ : ℝ) := by exact_mod_cast hfour
have hu' : (0 : ℝ) ≀ u := by exact_mod_cast (le_of_lt hu)
rw [← hpow, one_div]
exact Real.pow_rpow_inv_natCast hu' (by decide : (4 : Nat) β‰  0)
theorem exists_symbol_dimension_real (r : Nat) {Ξ΄ : β„š} (hΞ΄ : 0 < Ξ΄) :
βˆƒ s : Nat, r + 1 < s ∧
(levelConstant r : ℝ) * (rho r s : ℝ) ^ (1 / 4 : ℝ) ≀ (Ξ΄ : ℝ) / 8 := by
obtain ⟨s, hs, u, hu, hfour, hbound⟩ := exists_symbol_dimension r hδ
refine ⟨s, hs, ?_⟩
rw [fourth_root_as_rpow hu hfour]
exact_mod_cast hbound
theorem kernelProbability_real {s d : Nat}
(g : DFVSGames.Reduction.ActualSource.SplitGadget s d)
{P : Type} [AddCommGroup P] [Module F2 P] [DecidableEq P]
(S : (Vector s Γ— Vector d) β†’β‚—[F2] P) :
(SplitGadget.kernelProbability g S : ℝ) =
Finset.univ.expect (fun i => if S (g.noise i) = 0 then (1 : ℝ) else 0) := by
classical
unfold SplitGadget.kernelProbability
simp only [Finset.expect_eq_sum_div_card, Rat.cast_div, Rat.cast_sum, Rat.cast_natCast]
congr 1
apply Finset.sum_congr rfl
intro i _
by_cases h : S (g.noise i) = 0 <;> simp [h]
theorem kernelProbability_real_le {s d : Nat}
(g : DFVSGames.Reduction.ActualSource.SplitGadget s d)
{P : Type} [AddCommGroup P] [Module F2 P] [DecidableEq P]
(S : (Vector s Γ— Vector d) β†’β‚—[F2] P) {Ξ½ : β„š}
(h : SplitGadget.kernelProbability g S ≀ Ξ½) :
Finset.univ.expect (fun i => if S (g.noise i) = 0 then (1 : ℝ) else 0) ≀ (Ξ½ : ℝ) := by
classical
rw [← kernelProbability_real g S]
exact_mod_cast h
theorem comparison_square_budget {t k L : Nat} {ΞΈ : β„š} (hk : 0 < k)
(h : 16 * (t : β„š) ^ 2 * 2 ^ (t * L) ≀ (k : β„š) * ΞΈ ^ 2) :
((t : ℝ) ^ 2 / (k : ℝ)) * 2 ^ (t * L) ≀ ((ΞΈ : ℝ) / 4) ^ 2 := by
have hk' : (0 : ℝ) < k := by exact_mod_cast hk
have h' : 16 * (t : ℝ) ^ 2 * 2 ^ (t * L) ≀ (k : ℝ) * (ΞΈ : ℝ) ^ 2 := by
exact_mod_cast h
rw [div_mul_eq_mul_div, div_le_iffβ‚€ hk']
nlinarith
end DFVSGames.Integration.RealBounds
namespace DFVSGames.Soundness.ActualMapComparison
open LinearMapDensity PartnerProjection PartnerSampling
theorem actual_partner_expectation_comparison {k t : β„•}
(hk : 0 < k) (htk : t ≀ k) (rhs : Fin k β†’ Bool)
{R : Type} [AddCommGroup R] [Module (ZMod 2) R] [FiniteDimensional (ZMod 2) R]
[Fintype (SourcePoint rhs β†’β‚—[ZMod 2] R)]
[βˆ€ p : Partner k t, Fintype (PartnerPoint rhs (active p) β†’β‚—[ZMod 2] R)]
(H : (SourcePoint rhs β†’β‚—[ZMod 2] R) β†’ ℝ) (hH : βˆ€ M, |H M| ≀ 1) :
|uniformMean (fun p : Partner k t =>
uniformMean (fun B : PartnerPoint rhs (active p) β†’β‚—[ZMod 2] R =>
H (B.comp (PartnerLinear.projection rhs (active p) (slots p))))) - uniformMean H| ≀
Real.sqrt (((t : ℝ)^2 / k) * (2 : ℝ)^(Module.finrank (ZMod 2) R * t)) := by
let : Nonempty (Partner k t) := partner_nonempty htk
have hsecond :
uniformMean (fun M : SourcePoint rhs β†’β‚—[ZMod 2] R =>
(mixtureDensity (kernel (t := t) rhs) M)^2) ≀
1 + ((t : ℝ)^2 / k) * (2 : ℝ)^(Module.finrank (ZMod 2) R * t) := by
rw [mixtureDensity_second_moment]
exact kernel_overlap_weight_le hk htk rhs (Module.finrank (ZMod 2) R)
have hc := ExpectationComparison.bounded_test_expectation_comparison
Finset.univ Finset.univ_nonempty (mixtureDensity (R := R) (kernel (t := t) rhs)) H
(((t : ℝ)^2 / k) * (2 : ℝ)^(Module.finrank (ZMod 2) R * t))
(mixtureDensity_mean (R := R) (kernel (t := t) rhs)) hsecond (fun M _ => hH M)
rw [mixture_pullback_uniformMean
(fun p : Partner k t => PartnerLinear.projection rhs (active p) (slots p))
(fun p => PartnerLinear.projection_surjective rhs (active p) (slots p)) H]
have hkernel : kernel (t := t) rhs =
(fun p : Partner k t => (PartnerLinear.projection rhs (active p) (slots p)).ker) := rfl
rw [hkernel] at hc
simpa only [uniformMean, mul_comm] using hc
theorem actual_partner_expectation_comparison_dimension {k t L : β„•}
(hk : 0 < k) (htk : t ≀ k) (rhs : Fin k β†’ Bool)
{R : Type} [AddCommGroup R] [Module (ZMod 2) R] [FiniteDimensional (ZMod 2) R]
[Fintype (SourcePoint rhs β†’β‚—[ZMod 2] R)]
[βˆ€ p : Partner k t, Fintype (PartnerPoint rhs (active p) β†’β‚—[ZMod 2] R)]
(H : (SourcePoint rhs β†’β‚—[ZMod 2] R) β†’ ℝ) (hH : βˆ€ M, |H M| ≀ 1)
(hm : Module.finrank (ZMod 2) R ≀ L) :
|uniformMean (fun p : Partner k t =>
uniformMean (fun B : PartnerPoint rhs (active p) β†’β‚—[ZMod 2] R =>
H (B.comp (PartnerLinear.projection rhs (active p) (slots p))))) - uniformMean H| ≀
Real.sqrt (((t : ℝ)^2 / k) * (2 : ℝ)^(t * L)) := by
have he : Module.finrank (ZMod 2) R * t ≀ t * L := by
simpa only [Nat.mul_comm] using Nat.mul_le_mul_right t hm
have hp : (2 : ℝ)^(Module.finrank (ZMod 2) R * t) ≀ (2 : ℝ)^(t*L) :=
pow_le_pow_rightβ‚€ (by norm_num) he
exact (actual_partner_expectation_comparison hk htk rhs H hH).trans
(Real.sqrt_le_sqrt (mul_le_mul_of_nonneg_left hp
(div_nonneg (sq_nonneg (t : ℝ)) (Nat.cast_nonneg k))))
theorem actual_partner_expectation_quarter {k t L : β„•} {ΞΈ : β„š}
(hk : 0 < k) (htk : t ≀ k) (rhs : Fin k β†’ Bool)
{R : Type} [AddCommGroup R] [Module (ZMod 2) R] [FiniteDimensional (ZMod 2) R]
[Fintype (SourcePoint rhs β†’β‚—[ZMod 2] R)]
[βˆ€ p : Partner k t, Fintype (PartnerPoint rhs (active p) β†’β‚—[ZMod 2] R)]
(H : (SourcePoint rhs β†’β‚—[ZMod 2] R) β†’ ℝ) (hH : βˆ€ M, |H M| ≀ 1)
(hm : Module.finrank (ZMod 2) R ≀ L) (hΞΈ : 0 ≀ ΞΈ)
(budget : 16 * (t : β„š)^2 * 2^(t*L) ≀ (k : β„š)*ΞΈ^2) :
|uniformMean (fun p : Partner k t =>
uniformMean (fun B : PartnerPoint rhs (active p) β†’β‚—[ZMod 2] R =>
H (B.comp (PartnerLinear.projection rhs (active p) (slots p))))) - uniformMean H| ≀
(ΞΈ : ℝ) / 4 :=
(actual_partner_expectation_comparison_dimension hk htk rhs H hH hm).trans
(ExpectationComparison.comparison_error_le_quarter _ _ (by exact_mod_cast hΞΈ)
(Integration.RealBounds.comparison_square_budget hk budget))
end DFVSGames.Soundness.ActualMapComparison
namespace DFVSGames.Soundness.ActualMapComparison
def sourcePrecomposeEquiv {A E R : Type}
[AddCommGroup A] [Module (ZMod 2) A] [AddCommGroup E] [Module (ZMod 2) E]
[AddCommGroup R] [Module (ZMod 2) R] (e : A ≃ₗ[ZMod 2] E) :
(E β†’β‚—[ZMod 2] R) ≃ (A β†’β‚—[ZMod 2] R) where
toFun M := M.comp e.toLinearMap
invFun M := M.comp e.symm.toLinearMap
left_inv M := by
apply LinearMap.ext
intro x
change M (e (e.symm x)) = M x
rw [e.apply_symm_apply]
right_inv M := by
apply LinearMap.ext
intro x
change M (e.symm (e x)) = M x
rw [e.symm_apply_apply]
theorem uniformMean_sourcePrecompose {A E R : Type}
[AddCommGroup A] [Module (ZMod 2) A] [AddCommGroup E] [Module (ZMod 2) E]
[AddCommGroup R] [Module (ZMod 2) R]
[Fintype (A β†’β‚—[ZMod 2] R)] [Fintype (E β†’β‚—[ZMod 2] R)]
(e : A ≃ₗ[ZMod 2] E) (H : (E β†’β‚—[ZMod 2] R) β†’ ℝ) :
LinearMapDensity.uniformMean (fun M : A β†’β‚—[ZMod 2] R =>
H (M.comp e.symm.toLinearMap)) = LinearMapDensity.uniformMean H := by
simpa only [LinearMapDensity.uniformMean] using
(Fintype.expect_equiv (sourcePrecomposeEquiv e).symm
(fun M : A β†’β‚—[ZMod 2] R => H (M.comp e.symm.toLinearMap)) H (fun _ => rfl))
theorem actual_partner_expectation_quarter_equiv {k t L : β„•} {ΞΈ : β„š}
(hk : 0 < k) (htk : t ≀ k) (rhs : Fin k β†’ Bool)
{R E : Type} [AddCommGroup R] [Module (ZMod 2) R] [FiniteDimensional (ZMod 2) R]
[AddCommGroup E] [Module (ZMod 2) E]
[Fintype (PartnerProjection.SourcePoint rhs β†’β‚—[ZMod 2] R)]
[Fintype (E β†’β‚—[ZMod 2] R)]
[βˆ€ p : PartnerSampling.Partner k t,
Fintype (PartnerProjection.PartnerPoint rhs (PartnerSampling.active p) β†’β‚—[ZMod 2] R)]
(e : PartnerProjection.SourcePoint rhs ≃ₗ[ZMod 2] E)
(H : (E β†’β‚—[ZMod 2] R) β†’ ℝ) (hH : βˆ€ M, |H M| ≀ 1)
(hm : Module.finrank (ZMod 2) R ≀ L) (hΞΈ : 0 ≀ ΞΈ)
(budget : 16 * (t : β„š)^2 * 2^(t*L) ≀ (k : β„š) * ΞΈ^2) :
|LinearMapDensity.uniformMean (fun p : PartnerSampling.Partner k t =>
LinearMapDensity.uniformMean (fun B :
PartnerProjection.PartnerPoint rhs (PartnerSampling.active p) β†’β‚—[ZMod 2] R =>
H (B.comp ((PartnerLinear.projection rhs (PartnerSampling.active p)
(PartnerSampling.slots p)).comp e.symm.toLinearMap)))) -
LinearMapDensity.uniformMean H| ≀ (ΞΈ : ℝ) / 4 := by
let Hcanon : (PartnerProjection.SourcePoint rhs β†’β‚—[ZMod 2] R) β†’ ℝ :=
fun M => H (M.comp e.symm.toLinearMap)
have hcanon := actual_partner_expectation_quarter hk htk rhs Hcanon
(fun M => hH (M.comp e.symm.toLinearMap)) hm hΞΈ budget
have hmean : LinearMapDensity.uniformMean Hcanon = LinearMapDensity.uniformMean H :=
uniformMean_sourcePrecompose e H
rw [hmean] at hcanon
simpa only [Hcanon, LinearMap.comp_assoc] using hcanon
end DFVSGames.Soundness.ActualMapComparison
namespace DFVSGames.Soundness.RawTargetLaw
open scoped BigOperators
open DFVSGames.Integration.BinaryLinear (F2)
open DFVSGames.Reduction
open PartnerProjection PartnerMapCoordinates RawPartnerTarget
theorem partnerProjection_congr_slots {k : Nat} (rhs : Fin k β†’ Bool)
(J : Finset (Fin k)) (slot slot' : Fin k β†’ Slot)
(agree : βˆ€ j ∈ J, slot j = slot' j) :
PartnerLinear.projection rhs (activeOf J) slot =
PartnerLinear.projection rhs (activeOf J) slot' := by
apply PartnerFullSampling.projection_eq_of_slots_eq_on_active
intro j hj
exact agree j (by simpa [activeOf] using hj)
theorem rawProjection_congr_slots {k : Nat} (rhs : Fin k β†’ Bool)
(J : Finset (Fin k)) (slot slot' : Fin k β†’ Slot)
(agree : βˆ€ j ∈ J, slot j = slot' j) :
RawPartnerTarget.rawProjection rhs J slot =
RawPartnerTarget.rawProjection rhs J slot' := by
unfold RawPartnerTarget.rawProjection
rw [partnerProjection_congr_slots rhs J slot slot' agree]
theorem precompose_rawProjection {k : Nat} (rhs : Fin k β†’ Bool)
(J : Finset (Fin k)) (slot : Fin k β†’ Slot)
{R : Type} [AddCommGroup R] [Module F2 R]
(M : RawPoint J β†’β‚—[F2] R) :
(M.comp (pointEquiv rhs J).toLinearMap).comp
((PartnerLinear.projection rhs (activeOf J) slot).comp
(PartnerLinear.sourceLinearEquiv rhs).symm.toLinearMap) =
M.comp (RawPartnerTarget.rawProjection rhs J slot) := by
simp only [RawPartnerTarget.rawProjection, LinearMap.comp_assoc]
theorem partner_row_column_expectation {k : Nat} (rhs : Fin k β†’ Bool)
(J : Finset (Fin k)) (slot : Fin k β†’ Slot)
{D C : Type} [AddCommGroup D] [Module F2 D] [AddCommGroup C] [Module F2 C]
[Fintype (PartnerPoint rhs (activeOf J) β†’β‚—[F2] D)]
[Fintype (PartnerPoint rhs (activeOf J) β†’β‚—[F2] C)]
[Fintype (RawPoint J β†’β‚—[F2] D)] [Fintype (RawPoint J β†’β‚—[F2] C)]
(H : (ActualHomogeneous.E k β†’β‚—[F2] D) β†’
(ActualHomogeneous.E k β†’β‚—[F2] C) β†’ ℝ) :
(𝔼 Z : PartnerPoint rhs (activeOf J) β†’β‚—[F2] D,
𝔼 X : PartnerPoint rhs (activeOf J) β†’β‚—[F2] C,
let pi := (PartnerLinear.projection rhs (activeOf J) slot).comp
(PartnerLinear.sourceLinearEquiv rhs).symm.toLinearMap
H (Z.comp pi) (X.comp pi)) =
(𝔼 Z : RawPoint J β†’β‚—[F2] D, 𝔼 X : RawPoint J β†’β‚—[F2] C,
H (Z.comp (RawPartnerTarget.rawProjection rhs J slot))
(X.comp (RawPartnerTarget.rawProjection rhs J slot))) := by
symm
apply Fintype.expect_equiv
(ActualMapComparison.sourcePrecomposeEquiv (R := D) (pointEquiv rhs J))
intro Z
apply Fintype.expect_equiv
(ActualMapComparison.sourcePrecomposeEquiv (R := C) (pointEquiv rhs J))
intro X
change H (Z.comp (RawPartnerTarget.rawProjection rhs J slot))
(X.comp (RawPartnerTarget.rawProjection rhs J slot)) =
H ((Z.comp (pointEquiv rhs J).toLinearMap).comp
((PartnerLinear.projection rhs (activeOf J) slot).comp
(PartnerLinear.sourceLinearEquiv rhs).symm.toLinearMap))
((X.comp (pointEquiv rhs J).toLinearMap).comp
((PartnerLinear.projection rhs (activeOf J) slot).comp
(PartnerLinear.sourceLinearEquiv rhs).symm.toLinearMap))
simp only [precompose_rawProjection]
end DFVSGames.Soundness.RawTargetLaw
namespace DFVSGames.Soundness.UniformPartition
open scoped BigOperators
noncomputable section
def mean {Ξ© : Type} [Fintype Ξ©] (g : Ξ© β†’ ℝ) : ℝ :=
(βˆ‘ Ο‰, g Ο‰) / Fintype.card Ξ©
theorem mean_equiv {Ξ© Ξ“ : Type} [Fintype Ξ©] [Fintype Ξ“]
(e : Ξ© ≃ Ξ“) (g : Ξ“ β†’ ℝ) : mean (fun Ο‰ => g (e Ο‰)) = mean g := by
unfold mean
rw [e.sum_comp, Fintype.card_congr e]
def fiberSum {Ξ© H : Type} [Fintype Ξ©] [DecidableEq H]
(f : Ξ© β†’ H) (h : H) (g : Ξ© β†’ ℝ) : ℝ :=
βˆ‘ Ο‰, if f Ο‰ = h then g Ο‰ else 0
def fiberSize {Ξ© H : Type} [Fintype Ξ©] [DecidableEq H]
(f : Ξ© β†’ H) (h : H) : ℝ := fiberSum f h (fun _ => 1)
theorem fiberSize_eq_card {Ξ© H : Type} [Fintype Ξ©] [DecidableEq H]
(f : Ξ© β†’ H) (h : H) :
fiberSize f h = ((Finset.univ.filter (fun Ο‰ => f Ο‰ = h)).card : ℝ) := by
classical
unfold fiberSize fiberSum
rw [← Finset.sum_filter]
simp
theorem sum_fiberSum {Ξ© H : Type} [Fintype Ξ©] [Fintype H] [DecidableEq H]
(f : Ξ© β†’ H) (g : Ξ© β†’ ℝ) :
(βˆ‘ h, fiberSum f h g) = βˆ‘ Ο‰, g Ο‰ := by
unfold fiberSum
rw [Finset.sum_comm]
apply Finset.sum_congr rfl
intro Ο‰ _
simp
theorem fiberSize_mul {Ξ© H : Type} [Fintype Ξ©] [DecidableEq H]
(f : Ξ© β†’ H) (b : H β†’ ℝ) (h : H) :
fiberSize f h * b h = fiberSum f h (fun Ο‰ => b (f Ο‰)) := by
unfold fiberSize fiberSum
rw [Finset.sum_mul]
apply Finset.sum_congr rfl
intro Ο‰ _
by_cases hω : f ω = h <;> simp [hω]
theorem fiberSize_pos {Ξ© H : Type} [Fintype Ξ©] [DecidableEq H]
(f : Ξ© β†’ H) (h : H) (hh : βˆƒ Ο‰, f Ο‰ = h) : 0 < fiberSize f h := by
classical
obtain βŸ¨Ο‰, hΟ‰βŸ© := hh
rw [fiberSize_eq_card]
have hc : 0 < (Finset.univ.filter (fun Ο‰ => f Ο‰ = h)).card :=
Finset.card_pos.mpr βŸ¨Ο‰, by simp [hΟ‰]⟩
exact_mod_cast hc
theorem fiberSize_mul_conditional {Ξ© H : Type} [Fintype Ξ©] [DecidableEq H]
(f : Ξ© β†’ H) (g : Ξ© β†’ ℝ) (h : H) :
fiberSize f h * (fiberSum f h g / fiberSize f h) = fiberSum f h g := by
classical
by_cases hh : βˆƒ Ο‰, f Ο‰ = h
Β· have hn : fiberSize f h β‰  0 := ne_of_gt (fiberSize_pos f h hh)
field_simp [hn]
Β· have hz : βˆ€ Ο‰, f Ο‰ β‰  h := fun Ο‰ hΟ‰ => hh βŸ¨Ο‰, hΟ‰βŸ©
simp [fiberSize, fiberSum, hz]
theorem total_mean {Ξ© H : Type} [Fintype Ξ©] [Fintype H] [DecidableEq H]
(f : Ξ© β†’ H) (g : Ξ© β†’ ℝ) :
mean g = mean (fun Ο‰ => fiberSum f (f Ο‰) g / fiberSize f (f Ο‰)) := by
let b : H β†’ ℝ := fun h => fiberSum f h g / fiberSize f h
change mean g = mean (fun Ο‰ => b (f Ο‰))
unfold mean
apply congrArg (fun x : ℝ => x / (Fintype.card Ξ© : ℝ))
calc
(βˆ‘ Ο‰, g Ο‰) = βˆ‘ h, fiberSum f h g := (sum_fiberSum f g).symm
_ = βˆ‘ h, fiberSize f h * b h := by
apply Finset.sum_congr rfl
intro h _
exact (fiberSize_mul_conditional f g h).symm
_ = βˆ‘ h, fiberSum f h (fun Ο‰ => b (f Ο‰)) := by
apply Finset.sum_congr rfl
intro h _
exact fiberSize_mul f b h
_ = βˆ‘ Ο‰, b (f Ο‰) := sum_fiberSum f (fun Ο‰ => b (f Ο‰))
theorem mean_mono {Ξ© : Type} [Fintype Ξ©] {g g' : Ξ© β†’ ℝ}
(h : βˆ€ Ο‰, g Ο‰ ≀ g' Ο‰) : mean g ≀ mean g' := by
exact div_le_div_of_nonneg_right (Finset.sum_le_sum (fun Ο‰ _ => h Ο‰)) (Nat.cast_nonneg _)
theorem mean_le_partition_bound {Ξ© H : Type}
[Fintype Ξ©] [Fintype H] [DecidableEq H]
(f : Ξ© β†’ H) (g : Ξ© β†’ ℝ) (bound : H β†’ ℝ)
(hlocal : βˆ€ h, (βˆƒ Ο‰, f Ο‰ = h) β†’
fiberSum f h g / fiberSize f h ≀ bound h) :
mean g ≀ mean (fun Ο‰ => bound (f Ο‰)) := by
calc
mean g = mean (fun Ο‰ => fiberSum f (f Ο‰) g / fiberSize f (f Ο‰)) := total_mean f g
_ ≀ mean (fun Ο‰ => bound (f Ο‰)) := mean_mono (fun Ο‰ => hlocal (f Ο‰) βŸ¨Ο‰,rfl⟩)
theorem fiber_conditional_eq_subtype_mean {Ξ© H : Type}
[Fintype Ξ©] [DecidableEq H] (f : Ξ© β†’ H) (h : H) (g : Ξ© β†’ ℝ) :
fiberSum f h g / fiberSize f h =
mean (fun Ο‰ : {Ο‰ // f Ο‰ = h} => g Ο‰.val) := by
classical
simp only [fiberSum, fiberSize, mean]
congr 1
Β· rw [← Finset.sum_filter]
exact Finset.sum_subtype _ (fun Ο‰ => by simp) g
Β· rw [← Finset.sum_filter]
simp [Fintype.card_subtype]
end
end DFVSGames.Soundness.UniformPartition
end OAI