import Mathlib namespace OAI section section section section section section section section section section section section section section section section section section section section section section section section namespace UniqueGames.Foundations.Games open scoped BigOperators noncomputable section structure FiniteDistribution (Ω : Type*) [Fintype Ω] where weight : Ω → ℝ nonnegative : ∀ x, 0 ≤ weight x normalized : ∑ x, weight x = 1 namespace FiniteDistribution variable {Ω Γ : Type*} [Fintype Ω] [Fintype Γ] def expectation (μ : FiniteDistribution Ω) (f : Ω → ℝ) : ℝ := ∑ x, μ.weight x * f x def probability (μ : FiniteDistribution Ω) (event : Ω → Bool) : ℝ := ∑ x, if event x then μ.weight x else 0 theorem probability_nonnegative (μ : FiniteDistribution Ω) (event : Ω → Bool) : 0 ≤ μ.probability event := by apply Finset.sum_nonneg intro x _ split · exact μ.nonnegative x · exact le_rfl theorem probability_le_one (μ : FiniteDistribution Ω) (event : Ω → Bool) : μ.probability event ≤ 1 := by rw [← μ.normalized] apply Finset.sum_le_sum intro x _ split · exact le_rfl · exact μ.nonnegative x @[simp] theorem probability_true (μ : FiniteDistribution Ω) : μ.probability (fun _ => true) = 1 := by simpa [probability] using μ.normalized @[simp] theorem probability_false (μ : FiniteDistribution Ω) : μ.probability (fun _ => false) = 0 := by simp [probability] theorem probability_mono (μ : FiniteDistribution Ω) {event event' : Ω → Bool} (h : ∀ x, event x = true → event' x = true) : μ.probability event ≤ μ.probability event' := by apply Finset.sum_le_sum intro x _ by_cases hx : event x = true · simp [hx, h x hx] · simp [hx] split · exact μ.nonnegative x · exact le_rfl def pushforward (μ : FiniteDistribution Ω) (f : Ω → Γ) : FiniteDistribution Γ := by classical exact { weight := fun y => ∑ x, if f x = y then μ.weight x else 0 nonnegative := fun y => Finset.sum_nonneg fun x _ => by split · exact μ.nonnegative x · exact le_rfl normalized := by rw [Finset.sum_comm] simpa using μ.normalized } theorem probability_pushforward (μ : FiniteDistribution Ω) (f : Ω → Γ) (event : Γ → Bool) : (μ.pushforward f).probability event = μ.probability (fun x => event (f x)) := by classical simp only [probability, pushforward] calc _ = ∑ y, ∑ x, if f x = y then (if event y then μ.weight x else 0) else 0 := by apply Finset.sum_congr rfl intro y _ by_cases hy : event y = true <;> simp [hy] _ = _ := by rw [Finset.sum_comm]; simp def transport (μ : FiniteDistribution Ω) (equiv : Ω ≃ Γ) : FiniteDistribution Γ where weight y := μ.weight (equiv.symm y) nonnegative y := μ.nonnegative (equiv.symm y) normalized := by rw [equiv.symm.sum_comp, μ.normalized] theorem probability_transport (μ : FiniteDistribution Ω) (equiv : Ω ≃ Γ) (event : Γ → Bool) : (μ.transport equiv).probability event = μ.probability (fun x => event (equiv x)) := by unfold probability transport exact Fintype.sum_equiv equiv.symm _ _ (fun _ => by simp) def iid (μ : FiniteDistribution Ω) (n : Nat) : FiniteDistribution (Fin n → Ω) where weight x := ∏ i, μ.weight (x i) nonnegative x := Finset.prod_nonneg fun i _ => μ.nonnegative (x i) normalized := by rw [← Fintype.sum_pow, μ.normalized, one_pow] theorem probability_iid_all (μ : FiniteDistribution Ω) (event : Ω → Bool) (n : Nat) : (μ.iid n).probability (fun x => decide (∀ i, event (x i) = true)) = μ.probability event ^ n := by classical unfold probability iid rw [Fintype.sum_pow] apply Finset.sum_congr rfl intro x _ simp only [decide_eq_true_eq] by_cases h : ∀ i, event (x i) = true · simp [h] · rw [ite_eq_right h] obtain ⟨i, hi⟩ := not_forall.mp h symm apply Finset.prod_eq_zero (Finset.mem_univ i) simp [hi] end FiniteDistribution abbrev Strategy (Q₁ Q₂ A₁ A₂ : Type*) := (Q₁ → A₁) × (Q₂ → A₂) structure Game (Q₁ Q₂ A₁ A₂ : Type*) [Fintype Q₁] [Fintype Q₂] [Fintype A₁] [Fintype A₂] where questions : FiniteDistribution (Q₁ × Q₂) accepts : Q₁ → Q₂ → A₁ → A₂ → Bool namespace Game variable {Q₁ Q₂ A₁ A₂ : Type*} [Fintype Q₁] [Fintype Q₂] [Fintype A₁] [Fintype A₂] def wins (G : Game Q₁ Q₂ A₁ A₂) (strategy : Strategy Q₁ Q₂ A₁ A₂) (questions : Q₁ × Q₂) : Bool := G.accepts questions.1 questions.2 (strategy.1 questions.1) (strategy.2 questions.2) def success (G : Game Q₁ Q₂ A₁ A₂) (strategy : Strategy Q₁ Q₂ A₁ A₂) : ℝ := G.questions.probability (G.wins strategy) theorem success_nonnegative (G : Game Q₁ Q₂ A₁ A₂) (strategy : Strategy Q₁ Q₂ A₁ A₂) : 0 ≤ G.success strategy := G.questions.probability_nonnegative _ theorem success_le_one (G : Game Q₁ Q₂ A₁ A₂) (strategy : Strategy Q₁ Q₂ A₁ A₂) : G.success strategy ≤ 1 := G.questions.probability_le_one _ def simulatedStrategy {R₁ R₂ B₁ B₂ : Type*} (questionMap₁ : Q₁ → R₁) (questionMap₂ : Q₂ → R₂) (answerMap₁ : Q₁ → B₁ → A₁) (answerMap₂ : Q₂ → B₂ → A₂) (strategy : Strategy R₁ R₂ B₁ B₂) : Strategy Q₁ Q₂ A₁ A₂ := (fun x => answerMap₁ x (strategy.1 (questionMap₁ x)), fun y => answerMap₂ y (strategy.2 (questionMap₂ y))) theorem success_le_of_localSimulation {R₁ R₂ B₁ B₂ : Type*} [Fintype R₁] [Fintype R₂] [Fintype B₁] [Fintype B₂] (G : Game Q₁ Q₂ A₁ A₂) (H : Game R₁ R₂ B₁ B₂) (questionMap₁ : Q₁ → R₁) (questionMap₂ : Q₂ → R₂) (answerMap₁ : Q₁ → B₁ → A₁) (answerMap₂ : Q₂ → B₂ → A₂) (questionLaw : H.questions = G.questions.pushforward (fun q => (questionMap₁ q.1, questionMap₂ q.2))) (acceptance : ∀ x y a b, H.accepts (questionMap₁ x) (questionMap₂ y) a b = true → G.accepts x y (answerMap₁ x a) (answerMap₂ y b) = true) (strategy : Strategy R₁ R₂ B₁ B₂) : H.success strategy ≤ G.success (simulatedStrategy questionMap₁ questionMap₂ answerMap₁ answerMap₂ strategy) := by unfold success rw [questionLaw, FiniteDistribution.probability_pushforward] apply FiniteDistribution.probability_mono intro questions h exact acceptance questions.1 questions.2 _ _ h def tupleQuestionEquiv (n : Nat) : (Fin n → Q₁ × Q₂) ≃ (Fin n → Q₁) × (Fin n → Q₂) where toFun questions := (fun i => (questions i).1, fun i => (questions i).2) invFun questions := fun i => (questions.1 i, questions.2 i) left_inv _ := rfl right_inv _ := rfl def repetition (G : Game Q₁ Q₂ A₁ A₂) (n : Nat) : Game (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂) := by classical exact { questions := (G.questions.iid n).transport (tupleQuestionEquiv n) accepts := fun x y a b => decide (∀ i, G.accepts (x i) (y i) (a i) (b i) = true) } def repeatStrategy (strategy : Strategy Q₁ Q₂ A₁ A₂) (n : Nat) : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂) := (fun x i => strategy.1 (x i), fun y i => strategy.2 (y i)) theorem success_repeatStrategy (G : Game Q₁ Q₂ A₁ A₂) (strategy : Strategy Q₁ Q₂ A₁ A₂) (n : Nat) : (G.repetition n).success (repeatStrategy strategy n) = G.success strategy ^ n := by unfold success change ((G.questions.iid n).transport (tupleQuestionEquiv n)).probability _ = _ rw [FiniteDistribution.probability_transport] exact G.questions.probability_iid_all (G.wins strategy) n @[simp] theorem repetition_question_weight (G : Game Q₁ Q₂ A₁ A₂) (n : Nat) (questions : (Fin n → Q₁) × (Fin n → Q₂)) : (G.repetition n).questions.weight questions = ∏ i, G.questions.weight (questions.1 i, questions.2 i) := rfl @[simp] theorem repetition_accepts_iff (G : Game Q₁ Q₂ A₁ A₂) (n : Nat) (x : Fin n → Q₁) (y : Fin n → Q₂) (a : Fin n → A₁) (b : Fin n → A₂) : (G.repetition n).accepts x y a b = true ↔ ∀ i, G.accepts (x i) (y i) (a i) (b i) = true := by classical simp [repetition] def coordinateWin (G : Game Q₁ Q₂ A₁ A₂) {n : Nat} (strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂)) (coordinate : Fin n) (questions : (Fin n → Q₁) × (Fin n → Q₂)) : Bool := G.accepts (questions.1 coordinate) (questions.2 coordinate) (strategy.1 questions.1 coordinate) (strategy.2 questions.2 coordinate) def selectedWins (G : Game Q₁ Q₂ A₁ A₂) {n : Nat} (strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂)) (selected : Finset (Fin n)) (questions : (Fin n → Q₁) × (Fin n → Q₂)) : Bool := by classical exact decide (∀ i ∈ selected, G.coordinateWin strategy i questions = true) theorem selectedWins_mono (G : Game Q₁ Q₂ A₁ A₂) {n : Nat} (strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂)) {selected selected' : Finset (Fin n)} (h : selected ⊆ selected') : (G.repetition n).questions.probability (G.selectedWins strategy selected') ≤ (G.repetition n).questions.probability (G.selectedWins strategy selected) := by apply FiniteDistribution.probability_mono intro questions hwin simp only [selectedWins, decide_eq_true_eq] at hwin ⊢ intro i hi exact hwin i (h hi) @[simp] theorem selectedWins_empty (G : Game Q₁ Q₂ A₁ A₂) {n : Nat} (strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂)) (questions : (Fin n → Q₁) × (Fin n → Q₂)) : G.selectedWins strategy ∅ questions = true := by simp [selectedWins] theorem selectedWins_univ (G : Game Q₁ Q₂ A₁ A₂) {n : Nat} (strategy : Strategy (Fin n → Q₁) (Fin n → Q₂) (Fin n → A₁) (Fin n → A₂)) : G.selectedWins strategy Finset.univ = (G.repetition n).wins strategy := by classical funext questions simp [selectedWins, coordinateWin, repetition, wins] end Game end end UniqueGames.Foundations.Games end end end end end end end end end end end end end end end end end end end end end end end end end OAI