module public import ConditionalGoldbach.Proofs.CharacterTraceBounds /-! Exact odd-character Parseval for complex coefficients supported strictly below N/2. -/ public section set_option autoImplicit false noncomputable section open MeasureTheory Filter Set Complex open scoped Topology ComplexConjugate BigOperators namespace ConditionalGoldbach /-- Expand the product of two finite character sums before averaging over characters. -/ lemma character_sum_mul_conj (N : ℕ) (χ : Character N) (S : Finset ℕ) (c d : ℕ → ℂ) : (∑ n ∈ S, c n * χ n) * conj (∑ m ∈ S, d m * χ m) = ∑ n ∈ S, ∑ m ∈ S, c n * conj (d m) * (χ n * conj (χ m)) := by rw [map_sum, Finset.sum_mul] simp only [map_mul, Finset.mul_sum] apply Finset.sum_congr rfl intro n _ apply Finset.sum_congr rfl intro m _ ring lemma complex_character_sum_norm_sq (N : ℕ) (χ : Character N) (S : Finset ℕ) (c : ℕ → ℂ) : ((‖∑ n ∈ S, c n * χ n‖ ^ 2 : ℝ) : ℂ) = ∑ n ∈ S, ∑ m ∈ S, c n * conj (c m) * (χ n * conj (χ m)) := by rw [Complex.sq_norm, Complex.normSq_eq_conj_mul_self, mul_comm] exact character_sum_mul_conj N χ S c c /-- Odd-character orthogonality with independent complex coefficients on the two sides. -/ lemma odd_character_pairing_complex (N : ℕ) [NeZero N] (hN : Even N) (hN4 : 4 ≤ N) (S : Finset ℕ) (c d : ℕ → ℂ) : (2 / (N.totient : ℂ)) * ∑ χ ∈ oddCharacters N, (∑ n ∈ S, c n * χ n) * conj (∑ m ∈ S, d m * χ m) = ∑ n ∈ S, ∑ m ∈ S, c n * conj (d m) * (if Nat.Coprime (n * m) N then (if (n : ZMod N) = m then (1 : ℂ) else 0) - (if (n : ZMod N) = -(m : ZMod N) then 1 else 0) else 0) := by simp_rw [character_sum_mul_conj] rw [Finset.sum_comm] simp_rw [Finset.sum_comm (s := oddCharacters N) (t := S)] simp_rw [Finset.mul_sum] apply Finset.sum_congr rfl intro n _ apply Finset.sum_congr rfl intro m _ calc _ = c n * conj (d m) * ((2 : ℂ) / N.totient * ∑ χ ∈ oddCharacters N, χ n * conj (χ m)) := by simp only [Finset.mul_sum] apply Finset.sum_congr rfl intro χ _ ring _ = _ := by rw [lemma_3_1_odd_orthogonality N hN hN4] lemma odd_character_quadratic_complex (N : ℕ) [NeZero N] (hN : Even N) (hN4 : 4 ≤ N) (S : Finset ℕ) (c : ℕ → ℂ) : (((2 / (N.totient : ℝ)) * ∑ χ ∈ oddCharacters N, ‖∑ n ∈ S, c n * χ n‖ ^ 2 : ℝ) : ℂ) = ∑ n ∈ S, ∑ m ∈ S, c n * conj (c m) * (if Nat.Coprime (n * m) N then (if (n : ZMod N) = m then (1 : ℂ) else 0) - (if (n : ZMod N) = -(m : ZMod N) then 1 else 0) else 0) := by simpa only [Complex.ofReal_mul, Complex.ofReal_div, Complex.ofReal_ofNat, Complex.ofReal_natCast, Complex.ofReal_sum, Complex.mul_conj, Complex.normSq_eq_norm_sq] using odd_character_pairing_complex N hN hN4 S c c /-- Below half the modulus the positive congruence is equality and the negative one is empty. -/ lemma odd_character_short_pairing (N : ℕ) [NeZero N] (hN : Even N) (hN4 : 4 ≤ N) (S : Finset ℕ) (c d : ℕ → ℂ) (hc : ∀ n ∈ S, c n ≠ 0 → 0 < n ∧ 2 * n < N) (hd : ∀ n ∈ S, d n ≠ 0 → 0 < n ∧ 2 * n < N) : (2 / (N.totient : ℂ)) * ∑ χ ∈ oddCharacters N, (∑ n ∈ S, c n * χ n) * conj (∑ m ∈ S, d m * χ m) = ∑ n ∈ S, if Nat.Coprime n N then c n * conj (d n) else 0 := by classical rw [odd_character_pairing_complex N hN hN4] apply Finset.sum_congr rfl intro n hn have hterm (m : ℕ) (hm : m ∈ S) : c n * conj (d m) * (if Nat.Coprime (n * m) N then (if (n : ZMod N) = m then (1 : ℂ) else 0) - (if (n : ZMod N) = -(m : ZMod N) then 1 else 0) else 0) = if m = n then (if Nat.Coprime n N then c n * conj (d n) else 0) else 0 := by by_cases hcn : c n = 0 · simp [hcn] by_cases hdm : d m = 0 · by_cases hmn : m = n · subst m simp [hdm] · simp [hdm, hmn] obtain ⟨hn0, hn2⟩ := hc n hn hcn obtain ⟨hm0, hm2⟩ := hd m hm hdm obtain ⟨hpos, hneg⟩ := residue_diagonals (by omega : 0 < N) hn0 (by omega) hm0 (by omega) have hsum : n + m ≠ N := by omega simp only [hpos, hneg, hsum, ite_false, sub_zero] by_cases hmn : m = n · subst m by_cases hcop : Nat.Coprime n N <;> simp [Nat.coprime_mul_iff_left, hcop] · simp [hmn, Ne.symm hmn] rw [Finset.sum_congr rfl hterm, Finset.sum_ite_eq' S n] simp [hn] lemma odd_character_short_parseval (N : ℕ) [NeZero N] (hN : Even N) (hN4 : 4 ≤ N) (S : Finset ℕ) (c : ℕ → ℂ) (hsupport : ∀ n ∈ S, c n ≠ 0 → 0 < n ∧ 2 * n < N) : (2 / (N.totient : ℝ)) * ∑ χ ∈ oddCharacters N, ‖∑ n ∈ S, c n * χ n‖ ^ 2 = ∑ n ∈ S, if Nat.Coprime n N then ‖c n‖ ^ 2 else 0 := by apply Complex.ofReal_injective simpa only [Complex.ofReal_mul, Complex.ofReal_div, Complex.ofReal_ofNat, Complex.ofReal_natCast, Complex.ofReal_sum, apply_ite (fun x : ℝ => (x : ℂ)), Complex.ofReal_zero, Complex.mul_conj, Complex.normSq_eq_norm_sq] using odd_character_short_pairing N hN hN4 S c c hsupport hsupport lemma smoothedPerronWeight_eq_zero_of_le {X : ℝ} (hX : 1 < X) (n : ℕ) (hn : X ≤ (n : ℝ)) : smoothedPerronWeight X n = 0 := by have hs : Real.sqrt X < X := by apply (Real.sqrt_lt (by linarith : 0 ≤ X) (by linarith : 0 ≤ X)).mpr nlinarith have hn' : ¬(n : ℝ) ≤ Real.sqrt X := by linarith unfold smoothedPerronWeight rw [ite_eq_right hn'] split_ifs with hnX · have he : (n : ℝ) = X := le_antisymm hnX hn rw [he, div_self (by linarith : X ≠ 0), Real.log_one, zero_div] · rfl lemma smoothedPerronWeight_nonneg_le_one {X : ℝ} (hX : 1 < X) (n : ℕ) : 0 ≤ smoothedPerronWeight X n ∧ smoothedPerronWeight X n ≤ 1 := by unfold smoothedPerronWeight split_ifs with hn hnX · exact ⟨zero_le_one, le_rfl⟩ · have hs : 1 < Real.sqrt X := (Real.lt_sqrt (by norm_num)).mpr (by simpa using hX) have hn0 : (0 : ℝ) < n := by linarith have hlog : 0 < Real.log (Real.sqrt X) := Real.log_pos hs constructor · apply div_nonneg _ hlog.le exact Real.log_nonneg ((one_le_div hn0).mpr hnX) · apply (div_le_one hlog).mpr apply Real.log_le_log (div_pos (by linarith) hn0) apply (div_le_iff₀ hn0).mpr have hsq := Real.sq_sqrt (by linarith : 0 ≤ X) nlinarith [Real.sqrt_nonneg X] · exact ⟨le_rfl, zero_le_one⟩ /-- The complex coefficient of the smoothed Perron polynomial before twisting by a character. -/ def smoothedPolynomialCoeff (X : ℝ) (u : ℂ) (n : ℕ) : ℂ := (mangoldt n : ℂ) * (n : ℂ) ^ (-u) * smoothedPerronWeight X n lemma smoothedDirichletPolynomial_eq_sum {N : ℕ} (χ : Character N) (X : ℝ) (u : ℂ) : smoothedDirichletPolynomial χ X u = ∑ n ∈ Finset.range (⌊X⌋₊ + 1), smoothedPolynomialCoeff X u n * χ n := by apply Finset.sum_congr rfl intro n _ unfold smoothedPolynomialCoeff ring lemma smoothedPolynomialCoeff_support (N : ℕ) (hN4 : 4 ≤ N) (u : ℂ) (n : ℕ) (hc : smoothedPolynomialCoeff ((N : ℝ) / 2) u n ≠ 0) : 0 < n ∧ 2 * n < N := by have h0 : smoothedPolynomialCoeff ((N : ℝ) / 2) u 0 = 0 := by simp [smoothedPolynomialCoeff, mangoldt] refine ⟨Nat.pos_of_ne_zero (by intro he; subst n; exact hc h0), ?_⟩ by_contra hnN have hreal : (N : ℝ) / 2 ≤ n := by have hh : N ≤ 2 * n := le_of_not_gt hnN exact (div_le_iff₀ (by norm_num)).mpr (by exact_mod_cast (show N ≤ n * 2 by omega)) have hNreal : (4 : ℝ) ≤ N := by exact_mod_cast hN4 have hw := smoothedPerronWeight_eq_zero_of_le (by linarith : 1 < (N : ℝ) / 2) n hreal exact hc (by simp only [smoothedPolynomialCoeff, hw, Complex.ofReal_zero, mul_zero]) /-- At two arbitrary spectral parameters the smoothed character average is exactly diagonal. -/ theorem smoothed_polynomial_odd_pairing (N : ℕ) [NeZero N] (hN : Even N) (hN4 : 4 ≤ N) (u v : ℂ) : (2 / (N.totient : ℂ)) * ∑ χ ∈ oddCharacters N, smoothedDirichletPolynomial χ ((N : ℝ) / 2) u * conj (smoothedDirichletPolynomial χ ((N : ℝ) / 2) v) = ∑ n ∈ Finset.range (⌊(N : ℝ) / 2⌋₊ + 1), if Nat.Coprime n N then smoothedPolynomialCoeff ((N : ℝ) / 2) u n * conj (smoothedPolynomialCoeff ((N : ℝ) / 2) v n) else 0 := by simp_rw [smoothedDirichletPolynomial_eq_sum] exact odd_character_short_pairing N hN hN4 _ _ _ (fun n _ => smoothedPolynomialCoeff_support N hN4 u n) (fun n _ => smoothedPolynomialCoeff_support N hN4 v n) lemma smoothed_polynomial_odd_parseval (N : ℕ) [NeZero N] (hN : Even N) (hN4 : 4 ≤ N) (u : ℂ) : (2 / (N.totient : ℝ)) * ∑ χ ∈ oddCharacters N, ‖smoothedDirichletPolynomial χ ((N : ℝ) / 2) u‖ ^ 2 = ∑ n ∈ Finset.range (⌊(N : ℝ) / 2⌋₊ + 1), if Nat.Coprime n N then ‖(mangoldt n : ℂ) * (n : ℂ) ^ (-u) * smoothedPerronWeight ((N : ℝ) / 2) n‖ ^ 2 else 0 := by simp_rw [smoothedDirichletPolynomial_eq_sum] exact odd_character_short_parseval N hN hN4 _ _ (fun n _ => smoothedPolynomialCoeff_support N hN4 u n) end ConditionalGoldbach