import Mathlib.Analysis.SpecialFunctions.Sqrt import Mathlib.Algebra.Order.Chebyshev import Mathlib.Tactic open scoped BigOperators namespace Inekoalaty /-- Core inequality used in the game analysis: if `a,b ≥ 0` and `a^2+b^2=2` then `a+b ≥ √2`. -/ lemma add_ge_sqrt_two_of_sq_add_sq_eq_two {a b : ℝ} (ha : 0 ≤ a) (hb : 0 ≤ b) (h : a^2 + b^2 = 2) : Real.sqrt 2 ≤ a + b := by have hab : 0 ≤ a + b := add_nonneg ha hb have habmul : 0 ≤ a * b := mul_nonneg ha hb have h_expand : (a + b)^2 = 2 + 2 * (a * b) := by calc (a + b)^2 = a^2 + b^2 + 2 * (a * b) := by ring _ = 2 + 2 * (a * b) := by simp [h] have hsq : (2 : ℝ) ≤ (a + b)^2 := by have : (2 : ℝ) ≤ 2 + 2 * (a * b) := by linarith simpa [h_expand] using this exact (Real.sqrt_le_iff).2 ⟨hab, by simpa using hsq⟩ /-- A convenient Cauchy–Schwarz bound specialized to the inequality used in the Alice strategy. If `f i ≥ 0` on a finite set `s` and `∑ f i ^ 2 ≤ 2 * card s`, then `∑ f i ≤ card s * √2`. -/ lemma sum_le_card_mul_sqrt_two {ι : Type*} (s : Finset ι) (f : ι → ℝ) (hf : ∀ i ∈ s, 0 ≤ f i) (hsq : (∑ i ∈ s, (f i) ^ 2) ≤ 2 * (s.card : ℝ)) : (∑ i ∈ s, f i) ≤ (s.card : ℝ) * Real.sqrt 2 := by have hsum0 : 0 ≤ (∑ i ∈ s, f i) := Finset.sum_nonneg hf have hcs : (∑ i ∈ s, f i) ^ 2 ≤ (s.card : ℝ) * ∑ i ∈ s, (f i) ^ 2 := by simpa using (sq_sum_le_card_mul_sum_sq (s := s) (f := f)) have hsq' : (s.card : ℝ) * (∑ i ∈ s, (f i) ^ 2) ≤ (s.card : ℝ) * (2 * (s.card : ℝ)) := by gcongr have hbound : (∑ i ∈ s, f i) ^ 2 ≤ ((s.card : ℝ) * Real.sqrt 2) ^ 2 := by -- combine the previous inequalities and simplify have : (∑ i ∈ s, f i) ^ 2 ≤ (s.card : ℝ) * (2 * (s.card : ℝ)) := by exact le_trans hcs (le_trans (by -- use `hsq` in the right factor have : (s.card : ℝ) * (∑ i ∈ s, (f i) ^ 2) ≤ (s.card : ℝ) * (2 * (s.card : ℝ)) := by gcongr exact this) (le_rfl)) -- turn `card * (2*card)` into `(card*sqrt 2)^2` -- `ring` works after rewriting `(^2)`. -- First, rewrite RHS. have hR : (s.card : ℝ) * (2 * (s.card : ℝ)) = ((s.card : ℝ) * Real.sqrt 2) ^ 2 := by have : ((s.card : ℝ) * Real.sqrt 2) ^ 2 = (s.card : ℝ) ^ 2 * (Real.sqrt 2) ^ 2 := by ring -- but simpler: just use `ring` with `Real.sq_sqrt`. -- We'll do it directly. calc (s.card : ℝ) * (2 * (s.card : ℝ)) = 2 * (s.card : ℝ) ^ 2 := by ring _ = ((s.card : ℝ) * Real.sqrt 2) ^ 2 := by -- `(c*sqrt2)^2 = c^2*2` simp [pow_two, mul_assoc, mul_left_comm, mul_comm] -- use it simpa [hR] using this -- Convert squared inequality back using nonnegativity. have hcard0 : 0 ≤ (s.card : ℝ) * Real.sqrt 2 := by positivity have habs : |∑ i ∈ s, f i| ≤ |(s.card : ℝ) * Real.sqrt 2| := (sq_le_sq).1 (by simpa [pow_two] using hbound) -- remove abs using nonnegativity simpa [abs_of_nonneg hsum0, abs_of_nonneg hcard0] using habs /-- Archimedean lemma used to choose a sufficiently large stage in the game. If `lam < √2/2`, then eventually `k√2 > lam(2k+1)`. -/ lemma exists_nat_mul_sqrt2_gt_linear (lam : ℝ) (hlam : lam < Real.sqrt 2 / 2) : ∃ k : ℕ, (k : ℝ) * Real.sqrt 2 > lam * (2 * (k : ℝ) + 1) := by -- Set `δ = √2 - 2*lam`, a positive gap since `lam < √2/2`. let δ : ℝ := Real.sqrt 2 - 2 * lam have hδ : 0 < δ := by have : 2 * lam < Real.sqrt 2 := by nlinarith [hlam] simpa [δ, sub_pos] using this have hδ0 : δ ≠ 0 := ne_of_gt hδ -- Choose `k > lam/δ` by the Archimedean property. obtain ⟨k : ℕ, hk : lam / δ < (k : ℝ)⟩ := by simpa using (exists_nat_gt (lam / δ)) refine ⟨k, ?_⟩ -- Multiply by `δ>0` to get `lam < k*δ`. have hkδ : lam < (k : ℝ) * δ := by have hmul : lam / δ * δ < (k : ℝ) * δ := mul_lt_mul_of_pos_right hk hδ simpa [div_eq_mul_inv, mul_assoc, hδ0] using hmul -- Rearrange the desired inequality to a positivity statement. have hEq : (k : ℝ) * Real.sqrt 2 - lam * (2 * (k : ℝ) + 1) = (k : ℝ) * δ - lam := by simp [δ] ring have : 0 < (k : ℝ) * Real.sqrt 2 - lam * (2 * (k : ℝ) + 1) := by have : 0 < (k : ℝ) * δ - lam := by linarith simpa [hEq] using this linarith end Inekoalaty namespace Inekoalaty /-- If `lam > √2/2`, then `k√2 < lam(2k+1)` holds for all natural `k`. -/ lemma nat_mul_sqrt2_lt_linear_of_half_sqrt2_lt (lam : ℝ) (hlam : Real.sqrt 2 / 2 < lam) (k : ℕ) : (k : ℝ) * Real.sqrt 2 < lam * (2 * (k : ℝ) + 1) := by -- `lam*(2k+1) - k*sqrt2 = k*(2lam-sqrt2)+lam` is positive. have hδ : 0 < 2 * lam - Real.sqrt 2 := by nlinarith [hlam] have : 0 < lam * (2 * (k : ℝ) + 1) - (k : ℝ) * Real.sqrt 2 := by -- rewrite and bound by positivity calc lam * (2 * (k : ℝ) + 1) - (k : ℝ) * Real.sqrt 2 = (k : ℝ) * (2 * lam - Real.sqrt 2) + lam := by ring _ > 0 := by have hk0 : 0 ≤ (k : ℝ) := by exact_mod_cast (Nat.zero_le k) have hkδ0 : 0 ≤ (k : ℝ) * (2 * lam - Real.sqrt 2) := mul_nonneg hk0 (le_of_lt hδ) have hlam0 : 0 < lam := lt_trans (by positivity) hlam exact add_pos_of_nonneg_of_pos hkδ0 hlam0 linarith /-- If `lam > √2/2`, then for some `k` we have `lam(2k+1) - k√2 > √2`. This is the quantitative step used to ensure Alice can play a move bigger than `√2`. -/ lemma exists_nat_linear_minus_mul_sqrt2_gt_sqrt2 (lam : ℝ) (hlam : Real.sqrt 2 / 2 < lam) : ∃ k : ℕ, lam * (2 * (k : ℝ) + 1) - (k : ℝ) * Real.sqrt 2 > Real.sqrt 2 := by let δ : ℝ := 2 * lam - Real.sqrt 2 have hδ : 0 < δ := by have : Real.sqrt 2 < 2 * lam := by nlinarith [hlam] simpa [δ, sub_pos] using this have hδ0 : δ ≠ 0 := ne_of_gt hδ -- We want: k*δ + lam > √2, i.e. k*δ > √2 - lam. obtain ⟨k : ℕ, hk : (Real.sqrt 2 - lam) / δ < (k : ℝ)⟩ := by simpa using (exists_nat_gt ((Real.sqrt 2 - lam) / δ)) refine ⟨k, ?_⟩ have hkδ : Real.sqrt 2 - lam < (k : ℝ) * δ := by have hmul : (Real.sqrt 2 - lam) / δ * δ < (k : ℝ) * δ := mul_lt_mul_of_pos_right hk hδ simpa [div_eq_mul_inv, mul_assoc, hδ0] using hmul have hEq : lam * (2 * (k : ℝ) + 1) - (k : ℝ) * Real.sqrt 2 = (k : ℝ) * δ + lam := by simp [δ] ring -- Conclude. have : Real.sqrt 2 < (k : ℝ) * δ + lam := by linarith simpa [hEq] using this /-- A convenient corollary: for `t ∈ [0, √2]`, we have `t + √(2 - t^2) ≥ √2`. -/ lemma add_sqrt_two_sub_sq_ge_sqrt_two {t : ℝ} (ht0 : 0 ≤ t) (ht2 : t ^ 2 ≤ 2) : Real.sqrt 2 ≤ t + Real.sqrt (2 - t ^ 2) := by have hnonneg : 0 ≤ 2 - t ^ 2 := by linarith -- Apply the `a^2+b^2=2` lemma with `a=t` and `b=√(2-t^2)`. have hsq : t ^ 2 + (Real.sqrt (2 - t ^ 2)) ^ 2 = 2 := by have : (Real.sqrt (2 - t ^ 2)) ^ 2 = 2 - t ^ 2 := by simpa [pow_two] using (Real.sq_sqrt hnonneg) nlinarith [this] have hb0 : 0 ≤ Real.sqrt (2 - t ^ 2) := by positivity simpa [add_comm, add_left_comm, add_assoc] using (add_ge_sqrt_two_of_sq_add_sq_eq_two (a := t) (b := Real.sqrt (2 - t ^ 2)) ht0 hb0 hsq) end Inekoalaty