roseking's picture
Add lean source and binary files (part 61)
ea76aac verified
Raw History Blame Contribute Delete
35.4 kB
import Mathlib
import OAI.Computability.MaxCut.Encoding.PaddedLaw
import OAI.Computability.MaxCut.Encoding.TableKeys
import OAI.Computability.MaxCut.Games.ActualAdviceStochasticBridge
namespace OAI
/-!
The actual finite advice law. Uniform independent hidden/complement maps induce
the exact uniform visible-map law, including for rank-deficient public maps.
The whole-table comparison retains an arbitrary common occurrence/public-data
law, so weighted occurrence sampling is not replaced by uniform IDs.
-/
namespace MaxCutGames.Decoder.AdviceLaw
open scoped BigOperators
open MaxCutGames.Integration.BinaryLinear
open MaxCutGames.Reduction MaxCutGames.Soundness
open ConditionalIncidences RawPartnerTarget RawMapLaw
open MaxCutGames.Foundations.Games
open MaxCutGames.Clean
noncomputable section
attribute [local instance] Classical.propDecidable
section VisibleMap
variable {k : ℕ} {K W R : Type}
[AddCommGroup K] [Module F2 K] [Fintype K]
[AddCommGroup W] [Module F2 W] [Fintype W]
[AddCommGroup R] [Module F2 R] [Fintype R]
/-- The precise visible table `(T,A M)`, with the second component in its
actual attainable range. The argument order is complement, hidden matrix. -/
def visibleMap (A : K →ₗ[F2] R) {J : Finset (Fin k)}
(T : RawPoint J →ₗ[F2] W) (M : RawPoint J →ₗ[F2] K) :
RawPoint J →ₗ[F2] (W × A.range) :=
T.prod (A.rangeRestrict.comp M)
omit [Fintype K] [Fintype W] [Fintype R] in
theorem visibleMap_apply (A : K →ₗ[F2] R) {J : Finset (Fin k)}
(T : RawPoint J →ₗ[F2] W) (M : RawPoint J →ₗ[F2] K) (x : RawPoint J) :
visibleMap A T M x = (T x, AdviceImageLaw.rangePoint A (M x)) := rfl
def rawMapPairCoefficientsEquiv (J : Finset (Fin k)) :
((RawPoint J →ₗ[F2] W) × (RawPoint J →ₗ[F2] K)) ≃
(RawSlot J → W × K) :=
(Equiv.prodCongr (rawMapEquiv J W).symm (rawMapEquiv J K).symm).trans
(Equiv.arrowProdEquivProdArrow (RawSlot J) (fun _ => W) (fun _ => K)).symm
omit [Fintype K] [Fintype W] [Fintype R] in
theorem visibleMap_raw (A : K →ₗ[F2] R) (J : Finset (Fin k))
(TM : (RawPoint J →ₗ[F2] W) × (RawPoint J →ₗ[F2] K)) :
visibleMap A TM.1 TM.2 = rawMap J (W × A.range)
(AdviceImageLaw.visibleCoefficients A (rawMapPairCoefficientsEquiv J TM)) := by
exact (rawMap_coefficients J (W × A.range) (visibleMap A TM.1 TM.2)).symm
/-- Equality for every observable proves the whole joint visible-map law. -/
theorem uniform_visible_maps (A : K →ₗ[F2] R) (J : Finset (Fin k))
(H : (RawPoint J →ₗ[F2] (W × A.range)) → ℝ) :
(𝔼 TM : (RawPoint J →ₗ[F2] W) × (RawPoint J →ₗ[F2] K),
H (visibleMap A TM.1 TM.2)) =
𝔼 Y : RawPoint J →ₗ[F2] (W × A.range), H Y := by
calc
_ = 𝔼 columns : RawSlot J → W × K,
H (rawMap J (W × A.range) (AdviceImageLaw.visibleCoefficients A columns)) := by
apply Fintype.expect_equiv (rawMapPairCoefficientsEquiv J)
intro TM
rw [visibleMap_raw]
_ = 𝔼 gamma : RawSlot J → W × A.range, H (rawMap J (W × A.range) gamma) :=
AdviceImageLaw.uniform_visible_coefficients (I := RawSlot J) (W := W) A
(fun gamma : RawSlot J → W × A.range => H (rawMap J (W × A.range) gamma))
_ = _ := PaddedLaw.uniform_rawMaps J H
theorem uniform_visible_maps_expectation (A : K →ₗ[F2] R) (J : Finset (Fin k))
(H : (RawPoint J →ₗ[F2] (W × A.range)) → ℝ) :
(FiniteDistribution.uniform
((RawPoint J →ₗ[F2] W) × (RawPoint J →ₗ[F2] K))).expectation
(fun TM => H (visibleMap A TM.1 TM.2)) =
(FiniteDistribution.uniform (RawPoint J →ₗ[F2] (W × A.range))).expectation H := by
simpa only [FiniteDistribution.expectation_uniform,
← Fintype.expect_eq_sum_div_card] using uniform_visible_maps A J H
variable {O N : Type} [Fintype O] [DecidableEq O] [Fintype N] [DecidableEq N]
/-- Actual success starts with genuinely sampled hidden and complement maps.
The iid incidence law includes every slot choice, including unused choices at
full positions. Policies receive only their respective visible table. -/
def actualSuccess (μ : FiniteDistribution (O × Fin 3))
(g : IncidenceExtraction.Incidence O N) (A : K →ₗ[F2] R)
(policy : ActualAdviceStochasticBridge.Policies k g (W × A.range))
(β : ℝ) (hβ₀ : 0 ≤ β) (hβ₁ : β ≤ 1) : ℝ :=
((Clean.bernoulli β hβ₀ hβ₁).iid k).expectation fun mask =>
(FiniteDistribution.uniform
((RawPoint (NativeExperiment.maskSet mask) →ₗ[F2] W) ×
(RawPoint (NativeExperiment.maskSet mask) →ₗ[F2] K))).expectation fun TM =>
ActualAdviceStochasticBridge.fixedMapSuccess μ g policy
(NativeExperiment.maskSet mask) (visibleMap A TM.1 TM.2)
omit [DecidableEq O] [Fintype N] [DecidableEq N] in
theorem actualSuccess_eq_cleanSuccess (μ : FiniteDistribution (O × Fin 3))
(g : IncidenceExtraction.Incidence O N) (A : K →ₗ[F2] R)
(policy : ActualAdviceStochasticBridge.Policies k g (W × A.range))
(β : ℝ) (hβ₀ : 0 ≤ β) (hβ₁ : β ≤ 1) :
actualSuccess μ g A policy β hβ₀ hβ₁ =
ActualAdviceStochasticBridge.success μ g policy β hβ₀ hβ₁ := by
unfold actualSuccess ActualAdviceStochasticBridge.success
apply FiniteDistribution.expectation_congr
intro mask
exact uniform_visible_maps_expectation A (NativeExperiment.maskSet mask)
(ActualAdviceStochasticBridge.fixedMapSuccess μ g policy (NativeExperiment.maskSet mask))
end VisibleMap
section WholeTable
variable {k : ℕ} {V : Type} [AddCommGroup V] [Module F2 V] [Fintype V]
[Fintype (ActualHomogeneous.E k →ₗ[F2] V)]
def drawDistribution (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :
FiniteDistribution ((Fin k → PaddedLaw.BlockDraw V) × V) where
weight := PaddedLaw.drawWeights β k
nonnegative dz := mul_nonneg
((SparseLaw.independentWeights_isProbability _
(PaddedLaw.blockWeights_isProbability β hβ hβ') k).1 dz.1)
(SparseLaw.uniformWeights_pos dz.2).le
normalized := by
rw [Fintype.sum_prod_type]
simp only [PaddedLaw.drawWeights, ← Finset.mul_sum,
(SparseLaw.uniformWeights_isProbability (α := V)).2, mul_one]
exact (SparseLaw.independentWeights_isProbability _
(PaddedLaw.blockWeights_isProbability β hβ hβ') k).2
def paddedDistribution (rhs : Fin k → Bool) (β : ℝ)
(hβ : 0 ≤ β) (hβ' : β ≤ 1) :
FiniteDistribution (ActualHomogeneous.E k →ₗ[F2] V) :=
(drawDistribution β hβ hβ').pushforward (fun dz => PaddedLaw.paddedMap rhs dz.1 dz.2)
/-- Padding adds an independent uniform affine intercept. The full map's
variation is therefore exactly the sparse slope variation used in constants. -/
theorem paddedDistribution_totalVariation_eq_slope (rhs : Fin k → Bool) (β : ℝ)
(hβ : 0 ≤ β) (hβ' : β ≤ 1) :
(paddedDistribution (V := V) rhs β hβ hβ').totalVariation
(FiniteDistribution.uniform (ActualHomogeneous.E k →ₗ[F2] V)) =
MaxCutGames.Foundations.Information.totalVariation
(SparseLaw.independentWeights (SparseLaw.mixture β (SparseLaw.singletonPairWeights V)) k)
(SparseLaw.uniformWeights (Fin k → V × V)) := by
exact PaddedLaw.paddedMapWeights_totalVariation_eq_slope rhs β
theorem paddedDistribution_totalVariation (rhs : Fin k → Bool) (β : ℝ)
(hβ : 0 ≤ β) (hβ' : β ≤ 1) :
(paddedDistribution (V := V) rhs β hβ hβ').totalVariation
(FiniteDistribution.uniform (ActualHomogeneous.E k →ₗ[F2] V)) ≤
Real.sqrt ((1 + β ^ 2 * ((Fintype.card V : ℝ) - 1) / 3) ^ k - 1) / 2 := by
exact PaddedLaw.paddedMapWeights_totalVariation rhs β hβ hβ'
end WholeTable
section CommonLaw
variable {Ω Y : Type*} [Fintype Ω] [Fintype Y]
/-- Keep the common outer datum while sampling its conditional table law. -/
def withKernel (μ : FiniteDistribution Ω) (p : Ω → FiniteDistribution Y) :
FiniteDistribution (Ω × Y) where
weight xy := μ.weight xy.1 * (p xy.1).weight xy.2
nonnegative xy := mul_nonneg (μ.nonnegative _) ((p _).nonnegative _)
normalized := by
rw [Fintype.sum_prod_type]
simp_rw [← Finset.mul_sum, FiniteDistribution.normalized, mul_one]
exact μ.normalized
theorem withKernel_totalVariation (μ : FiniteDistribution Ω)
(p q : Ω → FiniteDistribution Y) :
(withKernel μ p).totalVariation (withKernel μ q) =
∑ x, μ.weight x * (p x).totalVariation (q x) := by
unfold FiniteDistribution.totalVariation withKernel
rw [Fintype.sum_prod_type]
have inner (x : Ω) :
(∑ y, |μ.weight x * (p x).weight y - μ.weight x * (q x).weight y|) =
μ.weight x * ∑ y, |(p x).weight y - (q x).weight y| := by
simp only [← mul_sub, abs_mul, abs_of_nonneg (μ.nonnegative x), ← Finset.mul_sum]
simp_rw [inner]
rw [Finset.sum_div]
apply Finset.sum_congr rfl
intro x _
ring
theorem withKernel_totalVariation_le (μ : FiniteDistribution Ω)
(p q : Ω → FiniteDistribution Y) (η : ℝ)
(h : ∀ x, (p x).totalVariation (q x) ≤ η) :
(withKernel μ p).totalVariation (withKernel μ q) ≤ η := by
rw [withKernel_totalVariation]
calc
_ ≤ ∑ x, μ.weight x * η := Finset.sum_le_sum fun x _ =>
mul_le_mul_of_nonneg_left (h x) (μ.nonnegative x)
_ = η := by rw [← Finset.sum_mul, μ.normalized, one_mul]
end CommonLaw
/-- Whole `(occurrences, public advice, Mπ,Tπ)` comparison. The product
codomain represents the two genuine sampled maps; occurrence weights are
arbitrary and remain in both laws. The public law can in particular be uniform
on all row maps. Projection choices are averaged out before this comparison. -/
theorem wholeAdvice_totalVariation {k : ℕ} {Id A V : Type}
[Fintype Id] [Fintype A] [AddCommGroup V] [Module F2 V] [Fintype V]
[Fintype (ActualHomogeneous.E k →ₗ[F2] V)]
(occurrences : FiniteDistribution (Fin k → Id)) (publicLaw : FiniteDistribution A)
(rhs : Id → Bool) (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :
(withKernel (occurrences.product publicLaw)
(fun ua => paddedDistribution (V := V) (fun j => rhs (ua.1 j)) β hβ hβ')).totalVariation
(withKernel (occurrences.product publicLaw)
(fun _ => FiniteDistribution.uniform (ActualHomogeneous.E k →ₗ[F2] V))) ≤
Real.sqrt ((1 + β ^ 2 * ((Fintype.card V : ℝ) - 1) / 3) ^ k - 1) / 2 := by
apply withKernel_totalVariation_le
intro ua
exact paddedDistribution_totalVariation (fun j => rhs (ua.1 j)) β hβ hβ'
/-- Common occurrence/public randomness preserves the exact slope variation. -/
theorem wholeAdvice_totalVariation_eq_slope {k : ℕ} {Id A V : Type}
[Fintype Id] [Fintype A] [AddCommGroup V] [Module F2 V] [Fintype V]
[Fintype (ActualHomogeneous.E k →ₗ[F2] V)]
(occurrences : FiniteDistribution (Fin k → Id)) (publicLaw : FiniteDistribution A)
(rhs : Id → Bool) (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :
(withKernel (occurrences.product publicLaw)
(fun ua => paddedDistribution (V := V) (fun j => rhs (ua.1 j)) β hβ hβ')).totalVariation
(withKernel (occurrences.product publicLaw)
(fun _ => FiniteDistribution.uniform (ActualHomogeneous.E k →ₗ[F2] V))) =
MaxCutGames.Foundations.Information.totalVariation
(SparseLaw.independentWeights (SparseLaw.mixture β (SparseLaw.singletonPairWeights V)) k)
(SparseLaw.uniformWeights (Fin k → V × V)) := by
rw [withKernel_totalVariation]
simp_rw [paddedDistribution_totalVariation_eq_slope]
rw [← Finset.sum_mul, (occurrences.product publicLaw).normalized, one_mul]
theorem wholeAdvice_totalVariation_le_slope {k : ℕ} {Id A V : Type}
[Fintype Id] [Fintype A] [AddCommGroup V] [Module F2 V] [Fintype V]
[Fintype (ActualHomogeneous.E k →ₗ[F2] V)]
(occurrences : FiniteDistribution (Fin k → Id)) (publicLaw : FiniteDistribution A)
(rhs : Id → Bool) (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :
(withKernel (occurrences.product publicLaw)
(fun ua => paddedDistribution (V := V) (fun j => rhs (ua.1 j)) β hβ hβ')).totalVariation
(withKernel (occurrences.product publicLaw)
(fun _ => FiniteDistribution.uniform (ActualHomogeneous.E k →ₗ[F2] V))) ≤
MaxCutGames.Foundations.Information.totalVariation
(SparseLaw.independentWeights (SparseLaw.mixture β (SparseLaw.singletonPairWeights V)) k)
(SparseLaw.uniformWeights (Fin k → V × V)) :=
(wholeAdvice_totalVariation_eq_slope occurrences publicLaw rhs β hβ hβ').le
section HiddenRows
variable {k : ℕ} {K R : Type}
[AddCommGroup K] [Module F2 K] [Fintype K]
[AddCommGroup R] [Module F2 R] [Fintype R]
instance observedRowsFintype (J : Finset (Fin k)) (A : K →ₗ[F2] R) :
Fintype (AdviceFibers.ObservedRow (E := RawPoint J) A) := Fintype.ofFinite _
/-- After fixing the mask, public map and complement table, the uniform hidden
matrix has independent uniform attainable rows and private kernel coordinates.
The observation fixes only `A M`, not `M` or a chosen witness. -/
theorem observed_hidden_independent (J : Finset (Fin k)) (A : K →ₗ[F2] R)
(f : AdviceFibers.ObservedRow (E := RawPoint J) A → ℝ)
(g : (RawPoint J →ₗ[F2] A.ker) → ℝ) :
(𝔼 M : RawPoint J →ₗ[F2] K,
f (AdviceFibers.observe A M) * g (AdviceFibers.hiddenCoordinate A M)) =
(𝔼 S : AdviceFibers.ObservedRow (E := RawPoint J) A, f S) *
(𝔼 N : RawPoint J →ₗ[F2] A.ker, g N) :=
AdviceFibers.observed_hidden_independent A f g
end HiddenRows
section ProjectionSeeds
variable {k : ℕ} {V : Type} [AddCommGroup V] [Module F2 V] [Fintype V]
/-- The actual two-stage sampler retains both its projection choices and its
uniform map on that projected target. Thus target advice is not forgotten. -/
abbrev ProjectionSeed (k : ℕ) (V : Type) [AddCommGroup V] [Module F2 V] :=
Σ c : Fin k → PaddedLaw.ProjectionChoice,
RawPoint (PaddedLaw.choiceMask c) →ₗ[F2] V
def projectionSeedDistribution (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :
FiniteDistribution (ProjectionSeed k V) where
weight s := PaddedLaw.choiceTupleWeight β s.1 * SparseLaw.uniformWeights _ s.2
nonnegative s := mul_nonneg
((PaddedLaw.choiceTupleWeight_isProbability β hβ hβ').1 s.1)
(SparseLaw.uniformWeights_pos s.2).le
normalized := by
rw [Fintype.sum_sigma]
simp_rw [← Finset.mul_sum, (SparseLaw.uniformWeights_isProbability).2, mul_one]
exact (PaddedLaw.choiceTupleWeight_isProbability β hβ hβ').2
def projectSeedMap (rhs : Fin k → Bool) (s : ProjectionSeed k V) :
ActualHomogeneous.E k →ₗ[F2] V :=
s.2.comp (rawProjection rhs (PaddedLaw.choiceMask s.1) (PaddedLaw.choiceSlots s.1))
variable [Fintype (ActualHomogeneous.E k →ₗ[F2] V)]
theorem projectionSeed_expectation (rhs : Fin k → Bool) (β : ℝ)
(hβ : 0 ≤ β) (hβ' : β ≤ 1)
(H : (ActualHomogeneous.E k →ₗ[F2] V) → ℝ) :
(projectionSeedDistribution β hβ hβ').expectation (fun s => H (projectSeedMap rhs s)) =
(paddedDistribution rhs β hβ hβ').expectation H := by
rw [paddedDistribution, FiniteDistribution.expectation_pushforward]
change (∑ s : ProjectionSeed k V,
PaddedLaw.choiceTupleWeight β s.1 * SparseLaw.uniformWeights _ s.2 *
H (projectSeedMap rhs s)) =
∑ dz, PaddedLaw.drawWeights β k dz * H (PaddedLaw.paddedMap rhs dz.1 dz.2)
rw [PaddedLaw.actual_projection_mixture_expectation, Fintype.sum_sigma]
apply Finset.sum_congr rfl
intro c _
calc
_ = PaddedLaw.choiceTupleWeight β c *
∑ Y : RawPoint (PaddedLaw.choiceMask c) →ₗ[F2] V,
SparseLaw.uniformWeights _ Y *
H (Y.comp (rawProjection rhs (PaddedLaw.choiceMask c) (PaddedLaw.choiceSlots c))) := by
rw [Finset.mul_sum]
apply Finset.sum_congr rfl
intro Y _
exact mul_assoc _ _ _
_ = _ := by rw [PaddedLaw.sum_uniformWeights_mul]
theorem projectionSeed_pushforward (rhs : Fin k → Bool) (β : ℝ)
(hβ : 0 ≤ β) (hβ' : β ≤ 1) :
(projectionSeedDistribution β hβ hβ').pushforward (projectSeedMap (V := V) rhs) =
paddedDistribution rhs β hβ hβ' := by
apply FiniteDistribution.eq_of_weight_eq
intro Y
have h := projectionSeed_expectation rhs β hβ hβ' (fun X => if X = Y then 1 else 0)
simpa [FiniteDistribution.pushforward, FiniteDistribution.expectation, mul_ite,
PaddedLaw.pushforwardWeight] using h
end ProjectionSeeds
section ActualDraw
variable {k : ℕ} {Id K W R : Type}
[AddCommGroup K] [Module F2 K] [AddCommGroup W] [Module F2 W]
[AddCommGroup R] [Module F2 R]
/-- Convert the actual two-stage seed into the full hidden experiment. The
second summand of the seed remains available for the target-side observation. -/
def seedToActualDraw (occ : Fin k → Id) (A : K →ₗ[F2] R)
(s : ProjectionSeed k (K × W)) : AdviceExperiment.Draw k Id K W R where
singletons := PaddedLaw.choiceMask s.1
occurrences := occ
positions := PaddedLaw.choiceSlots s.1
rowMap := A
hiddenMatrix := (LinearMap.fst F2 K W).comp s.2
complement := (LinearMap.snd F2 K W).comp s.2
theorem seed_projection (rhs : Id → F2) (occ : Fin k → Id) (A : K →ₗ[F2] R)
(s : ProjectionSeed k (K × W)) :
AdviceExperiment.projection rhs (seedToActualDraw occ A s) =
rawProjection (fun j => toBit (rhs (occ j)))
(PaddedLaw.choiceMask s.1) (PaddedLaw.choiceSlots s.1) := rfl
theorem seed_padded_pair (rhs : Id → F2) (occ : Fin k → Id) (A : K →ₗ[F2] R)
(s : ProjectionSeed k (K × W)) :
(AdviceExperiment.paddedMatrix rhs (seedToActualDraw occ A s)).prod
(AdviceExperiment.paddedComplement rhs (seedToActualDraw occ A s)) =
projectSeedMap (fun j => toBit (rhs (occ j))) s := by
ext x <;> rfl
theorem seed_left_observation (rhs : Id → F2) (occ : Fin k → Id) (A : K →ₗ[F2] R)
(s : ProjectionSeed k (K × W)) :
AdviceExperiment.leftObservation rhs (seedToActualDraw occ A s) = {
occurrences := occ, rowMap := A,
complement := (LinearMap.snd F2 K W).comp
(projectSeedMap (fun j => toBit (rhs (occ j))) s),
rows := A.comp ((LinearMap.fst F2 K W).comp
(projectSeedMap (fun j => toBit (rhs (occ j))) s)) } := rfl
theorem seed_right_observation {Name : Type} (names : Id → Fin 3 → Name)
(occ : Fin k → Id) (A : K →ₗ[F2] R) (s : ProjectionSeed k (K × W)) :
AdviceExperiment.rightObservation names (seedToActualDraw occ A s) =
⟨PaddedLaw.choiceMask s.1, {
question := RawPrivateTable.supported (PaddedLaw.choiceMask s.1) names occ
(PaddedLaw.choiceSlots s.1), rowMap := A,
complement := (LinearMap.snd F2 K W).comp s.2,
rows := A.comp ((LinearMap.fst F2 K W).comp s.2) }⟩ := rfl
end ActualDraw
section MaskSlots
def choiceDistribution (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :
FiniteDistribution PaddedLaw.ProjectionChoice where
weight := PaddedLaw.choiceWeight β
nonnegative := (PaddedLaw.choiceWeight_isProbability β hβ hβ').1
normalized := (PaddedLaw.choiceWeight_isProbability β hβ hβ').2
/-- Full positions discard their auxiliary slot; singleton positions retain it. -/
def maskSlotChoice (p : Bool × Fin 3) : PaddedLaw.ProjectionChoice :=
if p.1 then some p.2 else none
theorem maskSlotChoice_pushforward (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :
((Clean.bernoulli β hβ hβ').product (FiniteDistribution.uniform (Fin 3))).pushforward
maskSlotChoice = choiceDistribution β hβ hβ' := by
apply FiniteDistribution.eq_of_weight_eq
intro c
simp only [FiniteDistribution.pushforward, FiniteDistribution.product,
FiniteDistribution.uniform, Clean.bernoulli, choiceDistribution]
rw [Fintype.sum_prod_type, Fintype.sum_bool]
cases c <;> simp [maskSlotChoice, PaddedLaw.choiceWeight, div_eq_mul_inv] ; ring
def choicesOfMaskSlots {k : ℕ} (mask : Fin k → Bool) (slots : Fin k → Fin 3) :
Fin k → PaddedLaw.ProjectionChoice :=
fun j => maskSlotChoice (mask j, slots j)
/-- The Option sampler is exactly the Bernoulli-mask sampler with independent
uniform slots at every position, including the full positions. This identity
allows arbitrary functions of the retained choices. -/
theorem choices_expectation {k : ℕ} (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1)
(H : (Fin k → PaddedLaw.ProjectionChoice) → ℝ) :
((choiceDistribution β hβ hβ').iid k).expectation H =
((Clean.bernoulli β hβ hβ').iid k).expectation (fun mask =>
(FiniteDistribution.uniform (Fin k → Fin 3)).expectation (fun slots =>
H (choicesOfMaskSlots mask slots))) := by
rw [← maskSlotChoice_pushforward, FiniteDistribution.iid_pushforward,
FiniteDistribution.expectation_pushforward, NativeExperiment.expectation_iid_product,
FiniteDistribution.iid_uniform]
rfl
theorem choices_mask {k : ℕ} (mask : Fin k → Bool) (slots : Fin k → Fin 3) :
PaddedLaw.choiceMask (choicesOfMaskSlots mask slots) =
NativeExperiment.maskSet mask := by
ext j
cases h : mask j <;>
simp [PaddedLaw.choiceMask, NativeExperiment.maskSet, choicesOfMaskSlots,
maskSlotChoice, h]
theorem choices_active_slot {k : ℕ} (mask : Fin k → Bool) (slots : Fin k → Fin 3)
(j : Fin k) (hj : mask j = true) :
PaddedLaw.choiceSlots (choicesOfMaskSlots mask slots) j = PaddedLaw.decodeSlot (slots j) := by
simp [PaddedLaw.choiceSlots, PaddedLaw.choiceSlot, choicesOfMaskSlots, maskSlotChoice, hj]
/-- The same identity with the entire original target map retained. This is
the full two-stage seed law, not merely the law of its padded marginal. -/
theorem projectionSeed_mask_slots_expectation {k : ℕ} {V : Type}
[AddCommGroup V] [Module F2 V] [Fintype V]
(β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) (H : ProjectionSeed k V → ℝ) :
(projectionSeedDistribution β hβ hβ').expectation H =
((Clean.bernoulli β hβ hβ').iid k).expectation (fun mask =>
(FiniteDistribution.uniform (Fin k → Fin 3)).expectation (fun slots =>
(FiniteDistribution.uniform
(RawPoint (PaddedLaw.choiceMask (choicesOfMaskSlots mask slots)) →ₗ[F2] V)).expectation
(fun Y => H ⟨choicesOfMaskSlots mask slots, Y⟩))) := by
calc
_ = ((choiceDistribution β hβ hβ').iid k).expectation (fun c =>
(FiniteDistribution.uniform (RawPoint (PaddedLaw.choiceMask c) →ₗ[F2] V)).expectation
(fun Y => H ⟨c, Y⟩)) := by
unfold FiniteDistribution.expectation
rw [Fintype.sum_sigma]
apply Finset.sum_congr rfl
intro c _
change (∑ Y, PaddedLaw.choiceTupleWeight β c * SparseLaw.uniformWeights _ Y * H ⟨c, Y⟩) =
PaddedLaw.choiceTupleWeight β c * ∑ Y, SparseLaw.uniformWeights _ Y * H ⟨c, Y⟩
rw [Finset.mul_sum]
apply Finset.sum_congr rfl
intro Y _
exact mul_assoc _ _ _
_ = _ := choices_expectation β hβ hβ' _
end MaskSlots
section FullSeedLaw
variable {Ω Z Y : Type*} [Fintype Ω] [Fintype Z] [Fintype Y]
theorem product_pushforward_withKernel (μ : FiniteDistribution Ω)
(ν : FiniteDistribution Z) (f : Ω → Z → Y) :
(μ.product ν).pushforward (fun xz => (xz.1, f xz.1 xz.2)) =
withKernel μ (fun x => ν.pushforward (f x)) := by
apply FiniteDistribution.eq_of_weight_eq
rintro ⟨a, b⟩
simp only [FiniteDistribution.pushforward, FiniteDistribution.product, withKernel]
rw [Fintype.sum_prod_type]
calc
_ = ∑ x : Ω, if x = a then μ.weight x *
∑ z, if f x z = b then ν.weight z else 0 else 0 := by
apply Finset.sum_congr rfl
intro x _
by_cases hx : x = a
· subst x
simp only [Prod.mk.injEq, true_and, ite_true]
rw [Finset.mul_sum]
apply Finset.sum_congr rfl
intro z _
split_ifs <;> simp
· simp [Prod.mk.injEq, hx]
_ = _ := by simp
end FullSeedLaw
/-- A finite hidden sample whose actual Draw is `seedToActualDraw`. -/
def fullSeedLaw {k : ℕ} {Id A V : Type} [Fintype Id] [Fintype A]
[AddCommGroup V] [Module F2 V] [Fintype V]
(occurrences : FiniteDistribution (Fin k → Id)) (publicLaw : FiniteDistribution A)
(β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :=
(occurrences.product publicLaw).product (projectionSeedDistribution (k := k) (V := V) β hβ hβ')
def fullSeedPad {k : ℕ} {Id A V : Type} [AddCommGroup V] [Module F2 V]
(rhs : Id → Bool) (s : ((Fin k → Id) × A) × ProjectionSeed k V) :
((Fin k → Id) × A) × (ActualHomogeneous.E k →ₗ[F2] V) :=
(s.1, projectSeedMap (fun j => rhs (s.1.1 j)) s.2)
theorem fullSeed_pad_law {k : ℕ} {Id A V : Type}
[Fintype Id] [Fintype A] [AddCommGroup V] [Module F2 V] [Fintype V]
[Fintype (ActualHomogeneous.E k →ₗ[F2] V)]
(occurrences : FiniteDistribution (Fin k → Id)) (publicLaw : FiniteDistribution A)
(rhs : Id → Bool) (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :
(fullSeedLaw (V := V) occurrences publicLaw β hβ hβ').pushforward (fullSeedPad rhs) =
withKernel (occurrences.product publicLaw)
(fun ua => paddedDistribution (V := V) (fun j => rhs (ua.1 j)) β hβ hβ') := by
unfold fullSeedLaw fullSeedPad
rw [product_pushforward_withKernel (occurrences.product publicLaw)
(projectionSeedDistribution (k := k) (V := V) β hβ hβ')
(fun ua seed => projectSeedMap (fun j => rhs (ua.1 j)) seed)]
congr 1
funext ua
exact projectionSeed_pushforward (fun j => rhs (ua.1 j)) β hβ hβ'
theorem fullSeed_totalVariation {k : ℕ} {Id A V : Type}
[Fintype Id] [Fintype A] [AddCommGroup V] [Module F2 V] [Fintype V]
[Fintype (ActualHomogeneous.E k →ₗ[F2] V)]
(occurrences : FiniteDistribution (Fin k → Id)) (publicLaw : FiniteDistribution A)
(rhs : Id → Bool) (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :
((fullSeedLaw (V := V) occurrences publicLaw β hβ hβ').pushforward
(fullSeedPad rhs)).totalVariation
(withKernel (occurrences.product publicLaw)
(fun _ => FiniteDistribution.uniform (ActualHomogeneous.E k →ₗ[F2] V))) ≤
Real.sqrt ((1 + β ^ 2 * ((Fintype.card V : ℝ) - 1) / 3) ^ k - 1) / 2 := by
rw [fullSeed_pad_law]
exact wholeAdvice_totalVariation occurrences publicLaw rhs β hβ hβ'
theorem fullSeed_totalVariation_eq_slope {k : ℕ} {Id A V : Type}
[Fintype Id] [Fintype A] [AddCommGroup V] [Module F2 V] [Fintype V]
[Fintype (ActualHomogeneous.E k →ₗ[F2] V)]
(occurrences : FiniteDistribution (Fin k → Id)) (publicLaw : FiniteDistribution A)
(rhs : Id → Bool) (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :
((fullSeedLaw (V := V) occurrences publicLaw β hβ hβ').pushforward
(fullSeedPad rhs)).totalVariation
(withKernel (occurrences.product publicLaw)
(fun _ => FiniteDistribution.uniform (ActualHomogeneous.E k →ₗ[F2] V))) =
MaxCutGames.Foundations.Information.totalVariation
(SparseLaw.independentWeights (SparseLaw.mixture β (SparseLaw.singletonPairWeights V)) k)
(SparseLaw.uniformWeights (Fin k → V × V)) := by
rw [fullSeed_pad_law]
exact wholeAdvice_totalVariation_eq_slope occurrences publicLaw rhs β hβ hβ'
theorem fullSeed_totalVariation_le_slope {k : ℕ} {Id A V : Type}
[Fintype Id] [Fintype A] [AddCommGroup V] [Module F2 V] [Fintype V]
[Fintype (ActualHomogeneous.E k →ₗ[F2] V)]
(occurrences : FiniteDistribution (Fin k → Id)) (publicLaw : FiniteDistribution A)
(rhs : Id → Bool) (β : ℝ) (hβ : 0 ≤ β) (hβ' : β ≤ 1) :
((fullSeedLaw (V := V) occurrences publicLaw β hβ hβ').pushforward
(fullSeedPad rhs)).totalVariation
(withKernel (occurrences.product publicLaw)
(fun _ => FiniteDistribution.uniform (ActualHomogeneous.E k →ₗ[F2] V))) ≤
MaxCutGames.Foundations.Information.totalVariation
(SparseLaw.independentWeights (SparseLaw.mixture β (SparseLaw.singletonPairWeights V)) k)
(SparseLaw.uniformWeights (Fin k → V × V)) :=
(fullSeed_totalVariation_eq_slope occurrences publicLaw rhs β hβ hβ').le
variable {k : ℕ} {Id K W R : Type}
[AddCommGroup K] [Module F2 K] [AddCommGroup W] [Module F2 W]
[AddCommGroup R] [Module F2 R]
abbrev FullSeed (k : ℕ) (Id K W R : Type)
[AddCommGroup K] [Module F2 K] [AddCommGroup W] [Module F2 W]
[AddCommGroup R] [Module F2 R] :=
((Fin k → Id) × (K →ₗ[F2] R)) × ProjectionSeed k (K × W)
/-- Complete visible conditioning data: occurrences, public map, projection
choices, the entire complement map, and precisely the attainable rows. -/
abbrev CompleteData (k : ℕ) (Id K W R : Type)
[AddCommGroup K] [Module F2 K] [AddCommGroup W] [Module F2 W]
[AddCommGroup R] [Module F2 R] :=
Σ ua : (Fin k → Id) × (K →ₗ[F2] R),
Σ c : Fin k → PaddedLaw.ProjectionChoice,
(RawPoint (PaddedLaw.choiceMask c) →ₗ[F2] W) ×
AdviceFibers.ObservedRow (E := RawPoint (PaddedLaw.choiceMask c)) ua.2
abbrev PrivateMap (d : CompleteData k Id K W R) :=
RawPoint (PaddedLaw.choiceMask d.2.1) →ₗ[F2] d.1.2.ker
def targetObservationEquiv (J : Finset (Fin k)) (A : K →ₗ[F2] R) :
(RawPoint J →ₗ[F2] (K × W)) ≃
((RawPoint J →ₗ[F2] W) × AdviceFibers.ObservedRow (E := RawPoint J) A) ×
(RawPoint J →ₗ[F2] A.ker) :=
(LinearMap.prodEquiv F2).toEquiv.symm |>.trans
(Equiv.prodComm _ _) |>.trans
(Equiv.prodCongr (Equiv.refl _) (AdviceFibers.observationEquiv A)) |>.trans
(Equiv.prodAssoc _ _ _).symm
/-- A global bijection retains all actual visible data, with exactly one
uniform kernel-valued matrix left after conditioning. -/
def fullSeedCoordinatesEquiv :
FullSeed k Id K W R ≃ Σ d : CompleteData k Id K W R, PrivateMap d :=
((Equiv.sigmaEquivProd ((Fin k → Id) × (K →ₗ[F2] R))
(ProjectionSeed k (K × W))).symm.trans
(Equiv.sigmaCongrRight fun (ua : (Fin k → Id) × (K →ₗ[F2] R)) =>
Equiv.sigmaCongrRight fun c => targetObservationEquiv (PaddedLaw.choiceMask c) ua.2)).trans
{ toFun := fun p => ⟨⟨p.1, p.2.1, p.2.2.1⟩, p.2.2.2⟩
invFun := fun p => ⟨p.1.1, p.1.2.1, p.1.2.2, p.2⟩
left_inv := fun p => by rcases p with ⟨ua, c, ⟨T, S⟩, N⟩; rfl
right_inv := fun p => by rcases p with ⟨⟨ua, c, T, S⟩, N⟩; rfl }
def completeObserve (s : FullSeed k Id K W R) : CompleteData k Id K W R :=
(fullSeedCoordinatesEquiv s).1
def completeAssemble (d : CompleteData k Id K W R) (N : PrivateMap d) :
FullSeed k Id K W R :=
fullSeedCoordinatesEquiv.symm ⟨d, N⟩
theorem completeObserve_eq (s : FullSeed k Id K W R) :
completeObserve s = ⟨s.1, s.2.1,
(LinearMap.snd F2 K W).comp s.2.2,
AdviceFibers.observe s.1.2 ((LinearMap.fst F2 K W).comp s.2.2)⟩ := rfl
theorem completeAssemble_eq (d : CompleteData k Id K W R) (N : PrivateMap d) :
completeAssemble d N = (d.1, ⟨d.2.1,
(AdviceFibers.assemble d.1.2 (AdviceFibers.observedBase d.1.2 d.2.2.2) N).prod
d.2.2.1⟩) := rfl
@[simp] theorem completeObserve_assemble (d : CompleteData k Id K W R)
(N : PrivateMap d) : completeObserve (completeAssemble d N) = d :=
congrArg Sigma.fst (fullSeedCoordinatesEquiv.apply_symm_apply ⟨d, N⟩)
/-- Exact equivalence for a fiber of the complete observation, not just the
marginal row observation. This is the input for finite conditioning. -/
def completeFiberEquiv (d : CompleteData k Id K W R) :
PrivateMap d ≃ {s : FullSeed k Id K W R // completeObserve s = d} :=
((Equiv.subtypeEquiv fullSeedCoordinatesEquiv (fun _ => Iff.rfl)).trans
(Equiv.sigmaSubtype d)).symm
@[simp] theorem completeFiberEquiv_val (d : CompleteData k Id K W R) (N : PrivateMap d) :
(completeFiberEquiv d N).val = completeAssemble d N := rfl
/-- The actual Draw obtained from the complete-data fiber coordinates. -/
def completeDraw (d : CompleteData k Id K W R) (N : PrivateMap d) :
AdviceExperiment.Draw k Id K W R where
singletons := PaddedLaw.choiceMask d.2.1
occurrences := d.1.1
positions := PaddedLaw.choiceSlots d.2.1
rowMap := d.1.2
hiddenMatrix := AdviceFibers.assemble d.1.2 (AdviceFibers.observedBase d.1.2 d.2.2.2) N
complement := d.2.2.1
theorem completeDraw_seed (d : CompleteData k Id K W R) (N : PrivateMap d) :
seedToActualDraw (completeAssemble d N).1.1 (completeAssemble d N).1.2
(completeAssemble d N).2 = completeDraw d N := rfl
theorem completeDraw_rows (d : CompleteData k Id K W R) (N : PrivateMap d) :
(completeDraw d N).rowMap.comp (completeDraw d N).hiddenMatrix = d.2.2.2.val := by
exact (AdviceFibers.observed_assemble _ _ N).trans
(AdviceFibers.observedBase_property _ _)
theorem completeDraw_left (rhs : Id → F2) (d : CompleteData k Id K W R)
(N : PrivateMap d) :
AdviceExperiment.leftObservation rhs (completeDraw d N) = {
occurrences := d.1.1, rowMap := d.1.2,
complement := d.2.2.1.comp (rawProjection (fun j => toBit (rhs (d.1.1 j)))
(PaddedLaw.choiceMask d.2.1) (PaddedLaw.choiceSlots d.2.1)),
rows := d.2.2.2.val.comp (rawProjection (fun j => toBit (rhs (d.1.1 j)))
(PaddedLaw.choiceMask d.2.1) (PaddedLaw.choiceSlots d.2.1)) } := by
simp only [AdviceExperiment.leftObservation, completeDraw_rows] ; rfl
theorem completeDraw_right {Name : Type} (names : Id → Fin 3 → Name)
(d : CompleteData k Id K W R) (N : PrivateMap d) :
AdviceExperiment.rightObservation names (completeDraw d N) =
⟨PaddedLaw.choiceMask d.2.1, {
question := RawPrivateTable.supported (PaddedLaw.choiceMask d.2.1) names d.1.1
(PaddedLaw.choiceSlots d.2.1), rowMap := d.1.2,
complement := d.2.2.1, rows := d.2.2.2.val }⟩ := by
simp only [AdviceExperiment.rightObservation, completeDraw_rows] ; rfl
variable [Fintype Id] [Fintype K] [Fintype W] [Fintype R] [Fintype (K →ₗ[F2] R)]
def completeWeight (occurrences : FiniteDistribution (Fin k → Id))
(publicLaw : FiniteDistribution (K →ₗ[F2] R)) (β : ℝ)
(d : CompleteData k Id K W R) : ℝ :=
(occurrences.weight d.1.1 * publicLaw.weight d.1.2) *
(PaddedLaw.choiceTupleWeight β d.2.1 *
(1 / (Fintype.card (RawPoint (PaddedLaw.choiceMask d.2.1) →ₗ[F2] (K × W)) : ℝ)))
omit [Fintype R] in
/-- The actual law has exactly constant point weights on every fiber of all
observed data, even for arbitrary occurrence and public-map laws. -/
theorem fullSeed_weight_observed (occurrences : FiniteDistribution (Fin k → Id))
(publicLaw : FiniteDistribution (K →ₗ[F2] R)) (β : ℝ)
(hβ : 0 ≤ β) (hβ' : β ≤ 1) (s : FullSeed k Id K W R) :
(fullSeedLaw (V := K × W) occurrences publicLaw β hβ hβ').weight s =
completeWeight occurrences publicLaw β (completeObserve s) := rfl
omit [Fintype R] in
theorem fullSeed_weight_fiber (occurrences : FiniteDistribution (Fin k → Id))
(publicLaw : FiniteDistribution (K →ₗ[F2] R)) (β : ℝ)
(hβ : 0 ≤ β) (hβ' : β ≤ 1) (d : CompleteData k Id K W R)
(s : FullSeed k Id K W R) (hs : completeObserve s = d) :
(fullSeedLaw (V := K × W) occurrences publicLaw β hβ hβ').weight s =
completeWeight occurrences publicLaw β d := by
rw [fullSeed_weight_observed, hs]
end
end MaxCutGames.Decoder.AdviceLaw
end OAI