math / data /lean /OAI /Computability /MinUncut /Estimates /ListDecoding.lean
introvoyz045's picture
Migrated from GitHub
4a56cd6 verified
Raw History Blame Contribute Delete
8.52 kB
import Mathlib
import OAI.Computability.MinUncut.Games.HintSoundness
namespace OAI
noncomputable section
open scoped BigOperators
namespace MinUncut.Outer
open MinUncut.Inner
attribute [local instance] Classical.propDecidable BinaryFourier.dualFintype
def paddedChoice {A : Type*} [Nonempty A] (S : Finset A) {L : β„•} (i : Fin L) : A :=
if h : i.val<S.card then ((Finset.equivFin S).symm ⟨i.val,h⟩).val else Classical.ofNonempty
lemma paddedChoice_covers {A : Type*} [Nonempty A] (S : Finset A) {L : β„•}
(hS : S.card≀L) (a : A) (ha : a ∈ S) : βˆƒ i : Fin L, paddedChoice S i=a := by
let j := (Finset.equivFin S) ⟨a,ha⟩
let i : Fin L := ⟨j.val,j.isLt.trans_le hS⟩
refine ⟨i,?_⟩
simp only [paddedChoice,i,dite_eq_left j.isLt]
exact congrArg Subtype.val ((Finset.equivFin S).symm_apply_apply ⟨a,ha⟩)
variable {Name I : Type*} [Fintype I]
structure HintLists (Name I : Type*) [Fintype I] (q : β„•) where
first : (U : I β†’ Equation Name) β†’ (Fin q β†’ Forms (FirstAlphabet U)) β†’ Finset (FirstAlphabet U)
second : (V : I β†’ SecondQuestion Name) β†’ (Fin q β†’ Forms (SecondAlphabet V)) β†’ Finset (SecondAlphabet V)
def HintLists.strategy {q L R : β„•} (lists : HintLists Name I q) (z : Fin L Γ— Fin R) :
HintedStrategy Name I q where
first U B := paddedChoice (lists.first U B) z.1
second V B := paddedChoice (lists.second V B) z.2
def HintLists.matches {q : β„•} (lists : HintLists Name I q)
(U : I β†’ Equation Name) (hidden : I β†’ Bool) (pos : I β†’ Fin 3)
(B : Fin q β†’ Forms (SecondAlphabet (secondQuestion U hidden pos))) : Prop :=
βˆƒ a ∈ lists.first U (fun j => formPullback (projection U hidden pos) (B j)),
βˆƒ b ∈ lists.second (secondQuestion U hidden pos) B, projection U hidden pos a=b
lemma HintLists.matching_le_sum {q L R : β„•} (lists : HintLists Name I q)
(hL : βˆ€ U B, (lists.first U B).card≀L)
(hR : βˆ€ V B, (lists.second V B).card≀R)
(U : I β†’ Equation Name) (hidden : I β†’ Bool) (pos : I β†’ Fin 3)
(B : Fin q β†’ Forms (SecondAlphabet (secondQuestion U hidden pos))) :
(if lists.matches U hidden pos B then (1 : ℝ) else 0) ≀
βˆ‘ z : Fin L Γ— Fin R, if hintedAcceptance (lists.strategy z) U hidden pos B then 1 else 0 := by
classical
by_cases hm : lists.matches U hidden pos B
Β· rw [ite_eq_left hm]
obtain ⟨a,ha,b,hb,hab⟩ := hm
obtain ⟨i,hi⟩ := paddedChoice_covers _ (hL _ _) a ha
obtain ⟨j,hj⟩ := paddedChoice_covers _ (hR _ _) b hb
have hwin : hintedAcceptance (lists.strategy (i,j)) U hidden pos B := by
change projection U hidden pos (paddedChoice _ i)=paddedChoice _ j
rw [hi,hj]
exact hab
have hs := Finset.single_le_sum (s := Finset.univ) (f := fun z : Fin L Γ— Fin R =>
if hintedAcceptance (lists.strategy z) U hidden pos B then (1 : ℝ) else 0)
(fun _ _ => by positivity) (Finset.mem_univ (i,j))
simpa only [ite_eq_left hwin] using hs
Β· rw [ite_eq_right hm]
exact Finset.sum_nonneg (fun _ _ => by positivity)
theorem HintLists.shared_soundness [Fintype Name]
{S : Type*} [Fintype S] [Nonempty S] (equations : S β†’ Equation Name)
(hsound : βˆ€ s : Name β†’ Fβ‚‚, equationFraction equations s ≀ 3/4)
{q L R : β„•} (lists : HintLists Name I q)
(hL : βˆ€ U B, (lists.first U B).card≀L)
(hR : βˆ€ V B, (lists.second V B).card≀R) (hidden : I β†’ Bool) :
(𝔼 w : I β†’ S Γ— Fin 3,
𝔼 B : Fin q β†’ Forms (SecondAlphabet
(secondQuestion (sampledEquations equations w) hidden (sampledPositions w))),
if lists.matches (sampledEquations equations w) hidden (sampledPositions w) B
then (1 : ℝ) else 0) ≀
(L : ℝ)*(R : ℝ)*hintRate q ^ Fintype.card {i // hidden i=true} := by
calc
_ ≀ 𝔼 w : I β†’ S Γ— Fin 3,
𝔼 B : Fin q β†’ Forms (SecondAlphabet
(secondQuestion (sampledEquations equations w) hidden (sampledPositions w))),
βˆ‘ z : Fin L Γ— Fin R,
if hintedAcceptance (lists.strategy z) (sampledEquations equations w) hidden
(sampledPositions w) B then (1 : ℝ) else 0 := by
apply Finset.expect_le_expect
intro w _
exact Finset.expect_le_expect (fun B _ => lists.matching_le_sum hL hR _ hidden _ B)
_ = βˆ‘ z : Fin L Γ— Fin R, 𝔼 w : I β†’ S Γ— Fin 3,
𝔼 B : Fin q β†’ Forms (SecondAlphabet
(secondQuestion (sampledEquations equations w) hidden (sampledPositions w))),
if hintedAcceptance (lists.strategy z) (sampledEquations equations w) hidden
(sampledPositions w) B then (1 : ℝ) else 0 := by
simp_rw [Finset.expect_sum_comm]
_ ≀ βˆ‘ _z : Fin L Γ— Fin R, hintRate q ^ Fintype.card {i // hidden i=true} := by
apply Finset.sum_le_sum
intro z _
exact shared_hint_soundness equations hsound (lists.strategy z) hidden
_ = _ := by simp [mul_assoc]
open scoped BigOperators
open MinUncut.Inner
attribute [local instance] Classical.propDecidable BinaryFourier.dualFintype
variable {Name I : Type*} [Fintype I]
abbrev CoordinateSlot (E : Equation Name) := Fin (Module.finrank Fβ‚‚ (alphabet E).direction) β†’ Fβ‚‚
abbrev FirstCoordinateSpace (U : I β†’ Equation Name) := βˆ€ i, CoordinateSlot (U i)
def firstCoordinates (U : I β†’ Equation Name) :
FirstCoordinateSpace U ≃ᡃ[Fβ‚‚] FirstAlphabet U :=
(LinearEquiv.piCongrRight (fun i => coordinates (U i))).toAffineEquiv.trans
(AffineEquiv.vaddConst Fβ‚‚ (fun i => origin (U i)))
omit [Fintype I] in
@[simp] lemma firstCoordinates_apply (U : I β†’ Equation Name)
(v : FirstCoordinateSpace U) (i : I) :
(firstCoordinates U v i).val = directionEmbedding (U i) (v i) + (origin (U i)).val := rfl
omit [Fintype I] in
lemma firstCoordinates_symm_apply (U : I β†’ Equation Name) (a : FirstAlphabet U) (i : I) :
(firstCoordinates U).symm a i = (alphabetCoordinates (U i)).symm (a i) := rfl
def formsTransport {V W A B : Type*} [AddCommGroup V] [Module Fβ‚‚ V] [AddTorsor V A]
[AddCommGroup W] [Module Fβ‚‚ W] [AddTorsor W B] (e : A ≃ᡃ[Fβ‚‚] B) :
Forms B ≃ₗ[Fβ‚‚] Forms A where
toFun f := f.comp e.toAffineMap
invFun f := f.comp e.symm.toAffineMap
left_inv f := by ext b; simp
right_inv f := by ext a; simp
map_add' f g := by ext a; rfl
map_smul' c f := by ext a; rfl
def firstFormCoordinates (U : I β†’ Equation Name) :
(Fβ‚‚ Γ— (βˆ€ i, Module.Dual Fβ‚‚ (CoordinateSlot (U i)))) ≃ₗ[Fβ‚‚] Forms (FirstAlphabet U) :=
((LinearEquiv.refl Fβ‚‚ Fβ‚‚).prodCongr
(LinearMap.lsum Fβ‚‚ (fun i => CoordinateSlot (U i)) Fβ‚‚)).trans
((AffineMap.toConstProdLinearMap Fβ‚‚).symm.trans (formsTransport (firstCoordinates U)).symm)
lemma firstFormCoordinates_apply (U : I β†’ Equation Name) (ΞΊ : Fβ‚‚)
(b : βˆ€ i, Module.Dual Fβ‚‚ (CoordinateSlot (U i))) (a : FirstAlphabet U) :
firstFormCoordinates U (ΞΊ,b) a =
(βˆ‘ i, b i ((alphabetCoordinates (U i)).symm (a i)))+ΞΊ := by
change (βˆ‘ i, (b i).comp (LinearMap.proj i)) ((firstCoordinates U).symm a)+ΞΊ=_
simp only [LinearMap.sum_apply,LinearMap.comp_apply,LinearMap.proj_apply,
firstCoordinates_symm_apply]
abbrev TupleCoordinateData (U : I β†’ Equation Name) (d : β„•) :=
(Fin d β†’ Fβ‚‚) Γ— (βˆ€ i, OuterSmoothness.JointForms.Block
(Module.finrank Fβ‚‚ (alphabet (U i)).direction) d)
def tupleCoordinateSlice (U : I β†’ Equation Name) (d : β„•) (k : Fin d) :
TupleCoordinateData U d β†’β‚—[Fβ‚‚] (Fβ‚‚ Γ— (βˆ€ i, Module.Dual Fβ‚‚ (CoordinateSlot (U i)))) where
toFun z := (z.1 k,fun i => z.2 i k)
map_add' _ _ := rfl
map_smul' _ _ := rfl
def tupleCoordinateGenerator (U : I β†’ Equation Name) (d : β„•) :
TupleCoordinateData U d β†’β‚—[Fβ‚‚] (Fin d β†’ Forms (FirstAlphabet U)) :=
LinearMap.pi (fun k => (firstFormCoordinates U).toLinearMap.comp (tupleCoordinateSlice U d k))
lemma tupleCoordinateGenerator_surjective (U : I β†’ Equation Name) (d : β„•) :
Function.Surjective (tupleCoordinateGenerator U d) := by
intro f
let z := fun k => (firstFormCoordinates U).symm (f k)
refine ⟨(fun k => (z k).1,fun i k => (z k).2 i),?_⟩
funext k
exact (firstFormCoordinates U).apply_symm_apply (f k)
lemma uniform_tupleCoordinateGenerator (U : I β†’ Equation Name) (d : β„•)
(f : (Fin d β†’ Forms (FirstAlphabet U)) β†’ ℝ) :
(𝔼 z : TupleCoordinateData U d, f (tupleCoordinateGenerator U d z)) = 𝔼 L, f L :=
IndependentSquares.expect_surjective_linear _ (tupleCoordinateGenerator_surjective U d) f
end MinUncut.Outer
end
end OAI