Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Definitions of SampledGame: Games generated from finite uniform samples Unlike `SeededGame`, the seed and the two question alphabets may differ

Definition
MIPRE_Foundations_SampledGame

by thomasvidick · Oct 16, 2026 · Mathlib 0df444a (Lean v4.33.1)

mip-remipre-formalizationverifiers

The 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).

Definition code
/-
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
Source
https://github.com/vidick/MIPRE-formalization/blob/70cbf1c52e3d5e1dff1162fdf952c9a9f4bd99ed/MIPRE/Foundations/SampledGame.lean; blueprint lem:detype-game-soundness

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me