Download data/lean/OAI/Computability/DirectedFeedback/Games/Collision.lean from introvoyz045/math: direct link, hf CLI and curl.
- Browser
- Download file 30.7 kB
-
https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/DirectedFeedback/Games/Collision.lean
- Command line
-
hf download hf://datasets/introvoyz045/math/data/lean/OAI/Computability/DirectedFeedback/Games/Collision.lean
-
curl -L -o Collision.lean https://huggingface.co/datasets/introvoyz045/math/resolve/main/data/lean/OAI/Computability/DirectedFeedback/Games/Collision.lean
30.7 kB
| import Mathlib | |
| import OAI.Computability.DirectedFeedback.Games.SharedSampling | |
| namespace OAI | |
| namespace DFVSGames.Repetition | |
| open DFVSGames.Foundations.Games | |
| open scoped BigOperators | |
| noncomputable section | |
| structure ProjectionKernel (Qβ Qβ Aβ Aβ : Type*) | |
| [Fintype Qβ] [Fintype Qβ] [Fintype Aβ] [Fintype Aβ] where | |
| outer : FiniteDistribution Qβ | |
| inner : Qβ β FiniteDistribution Qβ | |
| accepts : Qβ β Qβ β Aβ β Aβ β Bool | |
| projection : β x y a b b', accepts x y a b = true β | |
| accepts x y a b' = true β b = b' | |
| namespace ProjectionKernel | |
| variable {Qβ Qβ Aβ Aβ Ξ© : Type*} | |
| [Fintype Qβ] [Fintype Qβ] [Fintype Aβ] [Fintype Aβ] [Fintype Ξ©] | |
| def toGame (K : ProjectionKernel Qβ Qβ Aβ Aβ) : Game Qβ Qβ Aβ Aβ where | |
| questions := | |
| { weight := fun q => K.outer.weight q.2 * (K.inner q.2).weight q.1 | |
| nonnegative := fun q => mul_nonneg (K.outer.nonnegative _) ((K.inner _).nonnegative _) | |
| normalized := by | |
| rw [Fintype.sum_prod_type, Finset.sum_comm] | |
| simp_rw [β Finset.mul_sum, FiniteDistribution.normalized, mul_one] | |
| exact K.outer.normalized } | |
| accepts := K.accepts | |
| theorem toGame_isProjection (K : ProjectionKernel Qβ Qβ Aβ Aβ) : | |
| IsProjection K.toGame := K.projection | |
| def apply (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (f : Qβ β Aβ β β) (y : Qβ) (b : Aβ) : β := | |
| β x, (K.inner y).weight x * β a, if K.accepts x y a b then f x a else 0 | |
| def energy (K : ProjectionKernel Qβ Qβ Aβ Aβ) (f : Qβ β Aβ β β) : β := | |
| β y, K.outer.weight y * β b, K.apply f y b ^ 2 | |
| def assignment (labels : Qβ β Aβ) (x : Qβ) (a : Aβ) : β := by | |
| classical | |
| exact if labels x = a then 1 else 0 | |
| def assignmentEnergy (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (labels : Qβ β Aβ) : β := K.energy (assignment labels) | |
| def collisionValue [Nonempty Aβ] (K : ProjectionKernel Qβ Qβ Aβ Aβ) : β := by | |
| classical | |
| exact Finset.univ.sup' Finset.univ_nonempty K.assignmentEnergy | |
| def vectorEnergy (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (f : Ξ© β Qβ β Aβ β β) : β := β Ο, K.energy (f Ο) | |
| def vectorMass (f : Ξ© β Qβ β Aβ β β) (x : Qβ) : β := | |
| β Ο, (β a, f Ο x a) ^ 2 | |
| theorem energy_nonneg (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (f : Qβ β Aβ β β) : 0 β€ K.energy f := by | |
| exact Finset.sum_nonneg fun y _ => mul_nonneg (K.outer.nonnegative y) | |
| (Finset.sum_nonneg fun b _ => sq_nonneg _) | |
| theorem assignmentEnergy_le_collisionValue [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) (labels : Qβ β Aβ) : | |
| K.assignmentEnergy labels β€ K.collisionValue := by | |
| classical | |
| exact Finset.le_sup' _ (Finset.mem_univ labels) | |
| theorem collisionValue_le_iff [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) (bound : β) : | |
| K.collisionValue β€ bound β β labels, K.assignmentEnergy labels β€ bound := by | |
| classical | |
| simp [collisionValue, Finset.sup'_le_iff] | |
| theorem exists_optimal_assignment [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) : | |
| β labels, K.assignmentEnergy labels = K.collisionValue := by | |
| classical | |
| obtain β¨labels, _, hβ© := Finset.exists_mem_eq_sup' | |
| (s := (Finset.univ : Finset (Qβ β Aβ))) Finset.univ_nonempty K.assignmentEnergy | |
| exact β¨labels, h.symmβ© | |
| theorem collisionValue_nonneg [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) : 0 β€ K.collisionValue := by | |
| obtain β¨labels, hβ© := K.exists_optimal_assignment | |
| rw [β h] | |
| exact K.energy_nonneg _ | |
| @[simp] theorem apply_assignment (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (labels : Qβ β Aβ) (y : Qβ) (b : Aβ) : | |
| K.apply (assignment labels) y b = | |
| β x, if K.accepts x y (labels x) b then (K.inner y).weight x else 0 := by | |
| classical | |
| unfold apply assignment | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| have hsum : (β a, if K.accepts x y a b then | |
| (if labels x = a then (1 : β) else 0) else 0) = | |
| if K.accepts x y (labels x) b then (1 : β) else 0 := by | |
| have hpoint (a : Aβ) : | |
| (if K.accepts x y a b then (if labels x = a then (1 : β) else 0) else 0) = | |
| (if a = labels x then (if K.accepts x y a b then (1 : β) else 0) else 0) := by | |
| by_cases h : a = labels x | |
| Β· subst a | |
| simp | |
| Β· simp [h, Ne.symm h] | |
| simp_rw [hpoint] | |
| simp | |
| rw [hsum] | |
| by_cases h : K.accepts x y (labels x) b = true <;> simp [h] | |
| end ProjectionKernel | |
| end | |
| end DFVSGames.Repetition | |
| namespace DFVSGames.Repetition.ProjectionKernel | |
| open Foundations.Games | |
| open scoped BigOperators | |
| noncomputable section | |
| attribute [local instance] Classical.propDecidable | |
| variable {Qβ Qβ Aβ Aβ Ξ© : Type*} | |
| [Fintype Qβ] [Fintype Qβ] [Fintype Aβ] [Fintype Aβ] [Fintype Ξ©] | |
| abbrev SymmetricEdge (Qβ Qβ : Type*) := Qβ Γ Qβ Γ Qβ | |
| def symmetricLeft (e : SymmetricEdge Qβ Qβ) : Qβ := e.2.1 | |
| def symmetricRight (e : SymmetricEdge Qβ Qβ) : Qβ := e.2.2 | |
| def symmetricDistribution (K : ProjectionKernel Qβ Qβ Aβ Aβ) : | |
| FiniteDistribution (SymmetricEdge Qβ Qβ) where | |
| weight e := K.outer.weight e.1 * (K.inner e.1).weight e.2.1 * | |
| (K.inner e.1).weight e.2.2 | |
| nonnegative e := mul_nonneg | |
| (mul_nonneg (K.outer.nonnegative _) ((K.inner _).nonnegative _)) | |
| ((K.inner _).nonnegative _) | |
| normalized := by | |
| rw [Fintype.sum_prod_type] | |
| calc | |
| _ = β y, K.outer.weight y := by | |
| apply Finset.sum_congr rfl | |
| intro y _ | |
| rw [Fintype.sum_prod_type] | |
| calc | |
| _ = β x, K.outer.weight y * (K.inner y).weight x := by | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| dsimp only | |
| rw [β Finset.mul_sum, (K.inner y).normalized, mul_one] | |
| _ = K.outer.weight y := by | |
| rw [β Finset.mul_sum, (K.inner y).normalized, mul_one] | |
| _ = 1 := K.outer.normalized | |
| def symmetricAccept (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (e : SymmetricEdge Qβ Qβ) (a a' : Aβ) : Bool := by | |
| classical | |
| exact decide (β b, K.accepts e.2.1 e.1 a b = true β§ | |
| K.accepts e.2.2 e.1 a' b = true) | |
| def singleLabelVector (a : Qβ β Ξ© β Aβ) (f : Qβ β Ξ© β β) | |
| (Ο : Ξ©) (x : Qβ) (b : Aβ) : β := by | |
| classical | |
| exact if a x Ο = b then f x Ο else 0 | |
| theorem sum_projection_gates (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (y : Qβ) (x x' : Qβ) (a a' : Aβ) (r s : β) : | |
| (β b, (if K.accepts x y a b then r else 0) * | |
| (if K.accepts x' y a' b then s else 0)) = | |
| if K.symmetricAccept (y, x, x') a a' then r * s else 0 := by | |
| classical | |
| by_cases hex : β b, K.accepts x y a b = true β§ K.accepts x' y a' b = true | |
| Β· obtain β¨bβ, hbβ, hbβ'β© := hex | |
| have hex' : β b, K.accepts x y a b = true β§ K.accepts x' y a' b = true := | |
| β¨bβ, hbβ, hbβ'β© | |
| simp only [symmetricAccept, hex', decide_true, ite_true] | |
| calc | |
| _ = (if K.accepts x y a bβ then r else 0) * | |
| (if K.accepts x' y a' bβ then s else 0) := by | |
| apply Finset.sum_eq_single bβ | |
| Β· intro b _ hne | |
| have hb : K.accepts x y a b β true := by | |
| intro hb | |
| exact hne (K.projection x y a b bβ hb hbβ) | |
| simp [hb] | |
| Β· simp | |
| _ = r * s := by simp [hbβ, hbβ'] | |
| Β· simp only [symmetricAccept, hex, decide_false, Bool.false_eq_true, ite_false] | |
| apply Finset.sum_eq_zero | |
| intro b _ | |
| by_cases hb : K.accepts x y a b = true | |
| Β· have hb' : K.accepts x' y a' b β true := fun hb' => hex β¨b, hb, hb'β© | |
| simp [hb'] | |
| Β· simp [hb] | |
| theorem apply_single_label (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (labels : Qβ β Aβ) (f : Qβ β β) (y : Qβ) (b : Aβ) : | |
| K.apply (fun x a => if labels x = a then f x else 0) y b = | |
| β x, (K.inner y).weight x * (if K.accepts x y (labels x) b then f x else 0) := by | |
| classical | |
| unfold apply | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| congr 1 | |
| calc | |
| _ = β a, if labels x = a then | |
| (if K.accepts x y (labels x) b then f x else 0) else 0 := by | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| by_cases ha : labels x = a | |
| Β· subst a | |
| simp | |
| Β· simp [ha] | |
| _ = _ := by simp | |
| theorem energy_single_label (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (labels : Qβ β Aβ) (f : Qβ β β) : | |
| K.energy (fun x a => if labels x = a then f x else 0) = | |
| K.symmetricDistribution.expectation (fun e => | |
| if K.symmetricAccept e (labels (symmetricLeft e)) (labels (symmetricRight e)) | |
| then f (symmetricLeft e) * f (symmetricRight e) else 0) := by | |
| classical | |
| have hexpand (y : Qβ) : | |
| (β b, (β x, (K.inner y).weight x * | |
| (if K.accepts x y (labels x) b then f x else 0)) ^ 2) = | |
| β x, β x', (K.inner y).weight x * (K.inner y).weight x' * | |
| (if K.symmetricAccept (y, x, x') (labels x) (labels x') | |
| then f x * f x' else 0) := by | |
| simp only [pow_two, Finset.sum_mul, Finset.mul_sum] | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro x' _ | |
| calc | |
| _ = (K.inner y).weight x * (K.inner y).weight x' * | |
| β b, (if K.accepts x y (labels x) b then f x else 0) * | |
| (if K.accepts x' y (labels x') b then f x' else 0) := by | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro b _ | |
| ring | |
| _ = _ := by rw [K.sum_projection_gates] | |
| unfold energy | |
| simp_rw [K.apply_single_label, hexpand] | |
| simp only [FiniteDistribution.expectation, symmetricDistribution, | |
| Fintype.sum_prod_type, symmetricLeft, symmetricRight, Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro y _ | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| apply Finset.sum_congr rfl | |
| intro x' _ | |
| simp only [mul_assoc] | |
| rfl | |
| theorem vectorEnergy_singleLabelVector (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (a : Qβ β Ξ© β Aβ) (f : Qβ β Ξ© β β) : | |
| K.vectorEnergy (singleLabelVector a f) = | |
| pairEnergy K.symmetricDistribution symmetricLeft symmetricRight K.symmetricAccept a f := by | |
| classical | |
| unfold vectorEnergy singleLabelVector | |
| simp_rw [K.energy_single_label] | |
| unfold pairEnergy FiniteDistribution.expectation | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro e _ | |
| rw [Finset.mul_sum] | |
| theorem symmetric_probability_eq_assignmentEnergy (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (labels : Qβ β Aβ) : | |
| K.symmetricDistribution.probability (fun e => | |
| K.symmetricAccept e (labels (symmetricLeft e)) (labels (symmetricRight e))) = | |
| K.assignmentEnergy labels := by | |
| classical | |
| change _ = K.energy (fun x a => if labels x = a then (1 : β) else 0) | |
| rw [K.energy_single_label] | |
| simp only [FiniteDistribution.probability, FiniteDistribution.expectation, | |
| mul_ite, mul_one, mul_zero] | |
| end | |
| end DFVSGames.Repetition.ProjectionKernel | |
| namespace DFVSGames.Repetition.ProjectionKernel | |
| open scoped BigOperators | |
| noncomputable section | |
| attribute [local instance] Classical.propDecidable | |
| variable {Qβ Qβ Aβ Aβ Ξ© : Type*} | |
| [Fintype Qβ] [Fintype Qβ] [Fintype Aβ] [Fintype Aβ] [Fintype Ξ©] | |
| def linearCoefficient (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (t : Qβ Γ Aβ) (x : Qβ) (a : Aβ) : β := | |
| (K.inner t.1).weight x * (if K.accepts x t.1 a t.2 then 1 else 0) | |
| theorem apply_eq_linearCoefficient_sum (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (h : Qβ β Aβ β β) (y : Qβ) (b : Aβ) : | |
| K.apply h y b = β x, β a, K.linearCoefficient (y, b) x a * h x a := by | |
| unfold apply | |
| simp_rw [Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| by_cases ha : K.accepts x y a b = true <;> simp [linearCoefficient, ha] | |
| theorem energy_eq_linearCoefficient_sum (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (h : Qβ β Aβ β β) : | |
| K.energy h = β t : Qβ Γ Aβ, K.outer.weight t.1 * | |
| (β x, β a, K.linearCoefficient t x a * h x a) ^ 2 := by | |
| rw [Fintype.sum_prod_type] | |
| simp_rw [β K.apply_eq_linearCoefficient_sum, β Finset.mul_sum] | |
| rfl | |
| theorem exists_energy_le_deterministicVector [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (h : Qβ β Aβ β β) (hh : β x a, 0 β€ h x a) : | |
| β labels : Qβ β Aβ, | |
| K.energy h β€ K.energy (deterministicVector h labels) := by | |
| classical | |
| obtain β¨labels, _, _, hlabelsβ© := exists_deterministic_vector h hh | |
| (fun t : Qβ Γ Aβ => K.outer.weight t.1) | |
| (fun t => K.outer.nonnegative t.1) K.linearCoefficient | |
| refine β¨labels, ?_β© | |
| rw [K.energy_eq_linearCoefficient_sum, K.energy_eq_linearCoefficient_sum] | |
| exact hlabels | |
| def vectorAmplitude (h : Ξ© β Qβ β Aβ β β) (x : Qβ) (Ο : Ξ©) : β := | |
| rowMass (h Ο) x | |
| omit [Fintype Ξ©] in | |
| omit [Fintype Qβ] in | |
| theorem vectorAmplitude_nonnegative (h : Ξ© β Qβ β Aβ β β) | |
| (hh : β Ο x a, 0 β€ h Ο x a) (x : Qβ) (Ο : Ξ©) : | |
| 0 β€ vectorAmplitude h x Ο := | |
| rowMass_nonnegative (h Ο) (hh Ο) x | |
| omit [Fintype Qβ] in | |
| @[simp] theorem rowSquareMass_vectorAmplitude (h : Ξ© β Qβ β Aβ β β) (x : Qβ) : | |
| rowSquareMass (vectorAmplitude h) x = vectorMass h x := rfl | |
| theorem exists_vectorEnergy_le_singleLabelVector [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (h : Ξ© β Qβ β Aβ β β) (hh : β Ο x a, 0 β€ h Ο x a) : | |
| β labels : Qβ β Ξ© β Aβ, | |
| K.vectorEnergy h β€ K.vectorEnergy (singleLabelVector labels (vectorAmplitude h)) := by | |
| classical | |
| have hex (Ο : Ξ©) := K.exists_energy_le_deterministicVector (h Ο) (hh Ο) | |
| let labels (Ο : Ξ©) : Qβ β Aβ := Classical.choose (hex Ο) | |
| have hlabels (Ο : Ξ©) : K.energy (h Ο) β€ | |
| K.energy (deterministicVector (h Ο) (labels Ο)) := Classical.choose_spec (hex Ο) | |
| refine β¨fun x Ο => labels Ο x, ?_β© | |
| apply Finset.sum_le_sum | |
| intro Ο _ | |
| have heq : deterministicVector (h Ο) (labels Ο) = | |
| singleLabelVector (fun x Ο => labels Ο x) (vectorAmplitude h) Ο := by | |
| funext x a | |
| by_cases ha : a = labels Ο x | |
| Β· simp [deterministicVector, singleLabelVector, vectorAmplitude, ha] | |
| Β· simp [deterministicVector, singleLabelVector, ha, Ne.symm ha] | |
| exact heq βΈ hlabels Ο | |
| theorem exists_mass_preserving_singleLabelVector [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (h : Ξ© β Qβ β Aβ β β) (hh : β Ο x a, 0 β€ h Ο x a) : | |
| β (labels : Qβ β Ξ© β Aβ) (f : Qβ β Ξ© β β), | |
| (β x Ο, 0 β€ f x Ο) β§ | |
| (β x, rowSquareMass f x = vectorMass h x) β§ | |
| K.vectorEnergy h β€ K.vectorEnergy (singleLabelVector labels f) := by | |
| obtain β¨labels, hlabelsβ© := K.exists_vectorEnergy_le_singleLabelVector h hh | |
| exact β¨labels, vectorAmplitude h, vectorAmplitude_nonnegative h hh, | |
| rowSquareMass_vectorAmplitude h, hlabelsβ© | |
| end | |
| end DFVSGames.Repetition.ProjectionKernel | |
| namespace DFVSGames.Repetition | |
| open DFVSGames.Foundations.Games | |
| open scoped BigOperators | |
| noncomputable section | |
| namespace ProjectionKernel | |
| variable {Qβ Qβ Aβ Aβ : Type*} | |
| [Fintype Qβ] [Fintype Qβ] [Fintype Aβ] [Fintype Aβ] | |
| theorem sq_expectation_le_expectation_sq {Ξ© : Type*} [Fintype Ξ©] | |
| (ΞΌ : FiniteDistribution Ξ©) (f : Ξ© β β) : | |
| ΞΌ.expectation f ^ 2 β€ ΞΌ.expectation (fun x => f x ^ 2) := by | |
| have h := Finset.sum_sq_le_sum_mul_sum_of_sq_le_mul | |
| (s := (Finset.univ : Finset Ξ©)) | |
| (r := fun x => ΞΌ.weight x * f x) | |
| (f := ΞΌ.weight) (g := fun x => ΞΌ.weight x * f x ^ 2) | |
| (fun x _ => ΞΌ.nonnegative x) | |
| (fun x _ => mul_nonneg (ΞΌ.nonnegative x) (sq_nonneg _)) | |
| (fun x _ => by ring_nf; exact le_rfl) | |
| simpa only [ΞΌ.normalized, one_mul, FiniteDistribution.expectation] using h | |
| theorem apply_assignment_nonneg (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (labels : Qβ β Aβ) (y : Qβ) (b : Aβ) : | |
| 0 β€ K.apply (assignment labels) y b := by | |
| rw [apply_assignment] | |
| exact (K.inner y).probability_nonnegative (fun x => K.accepts x y (labels x) b) | |
| theorem sum_apply_assignment_le_one (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (labels : Qβ β Aβ) (y : Qβ) : | |
| (β b, K.apply (assignment labels) y b) β€ 1 := by | |
| classical | |
| simp only [apply_assignment] | |
| rw [Finset.sum_comm, β (K.inner y).normalized] | |
| apply Finset.sum_le_sum | |
| intro x _ | |
| by_cases hex : β b, K.accepts x y (labels x) b = true | |
| Β· obtain β¨bβ, hbββ© := hex | |
| have hiff : β b, K.accepts x y (labels x) b = true β b = bβ := by | |
| intro b | |
| constructor | |
| Β· intro hb | |
| exact K.projection x y (labels x) b bβ hb hbβ | |
| Β· rintro rfl | |
| exact hbβ | |
| simp only [hiff] | |
| simp | |
| Β· have hnone : β b, K.accepts x y (labels x) b β true := by | |
| intro b hb | |
| exact hex β¨b, hbβ© | |
| simpa [hnone] using (K.inner y).nonnegative x | |
| theorem success_eq_outer_apply (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (s : Strategy Qβ Qβ Aβ Aβ) : | |
| K.toGame.success s = | |
| K.outer.expectation (fun y => K.apply (assignment s.1) y (s.2 y)) := by | |
| classical | |
| simp only [Game.success, Game.wins, toGame, FiniteDistribution.probability, | |
| FiniteDistribution.expectation, apply_assignment, Fintype.sum_prod_type] | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro y _ | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| by_cases h : K.accepts x y (s.1 x) (s.2 y) = true <;> simp [h] | |
| theorem success_sq_le_assignmentEnergy (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (s : Strategy Qβ Qβ Aβ Aβ) : | |
| K.toGame.success s ^ 2 β€ K.assignmentEnergy s.1 := by | |
| rw [success_eq_outer_apply] | |
| calc | |
| _ β€ K.outer.expectation | |
| (fun y => K.apply (assignment s.1) y (s.2 y) ^ 2) := | |
| sq_expectation_le_expectation_sq K.outer _ | |
| _ β€ K.assignmentEnergy s.1 := by | |
| apply Finset.sum_le_sum | |
| intro y _ | |
| apply mul_le_mul_of_nonneg_left _ (K.outer.nonnegative y) | |
| exact Finset.single_le_sum (fun b _ => sq_nonneg _) (Finset.mem_univ (s.2 y)) | |
| theorem value_sq_le_collisionValue [Nonempty Aβ] [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) : | |
| K.toGame.value ^ 2 β€ K.collisionValue := by | |
| obtain β¨s, hsβ© := K.toGame.exists_optimal_strategy | |
| rw [β hs] | |
| exact (K.success_sq_le_assignmentEnergy s).trans (K.assignmentEnergy_le_collisionValue s.1) | |
| theorem exists_best_response [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) (labels : Qβ β Aβ) : | |
| β answers : Qβ β Aβ, β y b, | |
| K.apply (assignment labels) y b β€ K.apply (assignment labels) y (answers y) := by | |
| classical | |
| have h : β y, β b : Aβ, β b', | |
| K.apply (assignment labels) y b' β€ K.apply (assignment labels) y b := by | |
| intro y | |
| obtain β¨b, _, hbβ© := Finset.exists_mem_eq_sup' | |
| (s := (Finset.univ : Finset Aβ)) Finset.univ_nonempty | |
| (fun b => K.apply (assignment labels) y b) | |
| refine β¨b, fun b' => ?_β© | |
| rw [β hb] | |
| exact Finset.le_sup' _ (Finset.mem_univ b') | |
| exact β¨fun y => Classical.choose (h y), fun y b => Classical.choose_spec (h y) bβ© | |
| theorem assignmentEnergy_le_value [Nonempty Aβ] [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) (labels : Qβ β Aβ) : | |
| K.assignmentEnergy labels β€ K.toGame.value := by | |
| obtain β¨answers, hanswersβ© := K.exists_best_response labels | |
| calc | |
| _ β€ K.toGame.success (labels, answers) := by | |
| rw [success_eq_outer_apply] | |
| apply Finset.sum_le_sum | |
| intro y _ | |
| apply mul_le_mul_of_nonneg_left _ (K.outer.nonnegative y) | |
| calc | |
| _ β€ β b, K.apply (assignment labels) y b * | |
| K.apply (assignment labels) y (answers y) := by | |
| apply Finset.sum_le_sum | |
| intro b _ | |
| rw [pow_two] | |
| exact mul_le_mul_of_nonneg_left (hanswers y b) | |
| (K.apply_assignment_nonneg labels y b) | |
| _ = (β b, K.apply (assignment labels) y b) * | |
| K.apply (assignment labels) y (answers y) := (Finset.sum_mul _ _ _).symm | |
| _ β€ 1 * K.apply (assignment labels) y (answers y) := | |
| mul_le_mul_of_nonneg_right (K.sum_apply_assignment_le_one labels y) | |
| (K.apply_assignment_nonneg labels y (answers y)) | |
| _ = _ := one_mul _ | |
| _ β€ K.toGame.value := K.toGame.success_le_value _ | |
| theorem collisionValue_le_value [Nonempty Aβ] [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) : | |
| K.collisionValue β€ K.toGame.value := | |
| (K.collisionValue_le_iff _).mpr K.assignmentEnergy_le_value | |
| theorem collisionValue_le_one [Nonempty Aβ] [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) : K.collisionValue β€ 1 := | |
| K.collisionValue_le_value.trans K.toGame.value_le_one | |
| end ProjectionKernel | |
| end | |
| end DFVSGames.Repetition | |
| namespace DFVSGames.Repetition.ProjectionKernel | |
| open scoped BigOperators | |
| open Foundations.Games | |
| noncomputable section | |
| variable {Qβ Qβ Aβ Aβ Ξ© : Type*} | |
| [Fintype Qβ] [Fintype Qβ] [Fintype Aβ] [Fintype Aβ] [Fintype Ξ©] | |
| private theorem distribution_nonempty_inline_RoundingKernel {T : Type*} [Fintype T] | |
| (ΞΌ : FiniteDistribution T) : Nonempty T := by | |
| by_contra h | |
| have : IsEmpty T := not_nonempty_iff.mp h | |
| have hz : (β t, ΞΌ.weight t) = 0 := by simp | |
| linarith [ΞΌ.normalized] | |
| theorem vectorEnergy_le_gap_rate [Nonempty Aβ] [Nonempty Aβ] | |
| (K : ProjectionKernel Qβ Qβ Aβ Aβ) (f : Ξ© β Qβ β Aβ β β) | |
| (hf : β Ο x a, 0 β€ f Ο x a) (hmass : β x, vectorMass f x β€ 1) | |
| {g : β} (hg0 : 0 β€ g) (hg1 : g β€ 1) | |
| (hvalue : K.toGame.value β€ 1 - g) : | |
| K.vectorEnergy f β€ 1 - g ^ 2 / 8 := by | |
| classical | |
| let : Nonempty Qβ := distribution_nonempty_inline_RoundingKernel K.outer | |
| let : Nonempty Qβ := distribution_nonempty_inline_RoundingKernel | |
| (K.inner (Classical.choice (inferInstance : Nonempty Qβ))) | |
| rcases isEmpty_or_nonempty Ξ© with hΞ© | hΞ© | |
| Β· let : IsEmpty Ξ© := hΞ© | |
| have hzero : K.vectorEnergy f = 0 := by simp [vectorEnergy] | |
| rw [hzero] | |
| have hsq : g * g β€ (1 : β) * 1 := mul_le_mul hg1 hg1 hg0 (by norm_num) | |
| nlinarith | |
| Β· let : Nonempty Ξ© := hΞ© | |
| obtain β¨labels, hdetβ© := K.exists_vectorEnergy_le_singleLabelVector f hf | |
| have hnonneg := vectorAmplitude_nonnegative f hf | |
| have hrow : β x, rowSquareMass (vectorAmplitude f) x β€ 1 := by | |
| intro x | |
| rw [rowSquareMass_vectorAmplitude] | |
| exact hmass x | |
| rw [K.vectorEnergy_singleLabelVector] at hdet | |
| by_cases hg : g = 0 | |
| Β· subst g | |
| simp only [zero_pow (by decide : 2 β 0), zero_div, sub_zero] | |
| let fallback : Aβ := Classical.choice inferInstance | |
| have hpad := pairEnergy_le_padded K.symmetricDistribution symmetricLeft | |
| symmetricRight K.symmetricAccept labels (vectorAmplitude f) hnonneg fallback | |
| have hone := pairEnergy_le_one_of_unit_rows K.symmetricDistribution | |
| symmetricLeft symmetricRight K.symmetricAccept | |
| (paddedLabel labels fallback) (paddedAmplitude (vectorAmplitude f)) | |
| (paddedAmplitude_row (vectorAmplitude f) hrow) | |
| exact hdet.trans (hpad.trans hone) | |
| Β· have hgpos : 0 < g := lt_of_le_of_ne hg0 (Ne.symm hg) | |
| have hscore (a : Qβ β Aβ) : | |
| partialLabelScore K.symmetricDistribution symmetricLeft symmetricRight | |
| K.symmetricAccept a β€ 1 - g := by | |
| unfold partialLabelScore | |
| rw [K.symmetric_probability_eq_assignmentEnergy] | |
| exact (K.assignmentEnergy_le_collisionValue a).trans | |
| (K.collisionValue_le_value.trans hvalue) | |
| exact hdet.trans (pairEnergy_le_of_labeling_gap K.symmetricDistribution | |
| symmetricLeft symmetricRight K.symmetricAccept labels (vectorAmplitude f) | |
| hnonneg hrow hgpos hscore) | |
| end | |
| end DFVSGames.Repetition.ProjectionKernel | |
| namespace DFVSGames.Repetition | |
| open scoped BigOperators | |
| noncomputable section | |
| variable {X A Y B U D Z C I : Type*} | |
| [Fintype X] [Fintype A] [Fintype U] [Fintype D] [Fintype I] | |
| def kernelApply (K : Y β B β X β A β β) (f : X β A β β) (y : Y) (b : B) : β := | |
| β x, β a, K y b x a * f x a | |
| def tensorKernel (K : Y β B β X β A β β) (L : Z β C β U β D β β) | |
| (yz : Y Γ Z) (bc : B Γ C) (xu : X Γ U) (ad : A Γ D) : β := | |
| K yz.1 bc.1 xu.1 ad.1 * L yz.2 bc.2 xu.2 ad.2 | |
| theorem kernelApply_tensor | |
| (K : Y β B β X β A β β) (L : Z β C β U β D β β) | |
| (f : (X Γ U) β (A Γ D) β β) (y : Y) (z : Z) (b : B) (c : C) : | |
| kernelApply (tensorKernel K L) f (y,z) (b,c) = | |
| kernelApply K (fun x a => kernelApply L (fun u d => f (x,u) (a,d)) z c) y b := by | |
| classical | |
| simp only [kernelApply, tensorKernel, Fintype.sum_prod_type] | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| rw [Finset.sum_comm] | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| simp only [Finset.mul_sum, mul_assoc] | |
| theorem kernelApply_nonnegative | |
| (K : Y β B β X β A β β) (f : X β A β β) | |
| (hK : β y b x a, 0 β€ K y b x a) (hf : β x a, 0 β€ f x a) | |
| (y : Y) (b : B) : 0 β€ kernelApply K f y b := by | |
| apply Finset.sum_nonneg | |
| intro x _ | |
| apply Finset.sum_nonneg | |
| intro a _ | |
| exact mul_nonneg (hK y b x a) (hf x a) | |
| theorem kernelApply_sum | |
| (K : Y β B β X β A β β) (f : I β X β A β β) (y : Y) (b : B) : | |
| kernelApply K (fun x a => β i, f i x a) y b = | |
| β i, kernelApply K (f i) y b := by | |
| classical | |
| simp only [kernelApply, Finset.mul_sum] | |
| calc | |
| (β x, β a, β i, K y b x a * f i x a) = | |
| β x, β i, β a, K y b x a * f i x a := by | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| rw [Finset.sum_comm] | |
| _ = _ := by rw [Finset.sum_comm] | |
| theorem kernelApply_smul | |
| (K : Y β B β X β A β β) (f : X β A β β) (r : β) (y : Y) (b : B) : | |
| kernelApply K (fun x a => r * f x a) y b = r * kernelApply K f y b := by | |
| simp only [kernelApply, Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| exact mul_left_comm _ _ _ | |
| omit [Fintype X] in | |
| theorem kernelApply_slice_mass | |
| (L : Z β C β U β D β β) (f : (X Γ U) β (A Γ D) β β) | |
| (x : X) (z : Z) (c : C) : | |
| (β a, kernelApply L (fun u d => f (x,u) (a,d)) z c) = | |
| kernelApply L (fun u d => β a, f (x,u) (a,d)) z c := by | |
| symm | |
| exact kernelApply_sum L (fun a u d => f (x,u) (a,d)) z c | |
| end | |
| end DFVSGames.Repetition | |
| namespace DFVSGames.Repetition | |
| open DFVSGames.Foundations.Games | |
| open scoped BigOperators | |
| noncomputable section | |
| namespace ProjectionKernel | |
| variable {Qβ Qβ Aβ Aβ Rβ Rβ Bβ Bβ I : Type*} | |
| [Fintype Qβ] [Fintype Qβ] [Fintype Aβ] [Fintype Aβ] | |
| [Fintype Rβ] [Fintype Rβ] [Fintype Bβ] [Fintype Bβ] [Fintype I] | |
| def coefficients (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (y : Qβ) (b : Aβ) (x : Qβ) (a : Aβ) : β := | |
| (K.inner y).weight x * if K.accepts x y a b then 1 else 0 | |
| theorem apply_eq_kernelApply (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (f : Qβ β Aβ β β) (y : Qβ) (b : Aβ) : | |
| K.apply f y b = kernelApply K.coefficients f y b := by | |
| classical | |
| unfold apply kernelApply coefficients | |
| apply Finset.sum_congr rfl | |
| intro x _ | |
| rw [Finset.mul_sum] | |
| apply Finset.sum_congr rfl | |
| intro a _ | |
| by_cases h : K.accepts x y a b = true <;> simp [h] | |
| theorem apply_nonnegative (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (f : Qβ β Aβ β β) (hf : β x a, 0 β€ f x a) (y : Qβ) (b : Aβ) : | |
| 0 β€ K.apply f y b := by | |
| apply Finset.sum_nonneg | |
| intro x _ | |
| apply mul_nonneg ((K.inner y).nonnegative x) | |
| apply Finset.sum_nonneg | |
| intro a _ | |
| split | |
| Β· exact hf x a | |
| Β· exact le_rfl | |
| theorem apply_sum (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (f : I β Qβ β Aβ β β) (y : Qβ) (b : Aβ) : | |
| K.apply (fun x a => β i, f i x a) y b = β i, K.apply (f i) y b := by | |
| simp_rw [apply_eq_kernelApply] | |
| exact kernelApply_sum _ _ _ _ | |
| theorem apply_smul (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (f : Qβ β Aβ β β) (r : β) (y : Qβ) (b : Aβ) : | |
| K.apply (fun x a => r * f x a) y b = r * K.apply f y b := by | |
| simp_rw [apply_eq_kernelApply] | |
| exact kernelApply_smul _ _ _ _ _ | |
| def product (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (H : ProjectionKernel Rβ Rβ Bβ Bβ) : | |
| ProjectionKernel (Qβ Γ Rβ) (Qβ Γ Rβ) (Aβ Γ Bβ) (Aβ Γ Bβ) where | |
| outer := K.outer.product H.outer | |
| inner q := (K.inner q.1).product (H.inner q.2) | |
| accepts x y a b := K.accepts x.1 y.1 a.1 b.1 && H.accepts x.2 y.2 a.2 b.2 | |
| projection x y a b b' hb hb' := by | |
| have hβ := Bool.and_eq_true_iff.mp hb | |
| have hβ := Bool.and_eq_true_iff.mp hb' | |
| exact Prod.ext (K.projection _ _ _ _ _ hβ.1 hβ.1) | |
| (H.projection _ _ _ _ _ hβ.2 hβ.2) | |
| theorem coefficients_product (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (H : ProjectionKernel Rβ Rβ Bβ Bβ) : | |
| (K.product H).coefficients = tensorKernel K.coefficients H.coefficients := by | |
| funext yz bc xu ad | |
| unfold coefficients product tensorKernel FiniteDistribution.product | |
| by_cases hk : K.accepts xu.1 yz.1 ad.1 bc.1 = true <;> | |
| by_cases hh : H.accepts xu.2 yz.2 ad.2 bc.2 = true <;> simp [hk, hh] | |
| theorem apply_product (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (H : ProjectionKernel Rβ Rβ Bβ Bβ) | |
| (f : (Qβ Γ Rβ) β (Aβ Γ Bβ) β β) | |
| (y : Qβ) (z : Rβ) (b : Aβ) (c : Bβ) : | |
| (K.product H).apply f (y,z) (b,c) = | |
| K.apply (fun x a => H.apply (fun u d => f (x,u) (a,d)) z c) y b := by | |
| simp_rw [apply_eq_kernelApply] | |
| rw [coefficients_product] | |
| exact kernelApply_tensor _ _ _ _ _ _ _ | |
| theorem toGame_product (K : ProjectionKernel Qβ Qβ Aβ Aβ) | |
| (H : ProjectionKernel Rβ Rβ Bβ Bβ) : | |
| (K.product H).toGame = DFVSGames.Repetition.product K.toGame H.toGame := by | |
| have hquestions : (K.product H).toGame.questions = | |
| (DFVSGames.Repetition.product K.toGame H.toGame).questions := by | |
| apply FiniteDistribution.eq_of_weight_eq | |
| intro q | |
| change (K.outer.weight q.2.1 * H.outer.weight q.2.2) * | |
| ((K.inner q.2.1).weight q.1.1 * (H.inner q.2.2).weight q.1.2) = | |
| (K.outer.weight q.2.1 * (K.inner q.2.1).weight q.1.1) * | |
| (H.outer.weight q.2.2 * (H.inner q.2.2).weight q.1.2) | |
| ring | |
| exact congrArg | |
| (fun questions : FiniteDistribution ((Qβ Γ Rβ) Γ (Qβ Γ Rβ)) => | |
| ({ questions := questions | |
| accepts := fun x y a b => | |
| K.accepts x.1 y.1 a.1 b.1 && H.accepts x.2 y.2 a.2 b.2 } : | |
| Game (Qβ Γ Rβ) (Qβ Γ Rβ) (Aβ Γ Bβ) (Aβ Γ Bβ))) hquestions | |
| end ProjectionKernel | |
| end | |
| end DFVSGames.Repetition | |
| end OAI | |