/-Copyright (c) 2026 Carles MarΓn. All rights reserved.Released under Apache 2.0 license as described in the file LICENSE.Authors: Carles MarΓn, Claude (AI assistant)-/-- encaje: identidades de producto de senos y valores espinoriales en la recta de Ο (tipos B, D)module public import Mathlib.RingTheory.RootsOfUnity.Lemmaspublic import Mathlib.RingTheory.RootsOfUnity.Complexpublic import Mathlib.Analysis.SpecialFunctions.Trigonometric.Basicpublic import Mathlib.Analysis.Complex.Trigonometricpublic import Mathlib.Analysis.Real.Sqrtpublic import Mathlib.Algebra.BigOperators.Intervals /-!# Sine products and the spin values on the Ο-line of types B and D Classical trigonometric identities (the product of sines `β_{k=1}^{n-1} 2 sin(kΟ/n) = n`, theDirichlet kernel, the index shift of `sin`) and their consequences for the spin values on theΟ-line: the spin representation of `B_m` gives `β_{j=1}^{m} 2 sin(jΟ/(2m+1)) = β(2m+1)` (and itscosine form) and the half-spin representations of `D_m` give `β_{j=1}^{m-1} 2 sin(jΟ/(2m)) = βm`.The values `β(2m+1)` and `βm` are known in the literature as level-2 quantum dimensions(Gannon; GannonβSchopieray); the formalization is ours. The product of sines is derived from`IsPrimitiveRoot.prod_pow_sub_one_eq_order` via `|e^{2Οik/n} - 1| = 2 sin(Οk/n)`. ## Main results * `SpinRhoLine.prod_two_sin`: `β_{k=1}^{n-1} 2 sin(kΟ/n) = n` for `n β₯ 1`* `SpinRhoLine.spin_B`, `SpinRhoLine.spin_B_cos`: the type-B spin value `β(2m+1)`* `SpinRhoLine.halfspin_D`: the type-D half-spin value `βm`* `SpinRhoLine.dirichlet`: `1 + β_{j=1}^{m} 2 cos(2Οj/q) = sin((2m+1)Ο/q) / sin(Ο/q)`* `SpinRhoLine.index_shift`, `SpinRhoLine.index_shift_div`: `sin((hq+r)Ο/q) = (-1)^h sin(rΟ/q)`* `SpinRhoLine.sqrt_two_mul_add_one_eq_nat_iff`, `SpinRhoLine.sqrt_eq_nat_iff`: `β(2m+1)` (resp. `βm`) is a natural number iff `2m+1` (resp. `m`) is a perfect square-/ @[expose] public section open Real Finset namespace SpinRhoLine /-- `|e^{2Οik/n} - 1| = |2 sin(kΟ/n)|`. -/lemma norm_exp_pow_sub_one (n k : β) : βComplex.exp (2 * Ο * Complex.I / n) ^ k - 1β = β2 * Real.sin (k * Ο / n)β := by rw [β Complex.exp_nat_mul] have : (k : β) * (2 * Ο * Complex.I / n) = Complex.I * ((2 * k * Ο / n : β) : β) := by push_cast; ring rw [this, Complex.norm_exp_I_mul_ofReal_sub_one, show 2 * k * Ο / n / 2 = k * Ο / n by ring] lemma sin_nat_pos {k n : β} (hk : 0 < k) (hkn : k < n) : 0 < Real.sin (k * Ο / n) := by have hk' : (0 : β) < k := by exact_mod_cast hk have hkn' : (k : β) < n := by exact_mod_cast hkn have hn' : (0 : β) < n := by linarith apply sin_pos_of_pos_of_lt_pi (by positivity) rw [div_lt_iffβ hn'] nlinarith [pi_pos] /-- Reflection `sin(aΟ/D) = sin(bΟ/D)` when `a + b = D`. -/lemma sin_reflect {a b D : β} (h : a + b = D) (hD : D β 0) : Real.sin (a * Ο / D) = Real.sin (b * Ο / D) := by rw [β sin_pi_sub] congr 1 have hD' : (D : β) β 0 := by exact_mod_cast hD have hab : (a : β) = D - b := by rw [β h]; push_cast; ring rw [hab] field_simp ring /-- Product of sines, `range` form: `β_{k<N} 2 sin((k+1)Ο/(N+1)) = N+1`. -/theorem prod_two_sin_range (N : β) : β k β range N, 2 * Real.sin (((k + 1 : β) : β) * Ο / ((N + 1 : β) : β)) = ((N + 1 : β) : β) := by have hΞΌ := Complex.isPrimitiveRoot_exp (N + 1) (Nat.succ_ne_zero N) have h := congrArg norm (hΞΌ.prod_pow_sub_one_eq_order) rw [norm_mul, norm_pow, norm_neg, norm_one, one_pow, one_mul, norm_prod] at h have h2 : β((N : β) + 1)β = ((N + 1 : β) : β) := by rw [show ((N : β) + 1) = ((N + 1 : β) : β) by push_cast; ring, Complex.norm_natCast] rw [h2] at h refine Eq.trans ?_ h refine prod_congr rfl (fun k hk => ?_) rw [mem_range] at hk rw [norm_exp_pow_sub_one, Real.norm_eq_abs, abs_of_pos] exact mul_pos two_pos (sin_nat_pos (n := N + 1) (Nat.succ_pos k) (by omega)) /-- **Product of sines.** For `n β₯ 1`, `β_{k=1}^{n-1} 2 sin(kΟ/n) = n`. -/theorem prod_two_sin (n : β) (hn : 1 β€ n) : β k β Ico 1 n, 2 * Real.sin (k * Ο / n) = n := by obtain β¨N, rflβ© : β N, n = N + 1 := β¨n - 1, by omegaβ© rw [prod_Ico_eq_prod_range, Nat.add_sub_cancel] refine Eq.trans ?_ (prod_two_sin_range N) refine prod_congr rfl (fun k _ => ?_) rw [add_comm 1 k] /-- Type B, squared form, in `range` notation. -/lemma spin_B_range_sq (m : β) : (β k β range m, 2 * Real.sin (((k + 1 : β) : β) * Ο / ((2 * m + 1 : β) : β))) ^ 2 = ((2 * m + 1 : β) : β) := by set f : β β β := fun j => 2 * Real.sin ((j : β) * Ο / ((2 * m + 1 : β) : β)) with hf have h := prod_two_sin_range (2 * m) have hsplit : β k β range (2 * m), f (k + 1) = (β k β range m, f (k + 1)) * β k β range m, f (m + k + 1) := by rw [two_mul, prod_range_add] have hrefl : β k β range m, f (m + k + 1) = β k β range m, f (k + 1) := by refine Eq.trans ?_ (prod_range_reflect (fun k => f (k + 1)) m) refine prod_congr rfl (fun k hk => ?_) rw [mem_range] at hk simp only [hf] rw [sin_reflect (a := m + k + 1) (b := m - 1 - k + 1) (by omega) (by omega)] have : β k β range (2 * m), f (k + 1) = ((2 * m + 1 : β) : β) := h rw [hsplit, hrefl] at this rw [sq] exact this lemma spin_B_range (m : β) : β k β range m, 2 * Real.sin (((k + 1 : β) : β) * Ο / ((2 * m + 1 : β) : β)) = Real.sqrt ((2 * m + 1 : β) : β) := by have hnn : 0 β€ β k β range m, 2 * Real.sin (((k + 1 : β) : β) * Ο / ((2 * m + 1 : β) : β)) := by refine prod_nonneg (fun k hk => ?_) rw [mem_range] at hk exact (mul_pos two_pos (sin_nat_pos (n := 2 * m + 1) (Nat.succ_pos k) (by omega))).le conv_rhs => rw [β spin_B_range_sq m] rw [Real.sqrt_sq hnn] /-- **Type B spin value.** `β_{j=1}^{m} 2 sin(jΟ/(2m+1)) = β(2m+1)` (also true for `m = 0`). -/theorem spin_B (m : β) : β j β Ico 1 (m + 1), 2 * Real.sin (j * Ο / (2 * m + 1)) = Real.sqrt (2 * m + 1) := by have h := spin_B_range m push_cast at h rw [prod_Ico_eq_prod_range, Nat.add_sub_cancel, β h] refine prod_congr rfl (fun k _ => ?_) push_cast ring_nf /-- **Type B spin value, cosine form.** `β_{i=1}^{m} 2 cos((2i-1)Ο/(4m+2)) = β(2m+1)`. -/theorem spin_B_cos (m : β) : β i β Ico 1 (m + 1), 2 * Real.cos ((2 * i - 1) * Ο / (4 * m + 2)) = Real.sqrt (2 * m + 1) := by have h := spin_B_range m rw [β prod_range_reflect] at h push_cast at h rw [prod_Ico_eq_prod_range, Nat.add_sub_cancel, β h] refine prod_congr rfl (fun k hk => ?_) rw [mem_range] at hk have hc : ((m - 1 - k : β) : β) = m - 1 - k := by rw [Nat.cast_sub (by omega), Nat.cast_sub (by omega)]; push_cast; ring rw [hc, β sin_pi_div_two_sub] congr 2 have hm : (2 * (m : β) + 1) β 0 := by positivity have hm' : (4 * (m : β) + 2) β 0 := by positivity push_cast field_simp ring /-- **Type D half-spin value.** For `m β₯ 1`, `β_{j=1}^{m-1} 2 sin(jΟ/(2m)) = βm`. -/theorem halfspin_D (m : β) (hm : 1 β€ m) : β j β Ico 1 m, 2 * Real.sin (j * Ο / (2 * m)) = Real.sqrt m := by obtain β¨M, rflβ© : β M, m = M + 1 := β¨m - 1, by omegaβ© set f : β β β := fun j => 2 * Real.sin ((j : β) * Ο / ((2 * M + 1 + 1 : β) : β)) with hf have h : β k β range (2 * M + 1), f (k + 1) = ((2 * M + 1 + 1 : β) : β) := prod_two_sin_range (2 * M + 1) have hsplit : β k β range (2 * M + 1), f (k + 1) = (β k β range M, f (k + 1)) * ((β k β range M, f (M + k + 2)) * f (M + 1)) := by rw [show 2 * M + 1 = M + (M + 1) by ring, prod_range_add, prod_range_succ'] rfl have hmid : f (M + 1) = 2 := by simp only [hf] have : ((M + 1 : β) : β) * Ο / ((2 * M + 1 + 1 : β) : β) = Ο / 2 := by push_cast; field_simp; ring rw [this, sin_pi_div_two, mul_one] have hrefl : β k β range M, f (M + k + 2) = β k β range M, f (k + 1) := by refine Eq.trans ?_ (prod_range_reflect (fun k => f (k + 1)) M) refine prod_congr rfl (fun k hk => ?_) rw [mem_range] at hk simp only [hf] rw [sin_reflect (a := M + k + 2) (b := M - 1 - k + 1) (by omega) (by omega)] rw [hsplit, hrefl, hmid] at h have hsq : (β k β range M, f (k + 1)) ^ 2 = ((M + 1 : β) : β) := by push_cast at h β’; nlinarith [h] have hnn : 0 β€ β k β range M, f (k + 1) := by refine prod_nonneg (fun k hk => ?_) rw [mem_range] at hk exact (mul_pos two_pos (sin_nat_pos (n := 2 * M + 1 + 1) (Nat.succ_pos k) (by omega))).le conv_rhs => rw [β hsq] rw [Real.sqrt_sq hnn, prod_Ico_eq_prod_range, Nat.add_sub_cancel] refine prod_congr rfl (fun k _ => ?_) simp only [hf] push_cast ring_nf /-- Dirichlet kernel, multiplied form, for any `x`. -/lemma sin_mul_dirichlet (x : β) (m : β) : Real.sin x * (1 + β j β range m, 2 * Real.cos (2 * ((j : β) + 1) * x)) = Real.sin ((2 * m + 1) * x) := by induction m with | zero => simp | succ m ih => rw [sum_range_succ, β add_assoc, mul_add, ih] push_cast rw [show (2 * (m : β) + 1) * x = (2 * m + 2) * x - x by ring, show (2 * ((m : β) + 1) + 1) * x = (2 * m + 2) * x + x by ring, show 2 * ((m : β) + 1) * x = (2 * m + 2) * x by ring, sin_add, sin_sub] ring /-- **Dirichlet kernel.** For `q β₯ 2`, `1 + β_{j=1}^{m} 2 cos(2Οj/q) = sin((2m+1)Ο/q)/sin(Ο/q)`. -/theorem dirichlet (q m : β) (hq : 2 β€ q) : 1 + β j β Icc 1 m, 2 * Real.cos (2 * Ο * j / q) = Real.sin ((2 * m + 1) * Ο / q) / Real.sin (Ο / q) := by have hs : 0 < Real.sin (Ο / q) := by have := sin_nat_pos (k := 1) (n := q) one_pos (by omega) simpa using this have hIcc : Icc 1 m = Ico 1 (m + 1) := by ext; simp only [mem_Icc, mem_Ico]; omega rw [eq_div_iff hs.ne', hIcc, sum_Ico_eq_sum_range, Nat.add_sub_cancel, mul_comm, show (2 * (m : β) + 1) * Ο / q = (2 * m + 1) * (Ο / q) by ring, β sin_mul_dirichlet] congr 2 refine sum_congr rfl (fun k _ => ?_) push_cast ring_nf /-- **Index shift.** For `q β₯ 1`, `sin((hq+r)Ο/q) = (-1)^h sin(rΟ/q)`. -/theorem index_shift (q h r : β) (hq : 1 β€ q) : Real.sin ((h * q + r) * Ο / q) = (-1) ^ h * Real.sin (r * Ο / q) := by have hq' : (q : β) β 0 := by exact_mod_cast (show q β 0 by omega) rw [show ((h : β) * q + r) * Ο / q = r * Ο / q + h * Ο by field_simp; ring] exact sin_add_nat_mul_pi _ _ /-- **Index shift, divided form.** -/theorem index_shift_div (q h r : β) (hq : 1 β€ q) : Real.sin ((h * q + r) * Ο / q) / Real.sin (Ο / q) = (-1) ^ h * (Real.sin (r * Ο / q) / Real.sin (Ο / q)) := by rw [index_shift q h r hq, mul_div_assoc] /-- `βn` is a natural number iff `n` is a perfect square. -/theorem sqrt_eq_nat_iff (n : β) : (β k : β, Real.sqrt n = k) β IsSquare n := by constructor Β· rintro β¨k, hkβ© have : (n : β) = k * k := by rw [β hk]; exact (Real.mul_self_sqrt (Nat.cast_nonneg n)).symm exact β¨k, by exact_mod_cast thisβ© Β· rintro β¨r, hrβ© exact β¨r, by rw [hr]; push_cast; exact Real.sqrt_mul_self (Nat.cast_nonneg r)β© /-- **Corollary (type B).** `β(2m+1)` is a natural number iff `2m+1` is a perfect square. -/theorem sqrt_two_mul_add_one_eq_nat_iff (m : β) : (β k : β, Real.sqrt (2 * m + 1) = k) β IsSquare (2 * m + 1) := by have := sqrt_eq_nat_iff (2 * m + 1) push_cast at this exact this /-- **Corollary (type B), product form.** The spin value is an integer iff `2m+1` is a square. -/theorem spin_B_eq_nat_iff (m : β) : (β k : β, β j β Ico 1 (m + 1), 2 * Real.sin (j * Ο / (2 * m + 1)) = k) β IsSquare (2 * m + 1) := by rw [spin_B]; exact sqrt_two_mul_add_one_eq_nat_iff m /-- **Corollary (type D), product form.** The half-spin value is an integer iff `m` is a square. -/theorem halfspin_D_eq_nat_iff (m : β) (hm : 1 β€ m) : (β k : β, β j β Ico 1 m, 2 * Real.sin (j * Ο / (2 * m)) = k) β IsSquare m := by rw [halfspin_D m hm]; exact sqrt_eq_nat_iff m end SpinRhoLine