Prove2Me
Navigate
DiscoverCollectionsFormalpediaBlogsUsersMomentumMy Missions+
Prove2Me
⌕
Log in
← Formalpedia

Mazur order 13 (Huang FLT port): definitions, layer 0

Definition
MazurN13_L0

by xuanji · Oct 9, 2026 · Mathlib 0df444a (Lean v4.33.1)

huang-flt-portmazur-full-torsionmazur-n13-portorder13

Layer 0 of 12 of the definitions used by a machine-checked Lean proof of the case N=13N=13N=13 of Mazur's torsion theorem (no elliptic curve over Q\mathbb{Q}Q has a rational point of exact order 131313). It collects the definitions, structures, instances and small structural lemmas of Xiang Huang's development whose dependencies are available at this layer; larger lemmas they rely on are separate platform theorems, imported here as already-proved results. Layer kkk imports layer k−1k-1k−1.

Port notes: only API-drift fixes (transparency options, renamed lemmas); local notations expanded and private removed.

Definition code
import Mathlib

set_option maxHeartbeats 1000000

-- ===== FLT.Assumptions.MazurProof.N13RankTwoQuotientAlgebra =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13RankTwoQuotientAlgebra =====
section
/-!
# Rank-two quotient algebras for the N13 integral graph

Once a relative degree-two divisor has been shown finite and flat, its
affine coordinate quotient is free of rank two with the literal basis
`{1,x}`.  This file records the structural algebra needed to recover its
Mumford equation.

A basis `{1,x}` is a power basis.  Over an arbitrary nontrivial
commutative base ring, evaluation at its generator has kernel generated by
the power-basis relation polynomial.  That polynomial is also the
characteristic polynomial of multiplication by the generator.
-/
open Module
open Polynomial
namespace MazurProof.N13RankTwoQuotientAlgebra
noncomputable section
universe u v
variable {R : Type u} {B : Type v}
section PowerBasisKernel
variable [CommRing R] [Nontrivial R]
variable [Ring B] [Algebra R B]
end PowerBasisKernel
section CharacteristicPolynomial
variable [CommRing R]
variable [Ring B] [Algebra R B]
variable [Module.Free R B] [Module.Finite R B]
end CharacteristicPolynomial
section LiteralOneXBasis
variable [CommRing R]
variable [Ring B] [Algebra R B]
/-- A literal rank-two basis `{1,x}` is a power basis generated by `x`. -/
def powerBasisOfOneX
    (x : B) (b : Basis (Fin 2) R B)
    (hb0 : b 0 = 1) (hb1 : b 1 = x) :
    PowerBasis R B where
  gen := x
  dim := 2
  basis := b
  basis_eq_pow i := by
    fin_cases i
    · simpa using hb0
    · simpa using hb1
@[simp] theorem powerBasisOfOneX_gen
    (x : B) (b : Basis (Fin 2) R B)
    (hb0 : b 0 = 1) (hb1 : b 1 = x) :
    (powerBasisOfOneX x b hb0 hb1).gen = x := rfl
@[simp] theorem powerBasisOfOneX_dim
    (x : B) (b : Basis (Fin 2) R B)
    (hb0 : b 0 = 1) (hb1 : b 1 = x) :
    (powerBasisOfOneX x b hb0 hb1).dim = 2 := rfl
end LiteralOneXBasis
end
end MazurProof.N13RankTwoQuotientAlgebra
end

end

-- ===== FLT.Assumptions.MazurProof.N13RankTwoIdealRecovery =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13RankTwoIdealRecovery =====
section
/-!
# Recovering the literal graph ideal from a rank-two quotient

Once a quotient has basis `{1,x̄}`, the characteristic polynomial `u` of
multiplication by `x̄` generates the evaluation kernel.  Expressing `ȳ` as
`v(x̄)` then recovers the original ambient ideal literally as

`(u(x), y-v(x))`.

This is an ideal-correspondence argument.  It does not assume that the
original ideal was already given in Mumford graph form.
-/
open Polynomial
namespace MazurProof.N13RankTwoIdealRecovery
noncomputable section
universe uR uA
variable {R : Type uR} {A : Type uA}
variable [CommRing R] [CommRing A] [Algebra R A]
/-- Polynomial normal form of degree at most one in the second coordinate. -/
def HasRankTwoPolynomialNormalForm (x y : A) : Prop :=
  ∀ a : A, ∃ p q : R[X],
    a = aeval x p + aeval x q * y
end
end MazurProof.N13RankTwoIdealRecovery
end

end

-- ===== FLT.Assumptions.MazurProof.TateNFDivision =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.TateNFDivision =====
section
/-!
# Division polynomials at the Tate normal form origin

For the Tate normal form `y² + (1-c)xy - by = x³ - bx²` with marked point
`P = (0,0)`, the division polynomials `ψₙ` evaluated at `P` factor as
`ψₙ(P) = b^eₙ · Fₙ(b,c)` where `Fₙ` is a small polynomial.

The condition "P has exact order n" is `Fₙ(b,c) = 0` (with `b ≠ 0` and
nonsingularity).  These compact factors are the foundation for all cyclic
torsion exclusions via Tate normal form.

## References

* Kubert, "Universal bounds on the torsion of elliptic curves", 1976
* The division polynomial recurrence specialized at the origin
-/
namespace MazurProof.TateNFDivision
variable {K : Type*} [Field K]
/-! ## Tate normal form curve and origin -/
/-! ## Weierstrass invariants of the Tate normal form -/
/-! ## Compact factors of ψₙ(0,0) / b^eₙ

These are the NON-trivial factors after removing the power of `b`.
The order-n condition at the Tate origin is `Fₙ(b,c) = 0`.
-/
/-- `ψ₈(0,0) / (-b²¹c) = 2b² - 3bc - bc² + c²`.  Order 8 at origin
    requires additionally `c ≠ 0`. -/
def F8 (b c : K) : K := 2 * b ^ 2 - 3 * b * c - b * c ^ 2 + c ^ 2
/-! ## Expanded forms (useful for ring-level reasoning) -/
/-! ## Two-division polynomial (for rational 2-torsion detection) -/
/-! ## Relation to Weierstrass invariants -/
/-! ## Order conditions at the Tate origin

Exact order `n` at the origin means `Fₙ(b,c) = 0` and all proper divisor
conditions are nonzero.
-/
/-! ## Composite order systems via coprime decomposition -/
end MazurProof.TateNFDivision
end

end

-- ===== FLT.Assumptions.MazurProof.N13CurveModel =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13CurveModel =====
section
/-!
# Equivalent affine models of `X₁(13)`

The optimized generalized model from `N13TateBridge` is completed to the
standard even-degree hyperelliptic model

`Y² = X⁶ + 4X⁵ + 6X⁴ + 2X³ + X² + 2X + 1`

by the elementary change of variables

`X = -x - 1`, `Y = 2y + x³ + x² + 1`.

This exposes the four affine cusps as the points over `X = 0,-1`.  The two
remaining cusps are the two points at infinity on the smooth projective
completion; they do not occur in the affine Tate chart.
-/
namespace MazurProof.N13CurveModel
/-- The standard sextic defining the hyperelliptic model of `X₁(13)`. -/
def sexticF13 (X : ℚ) : ℚ :=
  X ^ 6 + 4 * X ^ 5 + 6 * X ^ 4 + 2 * X ^ 3 + X ^ 2 + 2 * X + 1
/-- The affine standard hyperelliptic model of `X₁(13)`. -/
def C13SexticEq (X Y : ℚ) : Prop :=
  Y ^ 2 = sexticF13 X
@[simp] theorem sexticF13_zero : sexticF13 0 = 1 := by
  norm_num [sexticF13]
@[simp] theorem sexticF13_neg_one : sexticF13 (-1) = 1 := by
  norm_num [sexticF13]
/-- The four visible affine points above `X=0,-1` lie on the curve. -/
theorem affine_cusp_mem
    {X Y : ℚ} (hX : X = 0 ∨ X = -1) (hY : Y = 1 ∨ Y = -1) :
    C13SexticEq X Y := by
  rcases hX with rfl | rfl <;> rcases hY with rfl | rfl <;>
    norm_num [C13SexticEq]
end MazurProof.N13CurveModel
end

end

-- ===== FLT.Assumptions.MazurProof.N13GoodModelTwo =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GoodModelTwo =====
section
/-!
# A good characteristic-two model of `X₁(13)`

The completed-square sextic is not the model to reduce modulo two.  This file
uses the generalized hyperelliptic equation

`y² + (x³+x+1)y = x⁵+x⁴`.

Over the rationals, completing the square gives the existing N13 sextic.
In characteristic two, the affine chart and the chart at infinity both have
nonzero derivative in the second coordinate.  The `F₂`- and `F₄`-point
counts are obtained from Frobenius and the Artin--Schreier map, not by
enumerating field elements.
-/
namespace MazurProof.N13GoodModelTwo
noncomputable section
open scoped CharTwo
open Polynomial
universe u
variable {R : Type u} [CommRing R]
/-- The coefficient of `y` in the generalized equation. -/
def h (x : R) : R := x ^ 3 + x + 1
/-- The right-hand side of the generalized equation. -/
def rhs (x : R) : R := x ^ 5 + x ^ 4
/-- The affine equation with zero on the right. -/
def affineResidual (x y : R) : R :=
  y ^ 2 + h x * y - rhs x
/-- The affine generalized hyperelliptic equation. -/
def AffineEquation (x y : R) : Prop :=
  y ^ 2 + h x * y = rhs x
theorem affineEquation_iff_residual (x y : R) :
    AffineEquation x y ↔ affineResidual x y = 0 := by
  simp [AffineEquation, affineResidual, sub_eq_zero]
/-- Its completed-square polynomial. -/
def completedSextic (x : R) : R :=
  x ^ 6 + 4 * x ^ 5 + 6 * x ^ 4 + 2 * x ^ 3 + x ^ 2 + 2 * x + 1
theorem h_sq_add_four_rhs (x : R) :
    h x ^ 2 + 4 * rhs x = completedSextic x := by
  simp only [h, rhs, completedSextic]
  ring
/-- Completing the square before reduction. -/
theorem completed_square_identity (x y : R) :
    (2 * y + h x) ^ 2 =
      completedSextic x + 4 * (y ^ 2 + h x * y - rhs x) := by
  rw [← h_sq_add_four_rhs]
  ring
theorem completedSextic_rat (x : ℚ) :
    completedSextic x = N13CurveModel.sexticF13 x := by
  rfl
/-- The inverse completed-square coordinate over `ℚ`. -/
def sexticToGoodY (x Y : ℚ) : ℚ :=
  (Y - h x) / 2
theorem sextic_good_y_roundtrip (x Y : ℚ) :
    2 * sexticToGoodY x Y + h x = Y := by
  simp only [sexticToGoodY]
  ring
/-- The standard sextic maps back to the good generalized model over `ℚ`. -/
theorem sextic_to_good
    {x Y : ℚ} (hp : N13CurveModel.C13SexticEq x Y) :
    AffineEquation x (sexticToGoodY x Y) := by
  have hs := completed_square_identity x (sexticToGoodY x Y)
  rw [sextic_good_y_roundtrip] at hs
  rw [N13CurveModel.C13SexticEq, ← completedSextic_rat] at hp
  rw [hp] at hs
  have hz :
      sexticToGoodY x Y ^ 2 + h x * sexticToGoodY x Y - rhs x = 0 := by
    linarith
  exact sub_eq_zero.mp hz
/-! ## The two charts of the weighted projective completion -/
/-- Equation on the `X=1` chart, with `t=Z/X` and `v=Y/X³`. -/
def InfinityChartEquation (t v : R) : Prop :=
  v ^ 2 + (1 + t ^ 2 + t ^ 3) * v = t + t ^ 2
/-- Residual form of the `X=1` chart. -/
def infinityChartResidual (t v : R) : R :=
  v ^ 2 + (1 + t ^ 2 + t ^ 3) * v - (t + t ^ 2)
theorem infinityChartEquation_iff (t v : R) :
    InfinityChartEquation t v ↔ infinityChartResidual t v = 0 := by
  simp [InfinityChartEquation, infinityChartResidual, sub_eq_zero]
/-- Derivative of the affine equation with respect to `y`. -/
def affineDerivativeY (x y : R) : R :=
  2 * y + h x
/-- The affine equation as a polynomial in the second coordinate. -/
def affineFiber (x : R) : R[X] :=
  X ^ 2 + C (h x) * X - C (rhs x)
@[simp] theorem affineFiber_eval (x y : R) :
    (affineFiber x).eval y = affineResidual x y := by
  simp [affineFiber, affineResidual]
/-! ## Structural characteristic-two point classification -/
variable {K : Type u} [Field K] [CharP K 2]
omit [CharP K 2] in
theorem fixedTwo_eq_zero_or_one (x : K) (hx : x ^ 2 = x) :
    x = 0 ∨ x = 1 := by
  have hfac : x * (x - 1) = 0 := by
    calc
      x * (x - 1) = x ^ 2 - x := by ring
      _ = 0 := sub_eq_zero.mpr hx
  rcases mul_eq_zero.mp hfac with hx0 | hx1
  · exact Or.inl hx0
  · exact Or.inr (sub_eq_zero.mp hx1)
/-- Affine points as a finite type. -/
abbrev AffinePoint (K : Type u) [Field K] :=
  {p : K × K // AffineEquation p.1 p.2}
/-- Points on the fibre `t=0` of the infinity chart. -/
abbrev InfinityPoint (K : Type u) [Field K] :=
  {v : K // InfinityChartEquation 0 v}
theorem infinityChartEquation_zero_iff_fixed (v : K) :
    InfinityChartEquation 0 v ↔ v ^ 2 = v := by
  have htwo : (2 : K) = 0 := CharP.cast_eq_zero K 2
  unfold InfinityChartEquation
  constructor <;> intro hv
  · linear_combination hv - v * htwo
  · linear_combination hv + v * htwo
/-- The point type presented by the affine chart and its two infinity points. -/
abbrev CompletedPoint (K : Type u) [Field K] :=
  AffinePoint K ⊕ InfinityPoint K
/-! ## The fields `F₂` and `F₄` -/
abbrev F2 := ZMod 2
abbrev F4 := GaloisField 2 2
theorem f2_fourth_eq (x : F2) : x ^ 4 = x := by
  have hx : x ^ 2 = x := ZMod.pow_card x
  calc
    x ^ 4 = (x ^ 2) ^ 2 := by ring
    _ = x ^ 2 := congrArg (fun z : F2 => z ^ 2) hx
    _ = x := hx
local instance instFintypeF4 : Fintype F4 := Fintype.ofFinite F4
end
end MazurProof.N13GoodModelTwo
end

end

-- ===== FLT.Assumptions.MazurProof.N13GeneralizedMumfordIntegral =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GeneralizedMumfordIntegral =====
section
/-!
# Integral generalized Mumford graph quotients for N13

For the good equation

`Y² + (X³ + X + 1)Y = X⁵ + X⁴`,

evaluation on a graph `Y=v mod u` identifies the graph quotient with
`R[X]/(u)` over any nontrivial commutative base ring.  If the base is a
domain and `u` is monic, this quotient is free and hence torsion-free.
Consequently every graph ideal is saturated with respect to each nonzero
base scalar.

This is the elementary integral algebra needed before reduction modulo two;
it uses neither normality of the affine ring nor a Picard scheme.
-/
open Polynomial
namespace MazurProof.N13GeneralizedMumfordIntegral
noncomputable section
universe u
variable {R : Type u} [CommRing R]
def hPoly : R[X] :=
  X ^ 3 + X + 1
def rhsPoly : R[X] :=
  X ^ 5 + X ^ 4
def curvePoly : R[X][X] :=
  X ^ 2 + C hPoly * X - C rhsPoly
theorem curvePoly_monic : (curvePoly : R[X][X]).Monic := by
  unfold curvePoly
  monicity <;> norm_num
abbrev CoordinateRing : Type u :=
  AdjoinRoot (curvePoly : R[X][X])
noncomputable instance instAlgebraCoordinateRing : Algebra R (CoordinateRing (R := R)) :=
  inferInstance
noncomputable instance instAlgebraPolynomialCoordinateRing : Algebra R[X] (CoordinateRing (R := R)) :=
  inferInstance
def mk : R[X][X] →+* CoordinateRing (R := R) :=
  AdjoinRoot.mk (curvePoly (R := R))
def xClass (p : R[X]) : CoordinateRing (R := R) :=
  mk (R := R) (C p)
def yClass : CoordinateRing (R := R) :=
  mk (R := R) X
def xClassHom : R[X] →+* CoordinateRing (R := R) :=
  AdjoinRoot.of (curvePoly (R := R))
@[simp] theorem xClassHom_apply (p : R[X]) :
    xClassHom p = xClass p := rfl
@[simp] theorem xClass_zero : xClass (0 : R[X]) = 0 :=
  map_zero xClassHom
@[simp] theorem xClass_one : xClass (1 : R[X]) = 1 :=
  map_one xClassHom
@[simp] theorem xClass_sub (p q : R[X]) :
    xClass (p - q) = xClass p - xClass q :=
  map_sub xClassHom p q
@[simp] theorem xClass_neg (p : R[X]) :
    xClass (-p) = -xClass p :=
  map_neg xClassHom p
@[simp] theorem xClass_mul (p q : R[X]) :
    xClass (p * q) = xClass p * xClass q :=
  map_mul xClassHom p q
@[simp] theorem xClass_pow (p : R[X]) (n : ℕ) :
    xClass (p ^ n) = xClass p ^ n :=
  map_pow xClassHom p n
def normalPoly :
    CoordinateRing (R := R) →ₗ[R[X]] R[X][X] :=
  AdjoinRoot.modByMonicHom (curvePoly_monic (R := R))
def coeff0 :
    CoordinateRing (R := R) →ₗ[R[X]] R[X] :=
  (Polynomial.lcoeff R[X] 0).comp (normalPoly (R := R))
def coeffY :
    CoordinateRing (R := R) →ₗ[R[X]] R[X] :=
  (Polynomial.lcoeff R[X] 1).comp (normalPoly (R := R))
set_option maxHeartbeats 4000000 in
/-- The generalized graph relation; no smoothness assumption is needed for
the evaluation-kernel and saturation theorems. -/
structure SemiMumford where
  u : R[X]
  v : R[X]
  w : R[X]
  u_monic : u.Monic
  curve_eq : v ^ 2 + hPoly * v - rhsPoly = u * w
/-- Hyperelliptic conjugation sends a graph value `v` to `-h-v`. -/
def conjugateV (v : R[X]) : R[X] :=
  -hPoly - v
def ySubClass (v : R[X]) : CoordinateRing (R := R) :=
  yClass - xClass v
def mumfordIdeal (u v : R[X]) :
    Ideal (CoordinateRing (R := R)) :=
  Ideal.span {xClass u, ySubClass v}
theorem xClass_mem_mumfordIdeal (u v : R[X]) :
    xClass u ∈ mumfordIdeal u v :=
  Ideal.subset_span (by simp)
theorem ySubClass_mem_mumfordIdeal (u v : R[X]) :
    ySubClass v ∈ mumfordIdeal u v :=
  Ideal.subset_span (by simp)
abbrev MumfordResidue
    (D : SemiMumford (R := R)) : Type u :=
  R[X] ⧸ Ideal.span ({D.u} : Set R[X])
theorem mumford_root_relation
    (D : SemiMumford (R := R)) :
    curvePoly.eval₂
      (Ideal.Quotient.mk (Ideal.span ({D.u} : Set R[X])))
      (Ideal.Quotient.mk (Ideal.span ({D.u} : Set R[X])) D.v) = 0 := by
  change (X ^ 2 + C hPoly * X - C rhsPoly).eval₂
      (Ideal.Quotient.mk (Ideal.span ({D.u} : Set R[X])))
      (Ideal.Quotient.mk (Ideal.span ({D.u} : Set R[X])) D.v) = 0
  simp only [eval₂_sub, eval₂_add, eval₂_pow, eval₂_X, eval₂_C,
    eval₂_mul]
  change Ideal.Quotient.mk (Ideal.span ({D.u} : Set R[X]))
    (D.v ^ 2 + hPoly * D.v - rhsPoly) = 0
  rw [Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton]
  exact ⟨D.w, D.curve_eq⟩
def mumfordEval (D : SemiMumford (R := R)) :
    CoordinateRing (R := R) →+* MumfordResidue D :=
  AdjoinRoot.lift
    (Ideal.Quotient.mk (Ideal.span ({D.u} : Set R[X])))
    (Ideal.Quotient.mk (Ideal.span ({D.u} : Set R[X])) D.v)
    (mumford_root_relation D)
@[simp] theorem mumfordEval_xClass
    (D : SemiMumford (R := R)) (p : R[X]) :
    mumfordEval D (xClass p) =
      Ideal.Quotient.mk (Ideal.span ({D.u} : Set R[X])) p := by
  change mumfordEval D (AdjoinRoot.of curvePoly p) = _
  exact AdjoinRoot.lift_of (mumford_root_relation D)
theorem mumfordEval_surjective
    (D : SemiMumford (R := R)) :
    Function.Surjective (mumfordEval D) := by
  intro z
  obtain ⟨p, rfl⟩ := Ideal.Quotient.mk_surjective z
  exact ⟨xClass p, mumfordEval_xClass D p⟩
/-- A monic graph quotient is free over the base. -/
noncomputable instance mumfordResidueFree
    (D : SemiMumford (R := R)) :
    Module.Free R (MumfordResidue D) :=
  D.u_monic.free_quotient
namespace TwoAdic
abbrev R₂ : Type := ℤ_[2]
abbrev SemiMumford₂ : Type :=
  SemiMumford (R := R₂)
end TwoAdic
end
end MazurProof.N13GeneralizedMumfordIntegral
end

end

-- ===== FLT.Assumptions.MazurProof.N13GoodCoordinateRingTwo =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GoodCoordinateRingTwo =====
section
/-!
# The affine coordinate ring of the N13 good fibre at two

The good characteristic-two equation

`Y² + (X³ + X + 1)Y = X⁵ + X⁴`

defines a quadratic extension of `F₂(X)`.  This file constructs its affine
coordinate ring as an `AdjoinRoot` and proves irreducibility structurally.
The proof uses degree dominance and two coefficient comparisons; it does not
enumerate polynomials over `F₂`.
-/
open Polynomial
open FractionalIdeal (coeIdeal_mul)
open scoped nonZeroDivisors
namespace MazurProof.N13GoodCoordinateRingTwo
noncomputable section
abbrev K := N13GoodModelTwo.F2
/-- The coefficient of `Y` in polynomial form. -/
def hPoly : K[X] :=
  X ^ 3 + X + 1
/-- The right-hand side in polynomial form. -/
def rhsPoly : K[X] :=
  X ^ 5 + X ^ 4
/-- The outer variable is `Y`, with coefficients in `F₂[X]`. -/
def curvePoly : K[X][X] :=
  X ^ 2 + C hPoly * X - C rhsPoly
theorem hPoly_monic : hPoly.Monic := by
  unfold hPoly
  (monicity; norm_num)
theorem rhsPoly_monic : rhsPoly.Monic := by
  unfold rhsPoly
  monicity <;> norm_num
theorem rhsPoly_natDegree : rhsPoly.natDegree = 5 := by
  unfold rhsPoly
  compute_degree <;> norm_num
theorem curvePoly_monic : curvePoly.Monic := by
  unfold curvePoly
  monicity <;> norm_num
/-- The affine coordinate ring of the special fibre. -/
abbrev CoordinateRing : Type :=
  AdjoinRoot curvePoly
/-- Its fraction field. -/
abbrev FunctionField : Type :=
  FractionRing CoordinateRing
noncomputable instance instAlgebraKCoordinateRing : Algebra K CoordinateRing :=
  inferInstance
noncomputable instance instAlgebraPolynomialKCoordinateRing : Algebra K[X] CoordinateRing :=
  inferInstance
/-- Quotient map to the affine coordinate ring. -/
def mk : K[X][X] →+* CoordinateRing :=
  AdjoinRoot.mk curvePoly
/-- Embed a polynomial in the `X` coordinate. -/
def xClass (p : K[X]) : CoordinateRing :=
  mk (C p)
/-- The class of the `Y` coordinate. -/
def yClass : CoordinateRing :=
  mk X
/-- The polynomial-coordinate embedding. -/
def xClassHom : K[X] →+* CoordinateRing :=
  AdjoinRoot.of curvePoly
@[simp] theorem xClassHom_apply (p : K[X]) :
    xClassHom p = xClass p := rfl
@[simp] theorem xClass_zero : xClass 0 = 0 :=
  map_zero xClassHom
@[simp] theorem xClass_one : xClass 1 = 1 :=
  map_one xClassHom
@[simp] theorem xClass_sub (p q : K[X]) :
    xClass (p - q) = xClass p - xClass q :=
  map_sub xClassHom p q
@[simp] theorem xClass_neg (p : K[X]) :
    xClass (-p) = -xClass p :=
  map_neg xClassHom p
@[simp] theorem xClass_mul (p q : K[X]) :
    xClass (p * q) = xClass p * xClass q :=
  map_mul xClassHom p q
@[simp] theorem xClass_pow (p : K[X]) (n : ℕ) :
    xClass (p ^ n) = xClass p ^ n :=
  map_pow xClassHom p n
/-- The canonical degree-less-than-two polynomial representative. -/
def normalPoly : CoordinateRing →ₗ[K[X]] K[X][X] :=
  AdjoinRoot.modByMonicHom curvePoly_monic
/-- Constant coefficient in the `1,Y` basis. -/
def coeff0 : CoordinateRing →ₗ[K[X]] K[X] :=
  (Polynomial.lcoeff K[X] 0).comp normalPoly
/-- `Y` coefficient in the `1,Y` basis. -/
def coeffY : CoordinateRing →ₗ[K[X]] K[X] :=
  (Polynomial.lcoeff K[X] 1).comp normalPoly
@[simp] theorem normalPoly_mk (g : K[X][X]) :
    normalPoly (mk g) = g %ₘ curvePoly := rfl
@[simp] theorem coeff0_mk (g : K[X][X]) :
    coeff0 (mk g) = (g %ₘ curvePoly).coeff 0 := rfl
@[simp] theorem coeffY_mk (g : K[X][X]) :
    coeffY (mk g) = (g %ₘ curvePoly).coeff 1 := rfl
/-! ## Generalized Mumford graph ideals -/
/-- Hyperelliptic conjugation sends a graph value `v` to `-h-v`. -/
def conjugateV (v : K[X]) : K[X] :=
  -hPoly - v
set_option maxHeartbeats 4000000 in
/-- Integral generalized Mumford data, including the Cantor quotient and
the precise smoothness Bézout identity needed for ideal invertibility. -/
structure SemiMumford where
  u : K[X]
  v : K[X]
  w : K[X]
  u_monic : u.Monic
  curve_eq : v ^ 2 + hPoly * v - rhsPoly = u * w
  bezout :
    ∃ a b c : K[X],
      a * u + b * (2 * v + hPoly) + c * w = 1
/-- The graph function `Y-v(X)`. -/
def ySubClass (v : K[X]) : CoordinateRing :=
  yClass - xClass v
/-- The integral graph ideal `(u,Y-v)`. -/
def mumfordIdeal (u v : K[X]) : Ideal CoordinateRing :=
  Ideal.span {xClass u, ySubClass v}
theorem xClass_mem_mumfordIdeal (u v : K[X]) :
    xClass u ∈ mumfordIdeal u v :=
  Ideal.subset_span (by simp)
theorem ySubClass_mem_mumfordIdeal (u v : K[X]) :
    ySubClass v ∈ mumfordIdeal u v :=
  Ideal.subset_span (by simp)
/-! ## Evaluation at a generalized Mumford graph -/
abbrev MumfordResidue (D : SemiMumford) : Type :=
  K[X] ⧸ Ideal.span ({D.u} : Set K[X])
theorem mumford_root_relation (D : SemiMumford) :
    curvePoly.eval₂
      (Ideal.Quotient.mk (Ideal.span ({D.u} : Set K[X])))
      (Ideal.Quotient.mk (Ideal.span ({D.u} : Set K[X])) D.v) = 0 := by
  change (X ^ 2 + C hPoly * X - C rhsPoly).eval₂
      (Ideal.Quotient.mk (Ideal.span ({D.u} : Set K[X])))
      (Ideal.Quotient.mk (Ideal.span ({D.u} : Set K[X])) D.v) = 0
  simp only [eval₂_sub, eval₂_add, eval₂_pow, eval₂_X, eval₂_C,
    eval₂_mul]
  change Ideal.Quotient.mk (Ideal.span ({D.u} : Set K[X]))
    (D.v ^ 2 + hPoly * D.v - rhsPoly) = 0
  rw [Ideal.Quotient.eq_zero_iff_mem, Ideal.mem_span_singleton]
  exact ⟨D.w, D.curve_eq⟩
/-- Evaluation `X ↦ X mod u`, `Y ↦ v mod u`. -/
def mumfordEval (D : SemiMumford) :
    CoordinateRing →+* MumfordResidue D :=
  AdjoinRoot.lift
    (Ideal.Quotient.mk (Ideal.span ({D.u} : Set K[X])))
    (Ideal.Quotient.mk (Ideal.span ({D.u} : Set K[X])) D.v)
    (mumford_root_relation D)
@[simp] theorem mumfordEval_xClass
    (D : SemiMumford) (p : K[X]) :
    mumfordEval D (xClass p) =
      Ideal.Quotient.mk (Ideal.span ({D.u} : Set K[X])) p := by
  change mumfordEval D (AdjoinRoot.of curvePoly p) = _
  exact AdjoinRoot.lift_of (mumford_root_relation D)
theorem mumfordEval_surjective (D : SemiMumford) :
    Function.Surjective (mumfordEval D) := by
  intro z
  obtain ⟨p, rfl⟩ := Ideal.Quotient.mk_surjective z
  exact ⟨xClass p, mumfordEval_xClass D p⟩
/-- Invertible fractional ideals of the special affine coordinate ring. -/
abbrev InvFrac :=
  (FractionalIdeal CoordinateRing⁰ FunctionField)ˣ
end
end MazurProof.N13GoodCoordinateRingTwo
end

end

-- ===== FLT.Assumptions.MazurProof.N13GeneralizedMumfordReduction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GeneralizedMumfordReduction =====
section
/-!
# Reduction of integral N13 Mumford graphs at two

The good integral equation

`Y² + (X³ + X + 1)Y = X⁵ + X⁴`

has the same coefficients after reduction from `ℤ₂` to `𝔽₂`.  Hence
coefficientwise reduction induces a canonical ring homomorphism between
the two affine coordinate rings.  This file proves that the homomorphism
preserves both coordinates and carries every generalized Mumford graph
ideal exactly to the corresponding special-fibre graph ideal.
-/
open Polynomial
namespace MazurProof.N13GeneralizedMumfordReduction
noncomputable section
abbrev R₂ : Type :=
  N13GeneralizedMumfordIntegral.TwoAdic.R₂
abbrev K : Type :=
  N13GoodCoordinateRingTwo.K
abbrev IntegralRing : Type :=
  N13GeneralizedMumfordIntegral.CoordinateRing (R := R₂)
abbrev SpecialRing : Type :=
  N13GoodCoordinateRingTwo.CoordinateRing
/-- Coefficient reduction from the two-adic integers to `𝔽₂`. -/
def reduceBase : R₂ →+* K :=
  PadicInt.toZMod
/-- Coefficientwise reduction of polynomials in the `X` coordinate. -/
def reducePoly : R₂[X] →+* K[X] :=
  Polynomial.mapRingHom reduceBase
@[simp] theorem reducePoly_apply (p : R₂[X]) :
    reducePoly p = p.map reduceBase := rfl
@[simp] theorem reduce_hPoly :
    reducePoly
        (N13GeneralizedMumfordIntegral.hPoly (R := R₂)) =
      N13GoodCoordinateRingTwo.hPoly := by
  simp [reducePoly, reduceBase,
    N13GeneralizedMumfordIntegral.hPoly,
    N13GoodCoordinateRingTwo.hPoly]
@[simp] theorem reduce_rhsPoly :
    reducePoly
        (N13GeneralizedMumfordIntegral.rhsPoly (R := R₂)) =
      N13GoodCoordinateRingTwo.rhsPoly := by
  simp [reducePoly, reduceBase,
    N13GeneralizedMumfordIntegral.rhsPoly,
    N13GoodCoordinateRingTwo.rhsPoly]
theorem reduce_curvePoly :
    (N13GeneralizedMumfordIntegral.curvePoly (R := R₂)).map
        reducePoly =
      N13GoodCoordinateRingTwo.curvePoly := by
  simp only [N13GeneralizedMumfordIntegral.curvePoly,
    N13GoodCoordinateRingTwo.curvePoly, Polynomial.map_sub,
    Polynomial.map_add, Polynomial.map_pow, Polynomial.map_X,
    Polynomial.map_C, Polynomial.map_mul]
  change
    X ^ 2 +
          C (reducePoly
            (N13GeneralizedMumfordIntegral.hPoly (R := R₂))) * X -
        C (reducePoly
          (N13GeneralizedMumfordIntegral.rhsPoly (R := R₂))) =
      X ^ 2 + C N13GoodCoordinateRingTwo.hPoly * X -
        C N13GoodCoordinateRingTwo.rhsPoly
  rw [reduce_hPoly, reduce_rhsPoly]
theorem special_curve_dvd :
    N13GoodCoordinateRingTwo.curvePoly ∣
      (N13GeneralizedMumfordIntegral.curvePoly (R := R₂)).map
        reducePoly := by
  rw [reduce_curvePoly]
/-- Reduction on the affine coordinate ring of the good equation. -/
def reduceCoordinate : IntegralRing →+* SpecialRing :=
  AdjoinRoot.map reducePoly
    (N13GeneralizedMumfordIntegral.curvePoly (R := R₂))
    N13GoodCoordinateRingTwo.curvePoly
    special_curve_dvd
@[simp] theorem reduce_xClass (p : R₂[X]) :
    reduceCoordinate
        (N13GeneralizedMumfordIntegral.xClass (R := R₂) p) =
      N13GoodCoordinateRingTwo.xClass (reducePoly p) := by
  exact AdjoinRoot.map_of
    reducePoly
    (N13GeneralizedMumfordIntegral.curvePoly (R := R₂))
    N13GoodCoordinateRingTwo.curvePoly
    special_curve_dvd p
@[simp] theorem reduce_yClass :
    reduceCoordinate
        (N13GeneralizedMumfordIntegral.yClass (R := R₂)) =
      N13GoodCoordinateRingTwo.yClass := by
  exact AdjoinRoot.map_root
    reducePoly
    (N13GeneralizedMumfordIntegral.curvePoly (R := R₂))
    N13GoodCoordinateRingTwo.curvePoly
    special_curve_dvd
@[simp] theorem reduce_ySubClass (v : R₂[X]) :
    reduceCoordinate
        (N13GeneralizedMumfordIntegral.ySubClass (R := R₂) v) =
      N13GoodCoordinateRingTwo.ySubClass (reducePoly v) := by
  simp [N13GeneralizedMumfordIntegral.ySubClass,
    N13GoodCoordinateRingTwo.ySubClass]
/-- Reduction carries the integral graph ideal onto, rather than merely
into, the graph ideal with reduced coefficients. -/
theorem map_mumfordIdeal (u v : R₂[X]) :
    Ideal.map reduceCoordinate
        (N13GeneralizedMumfordIntegral.mumfordIdeal
          (R := R₂) u v) =
      N13GoodCoordinateRingTwo.mumfordIdeal
        (reducePoly u) (reducePoly v) := by
  rw [N13GeneralizedMumfordIntegral.mumfordIdeal,
    N13GoodCoordinateRingTwo.mumfordIdeal, Ideal.map_span,
    Set.image_pair, reduce_xClass, reduce_ySubClass]
set_option maxHeartbeats 4000000 in
/-- Integral generalized Mumford data carrying the smoothness Bézout
identity.  This is precisely the extra condition needed for the reduced
graph ideal to be invertible. -/
structure SmoothMumford₂ : Type
    extends
      N13GeneralizedMumfordIntegral.TwoAdic.SemiMumford₂ where
  bezout :
    ∃ a b c : R₂[X],
      a * u + b * (2 * v +
        N13GeneralizedMumfordIntegral.hPoly (R := R₂)) +
          c * w = 1
/-- Smooth integral Mumford data reduce to the already constructed smooth
special-fibre data. -/
def reduceSmoothMumford
    (D : SmoothMumford₂) :
    N13GoodCoordinateRingTwo.SemiMumford where
  u := reducePoly D.u
  v := reducePoly D.v
  w := reducePoly D.w
  u_monic := D.u_monic.map reduceBase
  curve_eq := by
    have h := congrArg reducePoly D.curve_eq
    simpa only [map_add, map_sub, map_mul, map_pow,
      reduce_hPoly, reduce_rhsPoly] using h
  bezout := by
    obtain ⟨a, b, c, habc⟩ := D.bezout
    refine ⟨reducePoly a, reducePoly b, reducePoly c, ?_⟩
    have h := congrArg reducePoly habc
    simpa only [map_add, map_mul, map_ofNat, map_one,
      reduce_hPoly] using h
@[simp] theorem reduceSmoothMumford_u
    (D : SmoothMumford₂) :
    (reduceSmoothMumford D).u = reducePoly D.u := rfl
@[simp] theorem reduceSmoothMumford_v
    (D : SmoothMumford₂) :
    (reduceSmoothMumford D).v = reducePoly D.v := rfl
/-- The exact ideal reduction theorem, now stated for smooth integral data. -/
theorem map_smoothMumfordIdeal
    (D : SmoothMumford₂) :
    Ideal.map reduceCoordinate
        (N13GeneralizedMumfordIntegral.mumfordIdeal
          (R := R₂) D.u D.v) =
      N13GoodCoordinateRingTwo.mumfordIdeal
        (reduceSmoothMumford D).u
        (reduceSmoothMumford D).v := by
  simpa using map_mumfordIdeal D.u D.v
end
end MazurProof.N13GeneralizedMumfordReduction
end

end

-- ===== FLT.Assumptions.MazurProof.SexticMumford =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.SexticMumford =====
section
/-!
# Balanced Mumford data for a separable monic sextic

This file contains the curve-independent algebra underlying the balanced
Mumford representation for a genus-two curve

`Y² = f(X)`,

where `f` is monic, separable, and has degree six.  Arithmetic for a specific
curve belongs in a separate model instance.

The semantic target is an oriented fractional-ideal quotient of the affine
coordinate ring.  Constructing the order at a chosen point at infinity and
proving the normal-form theorem are deliberately separate later layers.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.SexticMumford
noncomputable section
universe u
set_option maxHeartbeats 4000000 in
/-- A smooth monic degree-six hyperelliptic equation. -/
structure Model (K : Type u) [Field K] where
  f : K[X]
  monic : f.Monic
  natDegree : f.natDegree = 6
  separable : f.Separable
  two_ne_zero : (2 : K) ≠ 0
variable {K : Type u} [Field K]
namespace Model
theorem squarefree (M : Model K) : Squarefree M.f :=
  M.separable.squarefree
theorem ne_zero (M : Model K) : M.f ≠ 0 :=
  M.monic.ne_zero
theorem not_isUnit (M : Model K) : ¬IsUnit M.f :=
  Polynomial.not_isUnit_of_natDegree_pos M.f (by rw [M.natDegree]; norm_num)
end Model
variable (M : Model K)
/-! ## The affine coordinate ring -/
/-- The outer variable is `Y`; its coefficients are polynomials in `X`. -/
def curvePoly : K[X][X] :=
  X ^ 2 - C M.f
theorem curvePoly_monic : (curvePoly M).Monic := by
  unfold curvePoly
  monicity!
abbrev CoordinateRing : Type u :=
  AdjoinRoot (curvePoly M)
abbrev FunctionField : Type u :=
  FractionRing (CoordinateRing M)
noncomputable instance instAlgebraCoordinateRing : Algebra K (CoordinateRing M) :=
  inferInstance
noncomputable instance instAlgebraPolynomialCoordinateRing : Algebra K[X] (CoordinateRing M) :=
  inferInstance
/-- Quotient map to the affine coordinate ring. -/
def mk : K[X][X] →+* CoordinateRing M :=
  AdjoinRoot.mk (curvePoly M)
/-- Embed a polynomial in the `X` coordinate into the coordinate ring. -/
def xClass (p : K[X]) : CoordinateRing M :=
  mk M (C p)
/-- The class of the `Y` coordinate. -/
def yClass : CoordinateRing M :=
  mk M X
/-! ## Balanced triples -/
set_option maxHeartbeats 4000000 in
attribute [local irreducible] MazurProof.SexticMumford.curvePoly in
/-- A balanced Mumford representative for a divisor class on a monic sextic
with two distinguished points at infinity. -/
structure Mumford where
  u : K[X]
  v : K[X]
  nInf : ℕ
  u_monic : u.Monic
  deg_u : u.natDegree ≤ 2
  v_reduced : v % u = v
  curve_dvd : u ∣ M.f - v ^ 2
  infinity_bound : u.natDegree + nInf ≤ 2
set_option maxHeartbeats 4000000 in
attribute [local irreducible] MazurProof.SexticMumford.curvePoly in
/-- The unreduced integral version used during ideal multiplication. -/
structure SemiMumford where
  u : K[X]
  v : K[X]
  nInf : ℤ
  u_monic : u.Monic
  v_reduced : v % u = v
  curve_dvd : u ∣ M.f - v ^ 2
/-- Forget the balancing bounds while retaining the ideal data. -/
def Mumford.toSemi (D : Mumford M) : SemiMumford M where
  u := D.u
  v := D.v
  nInf := D.nInf
  u_monic := D.u_monic
  v_reduced := D.v_reduced
  curve_dvd := D.curve_dvd
@[simp] theorem toSemi_u (D : Mumford M) : D.toSemi.u = D.u := rfl
@[simp] theorem toSemi_v (D : Mumford M) : D.toSemi.v = D.v := rfl
@[simp] theorem toSemi_nInf (D : Mumford M) : D.toSemi.nInf = D.nInf := rfl
/-- The balanced representative of the identity class. -/
def zero : Mumford M where
  u := 1
  v := 0
  nInf := 1
  u_monic := monic_one
  deg_u := by simp
  v_reduced := by simp
  curve_dvd := one_dvd _
  infinity_bound := by simp
@[simp] theorem zero_u : (zero M).u = 1 := rfl
@[simp] theorem zero_v : (zero M).v = 0 := rfl
@[simp] theorem zero_nInf : (zero M).nInf = 1 := rfl
/-! ## Curve points and their balanced representatives -/
/-- The two-infinity projective completion of the affine sextic. -/
inductive CurvePoint where
  | infinityPlus
  | infinityMinus
  | affine (x y : K) (onCurve : y ^ 2 = M.f.eval x)
/-- With `∞₊` as base point, an affine point `(x,y)` is represented by
`(X-x,y,0)`. -/
def affinePointMumford (x y : K) (h : y ^ 2 = M.f.eval x) :
    Mumford M where
  u := X - C x
  v := C y
  nInf := 0
  u_monic := monic_X_sub_C x
  deg_u := by simp
  v_reduced := by
    rw [mod_eq_self_iff (monic_X_sub_C x).ne_zero]
    exact degree_C_le.trans_lt (by rw [degree_X_sub_C]; norm_num)
  curve_dvd := by
    have heval : (M.f - (C y) ^ 2).eval x = 0 := by
      rw [eval_sub, eval_pow, eval_C, ← h, sub_self]
    have hd := X_sub_C_dvd_sub_C_eval (p := M.f - (C y) ^ 2) (a := x)
    simpa only [heval, C_0, sub_zero] using hd
  infinity_bound := by simp
/-- The negative point at infinity is represented by `(1,0,0)`. -/
def infinityMinusMumford : Mumford M where
  u := 1
  v := 0
  nInf := 0
  u_monic := monic_one
  deg_u := by simp
  v_reduced := by simp
  curve_dvd := one_dvd _
  infinity_bound := by simp
/-- The balanced representative attached to a projective curve point. -/
def pointMumford : CurvePoint M → Mumford M
  | .infinityPlus => zero M
  | .infinityMinus => infinityMinusMumford M
  | .affine x y h => affinePointMumford M x y h
/-! ## Mumford ideals -/
def ySubClass (v : K[X]) : CoordinateRing M :=
  yClass M - xClass M v
def mumfordIdeal (u v : K[X]) : Ideal (CoordinateRing M) :=
  Ideal.span {xClass M u, ySubClass M v}
theorem xClass_mem_mumfordIdeal (u v : K[X]) :
    xClass M u ∈ mumfordIdeal M u v := by
  exact Ideal.subset_span (by simp)
/-! ## The oriented fractional-ideal quotient -/
abbrev InvFrac : Type u :=
  (FractionalIdeal (CoordinateRing M)⁰ (FunctionField M))ˣ
abbrev OrientedFrac : Type u :=
  InvFrac M × Multiplicative ℤ
set_option maxHeartbeats 4000000 in
attribute [local irreducible] MazurProof.SexticMumford.curvePoly in
set_option maxHeartbeats 2000000 in
/-- The valuation datum at the chosen positive point at infinity. -/
structure InfinityOrder where
  ordPlus : (FunctionField M)ˣ →* Multiplicative ℤ
end
end MazurProof.SexticMumford
end

end

-- ===== FLT.Assumptions.MazurProof.N13Mumford =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13Mumford =====
section
/-!
# The smooth sextic and Mumford model for `X₁(13)`

This file instantiates the curve-independent balanced Mumford layer with the
standard sextic model of `X₁(13)`.  Smoothness is proved by a short Bézout
identity between the sextic and its derivative.
-/
open Polynomial
namespace MazurProof.N13Mumford
noncomputable section
universe u
variable (K : Type u) [Field K] [CharZero K]
/-- The standard sextic over an arbitrary characteristic-zero field. -/
def f : K[X] :=
  X ^ 6 + 4 * X ^ 5 + 6 * X ^ 4 + 2 * X ^ 3 + X ^ 2 + 2 * X + 1
def fQ : ℚ[X] :=
  X ^ 6 + 4 * X ^ 5 + 6 * X ^ 4 + 2 * X ^ 3 + X ^ 2 + 2 * X + 1
theorem f_natDegree : (f K).natDegree = 6 := by
  unfold f
  compute_degree!
def bezoutA : ℚ[X] :=
  300 * X ^ 4 + 784 * X ^ 3 + 606 * X ^ 2 - 192 * X + 234
def bezoutB : ℚ[X] :=
  -50 * X ^ 5 - 164 * X ^ 4 - 177 * X ^ 3 + 40 * X ^ 2 - 73 * X - 65
theorem C_nat (n : ℕ) : C (n : ℚ) = (n : ℚ[X]) := by
  exact map_natCast (C : ℚ →+* ℚ[X]) n
theorem fQ_derivative :
    fQ.derivative =
      6 * X ^ 5 + 20 * X ^ 4 + 24 * X ^ 3 + 6 * X ^ 2 + 2 * X + 2 := by
  simp only [fQ, derivative_add, derivative_one, derivative_X, derivative_pow,
    derivative_ofNat, derivative_mul, zero_mul, zero_add, add_zero]
  rw [C_nat 2, C_nat 3, C_nat 4, C_nat 5, C_nat 6]
  ring
/-- A small fixed smoothness certificate for the `X₁(13)` sextic. -/
theorem fQ_bezout_derivative :
    bezoutA * fQ + bezoutB * fQ.derivative = 104 := by
  rw [fQ_derivative]
  simp only [bezoutA, bezoutB, fQ]
  ring
theorem fQ_separable : fQ.Separable := by
  rw [separable_def']
  refine ⟨C (1 / 104 : ℚ) * bezoutA, C (1 / 104 : ℚ) * bezoutB, ?_⟩
  calc
    (C (1 / 104 : ℚ) * bezoutA) * fQ +
        (C (1 / 104 : ℚ) * bezoutB) * fQ.derivative =
      C (1 / 104 : ℚ) * (bezoutA * fQ + bezoutB * fQ.derivative) := by
        ring
    _ = C (1 / 104 : ℚ) * 104 := by rw [fQ_bezout_derivative]
    _ = C (1 / 104 : ℚ) * C 104 := by rw [C_ofNat]
    _ = 1 := by rw [← C_mul]; norm_num
theorem f_eq_map :
    f K = fQ.map (algebraMap ℚ K) := by
  simp [f, fQ]
theorem f_separable : (f K).Separable := by
  rw [f_eq_map]
  exact (separable_map (algebraMap ℚ K)).mpr fQ_separable
theorem f_eval_eq_sexticF13 (x : ℚ) :
    (f ℚ).eval x = N13CurveModel.sexticF13 x := by
  simp [f, N13CurveModel.sexticF13]
/-! ## The six rational cusps -/
/-- Names for the six rational cusps on the smooth projective curve. -/
inductive Cusp13
  | infinityPlus
  | infinityMinus
  | zeroPlus
  | zeroMinus
  | negOnePlus
  | negOneMinus
  deriving DecidableEq
instance instFintypeCusp13 : Fintype Cusp13 where
  elems := {Cusp13.infinityPlus, Cusp13.infinityMinus, Cusp13.zeroPlus, Cusp13.zeroMinus,
    Cusp13.negOnePlus, Cusp13.negOneMinus}
  complete := by intro x; cases x <;> decide
end
end MazurProof.N13Mumford
end

end

-- ===== FLT.Assumptions.MazurProof.N13GoodSexticCoordinateEquiv =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GoodSexticCoordinateEquiv =====
section
/-!
# Completing the square on the N13 coordinate rings

Over any field of characteristic zero, the good generalized equation

`y² + (X³+X+1)y = X⁵+X⁴`

and the sextic equation already used by the concrete Picard group are
isomorphic by

`Y = 2y + (X³+X+1)`.

This file constructs that isomorphism directly from the two `AdjoinRoot`
presentations and records its action on both coordinates.  It is the
algebraic bridge needed to interpret integral generalized Mumford graph
ideals as classes in the existing oriented sextic Picard group.
-/
open Polynomial
namespace MazurProof.N13GoodSexticCoordinateEquiv
noncomputable section
universe u
variable {K : Type u} [Field K] [CharZero K]
abbrev GoodRing : Type u :=
  N13GeneralizedMumfordIntegral.CoordinateRing (R := K)
def goodXHom : K[X] →+* GoodRing (K := K) :=
  N13GeneralizedMumfordIntegral.xClassHom
@[simp] theorem goodXHom_apply (p : K[X]) :
    goodXHom (K := K) p =
      N13GeneralizedMumfordIntegral.xClass p := rfl
abbrev hPoly : K[X] :=
  N13GeneralizedMumfordIntegral.hPoly
abbrev rhsPoly : K[X] :=
  N13GeneralizedMumfordIntegral.rhsPoly
/-- The polynomial identity behind completion of the square. -/
theorem sextic_eq_h_sq_add_four_rhs :
    N13Mumford.f K = hPoly ^ 2 + 4 * rhsPoly := by
  simp only [N13Mumford.f, hPoly, rhsPoly,
    N13GeneralizedMumfordIntegral.hPoly,
    N13GeneralizedMumfordIntegral.rhsPoly]
  ring
/-- The sextic `Y` coordinate inside the good coordinate ring. -/
def sexticYInGood : GoodRing (K := K) :=
  2 * N13GeneralizedMumfordIntegral.yClass +
    goodXHom (K := K) hPoly
end
end MazurProof.N13GoodSexticCoordinateEquiv
end

end

-- ===== FLT.Assumptions.MazurProof.N13GoodSexticMumfordTransport =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GoodSexticMumfordTransport =====
section
/-!
# Transporting N13 Mumford graph ideals through completion of the square

The rational change of coordinates

`Y = 2y + (X³ + X + 1)`

does more than identify the two affine coordinate rings.  It sends the
generalized graph ideal `(u, y - v)` exactly to the sextic graph ideal
`(u, Y - (2v + X³ + X + 1))`.  The factor `1 / 2` appearing on the second
generator is a unit in the base field, so it does not change the generated
ideal.
-/
open Polynomial
namespace MazurProof.N13GoodSexticMumfordTransport
noncomputable section
open N13GoodSexticCoordinateEquiv
/-- Multiplying one generator of a two-generated ideal by a unit does not
change the ideal. -/
theorem span_pair_mul_right_unit
    {R : Type*} [CommRing R] (x a y : R) (ha : IsUnit a) :
    Ideal.span {x, a * y} = Ideal.span {x, y} := by
  apply le_antisymm
  · apply Ideal.span_le.2
    intro z hz
    simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hz
    rcases hz with hz | hz
    · rw [hz]
      exact Ideal.subset_span (by simp)
    · rw [hz]
      exact Ideal.mul_mem_left _ a (Ideal.subset_span (by simp))
  · apply Ideal.span_le.2
    intro z hz
    simp only [Set.mem_insert_iff, Set.mem_singleton_iff] at hz
    rcases hz with hz | hz
    · rw [hz]
      exact Ideal.subset_span (by simp)
    · rw [hz]
      obtain ⟨b, hab⟩ := isUnit_iff_exists_inv.mp ha
      have hba : b * a = 1 := by
        simpa [mul_comm] using hab
      have hay : a * y ∈ Ideal.span {x, a * y} :=
        Ideal.subset_span (by simp)
      have hby : b * (a * y) ∈ Ideal.span {x, a * y} :=
        Ideal.mul_mem_left _ b hay
      simpa [← mul_assoc, hba] using hby
universe u
variable {K : Type u} [Field K] [CharZero K]
/-- The sextic graph polynomial corresponding to a generalized graph
polynomial `v`. -/
def completedGraph (v : K[X]) : K[X] :=
  2 * v + N13GeneralizedMumfordIntegral.hPoly
/-- The reduced sextic graph polynomial attached to generalized data. -/
def reducedCompletedGraph (u v : K[X]) : K[X] :=
  completedGraph v % u
theorem dvd_sub_mod (p u : K[X]) :
    u ∣ p - p % u := by
  refine ⟨p / u, ?_⟩
  have h := EuclideanDomain.mod_add_div p u
  calc
    p - p % u = (p % u + u * (p / u)) - p % u := by
      rw [h]
    _ = u * (p / u) := by ring
end
end MazurProof.N13GoodSexticMumfordTransport
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoAdicMumfordTransport =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoAdicMumfordTransport =====
section
/-!
# Transporting integral N13 Mumford data to the two-adic sextic model

Smooth generalized Mumford data over `ℤ₂` first extend coefficientwise to
`ℚ₂`.  Completion of the square then gives a standard reduced sextic
semirepresentative.  This file records that passage without choosing
coordinates or enumerating residue classes.
-/
open Polynomial
namespace MazurProof.N13TwoAdicMumfordTransport
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  ℤ_[2]
abbrev Q₂ : Type :=
  ℚ_[2]
def coeffMap : R₂ →+* Q₂ :=
  algebraMap R₂ Q₂
def mapPoly : R₂[X] →+* Q₂[X] :=
  Polynomial.mapRingHom coeffMap
@[simp] theorem mapPoly_apply (p : R₂[X]) :
    mapPoly p = p.map coeffMap := rfl
@[simp] theorem mapPoly_hPoly :
    mapPoly
        (N13GeneralizedMumfordIntegral.hPoly (R := R₂)) =
      N13GeneralizedMumfordIntegral.hPoly (R := Q₂) := by
  simp [mapPoly, coeffMap,
    N13GeneralizedMumfordIntegral.hPoly]
@[simp] theorem mapPoly_rhsPoly :
    mapPoly
        (N13GeneralizedMumfordIntegral.rhsPoly (R := R₂)) =
      N13GeneralizedMumfordIntegral.rhsPoly (R := Q₂) := by
  simp [mapPoly, coeffMap,
    N13GeneralizedMumfordIntegral.rhsPoly]
/-- Coefficient extension does not require the additional special-fibre
smoothness witness. -/
def baseChangeSemi
    (D :
      N13GeneralizedMumfordIntegral.TwoAdic.SemiMumford₂) :
    N13GeneralizedMumfordIntegral.SemiMumford (R := Q₂) where
  u := mapPoly D.u
  v := mapPoly D.v
  w := mapPoly D.w
  u_monic := D.u_monic.map coeffMap
  curve_eq := by
    have h := congrArg mapPoly D.curve_eq
    simpa only [map_add, map_sub, map_mul, map_pow,
      mapPoly_hPoly, mapPoly_rhsPoly] using h
@[simp] theorem baseChangeSemi_u
    (D :
      N13GeneralizedMumfordIntegral.TwoAdic.SemiMumford₂) :
    (baseChangeSemi D).u = mapPoly D.u := rfl
@[simp] theorem baseChangeSemi_v
    (D :
      N13GeneralizedMumfordIntegral.TwoAdic.SemiMumford₂) :
    (baseChangeSemi D).v = mapPoly D.v := rfl
@[simp] theorem baseChangeSemi_w
    (D :
      N13GeneralizedMumfordIntegral.TwoAdic.SemiMumford₂) :
    (baseChangeSemi D).w = mapPoly D.w := rfl
end
end MazurProof.N13TwoAdicMumfordTransport
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoAdicCoordinateBaseChange =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoAdicCoordinateBaseChange =====
section
/-!
# Base change of the N13 integral coordinate ring to `ℚ₂`

Coefficient extension from `ℤ₂` to `ℚ₂` induces a map between the two
generalized-hyperelliptic coordinate rings.  It carries an integral Mumford
graph ideal exactly onto the graph ideal obtained by coefficient extension.
Composing with completion of the square therefore sends the integral graph
directly to the standard sextic Mumford graph over `ℚ₂`.
-/
open Polynomial
namespace MazurProof.N13TwoAdicCoordinateBaseChange
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13TwoAdicMumfordTransport.R₂
abbrev Q₂ : Type :=
  N13TwoAdicMumfordTransport.Q₂
abbrev IntegralRing : Type :=
  N13GeneralizedMumfordIntegral.CoordinateRing (R := R₂)
abbrev GoodRing : Type :=
  N13GeneralizedMumfordIntegral.CoordinateRing (R := Q₂)
def coeffMap : R₂ →+* Q₂ :=
  N13TwoAdicMumfordTransport.coeffMap
def mapPoly : R₂[X] →+* Q₂[X] :=
  N13TwoAdicMumfordTransport.mapPoly
@[simp] theorem mapPoly_apply (p : R₂[X]) :
    mapPoly p = p.map coeffMap := rfl
/-- Coefficient extension from `ℤ₂[X]` to `ℚ₂[X]` is faithful. -/
theorem mapPoly_injective : Function.Injective mapPoly :=
  Polynomial.map_injective coeffMap
    (IsFractionRing.injective R₂ Q₂)
@[simp] theorem mapPoly_hPoly :
    mapPoly
        (N13GeneralizedMumfordIntegral.hPoly (R := R₂)) =
      N13GeneralizedMumfordIntegral.hPoly (R := Q₂) :=
  N13TwoAdicMumfordTransport.mapPoly_hPoly
@[simp] theorem mapPoly_rhsPoly :
    mapPoly
        (N13GeneralizedMumfordIntegral.rhsPoly (R := R₂)) =
      N13GeneralizedMumfordIntegral.rhsPoly (R := Q₂) :=
  N13TwoAdicMumfordTransport.mapPoly_rhsPoly
theorem map_curvePoly :
    (N13GeneralizedMumfordIntegral.curvePoly (R := R₂)).map
        mapPoly =
      N13GeneralizedMumfordIntegral.curvePoly (R := Q₂) := by
  simp only [N13GeneralizedMumfordIntegral.curvePoly,
    Polynomial.map_sub, Polynomial.map_add, Polynomial.map_pow,
    Polynomial.map_X, Polynomial.map_C, Polynomial.map_mul]
  change
    X ^ 2 +
          C (mapPoly
            (N13GeneralizedMumfordIntegral.hPoly (R := R₂))) * X -
        C (mapPoly
          (N13GeneralizedMumfordIntegral.rhsPoly (R := R₂))) =
      X ^ 2 +
          C (N13GeneralizedMumfordIntegral.hPoly (R := Q₂)) * X -
        C (N13GeneralizedMumfordIntegral.rhsPoly (R := Q₂))
  rw [mapPoly_hPoly, mapPoly_rhsPoly]
theorem target_curve_dvd :
    N13GeneralizedMumfordIntegral.curvePoly (R := Q₂) ∣
      (N13GeneralizedMumfordIntegral.curvePoly (R := R₂)).map
        mapPoly := by
  rw [map_curvePoly]
end
end MazurProof.N13TwoAdicCoordinateBaseChange
end

end

-- ===== FLT.Assumptions.MazurProof.N13Infinity =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13Infinity =====
section
/-!
# The positive infinity of the N13 genus-two curve

We construct the chosen branch at infinity inside `K((s))`.  With `x=s⁻¹`,
the equation becomes

`(s³ y)² = 1 + 4s + 6s² + 2s³ + s⁴ + 2s⁵ + s⁶`.

The square root with constant coefficient `+1` is obtained from the formal
binomial series.  The resulting embedding of the function field supplies the
integer orientation used in `SexticMumford`.
-/
open Polynomial
open scoped LaurentSeries PowerSeries
namespace MazurProof.N13Infinity
noncomputable section
universe u
variable (K : Type u) [Field K] [CharZero K]
/-! ## The formal positive square root -/
def reverseF : K⟦X⟧ :=
  1 + 4 * PowerSeries.X + 6 * PowerSeries.X ^ 2 +
    2 * PowerSeries.X ^ 3 + PowerSeries.X ^ 4 +
    2 * PowerSeries.X ^ 5 + PowerSeries.X ^ 6
def reverseTail : K⟦X⟧ := reverseF K - 1
/-! ## An algebraic model of the function field -/
/-! ## The branch `x = s⁻¹`, `s³y = +sqrt(reverseF)` -/
omit [CharZero K] in
theorem ratXInv_transcendental :
    Transcendental K ((RatFunc.X : RatFunc K)⁻¹) := by
  rw [Transcendental, ← IsAlgebraic.inv_iff]
  simpa [Transcendental] using (RatFunc.transcendental_X (K := K))
def invPolyAlgHom : K[X] →ₐ[K] RatFunc K :=
  Polynomial.aeval ((RatFunc.X : RatFunc K)⁻¹)
omit [CharZero K] in
theorem invPolyAlgHom_injective :
    Function.Injective (invPolyAlgHom K) := by
  exact transcendental_iff_injective.mp (ratXInv_transcendental K)
def ratInvAlgHom : RatFunc K →ₐ[K] RatFunc K :=
  RatFunc.liftAlgHom (invPolyAlgHom K)
    (nonZeroDivisors_le_comap_nonZeroDivisors_of_injective _
      (invPolyAlgHom_injective K))
def standardRatToLaurent : RatFunc K →+* LaurentSeries K :=
  IsFractionRing.lift
    (g := algebraMap K[X] (LaurentSeries K))
    (Polynomial.algebraMap_hahnSeries_injective (R := K) ℤ)
def ratToLaurent : RatFunc K →+* LaurentSeries K :=
  (standardRatToLaurent K).comp
    (ratInvAlgHom K).toRingHom
def parameter : LaurentSeries K := HahnSeries.single 1 1
@[simp] theorem parameter_ne_zero : parameter K ≠ 0 := by
  simp [parameter]
def laurentOrder : (LaurentSeries K)ˣ →* Multiplicative ℤ where
  toFun z := Multiplicative.ofAdd (z.1.order)
  map_one' := by
    change (1 : LaurentSeries K).order = 0
    simp
  map_mul' x y := by
    change ((x.1 * y.1 : LaurentSeries K).order) =
      x.1.order + y.1.order
    exact HahnSeries.order_mul x.ne_zero y.ne_zero
end
end MazurProof.N13Infinity
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralModelContraction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralModelContraction =====
section
/-!
# Vertical localization and ideal contraction for the N13 integral model

The affine coordinate ring of the N13 generic fibre is obtained from the
integral good-model coordinate ring by inverting only the nonzero scalars of
`ℤ₂`.  The proof uses the rank-two normal form `p(x) + q(x)y`: a common
scalar denominator clears the two coefficient polynomials simultaneously.

Consequently every ideal on the generic affine fibre has a canonical
contraction to the integral model, and extending this contraction recovers
the original ideal exactly.  The contraction is vertically saturated.  This
is the algebraic integral-model layer needed before taking a reflexive hull
or lifting a section; it does not assert that the contracted ideal is already
invertible on the two-dimensional integral surface.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralModelContraction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13TwoAdicCoordinateBaseChange.R₂
abbrev Q₂ : Type :=
  N13TwoAdicCoordinateBaseChange.Q₂
abbrev IntegralRing : Type :=
  N13TwoAdicCoordinateBaseChange.IntegralRing
abbrev GoodRing : Type :=
  N13TwoAdicCoordinateBaseChange.GoodRing
/-- The vertical multiplicative set consists exactly of nonzero `ℤ₂`
scalars inside the integral coordinate ring. -/
def verticalScalars : Submonoid IntegralRing :=
  (nonZeroDivisors R₂).map
    (algebraMap R₂ IntegralRing)
local instance polynomialAlgebra :
    Algebra R₂[X] Q₂[X] :=
  Polynomial.algebra R₂ Q₂
local instance polynomialLocalization :
    IsLocalization
      ((nonZeroDivisors R₂).map
        (Polynomial.C : R₂ →+* R₂[X]).toMonoidHom)
      Q₂[X] :=
  Polynomial.isLocalization (nonZeroDivisors R₂) Q₂
end
end MazurProof.N13IntegralModelContraction
end

end

-- ===== FLT.Assumptions.MazurProof.N13QuotientReduction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13QuotientReduction =====
section
/-!
# Reduction of N13 affine quotients

A surjective ambient reduction map descends along a literal mapped-ideal
equality.  The kernel of the descended map is exactly the image of the
ambient kernel.  For the N13 integral model this is the principal ideal
generated by the quotient class of `2`.

No flatness, saturation, or chosen Mumford presentation is used here.
-/
namespace MazurProof.N13QuotientReduction
noncomputable section
universe uA uS
variable {A : Type uA} {S : Type uS}
variable [CommRing A] [CommRing S]
theorem sourceIdeal_le_ker_quotientComp
    (f : A →+* S)
    (I : Ideal A)
    (J : Ideal S)
    (hmap : Ideal.map f I = J) :
    I ≤ RingHom.ker ((Ideal.Quotient.mk J).comp f) := by
  intro a ha
  rw [RingHom.mem_ker, RingHom.comp_apply,
    Ideal.Quotient.eq_zero_iff_mem, ← hmap]
  exact Ideal.mem_map_of_mem f ha
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13GeneralizedMumfordReduction.R₂
abbrev IntegralRing : Type :=
  N13GeneralizedMumfordReduction.IntegralRing
abbrev SpecialRing : Type :=
  N13GeneralizedMumfordReduction.SpecialRing
end
end MazurProof.N13QuotientReduction
end

end

-- ===== FLT.Assumptions.MazurProof.SexticMumfordQuotientBasis =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.SexticMumfordQuotientBasis =====
section
/-!
# The literal basis of a quadratic sextic Mumford quotient

For a monic degree-two Mumford polynomial `u`, graph evaluation identifies
the affine quotient by `(u,Y-v)` with `K[X]/(u)`.  Transporting the canonical
power basis gives the literal quotient basis `{1,x}`.
-/
open Module
open Polynomial
namespace MazurProof.SexticMumfordQuotientBasis
noncomputable section
universe u
variable {K : Type u} [Field K]
variable (M : SexticMumford.Model K)
variable (D : SexticMumford.SemiMumford M)
/-- The monic polynomial quotient has its canonical quadratic power basis. -/
def residueBasis
    (hdeg : D.u.natDegree = 2) :
    Basis (Fin 2) K (AdjoinRoot D.u) :=
  (AdjoinRoot.powerBasis' D.u_monic).basis.reindex
    (finCongr hdeg)
end
end MazurProof.SexticMumfordQuotientBasis
end

end

-- ===== FLT.Assumptions.MazurProof.N13CanonicalContractionQuotient =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13CanonicalContractionQuotient =====
section
/-!
# Generic quotient of a canonical N13 contraction

Extending a canonical vertical contraction to the generic fibre recovers the
original ideal.  The induced map on affine quotients is injective: membership
in the contraction is definitionally membership of the image in the generic
ideal.  For a quadratic Mumford graph, this map carries the literal integral
classes of `1` and `x` to the literal generic quotient basis `{1,x}`.
-/
open Polynomial
namespace MazurProof.N13CanonicalContractionQuotient
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralModelContraction.R₂
abbrev Q₂ : Type :=
  N13IntegralModelContraction.Q₂
abbrev IntegralRing : Type :=
  N13IntegralModelContraction.IntegralRing
/-- The integral affine `x` coordinate. -/
def integralX : IntegralRing :=
  N13GeneralizedMumfordIntegral.xClass (R := R₂) X
end
end MazurProof.N13CanonicalContractionQuotient
end

end

-- ===== FLT.Assumptions.MazurProof.N13QuotientVerticalFlatness =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13QuotientVerticalFlatness =====
section
/-!
# Vertical saturation gives flat N13 quotients

The canonical contraction of a generic ideal is saturated with respect to
every nonzero two-adic scalar.  Consequently its affine quotient has no
two-adic torsion.  Since the two-adic integers form a Dedekind domain, the
quotient is flat even before finiteness has been established.

This separates the easy vertical part of the two-fibre argument from the
genuine no-escape/finiteness step.
-/
namespace MazurProof.N13QuotientVerticalFlatness
noncomputable section
universe uR uA
variable {R : Type uR} {A : Type uA}
variable [CommRing R] [IsDomain R]
variable [CommRing A] [Algebra R A]
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralModelContraction.R₂
abbrev IntegralRing : Type :=
  N13IntegralModelContraction.IntegralRing
end
end MazurProof.N13QuotientVerticalFlatness
end

end

-- ===== FLT.Assumptions.MazurProof.N13SymmetricSquareTwo =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SymmetricSquareTwo =====
section
/-!
# The symmetric-square route to `#J(F₂)=19`

For a genus-two curve, the Abel map `Sym²(C) → J` is an isomorphism away
from the canonical divisor class.  Its exceptional fibre is the canonical
linear system `P¹`.  Over `F₂` this replaces three points by one.

The good N13 model has six `F₂`-points, so its ordinary symmetric square has
`6 multichoose 2 = 21` points.  This file proves the finite fibre-counting
argument that turns the geometric Abel-fibre statement into
`#J(F₂)=21-2=19`.  It deliberately isolates the remaining geometric input
as a structure, rather than assuming a general zeta-function API or
enumerating Jacobian representatives.
-/
namespace MazurProof.N13SymmetricSquareTwo
noncomputable section
open scoped BigOperators
abbrev CurvePoint :=
  N13GoodModelTwo.CompletedPoint N13GoodModelTwo.F2
/-- Unordered effective divisors of degree two on the special fibre. -/
abbrev EffectiveDivisorTwo :=
  Sym2 CurvePoint
section FiberCounting
variable {A B : Type*} [Fintype A] [Fintype B] [DecidableEq B]
end FiberCounting
end
end MazurProof.N13SymmetricSquareTwo
end

end

-- ===== FLT.Assumptions.MazurProof.N13AbelFiberTwoModel =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13AbelFiberTwoModel =====
section
/-!
# A finite set model for the N13 Abel fibres at two

The six points of the good characteristic-two model form three
hyperelliptic pairs.  On `Sym²(C)(F₂)`, collapse the three corresponding
canonical divisors to one class and leave every other divisor unchanged.
The resulting quotient has nineteen elements.

This quotient is only a set-level model of the expected Abel fibres.  It is
not asserted to be the geometric Picard group.  The structure
`GeometricAbelCriterion` records exactly the geometric statements required
to transfer the same fibre calculation to a genuine Picard target.
-/
namespace MazurProof.N13AbelFiberTwoModel
noncomputable section
open N13GoodModelTwo
open N13SymmetricSquareTwo
abbrev K := F2
abbrev CurvePoint := CompletedPoint K
/-- The three rational points of the hyperelliptic base. -/
abbrev BasePoint := K ⊕ Unit
def baseAtInfinity : BasePoint := Sum.inr ()
/-! ## Interface to a genuine geometric Picard target -/
namespace GeometricAbelCriterion
variable {J : Type*}
end GeometricAbelCriterion
end
end MazurProof.N13AbelFiberTwoModel
end

end

-- ===== FLT.Assumptions.MazurProof.N13FormalAbelLinearization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FormalAbelLinearization =====
section
/-!
# The integral linearization of an N13 Abel chart

The two integral points `(0,0)` and `(-1,0)` reduce to points with distinct
`x`-coordinates.  Their degree-two sum is therefore away from the canonical
hyperelliptic pencil.  In generalized Mumford coordinates its base
polynomial is `X² + X`, and the linearized curve relation has determinant
`-1`.

This file proves the polynomial identities behind that unit Jacobian over an
arbitrary nontrivial commutative ring.  No point or divisor enumeration is
used.
-/
open Polynomial
namespace MazurProof.N13FormalAbelLinearization
noncomputable section
universe u
variable {R : Type u} [CommRing R]
/-- The monic polynomial of the base divisor `(0,0)+(-1,0)`. -/
def uBase : R[X] :=
  X ^ 2 + X
/-- The coefficient of `Y` in the good generalized equation. -/
def hPoly : R[X] :=
  X ^ 3 + X + 1
theorem uBase_monic : (uBase : R[X]).Monic := by
  unfold uBase
  (monicity; norm_num)
/-! ## The Abel differential -/
end
end MazurProof.N13FormalAbelLinearization
end

end

-- ===== FLT.Assumptions.MazurProof.N13AbelChartBase =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13AbelChartBase =====
section
/-!
# The nonspecial base divisor for the N13 Abel chart

The integral divisor

`(0,0) + (-1,0)`

has generalized Mumford pair `u = X² + X`, `v = 0`.  Its reduction is the
unordered pair of the sheet-zero points over the distinct affine base
coordinates `0` and `1`.  A canonical hyperelliptic fibre contains one
point on each sheet, so this reduced divisor is noncanonical.

The same base pair satisfies a short Bézout identity.  Hence its graph ideal
is one of the smooth integral Mumford ideals already shown to commute with
reduction.
-/
open Polynomial
namespace MazurProof.N13AbelChartBase
noncomputable section
open N13AbelFiberTwoModel
open N13SymmetricSquareTwo
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev K : Type :=
  N13AbelFiberTwoModel.K
end
end MazurProof.N13AbelChartBase
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialDualFrame =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialDualFrame =====
section
/-!
# The explicit special-fibre dual frame

For the selected nonspecial graph ideal `(X²+X,Y)`, three explicit primal
and multiplier-dual elements have evaluation sum one.  The only
denominator is `(Y+h)/(X²+X)`; its inverse-ideal membership follows
directly from the curve equation.

This is a symbolic certificate in the special affine coordinate ring.  It
does not use invertibility of the graph ideal and is therefore suitable as
the input relation for the two-chart lifting argument.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13SpecialDualFrame
noncomputable section
abbrev k : Type := N13GoodCoordinateRingTwo.K
abbrev A : Type := N13GoodCoordinateRingTwo.CoordinateRing
abbrev F : Type := N13GoodCoordinateRingTwo.FunctionField
abbrev Frac : Type := FractionalIdeal A⁰ F
def u : k[X] := X ^ 2 + X
def c : k[X] := X ^ 2 + X + 1
def I : Ideal A :=
  N13GoodCoordinateRingTwo.mumfordIdeal u 0
def uF : F :=
  algebraMap A F (N13GoodCoordinateRingTwo.xClass u)
def cF : F :=
  algebraMap A F (N13GoodCoordinateRingTwo.xClass c)
def x3F : F :=
  algebraMap A F (N13GoodCoordinateRingTwo.xClass (X ^ 3))
def yF : F :=
  algebraMap A F N13GoodCoordinateRingTwo.yClass
def hF : F :=
  algebraMap A F
    (N13GoodCoordinateRingTwo.xClass
      N13GoodCoordinateRingTwo.hPoly)
/-- The three evaluations already lie in the special affine coordinate
ring, despite the denominator in the middle dual factor. -/
def product : Fin 3 → A :=
  ![
    N13GoodCoordinateRingTwo.xClass u *
      N13GoodCoordinateRingTwo.xClass (X ^ 3),
    N13GoodCoordinateRingTwo.xClass c *
      (N13GoodCoordinateRingTwo.yClass +
        N13GoodCoordinateRingTwo.xClass
          N13GoodCoordinateRingTwo.hPoly),
    N13GoodCoordinateRingTwo.yClass *
      N13GoodCoordinateRingTwo.xClass c
  ]
end
end MazurProof.N13SpecialDualFrame
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialQuotientBasis =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialQuotientBasis =====
section
/-!
# The literal basis of the fixed N13 special quotient

The selected special divisor has graph ideal `(X²+X,Y)`.  Evaluation on
that graph identifies its affine quotient with
`𝔽₂[X]/(X²+X)`.  The canonical monic power basis on the latter transports
back to the literal quotient basis `{1,x}`.

This file is only the fixed special-fibre endpoint.  It does not assert
that the contraction of an arbitrary generic Picard representative reduces
to this ideal.
-/
open Module
open Polynomial
namespace MazurProof.N13SpecialQuotientBasis
noncomputable section
abbrev k : Type :=
  N13GoodCoordinateRingTwo.K
abbrev A : Type :=
  N13GoodCoordinateRingTwo.CoordinateRing
end
end MazurProof.N13SpecialQuotientBasis
end

end

-- ===== FLT.Assumptions.MazurProof.N13TensorSpecialFiber =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TensorSpecialFiber =====
section
/-!
# Identifying a tensor special fibre from its quotient map

Suppose a surjective quotient-reduction map has kernel generated by the
image of a uniformizer.  Tensoring with the residue field then gives the
target quotient exactly.  The proof uses pure tensors and moves the
uniformizer to the residue-field factor; it does not identify a separate
quotient of the source ideal.
-/
open scoped TensorProduct
open Module
namespace MazurProof.N13TensorSpecialFiber
noncomputable section
universe uR uk uB uC uι
variable {R : Type uR} {k : Type uk}
variable {B : Type uB} {C : Type uC}
variable [CommRing R] [CommRing k]
variable [CommRing B] [CommRing C]
variable [Algebra R k] [Algebra R B] [Algebra R C]
variable [Algebra k C] [IsScalarTower R k C]
/-- Regard a ring homomorphism as an `R`-algebra homomorphism through the
supplied scalar factorization. -/
def factoredAlgHom
    (g : B →+* C)
    (hfactor :
      g.comp (algebraMap R B) =
        (algebraMap k C).comp (algebraMap R k)) :
    B →ₐ[R] C where
  toRingHom := g
  commutes' r := by
    calc
      g (algebraMap R B r) =
          algebraMap k C (algebraMap R k r) := by
        simpa only [RingHom.comp_apply] using
          DFunLike.congr_fun hfactor r
      _ = algebraMap R C r :=
        (IsScalarTower.algebraMap_apply R k C r).symm
@[simp] theorem factoredAlgHom_apply
    (g : B →+* C)
    (hfactor :
      g.comp (algebraMap R B) =
        (algebraMap k C).comp (algebraMap R k))
    (b : B) :
    factoredAlgHom g hfactor b = g b :=
  rfl
/-- The canonical map `a ⊗ b ↦ a • g(b)`. -/
def tensorLinearMap
    (g : B →+* C)
    (hfactor :
      g.comp (algebraMap R B) =
        (algebraMap k C).comp (algebraMap R k)) :
    k ⊗[R] B →ₗ[k] C :=
  (factoredAlgHom g hfactor).toLinearMap.liftBaseChange k
@[simp] theorem tensorLinearMap_tmul
    (g : B →+* C)
    (hfactor :
      g.comp (algebraMap R B) =
        (algebraMap k C).comp (algebraMap R k))
    (a : k) (b : B) :
    tensorLinearMap g hfactor (a ⊗ₜ[R] b) =
      a • g b := by
  simp [tensorLinearMap]
theorem tensorLinearMap_eq_zero
    (g : B →+* C)
    (hfactor :
      g.comp (algebraMap R B) =
        (algebraMap k C).comp (algebraMap R k))
    (hq : Function.Surjective (algebraMap R k))
    (π : R)
    (hπ : algebraMap R k π = 0)
    (hker :
      RingHom.ker g =
        Ideal.span ({algebraMap R B π} : Set B))
    {z : k ⊗[R] B}
    (hz : tensorLinearMap g hfactor z = 0) :
    z = 0 := by
  obtain ⟨b, rfl⟩ :=
    (TensorProduct.mk_surjective R B k hq) z
  change
    tensorLinearMap g hfactor
        ((1 : k) ⊗ₜ[R] b) = 0 at hz
  change (1 : k) ⊗ₜ[R] b = 0
  have hgb : g b = 0 := by
    simpa only [tensorLinearMap_tmul, one_smul] using hz
  have hbker : b ∈ RingHom.ker g :=
    RingHom.mem_ker.mpr hgb
  rw [hker, Ideal.mem_span_singleton] at hbker
  obtain ⟨c, rfl⟩ := hbker
  calc
    (1 : k) ⊗ₜ[R] (algebraMap R B π * c) =
        (1 : k) ⊗ₜ[R] (π • c) := by
      rw [Algebra.smul_def]
    _ = (π • (1 : k)) ⊗ₜ[R] c :=
      (TensorProduct.smul_tmul
        (R := R) π (1 : k) c).symm
    _ = 0 := by
      simp only [Algebra.smul_def, hπ, zero_mul,
        TensorProduct.zero_tmul]
theorem tensorLinearMap_injective
    (g : B →+* C)
    (hfactor :
      g.comp (algebraMap R B) =
        (algebraMap k C).comp (algebraMap R k))
    (hq : Function.Surjective (algebraMap R k))
    (π : R)
    (hπ : algebraMap R k π = 0)
    (hker :
      RingHom.ker g =
        Ideal.span ({algebraMap R B π} : Set B)) :
    Function.Injective (tensorLinearMap g hfactor) := by
  intro z₁ z₂ hz
  have hzero :
      tensorLinearMap g hfactor (z₁ - z₂) = 0 := by
    simpa only [map_sub, hz, sub_self]
  exact sub_eq_zero.mp
    (tensorLinearMap_eq_zero
      (g := g) (hfactor := hfactor)
      (hq := hq) (π := π) (hπ := hπ)
      (hker := hker) hzero)
theorem tensorLinearMap_surjective
    (g : B →+* C)
    (hfactor :
      g.comp (algebraMap R B) =
        (algebraMap k C).comp (algebraMap R k))
    (hg : Function.Surjective g) :
    Function.Surjective (tensorLinearMap g hfactor) := by
  intro c
  obtain ⟨b, rfl⟩ := hg c
  exact ⟨(1 : k) ⊗ₜ[R] b, by simp⟩
/-- The explicit linear equivalence between the tensor special fibre and
the target quotient. -/
def tensorLinearEquiv
    (g : B →+* C)
    (hfactor :
      g.comp (algebraMap R B) =
        (algebraMap k C).comp (algebraMap R k))
    (hq : Function.Surjective (algebraMap R k))
    (π : R)
    (hπ : algebraMap R k π = 0)
    (hg : Function.Surjective g)
    (hker :
      RingHom.ker g =
        Ideal.span ({algebraMap R B π} : Set B)) :
    k ⊗[R] B ≃ₗ[k] C :=
  LinearEquiv.ofBijective (tensorLinearMap g hfactor)
    ⟨tensorLinearMap_injective
        (g := g) (hfactor := hfactor)
        (hq := hq) (π := π) (hπ := hπ)
        (hker := hker),
      tensorLinearMap_surjective
        (g := g) (hfactor := hfactor) hg⟩
section ResidueField
variable [IsLocalRing R]
variable [Algebra (IsLocalRing.ResidueField R) C]
variable [IsScalarTower R (IsLocalRing.ResidueField R) C]
theorem residueFactor
    (g : B →+* C)
    (hfactor :
      g.comp (algebraMap R B) =
        (algebraMap (IsLocalRing.ResidueField R) C).comp (IsLocalRing.residue R)) :
    g.comp (algebraMap R B) =
      (algebraMap (IsLocalRing.ResidueField R) C).comp (algebraMap R (IsLocalRing.ResidueField R)) := by
  simpa only [IsLocalRing.ResidueField.algebraMap_eq R] using hfactor
theorem residueAlgebraMap_surjective :
    Function.Surjective (algebraMap R (IsLocalRing.ResidueField R)) := by
  simpa only [IsLocalRing.ResidueField.algebraMap_eq R] using
    (IsLocalRing.residue_surjective (R := R))
theorem residueElement_eq_zero
    (π : R)
    (hπ : π ∈ IsLocalRing.maximalIdeal R) :
    algebraMap R (IsLocalRing.ResidueField R) π = 0 := by
  rw [IsLocalRing.ResidueField.algebraMap_eq R,
    IsLocalRing.residue_eq_zero_iff]
  exact hπ
/-- Residue-field specialization of `tensorLinearEquiv`. -/
def residueLinearEquiv
    (g : B →+* C)
    (hfactor :
      g.comp (algebraMap R B) =
        (algebraMap (IsLocalRing.ResidueField R) C).comp (IsLocalRing.residue R))
    (π : R)
    (hπ : π ∈ IsLocalRing.maximalIdeal R)
    (hg : Function.Surjective g)
    (hker :
      RingHom.ker g =
        Ideal.span ({algebraMap R B π} : Set B)) :
    (IsLocalRing.ResidueField R) ⊗[R] B ≃ₗ[(IsLocalRing.ResidueField R)] C :=
  tensorLinearEquiv
    (g := g)
    (hfactor := residueFactor g hfactor)
    (hq := residueAlgebraMap_surjective (R := R))
    (π := π)
    (hπ := residueElement_eq_zero π hπ)
    (hg := hg)
    (hker := hker)
end ResidueField
section BasisTransport
variable {ι : Type uι}
/-- Pull a target basis back through the special-fibre equivalence. -/
def pullbackBasis
    (e : k ⊗[R] B ≃ₗ[k] C)
    (bC : Basis ι k C) :
    Basis ι k (k ⊗[R] B) :=
  bC.map e.symm
end BasisTransport
end
end MazurProof.N13TensorSpecialFiber
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoFiberNoEscape =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoFiberNoEscape =====
section
/-!
# Excluding denominator escape from two literal fibres

Let `B` be a torsion-free algebra over a domain `R`, with uniformizer
`π`.  Suppose two elements `e₀,e₁` reduce to a basis of a quotient over
`k = R/(π)`.  If every element of `B` can be brought into the span of
`e₀,e₁` after multiplication by some power of `π`, then it was already
in that span.

The proof removes one factor of `π` at a time.  Reduction modulo `π`
forces both coefficients to be divisible by `π`, and torsion-freeness
cancels the common factor.  This is the algebraic two-fibre no-escape
argument; it uses neither a finite presentation nor a valuation table.
-/
open Module
namespace MazurProof.N13TwoFiberNoEscape
noncomputable section
universe uR uk uB uC
variable {R : Type uR} {k : Type uk}
variable {B : Type uB} {C : Type uC}
variable [CommRing R] [IsDomain R]
variable [Field k]
variable [CommRing B] [CommRing C]
variable [Algebra R k] [Algebra R B] [Algebra R C]
variable [Algebra k C] [IsScalarTower R k C]
variable [Module.IsTorsionFree R B]
/-- The literal ordered pair used on both fibres. -/
def pairFamily (e₀ e₁ : B) : Fin 2 → B :=
  ![e₀, e₁]
section FractionFieldClearing
universe uK uG
variable {K : Type uK} {G : Type uG}
variable [Field K] [CommRing G]
variable [Algebra R K] [IsFractionRing R K]
variable [Algebra R G] [Algebra K G]
variable [IsScalarTower R K G]
end FractionFieldClearing
end
end MazurProof.N13TwoFiberNoEscape
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoFiberConcreteBasis =====
section
-- ===== FLT.Assumptions.MazurProof.N13TwoFiberConcreteBasis =====
section
/-!
# The concrete two-fibre basis for an N13 contraction

Assume only the remaining representative-level statement that the canonical
contraction reduces to the fixed special graph ideal.  The generic and special
quotient frames are then both literally `{1,x}`.  The two-fibre no-escape
theorem therefore makes the same pair an integral basis, without any prior
finiteness assumption.
-/
open Polynomial
open Module
open scoped TensorProduct
namespace MazurProof.N13TwoFiberConcreteBasis
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralModelContraction.R₂
abbrev Q₂ : Type :=
  N13IntegralModelContraction.Q₂
abbrev k : Type :=
  N13GoodCoordinateRingTwo.K
abbrev IntegralRing : Type :=
  N13IntegralModelContraction.IntegralRing
abbrev SpecialRing : Type :=
  N13GeneralizedMumfordReduction.SpecialRing
abbrev κ : Type :=
  IsLocalRing.ResidueField R₂
local instance baseSpecialAlgebra : Algebra R₂ k :=
  N13GeneralizedMumfordReduction.reduceBase.toAlgebra
universe uR uK uB uG uι
end
end MazurProof.N13TwoFiberConcreteBasis
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralFractionalHull =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralFractionalHull =====
section
/-!
# Divisorial hulls on the N13 integral model

The N13 generic affine ring is the vertical localization of its integral
good-model ring.  This file proves that the common function field is also the
fraction field of the integral model and that vertical extension commutes with
inverse fractional ideals.

The reverse inclusion is the substantive point: a fractional ideal over the
Noetherian integral model has finitely many generators, so one vertical scalar
clears all denominators of their products with a generic inverse section.
Consequently the divisorial double inverse of a contracted invertible generic
ideal has exactly the original generic fibre.  No affine generator or
principality assumption is used.
-/
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralFractionalHull
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev IntegralRing : Type :=
  N13IntegralModelContraction.IntegralRing
end
end MazurProof.N13IntegralFractionalHull
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralGraphContraction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralGraphContraction =====
section
/-!
# Exact contraction of integral N13 graph ideals

Coefficient extension and contraction already fix a smooth integral
generalized Mumford graph ideal.  Completion of the square is a coordinate
ring equivalence, so it cancels formally from a further extension and
contraction.  Hence the standard sextic graph contracts to the original
integral graph exactly.

This is a representative-level equality.  It does not construct an
integral graph from a generic Picard class.
-/
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralGraphContraction
noncomputable section
abbrev IntegralRing : Type :=
  N13IntegralModelContraction.IntegralRing
abbrev SmoothMumford₂ : Type :=
  N13GeneralizedMumfordReduction.SmoothMumford₂
abbrev SemiMumford₂ : Type :=
  N13GeneralizedMumfordIntegral.TwoAdic.SemiMumford₂
end
end MazurProof.N13IntegralGraphContraction
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialGraphDivisor =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialGraphDivisor =====
section
/-!
# Degree-two Mumford graphs as effective divisors on the N13 special fibre

A monic quadratic generalized Mumford graph on the good characteristic-two
model splits over `F₂`.  Indeed, an irreducible quadratic would produce an
affine point over its quadratic root field, while the structural Frobenius
classification forces that root back into `F₂`.

The two roots, with their graph values, therefore define an effective
degree-two divisor.  If that divisor is the selected nonspecial base divisor,
its two distinct points force `u = X² + X` and `u ∣ v`; hence its graph ideal
is literally the fixed special ideal.  No finite table or representative
enumeration is used.
-/
open Polynomial
open scoped Sym2
namespace MazurProof.N13SpecialGraphDivisor
noncomputable section
open MazurProof.N13GoodCoordinateRingTwo
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13SpecialGraphDivisor
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialGraphReduction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialGraphReduction =====
section
/-!
# Abel-compatible reduction of integral N13 Mumford graphs

Coefficientwise reduction of a smooth integral generalized Mumford graph is
again a special-fibre Mumford graph.  If its effective degree-two divisor
has the selected set-valued Abel class, special Abel rigidity identifies the
literal reduced graph ideal with `(X²+X,Y)`.

Combining this with exact contraction of integral sextic graphs gives the
representative-level special-ideal equality required by the two-fibre graph
recovery theorem.  The remaining geometric input is now only the existence
of an integral representative and its Abel compatibility.
-/
open Polynomial
namespace MazurProof.N13SpecialGraphReduction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev SmoothMumford₂ : Type :=
  N13GeneralizedMumfordReduction.SmoothMumford₂
/-- Monic degree is preserved by coefficientwise reduction. -/
theorem reduceSmoothMumford_u_natDegree
    (D : SmoothMumford₂)
    (hdeg : D.u.natDegree = 2) :
    (N13GeneralizedMumfordReduction.reduceSmoothMumford D).u.natDegree =
      2 := by
  change
    (D.u.map
      N13GeneralizedMumfordReduction.reduceBase).natDegree = 2
  calc
    (D.u.map
        N13GeneralizedMumfordReduction.reduceBase).natDegree =
        D.u.natDegree :=
      D.u_monic.natDegree_map
        N13GeneralizedMumfordReduction.reduceBase
    _ = 2 := hdeg
end
end MazurProof.N13SpecialGraphReduction
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoAdicDisks =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoAdicDisks =====
section
/-!
# The two integral residue disks used by the N13 Abel chart

For the good equation

`y² + (x³ + x + 1)y = x⁵ + x⁴`

over the two-adic integers, the fibres above the residue disks of `0` and
`-1` have a unique point whose `y`-coordinate lies in the maximal ideal.
Existence is one-variable Hensel lifting in the `y` coordinate.  Uniqueness
is the elementary factorization of the difference of two roots.

This is the local-curve part of the nonspecial Abel chart; it uses neither a
Picard scheme nor finite congruence tables.
-/
open Polynomial
namespace MazurProof.N13TwoAdicDisks
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  ℤ_[2]
/-- The good equation, viewed as a monic polynomial in `Y`. -/
abbrev yFiber (x : R₂) : R₂[X] :=
  N13GoodModelTwo.affineFiber x
theorem yFiber_monic (x : R₂) :
    (yFiber x).Monic := by
  unfold yFiber N13GoodModelTwo.affineFiber
  monicity <;> norm_num
@[simp] theorem yFiber_eval (x y : R₂) :
    (yFiber x).eval y =
      N13GoodModelTwo.affineResidual x y :=
  N13GoodModelTwo.affineFiber_eval x y
/-! ## The disk above `(0,0)` -/
/-! ## The disk above `(-1,0)` -/
end
end MazurProof.N13TwoAdicDisks
end

end

-- ===== FLT.Assumptions.MazurProof.N18RouteC_Separated =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N18RouteC_Separated =====
section
/-!
# Weak descent and formal-kernel separatedness for N18 Route C

This file is independent of any Mordell--Weil finite-generation theorem.  It
turns a weak `3`-descent, a seven-torsion reduction group, and strict growth in
the formal kernel into the uniform annihilator `[21]`.
-/
namespace MazurProof.N18RouteC.Separated
noncomputable section
def InfinitelyNSmulDivisible
    {G : Type*} [AddCommGroup G] (n : ℕ) (x : G) : Prop :=
  ∀ k : ℕ, ∃ y : G, (n ^ k) • y = x
def NSeparated (G : Type*) [AddCommGroup G] (n : ℕ) : Prop :=
  ∀ x : G, InfinitelyNSmulDivisible n x → x = 0
end
end MazurProof.N18RouteC.Separated
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoAdicKernelChart =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoAdicKernelChart =====
section
/-!
# A structural two-adic kernel chart

This file isolates the elementary formal-group argument needed for N13.
Suppose an additive group has two coordinates in `ℤ₂`, every coordinate is
divisible by two, and addition differs from coordinatewise addition by an
element of the product of the two coordinate ideals.  Then doubling raises
coordinate depth by at least one.  Infinite two-divisibility is therefore
incompatible with the separated two-adic filtration.

No formal power series, point table, or explicit genus-two addition formula
is used below.  The eventual curve-specific input is only the
cross-quadratic error statement.
-/
namespace MazurProof.N13TwoAdicKernelChart
noncomputable section
open N18RouteC.Separated
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  ℤ_[2]
universe u
variable {K : Type u} [AddCommGroup K]
namespace Chart
end Chart
/-! ## The unary doubling interface

Separatedness only iterates multiplication by two.  The binary addition
estimate above is therefore stronger than necessary: it is enough to know
the same quadratic error estimate on the diagonal. -/
namespace DoublingChart
end DoublingChart
end
end MazurProof.N13TwoAdicKernelChart
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAbelChartData =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAbelChartData =====
section
/-!
# Integral Mumford data on the nonspecial N13 two-adic Abel chart

A point in the residue disk of `(0,0)` and a point in the residue disk of
`(-1,0)` have distinct `x`-coordinates by a unit.  Lagrange interpolation
therefore gives an integral graph polynomial through the two points.

The product of the two linear factors divides the curve residual.  The same
interpolation argument, applied to the inverses of the two vertical
derivatives, gives the smoothness Bezout identity.  Thus every such pair
defines smooth generalized Mumford data over `ℤ₂`, without a search through
congruence classes.
-/
open Polynomial
namespace MazurProof.N13TwoAdicAbelChartData
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  ℤ_[2]
namespace DiskPair
end DiskPair
end
end MazurProof.N13TwoAdicAbelChartData
end

end

-- ===== FLT.Assumptions.MazurProof.N13LaurentPolynomialOrder =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13LaurentPolynomialOrder =====
section
/-!
# The order at infinity of a polynomial

The substitution `X = s⁻¹` reverses a polynomial.  Its leading
coefficient becomes the constant coefficient of the reversed polynomial,
so the latter has order zero; the factor `s⁻ⁿ` accounts for the whole
order.  This is the formal local calculation used at the cusps of `X₁(13)`.
-/
open Polynomial
open scoped LaurentSeries PowerSeries
namespace MazurProof
namespace N13LaurentPolynomialOrder
noncomputable section
universe u
variable (K : Type u) [Field K]
/-- The Laurent parameter at infinity. -/
def parameter : LaurentSeries K := HahnSeries.single 1 1
/-- Evaluation of a polynomial after the substitution `X = s⁻¹`. -/
def evalAtInfinity (p : K[X]) : LaurentSeries K :=
  p.eval₂ (algebraMap K (LaurentSeries K)) (parameter K)⁻¹
@[simp] lemma parameter_ne_zero : parameter K ≠ 0 := by
  simp [parameter]
end
end N13LaurentPolynomialOrder
end MazurProof
end

end

-- ===== FLT.Assumptions.MazurProof.N13BranchNorm =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13BranchNorm =====
section
/-!
# The two infinity branches and the quadratic norm on `X₁(13)`

For an affine function `p(X) + q(X)Y`, the two Laurent embeddings differ
only in the sign of `Y`.  Their product is therefore the polynomial norm
`p² - q²f`.  This packages the structural reason that the two infinity
orders must be used together: cancellation at one branch is detected by
the other branch.
-/
open Polynomial
open scoped LaurentSeries
namespace MazurProof.N13BranchNorm
noncomputable section
universe u
variable (K : Type u) [Field K] [CharZero K]
def evalPoly : K[X] →+* LaurentSeries K :=
  Polynomial.eval₂RingHom (algebraMap K (LaurentSeries K))
    ((N13Infinity.parameter K)⁻¹)
omit [CharZero K] in
@[simp] theorem evalPoly_apply (p : K[X]) :
    evalPoly K p =
      p.eval₂ (algebraMap K (LaurentSeries K))
        ((N13Infinity.parameter K)⁻¹) := rfl
omit [CharZero K] in
theorem evalPoly_eq_evalAtInfinity (p : K[X]) :
    evalPoly K p =
      N13LaurentPolynomialOrder.evalAtInfinity K p := by
  rfl
def normNumerator (p q : K[X]) : K[X] :=
  p ^ 2 - q ^ 2 * N13Mumford.f K
end
end MazurProof.N13BranchNorm
end

end

-- ===== FLT.Assumptions.MazurProof.N13BranchLeading =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13BranchLeading =====
section
/-!
# Leading pole degree across the two infinity branches

For `p(X) + q(X)Y`, cancellation can raise the order at one infinity, but
it cannot raise the order at both.  The minimum of the two branch orders is
the negative of

`max (deg p) (deg q + 3)`.

The proof is valuation-theoretic.  For arbitrary Laurent series `a,b`, the
pair `a+b, a-b` remembers the smaller of the orders of `a,b`, because `2` is
invertible.  This avoids any coefficient enumeration.
-/
open Polynomial
open scoped LaurentSeries
namespace MazurProof.N13BranchLeading
noncomputable section
universe u
variable (K : Type u) [Field K] [CharZero K]
def poleDegree (p q : K[X]) : ℕ :=
  by
    classical
    exact max p.natDegree (if q = 0 then 0 else q.natDegree + 3)
end
end MazurProof.N13BranchLeading
end

end

-- ===== FLT.Assumptions.MazurProof.SexticMumfordCantorReduction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.SexticMumfordCantorReduction =====
section
/-!
# One-step Cantor reduction for a monic sextic

This file isolates the structural algebra used by a well-founded Cantor
reduction.  It contains no enumeration and no Riemann--Roch input.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.SexticMumford
noncomputable section
universe u
variable {K : Type u} [Field K]
variable (M : Model K)
local instance instDecidableEq_fLT : DecidableEq K := Classical.decEq K
/-! ## Changing the graph polynomial modulo `u` -/
/-! ## The Cantor product identity -/
/-! ## Degree descent -/
/-! ## The normalized next semirepresentative -/
/-! ## Conjugating the complement -/
/-! ## Principal functions in one oriented step -/
/-! ## Exact oriented update -/
end
end MazurProof.SexticMumford
end

end

-- ===== FLT.Assumptions.MazurProof.N13MumfordInfinityBalance =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MumfordInfinityBalance =====
section
/-!
# Structural infinity balancing for the true `X₁(13)` sextic

The polynomial used here is exactly

`X⁶ + 4X⁵ + 6X⁴ + 2X³ + X² + 2X + 1`.

Its positive-infinity cubic part is

`s = X³ + 2X² + X - 1`,

with the exact low-degree identity `f - s² = 4X(X+1)`.  This file builds
the two adapted Cantor lifts needed to balance the integer at infinity.
There is no divisor enumeration or Riemann--Roch input.
-/
open Polynomial
open scoped LaurentSeries nonZeroDivisors
namespace MazurProof.N13MumfordInfinityBalance
noncomputable section
universe u
variable {K : Type u} [Field K] [CharZero K]
open MazurProof
open MazurProof.SexticMumford
/-- Polynomial part of the positive branch `Y` at infinity. -/
def sqrtInfinity : K[X] :=
  X ^ 3 + 2 * X ^ 2 + X - 1
theorem sqrtInfinity_isMonicOfDegree :
    IsMonicOfDegree (sqrtInfinity : K[X]) 3 := by
  constructor
  · unfold sqrtInfinity
    compute_degree!
  · unfold sqrtInfinity
    monicity!
@[simp] theorem sqrtInfinity_natDegree :
    (sqrtInfinity : K[X]).natDegree = 3 :=
  sqrtInfinity_isMonicOfDegree.natDegree_eq
/-! ## The two adapted lifts -/
/-! ## Degree bounds -/
theorem two_mul_sqrt_mul_natDegree_le
    (r : K[X]) {d : ℕ} (hr : r.natDegree < d) :
    (2 * (sqrtInfinity : K[X]) * r).natDegree ≤ d + 2 := by
  calc
    (2 * (sqrtInfinity : K[X]) * r).natDegree ≤
        (2 * (sqrtInfinity : K[X])).natDegree + r.natDegree :=
      natDegree_mul_le
    _ ≤ ((2 : K[X]).natDegree +
          (sqrtInfinity : K[X]).natDegree) + r.natDegree := by
      gcongr
      exact natDegree_mul_le
    _ = 3 + r.natDegree := by simp
    _ ≤ d + 2 := by omega
omit [CharZero K] in
theorem remainder_sq_natDegree_le
    (r : K[X]) {d : ℕ} (hd : d ≤ 2) (hr : r.natDegree < d) :
    (r ^ 2).natDegree ≤ d + 2 := by
  rw [natDegree_pow]
  omega
/-! ## Leading terms at the two infinities -/
/-! ## Exact orders of the principal Cantor corrections -/
/-! ## The two class-preserving balancing steps -/
/-! ## A well-founded measure for the two balance walls -/
/-! ## Structural infinity balancing -/
end
end MazurProof.N13MumfordInfinityBalance
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAbelChartPic =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAbelChartPic =====
section
/-!
# The N13 two-adic Abel chart inside the oriented Picard group

Every pair in the two distinguished residue disks gives smooth integral
generalized Mumford data.  After extending coefficients and completing the
square, the resulting standard sextic semirepresentative already has degree
two and infinity balance zero.  It is therefore a balanced Mumford
representative over `ℚ₂`.

Unique balanced normal forms make the resulting map to the oriented Picard
group injective.  Translating by the distinguished base pair gives the
faithful chart centred at the identity.  Thus the remaining geometric input
for the formal-kernel argument is existence of representatives in this
chart, not their uniqueness.
-/
open Polynomial
namespace MazurProof.N13TwoAdicAbelChartPic
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev Q₂ : Type :=
  ℚ_[2]
namespace DiskPair
end DiskPair
end
end MazurProof.N13TwoAdicAbelChartPic
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAbelChartRecover =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAbelChartRecover =====
section
/-!
# Recovering the N13 two-disk divisor from an integral Mumford graph

Suppose a smooth integral generalized Mumford graph reduces to the fixed
nonspecial graph `(X² + X, 0)`.  Hensel lifting splits its monic quadratic
into one root in each of the residue disks of `0` and `-1`.  Evaluating the
curve relation at those roots and using uniqueness in the vertical Hensel
fibres identifies the graph values with the canonical disk lifts.

Consequently every such integral graph comes from a unique `DiskPair`, up
to the harmless operation of changing its graph polynomial by a multiple
of `u`.  This is the algebraic reverse of
`N13TwoAdicAbelChartData.DiskPair.smoothMumford`; no divisor enumeration or
properness shortcut is used.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13TwoAdicAbelChartRecover
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  ℤ_[2]
abbrev K : Type :=
  N13GoodCoordinateRingTwo.K
abbrev Q₂ : Type :=
  ℚ_[2]
namespace NearBaseMumford
theorem reduceBase_eval
    (p : R₂[X]) (a : R₂) :
    N13GeneralizedMumfordReduction.reduceBase (p.eval a) =
      (N13GeneralizedMumfordReduction.reducePoly p).eval
        (N13GeneralizedMumfordReduction.reduceBase a) := by
  rw [N13GeneralizedMumfordReduction.reducePoly_apply,
    Polynomial.eval_map_apply]
theorem reduceBase_derivative_eval
    (p : R₂[X]) (a : R₂) :
    N13GeneralizedMumfordReduction.reduceBase
        (p.derivative.eval a) =
      (N13GeneralizedMumfordReduction.reducePoly p).derivative.eval
        (N13GeneralizedMumfordReduction.reduceBase a) := by
  rw [N13GeneralizedMumfordReduction.reducePoly_apply,
    Polynomial.derivative_map, Polynomial.eval_map_apply]
end NearBaseMumford
end
end MazurProof.N13TwoAdicAbelChartRecover
end

end

-- ===== FLT.Assumptions.MazurProof.N13AbelCompatibleGraphRecover =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13AbelCompatibleGraphRecover =====
section
/-!
# Recovering an N13 disk pair from an Abel-compatible integral graph

A special-fibre Abel equality identifies the reduced quadratic graph with
the selected divisor.  Its graph polynomial is therefore zero modulo the
reduced quadratic, but need not itself reduce coefficientwise to zero.

This file removes that harmless choice of representative.  Replacing `v`
by its monic remainder modulo `u`, and changing `w` by the resulting exact
algebraic formula, preserves the generalized Mumford equation, smoothness,
and graph ideal.  The normalized graph then satisfies the literal hypotheses
of the two-adic Hensel recovery theorem.
-/
open Polynomial
namespace MazurProof.N13AbelCompatibleGraphRecover
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13GeneralizedMumfordReduction.R₂
abbrev SmoothMumford₂ : Type :=
  N13GeneralizedMumfordReduction.SmoothMumford₂
/-- The quotient removed from the graph polynomial. -/
def graphQuotient (D : SmoothMumford₂) : R₂[X] :=
  D.v /ₘ D.u
/-- The canonical graph polynomial of degree strictly below `u`. -/
def normalizedV (D : SmoothMumford₂) : R₂[X] :=
  D.v %ₘ D.u
theorem normalizedV_add_mul_graphQuotient
    (D : SmoothMumford₂) :
    normalizedV D + D.u * graphQuotient D = D.v :=
  Polynomial.modByMonic_add_div D.v D.u
end
end MazurProof.N13AbelCompatibleGraphRecover
end

end

-- ===== FLT.Assumptions.MazurProof.N13ConcreteGraphRecovery =====
section
-- ===== FLT.Assumptions.MazurProof.N13ConcreteGraphRecovery =====
section
/-!
# Recovering the integral N13 graph from the concrete two-fibre basis

The literal basis `{1,x}` turns multiplication by `x` into a monic
characteristic polynomial of degree two.  Expressing the quotient class of
`y` in that basis then recovers the canonical contraction literally as a
generalized Mumford graph ideal.
-/
open Module
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13ConcreteGraphRecovery
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralModelContraction.R₂
abbrev Q₂ : Type :=
  N13IntegralModelContraction.Q₂
abbrev IntegralRing : Type :=
  N13IntegralModelContraction.IntegralRing
abbrev SmoothMumford₂ : Type :=
  N13GeneralizedMumfordReduction.SmoothMumford₂
/-- The integral affine `y` coordinate. -/
def integralY : IntegralRing :=
  N13GeneralizedMumfordIntegral.yClass (R := R₂)
end
end MazurProof.N13ConcreteGraphRecovery
end

end

-- ===== FLT.Assumptions.MazurProof.N13FiniteFlatBasisLift =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FiniteFlatBasisLift =====
section
/-!
# Lifting the literal special-fibre basis `{1,x}`

For a finite flat algebra over a local ring, a family whose residue-field
base change is a basis is already a basis over the local ring.  This file
specializes the structural local lifting theorem to the literal family
`{1,x}` needed by the N13 quotient.
-/
open scoped TensorProduct
open Module
namespace MazurProof.N13FiniteFlatBasisLift
noncomputable section
universe uR uB
variable {R : Type uR} {B : Type uB}
variable [CommRing R] [IsLocalRing R]
variable [CommRing B] [Algebra R B]
variable [Module.Finite R B] [Module.Flat R B]
/-- The literal two-element family. -/
def oneX (x : B) : Fin 2 → B :=
  ![1, x]
end
end MazurProof.N13FiniteFlatBasisLift
end

end

-- ===== FLT.Assumptions.MazurProof.N13GenericQuotientLocalization =====
section
-- ===== FLT.Assumptions.MazurProof.N13GenericQuotientLocalization =====
section
/-!
# The generic fibre of a canonical N13 contraction

The quotient by a canonical vertical contraction becomes the original
Mumford quotient after inverting the nonzero two-adic scalars.  Consequently,
a contracted quadratic Mumford quotient has rank two over the two-adic
integers.  No preferred integral basis is used.
-/
open scoped nonZeroDivisors
namespace MazurProof.N13GenericQuotientLocalization
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type := N13IntegralModelContraction.R₂
abbrev Q₂ : Type := N13IntegralModelContraction.Q₂
abbrev IntegralRing : Type := N13IntegralModelContraction.IntegralRing
end
end MazurProof.N13GenericQuotientLocalization
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoGeneratorFiberBasis =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoGeneratorFiberBasis =====
section
/-!
# A two-generator basis dichotomy in dimension two

The special N13 affine coordinate ring, and every one of its quotients, is
generated by the literal coordinates `x` and `y`.  In a two-dimensional
quotient over a field, this implies structurally that either `{1,x}` or
`{1,y}` is a basis.
-/
open Module
open Polynomial
namespace MazurProof.N13TwoGeneratorFiberBasis
noncomputable section
universe uK uB
variable {K : Type uK} {B : Type uB}
variable [Field K] [CommRing B] [Algebra K B] [Nontrivial B]
abbrev SpecialField : Type := N13GoodCoordinateRingTwo.K
abbrev SpecialRing : Type :=
  N13GoodCoordinateRingTwo.CoordinateRing
end
end MazurProof.N13TwoGeneratorFiberBasis
end

end

-- ===== FLT.Assumptions.MazurProof.N13ContractQuotientXYBasis =====
section
-- ===== FLT.Assumptions.MazurProof.N13ContractQuotientXYBasis =====
section
open Module
open Polynomial
open scoped TensorProduct
/-!
# Coordinate bases for finite quadratic contractions

For a finite canonical contraction of a quadratic N13 Mumford quotient,
the special fibre is a two-dimensional algebra generated by the literal
coordinates `x` and `y`.  Thus either `{1,x}` or `{1,y}` is a basis on the
special fibre.  Finite flat lifting gives the same literal alternative
over the two-adic integers.
-/
namespace MazurProof.N13ContractQuotientXYBasis
noncomputable section
universe uF uK uA uι
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type := N13IntegralModelContraction.R₂
abbrev Q₂ : Type := N13IntegralModelContraction.Q₂
abbrev k : Type := N13GoodCoordinateRingTwo.K
abbrev κ : Type := IsLocalRing.ResidueField R₂
abbrev IntegralRing : Type := N13IntegralModelContraction.IntegralRing
abbrev SpecialRing : Type :=
  N13GeneralizedMumfordReduction.SpecialRing
local instance baseSpecialAlgebra : Algebra R₂ k :=
  N13GeneralizedMumfordReduction.reduceBase.toAlgebra
def integralY : IntegralRing :=
  N13GeneralizedMumfordIntegral.yClass (R := R₂)
end
end MazurProof.N13ContractQuotientXYBasis
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralGraphJacobian =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralGraphJacobian =====
section
/-!
# Integral N13 graph ideals and the affine Jacobian

This file instantiates the generic graph-Jacobian dual frame for the good
integral N13 equation.  A short resultant certificate proves that the two
relative Jacobian rows generate one globally, so every integral Mumford
graph ideal is invertible.  No fixed special graph or point classification
is used.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralGraphJacobian
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralModelContraction.R₂
abbrev IntegralRing : Type :=
  N13IntegralFractionalHull.IntegralRing
abbrev SemiMumford₂ : Type :=
  N13GeneralizedMumfordIntegral.SemiMumford
    (R := R₂)
open N13GeneralizedMumfordIntegral
/-- The relative `Y`-Jacobian row of
`Y² + h(X)Y - rhs(X)`. -/
def jacobianY : IntegralRing :=
  2 * yClass +
    xClass (hPoly (R := R₂))
/-- The relative `X`-Jacobian row of
`Y² + h(X)Y - rhs(X)`. -/
def jacobianX : IntegralRing :=
  xClass (derivative (hPoly (R := R₂))) *
      yClass -
    xClass (derivative (rhsPoly (R := R₂)))
/-- The first coordinate-ring coefficient of the Jacobian Bézout
certificate. -/
def bezoutA : IntegralRing :=
  (30 * xClass X ^ 5 + 97 * xClass X ^ 4 +
      92 * xClass X ^ 3 + 50 * xClass X + 31) +
    (10 * xClass X ^ 2 + 30 * xClass X - 3) *
      yClass
/-- The second coordinate-ring coefficient of the Jacobian Bézout
certificate. -/
def bezoutB : IntegralRing :=
  (63 * xClass X ^ 5 + 153 * xClass X ^ 4 +
      98 * xClass X ^ 3 + 13 * xClass X ^ 2 -
      13 * xClass X + 13) +
    (60 * xClass X ^ 4 + 151 * xClass X ^ 3 +
      151 * xClass X ^ 2 - 63 * xClass X + 60) *
      yClass
/-! ## Graphs without a monicity hypothesis

Monicity is needed by the quotient-basis and contraction arguments, but not
by the Jacobian dual frame.  The following version isolates the exact
regularity input here: the horizontal graph equation is merely nonzero.
-/
end
end MazurProof.N13IntegralGraphJacobian
end

end

-- ===== FLT.Assumptions.MazurProof.N13RankTwoSemiGraphRecovery =====
section
-- ===== FLT.Assumptions.MazurProof.N13RankTwoSemiGraphRecovery =====
section
/-!
# Recovering an integral semigraph from a rank-two quotient basis

The graph-recovery algebra does not need a selected special divisor until
one asks for a particular vertical smoothness certificate.  A literal
integral quotient basis `{1,x}` already recovers a monic quadratic
generalized Mumford semigraph and identifies its graph ideal with the
canonical contraction.

This is the special-class-independent core needed for arbitrary proper
specialization.
-/
open Module
open Polynomial
namespace MazurProof.N13RankTwoSemiGraphRecovery
noncomputable section
abbrev R₂ : Type :=
  N13ConcreteGraphRecovery.R₂
abbrev IntegralRing : Type :=
  N13ConcreteGraphRecovery.IntegralRing
abbrev SemiMumford₂ : Type :=
  N13GeneralizedMumfordIntegral.TwoAdic.SemiMumford₂
end
end MazurProof.N13RankTwoSemiGraphRecovery
end

end

-- ===== FLT.Assumptions.MazurProof.N13RankTwoVerticalIdealRecovery =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13RankTwoVerticalIdealRecovery =====
section
open Polynomial
/-!
# Recovering a vertical graph from a rank-two quotient

If a quotient has basis `{1,y}`, multiplication by `y` supplies its monic
quadratic relation, while `x` is linear in `y`.  This file gives the
ideal-correspondence argument recovering the ambient ideal as
`(m(y), x-s(y))`.
-/
namespace MazurProof.N13RankTwoVerticalIdealRecovery
noncomputable section
universe uR uA
variable {R : Type uR} {A : Type uA}
variable [CommRing R] [CommRing A] [Algebra R A]
def HasVerticalPolynomialNormalForm
    (y x : A) (s : R[X]) : Prop :=
  ∀ z : A, ∃ p : R[X], ∃ q : A,
    z = aeval y p + q * (x - aeval y s)
end
end MazurProof.N13RankTwoVerticalIdealRecovery
end

end

-- ===== FLT.Assumptions.MazurProof.N13RankTwoVerticalGraphRecovery =====
section
-- ===== FLT.Assumptions.MazurProof.N13RankTwoVerticalGraphRecovery =====
section
open Module
open Polynomial
/-!
# Vertical graph recovery from a `{1,y}` basis

A rank-two quotient basis `{1,y}` recovers a monic quadratic relation
`m(y)` and a linear equation `x=a+cy`.  Substituting the latter into the
integral curve equation shows that the vertical curve polynomial factors
as `m*w`.
-/
namespace MazurProof.N13RankTwoVerticalGraphRecovery
noncomputable section
abbrev R₂ : Type := N13ConcreteGraphRecovery.R₂
abbrev IntegralRing : Type :=
  N13ConcreteGraphRecovery.IntegralRing
def verticalCurve (s : R₂[X]) : R₂[X] :=
  X ^ 2 +
    (N13GeneralizedMumfordIntegral.hPoly (R := R₂)).comp s * X -
    (N13GeneralizedMumfordIntegral.rhsPoly (R := R₂)).comp s
namespace VerticalGraph
end VerticalGraph
end
end MazurProof.N13RankTwoVerticalGraphRecovery
end

end

-- ===== FLT.Assumptions.MazurProof.N13VerticalGraphJacobian =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13VerticalGraphJacobian =====
section
open Polynomial
open scoped nonZeroDivisors
/-!
# The vertical graph Jacobian frame for the N13 integral model

A rank-two contraction with basis `{1, y}` is a vertical graph `x = s(y)`.
Dividing the curve equation by `x - s(y)` supplies the complementary factor.
Together with the differentiated vertical relation, these two factors express both
Jacobian rows in the graph frame. The global Jacobian Bezout identity then makes
the recovered graph ideal invertible.
-/
namespace MazurProof.N13VerticalGraphJacobian
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type := N13IntegralGraphJacobian.R₂
abbrev IntegralRing : Type :=
  N13IntegralGraphJacobian.IntegralRing
open N13GeneralizedMumfordIntegral
open N13RankTwoVerticalGraphRecovery
def curveInX : IntegralRing[X] :=
  C (N13ConcreteGraphRecovery.integralY ^ 2) +
    (hPoly (R := R₂)).map (algebraMap R₂ IntegralRing) *
      C N13ConcreteGraphRecovery.integralY -
    (rhsPoly (R := R₂)).map (algebraMap R₂ IntegralRing)
def fyPoly : IntegralRing[X] :=
  C (2 * N13ConcreteGraphRecovery.integralY) +
    (hPoly (R := R₂)).map (algebraMap R₂ IntegralRing)
end
end MazurProof.N13VerticalGraphJacobian
end

end

-- ===== FLT.Assumptions.MazurProof.N13FiniteContractIdealInvertible =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FiniteContractIdealInvertible =====
section
open Module
open Polynomial
open scoped nonZeroDivisors
/-!
# Invertibility of finite quadratic N13 contractions

A finite quadratic contraction admits a literal integral basis `{1,x}` or
`{1,y}`.  The first basis recovers a horizontal integral semigraph; the
second recovers a vertical graph.  The two structural Jacobian frames prove
invertibility in the respective cases.
-/
namespace MazurProof.N13FiniteContractIdealInvertible
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev R₂ : Type := N13IntegralModelContraction.R₂
abbrev IntegralRing : Type := N13IntegralModelContraction.IntegralRing
end
end MazurProof.N13FiniteContractIdealInvertible
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianGlobalArithmetic =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianGlobalArithmetic =====
section
/-!
# The Gaussian cubic at the ramified prime over 13

This file freezes the global Gaussian arithmetic attached to the actual N13
sextic

`X⁶ + 4X⁵ + 6X⁴ + 2X³ + X² + 2X + 1`.

Over `ℤ[i]` it is the product of a cubic and its conjugate.  The cubic has
discriminant `(3-2i)²`; after translating its root by `9`, it is Eisenstein at
the prime element `3-2i`.  Primality is proved from the Gaussian norm `13`,
and the Eisenstein constant-term test is the single norm nondivisibility
`13 ∤ 62197`.  No class-group computation or factor table is used.
-/
open Polynomial
namespace MazurProof.N13GaussianGlobalArithmetic
noncomputable section
abbrev GI := GaussianInt
/-- The standard Gaussian generator. -/
def i : GI := Zsqrtd.sqrtd
/-- The Gaussian prime above `13` at which the cubic is ramified. -/
def pi : GI := 3 - 2 * i
/-- The cubic Gaussian factor of the actual N13 sextic. -/
def g : GI[X] :=
  X ^ 3 + C (2 - 2 * i) * X ^ 2 +
    C (-1 - 2 * i) * X - 1
/-- Coefficient guard for the only N13 sextic used in this development. -/
def n13F : GI[X] :=
  X ^ 6 + 4 * X ^ 5 + 6 * X ^ 4 + 2 * X ^ 3 +
    X ^ 2 + 2 * X + 1
/-- The translate for which the ramified cubic is Eisenstein. -/
def h : GI[X] :=
  g.comp (X + C 9)
@[simp] theorem pi_norm : Zsqrtd.norm pi = 13 := by
  norm_num [pi, i, Zsqrtd.norm]
theorem pi_ne_zero : pi ≠ 0 := by
  intro hp
  have hnorm := congrArg Zsqrtd.norm hp
  rw [pi_norm] at hnorm
  norm_num at hnorm
theorem g_natDegree : g.natDegree = 3 := by
  unfold g
  compute_degree!
@[simp] theorem g_coeff_three : g.coeff 3 = 1 := by
  simp only [g, coeff_add, coeff_sub, coeff_X_pow,
    coeff_C_mul_X_pow, coeff_one]
  norm_num [Polynomial.coeff_one]
theorem g_monic : g.Monic := by
  rw [Polynomial.Monic.def, Polynomial.leadingCoeff,
    g_natDegree, g_coeff_three]
theorem h_monic : h.Monic :=
  g_monic.comp_X_add_C 9
theorem h_natDegree : h.natDegree = 3 := by
  simp [h, Polynomial.natDegree_comp, g_natDegree]
theorem h_degree : h.degree = 3 :=
  (degree_eq_iff_natDegree_eq h_monic.ne_zero).mpr h_natDegree
@[simp] theorem h_coeff_three :
    h.coeff 3 = 1 := by
  simpa [h_natDegree] using h_monic.coeff_natDegree
theorem pi_not_dvd_constantQuotient :
    ¬ pi ∣ (231 + 94 * i) := by
  rintro ⟨d, hd⟩
  have hnorm := congrArg Zsqrtd.norm hd
  rw [Zsqrtd.norm_mul, pi_norm] at hnorm
  have hc : Zsqrtd.norm (231 + 94 * i : GI) = 62197 := by
    norm_num [i, Zsqrtd.norm]
  rw [hc] at hnorm
  omega
end
end MazurProof.N13GaussianGlobalArithmetic
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianCubicField =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianCubicField =====
section
/-!
# The global N13 Gaussian cubic field

We form the fraction field `K = Frac(ℤ[i])` and adjoin a root of the
translated Gaussian cubic.  Its Eisenstein property proves irreducibility,
while the discriminant--Eisenstein criterion identifies the monogenic
Gaussian order with the full relative integral closure.

This file contains no class-group computation and no integral-basis search.
-/
open Algebra Module Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13GaussianCubicField
noncomputable section
open N13GaussianGlobalArithmetic
/-- The Gaussian rational field, kept as the literal fraction field of
`GaussianInt` so the integral-closure API applies definitionally. -/
abbrev K := FractionRing GI
/-- The translated cubic over the Gaussian rational field. -/
def hK : K[X] :=
  h.map (algebraMap GI K)
theorem hK_monic : hK.Monic :=
  h_monic.map (algebraMap GI K)
/-- The relative cubic field. -/
abbrev L := AdjoinRoot hK
/-- The shifted cubic generator. -/
def alpha : L :=
  AdjoinRoot.root hK
/-! ## The relative integral basis -/
/-! ## Discriminant of the relative integral basis -/
end
end MazurProof.N13GaussianCubicField
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianFractionField =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianFractionField =====
section
/-!
# The Gaussian fraction field as a quadratic number field

The fraction field of `ℤ[i]` has the structural rational basis `(1,i)`.
The only localization point to check is that inverting nonzero ordinary
integers already inverts every nonzero Gaussian integer: `z` divides its
nonzero integer norm `z * star z`.

No embeddings or Gaussian elements are enumerated.
-/
open Module
open Polynomial
open scoped nonZeroDivisors
open scoped Matrix
namespace MazurProof.N13GaussianFractionField
noncomputable section
open N13GaussianGlobalArithmetic
/-- The Gaussian rational field. -/
abbrev K := FractionRing GI
@[simp] theorem i_mul_self :
    i * i = -1 := by
  simp [i, Zsqrtd.dmuld]
/-- The Gaussian generator is integral over the integers. -/
theorem i_integral : IsIntegral ℤ i := by
  refine ⟨X ^ 2 + C (1 : ℤ), ?_, ?_⟩
  · exact Polynomial.monic_X_pow_add_C (1 : ℤ)
      (by norm_num)
  · simp [i, pow_two, Zsqrtd.dmuld]
/-! ## The integral basis `(1,i)` -/
/-- Gaussian real and imaginary coordinates as an additive equivalence. -/
def gaussianIntAddEquiv : GI ≃+ (Fin 2 → ℤ) where
  toFun := fun z j => Fin.cases z.re (fun _ => z.im) j
  invFun := fun v => ⟨v 0, v 1⟩
  left_inv := by
    intro z
    ext <;> rfl
  right_inv := by
    intro v
    funext j
    fin_cases j <;> rfl
  map_add' := by
    intro x y
    funext j
    fin_cases j <;> rfl
/-- The coordinate equivalence as an integer-linear equivalence. -/
def gaussianIntLinearEquiv : GI ≃ₗ[ℤ] (Fin 2 → ℤ) :=
  gaussianIntAddEquiv.toIntLinearEquiv
/-- The structural integral basis `(1,i)` of the Gaussian integers. -/
def gaussianIntBasis : Basis (Fin 2) ℤ GI :=
  Basis.ofEquivFun gaussianIntLinearEquiv
instance gaussianIntFree : Module.Free ℤ GI :=
  Module.Free.of_basis gaussianIntBasis
instance gaussianIntFinite : Module.Finite ℤ GI :=
  Module.Finite.of_basis gaussianIntBasis
@[simp] theorem gaussianIntBasis_repr_apply
    (z : GI) (j : Fin 2) :
    gaussianIntBasis.repr z j =
      Fin.cases z.re (fun _ => z.im) j := by
  rfl
@[simp] theorem gaussianIntBasis_zero :
    gaussianIntBasis (0 : Fin 2) = 1 := by
  apply gaussianIntBasis.ext_elem
  intro j
  rw [gaussianIntBasis.repr_self_apply]
  fin_cases j <;> rfl
@[simp] theorem gaussianIntBasis_one :
    gaussianIntBasis (1 : Fin 2) = i := by
  apply gaussianIntBasis.ext_elem
  intro j
  rw [gaussianIntBasis.repr_self_apply]
  fin_cases j <;> rfl
/-! ## Cofinality of ordinary integer denominators -/
/-- Images of nonzero ordinary integers in `ℤ[i]`. -/
abbrev intDenoms : Submonoid GI :=
  Algebra.algebraMapSubmonoid GI (nonZeroDivisors ℤ)
theorem intDenoms_le_nonZeroDivisors :
    intDenoms ≤ nonZeroDivisors GI := by
  rintro _ ⟨n, hn, rfl⟩
  rw [mem_nonZeroDivisors_iff_ne_zero]
  exact
    (RingHom.injective_int (algebraMap ℤ GI)).ne
      (nonZeroDivisors.ne_zero hn)
/-! ## The localized rational basis -/
instance intRatAlgebraScalarTower :
    @IsScalarTower ℤ ℚ K
      (@Algebra.toSMul ℤ ℚ _ _ inferInstance)
      (@Algebra.toSMul ℚ K _ _ inferInstance)
      (@Algebra.toSMul ℤ K _ _ inferInstance) :=
  IsScalarTower.of_algebraMap_eq fun z => by
    have hmaps :
        algebraMap ℤ K =
          (algebraMap ℚ K).comp (algebraMap ℤ ℚ) :=
      RingHom.ext_int _ _
    exact DFunLike.congr_fun hmaps z
/-- The Gaussian generator in its fraction field. -/
def iK : K :=
  algebraMap GI K i
@[simp] theorem iK_mul_self :
    iK * iK = -1 := by
  change algebraMap GI K i * algebraMap GI K i = -1
  rw [← map_mul, i_mul_self, map_neg, map_one]
/-! ## Power basis, minimal polynomial, and discriminant -/
/-- The quadratic polynomial of the Gaussian generator. -/
def gaussianMinpoly : ℚ[X] :=
  X ^ 2 + 1
theorem gaussianMinpoly_monic :
    gaussianMinpoly.Monic := by
  simpa [gaussianMinpoly] using
    (Polynomial.monic_X_pow_add_C (1 : ℚ)
      (show (2 : ℕ) ≠ 0 by decide))
@[simp] theorem aeval_gaussianMinpoly :
    Polynomial.aeval iK gaussianMinpoly = 0 := by
  simp [gaussianMinpoly, pow_two, iK_mul_self]
theorem gaussianMinpoly_degree :
    gaussianMinpoly.degree = ((2 : ℕ) : WithBot ℕ) := by
  change Polynomial.degree ((X : ℚ[X]) ^ 2 + C 1) =
    ((2 : ℕ) : WithBot ℕ)
  rw [Polynomial.degree_add_C (by simp)]
  simp
@[simp] theorem gaussianMinpoly_nextCoeff :
    gaussianMinpoly.nextCoeff = 0 := by
  have hnat : gaussianMinpoly.natDegree = 2 := by
    unfold gaussianMinpoly
    compute_degree!
  rw [Polynomial.nextCoeff_of_natDegree_pos (by omega), hnat]
  simp [gaussianMinpoly, Polynomial.coeff_one]
end
end MazurProof.N13GaussianFractionField
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianFactorization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianFactorization =====
section
/-!
# Gaussian factorization of the N13 sextic

The N13 sextic is the norm of a cubic over the Gaussian rationals.  This is
the structural input for a Gaussian two-descent.
-/
open Polynomial
namespace MazurProof.N13GaussianFactorization
noncomputable section
/-- The Gaussian rational algebra `ℚ[i]`, with `i² = -1`. -/
abbrev GaussianQ := QuadraticAlgebra ℚ (-1) 0
/-- The real cubic in the Gaussian factor. -/
def A : ℚ[X] := X ^ 3 + 2 * X ^ 2 - X - 1
/-- The imaginary quadratic part in the Gaussian factor. -/
def B : ℚ[X] := 2 * X * (X + 1)
end
end MazurProof.N13GaussianFactorization
end

end

-- ===== FLT.Assumptions.MazurProof.N13SexticSquareclass =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SexticSquareclass =====
section
/-!
# The rational-scalar survivor in the N13 fake square-class target

The apparent second local survivor in the weak two-descent is not a second
geometric class.  In the sextic algebra it differs from `13` by an explicit
square.  The proof first compresses the five power-basis expressions to two
degree-five polynomials `B` and `C`; it never expands the final product to
degree thirty-three.
-/
open Polynomial
namespace MazurProof.N13SexticSquareclass
noncomputable section
def f : ℚ[X] :=
  N13Mumford.f ℚ
def rB : ℚ[X] :=
  2 * X ^ 7 + 9 * X ^ 6 + 16 * X ^ 5 + 6 * X ^ 4 - 5 * X ^ 3 - X ^ 2 + 5 * X - 24
def rC : ℚ[X] :=
  -6 * X ^ 7 - 27 * X ^ 6 - 42 * X ^ 5 + 15 * X ^ 4 + 72 * X ^ 3 + 22 * X ^ 2 - 71 * X + 47
def r13 : ℚ[X] :=
  45 * X ^ 9 + 282 * X ^ 8 + 719 * X ^ 7 + 720 * X ^ 6 + 67 * X ^ 5 + 4 * X ^ 4 +
    828 * X ^ 3 + 148 * X ^ 2 - 236 * X + 196
abbrev SexticAlgebra : Type :=
  AdjoinRoot f
def ofPoly (p : ℚ[X]) : SexticAlgebra :=
  AdjoinRoot.mk f p
def halfOfPoly (p : ℚ[X]) : SexticAlgebra :=
  ofPoly (Polynomial.C (1 / 2 : ℚ) * p)
end
end MazurProof.N13SexticSquareclass
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianCubic =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianCubic =====
section
/-!
# The Gaussian cubic presentation of the N13 sextic algebra

The sextic algebra becomes cubic after adjoining its intrinsic order-four
unit `i`.  More importantly for the local descent, all long power-basis
generators have short expressions in `i` and the sextic root `θ`.

Every identity below has a constant or linear quotient by the defining
sextic.  Thus this file records the structural change of presentation rather
than a high-degree certificate.
-/
open Polynomial
namespace MazurProof.N13GaussianCubic
noncomputable section
open N13SexticSquareclass
abbrev L : Type := SexticAlgebra
/-- The sextic root. -/
def theta : L :=
  AdjoinRoot.root f
/-- The real and imaginary parts of the Gaussian cubic factor. -/
def cubicA : ℚ[X] :=
  X ^ 3 + 2 * X ^ 2 - X - 1
def cubicB : ℚ[X] :=
  2 * X * (X + 1)
@[simp] theorem ofPoly_X :
    ofPoly X = theta := rfl
end
end MazurProof.N13GaussianCubic
end

end

-- ===== FLT.Assumptions.MazurProof.N13SexticIrreducible =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SexticIrreducible =====
section
/-!
# Irreducibility of the N13 sextic

The sextic defining the fake two-descent algebra is irreducible over `ℚ`.
We prove this structurally by reduction modulo three.  An irreducible
degree-`d` factor over `𝔽₃` divides `X ^ (3 ^ d) - X`, by applying finite-field
Frobenius in its adjoin-root field.  Three short Bézout identities exclude
degrees one through three, which is the full Rabin test for a sextic.  No
finite-field polynomials are enumerated.
-/
open Polynomial
namespace MazurProof.N13SexticIrreducible
noncomputable section
def fInt : ℤ[X] :=
  X ^ 6 + 4 * X ^ 5 + 6 * X ^ 4 + 2 * X ^ 3 + X ^ 2 + 2 * X + 1
def fModThree : (ZMod 3)[X] :=
  fInt.map (Int.castRingHom (ZMod 3))
def bezoutOneA : (ZMod 3)[X] :=
  -X ^ 2 - X + 1
def bezoutOneB : (ZMod 3)[X] :=
  X ^ 5 - X ^ 4 + X ^ 3 + X + 1
def bezoutTwoA : (ZMod 3)[X] :=
  X ^ 8 - X ^ 6 + X ^ 5 - X ^ 3 - X ^ 2 - X + 1
def bezoutTwoB : (ZMod 3)[X] :=
  -X ^ 5 - X ^ 4 + X ^ 3 + X ^ 2 + X + 1
def bezoutThreeA : (ZMod 3)[X] :=
  -X ^ 25 + X ^ 22 + X ^ 21 + X ^ 20 + X ^ 19 - X ^ 18 - X ^ 17 +
    X ^ 16 - X ^ 12 - X ^ 10 + X ^ 8 - X ^ 6 + X ^ 5 - X ^ 4 + X ^ 3 + 1
def bezoutThreeB : (ZMod 3)[X] :=
  X ^ 4 + X ^ 3 + X - 1
theorem fInt_map_rat :
    fInt.map (algebraMap ℤ ℚ) = N13Mumford.f ℚ := by
  simp [fInt, N13Mumford.f]
end
end MazurProof.N13SexticIrreducible
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianFieldEquiv =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianFieldEquiv =====
section
/-!
# Equivalence of the sextic and Gaussian-cubic N13 fields

The root `α` of the translated Gaussian cubic gives

`θ = α + 9`.

This file proves that sending the sextic generator to this element is an
isomorphism from the original degree-six algebra to the Gaussian cubic
number field.  Equal absolute dimensions make the injective field map
surjective; no inverse polynomial is searched for.

The intrinsic order-four element of the sextic field maps to the Gaussian
unit `i`.  Consequently the short formulas for the descent generators show
directly that all of them are algebraic integers in the structural absolute
ring of integers.
-/
open Algebra Module Polynomial
namespace MazurProof.N13GaussianFieldEquiv
noncomputable section
open N13GaussianGlobalArithmetic
abbrev K := N13GaussianCubicField.K
abbrev Lg := N13GaussianCubicField.L
abbrev Ls := N13SexticSquareclass.SexticAlgebra
/-! ## Integrality of the structural generators -/
end
end MazurProof.N13GaussianFieldEquiv
end

end

-- ===== FLT.Assumptions.MazurProof.N13MumfordKummerValue =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MumfordKummerValue =====
section
/-!
# The N13 Mumford fake-Kummer value

Let `θ` be the sextic root.  The branch specialization

`ℚ[X,Y]/(Y²-f(X)) → ℚ(θ),  X ↦ θ,  Y ↦ 0`

turns the quadratic norm of an affine function into a square.  For a
balanced Mumford representative `(u,v,n∞)`, its raw fake-Kummer value is
the unit `u(θ)`, modulo squares and rational scalars.

Irreducibility of the sextic is used only to install the field structure
locally and hence turn the nonzero element `u(θ)` into a unit.  This file
does not yet assert that the value is independent of the chosen Mumford
representative; that is the next principal-ideal relation theorem.
-/
open Polynomial
namespace MazurProof.N13MumfordKummerValue
noncomputable section
open SexticMumford
abbrev f : ℚ[X] :=
  N13SexticSquareclass.f
abbrev L : Type :=
  N13SexticSquareclass.SexticAlgebra
end
end MazurProof.N13MumfordKummerValue
end

end

-- ===== FLT.Assumptions.MazurProof.N13FullNormPair =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FullNormPair =====
section
/-!
# The full norm-pair target for N13

This file specializes the abstract even-sextic target to the sextic field
`L = ℚ[θ]`.  Its full target remembers `(α,s)` with `N(α)=s²`, before
forgetting `s` to obtain the existing fake square-class target.

The kernel of forgetting has at most the identity and the sign class
represented by `(1,-1)`.  This is target algebra only: it does not assert
the hard principal-genus theorem for the Picard Kummer map.
-/
namespace MazurProof.N13FullNormPair
noncomputable section
open N13SexticSquareclass
abbrev L : Type :=
  SexticAlgebra
theorem minusOne_sq :
    (-1 : ℚˣ) ^ 2 = 1 := by
  simp
/-- The only rational units with square one are `1` and `-1`. -/
theorem ratUnit_sq_eq_one
    (ε : ℚˣ) (hε : ε ^ 2 = 1) :
    ε = 1 ∨ ε = -1 := by
  have hval : ((ε : ℚ) ^ 2) = 1 := by
    exact congrArg (fun u : ℚˣ => (u : ℚ)) hε
  have hfactor :
      ((ε : ℚ) - 1) * ((ε : ℚ) + 1) = 0 := by
    calc
      ((ε : ℚ) - 1) * ((ε : ℚ) + 1) =
          (ε : ℚ) ^ 2 - 1 := by ring
      _ = 0 := by rw [hval]; norm_num
  rcases mul_eq_zero.mp hfactor with hminus | hplus
  · left
    apply Units.ext
    change (ε : ℚ) = 1
    exact sub_eq_zero.mp hminus
  · right
    apply Units.ext
    change (ε : ℚ) = -1
    exact eq_neg_of_add_eq_zero_left hplus
end
end MazurProof.N13FullNormPair
end

end

-- ===== FLT.Assumptions.MazurProof.N13MumfordKummerNorm =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MumfordKummerNorm =====
section
/-!
# The square norm of an N13 Mumford Kummer value

For a Mumford pair `(u,v)`, the relation

`f - v² = u w`

implies structurally that

`Norm(u(θ)) = Res(f,u) = Res(u,v)²`.

This is the global norm condition used by the weak two-descent.  The proof
uses functorial identities of the resultant; it neither splits `u` nor
separates its possible degrees.
-/
open Polynomial
namespace MazurProof.N13MumfordKummerNorm
noncomputable section
abbrev L : Type :=
  N13SexticSquareclass.SexticAlgebra
end
end MazurProof.N13MumfordKummerNorm
end

end

-- ===== FLT.Assumptions.MazurProof.N13GlobalKummerNormalization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GlobalKummerNormalization =====
section
/-!
# Global primitive normalization of N13 Kummer values

A rational Mumford polynomial need not have integral coefficients.  We clear
all denominators simultaneously over `ℤ`, remove the polynomial content, and
evaluate the resulting primitive polynomial at the integral Gaussian-cubic
generator `α + 9`.

The resulting element lies in the actual absolute ring of integers and
differs from the original Kummer value by one nonzero rational scalar.
Primitivity and the degree bound are retained, and the norm of the integral
representative remains a rational square.  Thus denominator clearing is
separated cleanly from the subsequent ideal factorization.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13GlobalKummerNormalization
noncomputable section
open N13GaussianFieldEquiv
abbrev L := N13GaussianCubicField.L
local instance intNormalizationMonoid :
    NormalizationMonoid ℤ :=
  UniqueFactorizationMonoid.normalizationMonoid.toNormalizationMonoid
local instance intNormalizedGCDMonoid :
    NormalizedGCDMonoid ℤ :=
  UniqueFactorizationMonoid.toNormalizedGCDMonoid ℤ
/-- Clear all rational denominators. -/
def integralNormalization (p : ℚ[X]) : ℤ[X] :=
  IsLocalization.integerNormalization
    (nonZeroDivisors ℤ) p
end
end MazurProof.N13GlobalKummerNormalization
end

end

-- ===== FLT.Assumptions.MazurProof.N13MumfordKummerIdealSquare =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MumfordKummerIdealSquare =====
section
/-!
# The branch ideal of an N13 Mumford relation is a square

The identity behind the good-prime part of the two-descent is

`(u(θ), v(θ))² = (u(θ))`.

It follows without factoring `u`, splitting into its possible degrees, or
computing valuations.  If `f - v² = u w`, then any prime containing both
`u(θ)` and `w(θ)` also contains `v(θ)` and hence `f'(θ)`.  Thus, wherever
`f'(θ)` is a unit, `u(θ)` and `w(θ)` are coprime.  Bézout and
`u(θ)w(θ) = -v(θ)²` then give the displayed ideal identity.

For N13 we implement "away from the different" literally: start with the
integral monogenic order and invert `f'(θ)`.  No discriminant expansion or
prime-ideal table enters the proof.
-/
open Polynomial
namespace MazurProof.N13MumfordKummerIdealSquare
noncomputable section
variable {R : Type*} [CommRing R]
/-! The N13 monogenic order with its different inverted. -/
abbrev IntegralOrder : Type :=
  AdjoinRoot N13SexticIrreducible.fInt
def differentGenerator : IntegralOrder :=
  AdjoinRoot.mk N13SexticIrreducible.fInt
    N13SexticIrreducible.fInt.derivative
abbrev GoodOrder : Type :=
  Localization.Away differentGenerator
end
end MazurProof.N13MumfordKummerIdealSquare
end

end

-- ===== FLT.Assumptions.MazurProof.N13GlobalKummerIdealSquare =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GlobalKummerIdealSquare =====
section
/-!
# The good-locus square ideal of a normalized N13 Kummer value

Primitive normalization removes the arbitrary content of a rational
Mumford polynomial, but it does not make the other polynomial in the
Mumford pair integral.  We clear those remaining denominators
*homogeneously*: if

`f - v² = u w`

and `U = c u` is the primitive integral normalization, then a single
nonzero integer `d` can be chosen together with integral `V,W` so that

`d² f - V² = U W`.

After evaluating at the integral branch point and inverting the derivative
of `d² f`, the branch ideal `(U(θ),V(θ))` squares to `(U(θ))`.  This is the
principal ideal of the previously constructed `normalizedKummerInteger`.
Thus every denominator and bad-reduction prime is isolated in one
canonical localization; no prime factorization or valuation enumeration is
used.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13GlobalKummerIdealSquare
noncomputable section
open N13GaussianFieldEquiv
open N13GlobalKummerNormalization
abbrev L := N13GaussianCubicField.L
/-! ## The principal-ideal endpoint -/
end
end MazurProof.N13GlobalKummerIdealSquare
end

end

-- ===== FLT.Mathlib.RingTheory.Valuation.ValuationSubring =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Mathlib.RingTheory.Valuation.ValuationSubring =====
section
/-
Copyright (c) 2025 Ruben Van de Velde. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Ruben Van de Velde, Kevin Buzzard, Salvatore Mercuri
-/
/-!
# Valuation Subring

Material destined for Mathlib.
-/
section
variable {F : Type*} [Field F]
theorem ValuationSubring.isUnit_of_valued_eq_one {K : Type*} [Field K] {Γ₀ : Type*}
    [LinearOrderedCommGroupWithZero Γ₀] [hv : Valued K Γ₀] (x : hv.v.valuationSubring)
    (hx : Valued.v x.val = 1) : IsUnit x := by
  have : IsUnit x.val := by rw [isUnit_iff_ne_zero, ne_eq, ← map_eq_zero hv.v, hx]; aesop
  obtain ⟨u, hu⟩ := this
  have hu_inv_le : Valued.v u⁻¹.val ≤ 1 := by
    rw [← one_mul (Valued.v _), ← hx, ← hu, ← Valued.v.map_mul, u.mul_inv, hu, hx, Valued.v.map_one]
  rw [isUnit_iff_exists]
  exact ⟨⟨u⁻¹.val, hu_inv_le⟩,  ⟨by aesop, by aesop⟩⟩
end
end

end

-- ===== FLT.DedekindDomain.AdicValuation =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.DedekindDomain.AdicValuation =====
section
/-
Copyright (c) 2025 Matthew Jasper. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Matthew Jasper
-/
/-!

# Adic Completions

If `A` is a valued ring with field of fractions `K` there are two different
complete rings containing `A` one might define, the first is
`𝒪_v = {x ∈ K_v | v x ≤ 1}` (defined in Lean as `adicCompletionIntegers K v`)
and the second is the `v-adic` completion of `A`. In the case when `A` is a
Dedekind domain these definitions give isomorphic topological `A`-algebras.
This file makes some progress towards this.

## Main theorems/defs

* `IsDedekindDomain.HeightOneSpectrum.closureAlgebraMapIntegers_eq_integers` : The closure of
    `A` in `K_v` is `𝒪_v`.
* `IsDedekindDomain.HeightOneSpectrum.ResidueFieldEquivCompletionResidueField` : The canonical
  isomorphism `A ⧸ v ≅ 𝓞ᵥ / v`.
* `IsDedekindDomain.HeightOneSpectrum.closureAlgebraMapIntegers_eq_prodIntegers` : If `s` is
    a set of primes of `A`, then the closure of `A` in `∏_{v ∈ s} K_v` is `∏_{v ∈ s} 𝒪_v`.
* `IsDedekindDomain.HeightOneSpectrum.denseRange_of_prodAlgebraMap` : If `s` is a finite set
    of primes of `A`, then `K` is dense in `∏_{v ∈ s} K_v`.
* We show (as an unnamed instance) `IsDiscreteValuationRing (𝒪[v.adicCompletion K])`
-/
section
namespace IsDedekindDomain.HeightOneSpectrum
section Multiplicative
open scoped WithZero
end Multiplicative
variable {A : Type*} (K : Type*) [CommRing A] [Field K] [Algebra A K] [IsFractionRing A K] [IsDedekindDomain A] (v : HeightOneSpectrum A)
open scoped WithZero
-- could go in mathlib
instance instIsRankOneDiscreteWithZeroMultiplicativeIntAdicCompletionV_fLT : Valuation.IsRankOneDiscrete ((Valued.v : Valuation (v.adicCompletion K) ℤᵐ⁰)) where
  exists_generator_lt_one' := by
    have h : (v.valuation K).IsRankOneDiscrete := Valuation.IsRankOneDiscrete.mk' (valuation K v)
    exact ⟨h.generator, by rw [h.generator_zpowers_eq_valueGroup, adicCompletion_valueGroup_eq],
      h.generator_lt_one⟩
-- shortcut instances for next def: needed after mathlib #34045
noncomputable instance instCommSemiringSubtypeAdicCompletionMemValuationSubringAdicCompletionIntegers_fLT : CommSemiring ↥(adicCompletionIntegers K v) := inferInstance
noncomputable instance instFieldAdicCompletion_fLT : Field (adicCompletion K v) := inferInstance
-- dirty hack because of v4.29
namespace adicCompletion
-- IsDedekindDomain.HeightOneSpectrum.adicCompletion.exists_uniformizer
-- shortcut instance for next theorem: needed after mathlib #34045
noncomputable instance instRing_fLT : Ring (adicCompletion K v) := inferInstance
end adicCompletion
end IsDedekindDomain.HeightOneSpectrum
end
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianNumberField =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianNumberField =====
section
/-!
# The absolute N13 number field

The N13 Gaussian cubic is a degree-three extension of the quadratic
Gaussian field.  Combining the structural bases in the two stages gives
the six-element rational basis

`1, α, α², i, iα, iα²`.

This is a tower-basis construction; no embeddings or field elements are
enumerated.
-/
open Algebra Module
namespace MazurProof.N13GaussianNumberField
noncomputable section
open N13GaussianGlobalArithmetic
abbrev K := FractionRing GI
abbrev L := AdjoinRoot N13GaussianCubicField.hK
/- The subtype algebras otherwise prefer transitive `Subalgebra.algebra`
instances.  For a tower starting at `ℤ`, use the unique canonical integer
algebra structures so their modules are definitionally the usual `zsmul`
modules carried by the explicit bases. -/
local instance intAlgebraGI : Algebra ℤ GI :=
  Ring.toIntAlgebra GI
/-! ## The absolute ring of integers -/
/- Mathlib packages the ring of integers as a separate definition rather
than exposing the integral-closure subtype directly.  This carrier-preserving
equivalence is the explicit bridge between the two presentations. -/
/-! ## Absolute discriminant -/
end
end MazurProof.N13GaussianNumberField
end

end

-- ===== FLT.Assumptions.MazurProof.N13GlobalKummerSimpleRootParity =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GlobalKummerSimpleRootParity =====
section
/-!
# Simple-root parity for normalized N13 Kummer values

This file maps the primitive global Mumford polynomial and its homogeneous
curve relation into the integer ring of a height-one completion.  Away from
the different, the sextic secant is a unit.  Hence whenever the quadratic
Mumford polynomial has a simple root modulo the prime, its normalized
Kummer value has even multiplicity.

The denominator-clearing scale is not inverted in the integer ring.  It is
absorbed into the square root only after passing to the completion field,
so no denominator prime is excluded.
-/
open Polynomial
open IsDedekindDomain
open IsDedekindDomain.HeightOneSpectrum
open scoped nonZeroDivisors
namespace MazurProof.N13GlobalKummerSimpleRootParity
noncomputable section
open N13GlobalKummerNormalization
open N13GlobalKummerIdealSquare
abbrev L : Type :=
  N13GlobalKummerIdealSquare.L
end
end MazurProof.N13GlobalKummerSimpleRootParity
end

end

-- ===== FLT.Assumptions.MazurProof.N13GlobalKummerAwayDifferentParity =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GlobalKummerAwayDifferentParity =====
section
/-!
# Uniform N13 parity away from the different

The simple- and double-root principles together cover every primitive
quadratic at every height-one prime where the sextic is étale.  No
condition is imposed on the denominator-clearing scale.
-/
open Polynomial
open IsDedekindDomain
open IsDedekindDomain.HeightOneSpectrum
open scoped nonZeroDivisors
namespace MazurProof.N13GlobalKummerAwayDifferentParity
noncomputable section
open N13GlobalKummerNormalization
open N13GlobalKummerIdealSquare
open N13GlobalKummerSimpleRootParity
abbrev L : Type :=
  N13GlobalKummerSimpleRootParity.L
end
end MazurProof.N13GlobalKummerAwayDifferentParity
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianSignature =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianSignature =====
section
/-!
# The signature of the N13 number field

The Gaussian unit embeds into the N13 cubic and still squares to `-1`.
Consequently there is no real embedding, so the sextic field is totally
complex.  The signature and Dirichlet unit rank then follow from the
structural degree computation.
-/
open Algebra Module
namespace MazurProof.N13GaussianSignature
noncomputable section
abbrev K := N13GaussianFractionField.K
abbrev L := N13GaussianNumberField.L
/-- The Gaussian square root of `-1`, embedded in the N13 field. -/
def iL : L :=
  algebraMap K L N13GaussianFractionField.iK
end
end MazurProof.N13GaussianSignature
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianClassNumberOne =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianClassNumberOne =====
section
/-!
# Class number one for the N13 number field

The field is a totally complex sextic of discriminant `-10816`, so its
Minkowski bound is strictly below four.  Prime ideals of norms two and
three are excluded by reducing the integral sextic satisfied by
`θ = α + 9`; the finite-field arguments use Frobenius, not enumeration.
-/
open Algebra Module Polynomial Nat
open scoped nonZeroDivisors Real
namespace MazurProof.N13GaussianClassNumberOne
noncomputable section
open N13GaussianGlobalArithmetic
abbrev K := N13GaussianCubicField.K
abbrev L : Type :=
  N13GaussianNumberField.L
theorem pow_pos_eq_self_of_sq_eq_self
    {k : Type*} [Monoid k] {x : k}
    (hx : x ^ 2 = x) :
    ∀ n : ℕ, x ^ (n + 1) = x := by
  intro n
  induction n with
  | zero => simp
  | succ n ih =>
      rw [pow_succ, ih]
      simpa only [pow_two] using hx
/-! ## Minkowski's bound -/
/-! ## Excluding small prime ideals -/
end
end MazurProof.N13GaussianClassNumberOne
end

end

-- ===== FLT.Assumptions.MazurProof.N13GlobalKummerPID =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GlobalKummerPID =====
section
/-!
# Class-number-one endpoint for normalized N13 Kummer ideals

The structural class-number-one theorem supplies the sole global
principality input in the good-locus ideal-square theorem.  Consequently
every normalized N13 Kummer value becomes a unit times a square after
removing its denominator scale and the different.
-/
namespace MazurProof.N13GlobalKummerPID
noncomputable section
open N13GlobalKummerNormalization
open N13GlobalKummerIdealSquare
abbrev L := N13GaussianCubicField.L
end
end MazurProof.N13GlobalKummerPID
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianDifferentSupport =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianDifferentSupport =====
section
/-!
# Structural support of the N13 derivative

The two exceptional Gaussian factors are kept as literal algebraic
integers in the absolute maximal order:

* `A = 1 - i θ² - (1 + i) θ`,
* `Q = 2 - 3i`.

The Gaussian cubic relation gives the two short identities

`f'(θ) = 4 · i θ² (θ + 1) · A²`

and

`13 = (i - θ) · A³ · Q`.

All factors omitted from these displayed powers are exhibited as units.
Thus the different support and the ramification indices are read from
factorizations in the maximal order, rather than from a factor table or a
finite residue-field enumeration.
-/
open Algebra Module Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13GaussianDifferentSupport
noncomputable section
open N13GaussianFieldEquiv
open N13GlobalKummerNormalization
open N13GlobalKummerIdealSquare
abbrev L := N13GaussianCubicField.L
abbrev O := integralClosure ℤ L
/-! ## Norms and the ramified prime -/
abbrev GI := N13GaussianGlobalArithmetic.GI
abbrev K := N13GaussianCubicField.K
/-! ## The residue-degree-three prime

Primality of `Q` is not inferred from its composite norm.  Instead we
descend to the Gaussian prime `(2-3i)`.  The relative cubic is irreducible
there: in the thirteen-element residue field, Frobenius and a quadratic
Bézout identity exclude roots. -/
abbrev RelativeO :=
  integralClosure GI L
/-! ## The unique prime above two -/
def gaussianTwoInteger : GI :=
  1 - N13GaussianGlobalArithmetic.i
def gaussianTwoIdeal : Ideal GI :=
  Ideal.span ({gaussianTwoInteger} : Set GI)
abbrev GaussianTwoResidue :=
  GI ⧸ gaussianTwoIdeal
def gaussianTwoResidueCubic :
    GaussianTwoResidue[X] :=
  X ^ 3 + X ^ 2 + 1
def relativeGaussianTwoIdeal : Ideal RelativeO :=
  gaussianTwoIdeal.map (algebraMap GI RelativeO)
theorem relativeGaussianTwoIdeal_eq_span :
    relativeGaussianTwoIdeal =
      Ideal.span
        ({algebraMap GI RelativeO gaussianTwoInteger} :
          Set RelativeO) := by
  rw [relativeGaussianTwoIdeal, gaussianTwoIdeal,
    Ideal.map_span, Set.image_singleton]
/-! ## Height-one carriers and support of the different -/
open IsDedekindDomain
/-! ## Square norm and the two remaining parity bits -/
end
end MazurProof.N13GaussianDifferentSupport
end

end

-- ===== FLT.Assumptions.MazurProof.N13LocalDlogTwo =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13LocalDlogTwo =====
section
/-!
# The first ramified local character for N13 at two

Let `π = 1 - i`.  The first ramified quotient of the unramified cubic
extension of `ℚ₂(i)` is the dual-number ring

`𝔽₈[ε] / (ε²)`, where `𝔽₈ = 𝔽₂[α] / (α³ + α + 1)`.

This file formalizes the finite algebra in that quotient.  The logarithm
`a + εb ↦ b / a`, including its descent through squares and scalar units,
is supplied by `RamifiedDlog`.  Here we calculate the four N13 generator
jets and prove structurally that vanishing of the resulting `𝔽₈` character
leaves exactly the two candidates `(0, 0, s, s)`.
-/
open Polynomial
open scoped CharTwo
namespace MazurProof.N13LocalDlogTwo
noncomputable section
/-! ## The residue field -/
/-- The residue polynomial of the N13 cubic at the prime above two. -/
def residueCubic : (ZMod 2)[X] :=
  X ^ 3 + X + 1
theorem residueCubic_monic : residueCubic.Monic := by
  unfold residueCubic
  monicity!
/-- The degree-three residue field at two. -/
abbrev F8 : Type :=
  AdjoinRoot residueCubic
/-- The residue of the cubic generator. -/
def alpha : F8 :=
  AdjoinRoot.root residueCubic
/-! ## The four generator jets -/
/-! ## Structural collapse of the candidate space -/
end
end MazurProof.N13LocalDlogTwo
end

end

-- ===== FLT.Assumptions.MazurProof.N13LocalDlogRegimes =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13LocalDlogRegimes =====
section
/-!
# The two local first-jet regimes for N13 at two

This file connects the finite first-jet calculation in
`N13LocalDlogTwo` to the two valuation regimes for a `2`-adic affine
coordinate.

For an integral coordinate, reduction gives

`x - θ ↦ x̄ - α`,

a constant unit of the dual-number ring.  For a nonintegral coordinate,
putting `t = x⁻¹` and removing the rational scalar `x` gives

`1 - t θ ↦ 1`,

because positive `2`-adic valuation forces `t̄ = 0`.  Both jets therefore
have zero first ramified logarithm.  No local square-class enumeration is
used.

Proof boundary: this file proves the two coordinate-jet calculations and
their `ℚ₂` residue adapters.  It does not yet construct the map from the
actual completed sextic order modulo its prime square, nor identify a
Mumford/Jacobian Kummer value with one of these coordinate jets.  That
fixed local-order compatibility is isolated in
`scratch/N13_Q2_ADAPTER.md`.
-/
open scoped CharTwo
namespace MazurProof.N13LocalDlogRegimes
open N13LocalDlogTwo
open TrivSqZeroExt
noncomputable section
/-! ## Exact dual-number semantics -/
/-! ## `ℚ₂` and `ℤ₂` adapters -/
abbrev Q2 : Type := ℚ_[2]
abbrev Z2 : Type := ℤ_[2]
theorem nonintegral_coordinate_ne_zero
    (x : Q2) (hx : x.valuation < 0) :
    x ≠ 0 := by
  intro hx0
  rw [hx0, Padic.valuation_zero] at hx
  omega
end
end MazurProof.N13LocalDlogRegimes
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianOrderTwo =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianOrderTwo =====
section
/-!
# The fixed Gaussian order at two for N13

This file constructs the first ramified quotient directly from the
Gaussian cubic presentation.  We first adjoin a root `i` of `T² + 1`
over `ℤ₂`, and then a root `θ` of

`T³ + 2T² - T - 1 - i(2T(T+1))`.

Sending `i` to `1 + ε` and `θ` to the cubic residue `α` defines a
surjective ring homomorphism to `𝔽₈[ε]/(ε²)`.  Its kernel is proved to
be exactly `(1-i)² = (2)` by the two nested monic power bases.  Hence the
ramified-prime-square quotient is identified with the dual-number ring.
This is the direct quotient-ring core needed by the local N13 descent;
no ray-class enumeration is involved.

The remaining arithmetic identification with the completed maximal
order is recorded separately in `scratch/N13_GAUSSIAN_ORDER_TWO.md`.
-/
open Polynomial
open scoped CharTwo
namespace MazurProof.N13GaussianOrderTwo
noncomputable section
open N13LocalDlogTwo
open N13LocalDlogRegimes
open TrivSqZeroExt
open Module
abbrev Z2 : Type := ℤ_[2]
/-! ## The integral Gaussian cubic order -/
/-! ## The two nested power bases -/
/-! ## Direct reduction to the dual-number ring -/
def residue (z : Z2) : ZMod 2 :=
  PadicInt.toZMod z
/-! ## Exactness of the first-jet quotient -/
/-! ## Compatibility with the N13 descent generators -/
/-! ## The ramified prime square -/
/-! ## Structural surjectivity -/
end
end MazurProof.N13GaussianOrderTwo
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianGlobalReductionTwo =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianGlobalReductionTwo =====
section
/-!
# Global N13 integers in the first ramified quotient at two

The relative maximal order is monogenic over the Gaussian integers.  Its
power-basis universal property therefore maps the full global maximal order
to the fixed integral Gaussian order used at two:

* the Gaussian generator maps to the local generator `i`;
* the translated cubic generator maps to `theta - 9`.

Composing with the exact quotient map gives a genuine ring homomorphism from
the full ring of integers to `F₈[ε]/(ε²)`.  Thus later logarithmic detectors
act on every global unit, rather than only on a displayed list of elements.
-/
open Polynomial
namespace MazurProof.N13GaussianGlobalReductionTwo
noncomputable section
open N13GaussianGlobalArithmetic
open N13GaussianCubicField
open N13GaussianNumberField
open N13GaussianOrderTwo
abbrev L := N13GaussianCubicField.L
local instance intAlgebraGI : Algebra ℤ GI :=
  Ring.toIntAlgebra GI
abbrev RelativeO := integralClosure GI L
abbrev F8 := N13LocalDlogTwo.F8
end
end MazurProof.N13GaussianGlobalReductionTwo
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianUnitSquareclasses =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianUnitSquareclasses =====
section
/-!
# Unit squareclasses in the N13 field

Dirichlet's theorem decomposes the unit group as finite cyclic torsion
times a free abelian group of rank two.  Squaring has index two on the
torsion factor and index `2^2` on the free factor, so the N13 unit
squareclass group has exactly eight elements.  No units are enumerated.
-/
open Finset Module
noncomputable section
namespace MazurProof.UnitSquareClass
end MazurProof.UnitSquareClass
namespace NumberField.Units
variable (K : Type*) [Field K] [NumberField K]
end NumberField.Units
namespace MazurProof.N13GaussianUnitSquareclasses
abbrev L : Type :=
  N13GaussianNumberField.L
end MazurProof.N13GaussianUnitSquareclasses
end
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianNamedUnitSquareclasses =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianNamedUnitSquareclasses =====
section
/-!
# Named unit squareclasses in the N13 field

The three displayed N13 units are literal units of the maximal order.  Their
first ramified logarithms are `1`, `α²`, and `α + α²`, hence they are
independent modulo squares.  Dirichlet's theorem gives exactly eight unit
squareclasses, so these three classes form a basis and every maximal-order
unit is their binary product times a square.

The proof uses the genuine global reduction homomorphism from
`N13GaussianGlobalReductionTwo`; no field-unit surrogate or enumeration of
the eight classes is used.
-/
open Function
open Polynomial
namespace MazurProof.N13GaussianNamedUnitSquareclasses
noncomputable section
open N13GaussianGlobalArithmetic
open N13GaussianCubicField
open N13GaussianGlobalReductionTwo
open N13GaussianOrderTwo
open N13LocalDlogTwo
abbrev L := N13GaussianGlobalReductionTwo.L
local instance intAlgebraGI : Algebra ℤ GI :=
  Ring.toIntAlgebra GI
abbrev RelativeO := integralClosure GI L
abbrev F8 := N13LocalDlogTwo.F8
/-! ## Literal units of the relative and absolute maximal orders -/
/-! ## The global first-jet logarithm -/
/-! ## Structural generation of all unit squareclasses -/
abbrev F2 := ZMod 2
end
end MazurProof.N13GaussianNamedUnitSquareclasses
end

end

-- ===== FLT.Assumptions.MazurProof.N13CandidateCollapse =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13CandidateCollapse =====
section
/-!
# Structural collapse of the N13 fake-descent candidates

The first ramified logarithm reduces the sixteen binary exponent vectors to
`(0,0,s,s)`.  The remaining nonzero vector represents
`e₂ * a * q`, which differs from the rational scalar `13` by a square.

This file joins those two facts without a sixteen-row table.  It does not
assert that every global fake-Selmer class belongs to the candidate
envelope, nor that every local image lies in the first-jet kernel; those are
the two remaining arithmetic semantic bridges.
-/
namespace MazurProof.N13CandidateCollapse
noncomputable section
open N13SexticSquareclass
abbrev L : Type := SexticAlgebra
def thirteenUnit : ℚˣ :=
  Units.mk0 13 (by norm_num)
theorem scalarThirteen_isUnit :
    IsUnit (algebraMap ℚ L 13) := by
  exact (Units.map (algebraMap ℚ L).toMonoidHom thirteenUnit).isUnit
end
end MazurProof.N13CandidateCollapse
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianNamedUnitTransport =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianNamedUnitTransport =====
section
/-!
# Transport of the named N13 units

The unit squareclass computation is carried out in the maximal order of the
Gaussian cubic presentation, while the fake-descent candidates use the sextic
presentation.  This file gives the literal carrier-preserving map between the
two and proves that the three named units agree under it.

Consequently the structural maximal-order unit decomposition transports to the
same three units appearing in `N13CandidateCollapse`, without enumerating the
eight unit squareclasses.
-/
namespace MazurProof.N13GaussianNamedUnitTransport
noncomputable section
abbrev Lg := N13GaussianCubicField.L
abbrev Ls := N13SexticSquareclass.SexticAlgebra
end
end MazurProof.N13GaussianNamedUnitTransport
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianCandidateUnitAssembly =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianCandidateUnitAssembly =====
section
/-!
# Assembly of the N13 Gaussian candidate units

This file closes the final group-theoretic seam after the arithmetic descent
has produced one common ramified carrier bit.  A maximal-order unit is
transported to the sextic field and decomposed in the three named unit
generators.  The remaining common carrier is exactly the fourth generator,
up to a square.

No finite enumeration is used: the argument is an identity in the unit group,
followed by passage to the squareclass quotient.
-/
namespace MazurProof.N13GaussianCandidateUnitAssembly
noncomputable section
open N13GaussianNamedUnitTransport
abbrev Ls :=
  N13GaussianNamedUnitTransport.Ls
end
end MazurProof.N13GaussianCandidateUnitAssembly
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianNormalizationOrderTransport =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianNormalizationOrderTransport =====
section
/-!
# Transport from the N13 normalization order

The global Kummer normalization and the structural class-number computation
use definitionally different presentations of the same integral closure.
This file crosses that seam once through the compiled ring equivalence, then
transports a unit-times-square identity to the sextic presentation.

When every principal count is even there is no exceptional prime carrier.
Consequently the fourth candidate coordinate is literally zero.
-/
namespace MazurProof.N13GaussianNormalizationOrderTransport
noncomputable section
abbrev Lg := N13GaussianCubicField.L
abbrev Ls := N13SexticSquareclass.SexticAlgebra
end
end MazurProof.N13GaussianNormalizationOrderTransport
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianNormalizedSquareclassSeam =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianNormalizedSquareclassSeam =====
section
/-!
# The normalized and actual N13 fake squareclasses

The integral Kummer representative differs from the actual Mumford value by
a nonzero rational scalar.  The fake squareclass quotient kills precisely
such scalars, so the two values have the same fake squareclass.

The only technical seam is that the Gaussian--sextic equivalence and the
current sextic field presentation were compiled under definitionally
different rational algebra instances.  Uniqueness of a ring homomorphism out
of `ℚ` identifies the two scalar maps without unfolding either presentation.
-/
namespace MazurProof.N13GaussianNormalizedSquareclassSeam
noncomputable section
open N13GaussianNormalizationOrderTransport
abbrev Ls := N13SexticSquareclass.SexticAlgebra
end
end MazurProof.N13GaussianNormalizedSquareclassSeam
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianLocalization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianLocalization =====
section
/-!
# The global N13 sextic algebra inside the local Gaussian order

The fixed Gaussian cubic order is an integral presentation over `ℤ₂`.
After inverting `2`, its two generators satisfy the global sextic
presentation over `ℚ`.  This gives a structural specialization map from the
global sextic algebra to the localized order.

The construction deliberately stops before reduction modulo `2`: reduction
does not extend across an inverted `2`.  Instead, later lemmas identify the
global descent generators with integral elements of the order, which may then
be reduced by `N13GaussianOrderTwo.reduction`.
-/
open Polynomial
namespace MazurProof.N13GaussianLocalization
noncomputable section
open N13GaussianOrderTwo
abbrev Z2 : Type := ℤ_[2]
abbrev Q2 : Type := ℚ_[2]
/-! ## Integral images of the global descent generators -/
end
end MazurProof.N13GaussianLocalization
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianLowDegree =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianLowDegree =====
section
/-!
# Low-degree polynomial jets in the N13 Gaussian order

Every integral polynomial in `θ` reduces to a constant dual number: the
coefficients have no infinitesimal part and `θ` reduces to `α`.  If its
coefficient reduction is nonzero of degree at most two, evaluation at
`α` cannot vanish because the residue polynomial of `α` has degree three.

This treats split and nonsplit degree-two support uniformly.  It is a
statement about the explicit Gaussian order and its first quotient; the
global-to-completion and genuine local Kummer comparisons remain separate.
-/
open Polynomial
namespace MazurProof.N13GaussianLowDegree
noncomputable section
open N13GaussianOrderTwo
open N13LocalDlogTwo
open N13LocalDlogRegimes
open TrivSqZeroExt
abbrev Z2 : Type := N13GaussianOrderTwo.Z2
abbrev F8 : Type := N13LocalDlogTwo.F8
end
end MazurProof.N13GaussianLowDegree
end

end

-- ===== FLT.Assumptions.MazurProof.N13MumfordAbelJacobi =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MumfordAbelJacobi =====
section
/-!
# The N13 Abel--Jacobi embedding in oriented Mumford coordinates

The chosen positive infinity is the base point.  A curve point is first sent
to its balanced Mumford representative and then to its oriented Picard class.
-/
namespace MazurProof.N13MumfordAbelJacobi
noncomputable section
universe u
variable (K : Type u) [Field K] [CharZero K]
abbrev Cusp13 := N13Mumford.Cusp13
end
end MazurProof.N13MumfordAbelJacobi
end

end

-- ===== FLT.Assumptions.MazurProof.N13InfinityHalf =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InfinityHalf =====
section
/-!
# A half of the infinity-difference class on the N13 sextic

The Gaussian factorization `f = A² + B²` supplies a balanced Mumford pair
`u = X(X+1)`, `v = -(2X+1)` and the function `g = Y-A`.  We prove

`(u, Y-v)² = (g)` and `ord_{∞₊}(g) = -1`.

The corresponding oriented Picard identity says that this Mumford class
doubles to the difference of the two points at infinity.  This removes the
extra even-degree ambiguity in the fake 2-Kummer kernel.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13InfinityHalf
noncomputable section
open SexticMumford
def halfU : ℚ[X] := X * (X + 1)
def halfV : ℚ[X] := -(2 * X + 1)
theorem halfU_monic : halfU.Monic := by
  unfold halfU
  monicity!
theorem halfU_natDegree : halfU.natDegree = 2 := by
  unfold halfU
  compute_degree!
theorem half_curve_factor :
    N13Mumford.f ℚ - halfV ^ 2 =
      halfU * (X ^ 4 + 3 * X ^ 3 + 3 * X ^ 2 - X - 2) := by
  simp [N13Mumford.f, halfU, halfV]
  ring
def backQ : ℚ[X] := -4
end
end MazurProof.N13InfinityHalf
end

end

-- ===== FLT.Assumptions.MazurProof.N13GaussianGlobalZeroCarrierDlog =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GaussianGlobalZeroCarrierDlog =====
section
/-!
# Global zero-carrier classes and the first ramified logarithm

The global factorization of a normalized N13 Kummer integer is an exact
identity

`x = ε * y²`

in the maximal order.  The same maximal order has an honest reduction to the
first ramified quotient at two.  Reducing the identity therefore shows that
the logarithm of `ε` vanishes: the square contributes twice its logarithm,
while `x` is the evaluation of a primitive polynomial of degree at most two
and hence has a constant nonzero first jet.

This aligns the global named-unit coordinates with the local logarithm
without a valuation case split or a finite candidate search.
-/
open Polynomial
namespace MazurProof.N13GaussianGlobalZeroCarrierDlog
noncomputable section
open N13GaussianGlobalReductionTwo
open N13GaussianLowDegree
open N13GaussianOrderTwo
open N13GaussianNamedUnitSquareclasses
abbrev Z2 := N13GaussianOrderTwo.Z2
abbrev F8 := N13LocalDlogTwo.F8
/-! ## The global integral evaluation in the explicit order -/
/-! ## The same named-unit word globally and locally -/
/-! ## Group-level capstone -/
end
end MazurProof.N13GaussianGlobalZeroCarrierDlog
end

end

-- ===== FLT.Assumptions.MazurProof.N13FullNormPairGaussian =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FullNormPairGaussian =====
section
/-!
# The N13 full norm-pair sign is gauge-trivial

The N13 sextic field is a cubic extension of the Gaussian field, so it
contains a unit `i` with

`i² = -1`,  `Norm(i) = 1`.

Consequently the square/norm gauge at `i`, multiplied by the scalar/cubic
gauge at `-1`, is exactly the sign pair `(1,-1)`.  Thus the distinguished
sign class in the full norm-pair target is already trivial for N13.

This is a field-structure argument.  It uses neither divisor enumeration
nor a finite square-class certificate.
-/
namespace MazurProof.N13FullNormPairGaussian
noncomputable section
open N13GaussianGlobalArithmetic
abbrev Ls : Type :=
  N13GaussianFieldEquiv.Ls
abbrev Lg : Type :=
  N13GaussianFieldEquiv.Lg
abbrev K : Type :=
  N13GaussianFieldEquiv.K
abbrev GI : Type :=
  N13GaussianGlobalArithmetic.GI
end
end MazurProof.N13FullNormPairGaussian
end

end

-- ===== FLT.Assumptions.MazurProof.N13MumfordFullKummerIdentityFiber =====
section
-- ===== FLT.Assumptions.MazurProof.N13MumfordFullKummerIdentityFiber =====
section
/-!
# The remaining identity fibre of the N13 full Kummer map

The target algebra already shows that the N13 full Kummer map has one
kernel fibre.  This file unfolds that fibre instead of treating it as an
opaque equality:

* triviality in the full target is equivalent to an explicit full-gauge
  witness `(β,q)`;
* divisibility by two in the oriented Picard quotient is equivalent to an
  explicit square root of the raw oriented fractional ideal.

The remaining geometric seam is closed here by a dimension-theoretic Padé
numerator, homogeneous resultants, quadratic-algebra rigidity, and Cantor
ideal identities.  No representative enumeration or finite certificate is
used.
-/
namespace MazurProof.N13MumfordFullKummerIdentityFiber
noncomputable section
open Polynomial
open SexticMumford
open scoped nonZeroDivisors
abbrev L : Type :=
  N13FullNormPair.L
/-! ## Unfolding the full-gauge fibre -/
/-! ## The canonical polynomial square-root witness -/
/-! ## The structural Padé numerator -/
/-! ## The Cantor square behind a Padé half -/
universe u
variable {K : Type u} [Field K]
/-! ## From the sextic norm to the quadratic norm -/
/-! ## Closing the finite ideal square -/
namespace FinitePadeGraphRootData
end FinitePadeGraphRootData
namespace FiniteIdealGraphRootData
end FiniteIdealGraphRootData
/-! The branch `c = 0` is not a degenerate coefficient search.  The UFD
identity `q l² = a²u` says directly that the monic polynomial `u` is a
square; the corresponding repeated graph ideal is then the finite square
root. -/
/-! ## Squares in the oriented fractional-ideal quotient -/
/-! ## Absorbing the remaining infinity coordinate -/
/-! ## The structural full-gauge bridge -/
/-! ## Compatibility with the earlier abstract bridge interface -/
end
end MazurProof.N13MumfordFullKummerIdentityFiber
end

end

-- ===== FLT.Assumptions.MazurProof.SexticMumfordOrientedBaseChange =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.SexticMumfordOrientedBaseChange =====
section
/-!
# Base change of oriented Picard classes for smooth sextics

An injective coefficient map carrying one sextic equation to another induces
maps on the affine coordinate rings, their fraction fields, and invertible
fractional ideals.  If the distinguished infinity orders are compatible,
the resulting map on oriented fractional ideals descends to an additive map
of the concrete oriented Picard groups.

The construction is algebraic: extension of fractional ideals and a quotient
universal property.  It does not use a relative Picard scheme.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.SexticMumford.OrientedBaseChange
noncomputable section
universe u v
variable {K : Type u} {K' : Type v}
variable [Field K] [Field K']
variable {M : Model K} {M' : Model K'}
/-- Coefficient extension on the polynomial base ring. -/
def mapPoly (ι : K →+* K') : K[X] →+* K'[X] :=
  Polynomial.mapRingHom ι
@[simp] theorem mapPoly_apply (ι : K →+* K') (p : K[X]) :
    mapPoly ι p = p.map ι := rfl
theorem map_curvePoly
    (ι : K →+* K') (hM : M.f.map ι = M'.f) :
    (curvePoly M).map (mapPoly ι) = curvePoly M' := by
  simp [curvePoly, mapPoly, hM]
theorem target_curve_dvd
    (ι : K →+* K') (hM : M.f.map ι = M'.f) :
    curvePoly M' ∣ (curvePoly M).map (mapPoly ι) := by
  rw [map_curvePoly ι hM]
end
end MazurProof.SexticMumford.OrientedBaseChange
end

end

-- ===== FLT.Assumptions.MazurProof.N13InfinityBaseChange =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InfinityBaseChange =====
section
/-!
# Base change at the positive infinity of the N13 sextic

Coefficient extension commutes with the chosen positive Laurent branch of
the N13 function field.  The only apparent issue is the formal square root
used to define that branch.  We avoid coefficient calculations: after base
change the two candidate square roots have the same square and constant
coefficient `1`, so the factorization of a difference of squares excludes
the negative root.

For an injective coefficient map, coefficientwise extension of Laurent
series also preserves the support, hence its integer order.  Together these
facts give compatibility of the oriented infinity order and the induced
base-change map on concrete Picard groups.
-/
open Polynomial
open scoped LaurentSeries
namespace MazurProof.N13InfinityBaseChange
noncomputable section
universe u v
variable {K : Type u} {K' : Type v}
variable [Field K] [Field K'] [CharZero K] [CharZero K']
omit [CharZero K] [CharZero K'] in
@[simp] theorem map_n13_f
    (ι : K →+* K') :
    (N13Mumford.f K).map ι = N13Mumford.f K' := by
  simp [N13Mumford.f]
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev Q₂ : Type := ℚ_[2]
def ratToQ₂ : ℚ →+* Q₂ := algebraMap ℚ Q₂
theorem ratToQ₂_injective : Function.Injective ratToQ₂ :=
  (ratToQ₂).injective
end
end MazurProof.N13InfinityBaseChange
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralFiberDetection =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralFiberDetection =====
section
open Polynomial
open scoped BigOperators nonZeroDivisors
namespace MazurProof.N13IntegralFiberDetection
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev IntegralRing : Type :=
  N13IntegralModelContraction.IntegralRing
abbrev SpecialRing : Type :=
  N13GeneralizedMumfordReduction.SpecialRing
def reduceCoordinate : IntegralRing →+* SpecialRing :=
  N13GeneralizedMumfordReduction.reduceCoordinate
namespace DefectDualFrame
end DefectDualFrame
namespace ContractedDualFrame
end ContractedDualFrame
namespace ContractedDualFrame
end ContractedDualFrame
end
end MazurProof.N13IntegralFiberDetection
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialProductLift =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialProductLift =====
section
/-!
# The finite N13 product-lift seam

The special affine dual frame has three evaluations whose sum is one.
For the integral argument it is unnecessary to lift the six factors
separately.  It suffices to lift each evaluation into the product of the
contracted lattice with its multiplier inverse.  This is a weaker interface
than factorwise dual base change, but it is still the full special trace-unit
certificate and does not follow formally from contraction.

This file records exactly that weaker geometric obligation and connects it
to the generic--special fibre criterion.
-/
open scoped BigOperators nonZeroDivisors
namespace MazurProof.N13SpecialProductLift
noncomputable section
abbrev IntegralRing : Type :=
  N13IntegralFiberDetection.IntegralRing
namespace Data
end Data
end
end MazurProof.N13SpecialProductLift
end

end

-- ===== FLT.Assumptions.MazurProof.N13ConstructedHalfIntegralSpread =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13ConstructedHalfIntegralSpread =====
section
/-!
# The integral spread of the N13 constructed half

The proof of two-surjectivity selects a concrete invertible fractional-ideal
root over `ℚ`.  Base change sends that exact root to `ℚ₂`.  Multiplication by
its canonical fractional-ideal denominator produces an ordinary ideal, so
the existing contraction/divisorial-hull machinery applies without choosing
a different half.

The resulting hull has generic fibre equal to the selected root up to the
displayed principal denominator.  Its remaining integral invertibility
condition is exactly the existing three-product special trace lift.
-/
open scoped nonZeroDivisors
namespace MazurProof.N13ConstructedHalfIntegralSpread
noncomputable section
open Polynomial
open SexticMumford
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13ConstructedHalfIntegralSpread
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralGraphSpread =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralGraphSpread =====
section
/-!
# Invertible integral spreads of N13 Mumford graphs

A smooth integral generalized Mumford graph already gives an invertible
fractional ideal on the integral affine model: this is the explicit global
Jacobian dual-frame theorem.  Exact graph contraction then identifies the
canonical contraction of its generic sextic graph with that same integral
ideal.

Consequently the divisorial-hull construction makes no change at all on an
integral graph.  This is the representative-level adapter needed by the
proper-spread construction; it uses neither local factoriality nor a special
fibre classification.
-/
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralGraphSpread
noncomputable section
abbrev IntegralRing : Type :=
  N13IntegralFractionalHull.IntegralRing
end
end MazurProof.N13IntegralGraphSpread
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialCuspReduction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialCuspReduction =====
section
/-!
# The six N13 cusps on the special fibre

The good characteristic-two model has three hyperelliptic base points and
two sheets over each of them.  The six rational cusps reduce to these six
points bijectively.  This file records that correspondence as an explicit
equivalence.

The proof uses only the structural fact that every element of `F₂` is zero
or one.  It does not enumerate divisors or Jacobian representatives.
-/
namespace MazurProof.N13SpecialCuspReduction
noncomputable section
open N13AbelFiberTwoModel
abbrev Cusp13 : Type :=
  N13Mumford.Cusp13
abbrev SpecialCurvePoint : Type :=
  N13AbelFiberTwoModel.CurvePoint
end
end MazurProof.N13SpecialCuspReduction
end

end

-- ===== FLT.Assumptions.MazurProof.N13RationalPointEndgame =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13RationalPointEndgame =====
section
/-!
# The structural N13 rational-point endgame

This file isolates the exact proper-reduction input still needed after the
N13 two-descent and formal-kernel arguments.

A compatible reduction consists of the existing exact set-valued Picard
classifier, a reduction of rational curve points to the good special fibre,
and compatibility with the Abel map and the six rational cusps.  Since the
six cusps cover the special curve, every rational curve point has the same
reduced Abel class as a cusp.  Separatedness makes Picard reduction
injective, and the already-proved Abel--Jacobi embedding then identifies the
two curve points.

No group law on the nineteen-element set and no finite table are used.
-/
namespace MazurProof.N13RationalPointEndgame
noncomputable section
open scoped Sym2
abbrev SpecialCurvePoint : Type :=
  N13SpecialCuspReduction.SpecialCurvePoint
abbrev Cusp13 : Type :=
  N13Mumford.Cusp13
namespace CompatibleReduction
end CompatibleReduction
end
end MazurProof.N13RationalPointEndgame
end

end

-- ===== FLT.Assumptions.MazurProof.N13ProperCurveReduction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13ProperCurveReduction =====
section
/-!
# Proper two-chart reduction of N13 curve points at two

Rational points on the sextic are first transported to the generalized
hyperelliptic equation

`y² + (x³ + x + 1)y = x⁵ + x⁴`.

If `x` is integral, its monic equation makes `y` integral and the point
reduces on the affine chart.  If `x` is nonintegral, put `t = x⁻¹` and
`v = t³y`; then the monic infinity-chart equation makes `v` integral,
while positive valuation of `t` forces its residue to be zero.  Thus the
construction is proper and genuinely uses both charts.

The final theorem identifies the reductions of the six rational cusps
with the previously constructed six-point special-fibre equivalence.
No point enumeration is used.
-/
namespace MazurProof.N13ProperCurveReduction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev Q₂ : Type := ℚ_[2]
abbrev Z₂ : Type := ℤ_[2]
abbrev F₂ : Type := ZMod 2
abbrev SpecialCurvePoint : Type :=
  N13RationalPointEndgame.SpecialCurvePoint
def ratToQ₂ : ℚ →+* Q₂ :=
  N13InfinityBaseChange.ratToQ₂
theorem map_good_equation
    {X Y : ℚ} (hcurve : N13CurveModel.C13SexticEq X Y) :
    N13GoodModelTwo.AffineEquation
      (ratToQ₂ X)
      (ratToQ₂ (N13GoodModelTwo.sexticToGoodY X Y)) := by
  have hgood := N13GoodModelTwo.sextic_to_good hcurve
  simpa [N13GoodModelTwo.AffineEquation, N13GoodModelTwo.h,
    N13GoodModelTwo.rhs, ratToQ₂] using congrArg ratToQ₂ hgood
end
end MazurProof.N13ProperCurveReduction
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralAffinePointSpread =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralAffinePointSpread =====
section
/-!
# Integral spreads of affine N13 points

An integral point of the good two-adic affine chart gives the monic linear
generalized Mumford graph `(X-x, y)`.  Its curve equation follows by the
factor theorem.  Completion of the square identifies its generic sextic
graph with the standard Mumford graph of the corresponding curve point.

The semigraph contraction theorem and the global Jacobian frame therefore
make the canonical divisorial spread invertible.  This closes the affine
half of the proper degree-one branch without local factoriality.
-/
open Polynomial
namespace MazurProof.N13IntegralAffinePointSpread
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13ProperCurveReduction.Z₂
abbrev Q₂ : Type :=
  N13ProperCurveReduction.Q₂
abbrev IntegralPoint : Type :=
  {p : R₂ × R₂ //
    N13GoodModelTwo.AffineEquation p.1 p.2}
abbrev IntegralSemiMumford : Type :=
  N13GeneralizedMumfordIntegral.TwoAdic.SemiMumford₂
/-- The standard sextic ordinate obtained by completing the square. -/
def sexticY (P : IntegralPoint) : Q₂ :=
  2 * (P.1.2 : Q₂) +
    N13GoodModelTwo.h (P.1.1 : Q₂)
theorem goodEquation_Q₂ (P : IntegralPoint) :
    N13GoodModelTwo.AffineEquation
      (P.1.1 : Q₂) (P.1.2 : Q₂) := by
  simpa [N13GoodModelTwo.AffineEquation,
    N13GoodModelTwo.h, N13GoodModelTwo.rhs] using
    congrArg (algebraMap R₂ Q₂) P.2
/-! ## The integral branch of the selected degree-one Padé graph -/
end
end MazurProof.N13IntegralAffinePointSpread
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialCechObstruction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialCechObstruction =====
section
/-!
# The special-fibre Čech obstruction at the N13 base divisor

Put `t = 1/x` and `v = y/x³` on the infinity chart.  For the structure
sheaf, the two classes missing from the affine and infinity chart images
are represented by

`v t⁻², v t⁻¹`.

The two simple principal parts at `(0,0)` and `(1,0)` map to `(1,0)` and
`(1,1)` in this obstruction basis.  The resulting triangular matrix has
determinant one.  This is the explicit special-fibre Čech form of the
nonspeciality of the divisor `(0,0)+(1,0)`.

The polynomial identities below are the cleared-denominator transition
calculation.  They use the actual infinity-chart coefficient
`1+t²+t³`; no point enumeration or certificate table is involved.
-/
namespace MazurProof.N13SpecialCechObstruction
noncomputable section
abbrev K : Type :=
  N13GoodModelTwo.F2
/-! ## The two-chart Laurent obstruction -/
open LaurentPolynomial
open scoped LaurentPolynomial
end
end MazurProof.N13SpecialCechObstruction
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralCechObstruction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralCechObstruction =====
section
/-!
# The integral N13 Čech obstruction at two

The Laurent two-chart quotient is ring-generic, so over `ℤ₂` it is already
the free rank-two module with basis `v t⁻², v t⁻¹`.  The integral base
divisor is `(0,0)+(-1,0)`.  Expanding its two simple principal parts at
infinity gives the columns

`(1,0), (1,-1)`.

Thus the integral connecting matrix has determinant `-1`.  Its reduction
modulo two is exactly the special-fibre matrix with columns `(1,0),(1,1)`.
This supplies the finite bounded-pole integral complex to which the general
Čech--Nakayama correction applies.
-/
namespace MazurProof.N13IntegralCechObstruction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  ℤ_[2]
abbrev K : Type :=
  N13GoodModelTwo.F2
/-! ## Compatibility with the special fibre -/
/-! ## Nakayama lifting from the computed special complex -/
end
end MazurProof.N13IntegralCechObstruction
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralFormalCech =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralFormalCech =====
section
/-!
# The actual formal principal parts in the integral N13 Čech complex

The second N13 base point produces a regular tail containing
`1 / (1 + t)`.  This is why the proper/formal overlap must use Laurent
series rather than Laurent polynomials.

This file writes both integral principal parts as genuine formal Laurent
series, proves their cleared-denominator identities, and identifies their
classes with the finite connecting matrix already used by the
Čech--Nakayama argument.
-/
namespace MazurProof.N13IntegralFormalCech
noncomputable section
open HahnSeries
open scoped PowerSeries LaurentSeries
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralCechObstruction.R₂
/-! ## The genuine formal Čech quotient -/
end
end MazurProof.N13IntegralFormalCech
end

end

-- ===== FLT.Assumptions.MazurProof.N13FormalLineBundleCech =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FormalLineBundleCech =====
section
/-!
# Near-trivial formal line bundles in the N13 Čech chart

A line bundle in the kernel of specialization admits, after choosing local
trivializations, a formal overlap transition which reduces to `1`.  Twisting
the two actual principal parts by such a transition perturbs the integral
connecting matrix, but does not change its special fibre.

This file encodes the actual quadratic formal curve algebra at infinity,
proves coefficientwise reduction respects its multiplication, and applies
the previously proved Čech--Nakayama theorem to every invertible transition
reducing to `1`.

The remaining geometric task is now sharply isolated: construct these two
local trivializations from a rational Picard class in the specialization
kernel.  No cohomology or matrix-surjectivity hypothesis remains.
-/
namespace MazurProof.N13FormalLineBundleCech
noncomputable section
open HahnSeries
open scoped LaurentSeries
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralCechObstruction.R₂
abbrev K : Type :=
  N13IntegralCechObstruction.K
namespace NearIdentityTransition
end NearIdentityTransition
end
end MazurProof.N13FormalLineBundleCech
end

end

-- ===== FLT.Assumptions.MazurProof.N13FormalCurveOverlap =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FormalCurveOverlap =====
section
/-!
# The actual formal overlap algebra for the N13 integral curve

The pair multiplication used by the formal Čech calculation is not an
abstract two-dimensional algebra.  It is the normal-form multiplication in
the quadratic algebra

`R₂((t))[v] / (v² + (1+t²+t³)v - (t+t²))`.

This file identifies the two descriptions and constructs the restriction
homomorphism from the actual affine coordinate ring by

`x ↦ t⁻¹`, `y ↦ t⁻³v`.

Thus a unit obtained from a genuine local trivialization gives, without any
extra inverse hypothesis, the `NearIdentityTransition` consumed by the
Čech--Nakayama theorem.
-/
open Polynomial
namespace MazurProof.N13FormalCurveOverlap
noncomputable section
open HahnSeries
open scoped LaurentSeries
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13FormalLineBundleCech.R₂
/-! ## Restriction of the actual affine coordinate ring -/
end
end MazurProof.N13FormalCurveOverlap
end

end

-- ===== FLT.Assumptions.MazurProof.N13FormalInfinityChart =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FormalInfinityChart =====
section
/-!
# The actual formal infinity chart of the N13 integral curve

The additive Čech calculation described the infinity-chart image as pairs of
power series.  This file realizes that submodule as the image of the actual
quadratic formal curve

`ℤ₂[[t]][v] / (v² + (1+t²+t³)v - (t+t²))`

inside the punctured formal overlap.  In particular, the previously defined
`infinitySections` is neither an approximation nor a coefficientwise
superset: it is exactly the restriction image of the genuine chart ring.
-/
open Polynomial
namespace MazurProof.N13FormalInfinityChart
noncomputable section
open HahnSeries
open scoped PowerSeries LaurentSeries
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13FormalCurveOverlap.R₂
/-! ## Normal form on the complete chart -/
end
end MazurProof.N13FormalInfinityChart
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityChart =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityChart =====
section
/-!
# The ordinary integral infinity chart of N13

This algebraic chart precedes completion.  It is the quadratic algebra over
`ℤ₂[t]` cut out by

`v² + (1+t²+t³)v = t+t²`.

The coefficientwise map `ℤ₂[t] → ℤ₂[[t]]` induces the canonical completion
map to the already constructed formal infinity chart.
-/
open Polynomial
namespace MazurProof.N13IntegralInfinityChart
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13FormalInfinityChart.R₂
abbrev Base : Type :=
  R₂[X]
/-- Coefficient of `v` on the ordinary infinity chart. -/
def hBase : Base :=
  1 + X ^ 2 + X ^ 3
/-- Right-hand side on the ordinary infinity chart. -/
def rhsBase : Base :=
  X + X ^ 2
end
end MazurProof.N13IntegralInfinityChart
end

end

-- ===== FLT.Assumptions.MazurProof.N13OrdinaryCurveOverlap =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13OrdinaryCurveOverlap =====
section
/-!
# The ordinary algebraic overlap of the two N13 charts

This file begins the ordinary, pre-completion two-chart model.  It localizes
the infinity chart at `t` and constructs the affine restriction by

`x ↦ t⁻¹`, `y ↦ t⁻³v`.

The construction uses the universal properties of `AdjoinRoot` and
`Localization.Away`; its equation check is the presentation-independent
identity in `N13OrdinaryOverlapCore`.
-/
open Polynomial
namespace MazurProof.N13OrdinaryCurveOverlap
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralInfinityChart.R₂
abbrev Base : Type :=
  N13IntegralInfinityChart.Base
/-! ## The reverse chart map -/
end
end MazurProof.N13OrdinaryCurveOverlap
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralCurveScheme =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralCurveScheme =====
section
/-!
# The integral two-chart N13 curve

The ordinary affine and infinity charts over `R₂` are glued along their
distinguished principal opens.  As for the special fibre, the index type
is `Bool`, so the genuinely three-distinct-index part of
`CategoryTheory.GlueData'` is empty.
-/
open CategoryTheory CategoryTheory.Limits
open Polynomial
namespace MazurProof.N13IntegralCurveScheme
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
open AlgebraicGeometry
end
end MazurProof.N13IntegralCurveScheme
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralCurveProperties =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralCurveProperties =====
section
/-!
# Integrality of the ordinary N13 model

The affine chart embeds in its rational generic fibre.  On the infinity
chart, the parameter `t` is regular because the coordinate ring is free over
`ℤ₂[t]`; localizing at `t` identifies it with the affine overlap.  Thus both
charts and their common principal open are domains.

The two irreducible chart images cover the glued scheme and have nonempty
intersection.  This proves that the ordinary two-chart N13 model is reduced,
irreducible, and integral without any point enumeration.
-/
open CategoryTheory
open Polynomial
open Set Topology
namespace MazurProof.N13IntegralCurveProperties
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
open AlgebraicGeometry
end
end MazurProof.N13IntegralCurveProperties
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityPointSpread =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityPointSpread =====
section
/-!
# Integral point ideals on the N13 infinity chart

An integral point `(t₀,v₀)` on the ordinary infinity chart with
`t₀ ≡ 0 mod 2` defines the linear graph ideal

`(t-t₀, v-v₀)`.

Its generalized Jacobian in the ordinate direction reduces to `1`, hence
is a two-adic unit.  The abstract graph-ideal product theorem then gives an
explicit inverse for this point ideal.  This is the infinity-chart analogue
of the integral affine semigraph construction.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralInfinityPointSpread
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13ProperCurveReduction.Z₂
abbrev Base : Type :=
  N13IntegralInfinityChart.Base
abbrev IntegralInfinityPoint : Type :=
  {p : R₂ × R₂ //
    N13GoodModelTwo.InfinityChartEquation p.1 p.2}
/-- The ordinate Jacobian evaluated at the integral infinity point. -/
def pointJacobianValue (P : IntegralInfinityPoint) : R₂ :=
  2 * P.1.2 +
    (1 + P.1.1 ^ 2 + P.1.1 ^ 3)
/-! ## The matching affine-chart closure

On the overlap put `x=t⁻¹` and `y=x³v`.  Clearing these powers from the
infinity graph gives the integral affine graph

`u = 1-t₀x`, `y = v₀x³`.

Its horizontal equation is not monic, but the monicity-free global
Jacobian frame applies.
-/
end
end MazurProof.N13IntegralInfinityPointSpread
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityGraphJacobian =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityGraphJacobian =====
section
/-!
# Integral graph ideals on the N13 infinity chart

The ordinary infinity chart has equation

`v² + (1 + t² + t³)v = t + t²`.

An explicit integral Bézout certificate for its two relative Jacobian
rows has the odd value `117`.  Hence the rows generate one over the
two-adic integers, and the general graph-Jacobian dual frame makes every
nondegenerate integral polynomial graph on this chart invertible.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralInfinityGraphJacobian
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralInfinityChart.R₂
abbrev Base : Type :=
  N13IntegralInfinityChart.Base
end
end MazurProof.N13IntegralInfinityGraphJacobian
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityGraphTwoChart =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityGraphTwoChart =====
section
/-!
# Two-chart closures of integral N13 infinity graphs

An integral polynomial graph on the ordinary infinity chart can be
homogenized with the weights

`u ↦ X² u(X⁻¹)`, `v ↦ X³ v(X⁻¹)`, `w ↦ X⁴ w(X⁻¹)`.

`Polynomial.reflect` implements these three weighted reversals.  Reflecting
the infinity semigraph identity at total weight six gives the affine
semigraph identity, while on the Laurent overlap the two graph generators
differ by the units `x²` and `x³`.  Thus every bounded integral infinity
graph supplies an invertible root-free two-chart line.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralInfinityGraphTwoChart
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralInfinityChart.R₂
abbrev Base : Type :=
  N13IntegralInfinityChart.Base
theorem hBase_natDegree_le :
    N13IntegralInfinityChart.hBase.natDegree ≤ 3 := by
  unfold N13IntegralInfinityChart.hBase
  compute_degree <;> norm_num
end
end MazurProof.N13IntegralInfinityGraphTwoChart
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialInfinityChart =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialInfinityChart =====
section
/-!
# The special N13 infinity chart is integral

Over `F₂`, the infinity chart is

`v² + (1+t²+t³)v = t+t²`.

Irreducibility follows from a degree gap.  A factorization of the monic
quadratic would give polynomials `a,b` with `a*b = t+t²` and
`a+b = 1+t²+t³`.  The product forces both factors to have degree at most
two, whereas their sum has degree three.

No polynomial enumeration or coefficient table is used.
-/
open Polynomial
namespace MazurProof.N13SpecialInfinityChart
noncomputable section
abbrev K : Type :=
  N13GoodModelTwo.F2
end
end MazurProof.N13SpecialInfinityChart
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityReduction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityReduction =====
section
/-!
# Reduction of the N13 infinity chart at two

Coefficientwise reduction induces the special infinity chart

`v² + (1+t²+t³)v = t+t²`.

The induced map is onto and its kernel is exactly the vertical ideal `(2)`.
Both statements use the common rank-two normal form `a(t) + b(t)v`; no
enumeration of the special fibre is involved.
-/
open Polynomial
namespace MazurProof.N13IntegralInfinityReduction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralInfinityChart.R₂
abbrev K : Type :=
  N13SpecialInfinityChart.K
abbrev IntegralBase : Type :=
  N13IntegralInfinityChart.Base
abbrev SpecialBase : Type :=
  K[X]
end
end MazurProof.N13IntegralInfinityReduction
end

end

-- ===== FLT.Assumptions.MazurProof.N13FiniteAffineTwoChart =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FiniteAffineTwoChart =====
section
/-!
# Proper two-chart closure of a finite N13 affine divisor

An invertible ideal on the affine chart need not by itself record its
behaviour at infinity.  For an ideal with finite support over the two-adic
coefficient ring, however, the affine coordinate is integral in the
quotient.  A monic equation for that coordinate reflects to an equation with
constant coefficient one on the infinity chart.  Hence the infinity
uniformizer is a unit modulo the contracted overlap ideal.

The principal-localization patching theorem then upgrades invertibility on
the punctured infinity chart to invertibility on the full infinity chart.
This supplies proper extensions for finite N13 graph ideals, including
integral affine points and the finite irreducible quadratic branch, without
choosing reciprocal coordinates.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13FiniteAffineTwoChart
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
/-! ## Integral affine point lines -/
/-! ## Finite quadratic lines -/
end
end MazurProof.N13FiniteAffineTwoChart
end

end

-- ===== FLT.Assumptions.MazurProof.N13EscapingDegreeOneSpread =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13EscapingDegreeOneSpread =====
section
/-!
# The generic class of an escaping degree-one point line

For a nonintegral affine point `(x,y)` on the good two-adic model, the
infinity lift has coordinates `t=x⁻¹` and `v=t³y`.  The two-chart line
constructed from this integral point has affine graph

`(1-tX, Y-vX³)`.

After passing to the generic fibre, its first generator is a unit multiple
of `X-x`, and its completed-square ordinate agrees modulo `X-x` with the
standard sextic ordinate `2y+h(x)`.  Hence the generic fibre is exactly the
usual degree-one Mumford point ideal.

For an integral affine point, the finite-support closure theorem instead
contracts the overlap ideal onto the infinity chart.  Together the two
constructions give a proper two-chart line for every selected degree-one
graph.
-/
open Polynomial
namespace MazurProof.N13EscapingDegreeOneSpread
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev Q₂ : Type :=
  N13ProperCurveReduction.Q₂
abbrev PInf : Type :=
  N13IntegralInfinityPointSpread.IntegralInfinityPoint
def pointY (x y : Q₂) : Q₂ :=
  2 * y + N13GoodModelTwo.h x
end
end MazurProof.N13EscapingDegreeOneSpread
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoChartLineTensor =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoChartLineTensor =====
section
/-!
# Tensor products of explicit N13 two-chart lines

The ordinary affine and infinity presentations of a line multiply
chartwise.  Ideal extension commutes with multiplication, so the overlap
compatibility is preserved.  This turns the explicit escaping point lines
into proper spreads of split effective divisors without constructing a
Picard functor.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13TwoChartLineTensor
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
/-! ## The two rational points at infinity -/
abbrev IntegralInfinityPoint : Type :=
  N13IntegralInfinityPointSpread.IntegralInfinityPoint
end
end MazurProof.N13TwoChartLineTensor
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialCurveOverlap =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialCurveOverlap =====
section
/-!
# The special algebraic overlap of the two N13 charts

This file begins the special, pre-completion two-chart model.  It localizes
the infinity chart at `t` and constructs the affine restriction by

`x ↦ t⁻¹`, `y ↦ t⁻³v`.

The construction uses the universal properties of `AdjoinRoot` and
`Localization.Away`; its equation check is the presentation-independent
identity in `N13OrdinaryOverlapCore`.
-/
open Polynomial
namespace MazurProof.N13SpecialCurveOverlap
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev K : Type :=
  N13SpecialInfinityChart.K
abbrev Base : Type :=
  K[X]
/-! ## The reverse chart map -/
end
end MazurProof.N13SpecialCurveOverlap
end

end

-- ===== FLT.Assumptions.MazurProof.N13OverlapReductionCompatibility =====
section
-- ===== FLT.Assumptions.MazurProof.N13OverlapReductionCompatibility =====
section
/-!
# Reduction commutes with the N13 two-chart overlap

The ordinary affine and infinity reductions extend to their distinguished
principal opens.  The two resulting squares commute with the ordinary and
special overlap equivalences.

Everything is proved from localization and `AdjoinRoot` universal
properties.  No pointwise calculation on either special chart is used.
-/
open Polynomial
namespace MazurProof.N13OverlapReductionCompatibility
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13OverlapReductionCompatibility
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoChartSpecialRestriction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoChartSpecialRestriction =====
section
/-!
# Chartwise special restriction of proper N13 lines

A `TwoChartLine` is an invertible ideal on each ordinary chart together with
literal equality after extension to their common overlap.  Reducing both chart
ideals modulo two preserves that overlap equality because the ordinary and
special overlap maps form a commutative square.

This construction deliberately retains both reduced ideals.  It is the
ring-theoretic restriction datum needed before identifying the special fibre
with a concrete effective divisor; it does not assert a general sheaf-descent
theorem that is absent from the pinned Mathlib API.
-/
namespace MazurProof.N13TwoChartSpecialRestriction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13TwoChartSpecialRestriction
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialDivisorCharts =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialDivisorCharts =====
section
/-!
# Canonical special-chart ideals of degree-two divisors

The completed special N13 curve is covered by its ordinary affine chart and
its infinity chart.  A finite point with horizontal coordinate zero is absent
from the overlap, a finite point with horizontal coordinate one lies on both
charts, and an infinity point is absent from the ordinary affine chart.

This file assigns to every completed point its compatible pair of chart
ideals.  Products of two point pairs then descend through the symmetric square
to give canonical chart ideals for every effective divisor of degree two.
-/
open Polynomial
open scoped Sym2
namespace MazurProof.N13SpecialDivisorCharts
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13SpecialDivisorCharts
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoChartPicardRealization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoChartPicardRealization =====
section
/-!
# Two-fibre Picard realization of proper N13 lines

Mathlib does not currently descend the two chart ideals of a `TwoChartLine`
to a global invertible sheaf on the glued curve.  The N13 endgame needs less:
an oriented generic fractional ideal and a literal degree-two divisor on the
special fibre.

The structure in this file retains precisely that rigorous ring-level data.
Its two special equalities compare both reduced chart ideals with the
canonical chart pair of one effective divisor.  The generic and special
Picard classes are consequently definitions, rather than hypothesized class
maps.
-/
open scoped nonZeroDivisors
namespace MazurProof.N13TwoChartPicardRealization
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
/-- The two-adic coefficient field. -/
abbrev Q₂ : Type :=
  N13InfinityBaseChange.Q₂
namespace Data
end Data
end
end MazurProof.N13TwoChartPicardRealization
end

end

-- ===== FLT.Assumptions.MazurProof.N13CoherentChartComparison =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13CoherentChartComparison =====
section
/-!
Source pin: a6290bc36c3549d89239da82b13b1f59ebd0388e.
Candidate only. Lean elaboration / build / axiom checks: NOT RUN.
A denominator-cleared, two-chart principal comparison. Existence is not asserted.
-/
namespace MazurProof.N13CoherentChartComparison
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13CoherentChartComparison
end

end

-- ===== FLT.Assumptions.MazurProof.N13PrimitiveChartTransport =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13PrimitiveChartTransport =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

Transport an affine numerator and denominator with nonzero reductions to
the ordinary infinity chart without losing their reductions. Both chart
fractions are proved equal by an exact overlap cross-product equation.
No equality of line ideals is assumed or claimed in this transport lemma.
-/
namespace MazurProof.N13PrimitiveChartTransport
noncomputable section
open Polynomial
open scoped nonZeroDivisors
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13PrimitiveChartTransport
end

end

-- ===== FLT.Assumptions.MazurProof.N13EffectiveInfinityRepair =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13EffectiveInfinityRepair =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
New source candidate for FLT-C13-B00-EXIST r2. Lean checks: NOT RUN.

Move the balanced upper wall by an actual Cantor principal relation. The
result lies in the effective degree-two chamber relative to two copies of
positive infinity. This does not assert an integral chart extension theorem.
-/
namespace MazurProof.N13EffectiveInfinityRepair
noncomputable section
universe u
variable {K : Type u} [Field K] [CharZero K]
local instance instDecidableEq_fLT : DecidableEq K := Classical.decEq K
open SexticMumford N13MumfordInfinityBalance
open Polynomial
end
end MazurProof.N13EffectiveInfinityRepair
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialGraphDivisorCharts =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialGraphDivisorCharts =====
section
/-!
# Chart ideals of special N13 graph divisors

A smooth quadratic generalized Mumford graph on the characteristic-two
N13 fibre splits into two graph points.  This file proves that the product
of their canonical affine point ideals is exactly the original Mumford
ideal.

For distinct roots this is the graph-ideal Chinese remainder theorem.  For
a repeated root, the vertical derivative is the everywhere nonzero
polynomial `h = X³ + X + 1` on `F₂`; this identifies the tangent graph ideal
with the square of the point ideal.  Thus the result retains multiplicity
without enumerating effective divisors.
-/
open Polynomial
open scoped Sym2
namespace MazurProof.N13SpecialGraphDivisorCharts
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
open N13GoodCoordinateRingTwo
abbrev K := N13GoodCoordinateRingTwo.K
end
end MazurProof.N13SpecialGraphDivisorCharts
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialVerticalDivisorCharts =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialVerticalDivisorCharts =====
section
/-!
# Chart ideals of vertical special N13 divisors

The finite canonical fibre above `x = a` consists of the two points
`(a,0)` and `(a,1)`.  Their affine point ideals multiply to the principal
horizontal ideal `(X-a)`: the two graph factors are hyperelliptic conjugates.

This file also computes the infinity-chart ideal.  The fibre above `a = 0`
is absent from the overlap and has unit infinity ideal.  The fibre above
`a = 1` meets the infinity chart at `t = 1`, where the two ordinate ideals
again multiply to the principal ideal `(t-1)`.
-/
open Polynomial
open scoped Sym2
namespace MazurProof.N13SpecialVerticalDivisorCharts
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
open N13GoodCoordinateRingTwo
abbrev K := N13GoodCoordinateRingTwo.K
end
end MazurProof.N13SpecialVerticalDivisorCharts
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialConstantInfinityVerticalGraph =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialConstantInfinityVerticalGraph =====
section
/-!
# Constant vertical graphs on the special infinity chart

When a vertical relation specializes to the constant equation `t = a`, its
monic quadratic ordinate equation is forced by the special curve equation
to be `v²+v`.  Thus the vertical graph ideal is just the principal fibre
ideal `(t-a)`, and its divisor is the canonical pair of the two sheets over
that base point.  This calculation treats both `t=0` and `t=1` uniformly.
-/
open Polynomial
namespace MazurProof.N13SpecialConstantInfinityVerticalGraph
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
/-- The special residue field. -/
abbrev K := N13SpecialInfinityChart.K
end
end MazurProof.N13SpecialConstantInfinityVerticalGraph
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialQuadraticGraphRegularity =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialQuadraticGraphRegularity =====
section
/-!
# Automatic regularity of quadratic special N13 graphs

The coefficient `h=1+X²+X³` of the special affine curve is an irreducible
cubic over `F₂`.  It is therefore coprime to every monic quadratic.  This
supplies the Bézout field required by the special Mumford API for any monic
quadratic semigraph, without an additional smoothness hypothesis.

Consequently every integral monic quadratic semigraph reduces directly to
the special graph data whose canonical root divisor has the same affine
ideal.
-/
open Polynomial
namespace MazurProof.N13SpecialQuadraticGraphRegularity
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13SpecialQuadraticGraphRegularity
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialAffineVerticalGraph =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialAffineVerticalGraph =====
section
/-!
# Vertical graphs on the special affine chart

A rank-two affine quotient with basis `{1,y}` is cut out by a monic
quadratic `m(y)` and a linear relation `x=a+cy`.  Over `F₂` the reduced
slope is either zero or one.

For slope zero, the curve equation forces `m=y²+y`, and the graph ideal is
the principal fibre ideal `(x-a)`.  For slope one, the involution
`y=x+a` turns the vertical graph into the horizontal graph
`m(x+a)=0, y=x+a`.  This file proves both ideal identities and packages the
nonconstant branch as regular special Mumford data.
-/
open Polynomial
namespace MazurProof.N13SpecialAffineVerticalGraph
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
/-- The special residue field. -/
abbrev K :=
  N13GoodCoordinateRingTwo.K
end
end MazurProof.N13SpecialAffineVerticalGraph
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialInfinitySaturation =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialInfinitySaturation =====
section
/-!
# Saturated infinity ideals on the special N13 overlap

The special infinity and affine charts meet on the principal open where
`t` is invertible.  If `t` is already a unit modulo an infinity ideal, then
extension to the overlap and contraction loses no information.  This is the
infinity-chart counterpart of `N13SpecialAffineSaturation`.

Finite affine closures acquire this property from the reflected monic
equation used in their construction.  Canonical divisors of finite special
graphs acquire it point by point: a root at `x=0` contributes the unit ideal,
and a root at `x=1` contributes the relation `t=1`.
-/
open Polynomial
open scoped Sym2
namespace MazurProof.N13SpecialInfinitySaturation
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13SpecialInfinitySaturation
end

end

-- ===== FLT.Assumptions.MazurProof.N13FiniteQuadraticSpecialRestriction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FiniteQuadraticSpecialRestriction =====
section
/-!
# Special restriction of finite irreducible N13 quadratics

A finite canonical contraction is finite flat of rank two.  The existing
coordinate-basis theorem chooses either the literal basis `{1,x}` or
`{1,y}`.  The first basis recovers an integral horizontal semigraph; the
second recovers an integral vertical graph.

After reduction, a horizontal graph gives its canonical special root
divisor.  A vertical graph has reduced slope zero or one: slope zero gives
the canonical two-sheet fibre over `x=a`, while slope one translates to a
horizontal graph.  In every case the reduced affine ideal is canonical.
The reflected monic equation makes `t` invertible modulo the source
infinity closure, and the same property holds for the target finite
divisor.  Infinity-chart saturation therefore upgrades the affine equality
to equality of the complete chart pair.
-/
open Module
open Polynomial
namespace MazurProof.N13FiniteQuadraticSpecialRestriction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
/-- The two-adic coefficient ring. -/
abbrev R₂ :=
  N13IntegralModelContraction.R₂
/-- The special residue field. -/
abbrev K :=
  N13GoodCoordinateRingTwo.K
/-- The integral affine coordinate ring. -/
abbrev IntegralRing :=
  N13IntegralModelContraction.IntegralRing
end
end MazurProof.N13FiniteQuadraticSpecialRestriction
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityGraphSaturation =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityGraphSaturation =====
section
/-!
# Vertical saturation of reflected N13 infinity graphs

A monic graph on the integral infinity chart has quotient
`R₂[X] / (u)`, hence its quotient has no torsion from a nonzero base
scalar.  For a monic quadratic `u`, weighted reflection also makes the
affine coordinate `x` a unit modulo the reflected graph ideal.  These two
facts, together with equality on the ordinary overlap, show that the
reflected affine ideal is the canonical vertical contraction of its
generic fibre.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralInfinityGraphSaturation
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralInfinityChart.R₂
abbrev Base : Type :=
  N13IntegralInfinityChart.Base
end
end MazurProof.N13IntegralInfinityGraphSaturation
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityVerticalGraphJacobian =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityVerticalGraphJacobian =====
section
/-!
# Vertical graph ideals on the N13 infinity chart

A rank-two quotient whose integral basis is `{1,v}` is cut out by a monic
relation `m(v)` and a linear equation `t = a + c v`.  Substitution into the
infinity-chart equation produces the complementary factor.  Explicit
divided differences decompose both global Jacobian rows in this vertical
graph frame, so the generic decomposition theorem proves invertibility.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralInfinityVerticalGraphJacobian
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralInfinityChart.R₂
namespace VerticalGraph
end VerticalGraph
open N13IntegralInfinityGraphJacobian
end
end MazurProof.N13IntegralInfinityVerticalGraphJacobian
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityVerticalGraphTwoChart =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityVerticalGraphTwoChart =====
section
/-!
# Two-chart closure of a vertical N13 infinity graph

A recovered vertical graph has infinity ideal

`(m(v), t - (a + c v))`.

After the substitutions `t=x⁻¹` and `v=x⁻³y`, clearing weights gives the
affine generators `x⁶m(x⁻³y)` and
`x³(t-a-cv) = x²-a x³-cy`.  The direct reciprocal kernel also contains a
monic quadratic equation in `t`; its weighted reflection has constant
coefficient one.  Adding this third, redundant overlap generator keeps the
affine support inside `D(x)`.

The infinity ideal is invertible on `D(x)`.  The principal-localization
patching theorem then proves that the three-generated affine closure is
invertible globally.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralInfinityVerticalGraphTwoChart
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralInfinityChart.R₂
end
end MazurProof.N13IntegralInfinityVerticalGraphTwoChart
end

end

-- ===== FLT.Assumptions.MazurProof.N13RankTwoInfinityVerticalGraphRecovery =====
section
-- ===== FLT.Assumptions.MazurProof.N13RankTwoInfinityVerticalGraphRecovery =====
section
/-!
# Rank-two vertical recovery on the N13 infinity chart

The ordinary infinity ring has the polynomial normal form
`p(t) + q(t)v`.  If a quotient has literal two-adic basis `{1,v}`, then
multiplication by `v` recovers a monic quadratic `m(v)` and the class of
`t` is a linear polynomial `a+cv`.  The generic vertical ideal-recovery
theorem identifies the original ideal with this graph, while the curve
equation supplies its complementary factor.
-/
open Module
open Polynomial
namespace MazurProof.N13RankTwoInfinityVerticalGraphRecovery
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralInfinityChart.R₂
end
end MazurProof.N13RankTwoInfinityVerticalGraphRecovery
end

end

-- ===== FLT.Assumptions.MazurProof.N13RankTwoInfinityGraphRecovery =====
section
-- ===== FLT.Assumptions.MazurProof.N13RankTwoInfinityGraphRecovery =====
section
/-!
# Rank-two horizontal recovery on the N13 infinity chart

A quotient basis `{1,t}` recovers a monic quadratic horizontal relation
and a linear ordinate.  The infinity curve equation then supplies the
Cantor quotient, so the original ideal is literally a bounded integral
infinity semigraph.
-/
open Module
open Polynomial
namespace MazurProof.N13RankTwoInfinityGraphRecovery
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralInfinityChart.R₂
end
end MazurProof.N13RankTwoInfinityGraphRecovery
end

end

-- ===== FLT.Assumptions.MazurProof.N13AllPointAffineSpread =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13AllPointAffineSpread =====
section
/-!
# Affine integral spreads of all two-adic N13 points

An affine point of the good model has two structural integral
presentations.  If its horizontal coordinate is integral, use its monic
affine graph.  If it has negative valuation, use the affine half of its
explicit infinity-chart point line.  Both presentations are invertible
integral fractional ideals with exactly the standard sextic point ideal as
generic fibre.

Tensoring the two alternatives closes every split quadratic graph with
distinct roots, independently of the valuations of those roots.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13AllPointAffineSpread
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev Q₂ : Type :=
  N13EscapingDegreeOneSpread.Q₂
abbrev IntegralRing : Type :=
  N13IntegralGraphJacobian.IntegralRing
end
end MazurProof.N13AllPointAffineSpread
end

end

-- ===== FLT.Assumptions.MazurProof.N13RepeatedRootSpread =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13RepeatedRootSpread =====
section
/-!
# Integral spreads of repeated-root N13 graphs

A repeated horizontal root is a tangent divisor, not a degenerate case
requiring enumeration.  Smoothness forces the ordinate at that root to be
nonzero.  The tangent graph ideal is then exactly the square of the point
graph ideal, and the existing valuation-independent point spread can be
tensor-squared.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13RepeatedRootSpread
noncomputable section
universe u
variable {K : Type u} [Field K]
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13RepeatedRootSpread
end

end

-- ===== FLT.Assumptions.MazurProof.N13IrreducibleQuadraticChart =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IrreducibleQuadraticChart =====
section
/-!
# The proper chart of an irreducible quadratic N13 graph

An irreducible monic quadratic over `ℚ₂` cannot have one root in each
valuation regime.  A root-free Hensel argument gives the exact Newton
dichotomy: either both ordinary coefficients are integral, or both
coefficients of the reciprocal monic quadratic are integral.

This isolates the proper chart for the remaining nonsplit degree-two
graph without constructing its splitting field or enumerating quadratic
extensions.
-/
open Polynomial
namespace MazurProof.N13IrreducibleQuadraticChart
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev Q₂ : Type := ℚ_[2]
abbrev Z₂ : Type := ℤ_[2]
end
end MazurProof.N13IrreducibleQuadraticChart
end

end

-- ===== FLT.Assumptions.MazurProof.N13ReciprocalQuadraticReflection =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13ReciprocalQuadraticReflection =====
section
/-!
# Reflection of the reciprocal N13 quadratic

For a monic quadratic

`u(X) = X² + u₁X + u₀`

with `u₀ ≠ 0`, its monic reciprocal equation is

`m(T) = T² + (u₁/u₀)T + u₀⁻¹`.

Reflecting `m` at weight two gives exactly `u₀⁻¹ u`.  Consequently an
integral reciprocal equation produces an integral affine weighted closure
whose generic horizontal generator differs from the original Mumford
generator by a nonzero scalar.  This is the horizontal equality needed in
the reciprocal two-chart branch.
-/
open Polynomial
namespace MazurProof.N13ReciprocalQuadraticReflection
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralModelContraction.R₂
abbrev Q₂ : Type :=
  N13IntegralModelContraction.Q₂
end
end MazurProof.N13ReciprocalQuadraticReflection
end

end

-- ===== FLT.Assumptions.MazurProof.N13ReciprocalInfinityContraction =====
section
-- ===== FLT.Assumptions.MazurProof.N13ReciprocalInfinityContraction =====
section
/-!
# The reciprocal N13 divisor on the integral infinity chart

For a quadratic generic Mumford graph with nonzero constant coefficient,
the class of the affine coordinate is invertible in its graph quotient.
Its explicit inverse is the infinity coordinate `t`, and `t³y` is the
ordinary infinity ordinate.  The ordinary overlap identity therefore
defines a canonical map from the integral infinity chart into the original
generic Mumford quotient.  Its kernel is the integral infinity ideal used
for rank-two recovery.
-/
open Polynomial
open Module
open scoped nonZeroDivisors TensorProduct
namespace MazurProof.N13ReciprocalInfinityContraction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralInfinityChart.R₂
abbrev Q₂ : Type :=
  N13CanonicalContractionQuotient.Q₂
abbrev k : Type :=
  N13SpecialInfinityChart.K
end
end MazurProof.N13ReciprocalInfinityContraction
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityVerticalGraphContraction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityVerticalGraphContraction =====
section
/-!
# Contraction of a vertical N13 infinity graph

The direct reciprocal kernel maps the integral infinity chart into the
original Mumford quotient.  Since the infinity coordinate `t` maps to a
unit, this map extends to the ordinary overlap.  Its kernel there is the
extension of the direct kernel.

For a recovered vertical graph, the three-generated affine closure has the
same overlap ideal and already makes `x` a unit modulo the ideal.  Contracting
from the overlap therefore identifies this affine closure with the canonical
vertical contraction of the original generic Mumford ideal.
-/
open Polynomial
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralInfinityVerticalGraphContraction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralModelContraction.R₂
abbrev Q₂ : Type :=
  N13IntegralModelContraction.Q₂
end
end MazurProof.N13IntegralInfinityVerticalGraphContraction
end

end

-- ===== FLT.Assumptions.MazurProof.N13SymmetricSquareFrobenius =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SymmetricSquareFrobenius =====
section
/-!
# Frobenius-fixed degree-two divisors on the N13 special fibre

An `𝔽₂`-rational point of a geometric symmetric square can in general be a
nonsplit Frobenius pair of `𝔽₄`-points.  For the N13 good model this does
not occur: the structural point classification already proves that every
`𝔽₄` curve point has both coordinates fixed by Frobenius.

This file makes that source-type correction explicit.  Base change gives an
equivalence between the six `𝔽₂` points and the six `𝔽₄` points, geometric
Frobenius is pointwise the identity on the latter, and consequently its
fixed unordered degree-two divisors are exactly `Sym2(C(𝔽₂))`.
-/
namespace MazurProof.N13SymmetricSquareFrobenius
noncomputable section
open N13GoodModelTwo
abbrev F2 := N13GoodModelTwo.F2
end
end MazurProof.N13SymmetricSquareFrobenius
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialInfinityGraphDivisor =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialInfinityGraphDivisor =====
section
/-!
# Special divisors cut out by infinity-chart graphs

A monic quadratic graph on the special infinity chart splits over `F₂`.
Roots at `t = 0` give the two points at infinity, while roots at `t = 1`
give affine points on the overlap.  This is the proper root divisor needed
when an integral reciprocal graph loses affine degree after reduction.
-/
open Polynomial
open scoped Sym2
namespace MazurProof.N13SpecialInfinityGraphDivisor
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev K := N13SpecialInfinityChart.K
end
end MazurProof.N13SpecialInfinityGraphDivisor
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialInfinityGraphDivisorCharts =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialInfinityGraphDivisorCharts =====
section
/-!
# Chart ideals of special infinity-graph divisors

This file identifies the canonical two-chart ideals of the degree-two
divisor obtained from a monic graph on the special infinity chart.  The
key local calculation treats a repeated root directly: the square of the
point ideal equals the quadratic graph ideal because the curve coefficient
`h∞(a)` is a unit at every `F₂`-rational root.
-/
open Polynomial
open scoped Sym2
namespace MazurProof.N13SpecialInfinityGraphDivisorCharts
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev K := N13SpecialInfinityChart.K
end
end MazurProof.N13SpecialInfinityGraphDivisorCharts
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialNonconstantInfinityVerticalGraph =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialNonconstantInfinityVerticalGraph =====
section
/-!
# Nonconstant vertical graphs on the special infinity chart

In the nonconstant residue branch a vertical relation has the form
`t=a+v`.  Characteristic two makes this affine change of variable
involutive: `v=t+a`.  Consequently the vertical graph

`m(v)=0,  t=a+v`

is the same closed subscheme as the horizontal graph

`m(t+a)=0,  v=t+a`.

This file carries out that change of variables inside the special coordinate
ring and packages the translated equations as the monic horizontal graph data
already handled by the completed-root divisor construction.
-/
open Polynomial
namespace MazurProof.N13SpecialNonconstantInfinityVerticalGraph
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
/-- The special residue field. -/
abbrev K :=
  N13SpecialInfinityChart.K
end
end MazurProof.N13SpecialNonconstantInfinityVerticalGraph
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityVerticalGraphSpecialRestriction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityVerticalGraphSpecialRestriction =====
section
/-!
# Special restriction of constant vertical infinity graphs

An integral vertical infinity graph is defined by a monic quadratic
`m(v)` and a linear relation `t=a+cv`.  This file treats the branch in
which `c` reduces to zero.  On the special fibre the relation becomes the
constant equation `t=ā`, so the reduced quadratic is forced to be `v²+v`
and the infinity ideal is the principal fibre ideal `(t-ā)`.

The weighted affine closure is not recomputed generator by generator.
Its reflected reciprocal equation makes `x` a unit modulo the ideal, and
this property survives reduction.  The canonical target fibre has the same
property.  Equality of the infinity ideals and compatibility on the overlap
therefore determine the full reduced two-chart pair.
-/
open Polynomial
open scoped Sym2
namespace MazurProof.N13IntegralInfinityVerticalGraphSpecialRestriction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
/-- The two-adic coefficient ring. -/
abbrev R₂ :=
  N13IntegralInfinityChart.R₂
/-- The special residue field. -/
abbrev K :=
  N13SpecialInfinityChart.K
end
end MazurProof.N13IntegralInfinityVerticalGraphSpecialRestriction
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityGraphSpecialRestriction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralInfinityGraphSpecialRestriction =====
section
/-!
# Special restriction of integral infinity graph divisors

A bounded monic quadratic graph on the integral infinity chart has a
weighted-reflection closure on the affine chart.  Coefficient reduction
commutes with both graph generators and all three weighted reflections.

The reduced monic infinity polynomial splits over `F₂`.  Its four possible
unordered root patterns explicitly determine the reflected affine ideal:
roots at `t = 0` disappear from the affine chart, roots at `t = 1` become
the point `x = 1`, and a repeated `t = 1` root retains its multiplicity
through the characteristic-two tangent-ideal identity.  Consequently the
two reduced chart ideals are exactly the canonical chart pair of the
completed special root divisor.
-/
open Polynomial
open scoped Sym2
namespace MazurProof.N13IntegralInfinityGraphSpecialRestriction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13IntegralInfinityGraphSpecialRestriction
end

end

-- ===== FLT.Assumptions.MazurProof.N13IrreducibleQuadraticFinite =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IrreducibleQuadraticFinite =====
section
/-!
# Finiteness on the affine chart of an irreducible N13 quadratic

If the horizontal quadratic has integral affine coefficients, its monic
equation belongs to the canonical contraction.  The rank-two polynomial
normal form then makes the contracted quotient finite.  Vertical
saturation already makes the same quotient flat.

Combined with the proper-chart theorem, this leaves only the reciprocal
integral chart as the non-affine alternative.
-/
open Polynomial
namespace MazurProof.N13IrreducibleQuadraticFinite
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralModelContraction.R₂
abbrev Q₂ : Type :=
  N13IntegralModelContraction.Q₂
abbrev IntegralRing : Type :=
  N13IntegralModelContraction.IntegralRing
end
end MazurProof.N13IrreducibleQuadraticFinite
end

end

-- ===== FLT.Assumptions.MazurProof.N13IrreducibleQuadraticSpread =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IrreducibleQuadraticSpread =====
section
/-!
# Proper spreads for irreducible N13 quadratics

An irreducible quadratic Mumford graph lies in one of the two ordinary
proper charts.  In the finite branch, a monic equation in the finite
quotient patches the canonical affine contraction across the infinity
uniformizer.  In the escaping branch, the literal integral reciprocal
equation gives a horizontal or vertical infinity graph.  Both cases now
produce an invertible two-chart line with the exact generic graph ideal.
-/
open Polynomial
namespace MazurProof.N13IrreducibleQuadraticSpread
noncomputable section
abbrev R₂ : Type :=
  N13IntegralModelContraction.R₂
abbrev Q₂ : Type :=
  N13IntegralModelContraction.Q₂
end
end MazurProof.N13IrreducibleQuadraticSpread
end

end

-- ===== FLT.Assumptions.MazurProof.N13InfinityLineSpecialRestriction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InfinityLineSpecialRestriction =====
section
/-!
# Special restriction of the two N13 infinity point lines

The integral infinity-chart point ideal has generators
`t-t₀` and `v-v₀`.  Coefficientwise reduction therefore sends it exactly to
the corresponding special point ideal.  In particular, the positive
infinity line restricts to the sheet-zero point used as the special Abel
anchor.

This is an equality of both chart ideals, not merely an equality of their
images in the special Picard quotient.
-/
open Polynomial
namespace MazurProof.N13InfinityLineSpecialRestriction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13InfinityLineSpecialRestriction
end

end

-- ===== FLT.Assumptions.MazurProof.N13EscapingPointSpecialRestriction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13EscapingPointSpecialRestriction =====
section
/-!
# Special restriction of escaping affine N13 point lines

An affine point with negative two-adic horizontal valuation is integral on
the infinity chart.  Its inverse horizontal coordinate reduces to zero, so
the proper line specializes to one of the two points at infinity on the
special curve.

The infinity-chart equality is coefficientwise graph reduction.  On the
ordinary affine chart the cleared horizontal equation is `1-t₀x`; its
reduction is `1`, hence that chart ideal becomes the unit ideal.  Together
these are the exact two chart equalities required by the special-divisor
realization.
-/
open scoped Sym2
namespace MazurProof.N13EscapingPointSpecialRestriction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
/-- The two-adic coefficient field. -/
abbrev Q₂ : Type :=
  N13ProperCurveReduction.Q₂
end
end MazurProof.N13EscapingPointSpecialRestriction
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralAffinePointSpecialClass =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralAffinePointSpecialClass =====
section
/-!
# Special classes of integral affine N13 point lines

An integral point on the good two-adic affine chart has a literal monic graph
ideal and, by finite-support closure, an honest proper two-chart line.
Coefficientwise reduction sends that affine ideal exactly to the linear graph
of the reduced point on the special curve.

The special Abel model has degree two, so a reduced affine point is normalized
by adjoining the fixed positive-infinity anchor once.  This normalization is
kept explicit: the affine ideal alone cannot see it because the positive
infinity point line is trivial on the affine chart.
-/
open Polynomial
open scoped Sym2
namespace MazurProof.N13IntegralAffinePointSpecialClass
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
/-- The special affine coordinate ring. -/
abbrev SpecialRing : Type :=
  N13GeneralizedMumfordReduction.SpecialRing
end
end MazurProof.N13IntegralAffinePointSpecialClass
end

end

-- ===== FLT.Assumptions.MazurProof.N13FiniteAffinePointInfinityClosure =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FiniteAffinePointInfinityClosure =====
section
/-!
# Infinity closure of finite affine N13 point lines

For an integral affine point `(a,b)`, the same section on the infinity chart
is cut out by the weighted equations

`1 - a t = 0` and `v - b t³ = 0`.

The first equation makes `t` invertible modulo the weighted ideal, with
inverse `a`.  Hence the ideal is already saturated with respect to `t`;
contracting its extension from the overlap introduces no extra component.
This identifies the abstract `infinityClosure` with the explicit weighted
point ideal and makes its special reduction computable.
-/
open Polynomial
namespace MazurProof.N13FiniteAffinePointInfinityClosure
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13FiniteAffinePointInfinityClosure
end

end

-- ===== FLT.Assumptions.MazurProof.N13QuadraticTwoChartSpread =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13QuadraticTwoChartSpread =====
section
/-!
# Proper two-chart spreads for every quadratic N13 graph

Every two-adic affine point has a proper point line.  Integral points use the
finite-support closure of their monic affine graph, while nonintegral points
use the explicit infinity-chart line.  Tensoring two such point lines gives
proper spreads for split quadratic graphs, including the tangent
repeated-root case.

A monic quadratic is either split or irreducible.  Combining the point-line
tensor construction with the irreducible quadratic closure therefore gives
an honest proper two-chart line for every balanced quadratic Mumford graph.
-/
open Polynomial
namespace MazurProof.N13QuadraticTwoChartSpread
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13QuadraticTwoChartSpread
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralPointPicardRealization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralPointPicardRealization =====
section
/-!
# Picard realization of integral degree-one N13 points

An integral affine point has a proper two-chart closure whose two special
ideals are the canonical ideals of its coefficientwise reduction.  Adjoining
the positive-infinity line once places that point in the degree-two special
Abel model without changing its generic affine ideal.

The original point is affine, so its Mumford representative has `nInf = 0`.
Consequently the oriented generic exponent is `-1`, exactly as in the
escaping degree-one branch.
-/
open scoped nonZeroDivisors
namespace MazurProof.N13IntegralPointPicardRealization
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13IntegralPointPicardRealization
end

end

-- ===== FLT.Assumptions.MazurProof.N13EscapingPointPicardRealization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13EscapingPointPicardRealization =====
section
/-!
# Picard realization of escaping degree-one N13 points

An escaping affine point is integral on the ordinary infinity chart.  Its
proper point line reduces to the canonical reduced infinity point.  Tensoring
once with the positive-infinity point line supplies the second special point
required by the degree-two Abel model, while preserving the generic affine
ideal exactly.

The explicit oriented integer is `-1`: a degree-one affine Mumford point has
`nInf = 0`, and `SexticMumford.mumfordRaw` records `nInf - 1`.
-/
open scoped nonZeroDivisors
namespace MazurProof.N13EscapingPointPicardRealization
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13EscapingPointPicardRealization
end

end

-- ===== FLT.Assumptions.MazurProof.N13QuadraticTwoChartSpreadSaturation =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13QuadraticTwoChartSpreadSaturation =====
section
/-!
# Vertical saturation of split quadratic N13 spreads

The affine ideal of a two-chart line is invertible in the common function
field.  If two such ideals have no vertical scalar torsion, their product has
none either: multiply by the inverse of the first fractional ideal, cancel the
base scalar in the second ideal, and multiply the first ideal back.

Applying this cancellation theorem to the valuation-independent point-line
constructor proves vertical saturation of `pairLine`.  Coincident points are
allowed, so the result covers both split secants and repeated-root tangents.
-/
open scoped nonZeroDivisors
namespace MazurProof.N13QuadraticTwoChartSpreadSaturation
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type := N13IntegralModelContraction.R₂
abbrev A : Type := N13IntegralModelContraction.IntegralRing
end
end MazurProof.N13QuadraticTwoChartSpreadSaturation
end

end

-- ===== FLT.Assumptions.MazurProof.N13SplitQuadraticSpecialRestriction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SplitQuadraticSpecialRestriction =====
section
/-!
# Special restriction of split quadratic N13 lines

The valuation-independent point line chooses the ordinary affine closure for
an integral horizontal coordinate and the infinity-chart closure for an
escaping coordinate.  Both branches have already been identified with the
canonical chart pair of their reduced special point.

This file packages that case split once.  Tensoring the resulting point-line
equalities then identifies every split quadratic line, including a repeated
root, with the canonical chart pair of its literal degree-two special
divisor.  These are equalities of both chart ideals; no Picard orientation is
inferred from them.
-/
open scoped Sym2
namespace MazurProof.N13SplitQuadraticSpecialRestriction
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13SplitQuadraticSpecialRestriction
end

end

-- ===== FLT.Assumptions.MazurProof.N13SplitQuadraticPicardRealization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SplitQuadraticPicardRealization =====
section
/-!
# Picard realization of split quadratic N13 graphs

The split and repeated-root constructors already produce a proper line with
the exact generic quadratic Mumford ideal and the exact two chart ideals of a
literal special divisor.  Marking that line by the representative's oriented
exponent `nInf - 1` therefore fills every field of the two-fibre Picard
realization.

This file performs only that semantic packaging.  In particular, it does not
alter the vanishing-ideal convention or infer a divisor sign from support.
-/
namespace MazurProof.N13SplitQuadraticPicardRealization
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13SplitQuadraticPicardRealization
end

end

-- ===== FLT.Assumptions.MazurProof.N13QuadraticPicardRealization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13QuadraticPicardRealization =====
section
/-!
# Picard realization of every quadratic N13 graph

The finite irreducible branch now has a literal special divisor, while the
reciprocal branch is complete for both horizontal and vertical rank-two
recovery.  Combining those two cases gives complete two-fibre Picard data
for every irreducible quadratic Mumford representative.

A nonirreducible monic quadratic factors into two linear terms.  Distinct
roots use the existing secant realization and a repeated root uses the
existing tangent realization.  Thus every balanced quadratic representative
has exact generic raw data, its standard oriented generic Picard class, and
the canonical two-chart ideals of a literal effective special divisor.
-/
open Polynomial
namespace MazurProof.N13QuadraticPicardRealization
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13QuadraticPicardRealization
end

end

-- ===== FLT.Assumptions.MazurProof.N13InfinityPointPicardRealization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InfinityPointPicardRealization =====
section
/-!
# Picard realization of the two N13 infinity points

The positive infinity point is the Abel--Jacobi base point.  Two copies of
its proper point line therefore realize the identity class and reduce to the
doubled special anchor.  Tensoring the negative infinity line with the
positive anchor realizes the difference of the two infinity points and
retains both special sheets.

These are the two projective cases missing from the existing affine-point
realizations.  Both constructions use literal chart ideals and the standard
oriented Mumford representatives.
-/
open scoped Sym2
namespace MazurProof.N13InfinityPointPicardRealization
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
end
end MazurProof.N13InfinityPointPicardRealization
end

end

-- ===== FLT.Assumptions.MazurProof.N13EffectiveGraphData =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13EffectiveGraphData =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
New source candidate for FLT-C13-B00-EXIST r2. Lean checks: NOT RUN.

Actual chart constructions for an effective degree-two semirepresentative.
The degree-one negative marking uses the negative infinity point line; the
constant negative marking uses two copies of that line. A repaired quadratic
uses the residual graph, rather than the original balanced graph.

The raw/class conclusions below are proved from the displayed constructors.
Their generic formal-branch marking and integral-comparison theorems are
separate obligations, not consequences asserted from affine saturation.
-/
namespace MazurProof.N13EffectiveGraphData
noncomputable section
open Polynomial
open scoped Sym2
open N13TwoChartPicardRealization N13EffectiveInfinityRepair
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13EffectiveGraphData
end

end

-- ===== FLT.Assumptions.MazurProof.N13FormalInfinityBranches =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FormalInfinityBranches =====
section
/-!
# The two Hensel branches at infinity for N13

The formal-infinity equation

`v² + (1 + X² + X³)v - (X + X²) = 0`

reduces modulo `X` to `v(v + 1)`.  Both roots of the special fibre are
simple.  This file lifts the root `0` by X-adic Hensel, obtains the conjugate
root from the quadratic equation, and proves that their difference is a
unit.  These are the structural inputs for splitting the complete
infinity-chart algebra by two-point evaluation.
-/
open Polynomial
namespace MazurProof.N13FormalInfinityBranches
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13FormalInfinityChart.R₂
end
end MazurProof.N13FormalInfinityBranches
end

end

-- ===== FLT.Assumptions.MazurProof.N13FormalInfinitySplit =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FormalInfinitySplit =====
section
/-!
# Splitting the N13 formal infinity chart

The two Hensel roots of the formal-infinity equation differ by a unit.
Evaluation on those roots therefore identifies every function in the
quadratic chart with its values on the two disjoint branches.  Injectivity
uses the normal form `a + bv`; surjectivity is explicit two-point
interpolation.
-/
open Polynomial
namespace MazurProof.N13FormalInfinitySplit
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
open N13FormalInfinityBranches
end
end MazurProof.N13FormalInfinitySplit
end

end

-- ===== FLT.Assumptions.MazurProof.N13FormalOverlapSplit =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13FormalOverlapSplit =====
section
/-!
# Splitting the punctured N13 formal overlap

The two Hensel branches remain disjoint after passing from power series to
Laurent series.  Evaluation therefore splits the actual quadratic
punctured-overlap algebra as a product of two Laurent-series rings.  The
explicit interpolation inverse is compatible with restriction from the
complete formal-infinity chart.
-/
open Polynomial
namespace MazurProof.N13FormalOverlapSplit
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
open N13FormalInfinityBranches
end
end MazurProof.N13FormalOverlapSplit
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoInfinityRestriction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoInfinityRestriction =====
section
/-!
# Restriction of N13 fractional ideals to the two infinity branches

The two Laurent expansions at infinity combine into a faithful map from the
N13 function field to the product of the two branch fields.  Consequently an
affine fractional ideal restricts canonically to a fractional submodule of
that product.  This construction uses the ideal itself, rather than a chosen
global generator.
-/
open scoped LaurentSeries nonZeroDivisors
namespace MazurProof.N13TwoInfinityRestriction
noncomputable section
universe u
variable (K : Type u) [Field K] [CharZero K]
abbrev BranchPair : Type u :=
  LaurentSeries K × LaurentSeries K
end
end MazurProof.N13TwoInfinityRestriction
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoAdicInfinityCompatibility =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoAdicInfinityCompatibility =====
section
/-!
# Compatibility of the integral and rational N13 infinity branches

The two branches obtained by X-adic Hensel lifting over `ℤ₂` are the same
branches as the positive and negative Laurent expansions of the sextic
function field after extension to `ℚ₂`.  This identifies the integral
complete-chart lattices with the rational branch pair used to restrict
fractional ideals.
-/
open Polynomial
open scoped LaurentSeries PowerSeries
namespace MazurProof.N13TwoAdicInfinityCompatibility
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13TwoAdicCoordinateBaseChange.R₂
abbrev Q₂ : Type :=
  N13TwoAdicCoordinateBaseChange.Q₂
abbrev IntegralPower : Type :=
  PowerSeries R₂
abbrev IntegralLaurent : Type :=
  LaurentSeries R₂
abbrev RationalPower : Type :=
  PowerSeries Q₂
abbrev RationalLaurent : Type :=
  LaurentSeries Q₂
def coeffMap : R₂ →+* Q₂ :=
  N13TwoAdicCoordinateBaseChange.coeffMap
/-- Coefficientwise extension of integral power series. -/
def powerMap : IntegralPower →+* RationalPower :=
  PowerSeries.map coeffMap
@[simp] theorem powerMap_coeff
    (f : IntegralPower) (n : ℕ) :
    PowerSeries.coeff n (powerMap f) =
      coeffMap (PowerSeries.coeff n f) :=
  rfl
/-- Laurent monomials over `ℚ₂`. -/
def tPowQ (n : ℤ) : RationalLaurent :=
  HahnSeries.single n 1
@[simp] theorem tPowQ_zero :
    tPowQ 0 = 1 := rfl
def hInfinityQ : RationalLaurent :=
  tPowQ 0 + tPowQ 2 + tPowQ 3
def rhsInfinityQ : RationalLaurent :=
  tPowQ 1 + tPowQ 2
end
end MazurProof.N13TwoAdicInfinityCompatibility
end

end

-- ===== FLT.Assumptions.MazurProof.N13InverseInfinityData =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InverseInfinityData =====
section
/-!
# Special divisor of the nInf = 2 degree-zero witness

The split quadratic u = X(X+1), v = 1 has roots x = 0, -1 with good ordinates 0 and 1; its literal reduced
special divisor is s(zeroPlus, negOnePlus) = C + A (cf. N13CuspCARelation: AJ13 C + AJ13 A = -AJ13 T).
This corrects the D + B divisor guessed in ChatGPT answer Q8689.
-/
namespace MazurProof.N13InverseInfinityData
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
open N13SplitQuadraticSpecialRestriction
end
end MazurProof.N13InverseInfinityData
end

end

-- ===== FLT.Assumptions.MazurProof.N13CuspCARelation =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13CuspCARelation =====
section
set_option autoImplicit false
set_option relaxedAutoImplicit false
noncomputable section
open Polynomial
open scoped LaurentSeries nonZeroDivisors
namespace MazurProof.N13Arithmetic
/-- The cubic polynomial part of the positive infinity branch. -/
def s13 : ℚ[X] :=
  N13MumfordInfinityBalance.sqrtInfinity
def quarter13 : ℚ[X] :=
  Polynomial.C (1 / 4 : ℚ)
/-! ## Exact order at the positive infinity branch -/
/-! ## Pass the principal divisor to the oriented Picard quotient -/
end MazurProof.N13Arithmetic
end
end

end

-- ===== FLT.Assumptions.MazurProof.N13InverseInfinityWitness =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InverseInfinityWitness =====
section
/-!
# Candidate nInf = 2 witness: the cusp-pair line with generic infinity integer `-2`

The proper split-quadratic line through `x = 0, -1` (good ordinates `0, 1`) has literal special divisor
`s(zeroPlus, negOnePlus) = C + A` (`N13InverseInfinityData`).  We package it with generic infinity integer
`-2` (= nInf − 1 for the inverse-infinity orientation; the balanced datum `(X(X+1), 1, 0)` would give `-1`,
whose class is `2 •` the target, see `N13OppositeInfinityClass`).

Proved here: the special Abel class, and the exact one-step shift of the generic class
`genericClass L (k - 1) = genericClass L k + classOf (1,0,0)`, so that the generic class of the witness
equals `classOf D_CA - classOf (1,0,2)` whenever `D_CA` realizes the line's affine ideal.
-/
set_option autoImplicit false
set_option relaxedAutoImplicit false
noncomputable section
namespace MazurProof.N13InverseInfinityWitness
open N13SplitQuadraticSpecialRestriction MazurProof.N13InverseInfinityData
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end MazurProof.N13InverseInfinityWitness
end
end

end

-- ===== FLT.Assumptions.MazurProof.N13InverseInfinityWitnessClass =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InverseInfinityWitnessClass =====
section
/-!
# Generic class of the nInf = 2 witness

`inverseInfinityData` (cusp-pair line, generic infinity integer `-2`, special divisor `C + A`) has generic class
`classOf (1,0,2)` over `Q₂`: its raw datum is `raw C₂ * raw A₂`, and over `ℚ` `AJ13 C + AJ13 A = classOf (1,0,2)`.
-/
set_option autoImplicit false
set_option relaxedAutoImplicit false
noncomputable section
namespace MazurProof.N13InverseInfinityWitness
open Polynomial MazurProof.N13Arithmetic
local instance instFactPrimeOfNatNat_fLT_1 : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end MazurProof.N13InverseInfinityWitness
end
end

end

-- ===== FLT.Assumptions.MazurProof.N13InfinityChartMarking =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InfinityChartMarking =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
New source candidate for FLT-C13-B00-EXIST r2. Lean checks: NOT RUN.

Tie the infinity marking to the actual ordinary infinity ideal by extending
that ideal into the two generic formal branch rings. This reads the chart
ideal itself, not the separately stored integer. The two infinity sections
and their tensor products are certified here.
-/
namespace MazurProof.N13InfinityChartMarking
noncomputable section
open Polynomial
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev QP := N13TwoAdicInfinityCompatibility.RationalPower
end
end MazurProof.N13InfinityChartMarking
end

end

-- ===== FLT.Assumptions.MazurProof.N13OrdinaryCompletionCompatibility =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13OrdinaryCompletionCompatibility =====
section
/-!
# Compatibility of the ordinary and formal N13 overlaps

The ordinary infinity overlap is obtained by inverting `t`.  Composing the
ordinary infinity chart with its completion and the formal restriction sends
`t` to a Laurent unit, so the universal property of `Localization.Away`
gives a canonical map to the formal overlap.

This file proves that the resulting map agrees with both ordinary chart
restrictions.  No flatness, injectivity of completion, or algebraization
theorem is used.
-/
namespace MazurProof.N13OrdinaryCompletionCompatibility
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13IntegralInfinityChart.R₂
end
end MazurProof.N13OrdinaryCompletionCompatibility
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAffineRestrictionCompatibility =====
section
-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAffineRestrictionCompatibility =====
section
/-!
# Base-change compatibility of the N13 affine restriction

There are two ways to restrict an integral affine function to the two
rational branches at infinity:

1. restrict it to the integral punctured formal chart, split the two Hensel
   branches, and extend coefficients from `ℤ₂` to `ℚ₂`;
2. pass to the good generic fibre, complete the square to the sextic model,
   and use the positive and negative rational Laurent expansions.

This file proves that the resulting square commutes.  The proof checks the
two genuine affine generators `x` and `y`, with polynomial naturality
handling all functions of `x`.
-/
open Polynomial
open scoped LaurentSeries PowerSeries
namespace MazurProof.N13TwoAdicAffineRestrictionCompatibility
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13TwoAdicInfinityCompatibility.R₂
abbrev Q₂ : Type :=
  N13TwoAdicInfinityCompatibility.Q₂
abbrev IntegralLaurent : Type :=
  N13TwoAdicInfinityCompatibility.IntegralLaurent
abbrev RationalLaurent : Type :=
  N13TwoAdicInfinityCompatibility.RationalLaurent
abbrev IntegralRing : Type :=
  N13TwoAdicCoordinateBaseChange.IntegralRing
abbrev RationalBranchPair : Type :=
  RationalLaurent × RationalLaurent
def coeffMap : R₂ →+* Q₂ :=
  N13TwoAdicInfinityCompatibility.coeffMap
def tPowQ : ℤ → RationalLaurent :=
  N13TwoAdicInfinityCompatibility.tPowQ
abbrev IntegralBranchPair : Type :=
  IntegralLaurent × IntegralLaurent
end
end MazurProof.N13TwoAdicAffineRestrictionCompatibility
end

end

-- ===== FLT.Assumptions.MazurProof.N13OverlapBranchCompatibility =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13OverlapBranchCompatibility =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

The actual ordinary overlap has two faithful rational Laurent branch maps.
Their affine restrictions are the named function-field expansions; their
infinity restrictions are the inclusions of the named power-series maps.
Thus the primitive chart transport gives the SAME fraction on BOTH branches.
-/
namespace MazurProof.N13OverlapBranchCompatibility
noncomputable section
open scoped nonZeroDivisors LaurentSeries
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev Q₂ := N13TwoAdicInfinityCompatibility.Q₂
abbrev L := N13TwoAdicInfinityCompatibility.RationalLaurent
abbrev QP := N13TwoAdicInfinityCompatibility.RationalPower
end
end MazurProof.N13OverlapBranchCompatibility
end

end

-- ===== FLT.Assumptions.MazurProof.N13InvertibleReductionSaturation =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InvertibleReductionSaturation =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
New source candidate for the integral principal-comparison seam.
Lean compilation and axiom checks: NOT RUN.

An invertible ideal with nonzero image in a domain-valued reduction is
saturated by the generator of the reduction kernel. This is a genuine
descent lemma; it assumes no Picard comparison or specialization law.
-/
namespace MazurProof.N13InvertibleReductionSaturation
noncomputable section
open scoped nonZeroDivisors
section General
variable {A K S : Type*} [CommRing A] [IsDomain A] [Field K] [Algebra A K] [IsFractionRing A K] [CommRing S] [IsDomain S]
end General
section TwoAdic
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev R₂ := N13IntegralModelContraction.R₂
variable {A K S : Type*} [CommRing A] [IsDomain A] [Field K] [Algebra A K] [IsFractionRing A K] [Algebra R₂ A] [CommRing S] [IsDomain S]
end TwoAdic
section InfinityApplication
open Polynomial
open scoped Sym2
local instance instFactPrimeOfNatNat_fLT_1 : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end InfinityApplication
end
end MazurProof.N13InvertibleReductionSaturation
end

end

-- ===== FLT.Assumptions.MazurProof.N13PrimitiveVerticalPresentation =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13PrimitiveVerticalPresentation =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Mathlib pin: 96fd0fff3b8837985ae21dd02e712cb5df72ec05.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

Krull intersection gives an actual primitive factorization of every
nonzero integral chart function. A rational function therefore has a
numerator and denominator with nonzero reductions after removing the two
explicit vertical powers. Transport to the other chart remains separate.
-/
namespace MazurProof.N13PrimitiveVerticalPresentation
noncomputable section
open scoped nonZeroDivisors
variable {A S : Type*} [CommRing A] [IsDomain A] [IsNoetherianRing A] [CommRing S] [Nontrivial S]
variable {K : Type*} [Field K] [Algebra A K] [IsFractionRing A K]
section N13Charts
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end N13Charts
end
end MazurProof.N13PrimitiveVerticalPresentation
end

end

-- ===== FLT.Assumptions.MazurProof.N13PrincipalBranchIdeals =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13PrincipalBranchIdeals =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

Primitive presentations retain powers of two. These are Laurent-order-zero
scalars, so the SAME transported infinity numerator/denominator has the
prescribed difference of orders at both branches. Power-series division by
X^order turns the order equations into actual principal ideal equations.
-/
namespace MazurProof.N13PrincipalBranchIdeals
noncomputable section
open N13OverlapBranchCompatibility
open scoped nonZeroDivisors LaurentSeries
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
open N13InfinityChartMarking hiding QP
open N13EffectiveInfinityRepair
end
end MazurProof.N13PrincipalBranchIdeals
end

end

-- ===== FLT.Assumptions.MazurProof.N13PrimitiveAffineComparison =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13PrimitiveAffineComparison =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

A principal equality on the generic affine chart descends to the exact
primitive integral numerator/denominator equation. Powers of two removed
from a field presentation contribute unit ideals only on the generic fibre.
The integral descent uses proved saturation, not cancellation of integral
nonunits.
-/
namespace MazurProof.N13PrimitiveAffineComparison
noncomputable section
open N13OverlapBranchCompatibility N13PrincipalBranchIdeals
open N13TwoChartPicardRealization hiding Q₂
open N13InvertibleReductionSaturation
open scoped nonZeroDivisors
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev R₂ := N13IntegralModelContraction.R₂
end
end MazurProof.N13PrimitiveAffineComparison
end

end

-- ===== FLT.Assumptions.MazurProof.N13InfinityBranchJets =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InfinityBranchJets =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

Finite-jet geometry for the actual ordinary N13 infinity chart and its two
named Hensel branch maps. The two roots differ by a unit. Consequently both
branch jets vanish exactly when the ordinary element is divisible by t^n.
-/
namespace MazurProof.N13InfinityBranchJets
noncomputable section
open Polynomial
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev R₂ := N13IntegralInfinityChart.R₂
abbrev QP := N13TwoAdicInfinityCompatibility.RationalPower
end
end MazurProof.N13InfinityBranchJets
end

end

-- ===== FLT.Assumptions.MazurProof.N13InfinityBranchJetLift =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InfinityBranchJetLift =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

Lift arbitrary finite generic jets on BOTH actual N13 infinity branches.
The witness is an ordinary integral chart element after multiplying the
prescribed jet pair by one explicitly obtained nonzero two-adic scalar.
-/
namespace MazurProof.N13InfinityBranchJetLift
noncomputable section
open Polynomial N13InfinityBranchJets
open scoped nonZeroDivisors
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev Q₂ := N13TwoAdicInfinityCompatibility.Q₂
abbrev cMap := N13TwoAdicInfinityCompatibility.coeffMap
local instance instAlgebraPolynomialR₂Q₂ : Algebra R₂[X] Q₂[X] := Polynomial.algebra R₂ Q₂
local instance instIsLocalizationPolynomialR₂MapMonoidHomCNonZeroDivisorsQ₂ : IsLocalization
    ((nonZeroDivisors R₂).map (Polynomial.C : R₂ →+* R₂[X]).toMonoidHom) Q₂[X] :=
  Polynomial.isLocalization (nonZeroDivisors R₂) Q₂
end
end MazurProof.N13InfinityBranchJetLift
end

end

-- ===== FLT.Assumptions.MazurProof.N13InfinityIdealApproximation =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13InfinityIdealApproximation =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

Actual N13 two-branch ideal equality implies all-order approximation on the
ordinary infinity chart after clearing one nonzero vertical scalar. The
scalar is retained, not cancelled in the integral ring. This is the precise
input that becomes ordinary approximation after generic-fibre localization.
-/
namespace MazurProof.N13InfinityIdealApproximation
noncomputable section
open N13InfinityBranchJets N13InfinityBranchJetLift
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
def jetIdeal (n : ℕ) : Ideal QP := Ideal.span ({PowerSeries.X ^ n} : Set QP)
abbrev Jet (n : ℕ) := QP ⧸ jetIdeal n
abbrev JetPair (n : ℕ) := Jet n × Jet n
def jetQuot (n : ℕ) : QP →+* Jet n := Ideal.Quotient.mk (jetIdeal n)
end
end MazurProof.N13InfinityIdealApproximation
end

end

-- ===== FLT.Assumptions.MazurProof.N13GenericInfinityComparison =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GenericInfinityComparison =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

Actual two-branch equality now yields the required approximation predicates
on the generic ordinary infinity chart. The vertical scalars are cancelled
only after localizing them. Combined with the actual principal open D(t),
this proves generic infinity-ideal equality.
-/
namespace MazurProof.N13GenericInfinityComparison
noncomputable section
open N13InfinityBranchJets N13InfinityIdealApproximation
open scoped nonZeroDivisors
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13GenericInfinityComparison
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralPrincipalComparison =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralPrincipalComparison =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

Transport the proved integral affine equation to the actual ordinary
overlap, then use the two actual branch equations to descend the infinity
equation. The final comparison uses one common primitive fraction.
-/
namespace MazurProof.N13IntegralPrincipalComparison
noncomputable section
open N13OverlapBranchCompatibility N13PrincipalBranchIdeals
open N13TwoChartPicardRealization hiding Q₂
open N13GenericInfinityComparison
open N13InfinityChartMarking hiding QP
open N13EffectiveInfinityRepair
open scoped nonZeroDivisors
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13IntegralPrincipalComparison
end

end

-- ===== FLT.Assumptions.MazurProof.N13MarkedQuadraticExistence =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MarkedQuadraticExistence =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
New source candidate for FLT-C13-B00-EXIST r2. Lean checks: NOT RUN.

Retain the infinity-marking certificate on the same quadratic witness.
The case constructions are the pinned finite, split and reciprocal source
proofs, augmented by the actual branch-ideal proofs; no existing file changes.
This supplies no integral principal-comparison or global chooser theorem.
-/
namespace MazurProof.N13MarkedQuadraticExistence
noncomputable section
open Polynomial N13InfinityChartMarking
open N13SplitQuadraticPicardRealization N13SplitQuadraticSpecialRestriction
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev Q₂ := N13TwoChartPicardRealization.Q₂
end
end MazurProof.N13MarkedQuadraticExistence
end

end

-- ===== FLT.Assumptions.MazurProof.N13MarkedEffectiveData =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MarkedEffectiveData =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
New source candidate for FLT-C13-B00-EXIST r2. Lean checks: NOT RUN.

The explicit effective-chart constructors now retain actual generic
infinity multiplicities on their same witness. Integral principal extension
and global chooser compatibility are not proved here.
-/
namespace MazurProof.N13MarkedEffectiveData
noncomputable section
open Polynomial N13InfinityChartMarking
open N13TwoChartPicardRealization N13EffectiveInfinityRepair N13EffectiveGraphData
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13MarkedEffectiveData
end

end

-- ===== FLT.Assumptions.MazurProof.N13MarkedTensorComparison =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MarkedTensorComparison =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

For the actual marked effective data constructed in this series, equality
of the generic class sums produces an integral two-chart tensor comparison.
No integral comparison, global specialization, branch compatibility, or
special additive law is assumed.
-/
namespace MazurProof.N13MarkedTensorComparison
noncomputable section
open N13OverlapBranchCompatibility N13PrincipalBranchIdeals
open N13TwoChartPicardRealization hiding Q₂
open N13InfinityChartMarking hiding QP
open N13EffectiveInfinityRepair N13IntegralPrincipalComparison
open scoped nonZeroDivisors
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13MarkedTensorComparison
end

end

-- ===== FLT.Assumptions.MazurProof.N13EffectiveDataCompatibility =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13EffectiveDataCompatibility =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

The proved raw, effective, saturated, and actual-branch properties are
packaged together without adding a comparison assumption. Equal generic
classes of certified data give an integral comparison. Every rational class
has such data, and the resulting choice already has integral tensor
comparisons. The three exact calibrations and named-point compatibility are
the remaining GlobalExistenceTarget assembly.
-/
namespace MazurProof.N13EffectiveDataCompatibility
noncomputable section
open N13OverlapBranchCompatibility N13PrincipalBranchIdeals
open N13TwoChartPicardRealization hiding Q₂
open N13InfinityChartMarking hiding QP
open N13EffectiveInfinityRepair
open N13MarkedTensorComparison
open scoped nonZeroDivisors
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13EffectiveDataCompatibility
end

end

-- ===== FLT.Assumptions.MazurProof.N13RationalCurvePointPicardRealization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13RationalCurvePointPicardRealization =====
section
/-!
# Two-fibre Picard realization of every rational N13 curve point

The projective N13 curve has two infinity points and an affine chart.  The
two infinity points are realized by their integral chart lines.  An affine
rational point is first transported to the good two-adic model and then
realized by the integral or escaping point line according to the valuation
of its first coordinate.

The package below records both identifications needed for specialization:
its generic class is the rational Abel--Jacobi class after base change to
`ℚ₂`, and its special class is the anchored Abel class of the point's proper
reduction.  Thus this file proves pointwise existence of honest two-fibre
data; it does not postulate a specialization map on arbitrary Picard classes.
-/
namespace MazurProof.N13RationalCurvePointPicardRealization
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
/-!
## The two points at infinity

The chosen positive point at infinity is the Abel--Jacobi base point, whereas
the negative point contributes the distinguished infinity Mumford class.  The
existing integral chart lines realize these two classes and specialize to the
anchor and cusp, respectively.
-/
/-!
## Affine rational points

The sextic coordinates over `ℚ` are first sent to the good two-adic model by
the completion-of-the-square coordinate change.  The valuation of `x` then
selects one of the two proper integral chart constructions.  In either case we
compare the resulting degree-one Mumford representative componentwise with
the base change of the original rational point representative.
-/
/-!
## Literal generic ideals

The preceding constructions identify generic Picard classes.  Global spread
existence needs the stronger statement that the affine ideal itself is the
Mumford ideal obtained by coefficient extension.  The following two lemmas
expose that stronger invariant for the integral and escaping branches.
-/
/-!
## Relation-first spread lines

A spread line remembers the rational Picard class it represents in addition
to its two-fibre geometric realization.  This makes the eventual reduction
classifier a statement about equality of concrete specializations, while the
pointwise constructions above supply Abel--Jacobi compatibility directly.
-/
end
end MazurProof.N13RationalCurvePointPicardRealization
end

end

-- ===== FLT.Assumptions.MazurProof.N13PointDataCertificates =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13PointDataCertificates =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

The named point realizations carry the same effective raw/branch certificate
as the new arbitrary-class choices. This discharges point compatibility by
the proved integral comparison theorem, without changing any named point
data or its special divisor.
-/
namespace MazurProof.N13PointDataCertificates
noncomputable section
open Polynomial N13EffectiveDataCompatibility N13EffectiveInfinityRepair
open N13InfinityChartMarking hiding QP
open N13TwoChartPicardRealization
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13PointDataCertificates
end

end

-- ===== FLT.Assumptions.MazurProof.N13CalibratedChooser =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13CalibratedChooser =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled source candidate; all Lean and axiom checks NOT RUN.

Construct the exact calibrated Chooser from the actual marked effective
realizations and the proved integral comparisons. In particular the inverse
infinity value is the required existing C+A datum, with raw mark -2 and
actual branch multiplicities (0,0). GlobalExistenceTarget is unchanged.
-/
namespace MazurProof.N13CalibratedChooser
noncomputable section
open Polynomial N13EffectiveDataCompatibility N13EffectiveInfinityRepair
open N13InfinityChartMarking N13TwoChartPicardRealization N13PointDataCertificates
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13CalibratedChooser
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialInfinityBranchJets =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialInfinityBranchJets =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled B03 source candidate; all Lean and axiom checks NOT RUN.

The actual characteristic-two infinity chart has two power-series branches
obtained by reducing the integral Hensel roots. Both n-jets vanish exactly
on the principal ideal (t^n). This is special-fibre geometry, independent of
the unreviewed calibrated chooser and of the missing special-code theorem.
-/
namespace MazurProof.N13SpecialInfinityBranchJets
noncomputable section
open Polynomial
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev K := N13GoodModelTwo.F2
end
end MazurProof.N13SpecialInfinityBranchJets
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialComparisonFactorPair =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialComparisonFactorPair =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled B03 source candidate; all Lean and axiom checks NOT RUN.

Every degree-four special comparison supplies an actual affine factor pair
whose product is a monic polynomial of degree at most eight. The factors
represent the same numerator/denominator as the input comparison, after
clearing only the explicit rational-point fibre polynomials. This removes
arbitrary affine denominators without assuming a principal-code law.
-/
namespace MazurProof.N13SpecialComparisonFactorPair
noncomputable section
open Polynomial N13SpecialDivisorCharts
open scoped Sym2
abbrev xClass := N13GoodCoordinateRingTwo.xClass
end
end MazurProof.N13SpecialComparisonFactorPair
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialLaurentBranches =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialLaurentBranches =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled B03 source candidate; all Lean and axiom checks NOT RUN.

Actual Laurent expansions of the GOOD characteristic-two affine model.
The branch difference is h(x), not twice a square root. The resulting
two-infinity pole bound forces deg(A)<=d and deg(B)+3<=d for A+B*y.
-/
namespace MazurProof.N13SpecialLaurentBranches
noncomputable section
open Polynomial
open scoped LaurentSeries
abbrev K := N13GoodModelTwo.F2
abbrev R := N13GoodCoordinateRingTwo.CoordinateRing
abbrev L := LaurentSeries K
abbrev t := N13LaurentPolynomialOrder.parameter K
theorem t_ne_zero : t ≠ 0 := N13LaurentPolynomialOrder.parameter_ne_zero K
end
end MazurProof.N13SpecialLaurentBranches
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialSmallFunctionCertificate =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialSmallFunctionCertificate =====
section
/-!
Source pin: b07243d72093bec5686e15b1208cb50d000f3e8d.
Source-only repair of the certificate candidate from
4109ba77745784c1a9f8c4c7b304df4124bf5ac4. Lean and axiom checks NOT RUN.

Finite polynomial certificates for all 32 * 4 coefficient pairs in the
GOOD F2 model. Polynomial divisibility is never passed to a decision
procedure. The six local equations have explicit cofactors. Each of the
58 unsupported nonzero norms has an explicit factor coprime to both X
and X - 1; its two Bezout identities rule out support. The zero norm is
excluded separately. The 69 supported rows have explicit six-polynomial
normal forms and first-nonzero-coefficient certificates.

All public definition values and theorem statements are unchanged.
The link between these nine-jet orders and the six geometric local
orders is a separate theorem.
-/
namespace MazurProof.N13SpecialSmallFunctionCertificate
noncomputable section
open Polynomial
set_option maxRecDepth 200000
set_option maxHeartbeats 4000000
abbrev K := N13GoodModelTwo.F2
def jetZeroZero : K[X] := X ^ 4 + X ^ 7
def jetZeroOne : K[X] := 1 + X + X ^ 3 + X ^ 4 + X ^ 7
def jetOneZero : K[X] := X + X ^ 2 + X ^ 3 + X ^ 4 + X ^ 5 + X ^ 6 + X ^ 8
def jetOneOne : K[X] := 1 + X + X ^ 4 + X ^ 5 + X ^ 6 + X ^ 8
def jetInfinityZero : K[X] := X + X ^ 3 + X ^ 4 + X ^ 5 + X ^ 6 + X ^ 8
def jetInfinityOne : K[X] := 1 + X + X ^ 2 + X ^ 4 + X ^ 5 + X ^ 6 + X ^ 8
/-- First nonzero coefficient among 0,...,8; value9 means no such coefficient. -/
def jetOrder (p : K[X]) : ℕ :=
  (List.range 9).findIdx (fun n => decide (p.coeff n ≠ 0))
-- Coefficient bit codes (a, b) = (0, 0).
-- Coefficient bit codes (a, b) = (0, 1).
-- Coefficient bit codes (a, b) = (0, 2).
-- Coefficient bit codes (a, b) = (0, 3).
-- Coefficient bit codes (a, b) = (1, 0).
-- Coefficient bit codes (a, b) = (1, 1).
-- Coefficient bit codes (a, b) = (1, 2).
-- Coefficient bit codes (a, b) = (1, 3).
-- Coefficient bit codes (a, b) = (2, 0).
-- Coefficient bit codes (a, b) = (2, 1).
-- Coefficient bit codes (a, b) = (2, 2).
-- Coefficient bit codes (a, b) = (2, 3).
-- Coefficient bit codes (a, b) = (3, 0).
-- Coefficient bit codes (a, b) = (3, 1).
-- Coefficient bit codes (a, b) = (3, 2).
-- Coefficient bit codes (a, b) = (3, 3).
-- Coefficient bit codes (a, b) = (4, 0).
-- Coefficient bit codes (a, b) = (4, 1).
-- Coefficient bit codes (a, b) = (4, 2).
-- Coefficient bit codes (a, b) = (4, 3).
-- Coefficient bit codes (a, b) = (5, 0).
-- Coefficient bit codes (a, b) = (5, 1).
-- Coefficient bit codes (a, b) = (5, 2).
-- Coefficient bit codes (a, b) = (5, 3).
-- Coefficient bit codes (a, b) = (6, 0).
-- Coefficient bit codes (a, b) = (6, 1).
-- Coefficient bit codes (a, b) = (6, 2).
-- Coefficient bit codes (a, b) = (6, 3).
-- Coefficient bit codes (a, b) = (7, 0).
-- Coefficient bit codes (a, b) = (7, 1).
-- Coefficient bit codes (a, b) = (7, 2).
-- Coefficient bit codes (a, b) = (7, 3).
-- Coefficient bit codes (a, b) = (8, 0).
-- Coefficient bit codes (a, b) = (8, 1).
-- Coefficient bit codes (a, b) = (8, 2).
-- Coefficient bit codes (a, b) = (8, 3).
-- Coefficient bit codes (a, b) = (9, 0).
-- Coefficient bit codes (a, b) = (9, 1).
-- Coefficient bit codes (a, b) = (9, 2).
-- Coefficient bit codes (a, b) = (9, 3).
-- Coefficient bit codes (a, b) = (10, 0).
-- Coefficient bit codes (a, b) = (10, 1).
-- Coefficient bit codes (a, b) = (10, 2).
-- Coefficient bit codes (a, b) = (10, 3).
-- Coefficient bit codes (a, b) = (11, 0).
-- Coefficient bit codes (a, b) = (11, 1).
-- Coefficient bit codes (a, b) = (11, 2).
-- Coefficient bit codes (a, b) = (11, 3).
-- Coefficient bit codes (a, b) = (12, 0).
-- Coefficient bit codes (a, b) = (12, 1).
-- Coefficient bit codes (a, b) = (12, 2).
-- Coefficient bit codes (a, b) = (12, 3).
-- Coefficient bit codes (a, b) = (13, 0).
-- Coefficient bit codes (a, b) = (13, 1).
-- Coefficient bit codes (a, b) = (13, 2).
-- Coefficient bit codes (a, b) = (13, 3).
-- Coefficient bit codes (a, b) = (14, 0).
-- Coefficient bit codes (a, b) = (14, 1).
-- Coefficient bit codes (a, b) = (14, 2).
-- Coefficient bit codes (a, b) = (14, 3).
-- Coefficient bit codes (a, b) = (15, 0).
-- Coefficient bit codes (a, b) = (15, 1).
-- Coefficient bit codes (a, b) = (15, 2).
-- Coefficient bit codes (a, b) = (15, 3).
-- Coefficient bit codes (a, b) = (16, 0).
-- Coefficient bit codes (a, b) = (16, 1).
-- Coefficient bit codes (a, b) = (16, 2).
-- Coefficient bit codes (a, b) = (16, 3).
-- Coefficient bit codes (a, b) = (17, 0).
-- Coefficient bit codes (a, b) = (17, 1).
-- Coefficient bit codes (a, b) = (17, 2).
-- Coefficient bit codes (a, b) = (17, 3).
-- Coefficient bit codes (a, b) = (18, 0).
-- Coefficient bit codes (a, b) = (18, 1).
-- Coefficient bit codes (a, b) = (18, 2).
-- Coefficient bit codes (a, b) = (18, 3).
-- Coefficient bit codes (a, b) = (19, 0).
-- Coefficient bit codes (a, b) = (19, 1).
-- Coefficient bit codes (a, b) = (19, 2).
-- Coefficient bit codes (a, b) = (19, 3).
-- Coefficient bit codes (a, b) = (20, 0).
-- Coefficient bit codes (a, b) = (20, 1).
-- Coefficient bit codes (a, b) = (20, 2).
-- Coefficient bit codes (a, b) = (20, 3).
-- Coefficient bit codes (a, b) = (21, 0).
-- Coefficient bit codes (a, b) = (21, 1).
-- Coefficient bit codes (a, b) = (21, 2).
-- Coefficient bit codes (a, b) = (21, 3).
-- Coefficient bit codes (a, b) = (22, 0).
-- Coefficient bit codes (a, b) = (22, 1).
-- Coefficient bit codes (a, b) = (22, 2).
-- Coefficient bit codes (a, b) = (22, 3).
-- Coefficient bit codes (a, b) = (23, 0).
-- Coefficient bit codes (a, b) = (23, 1).
-- Coefficient bit codes (a, b) = (23, 2).
-- Coefficient bit codes (a, b) = (23, 3).
-- Coefficient bit codes (a, b) = (24, 0).
-- Coefficient bit codes (a, b) = (24, 1).
-- Coefficient bit codes (a, b) = (24, 2).
-- Coefficient bit codes (a, b) = (24, 3).
-- Coefficient bit codes (a, b) = (25, 0).
-- Coefficient bit codes (a, b) = (25, 1).
-- Coefficient bit codes (a, b) = (25, 2).
-- Coefficient bit codes (a, b) = (25, 3).
-- Coefficient bit codes (a, b) = (26, 0).
-- Coefficient bit codes (a, b) = (26, 1).
-- Coefficient bit codes (a, b) = (26, 2).
-- Coefficient bit codes (a, b) = (26, 3).
-- Coefficient bit codes (a, b) = (27, 0).
-- Coefficient bit codes (a, b) = (27, 1).
-- Coefficient bit codes (a, b) = (27, 2).
-- Coefficient bit codes (a, b) = (27, 3).
-- Coefficient bit codes (a, b) = (28, 0).
-- Coefficient bit codes (a, b) = (28, 1).
-- Coefficient bit codes (a, b) = (28, 2).
-- Coefficient bit codes (a, b) = (28, 3).
-- Coefficient bit codes (a, b) = (29, 0).
-- Coefficient bit codes (a, b) = (29, 1).
-- Coefficient bit codes (a, b) = (29, 2).
-- Coefficient bit codes (a, b) = (29, 3).
-- Coefficient bit codes (a, b) = (30, 0).
-- Coefficient bit codes (a, b) = (30, 1).
-- Coefficient bit codes (a, b) = (30, 2).
-- Coefficient bit codes (a, b) = (30, 3).
-- Coefficient bit codes (a, b) = (31, 0).
-- Coefficient bit codes (a, b) = (31, 1).
-- Coefficient bit codes (a, b) = (31, 2).
-- Coefficient bit codes (a, b) = (31, 3).
theorem binary (x : K) : x = 0 ∨ x = 1 := by
  revert x; decide
end
end MazurProof.N13SpecialSmallFunctionCertificate
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialFiniteBranchFaithfulness =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialFiniteBranchFaithfulness =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
Uncompiled B03 source candidate; all Lean and axiom checks NOT RUN.

The finite Hensel maps are faithful: their product is the translated
nonzero polynomial norm. Translation by a has an explicit inverse, so the
base-polynomial evaluation cannot kill a nonzero polynomial.
-/
namespace MazurProof.N13SpecialFiniteBranchFaithfulness
noncomputable section
open Polynomial N13SpecialInfinityBranchJets
abbrev R := N13GoodCoordinateRingTwo.CoordinateRing
end
end MazurProof.N13SpecialFiniteBranchFaithfulness
end

end

-- ===== FLT.Assumptions.MazurProof.N13SpecialAbelCode =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13SpecialAbelCode =====
section
open scoped Sym2
open MazurProof.N13AbelFiberTwoModel
open MazurProof.N13SymmetricSquareTwo
namespace MazurProof.N13SpecialAbelCode
noncomputable section
abbrev Code : Type :=
  ZMod 19
end
end MazurProof.N13SpecialAbelCode
end

end

-- ===== FLT.Assumptions.MazurProof.N13KernelInfinityMultiplicity =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13KernelInfinityMultiplicity =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K1. Source candidate; Lean and axiom checks NOT RUN.

The finite special divisor C+B forces both actual generic infinity orders
to vanish. The proof uses the integral branch constant coefficients and
the literal element t-1 in the reduced infinity ideal; it does not infer
generic marking from an independent integer attached to Data.
-/
namespace MazurProof.N13KernelInfinityMultiplicity
noncomputable section
open N13InfinityChartMarking
open N13EffectiveDataCompatibility N13EffectiveInfinityRepair
open N13TwoChartPicardRealization
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev SP := PowerSeries (ZMod 2)
end
end MazurProof.N13KernelInfinityMultiplicity
end

end

-- ===== FLT.Assumptions.MazurProof.N13MumfordFormalTransition =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MumfordFormalTransition =====
section
/-!
# The formal transition of a near-base N13 Mumford graph

The affine graph ideal of integral Mumford data contains its monic polynomial
`u(x)`.  On the punctured formal neighbourhood of infinity this polynomial
is a unit: after factoring its pole `t⁻ᵈ`, the remaining power series is the
reversal of `u`, whose constant coefficient is the leading coefficient `1`.

For data reducing to the selected base graph, the ratio between `u` and the
base polynomial is therefore a genuine unit of the integral quadratic formal
overlap.  Its coefficientwise reduction is one, so it supplies the actual
`NearIdentityTransition` required by the twisted Čech complex.  No Laurent
coefficient enumeration or global generator of the affine ideal is used.
-/
open Polynomial
open scoped LaurentSeries PowerSeries
namespace MazurProof.N13MumfordFormalTransition
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13FormalCurveOverlap.R₂
abbrev K : Type :=
  N13FormalLineBundleCech.K
/-! ## Reduction of polynomial restrictions -/
/-! ## The near-base transition -/
end
end MazurProof.N13MumfordFormalTransition
end

end

-- ===== FLT.Assumptions.MazurProof.N13MumfordFormalTransitionJet =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MumfordFormalTransitionJet =====
section
/-!
# First-order coordinates of the N13 formal Mumford transition

The transition of a two-disk Mumford graph is a quotient of two formal
polynomial units.  Multiplying its displacement from the identity by the
fixed base unit cancels the denominator exactly, leaving the finite Laurent
polynomial attached to `u - uBase`.

Its coefficients in degrees `-1` and `0` recover the two disk coordinates
up to the single quadratic term `x₀ * (x₁ + 1)`.  Thus the actual weighted
transition jet agrees with the Abel-chart coordinates modulo the square of
their coordinate ideal, without expanding an inverse power series.
-/
open Polynomial
namespace MazurProof.N13MumfordFormalTransitionJet
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  N13MumfordFormalTransition.R₂
end
end MazurProof.N13MumfordFormalTransitionJet
end

end

-- ===== FLT.Assumptions.MazurProof.N13CrossQuadraticPolynomial =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13CrossQuadraticPolynomial =====
section
/-!
# Cross-quadratic errors in two disjoint variable blocks

For a polynomial ring whose variables are split into a left and a right
block, the two coordinate-axis ideals have intersection equal to their
product.  Consequently a polynomial that vanishes on both axes has a
mixed factor.

The proof is by monomial support.  It is independent of N13 and performs no
coefficient expansion.
-/
namespace MazurProof.N13CrossQuadraticPolynomial
noncomputable section
open MvPolynomial
universe u
variable (R : Type u) [CommRing R]
abbrev Var : Type :=
  Sum (Fin 2) (Fin 2)
abbrev BiPoly : Type u :=
  MvPolynomial Var R
def leftIndices : Set Var :=
  Set.range Sum.inl
def rightIndices : Set Var :=
  Set.range Sum.inr
def leftIdeal : Ideal (BiPoly R) :=
  Ideal.span (X '' leftIndices)
def rightIdeal : Ideal (BiPoly R) :=
  Ideal.span (X '' rightIndices)
end
end MazurProof.N13CrossQuadraticPolynomial
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAbelChartLaw =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAbelChartLaw =====
section
/-!
# From a regular Abel law to the N13 two-adic kernel chart

The universal addition law is a polynomial in two disjoint coordinate
blocks.  If its restrictions to both axes are the identity, its nonlinear
error lies in the product of the two axis ideals.  Evaluation sends those
axis ideals into the coordinate ideals of the two input points, giving
exactly the error estimate required by `N13TwoAdicKernelChart.Chart`.

The final structure in this file records the remaining geometric seam:
kernel classes must be represented faithfully by the two Hensel disks and
their transported group law must be regular on this chart.
-/
namespace MazurProof.N13TwoAdicAbelChartLaw
noncomputable section
open MvPolynomial
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
abbrev R₂ : Type :=
  ℤ_[2]
abbrev BiPoly : Type :=
  N13CrossQuadraticPolynomial.BiPoly R₂
universe u
variable {K : Type u}
variable [AddCommGroup K]
namespace DoublingLaw
variable {coord : K → Fin 2 → R₂}
end DoublingLaw
namespace PolynomialLaw
variable {coord : K → Fin 2 → R₂}
end PolynomialLaw
namespace DoublingGeometricData
end DoublingGeometricData
namespace GeometricData
end GeometricData
end
end MazurProof.N13TwoAdicAbelChartLaw
end

end

-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAbelChartSection =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13TwoAdicAbelChartSection =====
section
/-!
# Recovering the N13 kernel chart from Picard representatives

The two-disk Abel map is already known to be injective in `J(ℚ₂)`.
Consequently a map from an additive group into `J(ℚ₂)`, together with a
two-disk representative for each of its elements, automatically gives the
correct base pair and an injective representative map.  Those facts should
not remain separate geometric hypotheses.

For a subgroup of the rational Picard group, coefficient extension
`J(ℚ) → J(ℚ₂)` is injective as well.  Thus the only inputs left for the
formal-kernel chart are existence of the two-disk representatives and the
regularity estimate for their transported addition law.
-/
namespace MazurProof.N13TwoAdicAbelChartSection
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
universe u
variable {K : Type u} [AddCommGroup K]
namespace DoublingData
end DoublingData
namespace Data
end Data
namespace RationalKernelDoublingData
end RationalKernelDoublingData
namespace RationalKernelData
end RationalKernelData
end
end MazurProof.N13TwoAdicAbelChartSection
end

end

-- ===== FLT.Assumptions.MazurProof.N13RationalKernelDoublingAdapter =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13RationalKernelDoublingAdapter =====
section
/-!
# N13 rational-kernel unary doubling adapter

The two-adic transition calculation already controls the tensor square of
one near-base line bundle to first order.  To turn that calculation into
separatedness for the actual rational reduction kernel, two geometric
producers remain:

* a centered near-base integral Mumford graph for every kernel class; and
* comparison, modulo the square of the moving coordinate ideal, between
  the chosen graph for `2 • z` and the square of the graph for `z`.

This file packages those producers and derives the exact
`RationalKernelDoublingData` consumed by the N13 endgame.  It introduces no
new assumption and keeps the remaining first-jet theorem explicit.
-/
namespace MazurProof.N13RationalKernelDoublingAdapter
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
universe u
/-! ## Recovering canonical disk pairs from kernel representatives -/
namespace NearBaseFamily
end NearBaseFamily
namespace MappedSpecialRepresentative
end MappedSpecialRepresentative
namespace MappedSpecialFamily
end MappedSpecialFamily
/-! ## Canonical mapped-special representatives -/
namespace CanonicalMappedSpecialFamily
end CanonicalMappedSpecialFamily
namespace NearBaseFamily
/-! ## Comparing a selected double with the squared transition -/
end NearBaseFamily
/-! ## The exact remaining unary compatibility -/
namespace FirstJetDoublingCompatibility
end FirstJetDoublingCompatibility
/-! ## One-call assembly from mapped-special representatives -/
namespace MappedSpecialFamily
end MappedSpecialFamily
namespace CanonicalMappedSpecialFamily
end CanonicalMappedSpecialFamily
/-! ## Specialization to the eventual spread classifier -/
namespace Concrete
variable {Line : Type u}
end Concrete
end
end MazurProof.N13RationalKernelDoublingAdapter
end

end

-- ===== FLT.Assumptions.MazurProof.N13KernelGraphContraction =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13KernelGraphContraction =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K1. Source candidate; Lean and axiom checks NOT RUN.

The finite C+B special divisor is the literal graph ideal (X²+X,Y).
Vertical saturation then identifies a certified affine lattice with the
canonical contraction of its same generic Mumford graph. These conclusions
retain the actual witness and do not use normal-form spread coherence.
-/
namespace MazurProof.N13KernelGraphContraction
noncomputable section
open Polynomial N13KernelInfinityMultiplicity
open N13TwoChartPicardRealization N13EffectiveGraphData N13EffectiveInfinityRepair
open scoped nonZeroDivisors
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev A := N13IntegralModelContraction.IntegralRing
end
end MazurProof.N13KernelGraphContraction
end

end

-- ===== FLT.Assumptions.MazurProof.N13KernelBasePic =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13KernelBasePic =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K1. Source candidate; Lean and axiom checks NOT RUN.

Both a finite effective quadratic and the fixed C+B divisor acquire the
same +1 raw infinity twist when their graph is balanced. Keeping this
twist explicit proves the adapter's exact centered class equality.
-/
namespace MazurProof.N13KernelBasePic
noncomputable section
open Polynomial N13KernelGraphContraction
open N13TwoChartPicardRealization N13EffectiveGraphData
open scoped nonZeroDivisors
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13KernelBasePic
end

end

-- ===== FLT.Assumptions.MazurProof.N13ConstructedMappedSpecialFamily =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13ConstructedMappedSpecialFamily =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K1. Source candidate; Lean and axiom checks NOT RUN.

Construct the adapter's exact MappedSpecialFamily for the actual additive
specialization kernel. No mapped-special, near-base, or compatibility
assumption is an input. FirstJetDoublingCompatibility remains separate.
-/
namespace MazurProof.N13ConstructedMappedSpecialFamily
noncomputable section
open N13KernelInfinityMultiplicity N13KernelGraphContraction
open N13KernelBasePic N13TwoChartPicardRealization N13EffectiveGraphData
open N13RationalKernelDoublingAdapter
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13ConstructedMappedSpecialFamily
end

end

-- ===== FLT.Assumptions.MazurProof.N13MumfordCenteredDoublingJet =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MumfordCenteredDoublingJet =====
section
/-!
# Denominator-free centered doubling jets for N13

Let `u_B = X² + X` be the fixed Abel-chart base polynomial and let `u_P`
be the monic quadratic of a disk pair.  The square of the centered transition
`u_P / u_B` has a canonical first-order monic normalization

`u_square = 2 * u_P - u_B`.

Cross-multiplication gives the exact error

`u_P² - u_B * u_square = (u_P - u_B)²`.

Thus its constant and linear deviations are the doubled disk coordinates
modulo the square of the moving coordinate ideal.  These identities are the
denominator-free polynomial core of the missing first-jet doubling theorem;
identifying the chosen representative of the doubled Picard class with this
normalization remains a separate step.
-/
open Polynomial
namespace MazurProof.N13MumfordCenteredDoublingJet
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
/-! ## A curve-compatible linearized double -/
/-! ## Quadratic Hensel expansions of the selected ordinates -/
/-! ## Reduction from cross-multiplied normalization to coordinate doubling -/
end
end MazurProof.N13MumfordCenteredDoublingJet
end

end

-- ===== FLT.Assumptions.MazurProof.N13MumfordCenteredDoublingAdapter =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13MumfordCenteredDoublingAdapter =====
section
/-!
# Cross-coefficient adapter for the N13 rational-kernel doubling law

For a recovered disk pair `P` and the pair `Q` selected for twice its Picard
class, the polynomial

`P.u² - uBase * Q.u`

measures failure of the proposed double to equal the centered square.  Only
its coefficients in degrees one and three are needed.  The centered
polynomial reducer turns those two quadratic memberships into literal disk
coordinate doubling, while the existing transition calculation identifies
the square transition with the same doubled coordinates.

This file performs that final subtraction.  It leaves the two
cross-coefficient memberships as the precise arithmetic input and introduces
no Picard-classification or separatedness assumption.
-/
namespace MazurProof.N13MumfordCenteredDoublingAdapter
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) :=
  ⟨Nat.prime_two⟩
open MazurProof.N13RationalKernelDoublingAdapter
namespace FirstJetDoublingCompatibility
end FirstJetDoublingCompatibility
end
end MazurProof.N13MumfordCenteredDoublingAdapter
end

end

-- ===== FLT.Assumptions.MazurProof.N13CenteredPrincipalNumerator =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13CenteredPrincipalNumerator =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

Extract the actual principal multiplier for the selected centered double,
with zero order on both infinity sheets. Clearing u(P)^2 gives a nonzero
regular numerator lying in BOTH the base/double ideal and the squared
conjugate ideal. The normalized Hermite numerator is not identified here.
-/
namespace MazurProof.N13CenteredPrincipalNumerator
noncomputable section
open SexticMumford
open scoped nonZeroDivisors
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev K := ℚ_[2]
end
end MazurProof.N13CenteredPrincipalNumerator
end

end

-- ===== FLT.Assumptions.MazurProof.N13CenteredNumeratorPoleBounds =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13CenteredNumeratorPoleBounds =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

The actual selected-double principal numerator has pole order exactly four
at both infinities. The existing two-branch minimum-order theorem therefore
forces its sextic polynomial coefficients into degrees at most four and
one. No small-numerator hypothesis is supplied by the caller.
-/
namespace MazurProof.N13CenteredNumeratorPoleBounds
noncomputable section
open Polynomial SexticMumford N13CenteredPrincipalNumerator
open scoped LaurentSeries nonZeroDivisors
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13CenteredNumeratorPoleBounds
end

end

-- ===== FLT.Assumptions.MazurProof.N13GoodCenteredNumerator =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GoodCenteredNumerator =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

Change the actual small principal numerator from the sextic coordinates to
the good model. Its membership in the SAME fixed base ideal forces the
polynomial part to be divisible by uBase. Thus the regular numerator has
the exact Hermite shape uBase*A+b*y, with deg A≤2 and deg b≤1 over Q2.
-/
namespace MazurProof.N13GoodCenteredNumerator
noncomputable section
open Polynomial SexticMumford N13CenteredPrincipalNumerator
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev Good := N13GoodSexticCoordinateEquiv.GoodRing (K := K)
abbrev gx := N13GeneralizedMumfordIntegral.xClass (R := K)
abbrev gy := N13GeneralizedMumfordIntegral.yClass (R := K)
end
end MazurProof.N13GoodCenteredNumerator
end

end

-- ===== FLT.Assumptions.MazurProof.N13GoodPointFirstJet =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13GoodPointFirstJet =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

An actual point and implicit tangent on the good quadratic curve define a
ring map to dual numbers. Squared graph-ideal membership therefore forces
both the value and first derivative of a regular function to vanish.
Only this direction is needed for the principal/Hermite matching step.
-/
namespace MazurProof.N13GoodPointFirstJet
noncomputable section
open Polynomial MulOpposite
universe u
variable {K : Type u} [Field K]
abbrev Dual (K : Type u) [Field K] := TrivSqZeroExt K K
abbrev Good (K : Type u) [Field K] := N13GeneralizedMumfordIntegral.CoordinateRing (R := K)
def polynomialJet (x : K) : K[X] →+* Dual K where
  toFun p := (p.eval x, p.derivative.eval x)
  map_zero' := by apply TrivSqZeroExt.ext <;> simp
  map_one' := by apply TrivSqZeroExt.ext <;> simp
  map_add' p q := by apply TrivSqZeroExt.ext <;> simp
  map_mul' p q := by
    apply TrivSqZeroExt.ext
    · simp
    · simp [derivative_mul, smul_eq_mul, op_smul_eq_smul]
      ring
section
variable (x y s : K)
variable (hc : y ^ 2 + (x ^ 3 + x + 1) * y - (x ^ 5 + x ^ 4) = 0)
variable (hd : (2 * y + (x ^ 3 + x + 1)) * s + (3 * x ^ 2 + 1) * y - (5 * x ^ 4 + 4 * x ^ 3) = 0)
end
end
end MazurProof.N13GoodPointFirstJet
end

end

-- ===== FLT.Assumptions.MazurProof.N13CenteredHermiteFirstOrder =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13CenteredHermiteFirstOrder =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

A concrete Hermite numerator calculation. If uBase*A+b*y vanishes twice
on the conjugates of an actual disk pair, where A is monic quadratic and
b is linear, its coefficients are forced to the centered-square values
modulo the moving coordinate ideal squared. Constructing such a normalized
numerator for the actual principal comparison remains a separate goal.
-/
namespace MazurProof.N13CenteredHermiteFirstOrder
noncomputable section
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev R₂ := ℤ_[2]
end
end MazurProof.N13CenteredHermiteFirstOrder
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralHermiteNumerator =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralHermiteNumerator =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

Construct the monic Hermite numerator directly over Z2. Its four linear
equations have an invertible residue matrix for every actual disk pair;
the tangent slopes need only be integral. This discharges existence of the
four equations used in CenteredHermiteFirstOrder. Identification with the
principal comparison and its residual divisor is a separate obligation.
-/
namespace MazurProof.N13IntegralHermiteNumerator
noncomputable section
open N13CenteredHermiteFirstOrder
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
def residueMatrix (s₀ s₁ : ZMod 2) : Matrix (Fin 4) (Fin 4) (ZMod 2) :=
  !![0, 0, 1, 0; 0, 0, 1, 1;
     1, 0, s₀, 1; 1, 1, s₁, 1 + s₁]
def residueInverse (s₀ s₁ : ZMod 2) : Matrix (Fin 4) (Fin 4) (ZMod 2) :=
  !![1 - s₀, -1, 1, 0; s₀, -s₁, -1, 1;
     1, 0, 0, 0; -1, 1, 0, 0]
end
end MazurProof.N13IntegralHermiteNumerator
end

end

-- ===== FLT.Assumptions.MazurProof.N13HermiteResidualDivisibility =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13HermiteResidualDivisibility =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

Use the actual implicit tangent slopes on the conjugate sheets. The
constructed numerator's norm has uBase as an explicit factor. Its residual
is divisible by u(P)^2 even when P shares an x-coordinate with the base
divisor: cancellation is by the unit conjugate ordinate, never by uBase(x).
-/
namespace MazurProof.N13HermiteResidualDivisibility
noncomputable section
open Polynomial N13CenteredHermiteFirstOrder
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13HermiteResidualDivisibility
end

end

-- ===== FLT.Assumptions.MazurProof.N13ActualHermiteEquations =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13ActualHermiteEquations =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

Transport the actual conjugate graph through completion of the square and
evaluate its squared ideal in the actual opposite-sheet dual-number jets.
This proves the four Hermite equations for the SAME principal numerator
already extracted from the selected centered double.
-/
namespace MazurProof.N13ActualHermiteEquations
noncomputable section
open Polynomial SexticMumford N13CenteredPrincipalNumerator N13GoodCenteredNumerator
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13ActualHermiteEquations
end

end

-- ===== FLT.Assumptions.MazurProof.N13RationalHermiteMatrix =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13RationalHermiteMatrix =====
section
/-!
Operative source pin: 940dc5a6b4062e8f591ddd744e4f3b8c2b562ea5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

The accepted integral interpolation matrix stays invertible over Q2.
Consequently every rational Hermite numerator with leading coefficient t
has its four remaining coefficients equal to t times one integral solution.
No division by a moving coordinate or by t occurs in this comparison.
-/
namespace MazurProof.N13RationalHermiteMatrix
noncomputable section
open N13CenteredPrincipalNumerator N13ActualHermiteEquations
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev R₂ := ℤ_[2]
end
end MazurProof.N13RationalHermiteMatrix
end

end

-- ===== FLT.Assumptions.MazurProof.N13PrincipalHermiteNormalization =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13PrincipalHermiteNormalization =====
section
/-!
Operative source pin: 940dc5a6b4062e8f591ddd744e4f3b8c2b562ea5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

Match the actual rational principal numerator to an integral normalized
Hermite numerator. The degree-two leading coefficient is proved nonzero
from the same numerator's nonvanishing, rather than assumed or inverted
without justification. The integral coefficients retain their I² bounds.
-/
namespace MazurProof.N13PrincipalHermiteNormalization
noncomputable section
open Polynomial SexticMumford N13CenteredPrincipalNumerator N13GoodCenteredNumerator
open N13ActualHermiteEquations N13RationalHermiteMatrix
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13PrincipalHermiteNormalization
end

end

-- ===== FLT.Assumptions.MazurProof.N13ActualPrincipalNorm =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13ActualPrincipalNorm =====
section
/-!
Operative source pin: 940dc5a6b4062e8f591ddd744e4f3b8c2b562ea5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

The actual affine principal relation determines the cleared numerator's
norm up to a nonzero scalar. This retains all four graph factors and then
translates that exact identity into the good-model Hermite shape.
-/
namespace MazurProof.N13ActualPrincipalNorm
noncomputable section
open Polynomial SexticMumford N13CenteredPrincipalNumerator N13GoodCenteredNumerator
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13ActualPrincipalNorm
end

end

-- ===== FLT.Assumptions.MazurProof.N13NormalizedHermiteResidual =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13NormalizedHermiteResidual =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

The residual produced by integral Hermite interpolation has unit leading
coefficient 1-b1, not necessarily leading coefficient 1. Divide by this
actual unit to construct a monic quadratic residual over Z2, retaining the
unit scale in the exact norm equation.
-/
namespace MazurProof.N13NormalizedHermiteResidual
noncomputable section
open Polynomial N13CenteredHermiteFirstOrder N13HermiteResidualDivisibility
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13NormalizedHermiteResidual
end

end

-- ===== FLT.Assumptions.MazurProof.N13CenteredNormFirstOrder =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13CenteredNormFirstOrder =====
section
/-!
Source pin: 887d29cd9eb9b60a6e5ec438ff919a74ccda41e5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

An exact comparison-numerator norm identity turns the Hermite calculation
into the required centered cross-coefficient congruences. Cancellation is
by monic polynomials over R/I², which can have zero divisors. The scalar in
the norm factorization is retained and its residue is proved to be one.
-/
namespace MazurProof.N13CenteredNormFirstOrder
noncomputable section
open Polynomial N13CenteredHermiteFirstOrder
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13CenteredNormFirstOrder
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralMatchedNorm =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralMatchedNorm =====
section
/-!
Operative source pin: 940dc5a6b4062e8f591ddd744e4f3b8c2b562ea5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

Descend the actual matched norm identity to Z2. Leading coefficients
determine the scalar exactly as 1-e1 after cancelling the nonzero rational
normalization scale squared. Coefficient injection then gives the literal
integral norm equation required by the accepted centered-norm theorem.
-/
namespace MazurProof.N13IntegralMatchedNorm
noncomputable section
open Polynomial N13CenteredPrincipalNumerator N13ActualHermiteEquations
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
abbrev R₂ := ℤ_[2]
end
end MazurProof.N13IntegralMatchedNorm
end

end

-- ===== FLT.Assumptions.MazurProof.N13IntegralHermiteCoefficientBounds =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13IntegralHermiteCoefficientBounds =====
section
/-!
Operative source pin: 940dc5a6b4062e8f591ddd744e4f3b8c2b562ea5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

Convert the four retained integral coefficient bounds to the literal
coefficientwise hypotheses of the accepted centered-norm theorem.
-/
namespace MazurProof.N13IntegralHermiteCoefficientBounds
noncomputable section
open Polynomial N13CenteredHermiteFirstOrder N13HermiteResidualDivisibility
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13IntegralHermiteCoefficientBounds
end

end

-- ===== FLT.Assumptions.MazurProof.N13ConstructedKernelDoubling =====
section
set_option backward.isDefEq.respectTransparency false
set_option backward.isDefEq.respectTransparency.types false
-- ===== FLT.Assumptions.MazurProof.N13ConstructedKernelDoubling =====
section
/-!
Operative source pin: 940dc5a6b4062e8f591ddd744e4f3b8c2b562ea5.
FLT-C13-KERNEL r1, K2. Source candidate; Lean and axiom checks NOT RUN.

Assemble the exact FirstJetDoublingCompatibility from the actual selected
principal multiplier. The SAME alpha and numerator are retained through
regularity, two-infinity bounds, good-model conversion, Hermite matching,
and exact integral norm descent. No compatibility or separatedness input
is added. Together with constructed K1 this gives actual-kernel separation.
-/
namespace MazurProof.N13ConstructedKernelDoubling
noncomputable section
open Polynomial SexticMumford N13CenteredPrincipalNumerator
open N13CenteredNumeratorPoleBounds N13GoodCenteredNumerator
open N13PrincipalHermiteNormalization N13ActualPrincipalNorm N13IntegralMatchedNorm
open N13IntegralHermiteCoefficientBounds
local instance instFactPrimeOfNatNat_fLT : Fact (Nat.Prime 2) := ⟨Nat.prime_two⟩
end
end MazurProof.N13ConstructedKernelDoubling
end

end
Source
Xiang Huang, FLT fork, https://github.com/xiangyazi24/FLT/blob/51bbb4f/FLT/Assumptions/MazurProof

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paper
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me