Definitions of SampledGame: Games generated from finite uniform samples Unlike `SeededGame`, the seed and the two question alphabets may differ
DefinitionMIPRE_Foundations_SampledGameThe definitions of the module MIPRE.Foundations.SampledGame of the MIP* = RE formalization (commit 70cbf1c of vidick/MIPRE-formalization). Games generated from finite uniform samples. Unlike SeededGame, the seed and the two question alphabets may differ. This is needed for typed games, whose seed is an edge and a common vector.
Definitions (2): MIPRE.SampledGame.dist (Push forward the uniform law by the two question maps.); MIPRE.SampledGame.game (The finite game generated by the question maps and decision predicate.).
Embedded lemmas (3): the small results the bodies of these definitions need (proof fields, simp rules, decidability and finiteness instances), proved inside the bundle so that it imports no unproved statement: dist_nonneg, sum_dist, sum_dist_mul.
Formalization Note The bundle is the module MIPRE.Foundations.SampledGame (MIPRE/Foundations/SampledGame.lean) with every declaration not listed removed, imports rewritten to the bundles of the module's import closure; the declarations keep their names, statements and bodies; the source module is split over 3 imported bundle(s).
/-
Copyright (c) 2026 MIPRE contributors. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
-/
/- Generated for Prove2Me from vidick/MIPRE-formalization@70cbf1c, MIPRE/Foundations/SampledGame.lean (definition bundle: declarations the uploaded statements rest on);
produced mechanically by prove2me/tools/gen.py, never edited by hand. -/
import Mathlib.Analysis.CStarAlgebra.CStarMatrix
import Mathlib.Analysis.CStarAlgebra.Classes
import Mathlib.Analysis.Matrix.Order
import Mathlib.Data.ENat.Lattice
import Mathlib.LinearAlgebra.Matrix.Kronecker
import Definitions.Def_MIPRE_Foundations_Games
import Definitions.Def_MIPRE_Foundations_GameTransport
import Definitions.Def_MIPRE_Foundations_GameAdapt
/-! # Games generated from finite uniform samples
Unlike `SeededGame`, the seed and the two question alphabets may differ.
This is needed for typed games, whose seed is an edge and a common vector.
-/
noncomputable section
namespace MIPRE
open Finset Classical
set_option linter.unusedSectionVars false
namespace SampledGame
variable {S X Y : Type*} [Fintype S] [Fintype X] [Fintype Y]
/-- Push forward the uniform law by the two question maps. -/
def dist (qA : S → X) (qB : S → Y) (x : X) (y : Y) : ℝ :=
(Fintype.card S : ℝ)⁻¹ * ∑ s, if (qA s, qB s) = (x, y) then 1 else 0
/-- Averages over questions are averages over the common sample. -/
theorem sum_dist_mul (qA : S → X) (qB : S → Y) (f : X → Y → ℝ) :
∑ x, ∑ y, dist qA qB x y * f x y = (∑ s, f (qA s) (qB s)) / Fintype.card S := by
rw [← Fintype.sum_prod_type' fun x y => dist qA qB x y * f x y]
simp only [dist, mul_assoc, Finset.sum_mul, ← Finset.mul_sum]
rw [Finset.sum_comm]
have hs : ∀ s, (∑ p : X × Y, (if (qA s, qB s) = p then (1 : ℝ) else 0) * f p.1 p.2) =
f (qA s) (qB s) := by
intro s
rw [Finset.sum_eq_single (qA s, qB s)]
· simp
· intro p _ hp
simp [Ne.symm hp]
· simp
simp only [hs]
ring
/-- A uniform sample law is nonnegative. -/
theorem dist_nonneg (qA : S → X) (qB : S → Y) (x : X) (y : Y) : 0 ≤ dist qA qB x y :=
mul_nonneg (inv_nonneg.mpr (Nat.cast_nonneg _))
(Finset.sum_nonneg fun _ _ => by split_ifs <;> norm_num)
/-- A nonempty sample space gives a probability distribution. -/
theorem sum_dist [Nonempty S] (qA : S → X) (qB : S → Y) : ∑ x, ∑ y, dist qA qB x y = 1 := by
have h := sum_dist_mul qA qB (fun _ _ => 1)
have hc : (Fintype.card S : ℝ) ≠ 0 := by exact_mod_cast Fintype.card_ne_zero
simpa [hc] using h
/-- The finite game generated by the question maps and decision predicate. -/
def game [Nonempty S] {A B : Type*} [Fintype A] [Fintype B]
(qA : S → X) (qB : S → Y) (D : X → Y → A → B → Bool) : Game X Y A B where
μ := dist qA qB
μ_nonneg := dist_nonneg qA qB
μ_sum_one := sum_dist qA qB
D := D
end SampledGame
end MIPRE