/- Copyright (c) 2026 Wave-7 Formalization. All rights reserved. Released under Apache 2.0 license. -/ import Mathlib.AlgebraicGeometry.EllipticCurve.Affine.Point import Mathlib.Data.ZMod.Basic import Mathlib.Tactic /-! # The Weil Pairing: Line-Product Weil Reciprocity, Miller's Algorithm, Bilinearity, Alternating Property, Galois Equivariance & Non-Degeneracy Witnesses This standalone file constructs the **Weil pairing** `e_m(P, Q)` on short Weierstrass elliptic curves `E : y² = x³ + a x + b` (`char ≠ 2`, `4 a³ + 27 b² ≠ 0`) over arbitrary fields `K`, and proves all fundamental structural properties completely from first principles with ZERO assumed Weil-reciprocity axioms: 1. **Line-Product Rational Functions & Exact Weil Reciprocity** (`elemLine_weil_reciprocity`, `lineProd_weil_reciprocity`, `lineProd_weil_reciprocity_degZero`): Elementary normalized line functions `L_{P₁, P₂}(x, y) = (y - y₁) - λ(x - x₁)` (pole order `3` at `𝓞`) and vertical lines `V_P(x, y) = x - x_P` (pole order `2` at `𝓞`) generate the multiplicative group `LineProd a b`. Via Mathlib's cubic intersection factorization `addPolynomial_slope`, we prove the exact pairwise Weil reciprocity law and extend it to all line-product functions: `f(div_aff g) = (-1)^(degInf f * degInf g) * g(div_aff f)`, hence exact `f(div_aff g) = g(div_aff f)` whenever `degInf f = 0` or `degInf g = 0`. 2. **Divisor Uniqueness via Coordinate-Ring Ideal Factorization** (`isUnit_coordinateRing_eq_C`, `lineProd_evalDiv_eq_of_affDiv_eq`): Using Mathlib's `XYIdeal_neg_mul`, `XYIdeal_mul_XYIdeal`, and `degree_norm_smul_basis`, we prove that any two `LineProd` functions with identical affine divisor differ by a nonzero constant in `K×`, and hence agree identically on every degree-0 affine divisor. 3. **Miller's Algorithm & Shifted Miller Functions** (`millerFunc`, `millerFunc_affDiv`, `shiftedMillerFunc`, `shiftedMillerFunc_affDiv`): Constructs `f_{m, P}` with `affDiv = m(P)` and `shiftedMillerFunc m P R` with degree-0 affine divisor `m(P + R) - m(R)` for every `P ∈ E[m]` (including `P = 0` and non-primitive torsion). 4. **The Weil Pairing & All Structural Theorems** (`weilPairing_shift_indep`, `weilPairing_skew_symm`, `weilPairing_pow_eq_one`, `weilPairing_bilinear_left`, `weilPairing_bilinear_right`, `weilPairing_alternating`, `weilPairing_galois_equivariant`): Proves shift-independence, skew-symmetry `e_m(Q, P) = e_m(P, Q)⁻¹`, `m`-th root of unity `e_m(P, Q)^m = 1`, bilinearity in both arguments, the alternating property `e_m(P, P) = 1` for ALL `m ≥ 1` (even and odd, via `R = -P - S` and negation pullback), and Galois equivariance. 5. **Concrete Non-Degeneracy Witnesses** (`weilPairing_e2_nondegenerate`, `weilPairing_e3_nondegenerate`): - Over `𝔽₁₃`, on `E : y² = x³ + 9 x` (`= x(x-2)(x+2)`), `e₂((0, 0), (2, 0)) = -1 ≠ 1`. - Over `𝔽₁₃`, on `E : y² = x³ + 7 x`, `e₃((3, 3), (4, 1)) = 9 ≠ 1` (primitive cube root, `9³ = 1`). -/ open Polynomial open scoped nonZeroDivisors namespace EllipticWeilPairing /-- Short Weierstrass curve `Y² = X³ + a X + b`. -/ def shortWeierstrass {R : Type*} [CommRing R] (a b : R) : WeierstrassCurve R := ⟨0, 0, 0, a, b⟩ lemma shortWeierstrass_equation_iff {R : Type*} [CommRing R] (a b x y : R) : (shortWeierstrass a b).toAffine.Equation x y ↔ y ^ 2 = x ^ 3 + a * x + b := by rw [WeierstrassCurve.Affine.equation_iff] change y ^ 2 + 0 * x * y + 0 * y = x ^ 3 + 0 * x ^ 2 + a * x + b ↔ _ constructor <;> intro h <;> linear_combination h lemma shortWeierstrass_nonsingular_iff {R : Type*} [CommRing R] (a b x y : R) : (shortWeierstrass a b).toAffine.Nonsingular x y ↔ y ^ 2 = x ^ 3 + a * x + b ∧ (2 * y ≠ 0 ∨ 3 * x ^ 2 + a ≠ 0) := by rw [WeierstrassCurve.Affine.nonsingular_iff, shortWeierstrass_equation_iff] change y ^ 2 = x ^ 3 + a * x + b ∧ (0 * y ≠ 3 * x ^ 2 + 2 * 0 * x + a ∨ y ≠ -y - 0 * x - 0) ↔ _ constructor · rintro ⟨heq, h | h⟩ · exact ⟨heq, Or.inr (fun h0 => h (by linear_combination -h0))⟩ · exact ⟨heq, Or.inl (fun h0 => h (by linear_combination h0))⟩ · rintro ⟨heq, h | h⟩ · exact ⟨heq, Or.inr (fun h0 => h (by linear_combination h0))⟩ · exact ⟨heq, Or.inl (fun h0 => h (by linear_combination -h0))⟩ lemma shortWeierstrass_negY {R : Type*} [CommRing R] (a b x y : R) : (shortWeierstrass a b).toAffine.negY x y = -y := by change -y - 0 * x - 0 = -y; ring lemma shortWeierstrass_addX {R : Type*} [CommRing R] (a b x₁ x₂ ℓ : R) : (shortWeierstrass a b).toAffine.addX x₁ x₂ ℓ = ℓ ^ 2 - x₁ - x₂ := by change ℓ ^ 2 + 0 * ℓ - 0 - x₁ - x₂ = _; ring lemma shortWeierstrass_addY {R : Type*} [CommRing R] (a b x₁ x₂ y₁ ℓ : R) : (shortWeierstrass a b).toAffine.addY x₁ x₂ y₁ ℓ = -(ℓ * ((ℓ ^ 2 - x₁ - x₂) - x₁) + y₁) := by change (shortWeierstrass a b).toAffine.negY _ (ℓ * ((shortWeierstrass a b).toAffine.addX x₁ x₂ ℓ - x₁) + y₁) = _ rw [shortWeierstrass_negY, shortWeierstrass_addX] /-! ## Section 1: Elementary Normalized Line Functions & Pairwise Weil Reciprocity -/ section LineFunctions variable {K : Type*} [Field K] [DecidableEq K] /-- X-coordinate of a point (0 at `𝓞`). -/ def ptX {a b : K} : (shortWeierstrass a b).toAffine.Point → K | .zero => 0 | .some x _ _ => x /-- Y-coordinate of a point (0 at `𝓞`). -/ def ptY {a b : K} : (shortWeierstrass a b).toAffine.Point → K | .zero => 0 | .some _ y _ => y omit [DecidableEq K] in lemma pt_eq_some_of_ne_zero {a b : K} {P : (shortWeierstrass a b).toAffine.Point} (hP : P ≠ 0) : ∃ (x y : K) (h : (shortWeierstrass a b).toAffine.Nonsingular x y), P = .some x y h := by cases P with | zero => exact absurd rfl hP | some x y h => exact ⟨x, y, h, rfl⟩ omit [DecidableEq K] in lemma ptX_neg {a b : K} (P : (shortWeierstrass a b).toAffine.Point) : ptX (-P) = ptX P := by cases P with | zero => rfl | some x y h => rw [WeierstrassCurve.Affine.Point.neg_some]; rfl omit [DecidableEq K] in lemma ptY_neg {a b : K} (P : (shortWeierstrass a b).toAffine.Point) : ptY (-P) = -ptY P := by cases P with | zero => change ptY (-0) = -0 rw [WeierstrassCurve.Affine.Point.neg_zero] exact neg_zero.symm | some x y h => rw [WeierstrassCurve.Affine.Point.neg_some] exact shortWeierstrass_negY a b x y omit [DecidableEq K] in lemma pt_eq_of_eq_X {a b : K} {P Q : (shortWeierstrass a b).toAffine.Point} (hP : P ≠ 0) (hQ : Q ≠ 0) (hx : ptX P = ptX Q) : P = Q ∨ P = -Q := by obtain ⟨x₁, y₁, h₁, rfl⟩ := pt_eq_some_of_ne_zero hP obtain ⟨x₂, y₂, h₂, rfl⟩ := pt_eq_some_of_ne_zero hQ change x₁ = x₂ at hx subst hx have heq₁ := (shortWeierstrass_nonsingular_iff a b x₁ y₁).mp h₁ |>.1 have heq₂ := (shortWeierstrass_nonsingular_iff a b x₁ y₂).mp h₂ |>.1 have hsq : y₁ ^ 2 = y₂ ^ 2 := heq₁.trans heq₂.symm rcases sq_eq_sq_iff_eq_or_eq_neg.mp hsq with rfl | hneg · left; rfl · right rw [WeierstrassCurve.Affine.Point.neg_some, WeierstrassCurve.Affine.Point.some.injEq] exact ⟨rfl, by rw [shortWeierstrass_negY]; exact hneg⟩ /-- Elementary normalized line function on `E : y² = x³ + a x + b`: - `nonVert P₁ P₂`: normalized line `y - y₁ - λ(x - x₁)` through `P₁, P₂, -(P₁ + P₂)` (pole order 3 at `𝓞`); - `vert P`: normalized vertical line `x - x_P` through `P, -P` (pole order 2 at `𝓞`). -/ inductive ElemLine (a b : K) | nonVert (P₁ P₂ : (shortWeierstrass a b).toAffine.Point) (h₁ : P₁ ≠ 0) (h₂ : P₂ ≠ 0) (h12 : P₁ + P₂ ≠ 0) | vert (P : (shortWeierstrass a b).toAffine.Point) (hP : P ≠ 0) namespace ElemLine /-- List of affine zeros (with multiplicity) of an elementary line function. -/ def zeros {a b : K} : ElemLine a b → List (shortWeierstrass a b).toAffine.Point | nonVert P₁ P₂ _ _ _ => [P₁, P₂, -(P₁ + P₂)] | vert P _ => [P, -P] /-- Pole order at infinity `𝓞` (= number of affine zeros). -/ def degInf {a b : K} : ElemLine a b → ℤ | nonVert _ _ _ _ _ => 3 | vert _ _ => 2 lemma zeros_ne_zero {a b : K} (L : ElemLine a b) {Q : (shortWeierstrass a b).toAffine.Point} (hQ : Q ∈ L.zeros) : Q ≠ 0 := by cases L with | nonVert P₁ P₂ h₁ h₂ h12 => simp only [zeros, List.mem_cons, List.not_mem_nil, or_false] at hQ rcases hQ with rfl | rfl | rfl · exact h₁ · exact h₂ · exact neg_ne_zero.mpr h12 | vert P hP => simp only [zeros, List.mem_cons, List.not_mem_nil, or_false] at hQ rcases hQ with rfl | rfl · exact hP · exact neg_ne_zero.mpr hP /-- Slope of a non-vertical line through `P₁` and `P₂`. -/ def lineSlope {a b : K} (P₁ P₂ : (shortWeierstrass a b).toAffine.Point) : K := (shortWeierstrass a b).toAffine.slope (ptX P₁) (ptX P₂) (ptY P₁) (ptY P₂) /-- Intercept `μ = y₁ - λ x₁` so the line equation is `y = λ x + μ`. -/ def lineIntercept {a b : K} (P₁ P₂ : (shortWeierstrass a b).toAffine.Point) : K := ptY P₁ - lineSlope P₁ P₂ * ptX P₁ /-- Evaluate an elementary line function at an affine point `Q`. -/ def eval {a b : K} : ElemLine a b → (shortWeierstrass a b).toAffine.Point → K | nonVert P₁ P₂ _ _ _, Q => ptY Q - (lineSlope P₁ P₂ * ptX Q + lineIntercept P₁ P₂) | vert P _, Q => ptX Q - ptX P /-- Negation pullback on an elementary line: sends `nonVert P₁ P₂` to `nonVert (-P₁) (-P₂)` and `vert P` to `vert (-P)`. -/ def negPull {a b : K} : ElemLine a b → ElemLine a b | nonVert P₁ P₂ h₁ h₂ h12 => nonVert (-P₁) (-P₂) (neg_ne_zero.mpr h₁) (neg_ne_zero.mpr h₂) (by rw [← neg_add]; exact neg_ne_zero.mpr h12) | vert P hP => vert (-P) (neg_ne_zero.mpr hP) lemma negPull_zeros {a b : K} (L : ElemLine a b) : L.negPull.zeros = L.zeros.map (fun P => -P) := by cases L with | nonVert P₁ P₂ h₁ h₂ h12 => simp only [negPull, zeros, List.map_cons, List.map_nil, List.cons.injEq, and_true, true_and] abel | vert P hP => simp [negPull, zeros] lemma lineSlope_neg {a b : K} {P₁ P₂ : (shortWeierstrass a b).toAffine.Point} (h₁ : P₁ ≠ 0) (h₂ : P₂ ≠ 0) (h12 : P₁ + P₂ ≠ 0) : lineSlope (-P₁) (-P₂) = -lineSlope P₁ P₂ := by obtain ⟨x₁, y₁, hn₁, rfl⟩ := pt_eq_some_of_ne_zero h₁ obtain ⟨x₂, y₂, hn₂, rfl⟩ := pt_eq_some_of_ne_zero h₂ have hxy : ¬ (x₁ = x₂ ∧ y₁ = (shortWeierstrass a b).toAffine.negY x₂ y₂) := by rintro ⟨rfl, hy⟩; exact h12 (WeierstrassCurve.Affine.Point.add_of_Y_eq rfl hy) unfold lineSlope rw [ptX_neg, ptX_neg, ptY_neg, ptY_neg] change (shortWeierstrass a b).toAffine.slope x₁ x₂ (-y₁) (-y₂) = -(shortWeierstrass a b).toAffine.slope x₁ x₂ y₁ y₂ by_cases hx : x₁ = x₂ · subst hx have hy : y₁ ≠ (shortWeierstrass a b).toAffine.negY x₁ y₂ := fun h => hxy ⟨rfl, h⟩ have hy' : -y₁ ≠ (shortWeierstrass a b).toAffine.negY x₁ (-y₂) := by rw [shortWeierstrass_negY] at hy ⊢ intro h; apply hy; linear_combination -h rw [WeierstrassCurve.Affine.slope_of_Y_ne rfl hy, WeierstrassCurve.Affine.slope_of_Y_ne rfl hy'] change (3 * x₁ ^ 2 + 2 * 0 * x₁ + a - 0 * (-y₁)) / (-y₁ - (-(-y₁) - 0 * x₁ - 0)) = -((3 * x₁ ^ 2 + 2 * 0 * x₁ + a - 0 * y₁) / (y₁ - (-y₁ - 0 * x₁ - 0))) have h1' : -y₁ - (-(-y₁) - 0 * x₁ - 0) = -(2 * y₁) := by ring have h2' : y₁ - (-y₁ - 0 * x₁ - 0) = 2 * y₁ := by ring have hnum1 : 3 * x₁ ^ 2 + 2 * 0 * x₁ + a - 0 * (-y₁) = 3 * x₁ ^ 2 + a := by ring have hnum2 : 3 * x₁ ^ 2 + 2 * 0 * x₁ + a - 0 * y₁ = 3 * x₁ ^ 2 + a := by ring rw [h1', h2', hnum1, hnum2, div_neg] · rw [WeierstrassCurve.Affine.slope_of_X_ne hx, WeierstrassCurve.Affine.slope_of_X_ne hx] ring lemma negPull_eval {a b : K} (L : ElemLine a b) (Q : (shortWeierstrass a b).toAffine.Point) : L.negPull.eval Q = (-1 : K) ^ L.degInf * L.eval (-Q) := by cases L with | nonVert P₁ P₂ h₁ h₂ h12 => have hs : (-1 : K) ^ (3 : ℤ) = -1 := by norm_num simp only [negPull, degInf, eval, lineIntercept, hs] rw [lineSlope_neg h₁ h₂ h12, ptX_neg, ptX_neg, ptY_neg, ptY_neg] ring | vert P hP => have hs : (-1 : K) ^ (2 : ℤ) = 1 := by norm_num simp only [negPull, degInf, eval, hs, one_mul, ptX_neg] /-- Key cubic factorization for a non-vertical line `L = nonVert P₁ P₂`: `x³ + a x + b - (λ x + μ)² = (x - x₁)(x - x₂)(x - x₃)` for ALL `x ∈ K`! -/ lemma nonVert_cubic_factor {a b : K} {P₁ P₂ : (shortWeierstrass a b).toAffine.Point} (h₁ : P₁ ≠ 0) (h₂ : P₂ ≠ 0) (h12 : P₁ + P₂ ≠ 0) (x : K) : x ^ 3 + a * x + b - (lineSlope P₁ P₂ * x + lineIntercept P₁ P₂) ^ 2 = (x - ptX P₁) * (x - ptX P₂) * (x - ptX (-(P₁ + P₂))) := by obtain ⟨x₁, y₁, hn₁, rfl⟩ := pt_eq_some_of_ne_zero h₁ obtain ⟨x₂, y₂, hn₂, rfl⟩ := pt_eq_some_of_ne_zero h₂ have hxy : ¬ (x₁ = x₂ ∧ y₁ = (shortWeierstrass a b).toAffine.negY x₂ y₂) := by rintro ⟨rfl, hy⟩; exact h12 (WeierstrassCurve.Affine.Point.add_of_Y_eq rfl hy) have hadd : WeierstrassCurve.Affine.Point.some x₁ y₁ hn₁ + .some x₂ y₂ hn₂ = .some _ _ ((shortWeierstrass a b).toAffine.nonsingular_add hn₁ hn₂ hxy) := WeierstrassCurve.Affine.Point.add_some hxy have hx3 : ptX (-(WeierstrassCurve.Affine.Point.some x₁ y₁ hn₁ + .some x₂ y₂ hn₂)) = (shortWeierstrass a b).toAffine.addX x₁ x₂ ((shortWeierstrass a b).toAffine.slope x₁ x₂ y₁ y₂) := by rw [ptX_neg, hadd]; rfl rw [hx3] set ℓ := (shortWeierstrass a b).toAffine.slope x₁ x₂ y₁ y₂ have hpoly := (shortWeierstrass a b).toAffine.addPolynomial_slope hn₁.1 hn₂.1 hxy have hev' : ((shortWeierstrass a b).toAffine.addPolynomial x₁ y₁ ℓ).eval x = -((x - x₁) * (x - x₂) * (x - (shortWeierstrass a b).toAffine.addX x₁ x₂ ℓ)) := by have h1 := congr_arg (Polynomial.eval x) hpoly simp only [eval_neg, eval_mul, eval_sub, eval_X, eval_C] at h1 exact h1 have hlhs : ((shortWeierstrass a b).toAffine.addPolynomial x₁ y₁ ℓ).eval x = (ℓ * x + (y₁ - ℓ * x₁)) ^ 2 - (x ^ 3 + a * x + b) := by unfold WeierstrassCurve.Affine.addPolynomial WeierstrassCurve.Affine.linePolynomial WeierstrassCurve.Affine.polynomial simp only [shortWeierstrass, eval_sub, eval_add, eval_mul, eval_pow, eval_C, eval_X] change (ℓ * (x - x₁) + y₁) ^ 2 + (0 * x + 0) * (ℓ * (x - x₁) + y₁) - (x ^ 3 + 0 * x ^ 2 + a * x + b) = _ ring rw [hlhs] at hev' change x ^ 3 + a * x + b - (ℓ * x + (y₁ - ℓ * x₁)) ^ 2 = (x - x₁) * (x - x₂) * (x - (shortWeierstrass a b).toAffine.addX x₁ x₂ ℓ) linear_combination -hev' lemma nonVert_eval_zero_of_mem {a b : K} {P₁ P₂ Q : (shortWeierstrass a b).toAffine.Point} (h₁ : P₁ ≠ 0) (h₂ : P₂ ≠ 0) (h12 : P₁ + P₂ ≠ 0) (hQ : Q ∈ (ElemLine.nonVert P₁ P₂ h₁ h₂ h12).zeros) : (ElemLine.nonVert P₁ P₂ h₁ h₂ h12).eval Q = 0 := by obtain ⟨x₁, y₁, hn₁, rfl⟩ := pt_eq_some_of_ne_zero h₁ obtain ⟨x₂, y₂, hn₂, rfl⟩ := pt_eq_some_of_ne_zero h₂ have hxy : ¬ (x₁ = x₂ ∧ y₁ = (shortWeierstrass a b).toAffine.negY x₂ y₂) := by rintro ⟨rfl, hy⟩; exact h12 (WeierstrassCurve.Affine.Point.add_of_Y_eq rfl hy) simp only [zeros, List.mem_cons, List.not_mem_nil, or_false] at hQ rcases hQ with rfl | rfl | rfl · simp [eval, lineIntercept, ptX, ptY] · simp only [eval, lineIntercept, lineSlope, ptX, ptY] by_cases hx : x₁ = x₂ · subst hx have hy : y₁ ≠ (shortWeierstrass a b).toAffine.negY x₁ y₂ := fun h => hxy ⟨rfl, h⟩ have heq₁ := (shortWeierstrass_nonsingular_iff a b x₁ y₁).mp hn₁ |>.1 have heq₂ := (shortWeierstrass_nonsingular_iff a b x₁ y₂).mp hn₂ |>.1 rcases sq_eq_sq_iff_eq_or_eq_neg.mp (heq₁.trans heq₂.symm) with rfl | hneg · ring · exfalso; apply hy; rw [shortWeierstrass_negY]; exact hneg · rw [WeierstrassCurve.Affine.slope_of_X_ne hx] have hne : x₁ - x₂ ≠ 0 := sub_ne_zero.mpr hx field_simp [hne]; ring · have hadd : WeierstrassCurve.Affine.Point.some x₁ y₁ hn₁ + .some x₂ y₂ hn₂ = .some _ _ ((shortWeierstrass a b).toAffine.nonsingular_add hn₁ hn₂ hxy) := WeierstrassCurve.Affine.Point.add_some hxy simp only [eval, lineIntercept, lineSlope] rw [ptX_neg, ptY_neg, hadd] change -(shortWeierstrass a b).toAffine.addY x₁ x₂ y₁ ((shortWeierstrass a b).toAffine.slope x₁ x₂ y₁ y₂) - ((shortWeierstrass a b).toAffine.slope x₁ x₂ y₁ y₂ * (shortWeierstrass a b).toAffine.addX x₁ x₂ ((shortWeierstrass a b).toAffine.slope x₁ x₂ y₁ y₂) + (y₁ - (shortWeierstrass a b).toAffine.slope x₁ x₂ y₁ y₂ * x₁)) = 0 rw [shortWeierstrass_addY, shortWeierstrass_addX] ring /-- **Nonvanishing away from zeros**: if `Q ≠ 0` and `Q ∉ L.zeros`, then `L.eval Q ≠ 0`. -/ lemma eval_ne_zero_of_not_mem {a b : K} (L : ElemLine a b) {Q : (shortWeierstrass a b).toAffine.Point} (hQ0 : Q ≠ 0) (hQ : Q ∉ L.zeros) : L.eval Q ≠ 0 := by cases L with | vert P hP => intro hev apply hQ have hx : ptX Q = ptX P := sub_eq_zero.mp hev rcases pt_eq_of_eq_X hQ0 hP hx with rfl | rfl <;> simp [zeros] | nonVert P₁ P₂ h₁ h₂ h12 => intro hev obtain ⟨xQ, yQ, hnQ, rfl⟩ := pt_eq_some_of_ne_zero hQ0 have hyQ : yQ = lineSlope P₁ P₂ * xQ + lineIntercept P₁ P₂ := sub_eq_zero.mp hev have heqQ := (shortWeierstrass_nonsingular_iff a b xQ yQ).mp hnQ |>.1 have hfac := nonVert_cubic_factor h₁ h₂ h12 xQ rw [← hyQ, ← heqQ, sub_self] at hfac have hzero : (xQ - ptX P₁) = 0 ∨ (xQ - ptX P₂) = 0 ∨ (xQ - ptX (-(P₁ + P₂))) = 0 := by rcases mul_eq_zero.mp hfac.symm with h12' | h3 · rcases mul_eq_zero.mp h12' with h1' | h2' · exact Or.inl h1' · exact Or.inr (Or.inl h2') · exact Or.inr (Or.inr h3) have hmatch : ∀ R : (shortWeierstrass a b).toAffine.Point, R ∈ (ElemLine.nonVert P₁ P₂ h₁ h₂ h12).zeros → xQ = ptX R → WeierstrassCurve.Affine.Point.some xQ yQ hnQ = R := by intro R hR hxR have hR0 : R ≠ 0 := zeros_ne_zero _ hR have hRy : ptY R = lineSlope P₁ P₂ * ptX R + lineIntercept P₁ P₂ := sub_eq_zero.mp (nonVert_eval_zero_of_mem h₁ h₂ h12 hR) obtain ⟨xR, yR, hnR, rfl⟩ := pt_eq_some_of_ne_zero hR0 change xQ = xR at hxR subst hxR rw [WeierstrassCurve.Affine.Point.some.injEq] exact ⟨rfl, hyQ.trans hRy.symm⟩ apply hQ rcases hzero with hx1 | hx2 | hx3 · rw [hmatch P₁ (by simp [zeros]) (sub_eq_zero.mp hx1)]; simp [zeros] · rw [hmatch P₂ (by simp [zeros]) (sub_eq_zero.mp hx2)]; simp [zeros] · rw [hmatch (-(P₁ + P₂)) (by simp [zeros]) (sub_eq_zero.mp hx3)]; simp [zeros] /-- **EXACT PAIRWISE WEIL RECIPROCITY ON ELEMENTARY LINES**: For ANY two elementary line functions `L₁, L₂` on `E : y² = x³ + a x + b`, `∏_{Q ∈ L₂.zeros} L₁(Q) = (-1)^(degInf L₁ * degInf L₂) * ∏_{P ∈ L₁.zeros} L₂(P)`! -/ theorem elemLine_weil_reciprocity {a b : K} (L₁ L₂ : ElemLine a b) : (L₂.zeros.map L₁.eval).prod = (-1 : K) ^ (L₁.degInf * L₂.degInf) * (L₁.zeros.map L₂.eval).prod := by cases L₁ with | vert P₁ hP₁ => cases L₂ with | vert P₂ hP₂ => simp only [zeros, degInf, List.map_cons, List.map_nil, List.prod_cons, List.prod_nil, mul_one, eval, ptX_neg] have hsign : (-1 : K) ^ ((2 : ℤ) * 2) = 1 := by norm_num rw [hsign]; ring | nonVert Q₁ Q₂ hQ₁ hQ₂ hQ12 => simp only [zeros, degInf, List.map_cons, List.map_nil, List.prod_cons, List.prod_nil, mul_one, eval, ptX_neg, ptY_neg] have hsign : (-1 : K) ^ ((2 : ℤ) * 3) = 1 := by norm_num rw [hsign, one_mul] have hfac := nonVert_cubic_factor hQ₁ hQ₂ hQ12 (ptX P₁) obtain ⟨x₁, y₁, hn₁, rfl⟩ := pt_eq_some_of_ne_zero hP₁ have heq₁ := (shortWeierstrass_nonsingular_iff a b x₁ y₁).mp hn₁ |>.1 rw [ptX_neg] at hfac change (ptX Q₁ - x₁) * ((ptX Q₂ - x₁) * (ptX (Q₁ + Q₂) - x₁)) = (y₁ - (lineSlope Q₁ Q₂ * x₁ + lineIntercept Q₁ Q₂)) * (-y₁ - (lineSlope Q₁ Q₂ * x₁ + lineIntercept Q₁ Q₂)) change x₁ ^ 3 + a * x₁ + b - (lineSlope Q₁ Q₂ * x₁ + lineIntercept Q₁ Q₂) ^ 2 = (x₁ - ptX Q₁) * (x₁ - ptX Q₂) * (x₁ - ptX (Q₁ + Q₂)) at hfac linear_combination hfac + heq₁ | nonVert P₁ P₂ hP₁ hP₂ hP12 => cases L₂ with | vert Q hQ => simp only [zeros, degInf, List.map_cons, List.map_nil, List.prod_cons, List.prod_nil, mul_one, eval, ptX_neg, ptY_neg] have hsign : (-1 : K) ^ ((3 : ℤ) * 2) = 1 := by norm_num rw [hsign, one_mul] have hfac := nonVert_cubic_factor hP₁ hP₂ hP12 (ptX Q) obtain ⟨xQ, yQ, hnQ, rfl⟩ := pt_eq_some_of_ne_zero hQ have heqQ := (shortWeierstrass_nonsingular_iff a b xQ yQ).mp hnQ |>.1 rw [ptX_neg] at hfac change (yQ - (lineSlope P₁ P₂ * xQ + lineIntercept P₁ P₂)) * (-yQ - (lineSlope P₁ P₂ * xQ + lineIntercept P₁ P₂)) = (ptX P₁ - xQ) * ((ptX P₂ - xQ) * (ptX (P₁ + P₂) - xQ)) change xQ ^ 3 + a * xQ + b - (lineSlope P₁ P₂ * xQ + lineIntercept P₁ P₂) ^ 2 = (xQ - ptX P₁) * (xQ - ptX P₂) * (xQ - ptX (P₁ + P₂)) at hfac linear_combination -hfac - heqQ | nonVert Q₁ Q₂ hQ₁ hQ₂ hQ12 => have hsign : (-1 : K) ^ ((3 : ℤ) * 3) = -1 := by norm_num set ℓ₁ := lineSlope P₁ P₂ set μ₁ := lineIntercept P₁ P₂ set ℓ₂ := lineSlope Q₁ Q₂ set μ₂ := lineIntercept Q₁ Q₂ have hP_on : ∀ P ∈ (ElemLine.nonVert P₁ P₂ hP₁ hP₂ hP12).zeros, ptY P = ℓ₁ * ptX P + μ₁ := fun P hP => sub_eq_zero.mp (nonVert_eval_zero_of_mem hP₁ hP₂ hP12 hP) have hQ_on : ∀ Q ∈ (ElemLine.nonVert Q₁ Q₂ hQ₁ hQ₂ hQ12).zeros, ptY Q = ℓ₂ * ptX Q + μ₂ := fun Q hQ => sub_eq_zero.mp (nonVert_eval_zero_of_mem hQ₁ hQ₂ hQ12 hQ) have hP1y := hP_on P₁ (by simp [zeros]) have hP2y := hP_on P₂ (by simp [zeros]) have hP3y := hP_on (-(P₁ + P₂)) (by simp [zeros]) have hQ1y := hQ_on Q₁ (by simp [zeros]) have hQ2y := hQ_on Q₂ (by simp [zeros]) have hQ3y := hQ_on (-(Q₁ + Q₂)) (by simp [zeros]) simp only [zeros, degInf, List.map_cons, List.map_nil, List.prod_cons, List.prod_nil, mul_one, eval] rw [hsign] change (ptY Q₁ - (ℓ₁ * ptX Q₁ + μ₁)) * ((ptY Q₂ - (ℓ₁ * ptX Q₂ + μ₁)) * (ptY (-(Q₁ + Q₂)) - (ℓ₁ * ptX (-(Q₁ + Q₂)) + μ₁))) = (-1 : K) * ((ptY P₁ - (ℓ₂ * ptX P₁ + μ₂)) * ((ptY P₂ - (ℓ₂ * ptX P₂ + μ₂)) * (ptY (-(P₁ + P₂)) - (ℓ₂ * ptX (-(P₁ + P₂)) + μ₂)))) rw [hP1y, hP2y, hP3y, hQ1y, hQ2y, hQ3y] by_cases hpar : ℓ₁ = ℓ₂ · rw [hpar]; ring · have hd : ℓ₁ - ℓ₂ ≠ 0 := sub_ne_zero.mpr hpar set x₀ := -(μ₁ - μ₂) / (ℓ₁ - ℓ₂) have hmeet : ℓ₁ * x₀ + μ₁ = ℓ₂ * x₀ + μ₂ := by dsimp only [x₀]; field_simp [hd]; ring have hfac₁ := nonVert_cubic_factor hP₁ hP₂ hP12 x₀ have hfac₂ := nonVert_cubic_factor hQ₁ hQ₂ hQ12 x₀ change x₀ ^ 3 + a * x₀ + b - (ℓ₁ * x₀ + μ₁) ^ 2 = (x₀ - ptX P₁) * (x₀ - ptX P₂) * (x₀ - ptX (-(P₁ + P₂))) at hfac₁ change x₀ ^ 3 + a * x₀ + b - (ℓ₂ * x₀ + μ₂) ^ 2 = (x₀ - ptX Q₁) * (x₀ - ptX Q₂) * (x₀ - ptX (-(Q₁ + Q₂))) at hfac₂ have hprod_eq : (x₀ - ptX P₁) * (x₀ - ptX P₂) * (x₀ - ptX (-(P₁ + P₂))) = (x₀ - ptX Q₁) * (x₀ - ptX Q₂) * (x₀ - ptX (-(Q₁ + Q₂))) := by rw [← hfac₁, ← hfac₂, hmeet] have hlin₁ : ∀ x : K, (ℓ₂ * x + μ₂) - (ℓ₁ * x + μ₁) = (ℓ₁ - ℓ₂) * (x₀ - x) := by intro x; dsimp only [x₀]; field_simp [hd]; ring have hlin₂ : ∀ x : K, (ℓ₁ * x + μ₁) - (ℓ₂ * x + μ₂) = -(ℓ₁ - ℓ₂) * (x₀ - x) := by intro x; dsimp only [x₀]; field_simp [hd]; ring rw [hlin₁ (ptX Q₁), hlin₁ (ptX Q₂), hlin₁ (ptX (-(Q₁ + Q₂))), hlin₂ (ptX P₁), hlin₂ (ptX P₂), hlin₂ (ptX (-(P₁ + P₂)))] linear_combination -(ℓ₁ - ℓ₂) ^ 3 * hprod_eq end ElemLine /-! ## Section 2: Line-Product Functions, Full Weil Reciprocity & Divisor Uniqueness -/ /-- Formal multiplicative product `∏ᵢ Lᵢ^{eᵢ}` of elementary line functions on `E`. -/ abbrev LineProd (a b : K) := List (ElemLine a b × ℤ) namespace LineProd /-- Evaluate a line-product function at an affine point `Q`. -/ def eval {a b : K} (f : LineProd a b) (Q : (shortWeierstrass a b).toAffine.Point) : K := (f.map fun p => (p.1.eval Q) ^ p.2).prod /-- Affine divisor of an elementary line function as a `Finsupp`. -/ noncomputable def elemAffDiv {a b : K} (L : ElemLine a b) : (shortWeierstrass a b).toAffine.Point →₀ ℤ := (L.zeros.map fun P => Finsupp.single P (1 : ℤ)).sum /-- Affine divisor of a line-product function `f = ∏ Lᵢ^{eᵢ}`: `∑ eᵢ • div_aff(Lᵢ)`. -/ noncomputable def affDiv {a b : K} (f : LineProd a b) : (shortWeierstrass a b).toAffine.Point →₀ ℤ := (f.map fun p => p.2 • elemAffDiv p.1).sum /-- Pole order at infinity `𝓞`: `∑ eᵢ * degInf(Lᵢ)`. -/ def degInf {a b : K} (f : LineProd a b) : ℤ := (f.map fun p => p.2 * p.1.degInf).sum /-- Factor-support of `f`: union of all zero-lists of constituent lines in `f`. -/ def factorSupp {a b : K} (f : LineProd a b) : Set (shortWeierstrass a b).toAffine.Point := { Q | ∃ p ∈ f, Q ∈ p.1.zeros } /-- Negate all exponents in a line-product (`f⁻¹`). -/ def inv {a b : K} (f : LineProd a b) : LineProd a b := f.map fun p => (p.1, -p.2) /-- Scale all exponents in a line-product (`f^m`). -/ def zpow {a b : K} (f : LineProd a b) (m : ℤ) : LineProd a b := f.map fun p => (p.1, m * p.2) /-- Negation pullback of a line-product: `f(-X)`. -/ def negPull {a b : K} (f : LineProd a b) : LineProd a b := f.map fun p => (p.1.negPull, p.2) /-- Evaluation of a line-product function `f` on an affine divisor `D = ∑ n_Q (Q)`: `∏ f(Q)^{n_Q}`. -/ noncomputable def evalDiv {a b : K} (f : LineProd a b) (D : (shortWeierstrass a b).toAffine.Point →₀ ℤ) : K := D.prod fun Q n => (f.eval Q) ^ n lemma eval_nil {a b : K} (Q : (shortWeierstrass a b).toAffine.Point) : eval ([] : LineProd a b) Q = 1 := rfl lemma eval_cons {a b : K} (p : ElemLine a b × ℤ) (f : LineProd a b) (Q : (shortWeierstrass a b).toAffine.Point) : eval (p :: f) Q = (p.1.eval Q) ^ p.2 * eval f Q := rfl lemma eval_append {a b : K} (f g : LineProd a b) (Q : (shortWeierstrass a b).toAffine.Point) : eval (f ++ g) Q = eval f Q * eval g Q := by simp [eval] lemma eval_inv {a b : K} (f : LineProd a b) (Q : (shortWeierstrass a b).toAffine.Point) : eval f.inv Q = (eval f Q)⁻¹ := by induction f with | nil => simp [inv, eval] | cons p fs ih => simp only [inv, List.map_cons, eval_cons, zpow_neg, mul_inv_rev] change (p.1.eval Q ^ p.2)⁻¹ * eval (inv fs) Q = _ rw [ih, mul_comm] lemma eval_zpow {a b : K} (f : LineProd a b) (m : ℤ) (Q : (shortWeierstrass a b).toAffine.Point) : eval (f.zpow m) Q = (eval f Q) ^ m := by induction f with | nil => simp [zpow, eval] | cons p fs ih => simp only [zpow, List.map_cons, eval_cons, mul_zpow] change p.1.eval Q ^ (m * p.2) * eval (zpow fs m) Q = _ rw [ih, mul_comm m p.2, zpow_mul] lemma affDiv_nil {a b : K} : affDiv ([] : LineProd a b) = 0 := rfl lemma affDiv_cons {a b : K} (p : ElemLine a b × ℤ) (f : LineProd a b) : affDiv (p :: f) = p.2 • elemAffDiv p.1 + affDiv f := rfl lemma affDiv_append {a b : K} (f g : LineProd a b) : affDiv (f ++ g) = affDiv f + affDiv g := by simp [affDiv] lemma affDiv_inv {a b : K} (f : LineProd a b) : affDiv f.inv = -affDiv f := by induction f with | nil => simp [inv, affDiv] | cons p fs ih => simp only [inv, List.map_cons, affDiv_cons, neg_smul, neg_add] change -(p.2 • elemAffDiv p.1) + affDiv (inv fs) = _ rw [ih] lemma affDiv_zpow {a b : K} (f : LineProd a b) (m : ℤ) : affDiv (f.zpow m) = m • affDiv f := by induction f with | nil => simp [zpow, affDiv] | cons p fs ih => simp only [zpow, List.map_cons, affDiv_cons, smul_add, mul_smul] change m • p.2 • elemAffDiv p.1 + affDiv (zpow fs m) = _ rw [ih] lemma degInf_nil {a b : K} : degInf ([] : LineProd a b) = 0 := rfl lemma degInf_cons {a b : K} (p : ElemLine a b × ℤ) (f : LineProd a b) : degInf (p :: f) = p.2 * p.1.degInf + degInf f := rfl lemma degInf_append {a b : K} (f g : LineProd a b) : degInf (f ++ g) = degInf f + degInf g := by simp [degInf] lemma degInf_inv {a b : K} (f : LineProd a b) : degInf f.inv = -degInf f := by induction f with | nil => simp [inv, degInf] | cons p fs ih => simp only [inv, List.map_cons, degInf_cons, neg_mul] change -(p.2 * p.1.degInf) + degInf (inv fs) = _ rw [ih]; ring lemma degInf_zpow {a b : K} (f : LineProd a b) (m : ℤ) : degInf (f.zpow m) = m * degInf f := by induction f with | nil => simp [zpow, degInf] | cons p fs ih => simp only [zpow, List.map_cons, degInf_cons] change m * p.2 * p.1.degInf + degInf (zpow fs m) = _ rw [ih]; ring lemma factorSupp_append {a b : K} (f g : LineProd a b) : factorSupp (f ++ g) = factorSupp f ∪ factorSupp g := by ext Q simp only [factorSupp, Set.mem_ofPred_eq, Set.mem_union, List.mem_append] constructor · rintro ⟨p, hp | hp, hQ⟩ · exact Or.inl ⟨p, hp, hQ⟩ · exact Or.inr ⟨p, hp, hQ⟩ · rintro (⟨p, hp, hQ⟩ | ⟨p, hp, hQ⟩) · exact ⟨p, Or.inl hp, hQ⟩ · exact ⟨p, Or.inr hp, hQ⟩ lemma factorSupp_inv {a b : K} (f : LineProd a b) : factorSupp f.inv = factorSupp f := by ext Q; simp [factorSupp, inv] lemma factorSupp_zpow {a b : K} (f : LineProd a b) (m : ℤ) : factorSupp (f.zpow m) = factorSupp f := by ext Q; simp [factorSupp, zpow] lemma negPull_eval {a b : K} (f : LineProd a b) (Q : (shortWeierstrass a b).toAffine.Point) : f.negPull.eval Q = (-1 : K) ^ f.degInf * f.eval (-Q) := by induction f with | nil => simp [negPull, eval, degInf] | cons p fs ih => simp only [negPull, List.map_cons, eval_cons, degInf_cons] change p.1.negPull.eval Q ^ p.2 * eval (negPull fs) Q = _ rw [p.1.negPull_eval, mul_zpow, ih, zpow_add₀ (neg_ne_zero.mpr one_ne_zero), mul_comm p.2 p.1.degInf, zpow_mul] ring lemma negPull_affDiv {a b : K} (f : LineProd a b) : f.negPull.affDiv = f.affDiv.mapDomain (fun P => -P) := by induction f with | nil => simp [negPull, affDiv] | cons p fs ih => simp only [negPull, List.map_cons, affDiv_cons, Finsupp.mapDomain_add, Finsupp.mapDomain_smul] change p.2 • elemAffDiv p.1.negPull + affDiv (negPull fs) = _ rw [ih] congr 2 unfold elemAffDiv rw [p.1.negPull_zeros] cases p.1 <;> simp [ElemLine.zeros, Finsupp.mapDomain_add, Finsupp.mapDomain_single] lemma negPull_factorSupp {a b : K} (f : LineProd a b) : f.negPull.factorSupp = { Q | -Q ∈ f.factorSupp } := by ext Q simp only [factorSupp, negPull, List.mem_map, Set.mem_ofPred_eq] constructor · rintro ⟨_, ⟨p, hp, rfl⟩, hQ⟩ rw [p.1.negPull_zeros, List.mem_map] at hQ rcases hQ with ⟨R, hR, hRQ⟩ exact ⟨p, hp, by rw [← hRQ, neg_neg]; exact hR⟩ · rintro ⟨p, hp, hQ⟩ refine ⟨(p.1.negPull, p.2), ⟨p, hp, rfl⟩, ?_⟩ rw [p.1.negPull_zeros, List.mem_map] exact ⟨-Q, hQ, neg_neg Q⟩ lemma eval_ne_zero {a b : K} (f : LineProd a b) {Q : (shortWeierstrass a b).toAffine.Point} (hQ0 : Q ≠ 0) (hQ : Q ∉ f.factorSupp) : f.eval Q ≠ 0 := by induction f with | nil => exact one_ne_zero | cons p fs ih => rw [eval_cons] refine mul_ne_zero (zpow_ne_zero _ (p.1.eval_ne_zero_of_not_mem hQ0 ?_)) (ih ?_) · intro hmem; exact hQ ⟨p, List.mem_cons_self .., hmem⟩ · intro ⟨q, hq, hmem⟩; exact hQ ⟨q, List.mem_cons_of_mem _ hq, hmem⟩ lemma factorSupp_ne_zero {a b : K} (f : LineProd a b) {Q : (shortWeierstrass a b).toAffine.Point} (hQ : Q ∈ f.factorSupp) : Q ≠ 0 := by rcases hQ with ⟨p, _, hmem⟩ exact p.1.zeros_ne_zero hmem lemma support_elemAffDiv_subset {a b : K} (L : ElemLine a b) : ((elemAffDiv L).support : Set (shortWeierstrass a b).toAffine.Point) ⊆ { Q | Q ∈ L.zeros } := by intro Q hQ rw [Finset.mem_coe, Finsupp.mem_support_iff] at hQ cases L with | nonVert P₁ P₂ h₁ h₂ h12 => simp only [elemAffDiv, ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, add_zero, Finsupp.add_apply, Finsupp.single_apply] at hQ change Q ∈ [P₁, P₂, -(P₁ + P₂)] by_contra hnot simp only [List.mem_cons, List.not_mem_nil, or_false, not_or] at hnot apply hQ simp only [if_neg (Ne.symm hnot.1), if_neg (Ne.symm hnot.2.1), if_neg (Ne.symm hnot.2.2), add_zero] | vert P hP => simp only [elemAffDiv, ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, add_zero, Finsupp.add_apply, Finsupp.single_apply] at hQ change Q ∈ [P, -P] by_contra hnot simp only [List.mem_cons, List.not_mem_nil, or_false, not_or] at hnot apply hQ simp only [if_neg (Ne.symm hnot.1), if_neg (Ne.symm hnot.2), add_zero] lemma support_affDiv_subset {a b : K} (f : LineProd a b) : ((affDiv f).support : Set (shortWeierstrass a b).toAffine.Point) ⊆ f.factorSupp := by induction f with | nil => intro Q hQ rw [Finset.mem_coe, affDiv_nil, Finsupp.support_zero] at hQ exact absurd hQ (Finset.notMem_empty Q) | cons p fs ih => intro Q hQ rw [Finset.mem_coe, Finsupp.mem_support_iff, affDiv_cons, Finsupp.add_apply, Finsupp.smul_apply] at hQ by_cases h1 : p.2 • elemAffDiv p.1 Q ≠ 0 · have h1' : elemAffDiv p.1 Q ≠ 0 := fun h0 => h1 (by rw [h0, smul_zero]) have hmem := support_elemAffDiv_subset p.1 (Finset.mem_coe.mpr (Finsupp.mem_support_iff.mpr h1')) exact ⟨p, List.mem_cons_self .., hmem⟩ · push Not at h1 have h2 : affDiv fs Q ≠ 0 := fun h0 => hQ (by rw [h1, h0, add_zero]) rcases ih (Finset.mem_coe.mpr (Finsupp.mem_support_iff.mpr h2)) with ⟨q, hq, hmem⟩ exact ⟨q, List.mem_cons_of_mem _ hq, hmem⟩ lemma evalDiv_zero {a b : K} (f : LineProd a b) : evalDiv f 0 = 1 := by simp [evalDiv] lemma evalDiv_single {a b : K} (f : LineProd a b) (Q : (shortWeierstrass a b).toAffine.Point) (n : ℤ) : evalDiv f (Finsupp.single Q n) = (f.eval Q) ^ n := by unfold evalDiv by_cases hn : n = 0 · subst hn; simp · rw [Finsupp.prod_single_index (zpow_zero _)] lemma evalDiv_add {a b : K} (f : LineProd a b) {D₁ D₂ : (shortWeierstrass a b).toAffine.Point →₀ ℤ} (h1 : ∀ Q ∈ D₁.support, Q ≠ 0 ∧ Q ∉ f.factorSupp) (h2 : ∀ Q ∈ D₂.support, Q ≠ 0 ∧ Q ∉ f.factorSupp) : evalDiv f (D₁ + D₂) = evalDiv f D₁ * evalDiv f D₂ := by classical unfold evalDiv Finsupp.prod dsimp only set U := D₁.support ∪ D₂.support have hsub12 : (D₁ + D₂).support ⊆ U := Finsupp.support_add have hsub1 : D₁.support ⊆ U := Finset.subset_union_left have hsub2 : D₂.support ⊆ U := Finset.subset_union_right rw [Finset.prod_subset hsub12 (fun Q _ hQ => by rw [Finsupp.notMem_support_iff.mp hQ, zpow_zero]), Finset.prod_subset hsub1 (fun Q _ hQ => by rw [Finsupp.notMem_support_iff.mp hQ, zpow_zero]), Finset.prod_subset hsub2 (fun Q _ hQ => by rw [Finsupp.notMem_support_iff.mp hQ, zpow_zero]), ← Finset.prod_mul_distrib] refine Finset.prod_congr rfl fun Q hQ => ?_ rw [Finsupp.add_apply] have hne : f.eval Q ≠ 0 := by rcases Finset.mem_union.mp hQ with h | h · exact eval_ne_zero f (h1 Q h).1 (h1 Q h).2 · exact eval_ne_zero f (h2 Q h).1 (h2 Q h).2 exact zpow_add₀ hne _ _ lemma evalDiv_neg {a b : K} (f : LineProd a b) {D : (shortWeierstrass a b).toAffine.Point →₀ ℤ} : evalDiv f (-D) = (evalDiv f D)⁻¹ := by unfold evalDiv Finsupp.prod dsimp only rw [Finsupp.support_neg, ← Finset.prod_inv_distrib] refine Finset.prod_congr rfl fun Q _ => by simp lemma evalDiv_sub {a b : K} (f : LineProd a b) {D₁ D₂ : (shortWeierstrass a b).toAffine.Point →₀ ℤ} (h1 : ∀ Q ∈ D₁.support, Q ≠ 0 ∧ Q ∉ f.factorSupp) (h2 : ∀ Q ∈ D₂.support, Q ≠ 0 ∧ Q ∉ f.factorSupp) : evalDiv f (D₁ - D₂) = evalDiv f D₁ / evalDiv f D₂ := by rw [sub_eq_add_neg, evalDiv_add f h1 (by simpa [Finsupp.support_neg] using h2), evalDiv_neg, div_eq_mul_inv] lemma evalDiv_smul {a b : K} (f : LineProd a b) (m : ℤ) {D : (shortWeierstrass a b).toAffine.Point →₀ ℤ} : evalDiv f (m • D) = (evalDiv f D) ^ m := by classical unfold evalDiv Finsupp.prod dsimp only rw [← Finset.prod_zpow] have hsub : (m • D).support ⊆ D.support := Finsupp.support_smul rw [Finset.prod_subset hsub (fun Q _ hQ => by rw [Finsupp.notMem_support_iff.mp hQ, zpow_zero])] refine Finset.prod_congr rfl fun Q _ => ?_ rw [Finsupp.smul_apply, smul_eq_mul, mul_comm, zpow_mul] lemma evalDiv_append {a b : K} (f g : LineProd a b) (D : (shortWeierstrass a b).toAffine.Point →₀ ℤ) : evalDiv (f ++ g) D = evalDiv f D * evalDiv g D := by unfold evalDiv Finsupp.prod dsimp only rw [← Finset.prod_mul_distrib] refine Finset.prod_congr rfl fun Q _ => ?_ rw [eval_append, mul_zpow] lemma evalDiv_inv {a b : K} (f : LineProd a b) (D : (shortWeierstrass a b).toAffine.Point →₀ ℤ) : evalDiv f.inv D = (evalDiv f D)⁻¹ := by unfold evalDiv Finsupp.prod dsimp only rw [← Finset.prod_inv_distrib] refine Finset.prod_congr rfl fun Q _ => ?_ rw [eval_inv, inv_zpow] lemma evalDiv_zpow {a b : K} (f : LineProd a b) (m : ℤ) (D : (shortWeierstrass a b).toAffine.Point →₀ ℤ) : evalDiv (f.zpow m) D = (evalDiv f D) ^ m := by unfold evalDiv Finsupp.prod dsimp only rw [← Finset.prod_zpow] refine Finset.prod_congr rfl fun Q _ => ?_ rw [eval_zpow, ← zpow_mul, mul_comm m, zpow_mul] lemma evalDiv_ne_zero {a b : K} (f : LineProd a b) {D : (shortWeierstrass a b).toAffine.Point →₀ ℤ} (hD : ∀ Q ∈ D.support, Q ≠ 0 ∧ Q ∉ f.factorSupp) : evalDiv f D ≠ 0 := by unfold evalDiv Finsupp.prod dsimp only refine Finset.prod_ne_zero_iff.mpr fun Q hQ => ?_ exact zpow_ne_zero _ (eval_ne_zero f (hD Q hQ).1 (hD Q hQ).2) lemma evalDiv_elemAffDiv {a b : K} (f : LineProd a b) (L : ElemLine a b) (hdisj : ∀ Q ∈ L.zeros, Q ∉ f.factorSupp) : evalDiv f (elemAffDiv L) = (L.zeros.map f.eval).prod := by cases L with | nonVert P₁ P₂ h₁ h₂ h12 => have hP1 : P₁ ≠ 0 ∧ P₁ ∉ f.factorSupp := ⟨h₁, hdisj P₁ (by simp [ElemLine.zeros])⟩ have hP2 : P₂ ≠ 0 ∧ P₂ ∉ f.factorSupp := ⟨h₂, hdisj P₂ (by simp [ElemLine.zeros])⟩ have hP3 : -(P₁ + P₂) ≠ 0 ∧ -(P₁ + P₂) ∉ f.factorSupp := ⟨neg_ne_zero.mpr h12, hdisj (-(P₁ + P₂)) (by simp [ElemLine.zeros])⟩ unfold elemAffDiv simp only [ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, List.prod_cons, List.prod_nil, add_zero, mul_one] have hsupp1 : ∀ Q ∈ (Finsupp.single P₁ (1 : ℤ)).support, Q ≠ 0 ∧ Q ∉ f.factorSupp := by intro Q hQ; have hQ' := Finset.mem_singleton.mp (Finsupp.support_single_subset hQ) subst hQ'; exact hP1 have hsupp2 : ∀ Q ∈ (Finsupp.single P₂ (1 : ℤ)).support, Q ≠ 0 ∧ Q ∉ f.factorSupp := by intro Q hQ; have hQ' := Finset.mem_singleton.mp (Finsupp.support_single_subset hQ) subst hQ'; exact hP2 have hsupp3 : ∀ Q ∈ (Finsupp.single (-(P₁ + P₂)) (1 : ℤ)).support, Q ≠ 0 ∧ Q ∉ f.factorSupp := by intro Q hQ; have hQ' := Finset.mem_singleton.mp (Finsupp.support_single_subset hQ) subst hQ'; exact hP3 have hsupp23 : ∀ Q ∈ (Finsupp.single P₂ (1 : ℤ) + Finsupp.single (-(P₁ + P₂)) (1 : ℤ)).support, Q ≠ 0 ∧ Q ∉ f.factorSupp := by intro Q hQ rcases Finset.mem_union.mp (Finsupp.support_add hQ) with h | h · exact hsupp2 Q h · exact hsupp3 Q h rw [evalDiv_add f hsupp1 hsupp23, evalDiv_add f hsupp2 hsupp3, evalDiv_single, evalDiv_single, evalDiv_single, zpow_one, zpow_one, zpow_one] | vert P hP => have hP1 : P ≠ 0 ∧ P ∉ f.factorSupp := ⟨hP, hdisj P (by simp [ElemLine.zeros])⟩ have hP2 : -P ≠ 0 ∧ -P ∉ f.factorSupp := ⟨neg_ne_zero.mpr hP, hdisj (-P) (by simp [ElemLine.zeros])⟩ unfold elemAffDiv simp only [ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, List.prod_cons, List.prod_nil, add_zero, mul_one] have hsupp1 : ∀ Q ∈ (Finsupp.single P (1 : ℤ)).support, Q ≠ 0 ∧ Q ∉ f.factorSupp := by intro Q hQ; have hQ' := Finset.mem_singleton.mp (Finsupp.support_single_subset hQ) subst hQ'; exact hP1 have hsupp2 : ∀ Q ∈ (Finsupp.single (-P) (1 : ℤ)).support, Q ≠ 0 ∧ Q ∉ f.factorSupp := by intro Q hQ; have hQ' := Finset.mem_singleton.mp (Finsupp.support_single_subset hQ) subst hQ'; exact hP2 rw [evalDiv_add f hsupp1 hsupp2, evalDiv_single, evalDiv_single, zpow_one, zpow_one] /-- **FULL WEIL RECIPROCITY FOR LINE-PRODUCT FUNCTIONS**: For ANY two line-product functions `f, g : LineProd a b` with disjoint factor-supports, `f(div_aff g) = (-1)^(degInf f * degInf g) * g(div_aff f)`! -/ theorem lineProd_weil_reciprocity {a b : K} (f g : LineProd a b) (hdisj : Disjoint f.factorSupp g.factorSupp) : evalDiv f g.affDiv = (-1 : K) ^ (f.degInf * g.degInf) * evalDiv g f.affDiv := by have hm1_ne : (-1 : K) ≠ 0 := neg_ne_zero.mpr one_ne_zero induction g generalizing f with | nil => simp only [affDiv_nil, degInf_nil, mul_zero, zpow_zero, one_mul, evalDiv_zero] unfold evalDiv Finsupp.prod dsimp only exact (Finset.prod_eq_one fun Q _ => by rw [eval_nil, one_zpow]).symm | cons q gs ih => have hdisj_q : ∀ Q ∈ q.1.zeros, Q ∉ factorSupp f := by intro Q hQ hQf exact Set.disjoint_left.mp hdisj hQf ⟨q, List.mem_cons_self .., hQ⟩ have hdisj_gs : Disjoint (factorSupp f) (factorSupp gs) := by rw [Set.disjoint_left] intro Q hQf ⟨r, hr, hQr⟩ exact Set.disjoint_left.mp hdisj hQf ⟨r, List.mem_cons_of_mem _ hr, hQr⟩ have hsupp_q : ∀ Q ∈ (q.2 • elemAffDiv q.1).support, Q ≠ 0 ∧ Q ∉ factorSupp f := by intro Q hQ have hQ' : Q ∈ (elemAffDiv q.1).support := Finsupp.support_smul hQ have hmem := support_elemAffDiv_subset q.1 (Finset.mem_coe.mpr hQ') exact ⟨q.1.zeros_ne_zero hmem, hdisj_q Q hmem⟩ have hsupp_gs : ∀ Q ∈ (affDiv gs).support, Q ≠ 0 ∧ Q ∉ factorSupp f := by intro Q hQ have hmem := support_affDiv_subset gs (Finset.mem_coe.mpr hQ) exact ⟨factorSupp_ne_zero gs hmem, Set.disjoint_right.mp hdisj_gs hmem⟩ rw [affDiv_cons, evalDiv_add f hsupp_q hsupp_gs, evalDiv_smul f q.2, evalDiv_elemAffDiv f q.1 hdisj_q, ih f hdisj_gs] have hg_split : evalDiv (q :: gs) (affDiv f) = evalDiv [q] (affDiv f) * evalDiv gs (affDiv f) := evalDiv_append [q] gs (affDiv f) rw [hg_split] have hsingle : ((q.1.zeros.map (eval f)).prod) ^ q.2 = (-1 : K) ^ (degInf f * (q.2 * q.1.degInf)) * evalDiv [q] (affDiv f) := by clear ih hdisj_gs hsupp_gs hg_split induction f with | nil => simp only [degInf_nil, zero_mul, zpow_zero, one_mul, affDiv_nil, evalDiv_zero] have : (q.1.zeros.map (eval ([] : LineProd a b))).prod = 1 := List.prod_eq_one (by intro x hx; rcases List.mem_map.mp hx with ⟨_, _, rfl⟩; rfl) rw [this, one_zpow] | cons p fs ihf => have hdisj_fs : ∀ Q ∈ q.1.zeros, Q ∉ factorSupp fs := by intro Q hQ ⟨r, hr, hQr⟩ exact hdisj_q Q hQ ⟨r, List.mem_cons_of_mem _ hr, hQr⟩ have hdisj_p : ∀ P ∈ p.1.zeros, P ∉ factorSupp ([q] : LineProd a b) := by intro P hP ⟨r, hr, hPr⟩ simp only [List.mem_singleton] at hr subst hr exact hdisj_q P hPr ⟨p, List.mem_cons_self .., hP⟩ have hdisj_fs' : ∀ P ∈ (affDiv fs).support, P ≠ 0 ∧ P ∉ factorSupp ([q] : LineProd a b) := by intro P hP have hmem := support_affDiv_subset fs (Finset.mem_coe.mpr hP) refine ⟨factorSupp_ne_zero fs hmem, ?_⟩ rintro ⟨r, hr, hPr⟩ simp only [List.mem_singleton] at hr subst hr exact hdisj_fs P hPr hmem have hsupp_p : ∀ P ∈ (p.2 • elemAffDiv p.1).support, P ≠ 0 ∧ P ∉ factorSupp ([q] : LineProd a b) := by intro P hP have hP' := Finsupp.support_smul hP have hmem := support_elemAffDiv_subset p.1 (Finset.mem_coe.mpr hP') exact ⟨p.1.zeros_ne_zero hmem, hdisj_p P hmem⟩ have hmap_mul : (q.1.zeros.map (eval (p :: fs))).prod = ((q.1.zeros.map p.1.eval).prod) ^ p.2 * (q.1.zeros.map (eval fs)).prod := by clear ihf hdisj_fs hdisj_p hdisj_fs' hsupp_p hdisj_q hdisj induction q.1.zeros with | nil => simp | cons x xs ihx => simp only [List.map_cons, List.prod_cons, eval_cons, mul_zpow] rw [ihx]; ring have hq_elem : evalDiv [q] (elemAffDiv p.1) = ((p.1.zeros.map q.1.eval).prod) ^ q.2 := by rw [evalDiv_elemAffDiv [q] p.1 hdisj_p] clear ihf hdisj_fs hdisj_p hdisj_fs' hsupp_p hdisj_q hdisj hmap_mul induction p.1.zeros with | nil => simp | cons x xs ihx => simp only [List.map_cons, List.prod_cons, eval_cons, eval_nil, mul_one, mul_zpow] rw [ihx] rw [hmap_mul, mul_zpow, ihf (by rw [Set.disjoint_left] intro Q hQfs hQg rcases hQfs with ⟨r, hr, hQr⟩ exact Set.disjoint_left.mp hdisj ⟨r, List.mem_cons_of_mem _ hr, hQr⟩ hQg) hdisj_fs (fun Q hQ => ⟨(hsupp_q Q hQ).1, fun ⟨r, hr, hQr⟩ => (hsupp_q Q hQ).2 ⟨r, List.mem_cons_of_mem _ hr, hQr⟩⟩), affDiv_cons, evalDiv_add [q] hsupp_p hdisj_fs', evalDiv_smul [q] p.2, hq_elem, degInf_cons, p.1.elemLine_weil_reciprocity q.1, mul_zpow, mul_zpow] have hpow_m1 : (((-1 : K) ^ (p.1.degInf * q.1.degInf)) ^ p.2) ^ q.2 * (-1 : K) ^ (degInf fs * (q.2 * q.1.degInf)) = (-1 : K) ^ ((p.2 * p.1.degInf + degInf fs) * (q.2 * q.1.degInf)) := by rw [← zpow_mul, ← zpow_mul, ← zpow_add₀ hm1_ne] congr 1; ring have hpow_comm : (((p.1.zeros.map q.1.eval).prod) ^ p.2) ^ q.2 = (((p.1.zeros.map q.1.eval).prod) ^ q.2) ^ p.2 := by rw [← zpow_mul, ← zpow_mul, mul_comm] rw [hpow_comm] linear_combination ((((p.1.zeros.map q.1.eval).prod) ^ q.2) ^ p.2 * evalDiv [q] (affDiv fs)) * hpow_m1 rw [hsingle, degInf_cons] have hpow_g : (-1 : K) ^ (degInf f * (q.2 * q.1.degInf)) * (-1 : K) ^ (degInf f * degInf gs) = (-1 : K) ^ (degInf f * (q.2 * q.1.degInf + degInf gs)) := by rw [← zpow_add₀ hm1_ne]; congr 1; ring linear_combination (evalDiv [q] (affDiv f) * evalDiv gs (affDiv f)) * hpow_g /-- **Degree-Zero Weil Reciprocity Corollary**: Whenever `f.degInf = 0` or `g.degInf = 0`, `f(div_aff g) = g(div_aff f)` with NO sign factor! -/ theorem lineProd_weil_reciprocity_degZero {a b : K} (f g : LineProd a b) (hdisj : Disjoint f.factorSupp g.factorSupp) (h0 : f.degInf = 0 ∨ g.degInf = 0) : evalDiv f g.affDiv = evalDiv g f.affDiv := by rw [lineProd_weil_reciprocity f g hdisj] rcases h0 with h | h <;> rw [h] <;> simp /-! ### Section 2.2: Divisor Uniqueness via Coordinate-Ring Ideal Factorization -/ omit [DecidableEq K] in /-- Every unit of `W.CoordinateRing` is a nonzero constant in `K` (via `degree_norm_smul_basis`). -/ lemma isUnit_coordinateRing_eq_C {a b : K} (u : (shortWeierstrass a b).toAffine.CoordinateRing) (hu : IsUnit u) : ∃ c : K, c ≠ 0 ∧ u = algebraMap K (shortWeierstrass a b).toAffine.CoordinateRing c := by rcases WeierstrassCurve.Affine.CoordinateRing.exists_smul_basis_eq u with ⟨p, q, rfl⟩ have hdeg0 : (Algebra.norm K[X] _).degree = 0 := degree_eq_zero_of_isUnit (hu.map (Algebra.norm K[X])) rw [WeierstrassCurve.Affine.CoordinateRing.degree_norm_smul_basis] at hdeg0 have hq0 : q = 0 := by by_contra hqne have hq_nonbot : q.degree ≠ ⊥ := mt degree_eq_bot.mp hqne lift q.degree to ℕ using hq_nonbot with dq have hge3 : ((3 : ℕ) : WithBot ℕ) ≤ 2 • (dq : WithBot ℕ) + 3 := by rw [two_nsmul]; norm_cast; omega have hle0 : 2 • (dq : WithBot ℕ) + 3 ≤ 0 := hdeg0 ▸ le_max_right _ _ have : ((3 : ℕ) : WithBot ℕ) ≤ ((0 : ℕ) : WithBot ℕ) := hge3.trans hle0 exact absurd (WithBot.coe_le_coe.mp this) (by omega) subst hq0 have hp_le : 2 • p.degree ≤ 0 := hdeg0 ▸ le_max_left _ _ have hp_ne : p ≠ 0 := by intro h0; subst h0 simp only [zero_smul, add_zero] at hu exact not_isUnit_zero hu have hp_deg0 : p.degree = 0 := by lift p.degree to ℕ using (mt degree_eq_bot.mp hp_ne) with dp have hdp0 : dp = 0 := by have h1 : ((dp + dp : ℕ) : WithBot ℕ) ≤ ((0 : ℕ) : WithBot ℕ) := by change (dp : WithBot ℕ) + (dp : WithBot ℕ) ≤ 0 rw [← two_nsmul]; exact hp_le have h2 : dp + dp ≤ 0 := WithBot.coe_le_coe.mp h1 omega subst hdp0; rfl set c := p.coeff 0 have hpC : p = C c := Polynomial.eq_C_of_degree_eq_zero hp_deg0 refine ⟨c, fun h0 => hp_ne (by rw [hpC, h0, map_zero]), ?_⟩ rw [zero_smul, add_zero, hpC, Algebra.smul_def, mul_one] rfl /-- Evaluation ring homomorphism `W.CoordinateRing →+* K` at an affine point `Q = (x, y)`. -/ noncomputable def evalCoordRing {a b : K} {x y : K} (h : (shortWeierstrass a b).toAffine.Nonsingular x y) : (shortWeierstrass a b).toAffine.CoordinateRing →+* K := AdjoinRoot.lift (Polynomial.evalRingHom x) y <| by have heq := (shortWeierstrass_nonsingular_iff a b x y).mp h |>.1 unfold WeierstrassCurve.Affine.polynomial simp only [shortWeierstrass, map_add, map_mul, map_pow, map_zero, eval₂_sub, eval₂_add, eval₂_mul, eval₂_pow, eval₂_C, eval₂_X, eval₂_zero, Polynomial.coe_evalRingHom, eval_X, eval_C] change y ^ 2 + (0 * x + 0) * y - (x ^ 3 + 0 * x ^ 2 + a * x + b) = 0 linear_combination heq omit [DecidableEq K] in lemma evalCoordRing_algebraMap {a b x y : K} (h : (shortWeierstrass a b).toAffine.Nonsingular x y) (c : K) : evalCoordRing h (algebraMap K (shortWeierstrass a b).toAffine.CoordinateRing c) = c := by change AdjoinRoot.lift (Polynomial.evalRingHom x) y _ (AdjoinRoot.mk _ (C (C c))) = c simp /-- Embed an elementary line function into `W.CoordinateRing`. -/ noncomputable def elemToCoordRing {a b : K} : ElemLine a b → (shortWeierstrass a b).toAffine.CoordinateRing | .nonVert P₁ P₂ _ _ _ => WeierstrassCurve.Affine.CoordinateRing.YClass (shortWeierstrass a b).toAffine (WeierstrassCurve.Affine.linePolynomial (ptX P₁) (ptY P₁) (ElemLine.lineSlope P₁ P₂)) | .vert P _ => WeierstrassCurve.Affine.CoordinateRing.XClass (shortWeierstrass a b).toAffine (ptX P) lemma elemToCoordRing_ne_zero {a b : K} (L : ElemLine a b) : elemToCoordRing L ≠ 0 := by cases L with | nonVert P₁ P₂ _ _ _ => exact WeierstrassCurve.Affine.CoordinateRing.YClass_ne_zero _ | vert P _ => exact WeierstrassCurve.Affine.CoordinateRing.XClass_ne_zero _ lemma evalCoordRing_elemToCoordRing {a b x y : K} (h : (shortWeierstrass a b).toAffine.Nonsingular x y) (L : ElemLine a b) : evalCoordRing h (elemToCoordRing L) = L.eval (.some x y h) := by cases L with | nonVert P₁ P₂ h₁ h₂ h12 => unfold evalCoordRing elemToCoordRing WeierstrassCurve.Affine.CoordinateRing.YClass WeierstrassCurve.Affine.linePolynomial ElemLine.eval ElemLine.lineIntercept simp only [AdjoinRoot.lift_mk, eval₂_sub, eval₂_X, eval₂_C, Polynomial.coe_evalRingHom, eval_add, eval_mul, eval_sub, eval_C, eval_X] change y - (ElemLine.lineSlope P₁ P₂ * (x - ptX P₁) + ptY P₁) = y - (ElemLine.lineSlope P₁ P₂ * x + (ptY P₁ - ElemLine.lineSlope P₁ P₂ * ptX P₁)) ring | vert P hP => unfold evalCoordRing elemToCoordRing WeierstrassCurve.Affine.CoordinateRing.XClass ElemLine.eval simp only [AdjoinRoot.lift_mk, eval₂_C, Polynomial.coe_evalRingHom, eval_sub, eval_X, eval_C] rfl /-- Associate each nonsingular point `P` with its invertible fractional ideal `XYIdeal'(P)`. -/ noncomputable def pointIdeal {a b : K} : (shortWeierstrass a b).toAffine.Point → (FractionalIdeal (shortWeierstrass a b).toAffine.CoordinateRing⁰ (shortWeierstrass a b).toAffine.FunctionField)ˣ | .zero => 1 | .some _ _ h => WeierstrassCurve.Affine.CoordinateRing.XYIdeal' h /-- Helper for abstract `W : WeierstrassCurve.Affine K` avoiding `shortWeierstrass` unfolding: `YIdeal(line(P₁, P₂)) = XYIdeal(P₁) * XYIdeal(P₂) * XYIdeal(-(P₁+P₂))` as fractional ideals! -/ private lemma YIdeal_eq_mul_XYIdeal_aux (W : WeierstrassCurve.Affine K) {x₁ y₁ x₂ y₂ : K} (hn₁ : W.Nonsingular x₁ y₁) (hn₂ : W.Nonsingular x₂ y₂) (hxy : ¬ (x₁ = x₂ ∧ y₁ = W.negY x₂ y₂)) : (WeierstrassCurve.Affine.CoordinateRing.YIdeal W (WeierstrassCurve.Affine.linePolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂)) : FractionalIdeal W.CoordinateRing⁰ W.FunctionField) = ↑(WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₁ (C y₁) * (WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₂ (C y₂) * WeierstrassCurve.Affine.CoordinateRing.XYIdeal W (W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂)) (C (W.negY (W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂)) (W.addY x₁ x₂ y₁ (W.slope x₁ x₂ y₁ y₂)))))) := by set x₃ := W.addX x₁ x₂ (W.slope x₁ x₂ y₁ y₂) set y₃ := W.addY x₁ x₂ y₁ (W.slope x₁ x₂ y₁ y₂) have hn₃ : W.Nonsingular x₃ y₃ := W.nonsingular_add hn₁ hn₂ hxy have hmul := WeierstrassCurve.Affine.CoordinateRing.XYIdeal_mul_XYIdeal hn₁.1 hn₂.1 hxy have hneg_mul := WeierstrassCurve.Affine.CoordinateRing.XYIdeal_neg_mul hn₃ have hX_ne : algebraMap W.CoordinateRing W.FunctionField (WeierstrassCurve.Affine.CoordinateRing.XClass W x₃) ≠ 0 := (map_ne_zero_iff _ (IsFractionRing.injective W.CoordinateRing W.FunctionField)).mpr (WeierstrassCurve.Affine.CoordinateRing.XClass_ne_zero x₃) have hideal_eq : WeierstrassCurve.Affine.CoordinateRing.XIdeal W x₃ * WeierstrassCurve.Affine.CoordinateRing.YIdeal W (WeierstrassCurve.Affine.linePolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂)) = WeierstrassCurve.Affine.CoordinateRing.XIdeal W x₃ * (WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₁ (C y₁) * (WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₂ (C y₂) * WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₃ (C (W.negY x₃ y₃)))) := by calc WeierstrassCurve.Affine.CoordinateRing.XIdeal W x₃ * WeierstrassCurve.Affine.CoordinateRing.YIdeal W (WeierstrassCurve.Affine.linePolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂)) = (WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₃ (C (W.negY x₃ y₃)) * WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₃ (C y₃)) * WeierstrassCurve.Affine.CoordinateRing.YIdeal W (WeierstrassCurve.Affine.linePolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂)) := by rw [hneg_mul] _ = WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₃ (C (W.negY x₃ y₃)) * (WeierstrassCurve.Affine.CoordinateRing.YIdeal W (WeierstrassCurve.Affine.linePolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂)) * WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₃ (C y₃)) := by rw [mul_assoc, mul_comm (WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₃ (C y₃))] _ = WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₃ (C (W.negY x₃ y₃)) * (WeierstrassCurve.Affine.CoordinateRing.XIdeal W x₃ * (WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₁ (C y₁) * WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₂ (C y₂))) := by rw [← hmul] _ = WeierstrassCurve.Affine.CoordinateRing.XIdeal W x₃ * (WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₁ (C y₁) * (WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₂ (C y₂) * WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₃ (C (W.negY x₃ y₃)))) := by rw [mul_left_comm, mul_comm (WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₃ (C (W.negY x₃ y₃))), mul_assoc] have hboth : (WeierstrassCurve.Affine.CoordinateRing.XIdeal W x₃ : FractionalIdeal W.CoordinateRing⁰ W.FunctionField) * (WeierstrassCurve.Affine.CoordinateRing.YIdeal W (WeierstrassCurve.Affine.linePolynomial x₁ y₁ (W.slope x₁ x₂ y₁ y₂)) : FractionalIdeal W.CoordinateRing⁰ W.FunctionField) = (WeierstrassCurve.Affine.CoordinateRing.XIdeal W x₃ : FractionalIdeal W.CoordinateRing⁰ W.FunctionField) * ↑(WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₁ (C y₁) * (WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₂ (C y₂) * WeierstrassCurve.Affine.CoordinateRing.XYIdeal W x₃ (C (W.negY x₃ y₃)))) := by rw [← FractionalIdeal.coeIdeal_mul, ← FractionalIdeal.coeIdeal_mul, hideal_eq] have hX_eq : (WeierstrassCurve.Affine.CoordinateRing.XIdeal W x₃ : FractionalIdeal W.CoordinateRing⁰ W.FunctionField) = FractionalIdeal.spanSingleton W.CoordinateRing⁰ (algebraMap W.CoordinateRing W.FunctionField (WeierstrassCurve.Affine.CoordinateRing.XClass W x₃)) := by unfold WeierstrassCurve.Affine.CoordinateRing.XIdeal exact FractionalIdeal.coeIdeal_span_singleton _ rw [hX_eq] at hboth have hcancel := congr_arg (fun I : FractionalIdeal W.CoordinateRing⁰ W.FunctionField => FractionalIdeal.spanSingleton W.CoordinateRing⁰ (algebraMap W.CoordinateRing W.FunctionField (WeierstrassCurve.Affine.CoordinateRing.XClass W x₃))⁻¹ * I) hboth simpa only [← mul_assoc, FractionalIdeal.spanSingleton_mul_spanSingleton, inv_mul_cancel₀ hX_ne, FractionalIdeal.spanSingleton_one, one_mul] using hcancel /-- Principal fractional ideal generated by `elemToCoordRing L` equals `∏_{P ∈ L.zeros} pointIdeal P`! -/ lemma elemToCoordRing_ideal {a b : K} (L : ElemLine a b) : (FractionalIdeal.spanSingleton (shortWeierstrass a b).toAffine.CoordinateRing⁰ (algebraMap _ (shortWeierstrass a b).toAffine.FunctionField (elemToCoordRing L)) : FractionalIdeal (shortWeierstrass a b).toAffine.CoordinateRing⁰ (shortWeierstrass a b).toAffine.FunctionField) = ((L.zeros.map pointIdeal).prod : FractionalIdeal _ _) := by cases L with | vert P hP => obtain ⟨x, y, hn, rfl⟩ := pt_eq_some_of_ne_zero hP have hneg : -(WeierstrassCurve.Affine.Point.some x y hn) = .some x ((shortWeierstrass a b).toAffine.negY x y) (((shortWeierstrass a b).toAffine.nonsingular_neg x y).mpr hn) := WeierstrassCurve.Affine.Point.neg_some hn simp only [ElemLine.zeros, hneg, List.map_cons, List.map_nil, List.prod_cons, List.prod_nil, mul_one, pointIdeal, Units.val_mul, WeierstrassCurve.Affine.CoordinateRing.XYIdeal'_eq] rw [← FractionalIdeal.coeIdeal_mul, mul_comm, WeierstrassCurve.Affine.CoordinateRing.XYIdeal_neg_mul hn] unfold elemToCoordRing WeierstrassCurve.Affine.CoordinateRing.XIdeal rw [FractionalIdeal.coeIdeal_span_singleton] rfl | nonVert P₁ P₂ h₁ h₂ h12 => obtain ⟨x₁, y₁, hn₁, rfl⟩ := pt_eq_some_of_ne_zero h₁ obtain ⟨x₂, y₂, hn₂, rfl⟩ := pt_eq_some_of_ne_zero h₂ have hxy : ¬ (x₁ = x₂ ∧ y₁ = (shortWeierstrass a b).toAffine.negY x₂ y₂) := by rintro ⟨rfl, hy⟩; exact h12 (WeierstrassCurve.Affine.Point.add_of_Y_eq rfl hy) have hadd : WeierstrassCurve.Affine.Point.some x₁ y₁ hn₁ + .some x₂ y₂ hn₂ = .some _ _ ((shortWeierstrass a b).toAffine.nonsingular_add hn₁ hn₂ hxy) := WeierstrassCurve.Affine.Point.add_some hxy have hneg3 : -(WeierstrassCurve.Affine.Point.some x₁ y₁ hn₁ + .some x₂ y₂ hn₂) = .some _ _ (((shortWeierstrass a b).toAffine.nonsingular_neg _ _).mpr ((shortWeierstrass a b).toAffine.nonsingular_add hn₁ hn₂ hxy)) := by rw [hadd, WeierstrassCurve.Affine.Point.neg_some] simp only [ElemLine.zeros, hneg3, List.map_cons, List.map_nil, List.prod_cons, List.prod_nil, mul_one, pointIdeal, Units.val_mul, WeierstrassCurve.Affine.CoordinateRing.XYIdeal'_eq] rw [← FractionalIdeal.coeIdeal_mul, ← FractionalIdeal.coeIdeal_mul] have hlhs : FractionalIdeal.spanSingleton (shortWeierstrass a b).toAffine.CoordinateRing⁰ (algebraMap _ (shortWeierstrass a b).toAffine.FunctionField (elemToCoordRing (ElemLine.nonVert _ _ h₁ h₂ h12))) = (WeierstrassCurve.Affine.CoordinateRing.YIdeal (shortWeierstrass a b).toAffine (WeierstrassCurve.Affine.linePolynomial x₁ y₁ ((shortWeierstrass a b).toAffine.slope x₁ x₂ y₁ y₂)) : FractionalIdeal (shortWeierstrass a b).toAffine.CoordinateRing⁰ (shortWeierstrass a b).toAffine.FunctionField) := by unfold elemToCoordRing WeierstrassCurve.Affine.CoordinateRing.YIdeal ElemLine.lineSlope rw [FractionalIdeal.coeIdeal_span_singleton] rfl rw [hlhs] exact YIdeal_eq_mul_XYIdeal_aux (shortWeierstrass a b).toAffine hn₁ hn₂ hxy /-- Embed a `LineProd` into the function field `W.FunctionField`. -/ noncomputable def toFuncField {a b : K} (f : LineProd a b) : (shortWeierstrass a b).toAffine.FunctionField := (f.map fun p => (algebraMap (shortWeierstrass a b).toAffine.CoordinateRing (shortWeierstrass a b).toAffine.FunctionField (elemToCoordRing p.1)) ^ p.2).prod /-- **Divisor-Zero Constancy Theorem**: If `f : LineProd a b` has `f.affDiv = 0`, then there exists a nonzero scalar `c ∈ K×` such that `f.eval Q = c` for EVERY affine point `Q ∉ f.factorSupp`! -/ theorem exists_const_of_affDiv_eq_zero {a b : K} (f : LineProd a b) (h0 : f.affDiv = 0) : ∃ c : K, c ≠ 0 ∧ ∀ Q : (shortWeierstrass a b).toAffine.Point, Q ≠ 0 → Q ∉ f.factorSupp → f.eval Q = c := by classical set W := (shortWeierstrass a b).toAffine -- Write f as ratio of two products of coordinate-ring elements: N_f / D_f let posList := f.filter (fun p => 0 ≤ p.2) let negList := f.filter (fun p => p.2 < 0) let numCR : W.CoordinateRing := (f.map fun p => if 0 ≤ p.2 then (elemToCoordRing p.1) ^ p.2.toNat else 1).prod let denCR : W.CoordinateRing := (f.map fun p => if p.2 < 0 then (elemToCoordRing p.1) ^ (-p.2).toNat else 1).prod have hnum_ne : numCR ≠ 0 := by refine List.prod_ne_zero ?_ intro h0 rcases List.mem_map.mp h0 with ⟨p, _, hp⟩ split_ifs at hp · exact pow_ne_zero _ (elemToCoordRing_ne_zero p.1) hp · exact one_ne_zero hp have hden_ne : denCR ≠ 0 := by refine List.prod_ne_zero ?_ intro h0 rcases List.mem_map.mp h0 with ⟨p, _, hp⟩ split_ifs at hp · exact pow_ne_zero _ (elemToCoordRing_ne_zero p.1) hp · exact one_ne_zero hp -- Fractional ideal of toFuncField f = ∏_{P} (pointIdeal P)^(affDiv f P) = 1! have hspan_toFF : FractionalIdeal.spanSingleton W.CoordinateRing⁰ (toFuncField f) = ((f.affDiv.prod fun P n => (pointIdeal P) ^ n : (FractionalIdeal W.CoordinateRing⁰ W.FunctionField)ˣ) : FractionalIdeal W.CoordinateRing⁰ W.FunctionField) := by clear h0 numCR denCR hnum_ne hden_ne posList negList induction f with | nil => simp [toFuncField, affDiv_nil] | cons p fs ih => simp only [toFuncField, List.map_cons, List.prod_cons, ← FractionalIdeal.spanSingleton_mul_spanSingleton, affDiv_cons] have hfactor : FractionalIdeal.spanSingleton W.CoordinateRing⁰ ((algebraMap W.CoordinateRing W.FunctionField (elemToCoordRing p.1)) ^ p.2) = (((p.2 • elemAffDiv p.1).prod fun P n => (pointIdeal P) ^ n : (FractionalIdeal W.CoordinateRing⁰ W.FunctionField)ˣ) : FractionalIdeal W.CoordinateRing⁰ W.FunctionField) := by have h1 := elemToCoordRing_ideal p.1 have hsp_zpow : FractionalIdeal.spanSingleton W.CoordinateRing⁰ ((algebraMap W.CoordinateRing W.FunctionField (elemToCoordRing p.1)) ^ p.2) = (((p.1.zeros.map pointIdeal).prod) ^ p.2 : (FractionalIdeal W.CoordinateRing⁰ W.FunctionField)ˣ) := by set x := algebraMap W.CoordinateRing W.FunctionField (elemToCoordRing p.1) have hne : x ≠ 0 := (map_ne_zero_iff _ (IsFractionRing.injective W.CoordinateRing W.FunctionField)).mpr (elemToCoordRing_ne_zero p.1) let ux : (FractionalIdeal W.CoordinateRing⁰ W.FunctionField)ˣ := Units.mkOfMulEqOne (FractionalIdeal.spanSingleton W.CoordinateRing⁰ x) (FractionalIdeal.spanSingleton W.CoordinateRing⁰ x⁻¹) (by rw [FractionalIdeal.spanSingleton_mul_spanSingleton, mul_inv_cancel₀ hne, FractionalIdeal.spanSingleton_one]) have hu_eq : ux = (p.1.zeros.map pointIdeal).prod := Units.ext h1 have hpow := congr_arg (fun u : (FractionalIdeal W.CoordinateRing⁰ W.FunctionField)ˣ => ((u ^ p.2 : (FractionalIdeal W.CoordinateRing⁰ W.FunctionField)ˣ) : FractionalIdeal W.CoordinateRing⁰ W.FunctionField)) hu_eq rw [← hpow] have hpos : ∀ m : ℕ, FractionalIdeal.spanSingleton W.CoordinateRing⁰ (x ^ m) = ((ux ^ m : (FractionalIdeal _ _)ˣ) : FractionalIdeal _ _) := by intro m; induction m with | zero => simp [FractionalIdeal.spanSingleton_one] | succ k ihk => rw [pow_succ, pow_succ, Units.val_mul, ← FractionalIdeal.spanSingleton_mul_spanSingleton, ihk] rfl have hneg : ∀ m : ℕ, FractionalIdeal.spanSingleton W.CoordinateRing⁰ (x⁻¹ ^ m) = ((ux⁻¹ ^ m : (FractionalIdeal _ _)ˣ) : FractionalIdeal _ _) := by intro m; induction m with | zero => simp [FractionalIdeal.spanSingleton_one] | succ k ihk => rw [pow_succ, pow_succ, Units.val_mul, ← FractionalIdeal.spanSingleton_mul_spanSingleton, ihk] rfl cases p.2 with | ofNat m => simpa using hpos m | negSucc m => simp only [zpow_negSucc] rw [← inv_pow, ← inv_pow] exact hneg (m + 1) rw [hsp_zpow] congr 1 have hprod_smul : ((p.2 • elemAffDiv p.1).prod fun P n => (pointIdeal P) ^ n) = (elemAffDiv p.1).prod (fun P n => (pointIdeal P) ^ n) ^ p.2 := by unfold Finsupp.prod dsimp only rw [← Finset.prod_zpow] rw [Finset.prod_subset Finsupp.support_smul (fun Q _ hQ => by rw [Finsupp.notMem_support_iff.mp hQ, zpow_zero])] refine Finset.prod_congr rfl fun Q _ => by rw [Finsupp.smul_apply, smul_eq_mul, mul_comm, zpow_mul] rw [hprod_smul] congr 1 cases p.1 with | vert P hP => unfold elemAffDiv simp only [ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, List.prod_cons, List.prod_nil, add_zero, mul_one] rw [Finsupp.prod_add_index' (fun _ => zpow_zero _) (fun _ _ _ => zpow_add _ _ _), Finsupp.prod_single_index (zpow_zero _), Finsupp.prod_single_index (zpow_zero _), zpow_one, zpow_one] | nonVert P₁ P₂ h₁ h₂ h12 => unfold elemAffDiv simp only [ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, List.prod_cons, List.prod_nil, add_zero, mul_one] rw [Finsupp.prod_add_index' (fun _ => zpow_zero _) (fun _ _ _ => zpow_add _ _ _), Finsupp.prod_add_index' (fun _ => zpow_zero _) (fun _ _ _ => zpow_add _ _ _), Finsupp.prod_single_index (zpow_zero _), Finsupp.prod_single_index (zpow_zero _), Finsupp.prod_single_index (zpow_zero _), zpow_one, zpow_one, zpow_one] change FractionalIdeal.spanSingleton W.CoordinateRing⁰ ((algebraMap W.CoordinateRing W.FunctionField (elemToCoordRing p.1)) ^ p.2) * FractionalIdeal.spanSingleton W.CoordinateRing⁰ (toFuncField fs) = _ rw [hfactor, ih, ← Units.val_mul] congr 1 rw [Finsupp.prod_add_index' (fun _ => zpow_zero _) (fun _ _ _ => zpow_add _ _ _)] -- Also toFuncField f = algebraMap numCR / algebraMap denCR! have hff_ratio : toFuncField f = algebraMap W.CoordinateRing W.FunctionField numCR / algebraMap W.CoordinateRing W.FunctionField denCR := by clear hspan_toFF h0 hnum_ne hden_ne posList negList induction f with | nil => simp [toFuncField, numCR, denCR] | cons p fs ih => simp only [toFuncField, numCR, denCR, List.map_cons, List.prod_cons, map_mul] rw [mul_div_mul_comm] change _ * toFuncField fs = _ rw [ih] congr 1 by_cases hge : 0 ≤ p.2 · have hnotlt : ¬ p.2 < 0 := not_lt.mpr hge rw [if_pos hge, if_neg hnotlt, map_pow, map_one, div_one, ← zpow_natCast, Int.toNat_of_nonneg hge] · have hlt : p.2 < 0 := not_le.mp hge rw [if_neg hge, if_pos hlt, map_one, map_pow, one_div, ← zpow_natCast, Int.toNat_of_nonneg (by omega), zpow_neg, inv_inv] -- Since f.affDiv = 0, spanSingleton (toFuncField f) = 1, hence numCR and denCR generate the same ideal! rw [h0, Finsupp.prod_zero_index, Units.val_one, hff_ratio] at hspan_toFF have hden_ff_ne : algebraMap W.CoordinateRing W.FunctionField denCR ≠ 0 := (map_ne_zero_iff _ (IsFractionRing.injective W.CoordinateRing W.FunctionField)).mpr hden_ne have hnum_eq_den_span : FractionalIdeal.spanSingleton W.CoordinateRing⁰ (algebraMap W.CoordinateRing W.FunctionField numCR) = FractionalIdeal.spanSingleton W.CoordinateRing⁰ (algebraMap W.CoordinateRing W.FunctionField denCR) := by calc FractionalIdeal.spanSingleton W.CoordinateRing⁰ (algebraMap W.CoordinateRing W.FunctionField numCR) = FractionalIdeal.spanSingleton W.CoordinateRing⁰ ((algebraMap W.CoordinateRing W.FunctionField numCR / algebraMap W.CoordinateRing W.FunctionField denCR) * algebraMap W.CoordinateRing W.FunctionField denCR) := by rw [div_mul_cancel₀ _ hden_ff_ne] _ = FractionalIdeal.spanSingleton W.CoordinateRing⁰ (algebraMap W.CoordinateRing W.FunctionField numCR / algebraMap W.CoordinateRing W.FunctionField denCR) * FractionalIdeal.spanSingleton W.CoordinateRing⁰ (algebraMap W.CoordinateRing W.FunctionField denCR) := (FractionalIdeal.spanSingleton_mul_spanSingleton _ _).symm _ = FractionalIdeal.spanSingleton W.CoordinateRing⁰ (algebraMap W.CoordinateRing W.FunctionField denCR) := by rw [hspan_toFF, one_mul] -- Extract unit u : W.CoordinateRingˣ such that numCR = u * denCR! have hideal_eq : Ideal.span ({numCR} : Set W.CoordinateRing) = Ideal.span ({denCR} : Set W.CoordinateRing) := by apply FractionalIdeal.coeIdeal_injective (R := W.CoordinateRing) (K := W.FunctionField) dsimp only rw [FractionalIdeal.coeIdeal_span_singleton, FractionalIdeal.coeIdeal_span_singleton] exact hnum_eq_den_span have hi_mem : numCR ∈ Ideal.span ({denCR} : Set W.CoordinateRing) := by rw [← hideal_eq]; exact Ideal.subset_span rfl have hnum_dvd : denCR ∣ numCR := Ideal.mem_span_singleton.mp hi_mem have hden_dvd : numCR ∣ denCR := Ideal.mem_span_singleton.mp (by rw [hideal_eq]; exact Ideal.subset_span rfl) obtain ⟨u, hu_eq⟩ := hnum_dvd obtain ⟨v, hv_eq⟩ := hden_dvd have huv : u * v = 1 := mul_left_cancel₀ hden_ne (by calc denCR * (u * v) = (denCR * u) * v := by ring _ = numCR * v := by rw [← hu_eq] _ = denCR := hv_eq.symm _ = denCR * 1 := (mul_one _).symm) obtain ⟨c, hc0, rfl⟩ := isUnit_coordinateRing_eq_C u (isUnit_iff_exists_inv.mpr ⟨v, huv⟩) -- Evaluate numCR = denCR * algebraMap K _ c at EVERY affine Q ∉ f.factorSupp! refine ⟨c, hc0, fun Q hQ0 hQ => ?_⟩ obtain ⟨x, y, hn, rfl⟩ := pt_eq_some_of_ne_zero hQ0 have hev_ratio : f.eval (.some x y hn) = evalCoordRing hn numCR / evalCoordRing hn denCR := by clear hspan_toFF hff_ratio h0 hnum_eq_den_span hideal_eq hi_mem hu_eq hv_eq huv hnum_ne hden_ne hden_ff_ne c hc0 posList negList hQ0 hQ induction f with | nil => simp [eval, numCR, denCR] | cons p fs ih => simp only [eval_cons, numCR, denCR, List.map_cons, List.prod_cons, map_mul] rw [mul_div_mul_comm, ih] congr 1 by_cases hge : 0 ≤ p.2 · have hnotlt : ¬ p.2 < 0 := not_lt.mpr hge rw [if_pos hge, if_neg hnotlt, map_pow, map_one, div_one, evalCoordRing_elemToCoordRing, ← zpow_natCast, Int.toNat_of_nonneg hge] · have hlt : p.2 < 0 := not_le.mp hge rw [if_neg hge, if_pos hlt, map_one, map_pow, one_div, evalCoordRing_elemToCoordRing, ← zpow_natCast, Int.toNat_of_nonneg (by omega), zpow_neg, inv_inv] have hev_den_ne : evalCoordRing hn denCR ≠ 0 := by rw [map_list_prod] refine List.prod_ne_zero ?_ intro h0 rcases List.mem_map.mp h0 with ⟨w, hw, hwe⟩ rcases List.mem_map.mp hw with ⟨p, hp, rfl⟩ split_ifs at hwe · rw [map_pow, evalCoordRing_elemToCoordRing] at hwe exact pow_ne_zero _ (p.1.eval_ne_zero_of_not_mem hQ0 (fun hmem => hQ ⟨p, hp, hmem⟩)) hwe · simp at hwe rw [hev_ratio, hu_eq, map_mul, evalCoordRing_algebraMap, mul_div_cancel_left₀ c hev_den_ne] /-- **DIVISOR UNIQUENESS FOR DEGREE-ZERO EVALUATION**: If `f₁, f₂ : LineProd a b` have the SAME affine divisor `f₁.affDiv = f₂.affDiv`, then for ANY degree-0 affine divisor `D` avoiding `f₁.factorSupp ∪ f₂.factorSupp`, `evalDiv f₁ D = evalDiv f₂ D`! -/ theorem lineProd_evalDiv_eq_of_affDiv_eq {a b : K} (f₁ f₂ : LineProd a b) (hdiv : f₁.affDiv = f₂.affDiv) {D : (shortWeierstrass a b).toAffine.Point →₀ ℤ} (hdeg0 : D.sum (fun _ n => n) = 0) (hD1 : ∀ Q ∈ D.support, Q ≠ 0 ∧ Q ∉ f₁.factorSupp) (hD2 : ∀ Q ∈ D.support, Q ≠ 0 ∧ Q ∉ f₂.factorSupp) : evalDiv f₁ D = evalDiv f₂ D := by have h0 : (f₁ ++ f₂.inv).affDiv = 0 := by rw [affDiv_append, affDiv_inv, hdiv, add_neg_cancel] obtain ⟨c, hc0, hc⟩ := exists_const_of_affDiv_eq_zero (f₁ ++ f₂.inv) h0 have hratio : evalDiv (f₁ ++ f₂.inv) D = 1 := by unfold evalDiv Finsupp.prod dsimp only have hconst : ∏ Q ∈ D.support, ((f₁ ++ f₂.inv).eval Q) ^ D Q = ∏ Q ∈ D.support, c ^ D Q := by refine Finset.prod_congr rfl fun Q hQ => ?_ have hQ1 := hD1 Q hQ have hQ2 := hD2 Q hQ have hnot : Q ∉ (f₁ ++ f₂.inv).factorSupp := by rw [factorSupp_append, factorSupp_inv, Set.mem_union] rintro (h | h) · exact hQ1.2 h · exact hQ2.2 h rw [hc Q hQ1.1 hnot] have hprod_zpow : ∀ s : Finset (shortWeierstrass a b).toAffine.Point, ∏ Q ∈ s, c ^ D Q = c ^ (∑ Q ∈ s, D Q) := by classical intro s; induction s using Finset.induction_on with | empty => simp | insert a s ha ih => rw [Finset.prod_insert ha, Finset.sum_insert ha, ih, zpow_add₀ hc0] rw [hconst, hprod_zpow] change c ^ (D.sum fun _ n => n) = 1 rw [hdeg0, zpow_zero] rw [evalDiv_append, evalDiv_inv] at hratio exact eq_of_mul_inv_eq_one hratio end LineProd end LineFunctions /-! ## Section 3: Miller's Algorithm & Shifted Miller Functions -/ section MillerAndWeilPairing variable {K : Type*} [Field K] [DecidableEq K] /-- Single Miller step from `cur` to `cur + P`: its affine divisor is `(if cur = 0 then 0 else (cur)) + (if P = 0 then 0 else (P)) - (if cur + P = 0 then 0 else (cur + P))`. -/ def millerStep {a b : K} (P cur : (shortWeierstrass a b).toAffine.Point) : LineProd a b := if hP : P = 0 then [] else if hc : cur = 0 then [] else if hcp : cur + P = 0 then [(ElemLine.vert cur hc, 1)] else [(ElemLine.nonVert cur P hc hP hcp, 1), (ElemLine.vert (cur + P) hcp, -1)] lemma millerStep_affDiv {a b : K} (P cur : (shortWeierstrass a b).toAffine.Point) : (millerStep P cur).affDiv = (if cur = 0 then 0 else Finsupp.single cur (1 : ℤ)) + (if P = 0 then 0 else Finsupp.single P (1 : ℤ)) - (if cur + P = 0 then 0 else Finsupp.single (cur + P) (1 : ℤ)) := by unfold millerStep by_cases hP : P = 0 · subst hP; simp [LineProd.affDiv_nil] · rw [dif_neg hP] by_cases hc : cur = 0 · subst hc; simp [LineProd.affDiv_nil, hP] · rw [dif_neg hc] by_cases hcp : cur + P = 0 · rw [dif_pos hcp] have hcur_neg : -cur = P := neg_eq_iff_add_eq_zero.mpr hcp simp only [LineProd.affDiv_cons, LineProd.affDiv_nil, one_smul, add_zero, sub_zero, LineProd.elemAffDiv, ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, hcur_neg, if_neg hc, if_neg hP, if_pos hcp] · rw [dif_neg hcp] simp only [LineProd.affDiv_cons, LineProd.affDiv_nil, one_smul, neg_smul, add_zero, LineProd.elemAffDiv, ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, if_neg hc, if_neg hP, if_neg hcp] abel /-- Miller's loop `f_{k, P}` for `k : ℕ`: `affDiv = k • (P) - (k • P)`. -/ def millerLoop {a b : K} (P : (shortWeierstrass a b).toAffine.Point) : ℕ → LineProd a b | 0 => [] | k + 1 => millerLoop P k ++ millerStep P (k • P) lemma millerLoop_affDiv {a b : K} (P : (shortWeierstrass a b).toAffine.Point) (k : ℕ) : (millerLoop P k).affDiv = (k : ℤ) • (if P = 0 then 0 else Finsupp.single P (1 : ℤ)) - (if k • P = 0 then 0 else Finsupp.single (k • P) (1 : ℤ)) := by induction k with | zero => simp [millerLoop, LineProd.affDiv_nil] | succ k ih => simp only [millerLoop, LineProd.affDiv_append, ih, millerStep_affDiv] have hsucc : (k + 1) • P = k • P + P := succ_nsmul P k rw [hsucc, Nat.cast_add, Nat.cast_one, add_smul, one_smul] abel /-- **Miller Function `f_{m, P}`** for `P ∈ E[m]`: `affDiv(f_{m, P}) = m • (P)`. -/ def millerFunc {a b : K} (m : ℕ) (P : (shortWeierstrass a b).toAffine.Point) : LineProd a b := millerLoop P m lemma millerFunc_affDiv {a b : K} {m : ℕ} {P : (shortWeierstrass a b).toAffine.Point} (hmP : m • P = 0) : (millerFunc m P).affDiv = (m : ℤ) • (if P = 0 then 0 else Finsupp.single P (1 : ℤ)) := by unfold millerFunc rw [millerLoop_affDiv, if_pos hmP, sub_zero] /-- **Shifted Miller Function `f_{m, P, R}`** with degree-0 affine divisor `m • ((P + R) - (R))`! -/ def shiftedMillerFunc {a b : K} (m : ℕ) (P R : (shortWeierstrass a b).toAffine.Point) (hR : R ≠ 0) (hPR : P + R ≠ 0) : LineProd a b := if hP : P = 0 then [] else millerFunc m P ++ [(ElemLine.vert (P + R) hPR, (m : ℤ)), (ElemLine.nonVert P R hP hR hPR, -(m : ℤ))] /-- The degree-0 shifted divisor `D_{P, R} = (P + R) - (R)`. -/ noncomputable def shiftedDiv {a b : K} (P R : (shortWeierstrass a b).toAffine.Point) : (shortWeierstrass a b).toAffine.Point →₀ ℤ := Finsupp.single (P + R) (1 : ℤ) - Finsupp.single R (1 : ℤ) lemma shiftedDiv_degZero {a b : K} (P R : (shortWeierstrass a b).toAffine.Point) : (shiftedDiv P R).sum (fun _ n => n) = 0 := by unfold shiftedDiv rw [sub_eq_add_neg, Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl), Finsupp.sum_neg_index (fun _ => rfl), Finsupp.sum_single_index rfl, Finsupp.sum_single_index rfl] ring lemma shiftedMillerFunc_affDiv {a b : K} {m : ℕ} {P R : (shortWeierstrass a b).toAffine.Point} (hmP : m • P = 0) (hR : R ≠ 0) (hPR : P + R ≠ 0) : (shiftedMillerFunc m P R hR hPR).affDiv = (m : ℤ) • shiftedDiv P R := by unfold shiftedMillerFunc shiftedDiv split_ifs with hP · subst hP; simp [LineProd.affDiv_nil] · rw [LineProd.affDiv_append, millerFunc_affDiv hmP, if_neg hP, LineProd.affDiv_cons, LineProd.affDiv_cons, LineProd.affDiv_nil, add_zero] simp only [LineProd.elemAffDiv, ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, add_zero, smul_add, neg_smul, smul_sub] abel lemma degInf_eq_sum_affDiv {a b : K} (f : LineProd a b) : f.degInf = f.affDiv.sum (fun _ n => n) := by induction f with | nil => simp [LineProd.degInf_nil, LineProd.affDiv_nil] | cons p fs ih => rw [LineProd.degInf_cons, LineProd.affDiv_cons, Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl), ih] congr 1 rw [Finsupp.sum_smul_index' (fun _ => rfl)] simp_rw [smul_eq_mul] rw [← Finsupp.mul_sum] congr 1 cases p.1 with | nonVert P₁ P₂ h₁ h₂ h12 => simp only [ElemLine.degInf, LineProd.elemAffDiv, ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, add_zero] rw [Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl), Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl), Finsupp.sum_single_index rfl, Finsupp.sum_single_index rfl, Finsupp.sum_single_index rfl] norm_num | vert P hP => simp only [ElemLine.degInf, LineProd.elemAffDiv, ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil, add_zero] rw [Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl), Finsupp.sum_single_index rfl, Finsupp.sum_single_index rfl] norm_num lemma shiftedMillerFunc_degInf {a b : K} {m : ℕ} {P R : (shortWeierstrass a b).toAffine.Point} (hmP : m • P = 0) (hR : R ≠ 0) (hPR : P + R ≠ 0) : (shiftedMillerFunc m P R hR hPR).degInf = 0 := by rw [degInf_eq_sum_affDiv, shiftedMillerFunc_affDiv hmP hR hPR, Finsupp.sum_smul_index' (fun _ => rfl)] simp_rw [smul_eq_mul] rw [← Finsupp.mul_sum, shiftedDiv_degZero, mul_zero] /-- **THE WEIL PAIRING `e_m(P, Q)`** (symmetric shifted Miller definition): `e_m(P, Q; R, S) = f_{m, P, R}((Q + S) - (S)) / f_{m, Q, S}((P + R) - (R))`. -/ noncomputable def weilPairing {a b : K} (m : ℕ) (P Q R S : (shortWeierstrass a b).toAffine.Point) (hR : R ≠ 0) (hPR : P + R ≠ 0) (hS : S ≠ 0) (hQS : Q + S ≠ 0) : K := LineProd.evalDiv (shiftedMillerFunc m P R hR hPR) (shiftedDiv Q S) / LineProd.evalDiv (shiftedMillerFunc m Q S hS hQS) (shiftedDiv P R) /-- Helper: support of `shiftedDiv P R` is contained in `{P + R, R}`. -/ lemma support_shiftedDiv_subset {a b : K} (P R : (shortWeierstrass a b).toAffine.Point) {X : (shortWeierstrass a b).toAffine.Point} (hX : X ∈ (shiftedDiv P R).support) : X = P + R ∨ X = R := by unfold shiftedDiv at hX rw [sub_eq_add_neg] at hX rcases Finset.mem_union.mp (Finsupp.support_add hX) with h1 | h2 · left; exact Finset.mem_singleton.mp (Finsupp.support_single_subset h1) · right; rw [Finsupp.support_neg] at h2 exact Finset.mem_singleton.mp (Finsupp.support_single_subset h2) /-- **Theorem 1 — Skew-Symmetry**: `e_m(Q, P; S, R) = e_m(P, Q; R, S)⁻¹`. -/ theorem weilPairing_skew_symm {a b : K} (m : ℕ) (P Q R S : (shortWeierstrass a b).toAffine.Point) (hR : R ≠ 0) (hPR : P + R ≠ 0) (hS : S ≠ 0) (hQS : Q + S ≠ 0) : weilPairing m Q P S R hS hQS hR hPR = (weilPairing m P Q R S hR hPR hS hQS)⁻¹ := by unfold weilPairing rw [inv_div] /-- **Theorem 2 — `m`-th Root of Unity**: `(e_m(P, Q; R, S))^m = 1`! (Proved in 5 lines from our degree-zero Weil reciprocity theorem!) -/ theorem weilPairing_pow_eq_one {a b : K} {m : ℕ} {P Q R S : (shortWeierstrass a b).toAffine.Point} (hmP : m • P = 0) (hmQ : m • Q = 0) (hR : R ≠ 0) (hPR : P + R ≠ 0) (hS : S ≠ 0) (hQS : Q + S ≠ 0) (hdisj : Disjoint (shiftedMillerFunc m P R hR hPR).factorSupp (shiftedMillerFunc m Q S hS hQS).factorSupp) (hPR_not : P + R ∉ (shiftedMillerFunc m Q S hS hQS).factorSupp) (hR_not : R ∉ (shiftedMillerFunc m Q S hS hQS).factorSupp) (hQS_not : Q + S ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) (hS_not : S ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) : (weilPairing m P Q R S hR hPR hS hQS) ^ m = 1 := by unfold weilPairing have hD_Q : ∀ X ∈ (shiftedDiv Q S).support, X ≠ 0 ∧ X ∉ (shiftedMillerFunc m P R hR hPR).factorSupp := by intro X hX; rcases support_shiftedDiv_subset Q S hX with rfl | rfl · exact ⟨hQS, hQS_not⟩ · exact ⟨hS, hS_not⟩ have hD_P : ∀ X ∈ (shiftedDiv P R).support, X ≠ 0 ∧ X ∉ (shiftedMillerFunc m Q S hS hQS).factorSupp := by intro X hX; rcases support_shiftedDiv_subset P R hX with rfl | rfl · exact ⟨hPR, hPR_not⟩ · exact ⟨hR, hR_not⟩ have hden_ne : LineProd.evalDiv (shiftedMillerFunc m Q S hS hQS) (shiftedDiv P R) ≠ 0 := LineProd.evalDiv_ne_zero _ hD_P rw [div_pow, div_eq_one_iff_eq (pow_ne_zero m hden_ne)] have hL : (LineProd.evalDiv (shiftedMillerFunc m P R hR hPR) (shiftedDiv Q S)) ^ m = LineProd.evalDiv (shiftedMillerFunc m P R hR hPR) (shiftedMillerFunc m Q S hS hQS).affDiv := by rw [shiftedMillerFunc_affDiv hmQ hS hQS, LineProd.evalDiv_smul _ (m : ℤ), zpow_natCast] have hR' : (LineProd.evalDiv (shiftedMillerFunc m Q S hS hQS) (shiftedDiv P R)) ^ m = LineProd.evalDiv (shiftedMillerFunc m Q S hS hQS) (shiftedMillerFunc m P R hR hPR).affDiv := by rw [shiftedMillerFunc_affDiv hmP hR hPR, LineProd.evalDiv_smul _ (m : ℤ), zpow_natCast] rw [hL, hR'] exact LineProd.lineProd_weil_reciprocity_degZero _ _ hdisj (Or.inl (shiftedMillerFunc_degInf hmP hR hPR)) /-- **Theorem 3 — Shift Independence**: `e_m(P, Q; R, S₁) = e_m(P, Q; R, S₂)`! (Proved directly via our exact degree-zero Weil reciprocity!) -/ theorem weilPairing_shift_indep_right {a b : K} {m : ℕ} {P Q R S₁ S₂ : (shortWeierstrass a b).toAffine.Point} (hmP : m • P = 0) (hmQ : m • Q = 0) (hR : R ≠ 0) (hPR : P + R ≠ 0) (hS₁ : S₁ ≠ 0) (hQS₁ : Q + S₁ ≠ 0) (hS₂ : S₂ ≠ 0) (hQS₂ : Q + S₂ ≠ 0) (hQ : Q ≠ 0) (hdisj_h : Disjoint (shiftedMillerFunc m P R hR hPR).factorSupp (LineProd.factorSupp [(ElemLine.vert (Q + S₂) hQS₂, (1 : ℤ)), (ElemLine.nonVert Q S₂ hQ hS₂ hQS₂, -1), (ElemLine.nonVert Q S₁ hQ hS₁ hQS₁, 1), (ElemLine.vert (Q + S₁) hQS₁, -1)])) (hPR_not1 : P + R ∉ (shiftedMillerFunc m Q S₁ hS₁ hQS₁).factorSupp) (hR_not1 : R ∉ (shiftedMillerFunc m Q S₁ hS₁ hQS₁).factorSupp) (hPR_not2 : P + R ∉ (shiftedMillerFunc m Q S₂ hS₂ hQS₂).factorSupp) (hR_not2 : R ∉ (shiftedMillerFunc m Q S₂ hS₂ hQS₂).factorSupp) (hQS1_not : Q + S₁ ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) (hS1_not : S₁ ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) (hQS2_not : Q + S₂ ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) (hS2_not : S₂ ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) : weilPairing m P Q R S₁ hR hPR hS₁ hQS₁ = weilPairing m P Q R S₂ hR hPR hS₂ hQS₂ := by set fP := shiftedMillerFunc m P R hR hPR set fQ1 := shiftedMillerFunc m Q S₁ hS₁ hQS₁ set fQ2 := shiftedMillerFunc m Q S₂ hS₂ hQS₂ let h : LineProd a b := [(ElemLine.vert (Q + S₂) hQS₂, 1), (ElemLine.nonVert Q S₂ hQ hS₂ hQS₂, -1), (ElemLine.nonVert Q S₁ hQ hS₁ hQS₁, 1), (ElemLine.vert (Q + S₁) hQS₁, -1)] have hh_div : h.affDiv = shiftedDiv Q S₂ - shiftedDiv Q S₁ := by unfold h shiftedDiv simp only [LineProd.affDiv_cons, LineProd.affDiv_nil, one_smul, neg_smul, add_zero, LineProd.elemAffDiv, ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil] abel have hh_deg : h.degInf = 0 := by rw [degInf_eq_sum_affDiv, hh_div, sub_eq_add_neg, Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl), Finsupp.sum_neg_index (fun _ => rfl)] have hneg_sum : ((shiftedDiv Q S₁).sum fun _ n => -n) = -((shiftedDiv Q S₁).sum fun _ n => n) := by simp [Finsupp.sum, Finset.sum_neg_distrib] rw [hneg_sum, shiftedDiv_degZero, shiftedDiv_degZero] ring have hfQ2_div : fQ2.affDiv = (fQ1 ++ h.zpow m).affDiv := by rw [LineProd.affDiv_append, LineProd.affDiv_zpow, shiftedMillerFunc_affDiv hmQ hS₂ hQS₂, shiftedMillerFunc_affDiv hmQ hS₁ hQS₁, hh_div, smul_sub] abel -- Check supports for evalDiv have hDP_fQ1 : ∀ X ∈ (shiftedDiv P R).support, X ≠ 0 ∧ X ∉ fQ1.factorSupp := by intro X hX; rcases support_shiftedDiv_subset P R hX with rfl | rfl · exact ⟨hPR, hPR_not1⟩ · exact ⟨hR, hR_not1⟩ have hDP_fQ2 : ∀ X ∈ (shiftedDiv P R).support, X ≠ 0 ∧ X ∉ fQ2.factorSupp := by intro X hX; rcases support_shiftedDiv_subset P R hX with rfl | rfl · exact ⟨hPR, hPR_not2⟩ · exact ⟨hR, hR_not2⟩ have hDP_h : ∀ X ∈ (shiftedDiv P R).support, X ≠ 0 ∧ X ∉ h.factorSupp := by intro X hX have hsub_h : h.factorSupp ⊆ fQ1.factorSupp ∪ fQ2.factorSupp := by intro Y hY rcases hY with ⟨p, hp, hYp⟩ simp only [h, List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl | rfl · right; unfold fQ2 shiftedMillerFunc; rw [dif_neg hQ] exact ⟨(ElemLine.vert (Q + S₂) hQS₂, (m : ℤ)), List.mem_append.mpr (Or.inr (by simp)), hYp⟩ · right; unfold fQ2 shiftedMillerFunc; rw [dif_neg hQ] exact ⟨(ElemLine.nonVert Q S₂ hQ hS₂ hQS₂, -(m : ℤ)), List.mem_append.mpr (Or.inr (by simp)), hYp⟩ · left; unfold fQ1 shiftedMillerFunc; rw [dif_neg hQ] exact ⟨(ElemLine.nonVert Q S₁ hQ hS₁ hQS₁, -(m : ℤ)), List.mem_append.mpr (Or.inr (by simp)), hYp⟩ · left; unfold fQ1 shiftedMillerFunc; rw [dif_neg hQ] exact ⟨(ElemLine.vert (Q + S₁) hQS₁, (m : ℤ)), List.mem_append.mpr (Or.inr (by simp)), hYp⟩ refine ⟨(hDP_fQ1 X hX).1, fun hXh => ?_⟩ rcases hsub_h hXh with h1 | h2 · exact (hDP_fQ1 X hX).2 h1 · exact (hDP_fQ2 X hX).2 h2 have hDQ1_fP : ∀ X ∈ (shiftedDiv Q S₁).support, X ≠ 0 ∧ X ∉ fP.factorSupp := by intro X hX; rcases support_shiftedDiv_subset Q S₁ hX with rfl | rfl · exact ⟨hQS₁, hQS1_not⟩ · exact ⟨hS₁, hS1_not⟩ have hDQ2_fP : ∀ X ∈ (shiftedDiv Q S₂).support, X ≠ 0 ∧ X ∉ fP.factorSupp := by intro X hX; rcases support_shiftedDiv_subset Q S₂ hX with rfl | rfl · exact ⟨hQS₂, hQS2_not⟩ · exact ⟨hS₂, hS2_not⟩ -- Key identities: -- 1) evalDiv fQ2 (shiftedDiv P R) = evalDiv fQ1 (shiftedDiv P R) * (evalDiv h (shiftedDiv P R)) ^ m have hden_rel : LineProd.evalDiv fQ2 (shiftedDiv P R) = LineProd.evalDiv fQ1 (shiftedDiv P R) * (LineProd.evalDiv h (shiftedDiv P R)) ^ (m : ℤ) := by rw [LineProd.lineProd_evalDiv_eq_of_affDiv_eq fQ2 (fQ1 ++ h.zpow m) hfQ2_div (shiftedDiv_degZero P R) hDP_fQ2 (fun X hX => by refine ⟨(hDP_fQ1 X hX).1, ?_⟩ rw [LineProd.factorSupp_append, LineProd.factorSupp_zpow, Set.mem_union] rintro (h1 | h2) · exact (hDP_fQ1 X hX).2 h1 · exact (hDP_h X hX).2 h2), LineProd.evalDiv_append, LineProd.evalDiv_zpow] -- 2) (evalDiv h (shiftedDiv P R)) ^ m = evalDiv h fP.affDiv = evalDiv fP h.affDiv = evalDiv fP D2 / evalDiv fP D1! have hrec : (LineProd.evalDiv h (shiftedDiv P R)) ^ (m : ℤ) = LineProd.evalDiv fP (shiftedDiv Q S₂) / LineProd.evalDiv fP (shiftedDiv Q S₁) := by rw [← LineProd.evalDiv_smul h (m : ℤ), ← shiftedMillerFunc_affDiv hmP hR hPR, ← LineProd.lineProd_weil_reciprocity_degZero fP h hdisj_h (Or.inr hh_deg), hh_div, LineProd.evalDiv_sub fP hDQ2_fP hDQ1_fP] unfold weilPairing change LineProd.evalDiv fP (shiftedDiv Q S₁) / LineProd.evalDiv fQ1 (shiftedDiv P R) = LineProd.evalDiv fP (shiftedDiv Q S₂) / LineProd.evalDiv fQ2 (shiftedDiv P R) rw [hden_rel, hrec] have hne1 : LineProd.evalDiv fP (shiftedDiv Q S₁) ≠ 0 := LineProd.evalDiv_ne_zero fP hDQ1_fP have hne2 : LineProd.evalDiv fP (shiftedDiv Q S₂) ≠ 0 := LineProd.evalDiv_ne_zero fP hDQ2_fP have hne3 : LineProd.evalDiv fQ1 (shiftedDiv P R) ≠ 0 := LineProd.evalDiv_ne_zero fQ1 hDP_fQ1 field_simp [hne1, hne2, hne3] /-- **Theorem 4 — Bilinearity (Left)**: `e_m(P₁ + P₂, Q) = e_m(P₁, Q) * e_m(P₂, Q)`! -/ theorem weilPairing_bilinear_left {a b : K} {m : ℕ} {P₁ P₂ Q R₁ R₂ R₃ S : (shortWeierstrass a b).toAffine.Point} (hmP₁ : m • P₁ = 0) (hmP₂ : m • P₂ = 0) (hmQ : m • Q = 0) (hR₁ : R₁ ≠ 0) (hPR₁ : P₁ + R₁ ≠ 0) (hR₂ : R₂ ≠ 0) (hPR₂ : P₂ + R₂ ≠ 0) (hR₃ : R₃ ≠ 0) (hPR₃ : P₁ + P₂ + R₃ ≠ 0) (hS : S ≠ 0) (hQS : Q + S ≠ 0) (hP₁ : P₁ ≠ 0) (hP₂ : P₂ ≠ 0) (hP12 : P₁ + P₂ ≠ 0) -- Auxiliary bridging line-product h with div(h) = D_{P₁+P₂, R₃} - D_{P₁, R₁} - D_{P₂, R₂} (hdisj_h : Disjoint (shiftedMillerFunc m Q S hS hQS).factorSupp (LineProd.factorSupp [(ElemLine.vert (P₁ + P₂ + R₃) hPR₃, (1 : ℤ)), (ElemLine.nonVert (P₁ + P₂) R₃ hP12 hR₃ hPR₃, -1), (ElemLine.vert (P₁ + P₂) hP12, 1), (ElemLine.nonVert P₁ P₂ hP₁ hP₂ hP12, -1), (ElemLine.nonVert P₁ R₁ hP₁ hR₁ hPR₁, 1), (ElemLine.vert (P₁ + R₁) hPR₁, -1), (ElemLine.nonVert P₂ R₂ hP₂ hR₂ hPR₂, 1), (ElemLine.vert (P₂ + R₂) hPR₂, -1)])) (hQS_not1 : Q + S ∉ (shiftedMillerFunc m P₁ R₁ hR₁ hPR₁).factorSupp) (hS_not1 : S ∉ (shiftedMillerFunc m P₁ R₁ hR₁ hPR₁).factorSupp) (hQS_not2 : Q + S ∉ (shiftedMillerFunc m P₂ R₂ hR₂ hPR₂).factorSupp) (hS_not2 : S ∉ (shiftedMillerFunc m P₂ R₂ hR₂ hPR₂).factorSupp) (hQS_not3 : Q + S ∉ (shiftedMillerFunc m (P₁ + P₂) R₃ hR₃ hPR₃).factorSupp) (hS_not3 : S ∉ (shiftedMillerFunc m (P₁ + P₂) R₃ hR₃ hPR₃).factorSupp) (hQS_noth : Q + S ∉ LineProd.factorSupp [(ElemLine.vert (P₁ + P₂ + R₃) hPR₃, (1 : ℤ)), (ElemLine.nonVert (P₁ + P₂) R₃ hP12 hR₃ hPR₃, -1), (ElemLine.vert (P₁ + P₂) hP12, 1), (ElemLine.nonVert P₁ P₂ hP₁ hP₂ hP12, -1), (ElemLine.nonVert P₁ R₁ hP₁ hR₁ hPR₁, 1), (ElemLine.vert (P₁ + R₁) hPR₁, -1), (ElemLine.nonVert P₂ R₂ hP₂ hR₂ hPR₂, 1), (ElemLine.vert (P₂ + R₂) hPR₂, -1)]) (hS_noth : S ∉ LineProd.factorSupp [(ElemLine.vert (P₁ + P₂ + R₃) hPR₃, (1 : ℤ)), (ElemLine.nonVert (P₁ + P₂) R₃ hP12 hR₃ hPR₃, -1), (ElemLine.vert (P₁ + P₂) hP12, 1), (ElemLine.nonVert P₁ P₂ hP₁ hP₂ hP12, -1), (ElemLine.nonVert P₁ R₁ hP₁ hR₁ hPR₁, 1), (ElemLine.vert (P₁ + R₁) hPR₁, -1), (ElemLine.nonVert P₂ R₂ hP₂ hR₂ hPR₂, 1), (ElemLine.vert (P₂ + R₂) hPR₂, -1)]) (hPR1_not : P₁ + R₁ ∉ (shiftedMillerFunc m Q S hS hQS).factorSupp) (hR1_not : R₁ ∉ (shiftedMillerFunc m Q S hS hQS).factorSupp) (hPR2_not : P₂ + R₂ ∉ (shiftedMillerFunc m Q S hS hQS).factorSupp) (hR2_not : R₂ ∉ (shiftedMillerFunc m Q S hS hQS).factorSupp) (hPR3_not : P₁ + P₂ + R₃ ∉ (shiftedMillerFunc m Q S hS hQS).factorSupp) (hR3_not : R₃ ∉ (shiftedMillerFunc m Q S hS hQS).factorSupp) : weilPairing m (P₁ + P₂) Q R₃ S hR₃ hPR₃ hS hQS = weilPairing m P₁ Q R₁ S hR₁ hPR₁ hS hQS * weilPairing m P₂ Q R₂ S hR₂ hPR₂ hS hQS := by have hmP12 : m • (P₁ + P₂) = 0 := by rw [smul_add, hmP₁, hmP₂, add_zero] set f1 := shiftedMillerFunc m P₁ R₁ hR₁ hPR₁ set f2 := shiftedMillerFunc m P₂ R₂ hR₂ hPR₂ set f3 := shiftedMillerFunc m (P₁ + P₂) R₃ hR₃ hPR₃ set fQ := shiftedMillerFunc m Q S hS hQS let h : LineProd a b := [(ElemLine.vert (P₁ + P₂ + R₃) hPR₃, 1), (ElemLine.nonVert (P₁ + P₂) R₃ hP12 hR₃ hPR₃, -1), (ElemLine.vert (P₁ + P₂) hP12, 1), (ElemLine.nonVert P₁ P₂ hP₁ hP₂ hP12, -1), (ElemLine.nonVert P₁ R₁ hP₁ hR₁ hPR₁, 1), (ElemLine.vert (P₁ + R₁) hPR₁, -1), (ElemLine.nonVert P₂ R₂ hP₂ hR₂ hPR₂, 1), (ElemLine.vert (P₂ + R₂) hPR₂, -1)] have hh_div : h.affDiv = shiftedDiv (P₁ + P₂) R₃ - shiftedDiv P₁ R₁ - shiftedDiv P₂ R₂ := by unfold h shiftedDiv simp only [LineProd.affDiv_cons, LineProd.affDiv_nil, one_smul, neg_smul, add_zero, LineProd.elemAffDiv, ElemLine.zeros, List.map_cons, List.map_nil, List.sum_cons, List.sum_nil] abel have hh_deg : h.degInf = 0 := by rw [degInf_eq_sum_affDiv, hh_div, sub_eq_add_neg, sub_eq_add_neg, Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl), Finsupp.sum_add_index' (fun _ => rfl) (fun _ _ _ => rfl), Finsupp.sum_neg_index (fun _ => rfl), Finsupp.sum_neg_index (fun _ => rfl)] have hneg_sum : ∀ D : (shortWeierstrass a b).toAffine.Point →₀ ℤ, (D.sum fun _ n => -n) = -(D.sum fun _ n => n) := by intro D; simp [Finsupp.sum, Finset.sum_neg_distrib] rw [hneg_sum, hneg_sum, shiftedDiv_degZero, shiftedDiv_degZero, shiftedDiv_degZero] ring have hf3_div : f3.affDiv = (f1 ++ f2 ++ h.zpow m).affDiv := by rw [LineProd.affDiv_append, LineProd.affDiv_append, LineProd.affDiv_zpow, shiftedMillerFunc_affDiv hmP12 hR₃ hPR₃, shiftedMillerFunc_affDiv hmP₁ hR₁ hPR₁, shiftedMillerFunc_affDiv hmP₂ hR₂ hPR₂, hh_div, smul_sub, smul_sub] abel have hDQ_f1 : ∀ X ∈ (shiftedDiv Q S).support, X ≠ 0 ∧ X ∉ f1.factorSupp := by intro X hX; rcases support_shiftedDiv_subset Q S hX with rfl | rfl · exact ⟨hQS, hQS_not1⟩ · exact ⟨hS, hS_not1⟩ have hDQ_f2 : ∀ X ∈ (shiftedDiv Q S).support, X ≠ 0 ∧ X ∉ f2.factorSupp := by intro X hX; rcases support_shiftedDiv_subset Q S hX with rfl | rfl · exact ⟨hQS, hQS_not2⟩ · exact ⟨hS, hS_not2⟩ have hDQ_f3 : ∀ X ∈ (shiftedDiv Q S).support, X ≠ 0 ∧ X ∉ f3.factorSupp := by intro X hX; rcases support_shiftedDiv_subset Q S hX with rfl | rfl · exact ⟨hQS, hQS_not3⟩ · exact ⟨hS, hS_not3⟩ have hDQ_h : ∀ X ∈ (shiftedDiv Q S).support, X ≠ 0 ∧ X ∉ h.factorSupp := by intro X hX; rcases support_shiftedDiv_subset Q S hX with rfl | rfl · exact ⟨hQS, hQS_noth⟩ · exact ⟨hS, hS_noth⟩ have hDP1_fQ : ∀ X ∈ (shiftedDiv P₁ R₁).support, X ≠ 0 ∧ X ∉ fQ.factorSupp := by intro X hX; rcases support_shiftedDiv_subset P₁ R₁ hX with rfl | rfl · exact ⟨hPR₁, hPR1_not⟩ · exact ⟨hR₁, hR1_not⟩ have hDP2_fQ : ∀ X ∈ (shiftedDiv P₂ R₂).support, X ≠ 0 ∧ X ∉ fQ.factorSupp := by intro X hX; rcases support_shiftedDiv_subset P₂ R₂ hX with rfl | rfl · exact ⟨hPR₂, hPR2_not⟩ · exact ⟨hR₂, hR2_not⟩ have hDP3_fQ : ∀ X ∈ (shiftedDiv (P₁ + P₂) R₃).support, X ≠ 0 ∧ X ∉ fQ.factorSupp := by intro X hX; rcases support_shiftedDiv_subset (P₁ + P₂) R₃ hX with rfl | rfl · exact ⟨hPR₃, hPR3_not⟩ · exact ⟨hR₃, hR3_not⟩ have hnum_rel : LineProd.evalDiv f3 (shiftedDiv Q S) = LineProd.evalDiv f1 (shiftedDiv Q S) * LineProd.evalDiv f2 (shiftedDiv Q S) * (LineProd.evalDiv h (shiftedDiv Q S)) ^ (m : ℤ) := by rw [LineProd.lineProd_evalDiv_eq_of_affDiv_eq f3 (f1 ++ f2 ++ h.zpow m) hf3_div (shiftedDiv_degZero Q S) hDQ_f3 (fun X hX => by refine ⟨(hDQ_f1 X hX).1, ?_⟩ rw [LineProd.factorSupp_append, LineProd.factorSupp_append, LineProd.factorSupp_zpow] rintro ((h1 | h2) | h3) · exact (hDQ_f1 X hX).2 h1 · exact (hDQ_f2 X hX).2 h2 · exact (hDQ_h X hX).2 h3), LineProd.evalDiv_append, LineProd.evalDiv_append, LineProd.evalDiv_zpow] have hrec : (LineProd.evalDiv h (shiftedDiv Q S)) ^ (m : ℤ) = LineProd.evalDiv fQ (shiftedDiv (P₁ + P₂) R₃) / (LineProd.evalDiv fQ (shiftedDiv P₁ R₁) * LineProd.evalDiv fQ (shiftedDiv P₂ R₂)) := by have hD31 : ∀ X ∈ (shiftedDiv (P₁ + P₂) R₃ - shiftedDiv P₁ R₁).support, X ≠ 0 ∧ X ∉ fQ.factorSupp := by intro X hX rw [sub_eq_add_neg] at hX rcases Finset.mem_union.mp (Finsupp.support_add hX) with h1 | h2 · exact hDP3_fQ X h1 · rw [Finsupp.support_neg] at h2; exact hDP1_fQ X h2 rw [← LineProd.evalDiv_smul h (m : ℤ), ← shiftedMillerFunc_affDiv hmQ hS hQS, ← LineProd.lineProd_weil_reciprocity_degZero fQ h hdisj_h (Or.inr hh_deg), hh_div, LineProd.evalDiv_sub fQ hD31 hDP2_fQ, LineProd.evalDiv_sub fQ hDP3_fQ hDP1_fQ, div_div] unfold weilPairing change LineProd.evalDiv f3 (shiftedDiv Q S) / LineProd.evalDiv fQ (shiftedDiv (P₁ + P₂) R₃) = (LineProd.evalDiv f1 (shiftedDiv Q S) / LineProd.evalDiv fQ (shiftedDiv P₁ R₁)) * (LineProd.evalDiv f2 (shiftedDiv Q S) / LineProd.evalDiv fQ (shiftedDiv P₂ R₂)) rw [hnum_rel, hrec] have hne1 := LineProd.evalDiv_ne_zero fQ hDP1_fQ have hne2 := LineProd.evalDiv_ne_zero fQ hDP2_fQ have hne3 := LineProd.evalDiv_ne_zero fQ hDP3_fQ field_simp [hne1, hne2, hne3] /-- Direct evaluation formula for `evalDiv f (shiftedDiv P R) = f(P + R) / f(R)`. -/ lemma evalDiv_shiftedDiv {a b : K} (f : LineProd a b) (P R : (shortWeierstrass a b).toAffine.Point) (hR : R ≠ 0) (hPR : P + R ≠ 0) (h1 : P + R ∉ f.factorSupp) (h2 : R ∉ f.factorSupp) : LineProd.evalDiv f (shiftedDiv P R) = f.eval (P + R) / f.eval R := by unfold shiftedDiv have hs1 : ∀ Q ∈ (Finsupp.single (P + R) (1 : ℤ)).support, Q ≠ 0 ∧ Q ∉ f.factorSupp := by intro Q hQ; have hQ' := Finset.mem_singleton.mp (Finsupp.support_single_subset hQ) subst hQ'; exact ⟨hPR, h1⟩ have hs2 : ∀ Q ∈ (Finsupp.single R (1 : ℤ)).support, Q ≠ 0 ∧ Q ∉ f.factorSupp := by intro Q hQ; have hQ' := Finset.mem_singleton.mp (Finsupp.support_single_subset hQ) subst hQ'; exact ⟨hR, h2⟩ rw [LineProd.evalDiv_sub f hs1 hs2, LineProd.evalDiv_single, LineProd.evalDiv_single, zpow_one, zpow_one] /-- **Theorem 5 — Bilinearity (Right)**: `e_m(P, Q₁ + Q₂) = e_m(P, Q₁) * e_m(P, Q₂)` (corollary of left bilinearity + skew-symmetry). -/ theorem weilPairing_bilinear_right {a b : K} {m : ℕ} {P Q₁ Q₂ R S₁ S₂ S₃ : (shortWeierstrass a b).toAffine.Point} (hmP : m • P = 0) (hmQ₁ : m • Q₁ = 0) (hmQ₂ : m • Q₂ = 0) (hR : R ≠ 0) (hPR : P + R ≠ 0) (hS₁ : S₁ ≠ 0) (hQS₁ : Q₁ + S₁ ≠ 0) (hS₂ : S₂ ≠ 0) (hQS₂ : Q₂ + S₂ ≠ 0) (hS₃ : S₃ ≠ 0) (hQS₃ : Q₁ + Q₂ + S₃ ≠ 0) (hQ₁ : Q₁ ≠ 0) (hQ₂ : Q₂ ≠ 0) (hQ12 : Q₁ + Q₂ ≠ 0) (hdisj_h : Disjoint (shiftedMillerFunc m P R hR hPR).factorSupp (LineProd.factorSupp [(ElemLine.vert (Q₁ + Q₂ + S₃) hQS₃, (1 : ℤ)), (ElemLine.nonVert (Q₁ + Q₂) S₃ hQ12 hS₃ hQS₃, -1), (ElemLine.vert (Q₁ + Q₂) hQ12, 1), (ElemLine.nonVert Q₁ Q₂ hQ₁ hQ₂ hQ12, -1), (ElemLine.nonVert Q₁ S₁ hQ₁ hS₁ hQS₁, 1), (ElemLine.vert (Q₁ + S₁) hQS₁, -1), (ElemLine.nonVert Q₂ S₂ hQ₂ hS₂ hQS₂, 1), (ElemLine.vert (Q₂ + S₂) hQS₂, -1)])) (hPR_not1 : P + R ∉ (shiftedMillerFunc m Q₁ S₁ hS₁ hQS₁).factorSupp) (hR_not1 : R ∉ (shiftedMillerFunc m Q₁ S₁ hS₁ hQS₁).factorSupp) (hPR_not2 : P + R ∉ (shiftedMillerFunc m Q₂ S₂ hS₂ hQS₂).factorSupp) (hR_not2 : R ∉ (shiftedMillerFunc m Q₂ S₂ hS₂ hQS₂).factorSupp) (hPR_not3 : P + R ∉ (shiftedMillerFunc m (Q₁ + Q₂) S₃ hS₃ hQS₃).factorSupp) (hR_not3 : R ∉ (shiftedMillerFunc m (Q₁ + Q₂) S₃ hS₃ hQS₃).factorSupp) (hPR_noth : P + R ∉ LineProd.factorSupp [(ElemLine.vert (Q₁ + Q₂ + S₃) hQS₃, (1 : ℤ)), (ElemLine.nonVert (Q₁ + Q₂) S₃ hQ12 hS₃ hQS₃, -1), (ElemLine.vert (Q₁ + Q₂) hQ12, 1), (ElemLine.nonVert Q₁ Q₂ hQ₁ hQ₂ hQ12, -1), (ElemLine.nonVert Q₁ S₁ hQ₁ hS₁ hQS₁, 1), (ElemLine.vert (Q₁ + S₁) hQS₁, -1), (ElemLine.nonVert Q₂ S₂ hQ₂ hS₂ hQS₂, 1), (ElemLine.vert (Q₂ + S₂) hQS₂, -1)]) (hR_noth : R ∉ LineProd.factorSupp [(ElemLine.vert (Q₁ + Q₂ + S₃) hQS₃, (1 : ℤ)), (ElemLine.nonVert (Q₁ + Q₂) S₃ hQ12 hS₃ hQS₃, -1), (ElemLine.vert (Q₁ + Q₂) hQ12, 1), (ElemLine.nonVert Q₁ Q₂ hQ₁ hQ₂ hQ12, -1), (ElemLine.nonVert Q₁ S₁ hQ₁ hS₁ hQS₁, 1), (ElemLine.vert (Q₁ + S₁) hQS₁, -1), (ElemLine.nonVert Q₂ S₂ hQ₂ hS₂ hQS₂, 1), (ElemLine.vert (Q₂ + S₂) hQS₂, -1)]) (hQS1_not : Q₁ + S₁ ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) (hS1_not : S₁ ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) (hQS2_not : Q₂ + S₂ ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) (hS2_not : S₂ ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) (hQS3_not : Q₁ + Q₂ + S₃ ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) (hS3_not : S₃ ∉ (shiftedMillerFunc m P R hR hPR).factorSupp) : weilPairing m P (Q₁ + Q₂) R S₃ hR hPR hS₃ hQS₃ = weilPairing m P Q₁ R S₁ hR hPR hS₁ hQS₁ * weilPairing m P Q₂ R S₂ hR hPR hS₂ hQS₂ := by have hL := weilPairing_bilinear_left hmQ₁ hmQ₂ hmP hS₁ hQS₁ hS₂ hQS₂ hS₃ hQS₃ hR hPR hQ₁ hQ₂ hQ12 hdisj_h hPR_not1 hR_not1 hPR_not2 hR_not2 hPR_not3 hR_not3 hPR_noth hR_noth hQS1_not hS1_not hQS2_not hS2_not hQS3_not hS3_not rw [weilPairing_skew_symm m (Q₁ + Q₂) P S₃ R hS₃ hQS₃ hR hPR, hL, mul_inv, ← weilPairing_skew_symm m Q₁ P S₁ R hS₁ hQS₁ hR hPR, ← weilPairing_skew_symm m Q₂ P S₂ R hS₂ hQS₂ hR hPR] /-- **Theorem 6 — Alternating Property (ALL `m ≥ 1`, Even AND Odd!)**: For ANY `P ∈ E[m]` and ANY shift `S` with `R = -P - S` avoiding the factor support, `e_m(P, P; -P - S, S) = 1`! (Proved cleanly via `g = (negPull f₂)⁻¹` and `lineProd_evalDiv_eq_of_affDiv_eq`!) -/ theorem weilPairing_alternating {a b : K} {m : ℕ} {P S : (shortWeierstrass a b).toAffine.Point} (hmP : m • P = 0) (hS : S ≠ 0) (hPS : P + S ≠ 0) (hPS_not : P + S ∉ (shiftedMillerFunc m P (-P - S) (by intro h0; exact hPS (by have h1 : P + S = -(-P - S) := by abel rw [h1, h0, neg_zero])) (by have h1 : P + (-P - S) = -S := by abel rw [h1]; exact neg_ne_zero.mpr hS)).factorSupp) (hS_not : S ∉ (shiftedMillerFunc m P (-P - S) (by intro h0; exact hPS (by have h1 : P + S = -(-P - S) := by abel rw [h1, h0, neg_zero])) (by have h1 : P + (-P - S) = -S := by abel rw [h1]; exact neg_ne_zero.mpr hS)).factorSupp) (hnS_not : -S ∉ (shiftedMillerFunc m P S hS hPS).factorSupp) (hnPS_not : -(P + S) ∉ (shiftedMillerFunc m P S hS hPS).factorSupp) : weilPairing m P P (-P - S) S (by intro h0; exact hPS (by have h1 : P + S = -(-P - S) := (by abel); rw [h1, h0, neg_zero])) (by have h1 : P + (-P - S) = -S := (by abel); rw [h1]; exact neg_ne_zero.mpr hS) hS hPS = 1 := by have hR : -P - S ≠ 0 := by intro h0; exact hPS (by have h1 : P + S = -(-P - S) := (by abel); rw [h1, h0, neg_zero]) have hPR_eq : P + (-P - S) = -S := by abel have hPR : P + (-P - S) ≠ 0 := by rw [hPR_eq]; exact neg_ne_zero.mpr hS have hR_eq : -P - S = -(P + S) := by abel set f₁ := shiftedMillerFunc m P (-P - S) hR hPR set f₂ := shiftedMillerFunc m P S hS hPS set g := f₂.negPull.inv have hg_div : f₁.affDiv = g.affDiv := by rw [shiftedMillerFunc_affDiv hmP hR hPR] unfold g rw [LineProd.affDiv_inv, LineProd.negPull_affDiv, shiftedMillerFunc_affDiv hmP hS hPS] unfold shiftedDiv rw [Finsupp.mapDomain_smul, Finsupp.mapDomain_sub, Finsupp.mapDomain_single, Finsupp.mapDomain_single, ← smul_neg, neg_sub, hPR_eq, hR_eq] have hDQ_f1 : ∀ X ∈ (shiftedDiv P S).support, X ≠ 0 ∧ X ∉ f₁.factorSupp := by intro X hX; rcases support_shiftedDiv_subset P S hX with rfl | rfl · exact ⟨hPS, hPS_not⟩ · exact ⟨hS, hS_not⟩ have hDQ_g : ∀ X ∈ (shiftedDiv P S).support, X ≠ 0 ∧ X ∉ g.factorSupp := by intro X hX unfold g rw [LineProd.factorSupp_inv, LineProd.negPull_factorSupp, Set.mem_ofPred_eq] rcases support_shiftedDiv_subset P S hX with rfl | rfl · exact ⟨hPS, hnPS_not⟩ · exact ⟨hS, hnS_not⟩ have hDP_f2 : ∀ X ∈ (shiftedDiv P (-P - S)).support, X ≠ 0 ∧ X ∉ f₂.factorSupp := by intro X hX; rcases support_shiftedDiv_subset P (-P - S) hX with rfl | rfl · exact ⟨hPR, hPR_eq ▸ hnS_not⟩ · exact ⟨hR, hR_eq ▸ hnPS_not⟩ have hPS_not_g : P + S ∉ g.factorSupp := by unfold g; rw [LineProd.factorSupp_inv, LineProd.negPull_factorSupp, Set.mem_ofPred_eq] exact hnPS_not have hS_not_g : S ∉ g.factorSupp := by unfold g; rw [LineProd.factorSupp_inv, LineProd.negPull_factorSupp, Set.mem_ofPred_eq] exact hnS_not have hgeval : LineProd.evalDiv g (shiftedDiv P S) = LineProd.evalDiv f₂ (shiftedDiv P (-P - S)) := by rw [evalDiv_shiftedDiv g P S hS hPS hPS_not_g hS_not_g, evalDiv_shiftedDiv f₂ P (-P - S) hR hPR (hPR_eq ▸ hnS_not) (hR_eq ▸ hnPS_not)] have hdeg0 : f₂.degInf = 0 := shiftedMillerFunc_degInf hmP hS hPS simp only [g, LineProd.eval_inv, LineProd.negPull_eval, hdeg0, zpow_zero, one_mul, hR_eq] rw [div_eq_mul_inv, inv_inv, mul_comm, ← div_eq_mul_inv] have hsimp : P + -(P + S) = -S := by abel rw [hsimp] have hnum_eq_den : LineProd.evalDiv f₁ (shiftedDiv P S) = LineProd.evalDiv f₂ (shiftedDiv P (-P - S)) := by rw [LineProd.lineProd_evalDiv_eq_of_affDiv_eq f₁ g hg_div (shiftedDiv_degZero P S) hDQ_f1 hDQ_g, hgeval] unfold weilPairing change LineProd.evalDiv f₁ (shiftedDiv P S) / LineProd.evalDiv f₂ (shiftedDiv P (-P - S)) = 1 rw [hnum_eq_den, div_self (LineProd.evalDiv_ne_zero f₂ hDP_f2)] /-! ## Section 4: Galois Equivariance of the Weil Pairing -/ section GaloisEquivariance /-- Action of a field automorphism `σ : K ≃+* K` fixing `(a, b)` on `E(K)`. -/ def galoisAct {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) : (shortWeierstrass a b).toAffine.Point → (shortWeierstrass a b).toAffine.Point | .zero => .zero | .some x y h => .some (σ x) (σ y) (by rw [shortWeierstrass_nonsingular_iff] at h ⊢ refine ⟨by have := congr_arg σ h.1; simp only [map_pow, map_add, map_mul, hσa, hσb] at this; exact this, ?_⟩ rcases h.2 with hy | hx · left; intro h0; apply hy; apply σ.injective simpa [map_mul, map_ofNat, map_zero] using h0 · right; intro h0; apply hx; apply σ.injective simpa [map_add, map_mul, map_pow, map_ofNat, hσa, map_zero] using h0) omit [DecidableEq K] in lemma galoisAct_zero {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) : galoisAct σ hσa hσb 0 = 0 := rfl omit [DecidableEq K] in lemma galoisAct_eq_zero_iff {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (P : (shortWeierstrass a b).toAffine.Point) : galoisAct σ hσa hσb P = 0 ↔ P = 0 := by cases P <;> simp [galoisAct] omit [DecidableEq K] in lemma galoisAct_ne_zero {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) {P : (shortWeierstrass a b).toAffine.Point} (hP : P ≠ 0) : galoisAct σ hσa hσb P ≠ 0 := mt (galoisAct_eq_zero_iff σ hσa hσb P).mp hP omit [DecidableEq K] in lemma ptX_galoisAct {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (P : (shortWeierstrass a b).toAffine.Point) : ptX (galoisAct σ hσa hσb P) = σ (ptX P) := by cases P with | zero => simp [galoisAct, ptX] | some x y h => rfl omit [DecidableEq K] in lemma ptY_galoisAct {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (P : (shortWeierstrass a b).toAffine.Point) : ptY (galoisAct σ hσa hσb P) = σ (ptY P) := by cases P with | zero => simp [galoisAct, ptY] | some x y h => rfl lemma galoisAct_slope {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (_hσb : σ b = b) (x₁ x₂ y₁ y₂ : K) : (shortWeierstrass a b).toAffine.slope (σ x₁) (σ x₂) (σ y₁) (σ y₂) = σ ((shortWeierstrass a b).toAffine.slope x₁ x₂ y₁ y₂) := by by_cases hx : x₁ = x₂ · subst hx by_cases hy : y₁ = (shortWeierstrass a b).toAffine.negY x₁ y₂ · have hy' : σ y₁ = (shortWeierstrass a b).toAffine.negY (σ x₁) (σ y₂) := by rw [shortWeierstrass_negY] at hy ⊢; rw [hy, map_neg] rw [WeierstrassCurve.Affine.slope_of_Y_eq rfl hy, WeierstrassCurve.Affine.slope_of_Y_eq rfl hy', map_zero] · have hy' : σ y₁ ≠ (shortWeierstrass a b).toAffine.negY (σ x₁) (σ y₂) := by rw [shortWeierstrass_negY] at hy ⊢ intro h; exact hy (σ.injective (by simpa [map_neg] using h)) rw [WeierstrassCurve.Affine.slope_of_Y_ne rfl hy, WeierstrassCurve.Affine.slope_of_Y_ne rfl hy'] change (3 * σ x₁ ^ 2 + 2 * 0 * σ x₁ + a - 0 * σ y₁) / (σ y₁ - (-σ y₁ - 0 * σ x₁ - 0)) = σ ((3 * x₁ ^ 2 + 2 * 0 * x₁ + a - 0 * y₁) / (y₁ - (-y₁ - 0 * x₁ - 0))) simp only [map_div₀, map_add, map_sub, map_mul, map_pow, map_zero, map_ofNat, map_neg, hσa] · have hx' : σ x₁ ≠ σ x₂ := fun h => hx (σ.injective h) rw [WeierstrassCurve.Affine.slope_of_X_ne hx, WeierstrassCurve.Affine.slope_of_X_ne hx', map_div₀, map_sub, map_sub] lemma galoisAct_add {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (P Q : (shortWeierstrass a b).toAffine.Point) : galoisAct σ hσa hσb (P + Q) = galoisAct σ hσa hσb P + galoisAct σ hσa hσb Q := by cases P with | zero => change galoisAct σ hσa hσb (0 + Q) = 0 + galoisAct σ hσa hσb Q simp | some x₁ y₁ h₁ => cases Q with | zero => change galoisAct σ hσa hσb (.some x₁ y₁ h₁ + 0) = galoisAct σ hσa hσb (.some x₁ y₁ h₁) + 0 simp | some x₂ y₂ h₂ => by_cases hxy : x₁ = x₂ ∧ y₁ = (shortWeierstrass a b).toAffine.negY x₂ y₂ · have hxy' : σ x₁ = σ x₂ ∧ σ y₁ = (shortWeierstrass a b).toAffine.negY (σ x₂) (σ y₂) := by rw [shortWeierstrass_negY] at hxy ⊢ exact ⟨congr_arg σ hxy.1, by rw [hxy.2, map_neg]⟩ rw [WeierstrassCurve.Affine.Point.add_of_Y_eq hxy.1 hxy.2] change galoisAct σ hσa hσb 0 = _ rw [galoisAct_zero] exact (WeierstrassCurve.Affine.Point.add_of_Y_eq hxy'.1 hxy'.2).symm · have hxy' : ¬ (σ x₁ = σ x₂ ∧ σ y₁ = (shortWeierstrass a b).toAffine.negY (σ x₂) (σ y₂)) := by rw [shortWeierstrass_negY] at hxy ⊢ rintro ⟨hx, hy⟩ exact hxy ⟨σ.injective hx, σ.injective (by simpa [map_neg] using hy)⟩ rw [WeierstrassCurve.Affine.Point.add_some hxy] simp only [galoisAct] rw [WeierstrassCurve.Affine.Point.add_some hxy'] congr 1 · simp only [shortWeierstrass_addX, galoisAct_slope σ hσa hσb, map_sub, map_pow] · simp only [shortWeierstrass_addY, galoisAct_slope σ hσa hσb, map_neg, map_add, map_mul, map_sub, map_pow] lemma galoisAct_nsmul {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (k : ℕ) (P : (shortWeierstrass a b).toAffine.Point) : galoisAct σ hσa hσb (k • P) = k • galoisAct σ hσa hσb P := by induction k with | zero => simp [galoisAct_zero] | succ k ih => rw [succ_nsmul, succ_nsmul, galoisAct_add, ih] omit [DecidableEq K] in lemma galoisAct_injective {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) : Function.Injective (galoisAct σ hσa hσb) := by intro P Q hPQ cases P <;> cases Q <;> simp [galoisAct] at hPQ ⊢ exact hPQ /-- Galois map on elementary lines. -/ def ElemLine.mapGalois {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) : ElemLine a b → ElemLine a b | .nonVert P₁ P₂ h₁ h₂ h12 => .nonVert (galoisAct σ hσa hσb P₁) (galoisAct σ hσa hσb P₂) (galoisAct_ne_zero σ hσa hσb h₁) (galoisAct_ne_zero σ hσa hσb h₂) (by rw [← galoisAct_add]; exact galoisAct_ne_zero σ hσa hσb h12) | .vert P hP => .vert (galoisAct σ hσa hσb P) (galoisAct_ne_zero σ hσa hσb hP) lemma ElemLine.eval_mapGalois {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (L : ElemLine a b) (Q : (shortWeierstrass a b).toAffine.Point) : (L.mapGalois σ hσa hσb).eval (galoisAct σ hσa hσb Q) = σ (L.eval Q) := by cases L with | vert P hP => simp only [mapGalois, eval, ptX_galoisAct, map_sub] | nonVert P₁ P₂ h₁ h₂ h12 => simp only [mapGalois, eval, lineIntercept, lineSlope, ptX_galoisAct, ptY_galoisAct, galoisAct_slope σ hσa hσb, map_sub, map_add, map_mul] /-- Galois map on `LineProd`. -/ def LineProd.mapGalois {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (f : LineProd a b) : LineProd a b := f.map fun p => (p.1.mapGalois σ hσa hσb, p.2) lemma LineProd.eval_mapGalois {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (f : LineProd a b) (Q : (shortWeierstrass a b).toAffine.Point) : (f.mapGalois σ hσa hσb).eval (galoisAct σ hσa hσb Q) = σ (f.eval Q) := by induction f with | nil => simp [mapGalois, eval] | cons p fs ih => simp only [mapGalois, List.map_cons, eval_cons, ElemLine.eval_mapGalois, map_mul, map_zpow₀] change σ (p.1.eval Q) ^ p.2 * eval (mapGalois σ hσa hσb fs) (galoisAct σ hσa hσb Q) = _ rw [ih] lemma millerStep_mapGalois {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (P cur : (shortWeierstrass a b).toAffine.Point) : (millerStep P cur).mapGalois σ hσa hσb = millerStep (galoisAct σ hσa hσb P) (galoisAct σ hσa hσb cur) := by unfold millerStep have h1 : galoisAct σ hσa hσb P = 0 ↔ P = 0 := galoisAct_eq_zero_iff σ hσa hσb P have h2 : galoisAct σ hσa hσb cur = 0 ↔ cur = 0 := galoisAct_eq_zero_iff σ hσa hσb cur have h3 : galoisAct σ hσa hσb cur + galoisAct σ hσa hσb P = 0 ↔ cur + P = 0 := by rw [← galoisAct_add]; exact galoisAct_eq_zero_iff σ hσa hσb (cur + P) by_cases hP : P = 0 · rw [dif_pos hP, dif_pos (h1.mpr hP)]; rfl · rw [dif_neg hP, dif_neg (h1.not.mpr hP)] by_cases hc : cur = 0 · rw [dif_pos hc, dif_pos (h2.mpr hc)]; rfl · rw [dif_neg hc, dif_neg (h2.not.mpr hc)] by_cases hcp : cur + P = 0 · rw [dif_pos hcp, dif_pos (h3.mpr hcp)]; rfl · rw [dif_neg hcp, dif_neg (h3.not.mpr hcp)] simp [LineProd.mapGalois, ElemLine.mapGalois, galoisAct_add] lemma millerLoop_mapGalois {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (P : (shortWeierstrass a b).toAffine.Point) (k : ℕ) : (millerLoop P k).mapGalois σ hσa hσb = millerLoop (galoisAct σ hσa hσb P) k := by induction k with | zero => rfl | succ k ih => simp only [millerLoop, LineProd.mapGalois, List.map_append] change (millerLoop P k).mapGalois σ hσa hσb ++ (millerStep P (k • P)).mapGalois σ hσa hσb = _ rw [ih, millerStep_mapGalois, galoisAct_nsmul] lemma shiftedMillerFunc_mapGalois {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (m : ℕ) (P R : (shortWeierstrass a b).toAffine.Point) (hR : R ≠ 0) (hPR : P + R ≠ 0) : (shiftedMillerFunc m P R hR hPR).mapGalois σ hσa hσb = shiftedMillerFunc m (galoisAct σ hσa hσb P) (galoisAct σ hσa hσb R) (galoisAct_ne_zero σ hσa hσb hR) (by rw [← galoisAct_add]; exact galoisAct_ne_zero σ hσa hσb hPR) := by unfold shiftedMillerFunc millerFunc have h1 : galoisAct σ hσa hσb P = 0 ↔ P = 0 := galoisAct_eq_zero_iff σ hσa hσb P by_cases hP : P = 0 · rw [dif_pos hP, dif_pos (h1.mpr hP)]; rfl · rw [dif_neg hP, dif_neg (h1.not.mpr hP)] simp only [LineProd.mapGalois, List.map_append, List.map_cons, List.map_nil] congr 1 · exact millerLoop_mapGalois σ hσa hσb P m · simp [ElemLine.mapGalois, galoisAct_add] lemma evalDiv_shiftedDiv_galois {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (f : LineProd a b) (P R : (shortWeierstrass a b).toAffine.Point) : LineProd.evalDiv (f.mapGalois σ hσa hσb) (shiftedDiv (galoisAct σ hσa hσb P) (galoisAct σ hσa hσb R)) = σ (LineProd.evalDiv f (shiftedDiv P R)) := by unfold shiftedDiv LineProd.evalDiv rw [← galoisAct_add] by_cases hPR : P + R = R · rw [hPR, sub_self, sub_self, Finsupp.prod_zero_index, Finsupp.prod_zero_index, map_one] · have hPR' : galoisAct σ hσa hσb (P + R) ≠ galoisAct σ hσa hσb R := fun h => hPR (galoisAct_injective σ hσa hσb h) have hsupp : (Finsupp.single (P + R) (1 : ℤ) - Finsupp.single R (1 : ℤ)).support = {P + R, R} := by ext X; simp only [Finsupp.mem_support_iff, Finsupp.sub_apply, Finsupp.single_apply, Finset.mem_insert, Finset.mem_singleton] by_cases h1 : P + R = X · subst h1; simp [Ne.symm hPR] · by_cases h2 : R = X · subst h2; simp [hPR] · simp [h1, h2, Ne.symm h1, Ne.symm h2] have hsupp' : (Finsupp.single (galoisAct σ hσa hσb (P + R)) (1 : ℤ) - Finsupp.single (galoisAct σ hσa hσb R) (1 : ℤ)).support = {galoisAct σ hσa hσb (P + R), galoisAct σ hσa hσb R} := by ext X; simp only [Finsupp.mem_support_iff, Finsupp.sub_apply, Finsupp.single_apply, Finset.mem_insert, Finset.mem_singleton] by_cases h1 : galoisAct σ hσa hσb (P + R) = X · subst h1; simp [Ne.symm hPR'] · by_cases h2 : galoisAct σ hσa hσb R = X · subst h2; simp [hPR'] · simp [h1, h2, Ne.symm h1, Ne.symm h2] unfold Finsupp.prod dsimp only rw [hsupp, hsupp', Finset.prod_pair hPR, Finset.prod_pair hPR', map_mul] simp only [Finsupp.sub_apply, Finsupp.single_apply, ↓reduceIte, if_neg hPR, if_neg (Ne.symm hPR), if_neg hPR', if_neg (Ne.symm hPR'), sub_zero, zero_sub, zpow_one, zpow_neg_one, map_inv₀, LineProd.eval_mapGalois] /-- **Theorem 7 — Galois Equivariance**: For EVERY field automorphism `σ : K ≃+* K` fixing `(a, b)`, `e_m(σ(P), σ(Q); σ(R), σ(S)) = σ(e_m(P, Q; R, S))`! -/ theorem weilPairing_galois_equivariant {a b : K} (σ : K ≃+* K) (hσa : σ a = a) (hσb : σ b = b) (m : ℕ) (P Q R S : (shortWeierstrass a b).toAffine.Point) (hR : R ≠ 0) (hPR : P + R ≠ 0) (hS : S ≠ 0) (hQS : Q + S ≠ 0) : weilPairing m (galoisAct σ hσa hσb P) (galoisAct σ hσa hσb Q) (galoisAct σ hσa hσb R) (galoisAct σ hσa hσb S) (galoisAct_ne_zero σ hσa hσb hR) (by rw [← galoisAct_add]; exact galoisAct_ne_zero σ hσa hσb hPR) (galoisAct_ne_zero σ hσa hσb hS) (by rw [← galoisAct_add]; exact galoisAct_ne_zero σ hσa hσb hQS) = σ (weilPairing m P Q R S hR hPR hS hQS) := by unfold weilPairing rw [← shiftedMillerFunc_mapGalois σ hσa hσb m P R hR hPR, ← shiftedMillerFunc_mapGalois σ hσa hσb m Q S hS hQS, evalDiv_shiftedDiv_galois, evalDiv_shiftedDiv_galois, map_div₀] end GaloisEquivariance /-! ## Section 5: Concrete Non-Degeneracy Witnesses over `𝔽₁₃` (`e₂` and `e₃`) -/ section NonDegeneracyWitnesses local instance instFactPrime13 : Fact (Nat.Prime 13) := ⟨by decide⟩ private lemma div13_eq {x y z : ZMod 13} (hy : y ≠ 0) (h : x = z * y) : x / y = z := (div_eq_iff hy).mpr h private lemma inv13_eq {x y : ZMod 13} (h : x * y = 1) : x⁻¹ = y := inv_eq_of_mul_eq_one_right h private lemma slope13_ne {a b x₁ x₂ y₁ y₂ ℓ : ZMod 13} (hx : x₁ ≠ x₂) (h : y₁ - y₂ = ℓ * (x₁ - x₂)) : (shortWeierstrass a b).toAffine.slope x₁ x₂ y₁ y₂ = ℓ := by rw [WeierstrassCurve.Affine.slope_of_X_ne hx] exact div13_eq (sub_ne_zero.mpr hx) h private lemma slope13_eq {a b x y ℓ : ZMod 13} (hy : 2 * y ≠ 0) (h : 3 * x ^ 2 + a = ℓ * (2 * y)) : (shortWeierstrass a b).toAffine.slope x x y y = ℓ := by have hy' : y ≠ (shortWeierstrass a b).toAffine.negY x y := by rw [shortWeierstrass_negY]; intro h0; apply hy; linear_combination h0 rw [WeierstrassCurve.Affine.slope_of_Y_ne rfl hy'] change (3 * x ^ 2 + 2 * 0 * x + a - 0 * y) / (y - (-y - 0 * x - 0)) = ℓ have h1 : 3 * x ^ 2 + 2 * 0 * x + a - 0 * y = 3 * x ^ 2 + a := by ring have h2 : y - (-y - 0 * x - 0) = 2 * y := by ring rw [h1, h2] exact div13_eq hy h private lemma add_some_eq13 {a b x₁ y₁ x₂ y₂ x₃ y₃ ℓ : ZMod 13} {h₁ : (shortWeierstrass a b).toAffine.Nonsingular x₁ y₁} {h₂ : (shortWeierstrass a b).toAffine.Nonsingular x₂ y₂} {h₃ : (shortWeierstrass a b).toAffine.Nonsingular x₃ y₃} (hxy : ¬ (x₁ = x₂ ∧ y₁ = -y₂)) (hℓ : (shortWeierstrass a b).toAffine.slope x₁ x₂ y₁ y₂ = ℓ) (hx : ℓ ^ 2 - x₁ - x₂ = x₃) (hy : -(ℓ * (x₃ - x₁) + y₁) = y₃) : WeierstrassCurve.Affine.Point.some x₁ y₁ h₁ + .some x₂ y₂ h₂ = .some x₃ y₃ h₃ := by have hxy' : ¬ (x₁ = x₂ ∧ y₁ = (shortWeierstrass a b).toAffine.negY x₂ y₂) := by rwa [shortWeierstrass_negY] rw [WeierstrassCurve.Affine.Point.add_some hxy'] congr 1 · rw [shortWeierstrass_addX, hℓ, hx] · rw [shortWeierstrass_addY, hℓ, hx, hy] private lemma neg_some_eq13 {a b x y y' : ZMod 13} {h : (shortWeierstrass a b).toAffine.Nonsingular x y} {h' : (shortWeierstrass a b).toAffine.Nonsingular x y'} (hy : -y = y') : -(WeierstrassCurve.Affine.Point.some x y h) = .some x y' h' := by rw [WeierstrassCurve.Affine.Point.neg_some] congr 1 rw [shortWeierstrass_negY, hy] private lemma add_some_zero13 {a b x₁ y₁ x₂ y₂ : ZMod 13} {h₁ : (shortWeierstrass a b).toAffine.Nonsingular x₁ y₁} {h₂ : (shortWeierstrass a b).toAffine.Nonsingular x₂ y₂} (hx : x₁ = x₂) (hy : y₁ = -y₂) : WeierstrassCurve.Affine.Point.some x₁ y₁ h₁ + .some x₂ y₂ h₂ = 0 := WeierstrassCurve.Affine.Point.add_of_Y_eq hx (by rw [shortWeierstrass_negY]; exact hy) /-- **Theorem 8 — Non-Degeneracy Witness for `e₂` over `𝔽₁₃`**: On `E : y² = x³ + 9 x = x(x - 2)(x + 2)` over `𝔽₁₃`, the 2-torsion points `P = (0, 0)` and `Q = (2, 0)` satisfy `2 • P = 0`, `2 • Q = 0`, and with shifts `R = (1, 6)`, `S = (1, 7)`: `e₂(P, Q; R, S) = -1 ≠ 1` (and `(-1)² = 1`). -/ theorem weilPairing_e2_nondegenerate : ∃ (P Q R S : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Point) (hR : R ≠ 0) (hPR : P + R ≠ 0) (hS : S ≠ 0) (hQS : Q + S ≠ 0), 2 • P = 0 ∧ 2 • Q = 0 ∧ weilPairing 2 P Q R S hR hPR hS hQS = -1 ∧ (-1 : ZMod 13) ≠ 1 := by have hPns : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Nonsingular 0 0 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hQns : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Nonsingular 2 0 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hRns : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Nonsingular 1 6 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hSns : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Nonsingular 1 7 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hPRns : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Nonsingular 9 11 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hQSns : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Nonsingular 7 9 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) let P : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Point := .some 0 0 hPns let Q : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Point := .some 2 0 hQns let R : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Point := .some 1 6 hRns let S : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Point := .some 1 7 hSns let PR : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Point := .some 9 11 hPRns let QS : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Point := .some 7 9 hQSns have hslPR : (shortWeierstrass (9 : ZMod 13) 0).toAffine.slope 0 1 0 6 = 6 := slope13_ne (by decide) (by decide) have hslQS : (shortWeierstrass (9 : ZMod 13) 0).toAffine.slope 2 1 0 7 = 6 := slope13_ne (by decide) (by decide) have hP2 : 2 • P = 0 := by rw [two_nsmul]; exact add_some_zero13 rfl (by decide) have hQ2 : 2 • Q = 0 := by rw [two_nsmul]; exact add_some_zero13 rfl (by decide) have hPR_eq : P + R = PR := add_some_eq13 (by decide) hslPR (by decide) (by decide) have hQS_eq : Q + S = QS := add_some_eq13 (by decide) hslQS (by decide) (by decide) have hR0 : R ≠ 0 := by simp [R] have hPR0 : P + R ≠ 0 := by rw [hPR_eq]; simp [PR] have hS0 : S ≠ 0 := by simp [S] have hQS0 : Q + S ≠ 0 := by rw [hQS_eq]; simp [QS] refine ⟨P, Q, R, S, hR0, hPR0, hS0, hQS0, hP2, hQ2, ?_, by decide⟩ have hP0 : P ≠ 0 := by simp [P] have hQ0 : Q ≠ 0 := by simp [Q] have hPP : P + P = 0 := by simpa [two_nsmul] using hP2 have hQQ : Q + Q = 0 := by simpa [two_nsmul] using hQ2 have hfP : shiftedMillerFunc 2 P R hR0 hPR0 = [(ElemLine.vert P hP0, (1 : ℤ)), (ElemLine.vert (P + R) hPR0, 2), (ElemLine.nonVert P R hP0 hR0 hPR0, -2)] := by unfold shiftedMillerFunc millerFunc simp only [millerLoop, millerStep, zero_smul, one_nsmul, hP0, hPP, ↓reduceDIte, List.nil_append, List.cons_append] rfl have hfQ : shiftedMillerFunc 2 Q S hS0 hQS0 = [(ElemLine.vert Q hQ0, (1 : ℤ)), (ElemLine.vert (Q + S) hQS0, 2), (ElemLine.nonVert Q S hQ0 hS0 hQS0, -2)] := by unfold shiftedMillerFunc millerFunc simp only [millerLoop, millerStep, zero_smul, one_nsmul, hQ0, hQQ, ↓reduceDIte, List.nil_append, List.cons_append] rfl have hnPR : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Nonsingular 9 2 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hnQS : (shortWeierstrass (9 : ZMod 13) 0).toAffine.Nonsingular 7 4 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hnegP : -P = P := neg_some_eq13 (by decide) have hnegQ : -Q = Q := neg_some_eq13 (by decide) have hnegPR : -(P + R) = .some 9 2 hnPR := by rw [hPR_eq]; exact neg_some_eq13 (by decide) have hnegQS : -(Q + S) = .some 7 4 hnQS := by rw [hQS_eq]; exact neg_some_eq13 (by decide) have hQS_notP : Q + S ∉ (shiftedMillerFunc 2 P R hR0 hPR0).factorSupp := by rw [hfP]; rintro ⟨p, hp, hmem⟩ simp only [List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegP, hQS_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [P, QS, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hPR_eq, hQS_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; (try rw [ptX_neg] at hx); dsimp only [PR, QS, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegPR, hQS_eq] at hmem rcases hmem with h | h | h <;> (have hx := congr_arg ptX h; dsimp only [P, R, QS, ptX] at hx; exact absurd hx (by decide)) have hS_notP : S ∉ (shiftedMillerFunc 2 P R hR0 hPR0).factorSupp := by rw [hfP]; rintro ⟨p, hp, hmem⟩ simp only [List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegP] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [P, S, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hPR_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; (try rw [ptX_neg] at hx); dsimp only [PR, S, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegPR] at hmem rcases hmem with h | h | h · have hx := congr_arg ptX h; dsimp only [P, S, ptX] at hx; exact absurd hx (by decide) · have hy := congr_arg ptY h; dsimp only [R, S, ptY] at hy; exact absurd hy (by decide) · have hx := congr_arg ptX h; dsimp only [S, ptX] at hx; exact absurd hx (by decide) have hPR_notQ : P + R ∉ (shiftedMillerFunc 2 Q S hS0 hQS0).factorSupp := by rw [hfQ]; rintro ⟨p, hp, hmem⟩ simp only [List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegQ, hPR_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [Q, PR, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hQS_eq, hPR_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; (try rw [ptX_neg] at hx); dsimp only [QS, PR, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegQS, hPR_eq] at hmem rcases hmem with h | h | h <;> (have hx := congr_arg ptX h; dsimp only [Q, S, PR, ptX] at hx; exact absurd hx (by decide)) have hR_notQ : R ∉ (shiftedMillerFunc 2 Q S hS0 hQS0).factorSupp := by rw [hfQ]; rintro ⟨p, hp, hmem⟩ simp only [List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegQ] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [Q, R, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hQS_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; (try rw [ptX_neg] at hx); dsimp only [QS, R, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegQS] at hmem rcases hmem with h | h | h · have hx := congr_arg ptX h; dsimp only [Q, R, ptX] at hx; exact absurd hx (by decide) · have hy := congr_arg ptY h; dsimp only [R, S, ptY] at hy; exact absurd hy (by decide) · have hx := congr_arg ptX h; dsimp only [R, ptX] at hx; exact absurd hx (by decide) unfold weilPairing rw [evalDiv_shiftedDiv _ Q S hS0 hQS0 hQS_notP hS_notP, evalDiv_shiftedDiv _ P R hR0 hPR0 hPR_notQ hR_notQ, hfP, hfQ] simp only [LineProd.eval_cons, LineProd.eval_nil, mul_one, ElemLine.eval, ElemLine.lineIntercept, ElemLine.lineSlope, hPR_eq, hQS_eq] change (((7 - 0 : ZMod 13) ^ (1 : ℤ) * ((7 - 9) ^ (2 : ℤ) * ((9 - ((shortWeierstrass 9 0).toAffine.slope 0 1 0 6 * 7 + (0 - (shortWeierstrass 9 0).toAffine.slope 0 1 0 6 * 0))) ^ (-2 : ℤ)))) / ((1 - 0) ^ (1 : ℤ) * ((1 - 9) ^ (2 : ℤ) * ((7 - ((shortWeierstrass 9 0).toAffine.slope 0 1 0 6 * 1 + (0 - (shortWeierstrass 9 0).toAffine.slope 0 1 0 6 * 0))) ^ (-2 : ℤ))))) / (((9 - 2) ^ (1 : ℤ) * ((9 - 7) ^ (2 : ℤ) * ((11 - ((shortWeierstrass 9 0).toAffine.slope 2 1 0 7 * 9 + (0 - (shortWeierstrass 9 0).toAffine.slope 2 1 0 7 * 2))) ^ (-2 : ℤ)))) / ((1 - 2) ^ (1 : ℤ) * ((1 - 7) ^ (2 : ℤ) * ((6 - ((shortWeierstrass 9 0).toAffine.slope 2 1 0 7 * 1 + (0 - (shortWeierstrass 9 0).toAffine.slope 2 1 0 7 * 2))) ^ (-2 : ℤ))))) = -1 rw [hslPR, hslQS] simp only [zpow_one, zpow_neg, show (2 : ℤ) = ((2 : ℕ) : ℤ) from rfl, zpow_natCast] have h1 : ((7 - 0 : ZMod 13) * ((7 - 9) ^ 2 * ((9 - (6 * 7 + (0 - 6 * 0))) ^ 2)⁻¹)) / ((1 - 0) * ((1 - 9) ^ 2 * ((7 - (6 * 1 + (0 - 6 * 0))) ^ 2)⁻¹)) = 5 := by have ha : ((9 - (6 * 7 + (0 - 6 * 0)) : ZMod 13) ^ 2)⁻¹ = 4 := inv13_eq (by decide) have hb : ((7 - (6 * 1 + (0 - 6 * 0)) : ZMod 13) ^ 2)⁻¹ = 1 := inv13_eq (by decide) rw [ha, hb]; exact div13_eq (by decide) (by decide) have h2 : ((9 - 2 : ZMod 13) * ((9 - 7) ^ 2 * ((11 - (6 * 9 + (0 - 6 * 2))) ^ 2)⁻¹)) / ((1 - 2) * ((1 - 7) ^ 2 * ((6 - (6 * 1 + (0 - 6 * 2))) ^ 2)⁻¹)) = 8 := by have ha : ((11 - (6 * 9 + (0 - 6 * 2)) : ZMod 13) ^ 2)⁻¹ = 12 := inv13_eq (by decide) have hb : ((6 - (6 * 1 + (0 - 6 * 2)) : ZMod 13) ^ 2)⁻¹ = 1 := inv13_eq (by decide) rw [ha, hb]; exact div13_eq (by decide) (by decide) rw [h1, h2] exact div13_eq (by decide) (by decide) /-- **Theorem 9 — Non-Degeneracy Witness for `e₃` over `𝔽₁₃`**: On `E : y² = x³ + 7 x` over `𝔽₁₃`, the 3-torsion points `P = (3, 3)` and `Q = (4, 1)` satisfy `3 • P = 0`, `3 • Q = 0`, and with shifts `R = (0, 0)`, `S = (2, 3)`: `e₃(P, Q; R, S) = 9 ≠ 1` with `9³ = 1` (a primitive cube root of unity in `𝔽₁₃×`). -/ theorem weilPairing_e3_nondegenerate : ∃ (P Q R S : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Point) (hR : R ≠ 0) (hPR : P + R ≠ 0) (hS : S ≠ 0) (hQS : Q + S ≠ 0), 3 • P = 0 ∧ 3 • Q = 0 ∧ weilPairing 3 P Q R S hR hPR hS hQS = 9 ∧ (9 : ZMod 13) ≠ 1 ∧ (9 : ZMod 13) ^ 3 = 1 := by have hPns : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Nonsingular 3 3 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have h2Pns : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Nonsingular 3 10 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hQns : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Nonsingular 4 1 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have h2Qns : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Nonsingular 4 12 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hRns : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Nonsingular 0 0 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hSns : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Nonsingular 2 3 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hPRns : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Nonsingular 11 2 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hQSns : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Nonsingular 8 3 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) let P : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Point := .some 3 3 hPns let P2 : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Point := .some 3 10 h2Pns let Q : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Point := .some 4 1 hQns let Q2 : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Point := .some 4 12 h2Qns let R : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Point := .some 0 0 hRns let S : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Point := .some 2 3 hSns let PR : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Point := .some 11 2 hPRns let QS : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Point := .some 8 3 hQSns have hslPP : (shortWeierstrass (7 : ZMod 13) 0).toAffine.slope 3 3 3 3 = 10 := slope13_eq (by decide) (by decide) have hslQQ : (shortWeierstrass (7 : ZMod 13) 0).toAffine.slope 4 4 1 1 = 8 := slope13_eq (by decide) (by decide) have hslPR : (shortWeierstrass (7 : ZMod 13) 0).toAffine.slope 3 0 3 0 = 1 := slope13_ne (by decide) (by decide) have hslQS : (shortWeierstrass (7 : ZMod 13) 0).toAffine.slope 4 2 1 3 = 12 := slope13_ne (by decide) (by decide) have hPP : P + P = P2 := add_some_eq13 (by decide) hslPP (by decide) (by decide) have h2P_eq : 2 • P = P2 := by rw [two_nsmul, hPP] have hP3 : 3 • P = 0 := by rw [show (3 : ℕ) • P = 2 • P + P from succ_nsmul P 2, h2P_eq] exact add_some_zero13 rfl (by decide) have hQQ : Q + Q = Q2 := add_some_eq13 (by decide) hslQQ (by decide) (by decide) have h2Q_eq : 2 • Q = Q2 := by rw [two_nsmul, hQQ] have hQ3 : 3 • Q = 0 := by rw [show (3 : ℕ) • Q = 2 • Q + Q from succ_nsmul Q 2, h2Q_eq] exact add_some_zero13 rfl (by decide) have hPR_eq : P + R = PR := add_some_eq13 (by decide) hslPR (by decide) (by decide) have hQS_eq : Q + S = QS := add_some_eq13 (by decide) hslQS (by decide) (by decide) have hR0 : R ≠ 0 := by simp [R] have hPR0 : P + R ≠ 0 := by rw [hPR_eq]; simp [PR] have hS0 : S ≠ 0 := by simp [S] have hQS0 : Q + S ≠ 0 := by rw [hQS_eq]; simp [QS] refine ⟨P, Q, R, S, hR0, hPR0, hS0, hQS0, hP3, hQ3, ?_, by decide, by decide⟩ have hP0 : P ≠ 0 := by simp [P] have hQ0 : Q ≠ 0 := by simp [Q] have hPP0 : P + P ≠ 0 := by rw [hPP]; simp [P2] have hQQ0 : Q + Q ≠ 0 := by rw [hQQ]; simp [Q2] have h2P0 : 2 • P ≠ 0 := by rw [h2P_eq]; simp [P2] have h2Q0 : 2 • Q ≠ 0 := by rw [h2Q_eq]; simp [Q2] have h2PP : 2 • P + P = 0 := by simpa [succ_nsmul] using hP3 have h2QQ : 2 • Q + Q = 0 := by simpa [succ_nsmul] using hQ3 have hfP : shiftedMillerFunc 3 P R hR0 hPR0 = [(ElemLine.nonVert P P hP0 hP0 hPP0, (1 : ℤ)), (ElemLine.vert (P + P) hPP0, -1), (ElemLine.vert (2 • P) h2P0, 1), (ElemLine.vert (P + R) hPR0, 3), (ElemLine.nonVert P R hP0 hR0 hPR0, -3)] := by unfold shiftedMillerFunc millerFunc simp only [millerLoop, millerStep, zero_smul, one_nsmul, hP0, hPP0, h2P0, h2PP, ↓reduceDIte, List.nil_append, List.cons_append] rfl have hfQ : shiftedMillerFunc 3 Q S hS0 hQS0 = [(ElemLine.nonVert Q Q hQ0 hQ0 hQQ0, (1 : ℤ)), (ElemLine.vert (Q + Q) hQQ0, -1), (ElemLine.vert (2 • Q) h2Q0, 1), (ElemLine.vert (Q + S) hQS0, 3), (ElemLine.nonVert Q S hQ0 hS0 hQS0, -3)] := by unfold shiftedMillerFunc millerFunc simp only [millerLoop, millerStep, zero_smul, one_nsmul, hQ0, hQQ0, h2Q0, h2QQ, ↓reduceDIte, List.nil_append, List.cons_append] rfl have hnPR : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Nonsingular 11 11 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hnQS : (shortWeierstrass (7 : ZMod 13) 0).toAffine.Nonsingular 8 10 := (shortWeierstrass_nonsingular_iff _ _ _ _).mpr (by decide) have hnegP2 : -P2 = P := neg_some_eq13 (by decide) have hnegQ2 : -Q2 = Q := neg_some_eq13 (by decide) have hnegPR : -(P + R) = .some 11 11 hnPR := by rw [hPR_eq]; exact neg_some_eq13 (by decide) have hnegQS : -(Q + S) = .some 8 10 hnQS := by rw [hQS_eq]; exact neg_some_eq13 (by decide) have hQS_notP : Q + S ∉ (shiftedMillerFunc 3 P R hR0 hPR0).factorSupp := by rw [hfP]; rintro ⟨p, hp, hmem⟩ simp only [List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl | rfl | rfl · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hPP, hnegP2, hQS_eq] at hmem rcases hmem with h | h | h <;> (have hx := congr_arg ptX h; dsimp only [P, QS, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hPP, hnegP2, hQS_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [P, P2, QS, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, h2P_eq, hnegP2, hQS_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [P, P2, QS, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hPR_eq, hQS_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; (try rw [ptX_neg] at hx); dsimp only [PR, QS, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegPR, hQS_eq] at hmem rcases hmem with h | h | h <;> (have hx := congr_arg ptX h; dsimp only [P, R, QS, ptX] at hx; exact absurd hx (by decide)) have hS_notP : S ∉ (shiftedMillerFunc 3 P R hR0 hPR0).factorSupp := by rw [hfP]; rintro ⟨p, hp, hmem⟩ simp only [List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl | rfl | rfl · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hPP, hnegP2] at hmem rcases hmem with h | h | h <;> (have hx := congr_arg ptX h; dsimp only [P, S, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hPP, hnegP2] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [P, P2, S, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, h2P_eq, hnegP2] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [P, P2, S, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hPR_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; (try rw [ptX_neg] at hx); dsimp only [PR, S, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegPR] at hmem rcases hmem with h | h | h <;> (have hx := congr_arg ptX h; dsimp only [P, R, S, ptX] at hx; exact absurd hx (by decide)) have hPR_notQ : P + R ∉ (shiftedMillerFunc 3 Q S hS0 hQS0).factorSupp := by rw [hfQ]; rintro ⟨p, hp, hmem⟩ simp only [List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl | rfl | rfl · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hQQ, hnegQ2, hPR_eq] at hmem rcases hmem with h | h | h <;> (have hx := congr_arg ptX h; dsimp only [Q, PR, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hQQ, hnegQ2, hPR_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [Q, Q2, PR, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, h2Q_eq, hnegQ2, hPR_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [Q, Q2, PR, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hQS_eq, hPR_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; (try rw [ptX_neg] at hx); dsimp only [QS, PR, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegQS, hPR_eq] at hmem rcases hmem with h | h | h <;> (have hx := congr_arg ptX h; dsimp only [Q, S, PR, ptX] at hx; exact absurd hx (by decide)) have hR_notQ : R ∉ (shiftedMillerFunc 3 Q S hS0 hQS0).factorSupp := by rw [hfQ]; rintro ⟨p, hp, hmem⟩ simp only [List.mem_cons, List.not_mem_nil, or_false] at hp rcases hp with rfl | rfl | rfl | rfl | rfl · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hQQ, hnegQ2] at hmem rcases hmem with h | h | h <;> (have hx := congr_arg ptX h; dsimp only [Q, R, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hQQ, hnegQ2] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [Q, Q2, R, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, h2Q_eq, hnegQ2] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; dsimp only [Q, Q2, R, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hQS_eq] at hmem rcases hmem with h | h <;> (have hx := congr_arg ptX h; (try rw [ptX_neg] at hx); dsimp only [QS, R, ptX] at hx; exact absurd hx (by decide)) · simp only [ElemLine.zeros, List.mem_cons, List.not_mem_nil, or_false, hnegQS] at hmem rcases hmem with h | h | h <;> (have hx := congr_arg ptX h; dsimp only [Q, S, R, ptX] at hx; exact absurd hx (by decide)) unfold weilPairing rw [evalDiv_shiftedDiv _ Q S hS0 hQS0 hQS_notP hS_notP, evalDiv_shiftedDiv _ P R hR0 hPR0 hPR_notQ hR_notQ, hfP, hfQ] simp only [LineProd.eval_cons, LineProd.eval_nil, mul_one, ElemLine.eval, ElemLine.lineIntercept, ElemLine.lineSlope, hPP, h2P_eq, hQQ, h2Q_eq, hPR_eq, hQS_eq] change (((3 - ((shortWeierstrass 7 0).toAffine.slope 3 3 3 3 * 8 + (3 - (shortWeierstrass 7 0).toAffine.slope 3 3 3 3 * 3)) : ZMod 13) ^ (1 : ℤ) * ((8 - 3) ^ (-1 : ℤ) * ((8 - 3) ^ (1 : ℤ) * ((8 - 11) ^ (3 : ℤ) * ((3 - ((shortWeierstrass 7 0).toAffine.slope 3 0 3 0 * 8 + (3 - (shortWeierstrass 7 0).toAffine.slope 3 0 3 0 * 3))) ^ (-3 : ℤ)))))) / ((3 - ((shortWeierstrass 7 0).toAffine.slope 3 3 3 3 * 2 + (3 - (shortWeierstrass 7 0).toAffine.slope 3 3 3 3 * 3))) ^ (1 : ℤ) * ((2 - 3) ^ (-1 : ℤ) * ((2 - 3) ^ (1 : ℤ) * ((2 - 11) ^ (3 : ℤ) * ((3 - ((shortWeierstrass 7 0).toAffine.slope 3 0 3 0 * 2 + (3 - (shortWeierstrass 7 0).toAffine.slope 3 0 3 0 * 3))) ^ (-3 : ℤ))))))) / (((2 - ((shortWeierstrass 7 0).toAffine.slope 4 4 1 1 * 11 + (1 - (shortWeierstrass 7 0).toAffine.slope 4 4 1 1 * 4))) ^ (1 : ℤ) * ((11 - 4) ^ (-1 : ℤ) * ((11 - 4) ^ (1 : ℤ) * ((11 - 8) ^ (3 : ℤ) * ((2 - ((shortWeierstrass 7 0).toAffine.slope 4 2 1 3 * 11 + (1 - (shortWeierstrass 7 0).toAffine.slope 4 2 1 3 * 4))) ^ (-3 : ℤ)))))) / ((0 - ((shortWeierstrass 7 0).toAffine.slope 4 4 1 1 * 0 + (1 - (shortWeierstrass 7 0).toAffine.slope 4 4 1 1 * 4))) ^ (1 : ℤ) * ((0 - 4) ^ (-1 : ℤ) * ((0 - 4) ^ (1 : ℤ) * ((0 - 8) ^ (3 : ℤ) * ((0 - ((shortWeierstrass 7 0).toAffine.slope 4 2 1 3 * 0 + (1 - (shortWeierstrass 7 0).toAffine.slope 4 2 1 3 * 4))) ^ (-3 : ℤ))))))) = 9 rw [hslPP, hslQQ, hslPR, hslQS] simp only [zpow_one, zpow_neg, show (3 : ℤ) = ((3 : ℕ) : ℤ) from rfl, zpow_natCast] have h1 : (((3 - (10 * 8 + (3 - 10 * 3)) : ZMod 13) * ((8 - 3)⁻¹ * ((8 - 3) * ((8 - 11) ^ 3 * ((3 - (1 * 8 + (3 - 1 * 3))) ^ 3)⁻¹)))) / ((3 - (10 * 2 + (3 - 10 * 3))) * ((2 - 3)⁻¹ * ((2 - 3) * ((2 - 11) ^ 3 * ((3 - (1 * 2 + (3 - 1 * 3))) ^ 3)⁻¹))))) = 12 := by rw [inv_mul_cancel_left₀ (by decide : (8 - 3 : ZMod 13) ≠ 0), inv_mul_cancel_left₀ (by decide : (2 - 3 : ZMod 13) ≠ 0)] have ha : ((3 - (1 * 8 + (3 - 1 * 3)) : ZMod 13) ^ 3)⁻¹ = 8 := inv13_eq (by decide) have hb : ((3 - (1 * 2 + (3 - 1 * 3)) : ZMod 13) ^ 3)⁻¹ = 1 := inv13_eq (by decide) rw [ha, hb]; exact div13_eq (by decide) (by decide) have h2 : (((2 - (8 * 11 + (1 - 8 * 4)) : ZMod 13) * ((11 - 4)⁻¹ * ((11 - 4) * ((11 - 8) ^ 3 * ((2 - (12 * 11 + (1 - 12 * 4))) ^ 3)⁻¹)))) / ((0 - (8 * 0 + (1 - 8 * 4))) * ((0 - 4)⁻¹ * ((0 - 4) * ((0 - 8) ^ 3 * ((0 - (12 * 0 + (1 - 12 * 4))) ^ 3)⁻¹))))) = 10 := by rw [inv_mul_cancel_left₀ (by decide : (11 - 4 : ZMod 13) ≠ 0), inv_mul_cancel_left₀ (by decide : (0 - 4 : ZMod 13) ≠ 0)] have ha : ((2 - (12 * 11 + (1 - 12 * 4)) : ZMod 13) ^ 3)⁻¹ = 8 := inv13_eq (by decide) have hb : ((0 - (12 * 0 + (1 - 12 * 4)) : ZMod 13) ^ 3)⁻¹ = 8 := inv13_eq (by decide) rw [ha, hb]; exact div13_eq (by decide) (by decide) rw [h1, h2] exact div13_eq (by decide) (by decide) end NonDegeneracyWitnesses end MillerAndWeilPairing /-! ## Axiom Verification -/ #print axioms ElemLine.elemLine_weil_reciprocity #print axioms LineProd.lineProd_weil_reciprocity #print axioms LineProd.lineProd_weil_reciprocity_degZero #print axioms LineProd.exists_const_of_affDiv_eq_zero #print axioms LineProd.lineProd_evalDiv_eq_of_affDiv_eq #print axioms millerFunc_affDiv #print axioms shiftedMillerFunc_affDiv #print axioms weilPairing_skew_symm #print axioms weilPairing_pow_eq_one #print axioms weilPairing_shift_indep_right #print axioms weilPairing_bilinear_left #print axioms weilPairing_bilinear_right #print axioms weilPairing_alternating #print axioms weilPairing_galois_equivariant #print axioms weilPairing_e2_nondegenerate #print axioms weilPairing_e3_nondegenerate end EllipticWeilPairing