81 The Hodge Conjecture: Map, Computations and Proved Parts

81.1 The statement and the known cases

For a smooth complex projective variety \(X\), a class in \(H^{2p}(X,\mathbb Q)\cap H^{p,p}(X)\) is a Hodge class. The Hodge conjecture states that every Hodge class is a rational combination of classes of algebraic subvarieties. The file HODGE_MAP.md is the dependency graph; each node is proved (Lean), cited, measured, or remaining with its exact statement.

In degree \(2\) the conjecture holds with integer coefficients: the first Chern class maps the Picard group onto \(H^{1,1}\cap H^2(X,\mathbb Z)\) (Lefschetz). Hard Lefschetz carries codimension \(p\) to codimension \(n-p\), so the conjecture holds in degree \(2n-2\) and for every \(X\) of dimension at most \(3\). It holds for unirational and uniruled fourfolds and for cubic fourfolds [1783, 1806, 1823]; for generic abelian varieties, for powers of an elliptic curve, for simple abelian varieties of prime dimension [1802, 1810]; for abelian varieties of dimension at most \(5\) it reduces to Weil classes [1804], which Markman proved algebraic on Weil fourfolds of discriminant \(1\) [1800]; a 2025 preprint extends this to all abelian fourfolds [1801]. Hodge classes on abelian varieties are absolutely Hodge [1785], and the locus where a class stays Hodge in a family is algebraic [1771, 1777].

81.2 What a proof must avoid

With integer coefficients the statement is false: Atiyah and Hirzebruch found torsion Hodge classes that are not algebraic [1766], and Kollár found non-torsion ones on hypersurfaces in \(\mathbb P^4\) [1796]. On compact Kähler manifolds the statement with coherent sheaves in place of subvarieties is false [1821]. A proof has to use rational coefficients and the ample class; an argument that works for integral classes or for Kähler manifolds proves a false statement.

81.3 Fermat varieties (Lean and computation)

For \(X=X_m^n:\ x_0^m+\dots +x_{n+1}^m=0\) with \(n=2p\), the group \(\mu _m^{n+2}\) acts, and the primitive middle cohomology splits into lines \(V(a)\), one for each character \(a=(a_0,\dots ,a_{n+1})\) with \(a_i\not \equiv 0\) and \(\sum a_i\equiv 0\pmod m\). The line \(V(a)\) consists of Hodge classes exactly when \(\sum _i\langle ta_i\rangle =(p+1)m\) for every unit \(t\) modulo \(m\) [1809, 1812]. A character that splits into pairs \(\{b,-b\}\) comes from a linear subspace. paired_sum proves that such a character satisfies the Hodge condition, for every \(m\) and every dimension: after multiplication by a unit, each pair contributes residues \(x,y\) with \(0<x+y<2m\) and \(m\mid x+y\), so \(x+y=m\) (dv_between), and \(p+1\) pairs give \((p+1)m\). For small \((m,n)\) the numbers of characters, of Hodge characters and of paired Hodge characters are computed in Lean (count_*): the quartic surface has \(21\) characters, \(19\) of them Hodge and all paired (Picard number \(20\)); the sextic surface has \(85\) Hodge characters of which \(61\) are paired.

numeric_hodge.py extends the count to \(n=2\), \(m\le 40\); \(n=4\), \(m\le 24\); \(n=6\), \(m\le 12\) (Kamiak). The number of characters agrees with \(((m-1)^{n+2}+(m-1))/m\) in every case, and the Hodge numbers of the primitive part reproduce the known ones (quartic surface \(1,19,1\); cubic fourfold \(0,1,20,1,0\)). For each Hodge character the program decides whether it splits into pairs, into Hodge blocks of smaller even-dimensional Fermat varieties (the inductive structure of [1812]), and into such blocks when the characters \((a,a+\frac m2,-2a,\frac m2)\) and \((a,a+\frac m3,a+\frac {2m}3,-3a)\), the shapes of the standard characters of Aoki and Shioda [1768], are added. Every Hodge character is reached when \(m\) is prime, as Ran proved [1809], and also for \(m=4,6,8,9,25,27,33,35,39\) on surfaces and \(m=3,4,9\) in dimensions \(4\) and \(6\). The characters not reached (EXC in NUMERIC_HODGE.txt) appear for the other composite degrees, first at \(m=10\) on surfaces and \(m=6\) in dimensions \(4\) and \(6\). On surfaces they are algebraic by Lefschetz; in higher dimension they are algebraic by Shioda’s condition for \(m\le 20\) and its computer check for \(m=21,27\) [1812, 1824]. For \((m,n)=(22,4)\) and \((24,4)\) the cited results do not cover them.

81.4 Products of elliptic curves (computation)

On \(E^n\) the Hodge classes are the invariants of the Hodge group: \(\mathrm {SL}_2\) acting diagonally on \(H^1(E)^{\oplus n}\) when \(E\) has no complex multiplication, the circle of the complex multiplication when it has. numeric_hodge.py computes these invariants in \(\Lambda ^{2k}\) by exact rational linear algebra and compares them with the span of \(k\)-fold products of divisor classes. For \(n\le 4\) and every \(k\) the two dimensions agree: \(\binom {n}{k}^2\) with complex multiplication (\(16,36,16\) for \(n=4\)), and \(1,10,20,10,1\) for \(n=4\) without. Products of divisors are algebraic, so the conjecture holds on these \(E^n\) by explicit cycles, as Tate and Murasaki proved for all \(n\) [1805].

81.5 What remains

The Hodge locus is algebraic, but algebraicity of the class along it is the variational Hodge conjecture, open (variational); Hodge classes are absolutely Hodge only for abelian varieties (absolute_hodge); and the conjecture itself is open in general, among abelian varieties from dimension \(6\) on (hodge). The atypical part of the Hodge locus lies in finitely many special families [1772].

81.6 Fermat characters for prime degree: Hodge equals symmetric

Let \(m\) be a prime with \(3\le m<100\) and let \(a=(a_0,\dots ,a_{n+1})\), \(1\le a_i\le m-1\), be a character of the Fermat variety \(X_m^n\) with \(\sum a_i\equiv 0\). Then

\[ \sum _i\Bigl \langle \frac {ta_i}m\Bigr \rangle =\frac {n+2}2\quad \text {for all }t\in (\mathbb Z/m)^\times \qquad \Longleftrightarrow \qquad \#\{i:a_i=b\}=\#\{i:a_i=m-b\}\ \text { for all } b , \]
so every Hodge character is a sum of pairs \((b,m-b)\), i.e. of classes of linear subspaces.
\begin{align*} &H_t(a)=\textstyle \sum _{b=1}^{m-1}\mathrm {cnt}_b(a)\,\langle tb\rangle _m &&\text {(regroup by value)}\\ &\textstyle \sum _t\ell _t\,\bigl (2\langle tb\rangle _m-m\bigr )=D\,\delta _{b,b_0}\ \ (1\le b\le \frac {m-1}2) &&\text {(certificate, checked by rfl)}\\ &\mathrm {cnt}_{b_0}(a)-\mathrm {cnt}_{m-b_0}(a)=0 &&\text {(apply the certificate to the Hodge equations)} \end{align*}

The converse is HodgeCounts.sym_hodge. The certificates exist because the matrix \((2\langle tb\rangle -m)\) has full rank, which is \(h^-_m\ne 0\).

Listing 225: hodge/FermatFull.lean

hodge/FermatFull.lean

/-
  hodge/FermatFull.lean — T41 cycle 6: from Shioda's condition on a character to "paired",
  directly on the list of exponents, for m = 3, 5, 7, 11, 13 and every dimension.

  Lean 4 core plus hodge/FermatPrime (sum_scale, sum_indicator, rdistrib, dot, lsum, S, ind,
  allBelow, all_range, nthD, pos, negp, units, and_left/right, beq_eq, cancel_l).

  A character of X_m^n is a list a of exponents in 1..m−1 (length n + 2, sum ≡ 0). Shioda's
  condition at a unit t, with Σ_i 1 = n + 2 = 2(n/2 + 1), reads
      Σ_i 2⟨t a_i⟩ = Σ_i m                                            (H_t)
  Writing x_c = #{i : a_i = c + 1} (c < m − 1), H_t is the linear equation q_t · x = m · x with
  q_t(c) = 2⟨t(c+1)⟩ (regroup). Weighted sums of the H_t give S·x = S'·x (combine1); a certificate
  S + D e_{b'} = S' + D e_b (b' = m − 2 − b, the index of the residue m − (b+1)) gives x_b = x_{b'}
  (extract1). The certificates are those of FermatPrime (ℓᵀA = D(e_b − e_{b'}) for the full matrix
  A_{tv} = 2⟨tv⟩ − m), checked here by rfl.

    regroup               Σ_i g(a_i) = Σ_{c<M} x_c g(c+1) for entries in 1..M
    combine1, extract1    the linear algebra in ℕ
    paired_char_3 … paired_char_13
                          every list a with entries in 1..m−1 satisfying H_t for all units t has
                          #{a_i = b+1} = #{a_i = m−(b+1)} for b < (m−1)/2: every Hodge character
                          of every Fermat variety X_m^n (m = 3, 5, 7, 11, 13, every even n) is paired,
                          i.e. its Hodge class is a combination of classes of linear subspaces
                          (with HodgeChain.paired_sum for the converse).
-/
import hodge.FermatPrime

namespace FermatFull
open FTAChain FrobChain FermatPrime

/-! ## Counting -/

/-- #{i : a_i = v}. -/
def cnt (v : Nat) : List Nat → Nat
  | [] => 0
  | x :: a => ind x 1 v + cnt v a

def lsumL (g : Nat → Nat) : List Nat → Nat
  | [] => 0
  | x :: a => g x + lsumL g a

def AllIn (M : Nat) : List Nat → Prop
  | [] => True
  | x :: a => (0 < x ∧ x ≤ M) ∧ AllIn M a

theorem sum_zero'' : ∀ n, sumTo n (fun _ => 0) = 0
  | 0 => rfl
  | n + 1 => by show sumTo n (fun _ => 0) + 0 = 0; rw [sum_zero'' n]

/-- Regrouping a sum over the list by values. -/
theorem regroup (M : Nat) (g : Nat → Nat) : ∀ a : List Nat, AllIn M a →
    lsumL g a = sumTo M (fun c => cnt (c + 1) a * g (c + 1))
  | [], _ => by
    show 0 = sumTo M (fun c => 0 * g (c + 1))
    rw [sum_ext _ _ (fun _ => 0) (fun c _ => Nat.zero_mul _), sum_zero'']
  | x :: a, h => by
    show g x + lsumL g a = sumTo M (fun c => (ind x 1 (c + 1) + cnt (c + 1) a) * g (c + 1))
    rw [sum_ext _ _ _ (fun c _ => rdistrib _ _ _), sum_add, ← regroup M g a h.2]
    cases x with
    | zero => exact absurd h.1.1 (Nat.lt_irrefl 0)
    | succ j =>
      have e : ∀ c, ind (j + 1) 1 (c + 1) * g (c + 1) = ind j 1 c * g (c + 1) := by
        intro c
        unfold ind
        cases Nat.decEq c j with
        | isTrue hc => rw [hc, ite_eq_left rfl, ite_eq_left rfl]
        | isFalse hc =>
          rw [ite_eq_right (fun e => hc (Nat.succ.inj e)), ite_eq_right hc]
      rw [sum_ext _ _ _ (fun c _ => e c), sum_indicator j 1 (fun c => g (c + 1)) M h.1.2, Nat.one_mul]

/-! ## One-sided linear algebra -/

def S1 (T : List Nat) (lam mu : Nat → Nat) (q r : Nat → Nat → Nat) (c : Nat) : Nat :=
  lsum T (fun t => lam t * q t c + mu t * r t c)

theorem combine1 (M : Nat) (q r : Nat → Nat → Nat) (x lam mu : Nat → Nat) : ∀ T : List Nat,
    (∀ t, t ∈ T → dot M (q t) x = dot M (r t) x) →
    dot M (S1 T lam mu q r) x = dot M (S1 T lam mu r q) x
  | [] => fun _ => rfl
  | t :: T => fun h => by
    have ih := combine1 M q r x lam mu T (fun t' ht' => h t' (List.Mem.tail t ht'))
    have ht := h t (List.Mem.head T)
    unfold S1 at ih ⊢
    rw [dot_lsum, dot_lsum] at ih ⊢
    show dot M (fun c => lam t * q t c + mu t * r t c) x + lsum T (fun t => dot M (fun c => lam t * q t c + mu t * r t c) x)
      = dot M (fun c => lam t * r t c + mu t * q t c) x + lsum T (fun t => dot M (fun c => lam t * r t c + mu t * q t c) x)
    rw [dot_add_scale, dot_add_scale, ih, ht]

theorem extract1 (M b b' D : Nat) (hb : b < M) (hb' : b' < M) (hD : 0 < D) (s s' x : Nat → Nat)
    (hs : ∀ c, c < M → s c + ind b' D c = s' c + ind b D c)
    (h : dot M s x = dot M s' x) : x b = x b' := by
  have e1 : dot M s x + D * x b' = dot M s' x + D * x b := by
    unfold dot
    rw [← sum_indicator b' D x M hb', ← sum_indicator b D x M hb, ← sum_add, ← sum_add]
    exact sum_ext _ _ _ (fun c hc => by rw [← rdistrib, ← rdistrib, hs c hc])
  rw [h] at e1
  exact (Nat.eq_of_mul_eq_mul_left hD (cancel_l e1)).symm

/-! ## Instances -/

def qf (m t c : Nat) : Nat := 2 * (t * (c + 1) % m)
def rf (m _ _ : Nat) : Nat := m

def certF (m b D : Nat) (l : List Int) : Bool :=
  allBelow (fun c =>
    Nat.beq (S1 (units m) (fun t => pos (nthD l (t - 1))) (fun t => negp (nthD l (t - 1))) (qf m) (rf m) c
        + ind (m - 2 - b) D c)
      (S1 (units m) (fun t => pos (nthD l (t - 1))) (fun t => negp (nthD l (t - 1))) (rf m) (qf m) c
        + ind b D c)) (m - 1)

def HodgeList (m : Nat) (a : List Nat) : Prop :=
  ∀ t, t ∈ units m → lsumL (fun i => 2 * (t * i % m)) a = lsumL (fun _ => m) a

theorem pair_one (m b D : Nat) (l : List Int) (hb : b < m - 1) (hb' : m - 2 - b < m - 1) (hD : 0 < D)
    (hc : certF m b D l = true) (a : List Nat) (hin : AllIn (m - 1) a) (h : HodgeList m a) :
    cnt (b + 1) a = cnt (m - 2 - b + 1) a := by
  let x : Nat → Nat := fun c => cnt (c + 1) a
  have hx : ∀ t, t ∈ units m → dot (m - 1) (qf m t) x = dot (m - 1) (rf m t) x := by
    intro t ht
    have e := h t ht
    rw [regroup (m - 1) _ a hin, regroup (m - 1) _ a hin] at e
    unfold dot
    rw [sum_ext _ _ _ (fun c _ => nmul_comm (qf m t c) (x c)),
      sum_ext _ _ _ (fun c _ => nmul_comm (rf m t c) (x c))]
    exact e
  exact extract1 (m - 1) b (m - 2 - b) D hb hb' hD _ _ x
    (fun c hcM => beq_eq (all_range _ (m - 1) hc c hcM))
    (combine1 (m - 1) (qf m) (rf m) x _ _ (units m) hx)

theorem certF3_0 : certF 3 0 1 [-1, 0] = true := rfl

/-- X_3^n, every n: a Hodge character is paired. -/
theorem paired_char_3 (a : List Nat) (hin : AllIn 2 a) (h : HodgeList 3 a) :
    cnt 1 a = cnt 2 a :=
  pair_one 3 0 1 [-1, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF3_0 a hin h

theorem certF5_0 : certF 5 0 10 [-3, -1, 0, 0] = true := rfl
theorem certF5_1 : certF 5 1 10 [-1, 3, 0, 0] = true := rfl

/-- X_5^n, every n: a Hodge character is paired. -/
theorem paired_char_5 (a : List Nat) (hin : AllIn 4 a) (h : HodgeList 5 a) :
    cnt 1 a = cnt 4 a ∧ cnt 2 a = cnt 3 a :=
  ⟨pair_one 5 0 10 [-3, -1, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF5_0 a hin h,
   pair_one 5 1 10 [-1, 3, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF5_1 a hin h⟩

theorem certF7_0 : certF 7 0 14 [-2, -1, -1, 0, 0, 0] = true := rfl
theorem certF7_1 : certF 7 1 14 [-1, 1, 2, 0, 0, 0] = true := rfl
theorem certF7_2 : certF 7 2 14 [-1, 2, -1, 0, 0, 0] = true := rfl

/-- X_7^n, every n: a Hodge character is paired. -/
theorem paired_char_7 (a : List Nat) (hin : AllIn 6 a) (h : HodgeList 7 a) :
    cnt 1 a = cnt 6 a ∧ cnt 2 a = cnt 5 a ∧ cnt 3 a = cnt 4 a :=
  ⟨pair_one 7 0 14 [-2, -1, -1, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF7_0 a hin h,
   pair_one 7 1 14 [-1, 1, 2, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF7_1 a hin h,
   pair_one 7 2 14 [-1, 2, -1, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF7_2 a hin h⟩

theorem certF11_0 : certF 11 0 22 [-1, -1, -1, 0, -1, 0, 0, 0, 0, 0] = true := rfl
theorem certF11_1 : certF 11 1 22 [-1, 0, 1, 1, 1, 0, 0, 0, 0, 0] = true := rfl
theorem certF11_2 : certF 11 2 22 [-1, 1, 1, -1, 0, 0, 0, 0, 0, 0] = true := rfl
theorem certF11_3 : certF 11 3 22 [0, 1, -1, -1, 1, 0, 0, 0, 0, 0] = true := rfl
theorem certF11_4 : certF 11 4 22 [-1, 1, 0, 1, -1, 0, 0, 0, 0, 0] = true := rfl

/-- X_11^n, every n: a Hodge character is paired. -/
theorem paired_char_11 (a : List Nat) (hin : AllIn 10 a) (h : HodgeList 11 a) :
    cnt 1 a = cnt 10 a ∧ cnt 2 a = cnt 9 a ∧ cnt 3 a = cnt 8 a ∧ cnt 4 a = cnt 7 a ∧ cnt 5 a = cnt 6 a :=
  ⟨pair_one 11 0 22 [-1, -1, -1, 0, -1, 0, 0, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF11_0 a hin h,
   pair_one 11 1 22 [-1, 0, 1, 1, 1, 0, 0, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF11_1 a hin h,
   pair_one 11 2 22 [-1, 1, 1, -1, 0, 0, 0, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF11_2 a hin h,
   pair_one 11 3 22 [0, 1, -1, -1, 1, 0, 0, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF11_3 a hin h,
   pair_one 11 4 22 [-1, 1, 0, 1, -1, 0, 0, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF11_4 a hin h⟩

theorem certF13_0 : certF 13 0 26 [-1, 0, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0] = true := rfl
theorem certF13_1 : certF 13 1 26 [0, -1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0] = true := rfl
theorem certF13_2 : certF 13 2 26 [-1, 0, 1, 1, 0, -1, 0, 0, 0, 0, 0, 0] = true := rfl
theorem certF13_3 : certF 13 3 26 [-1, 1, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0] = true := rfl
theorem certF13_4 : certF 13 4 26 [-1, 1, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0] = true := rfl
theorem certF13_5 : certF 13 5 26 [0, 1, -1, 0, -1, 1, 0, 0, 0, 0, 0, 0] = true := rfl

/-- X_13^n, every n: a Hodge character is paired. -/
theorem paired_char_13 (a : List Nat) (hin : AllIn 12 a) (h : HodgeList 13 a) :
    cnt 1 a = cnt 12 a ∧ cnt 2 a = cnt 11 a ∧ cnt 3 a = cnt 10 a ∧ cnt 4 a = cnt 9 a ∧ cnt 5 a = cnt 8 a ∧ cnt 6 a = cnt 7 a :=
  ⟨pair_one 13 0 26 [-1, 0, -1, -1, -1, 0, 0, 0, 0, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF13_0 a hin h,
   pair_one 13 1 26 [0, -1, 0, 1, 1, 1, 0, 0, 0, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF13_1 a hin h,
   pair_one 13 2 26 [-1, 0, 1, 1, 0, -1, 0, 0, 0, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF13_2 a hin h,
   pair_one 13 3 26 [-1, 1, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF13_3 a hin h,
   pair_one 13 4 26 [-1, 1, 0, 0, 1, -1, 0, 0, 0, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF13_4 a hin h,
   pair_one 13 5 26 [0, 1, -1, 0, -1, 1, 0, 0, 0, 0, 0, 0] (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) certF13_5 a hin h⟩

end FermatFull

#print axioms FermatFull.sum_zero''
#print axioms FermatFull.regroup
#print axioms FermatFull.combine1
#print axioms FermatFull.extract1
#print axioms FermatFull.pair_one
#print axioms FermatFull.certF3_0
#print axioms FermatFull.paired_char_3
#print axioms FermatFull.certF5_0
#print axioms FermatFull.certF5_1
#print axioms FermatFull.paired_char_5
#print axioms FermatFull.certF7_0
#print axioms FermatFull.certF7_1
#print axioms FermatFull.certF7_2
#print axioms FermatFull.paired_char_7
#print axioms FermatFull.certF11_0
#print axioms FermatFull.certF11_1
#print axioms FermatFull.certF11_2
#print axioms FermatFull.certF11_3
#print axioms FermatFull.certF11_4
#print axioms FermatFull.paired_char_11
#print axioms FermatFull.certF13_0
#print axioms FermatFull.certF13_1
#print axioms FermatFull.certF13_2
#print axioms FermatFull.certF13_3
#print axioms FermatFull.certF13_4
#print axioms FermatFull.certF13_5
#print axioms FermatFull.paired_char_13

Listing 226: hodge/HodgeCounts.lean

hodge/HodgeCounts.lean

/-
  hodge/HodgeCounts.lean — T41 cycle 39: Shioda's condition depends only on the count vector, and the
  converse "symmetric counts ⇒ Hodge" for every m.

  Lean 4 core plus hodge/HodgeIff.
    hodge_of_counts    equal counts (entries in 1..M) ⇒ same Hodge status
    cnt_pairsList      #v in pairsList m l = #v in l + #(m − v) in l   (for 0 < v < m, entries of l in 1..m−1)
    sym_hodge          symmetric counts ⇒ Hodge (odd m, t·b ≢ 0 for units t), through the explicit
                       list pairsList m (lows m a), which has the same counts as a (counts_match).
  With FermatFull/FermatPrimes2 (Hodge ⇒ symmetric): for every prime m ≤ 47 and every n,
  Hodge character ⟺ symmetric count vector ⟺ sum of classes of linear subspaces (Ran).
-/
import hodge.HodgeIff
import bsd.Congruent2pF

namespace HodgeCounts
open FTAChain FrobChain QRChain ESChain FermatPrime FermatFull HodgeChain HodgeIff

theorem hodge_of_counts (m M : Nat) (a b : List Nat) (ha : AllIn M a) (hb : AllIn M b)
    (hc : ∀ v, cnt v a = cnt v b) (h : HodgeList m a) : HodgeList m b := by
  intro t ht
  have e := h t ht
  rw [regroup M _ a ha, regroup M _ a ha] at e
  rw [regroup M _ b hb, regroup M _ b hb]
  have l : sumTo M (fun c => cnt (c + 1) b * (2 * (t * (c + 1) % m)))
      = sumTo M (fun c => cnt (c + 1) a * (2 * (t * (c + 1) % m))) :=
    sum_ext _ _ _ (fun c _ => by rw [hc (c + 1)])
  have r : sumTo M (fun c => cnt (c + 1) b * m) = sumTo M (fun c => cnt (c + 1) a * m) :=
    sum_ext _ _ _ (fun c _ => by rw [hc (c + 1)])
  rw [l, r]
  exact e

def lows (m : Nat) : List Nat → List Nat
  | [] => []
  | x :: l => cond (Nat.blt (x + x) m) (x :: lows m l) (lows m l)

def cntNeg (m v : Nat) : List Nat → Nat
  | [] => 0
  | x :: l => ind (m - x) 1 v + cntNeg m v l

theorem cnt_cons (v x : Nat) (l : List Nat) : cnt v (x :: l) = ind x 1 v + cnt v l := rfl

theorem cnt_append (v : Nat) : ∀ a b : List Nat, cnt v (a ++ b) = cnt v a + cnt v b
  | [], b => (Nat.zero_add _).symm
  | x :: a, b => by
    show ind x 1 v + cnt v (a ++ b) = ind x 1 v + cnt v a + cnt v b
    rw [cnt_append v a b, nadd_assoc]

theorem cnt_pairsList (m v : Nat) : ∀ l : List Nat, cnt v (pairsList m l) = cnt v l + cntNeg m v l
  | [] => rfl
  | x :: l => by
    show cnt v ([x, m - x] ++ pairsList m l) = ind x 1 v + cnt v l + (ind (m - x) 1 v + cntNeg m v l)
    rw [cnt_append, cnt_pairsList m v l]
    show ind x 1 v + (ind (m - x) 1 v + 0) + (cnt v l + cntNeg m v l)
      = ind x 1 v + cnt v l + (ind (m - x) 1 v + cntNeg m v l)
    rw [Nat.add_zero, Congruent2pF.nmid4]

theorem ind_eq (x v : Nat) (h : v = x) : ind x 1 v = 1 := by unfold ind; exact ite_eq_left h
theorem ind_ne (x v : Nat) (h : ¬ v = x) : ind x 1 v = 0 := by unfold ind; exact ite_eq_right h

/-- #v in lows m l: all of #v l if 2v < m, none otherwise. -/
theorem cnt_lows (m v : Nat) : ∀ l : List Nat,
    cnt v (lows m l) = cond (Nat.blt (v + v) m) (cnt v l) 0
  | [] => by cases Nat.blt (v + v) m <;> rfl
  | x :: l => by
    have ih := cnt_lows m v l
    unfold lows
    cases hx : Nat.blt (x + x) m with
    | true =>
      show ind x 1 v + cnt v (lows m l) = cond (Nat.blt (v + v) m) (ind x 1 v + cnt v l) 0
      rw [ih]
      cases Nat.decEq v x with
      | isTrue e => rw [e, hx, ind_eq x x rfl]; rfl
      | isFalse ne =>
        rw [ind_ne x v ne, Nat.zero_add, Nat.zero_add]
    | false =>
      show cnt v (lows m l) = cond (Nat.blt (v + v) m) (ind x 1 v + cnt v l) 0
      rw [ih]
      cases Nat.decEq v x with
      | isTrue e => rw [e, hx]; rfl
      | isFalse ne => rw [ind_ne x v ne, Nat.zero_add]

/-- For x, v ≤ m: m − x = v ⟺ x = m − v. -/
theorem sub_swap (m x v : Nat) (hx : x ≤ m) (hv : v ≤ m) : (v = m - x) ↔ (m - v = x) := by
  constructor
  · intro e
    have h1 := add_sub_of_le' x m hx
    rw [← e] at h1
    have h2 := add_sub_of_le' v m hv
    exact add_left_cancel' v _ _ (h2.trans (h1.symm.trans (nadd_comm x v)))
  · intro e
    have h2 := add_sub_of_le' v m hv
    rw [e] at h2
    have h1 := add_sub_of_le' x m hx
    exact add_left_cancel' x _ _ ((nadd_comm x v).trans (h2.trans h1.symm))

theorem cntNeg_eq (m v : Nat) (hv : v ≤ m) : ∀ l : List Nat, AllIn (m - 1) l → cntNeg m v l = cnt (m - v) l
  | [], _ => rfl
  | x :: l, h => by
    show ind (m - x) 1 v + cntNeg m v l = ind x 1 (m - v) + cnt (m - v) l
    have hxm : x ≤ m := Nat.le_trans h.1.2 (Nat.sub_le m 1)
    rw [cntNeg_eq m v hv l h.2]
    congr 1
    cases Nat.decEq v (m - x) with
    | isTrue e => rw [ind_eq _ _ e, ind_eq _ _ ((sub_swap m x v hxm hv).mp e)]
    | isFalse ne => rw [ind_ne _ _ ne, ind_ne _ _ (fun e' => ne ((sub_swap m x v hxm hv).mpr e'))]

theorem cnt_out (M v : Nat) : ∀ l : List Nat, AllIn M l → (v = 0 ∨ M < v) → cnt v l = 0
  | [], _, _ => rfl
  | x :: l, h, hv => by
    show ind x 1 v + cnt v l = 0
    rw [cnt_out M v l h.2 hv]
    apply ind_ne
    intro e
    rw [e] at hv
    cases hv with
    | inl z => rw [z] at h; exact absurd h.1.1 (Nat.lt_irrefl 0)
    | inr g => exact absurd (Nat.lt_of_lt_of_le g h.1.2) (Nat.lt_irrefl _)

theorem allIn_lows (M m : Nat) : ∀ l : List Nat, AllIn M l → AllIn M (lows m l)
  | [], _ => trivial
  | x :: l, h => by
    unfold lows
    cases Nat.blt (x + x) m with
    | true => exact ⟨h.1, allIn_lows M m l h.2⟩
    | false => exact allIn_lows M m l h.2

theorem allIn_append (M : Nat) : ∀ a b : List Nat, AllIn M a → AllIn M b → AllIn M (a ++ b)
  | [], _, _, hb => hb
  | _ :: a, b, ha, hb => ⟨ha.1, allIn_append M a b ha.2 hb⟩

theorem allIn_pairs (m' : Nat) : ∀ l : List Nat, AllIn m' l → AllIn m' (pairsList (m' + 1) l)
  | [], _ => trivial
  | x :: l, h => by
    apply allIn_append m' [x, m' + 1 - x] _ _ (allIn_pairs m' l h.2)
    refine ⟨h.1, ⟨?_, ?_⟩, trivial⟩
    · -- 0 < m' + 1 − x since x ≤ m'
      have e := add_sub_of_le' x (m' + 1) (Nat.le_succ_of_le h.1.2)
      cases hz : m' + 1 - x with
      | zero => rw [hz, Nat.add_zero] at e; rw [e] at h; exact absurd h.1.2 (Nat.lt_irrefl _)
      | succ k => exact Nat.zero_lt_succ k
    · -- m' + 1 − x ≤ m' since x ≥ 1
      have e := add_sub_of_le' x (m' + 1) (Nat.le_succ_of_le h.1.2)
      apply Nat.le_of_lt_succ
      apply Nat.lt_of_add_lt_add_left (n := x)
      rw [e]
      show m' + 1 < x + (m' + 1)
      rw [nadd_comm x]
      exact Nat.lt_add_of_pos_right h.1.1
theorem allIn_mem (M : Nat) : ∀ l : List Nat, AllIn M l → ∀ b, b ∈ l → 0 < b ∧ b ≤ M
  | [], _, _, hb => by cases hb
  | x :: l, h, b, hb => by
    cases hb with
    | head => exact h.1
    | tail _ hb => exact allIn_mem M l h.2 b hb

theorem lt_of_blt {a b : Nat} (h : Nat.blt a b = true) : a < b := Nat.le_of_ble_eq_true h

/-- counts of the explicit pair list agree with a (symmetric counts, odd m). -/
theorem counts_match (m' : Nat) (a : List Nat) (hin : AllIn m' a)
    (hsym : ∀ v, 0 < v → v ≤ m' → cnt v a = cnt (m' + 1 - v) a) (hodd : ∀ v, v + v ≠ m' + 1) (v : Nat)
    (h0 : 0 < v) (hv : v ≤ m') :
    cnt v (pairsList (m' + 1) (lows (m' + 1) a)) = cnt v a := by
  have hl := allIn_lows m' (m' + 1) a hin
  rw [cnt_pairsList, cntNeg_eq (m' + 1) v (Nat.le_succ_of_le hv) _ hl, cnt_lows, cnt_lows]
  have hw := add_sub_of_le' v (m' + 1) (Nat.le_succ_of_le hv)
  generalize hW : m' + 1 - v = w at hw
  -- hw : v + w = m' + 1
  cases hb : Nat.blt (v + v) (m' + 1) with
  | true =>
    have lt := lt_of_blt hb
    cases hb' : Nat.blt (w + w) (m' + 1) with
    | false => rfl
    | true =>
      have lt' := lt_of_blt hb'
      -- v + v < v + w and w + w < v + w impossible together
      have a1 : v < w := Nat.lt_of_add_lt_add_left (n := v) (hw ▸ lt)
      have a2 : w < v := Nat.lt_of_add_lt_add_left (n := w) (by rw [nadd_comm w v, hw]; exact lt')
      exact absurd (Nat.lt_trans a1 a2) (Nat.lt_irrefl v)
  | false =>
    cases hb' : Nat.blt (w + w) (m' + 1) with
    | false =>
      -- v + v ≥ m'+1 and w + w ≥ m'+1 with v + w = m'+1 ⇒ v = w ⇒ v + v = m' + 1
      exfalso
      have nv : ¬ (v + v < m' + 1) := fun h => by rw [show Nat.blt (v + v) (m' + 1) = true from Nat.ble_eq_true_of_le h] at hb; exact Bool.noConfusion hb
      have nw : ¬ (w + w < m' + 1) := fun h => by rw [show Nat.blt (w + w) (m' + 1) = true from Nat.ble_eq_true_of_le h] at hb'; exact Bool.noConfusion hb'
      cases Nat.lt_or_ge v w with
      | inl l => exact nv (hw ▸ Nat.add_lt_add_left l v)
      | inr g =>
        cases Nat.lt_or_eq_of_le g with
        | inl l => exact nw (by rw [← hw, nadd_comm v w]; exact Nat.add_lt_add_left l w)
        | inr e => exact hodd v (by rw [← hw, ← e])
    | true =>
      show 0 + cnt w a = cnt v a
      rw [Nat.zero_add]
      have w0 : 0 < w := by
        cases w with
        | zero => rw [Nat.add_zero] at hw; rw [hw] at hv; exact absurd hv (Nat.not_succ_le_self m')
        | succ k => exact Nat.zero_lt_succ k
      have wv : w ≤ m' := Nat.le_of_lt_succ (show w < m' + 1 by
        rw [← hw, nadd_comm v w]; exact Nat.lt_add_of_pos_right h0)
      rw [hsym w w0 wv]
      have : m' + 1 - w = v := by
        have t1 := add_sub_of_le' w (m' + 1) (Nat.le_succ_of_le wv)
        exact add_left_cancel' w _ _ (t1.trans (hw.symm.trans (nadd_comm v w)))
      rw [this]

/-- **Symmetric counts ⇒ Hodge** (odd m; every unit t with t·b ≢ 0 for 0 < b < m). -/
theorem sym_hodge (m' : Nat) (a : List Nat) (hin : AllIn m' a)
    (hsym : ∀ v, 0 < v → v ≤ m' → cnt v a = cnt (m' + 1 - v) a) (hodd : ∀ v, v + v ≠ m' + 1)
    (hnz : ∀ b, 0 < b → b ≤ m' → ∀ t, t ∈ FermatPrime.units (m' + 1) → rem (m' + 1) (t * b) ≠ 0) :
    HodgeList (m' + 1) a := by
  have hl := allIn_lows m' (m' + 1) a hin
  have hb := allIn_pairs m' _ hl
  have hp : HodgeList (m' + 1) (pairsList (m' + 1) (lows (m' + 1) a)) :=
    pairs_hodge m' _ (fun b hbm =>
      have r := allIn_mem m' _ hl b hbm
      ⟨Nat.le_succ_of_le r.2, hnz b r.1 r.2⟩)
  apply hodge_of_counts (m' + 1) m' _ a hb hin _ hp
  intro v
  cases Nat.eq_zero_or_pos v with
  | inl z => rw [cnt_out m' v _ hb (Or.inl z), cnt_out m' v _ hin (Or.inl z)]
  | inr pos =>
    cases Nat.lt_or_ge m' v with
    | inl g => rw [cnt_out m' v _ hb (Or.inr g), cnt_out m' v _ hin (Or.inr g)]
    | inr le => exact counts_match m' a hin hsym hodd v pos le

end HodgeCounts

#print axioms HodgeCounts.hodge_of_counts
#print axioms HodgeCounts.cnt_cons
#print axioms HodgeCounts.cnt_append
#print axioms HodgeCounts.cnt_pairsList
#print axioms HodgeCounts.ind_eq
#print axioms HodgeCounts.ind_ne
#print axioms HodgeCounts.cnt_lows
#print axioms HodgeCounts.sub_swap
#print axioms HodgeCounts.cntNeg_eq
#print axioms HodgeCounts.cnt_out
#print axioms HodgeCounts.allIn_lows
#print axioms HodgeCounts.allIn_append
#print axioms HodgeCounts.allIn_pairs
#print axioms HodgeCounts.allIn_mem
#print axioms HodgeCounts.lt_of_blt
#print axioms HodgeCounts.counts_match
#print axioms HodgeCounts.sym_hodge

81.7 The inductive structure, one step

For every \(m\), every unit \(t\) and characters \((A,c)\) of \(X_m^r\), \((B,s)\) of \(X_m^{s'}\) with \(c+s=m\) and \(m\nmid tc\):

\[ 2\,T_t(c::A)=(|A|+1)m,\quad 2\,T_t(s::B)=(|B|+1)m\ \Longrightarrow \ 2\,T_t(A\sqcup B)=(|A|+|B|)m, \qquad T_t(x)=\sum _i\langle tx_i\rangle _m . \]
\begin{align*} &\langle tc\rangle _m+\langle ts\rangle _m\equiv t(c+s)\equiv 0,\quad 0<\langle tc\rangle _m+\langle ts\rangle _m<2m &&\\ &\langle tc\rangle _m+\langle ts\rangle _m=m &&\\ &T_t(A\sqcup B)=T_t(A)+T_t(B)=T_t(c::A)+T_t(s::B)-m && \end{align*}

Listing 227: hodge/InductiveStep.lean

hodge/InductiveStep.lean

/-
  hodge/InductiveStep.lean — T41 cycle 67: one step of Shioda's inductive structure, at the character
  level, for every m.

  Lean 4 core plus hodge/FermatGens (tsum), ESChain (rem_eq_mod), QRChain, lib/Semi (lib_nat).
  For a unit t (m ∤ t·x when m ∤ x) and pieces A, B with connecting characters c, s (c + s = m, m ∤ t·c):
    pair_m        ⟨tc⟩ + ⟨ts⟩ = m
    tsum_append   tsum(A ++ B) = tsum A + tsum B
    step_hodge    2·tsum(c :: A) = (|A|+1)m  and  2·tsum(s :: B) = (|B|+1)m  ⇒  2·tsum(A ++ B) = (|A|+|B|)m
  i.e. if (A, c) is a Hodge character of X^r and (B, s) of X^s, then A ⊔ B is Hodge on X^{r+s}: the
  combinatorial half of Shioda's inductive structure (the cycle-theoretic half: the rational map
  X^r × X^s ⇢ X^{r+s} carries algebraic cycles to algebraic cycles — cited).
-/
import hodge.FermatGens
import ESChain
import lib.Semi

namespace InductiveStep
open FTAChain FrobChain QRChain ESChain FermatGens

theorem tsum_append (m t : Nat) : ∀ A B : List Nat, tsum m t (A ++ B) = tsum m t A + tsum m t B
  | [], B => by show tsum m t B = 0 + tsum m t B; rw [Nat.zero_add]
  | a :: A, B => by
    show (t * a) % m + tsum m t (A ++ B) = ((t * a) % m + tsum m t A) + tsum m t B
    rw [tsum_append m t A B, Nat.add_assoc]

theorem pair_m (m' t c s : Nat) (hcs : c + s = m' + 1)
    (hc : ¬ Dv (m' + 1) (t * c)) :
    (t * c) % (m' + 1) + (t * s) % (m' + 1) = m' + 1 := by
  rw [← rem_eq_mod, ← rem_eq_mod]
  have hx := rem_lt' m' (t * c)
  have hy := rem_lt' m' (t * s)
  have z : rem (m' + 1) (rem (m' + 1) (t * c) + rem (m' + 1) (t * s)) = 0 := by
    rw [rem_add_congr2 m' _ (t * c) _ (t * s) (rem_idem m' _) (rem_idem m' _)]
    apply rem_zero_of_dv
    exact ⟨t, by rw [← nleft_distrib, hcs, nmul_comm]⟩
  have hx0 : rem (m' + 1) (t * c) ≠ 0 := fun e => hc (dv_of_rem_zero _ _ e)
  cases dv_of_rem_zero _ _ z with
  | intro q hq =>
    match q, hq with
    | 0, hq =>
      rw [Nat.zero_mul] at hq
      exact absurd (Nat.eq_zero_of_add_eq_zero_right hq) hx0
    | 1, hq => rw [hq, Nat.one_mul]
    | q + 2, hq =>
      have l : rem (m' + 1) (t * c) + rem (m' + 1) (t * s) < (m' + 1) + (m' + 1) := Nat.add_lt_add hx hy
      have g : (m' + 1) + (m' + 1) ≤ (q + 2) * (m' + 1) := by
        have e : (q + 2) * (m' + 1) = q * (m' + 1) + ((m' + 1) + (m' + 1)) := by lib_nat
        rw [e]; exact Nat.le_add_left _ _
      rw [hq] at l
      exact absurd (Nat.lt_of_lt_of_le l g) (Nat.lt_irrefl _)

/-- **Inductive step at character level.** -/
theorem step_hodge (m' t c s : Nat) (A B : List Nat) (hcs : c + s = m' + 1)
    (hc : ¬ Dv (m' + 1) (t * c))
    (hA : tsum (m' + 1) t (c :: A) + tsum (m' + 1) t (c :: A) = (A.length + 1) * (m' + 1))
    (hB : tsum (m' + 1) t (s :: B) + tsum (m' + 1) t (s :: B) = (B.length + 1) * (m' + 1)) :
    tsum (m' + 1) t (A ++ B) + tsum (m' + 1) t (A ++ B) = (A.length + B.length) * (m' + 1) := by
  have pm := pair_m m' t c s hcs hc
  rw [tsum_append]
  have hA' : tsum (m' + 1) t (c :: A) = (t * c) % (m' + 1) + tsum (m' + 1) t A := rfl
  have hB' : tsum (m' + 1) t (s :: B) = (t * s) % (m' + 1) + tsum (m' + 1) t B := rfl
  rw [hA'] at hA; rw [hB'] at hB
  revert hA hB pm
  generalize (t * c) % (m' + 1) = x
  generalize (t * s) % (m' + 1) = y
  generalize tsum (m' + 1) t A = a
  generalize tsum (m' + 1) t B = b
  generalize A.length = la
  generalize B.length = lb
  generalize m' + 1 = M
  intro hA hB pm
  -- (a+b)+(a+b) + (M + M) = (la+lb) M + (M + M)
  apply add_left_cancel' (M + M)
  have e1 : (M + M) + ((a + b) + (a + b)) = ((x + a) + (x + a)) + ((y + b) + (y + b)) := by
    rw [← pm]; lib_nat
  rw [e1, hA, hB]; lib_nat

end InductiveStep

#print axioms InductiveStep.tsum_append
#print axioms InductiveStep.pair_m
#print axioms InductiveStep.step_hodge

81.8 Composite degrees: every Hodge character reached from surfaces

For \(m\in \{18,20,21\}\) and \(n=4\), every Hodge character of \(X_m^4\) is reached by the inductive structure from characters of length at most \(4\) (curves and surfaces, where Hodge classes are algebraic by Lefschetz \((1,1)\)): \(c=A\sqcup B\) with \((A,-\Sigma A)\) and \((B,\Sigma A)\) Hodge and reached, or \(c\) a sum of two Hodge characters. For \(m=10\) (\(n\le 8\)) and \(m=15\) (\(n\le 4\)) the generators are pairs, length-\(4\) characters and curve \(\times \) curve sextuples. For \(m=14\) the characters \((1,1,9,9,11,11)\) and \((3,3,5,5,13,13)\) are not products, and they are reached with a connecting character:

\[ (1,1,9,9,11,11)=(1,9,11\mid 7)\sqcup (1,9,11\mid 7),\qquad (1,9,11,7)\ \text {Hodge on }X_{14}^2 . \]
All checks are Boolean closures evaluated by rfl.

Listing 228: hodge/FermatGens2.lean

hodge/FermatGens2.lean

/-
  hodge/FermatGens2.lean — T41 cycle 49: for m = 10 (n ≤ 8) and m = 15 (n ≤ 4) every Hodge character
  of the Fermat variety X_m^n is a sum of characters of length 2 and 4 (Hodge classes on Fermat curves'
  products of dimension ≤ 2: algebraic by Lefschetz (1,1) through Shioda's inductive structure) and
  curve×curve sextuples (two zero-sum triples). Checked by rfl with FermatGens.check.
-/
import hodge.FermatGens

namespace FermatGens2
open FermatGens

def G10 : List (List Nat) := [[1, 9], [2, 8], [3, 7], [4, 6], [5, 5], [1, 3, 8, 8], [1, 5, 6, 8], [1, 6, 6, 7], [2, 2, 7, 9], [2, 4, 5, 9], [2, 5, 6, 7], [3, 4, 4, 9], [3, 4, 5, 8], [1, 1, 6, 6, 8, 8], [2, 2, 4, 4, 9, 9], [2, 2, 6, 6, 7, 7], [3, 3, 4, 4, 8, 8]]
theorem gens10_hodge : G10.all (hodgeB 10 [1, 3, 7, 9]) = true := rfl
theorem split10_0 : zs 10 [1, 1, 8] && zs 10 [6, 6, 8] = true := rfl
theorem split10_1 : zs 10 [2, 4, 4] && zs 10 [2, 9, 9] = true := rfl
theorem split10_2 : zs 10 [2, 2, 6] && zs 10 [6, 7, 7] = true := rfl
theorem split10_3 : zs 10 [3, 3, 4] && zs 10 [4, 8, 8] = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem cover10_2 : check 10 [1, 3, 7, 9] G10 2 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem cover10_4 : check 10 [1, 3, 7, 9] G10 4 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem cover10_6 : check 10 [1, 3, 7, 9] G10 6 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem cover10_8 : check 10 [1, 3, 7, 9] G10 8 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem cover10_10 : check 10 [1, 3, 7, 9] G10 10 = true := rfl
def G15 : List (List Nat) := [[1, 14], [2, 13], [3, 12], [4, 11], [5, 10], [6, 9], [7, 8], [1, 6, 10, 13], [1, 6, 11, 12], [1, 7, 10, 12], [2, 5, 9, 14], [2, 5, 11, 12], [2, 7, 9, 12], [3, 4, 9, 14], [3, 4, 10, 13], [3, 5, 8, 14], [3, 6, 8, 13], [4, 7, 9, 10], [5, 6, 8, 11], [1, 2, 7, 11, 12, 12], [1, 4, 7, 10, 10, 13], [1, 6, 6, 8, 11, 13], [2, 4, 7, 9, 9, 14], [2, 5, 5, 8, 11, 14], [3, 3, 4, 8,   -- (+8 chars; full line in the Zenodo source)
theorem gens15_hodge : G15.all (hodgeB 15 [1, 2, 4, 7, 8, 11, 13, 14]) = true := rfl
theorem split15_0 : zs 15 [1, 2, 12] && zs 15 [7, 11, 12] = true := rfl
theorem split15_1 : zs 15 [1, 4, 10] && zs 15 [7, 10, 13] = true := rfl
theorem split15_2 : zs 15 [1, 6, 8] && zs 15 [6, 11, 13] = true := rfl
theorem split15_3 : zs 15 [2, 4, 9] && zs 15 [7, 9, 14] = true := rfl
theorem split15_4 : zs 15 [2, 5, 8] && zs 15 [5, 11, 14] = true := rfl
theorem split15_5 : zs 15 [3, 4, 8] && zs 15 [3, 13, 14] = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem cover15_2 : check 15 [1, 2, 4, 7, 8, 11, 13, 14] G15 2 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem cover15_4 : check 15 [1, 2, 4, 7, 8, 11, 13, 14] G15 4 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem cover15_6 : check 15 [1, 2, 4, 7, 8, 11, 13, 14] G15 6 = true := rfl

end FermatGens2

#print axioms FermatGens2.gens10_hodge
#print axioms FermatGens2.split10_0
#print axioms FermatGens2.split10_1
#print axioms FermatGens2.split10_2
#print axioms FermatGens2.split10_3
#print axioms FermatGens2.cover10_2
#print axioms FermatGens2.cover10_4
#print axioms FermatGens2.cover10_6
#print axioms FermatGens2.cover10_8
#print axioms FermatGens2.cover10_10
#print axioms FermatGens2.gens15_hodge
#print axioms FermatGens2.split15_0
#print axioms FermatGens2.split15_1
#print axioms FermatGens2.split15_2
#print axioms FermatGens2.split15_3
#print axioms FermatGens2.split15_4
#print axioms FermatGens2.split15_5
#print axioms FermatGens2.cover15_2
#print axioms FermatGens2.cover15_4
#print axioms FermatGens2.cover15_6

Listing 229: hodge/Fermat14Exc.lean

hodge/Fermat14Exc.lean

/-
  hodge/Fermat14Exc.lean — T41 cycle 55: the m = 14 exceptional sextuples are indecomposable.

  Lean 4 core plus hodge/FermatGens (hodgeB, zs). For m = 14 (units 1, 3, 5, 9, 11, 13) the Hodge
  characters (1,1,9,9,11,11) and (3,3,5,5,13,13) of X_14^4
    · are Hodge                                     (exc_hodge)
    · have no Hodge sub-character of length 2 or 4  (no_sub: so no product decomposition)
    · have no split into two zero-sum triples       (no_cc)
  so the inductive structure (surfaces, products of curves) does not reach them: the first open
  cases of the method for m = 14, n = 4 (they are the Galois orbit of one character up to t·).
-/
import hodge.FermatGens

namespace Fermat14Exc
open FermatGens

def U14 : List Nat := [1, 3, 5, 9, 11, 13]
def E1 : List Nat := [1, 1, 9, 9, 11, 11]
def E2 : List Nat := [3, 3, 5, 5, 13, 13]

/-- all sublists (as index choices) of a list -/
def subs : List Nat → List (List Nat)
  | [] => [[]]
  | x :: l => (subs l).map (x :: ·) ++ subs l

def compl (c s : List Nat) : List Nat := (sub c s).getD []

def noSub (c : List Nat) : Bool :=
  (subs c).all (fun s => !((Nat.beq s.length 2 || Nat.beq s.length 4) && hodgeB 14 U14 s))

def noCC (c : List Nat) : Bool :=
  (subs c).all (fun s => !(Nat.beq s.length 3 && zs 14 s && zs 14 (compl c s)))

theorem exc_hodge : hodgeB 14 U14 E1 && hodgeB 14 U14 E2 = true := rfl
theorem no_sub : noSub E1 && noSub E2 = true := rfl
theorem no_cc : noCC E1 && noCC E2 = true := rfl
/-- E2 = 3·E1 (mod 14): one Galois orbit. -/
theorem galois : (E1.map (fun x => (3 * x) % 14)) = [3, 3, 13, 13, 5, 5] := rfl

end Fermat14Exc

#print axioms Fermat14Exc.exc_hodge
#print axioms Fermat14Exc.no_sub
#print axioms Fermat14Exc.no_cc
#print axioms Fermat14Exc.galois

Listing 230: hodge/FermatInductive2.lean

hodge/FermatInductive2.lean

/-
  hodge/FermatInductive2.lean — T41 cycle 69: the inductive structure (with connecting characters) reaches every
  Hodge character of length 6 (n = 4) for m = 18, 20, 21 from surfaces (Lefschetz), checked by rfl, split by the smallest entry a (allReachFrom; every nondecreasing
  character of length 6 is a :: c with c nondecreasing from a), with
  allReach (same definition as FermatInductive) (compiled on Kamiak).
-/
import hodge.FermatGens

namespace FermatInductive2
open FermatGens

-- the definitions of FermatInductive (repeated: that file is checked on Kamiak, not a lake root)
def subs : List Nat → List (List Nat)
  | [] => [[]]
  | x :: l => (subs l).map (x :: ·) ++ subs l

def lsumN : List Nat → Nat
  | [] => 0
  | x :: l => x + lsumN l

def compl (c s : List Nat) : List Nat := (sub c s).getD []

/-- one split step, given the closure at smaller fuel -/
def splitOK (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c A : List Nat) : Bool :=
  let B := compl c A
  let s := lsumN A % m
  if Nat.beq s 0 then
    !A.isEmpty && !B.isEmpty && hodgeB m U A && hodgeB m U B && rec A && rec B
  else
    let A2 := (m - s) :: A
    let B2 := s :: B
    Nat.blt A2.length c.length && Nat.blt B2.length c.length &&
      hodgeB m U A2 && hodgeB m U B2 && rec A2 && rec B2

def anySplit (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c : List Nat) : List (List Nat) → Bool
  | [] => false
  | A :: As => splitOK m U rec c A || anySplit m U rec c As

def reach (m : Nat) (U : List Nat) : Nat → List Nat → Bool
  | 0, c => Nat.blt c.length 5
  | f + 1, c => Nat.blt c.length 5 || anySplit m U (reach m U f) c (subs c)

def allReach (m : Nat) (U : List Nat) (L : Nat) : Bool :=
  (multis m L 1).all (fun c => !(hodgeB m U c) || reach m U L c)



/-- the check restricted to characters whose smallest entry is a (split for memory) -/
def allReachFrom (m : Nat) (U : List Nat) (L a : Nat) : Bool :=
  (multis m L a).all (fun c => !(hodgeB m U (a :: c)) || reach m U (L + 1) (a :: c))

set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_1 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 1 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_2 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 2 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_3 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 3 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_4 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 4 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_5 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 5 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_6 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 6 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_7 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 7 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_8 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 8 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_9 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 9 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_10 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 10 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_11 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 11 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_12 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 12 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_13 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 13 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_14 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 14 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_15 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 15 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_16 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 16 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach18_6_17 : allReachFrom 18 [1, 5, 7, 11, 13, 17] 5 17 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_1 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 1 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_2 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 2 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_3 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 3 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_4 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 4 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_5 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 5 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_6 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 6 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_7 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 7 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_8 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 8 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_9 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 9 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_10 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 10 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_11 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 11 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_12 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 12 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_13 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 13 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_14 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 14 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_15 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 15 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_16 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 16 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_17 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 17 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_18 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 18 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach20_6_19 : allReachFrom 20 [1, 3, 7, 9, 11, 13, 17, 19] 5 19 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_1 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 1 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_2 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 2 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_3 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 3 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_4 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 4 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_5 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 5 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_6 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 6 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_7 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 7 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_8 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 8 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_9 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 9 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_10 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 10 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_11 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 11 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_12 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 12 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_13 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 13 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_14 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 14 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_15 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 15 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_16 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 16 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_17 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 17 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_18 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 18 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_19 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 19 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach21_6_20 : allReachFrom 21 [1, 2, 4, 5, 8, 10, 11, 13, 16, 17, 19, 20] 5 20 = true := rfl

end FermatInductive2

#print axioms FermatInductive2.reach18_6_1
#print axioms FermatInductive2.reach18_6_2
#print axioms FermatInductive2.reach18_6_3
#print axioms FermatInductive2.reach18_6_4
#print axioms FermatInductive2.reach18_6_5
#print axioms FermatInductive2.reach18_6_6
#print axioms FermatInductive2.reach18_6_7
#print axioms FermatInductive2.reach18_6_8
#print axioms FermatInductive2.reach18_6_9
#print axioms FermatInductive2.reach18_6_10
#print axioms FermatInductive2.reach18_6_11
#print axioms FermatInductive2.reach18_6_12
#print axioms FermatInductive2.reach18_6_13
#print axioms FermatInductive2.reach18_6_14
#print axioms FermatInductive2.reach18_6_15
#print axioms FermatInductive2.reach18_6_16
#print axioms FermatInductive2.reach18_6_17
#print axioms FermatInductive2.reach20_6_1
#print axioms FermatInductive2.reach20_6_2
#print axioms FermatInductive2.reach20_6_3
#print axioms FermatInductive2.reach20_6_4
#print axioms FermatInductive2.reach20_6_5
#print axioms FermatInductive2.reach20_6_6
#print axioms FermatInductive2.reach20_6_7
#print axioms FermatInductive2.reach20_6_8
#print axioms FermatInductive2.reach20_6_9
#print axioms FermatInductive2.reach20_6_10
#print axioms FermatInductive2.reach20_6_11
#print axioms FermatInductive2.reach20_6_12
#print axioms FermatInductive2.reach20_6_13
#print axioms FermatInductive2.reach20_6_14
#print axioms FermatInductive2.reach20_6_15
#print axioms FermatInductive2.reach20_6_16
#print axioms FermatInductive2.reach20_6_17
#print axioms FermatInductive2.reach20_6_18
#print axioms FermatInductive2.reach20_6_19
#print axioms FermatInductive2.reach21_6_1
#print axioms FermatInductive2.reach21_6_2
#print axioms FermatInductive2.reach21_6_3
#print axioms FermatInductive2.reach21_6_4
#print axioms FermatInductive2.reach21_6_5
#print axioms FermatInductive2.reach21_6_6
#print axioms FermatInductive2.reach21_6_7
#print axioms FermatInductive2.reach21_6_8
#print axioms FermatInductive2.reach21_6_9
#print axioms FermatInductive2.reach21_6_10
#print axioms FermatInductive2.reach21_6_11
#print axioms FermatInductive2.reach21_6_12
#print axioms FermatInductive2.reach21_6_13
#print axioms FermatInductive2.reach21_6_14
#print axioms FermatInductive2.reach21_6_15
#print axioms FermatInductive2.reach21_6_16
#print axioms FermatInductive2.reach21_6_17
#print axioms FermatInductive2.reach21_6_18
#print axioms FermatInductive2.reach21_6_19
#print axioms FermatInductive2.reach21_6_20

81.9 Standard characters and the first open case

For \(d\mid m\) the standard character of step \(m/d\) is

\[ \mathrm {std}(a)=\bigl (a,\ a+\tfrac md,\ \dots ,\ a+(d-1)\tfrac md,\ -da\bigr ). \]
For \(m=25\), \(n=4\) the four characters not reached by the inductive structure are exactly \(\mathrm {std}(1),\dots ,\mathrm {std}(4)\) with \(d=5\), one Galois orbit; with standard characters in the base, \(m=25,35,40\) are covered for \(n=4\). The first character reached by neither is
\[ m=32:\qquad c=(1,9,17,25)\sqcup (20,24), \]
a progression of step \(m/4\) and a pair; \(c\) is Hodge and is not \(\mathrm {std}(a)\) for any \(d\), \(a\).

\(m\) (\(n=4\)) Hodge characters unreached (inductive) unreached (with std)
\(\le 24\), \(26\)–\(31\), \(34\), \(37\), \(38\) all \(0\) \(0\)
\(25\) \(368\) \(4\) \(0\)
\(32\) \(1344\) \(4\) \(4\)
\(33\) \(990\) \(4\) \(4\)
\(35\) \(975\) \(6\) \(0\)
\(36\) \(3362\) \(96\) \(96\)
\(39\) \(1582\) \(12\) \(12\)
\(40\) \(3506\) \(4\) \(0\)

Listing 231: hodge/Fermat25Std.lean

hodge/Fermat25Std.lean

/-
  hodge/Fermat25Std.lean — T41 cycle 73: the four characters of X_25^4 that the inductive structure does not
  reach are exactly the Aoki–Shioda standard characters of step m/d = 5 (d = 5):
      std(a) = (a, a + 5, a + 10, a + 15, a + 20, −5a)   (a = 1, 2, 3, 4)
  They are Hodge (hodgeB, rfl), and std(a) for a = 1..4 is the list of unreached characters found by
  hodge_reach.py (NUMERIC_HODGE_REACH.jsonl). Standard characters are algebraic by Aoki–Shioda (cited):
  with them as an extra base, X_25^4 is covered.
-/
import hodge.FermatGens

namespace Fermat25Std
open FermatGens

def U25 : List Nat := [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24]

def std (m d a : Nat) : List Nat :=
  ((List.range d).map (fun k => (a + k * (m / d)) % m)) ++ [(m * m - d * a) % m]

theorem std_list : [1, 2, 3, 4].map (std 25 5) =
    [[1, 6, 11, 16, 21, 20], [2, 7, 12, 17, 22, 15], [3, 8, 13, 18, 23, 10], [4, 9, 14, 19, 24, 5]] := rfl

theorem std_hodge : ([1, 2, 3, 4].map (std 25 5)).all (hodgeB 25 U25) = true := rfl

/-- Every unit multiple of a standard character is standard: the orbit is closed (t · std(1) for t in U). -/
theorem std_orbit : U25.all (fun t => [1, 2, 3, 4].any (fun a =>
    FermatGens.sub ((std 25 5 1).map (fun x => (t * x) % 25)) (std 25 5 a) == some [])) = true := rfl

end Fermat25Std

#print axioms Fermat25Std.std_list
#print axioms Fermat25Std.std_hodge
#print axioms Fermat25Std.std_orbit

Listing 232: hodge/Fermat32Open.lean

hodge/Fermat32Open.lean

/-
  hodge/Fermat32Open.lean — T41 cycle 76: the first character not reached by inductive structure plus
  standard characters, m = 32, n = 4:
      c = (1, 9, 17, 25, 20, 24) = AP(1, step 8 = m/4) ⊔ (20, 24),   Σ AP ≡ 20,  20 + 24 + 20 ≡ 0
    c32_hodge     c is Hodge (rfl)
    c32_not_std   c is not a standard character std(m, d, a) for any d | 32 with d + 1 = 6 (no such d)
                  — and for every a, d it differs (finite check over d ∈ {1, 2, 4, 8, 16, 32})
  Not reached by the inductive closure with standard base: measured (NUMERIC_HODGE_REACH.jsonl).
  Its algebraicity needs a further cycle (Aoki's 'AP ⊔ pair' type or a correspondence); open here.
-/
import hodge.Fermat25Std

namespace Fermat32Open
open FermatGens Fermat25Std

def U32 : List Nat := [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31]
def c32 : List Nat := [1, 9, 17, 20, 24, 25]

def sameMS (a b : List Nat) : Bool := FermatGens.sub a b == some []

theorem c32_hodge : hodgeB 32 U32 c32 = true := rfl

theorem c32_not_std : ([1, 2, 4, 8, 16, 32].all (fun d => (List.range 32).all (fun a =>
    !(sameMS c32 (std 32 d a))))) = true := rfl

end Fermat32Open

#print axioms Fermat32Open.c32_hodge
#print axioms Fermat32Open.c32_not_std

81.10 Standard characters are Hodge for \(m\le 40\)

For every \(2\le m\le 40\), every odd \(d\mid m\) and every \(a\) such that \(\mathrm {std}(a)\) has no zero entry,

\[ \sum _{k<d}\Bigl \langle t\bigl (a+k\tfrac md\bigr )\Bigr \rangle _m+\langle -dta\rangle _m=\frac {(d+1)m}2 \quad \text {for every unit }t , \]
checked as one Boolean evaluation. In general the left side is \(d\,\langle ta\rangle _{m/d}+\frac {m(d-1)}2+\bigl (m-d\,\langle ta\rangle _{m/d}\bigr )\).

Listing 233: hodge/StdAll.lean

hodge/StdAll.lean

/-
  hodge/StdAll.lean — T41 cycle 85: every Aoki–Shioda standard character is Hodge, for every m ≤ 40.

  Lean 4 core plus hodge/FermatGens (hodgeB) and hodge/Fermat25Std (std). For 2 ≤ m ≤ 40, every d ∣ m with
  d + 1 even, and every a with no zero entry in
      std(m, d, a) = (a, a + m/d, …, a + (d−1)m/d, −da),
  std(m, d, a) satisfies the Hodge condition Σ_i ⟨t·c_i⟩ = (d+1)m/2 for every unit t (rfl).
  The general statement (all m) is the character half of Aoki–Shioda; their cycle half is cited.
-/
import hodge.Fermat25Std

namespace StdAll
open FermatGens Fermat25Std

def gcdF : Nat → Nat → Nat → Nat
  | 0, a, _ => a
  | f + 1, a, b => if b = 0 then a else gcdF f b (a % b)

def units (m : Nat) : List Nat := (List.range m).filter (fun t => Nat.beq (gcdF (m + 1) m t) 1)

def okStd (m : Nat) : Bool :=
  (List.range (m + 1)).all (fun d =>
    !(Nat.blt 1 d && Nat.beq (m % d) 0 && Nat.beq ((d + 1) % 2) 0) ||
    (List.range m).all (fun a =>
      let c := std m d a
      (c.any (fun x => Nat.beq x 0)) || hodgeB m (units m) c))

set_option maxRecDepth 100000 in
set_option maxHeartbeats 0 in
theorem std_hodge_le40 : (List.range 41).all (fun m => !(Nat.blt 1 m) || okStd m) = true := rfl

end StdAll

#print axioms StdAll.std_hodge_le40

81.11 Pullback, and the reach for \(m=12,14\)

For \(m=e\,m'\) and every \(x\), \(\langle ex\rangle _m=e\langle x\rangle _{m'}\), so

\[ 2T^{(m')}_t(c)=|c|\,m'\ \Longrightarrow \ 2T^{(m)}_t(e\cdot c)=|c|\,m , \]
the \(e\)-multiple of a Hodge character of \(X_{m'}\) is a Hodge character of \(X_m\). For \(m=12,14\) and lengths \(6\), \(8\) every Hodge character is reached by the inductive structure from surfaces (checked by rfl, split by the smallest entry).

Listing 234: hodge/Pullback.lean

hodge/Pullback.lean

/-
  hodge/Pullback.lean — T41 cycle 92: Fermat pullback at character level, every m.

  Lean 4 core plus hodge/FermatGens (tsum), ESChain (rem_eq_mod), FTAChain (rem_spec, rem_add_mul),
  QRChain (rem_of_lt), lib/Semi. For m = e·m′ (e ≥ 1, m′ ≥ 1):
    rem_scale      ⟨e·x⟩_{e m′} = e·⟨x⟩_{m′}
    tsum_scale     T^{(m)}_t(e·c) = e · T^{(m′)}_t(c)
    pull_hodge     2T^{(m′)}_t(c) = |c|·m′  ⇒  2T^{(m)}_t(e·c) = |c|·m
  so the e-multiple of a Hodge character of X_{m′} is a Hodge character of X_m (the cycle half: pullback
  along X_m → X_{m′}, x ↦ x^e, preserves algebraicity — cited).
-/
import hodge.FermatGens
import ESChain
import lib.Semi

namespace Pullback
open FTAChain FrobChain QRChain ESChain FermatGens

theorem rem_scale (e' m' x : Nat) :
    rem ((e' + 1) * (m' + 1)) ((e' + 1) * x) = (e' + 1) * rem (m' + 1) x := by
  have ⟨q, r, k, hx, hr, hrem⟩ := rem_spec m' x
  have hM : (e' + 1) * (m' + 1) = (e' * (m' + 1) + m') + 1 := by lib_nat
  rw [hrem, hM, hx]
  have e1 : (e' + 1) * (q * (m' + 1) + r) = q * ((e' * (m' + 1) + m') + 1) + (e' + 1) * r := by lib_nat
  rw [e1, rem_add_mul]
  apply rem_of_lt
  -- (e'+1) r < (e'+1)(m'+1) since r < m' + 1
  have lt : (e' + 1) * r < (e' + 1) * (m' + 1) := by
    have hr' : r + 1 ≤ m' + 1 := by rw [← hr]; exact Nat.add_le_add_left (Nat.succ_le_succ (Nat.zero_le k)) r
    have : (e' + 1) * r + (e' + 1) ≤ (e' + 1) * (m' + 1) := by
      rw [show (e' + 1) * r + (e' + 1) = (e' + 1) * (r + 1) by lib_nat]
      exact Nat.mul_le_mul_left _ hr'
    exact Nat.lt_of_lt_of_le (Nat.lt_add_of_pos_right (Nat.zero_lt_succ e')) this
  rw [← hM]; exact lt

theorem tsum_scale (e' m' t : Nat) : ∀ c : List Nat,
    tsum ((e' + 1) * (m' + 1)) t (c.map (fun x => (e' + 1) * x)) = (e' + 1) * tsum (m' + 1) t c
  | [] => rfl
  | a :: c => by
    show (t * ((e' + 1) * a)) % ((e' + 1) * (m' + 1)) + tsum ((e' + 1) * (m' + 1)) t (c.map (fun x => (e' + 1) * x))
      = (e' + 1) * ((t * a) % (m' + 1) + tsum (m' + 1) t c)
    rw [tsum_scale e' m' t c]
    have hM : (e' + 1) * (m' + 1) = (e' * (m' + 1) + m') + 1 := by lib_nat
    have h1 : (t * ((e' + 1) * a)) % ((e' + 1) * (m' + 1)) = (e' + 1) * ((t * a) % (m' + 1)) := by
      rw [hM, ← rem_eq_mod, ← rem_eq_mod, ← hM, show t * ((e' + 1) * a) = (e' + 1) * (t * a) by lib_nat]
      exact rem_scale e' m' (t * a)
    rw [h1]; lib_nat

theorem len_map (f : Nat → Nat) : ∀ c : List Nat, (c.map f).length = c.length
  | [] => rfl
  | _ :: c => congrArg Nat.succ (len_map f c)

/-- **Pullback of a Hodge character.** -/
theorem pull_hodge (e' m' t : Nat) (c : List Nat)
    (h : tsum (m' + 1) t c + tsum (m' + 1) t c = c.length * (m' + 1)) :
    tsum ((e' + 1) * (m' + 1)) t (c.map (fun x => (e' + 1) * x))
      + tsum ((e' + 1) * (m' + 1)) t (c.map (fun x => (e' + 1) * x))
      = (c.map (fun x => (e' + 1) * x)).length * ((e' + 1) * (m' + 1)) := by
  rw [tsum_scale, len_map]
  have e : (e' + 1) * tsum (m' + 1) t c + (e' + 1) * tsum (m' + 1) t c
      = (e' + 1) * (tsum (m' + 1) t c + tsum (m' + 1) t c) := by lib_nat
  rw [e, h]; lib_nat

end Pullback

#print axioms Pullback.rem_scale
#print axioms Pullback.tsum_scale
#print axioms Pullback.len_map
#print axioms Pullback.pull_hodge

Listing 235: hodge/FermatInductive.lean

hodge/FermatInductive.lean

/-
  hodge/FermatInductive.lean — T41 cycle 58: Shioda's inductive structure, with a connecting character,
  reaches every Hodge character of X_m^n for m = 12, 14 (n ≤ 6) from surfaces.

  Inductive structure (Shioda 1979): X_m^r × X_m^s ⇢ X_m^{r+s}; a character c = A ⊔ B of X^{r+s} comes from
  (A, −s) on X^r and (B, s) on X^s, s = ΣA mod m ≠ 0 (or s = 0: plain product). If both pieces are
  Hodge and algebraic, so is c. Base: length ≤ 4 (points, curves, surfaces: Lefschetz (1,1)).
    reach      Bool closure (fuel = length), checked by rfl
    e14_split  (1,1,9,9,11,11) = [1,9,11 | 7] ⊔ [1,9,11 | 7], and (1,9,11,7) is Hodge on X_14^2
    reach12_L_a, reach14_L_a   every Hodge character of length L = 6, 8 with smallest entry a is reached
  This corrects cycle 55: the m = 14 exceptional characters are indecomposable as products, but are
  reached with a connecting character (Fermat14Exc stays true as stated).
-/
import hodge.FermatGens

namespace FermatInductive
open FermatGens

def subs : List Nat → List (List Nat)
  | [] => [[]]
  | x :: l => (subs l).map (x :: ·) ++ subs l

def lsumN : List Nat → Nat
  | [] => 0
  | x :: l => x + lsumN l

def compl (c s : List Nat) : List Nat := (sub c s).getD []

/-- one split step, given the closure at smaller fuel -/
def splitOK (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c A : List Nat) : Bool :=
  let B := compl c A
  let s := lsumN A % m
  if Nat.beq s 0 then
    !A.isEmpty && !B.isEmpty && hodgeB m U A && hodgeB m U B && rec A && rec B
  else
    let A2 := (m - s) :: A
    let B2 := s :: B
    Nat.blt A2.length c.length && Nat.blt B2.length c.length &&
      hodgeB m U A2 && hodgeB m U B2 && rec A2 && rec B2

def anySplit (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c : List Nat) : List (List Nat) → Bool
  | [] => false
  | A :: As => splitOK m U rec c A || anySplit m U rec c As

def reach (m : Nat) (U : List Nat) : Nat → List Nat → Bool
  | 0, c => Nat.blt c.length 5
  | f + 1, c => Nat.blt c.length 5 || anySplit m U (reach m U f) c (subs c)

def allReach (m : Nat) (U : List Nat) (L : Nat) : Bool :=
  (multis m L 1).all (fun c => !(hodgeB m U c) || reach m U L c)

theorem e14_split : hodgeB 14 [1, 3, 5, 9, 11, 13] [1, 9, 11, 7] = true ∧
    lsumN [1, 9, 11] % 14 = 7 := ⟨rfl, rfl⟩
theorem e14_reach : reach 14 [1, 3, 5, 9, 11, 13] 6 [1, 1, 9, 9, 11, 11] = true ∧
    reach 14 [1, 3, 5, 9, 11, 13] 6 [3, 3, 5, 5, 13, 13] = true := ⟨rfl, rfl⟩

def allReachFrom (m : Nat) (U : List Nat) (L a : Nat) : Bool :=
  (multis m L a).all (fun c => !(hodgeB m U (a :: c)) || reach m U (L + 1) (a :: c))

set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_6_1 : allReachFrom 12 [1, 5, 7, 11] 5 1 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_6_2 : allReachFrom 12 [1, 5, 7, 11] 5 2 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_6_3 : allReachFrom 12 [1, 5, 7, 11] 5 3 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_6_4 : allReachFrom 12 [1, 5, 7, 11] 5 4 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_6_5 : allReachFrom 12 [1, 5, 7, 11] 5 5 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_6_6 : allReachFrom 12 [1, 5, 7, 11] 5 6 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_6_7 : allReachFrom 12 [1, 5, 7, 11] 5 7 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_6_8 : allReachFrom 12 [1, 5, 7, 11] 5 8 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_6_9 : allReachFrom 12 [1, 5, 7, 11] 5 9 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_6_10 : allReachFrom 12 [1, 5, 7, 11] 5 10 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_6_11 : allReachFrom 12 [1, 5, 7, 11] 5 11 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_8_1 : allReachFrom 12 [1, 5, 7, 11] 7 1 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_8_2 : allReachFrom 12 [1, 5, 7, 11] 7 2 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_8_3 : allReachFrom 12 [1, 5, 7, 11] 7 3 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_8_4 : allReachFrom 12 [1, 5, 7, 11] 7 4 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_8_5 : allReachFrom 12 [1, 5, 7, 11] 7 5 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_8_6 : allReachFrom 12 [1, 5, 7, 11] 7 6 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_8_7 : allReachFrom 12 [1, 5, 7, 11] 7 7 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_8_8 : allReachFrom 12 [1, 5, 7, 11] 7 8 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_8_9 : allReachFrom 12 [1, 5, 7, 11] 7 9 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_8_10 : allReachFrom 12 [1, 5, 7, 11] 7 10 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach12_8_11 : allReachFrom 12 [1, 5, 7, 11] 7 11 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_1 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 1 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_2 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 2 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_3 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 3 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_4 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 4 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_5 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 5 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_6 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 6 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_7 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 7 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_8 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 8 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_9 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 9 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_10 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 10 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_11 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 11 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_12 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 12 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_6_13 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 5 13 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_1 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 1 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_2 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 2 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_3 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 3 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_4 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 4 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_5 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 5 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_6 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 6 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_7 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 7 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_8 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 8 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_9 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 9 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_10 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 10 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_11 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 11 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_12 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 12 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach14_8_13 : allReachFrom 14 [1, 3, 5, 9, 11, 13] 7 13 = true := rfl

end FermatInductive

#print axioms FermatInductive.e14_split
#print axioms FermatInductive.e14_reach
#print axioms FermatInductive.reach12_6_1
#print axioms FermatInductive.reach12_6_2
#print axioms FermatInductive.reach12_6_3
#print axioms FermatInductive.reach12_6_4
#print axioms FermatInductive.reach12_6_5
#print axioms FermatInductive.reach12_6_6
#print axioms FermatInductive.reach12_6_7
#print axioms FermatInductive.reach12_6_8
#print axioms FermatInductive.reach12_6_9
#print axioms FermatInductive.reach12_6_10
#print axioms FermatInductive.reach12_6_11
#print axioms FermatInductive.reach12_8_1
#print axioms FermatInductive.reach12_8_2
#print axioms FermatInductive.reach12_8_3
#print axioms FermatInductive.reach12_8_4
#print axioms FermatInductive.reach12_8_5
#print axioms FermatInductive.reach12_8_6
#print axioms FermatInductive.reach12_8_7
#print axioms FermatInductive.reach12_8_8
#print axioms FermatInductive.reach12_8_9
#print axioms FermatInductive.reach12_8_10
#print axioms FermatInductive.reach12_8_11
#print axioms FermatInductive.reach14_6_1
#print axioms FermatInductive.reach14_6_2
#print axioms FermatInductive.reach14_6_3
#print axioms FermatInductive.reach14_6_4
#print axioms FermatInductive.reach14_6_5
#print axioms FermatInductive.reach14_6_6
#print axioms FermatInductive.reach14_6_7
#print axioms FermatInductive.reach14_6_8
#print axioms FermatInductive.reach14_6_9
#print axioms FermatInductive.reach14_6_10
#print axioms FermatInductive.reach14_6_11
#print axioms FermatInductive.reach14_6_12
#print axioms FermatInductive.reach14_6_13
#print axioms FermatInductive.reach14_8_1
#print axioms FermatInductive.reach14_8_2
#print axioms FermatInductive.reach14_8_3
#print axioms FermatInductive.reach14_8_4
#print axioms FermatInductive.reach14_8_5
#print axioms FermatInductive.reach14_8_6
#print axioms FermatInductive.reach14_8_7
#print axioms FermatInductive.reach14_8_8
#print axioms FermatInductive.reach14_8_9
#print axioms FermatInductive.reach14_8_10
#print axioms FermatInductive.reach14_8_11
#print axioms FermatInductive.reach14_8_12
#print axioms FermatInductive.reach14_8_13

81.12 Picard numbers of Fermat surfaces

For \(\gcd (m,6)=1\) and \(m\le 31\) the Fermat surface \(X_m^2\) has exactly

\[ \#\{\text {Hodge characters}\}=3(m-1)(m-2),\qquad \rho (X_m^2)=3(m-1)(m-2)+1 , \]
counted over ordered characters by rfl. For \(2\mid m\) or \(3\mid m\) there are more (\(m=6\): \(85\) against \(60\); \(m=12\): \(643\) against \(330\)), the correction terms of Aoki–Shioda.

Listing 236: hodge/SurfaceCount.lean

hodge/SurfaceCount.lean

/-
  hodge/SurfaceCount.lean — T41 cycle 98: the number of Hodge characters of the Fermat surface X_m^2 for
  gcd(m, 6) = 1, m ≤ 31: exactly 3(m − 1)(m − 2) — Aoki–Shioda's Picard number ρ(X_m^2) = 3(m−1)(m−2) + 1
  (the +1 is the hyperplane class). Counted over ordered characters (a₀, a₁, a₂, a₃), aᵢ ∈ [1, m), Σaᵢ ≡ 0,
  by rfl (compiled on Kamiak).
-/
import hodge.StdAll

namespace SurfaceCount
open FermatGens StdAll

def isH (m : Nat) (U : List Nat) (a b c : Nat) : Nat :=
  let d := (m * m * 3 - (a + b + c)) % m
  if d = 0 then 0 else if hodgeB m U [a, b, c, d] then 1 else 0

def count (m : Nat) : Nat :=
  let U := units m
  (List.range m).foldl (fun s a => (List.range m).foldl (fun s b => (List.range m).foldl (fun s c =>
    if a = 0 ∨ b = 0 ∨ c = 0 then s else s + isH m U a b c) s) s) 0

set_option maxRecDepth 1000000 in
set_option maxHeartbeats 0 in
theorem count_5 : count 5 = 3 * (5 - 1) * (5 - 2) := rfl
set_option maxRecDepth 1000000 in
set_option maxHeartbeats 0 in
theorem count_7 : count 7 = 3 * (7 - 1) * (7 - 2) := rfl
set_option maxRecDepth 1000000 in
set_option maxHeartbeats 0 in
theorem count_11 : count 11 = 3 * (11 - 1) * (11 - 2) := rfl
set_option maxRecDepth 1000000 in
set_option maxHeartbeats 0 in
theorem count_13 : count 13 = 3 * (13 - 1) * (13 - 2) := rfl
set_option maxRecDepth 1000000 in
set_option maxHeartbeats 0 in
theorem count_17 : count 17 = 3 * (17 - 1) * (17 - 2) := rfl
set_option maxRecDepth 1000000 in
set_option maxHeartbeats 0 in
theorem count_19 : count 19 = 3 * (19 - 1) * (19 - 2) := rfl
set_option maxRecDepth 1000000 in
set_option maxHeartbeats 0 in
theorem count_23 : count 23 = 3 * (23 - 1) * (23 - 2) := rfl
set_option maxRecDepth 1000000 in
set_option maxHeartbeats 0 in
theorem count_25 : count 25 = 3 * (25 - 1) * (25 - 2) := rfl
set_option maxRecDepth 1000000 in
set_option maxHeartbeats 0 in
theorem count_29 : count 29 = 3 * (29 - 1) * (29 - 2) := rfl
set_option maxRecDepth 1000000 in
set_option maxHeartbeats 0 in
theorem count_31 : count 31 = 3 * (31 - 1) * (31 - 2) := rfl

end SurfaceCount

#print axioms SurfaceCount.count_5
#print axioms SurfaceCount.count_7
#print axioms SurfaceCount.count_11
#print axioms SurfaceCount.count_13
#print axioms SurfaceCount.count_17
#print axioms SurfaceCount.count_19
#print axioms SurfaceCount.count_23
#print axioms SurfaceCount.count_25
#print axioms SurfaceCount.count_29
#print axioms SurfaceCount.count_31

81.13 Standard characters are Hodge for every \(m\)

Let \(m=dq\) with \(d\ge 2\), let \(t\) be a unit modulo \(d\) (\(tt'\equiv 1\)), \(a\) with \(q\nmid ta\), and \(c\equiv -da\pmod m\). Write \(\langle ta\rangle _m=r+sq\) with \(0<r<q\). Then

\[ 2\Bigl (\sum _{k<d}\bigl \langle t(a+kq)\bigr \rangle _m+\langle tc\rangle _m\Bigr )=(d+1)\,m . \]
\begin{align*} &\langle t(a+kq)\rangle _m=\langle x+\langle tk\rangle _d\,q\rangle _m,\quad x=\langle ta\rangle _m &&\text {(division of $tk$ by $d$)}\\ &\textstyle \sum _{k<d}f(\langle tk\rangle _d)=\sum _{j<d}f(j) &&\text {(inverse $j\mapsto \langle t'j\rangle _d$)}\\ &\textstyle \sum _{j<d}\langle x+jq\rangle _m=\sum _{j<d}(r+jq)=dr+q\sum _{j<d}j &&\text {(rotation $j\mapsto \langle s+j\rangle _d$)}\\ &\langle tc\rangle _m+dr=m &&\text {($\equiv t(c+da)\equiv 0$, between $0$ and $2m$)}\\ &\textstyle 2\sum _{j<d}j+d=d^2 && \end{align*}

Listing 237: hodge/Reindex.lean

hodge/Reindex.lean

/-
  hodge/Reindex.lean — T41 cycle 102: reindexing a finite Nat sum by a bijection given with its inverse
  (piece 1 of the general proof that standard characters are Hodge).

  Lean 4 core plus ESChain (eqI, sum_eqI, b2n), FrobChain (sumTo, sum_ext), bsd/CubeCount (sum_swap).
    reindex   σ, τ : [0, n) → [0, n), τ(σ k) = k, σ(τ j) = j  ⇒  Σ_{k<n} f(σ k) = Σ_{j<n} f j
  Proof: f(σ k) = Σ_j [σ k = j] f j, exchange the sums, and Σ_k [σ k = j] = 1 (the unique k is τ j).
-/
import bsd.CubeCount

namespace Reindex
open FTAChain FrobChain QRChain ESChain CubeCount

theorem pick (n : Nat) (f : Nat → Nat) (i : Nat) (hi : i < n) :
    sumTo n (fun j => eqI i j * f j) = f i := by
  have e : ∀ j, eqI i j * f j = eqI j i * f i := by
    intro j
    unfold eqI
    match Nat.decEq i j with
    | isTrue h => rw [ite_eq_left h, ite_eq_left h.symm, h]
    | isFalse h => rw [ite_eq_right h, ite_eq_right (fun e => h e.symm), Nat.zero_mul, Nat.zero_mul]
  rw [sum_ext _ _ _ (fun j _ => e j), ← sum_mul, sum_eqI i n hi, Nat.one_mul]

theorem reindex (n : Nat) (f σ τ : Nat → Nat) (hσ : ∀ k, k < n → σ k < n) (hτ : ∀ j, j < n → τ j < n)
    (h1 : ∀ k, k < n → τ (σ k) = k) (h2 : ∀ j, j < n → σ (τ j) = j) :
    sumTo n (fun k => f (σ k)) = sumTo n f := by
  have e1 : sumTo n (fun k => f (σ k)) = sumTo n (fun k => sumTo n (fun j => eqI (σ k) j * f j)) :=
    sum_ext _ _ _ (fun k hk => (pick n f (σ k) (hσ k hk)).symm)
  rw [e1, sum_swap]
  apply sum_ext; intro j hj
  -- Σ_k [σ k = j] f j = f j
  have e2 : ∀ k, k < n → eqI (σ k) j * f j = eqI k (τ j) * f j := by
    intro k hk
    unfold eqI
    match Nat.decEq (σ k) j with
    | isTrue h =>
      have : k = τ j := by rw [← h1 k hk, h]
      rw [ite_eq_left h, ite_eq_left this]
    | isFalse h =>
      have : ¬ k = τ j := fun e => h (by rw [e, h2 j hj])
      rw [ite_eq_right h, ite_eq_right this]
  rw [sum_ext _ _ _ e2, ← sum_mul, sum_eqI (τ j) n (hτ j hj), Nat.one_mul]

end Reindex

#print axioms Reindex.pick
#print axioms Reindex.reindex

Listing 238: hodge/StdSum.lean

hodge/StdSum.lean

/-
  hodge/StdSum.lean — T41 cycle 103: piece 2 of "standard characters are Hodge for every m".

  Lean 4 core plus hodge/Reindex, FTAChain/QRChain rem lemmas, lib/Semi. With d = d′+1, q = q′+1,
  m = dq and x = r + sq (r < q):
    point      ⟨x + jq⟩_m = r + ⟨s + j⟩_d · q
    rot_sum    Σ_{j<d} ⟨x + jq⟩_m = Σ_{j<d} (r + jq)        (j ↦ ⟨s + j⟩_d is a bijection, inverse ⟨j + d′s⟩_d)
-/
import hodge.Reindex
import lib.Semi

namespace StdSum
open FTAChain FrobChain QRChain ESChain Reindex

theorem point (d' q' r s j : Nat) (hr : r < q' + 1) :
    rem ((d' + 1) * (q' + 1)) (r + s * (q' + 1) + j * (q' + 1)) = r + rem (d' + 1) (s + j) * (q' + 1) := by
  have ⟨c, ρ, k, hsj, hρ, hrem⟩ := rem_spec d' (s + j)
  have hM : (d' + 1) * (q' + 1) = (d' * (q' + 1) + q') + 1 := by lib_nat
  have e : r + s * (q' + 1) + j * (q' + 1) = c * ((d' * (q' + 1) + q') + 1) + (r + ρ * (q' + 1)) := by
    have : r + s * (q' + 1) + j * (q' + 1) = r + (s + j) * (q' + 1) := by lib_nat
    rw [this, hsj]; lib_nat
  rw [hM, e, rem_add_mul, hrem]
  apply rem_of_lt
  -- r + ρ(q'+1) < (d'+1)(q'+1): ρ ≤ d'
  have hρd : ρ + 1 ≤ d' + 1 := by rw [← hρ]; exact Nat.add_le_add_left (Nat.succ_le_succ (Nat.zero_le k)) ρ
  have b1 : r + ρ * (q' + 1) < (ρ + 1) * (q' + 1) := by
    rw [show (ρ + 1) * (q' + 1) = ρ * (q' + 1) + (q' + 1) by lib_nat, Nat.add_comm r]
    exact Nat.add_lt_add_left hr _
  have b2 : (ρ + 1) * (q' + 1) ≤ (d' + 1) * (q' + 1) := Nat.mul_le_mul_right _ hρd
  rw [← hM]; exact Nat.lt_of_lt_of_le b1 b2

theorem rot_sum (d' q' r s : Nat) (hr : r < q' + 1) :
    sumTo (d' + 1) (fun j => rem ((d' + 1) * (q' + 1)) (r + s * (q' + 1) + j * (q' + 1)))
      = sumTo (d' + 1) (fun j => r + j * (q' + 1)) := by
  rw [sum_ext _ _ (fun j => (fun i => r + i * (q' + 1)) (rem (d' + 1) (s + j)))
    (fun j _ => point d' q' r s j hr)]
  apply reindex (d' + 1) (fun i => r + i * (q' + 1)) (fun j => rem (d' + 1) (s + j))
    (fun j => rem (d' + 1) (j + d' * s))
  · intro k _; exact rem_lt' d' _
  · intro j _; exact rem_lt' d' _
  · intro k hk
    show rem (d' + 1) (rem (d' + 1) (s + k) + d' * s) = k
    rw [rem_add_congr d' _ (s + k) _ (rem_idem d' _),
      show s + k + d' * s = s * (d' + 1) + k by lib_nat, rem_add_mul, rem_of_lt _ _ hk]
  · intro j hj
    show rem (d' + 1) (s + rem (d' + 1) (j + d' * s)) = j
    rw [rem_add_congr' d' _ (j + d' * s) s (rem_idem d' _),
      show s + (j + d' * s) = s * (d' + 1) + j by lib_nat, rem_add_mul, rem_of_lt _ _ hj]

end StdSum

#print axioms StdSum.point
#print axioms StdSum.rot_sum

Listing 239: hodge/StdGeneral.lean

hodge/StdGeneral.lean

/-
  hodge/StdGeneral.lean — T41 cycle 104: standard characters are Hodge, for every m (character half of
  Aoki–Shioda), in sum form.

  Lean 4 core plus hodge/StdSum, hodge/Reindex, lib/Semi. Let d = d′+1, q = q′+1, m = dq, t a unit mod d
  (t·t′ ≡ 1 mod d), a any, x = ⟨ta⟩_m written x = r + sq with 0 < r < q, and c ≡ −da (mod m). Then
      Σ_{k<d} ⟨t(a + kq)⟩_m + ⟨tc⟩_m = m + q·Σ_{j<d} j,     i.e.   2·T_t(std) = (d + 1)·m.
    shift_mod     ⟨x + (tk)q⟩_m = ⟨x + ⟨tk⟩_d q⟩_m
    t_sum         Σ_k ⟨t(a + kq)⟩_m = Σ_j (r + jq)
    neg_term      ⟨tc⟩_m = m − dr          (as: ⟨tc⟩_m + dr = m)
    std_hodge     the identity above;  std_hodge2: 2T = (d + 1)m
-/
import hodge.StdSum
import lib.Semi

namespace StdGeneral
open FTAChain FrobChain QRChain ESChain Reindex StdSum

theorem tsum_j (d' q' r : Nat) : sumTo (d' + 1) (fun j => r + j * (q' + 1))
    = (d' + 1) * r + (q' + 1) * sumTo (d' + 1) (fun j => j) := by
  have : ∀ n, sumTo n (fun j => r + j * (q' + 1)) = n * r + (q' + 1) * sumTo n (fun j => j) := by
    intro n; induction n with
    | zero => show 0 = 0 * r + (q' + 1) * 0; lib_nat
    | succ n ih =>
      show sumTo n (fun j => r + j * (q' + 1)) + (r + n * (q' + 1)) = (n + 1) * r + (q' + 1) * (sumTo n (fun j => j) + n)
      rw [ih]; lib_nat
  exact this _

theorem two_sum : ∀ n, sumTo n (fun j => j) + sumTo n (fun j => j) + n = n * n
  | 0 => rfl
  | n + 1 => by
    show sumTo n (fun j => j) + n + (sumTo n (fun j => j) + n) + (n + 1) = (n + 1) * (n + 1)
    have ih := two_sum n
    have e : sumTo n (fun j => j) + n + (sumTo n (fun j => j) + n) + (n + 1)
        = (sumTo n (fun j => j) + sumTo n (fun j => j) + n) + (n + n + 1) := by lib_nat
    rw [e, ih]; lib_nat

theorem shift_mod (d' q' x t k : Nat) :
    rem ((d' + 1) * (q' + 1)) (x + (t * k) * (q' + 1))
      = rem ((d' + 1) * (q' + 1)) (x + rem (d' + 1) (t * k) * (q' + 1)) := by
  have ⟨c, ρ, _, hk, _, hrem⟩ := rem_spec d' (t * k)
  have hM : (d' + 1) * (q' + 1) = (d' * (q' + 1) + q') + 1 := by lib_nat
  rw [hrem, hk, hM]
  rw [show x + (c * (d' + 1) + ρ) * (q' + 1) = c * ((d' * (q' + 1) + q') + 1) + (x + ρ * (q' + 1)) by lib_nat,
    rem_add_mul]

/-- The k-sum: Σ_k ⟨t(a + kq)⟩_m = Σ_j (r + jq). -/
theorem t_sum (d' q' t t' a r s : Nat) (hd : 0 < d') (ht : rem (d' + 1) (t' * t) = 1)
    (hx : rem ((d' + 1) * (q' + 1)) (t * a) = r + s * (q' + 1)) (hr : r < q' + 1) :
    sumTo (d' + 1) (fun k => rem ((d' + 1) * (q' + 1)) (t * (a + k * (q' + 1))))
      = sumTo (d' + 1) (fun j => r + j * (q' + 1)) := by
  have hM : (d' + 1) * (q' + 1) = (d' * (q' + 1) + q') + 1 := by lib_nat
  -- ⟨t(a + kq)⟩ = ⟨x + ⟨tk⟩_d q⟩ with x = ⟨ta⟩
  have p1 : ∀ k, rem ((d' + 1) * (q' + 1)) (t * (a + k * (q' + 1)))
      = (fun j => rem ((d' + 1) * (q' + 1)) (r + s * (q' + 1) + j * (q' + 1))) (rem (d' + 1) (t * k)) := by
    intro k
    show _ = rem ((d' + 1) * (q' + 1)) (r + s * (q' + 1) + rem (d' + 1) (t * k) * (q' + 1))
    rw [← hx, ← shift_mod d' q' _ t k, hM]
    rw [show t * (a + k * (q' + 1)) = t * a + (t * k) * (q' + 1) by lib_nat]
    exact rem_add_congr _ _ _ _ (rem_idem _ _).symm
  rw [sum_ext _ _ _ (fun k _ => p1 k)]
  refine (reindex (d' + 1) (fun j => rem ((d' + 1) * (q' + 1)) (r + s * (q' + 1) + j * (q' + 1))) (fun k => rem (d' + 1) (t * k)) (fun j => rem (d' + 1) (t' * j))
    (fun k _ => rem_lt' d' _) (fun j _ => rem_lt' d' _)
    (fun k hk => by
      show rem (d' + 1) (t' * rem (d' + 1) (t * k)) = k
      rw [rem_mul_congr' d' _ _ t' (rem_idem d' _), show t' * (t * k) = (t' * t) * k by lib_nat,
        rem_mul_congr d' _ 1 k (ht.trans (rem_one d' hd).symm), Nat.one_mul, rem_of_lt _ _ hk])
    (fun j hj => by
      show rem (d' + 1) (t * rem (d' + 1) (t' * j)) = j
      rw [rem_mul_congr' d' _ _ t (rem_idem d' _), show t * (t' * j) = (t' * t) * j by lib_nat,
        rem_mul_congr d' _ 1 j (ht.trans (rem_one d' hd).symm), Nat.one_mul, rem_of_lt _ _ hj])).trans ?_
  exact rot_sum d' q' r s hr

theorem sum_is_M (M' x y : Nat) (hx : x < M' + 1) (hy : y < M' + 1) (hy0 : 0 < y)
    (h : rem (M' + 1) (x + y) = 0) : x + y = M' + 1 := by
  cases dv_of_rem_zero _ _ h with
  | intro q hq =>
    match q, hq with
    | 0, hq => rw [Nat.zero_mul] at hq; exact absurd (Nat.eq_zero_of_add_eq_zero_left hq) (Nat.ne_of_gt hy0)
    | 1, hq => rw [hq, Nat.one_mul]
    | q + 2, hq =>
      have l : x + y < (M' + 1) + (M' + 1) := Nat.add_lt_add hx hy
      have g : (M' + 1) + (M' + 1) ≤ (q + 2) * (M' + 1) := by
        rw [show (q + 2) * (M' + 1) = q * (M' + 1) + ((M' + 1) + (M' + 1)) by lib_nat]; exact Nat.le_add_left _ _
      rw [hq] at l; exact absurd (Nat.lt_of_lt_of_le l g) (Nat.lt_irrefl _)

/-- ⟨tc⟩_m + d·r = m  for c ≡ −da. -/
theorem neg_term (d' q' t a c r s : Nat) (hc : rem ((d' + 1) * (q' + 1)) (c + (d' + 1) * a) = 0)
    (hx : rem ((d' + 1) * (q' + 1)) (t * a) = r + s * (q' + 1)) (hr : r < q' + 1) (hr0 : 0 < r) :
    rem ((d' + 1) * (q' + 1)) (t * c) + (d' + 1) * r = (d' + 1) * (q' + 1) := by
  have hM : (d' + 1) * (q' + 1) = (d' * (q' + 1) + q') + 1 := by lib_nat
  rw [hM] at hc hx ⊢
  -- rem(t d a) = rem(d r)
  have e1 : rem (d' * (q' + 1) + q' + 1) (t * ((d' + 1) * a)) = rem (d' * (q' + 1) + q' + 1) ((d' + 1) * r) := by
    rw [show t * ((d' + 1) * a) = (d' + 1) * (t * a) by lib_nat,
      rem_mul_congr' _ _ _ (d' + 1) (rem_idem _ (t * a)).symm, hx,
      show (d' + 1) * (r + s * (q' + 1)) = s * (d' * (q' + 1) + q' + 1) + (d' + 1) * r by lib_nat, rem_add_mul]
  have z : rem (d' * (q' + 1) + q' + 1) (t * c + (d' + 1) * r) = 0 := by
    rw [rem_add_congr' _ _ _ (t * c) e1.symm, show t * c + t * ((d' + 1) * a) = t * (c + (d' + 1) * a) by lib_nat,
      rem_mul_congr' _ _ _ t (rem_idem _ _).symm, hc, Nat.mul_zero]; rfl
  apply sum_is_M
  · exact rem_lt' _ _
  · rw [← hM]
    have : (d' + 1) * r < (d' + 1) * (q' + 1) := Nat.mul_lt_mul_of_pos_left hr (Nat.zero_lt_succ d')
    exact this
  · exact Nat.mul_pos (Nat.zero_lt_succ d') hr0
  · rw [rem_add_congr _ _ (t * c) _ (rem_idem _ _)]; exact z

/-- **Standard characters are Hodge, every m**:  2·(Σ_k ⟨t(a+kq)⟩_m + ⟨tc⟩_m) = (d + 1)·m. -/
theorem std_hodge (d' q' t t' a c r s : Nat) (hd : 0 < d') (ht : rem (d' + 1) (t' * t) = 1)
    (hc : rem ((d' + 1) * (q' + 1)) (c + (d' + 1) * a) = 0)
    (hx : rem ((d' + 1) * (q' + 1)) (t * a) = r + s * (q' + 1)) (hr : r < q' + 1) (hr0 : 0 < r) :
    2 * (sumTo (d' + 1) (fun k => rem ((d' + 1) * (q' + 1)) (t * (a + k * (q' + 1))))
        + rem ((d' + 1) * (q' + 1)) (t * c)) = (d' + 2) * ((d' + 1) * (q' + 1)) := by
  rw [t_sum d' q' t t' a r s hd ht hx hr, tsum_j]
  have n := neg_term d' q' t a c r s hc hx hr hr0
  have ts := two_sum (d' + 1)
  revert n ts
  generalize rem ((d' + 1) * (q' + 1)) (t * c) = X
  generalize sumTo (d' + 1) (fun j => j) = S
  intro n ts
  -- 2((d+1) r + q S + X) = 2(qS + m) since X + dr = m;  2qS = q(d² − d)
  have e : 2 * ((d' + 1) * r + (q' + 1) * S + X) = (q' + 1) * (S + S) + 2 * (X + (d' + 1) * r) := by lib_nat
  rw [e, n]
  apply add_left_cancel' ((q' + 1) * (d' + 1))
  have e3 : (q' + 1) * (d' + 1) + ((q' + 1) * (S + S) + 2 * ((d' + 1) * (q' + 1)))
      = (q' + 1) * (S + S + (d' + 1)) + 2 * ((d' + 1) * (q' + 1)) := by lib_nat
  rw [e3, ts]; lib_nat

end StdGeneral

#print axioms StdGeneral.tsum_j
#print axioms StdGeneral.two_sum
#print axioms StdGeneral.shift_mod
#print axioms StdGeneral.t_sum
#print axioms StdGeneral.sum_is_M
#print axioms StdGeneral.neg_term
#print axioms StdGeneral.std_hodge

81.14 A certified open case: \(m=33\)

The character \(c=(1,4,16,22,25,31)\) of \(X_{33}^4\) is Hodge, all its entries are \(\equiv 1\pmod 3\), it is not a standard character, and the inductive closure with standard base returns false on it (checked by rfl). Its algebraicity is not decided by the method.

Listing 240: hodge/Fermat33Open.lean

hodge/Fermat33Open.lean

/-
  hodge/Fermat33Open.lean — T41 cycle 113: the open characters of X_33^4 for the method.

  c = (1, 4, 16, 22, 25, 31) and its unit multiples: Hodge, every entry ≡ 1 (mod 3) (a twisted lift from
  X_11), not a standard character, and not reached by the inductive closure with standard base
  (reach returns false, rfl). Their algebraicity is open here.
-/
import hodge.Fermat32Open

namespace Fermat33Open
open FermatGens Fermat25Std Fermat32Open

def subs : List Nat → List (List Nat)
  | [] => [[]]
  | x :: l => (subs l).map (x :: ·) ++ subs l

def lsumN : List Nat → Nat
  | [] => 0
  | x :: l => x + lsumN l

def compl (c s : List Nat) : List Nat := (sub c s).getD []

/-- one split step, given the closure at smaller fuel -/
def splitOK (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c A : List Nat) : Bool :=
  let B := compl c A
  let s := lsumN A % m
  if Nat.beq s 0 then
    !A.isEmpty && !B.isEmpty && hodgeB m U A && hodgeB m U B && rec A && rec B
  else
    let A2 := (m - s) :: A
    let B2 := s :: B
    Nat.blt A2.length c.length && Nat.blt B2.length c.length &&
      hodgeB m U A2 && hodgeB m U B2 && rec A2 && rec B2

def anySplit (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c : List Nat) : List (List Nat) → Bool
  | [] => false
  | A :: As => splitOK m U rec c A || anySplit m U rec c As

def isStd (m : Nat) (c : List Nat) : Bool :=
  (List.range (m + 1)).any (fun d => Nat.blt 1 d && Nat.beq (m % d) 0 &&
    (List.range m).any (fun a => sameMS c (std m d a)))

def reach (m : Nat) (U : List Nat) : Nat → List Nat → Bool
  | 0, c => Nat.blt c.length 5 || isStd m c
  | f + 1, c => Nat.blt c.length 5 || isStd m c || anySplit m U (reach m U f) c (subs c)

def allReach (m : Nat) (U : List Nat) (L : Nat) : Bool :=
  (multis m L 1).all (fun c => !(hodgeB m U c) || reach m U L c)



def U33 : List Nat := [1, 2, 4, 5, 7, 8, 10, 13, 14, 16, 17, 19, 20, 23, 25, 26, 28, 29, 31, 32]
def c33 : List Nat := [1, 4, 16, 22, 25, 31]

theorem c33_hodge : hodgeB 33 U33 c33 = true := rfl
theorem c33_mod3 : c33.all (fun x => Nat.beq (x % 3) 1) = true := rfl
theorem c33_not_std : isStd 33 c33 = false := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem c33_not_reached : reach 33 U33 6 c33 = false := rfl

end Fermat33Open

#print axioms Fermat33Open.c33_hodge
#print axioms Fermat33Open.c33_mod3
#print axioms Fermat33Open.c33_not_std
#print axioms Fermat33Open.c33_not_reached

81.15 Galois orbits

For every \(m\) and units \(s,t\): \(\langle s\langle tx\rangle _m\rangle _m=\langle stx\rangle _m\), hence \(T_s(t\cdot c)=T_{st}(c)\) and the unit multiples of a Hodge character are Hodge.

Listing 241: hodge/GaloisOrbit.lean

hodge/GaloisOrbit.lean

/-
  hodge/GaloisOrbit.lean — T41 cycle 118: Hodge characters are closed under the Galois action, every m.

  Lean 4 core plus hodge/FermatGens (tsum), ESChain (rem_eq_mod), QRChain (rem lemmas).
    mul_mod      ⟨s·⟨t·x⟩_m⟩_m = ⟨(s t)·x⟩_m
    tsum_twist   T_s(t·c) = T_{st}(c)        (t·c = (⟨t c_i⟩_m)_i)
    twist_hodge  2T_{st}(c) = |c| m  ⇒  2T_s(t·c) = |t·c| m
  Since st runs over the units when s does (t a unit), the unit multiples of a Hodge character are Hodge:
  every statement about one character of an orbit holds for the whole orbit (used implicitly in the
  reach measurements and in Fermat25Std.std_orbit).
-/
import hodge.Pullback

namespace GaloisOrbit
open FTAChain FrobChain QRChain ESChain FermatGens Pullback

def twist (m t : Nat) (c : List Nat) : List Nat := c.map (fun x => (t * x) % m)

theorem mul_mod (m' s t x : Nat) :
    (s * ((t * x) % (m' + 1))) % (m' + 1) = ((s * t) * x) % (m' + 1) := by
  rw [← rem_eq_mod, ← rem_eq_mod, ← rem_eq_mod]
  rw [rem_mul_congr' m' _ _ s (rem_idem m' _), show s * (t * x) = s * t * x from (nmul_assoc s t x).symm]

theorem tsum_twist (m' s t : Nat) : ∀ c : List Nat,
    tsum (m' + 1) s (twist (m' + 1) t c) = tsum (m' + 1) (s * t) c
  | [] => rfl
  | x :: c => by
    show (s * ((t * x) % (m' + 1))) % (m' + 1) + tsum (m' + 1) s (twist (m' + 1) t c)
      = ((s * t) * x) % (m' + 1) + tsum (m' + 1) (s * t) c
    rw [mul_mod, tsum_twist m' s t c]

theorem twist_hodge (m' s t : Nat) (c : List Nat)
    (h : tsum (m' + 1) (s * t) c + tsum (m' + 1) (s * t) c = c.length * (m' + 1)) :
    tsum (m' + 1) s (twist (m' + 1) t c) + tsum (m' + 1) s (twist (m' + 1) t c)
      = (twist (m' + 1) t c).length * (m' + 1) := by
  unfold twist at *
  rw [len_map]
  have := tsum_twist m' s t c
  unfold twist at this
  rw [this]; exact h

end GaloisOrbit

#print axioms GaloisOrbit.mul_mod
#print axioms GaloisOrbit.tsum_twist
#print axioms GaloisOrbit.twist_hodge

81.16 \(m=25\) reached with standard characters

Every Hodge character of \(X_{25}^4\) is reached by the inductive structure with the standard characters as base. \(\forall c\in \mathrm {Hodge}(X_{25}^4):\ \mathrm {reach}(c)=\mathtt {true}\)

hodge/FermatInductive3m25.lean

/-
  hodge/FermatInductive3.lean — T41 cycle 110: inductive structure with the Aoki–Shioda standard characters
  as extra base (Hodge for every m: hodge/StdGeneral) covers every Hodge character of X_m^4 for the prime
  square m = 25 (split by smallest entry, rfl on Kamiak). Cycle half of both operations cited.
-/
import hodge.Fermat32Open

namespace FermatInductive3m25
open FermatGens Fermat25Std Fermat32Open

def subs : List Nat → List (List Nat)
  | [] => [[]]
  | x :: l => (subs l).map (x :: ·) ++ subs l

def lsumN : List Nat → Nat
  | [] => 0
  | x :: l => x + lsumN l

def compl (c s : List Nat) : List Nat := (sub c s).getD []

/-- one split step, given the closure at smaller fuel -/
def splitOK (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c A : List Nat) : Bool :=
  let B := compl c A
  let s := lsumN A % m
  if Nat.beq s 0 then
    !A.isEmpty && !B.isEmpty && hodgeB m U A && hodgeB m U B && rec A && rec B
  else
    let A2 := (m - s) :: A
    let B2 := s :: B
    Nat.blt A2.length c.length && Nat.blt B2.length c.length &&
      hodgeB m U A2 && hodgeB m U B2 && rec A2 && rec B2

def anySplit (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c : List Nat) : List (List Nat) → Bool
  | [] => false
  | A :: As => splitOK m U rec c A || anySplit m U rec c As

def isStd (m : Nat) (c : List Nat) : Bool :=
  (List.range (m + 1)).any (fun d => Nat.blt 1 d && Nat.beq (m % d) 0 &&
    (List.range m).any (fun a => sameMS c (std m d a)))

def reach (m : Nat) (U : List Nat) : Nat → List Nat → Bool
  | 0, c => Nat.blt c.length 5 || isStd m c
  | f + 1, c => Nat.blt c.length 5 || isStd m c || anySplit m U (reach m U f) c (subs c)

def allReach (m : Nat) (U : List Nat) (L : Nat) : Bool :=
  (multis m L 1).all (fun c => !(hodgeB m U c) || reach m U L c)


def allReachFrom (m : Nat) (U : List Nat) (L a : Nat) : Bool :=
  (multis m L a).all (fun c => !(hodgeB m U (a :: c)) || reach m U (L + 1) (a :: c))

set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_1 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 1 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_2 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 2 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_3 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 3 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_4 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 4 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_5 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 5 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_6 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 6 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_7 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 7 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_8 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 8 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_9 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 9 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_10 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 10 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_11 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 11 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_12 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 12 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_13 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 13 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_14 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 14 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_15 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 15 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_16 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 16 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_17 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 17 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_18 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 18 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_19 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 19 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_20 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 20 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_21 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 21 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_22 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 22 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_23 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 23 = true := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem reach25_24 : allReachFrom 25 [1, 2, 3, 4, 6, 7, 8, 9, 11, 12, 13, 14, 16, 17, 18, 19, 21, 22, 23, 24] 5 24 = true := rfl

end FermatInductive3m25

#print axioms FermatInductive3m25.reach25_1
#print axioms FermatInductive3m25.reach25_2
#print axioms FermatInductive3m25.reach25_3
#print axioms FermatInductive3m25.reach25_4
#print axioms FermatInductive3m25.reach25_5
#print axioms FermatInductive3m25.reach25_6
#print axioms FermatInductive3m25.reach25_7
#print axioms FermatInductive3m25.reach25_8
#print axioms FermatInductive3m25.reach25_9
#print axioms FermatInductive3m25.reach25_10
#print axioms FermatInductive3m25.reach25_11
#print axioms FermatInductive3m25.reach25_12
#print axioms FermatInductive3m25.reach25_13
#print axioms FermatInductive3m25.reach25_14
#print axioms FermatInductive3m25.reach25_15
#print axioms FermatInductive3m25.reach25_16
#print axioms FermatInductive3m25.reach25_17
#print axioms FermatInductive3m25.reach25_18
#print axioms FermatInductive3m25.reach25_19
#print axioms FermatInductive3m25.reach25_20
#print axioms FermatInductive3m25.reach25_21
#print axioms FermatInductive3m25.reach25_22
#print axioms FermatInductive3m25.reach25_23
#print axioms FermatInductive3m25.reach25_24

#print axioms: 24 theorems, no axioms.

81.17 A certified open case: \(m=62\)

The character \((1,31,33,35,39,47)\) of \(X_{62}^4\) is Hodge, not standard, and not reached by the closure. \(\mathrm {reach}_{62}(c)=\mathtt {false}\)

hodge/OpenCert62.lean

/-
  hodge/OpenCert62.lean — T41 cycle 135: the first twice-a-prime open case of the method, m = 62 = 2·31, n = 4:
  c = (1, 31, 33, 35, 39, 47) is Hodge, not standard, and the inductive closure with standard base returns false.
-/
import hodge.Fermat32Open

namespace OpenCert62
open FermatGens Fermat25Std Fermat32Open

def subs : List Nat → List (List Nat)
  | [] => [[]]
  | x :: l => (subs l).map (x :: ·) ++ subs l

def lsumN : List Nat → Nat
  | [] => 0
  | x :: l => x + lsumN l

def compl (c s : List Nat) : List Nat := (sub c s).getD []

/-- one split step, given the closure at smaller fuel -/
def splitOK (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c A : List Nat) : Bool :=
  let B := compl c A
  let s := lsumN A % m
  if Nat.beq s 0 then
    !A.isEmpty && !B.isEmpty && hodgeB m U A && hodgeB m U B && rec A && rec B
  else
    let A2 := (m - s) :: A
    let B2 := s :: B
    Nat.blt A2.length c.length && Nat.blt B2.length c.length &&
      hodgeB m U A2 && hodgeB m U B2 && rec A2 && rec B2

def anySplit (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c : List Nat) : List (List Nat) → Bool
  | [] => false
  | A :: As => splitOK m U rec c A || anySplit m U rec c As

def isStd (m : Nat) (c : List Nat) : Bool :=
  (List.range (m + 1)).any (fun d => Nat.blt 1 d && Nat.beq (m % d) 0 &&
    (List.range m).any (fun a => sameMS c (std m d a)))

def reach (m : Nat) (U : List Nat) : Nat → List Nat → Bool
  | 0, c => Nat.blt c.length 5 || isStd m c
  | f + 1, c => Nat.blt c.length 5 || isStd m c || anySplit m U (reach m U f) c (subs c)

def allReach (m : Nat) (U : List Nat) (L : Nat) : Bool :=
  (multis m L 1).all (fun c => !(hodgeB m U c) || reach m U L c)





def U62 : List Nat := [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 61]
def c62 : List Nat := [1, 31, 33, 35, 39, 47]
theorem c62_hodge : hodgeB 62 U62 c62 = true := rfl
theorem c62_not_std : isStd 62 c62 = false := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem c62_not_reached : reach 62 U62 6 c62 = false := rfl

end OpenCert62

#print axioms OpenCert62.c62_hodge
#print axioms OpenCert62.c62_not_std
#print axioms OpenCert62.c62_not_reached

#print axioms: 3 theorems, no axioms.

81.18 Reach of the method, \(n=4\), \(m\le 72\)

Hodge characters of \(X_m^4\) not reached by the inductive structure with standard characters (measured).

pict

81.19 Certified open cases: \(m=68,70\)

Two further characters of \(X_m^4\) are Hodge, not standard, and not reached by the closure. \(\mathrm {reach}_{68}(c_{68})=\mathrm {reach}_{70}(c_{70})=\mathtt {false}\)

hodge/OpenCerts2.lean

/-
  hodge/OpenCerts2.lean — T41 cycle 140: certified open characters for m = 68 = 4·17 and m = 70 = 2·5·7 (n = 4):
  Hodge, not standard, inductive closure with standard base false (rfl).
-/
import hodge.Fermat32Open

namespace OpenCerts2
open FermatGens Fermat25Std Fermat32Open

def subs : List Nat → List (List Nat)
  | [] => [[]]
  | x :: l => (subs l).map (x :: ·) ++ subs l

def lsumN : List Nat → Nat
  | [] => 0
  | x :: l => x + lsumN l

def compl (c s : List Nat) : List Nat := (sub c s).getD []

/-- one split step, given the closure at smaller fuel -/
def splitOK (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c A : List Nat) : Bool :=
  let B := compl c A
  let s := lsumN A % m
  if Nat.beq s 0 then
    !A.isEmpty && !B.isEmpty && hodgeB m U A && hodgeB m U B && rec A && rec B
  else
    let A2 := (m - s) :: A
    let B2 := s :: B
    Nat.blt A2.length c.length && Nat.blt B2.length c.length &&
      hodgeB m U A2 && hodgeB m U B2 && rec A2 && rec B2

def anySplit (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c : List Nat) : List (List Nat) → Bool
  | [] => false
  | A :: As => splitOK m U rec c A || anySplit m U rec c As

def isStd (m : Nat) (c : List Nat) : Bool :=
  (List.range (m + 1)).any (fun d => Nat.blt 1 d && Nat.beq (m % d) 0 &&
    (List.range m).any (fun a => sameMS c (std m d a)))

def reach (m : Nat) (U : List Nat) : Nat → List Nat → Bool
  | 0, c => Nat.blt c.length 5 || isStd m c
  | f + 1, c => Nat.blt c.length 5 || isStd m c || anySplit m U (reach m U f) c (subs c)

def allReach (m : Nat) (U : List Nat) (L : Nat) : Bool :=
  (multis m L 1).all (fun c => !(hodgeB m U c) || reach m U L c)





def U68 : List Nat := [1, 3, 5, 7, 9, 11, 13, 15, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 53, 55, 57, 59, 61, 63, 65, 67]
def c68 : List Nat := [1, 18, 35, 38, 52, 60]
theorem c68_hodge : hodgeB 68 U68 c68 = true := rfl
theorem c68_not_std : isStd 68 c68 = false := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem c68_not_reached : reach 68 U68 6 c68 = false := rfl
def U70 : List Nat := [1, 3, 9, 11, 13, 17, 19, 23, 27, 29, 31, 33, 37, 39, 41, 43, 47, 51, 53, 57, 59, 61, 67, 69]
def c70 : List Nat := [1, 6, 43, 45, 57, 58]
theorem c70_hodge : hodgeB 70 U70 c70 = true := rfl
theorem c70_not_std : isStd 70 c70 = false := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem c70_not_reached : reach 70 U70 6 c70 = false := rfl

end OpenCerts2

#print axioms OpenCerts2.c68_hodge
#print axioms OpenCerts2.c68_not_std
#print axioms OpenCerts2.c68_not_reached
#print axioms OpenCerts2.c70_hodge
#print axioms OpenCerts2.c70_not_std
#print axioms OpenCerts2.c70_not_reached

#print axioms: 6 theorems, no axioms.

81.20 Conjugation

The conjugate of a Hodge character is Hodge, for every \(m\). \(T_s(\bar c)+T_s(c)=|c|\,m\)

hodge/Conjugate.lean

/-
  hodge/Conjugate.lean — T41 cycle 147: Hodge characters are closed under complex conjugation, every m.

  Lean 4 core plus hodge/GaloisOrbit (twist, mul_mod), lib/Semi.
  Conjugation is the twist by m − 1 (≡ −1): ⟨s⟨(m−1)x⟩⟩ + ⟨sx⟩ = m when m ∤ sx, so
      T_s(c̄) + T_s(c) = |c|·m,   hence   2T_s(c) = |c|m  ⇒  2T_s(c̄) = |c|m
  (c̄ = (m−1)·c mod m; H^{p,q} ↔ H^{q,p}).
-/
import hodge.GaloisOrbit
import lib.Semi

namespace Conjugate
open FTAChain FrobChain QRChain ESChain FermatGens GaloisOrbit

theorem pair_gen (m' a b : Nat) (h0 : rem (m' + 1) (a + b) = 0) (hb : ¬ Dv (m' + 1) b) :
    a % (m' + 1) + b % (m' + 1) = m' + 1 := by
  rw [← rem_eq_mod, ← rem_eq_mod]
  have hx := rem_lt' m' a
  have hy := rem_lt' m' b
  have z : rem (m' + 1) (rem (m' + 1) a + rem (m' + 1) b) = 0 := by
    rw [rem_add_congr2 m' _ a _ b (rem_idem m' _) (rem_idem m' _)]; exact h0
  have hy0 : rem (m' + 1) b ≠ 0 := fun e => hb (dv_of_rem_zero _ _ e)
  cases dv_of_rem_zero _ _ z with
  | intro q hq =>
    match q, hq with
    | 0, hq => rw [Nat.zero_mul] at hq; exact absurd (Nat.eq_zero_of_add_eq_zero_left hq) hy0
    | 1, hq => rw [hq, Nat.one_mul]
    | q + 2, hq =>
      have l : rem (m' + 1) a + rem (m' + 1) b < (m' + 1) + (m' + 1) := Nat.add_lt_add hx hy
      have g : (m' + 1) + (m' + 1) ≤ (q + 2) * (m' + 1) := by
        rw [show (q + 2) * (m' + 1) = q * (m' + 1) + ((m' + 1) + (m' + 1)) by lib_nat]; exact Nat.le_add_left _ _
      rw [hq] at l; exact absurd (Nat.lt_of_lt_of_le l g) (Nat.lt_irrefl _)

def nz (m s : Nat) : List Nat → Prop
  | [] => True
  | x :: c => ¬ Dv m (s * x) ∧ nz m s c

theorem conj_sum (m' s : Nat) : ∀ c : List Nat, nz (m' + 1) s c →
    tsum (m' + 1) s (twist (m' + 1) m' c) + tsum (m' + 1) s c = c.length * (m' + 1)
  | [], _ => by show 0 + 0 = 0 * (m' + 1); rw [Nat.zero_mul]
  | x :: c, ⟨hx, hc⟩ => by
    have ih := conj_sum m' s c hc
    show (s * ((m' * x) % (m' + 1))) % (m' + 1) + tsum (m' + 1) s (twist (m' + 1) m' c)
        + ((s * x) % (m' + 1) + tsum (m' + 1) s c) = (c.length + 1) * (m' + 1)
    rw [mul_mod]
    have p := pair_gen m' (s * m' * x) (s * x) (by
      apply rem_zero_of_dv; exact ⟨s * x, by lib_nat⟩) hx
    have e : (s * m' * x) % (m' + 1) + tsum (m' + 1) s (twist (m' + 1) m' c) + ((s * x) % (m' + 1) + tsum (m' + 1) s c)
        = ((s * m' * x) % (m' + 1) + (s * x) % (m' + 1)) + (tsum (m' + 1) s (twist (m' + 1) m' c) + tsum (m' + 1) s c) := by
      lib_nat
    rw [e, p, ih]; lib_nat

/-- **Conjugation preserves the Hodge condition.** -/
theorem conj_hodge (m' s : Nat) (c : List Nat) (hnz : nz (m' + 1) s c)
    (h : tsum (m' + 1) s c + tsum (m' + 1) s c = c.length * (m' + 1)) :
    tsum (m' + 1) s (twist (m' + 1) m' c) + tsum (m' + 1) s (twist (m' + 1) m' c) = c.length * (m' + 1) := by
  have cs := conj_sum m' s c hnz
  apply add_left_cancel' (tsum (m' + 1) s c + tsum (m' + 1) s c)
  have e : tsum (m' + 1) s c + tsum (m' + 1) s c
      + (tsum (m' + 1) s (twist (m' + 1) m' c) + tsum (m' + 1) s (twist (m' + 1) m' c))
      = (tsum (m' + 1) s (twist (m' + 1) m' c) + tsum (m' + 1) s c)
        + (tsum (m' + 1) s (twist (m' + 1) m' c) + tsum (m' + 1) s c) := by lib_nat
  rw [e, cs, h]

end Conjugate

#print axioms Conjugate.pair_gen
#print axioms Conjugate.conj_sum
#print axioms Conjugate.conj_hodge

#print axioms: 3 theorems, no axioms.

81.21 Certified open cases: \(m=76,78\)

Two further characters of \(X_m^4\) are Hodge, not standard, and not reached by the closure. \(\mathrm {reach}_{76}(c_{76})=\mathrm {reach}_{78}(c_{78})=\mathtt {false}\)

hodge/OpenCerts3.lean

/-
  hodge/OpenCerts3.lean — T41 cycle 150: certified open characters for m = 76 = 4·19 and m = 78 = 2·3·13 (n = 4):
  Hodge, not standard, inductive closure with standard base false (rfl).
-/
import hodge.Fermat32Open

namespace OpenCerts3
open FermatGens Fermat25Std Fermat32Open

def subs : List Nat → List (List Nat)
  | [] => [[]]
  | x :: l => (subs l).map (x :: ·) ++ subs l

def lsumN : List Nat → Nat
  | [] => 0
  | x :: l => x + lsumN l

def compl (c s : List Nat) : List Nat := (sub c s).getD []

/-- one split step, given the closure at smaller fuel -/
def splitOK (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c A : List Nat) : Bool :=
  let B := compl c A
  let s := lsumN A % m
  if Nat.beq s 0 then
    !A.isEmpty && !B.isEmpty && hodgeB m U A && hodgeB m U B && rec A && rec B
  else
    let A2 := (m - s) :: A
    let B2 := s :: B
    Nat.blt A2.length c.length && Nat.blt B2.length c.length &&
      hodgeB m U A2 && hodgeB m U B2 && rec A2 && rec B2

def anySplit (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c : List Nat) : List (List Nat) → Bool
  | [] => false
  | A :: As => splitOK m U rec c A || anySplit m U rec c As

def isStd (m : Nat) (c : List Nat) : Bool :=
  (List.range (m + 1)).any (fun d => Nat.blt 1 d && Nat.beq (m % d) 0 &&
    (List.range m).any (fun a => sameMS c (std m d a)))

def reach (m : Nat) (U : List Nat) : Nat → List Nat → Bool
  | 0, c => Nat.blt c.length 5 || isStd m c
  | f + 1, c => Nat.blt c.length 5 || isStd m c || anySplit m U (reach m U f) c (subs c)

def allReach (m : Nat) (U : List Nat) (L : Nat) : Bool :=
  (multis m L 1).all (fun c => !(hodgeB m U c) || reach m U L c)





def U76 : List Nat := [1, 3, 5, 7, 9, 11, 13, 15, 17, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 59, 61, 63, 65, 67, 69, 71, 73, 75]
def c76 : List Nat := [1, 20, 39, 42, 58, 68]
theorem c76_hodge : hodgeB 76 U76 c76 = true := rfl
set_option maxRecDepth 100000 in
theorem c76_not_std : isStd 76 c76 = false := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem c76_not_reached : reach 76 U76 6 c76 = false := rfl
def U78 : List Nat := [1, 5, 7, 11, 17, 19, 23, 25, 29, 31, 35, 37, 41, 43, 47, 49, 53, 55, 59, 61, 67, 71, 73, 77]
def c78 : List Nat := [1, 6, 12, 64, 75, 76]
theorem c78_hodge : hodgeB 78 U78 c78 = true := rfl
set_option maxRecDepth 100000 in
theorem c78_not_std : isStd 78 c78 = false := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem c78_not_reached : reach 78 U78 6 c78 = false := rfl

end OpenCerts3

#print axioms OpenCerts3.c76_hodge
#print axioms OpenCerts3.c76_not_std
#print axioms OpenCerts3.c76_not_reached
#print axioms OpenCerts3.c78_hodge
#print axioms OpenCerts3.c78_not_std
#print axioms OpenCerts3.c78_not_reached

#print axioms: 6 theorems, no axioms.

81.22 Pair cancellation

Removing a Hodge block, in particular a complementary pair \([b,m-b]\), keeps the Hodge condition, every \(m\). \(a\mathbin {+\!\!+}b,\ b\ \text {Hodge}\Rightarrow a\ \text {Hodge}\)

hodge/PairCancel.lean

/-
  hodge/PairCancel.lean — T41 cycle 153: cancelling a Hodge block, every m, every dimension.

  Lean 4 core plus hodge/HodgeIff (lsumL_append, pair_hodge).
    cancel_right   a ++ b Hodge and b Hodge  ⇒  a Hodge
    cancel_left    b ++ a Hodge and b Hodge  ⇒  a Hodge
    pair_cancel    a ++ [b, m − b] Hodge (t·b ≢ 0 for every unit t)  ⇒  a Hodge
  Reading: an open character that contains a complementary pair reduces to a Hodge character two
  dimensions lower; with hodge_append the reduction is reversible, so open cases are pair-free up to a
  smaller open case.
-/
import hodge.HodgeIff

namespace PairCancel
open FTAChain FrobChain QRChain ESChain FermatPrime FermatFull HodgeChain HodgeIff

theorem cancel_right (m : Nat) (a b : List Nat) (hab : HodgeList m (a ++ b)) (hb : HodgeList m b) :
    HodgeList m a := by
  intro t ht
  have e := hab t ht
  rw [lsumL_append, lsumL_append, hb t ht] at e
  exact QRChain.add_right_cancel' _ _ _ e

theorem cancel_left (m : Nat) (a b : List Nat) (hab : HodgeList m (b ++ a)) (hb : HodgeList m b) :
    HodgeList m a := by
  intro t ht
  have e := hab t ht
  rw [lsumL_append, lsumL_append, hb t ht] at e
  exact QRChain.add_left_cancel' _ _ _ e

/-- **Removing a complementary pair keeps the Hodge condition.** -/
theorem pair_cancel (m' b : Nat) (a : List Nat) (hb : b ≤ m' + 1)
    (hnz : ∀ t, t ∈ FermatPrime.units (m' + 1) → rem (m' + 1) (t * b) ≠ 0)
    (h : HodgeList (m' + 1) (a ++ [b, m' + 1 - b])) : HodgeList (m' + 1) a :=
  cancel_right (m' + 1) a _ h (pair_hodge m' b hb hnz)

end PairCancel

#print axioms PairCancel.cancel_right
#print axioms PairCancel.cancel_left
#print axioms PairCancel.pair_cancel

#print axioms: 3 theorems, no axioms.

81.23 Descent

The converse of the pullback: \(e\cdot c\) is Hodge on \(X_m\) only if \(c\) is Hodge on \(X_{m/e}\), every \(m\). \(2T^{(m)}_t(e c)=|c|m\Rightarrow 2T^{(m/e)}_t(c)=|c|m/e\)

hodge/Descent.lean

/-
  hodge/Descent.lean — T41 cycle 156: descent of the Hodge condition along X_m → X_{m′}, every m.

  Lean 4 core plus hodge/Pullback (tsum_scale, len_map), QRChain (add_right_cancel'), lib/Semi.
    mul_cancel     k·A = k·B, k ≥ 1  ⇒  A = B   (by hand; Nat.eq_of_mul_eq_mul_left avoided)
    descent        2T^{(m)}_t(e·c) = |c|·m  ⇒  2T^{(m′)}_t(c) = |c|·m′      (m = e·m′)
  With Pullback.pull_hodge: e·c is a Hodge character of X_m iff c is one of X_{m′}, twist by twist.
  Reading: an open character of X_m with all entries divisible by e comes from an open character of
  X_{m/e}; the certified open cases (m = 32 … 78) all contain the entry 1, so none is a pullback.
-/
import hodge.Pullback

namespace Descent
open FTAChain FrobChain QRChain ESChain FermatGens Pullback

theorem mul_cancel (e' : Nat) : ∀ A B : Nat, (e' + 1) * A = (e' + 1) * B → A = B
  | 0, 0, _ => rfl
  | 0, B + 1, h => by
      have h' : 0 = (e' + 1) * B + e' + 1 := h
      exact Nat.noConfusion h'
  | A + 1, 0, h => by
      have h' : (e' + 1) * A + e' + 1 = 0 := h
      exact Nat.noConfusion h'
  | A + 1, B + 1, h => by
      have h' : (e' + 1) * A + (e' + 1) = (e' + 1) * B + (e' + 1) := h
      have := mul_cancel e' A B (add_right_cancel' _ _ _ h')
      rw [this]

/-- **Descent of a Hodge character.** -/
theorem descent (e' m' t : Nat) (c : List Nat)
    (h : tsum ((e' + 1) * (m' + 1)) t (c.map (fun x => (e' + 1) * x))
      + tsum ((e' + 1) * (m' + 1)) t (c.map (fun x => (e' + 1) * x))
      = (c.map (fun x => (e' + 1) * x)).length * ((e' + 1) * (m' + 1))) :
    tsum (m' + 1) t c + tsum (m' + 1) t c = c.length * (m' + 1) := by
  rw [tsum_scale, len_map] at h
  apply mul_cancel e'
  have e1 : (e' + 1) * (tsum (m' + 1) t c + tsum (m' + 1) t c)
      = (e' + 1) * tsum (m' + 1) t c + (e' + 1) * tsum (m' + 1) t c := by lib_nat
  have e2 : (e' + 1) * (c.length * (m' + 1)) = c.length * ((e' + 1) * (m' + 1)) := by lib_nat
  rw [e1, e2]; exact h

end Descent

#print axioms Descent.mul_cancel
#print axioms Descent.descent

#print axioms: 2 theorems, no axioms.

81.24 The entry \(m/2\)

Every odd twist fixes \(m/2\), so this entry is neutral for the Hodge condition, every even \(m\). \(a\mathbin {+\!\!+}[m/2]\ \text {Hodge}\iff a\ \text {Hodge}\)

hodge/HalfEntry.lean

/-
  hodge/HalfEntry.lean — T41 cycle 159: the entry m/2 is neutral for the Hodge condition, every even m.

  Lean 4 core plus hodge/HodgeIff (lsumL_append), FTAChain (rem_add_mul), QRChain (rem_of_lt,
  add_right_cancel'), ESChain (rem_eq_mod), lib/Semi. With m = 2q:
    half_mod      t odd  ⇒  ⟨t q⟩_m = q          (every odd twist fixes the entry m/2)
    half_cancel   a ++ [q] Hodge  ⇒  a Hodge     (when every unit t has ⟨t q⟩ = q)
    half_append   a Hodge  ⇒  a ++ [q] Hodge
    half62        every unit of 62 fixes 31 (rfl)
  Reading: the open character (1, 31, 33, 35, 39, 47) of m = 62 is Hodge iff its five entries without 31 are
  balanced, i.e. the entry 31 = m/2 carries no Hodge information; the obstruction sits in the odd-length rest.
-/
import hodge.HodgeIff
import lib.Semi

namespace HalfEntry
open FTAChain FrobChain QRChain ESChain FermatPrime FermatFull HodgeChain HodgeIff

theorem half_mod (q' j : Nat) : ((j + j + 1) * (q' + 1)) % ((q' + q' + 1) + 1) = q' + 1 := by
  rw [← rem_eq_mod, show (j + j + 1) * (q' + 1) = j * ((q' + q' + 1) + 1) + (q' + 1) by lib_nat,
    rem_add_mul]
  exact rem_of_lt _ _ (by
    show q' + 1 < (q' + q' + 1) + 1
    exact Nat.succ_lt_succ (Nat.lt_succ_of_le (Nat.le_add_left q' q')))

theorem half_cancel (q' : Nat) (a : List Nat)
    (hfix : ∀ t, t ∈ FermatPrime.units ((q' + q' + 1) + 1) → (t * (q' + 1)) % ((q' + q' + 1) + 1) = q' + 1)
    (h : HodgeList ((q' + q' + 1) + 1) (a ++ [q' + 1])) : HodgeList ((q' + q' + 1) + 1) a := by
  intro t ht
  have e := h t ht
  rw [lsumL_append, lsumL_append] at e
  have e' : lsumL (fun i => 2 * (t * i % ((q' + q' + 1) + 1))) a + ((q' + q' + 1) + 1)
      = lsumL (fun _ => (q' + q' + 1) + 1) a + ((q' + q' + 1) + 1) := by
    have l : lsumL (fun i => 2 * (t * i % ((q' + q' + 1) + 1))) [q' + 1] = (q' + q' + 1) + 1 := by
      show 2 * (t * (q' + 1) % ((q' + q' + 1) + 1)) + 0 = (q' + q' + 1) + 1
      rw [hfix t ht]; lib_nat
    have r : lsumL (fun _ => (q' + q' + 1) + 1) [q' + 1] = (q' + q' + 1) + 1 := by
      show (q' + q' + 1) + 1 + 0 = (q' + q' + 1) + 1; rfl
    rw [l, r] at e; exact e
  exact add_right_cancel' _ _ _ e'

theorem half_append (q' : Nat) (a : List Nat)
    (hfix : ∀ t, t ∈ FermatPrime.units ((q' + q' + 1) + 1) → (t * (q' + 1)) % ((q' + q' + 1) + 1) = q' + 1)
    (h : HodgeList ((q' + q' + 1) + 1) a) : HodgeList ((q' + q' + 1) + 1) (a ++ [q' + 1]) := by
  intro t ht
  rw [lsumL_append, lsumL_append, h t ht]
  show lsumL (fun _ => (q' + q' + 1) + 1) a + (2 * (t * (q' + 1) % ((q' + q' + 1) + 1)) + 0)
      = lsumL (fun _ => (q' + q' + 1) + 1) a + ((q' + q' + 1) + 1 + 0)
  rw [hfix t ht]; lib_nat

def fix62 : Bool := (FermatPrime.units 62).all (fun t => Nat.beq ((t * 31) % 62) 31)
theorem fix62_ok : fix62 = true := rfl

theorem half62 : ∀ t, t ∈ FermatPrime.units ((30 + 30 + 1) + 1) → (t * (30 + 1)) % ((30 + 30 + 1) + 1) = 30 + 1 :=
  fun t ht => Nat.eq_of_beq_eq_true (all_mem _ (FermatPrime.units 62) fix62_ok t ht)

end HalfEntry

#print axioms HalfEntry.half_mod
#print axioms HalfEntry.half_cancel
#print axioms HalfEntry.half_append
#print axioms HalfEntry.fix62_ok
#print axioms HalfEntry.half62

#print axioms: 5 theorems, no axioms.

81.25 Reordering

The Hodge condition depends only on the multiset of entries, every \(m\). \(a\sim b\Rightarrow T_t(a)=T_t(b)\)

hodge/PermInv.lean

/-
  hodge/PermInv.lean — T41 cycle 162: the Hodge condition depends only on the multiset of entries, every m.

  Lean 4 core plus hodge/HodgeIff (HodgeList, lsumL), hodge/FermatGens (tsum), lib/Semi.
    lsumL_perm    a ~ b (List.Perm)  ⇒  Σ_a g = Σ_b g
    tsum_perm     a ~ b  ⇒  T_t(a) = T_t(b)
    hodge_perm    a ~ b, a Hodge  ⇒  b Hodge
  With PairCancel and HalfEntry this lets a pair or the entry m/2 be removed from any position, e.g. 31 from
  (1, 31, 33, 35, 39, 47) at m = 62.
-/
import hodge.HodgeIff
import hodge.FermatGens
import lib.Semi

namespace PermInv
open FTAChain FrobChain QRChain ESChain FermatPrime FermatFull HodgeChain HodgeIff FermatGens

theorem lsumL_perm (g : Nat → Nat) {a b : List Nat} (h : a.Perm b) : lsumL g a = lsumL g b := by
  induction h with
  | nil => rfl
  | cons x _ ih => show g x + lsumL g _ = g x + lsumL g _; rw [ih]
  | swap x y l => show g y + (g x + lsumL g l) = g x + (g y + lsumL g l); lib_nat
  | trans _ _ ih1 ih2 => exact ih1.trans ih2

theorem tsum_perm (m t : Nat) {a b : List Nat} (h : a.Perm b) : tsum m t a = tsum m t b := by
  induction h with
  | nil => rfl
  | cons x _ ih => show (t * x) % m + tsum m t _ = (t * x) % m + tsum m t _; rw [ih]
  | swap x y l => show (t * y) % m + ((t * x) % m + tsum m t l) = (t * x) % m + ((t * y) % m + tsum m t l); lib_nat
  | trans _ _ ih1 ih2 => exact ih1.trans ih2

/-- **The Hodge condition is invariant under reordering.** -/
theorem hodge_perm (m : Nat) {a b : List Nat} (h : a.Perm b) (ha : HodgeList m a) : HodgeList m b := by
  intro t ht
  rw [← lsumL_perm _ h, ← lsumL_perm _ h]
  exact ha t ht

end PermInv

#print axioms PermInv.lsumL_perm
#print axioms PermInv.tsum_perm
#print axioms PermInv.hodge_perm

#print axioms: 3 theorems, no axioms.

81.26 The open character of \(m=62\) reduced

Removing the neutral entry \(31\) leaves a balanced list of length five. \((1,31,33,35,39,47)\ \text {Hodge}\Rightarrow 2T_t(1,33,35,39,47)=5\cdot 62\)

hodge/Reduce62.lean

/-
  hodge/Reduce62.lean — T41 cycle 165: the open character of m = 62 reduced to a balanced 5-list.

  Lean 4 core plus hodge/HalfEntry (half_cancel, half62), hodge/PermInv (hodge_perm), hodge/HodgeIff (all_mem).
    c62_hodge     (1, 31, 33, 35, 39, 47) satisfies Shioda's condition at every unit of 62 (rfl)
    rest62        (1, 33, 35, 39, 47) is balanced: 2T_t = 5·62 at every unit t, i.e. T_t = 155
  The certified open character of OpenCert62 is the neutral entry 31 plus an odd-length balanced list: its
  arithmetic content (the Hodge sums) sits entirely in this 5-list.
-/
import hodge.HalfEntry
import hodge.PermInv

namespace Reduce62
open FTAChain FrobChain QRChain ESChain FermatPrime FermatFull HodgeChain HodgeIff

def c62 : List Nat := [1, 31, 33, 35, 39, 47]
def r62 : List Nat := [1, 33, 35, 39, 47]

def chk : Bool := (FermatPrime.units 62).all (fun t =>
  Nat.beq (lsumL (fun i => 2 * (t * i % 62)) c62) (lsumL (fun _ => 62) c62))
theorem chk_ok : chk = true := rfl

theorem c62_hodge : HodgeList 62 c62 := fun t ht =>
  Nat.eq_of_beq_eq_true (all_mem _ (FermatPrime.units 62) chk_ok t ht)

theorem perm62 : c62.Perm (r62 ++ [31]) :=
  List.Perm.cons 1 ((List.Perm.swap 33 31 _).trans (List.Perm.cons 33 ((List.Perm.swap 35 31 _).trans
    (List.Perm.cons 35 ((List.Perm.swap 39 31 _).trans (List.Perm.cons 39 (List.Perm.swap 47 31 _)))))))

/-- **The rest of the m = 62 open character is balanced.** -/
theorem rest62 : HodgeList ((30 + 30 + 1) + 1) r62 :=
  HalfEntry.half_cancel 30 r62 HalfEntry.half62 (PermInv.hodge_perm 62 perm62 c62_hodge)

end Reduce62

#print axioms Reduce62.chk_ok
#print axioms Reduce62.c62_hodge
#print axioms Reduce62.perm62
#print axioms Reduce62.rest62

#print axioms: 4 theorems, no axioms.

81.27 No balanced splitting

The certified open characters do not split into two balanced blocks of any lengths. \(c=A\sqcup B,\ A,B\ne \emptyset \Rightarrow A\) or \(B\) not balanced

hodge/Indecomp.lean

/-
  hodge/Indecomp.lean — T41 cycle 168: the certified open characters have no balanced splitting.

  Lean 4 core, rfl. A list A is balanced for m if 2T_t(A) = |A|·m for every unit t (Shioda's condition at any
  length). For each certified open character c (m = 32, 33, 36, 56, 68, 70, 76, 78) no splitting c = A ⊔ B into
  two nonempty sub-multisets has both parts balanced; for m = 62 the only one is 31 ⊔ (1, 33, 35, 39, 47)
  (Reduce62), and that 5-list has none. So no block-wise reduction (pairs, m/2, Hodge sub-characters of any
  length) reaches these characters: they are irreducible obstructions of the inductive method.
-/
import hodge.FermatPrime

namespace Indecomp

def tsum (m t : Nat) : List Nat → Nat
  | [] => 0
  | a :: l => (t * a) % m + tsum m t l

def bal (m : Nat) (A : List Nat) : Bool :=
  (FermatPrime.units m).all (fun t => Nat.beq (tsum m t A + tsum m t A) (A.length * m))

/-- all (A, B) splittings of a list, as pairs of sub-multisets -/
def splits : List Nat → List (List Nat × List Nat)
  | [] => [([], [])]
  | x :: l => (splits l).flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])

def indec (m : Nat) (c : List Nat) : Bool :=
  (splits c).all (fun p => p.1.isEmpty || p.2.isEmpty || !(bal m p.1 && bal m p.2))

def openChars : List (Nat × List Nat) :=
  [(32, [1, 9, 17, 20, 24, 25]), (33, [1, 4, 16, 22, 25, 31]), (36, [1, 4, 13, 27, 29, 34]),
   (56, [1, 9, 29, 37, 42, 50]), (68, [1, 18, 35, 38, 52, 60]), (70, [1, 6, 43, 45, 57, 58]),
   (76, [1, 20, 39, 42, 58, 68]), (78, [1, 6, 12, 64, 75, 76]), (62, [1, 33, 35, 39, 47])]

set_option maxRecDepth 100000 in
theorem indec_ok : openChars.all (fun p => indec p.1 p.2) = true := rfl

-- the 5-list of m = 62 is itself balanced (Reduce62), so the split 31 ⊔ rest is the only one
set_option maxRecDepth 100000 in
theorem rest62_bal : bal 62 [1, 33, 35, 39, 47] = true := rfl

end Indecomp

#print axioms Indecomp.indec_ok
#print axioms Indecomp.rest62_bal

#print axioms: 2 theorems, no axioms.

81.28 All stored open characters

Of \(126\) stored unreached characters, \(110\) have no balanced splitting; the other \(16\) reduce to them or to \(m/2\). \(\text {length }8=\text {pair}\sqcup \text {open length }6;\quad \text {length }6\ \text {irreducible unless it contains }m/2\)

hodge/Indecomp2.lean

/-
  hodge/Indecomp2.lean — T41 cycle 171: indecomposability of every stored unreached character.

  Lean 4 core plus hodge/Indecomp (bal, splits, indec), rfl. NUMERIC_HODGE_REACH.jsonl stores up to five
  unreached characters per (m, length). Of the 126 distinct ones:
    indec_all   110 have no splitting into two nonempty balanced parts (all of length 6; m = 25, 32, 33, 35,
                36, 39, 40, 42, 44, 45, 48, 50, 52, 54, 56, 60, 64, 66, 68, 70, 72, 76, 78)
    dec_all     the other 16 do split: the length-8 ones into a pair and a length-6 open character, and the
                length-6 ones at m = 62 and m = 70 into the entry m/2 and a balanced 5-list
  So every stored open character of length 8 reduces to one of length 6, and every open character of length 6
  is irreducible unless it contains m/2.
-/
import hodge.Indecomp

namespace Indecomp2
open Indecomp

def indList : List (Nat × List Nat) :=
  [(25, [1, 6, 11, 16, 20, 21]),
   (25, [2, 7, 12, 15, 17, 22]),
   (25, [3, 8, 10, 13, 18, 23]),
   (25, [4, 5, 9, 14, 19, 24]),
   (32, [1, 9, 17, 20, 24, 25]),
   (32, [3, 8, 11, 19, 27, 28]),
   (32, [4, 5, 13, 21, 24, 29]),
   (32, [7, 8, 12, 15, 23, 31]),
   (33, [1, 4, 16, 22, 25, 31]),
   (33, [2, 8, 11, 17, 29, 32]),
   (33, [5, 11, 14, 20, 23, 26]),
   (33, [7, 10, 13, 19, 22, 28]),
   (35, [1, 8, 15, 22, 29, 30]),
   (35, [2, 9, 16, 23, 25, 30]),
   (35, [3, 10, 17, 20, 24, 31]),
   (35, [4, 11, 15, 18, 25, 32]),
   (35, [5, 6, 13, 20, 27, 34]),
   (36, [1, 4, 13, 27, 29, 34]),
   (36, [1, 5, 6, 29, 33, 34]),
   (36, [1, 5, 12, 27, 29, 34]),
   (36, [1, 5, 12, 28, 29, 33]),
   (36, [1, 5, 14, 26, 29, 33]),
   (39, [1, 7, 16, 22, 34, 37]),
   (39, [1, 14, 16, 22, 29, 35]),
   (39, [1, 16, 19, 22, 28, 31]),
   (39, [2, 5, 14, 29, 32, 35]),
   (39, [2, 5, 17, 23, 32, 38]),
   (40, [1, 9, 17, 25, 33, 35]),
   (40, [3, 11, 19, 25, 27, 35]),
   (40, [5, 7, 15, 23, 31, 39]),
   (40, [5, 13, 15, 21, 29, 37]),
   (42, [2, 10, 16, 27, 33, 38]),
   (42, [2, 15, 16, 20, 34, 39]),
   (42, [3, 4, 20, 32, 33, 34]),
   (42, [3, 8, 22, 26, 27, 40]),
   (42, [4, 9, 15, 26, 32, 40]),
   (44, [1, 12, 23, 26, 34, 36]),
   (44, [2, 6, 17, 28, 39, 40]),
   (44, [2, 13, 24, 28, 30, 35]),
   (44, [3, 14, 20, 25, 34, 36]),
   (44, [4, 5, 16, 27, 38, 42]),
   (45, [1, 19, 20, 28, 30, 37]),
   (45, [2, 11, 15, 29, 38, 40]),
   (45, [4, 13, 22, 30, 31, 35]),
   (45, [5, 7, 16, 30, 34, 43]),
   (45, [8, 15, 17, 25, 26, 44]),
   (48, [1, 6, 7, 39, 45, 46]),
   (48, [1, 7, 18, 34, 39, 45]),
   (48, [1, 7, 27, 30, 33, 46]),
   (48, [1, 7, 27, 33, 34, 42]),
   (48, [1, 13, 25, 28, 37, 40]),
   (50, [1, 7, 27, 30, 41, 44]),
   (50, [1, 11, 13, 40, 42, 43]),
   (50, [1, 11, 27, 30, 34, 47]),
   (50, [1, 13, 22, 32, 40, 42]),
   (50, [1, 13, 22, 33, 40, 41]),
   (52, [1, 14, 27, 30, 40, 44]),
   (52, [2, 7, 20, 33, 46, 48]),
   (52, [2, 15, 28, 34, 36, 41]),
   (52, [3, 16, 28, 29, 38, 42]),
   (52, [4, 6, 19, 32, 45, 50]),
   (54, [1, 4, 30, 31, 44, 52]),
   (54, [1, 5, 28, 37, 43, 48]),
   (54, [1, 5, 29, 41, 42, 44]),
   (54, [1, 6, 8, 44, 51, 52]),
   (54, [1, 6, 29, 31, 44, 51]),
   (56, [1, 9, 29, 37, 42, 50]),
   (56, [1, 10, 29, 36, 42, 50]),
   (56, [1, 15, 29, 32, 43, 48]),
   (56, [1, 15, 29, 36, 43, 44]),
   (56, [1, 18, 21, 29, 49, 50]),
   (60, [1, 3, 32, 44, 49, 51]),
   (60, [1, 7, 32, 41, 47, 52]),
   (60, [1, 8, 9, 49, 56, 57]),
   (60, [1, 8, 27, 39, 49, 56]),
   (60, [1, 13, 16, 41, 53, 56]),
   (64, [1, 17, 33, 36, 49, 56]),
   (64, [2, 18, 34, 40, 48, 50]),
   (64, [3, 19, 35, 40, 44, 51]),
   (64, [4, 9, 25, 41, 56, 57]),
   (64, [5, 21, 24, 37, 52, 53]),
   (66, [1, 5, 27, 38, 63, 64]),
   (66, [1, 5, 36, 38, 54, 64]),
   (66, [1, 5, 45, 46, 50, 51]),
   (66, [1, 6, 10, 54, 63, 64]),
   (66, [1, 8, 22, 50, 55, 62]),
   (68, [1, 18, 35, 38, 52, 60]),
   (68, [2, 9, 26, 43, 60, 64]),
   (68, [2, 19, 36, 42, 52, 53]),
   (68, [3, 20, 37, 44, 46, 54]),
   (68, [4, 8, 25, 42, 59, 66]),
   (70, [1, 6, 43, 45, 57, 58]),
   (70, [1, 16, 29, 45, 57, 62]),
   (70, [1, 20, 24, 42, 61, 62]),
   (70, [1, 20, 29, 43, 57, 60]),
   (72, [1, 6, 11, 59, 69, 70]),
   (72, [1, 10, 25, 57, 59, 64]),
   (72, [1, 10, 37, 50, 52, 66]),
   (72, [1, 10, 37, 50, 54, 64]),
   (72, [1, 10, 37, 54, 56, 58]),
   (76, [1, 20, 39, 42, 58, 68]),
   (76, [2, 10, 29, 48, 67, 72]),
   (76, [2, 21, 40, 46, 59, 60]),
   (76, [3, 22, 41, 50, 52, 60]),
   (76, [4, 9, 28, 47, 66, 74]),
   (78, [1, 6, 12, 64, 75, 76]),
   (78, [1, 6, 42, 45, 64, 76]),
   (78, [1, 7, 31, 61, 64, 70]),
   (78, [1, 7, 40, 43, 70, 73]),
   (78, [1, 7, 44, 49, 59, 74])]

def decList : List (Nat × List Nat) :=
  [(32, [1, 1, 9, 17, 20, 24, 25, 31]),
   (32, [1, 3, 8, 11, 19, 27, 28, 31]),
   (32, [1, 3, 9, 17, 20, 24, 25, 29]),
   (32, [1, 4, 5, 13, 21, 24, 29, 31]),
   (32, [1, 5, 9, 17, 20, 24, 25, 27]),
   (33, [1, 1, 4, 16, 22, 25, 31, 32]),
   (33, [1, 2, 4, 16, 22, 25, 31, 31]),
   (33, [1, 2, 8, 11, 17, 29, 32, 32]),
   (33, [1, 3, 4, 16, 22, 25, 30, 31]),
   (33, [1, 4, 4, 16, 22, 25, 29, 31]),
   (62, [1, 31, 33, 35, 39, 47]),
   (62, [3, 17, 31, 37, 43, 55]),
   (62, [5, 9, 31, 41, 49, 51]),
   (62, [7, 19, 25, 31, 45, 59]),
   (62, [11, 13, 21, 31, 53, 57]),
   (70, [1, 29, 35, 43, 45, 57])]

set_option maxRecDepth 200000 in
theorem indec_all : indList.all (fun p => indec p.1 p.2) = true := rfl
set_option maxRecDepth 200000 in
theorem dec_all : decList.all (fun p => !(indec p.1 p.2)) = true := rfl
set_option maxRecDepth 200000 in
theorem counts : indList.length = 110 ∧ decList.length = 16 := ⟨rfl, rfl⟩

end Indecomp2

#print axioms Indecomp2.indec_all
#print axioms Indecomp2.dec_all
#print axioms Indecomp2.counts

#print axioms: 3 theorems, no axioms.

81.29 Odd \(m\), even blocks

For odd \(m\) a balanced list has even length. \(T+T=L\cdot (2j+1)\Rightarrow L\ \text {even}\)

hodge/OddLength.lean

/-
  hodge/OddLength.lean — T41 cycle 174: for odd m every balanced list has even length.

  Lean 4 core plus lib/Semi. If 2T = L·m with m odd, then L is even (parity, by hand: no Nat.mod lemmas).
    par          every L is q + q or q + q + 1
    even_ne_odd  a + a ≠ b + b + 1
    odd_len      m = 2j + 1, T + T = L·m  ⇒  ∃ q, L = q + q
  Applied at the twist t = 1 (2T₁(A) = |A|·m): for odd m no balanced list — no block of a Hodge character — has
  odd length. The odd-length blocks of the m = 62, 70 characters (the entry m/2 and the balanced 5-lists,
  Indecomp2) can only occur for even m.
-/
import lib.Semi

namespace OddLength

theorem par : ∀ L : Nat, (∃ q, L = q + q) ∨ (∃ q, L = q + q + 1)
  | 0 => Or.inl ⟨0, rfl⟩
  | L + 1 => match par L with
    | Or.inl ⟨q, h⟩ => Or.inr ⟨q, by rw [h]⟩
    | Or.inr ⟨q, h⟩ => Or.inl ⟨q + 1, by rw [h]; lib_nat⟩

theorem even_ne_odd : ∀ a b : Nat, a + a ≠ b + b + 1
  | 0, 0, h => Nat.noConfusion h
  | 0, b + 1, h => Nat.noConfusion h
  | a + 1, 0, h => by
      have h' : Nat.succ (Nat.succ (a + a)) = Nat.succ 0 := by
        rw [show Nat.succ (Nat.succ (a + a)) = a + 1 + (a + 1) by lib_nat]; exact h
      exact Nat.noConfusion (Nat.succ.inj h')
  | a + 1, b + 1, h => by
      have h' : Nat.succ (Nat.succ (a + a)) = Nat.succ (Nat.succ (b + b + 1)) := by
        rw [show Nat.succ (Nat.succ (a + a)) = a + 1 + (a + 1) by lib_nat,
            show Nat.succ (Nat.succ (b + b + 1)) = b + 1 + (b + 1) + 1 by lib_nat]; exact h
      exact even_ne_odd a b (Nat.succ.inj (Nat.succ.inj h'))

/-- **Odd m forces even length.** -/
theorem odd_len (j T L : Nat) (h : T + T = L * (j + j + 1)) : ∃ q, L = q + q :=
  match par L with
  | Or.inl e => e
  | Or.inr ⟨q, hq⟩ => absurd (by rw [h, hq]; lib_nat : T + T = (q * (j + j + 1) + j) + (q * (j + j + 1) + j) + 1)
      (even_ne_odd T (q * (j + j + 1) + j))

end OddLength

#print axioms OddLength.par
#print axioms OddLength.even_ne_odd
#print axioms OddLength.odd_len

#print axioms: 3 theorems, no axioms.

81.30 Unreached sets that are one orbit

For twelve \(m\) the Galois orbit of one unreached character has the size of the whole unreached set. \(\#\{t\cdot c\bmod m\}=\#\text {unreached},\quad m=25,32,\dots ,76\)

hodge/Orbits.lean

/-
  hodge/Orbits.lean — T41 cycle 177: for twelve m the whole unreached set is one Galois orbit.

  Lean 4 core plus hodge/FermatPrime (units), rfl. orbit m c = the distinct sorted twists (t·c mod m), t a unit.
    orbit_sizes   for m = 25, 32, 33, 35, 40, 42, 44, 45, 52, 62, 68, 76 the orbit of the first stored unreached
                  character has exactly as many elements as the measured unreached set of length 6
                  (4, 4, 4, 6, 4, 6, 10, 6, 12, 6, 16, 18; NUMERIC_HODGE_REACH.jsonl)
  Since twisting preserves the Hodge condition (GaloisOrbit.twist_hodge) and the method's closure (lines,
  standard characters, pairs and splittings are twist-stable), the unreached set is twist-stable; equal sizes
  then mean it is exactly one orbit: one certificate per m covers it. For the other m (36, 39, 48, 50, 54, 56, 60,
  64, 66, 70, 72, 78) the unreached set is a union of several orbits.
-/
import hodge.FermatPrime

namespace Orbits

def ins (x : Nat) : List Nat → List Nat
  | [] => [x]
  | y :: l => if Nat.ble x y = true then x :: y :: l else y :: ins x l

def isort : List Nat → List Nat
  | [] => []
  | x :: l => ins x (isort l)

def leq : List Nat → List Nat → Bool
  | [], [] => true
  | [], _ :: _ => false
  | _ :: _, [] => false
  | x :: a, y :: b => Nat.beq x y && leq a b

def dedup : List (List Nat) → List (List Nat)
  | [] => []
  | c :: l => if (dedup l).any (fun d => leq c d) = true then dedup l else c :: dedup l

def orbit (m : Nat) (c : List Nat) : List (List Nat) :=
  dedup ((FermatPrime.units m).map (fun t => isort (c.map (fun a => (t * a) % m))))

def table : List (Nat × List Nat × Nat) :=
  [(25, [1, 6, 11, 16, 20, 21], 4), (32, [1, 9, 17, 20, 24, 25], 4), (33, [1, 4, 16, 22, 25, 31], 4),
   (35, [1, 8, 15, 22, 29, 30], 6), (40, [1, 9, 17, 25, 33, 35], 4), (42, [2, 10, 16, 27, 33, 38], 6),
   (44, [1, 12, 23, 26, 34, 36], 10), (45, [1, 19, 20, 28, 30, 37], 6), (52, [1, 14, 27, 30, 40, 44], 12),
   (62, [1, 31, 33, 35, 39, 47], 6), (68, [1, 18, 35, 38, 52, 60], 16), (76, [1, 20, 39, 42, 58, 68], 18)]

set_option maxRecDepth 100000 in
theorem orbit_sizes : table.all (fun p => Nat.beq (orbit p.1 p.2.1).length p.2.2) = true := rfl

end Orbits

#print axioms Orbits.orbit_sizes

#print axioms: 1 theorem, no axioms.

81.31 Whole orbits are irreducible

For eleven \(m\) every twist of the unreached representative has no balanced splitting. \(\forall t\in (\mathbb Z/m)^*:\ t\cdot c\ \text {indecomposable}\)

hodge/OrbitIndec.lean

/-
  hodge/OrbitIndec.lean — T41 cycle 180: every member of the twelve one-orbit unreached sets is irreducible.

  Lean 4 core plus hodge/Orbits (orbit, table), hodge/Indecomp (indec), rfl. For m = 25, 32, 33, 35, 40, 42, 44,
  45, 52, 68, 76 every twist of the representative has no splitting into two nonempty balanced parts; for m = 62
  every twist splits only as 31 ⊔ (balanced 5-list) (the twist fixes 31 = m/2).
    orbit_indec    the eleven orbits: all members indecomposable
    orbit62_dec    m = 62: all six members decomposable, each contains 31
  With Orbits.orbit_sizes the whole measured unreached set of length 6 is irreducible for these eleven m.
-/
import hodge.Orbits
import hodge.Indecomp

namespace OrbitIndec
open Orbits Indecomp

def table11 : List (Nat × List Nat) :=
  [(25, [1, 6, 11, 16, 20, 21]), (32, [1, 9, 17, 20, 24, 25]), (33, [1, 4, 16, 22, 25, 31]),
   (35, [1, 8, 15, 22, 29, 30]), (40, [1, 9, 17, 25, 33, 35]), (42, [2, 10, 16, 27, 33, 38]),
   (44, [1, 12, 23, 26, 34, 36]), (45, [1, 19, 20, 28, 30, 37]), (52, [1, 14, 27, 30, 40, 44]),
   (68, [1, 18, 35, 38, 52, 60]), (76, [1, 20, 39, 42, 58, 68])]

set_option maxRecDepth 200000 in
theorem orbit_indec : table11.all (fun p => (orbit p.1 p.2).all (fun c => indec p.1 c)) = true := rfl

set_option maxRecDepth 200000 in
theorem orbit62_dec : (orbit 62 [1, 31, 33, 35, 39, 47]).all (fun c => !(indec 62 c) && c.any (fun x => Nat.beq x 31)) = true := rfl

end OrbitIndec

#print axioms OrbitIndec.orbit_indec
#print axioms OrbitIndec.orbit62_dec

#print axioms: 2 theorems, no axioms.

81.32 Orbit decomposition, \(m=36\) to \(60\)

The full unreached sets are unions of a few Galois orbits; almost all members are irreducible. \(m=36:\ 9\ \text {orbits},\ 96;\quad m=54:\ 20,\ 360;\quad m=60:\ 9,\ 98\)

hodge/OrbitDecomp.lean

/-
  hodge/OrbitDecomp.lean — T41 cycle 183: Galois orbit decomposition of the full unreached sets, m = 36 … 60.

  Lean 4 core plus hodge/Orbits (orbit, dedup), hodge/Indecomp (indec), rfl. For each row (m, reps, u, i):
  the union of the twist orbits of the representatives has exactly u elements — the whole unreached set of
  length 6 (all of them stored by a2_reachall, NUMERIC: work/data/ckpt/agent2_T41/reach/all_<m>.jsonl) — and
  i of them have no balanced splitting (checked here for every row except m = 54, whose count 342 is from
  Python; the m = 54 rfl is left for Kamiak).
    m = 36: 9 orbits (96), 84 irreducible;   39: 2 (12), 12;   48: 12 (100), 92;   50: 2 (40), 40;
    m = 54: 20 (360), 342;   56: 7 (72), 72;   60: 9 (98), 98.
  The reducible ones contain m/2 (m = 36, 48, 54) and split off a balanced 5-list, as at m = 62.
-/
import hodge.Orbits
import hodge.Indecomp

namespace OrbitDecomp
open Orbits Indecomp

def tbl : List (Nat × List (List Nat) × Nat × Nat) :=
  [(36, [[1, 4, 13, 27, 29, 34], [1, 5, 6, 29, 33, 34], [1, 5, 12, 27, 29, 34], [1, 5, 12, 28, 29, 33], [1, 5, 14, 26, 29, 33], [1, 5, 14, 27, 29, 32], [1, 5, 18, 25, 27, 32], [1, 7, 19, 25, 26, 30], [1, 14, 15, 19, 26, 33]], 96, 84),
   (39, [[1, 7, 16, 22, 34, 37], [1, 14, 16, 22, 29, 35]], 12, 12),
   (48, [[1, 6, 7, 39, 45, 46], [1, 7, 18, 34, 39, 45], [1, 13, 25, 28, 37, 40], [1, 14, 17, 27, 39, 46], [1, 16, 17, 27, 39, 44], [1, 16, 19, 25, 40, 43], [1, 17, 18, 25, 41, 42], [1, 17, 18, 27, 39, 42], [1, 17, 22, 27, 38, 39], [1, 17, 24, 27, 36, 39], [2, 9, 21, 33, 34, 45], [3, 15, 16, 27, 39, 44]], 100, 92),
   (50, [[1, 7, 27, 30, 41, 44], [1, 13, 22, 32, 40, 42]], 40, 40),
   (54, [[1, 4, 30, 31, 44, 52], [1, 5, 28, 37, 43, 48], [1, 5, 29, 41, 42, 44], [1, 6, 8, 44, 51, 52], [1, 6, 29, 31, 44, 51], [1, 7, 19, 36, 49, 50], [1, 7, 24, 38, 41, 51], [1, 7, 27, 38, 41, 48], [1, 7, 36, 38, 39, 41], [1, 8, 15, 42, 44, 52], [1, 8, 20, 38, 44, 51], [1, 8, 21, 36, 44, 52], [1, 8, 22, 30, 49, 52], [1, 8, 30, 34, 37, 52], [1, 8, 30, 37, 38, 48], [1, 8, 36, 37, 38, 42], [1, 10,   -- (+103 chars; full line in the Zenodo source)
   (56, [[1, 9, 29, 37, 42, 50], [1, 10, 29, 36, 42, 50], [1, 15, 29, 32, 43, 48], [1, 15, 29, 36, 43, 44], [1, 18, 21, 29, 49, 50], [1, 18, 29, 34, 42, 44], [2, 10, 21, 34, 49, 52]], 72, 72),
   (60, [[1, 3, 32, 44, 49, 51], [1, 7, 32, 41, 47, 52], [1, 8, 9, 49, 56, 57], [1, 13, 16, 41, 53, 56], [1, 16, 25, 31, 52, 55], [1, 17, 27, 31, 47, 57], [3, 4, 15, 51, 52, 55], [3, 4, 25, 45, 51, 52], [4, 16, 25, 28, 52, 55]], 98, 98)]

def union (m : Nat) (reps : List (List Nat)) : List (List Nat) := dedup (reps.flatMap (orbit m))

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem sizes : tbl.all (fun (m, reps, u, _) => Nat.beq (union m reps).length u) = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irreducible : (tbl.filter (fun p => !(Nat.beq p.1 54))).all (fun (m, reps, _, i) => Nat.beq ((union m reps).filter (indec m)).length i) = true := rfl

end OrbitDecomp

#print axioms OrbitDecomp.sizes
#print axioms OrbitDecomp.irreducible

#print axioms: 2 theorems, no axioms.

81.33 Orbit decomposition, \(m=64\) to \(78\)

The full unreached sets at the remaining multi-orbit \(m\le 78\), as unions of Galois orbits. \(m=66:\ 24\ \text {orbits},\ 378;\quad m=78:\ 43,\ 804,\ 792\ \text {irreducible}\)

hodge/OrbitDecomp2.lean

/-
  hodge/OrbitDecomp2.lean — T41 cycle 186: Galois orbit decomposition of the full unreached sets, m = 64 … 78.

  Lean 4 core plus hodge/Orbits (orbit, dedup), hodge/Indecomp (indec), hodge/OrbitDecomp (union), rfl. For each m:
  the union of the twist orbits of the representatives has exactly u elements — the whole unreached set of length 6
  (a2_reachall, work/data/ckpt/agent2_T41/reach/all_<m>.jsonl) — and i of them have no balanced splitting.
    m = 64: 2 orbits (12), 12 irreducible;   66: 24 (378), 378;   70: 4 (60), 54;   72: 28 (384), 372;
    m = 78: 43 (804), 792.
  The reducible ones (m = 70, 72, 78) all contain m/2.
-/
import hodge.OrbitDecomp

namespace OrbitDecomp2
open Orbits Indecomp OrbitDecomp

def reps64 : List (List Nat) := [[1, 17, 33, 36, 49, 56], [2, 18, 34, 40, 48, 50]]

def reps66 : List (List Nat) := [[1, 5, 27, 38, 63, 64], [1, 5, 36, 38, 54, 64], [1, 5, 45, 46, 50, 51], [1, 6, 10, 54, 63, 64], [1, 8, 22, 50, 55, 62], [1, 8, 23, 52, 54, 60], [1, 9, 23, 51, 54, 60], [1, 9, 34, 46, 48, 60], [1, 10, 18, 51, 54, 64], [1, 10, 24, 46, 54, 63], [1, 10, 27, 36, 60, 64], [1, 10, 36, 42, 45, 64], [1, 10, 36, 45, 46, 60], [1, 12, 34, 45, 46, 60], [1, 18, 23, 37, 59, 60],   -- (+222 chars; full line in the Zenodo source)

def reps70 : List (List Nat) := [[1, 6, 43, 45, 57, 58], [1, 20, 24, 42, 61, 62], [1, 20, 29, 43, 57, 60], [1, 29, 35, 43, 45, 57]]

def reps72 : List (List Nat) := [[1, 6, 11, 59, 69, 70], [1, 10, 25, 57, 59, 64], [1, 10, 37, 50, 52, 66], [1, 10, 37, 50, 54, 64], [1, 10, 37, 54, 56, 58], [1, 11, 18, 57, 59, 70], [1, 11, 24, 51, 59, 70], [1, 11, 26, 50, 59, 69], [1, 13, 37, 49, 50, 66], [1, 19, 37, 40, 55, 64], [1, 19, 37, 48, 55, 56], [1, 26, 28, 37, 58, 66], [1, 26, 33, 37, 50, 69], [1, 26, 37, 40, 54, 58], [1, 26, 37, 42, 50  -- (+330 chars; full line in the Zenodo source)

def reps78 : List (List Nat) := [[1, 6, 12, 64, 75, 76], [1, 6, 42, 45, 64, 76], [1, 7, 31, 61, 64, 70], [1, 7, 44, 49, 59, 74], [1, 7, 44, 53, 59, 70], [1, 7, 53, 54, 59, 60], [1, 8, 27, 55, 69, 74], [1, 9, 20, 56, 73, 75], [1, 9, 42, 49, 61, 72], [1, 10, 41, 56, 62, 64], [1, 10, 45, 53, 62, 63], [1, 11, 40, 54, 56, 72], [1, 12, 21, 60, 64, 76], [1, 12, 28, 54, 64, 75], [1, 12, 32, 42, 73, 74], [  -- (+697 chars; full line in the Zenodo source)

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size64 : Nat.beq (union 64 reps64).length 12 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr64 : Nat.beq ((union 64 reps64).filter (indec 64)).length 12 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size66 : Nat.beq (union 66 reps66).length 378 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr66 : Nat.beq ((union 66 reps66).filter (indec 66)).length 378 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size70 : Nat.beq (union 70 reps70).length 60 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr70 : Nat.beq ((union 70 reps70).filter (indec 70)).length 54 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size72 : Nat.beq (union 72 reps72).length 384 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr72 : Nat.beq ((union 72 reps72).filter (indec 72)).length 372 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size78 : Nat.beq (union 78 reps78).length 804 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr78 : Nat.beq ((union 78 reps78).filter (indec 78)).length 792 = true := rfl

end OrbitDecomp2

#print axioms OrbitDecomp2.size64
#print axioms OrbitDecomp2.irr64

#print axioms OrbitDecomp2.size66
#print axioms OrbitDecomp2.irr66

#print axioms OrbitDecomp2.size70
#print axioms OrbitDecomp2.irr70

#print axioms OrbitDecomp2.size72
#print axioms OrbitDecomp2.irr72

#print axioms OrbitDecomp2.size78
#print axioms OrbitDecomp2.irr78

#print axioms: 10 theorems, no axioms.

81.34 The reducible unreached characters

Every reducible unreached character at \(m=36,\dots ,78\) is \(m/2\) plus an irreducible balanced \(5\)-list. \(c=\{m/2\}\sqcup c',\quad c'\ \text {balanced, indecomposable}\) (68 characters)

hodge/HalfSplit.lean

/-
  hodge/HalfSplit.lean — T41 cycle 189: the reducible unreached characters at m = 36, 48, 54, 70, 72, 78 are m/2
  plus an indecomposable balanced 5-list.

  Lean 4 core plus hodge/Indecomp (bal, indec), rfl. The 68 rows below are all the unreached characters of length 6 at
  m = 36 (12), 48 (8), 54 (18), 70 (6), 72 (12), 78 (12) that have a balanced splitting (OrbitDecomp,
  OrbitDecomp2: 96 − 84, 100 − 92, 360 − 342, 60 − 54, 384 − 372, 804 − 792). For
  each: m/2 is an entry, the other five entries form a balanced list, and that 5-list has no balanced splitting —
  as at m = 62 (Reduce62). The singleton m/2 is balanced for every even m.
-/
import hodge.Indecomp

namespace HalfSplit
open Indecomp

def rest (m : Nat) (c : List Nat) : List Nat := c.filter (fun a => !(Nat.beq a (m / 2)))

def red : List (Nat × List Nat) :=
  [(36, [1, 5, 18, 25, 27, 32]),
   (36, [1, 5, 18, 27, 28, 29]),
   (36, [1, 13, 18, 20, 27, 29]),
   (36, [4, 9, 11, 18, 31, 35]),
   (36, [4, 13, 17, 18, 27, 29]),
   (36, [5, 16, 17, 18, 25, 27]),
   (36, [7, 8, 9, 18, 31, 35]),
   (36, [7, 9, 16, 18, 23, 35]),
   (36, [7, 9, 18, 19, 23, 32]),
   (36, [8, 13, 17, 18, 25, 27]),
   (36, [9, 11, 18, 19, 20, 31]),
   (36, [9, 11, 18, 19, 23, 28]),
   (48, [1, 17, 24, 27, 36, 39]),
   (48, [3, 5, 24, 36, 37, 39]),
   (48, [3, 15, 24, 25, 36, 41]),
   (48, [7, 12, 23, 24, 33, 45]),
   (48, [9, 11, 12, 24, 43, 45]),
   (48, [9, 12, 21, 24, 31, 47]),
   (48, [12, 19, 21, 24, 33, 35]),
   (48, [13, 15, 24, 27, 29, 36]),
   (54, [1, 7, 27, 38, 41, 48]),
   (54, [1, 22, 27, 29, 41, 42]),
   (54, [1, 27, 29, 30, 31, 44]),
   (54, [2, 5, 27, 37, 43, 48]),
   (54, [4, 5, 27, 37, 42, 47]),
   (54, [5, 24, 27, 28, 35, 43]),
   (54, [6, 11, 17, 27, 49, 52]),
   (54, [6, 13, 16, 27, 47, 53]),
   (54, [6, 27, 29, 31, 34, 35]),
   (54, [7, 12, 17, 27, 49, 50]),
   (54, [7, 17, 24, 27, 41, 46]),
   (54, [8, 13, 27, 30, 37, 47]),
   (54, [10, 23, 24, 25, 27, 53]),
   (54, [11, 19, 23, 27, 40, 42]),
   (54, [11, 19, 26, 27, 30, 49]),
   (54, [12, 13, 25, 27, 32, 53]),
   (54, [12, 14, 27, 31, 35, 43]),
   (54, [19, 20, 23, 25, 27, 48]),
   (70, [1, 29, 35, 43, 45, 57]),
   (70, [3, 17, 31, 35, 59, 65]),
   (70, [5, 11, 35, 39, 53, 67]),
   (70, [9, 23, 35, 37, 51, 55]),
   (70, [13, 25, 27, 35, 41, 69]),
   (70, [15, 19, 33, 35, 47, 61]),
   (72, [2, 10, 36, 50, 54, 64]),
   (72, [2, 10, 36, 54, 56, 58]),
   (72, [2, 26, 36, 40, 54, 58]),
   (72, [8, 18, 22, 36, 62, 70]),
   (72, [8, 26, 34, 36, 54, 58]),
   (72, [10, 32, 34, 36, 50, 54]),
   (72, [14, 16, 18, 36, 62, 70]),
   (72, [14, 18, 32, 36, 46, 70]),
   (72, [14, 18, 36, 38, 46, 64]),
   (72, [16, 26, 34, 36, 50, 54]),
   (72, [18, 22, 36, 38, 40, 62]),
   (72, [18, 22, 36, 38, 46, 56]),
   (78, [1, 39, 42, 45, 53, 54]),
   (78, [3, 7, 39, 59, 60, 66]),
   (78, [5, 31, 36, 39, 54, 69]),
   (78, [6, 29, 39, 48, 55, 57]),
   (78, [6, 30, 39, 41, 51, 67]),
   (78, [9, 24, 39, 42, 47, 73]),
   (78, [11, 27, 37, 39, 48, 72]),
   (78, [12, 17, 39, 43, 60, 63]),
   (78, [12, 18, 19, 39, 71, 75]),
   (78, [15, 18, 35, 39, 61, 66]),
   (78, [21, 23, 30, 39, 49, 72]),
   (78, [24, 25, 33, 36, 39, 77])]

set_option maxRecDepth 100000 in
theorem has_half : red.all (fun (m, c) => c.any (fun a => Nat.beq a (m / 2)) && Nat.beq (rest m c).length 5) = true := rfl

set_option maxRecDepth 100000 in
theorem half_bal : red.all (fun (m, _) => bal m [m / 2]) = true := rfl

set_option maxRecDepth 100000 in
theorem rest_bal : red.all (fun (m, c) => bal m (rest m c)) = true := rfl

set_option maxRecDepth 100000 in
theorem rest_indec : red.all (fun (m, c) => indec m (rest m c)) = true := rfl

set_option maxRecDepth 100000 in
theorem reducible : red.all (fun (m, c) => !(indec m c)) = true := rfl

end HalfSplit

#print axioms HalfSplit.has_half
#print axioms HalfSplit.half_bal
#print axioms HalfSplit.rest_bal
#print axioms HalfSplit.rest_indec
#print axioms HalfSplit.reducible

#print axioms: 5 theorems, no axioms.

81.35 \(m=80\) and \(m=84\)

At \(m=80\) the 24 unreached characters are three orbits of an arithmetic progression of step \(m/4\) plus a pair. \(m=80:\ 3\times 8;\quad m=84:\ 12\ \text {reducible}=\{42\}\sqcup c'\)

hodge/Unreached80.lean

/-
  hodge/Unreached80.lean — T41 cycle 195: the unreached characters of length 6 at m = 80 and the reducible ones at
  m = 84 (a2_reach79: m = 79, 81, 82, 83 have none; work/data/ckpt/agent2_T41/reach/all_<m>.jsonl).

  Lean 4 core plus hodge/OrbitDecomp (union, orbit), hodge/HalfSplit (rest), hodge/Indecomp (bal, indec), rfl.
    size80, irr80   the twist orbits of 3 representatives give the 24 unreached characters at m = 80, all
                    without a balanced splitting
    ap80            each of the 24 contains an arithmetic progression a, a + 20, a + 40, a + 60 (step m/4) — the
                    pattern of m = 32 (O32) and m = 64: AP of step m/4 plus a pair
    red84           the 12 reducible unreached characters at m = 84 contain 42, the other five entries are balanced
                    and have no balanced splitting (as at m = 36 … 78, HalfSplit)
  The orbit decomposition of the 358 unreached characters at m = 84 (25 orbits, 346 irreducible) is
  hodge/OrbitDecomp3 (Kamiak).
-/
import hodge.OrbitDecomp
import hodge.HalfSplit

namespace Unreached80
open Orbits Indecomp OrbitDecomp HalfSplit

def reps80 : List (List Nat) := [[1, 21, 41, 44, 61, 72], [1, 21, 41, 48, 61, 68], [1, 21, 41, 52, 61, 64]]

set_option maxRecDepth 400000 in
theorem size80 : Nat.beq (union 80 reps80).length 24 = true := rfl

set_option maxRecDepth 400000 in
theorem irr80 : (union 80 reps80).all (indec 80) = true := rfl

def hasAP (m : Nat) (c : List Nat) : Bool :=
  c.any (fun a => [1, 2, 3].all (fun k => c.any (fun b => Nat.beq b ((a + k * (m / 4)) % m))))

set_option maxRecDepth 400000 in
theorem ap80 : (union 80 reps80).all (hasAP 80) = true := rfl

def red84 : List (List Nat) := [[1, 29, 42, 45, 66, 69], [3, 11, 42, 54, 67, 75], [3, 27, 42, 43, 66, 71], [5, 9, 42, 57, 61, 78], [6, 23, 27, 42, 75, 79], [6, 33, 37, 42, 65, 69], [9, 17, 30, 42, 73, 81], [13, 18, 41, 42, 57, 81], [15, 18, 39, 42, 55, 83], [15, 19, 42, 47, 51, 78], [25, 33, 42, 45, 53, 54], [30, 31, 39, 42, 51, 59]]

set_option maxRecDepth 100000 in
theorem red84_ok : red84.all (fun c => c.any (fun a => Nat.beq a 42) && bal 84 (rest 84 c) && indec 84 (rest 84 c)
    && !(indec 84 c)) = true := rfl

theorem red84_count : red84.length = 12 := rfl

end Unreached80

#print axioms Unreached80.size80
#print axioms Unreached80.irr80
#print axioms Unreached80.ap80
#print axioms Unreached80.red84_ok
#print axioms Unreached80.red84_count

#print axioms: 5 theorems, no axioms.

81.36 Orbit decomposition, \(m=84\)

The 358 unreached characters at \(m=84\) form 25 Galois orbits. \(25\ \text {orbits},\ 358,\ 346\ \text {irreducible}\)

hodge/OrbitDecomp3.lean

/-
  hodge/OrbitDecomp3.lean — T41 cycle 195: Galois orbit decomposition of the full unreached set at m = 84.

  Lean 4 core plus hodge/OrbitDecomp (union), hodge/Indecomp (indec), rfl (Kamiak). The twist orbits of the 25
  representatives give the 358 unreached characters of length 6 at m = 84 (a2_reach79, all_84.jsonl); 346 of them have
  no balanced splitting (the other 12: Unreached80.red84). Orbit sizes 4, 6×5, 12×11, 24×8.
-/
import hodge.OrbitDecomp

namespace OrbitDecomp3
open Orbits Indecomp OrbitDecomp

def reps84 : List (List Nat) := [[1, 6, 13, 69, 81, 82], [1, 12, 13, 69, 76, 81], [1, 13, 28, 51, 77, 82], [1, 13, 30, 58, 69, 81], [1, 13, 38, 50, 69, 81], [1, 13, 49, 51, 56, 82], [1, 25, 37, 43, 67, 79], [1, 25, 38, 43, 67, 78], [1, 26, 29, 45, 69, 82], [1, 28, 29, 51, 66, 77], [1, 29, 30, 43, 71, 78], [1, 29, 30, 45, 69, 78], [1, 29, 42, 45, 66, 69], [1, 29, 45, 48, 60, 69], [1, 30, 32, 43, 68  -- (+254 chars; full line in the Zenodo source)

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size84 : Nat.beq (union 84 reps84).length 358 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr84 : Nat.beq ((union 84 reps84).filter (indec 84)).length 346 = true := rfl

end OrbitDecomp3

#print axioms OrbitDecomp3.size84
#print axioms OrbitDecomp3.irr84

#print axioms: 2 theorems, no axioms.

81.37 \(m=88\) and \(m=90\)

At \(m=88\) the 20 unreached characters are two orbits of a progression of step \(m/4\) plus a pair. \(m=88:\ 2\times 10;\quad m=90:\ 6\ \text {reducible}=\{45\}\sqcup c'\)

hodge/Unreached88.lean

/-
  hodge/Unreached88.lean — T41 cycle 236: the unreached characters of length 6 at m = 88 and the reducible ones at
  m = 90 (a2_reach85: m = 85, 86, 87, 89 have none; work/data/ckpt/agent2_T41/reach/all_<m>.jsonl).

  Lean 4 core plus hodge/Unreached80 (hasAP), hodge/OrbitDecomp (union), hodge/HalfSplit (rest), rfl.
    size88, irr88, ap88   2 orbits of 10 give the 20 unreached characters at m = 88, all irreducible, each with an
                          arithmetic progression of step m/4 = 22 (start odd in one orbit, even in the other)
    red90                 the 6 reducible unreached characters at m = 90 are 45 plus an irreducible balanced 5-list
  The 480 unreached characters at m = 90 (23 orbits, 474 irreducible): hodge/OrbitDecomp4 (Kamiak).
-/
import hodge.Unreached80

namespace Unreached88
open Orbits Indecomp OrbitDecomp HalfSplit Unreached80

def reps88 : List (List Nat) := [[1,  23,  45,  48,  67,  80],  [2,  24,  46,  52,  68,  72]]

set_option maxRecDepth 400000 in
theorem size88 : Nat.beq (union 88 reps88).length 20 = true := rfl

set_option maxRecDepth 400000 in
theorem irr88 : (union 88 reps88).all (indec 88) = true := rfl

set_option maxRecDepth 400000 in
theorem ap88 : (union 88 reps88).all (hasAP 88) = true := rfl

def red90 : List (List Nat) := [[2,  38,  45,  55,  56,  74],  [4,  22,  45,  58,  65,  76],  [5,  28,  45,  46,  64,  82],  [8,  26,  44,  45,  62,  85],  [14,  25,  32,  45,  68,  86],  [16,  34,  35,  45,  52,  88]]

set_option maxRecDepth 100000 in
theorem red90_ok : red90.all (fun c => c.any (fun a => Nat.beq a 45) && bal 90 (rest 90 c) && indec 90 (rest 90 c)
    && !(indec 90 c)) = true := rfl

theorem red90_count : red90.length = 6 := rfl

end Unreached88

#print axioms Unreached88.size88
#print axioms Unreached88.irr88
#print axioms Unreached88.ap88
#print axioms Unreached88.red90_ok
#print axioms Unreached88.red90_count

#print axioms: 5 theorems, no axioms.

81.38 Orbit decomposition, \(m=90\)

The 480 unreached characters at \(m=90\) form 23 Galois orbits. \(23\ \text {orbits},\ 480,\ 474\ \text {irreducible}\)

hodge/OrbitDecomp4.lean

/-
  hodge/OrbitDecomp4.lean — T41 cycle 236: Galois orbit decomposition of the full unreached set at m = 90.

  Lean 4 core plus hodge/OrbitDecomp (union), hodge/Indecomp (indec), rfl (Kamiak). The twist orbits of the 23
  representatives give the 480 unreached characters of length 6 at m = 90 (a2_reach85, all_90.jsonl); 474 of them have
  no balanced splitting (the other 6: Unreached88.red90).
-/
import hodge.OrbitDecomp

namespace OrbitDecomp4
open Orbits Indecomp OrbitDecomp

def reps90 : List (List Nat) := [[1,  6,  14,  74,  87,  88],  [1,  7,  48,  52,  74,  88],  [1,  8,  26,  62,  85,  88],  [1,  12,  14,  74,  81,  88],  [1,  14,  24,  69,  74,  88],  [1,  14,  32,  62,  74,  87],  [1,  14,  37,  48,  82,  88],  [1,  14,  48,  58,  61,  88],  [1,  14,  48,  61,  62,  84],  [1,  14,  51,  61,  62,  81],  [1,  14,  57,  61,  62,  75],  [1,  14,  60,  61,  62,  72],  -- (+341 chars; full line in the Zenodo source)

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size90 : Nat.beq (union 90 reps90).length 480 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr90 : Nat.beq ((union 90 reps90).filter (indec 90)).length 474 = true := rfl

end OrbitDecomp4

#print axioms OrbitDecomp4.size90
#print axioms OrbitDecomp4.irr90

#print axioms: 2 theorems, no axioms.

81.39 Nat.mod by hand

Remainder lemmas from the fuel recursion of the core definition. \((x+by)\bmod y=x\bmod y,\quad x<y\Rightarrow x\bmod y=x\)

hodge/ModHand.lean

/-
  hodge/ModHand.lean — T41 cycle 239 (goal G4, step 1): the Nat.mod lemmas needed for balanced characters, proved
  by hand from the axiom-free unfoldings Nat.mod.eq_def, Nat.modCore.eq_def, Nat.modCore.go.eq_def (core's own
  Nat.mod_eq_of_lt, Nat.add_mod_right, … depend on propext).

  Lean 4 core only.
    go_fuel      the fuel of Nat.modCore.go is irrelevant (any fuel > x)
    go_lt        x < y ⇒ go … x = x
    go_le        y ≤ x ⇒ go … (F + 1) x = go … F (x − y)
    mod_go       x % y = go y _ (x + 1) x _
    mod_lt'      x < y ⇒ x % y = x
    add_sub'     (x + y) − y = x
    add_mod'     (x + y) % y = x % y
    add_mul_mod' (x + b·y) % y = x % y
-/
namespace ModHand

theorem go_fuel (y : Nat) (hy : 0 < y) : ∀ (F F' x : Nat) (h : x < F) (h' : x < F'),
    Nat.modCore.go y hy F x h = Nat.modCore.go y hy F' x h'
  | 0, _, x, h, _ => absurd h (Nat.not_lt_zero x)
  | _, 0, x, _, h' => absurd h' (Nat.not_lt_zero x)
  | F + 1, F' + 1, x, h, h' => by
    rw [Nat.modCore.go.eq_def, Nat.modCore.go.eq_def]
    show (if hyx : y ≤ x then Nat.modCore.go y hy F (x - y) _ else x)
      = (if hyx : y ≤ x then Nat.modCore.go y hy F' (x - y) _ else x)
    by_cases hyx : y ≤ x
    · rw [dite_eq_left hyx, dite_eq_left hyx]; exact go_fuel y hy F F' (x - y) _ _
    · rw [dite_eq_right hyx, dite_eq_right hyx]

theorem go_lt (y : Nat) (hy : 0 < y) : ∀ (F x : Nat) (h : x < F), x < y → Nat.modCore.go y hy F x h = x
  | 0, x, h, _ => absurd h (Nat.not_lt_zero x)
  | F + 1, x, h, hxy => by
    rw [Nat.modCore.go.eq_def]
    show (if hyx : y ≤ x then Nat.modCore.go y hy F (x - y) _ else x) = x
    rw [dite_eq_right (Nat.not_le_of_gt hxy)]

theorem go_le (y : Nat) (hy : 0 < y) (F x : Nat) (h : x < F + 1) (hyx : y ≤ x) (h2 : x - y < F) :
    Nat.modCore.go y hy (F + 1) x h = Nat.modCore.go y hy F (x - y) h2 := by
  rw [Nat.modCore.go.eq_def]
  show (if hyx : y ≤ x then Nat.modCore.go y hy F (x - y) _ else x) = _
  rw [dite_eq_left hyx]

theorem go_arg (y : Nat) (hy : 0 < y) (F x x' : Nat) (h : x < F) (h' : x' < F) (e : x = x') :
    Nat.modCore.go y hy F x h = Nat.modCore.go y hy F x' h' := by
  subst e; rfl

theorem mod_go (y : Nat) (hy : 0 < y) : ∀ x, x % y = Nat.modCore.go y hy (x + 1) x (Nat.lt_succ_self x)
  | 0 => by
    show Nat.mod 0 y = _
    rw [Nat.mod.eq_def]
    exact (go_lt y hy 1 0 _ hy).symm
  | k + 1 => by
    show Nat.mod (k + 1) y = _
    rw [Nat.mod.eq_def]
    show (if y ≤ k + 1 then Nat.modCore (k + 1) y else k + 1) = _
    by_cases hyx : y ≤ k + 1
    · rw [ite_eq_left hyx, Nat.modCore.eq_def, dite_eq_left hy]
    · rw [ite_eq_right hyx]
      exact (go_lt y hy (k + 2) (k + 1) _ (Nat.gt_of_not_le hyx)).symm

theorem mod_lt' (x y : Nat) (hxy : x < y) : x % y = x := by
  have hy : 0 < y := Nat.lt_of_le_of_lt (Nat.zero_le x) hxy
  rw [mod_go y hy x]
  exact go_lt y hy (x + 1) x _ hxy

theorem add_sub' (x : Nat) : ∀ y, (x + y) - y = x
  | 0 => rfl
  | y + 1 => by
    show (x + y + 1) - (y + 1) = x
    rw [Nat.succ_sub_succ]; exact add_sub' x y

theorem add_mod' (x y : Nat) (hy : 0 < y) : (x + y) % y = x % y := by
  rw [mod_go y hy (x + y), mod_go y hy x]
  have hle : y ≤ x + y := Nat.le_add_left y x
  have h2 : (x + y) - y < x + y := by rw [add_sub' x y]; exact Nat.lt_of_lt_of_le (Nat.lt_succ_self x) (Nat.succ_le_of_lt (Nat.lt_of_lt_of_le (Nat.lt_succ_self x) (Nat.succ_le_of_lt (Nat.lt_add_of_pos_right hy))))
  rw [go_le y hy (x + y) (x + y) _ hle h2]
  have e : (x + y) - y = x := add_sub' x y
  -- rewrite the argument and adjust the fuel
  rw [go_fuel y hy (x + y) (x + 1) ((x + y) - y) h2 (by rw [e]; exact Nat.lt_succ_self x)]
  exact go_arg y hy (x + 1) _ _ _ _ e

theorem add_mul_mod' (x y : Nat) (hy : 0 < y) : ∀ b, (x + b * y) % y = x % y
  | 0 => by rw [Nat.zero_mul, Nat.add_zero]
  | b + 1 => by
    rw [Nat.succ_mul, ← Nat.add_assoc, add_mod' _ y hy]
    exact add_mul_mod' x y hy b

end ModHand

#print axioms ModHand.go_fuel
#print axioms ModHand.go_lt
#print axioms ModHand.go_le
#print axioms ModHand.go_arg
#print axioms ModHand.mod_go
#print axioms ModHand.mod_lt'
#print axioms ModHand.add_sub'
#print axioms ModHand.add_mod'
#print axioms ModHand.add_mul_mod'

#print axioms: 9 theorems, no axioms.

81.40 \(m/2\) splits off, given odd units

The half splits off any balanced character of an even \(m\) whose units are odd. \([h]\ \text {balanced in}\ 2h,\quad h::c'\ \text {balanced}\Rightarrow c'\ \text {balanced}\)

hodge/HalfGeneral.lean

/-
  hodge/HalfGeneral.lean — T41 cycle 242 (goal G4, step 2): m/2 splits off a balanced character for every even m
  whose units are odd.

  Lean 4 core plus hodge/ModHand (mod_lt', add_mul_mod'), hodge/Indecomp (bal, tsum). For m = h + h, h > 0:
    isOdd, odd_form    structural parity; isOdd t ⇒ t = 2s + 1
    half_mul           t odd ⇒ t·h mod m = h
    half_bal           (units m).all isOdd ⇒ [h] is balanced
    rest_bal           (units m).all isOdd ⇒ (h :: rest balanced ⇒ rest balanced)
  The hypothesis (units m).all isOdd is true for every even m (a unit is prime to 2) — checked here by rfl for every
  even m ≤ 100 (units_odd_100); for symbolic m it needs gcd lemmas, which in core depend on Quot.sound.
-/
import hodge.ModHand
import hodge.Indecomp

namespace HalfGeneral
open Indecomp ModHand

def isOdd : Nat → Bool
  | 0 => false
  | 1 => true
  | n + 2 => isOdd n

theorem odd_form : ∀ t, isOdd t = true → ∃ s, t = 2 * s + 1
  | 0, h => Bool.noConfusion h
  | 1, _ => ⟨0, rfl⟩
  | n + 2, h => by
    have ⟨s, hs⟩ := odd_form n h
    exact ⟨s + 1, by rw [hs, Nat.mul_succ]⟩

theorem all_imp {α : Type} (p q : α → Bool) (h : ∀ x, p x = true → q x = true) :
    ∀ l : List α, l.all p = true → l.all q = true
  | [], _ => rfl
  | x :: l, hp => by
    have hp' : (p x && l.all p) = true := hp
    cases hpx : p x with
    | false => rw [hpx] at hp'; exact Bool.noConfusion hp'
    | true =>
      rw [hpx] at hp'
      show (q x && l.all q) = true
      rw [h x hpx, all_imp p q h l hp']; rfl

theorem beq_self (n : Nat) : Nat.beq n n = true := by
  induction n with
  | zero => rfl
  | succ k ih => exact ih

theorem add_right_cancel' (a b : Nat) : ∀ c, a + c = b + c → a = b
  | 0, h => h
  | c + 1, h => add_right_cancel' a b c (Nat.succ.inj h)

theorem half_mul (h t : Nat) (hh : 0 < h) (ht : isOdd t = true) : t * h % (h + h) = h := by
  have ⟨s, hs⟩ := odd_form t ht
  have e : t * h = h + s * (h + h) := by
    rw [hs, Nat.mul_comm (2 * s + 1) h, Nat.left_distrib, Nat.mul_one, Nat.two_mul, Nat.left_distrib,
      Nat.left_distrib s h h, Nat.mul_comm h s]
    exact Nat.add_comm _ _
  rw [e, add_mul_mod' h (h + h) (Nat.lt_of_lt_of_le hh (Nat.le_add_right h h)) s]
  exact mod_lt' h (h + h) (Nat.lt_add_of_pos_right hh)

/-- **[h] is balanced in m = h + h.** -/
theorem half_bal (h : Nat) (hh : 0 < h) (hu : (FermatPrime.units (h + h)).all isOdd = true) :
    bal (h + h) [h] = true := by
  unfold bal
  apply all_imp _ _ _ _ hu
  intro t ht
  show Nat.beq (t * h % (h + h) + 0 + (t * h % (h + h) + 0)) (1 * (h + h)) = true
  rw [half_mul h t hh ht, Nat.add_zero, Nat.one_mul]
  exact beq_self _

/-- **The rest of a balanced character containing h is balanced.** -/
theorem rest_bal (h : Nat) (hh : 0 < h) (hu : (FermatPrime.units (h + h)).all isOdd = true) (rest : List Nat)
    (hb : bal (h + h) (h :: rest) = true) : bal (h + h) rest = true := by
  unfold bal at hb ⊢
  -- pair each unit's two facts: odd and balanced for h :: rest
  have both : (FermatPrime.units (h + h)).all
      (fun t => isOdd t && Nat.beq (tsum (h + h) t (h :: rest) + tsum (h + h) t (h :: rest))
        ((h :: rest).length * (h + h))) = true := by
    have z : ∀ l : List Nat, l.all isOdd = true →
        l.all (fun t => Nat.beq (tsum (h + h) t (h :: rest) + tsum (h + h) t (h :: rest)) ((h :: rest).length * (h + h))) = true →
        l.all (fun t => isOdd t && Nat.beq (tsum (h + h) t (h :: rest) + tsum (h + h) t (h :: rest))
          ((h :: rest).length * (h + h))) = true := by
      intro l; induction l with
      | nil => intro _ _; rfl
      | cons x l ih =>
        intro h1 h2
        have h1' : (isOdd x && l.all isOdd) = true := h1
        have h2' : (Nat.beq (tsum (h + h) x (h :: rest) + tsum (h + h) x (h :: rest)) ((h :: rest).length * (h + h))
          && l.all _) = true := h2
        cases a : isOdd x <;> cases b : Nat.beq (tsum (h + h) x (h :: rest) + tsum (h + h) x (h :: rest))
          ((h :: rest).length * (h + h)) <;> rw [a] at h1' <;> rw [b] at h2'
        · exact Bool.noConfusion h1'
        · exact Bool.noConfusion h1'
        · exact Bool.noConfusion h2'
        · show ((isOdd x && Nat.beq (tsum (h + h) x (h :: rest) + tsum (h + h) x (h :: rest))
            ((h :: rest).length * (h + h))) && l.all _) = true
          rw [a, b, ih h1' h2']; rfl
    exact z _ hu hb
  apply all_imp _ _ _ _ both
  intro t hboth
  have hboth' : (isOdd t && Nat.beq (tsum (h + h) t (h :: rest) + tsum (h + h) t (h :: rest))
      ((h :: rest).length * (h + h))) = true := hboth
  cases a : isOdd t with
  | false => rw [a] at hboth'; exact Bool.noConfusion hboth'
  | true =>
    rw [a] at hboth'
    have e := Nat.eq_of_beq_eq_true hboth'
    have e2 : tsum (h + h) t (h :: rest) = h + tsum (h + h) t rest := by
      show t * h % (h + h) + tsum (h + h) t rest = _
      rw [half_mul h t hh a]
    rw [e2] at e
    -- (h + S) + (h + S) = (len + 1)(h + h) = len (h + h) + (h + h)
    have e3 : (tsum (h + h) t rest + tsum (h + h) t rest) + (h + h) = rest.length * (h + h) + (h + h) := by
      calc (tsum (h + h) t rest + tsum (h + h) t rest) + (h + h)
          = (h + tsum (h + h) t rest) + (h + tsum (h + h) t rest) := by
            rw [Nat.add_comm (tsum (h + h) t rest + tsum (h + h) t rest) (h + h), Nat.add_assoc, Nat.add_assoc,
              Nat.add_left_comm h (tsum (h + h) t rest)]
        _ = (rest.length + 1) * (h + h) := e
        _ = rest.length * (h + h) + (h + h) := Nat.succ_mul _ _
    rw [add_right_cancel' _ _ _ e3]
    exact beq_self _

theorem units_odd_100 : (List.range 51).all (fun h => Nat.beq h 0 || (FermatPrime.units (h + h)).all isOdd) = true := rfl

end HalfGeneral

#print axioms HalfGeneral.odd_form
#print axioms HalfGeneral.all_imp
#print axioms HalfGeneral.beq_self
#print axioms HalfGeneral.add_right_cancel'
#print axioms HalfGeneral.half_mul
#print axioms HalfGeneral.half_bal
#print axioms HalfGeneral.rest_bal
#print axioms HalfGeneral.units_odd_100

#print axioms: 8 theorems, no axioms.

81.41 Units of an even \(m\) are odd

Core gcd followed by hand through its fuel recursion; the half splits off for every even \(m\). \(2\mid m,\ 2\mid n\Rightarrow 2\mid \gcd (m,n)\)

hodge/GcdHand.lean

/-
  hodge/GcdHand.lean — T41 cycle 254 (goal G10): the units of an even m are odd, for every m, axiom-free; with
  HalfGeneral this gives the m/2 split for every even m with no hypothesis.

  Lean 4 core plus hodge/HalfGeneral (isOdd, half_bal, rest_bal), hodge/ModHand (mod_lt', add_mod', add_sub'),
  bsd/TorsionImage (parity, odd_ne_even), lib/Semi (lib_nat). Core's Nat.gcd is WellFounded.Nat.fix.go with fuel;
  its unfolding lemmas (Nat.gcd.eq_def, Nat.gcd_rec, Nat.dvd_gcd) depend on Quot.sound, but the definition itself
  matches GH/GF below by rfl, and the fuel recursion can be followed by hand.
    gcd_go        Nat.gcd m n = go GH GF (eager (m + 1)) ⟨m, n⟩          (rfl after delta)
    div_mod       n = n % m + m·q for some q                               (fuel induction, ModHand)
    even_mod      2 ∣ n, 2 ∣ m ⇒ 2 ∣ n % m
    two_dvd_gcd   2 ∣ m, 2 ∣ n ⇒ 2 ∣ gcd m n                               (fuel induction on go)
    units_odd     every unit of an even m is odd
    half_bal_even, rest_bal_even   HalfGeneral without the hypothesis (units m).all isOdd
-/
import hodge.HalfGeneral
import bsd.TorsionImage

namespace GcdHand
open ModHand HalfGeneral TorsionImage Indecomp

def GH : (_ : Nat) ×' Nat → Nat := fun x => PSigma.casesOn x fun m _ => m

def GF : (x : (_ : Nat) ×' Nat) → ((y : (_ : Nat) ×' Nat) → InvImage (fun x1 x2 => x1 < x2) GH y x → Nat) → Nat :=
  fun x a => PSigma.casesOn (motive := fun x =>
      ((y : (_ : Nat) ×' Nat) → InvImage (fun x1 x2 => x1 < x2) GH y x → Nat) → Nat)
    x (fun m n a => if h : m = 0 then n else a ⟨n % m, m⟩ (Nat.mod_lt n (Nat.pos_of_ne_zero h))) a

theorem eager_gt (m : Nat) : m < WellFounded.Nat.eager (m + 1) := by
  unfold WellFounded.Nat.eager
  split <;> exact Nat.lt_succ_self m

theorem gcd_go (m n : Nat) : Nat.gcd m n = WellFounded.Nat.fix.go GH GF (WellFounded.Nat.eager (m + 1)) ⟨m, n⟩ (eager_gt m) := by
  delta Nat.gcd Nat.gcd._unary WellFounded.Nat.fix
  rfl

theorem sub_add' : ∀ m n : Nat, m ≤ n → n - m + m = n
  | 0, n, _ => rfl
  | m + 1, 0, h => absurd h (Nat.not_succ_le_zero m)
  | m + 1, n + 1, h => by
    rw [Nat.succ_sub_succ, show n - m + (m + 1) = (n - m + m) + 1 from rfl, sub_add' m n (Nat.le_of_succ_le_succ h)]

theorem div_mod (m : Nat) (hm : 0 < m) : ∀ F n, n < F → ∃ q, n = n % m + m * q
  | 0, n, h => absurd h (Nat.not_lt_zero n)
  | F + 1, n, h => by
    by_cases hnm : n < m
    · exact ⟨0, by rw [mod_lt' n m hnm, Nat.mul_zero, Nat.add_zero]⟩
    · have hle : m ≤ n := Nat.le_of_not_lt hnm
      have e : n - m + m = n := sub_add' m n hle
      have hlt : n - m < F := by
        have this : n - m + 1 ≤ n := by
          have a := Nat.add_le_add_left hm (n - m)
          rw [e] at a; exact a
        exact Nat.lt_of_lt_of_le (Nat.lt_of_succ_le this) (Nat.le_of_lt_succ h)
      have ⟨q, hq⟩ := div_mod m hm F (n - m) hlt
      refine ⟨q + 1, ?_⟩
      have hmod : n % m = (n - m) % m := by rw [← add_mod' (n - m) m hm, e]
      rw [hmod]
      calc n = (n - m) + m := e.symm
        _ = ((n - m) % m + m * q) + m := by rw [← hq]
        _ = (n - m) % m + m * (q + 1) := by rw [Nat.mul_succ, Nat.add_assoc]

theorem even_mod (n m : Nat) (hm : 0 < m) (hn : ∃ a, n = 2 * a) (hm2 : ∃ b, m = 2 * b) : ∃ c, n % m = 2 * c := by
  have ⟨q, hq⟩ := div_mod m hm (n + 1) n (Nat.lt_succ_self n)
  have ⟨a, ha⟩ := hn
  have ⟨b, hb⟩ := hm2
  have ⟨c, hc⟩ := parity (n % m)
  cases hc with
  | inl e => exact ⟨c, e⟩
  | inr e =>
    rw [e, hb, ha, show 2 * c + 1 + 2 * b * q = 2 * (c + b * q) + 1 by lib_nat] at hq
    exact absurd hq.symm (odd_ne_even _ _)

theorem two_dvd_go : ∀ (f : Nat) (x : (_ : Nat) ×' Nat) (hf : GH x < f),
    (∃ a, x.1 = 2 * a) → (∃ b, x.2 = 2 * b) → ∃ c, WellFounded.Nat.fix.go GH GF f x hf = 2 * c
  | 0, _, hf, _, _ => absurd hf (Nat.not_lt_zero _)
  | f + 1, ⟨m, n⟩, hf, hm, hn => by
    show ∃ c, (if h : m = 0 then n else WellFounded.Nat.fix.go GH GF f ⟨n % m, m⟩ _) = 2 * c
    by_cases h0 : m = 0
    · rw [dite_eq_left h0]; exact hn
    · rw [dite_eq_right h0]
      exact two_dvd_go f ⟨n % m, m⟩ _ (even_mod n m (Nat.pos_of_ne_zero h0) hn hm) hm

theorem two_dvd_gcd (m n : Nat) (hm : ∃ a, m = 2 * a) (hn : ∃ b, n = 2 * b) : ∃ c, Nat.gcd m n = 2 * c := by
  rw [gcd_go]; exact two_dvd_go _ ⟨m, n⟩ _ hm hn

theorem isOdd_odd : ∀ c, isOdd (2 * c + 1) = true
  | 0 => rfl
  | c + 1 => by rw [show 2 * (c + 1) + 1 = (2 * c + 1) + 2 by lib_nat]; exact isOdd_odd c

theorem unit_isOdd (h t : Nat) (hg : Nat.gcd t (h + h) = 1) : isOdd t = true := by
  have ⟨c, hc⟩ := parity t
  cases hc with
  | inr e => rw [e]; exact isOdd_odd c
  | inl e =>
    have ⟨d, hd⟩ := two_dvd_gcd t (h + h) ⟨c, e⟩ ⟨h, by lib_nat⟩
    rw [hg] at hd
    exact absurd (show 2 * 0 + 1 = 2 * d by rw [← hd]) (odd_ne_even 0 d)

theorem filter_all {α : Type} (q p : α → Bool) (hqp : ∀ x, q x = true → p x = true) :
    ∀ l : List α, (l.filter q).all p = true
  | [] => rfl
  | x :: l => by
    cases hq : q x with
    | false =>
      have e : (x :: l).filter q = l.filter q := by
        show (match q x with | true => x :: l.filter q | false => l.filter q) = _; rw [hq]
      rw [e]; exact filter_all q p hqp l
    | true =>
      have e : (x :: l).filter q = x :: l.filter q := by
        show (match q x with | true => x :: l.filter q | false => l.filter q) = _; rw [hq]
      rw [e]
      show (p x && (l.filter q).all p) = true
      rw [hqp x hq, filter_all q p hqp l]; rfl

/-- **The units of an even m are odd.** -/
theorem units_odd (h : Nat) : (FermatPrime.units (h + h)).all isOdd = true :=
  filter_all _ _ (fun t hg => unit_isOdd h t (Nat.eq_of_beq_eq_true hg)) _

theorem half_bal_even (h : Nat) (hh : 0 < h) : bal (h + h) [h] = true := half_bal h hh (units_odd h)

theorem rest_bal_even (h : Nat) (hh : 0 < h) (rest : List Nat) (hb : bal (h + h) (h :: rest) = true) :
    bal (h + h) rest = true := rest_bal h hh (units_odd h) rest hb

end GcdHand

#print axioms GcdHand.eager_gt
#print axioms GcdHand.gcd_go
#print axioms GcdHand.sub_add'
#print axioms GcdHand.div_mod
#print axioms GcdHand.even_mod
#print axioms GcdHand.two_dvd_go
#print axioms GcdHand.two_dvd_gcd
#print axioms GcdHand.isOdd_odd
#print axioms GcdHand.unit_isOdd
#print axioms GcdHand.filter_all
#print axioms GcdHand.units_odd
#print axioms GcdHand.half_bal_even
#print axioms GcdHand.rest_bal_even

#print axioms: 13 theorems, no axioms.

81.42 Full reach at \(m=49\), length 6

Every balanced character of \(m=49\) of length 6 is reached by the standard moves; 48 piece files of rfl checks. \(\texttt {allReach}\ 49\ U_{49}\ 6=\texttt {true}\)

hodge/Reach49.lean

/-
  hodge/Reach49.lean — T41 cycle 192: inductive structure with the Aoki–Shioda standard characters as extra base
  covers every Hodge character of length 6 (X_49^4) for m = 49 = 7².

  Lean 4 core plus hodge/Reach49Defs (arf, arf_split, top) and the 48 files hodge/R49/A<a>.lean (first entry a, split
  adaptively until each rfl piece has ≤ 20000 lists; Kamiak). allReach 49 U49 6 is FermatInductive3m49's statement
  in one theorem.
-/
import hodge.R49.A1
import hodge.R49.A2
import hodge.R49.A3
import hodge.R49.A4
import hodge.R49.A5
import hodge.R49.A6
import hodge.R49.A7
import hodge.R49.A8
import hodge.R49.A9
import hodge.R49.A10
import hodge.R49.A11
import hodge.R49.A12
import hodge.R49.A13
import hodge.R49.A14
import hodge.R49.A15
import hodge.R49.A16
import hodge.R49.A17
import hodge.R49.A18
import hodge.R49.A19
import hodge.R49.A20
import hodge.R49.A21
import hodge.R49.A22
import hodge.R49.A23
import hodge.R49.A24
import hodge.R49.A25
import hodge.R49.A26
import hodge.R49.A27
import hodge.R49.A28
import hodge.R49.A29
import hodge.R49.A30
import hodge.R49.A31
import hodge.R49.A32
import hodge.R49.A33
import hodge.R49.A34
import hodge.R49.A35
import hodge.R49.A36
import hodge.R49.A37
import hodge.R49.A38
import hodge.R49.A39
import hodge.R49.A40
import hodge.R49.A41
import hodge.R49.A42
import hodge.R49.A43
import hodge.R49.A44
import hodge.R49.A45
import hodge.R49.A46
import hodge.R49.A47
import hodge.R49.A48

namespace Reach49All
open Reach49

theorem reach49 : allReach 49 U49 6 = true := by
  rw [top, arf_split]
  exact all_cons_true _ _ _ Reach49A1.q_1 (all_cons_true _ _ _ Reach49A2.q_2 (all_cons_true _ _ _ Reach49A3.q_3 (all_cons_true _ _ _ Reach49A4.q_4 (all_cons_true _ _ _ Reach49A5.q_5 (all_cons_true _ _ _ Reach49A6.q_6 (all_cons_true _ _ _ Reach49A7.q_7 (all_cons_true _ _ _ Reach49A8.q_8 (all_cons_true _ _ _ Reach49A9.q_9 (all_cons_true _ _ _ Reach49A10.q_10 (all_cons_true _ _ _ Reach49A11.q_11 (all  -- (+1417 chars; full line in the Zenodo source)

end Reach49All

#print axioms Reach49All.reach49

#print axioms: 1 theorem, no axioms.

81.43 Unreached characters at \(m=96\)

Seven orbits (40 characters) carry an arithmetic progression of step 24; the 8 reducible ones are 48 plus a 5-list. At \(m=104\) all 24 carry one of step 26. \(|\,\text {AP orbits}\,|=40,\quad c=48::c',\ c'\ \text {balanced, irreducible}\)

hodge/Unreached96.lean

/-
  hodge/Unreached96.lean — T41 cycle 266 (goal G8, m = 96): the arithmetic-progression orbits and the reducible
  characters among the 400 unreached characters of length 6 at m = 96 (a2_reach96, work/data/ckpt/agent2_T41/reach/
  all_96.jsonl; 34 orbits, 392 irreducible).

  Lean 4 core plus hodge/Unreached80 (hasAP), hodge/OrbitDecomp (union), hodge/HalfSplit (rest), rfl.
    size96ap, irr96ap, ap96   7 orbits give 40 unreached characters at m = 96, all irreducible, each with an
                              arithmetic progression of step m/4 = 24
    red96_ok, red96_count     the 8 reducible unreached characters are 48 plus an irreducible balanced 5-list
    size104, irr104, ap104    m = 104 (all_104.jsonl): 24 unreached characters, 2 orbits, all irreducible, each with
                              an arithmetic progression of step 26
  The full set at m = 96 (400 characters, 34 orbits): hodge/OrbitDecomp5 (Kamiak).
-/
import hodge.Unreached80

namespace Unreached96
open Orbits Indecomp OrbitDecomp HalfSplit Unreached80

def apreps96 : List (List Nat) := [[1,  25,  49,  52,  73,  88],  [1,  25,  49,  64,  73,  76],  [1,  25,  49,  68,  72,  73],  [2,  26,  50,  56,  74,  80],  [3,  27,  51,  60,  72,  75],  [4,  18,  42,  66,  68,  90],  [6,  30,  32,  54,  78,  88]]

set_option maxRecDepth 400000 in
theorem size96ap : Nat.beq (union 96 apreps96).length 40 = true := rfl

set_option maxRecDepth 400000 in
theorem irr96ap : (union 96 apreps96).all (indec 96) = true := rfl

set_option maxRecDepth 400000 in
theorem ap96 : (union 96 apreps96).all (hasAP 96) = true := rfl

def red96 : List (List Nat) := [[2,  34,  48,  54,  72,  78],  [6,  10,  48,  72,  74,  78],  [6,  30,  48,  50,  72,  82],  [14,  24,  46,  48,  66,  90],  [18,  22,  24,  48,  86,  90],  [18,  24,  42,  48,  62,  94],  [24,  38,  42,  48,  66,  70],  [26,  30,  48,  54,  58,  72]]

set_option maxRecDepth 100000 in
theorem red96_ok : red96.all (fun c => c.any (fun a => Nat.beq a 48) && bal 96 (rest 96 c) && indec 96 (rest 96 c)
    && !(indec 96 c)) = true := rfl

theorem red96_count : red96.length = 8 := rfl

def reps104 : List (List Nat) := [[1,  27,  53,  56,  79,  96],  [2,  28,  54,  60,  80,  88]]

set_option maxRecDepth 400000 in
theorem size104 : Nat.beq (union 104 reps104).length 24 = true := rfl

set_option maxRecDepth 400000 in
theorem irr104 : (union 104 reps104).all (indec 104) = true := rfl

set_option maxRecDepth 400000 in
theorem ap104 : (union 104 reps104).all (hasAP 104) = true := rfl

end Unreached96

#print axioms Unreached96.size96ap
#print axioms Unreached96.irr96ap
#print axioms Unreached96.ap96
#print axioms Unreached96.red96_ok
#print axioms Unreached96.red96_count
#print axioms Unreached96.size104
#print axioms Unreached96.irr104
#print axioms Unreached96.ap104

#print axioms: 8 theorems, no axioms.

81.44 AP\((m/4)\) plus a pair is balanced

For \(m=4q\) and \(8a+b=4q\), the progression of step \(q\) with the pair \((2q+4a,\,b)\) is balanced when no unit sends \(ta\) to \(0\) or \(q/2\) mod \(q\). \(\sum _i\langle tc_i\rangle _m=3m,\quad c=[a,a+q,a+2q,a+3q,2q+4a,b]\)

hodge/APPair.lean

/-
  hodge/APPair.lean — T41 cycle 268 (goal G8, general step): an arithmetic progression of step m/4 plus the pair
  (m/2 + 4a, m − 8a) is a balanced (Hodge) character of the Fermat variety, for every m = 4q.

  Lean 4 core plus lib/NatNorm (Nat polynomial identities), hodge/ModHand, hodge/GcdHand, hodge/HalfGeneral.
    mod_rep, mod_add, zero_mod_two    residues by hand (x = r + k m, r < m ⇒ x mod m = r; etc.)
    four_form, four_cases             t odd ⇒ t = 1 + 4s ∨ 3 + 4s;  N = n₀ + 4N′, n₀ < 4
    res_ap                            t(a + kq) mod 4q = ρ + q·e  when ta = ρ + q(n₀ + 4N′), n₀ + k t₀ = e + 4f
    tsum_key                          for odd t with ρ = ta mod q ∉ {0, q/2}:
                                      Σ ⟨t c_i⟩ = 12q = 3m  for c = [a, a+q, a+2q, a+3q, 2q+4a, b], 8a + b = 4q
    ap_pair_bal                       c is balanced in m = 4q whenever every unit t has ρ_t ∉ {0, q/2}
    ap_pair_96, ap_pair_104           the AP(24), AP(26) characters of Unreached96 come from ap_pair_bal
-/
import lib.NatNorm
import hodge.GcdHand

namespace APPair
open Indecomp ModHand HalfGeneral

theorem mod_rep (x r m k : Nat) (hr : r < m) (h : x = r + k * m) : x % m = r := by
  rw [h, add_mul_mod' r m (Nat.lt_of_le_of_lt (Nat.zero_le r) hr) k]
  exact mod_lt' r m hr

theorem decomp (n m : Nat) (hm : 0 < m) : ∃ k, n = n % m + m * k :=
  GcdHand.div_mod m hm (n + 1) n (Nat.lt_succ_self n)

theorem mod_add (u v m : Nat) (hm : 0 < m) : (u % m + v % m) % m = (u + v) % m := by
  have ⟨i, hi⟩ := decomp u m hm
  have ⟨j, hj⟩ := decomp v m hm
  have e : u + v = (u % m + v % m) + (i + j) * m := by
    calc u + v = (u % m + m * i) + (v % m + m * j) := by rw [← hi, ← hj]
      _ = (u % m + v % m) + (i + j) * m := ((show (u % m) + (m)*(i) + ((v % m) + (m)*(j)) = (u % m) + (v % m) + ((i) + (j))*(m) from NatNorm.sound [u % m, v % m, m, i, j] (.add (.add (.var 0) (.mul (.var 2) (.var 3))) (.add (.var 1) (.mul (.var 2) (.var 4)))) (.add (.add (.var 0) (.var 1)) (.mul (.add (.var 3) (.var 4)) (.var 2))) rfl))
  rw [e, add_mul_mod' _ m hm]

theorem zero_mod_two (z m : Nat) (h0 : 0 < z) (h2 : z < m + m) (hz : z % m = 0) : z = m := by
  cases Nat.lt_or_ge z m with
  | inl h =>
    rw [mod_lt' z m h] at hz
    rw [hz] at h0
    exact absurd h0 (Nat.lt_irrefl 0)
  | inr h =>
    have ⟨w, hw⟩ := Nat.le.dest h
    have hwm : w < m := Nat.lt_of_add_lt_add_left (hw ▸ h2)
    have e : z % m = w := by
      rw [← hw, Nat.add_comm, add_mod' w m (Nat.lt_of_le_of_lt (Nat.zero_le w) hwm)]
      exact mod_lt' w m hwm
    rw [e] at hz
    rw [← hw, hz]
    exact Nat.add_zero m

theorem two_form : ∀ s, ∃ s', s = 2 * s' ∨ s = 2 * s' + 1
  | 0 => ⟨0, Or.inl rfl⟩
  | s + 1 => by
    have ⟨s', h⟩ := two_form s
    cases h with
    | inl h => exact ⟨s', Or.inr (by rw [h])⟩
    | inr h => exact ⟨s' + 1, Or.inl (by rw [h]; exact ((show 2*(s')+1+1 = 2*((s')+1) from NatNorm.sound [s'] (.add (.add (.mul (.lit 2) (.var 0)) (.lit 1)) (.lit 1)) (.mul (.lit 2) (.add (.var 0) (.lit 1))) rfl)))⟩

theorem four_form (t : Nat) (ht : isOdd t = true) : ∃ s, t = 1 + 4 * s ∨ t = 3 + 4 * s := by
  have ⟨s, hs⟩ := odd_form t ht
  have ⟨s', h⟩ := two_form s
  cases h with
  | inl h => exact ⟨s', Or.inl (by rw [hs, h]; exact ((show 2*(2*(s'))+1 = 1+4*(s') from NatNorm.sound [s'] (.add (.mul (.lit 2) (.mul (.lit 2) (.var 0))) (.lit 1)) (.add (.lit 1) (.mul (.lit 4) (.var 0))) rfl)))⟩
  | inr h => exact ⟨s', Or.inr (by rw [hs, h]; exact ((show 2*(2*(s')+1)+1 = 3+4*(s') from NatNorm.sound [s'] (.add (.mul (.lit 2) (.add (.mul (.lit 2) (.var 0)) (.lit 1))) (.lit 1)) (.add (.lit 3) (.mul (.lit 4) (.var 0))) rfl)))⟩

theorem four_cases : ∀ N, ∃ N', N = 0 + 4 * N' ∨ N = 1 + 4 * N' ∨ N = 2 + 4 * N' ∨ N = 3 + 4 * N'
  | 0 => ⟨0, Or.inl rfl⟩
  | N + 1 => by
    have ⟨N', h⟩ := four_cases N
    cases h with
    | inl h => exact ⟨N', Or.inr (Or.inl (by rw [h]; exact ((show 0+4*(N')+1 = 1+4*(N') from NatNorm.sound [N'] (.add (.add (.lit 0) (.mul (.lit 4) (.var 0))) (.lit 1)) (.add (.lit 1) (.mul (.lit 4) (.var 0))) rfl))))⟩
    | inr h => cases h with
      | inl h => exact ⟨N', Or.inr (Or.inr (Or.inl (by rw [h]; exact ((show 1+4*(N')+1 = 2+4*(N') from NatNorm.sound [N'] (.add (.add (.lit 1) (.mul (.lit 4) (.var 0))) (.lit 1)) (.add (.lit 2) (.mul (.lit 4) (.var 0))) rfl)))))⟩
      | inr h => cases h with
        | inl h => exact ⟨N', Or.inr (Or.inr (Or.inr (by rw [h]; exact ((show 2+4*(N')+1 = 3+4*(N') from NatNorm.sound [N'] (.add (.add (.lit 2) (.mul (.lit 4) (.var 0))) (.lit 1)) (.add (.lit 3) (.mul (.lit 4) (.var 0))) rfl)))))⟩
        | inr h => exact ⟨N' + 1, Or.inl (by rw [h]; exact ((show 3+4*(N')+1 = 0+4*((N')+1) from NatNorm.sound [N'] (.add (.add (.lit 3) (.mul (.lit 4) (.var 0))) (.lit 1)) (.add (.lit 0) (.mul (.lit 4) (.add (.var 0) (.lit 1)))) rfl)))⟩

theorem lt4 (ρ q e : Nat) (hρ : ρ < q) (he : e < 4) : ρ + q * e < 4 * q := by
  have ⟨d, hd⟩ := Nat.le.dest he
  have e1 : 4 * q = (q + q * e) + q * d := by
    rw [← hd]; exact ((show ((e)+1+(d))*(q) = (q) + (q)*(e) + (q)*(d) from NatNorm.sound [q, e, d] (.mul (.add (.add (.var 1) (.lit 1)) (.var 2)) (.var 0)) (.add (.add (.var 0) (.mul (.var 0) (.var 1))) (.mul (.var 0) (.var 2))) rfl))
  rw [e1]
  exact Nat.lt_of_lt_of_le (Nat.add_lt_add_right hρ (q * e)) (Nat.le_add_right _ _)

theorem res_ap (q a t ρ N' s' t0 n0 k e f x : Nat) (hρ : ρ < q) (ht : t = t0 + 4 * s')
    (hta : t * a = ρ + q * (n0 + 4 * N')) (hx : x = a + k * q) (hk : n0 + k * t0 = e + 4 * f) (he : e < 4) :
    (t * x) % (4 * q) = ρ + q * e := by
  apply mod_rep _ _ _ (f + N' + k * s') (lt4 ρ q e hρ he)
  have e1 : t * x = t * a + k * q * t := by rw [hx]; exact ((show (t)*((a)+(k)*(q)) = (t)*(a) + (k)*(q)*(t) from NatNorm.sound [t, a, k, q] (.mul (.var 0) (.add (.var 1) (.mul (.var 2) (.var 3)))) (.add (.mul (.var 0) (.var 1)) (.mul (.mul (.var 2) (.var 3)) (.var 0))) rfl))
  rw [e1, hta, ht]
  have e2 : ρ + q * (n0 + 4 * N') + k * q * (t0 + 4 * s') = ρ + q * (n0 + k * t0) + (N' + k * s') * (4 * q) :=
    ((show (ρ) + (q)*((n0) + 4*(N')) + (k)*(q)*((t0) + 4*(s')) = (ρ) + (q)*((n0) + (k)*(t0)) + ((N') + (k)*(s'))*(4*(q)) from NatNorm.sound [ρ, q, n0, N', k, t0, s'] (.add (.add (.var 0) (.mul (.var 1) (.add (.var 2) (.mul (.lit 4) (.var 3))))) (.mul (.mul (.var 4) (.var 1)) (.add (.var 5) (.mul (.lit 4) (.var 6))))) (.add (.add (.var 0) (.mul (.var 1) (.add (.var 2) (.mul (.var 4) (.var 5))))) (.  -- (+77 chars; full line in the Zenodo source)
  rw [e2, hk]
  exact ((show (ρ) + (q)*((e) + 4*(f)) + ((N') + (k)*(s'))*(4*(q)) = (ρ) + (q)*(e) + ((f) + (N') + (k)*(s'))*(4*(q)) from NatNorm.sound [ρ, q, e, f, N', k, s'] (.add (.add (.var 0) (.mul (.var 1) (.add (.var 2) (.mul (.lit 4) (.var 3))))) (.mul (.add (.var 4) (.mul (.var 5) (.var 6))) (.mul (.lit 4) (.var 1)))) (.add (.add (.var 0) (.mul (.var 1) (.var 2))) (.mul (.add (.add (.var 3) (.var 4)) (.m  -- (+55 chars; full line in the Zenodo source)

/-- The four AP residues sum to 4ρ + 6q (for given residue pattern e₀..e₃). -/
theorem ap4 (q a t ρ N' s' t0 n0 e0 e1 e2 e3 f0 f1 f2 f3 : Nat) (hρ : ρ < q) (ht : t = t0 + 4 * s')
    (hta : t * a = ρ + q * (n0 + 4 * N'))
    (k0 : n0 + 0 * t0 = e0 + 4 * f0) (k1 : n0 + 1 * t0 = e1 + 4 * f1) (k2 : n0 + 2 * t0 = e2 + 4 * f2)
    (k3 : n0 + 3 * t0 = e3 + 4 * f3) (l0 : e0 < 4) (l1 : e1 < 4) (l2 : e2 < 4) (l3 : e3 < 4)
    (h6 : e0 + e1 + e2 + e3 = 6) :
    (t * a) % (4 * q) + ((t * (a + q)) % (4 * q) + ((t * (a + 2 * q)) % (4 * q) + (t * (a + 3 * q)) % (4 * q)))
      = 4 * ρ + 6 * q := by
  rw [res_ap q a t ρ N' s' t0 n0 0 e0 f0 a hρ ht hta ((show (a) = (a) + 0*(q) from NatNorm.sound [a, q] (.var 0) (.add (.var 0) (.mul (.lit 0) (.var 1))) rfl)) k0 l0,
    res_ap q a t ρ N' s' t0 n0 1 e1 f1 (a + q) hρ ht hta ((show (a)+(q) = (a) + 1*(q) from NatNorm.sound [a, q] (.add (.var 0) (.var 1)) (.add (.var 0) (.mul (.lit 1) (.var 1))) rfl)) k1 l1,
    res_ap q a t ρ N' s' t0 n0 2 e2 f2 (a + 2 * q) hρ ht hta rfl k2 l2,
    res_ap q a t ρ N' s' t0 n0 3 e3 f3 (a + 3 * q) hρ ht hta rfl k3 l3]
  have e : ρ + q * e0 + (ρ + q * e1 + (ρ + q * e2 + (ρ + q * e3))) = 4 * ρ + q * (e0 + e1 + e2 + e3) :=
    ((show (ρ) + (q)*(e0) + ((ρ) + (q)*(e1) + ((ρ) + (q)*(e2) + ((ρ) + (q)*(e3)))) = 4*(ρ) + (q)*((e0) + (e1) + (e2) + (e3)) from NatNorm.sound [ρ, q, e0, e1, e2, e3] (.add (.add (.var 0) (.mul (.var 1) (.var 2))) (.add (.add (.var 0) (.mul (.var 1) (.var 3))) (.add (.add (.var 0) (.mul (.var 1) (.var 4))) (.add (.var 0) (.mul (.var 1) (.var 5)))))) (.add (.mul (.lit 4) (.var 0)) (.mul (.var 1) (.  -- (+62 chars; full line in the Zenodo source)
  rw [e, h6, Nat.mul_comm q 6]

theorem add_lt_add' (a b c d : Nat) (h1 : a < b) (h2 : c < d) : a + c < b + d :=
  Nat.lt_trans (Nat.add_lt_add_right h1 c) (Nat.add_lt_add_left h2 b)

theorem pos4 (q : Nat) (hq : 0 < q) : 0 < 4 * q :=
  Nat.lt_of_lt_of_le hq (by rw [((show 4*(q) = (q) + 3*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.var 0) (.mul (.lit 3) (.var 0))) rfl))]; exact Nat.le_add_right q (3 * q))

theorem res_p1A (q a t ρ N' s' t0 n0 g : Nat) (ht : t = t0 + 4 * s') (hta : t * a = ρ + q * (n0 + 4 * N'))
    (hg : 2 * t0 = 2 + 4 * g) (hA : 4 * ρ + 2 * q < 4 * q) : (t * (2 * q + 4 * a)) % (4 * q) = 4 * ρ + 2 * q := by
  apply mod_rep _ _ _ (g + 2 * s' + n0 + 4 * N') hA
  rw [((show (t)*(2*(q)+4*(a)) = 2*(q)*(t) + 4*((t)*(a)) from NatNorm.sound [t, q, a] (.mul (.var 0) (.add (.mul (.lit 2) (.var 1)) (.mul (.lit 4) (.var 2)))) (.add (.mul (.mul (.lit 2) (.var 1)) (.var 0)) (.mul (.lit 4) (.mul (.var 0) (.var 2)))) rfl)), hta, ht,
    ((show 2*(q)*((t0)+4*(s')) + 4*((ρ) + (q)*((n0)+4*(N'))) = (q)*(2*(t0)) + 4*(ρ) + (2*(s') + (n0) + 4*(N'))*(4*(q)) from NatNorm.sound [q, t0, ρ, s', n0, N'] (.add (.mul (.mul (.lit 2) (.var 0)) (.add (.var 1) (.mul (.lit 4) (.var 3)))) (.mul (.lit 4) (.add (.var 2) (.mul (.var 0) (.add (.var 4) (.mul (.lit 4) (.var 5))))))) (.add (.add (.mul (.var 0) (.mul (.lit 2) (.var 1))) (.mul (.lit 4) (.  -- (+125 chars; full line in the Zenodo source)
  exact ((show (q)*(2+4*(g)) + 4*(ρ) + (2*(s') + (n0) + 4*(N'))*(4*(q)) = 4*(ρ) + 2*(q) + ((g) + 2*(s') + (n0) + 4*(N'))*(4*(q)) from NatNorm.sound [q, g, ρ, s', n0, N'] (.add (.add (.mul (.var 0) (.add (.lit 2) (.mul (.lit 4) (.var 1)))) (.mul (.lit 4) (.var 2))) (.mul (.add (.add (.mul (.lit 2) (.var 3)) (.var 4)) (.mul (.lit 4) (.var 5))) (.mul (.lit 4) (.var 0)))) (.add (.add (.mul (.lit 4) (.  -- (+161 chars; full line in the Zenodo source)

theorem res_p1B (q a t ρ N' s' t0 n0 g w : Nat) (ht : t = t0 + 4 * s') (hta : t * a = ρ + q * (n0 + 4 * N'))
    (hg : 2 * t0 = 2 + 4 * g) (hw : 4 * ρ = 2 * q + w) (hwl : w < 4 * q) : (t * (2 * q + 4 * a)) % (4 * q) = w := by
  apply mod_rep _ _ _ (1 + g + 2 * s' + n0 + 4 * N') hwl
  rw [((show (t)*(2*(q)+4*(a)) = 2*(q)*(t) + 4*((t)*(a)) from NatNorm.sound [t, q, a] (.mul (.var 0) (.add (.mul (.lit 2) (.var 1)) (.mul (.lit 4) (.var 2)))) (.add (.mul (.mul (.lit 2) (.var 1)) (.var 0)) (.mul (.lit 4) (.mul (.var 0) (.var 2)))) rfl)), hta, ht,
    ((show 2*(q)*((t0)+4*(s')) + 4*((ρ) + (q)*((n0)+4*(N'))) = (q)*(2*(t0)) + 4*(ρ) + (2*(s') + (n0) + 4*(N'))*(4*(q)) from NatNorm.sound [q, t0, ρ, s', n0, N'] (.add (.mul (.mul (.lit 2) (.var 0)) (.add (.var 1) (.mul (.lit 4) (.var 3)))) (.mul (.lit 4) (.add (.var 2) (.mul (.var 0) (.add (.var 4) (.mul (.lit 4) (.var 5))))))) (.add (.add (.mul (.var 0) (.mul (.lit 2) (.var 1))) (.mul (.lit 4) (.  -- (+129 chars; full line in the Zenodo source)
  exact ((show (q)*(2+4*(g)) + (2*(q) + (w)) + (2*(s') + (n0) + 4*(N'))*(4*(q)) = (w) + (1 + (g) + 2*(s') + (n0) + 4*(N'))*(4*(q)) from NatNorm.sound [q, g, w, s', n0, N'] (.add (.add (.mul (.var 0) (.add (.lit 2) (.mul (.lit 4) (.var 1)))) (.add (.mul (.lit 2) (.var 0)) (.var 2))) (.mul (.add (.add (.mul (.lit 2) (.var 3)) (.var 4)) (.mul (.lit 4) (.var 5))) (.mul (.lit 4) (.var 0)))) (.add (.var  -- (+147 chars; full line in the Zenodo source)

theorem res_8A (q a t ρ N' n0 : Nat) (hta : t * a = ρ + q * (n0 + 4 * N')) (h8 : 8 * ρ < 4 * q) :
    (t * (8 * a)) % (4 * q) = 8 * ρ := by
  apply mod_rep _ _ _ (2 * n0 + 8 * N') h8
  rw [((show (t)*(8*(a)) = 8*((t)*(a)) from NatNorm.sound [t, a] (.mul (.var 0) (.mul (.lit 8) (.var 1))) (.mul (.lit 8) (.mul (.var 0) (.var 1))) rfl)), hta]
  exact ((show 8*((ρ) + (q)*((n0) + 4*(N'))) = 8*(ρ) + (2*(n0) + 8*(N'))*(4*(q)) from NatNorm.sound [ρ, q, n0, N'] (.mul (.lit 8) (.add (.var 0) (.mul (.var 1) (.add (.var 2) (.mul (.lit 4) (.var 3)))))) (.add (.mul (.lit 8) (.var 0)) (.mul (.add (.mul (.lit 2) (.var 2)) (.mul (.lit 8) (.var 3))) (.mul (.lit 4) (.var 1)))) rfl))

theorem res_8B (q a t ρ N' n0 w : Nat) (hta : t * a = ρ + q * (n0 + 4 * N')) (hw : 4 * ρ = 2 * q + w)
    (h8 : w + w < 4 * q) : (t * (8 * a)) % (4 * q) = w + w := by
  apply mod_rep _ _ _ (1 + 2 * n0 + 8 * N') h8
  rw [((show (t)*(8*(a)) = 8*((t)*(a)) from NatNorm.sound [t, a] (.mul (.var 0) (.mul (.lit 8) (.var 1))) (.mul (.lit 8) (.mul (.var 0) (.var 1))) rfl)), hta, ((show 8*((ρ) + (q)*((n0) + 4*(N'))) = 2*(4*(ρ)) + (2*(n0) + 8*(N'))*(4*(q)) from NatNorm.sound [ρ, q, n0, N'] (.mul (.lit 8) (.add (.var 0) (.mul (.var 1) (.add (.var 2) (.mul (.lit 4) (.var 3)))))) (.add (.mul (.lit 2) (.mul (.lit 4) (.var  -- (+106 chars; full line in the Zenodo source)
  exact ((show 2*(2*(q) + (w)) + (2*(n0) + 8*(N'))*(4*(q)) = (w) + (w) + (1 + 2*(n0) + 8*(N'))*(4*(q)) from NatNorm.sound [q, w, n0, N'] (.add (.mul (.lit 2) (.add (.mul (.lit 2) (.var 0)) (.var 1))) (.mul (.add (.mul (.lit 2) (.var 2)) (.mul (.lit 8) (.var 3))) (.mul (.lit 4) (.var 0)))) (.add (.add (.var 1) (.var 1)) (.mul (.add (.add (.lit 1) (.mul (.lit 2) (.var 2))) (.mul (.lit 8) (.var 3)))   -- (+32 chars; full line in the Zenodo source)

theorem comp (x y m r : Nat) (hm : 0 < m) (hy : y % m = r) (hr0 : 0 < r) (hrm : r < m) (hxy : (x + y) % m = 0) :
    x % m + r = m := by
  have e := mod_add x y m hm
  rw [hy, hxy] at e
  exact zero_mod_two _ m (Nat.lt_of_lt_of_le hr0 (Nat.le_add_left r _)) (add_lt_add' _ _ _ _ (Nat.mod_lt x hm) hrm) e

theorem tb8 (q a b t : Nat) (hq : 0 < q) (hb : 8 * a + b = 4 * q) : (t * b + t * (8 * a)) % (4 * q) = 0 := by
  rw [((show (t)*(b) + (t)*(8*(a)) = (t)*(8*(a)+(b)) from NatNorm.sound [t, a, b] (.add (.mul (.var 0) (.var 2)) (.mul (.var 0) (.mul (.lit 8) (.var 1)))) (.mul (.var 0) (.add (.mul (.lit 8) (.var 1)) (.var 2))) rfl)), hb]
  exact mod_rep _ 0 _ t (pos4 q hq) ((show (t)*(4*(q)) = 0 + (t)*(4*(q)) from NatNorm.sound [t, q] (.mul (.var 0) (.mul (.lit 4) (.var 1))) (.add (.lit 0) (.mul (.var 0) (.mul (.lit 4) (.var 1)))) rfl))

theorem dbl_inj (x y : Nat) (h : x + x = y + y) : x = y := by
  cases Nat.lt_trichotomy x y with
  | inl l => exact absurd (h ▸ add_lt_add' _ _ _ _ l l) (Nat.lt_irrefl _)
  | inr h' => cases h' with
    | inl e => exact e
    | inr l => exact absurd (h ▸ add_lt_add' _ _ _ _ l l) (Nat.lt_irrefl _)

/-- **The pair part.** ⟨t(2q+4a)⟩ + ⟨tb⟩ + 4ρ = 6q. -/
theorem pair_sum (q a b t ρ N' s' t0 n0 g : Nat) (hq : 0 < q) (hb : 8 * a + b = 4 * q) (hρq : ρ < q) (hρ0 : 0 < ρ)
    (hρh : ρ + ρ ≠ q) (ht : t = t0 + 4 * s') (hta : t * a = ρ + q * (n0 + 4 * N')) (hg : 2 * t0 = 2 + 4 * g) :
    (t * (2 * q + 4 * a)) % (4 * q) + (t * b) % (4 * q) + 4 * ρ = 6 * q := by
  have hm := pos4 q hq
  have h4 : 4 * ρ < 4 * q := by
    rw [((show 4*(ρ) = (ρ) + (ρ) + ((ρ) + (ρ)) from NatNorm.sound [ρ] (.mul (.lit 4) (.var 0)) (.add (.add (.var 0) (.var 0)) (.add (.var 0) (.var 0))) rfl)), ((show 4*(q) = (q) + (q) + ((q) + (q)) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.add (.var 0) (.var 0)) (.add (.var 0) (.var 0))) rfl))]
    exact add_lt_add' _ _ _ _ (add_lt_add' _ _ _ _ hρq hρq) (add_lt_add' _ _ _ _ hρq hρq)
  cases Nat.lt_trichotomy (4 * ρ) (2 * q) with
  | inl lt =>
    have hA : 4 * ρ + 2 * q < 4 * q := by
      rw [((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact Nat.add_lt_add_right lt (2 * q)
    have h8 : 8 * ρ < 4 * q := by
      rw [((show 8*(ρ) = 4*(ρ) + 4*(ρ) from NatNorm.sound [ρ] (.mul (.lit 8) (.var 0)) (.add (.mul (.lit 4) (.var 0)) (.mul (.lit 4) (.var 0))) rfl)), ((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact add_lt_add' _ _ _ _ lt lt
    have h80 : 0 < 8 * ρ := Nat.lt_of_lt_of_le hρ0 (by rw [((show 8*(ρ) = (ρ) + 7*(ρ) from NatNorm.sound [ρ] (.mul (.lit 8) (.var 0)) (.add (.var 0) (.mul (.lit 7) (.var 0))) rfl))]; exact Nat.le_add_right _ _)
    have hB := comp (t * b) (t * (8 * a)) (4 * q) (8 * ρ) hm (res_8A q a t ρ N' n0 hta h8) h80 h8 (tb8 q a b t hq hb)
    rw [res_p1A q a t ρ N' s' t0 n0 g ht hta hg hA,
      ((show 4*(ρ) + 2*(q) + ((t * b) % (4 * q)) + 4*(ρ) = 2*(q) + (((t * b) % (4 * q)) + 8*(ρ)) from NatNorm.sound [ρ, q, (t * b) % (4 * q)] (.add (.add (.add (.mul (.lit 4) (.var 0)) (.mul (.lit 2) (.var 1))) (.var 2)) (.mul (.lit 4) (.var 0))) (.add (.mul (.lit 2) (.var 1)) (.add (.var 2) (.mul (.lit 8) (.var 0)))) rfl)), hB]
    exact ((show 2*(q) + 4*(q) = 6*(q) from NatNorm.sound [q] (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 4) (.var 0))) (.mul (.lit 6) (.var 0)) rfl))
  | inr h => cases h with
    | inl eq =>
      have e2 : ρ + ρ = q := dbl_inj _ _ (by rw [((show (ρ) + (ρ) + ((ρ) + (ρ)) = 4*(ρ) from NatNorm.sound [ρ] (.add (.add (.var 0) (.var 0)) (.add (.var 0) (.var 0))) (.mul (.lit 4) (.var 0)) rfl)), eq]; exact ((show 2*(q) = (q) + (q) from NatNorm.sound [q] (.mul (.lit 2) (.var 0)) (.add (.var 0) (.var 0)) rfl)))
      exact absurd e2 hρh
    | inr gt =>
      have ⟨k, hk⟩ := Nat.le.dest gt
      have hw : 4 * ρ = 2 * q + (k + 1) := by rw [← hk]; exact ((show 2*(q) + 1 + (k) = 2*(q) + ((k) + 1) from NatNorm.sound [q, k] (.add (.add (.mul (.lit 2) (.var 0)) (.lit 1)) (.var 1)) (.add (.mul (.lit 2) (.var 0)) (.add (.var 1) (.lit 1))) rfl))
      have hw2 : k + 1 < 2 * q := by
        apply Nat.lt_of_add_lt_add_left (n := 2 * q)
        rw [← hw, ← ((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact h4
      have h2q : 0 < 2 * q := Nat.lt_of_lt_of_le hq (by rw [((show 2*(q) = (q) + (q) from NatNorm.sound [q] (.mul (.lit 2) (.var 0)) (.add (.var 0) (.var 0)) rfl))]; exact Nat.le_add_right q q)
      have hwl : k + 1 < 4 * q := Nat.lt_trans hw2 (by rw [((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact Nat.lt_add_of_pos_right h2q)
      have h8 : (k + 1) + (k + 1) < 4 * q := by rw [((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact add_lt_add' _ _ _ _ hw2 hw2
      have hB := comp (t * b) (t * (8 * a)) (4 * q) ((k + 1) + (k + 1)) hm (res_8B q a t ρ N' n0 (k + 1) hta hw h8)
        (Nat.lt_of_lt_of_le (Nat.succ_pos k) (Nat.le_add_right _ _)) h8 (tb8 q a b t hq hb)
      rw [res_p1B q a t ρ N' s' t0 n0 g (k + 1) ht hta hg hw hwl, hw,
        ((show ((k + 1)) + ((t * b) % (4 * q)) + (2*(q) + ((k + 1))) = 2*(q) + (((t * b) % (4 * q)) + (((k + 1)) + ((k + 1)))) from NatNorm.sound [(k + 1), q, (t * b) % (4 * q)] (.add (.add (.var 0) (.var 2)) (.add (.mul (.lit 2) (.var 1)) (.var 0))) (.add (.mul (.lit 2) (.var 1)) (.add (.var 2) (.add (.var 0) (.var 0)))) rfl)), hB]
      exact ((show 2*(q) + 4*(q) = 6*(q) from NatNorm.sound [q] (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 4) (.var 0))) (.mul (.lit 6) (.var 0)) rfl))

theorem combine (X P B ρ q : Nat) (h1 : X = 4 * ρ + 6 * q) (h2 : P + B + 4 * ρ = 6 * q) : X + (P + B) = 12 * q := by
  rw [h1, ((show 4*(ρ) + 6*(q) + ((P) + (B)) = 6*(q) + ((P) + (B) + 4*(ρ)) from NatNorm.sound [ρ, q, P, B] (.add (.add (.mul (.lit 4) (.var 0)) (.mul (.lit 6) (.var 1))) (.add (.var 2) (.var 3))) (.add (.mul (.lit 6) (.var 1)) (.add (.add (.var 2) (.var 3)) (.mul (.lit 4) (.var 0)))) rfl)), h2]
  exact ((show 6*(q) + 6*(q) = 12*(q) from NatNorm.sound [q] (.add (.mul (.lit 6) (.var 0)) (.mul (.lit 6) (.var 0))) (.mul (.lit 12) (.var 0)) rfl))

/-- **Key identity.** For odd t with ρ = ⟨ta⟩_q ∉ {0, q/2}: Σ ⟨t c_i⟩_m = 12q = 3m. -/
theorem tsum_key (q a b t ρ N : Nat) (hq : 0 < q) (hb : 8 * a + b = 4 * q) (ht : isOdd t = true)
    (hN : t * a = ρ + q * N) (hρq : ρ < q) (hρ0 : 0 < ρ) (hρh : ρ + ρ ≠ q) :
    tsum (4 * q) t [a, a + q, a + 2 * q, a + 3 * q, 2 * q + 4 * a, b] = 12 * q := by
  show (t * a) % (4 * q) + ((t * (a + q)) % (4 * q) + ((t * (a + 2 * q)) % (4 * q) + ((t * (a + 3 * q)) % (4 * q) + ((t * (2 * q + 4 * a)) % (4 * q) + ((t * b) % (4 * q) + 0))))) = 12 * q
  rw [((show ((t * a) % (4 * q)) + (((t * (a + q)) % (4 * q)) + (((t * (a + 2 * q)) % (4 * q)) + (((t * (a + 3 * q)) % (4 * q)) + (((t * (2 * q + 4 * a)) % (4 * q)) + (((t * b) % (4 * q)) + 0))))) = ((t * a) % (4 * q)) + (((t * (a + q)) % (4 * q)) + (((t * (a + 2 * q)) % (4 * q)) + ((t * (a + 3 * q)) % (4 * q)))) + (((t * (2 * q + 4 * a)) % (4 * q)) + ((t * b) % (4 * q))) from NatNorm.sound [(t *   -- (+349 chars; full line in the Zenodo source)
  have ⟨s', hs⟩ := four_form t ht
  have ⟨N', hN'⟩ := four_cases N
  cases hs with
  | inl hs =>
    cases hN' with
    | inl hn =>
      have hta : t * a = ρ + q * (0 + 4 * N') := by rw [hN, hn]
      exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 1 0 0 1 2 3 0 0 0 0 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
        (pair_sum q a b t ρ N' s' 1 0 0 hq hb hρq hρ0 hρh hs hta rfl)
    | inr hn => cases hn with
      | inl hn =>
        have hta : t * a = ρ + q * (1 + 4 * N') := by rw [hN, hn]
        exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 1 1 1 2 3 0 0 0 0 1 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
          (pair_sum q a b t ρ N' s' 1 1 0 hq hb hρq hρ0 hρh hs hta rfl)
      | inr hn => cases hn with
        | inl hn =>
          have hta : t * a = ρ + q * (2 + 4 * N') := by rw [hN, hn]
          exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 1 2 2 3 0 1 0 0 1 1 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
            (pair_sum q a b t ρ N' s' 1 2 0 hq hb hρq hρ0 hρh hs hta rfl)
        | inr hn =>
          have hta : t * a = ρ + q * (3 + 4 * N') := by rw [hN, hn]
          exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 1 3 3 0 1 2 0 1 1 1 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
            (pair_sum q a b t ρ N' s' 1 3 0 hq hb hρq hρ0 hρh hs hta rfl)
  | inr hs =>
    cases hN' with
    | inl hn =>
      have hta : t * a = ρ + q * (0 + 4 * N') := by rw [hN, hn]
      exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 3 0 0 3 2 1 0 0 1 2 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
        (pair_sum q a b t ρ N' s' 3 0 1 hq hb hρq hρ0 hρh hs hta rfl)
    | inr hn => cases hn with
      | inl hn =>
        have hta : t * a = ρ + q * (1 + 4 * N') := by rw [hN, hn]
        exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 3 1 1 0 3 2 0 1 1 2 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
          (pair_sum q a b t ρ N' s' 3 1 1 hq hb hρq hρ0 hρh hs hta rfl)
      | inr hn => cases hn with
        | inl hn =>
          have hta : t * a = ρ + q * (2 + 4 * N') := by rw [hN, hn]
          exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 3 2 2 1 0 3 0 1 2 2 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
            (pair_sum q a b t ρ N' s' 3 2 1 hq hb hρq hρ0 hρh hs hta rfl)
        | inr hn =>
          have hta : t * a = ρ + q * (3 + 4 * N') := by rw [hN, hn]
          exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 3 3 3 2 1 0 0 1 2 3 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
            (pair_sum q a b t ρ N' s' 3 3 1 hq hb hρq hρ0 hρh hs hta rfl)

def good (q a t : Nat) : Bool := !(Nat.beq ((t * a) % q) 0) && !(Nat.beq ((t * a) % q + (t * a) % q) q)

theorem all_and {α : Type} (p r : α → Bool) : ∀ l : List α, l.all p = true → l.all r = true →
    l.all (fun x => p x && r x) = true
  | [], _, _ => rfl
  | x :: l, h1, h2 => by
    have h1' : (p x && l.all p) = true := h1
    have h2' : (r x && l.all r) = true := h2
    cases a : p x <;> cases b : r x <;> rw [a] at h1' <;> rw [b] at h2'
    · exact Bool.noConfusion h1'
    · exact Bool.noConfusion h1'
    · exact Bool.noConfusion h2'
    · show ((p x && r x) && l.all _) = true
      rw [a, b, all_and p r l h1' h2']; rfl

theorem bool_ne {b : Bool} (h : (!b) = true) : b = false := by
  cases b with
  | false => rfl
  | true => exact Bool.noConfusion h

/-- **AP(m/4) + pair is balanced.** For m = 4q, 8a + b = 4q and every unit t with ⟨ta⟩_q ∉ {0, q/2}, the character
    [a, a+q, a+2q, a+3q, 2q+4a, b] is balanced (Hodge). -/
theorem ap_pair_bal (q a b : Nat) (hq : 0 < q) (hb : 8 * a + b = 4 * q)
    (hgood : (FermatPrime.units (4 * q)).all (good q a) = true) :
    bal (4 * q) [a, a + q, a + 2 * q, a + 3 * q, 2 * q + 4 * a, b] = true := by
  have hodd : (FermatPrime.units (4 * q)).all isOdd = true := by
    rw [((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact GcdHand.units_odd (2 * q)
  unfold bal
  apply all_imp _ _ _ _ (all_and _ _ _ hodd hgood)
  intro t h
  have h' : (isOdd t && good q a t) = true := h
  cases ho : isOdd t with
  | false => rw [ho] at h'; exact Bool.noConfusion h'
  | true =>
    rw [ho] at h'
    have hg : (!(Nat.beq ((t * a) % q) 0) && !(Nat.beq ((t * a) % q + (t * a) % q) q)) = true := h'
    cases g1 : Nat.beq ((t * a) % q) 0 <;> cases g2 : Nat.beq ((t * a) % q + (t * a) % q) q <;>
      rw [g1, g2] at hg
    · have ⟨N, hN⟩ := decomp (t * a) q hq
      have e := tsum_key q a b t _ N hq hb ho hN (Nat.mod_lt _ hq)
        (Nat.pos_of_ne_zero (Nat.ne_of_beq_eq_false g1)) (Nat.ne_of_beq_eq_false g2)
      rw [e]
      show Nat.beq (12 * q + 12 * q) (6 * (4 * q)) = true
      rw [((show 6*(4*(q)) = 12*(q) + 12*(q) from NatNorm.sound [q] (.mul (.lit 6) (.mul (.lit 4) (.var 0))) (.add (.mul (.lit 12) (.var 0)) (.mul (.lit 12) (.var 0))) rfl))]
      exact beq_self _
    · exact Bool.noConfusion hg
    · exact Bool.noConfusion hg
    · exact Bool.noConfusion hg

/-- The AP(24) + pair characters at m = 96 with a = 1, 2, 3 (orbit representatives in Unreached96). -/
theorem ap_pair_96 : bal 96 [1, 25, 49, 73, 52, 88] = true ∧ bal 96 [2, 26, 50, 74, 56, 80] = true
    ∧ bal 96 [3, 27, 51, 75, 60, 72] = true :=
  ⟨ap_pair_bal 24 1 88 (Nat.le_of_ble_eq_true rfl) rfl rfl, ap_pair_bal 24 2 80 (Nat.le_of_ble_eq_true rfl) rfl rfl,
   ap_pair_bal 24 3 72 (Nat.le_of_ble_eq_true rfl) rfl rfl⟩

/-- The AP(26) + pair character at m = 104 (Unreached96.reps104). -/
theorem ap_pair_104 : bal 104 [1, 27, 53, 79, 56, 96] = true :=
  ap_pair_bal 26 1 96 (Nat.le_of_ble_eq_true rfl) rfl rfl

/-- The hypothesis holds for a = 1 and every 3 ≤ q ≤ 40 (m = 12 … 160). -/
theorem good1_table : (List.range 38).all (fun i => (FermatPrime.units (4 * (i + 3))).all (good (i + 3) 1)) = true := rfl

end APPair

#print axioms APPair.mod_rep
#print axioms APPair.mod_add
#print axioms APPair.zero_mod_two
#print axioms APPair.four_form
#print axioms APPair.four_cases
#print axioms APPair.res_ap
#print axioms APPair.ap4
#print axioms APPair.pair_sum
#print axioms APPair.tsum_key
#print axioms APPair.ap_pair_bal
#print axioms APPair.ap_pair_96
#print axioms APPair.ap_pair_104
#print axioms APPair.good1_table

#print axioms: 13 theorems, no axioms.

81.45 AP\((m/4)\) plus \((m/2+4,\,m-8)\), every \(m=4q\ge 12\)

The hypothesis of the previous subsection holds for \(a=1\) and every \(q\ge 3\) (a divisor of \(t\) and \(4q\) divides \(\gcd =1\)). \(\text {bal}\,(4q)\,[1,1+q,1+2q,1+3q,2q+4,4q-8]\)

hodge/APPair1.lean

/-
  hodge/APPair1.lean — T41 cycle 269 (goal G8b): the hypothesis of APPair.ap_pair_bal for a = 1 holds for every q ≥ 3,
  so AP(m/4) + (m/2 + 4, m − 8) is a balanced character for every m = 4q ≥ 12, with no hypothesis.

  Lean 4 core plus hodge/APPair, hodge/GcdHand (GH, GF, gcd_go, div_mod, filter_all), lib/NatNorm.
    dvd_sub_form   d·a = r + d·k ⇒ d ∣ r
    dvd_mod        d ∣ n, d ∣ m, m > 0 ⇒ d ∣ n mod m
    dvd_gcd        d ∣ m, d ∣ n ⇒ d ∣ gcd m n        (fuel induction on core's gcd, as GcdHand.two_dvd_gcd)
    good_unit      gcd t 4q = 1, q ≥ 3 ⇒ t mod q ∉ {0, q/2}
    ap_pair_bal1   bal (4q) [1, 1+q, 1+2q, 1+3q, 2q+4, b]  for 8 + b = 4q, q ≥ 3
-/
import hodge.APPair

namespace APPair1
open ModHand HalfGeneral Indecomp GcdHand APPair

theorem dvd_sub_form (d r : Nat) : ∀ k a, d * a = r + d * k → ∃ c, r = d * c
  | 0, a, h => ⟨a, by rw [h]; rfl⟩
  | k + 1, a, h => by
    cases a with
    | zero =>
      have h' : 0 = (r + d * k) + d := by rw [← ((show (r) + (d)*((k)+1) = (r) + (d)*(k) + (d) from NatNorm.sound [r, d, k] (.add (.var 0) (.mul (.var 1) (.add (.var 2) (.lit 1)))) (.add (.add (.var 0) (.mul (.var 1) (.var 2))) (.var 1)) rfl))]; exact h
      cases d with
      | zero => exact ⟨0, by rw [((show (r) + 0*(k) + 0 = (r) from NatNorm.sound [r, k] (.add (.add (.var 0) (.mul (.lit 0) (.var 1))) (.lit 0)) (.var 0) rfl))] at h'; rw [← h']⟩
      | succ d' => exact Nat.noConfusion h'
    | succ a' =>
      have h' : d * a' + d = (r + d * k) + d := by
        rw [← ((show (r) + (d)*((k)+1) = (r) + (d)*(k) + (d) from NatNorm.sound [r, d, k] (.add (.var 0) (.mul (.var 1) (.add (.var 2) (.lit 1)))) (.add (.add (.var 0) (.mul (.var 1) (.var 2))) (.var 1)) rfl)), ← h]; exact ((show (d)*(a') + (d) = (d)*((a') + 1) from NatNorm.sound [d, a'] (.add (.mul (.var 0) (.var 1)) (.var 0)) (.mul (.var 0) (.add (.var 1) (.lit 1))) rfl))
      exact dvd_sub_form d r k a' (add_right_cancel' _ _ _ h')

theorem dvd_mod (d n m : Nat) (hm : 0 < m) (hn : ∃ a, n = d * a) (hmd : ∃ b, m = d * b) : ∃ c, n % m = d * c := by
  have ⟨k, hk⟩ := decomp n m hm
  have ⟨a, ha⟩ := hn
  have ⟨b, hb⟩ := hmd
  apply dvd_sub_form d (n % m) (b * k) a
  rw [← ha]
  calc n = n % m + m * k := hk
    _ = n % m + d * (b * k) := by rw [hb, ((show (d)*(b)*(k) = (d)*((b)*(k)) from NatNorm.sound [d, b, k] (.mul (.mul (.var 0) (.var 1)) (.var 2)) (.mul (.var 0) (.mul (.var 1) (.var 2))) rfl))]

theorem dvd_go (d : Nat) : ∀ (f : Nat) (x : (_ : Nat) ×' Nat) (hf : GH x < f),
    (∃ a, x.1 = d * a) → (∃ b, x.2 = d * b) → ∃ c, WellFounded.Nat.fix.go GH GF f x hf = d * c
  | 0, _, hf, _, _ => absurd hf (Nat.not_lt_zero _)
  | f + 1, ⟨m, n⟩, hf, hm, hn => by
    show ∃ c, (if h : m = 0 then n else WellFounded.Nat.fix.go GH GF f ⟨n % m, m⟩ _) = d * c
    by_cases h0 : m = 0
    · rw [dite_eq_left h0]; exact hn
    · rw [dite_eq_right h0]
      exact dvd_go d f ⟨n % m, m⟩ _ (dvd_mod d n m (Nat.pos_of_ne_zero h0) hn hm) hm

theorem dvd_gcd (d m n : Nat) (hm : ∃ a, m = d * a) (hn : ∃ b, n = d * b) : ∃ c, Nat.gcd m n = d * c := by
  rw [gcd_go]; exact dvd_go d _ ⟨m, n⟩ _ hm hn

/-- 1 = d·c forces d = 1. -/
theorem one_eq_mul (d c : Nat) (h : 1 = d * c) (hd : 2 ≤ d) : False := by
  cases c with
  | zero => exact Nat.noConfusion h
  | succ c' =>
    have e : d * (c' + 1) = d + d * c' := ((show (d)*((c')+1) = (d) + (d)*(c') from NatNorm.sound [d, c'] (.mul (.var 0) (.add (.var 1) (.lit 1))) (.add (.var 0) (.mul (.var 0) (.var 1))) rfl))
    rw [e] at h
    have : 2 ≤ 1 := Nat.le_trans hd (h ▸ Nat.le_add_right d (d * c'))
    exact absurd this (Nat.not_succ_le_self 1)

/-- **For a unit t of 4q (q ≥ 3), t mod q is neither 0 nor q/2.** -/
theorem good_unit (q t : Nat) (hq : 3 ≤ q) (hg : Nat.gcd t (4 * q) = 1) : good q 1 t = true := by
  have hq0 : 0 < q := Nat.lt_of_lt_of_le (Nat.zero_lt_succ 2) hq
  have ⟨N, hN⟩ := decomp t q hq0
  have ht1 : t * 1 = t := Nat.mul_one t
  show (!(Nat.beq ((t * 1) % q) 0) && !(Nat.beq ((t * 1) % q + (t * 1) % q) q)) = true
  rw [ht1]
  cases g1 : Nat.beq (t % q) 0 with
  | true =>
    have e := Nat.eq_of_beq_eq_true g1
    rw [e, Nat.zero_add] at hN
    have ⟨c, hc⟩ := dvd_gcd q t (4 * q) ⟨N, hN⟩ ⟨4, Nat.mul_comm 4 q⟩
    rw [hg] at hc
    exact absurd (one_eq_mul q c hc (Nat.le_trans (Nat.le_succ 2) hq)) id
  | false =>
    cases g2 : Nat.beq (t % q + t % q) q with
    | false => rfl
    | true =>
      have e := Nat.eq_of_beq_eq_true g2
      -- ρ = t mod q divides t = ρ(1 + 2N) and 4q = ρ·8
      have ht : t = t % q * (1 + 2 * N) := by
        rw [((show (t % q)*(1 + 2*(N)) = (t % q) + ((t % q) + (t % q))*(N) from NatNorm.sound [t % q, N] (.mul (.var 0) (.add (.lit 1) (.mul (.lit 2) (.var 1)))) (.add (.var 0) (.mul (.add (.var 0) (.var 0)) (.var 1))) rfl)), e]; exact hN
      have h4 : 4 * q = t % q * 8 := by
        calc 4 * q = 4 * (t % q + t % q) := by rw [e]
          _ = t % q * 8 := ((show 4*((t % q) + (t % q)) = (t % q)*8 from NatNorm.sound [t % q] (.mul (.lit 4) (.add (.var 0) (.var 0))) (.mul (.var 0) (.lit 8)) rfl))
      have ⟨c, hc⟩ := dvd_gcd (t % q) t (4 * q) ⟨_, ht⟩ ⟨8, h4⟩
      rw [hg] at hc
      have h2 : 2 ≤ t % q := by
        cases Nat.lt_or_ge (t % q) 2 with
        | inr h => exact h
        | inl h =>
          have h1 : t % q ≤ 1 := Nat.le_of_lt_succ h
          have h' : t % q + t % q ≤ 1 + 1 :=
            Nat.le_trans (Nat.add_le_add_left h1 (t % q)) (Nat.add_le_add_right h1 1)
          rw [e] at h'
          exact absurd (Nat.le_trans hq h') (Nat.not_succ_le_self 2)
      exact absurd (one_eq_mul _ c hc h2) id

/-- **AP(m/4) + (m/2 + 4, m − 8) is balanced for every m = 4q ≥ 12.** -/
theorem ap_pair_bal1 (q b : Nat) (hq : 3 ≤ q) (hb : 8 + b = 4 * q) :
    bal (4 * q) [1, 1 + q, 1 + 2 * q, 1 + 3 * q, 2 * q + 4 * 1, b] = true :=
  ap_pair_bal q 1 b (Nat.lt_of_lt_of_le (Nat.zero_lt_succ 2) hq) hb
    (filter_all _ _ (fun t hg => good_unit q t hq (Nat.eq_of_beq_eq_true hg)) _)

end APPair1

#print axioms APPair1.dvd_sub_form
#print axioms APPair1.dvd_mod
#print axioms APPair1.dvd_go
#print axioms APPair1.dvd_gcd
#print axioms APPair1.one_eq_mul
#print axioms APPair1.good_unit
#print axioms APPair1.ap_pair_bal1

#print axioms: 7 theorems, no axioms.

81.46 Orbit decomposition, \(m=96\)

The 400 unreached characters at \(m=96\) form 34 Galois orbits. \(34\ \text {orbits},\ 400,\ 392\ \text {irreducible}\)

hodge/OrbitDecomp5.lean

/-
  hodge/OrbitDecomp5.lean — T41 cycle 267: Galois orbit decomposition of the full unreached set at m = 96.

  Lean 4 core plus hodge/OrbitDecomp (union), hodge/Indecomp (indec), rfl (Kamiak). The twist orbits of the 34
  representatives give the 400 unreached characters of length 6 at m = 96 (a2_reach96, all_96.jsonl); 392 of them have
  no balanced splitting (the other 8: Unreached96.red96).
-/
import hodge.OrbitDecomp

namespace OrbitDecomp5
open Orbits Indecomp OrbitDecomp

def reps96 : List (List Nat) := [[1,  6,  15,  79,  93,  94],  [1,  14,  49,  66,  68,  90],  [1,  15,  34,  66,  79,  93],  [1,  15,  51,  62,  65,  94],  [1,  15,  51,  65,  66,  90],  [1,  17,  49,  65,  66,  90],  [1,  25,  49,  52,  73,  88],  [1,  25,  49,  64,  73,  76],  [1,  25,  49,  68,  72,  73],  [1,  33,  34,  49,  81,  90],  [1,  34,  36,  49,  78,  90],  [1,  34,  45,  49,  66,  93  -- (+684 chars; full line in the Zenodo source)

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size96 : Nat.beq (union 96 reps96).length 400 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr96 : Nat.beq ((union 96 reps96).filter (indec 96)).length 392 = true := rfl

end OrbitDecomp5

#print axioms OrbitDecomp5.size96
#print axioms OrbitDecomp5.irr96

#print axioms: 2 theorems, no axioms.

81.47 The second pair family

AP\((m/4)\) plus \((m/2-2a,\,m-2a)\) is balanced when no unit sends \(ta\) to \(0\) mod \(q\); for \(a=1\), every \(m=4q\ge 12\). \(\text {bal}\,(4q)\,[1,1+q,1+2q,1+3q,2q-2,4q-2]\)

hodge/APPair2.lean

/-
  hodge/APPair2.lean — T41 cycle 274 (goal G17): the second pair family. For m = 4q, 2a + c = 2q, 2a + d = 4q, the
  character [a, a+q, a+2q, a+3q, c, d] = AP(a) + (m/2 − 2a, m − 2a) is balanced whenever every unit t has ta ≢ 0 (q);
  for a = 1 this holds for every q ≥ 3 (APPair1.good_unit), so AP(m/4) + (m/2 − 2, m − 2) is balanced for every
  m = 4q ≥ 12.

  Lean 4 core plus hodge/APPair (mod_rep, mod_add, res_ap, ap4, four_form, four_cases, combine), hodge/APPair1, lib/NatNorm.
    mod_two_cases     z < 2m, z mod m = s ⇒ z = s ∨ z = m + s
    pair2_even/odd    ⟨tc⟩ + ⟨td⟩ + 4ρ = 6q   (n₀ even / odd; ⟨2ta⟩ = 2ρ or 2ρ + 2q)
    tsum_key2, ap_pair2_bal, ap_pair2_bal1
-/
import hodge.APPair1

namespace APPair2
open ModHand HalfGeneral Indecomp GcdHand APPair

theorem mod_two_cases (z m s : Nat) (hz : z < m + m) (h : z % m = s) : z = s ∨ z = m + s := by
  cases Nat.lt_or_ge z m with
  | inl l => rw [mod_lt' z m l] at h; exact Or.inl h
  | inr g =>
    have ⟨w, hw⟩ := Nat.le.dest g
    have hwm : w < m := Nat.lt_of_add_lt_add_left (hw ▸ hz)
    have hm : 0 < m := Nat.lt_of_le_of_lt (Nat.zero_le w) hwm
    rw [← hw, Nat.add_comm, add_mod' w m hm, mod_lt' w m hwm] at h
    exact Or.inr (by rw [← hw, h])

theorem res_2q (q t t0 s' g : Nat) (hq : 0 < q) (ht : t = t0 + 4 * s') (hg : t0 = 1 + 2 * g) :
    (t * (2 * q)) % (4 * q) = 2 * q := by
  have h2 : 2 * q < 4 * q := by
    rw [((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le hq (by rw [((show 2*(q) = (q) + (q) from NatNorm.sound [q] (.mul (.lit 2) (.var 0)) (.add (.var 0) (.var 0)) rfl))]; exact Nat.le_add_right q q))
  apply mod_rep _ _ _ (g + 2 * s') h2
  rw [ht, hg]; exact ((show (1 + 2*(g) + 4*(s'))*(2*(q)) = 2*(q) + ((g) + 2*(s'))*(4*(q)) from NatNorm.sound [q, g, s'] (.mul (.add (.add (.lit 1) (.mul (.lit 2) (.var 1))) (.mul (.lit 4) (.var 2))) (.mul (.lit 2) (.var 0))) (.add (.mul (.lit 2) (.var 0)) (.mul (.add (.var 1) (.mul (.lit 2) (.var 2))) (.mul (.lit 4) (.var 0)))) rfl))

theorem res_x2 (q a t ρ N' n0 par h0 : Nat) (hta : t * a = ρ + q * (n0 + 4 * N')) (hn : n0 = par + 2 * h0)
    (hr : 2 * ρ + 2 * q * par < 4 * q) : (t * (2 * a)) % (4 * q) = 2 * ρ + 2 * q * par := by
  apply mod_rep _ _ _ (h0 + 2 * N') hr
  rw [((show (t)*(2*(a)) = 2*((t)*(a)) from NatNorm.sound [t, a] (.mul (.var 0) (.mul (.lit 2) (.var 1))) (.mul (.lit 2) (.mul (.var 0) (.var 1))) rfl)), hta, hn]
  exact ((show 2*((ρ) + (q)*((par) + 2*(h0) + 4*(N'))) = 2*(ρ) + 2*(q)*(par) + ((h0) + 2*(N'))*(4*(q)) from NatNorm.sound [ρ, q, par, h0, N'] (.mul (.lit 2) (.add (.var 0) (.mul (.var 1) (.add (.add (.var 2) (.mul (.lit 2) (.var 3))) (.mul (.lit 4) (.var 4)))))) (.add (.add (.mul (.lit 2) (.var 0)) (.mul (.mul (.lit 2) (.var 1)) (.var 2))) (.mul (.add (.var 3) (.mul (.lit 2) (.var 4))) (.mul (.lit  -- (+21 chars; full line in the Zenodo source)

theorem two_lt (ρ q : Nat) (hρq : ρ < q) : 2 * ρ < 2 * q := by
  rw [((show 2*(ρ) = (ρ) + (ρ) from NatNorm.sound [ρ] (.mul (.lit 2) (.var 0)) (.add (.var 0) (.var 0)) rfl)), ((show 2*(q) = (q) + (q) from NatNorm.sound [q] (.mul (.lit 2) (.var 0)) (.add (.var 0) (.var 0)) rfl))]; exact add_lt_add' _ _ _ _ hρq hρq

theorem pair2_even (q a c d t ρ N' s' t0 g h0 : Nat) (hq : 0 < q) (hρq : ρ < q) (hρ0 : 0 < ρ)
    (hc : 2 * a + c = 2 * q) (hd : 2 * a + d = 4 * q) (ht : t = t0 + 4 * s') (hg : t0 = 1 + 2 * g)
    (hta : t * a = ρ + q * ((0 + 2 * h0) + 4 * N')) :
    (t * c) % (4 * q) + (t * d) % (4 * q) + 4 * ρ = 6 * q := by
  have hm := pos4 q hq
  have h2 := two_lt ρ q hρq
  have hr : 2 * ρ + 2 * q * 0 < 4 * q := by
    rw [((show 2*(ρ) + 2*(q)*0 = 2*(ρ) from NatNorm.sound [ρ, q] (.add (.mul (.lit 2) (.var 0)) (.mul (.mul (.lit 2) (.var 1)) (.lit 0))) (.mul (.lit 2) (.var 0)) rfl))]
    exact Nat.lt_trans h2 (by rw [((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact Nat.lt_add_of_pos_right (Nat.lt_of_le_of_lt (Nat.zero_le _) h2))
  have x2 := res_x2 q a t ρ N' (0 + 2 * h0) 0 h0 hta rfl hr
  rw [((show 2*(ρ) + 2*(q)*0 = 2*(ρ) from NatNorm.sound [ρ, q] (.add (.mul (.lit 2) (.var 0)) (.mul (.mul (.lit 2) (.var 1)) (.lit 0))) (.mul (.lit 2) (.var 0)) rfl))] at x2
  -- d: complement of 2ta
  have hD : (t * d) % (4 * q) + 2 * ρ = 4 * q := by
    apply comp (t * d) (t * (2 * a)) (4 * q) (2 * ρ) hm x2
      (Nat.lt_of_lt_of_le hρ0 (by rw [((show 2*(ρ) = (ρ) + (ρ) from NatNorm.sound [ρ] (.mul (.lit 2) (.var 0)) (.add (.var 0) (.var 0)) rfl))]; exact Nat.le_add_right ρ ρ))
      (Nat.lt_trans h2 (by rw [((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact Nat.lt_add_of_pos_right (Nat.lt_of_le_of_lt (Nat.zero_le _) h2)))
    rw [((show (t)*(d) + (t)*(2*(a)) = (t)*(2*(a) + (d)) from NatNorm.sound [t, a, d] (.add (.mul (.var 0) (.var 2)) (.mul (.var 0) (.mul (.lit 2) (.var 1)))) (.mul (.var 0) (.add (.mul (.lit 2) (.var 1)) (.var 2))) rfl)), hd]
    exact mod_rep _ 0 _ t hm ((show (t)*(4*(q)) = 0 + (t)*(4*(q)) from NatNorm.sound [t, q] (.mul (.var 0) (.mul (.lit 4) (.var 1))) (.add (.lit 0) (.mul (.var 0) (.mul (.lit 4) (.var 1)))) rfl))
  -- c: ⟨tc⟩ + 2ρ ≡ 2q
  have e := mod_add (t * c) (t * (2 * a)) (4 * q) hm
  rw [x2, ((show (t)*(c) + (t)*(2*(a)) = (t)*(2*(a) + (c)) from NatNorm.sound [t, a, c] (.add (.mul (.var 0) (.var 2)) (.mul (.var 0) (.mul (.lit 2) (.var 1)))) (.mul (.var 0) (.add (.mul (.lit 2) (.var 1)) (.var 2))) rfl)), hc, res_2q q t t0 s' g hq ht hg] at e
  have hz : (t * c) % (4 * q) + 2 * ρ < 4 * q + 4 * q :=
    add_lt_add' _ _ _ _ (Nat.mod_lt _ hm) (Nat.lt_trans h2 (by rw [((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact Nat.lt_add_of_pos_right (Nat.lt_of_le_of_lt (Nat.zero_le _) h2)))
  have hC : (t * c) % (4 * q) + 2 * ρ = 2 * q := by
    cases mod_two_cases _ _ _ hz e with
    | inl e1 => exact e1
    | inr e2 =>
      have big : (t * c) % (4 * q) + 2 * ρ < 4 * q + 2 * q := add_lt_add' _ _ _ _ (Nat.mod_lt _ hm) h2
      rw [e2] at big; exact absurd big (Nat.lt_irrefl _)
  rw [((show ((t * c) % (4 * q)) + ((t * d) % (4 * q)) + 4*(ρ) = (((t * c) % (4 * q)) + 2*(ρ)) + (((t * d) % (4 * q)) + 2*(ρ)) from NatNorm.sound [(t * c) % (4 * q), (t * d) % (4 * q), ρ] (.add (.add (.var 0) (.var 1)) (.mul (.lit 4) (.var 2))) (.add (.add (.var 0) (.mul (.lit 2) (.var 2))) (.add (.var 1) (.mul (.lit 2) (.var 2)))) rfl)), hC, hD]
  exact ((show 2*(q) + 4*(q) = 6*(q) from NatNorm.sound [q] (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 4) (.var 0))) (.mul (.lit 6) (.var 0)) rfl))

theorem pair2_odd (q a c d t ρ N' s' t0 g h0 : Nat) (hq : 0 < q) (hρq : ρ < q) (hρ0 : 0 < ρ)
    (hc : 2 * a + c = 2 * q) (hd : 2 * a + d = 4 * q) (ht : t = t0 + 4 * s') (hg : t0 = 1 + 2 * g)
    (hta : t * a = ρ + q * ((1 + 2 * h0) + 4 * N')) :
    (t * c) % (4 * q) + (t * d) % (4 * q) + 4 * ρ = 6 * q := by
  have hm := pos4 q hq
  have h2 := two_lt ρ q hρq
  have hr : 2 * ρ + 2 * q * 1 < 4 * q := by
    rw [((show 2*(ρ) + 2*(q)*1 = 2*(ρ) + 2*(q) from NatNorm.sound [ρ, q] (.add (.mul (.lit 2) (.var 0)) (.mul (.mul (.lit 2) (.var 1)) (.lit 1))) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 1))) rfl)), ((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact Nat.add_lt_add_right h2 _
  have x2 := res_x2 q a t ρ N' (1 + 2 * h0) 1 h0 hta rfl hr
  rw [((show 2*(ρ) + 2*(q)*1 = 2*(ρ) + 2*(q) from NatNorm.sound [ρ, q] (.add (.mul (.lit 2) (.var 0)) (.mul (.mul (.lit 2) (.var 1)) (.lit 1))) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 1))) rfl))] at x2
  rw [((show 2*(ρ) + 2*(q)*1 = 2*(ρ) + 2*(q) from NatNorm.sound [ρ, q] (.add (.mul (.lit 2) (.var 0)) (.mul (.mul (.lit 2) (.var 1)) (.lit 1))) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 1))) rfl))] at hr
  have hpos : 0 < 2 * ρ + 2 * q :=
    Nat.lt_of_lt_of_le hρ0 (by rw [((show 2*(ρ) + 2*(q) = (ρ) + ((ρ) + 2*(q)) from NatNorm.sound [ρ, q] (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 1))) (.add (.var 0) (.add (.var 0) (.mul (.lit 2) (.var 1)))) rfl))]; exact Nat.le_add_right ρ _)
  have hD : (t * d) % (4 * q) + (2 * ρ + 2 * q) = 4 * q := by
    apply comp (t * d) (t * (2 * a)) (4 * q) _ hm x2 hpos hr
    rw [((show (t)*(d) + (t)*(2*(a)) = (t)*(2*(a) + (d)) from NatNorm.sound [t, a, d] (.add (.mul (.var 0) (.var 2)) (.mul (.var 0) (.mul (.lit 2) (.var 1)))) (.mul (.var 0) (.add (.mul (.lit 2) (.var 1)) (.var 2))) rfl)), hd]
    exact mod_rep _ 0 _ t hm ((show (t)*(4*(q)) = 0 + (t)*(4*(q)) from NatNorm.sound [t, q] (.mul (.var 0) (.mul (.lit 4) (.var 1))) (.add (.lit 0) (.mul (.var 0) (.mul (.lit 4) (.var 1)))) rfl))
  have e := mod_add (t * c) (t * (2 * a)) (4 * q) hm
  rw [x2, ((show (t)*(c) + (t)*(2*(a)) = (t)*(2*(a) + (c)) from NatNorm.sound [t, a, c] (.add (.mul (.var 0) (.var 2)) (.mul (.var 0) (.mul (.lit 2) (.var 1)))) (.mul (.var 0) (.add (.mul (.lit 2) (.var 1)) (.var 2))) rfl)), hc, res_2q q t t0 s' g hq ht hg] at e
  have hz : (t * c) % (4 * q) + (2 * ρ + 2 * q) < 4 * q + 4 * q := add_lt_add' _ _ _ _ (Nat.mod_lt _ hm) hr
  have hC : (t * c) % (4 * q) + (2 * ρ + 2 * q) = 4 * q + 2 * q := by
    cases mod_two_cases _ _ _ hz e with
    | inr e2 => exact e2
    | inl e1 =>
      -- x + 2ρ + 2q = 2q forces 2ρ = 0
      have e3 : (t * c) % (4 * q) + 2 * ρ + 2 * q = 0 + 2 * q := by
        rw [Nat.zero_add, Nat.add_assoc]; exact e1
      have e4 := add_right_cancel' _ _ _ e3
      have : 2 * ρ ≤ 0 := e4 ▸ Nat.le_add_left (2 * ρ) ((t * c) % (4 * q))
      exact absurd (Nat.lt_of_lt_of_le (Nat.lt_of_lt_of_le hρ0 (by rw [((show 2*(ρ) = (ρ) + (ρ) from NatNorm.sound [ρ] (.mul (.lit 2) (.var 0)) (.add (.var 0) (.var 0)) rfl))]; exact Nat.le_add_right ρ ρ)) this) (Nat.lt_irrefl 0)
  apply add_right_cancel' _ _ (4 * q)
  rw [((show ((t * c) % (4 * q)) + ((t * d) % (4 * q)) + 4*(ρ) + 4*(q) = (((t * c) % (4 * q)) + (2*(ρ) + 2*(q))) + (((t * d) % (4 * q)) + (2*(ρ) + 2*(q))) from NatNorm.sound [(t * c) % (4 * q), (t * d) % (4 * q), ρ, q] (.add (.add (.add (.var 0) (.var 1)) (.mul (.lit 4) (.var 2))) (.mul (.lit 4) (.var 3))) (.add (.add (.var 0) (.add (.mul (.lit 2) (.var 2)) (.mul (.lit 2) (.var 3)))) (.add (.var 1  -- (+75 chars; full line in the Zenodo source)
  exact ((show 4*(q) + 2*(q) + 4*(q) = 6*(q) + 4*(q) from NatNorm.sound [q] (.add (.add (.mul (.lit 4) (.var 0)) (.mul (.lit 2) (.var 0))) (.mul (.lit 4) (.var 0))) (.add (.mul (.lit 6) (.var 0)) (.mul (.lit 4) (.var 0))) rfl))

/-- **Key identity, second family.** For odd t with ρ = ⟨ta⟩_q ≠ 0: Σ ⟨t c_i⟩_m = 12q = 3m. -/
theorem tsum_key2 (q a c d t ρ N : Nat) (hq : 0 < q) (hc : 2 * a + c = 2 * q) (hd : 2 * a + d = 4 * q)
    (ht : isOdd t = true) (hN : t * a = ρ + q * N) (hρq : ρ < q) (hρ0 : 0 < ρ) :
    tsum (4 * q) t [a, a + q, a + 2 * q, a + 3 * q, c, d] = 12 * q := by
  show (t * a) % (4 * q) + ((t * (a + q)) % (4 * q) + ((t * (a + 2 * q)) % (4 * q) + ((t * (a + 3 * q)) % (4 * q) + ((t * c) % (4 * q) + ((t * d) % (4 * q) + 0))))) = 12 * q
  rw [((show ((t * a) % (4 * q)) + (((t * (a + q)) % (4 * q)) + (((t * (a + 2 * q)) % (4 * q)) + (((t * (a + 3 * q)) % (4 * q)) + (((t * c) % (4 * q)) + (((t * d) % (4 * q)) + 0))))) = ((t * a) % (4 * q)) + (((t * (a + q)) % (4 * q)) + (((t * (a + 2 * q)) % (4 * q)) + ((t * (a + 3 * q)) % (4 * q)))) + (((t * c) % (4 * q)) + ((t * d) % (4 * q))) from NatNorm.sound [(t * a) % (4 * q), (t * (a + q))   -- (+307 chars; full line in the Zenodo source)
  have ⟨s', hs⟩ := four_form t ht
  have ⟨N', hN'⟩ := four_cases N
  cases hs with
  | inl hs =>
    cases hN' with
    | inl hn =>
      have hta : t * a = ρ + q * (0 + 4 * N') := by rw [hN, hn]
      exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 1 0 0 1 2 3 0 0 0 0 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
        (pair2_even q a c d t ρ N' s' 1 0 0 hq hρq hρ0 hc hd hs rfl hta)
    | inr hn => cases hn with
      | inl hn =>
        have hta : t * a = ρ + q * (1 + 4 * N') := by rw [hN, hn]
        exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 1 1 1 2 3 0 0 0 0 1 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
          (pair2_odd q a c d t ρ N' s' 1 0 0 hq hρq hρ0 hc hd hs rfl hta)
      | inr hn => cases hn with
        | inl hn =>
          have hta : t * a = ρ + q * (2 + 4 * N') := by rw [hN, hn]
          exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 1 2 2 3 0 1 0 0 1 1 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
            (pair2_even q a c d t ρ N' s' 1 0 1 hq hρq hρ0 hc hd hs rfl hta)
        | inr hn =>
          have hta : t * a = ρ + q * (3 + 4 * N') := by rw [hN, hn]
          exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 1 3 3 0 1 2 0 1 1 1 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
            (pair2_odd q a c d t ρ N' s' 1 0 1 hq hρq hρ0 hc hd hs rfl hta)
  | inr hs =>
    cases hN' with
    | inl hn =>
      have hta : t * a = ρ + q * (0 + 4 * N') := by rw [hN, hn]
      exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 3 0 0 3 2 1 0 0 1 2 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
        (pair2_even q a c d t ρ N' s' 3 1 0 hq hρq hρ0 hc hd hs rfl hta)
    | inr hn => cases hn with
      | inl hn =>
        have hta : t * a = ρ + q * (1 + 4 * N') := by rw [hN, hn]
        exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 3 1 1 0 3 2 0 1 1 2 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
          (pair2_odd q a c d t ρ N' s' 3 1 0 hq hρq hρ0 hc hd hs rfl hta)
      | inr hn => cases hn with
        | inl hn =>
          have hta : t * a = ρ + q * (2 + 4 * N') := by rw [hN, hn]
          exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 3 2 2 1 0 3 0 1 2 2 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
            (pair2_even q a c d t ρ N' s' 3 1 1 hq hρq hρ0 hc hd hs rfl hta)
        | inr hn =>
          have hta : t * a = ρ + q * (3 + 4 * N') := by rw [hN, hn]
          exact combine _ _ _ ρ q (ap4 q a t ρ N' s' 3 3 3 2 1 0 0 1 2 3 hρq hs hta rfl rfl rfl rfl (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) (Nat.le_of_ble_eq_true rfl) rfl)
            (pair2_odd q a c d t ρ N' s' 3 1 1 hq hρq hρ0 hc hd hs rfl hta)

def good2 (q a t : Nat) : Bool := !(Nat.beq ((t * a) % q) 0)

/-- **AP(m/4) + (m/2 − 2a, m − 2a) is balanced** when no unit sends ta to 0 mod q. -/
theorem ap_pair2_bal (q a c d : Nat) (hq : 0 < q) (hc : 2 * a + c = 2 * q) (hd : 2 * a + d = 4 * q)
    (hgood : (FermatPrime.units (4 * q)).all (good2 q a) = true) :
    bal (4 * q) [a, a + q, a + 2 * q, a + 3 * q, c, d] = true := by
  have hodd : (FermatPrime.units (4 * q)).all isOdd = true := by
    rw [((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))]; exact GcdHand.units_odd (2 * q)
  unfold bal
  apply all_imp _ _ _ _ (all_and _ _ _ hodd hgood)
  intro t h
  have h' : (isOdd t && good2 q a t) = true := h
  cases ho : isOdd t with
  | false => rw [ho] at h'; exact Bool.noConfusion h'
  | true =>
    rw [ho] at h'
    have hg : (!(Nat.beq ((t * a) % q) 0)) = true := h'
    cases g1 : Nat.beq ((t * a) % q) 0 with
    | true => rw [g1] at hg; exact Bool.noConfusion hg
    | false =>
      have ⟨N, hN⟩ := decomp (t * a) q hq
      have e := tsum_key2 q a c d t _ N hq hc hd ho hN (Nat.mod_lt _ hq) (Nat.pos_of_ne_zero (Nat.ne_of_beq_eq_false g1))
      rw [e]
      show Nat.beq (12 * q + 12 * q) (6 * (4 * q)) = true
      rw [((show 6*(4*(q)) = 12*(q) + 12*(q) from NatNorm.sound [q] (.mul (.lit 6) (.mul (.lit 4) (.var 0))) (.add (.mul (.lit 12) (.var 0)) (.mul (.lit 12) (.var 0))) rfl))]
      exact beq_self _

/-- **For every m = 4q ≥ 12, AP(m/4) + (m/2 − 2, m − 2) is balanced.** -/
theorem ap_pair2_bal1 (q c d : Nat) (hq : 3 ≤ q) (hc : 2 + c = 2 * q) (hd : 2 + d = 4 * q) :
    bal (4 * q) [1, 1 + q, 1 + 2 * q, 1 + 3 * q, c, d] = true :=
  ap_pair2_bal q 1 c d (Nat.lt_of_lt_of_le (Nat.zero_lt_succ 2) hq) hc hd
    (filter_all _ _ (fun t hg => by
      have g := APPair1.good_unit q t hq (Nat.eq_of_beq_eq_true hg)
      have g' : (!(Nat.beq ((t * 1) % q) 0) && !(Nat.beq ((t * 1) % q + (t * 1) % q) q)) = true := g
      show (!(Nat.beq ((t * 1) % q) 0)) = true
      cases b1 : Nat.beq ((t * 1) % q) 0 with
      | false => rfl
      | true => rw [b1] at g'; exact Bool.noConfusion g') _)

/-- m = 96: [1, 25, 49, 73, 46, 94]. -/
theorem ap_pair2_96 : bal 96 [1, 25, 49, 73, 46, 94] = true :=
  ap_pair2_bal1 24 46 94 (Nat.le_of_ble_eq_true rfl) rfl rfl

end APPair2

#print axioms APPair2.mod_two_cases
#print axioms APPair2.res_2q
#print axioms APPair2.res_x2
#print axioms APPair2.pair2_even
#print axioms APPair2.pair2_odd
#print axioms APPair2.tsum_key2
#print axioms APPair2.ap_pair2_bal
#print axioms APPair2.ap_pair2_bal1
#print axioms APPair2.ap_pair2_96

#print axioms: 9 theorems, no axioms.

81.48 Irreducibility of the pair families

The first family is irreducible for \(32\le m\le 160\) and splits below; the second always splits (\(m\le 160\)). \(\text {indec}\,(4q)\,\text {fam}_1(q)\ (8\le q\le 40),\quad \neg \,\text {indec}\,(4q)\,\text {fam}_2(q)\ (3\le q\le 40)\)

hodge/APPairIrr.lean

/-
  hodge/APPairIrr.lean — T41 cycle 274 (goal G17, table): which pair families are irreducible.

  Lean 4 core plus hodge/Indecomp (bal, indec), rfl. For m = 4q:
    fam1 q = [1, 1+q, 1+2q, 1+3q, 2q+4, 4q−8]   (APPair1: balanced for q ≥ 3)
    fam2 q = [1, 1+q, 1+2q, 1+3q, 2q−2, 4q−2]   (APPair2: balanced for q ≥ 3)
  fam1_irr   fam1 q has no balanced splitting for every 8 ≤ q ≤ 40 (m = 32 … 160); for q ≤ 7 it splits (fam1_red)
  fam2_red   fam2 q splits for every 3 ≤ q ≤ 40 — the second family is never a new Hodge class
  So the AP(m/4) + (m/2 + 4, m − 8) characters are the irreducible ones, as in the unreached sets of m = 88, 96, 104.
-/
import hodge.Indecomp

namespace APPairIrr
open Indecomp

def fam1 (q : Nat) : List Nat := [1, 1 + q, 1 + 2 * q, 1 + 3 * q, 2 * q + 4, 4 * q - 8]
def fam2 (q : Nat) : List Nat := [1, 1 + q, 1 + 2 * q, 1 + 3 * q, 2 * q - 2, 4 * q - 2]

set_option maxRecDepth 100000 in
theorem fam1_irr : (List.range 33).all (fun i => indec (4 * (i + 8)) (fam1 (i + 8))) = true := rfl

set_option maxRecDepth 100000 in
theorem fam1_red : (List.range 5).all (fun i => !(indec (4 * (i + 3)) (fam1 (i + 3)))) = true := rfl

set_option maxRecDepth 100000 in
theorem fam2_red : (List.range 38).all (fun i => !(indec (4 * (i + 3)) (fam2 (i + 3)))) = true := rfl

end APPairIrr

#print axioms APPairIrr.fam1_irr
#print axioms APPairIrr.fam1_red
#print axioms APPairIrr.fam2_red

#print axioms: 3 theorems, no axioms.

81.49 The first pair family is irreducible for every \(m\ge 32\)

With \(q=8+r\) every splitting already fails the Hodge condition at \(t=1\), a linear identity in \(r\); checked by reflection. \(\text {indec}\,(4q)\,[1,1+q,1+2q,1+3q,2q+4,4q-8]\quad (q\ge 8)\)

hodge/APPairIrrGen.lean

/-
  hodge/APPairIrrGen.lean — T41 cycle 276 (goal G19): AP(m/4) + (m/2 + 4, m − 8) is irreducible for every m = 4q ≥ 32,
  symbolically in q, by reflection: with q = 8 + r the six entries are α_i + β_i r, and every splitting fails the Hodge
  condition already at t = 1 (a linear identity in r with incompatible coefficients, checked by rfl on the α, β).

  Lean 4 core plus hodge/GcdHand (gcd_go, GH, GF), hodge/HalfGeneral (all_imp), hodge/ModHand (mod_lt'),
  hodge/APPair (all_and), hodge/Reach49Defs (all_map), lib/NatNorm.
    range_succ'       List.range (n+1) = List.range n ++ [n]                       (hand)
    gcd_one           Nat.gcd 1 m = 1                                              (fuel recursion)
    units_one         a predicate true on all units of n+2 is true at t = 1
    bal_t1            bal m A ⇒ 2·Σ⟨A⟩ = |A|·m  (t = 1)
    splits_map        splits (map g l) = map (map g × map g) (splits l)
    lin_bal_false     check on the coefficients ⇒ bal (m₀ + m₁r) (S.map ev) = false
    fam1_indec        indec (32 + 4r) [1, 9+r, 17+2r, 25+3r, 20+2r, 24+4r]   for every r
    fam1_indec_q      the same in q: indec (4q) [1, 1+q, 1+2q, 1+3q, 2q+4, b] for q ≥ 8, 8 + b = 4q
-/
import hodge.APPair1
import lib.NatNorm
import hodge.Reach49Defs

namespace APPairIrrGen
open ModHand HalfGeneral Indecomp GcdHand

theorem loop_acc : ∀ (n : Nat) (acc : List Nat), List.range.loop n acc = List.range.loop n [] ++ acc
  | 0, acc => rfl
  | n + 1, acc => by
    show List.range.loop n (n :: acc) = List.range.loop n [n] ++ acc
    rw [loop_acc n (n :: acc), loop_acc n [n]]
    exact app_assoc (List.range.loop n []) [n] acc
where
  app_assoc : ∀ (a : List Nat) (b c : List Nat), a ++ (b ++ c) = (a ++ b) ++ c := by
    intro a; induction a with
    | nil => intro b c; rfl
    | cons x a ih => intro b c; show x :: (a ++ (b ++ c)) = x :: ((a ++ b) ++ c); rw [ih]

theorem range_succ' (n : Nat) : List.range (n + 1) = List.range n ++ [n] := loop_acc n [n]

theorem filter_append' {α : Type} (p : α → Bool) : ∀ l1 l2 : List α, (l1 ++ l2).filter p = l1.filter p ++ l2.filter p
  | [], _ => rfl
  | x :: l1, l2 => by
    cases h : p x with
    | false =>
      show (match p x with | true => x :: (l1 ++ l2).filter p | false => (l1 ++ l2).filter p)
        = (match p x with | true => x :: l1.filter p | false => l1.filter p) ++ l2.filter p
      rw [h]; exact filter_append' p l1 l2
    | true =>
      show (match p x with | true => x :: (l1 ++ l2).filter p | false => (l1 ++ l2).filter p)
        = (match p x with | true => x :: l1.filter p | false => l1.filter p) ++ l2.filter p
      rw [h, filter_append' p l1 l2]; rfl

theorem all_append' {α : Type} (p : α → Bool) : ∀ l1 l2 : List α, (l1 ++ l2).all p = true → l1.all p = true
  | [], _, _ => rfl
  | x :: l1, l2, h => by
    have h' : (p x && (l1 ++ l2).all p) = true := h
    cases a : p x with
    | false => rw [a] at h'; exact Bool.noConfusion h'
    | true =>
      rw [a] at h'
      show (p x && l1.all p) = true
      rw [a, all_append' p l1 l2 h']; rfl

theorem units_one_gen (p g : Nat → Bool) (hp : p 1 = true) :
    ∀ n, ((List.range (n + 2)).filter p).all g = true → g 1 = true
  | 0, h => by
    have h' : ([0, 1].filter p).all g = true := h
    cases a : p 0 with
    | false =>
      have e : [0, 1].filter p = [1] := by
        show (match p 0 with | true => 0 :: [1].filter p | false => [1].filter p) = [1]
        rw [a]; show (match p 1 with | true => [1] | false => []) = [1]; rw [hp]
      rw [e] at h'
      have h'' : (g 1 && true) = true := h'
      cases b : g 1 with
      | false => rw [b] at h''; exact Bool.noConfusion h''
      | true => rfl
    | true =>
      have e : [0, 1].filter p = [0, 1] := by
        show (match p 0 with | true => 0 :: [1].filter p | false => [1].filter p) = [0, 1]
        rw [a]; show 0 :: (match p 1 with | true => [1] | false => []) = [0, 1]; rw [hp]
      rw [e] at h'
      have h'' : (g 0 && (g 1 && true)) = true := h'
      cases b : g 1 with
      | false => rw [b] at h''; cases c : g 0 <;> rw [c] at h'' <;> exact Bool.noConfusion h''
      | true => rfl
  | n + 1, h => by
    rw [range_succ', filter_append'] at h
    exact units_one_gen p g hp n (all_append' g _ _ h)

theorem gcd_one (m : Nat) : Nat.gcd 1 m = 1 := by
  rw [gcd_go]
  have inner : ∀ f (hf : GH ⟨m % 1, 1⟩ < f), WellFounded.Nat.fix.go GH GF f ⟨m % 1, 1⟩ hf = 1 := by
    intro f hf
    cases f with
    | zero => exact absurd hf (Nat.not_lt_zero _)
    | succ f =>
      show (if h : m % 1 = 0 then 1 else WellFounded.Nat.fix.go GH GF f ⟨1 % (m % 1), m % 1⟩ _) = 1
      rw [dite_eq_left (Nat.mod_one m)]
  have outer : ∀ f (hf : GH ⟨1, m⟩ < f), WellFounded.Nat.fix.go GH GF f ⟨1, m⟩ hf = 1 := by
    intro f hf
    cases f with
    | zero => exact absurd hf (Nat.not_lt_zero _)
    | succ f =>
      show (if h : 1 = 0 then m else WellFounded.Nat.fix.go GH GF f ⟨m % 1, 1⟩ _) = 1
      rw [dite_eq_right (fun h => Nat.noConfusion h)]
      exact inner f _
  exact outer _ _

/-- A predicate true on every unit of n + 2 holds at t = 1. -/
theorem units_one (n : Nat) (g : Nat → Bool) (h : (FermatPrime.units (n + 2)).all g = true) : g 1 = true :=
  units_one_gen (fun t => Nat.beq (Nat.gcd t (n + 2)) 1) g (by show Nat.beq (Nat.gcd 1 (n + 2)) 1 = true; rw [gcd_one]; rfl) n h

def sumL : List Nat → Nat
  | [] => 0
  | x :: l => x + sumL l

theorem tsum1 (m : Nat) : ∀ A : List Nat, A.all (fun x => Nat.blt x m) = true → tsum m 1 A = sumL A
  | [], _ => rfl
  | x :: A, h => by
    have h' : (Nat.blt x m && A.all (fun x => Nat.blt x m)) = true := h
    cases a : Nat.blt x m with
    | false => rw [a] at h'; exact Bool.noConfusion h'
    | true =>
      rw [a] at h'
      show (1 * x) % m + tsum m 1 A = x + sumL A
      rw [Nat.one_mul, mod_lt' x m (Nat.le_of_ble_eq_true a), tsum1 m A h']

/-- **bal at t = 1.** -/
theorem bal_t1 (n : Nat) (A : List Nat) (hA : A.all (fun x => Nat.blt x (n + 2)) = true) (hb : bal (n + 2) A = true) :
    sumL A + sumL A = A.length * (n + 2) := by
  have h := units_one n _ hb
  rw [tsum1 (n + 2) A hA] at h
  exact Nat.eq_of_beq_eq_true h

/-! ## Reflection over coefficient lists -/

def ev (r : Nat) (c : Nat × Nat) : Nat := c.1 + c.2 * r

def sA : List (Nat × Nat) → Nat
  | [] => 0
  | c :: l => c.1 + sA l

def sB : List (Nat × Nat) → Nat
  | [] => 0
  | c :: l => c.2 + sB l

theorem sumL_map (r : Nat) : ∀ S : List (Nat × Nat), sumL (S.map (ev r)) = sA S + sB S * r
  | [] => by show 0 = 0 + 0 * r; exact ((show 0 = 0 + 0*(r) from NatNorm.sound [r] (.lit 0) (.add (.lit 0) (.mul (.lit 0) (.var 0))) rfl))
  | c :: S => by
    show c.1 + c.2 * r + sumL (S.map (ev r)) = c.1 + sA S + (c.2 + sB S) * r
    rw [sumL_map r S]
    exact ((show (c.1) + (c.2)*(r) + ((sA S) + (sB S)*(r)) = (c.1) + (sA S) + ((c.2) + (sB S))*(r) from NatNorm.sound [c.1, c.2, sA S, sB S, r] (.add (.add (.var 0) (.mul (.var 1) (.var 4))) (.add (.var 2) (.mul (.var 3) (.var 4)))) (.add (.add (.var 0) (.var 2)) (.mul (.add (.var 1) (.var 3)) (.var 4))) rfl))

theorem length_map' {α β : Type} (g : α → β) : ∀ l : List α, (l.map g).length = l.length
  | [] => rfl
  | _ :: l => by show (l.map g).length + 1 = l.length + 1; rw [length_map' g l]

/-- the coefficient test: 2Σα + 2Σβ·r = |S|(m₀ + m₁ r) is impossible for every r -/
def chk (m0 m1 : Nat) (S : List (Nat × Nat)) : Bool :=
  let a1 := 2 * sA S; let b1 := 2 * sB S; let a2 := S.length * m0; let b2 := S.length * m1
  (Nat.blt a1 a2 && Nat.ble b1 b2) || (Nat.blt a2 a1 && Nat.ble b2 b1)

def small (m0 m1 : Nat) (c : Nat × Nat) : Bool := Nat.blt c.1 m0 && Nat.ble c.2 m1

theorem lt_lin (a b c d r : Nat) (h1 : a < c) (h2 : b ≤ d) : a + b * r < c + d * r := by
  have ⟨x, hx⟩ := Nat.le.dest h1
  have ⟨y, hy⟩ := Nat.le.dest h2
  rw [← hx, ← hy, ((show (a) + 1 + (x) + ((b) + (y))*(r) = (a) + (b)*(r) + (1 + (x) + (y)*(r)) from NatNorm.sound [a, x, b, y, r] (.add (.add (.add (.var 0) (.lit 1)) (.var 1)) (.mul (.add (.var 2) (.var 3)) (.var 4))) (.add (.add (.var 0) (.mul (.var 2) (.var 4))) (.add (.add (.lit 1) (.var 1)) (.mul (.var 3) (.var 4)))) rfl))]
  exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.zero_lt_succ 0) (by
    rw [((show 1 + (x) + (y)*(r) = 1 + ((x) + (y)*(r)) from NatNorm.sound [x, y, r] (.add (.add (.lit 1) (.var 0)) (.mul (.var 1) (.var 2))) (.add (.lit 1) (.add (.var 0) (.mul (.var 1) (.var 2)))) rfl))]; exact Nat.le_add_right 1 _))

theorem small_lt (m0 m1 r : Nat) : ∀ S : List (Nat × Nat), S.all (small m0 m1) = true →
    (S.map (ev r)).all (fun x => Nat.blt x (m0 + m1 * r)) = true
  | [], _ => rfl
  | c :: S, h => by
    have h' : (small m0 m1 c && S.all (small m0 m1)) = true := h
    cases a : small m0 m1 c with
    | false => rw [a] at h'; exact Bool.noConfusion h'
    | true =>
      rw [a] at h'
      have a' : (Nat.blt c.1 m0 && Nat.ble c.2 m1) = true := a
      cases b1 : Nat.blt c.1 m0 <;> cases b2 : Nat.ble c.2 m1 <;> rw [b1, b2] at a'
      · exact Bool.noConfusion a'
      · exact Bool.noConfusion a'
      · exact Bool.noConfusion a'
      · show (Nat.blt (ev r c) (m0 + m1 * r) && (S.map (ev r)).all _) = true
        have lt : ev r c < m0 + m1 * r := lt_lin _ _ _ _ r (Nat.le_of_ble_eq_true b1) (Nat.le_of_ble_eq_true b2)
        have : Nat.blt (ev r c) (m0 + m1 * r) = true := Nat.ble_eq_true_of_le lt
        rw [this, small_lt m0 m1 r S h']; rfl

theorem lin_bal_false (n m0 m1 r : Nat) (hm : m0 + m1 * r = n + 2) (S : List (Nat × Nat))
    (hs : S.all (small m0 m1) = true) (hc : chk m0 m1 S = true) : bal (n + 2) (S.map (ev r)) = false := by
  cases hb : bal (n + 2) (S.map (ev r)) with
  | false => rfl
  | true =>
    have e := bal_t1 n _ (hm ▸ small_lt m0 m1 r S hs) hb
    rw [sumL_map, length_map', ← hm] at e
    have e2 : 2 * sA S + 2 * sB S * r = S.length * m0 + S.length * m1 * r := by
      rw [((show 2*(sA S) + 2*(sB S)*(r) = (sA S) + (sB S)*(r) + ((sA S) + (sB S)*(r)) from NatNorm.sound [sA S, sB S, r] (.add (.mul (.lit 2) (.var 0)) (.mul (.mul (.lit 2) (.var 1)) (.var 2))) (.add (.add (.var 0) (.mul (.var 1) (.var 2))) (.add (.var 0) (.mul (.var 1) (.var 2)))) rfl)), e]
      exact ((show (S.length)*((m0) + (m1)*(r)) = (S.length)*(m0) + (S.length)*(m1)*(r) from NatNorm.sound [S.length, m0, m1, r] (.mul (.var 0) (.add (.var 1) (.mul (.var 2) (.var 3)))) (.add (.mul (.var 0) (.var 1)) (.mul (.mul (.var 0) (.var 2)) (.var 3))) rfl))
    have hc' : ((Nat.blt (2 * sA S) (S.length * m0) && Nat.ble (2 * sB S) (S.length * m1)) ||
        (Nat.blt (S.length * m0) (2 * sA S) && Nat.ble (S.length * m1) (2 * sB S))) = true := hc
    cases c1 : Nat.blt (2 * sA S) (S.length * m0) <;> cases c2 : Nat.ble (2 * sB S) (S.length * m1) <;>
      cases c3 : Nat.blt (S.length * m0) (2 * sA S) <;> cases c4 : Nat.ble (S.length * m1) (2 * sB S) <;>
      rw [c1, c2, c3, c4] at hc' <;> first
        | exact Bool.noConfusion hc'
        | exact absurd (e2 ▸ lt_lin _ _ _ _ r (Nat.le_of_ble_eq_true c1) (Nat.le_of_ble_eq_true c2)) (Nat.lt_irrefl _)
        | exact absurd (e2 ▸ lt_lin _ _ _ _ r (Nat.le_of_ble_eq_true c3) (Nat.le_of_ble_eq_true c4)) (Nat.lt_irrefl _)

def splitsG {α : Type} : List α → List (List α × List α)
  | [] => [([], [])]
  | x :: l => (splitsG l).flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])

theorem splits_eq : ∀ l : List Nat, splits l = splitsG l
  | [] => rfl
  | x :: l => by
    show (splits l).flatMap _ = (splitsG l).flatMap _
    rw [splits_eq l]

theorem splits_map {α β : Type} (g : α → β) : ∀ l : List α,
    splitsG (l.map g) = (splitsG l).map (fun p => (p.1.map g, p.2.map g))
  | [] => rfl
  | x :: l => by
    show (splitsG (l.map g)).flatMap (fun p => [(g x :: p.1, p.2), (p.1, g x :: p.2)])
      = ((splitsG l).flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])).map (fun p => (p.1.map g, p.2.map g))
    rw [splits_map g l]
    generalize splitsG l = L
    induction L with
    | nil => rfl
    | cons p L ih =>
      show (g x :: p.1.map g, p.2.map g) :: (p.1.map g, g x :: p.2.map g) ::
          List.flatMap (fun p => [(g x :: p.1, p.2), (p.1, g x :: p.2)]) (L.map (fun p => (p.1.map g, p.2.map g)))
        = (g x :: p.1.map g, p.2.map g) :: (p.1.map g, g x :: p.2.map g) ::
          List.map (fun p => (p.1.map g, p.2.map g)) (List.flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)]) L)
      rw [ih]

def chkSplit (m0 m1 : Nat) (p : List (Nat × Nat) × List (Nat × Nat)) : Bool :=
  p.1.isEmpty || p.2.isEmpty || chk m0 m1 p.1 || chk m0 m1 p.2

theorem sub_small (m0 m1 : Nat) : ∀ (l : List (Nat × Nat)), l.all (small m0 m1) = true →
    (splitsG l).all (fun p => p.1.all (small m0 m1) && p.2.all (small m0 m1)) = true := by
  intro l; induction l with
  | nil => intro _; rfl
  | cons x l ih =>
    intro h
    have h' : (small m0 m1 x && l.all (small m0 m1)) = true := h
    cases a : small m0 m1 x with
    | false => rw [a] at h'; exact Bool.noConfusion h'
    | true =>
      rw [a] at h'
      have ih' := ih h'
      show ((splitsG l).flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])).all _ = true
      generalize splitsG l = L at ih'
      induction L with
      | nil => rfl
      | cons p L ihL =>
        have q : ((p.1.all (small m0 m1) && p.2.all (small m0 m1)) && L.all _) = true := ih'
        cases b1 : p.1.all (small m0 m1) <;> cases b2 : p.2.all (small m0 m1) <;> rw [b1, b2] at q
        · exact Bool.noConfusion q
        · exact Bool.noConfusion q
        · exact Bool.noConfusion q
        · show (((small m0 m1 x && p.1.all (small m0 m1)) && p.2.all (small m0 m1)) &&
            ((p.1.all (small m0 m1) && (small m0 m1 x && p.2.all (small m0 m1))) &&
              (List.flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)]) L).all
                (fun p => p.1.all (small m0 m1) && p.2.all (small m0 m1)))) = true
          rw [a, b1, b2, ihL q]; rfl

/-- **Reflection.** If every splitting passes chkSplit, the family is irreducible for every r. -/
theorem indec_lin (n m0 m1 r : Nat) (hm : m0 + m1 * r = n + 2) (co : List (Nat × Nat))
    (hs : co.all (small m0 m1) = true) (hsp : (splitsG co).all (chkSplit m0 m1) = true) :
    indec (n + 2) (co.map (ev r)) = true := by
  unfold indec
  rw [splits_eq, splits_map]
  have hb := APPair.all_and _ _ _ (sub_small m0 m1 co hs) hsp
  rw [Reach49.all_map]
  apply all_imp _ _ _ _ hb
  intro p hp
  have hp' : ((p.1.all (small m0 m1) && p.2.all (small m0 m1)) && chkSplit m0 m1 p) = true := hp
  cases s1 : p.1.all (small m0 m1) <;> cases s2 : p.2.all (small m0 m1) <;> rw [s1, s2] at hp'
  · exact Bool.noConfusion hp'
  · exact Bool.noConfusion hp'
  · exact Bool.noConfusion hp'
  · have hc : (p.1.isEmpty || p.2.isEmpty || chk m0 m1 p.1 || chk m0 m1 p.2) = true := hp'
    show ((p.1.map (ev r)).isEmpty || (p.2.map (ev r)).isEmpty || !(bal (n + 2) (p.1.map (ev r)) && bal (n + 2) (p.2.map (ev r)))) = true
    have em : ∀ l : List (Nat × Nat), (l.map (ev r)).isEmpty = l.isEmpty := fun l => by cases l <;> rfl
    rw [em, em]
    cases e1 : p.1.isEmpty
    · cases e2 : p.2.isEmpty
      · rw [e1, e2] at hc
        cases k1 : chk m0 m1 p.1
        · rw [k1] at hc
          have k2 : chk m0 m1 p.2 = true := hc
          rw [lin_bal_false n m0 m1 r hm p.2 s2 k2]
          cases bal (n + 2) (p.1.map (ev r)) <;> rfl
        · rw [lin_bal_false n m0 m1 r hm p.1 s1 k1]; rfl
      · rfl
    · rfl

def co1 : List (Nat × Nat) := [(1, 0), (9, 1), (17, 2), (25, 3), (20, 2), (24, 4)]

theorem co1_small : co1.all (small 32 4) = true := rfl
theorem co1_splits : (splitsG co1).all (chkSplit 32 4) = true := rfl

/-- **AP(m/4) + (m/2 + 4, m − 8) is irreducible for every m = 4(8 + r).** -/
theorem fam1_indec (r : Nat) : indec (30 + 4 * r + 2) (co1.map (ev r)) = true :=
  indec_lin (30 + 4 * r) 32 4 r ((show 32 + 4*(r) = 30 + 4*(r) + 2 from NatNorm.sound [r] (.add (.lit 32) (.mul (.lit 4) (.var 0))) (.add (.add (.lit 30) (.mul (.lit 4) (.var 0))) (.lit 2)) rfl)) co1 co1_small co1_splits

/-- The same in q: for q ≥ 8 and 8 + b = 4q, [1, 1+q, 1+2q, 1+3q, 2q+4, b] is irreducible in m = 4q. -/
theorem fam1_indec_q (q b : Nat) (hq : 8 ≤ q) (hb : 8 + b = 4 * q) :
    indec (4 * q) [1, 1 + q, 1 + 2 * q, 1 + 3 * q, 2 * q + 4, b] = true := by
  have ⟨r, hr⟩ := Nat.le.dest hq
  have e1 := fam1_indec r
  have hb' : b = 24 + 4 * r := by
    apply add_right_cancel' _ _ 8
    rw [Nat.add_comm b 8, hb, ← hr]; exact ((show 4*(8 + (r)) = 24 + 4*(r) + 8 from NatNorm.sound [r] (.mul (.lit 4) (.add (.lit 8) (.var 0))) (.add (.add (.lit 24) (.mul (.lit 4) (.var 0))) (.lit 8)) rfl))
  have eq : [1, 1 + q, 1 + 2 * q, 1 + 3 * q, 2 * q + 4, b] = co1.map (ev r) := by
    rw [hb', ← hr]
    show [1, 1 + (8 + r), 1 + 2 * (8 + r), 1 + 3 * (8 + r), 2 * (8 + r) + 4, 24 + 4 * r]
      = [1 + 0 * r, 9 + 1 * r, 17 + 2 * r, 25 + 3 * r, 20 + 2 * r, 24 + 4 * r]
    rw [((show 1 + 0*(r) = 1 from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 0) (.var 0))) (.lit 1) rfl)), ((show 1 + (8 + (r)) = 9 + 1*(r) from NatNorm.sound [r] (.add (.lit 1) (.add (.lit 8) (.var 0))) (.add (.lit 9) (.mul (.lit 1) (.var 0))) rfl)), ((show 1 + 2*(8 + (r)) = 17 + 2*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 2) (.add (.lit 8) (.var 0)))) (.add (.lit 17) (.mul (.lit 2)  -- (+183 chars; full line in the Zenodo source)
      ((show 2*(8 + (r)) + 4 = 20 + 2*(r) from NatNorm.sound [r] (.add (.mul (.lit 2) (.add (.lit 8) (.var 0))) (.lit 4)) (.add (.lit 20) (.mul (.lit 2) (.var 0))) rfl))]
  rw [eq, ← hr, ((show 4*(8 + (r)) = 30 + 4*(r) + 2 from NatNorm.sound [r] (.mul (.lit 4) (.add (.lit 8) (.var 0))) (.add (.add (.lit 30) (.mul (.lit 4) (.var 0))) (.lit 2)) rfl))]
  exact e1

end APPairIrrGen

#print axioms APPairIrrGen.range_succ'
#print axioms APPairIrrGen.gcd_one
#print axioms APPairIrrGen.units_one
#print axioms APPairIrrGen.bal_t1
#print axioms APPairIrrGen.splits_map
#print axioms APPairIrrGen.lin_bal_false
#print axioms APPairIrrGen.indec_lin
#print axioms APPairIrrGen.fam1_indec
#print axioms APPairIrrGen.fam1_indec_q

#print axioms: 9 theorems, no axioms.

81.50 The first pair family for every start \(a\)

Euclid’s lemma through the fuel recursion of core gcd removes the hypothesis of the AP-pair theorem for \(0<2a<q\). \(\text {bal}\,(4q)\,[a,a+q,a+2q,a+3q,2q+4a,4q-8a]\quad (0<a,\ 2a<q)\)

hodge/APPairGen.lean

/-
  hodge/APPairGen.lean — T41 cycle 277 (goal G20): Euclid's lemma by hand through core gcd, and the first pair family
  for every start a: AP(a) + (m/2 + 4a, m − 8a) is balanced in m = 4q whenever 0 < a and 2a < q.

  Lean 4 core plus hodge/APPair1 (dvd_sub_form, dvd_gcd), hodge/APPair (ap_pair_bal, good), hodge/GcdHand, lib/NatNorm.
    euclid_go     d ∣ x₁a, d ∣ x₂a ⇒ d ∣ (go x)·a            (fuel recursion of core gcd)
    euclid        gcd t n = 1, d ∣ ta, d ∣ na ⇒ d ∣ a
    not_dvd_small 0 < y < q ⇒ ¬ q ∣ y
    good_gen      gcd t 4q = 1, 0 < a, 2a < q ⇒ good q a t
    ap_pair_bal_gen   bal (4q) [a, a+q, a+2q, a+3q, 2q+4a, b]  for 8a + b = 4q, 0 < a, 2a < q
-/
import hodge.APPair1

namespace APPairGen
open ModHand HalfGeneral Indecomp GcdHand APPair APPair1

theorem euclid_go (d a : Nat) : ∀ (f : Nat) (x : (_ : Nat) ×' Nat) (hf : GH x < f),
    (∃ i, x.1 * a = d * i) → (∃ j, x.2 * a = d * j) → ∃ k, WellFounded.Nat.fix.go GH GF f x hf * a = d * k
  | 0, _, hf, _, _ => absurd hf (Nat.not_lt_zero _)
  | f + 1, ⟨m, n⟩, hf, hm, hn => by
    show ∃ k, (if h : m = 0 then n else WellFounded.Nat.fix.go GH GF f ⟨n % m, m⟩ _) * a = d * k
    by_cases h0 : m = 0
    · rw [dite_eq_left h0]; exact hn
    · rw [dite_eq_right h0]
      apply euclid_go d a f ⟨n % m, m⟩ _ _ hm
      -- n a = (n % m) a + (m a) k
      have ⟨k, hk⟩ := decomp n m (Nat.pos_of_ne_zero h0)
      have ⟨i, hi⟩ := hm
      have ⟨j, hj⟩ := hn
      apply dvd_sub_form d ((n % m) * a) (i * k) j
      rw [← hj]
      show n * a = n % m * a + d * (i * k)
      calc n * a = (n % m + m * k) * a := by rw [← hk]
        _ = n % m * a + (m * a) * k := ((show ((n % m) + (m)*(k))*(a) = (n % m)*(a) + ((m)*(a))*(k) from NatNorm.sound [n % m, m, k, a] (.mul (.add (.var 0) (.mul (.var 1) (.var 2))) (.var 3)) (.add (.mul (.var 0) (.var 3)) (.mul (.mul (.var 1) (.var 3)) (.var 2))) rfl))
        _ = n % m * a + d * (i * k) := by rw [hi, ((show (d)*(i)*(k) = (d)*((i)*(k)) from NatNorm.sound [d, i, k] (.mul (.mul (.var 0) (.var 1)) (.var 2)) (.mul (.var 0) (.mul (.var 1) (.var 2))) rfl))]

theorem euclid (t n d a : Nat) (hg : Nat.gcd t n = 1) (h1 : ∃ i, t * a = d * i) (h2 : ∃ j, n * a = d * j) :
    ∃ k, a = d * k := by
  have := euclid_go d a _ ⟨t, n⟩ (eager_gt t) h1 h2
  rw [← gcd_go, hg, Nat.one_mul] at this
  exact this

theorem not_dvd_small (q y k : Nat) (h0 : 0 < y) (hq : y < q) (h : y = q * k) : False := by
  cases k with
  | zero => rw [h, Nat.mul_zero] at h0; exact Nat.lt_irrefl 0 h0
  | succ k =>
    have : q ≤ y := by rw [h, ((show (q)*((k)+1) = (q) + (q)*(k) from NatNorm.sound [q, k] (.mul (.var 0) (.add (.var 1) (.lit 1))) (.add (.var 0) (.mul (.var 0) (.var 1))) rfl))]; exact Nat.le_add_right q _
    exact Nat.lt_irrefl y (Nat.lt_of_lt_of_le hq this)

theorem good_gen (q a t : Nat) (ha : 0 < a) (h2a : a + a < q) (hg : Nat.gcd t (4 * q) = 1) : good q a t = true := by
  have hq0 : 0 < q := Nat.lt_of_le_of_lt (Nat.zero_le _) h2a
  have haq : a < q := Nat.lt_of_le_of_lt (Nat.le_add_right a a) h2a
  have h4 : ∃ j, 4 * q * (a + a) = q * j := ⟨4 * (a + a), ((show 4*(q)*((a) + (a)) = (q)*(4*((a) + (a))) from NatNorm.sound [q, a] (.mul (.mul (.lit 4) (.var 0)) (.add (.var 1) (.var 1))) (.mul (.var 0) (.mul (.lit 4) (.add (.var 1) (.var 1)))) rfl))⟩
  have ⟨N, hN⟩ := decomp (t * a) q hq0
  show (!(Nat.beq ((t * a) % q) 0) && !(Nat.beq ((t * a) % q + (t * a) % q) q)) = true
  cases g1 : Nat.beq ((t * a) % q) 0 with
  | true =>
    have e := Nat.eq_of_beq_eq_true g1
    rw [e, Nat.zero_add] at hN
    have ⟨k, hk⟩ := euclid t (4 * q) q a hg ⟨N, hN⟩ ⟨4 * a, ((show 4*(q)*(a) = (q)*(4*(a)) from NatNorm.sound [q, a] (.mul (.mul (.lit 4) (.var 0)) (.var 1)) (.mul (.var 0) (.mul (.lit 4) (.var 1))) rfl))⟩
    exact absurd (not_dvd_small q a k ha haq hk) id
  | false =>
    cases g2 : Nat.beq ((t * a) % q + (t * a) % q) q with
    | false => rfl
    | true =>
      have e := Nat.eq_of_beq_eq_true g2
      have h1 : ∃ i, t * (a + a) = q * i := ⟨1 + 2 * N, by
        rw [((show (t)*((a) + (a)) = (t)*(a) + (t)*(a) from NatNorm.sound [t, a] (.mul (.var 0) (.add (.var 1) (.var 1))) (.add (.mul (.var 0) (.var 1)) (.mul (.var 0) (.var 1))) rfl)), hN,
          ((show ((t * a) % q) + (q)*(N) + (((t * a) % q) + (q)*(N)) = ((t * a) % q) + ((t * a) % q) + (q)*(2*(N)) from NatNorm.sound [(t * a) % q, q, N] (.add (.add (.var 0) (.mul (.var 1) (.var 2))) (.add (.var 0) (.mul (.var 1) (.var 2)))) (.add (.add (.var 0) (.var 0)) (.mul (.var 1) (.mul (.lit 2) (.var 2)))) rfl)), e]
        exact ((show (q) + (q)*(2*(N)) = (q)*(1 + 2*(N)) from NatNorm.sound [q, N] (.add (.var 0) (.mul (.var 0) (.mul (.lit 2) (.var 1)))) (.mul (.var 0) (.add (.lit 1) (.mul (.lit 2) (.var 1)))) rfl))⟩
      have ⟨k, hk⟩ := euclid t (4 * q) q (a + a) hg h1 h4
      exact absurd (not_dvd_small q (a + a) k (Nat.lt_of_lt_of_le ha (Nat.le_add_right a a)) h2a hk) id

/-- **AP(a) + (m/2 + 4a, m − 8a) is balanced for every m = 4q and 0 < a, 2a < q.** -/
theorem ap_pair_bal_gen (q a b : Nat) (ha : 0 < a) (h2a : a + a < q) (hb : 8 * a + b = 4 * q) :
    bal (4 * q) [a, a + q, a + 2 * q, a + 3 * q, 2 * q + 4 * a, b] = true :=
  ap_pair_bal q a b (Nat.lt_of_le_of_lt (Nat.zero_le _) h2a) hb
    (filter_all _ _ (fun t hg => good_gen q a t ha h2a (Nat.eq_of_beq_eq_true hg)) _)

end APPairGen

#print axioms APPairGen.euclid_go
#print axioms APPairGen.euclid
#print axioms APPairGen.not_dvd_small
#print axioms APPairGen.good_gen
#print axioms APPairGen.ap_pair_bal_gen

#print axioms: 5 theorems, no axioms.

81.51 Irreducible for every start \(a\) with \(q\ge 8a\)

The \(t=1\) reflection test in the two variables \(a\) and \(r=q-8a\). \(\text {indec}\,(4q)\,[a,a+q,a+2q,a+3q,2q+4a,4q-8a]\quad (a\ge 1,\ q\ge 8a)\)

hodge/APPairIrrGen2.lean

/-
  hodge/APPairIrrGen2.lean — T41 cycle 278 (goal G21): AP(a) + (m/2 + 4a, m − 8a) is irreducible in m = 4q for every
  a ≥ 1 and q ≥ 8a. With q = 8a + r every entry is α·a + β·r (α as for a = 1), and the t = 1 test of APPairIrrGen
  works verbatim in two variables (a > 0).

  Lean 4 core plus hodge/APPairIrrGen (splitsG, splits_eq, splits_map, chk, chkSplit, small, sA, sB, sub_small, bal_t1,
  sumL, length_map', co1, co1_small, co1_splits), hodge/APPairGen, lib/NatNorm.
    lt_lin2, sumL_map2, small_lt2, lin_bal_false2, indec_lin2
    fam_indec       indec (32a + 4r) [a, 9a+r, 17a+2r, 25a+3r, 20a+2r, 24a+4r]    (a ≥ 1, every r)
    fam_indec_q     indec (4q) [a, a+q, a+2q, a+3q, 2q+4a, b]  for q ≥ 8a, a ≥ 1, 8a + b = 4q
  With APPairGen.ap_pair_bal_gen: balanced and irreducible.
-/
import hodge.APPairIrrGen
import hodge.APPairGen

namespace APPairIrrGen2
open ModHand HalfGeneral Indecomp GcdHand APPairIrrGen

def ev2 (a r : Nat) (c : Nat × Nat) : Nat := c.1 * a + c.2 * r

theorem sumL_map2 (a r : Nat) : ∀ S : List (Nat × Nat), sumL (S.map (ev2 a r)) = sA S * a + sB S * r
  | [] => by show 0 = 0 * a + 0 * r; exact ((show 0 = 0*(a) + 0*(r) from NatNorm.sound [a, r] (.lit 0) (.add (.mul (.lit 0) (.var 0)) (.mul (.lit 0) (.var 1))) rfl))
  | c :: S => by
    show c.1 * a + c.2 * r + sumL (S.map (ev2 a r)) = (c.1 + sA S) * a + (c.2 + sB S) * r
    rw [sumL_map2 a r S]
    exact ((show (c.1)*(a) + (c.2)*(r) + ((sA S)*(a) + (sB S)*(r)) = ((c.1) + (sA S))*(a) + ((c.2) + (sB S))*(r) from NatNorm.sound [c.1, c.2, sA S, sB S, a, r] (.add (.add (.mul (.var 0) (.var 4)) (.mul (.var 1) (.var 5))) (.add (.mul (.var 2) (.var 4)) (.mul (.var 3) (.var 5)))) (.add (.mul (.add (.var 0) (.var 2)) (.var 4)) (.mul (.add (.var 1) (.var 3)) (.var 5))) rfl))

theorem lt_lin2 (p b c d a r : Nat) (ha : 0 < a) (h1 : p < c) (h2 : b ≤ d) : p * a + b * r < c * a + d * r := by
  have ⟨x, hx⟩ := Nat.le.dest h1
  have ⟨y, hy⟩ := Nat.le.dest h2
  rw [← hx, ← hy, ((show ((p) + 1 + (x))*(a) + ((b) + (y))*(r) = (p)*(a) + (b)*(r) + ((a) + ((x)*(a) + (y)*(r))) from NatNorm.sound [p, x, b, y, a, r] (.add (.mul (.add (.add (.var 0) (.lit 1)) (.var 1)) (.var 4)) (.mul (.add (.var 2) (.var 3)) (.var 5))) (.add (.add (.mul (.var 0) (.var 4)) (.mul (.var 2) (.var 5))) (.add (.var 4) (.add (.mul (.var 1) (.var 4)) (.mul (.var 3) (.var 5))))) rfl))]
  exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le ha (Nat.le_add_right a _))

theorem small_lt2 (m0 m1 a r : Nat) (ha : 0 < a) : ∀ S : List (Nat × Nat), S.all (small m0 m1) = true →
    (S.map (ev2 a r)).all (fun x => Nat.blt x (m0 * a + m1 * r)) = true
  | [], _ => rfl
  | c :: S, h => by
    have h' : (small m0 m1 c && S.all (small m0 m1)) = true := h
    cases e : small m0 m1 c with
    | false => rw [e] at h'; exact Bool.noConfusion h'
    | true =>
      rw [e] at h'
      have a' : (Nat.blt c.1 m0 && Nat.ble c.2 m1) = true := e
      cases b1 : Nat.blt c.1 m0 <;> cases b2 : Nat.ble c.2 m1 <;> rw [b1, b2] at a'
      · exact Bool.noConfusion a'
      · exact Bool.noConfusion a'
      · exact Bool.noConfusion a'
      · show (Nat.blt (ev2 a r c) (m0 * a + m1 * r) && (S.map (ev2 a r)).all _) = true
        have lt : ev2 a r c < m0 * a + m1 * r :=
          lt_lin2 _ _ _ _ a r ha (Nat.le_of_ble_eq_true b1) (Nat.le_of_ble_eq_true b2)
        have : Nat.blt (ev2 a r c) (m0 * a + m1 * r) = true := Nat.ble_eq_true_of_le lt
        rw [this, small_lt2 m0 m1 a r ha S h']; rfl

theorem lin_bal_false2 (n m0 m1 a r : Nat) (ha : 0 < a) (hm : m0 * a + m1 * r = n + 2) (S : List (Nat × Nat))
    (hs : S.all (small m0 m1) = true) (hc : chk m0 m1 S = true) : bal (n + 2) (S.map (ev2 a r)) = false := by
  cases hb : bal (n + 2) (S.map (ev2 a r)) with
  | false => rfl
  | true =>
    have e := bal_t1 n _ (hm ▸ small_lt2 m0 m1 a r ha S hs) hb
    rw [sumL_map2, length_map', ← hm] at e
    have e2 : 2 * sA S * a + 2 * sB S * r = S.length * m0 * a + S.length * m1 * r := by
      rw [((show 2*(sA S)*(a) + 2*(sB S)*(r) = (sA S)*(a) + (sB S)*(r) + ((sA S)*(a) + (sB S)*(r)) from NatNorm.sound [sA S, sB S, a, r] (.add (.mul (.mul (.lit 2) (.var 0)) (.var 2)) (.mul (.mul (.lit 2) (.var 1)) (.var 3))) (.add (.add (.mul (.var 0) (.var 2)) (.mul (.var 1) (.var 3))) (.add (.mul (.var 0) (.var 2)) (.mul (.var 1) (.var 3)))) rfl)), e]
      exact ((show (S.length)*((m0)*(a) + (m1)*(r)) = (S.length)*(m0)*(a) + (S.length)*(m1)*(r) from NatNorm.sound [S.length, m0, m1, a, r] (.mul (.var 0) (.add (.mul (.var 1) (.var 3)) (.mul (.var 2) (.var 4)))) (.add (.mul (.mul (.var 0) (.var 1)) (.var 3)) (.mul (.mul (.var 0) (.var 2)) (.var 4))) rfl))
    have hc' : ((Nat.blt (2 * sA S) (S.length * m0) && Nat.ble (2 * sB S) (S.length * m1)) ||
        (Nat.blt (S.length * m0) (2 * sA S) && Nat.ble (S.length * m1) (2 * sB S))) = true := hc
    cases c1 : Nat.blt (2 * sA S) (S.length * m0) <;> cases c2 : Nat.ble (2 * sB S) (S.length * m1) <;>
      cases c3 : Nat.blt (S.length * m0) (2 * sA S) <;> cases c4 : Nat.ble (S.length * m1) (2 * sB S) <;>
      rw [c1, c2, c3, c4] at hc' <;> first
        | exact Bool.noConfusion hc'
        | exact absurd (e2 ▸ lt_lin2 _ _ _ _ a r ha (Nat.le_of_ble_eq_true c1) (Nat.le_of_ble_eq_true c2)) (Nat.lt_irrefl _)
        | exact absurd (e2 ▸ lt_lin2 _ _ _ _ a r ha (Nat.le_of_ble_eq_true c3) (Nat.le_of_ble_eq_true c4)) (Nat.lt_irrefl _)

theorem indec_lin2 (n m0 m1 a r : Nat) (ha : 0 < a) (hm : m0 * a + m1 * r = n + 2) (co : List (Nat × Nat))
    (hs : co.all (small m0 m1) = true) (hsp : (splitsG co).all (chkSplit m0 m1) = true) :
    indec (n + 2) (co.map (ev2 a r)) = true := by
  unfold indec
  rw [splits_eq, splits_map]
  have hb := APPair.all_and _ _ _ (sub_small m0 m1 co hs) hsp
  rw [Reach49.all_map]
  apply all_imp _ _ _ _ hb
  intro p hp
  have hp' : ((p.1.all (small m0 m1) && p.2.all (small m0 m1)) && chkSplit m0 m1 p) = true := hp
  cases s1 : p.1.all (small m0 m1) <;> cases s2 : p.2.all (small m0 m1) <;> rw [s1, s2] at hp'
  · exact Bool.noConfusion hp'
  · exact Bool.noConfusion hp'
  · exact Bool.noConfusion hp'
  · have hc : (p.1.isEmpty || p.2.isEmpty || chk m0 m1 p.1 || chk m0 m1 p.2) = true := hp'
    show ((p.1.map (ev2 a r)).isEmpty || (p.2.map (ev2 a r)).isEmpty ||
      !(bal (n + 2) (p.1.map (ev2 a r)) && bal (n + 2) (p.2.map (ev2 a r)))) = true
    have em : ∀ l : List (Nat × Nat), (l.map (ev2 a r)).isEmpty = l.isEmpty := fun l => by cases l <;> rfl
    rw [em, em]
    cases e1 : p.1.isEmpty
    · cases e2 : p.2.isEmpty
      · rw [e1, e2] at hc
        cases k1 : chk m0 m1 p.1
        · rw [k1] at hc
          have k2 : chk m0 m1 p.2 = true := hc
          rw [lin_bal_false2 n m0 m1 a r ha hm p.2 s2 k2]
          cases bal (n + 2) (p.1.map (ev2 a r)) <;> rfl
        · rw [lin_bal_false2 n m0 m1 a r ha hm p.1 s1 k1]; rfl
      · rfl
    · rfl

/-- **AP(a) + (m/2 + 4a, m − 8a) is irreducible in m = 4(8a + r), every a ≥ 1, r.** -/
theorem fam_indec (a r : Nat) (ha : 0 < a) (n : Nat) (hn : 32 * a + 4 * r = n + 2) :
    indec (n + 2) (co1.map (ev2 a r)) = true :=
  indec_lin2 n 32 4 a r ha hn co1 co1_small co1_splits

/-- The same in q: for a ≥ 1, q ≥ 8a and 8a + b = 4q, [a, a+q, a+2q, a+3q, 2q+4a, b] is irreducible. -/
theorem fam_indec_q (q a b : Nat) (ha : 0 < a) (hq : 8 * a ≤ q) (hb : 8 * a + b = 4 * q) :
    indec (4 * q) [a, a + q, a + 2 * q, a + 3 * q, 2 * q + 4 * a, b] = true := by
  have ⟨r, hr⟩ := Nat.le.dest hq
  have ⟨k, hk⟩ := Nat.le.dest ha
  have hn : 32 * a + 4 * r = (30 * a + 4 * r + 2 * k) + 2 := by
    rw [← hk]; exact ((show 32*(0 + 1 + (k)) + 4*(r) = 30*(0 + 1 + (k)) + 4*(r) + 2*(k) + 2 from NatNorm.sound [k, r] (.add (.mul (.lit 32) (.add (.add (.lit 0) (.lit 1)) (.var 0))) (.mul (.lit 4) (.var 1))) (.add (.add (.add (.mul (.lit 30) (.add (.add (.lit 0) (.lit 1)) (.var 0))) (.mul (.lit 4) (.var 1))) (.mul (.lit 2) (.var 0))) (.lit 2)) rfl))
  have e1 := fam_indec a r ha _ hn
  have hb' : b = 24 * a + 4 * r := by
    apply add_right_cancel' _ _ (8 * a)
    rw [Nat.add_comm b (8 * a), hb, ← hr]; exact ((show 4*(8*(a) + (r)) = 24*(a) + 4*(r) + 8*(a) from NatNorm.sound [a, r] (.mul (.lit 4) (.add (.mul (.lit 8) (.var 0)) (.var 1))) (.add (.add (.mul (.lit 24) (.var 0)) (.mul (.lit 4) (.var 1))) (.mul (.lit 8) (.var 0))) rfl))
  have eq : [a, a + q, a + 2 * q, a + 3 * q, 2 * q + 4 * a, b] = co1.map (ev2 a r) := by
    rw [hb', ← hr]
    show [a, a + (8 * a + r), a + 2 * (8 * a + r), a + 3 * (8 * a + r), 2 * (8 * a + r) + 4 * a, 24 * a + 4 * r]
      = [1 * a + 0 * r, 9 * a + 1 * r, 17 * a + 2 * r, 25 * a + 3 * r, 20 * a + 2 * r, 24 * a + 4 * r]
    rw [((show 1*(a) + 0*(r) = (a) from NatNorm.sound [a, r] (.add (.mul (.lit 1) (.var 0)) (.mul (.lit 0) (.var 1))) (.var 0) rfl)), ((show (a) + (8*(a) + (r)) = 9*(a) + 1*(r) from NatNorm.sound [a, r] (.add (.var 0) (.add (.mul (.lit 8) (.var 0)) (.var 1))) (.add (.mul (.lit 9) (.var 0)) (.mul (.lit 1) (.var 1))) rfl)), ((show (a) + 2*(8*(a) + (r)) = 17*(a) + 2*(r) from NatNorm.sound [a, r] (.ad  -- (+133 chars; full line in the Zenodo source)
      ((show (a) + 3*(8*(a) + (r)) = 25*(a) + 3*(r) from NatNorm.sound [a, r] (.add (.var 0) (.mul (.lit 3) (.add (.mul (.lit 8) (.var 0)) (.var 1)))) (.add (.mul (.lit 25) (.var 0)) (.mul (.lit 3) (.var 1))) rfl)), ((show 2*(8*(a) + (r)) + 4*(a) = 20*(a) + 2*(r) from NatNorm.sound [a, r] (.add (.mul (.lit 2) (.add (.mul (.lit 8) (.var 0)) (.var 1))) (.mul (.lit 4) (.var 0))) (.add (.mul (.lit 20)  -- (+43 chars; full line in the Zenodo source)
  rw [eq, ← hr, ((show 4*(8*(a) + (r)) = 32*(a) + 4*(r) from NatNorm.sound [a, r] (.mul (.lit 4) (.add (.mul (.lit 8) (.var 0)) (.var 1))) (.add (.mul (.lit 32) (.var 0)) (.mul (.lit 4) (.var 1))) rfl)), hn]
  exact e1

end APPairIrrGen2

#print axioms APPairIrrGen2.sumL_map2
#print axioms APPairIrrGen2.lt_lin2
#print axioms APPairIrrGen2.lin_bal_false2
#print axioms APPairIrrGen2.indec_lin2
#print axioms APPairIrrGen2.fam_indec
#print axioms APPairIrrGen2.fam_indec_q

#print axioms: 6 theorems, no axioms.

81.52 Units are closed under multiplication

Through the fuel recursion of core gcd: \(\gcd (m,n)\) divides both, and Euclid’s lemma. \(\gcd (s,m)=\gcd (t,m)=1\Rightarrow \gcd (st\bmod m,\,m)=1\)

hodge/UnitMul.lean

/-
  hodge/UnitMul.lean — T41 cycle 281 (goal G24): the units of m are closed under multiplication mod m, axiom-free.

  Lean 4 core plus hodge/APPairGen (euclid), hodge/APPair1 (dvd_gcd, dvd_mod), hodge/GcdHand, lib/NatNorm.
    gcd_dvd_go, gcd_dvd   gcd m n divides m and n               (fuel recursion of core gcd)
    one_of_dvd_one        d ∣ 1 ⇒ d = 1
    unit_mul              gcd s m = 1, gcd t m = 1, m > 0 ⇒ gcd ((s t) mod m) m = 1
-/
import hodge.APPairGen

namespace UnitMul
open ModHand HalfGeneral GcdHand APPair APPair1 APPairGen

theorem gcd_dvd_go : ∀ (f : Nat) (x : (_ : Nat) ×' Nat) (hf : GH x < f),
    (∃ i, x.1 = WellFounded.Nat.fix.go GH GF f x hf * i) ∧ (∃ j, x.2 = WellFounded.Nat.fix.go GH GF f x hf * j)
  | 0, _, hf => absurd hf (Nat.not_lt_zero _)
  | f + 1, ⟨m, n⟩, hf => by
    show (∃ i, m = (if h : m = 0 then n else WellFounded.Nat.fix.go GH GF f ⟨n % m, m⟩ _) * i) ∧
      (∃ j, n = (if h : m = 0 then n else WellFounded.Nat.fix.go GH GF f ⟨n % m, m⟩ _) * j)
    by_cases h0 : m = 0
    · rw [dite_eq_left h0, h0]; exact ⟨⟨0, rfl⟩, ⟨1, (Nat.mul_one n).symm⟩⟩
    · rw [dite_eq_right h0]
      have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := gcd_dvd_go f ⟨n % m, m⟩ (Nat.lt_of_lt_of_le (Nat.mod_lt n (Nat.pos_of_ne_zero h0))
        (Nat.le_of_lt_succ (show m < f + 1 from hf)))
      refine ⟨⟨j, hj⟩, ?_⟩
      have ⟨k, hk⟩ := decomp n m (Nat.pos_of_ne_zero h0)
      refine ⟨i + j * k, ?_⟩
      calc n = n % m + m * k := hk
        _ = _ := by
          generalize WellFounded.Nat.fix.go GH GF f ⟨n % m, m⟩ _ = g at hi hj ⊢
          show n % m + m * k = g * (i + j * k)
          rw [((show (n % m) + (m)*(k) = (n % m) + (m)*(k) from NatNorm.sound [n % m, m, k] (.add (.var 0) (.mul (.var 1) (.var 2))) (.add (.var 0) (.mul (.var 1) (.var 2))) rfl))]
          have e1 : n % m = g * i := hi
          have e2 : m = g * j := hj
          rw [e1, e2]; exact ((show (g)*(i) + (g)*(j)*(k) = (g)*((i) + (j)*(k)) from NatNorm.sound [g, i, j, k] (.add (.mul (.var 0) (.var 1)) (.mul (.mul (.var 0) (.var 2)) (.var 3))) (.mul (.var 0) (.add (.var 1) (.mul (.var 2) (.var 3)))) rfl))

theorem gcd_dvd (m n : Nat) : (∃ i, m = Nat.gcd m n * i) ∧ (∃ j, n = Nat.gcd m n * j) := by
  rw [gcd_go]; exact gcd_dvd_go _ ⟨m, n⟩ _

theorem one_of_dvd_one (d k : Nat) (h : 1 = d * k) : d = 1 := by
  cases d with
  | zero => rw [Nat.zero_mul] at h; exact Nat.noConfusion h
  | succ d =>
    cases d with
    | zero => rfl
    | succ d => exact absurd h (fun h' => APPair1.one_eq_mul (d + 2) k h' (Nat.le_add_left 2 d))

/-- **Units are closed under multiplication.** -/
theorem unit_mul (s t m : Nat) (hm : 0 < m) (hs : Nat.gcd s m = 1) (ht : Nat.gcd t m = 1) :
    Nat.gcd ((s * t) % m) m = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := gcd_dvd ((s * t) % m) m
  generalize Nat.gcd ((s * t) % m) m = g at hi hj ⊢
  -- g ∣ s t  (s t = (s t) mod m + m k)
  have ⟨k, hk⟩ := decomp (s * t) m hm
  have h1 : ∃ a, s * t = g * a := by
    refine ⟨i + j * k, ?_⟩
    have e : s * t % m + m * k = g * i + g * j * k := by rw [hi]; rw [hj]
    rw [hk, e]; exact ((show (g)*(i) + (g)*(j)*(k) = (g)*((i) + (j)*(k)) from NatNorm.sound [g, i, j, k] (.add (.mul (.var 0) (.var 1)) (.mul (.mul (.var 0) (.var 2)) (.var 3))) (.mul (.var 0) (.add (.var 1) (.mul (.var 2) (.var 3)))) rfl))
  have h2 : ∃ b, m * t = g * b := ⟨j * t, by rw [hj]; exact ((show (g)*(j)*(t) = (g)*((j)*(t)) from NatNorm.sound [g, j, t] (.mul (.mul (.var 0) (.var 1)) (.var 2)) (.mul (.var 0) (.mul (.var 1) (.var 2))) rfl))⟩
  have ⟨c, hc⟩ := euclid s m g t hs h1 h2
  have ⟨d, hd⟩ := APPair1.dvd_gcd g t m ⟨c, hc⟩ ⟨j, hj⟩
  rw [ht] at hd
  exact one_of_dvd_one g d hd

end UnitMul

#print axioms UnitMul.gcd_dvd
#print axioms UnitMul.one_of_dvd_one
#print axioms UnitMul.unit_mul

#print axioms: 3 theorems, no axioms.

81.53 Balance is invariant under unit twists

For symbolic \(m\): \(T_s(t\cdot c)=T_{st}(c)\) and \(st\) is again a unit, so the whole Galois orbit of a balanced character is balanced. \(\text {bal}\,m\,c,\ \gcd (t,m)=1\Rightarrow \text {bal}\,m\,(t\cdot c)\)

hodge/TwistBal.lean

/-
  hodge/TwistBal.lean — T41 cycle 282 (goal G25): balance is invariant under every unit twist, for symbolic m.

  Lean 4 core plus hodge/UnitMul (unit_mul), hodge/APPairIrrGen (range_succ', filter_append', length_map'),
  hodge/Reach49Defs (all_append), hodge/ModHand, lib/NatNorm.
    all_fr_elim / all_fr_intro   (range m).filter p).all g  ⇔  ∀ x < m, p x ⇒ g x
    mul_mod_right                (a·(b mod m)) mod m = (a b) mod m
    tsum_tw                      T_s(t·c) = T_{(st) mod m}(c)
    bal_twist                    bal m c, gcd t m = 1 ⇒ bal m (t·c)
    fam_orbit                    every unit twist of AP(a) + (2q+4a, 4q−8a) (0 < a, 2a < q) is balanced
-/
import hodge.UnitMul
import hodge.APPairIrrGen

namespace TwistBal
open ModHand HalfGeneral Indecomp GcdHand APPair APPairIrrGen UnitMul

theorem all_fr_elim (p g : Nat → Bool) : ∀ m, ((List.range m).filter p).all g = true →
    ∀ x, x < m → p x = true → g x = true
  | 0, _, x, hx, _ => absurd hx (Nat.not_lt_zero x)
  | m + 1, h, x, hx, hp => by
    rw [range_succ', filter_append', Reach49.all_append] at h
    have h1 : ((List.range m).filter p).all g = true := by
      cases a : ((List.range m).filter p).all g with
      | true => rfl
      | false => rw [a] at h; exact Bool.noConfusion h
    cases Nat.lt_or_ge x m with
    | inl l => exact all_fr_elim p g m h1 x l hp
    | inr ge =>
      have ex : x = m := Nat.le_antisymm (Nat.le_of_lt_succ hx) ge
      rw [h1] at h
      rw [ex] at hp ⊢
      have h2 : ([m].filter p).all g = true := h
      have e : [m].filter p = [m] := by
        show (match p m with | true => [m] | false => []) = [m]; rw [hp]
      rw [e] at h2
      have h3 : (g m && true) = true := h2
      cases b : g m with
      | true => rfl
      | false => rw [b] at h3; exact Bool.noConfusion h3

theorem all_fr_intro (p g : Nat → Bool) : ∀ m, (∀ x, x < m → p x = true → g x = true) →
    ((List.range m).filter p).all g = true
  | 0, _ => rfl
  | m + 1, h => by
    rw [range_succ', filter_append', Reach49.all_append,
      all_fr_intro p g m (fun x hx hp => h x (Nat.lt_trans hx (Nat.lt_succ_self m)) hp)]
    show ([m].filter p).all g = true
    cases a : p m with
    | false =>
      have e : [m].filter p = [] := by show (match p m with | true => [m] | false => []) = []; rw [a]
      rw [e]; rfl
    | true =>
      have e : [m].filter p = [m] := by show (match p m with | true => [m] | false => []) = [m]; rw [a]
      rw [e]; show (g m && true) = true; rw [h m (Nat.lt_succ_self m) a]; rfl

theorem mul_mod_right (a b m : Nat) (hm : 0 < m) : (a * (b % m)) % m = (a * b) % m := by
  have ⟨k, hk⟩ := decomp b m hm
  have e : a * b = a * (b % m) + (a * k) * m := by
    conv => lhs; rw [hk]
    exact ((show (a)*((b % m) + (m)*(k)) = (a)*(b % m) + ((a)*(k))*(m) from NatNorm.sound [a, b % m, m, k] (.mul (.var 0) (.add (.var 1) (.mul (.var 2) (.var 3)))) (.add (.mul (.var 0) (.var 1)) (.mul (.mul (.var 0) (.var 3)) (.var 2))) rfl))
  rw [e, add_mul_mod' _ m hm]

def tw (m t : Nat) (c : List Nat) : List Nat := c.map (fun x => (t * x) % m)

theorem tsum_tw (m s t : Nat) (hm : 0 < m) : ∀ c, tsum m s (tw m t c) = tsum m ((s * t) % m) c
  | [] => rfl
  | x :: c => by
    show (s * ((t * x) % m)) % m + tsum m s (tw m t c) = (((s * t) % m) * x) % m + tsum m ((s * t) % m) c
    rw [tsum_tw m s t hm c, mul_mod_right s (t * x) m hm, Nat.mul_comm ((s * t) % m) x, mul_mod_right x (s * t) m hm,
      ((show (s)*((t)*(x)) = (x)*((s)*(t)) from NatNorm.sound [s, t, x] (.mul (.var 0) (.mul (.var 1) (.var 2))) (.mul (.var 2) (.mul (.var 0) (.var 1))) rfl))]

/-- **Balance is invariant under a unit twist.** -/
theorem bal_twist (m t : Nat) (hm : 0 < m) (ht : Nat.gcd t m = 1) (c : List Nat) (hc : bal m c = true) :
    bal m (tw m t c) = true := by
  unfold bal FermatPrime.units at *
  apply all_fr_intro
  intro s hs hp
  have hu : Nat.gcd ((s * t) % m) m = 1 := unit_mul s t m hm (Nat.eq_of_beq_eq_true hp) ht
  have h := all_fr_elim _ _ m hc ((s * t) % m) (Nat.mod_lt _ hm) (by rw [hu]; rfl)
  show Nat.beq (tsum m s (tw m t c) + tsum m s (tw m t c)) ((tw m t c).length * m) = true
  rw [tsum_tw m s t hm c]
  unfold tw; rw [length_map']
  exact h

/-- **Every unit twist of the first pair family is balanced** (0 < a, 2a < q, 8a + b = 4q). -/
theorem fam_orbit (q a b t : Nat) (ha : 0 < a) (h2a : a + a < q) (hb : 8 * a + b = 4 * q)
    (ht : Nat.gcd t (4 * q) = 1) :
    bal (4 * q) (tw (4 * q) t [a, a + q, a + 2 * q, a + 3 * q, 2 * q + 4 * a, b]) = true :=
  bal_twist (4 * q) t (pos4 q (Nat.lt_of_le_of_lt (Nat.zero_le _) h2a)) ht _
    (APPairGen.ap_pair_bal_gen q a b ha h2a hb)

end TwistBal

#print axioms TwistBal.all_fr_elim
#print axioms TwistBal.all_fr_intro
#print axioms TwistBal.mul_mod_right
#print axioms TwistBal.tsum_tw
#print axioms TwistBal.bal_twist
#print axioms TwistBal.fam_orbit

#print axioms: 6 theorems, no axioms.

81.54 Inverses of units

Bezout along the fuel recursion of core gcd: every entry stays a multiple of \(t\) mod \(m\). \(\gcd (t,m)=1\Rightarrow \exists v,\ vt\equiv 1\pmod m\)

hodge/UnitInv.lean

/-
  hodge/UnitInv.lean — T41 cycle 283 (goal G26): every unit has an inverse mod m (Bezout by hand), axiom-free.

  Lean 4 core plus hodge/TwistBal (mul_mod_right), hodge/APPair (mod_add, decomp), hodge/GcdHand, lib/NatNorm.
  Along core gcd's recursion on ⟨t, m⟩ every entry stays ≡ (multiple of t) mod m: from b = (b mod a) + a k,
  b mod a ≡ (β + k α (m − 1)) t. At the end gcd t m = 1 ≡ γ t.
    cong_add, cong_cancel, bez_go, inverse    gcd t m = 1, m ≥ 2 ⇒ ∃ v, (v t) mod m = 1
-/
import hodge.TwistBal

namespace UnitInv
open ModHand HalfGeneral GcdHand APPair TwistBal

theorem cong_add (x y z m : Nat) (hm : 0 < m) (h : x % m = y % m) : (x + z) % m = (y + z) % m := by
  rw [← mod_add x z m hm, ← mod_add y z m hm, h]

theorem cong_cancel (x y c m' : Nat) (h : (x + c) % (m' + 1) = (y + c) % (m' + 1)) : x % (m' + 1) = y % (m' + 1) := by
  have hm : 0 < m' + 1 := Nat.succ_pos m'
  have h2 := cong_add _ _ (c * m') _ hm h
  rw [((show (x) + (c) + (c)*(m') = (x) + (c)*((m') + 1) from NatNorm.sound [x, c, m'] (.add (.add (.var 0) (.var 1)) (.mul (.var 1) (.var 2))) (.add (.var 0) (.mul (.var 1) (.add (.var 2) (.lit 1)))) rfl)), ((show (y) + (c) + (c)*(m') = (y) + (c)*((m') + 1) from NatNorm.sound [y, c, m'] (.add (.add (.var 0) (.var 1)) (.mul (.var 1) (.var 2))) (.add (.var 0) (.mul (.var 1) (.add (.var 2) (.lit 1))  -- (+9 chars; full line in the Zenodo source)
    show x + c * (m' + 1) = x + c * (m' + 1) from rfl, add_mul_mod' x (m' + 1) hm c, add_mul_mod' y (m' + 1) hm c] at h2
  exact h2

theorem bez_go (t m' : Nat) : ∀ (f : Nat) (x : (_ : Nat) ×' Nat) (hf : GH x < f),
    (∃ α, (α * t) % (m' + 1) = x.1 % (m' + 1)) → (∃ β, (β * t) % (m' + 1) = x.2 % (m' + 1)) →
    ∃ γ, (γ * t) % (m' + 1) = WellFounded.Nat.fix.go GH GF f x hf % (m' + 1)
  | 0, _, hf, _, _ => absurd hf (Nat.not_lt_zero _)
  | f + 1, ⟨a, b⟩, hf, ha, hb => by
    show ∃ γ, (γ * t) % (m' + 1) = (if h : a = 0 then b else WellFounded.Nat.fix.go GH GF f ⟨b % a, a⟩ _) % (m' + 1)
    by_cases h0 : a = 0
    · rw [dite_eq_left h0]; exact hb
    · rw [dite_eq_right h0]
      apply bez_go t m' f ⟨b % a, a⟩ _ _ ha
      have ⟨α, hα⟩ := ha
      have ⟨β, hβ⟩ := hb
      have ⟨k, hk⟩ := decomp b a (Nat.pos_of_ne_zero h0)
      have hm : 0 < m' + 1 := Nat.succ_pos m'
      refine ⟨β + k * α * m', ?_⟩
      apply cong_cancel _ _ (k * a) m'
      -- (γ t + k a) ≡ (γ t + k α t) = β t + (k α t) m ≡ β t ≡ b = b mod a + a k
      have e1 : ((β + k * α * m') * t + k * a) % (m' + 1) = ((β + k * α * m') * t + k * (α * t)) % (m' + 1) := by
        rw [Nat.add_comm ((β + k * α * m') * t) (k * a), Nat.add_comm ((β + k * α * m') * t) (k * (α * t))]
        apply cong_add _ _ _ _ hm
        rw [← mul_mod_right k a _ hm, ← hα, mul_mod_right k _ _ hm]
      have e2 : (β + k * α * m') * t + k * (α * t) = β * t + (k * α * t) * (m' + 1) :=
        ((show ((β) + (k)*(α)*(m'))*(t) + (k)*((α)*(t)) = (β)*(t) + ((k)*(α)*(t))*((m') + 1) from NatNorm.sound [β, k, α, m', t] (.add (.mul (.add (.var 0) (.mul (.mul (.var 1) (.var 2)) (.var 3))) (.var 4)) (.mul (.var 1) (.mul (.var 2) (.var 4)))) (.add (.mul (.var 0) (.var 4)) (.mul (.mul (.mul (.var 1) (.var 2)) (.var 4)) (.add (.var 3) (.lit 1)))) rfl))
      rw [e1, e2, add_mul_mod' _ _ hm, hβ]
      show (b % (m' + 1)) = (b % a + k * a) % (m' + 1)
      rw [((show (b % a) + (k)*(a) = (b % a) + (a)*(k) from NatNorm.sound [b % a, k, a] (.add (.var 0) (.mul (.var 1) (.var 2))) (.add (.var 0) (.mul (.var 2) (.var 1))) rfl)), ← hk]

theorem mod_self' (m : Nat) (hm : 0 < m) : m % m = 0 := by
  have := add_mul_mod' 0 m hm 1
  rw [Nat.zero_add, Nat.one_mul, mod_lt' 0 m hm] at this
  exact this

/-- **Inverses mod m.** -/
theorem inverse (t m' : Nat) (hg : Nat.gcd t (m' + 1 + 1) = 1) : ∃ v, (v * t) % (m' + 1 + 1) = 1 := by
  have ⟨γ, hγ⟩ := bez_go t (m' + 1) _ ⟨t, m' + 1 + 1⟩ (eager_gt t) ⟨1, by rw [Nat.one_mul]⟩
    ⟨0, by
      have hm : 0 < m' + 1 + 1 := Nat.succ_pos _
      rw [Nat.zero_mul, mod_lt' 0 _ hm]
      show 0 = (m' + 1 + 1) % (m' + 1 + 1)
      rw [mod_self' _ hm]⟩
  rw [← gcd_go, hg] at hγ
  exact ⟨γ, by rw [hγ]; exact mod_lt' 1 _ (Nat.succ_lt_succ (Nat.succ_pos m'))⟩

end UnitInv

#print axioms UnitInv.cong_add
#print axioms UnitInv.cong_cancel
#print axioms UnitInv.bez_go
#print axioms UnitInv.inverse

#print axioms: 4 theorems, no axioms.

81.55 Irreducibility is invariant under unit twists

A balanced splitting of \(t\cdot c\) untwists by \(v=t^{-1}\) to one of \(c\); the whole orbit of the first pair family is irreducible. \(\text {indec}\,m\,c,\ \gcd (t,m)=1\Rightarrow \text {indec}\,m\,(t\cdot c)\)

hodge/TwistIndec.lean

/-
  hodge/TwistIndec.lean — T41 cycle 284 (goal G27): irreducibility is invariant under every unit twist, symbolic m.

  Lean 4 core plus hodge/UnitInv (inverse), hodge/UnitMul (gcd_dvd, one_of_dvd_one), hodge/TwistBal (bal_twist, tw),
  hodge/APPairIrrGen (splitsG, splits_eq, splits_map), hodge/APPair1 (dvd_mod).
    inv_unit       v t ≡ 1 (m) ⇒ gcd v m = 1
    untwist        entries < m, v t ≡ 1 ⇒ v·(t·A) = A
    splits_all     a property of all entries passes to both halves of every splitting
    indec_twist    indec m c, entries < m, gcd t m = 1, m ≥ 2 ⇒ indec m (t·c)
    fam_orbit_indec   every unit twist of AP(a) + (2q+4a, 4q−8a) (a ≥ 1, q ≥ 8a) is irreducible
-/
import hodge.UnitInv
import hodge.APPairIrrGen2

namespace TwistIndec
open ModHand HalfGeneral Indecomp GcdHand APPair APPairIrrGen UnitMul TwistBal UnitInv

theorem inv_unit (v t m : Nat) (hm : 0 < m) (h : (v * t) % m = 1) : Nat.gcd v m = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := gcd_dvd v m
  generalize Nat.gcd v m = g at hi hj ⊢
  have ⟨c, hc⟩ := APPair1.dvd_mod g (v * t) m hm ⟨i * t, by rw [hi]; exact ((show (g)*(i)*(t) = (g)*((i)*(t)) from NatNorm.sound [g, i, t] (.mul (.mul (.var 0) (.var 1)) (.var 2)) (.mul (.var 0) (.mul (.var 1) (.var 2))) rfl))⟩ ⟨j, hj⟩
  rw [h] at hc
  exact one_of_dvd_one g c hc

theorem untwist (m t v : Nat) (hm : 0 < m) (h : (v * t) % m = 1) : ∀ A : List Nat,
    A.all (fun x => Nat.blt x m) = true → tw m v (tw m t A) = A
  | [], _ => rfl
  | x :: A, hA => by
    have hA' : (Nat.blt x m && A.all (fun x => Nat.blt x m)) = true := hA
    cases a : Nat.blt x m with
    | false => rw [a] at hA'; exact Bool.noConfusion hA'
    | true =>
      rw [a] at hA'
      show (v * ((t * x) % m)) % m :: tw m v (tw m t A) = x :: A
      rw [untwist m t v hm h A hA', mul_mod_right v (t * x) m hm, ((show (v)*((t)*(x)) = (x)*((v)*(t)) from NatNorm.sound [v, t, x] (.mul (.var 0) (.mul (.var 1) (.var 2))) (.mul (.var 2) (.mul (.var 0) (.var 1))) rfl)),
        ← mul_mod_right x (v * t) m hm, h, Nat.mul_one, mod_lt' x m (Nat.le_of_ble_eq_true a)]

theorem splits_all {α : Type} (q : α → Bool) : ∀ l : List α, l.all q = true →
    (splitsG l).all (fun p => p.1.all q && p.2.all q) = true := by
  intro l; induction l with
  | nil => intro _; rfl
  | cons x l ih =>
    intro h
    have h' : (q x && l.all q) = true := h
    cases a : q x with
    | false => rw [a] at h'; exact Bool.noConfusion h'
    | true =>
      rw [a] at h'
      have ih' := ih h'
      show ((splitsG l).flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])).all _ = true
      generalize splitsG l = L at ih'
      induction L with
      | nil => rfl
      | cons p L ihL =>
        have r : ((p.1.all q && p.2.all q) && L.all _) = true := ih'
        cases b1 : p.1.all q <;> cases b2 : p.2.all q <;> rw [b1, b2] at r
        · exact Bool.noConfusion r
        · exact Bool.noConfusion r
        · exact Bool.noConfusion r
        · show (((q x && p.1.all q) && p.2.all q) && ((p.1.all q && (q x && p.2.all q)) &&
              (List.flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)]) L).all (fun p => p.1.all q && p.2.all q))) = true
          rw [a, b1, b2, ihL r]; rfl

/-- **Irreducibility is invariant under a unit twist.** -/
theorem indec_twist (m' t : Nat) (ht : Nat.gcd t (m' + 1 + 1) = 1) (c : List Nat)
    (hlt : c.all (fun x => Nat.blt x (m' + 1 + 1)) = true) (hc : indec (m' + 1 + 1) c = true) :
    indec (m' + 1 + 1) (tw (m' + 1 + 1) t c) = true := by
  have hm : 0 < m' + 1 + 1 := Nat.succ_pos _
  have ⟨v, hv⟩ := inverse t m' ht
  have hvu := inv_unit v t _ hm hv
  unfold indec at hc ⊢
  unfold tw
  rw [splits_eq, splits_map]
  rw [splits_eq] at hc
  rw [Reach49.all_map]
  apply all_imp _ _ _ _ (all_and _ _ _ (splits_all _ c hlt) hc)
  intro p hp
  have hp' : ((p.1.all (fun x => Nat.blt x (m' + 1 + 1)) && p.2.all (fun x => Nat.blt x (m' + 1 + 1))) &&
      (p.1.isEmpty || p.2.isEmpty || !(bal (m' + 1 + 1) p.1 && bal (m' + 1 + 1) p.2))) = true := hp
  cases s1 : p.1.all (fun x => Nat.blt x (m' + 1 + 1)) <;> cases s2 : p.2.all (fun x => Nat.blt x (m' + 1 + 1)) <;>
    rw [s1, s2] at hp'
  · exact Bool.noConfusion hp'
  · exact Bool.noConfusion hp'
  · exact Bool.noConfusion hp'
  · have em : ∀ l : List Nat, (l.map (fun x => (t * x) % (m' + 1 + 1))).isEmpty = l.isEmpty := fun l => by cases l <;> rfl
    show ((p.1.map _).isEmpty || (p.2.map _).isEmpty ||
      !(bal (m' + 1 + 1) (p.1.map (fun x => (t * x) % (m' + 1 + 1))) &&
        bal (m' + 1 + 1) (p.2.map (fun x => (t * x) % (m' + 1 + 1))))) = true
    rw [em, em]
    have back : ∀ A : List Nat, A.all (fun x => Nat.blt x (m' + 1 + 1)) = true →
        bal (m' + 1 + 1) (A.map (fun x => (t * x) % (m' + 1 + 1))) = true → bal (m' + 1 + 1) A = true := by
      intro A hA hb
      have := bal_twist _ v hm hvu _ hb
      rw [show A.map (fun x => (t * x) % (m' + 1 + 1)) = tw (m' + 1 + 1) t A from rfl, untwist _ t v hm hv A hA] at this
      exact this
    cases e1 : p.1.isEmpty <;> cases e2 : p.2.isEmpty <;> rw [e1, e2] at hp' <;> try rfl
    cases b1 : bal (m' + 1 + 1) p.1 <;> cases b2 : bal (m' + 1 + 1) p.2 <;> rw [b1, b2] at hp'
    · cases c1 : bal (m' + 1 + 1) (p.1.map (fun x => (t * x) % (m' + 1 + 1)))
      · rfl
      · rw [back p.1 s1 c1] at b1; exact Bool.noConfusion b1
    · cases c1 : bal (m' + 1 + 1) (p.1.map (fun x => (t * x) % (m' + 1 + 1)))
      · rfl
      · rw [back p.1 s1 c1] at b1; exact Bool.noConfusion b1
    · cases c2 : bal (m' + 1 + 1) (p.2.map (fun x => (t * x) % (m' + 1 + 1)))
      · cases bal (m' + 1 + 1) (p.1.map (fun x => (t * x) % (m' + 1 + 1))) <;> rfl
      · rw [back p.2 s2 c2] at b2; exact Bool.noConfusion b2
    · exact Bool.noConfusion hp'

/-- **Every unit twist of the first pair family is irreducible** (a ≥ 1, q = 8a + r, m = 32a + 4r). -/
theorem fam_orbit_indec (k r t : Nat) (ht : Nat.gcd t (32 * k + 30 + 4 * r + 1 + 1) = 1) :
    indec (32 * k + 30 + 4 * r + 1 + 1)
      (tw (32 * k + 30 + 4 * r + 1 + 1) t (co1.map (APPairIrrGen2.ev2 (k + 1) r))) = true := by
  have hm : 32 * (k + 1) + 4 * r = (32 * k + 30 + 4 * r) + 2 := ((show 32*((k) + 1) + 4*(r) = 32*(k) + 30 + 4*(r) + 2 from NatNorm.sound [k, r] (.add (.mul (.lit 32) (.add (.var 0) (.lit 1))) (.mul (.lit 4) (.var 1))) (.add (.add (.add (.mul (.lit 32) (.var 0)) (.lit 30)) (.mul (.lit 4) (.var 1))) (.lit 2)) rfl))
  apply indec_twist _ t ht
  · have := APPairIrrGen2.small_lt2 32 4 (k + 1) r (Nat.succ_pos k) co1 co1_small
    rw [hm] at this; exact this
  · exact APPairIrrGen2.fam_indec (k + 1) r (Nat.succ_pos k) _ hm

end TwistIndec

#print axioms TwistIndec.inv_unit
#print axioms TwistIndec.untwist
#print axioms TwistIndec.splits_all
#print axioms TwistIndec.indec_twist
#print axioms TwistIndec.fam_orbit_indec

#print axioms: 5 theorems, no axioms.

81.56 The duplication triple; the second family always splits

\(\{u,u+m/2,m-2u\}\) is balanced for every even \(m\) and \(0<u<m/2\); the second pair family is the sum of two such triples. \(\neg \,\text {indec}\,(4q)\,[1,1+q,1+2q,1+3q,2q-2,4q-2]\quad (q\ge 2)\)

hodge/DupTriple.lean

/-
  hodge/DupTriple.lean — T41 cycle 285 (goal G28): the duplication triple {u, u + m/2, m − 2u} is balanced for every
  even m = 2h and 0 < u < h, and the second pair family AP(m/4) + (m/2 − 2, m − 2) always splits into two such
  triples — it is never irreducible (symbolic in q ≥ 2).

  Lean 4 core plus hodge/TwistIndec (splits_eq), hodge/APPairGen (euclid, not_dvd_small), hodge/APPair (mod_rep,
  comp, decomp), hodge/HalfGeneral (half_mul), hodge/GcdHand (units_odd), lib/NatNorm.
    tsum_dup      for odd t with h ∤ tu: ⟨tu⟩ + ⟨t(u+h)⟩ + ⟨tw⟩ = 3h   (2u + w = 2h)
    dup_bal       bal (2h) [u, u+h, w]
    fam2_split    the splitting ([1, 1+2q, 4q−2], [1+q, 1+3q, 2q−2]) is balanced on both sides
    fam2_red      indec (4q) [1, 1+q, 1+2q, 1+3q, 2q−2, 4q−2] = false   (q ≥ 2)
-/
import hodge.TwistIndec

namespace DupTriple
open ModHand HalfGeneral Indecomp GcdHand APPair APPairIrrGen APPairGen TwistBal

theorem tsum_dup (h u w t : Nat) (hh : 0 < h) (hw : u + u + w = h + h) (ht : isOdd t = true)
    (hnd : (t * u) % h ≠ 0) :
    (t * u) % (h + h) + ((t * (u + h)) % (h + h) + (t * w) % (h + h)) = h + h + h := by
  have hm : 0 < h + h := Nat.lt_of_lt_of_le hh (Nat.le_add_right h h)
  have x_lt := Nat.mod_lt (t * u) hm
  -- ⟨t(u+h)⟩ = ⟨x + h⟩
  have e1 : (t * (u + h)) % (h + h) = ((t * u) % (h + h) + h) % (h + h) := by
    rw [Nat.left_distrib, ← mod_add (t * u) (t * h) _ hm, half_mul h t hh ht]
  -- ⟨tw⟩ + ⟨2x⟩ = m
  have ⟨k, hk⟩ := decomp (t * u) (h + h) hm
  generalize hx : (t * u) % (h + h) = x at e1 x_lt hk
  have hx0 : 0 < x := by
    cases x with
    | succ x => exact Nat.succ_pos x
    | zero =>
      apply absurd _ hnd
      rw [hk, Nat.zero_add, ((show ((h) + (h))*(k) = 0 + (2*(k))*(h) from NatNorm.sound [h, k] (.mul (.add (.var 0) (.var 0)) (.var 1)) (.add (.lit 0) (.mul (.mul (.lit 2) (.var 1)) (.var 0))) rfl)), add_mul_mod' 0 h hh, mod_lt' 0 h hh]
  have hxh : x ≠ h := by
    intro e
    apply hnd
    rw [hk, e, ((show (h) + ((h) + (h))*(k) = 0 + (1 + 2*(k))*(h) from NatNorm.sound [h, k] (.add (.var 0) (.mul (.add (.var 0) (.var 0)) (.var 1))) (.add (.lit 0) (.mul (.add (.lit 1) (.mul (.lit 2) (.var 1))) (.var 0))) rfl)), add_mul_mod' 0 h hh, mod_lt' 0 h hh]
  have hc2 : (t * (u + u)) % (h + h) = (x + x) % (h + h) := by
    rw [((show (t)*((u) + (u)) = (t)*(u) + (t)*(u) from NatNorm.sound [t, u] (.mul (.var 0) (.add (.var 1) (.var 1))) (.add (.mul (.var 0) (.var 1)) (.mul (.var 0) (.var 1))) rfl)), ← mod_add _ _ _ hm, hx]
  have hcomp : ∀ r, (t * (u + u)) % (h + h) = r → 0 < r → r < h + h → (t * w) % (h + h) + r = h + h := by
    intro r hr r0 rl
    apply comp (t * w) (t * (u + u)) (h + h) r hm hr r0 rl
    rw [((show (t)*(w) + (t)*((u) + (u)) = (t)*((u) + (u) + (w)) from NatNorm.sound [t, w, u] (.add (.mul (.var 0) (.var 1)) (.mul (.var 0) (.add (.var 2) (.var 2)))) (.mul (.var 0) (.add (.add (.var 2) (.var 2)) (.var 1))) rfl)), hw]
    exact mod_rep _ 0 _ t hm ((show (t)*((h) + (h)) = 0 + (t)*((h) + (h)) from NatNorm.sound [t, h] (.mul (.var 0) (.add (.var 1) (.var 1))) (.add (.lit 0) (.mul (.var 0) (.add (.var 1) (.var 1)))) rfl))
  cases Nat.lt_or_ge x h with
  | inl l =>
    have r1 : (x + h) % (h + h) = x + h := mod_lt' _ _ (Nat.add_lt_add_right l h)
    have r2 : (x + x) % (h + h) = x + x := mod_lt' _ _ (add_lt_add' _ _ _ _ l l)
    rw [hc2, r2] at hcomp
    have hc := hcomp (x + x) rfl (Nat.lt_of_lt_of_le hx0 (Nat.le_add_right x x)) (add_lt_add' _ _ _ _ l l)
    rw [e1, r1]
    apply add_right_cancel' _ _ (x + x)
    rw [((show (x) + ((x) + (h) + ((t * w) % (h + h))) + ((x) + (x)) = (x) + (x) + (h) + (((t * w) % (h + h)) + ((x) + (x))) from NatNorm.sound [x, h, (t * w) % (h + h)] (.add (.add (.var 0) (.add (.add (.var 0) (.var 1)) (.var 2))) (.add (.var 0) (.var 0))) (.add (.add (.add (.var 0) (.var 0)) (.var 1)) (.add (.var 2) (.add (.var 0) (.var 0)))) rfl)), hc]
    exact ((show (x) + (x) + (h) + ((h) + (h)) = (h) + (h) + (h) + ((x) + (x)) from NatNorm.sound [x, h] (.add (.add (.add (.var 0) (.var 0)) (.var 1)) (.add (.var 1) (.var 1))) (.add (.add (.add (.var 1) (.var 1)) (.var 1)) (.add (.var 0) (.var 0))) rfl))
  | inr g =>
    have ⟨y, hy⟩ := Nat.le.dest g
    have hyh : y < h := Nat.lt_of_add_lt_add_left (hy ▸ x_lt)
    have hy0 : 0 < y := by
      cases y with
      | succ y => exact Nat.succ_pos y
      | zero => exact absurd (by rw [← hy]; rfl) hxh
    have r1 : (x + h) % (h + h) = y := by
      rw [← hy]; apply mod_rep _ _ _ 1 (Nat.lt_of_lt_of_le hyh (Nat.le_add_right h h)); exact ((show (h) + (y) + (h) = (y) + 1*((h) + (h)) from NatNorm.sound [h, y] (.add (.add (.var 0) (.var 1)) (.var 0)) (.add (.var 1) (.mul (.lit 1) (.add (.var 0) (.var 0)))) rfl))
    have r2 : (x + x) % (h + h) = y + y := by
      rw [← hy]; apply mod_rep _ _ _ 1 (add_lt_add' _ _ _ _ hyh hyh); exact ((show (h) + (y) + ((h) + (y)) = (y) + (y) + 1*((h) + (h)) from NatNorm.sound [h, y] (.add (.add (.var 0) (.var 1)) (.add (.var 0) (.var 1))) (.add (.add (.var 1) (.var 1)) (.mul (.lit 1) (.add (.var 0) (.var 0)))) rfl))
    rw [hc2, r2] at hcomp
    have hc := hcomp (y + y) rfl (Nat.lt_of_lt_of_le hy0 (Nat.le_add_right y y)) (add_lt_add' _ _ _ _ hyh hyh)
    rw [e1, r1, ← hy]
    apply add_right_cancel' _ _ (y + y)
    rw [((show (h) + (y) + ((y) + ((t * w) % (h + h))) + ((y) + (y)) = (h) + (y) + (y) + (((t * w) % (h + h)) + ((y) + (y))) from NatNorm.sound [h, y, (t * w) % (h + h)] (.add (.add (.add (.var 0) (.var 1)) (.add (.var 1) (.var 2))) (.add (.var 1) (.var 1))) (.add (.add (.add (.var 0) (.var 1)) (.var 1)) (.add (.var 2) (.add (.var 1) (.var 1)))) rfl)), hc]
    exact ((show (h) + (y) + (y) + ((h) + (h)) = (h) + (h) + (h) + ((y) + (y)) from NatNorm.sound [h, y] (.add (.add (.add (.var 0) (.var 1)) (.var 1)) (.add (.var 0) (.var 0))) (.add (.add (.add (.var 0) (.var 0)) (.var 0)) (.add (.var 1) (.var 1))) rfl))

/-- **The duplication triple is balanced.** -/
theorem dup_bal (h u w : Nat) (hu : 0 < u) (huh : u < h) (hw : u + u + w = h + h) :
    bal (h + h) [u, u + h, w] = true := by
  have hh : 0 < h := Nat.lt_of_le_of_lt (Nat.zero_le u) huh
  have hm : 0 < h + h := Nat.lt_of_lt_of_le hh (Nat.le_add_right h h)
  unfold bal FermatPrime.units
  apply all_fr_intro
  intro t _ hp
  have hg := Nat.eq_of_beq_eq_true hp
  have ht : isOdd t = true := unit_isOdd h t hg
  have hnd : (t * u) % h ≠ 0 := by
    intro z
    have ⟨N, hN⟩ := decomp (t * u) h hh
    rw [z, Nat.zero_add] at hN
    have ⟨k, hk⟩ := euclid t (h + h) h u hg ⟨N, hN⟩ ⟨2 * u, ((show ((h) + (h))*(u) = (h)*(2*(u)) from NatNorm.sound [h, u] (.mul (.add (.var 0) (.var 0)) (.var 1)) (.mul (.var 0) (.mul (.lit 2) (.var 1))) rfl))⟩
    exact not_dvd_small h u k hu huh hk
  show Nat.beq ((t * u) % (h + h) + ((t * (u + h)) % (h + h) + ((t * w) % (h + h) + 0))
    + ((t * u) % (h + h) + ((t * (u + h)) % (h + h) + ((t * w) % (h + h) + 0)))) (3 * (h + h)) = true
  rw [Nat.add_zero, tsum_dup h u w t hh hw ht hnd, ((show (h) + (h) + (h) + ((h) + (h) + (h)) = 3*((h) + (h)) from NatNorm.sound [h] (.add (.add (.add (.var 0) (.var 0)) (.var 0)) (.add (.add (.var 0) (.var 0)) (.var 0))) (.mul (.lit 3) (.add (.var 0) (.var 0))) rfl))]
  exact beq_self _

theorem all_mem {α : Type} (P : α → Bool) {a : α} : ∀ {l : List α}, a ∈ l → l.all P = true → P a = true
  | _ :: _, List.Mem.head _, h => by
    have h' : (P a && _) = true := h
    cases e : P a with
    | true => rfl
    | false => rw [e] at h'; exact Bool.noConfusion h'
  | b :: l, List.Mem.tail _ m, h => by
    have h' : (P b && l.all P) = true := h
    cases e : l.all P with
    | true => exact all_mem P m e
    | false => rw [e] at h'; cases e2 : P b <;> rw [e2] at h' <;> exact Bool.noConfusion h'

/-- **The second pair family always splits.** (q ≥ 2, c + 2 = 2q, d + 2 = 4q) -/
theorem fam2_red (q c d : Nat) (hq : 2 ≤ q) (hc : c + 2 = 2 * q) (hd : d + 2 = 4 * q) :
    indec (4 * q) [1, 1 + q, 1 + 2 * q, 1 + 3 * q, c, d] = false := by
  have ⟨r, hr⟩ := Nat.le.dest hq
  -- first triple: u = 1, h = 2q
  have b1 : bal (2 * q + 2 * q) [1, 1 + 2 * q, d] = true := by
    apply dup_bal _ 1 d (Nat.succ_pos 0)
    · rw [← hr]; exact Nat.lt_of_lt_of_le (Nat.succ_lt_succ (Nat.succ_pos 0)) (by rw [((show 2*(2 + (r)) = 2 + (2 + 2*(r)) from NatNorm.sound [r] (.mul (.lit 2) (.add (.lit 2) (.var 0))) (.add (.lit 2) (.add (.lit 2) (.mul (.lit 2) (.var 0)))) rfl))]; exact Nat.le_add_right 2 _)
    · rw [((show 1 + 1 + (d) = (d) + 2 from NatNorm.sound [d] (.add (.add (.lit 1) (.lit 1)) (.var 0)) (.add (.var 0) (.lit 2)) rfl)), hd]; exact ((show 4*(q) = 2*(q) + 2*(q) from NatNorm.sound [q] (.mul (.lit 4) (.var 0)) (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) rfl))
  have b2 : bal (2 * q + 2 * q) [1 + q, 1 + q + 2 * q, c] = true := by
    apply dup_bal _ (1 + q) c (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 q))
    · rw [← hr, ((show 2*(2 + (r)) = 1 + (2 + (r)) + (1 + (r)) from NatNorm.sound [r] (.mul (.lit 2) (.add (.lit 2) (.var 0))) (.add (.add (.lit 1) (.add (.lit 2) (.var 0))) (.add (.lit 1) (.var 0))) rfl))]; exact Nat.lt_add_of_pos_right (by rw [Nat.add_comm]; exact Nat.succ_pos r)
    · rw [((show 1 + (q) + (1 + (q)) + (c) = (c) + 2 + 2*(q) from NatNorm.sound [q, c] (.add (.add (.add (.lit 1) (.var 0)) (.add (.lit 1) (.var 0))) (.var 1)) (.add (.add (.var 1) (.lit 2)) (.mul (.lit 2) (.var 0))) rfl)), hc]
  rw [((show 2*(q) + 2*(q) = 4*(q) from NatNorm.sound [q] (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) (.mul (.lit 4) (.var 0)) rfl)), ((show 1 + (q) + 2*(q) = 1 + 3*(q) from NatNorm.sound [q] (.add (.add (.lit 1) (.var 0)) (.mul (.lit 2) (.var 0))) (.add (.lit 1) (.mul (.lit 3) (.var 0))) rfl))] at b2
  rw [((show 2*(q) + 2*(q) = 4*(q) from NatNorm.sound [q] (.add (.mul (.lit 2) (.var 0)) (.mul (.lit 2) (.var 0))) (.mul (.lit 4) (.var 0)) rfl))] at b1
  cases hi : indec (4 * q) [1, 1 + q, 1 + 2 * q, 1 + 3 * q, c, d] with
  | false => rfl
  | true =>
    unfold indec at hi
    rw [splits_eq] at hi
    have mem : ([1, 1 + 2 * q, d], [1 + q, 1 + 3 * q, c]) ∈ splitsG [1, 1 + q, 1 + 2 * q, 1 + 3 * q, c, d] :=
      List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (Lis  -- (+89 chars; full line in the Zenodo source)
    have := all_mem _ mem hi
    have this' : (([1, 1 + 2 * q, d] : List Nat).isEmpty || ([1 + q, 1 + 3 * q, c] : List Nat).isEmpty ||
      !(bal (4 * q) [1, 1 + 2 * q, d] && bal (4 * q) [1 + q, 1 + 3 * q, c])) = true := this
    rw [b1, b2] at this'
    exact Bool.noConfusion this'

end DupTriple

#print axioms DupTriple.tsum_dup
#print axioms DupTriple.dup_bal
#print axioms DupTriple.all_mem
#print axioms DupTriple.fam2_red

#print axioms: 4 theorems, no axioms.

81.57 AP\(_d\) plus a duplication pair, every \(d\mid m\)

The progression of step \(m/d\) acts as \(\langle t\,da\rangle +(d-1)m/2\); with the pair \((da+m/2,\,m-2da)\) it completes a duplication triple. \(\text {bal}\,m\,[a,a+q,\dots ,a+(d-1)q,\ da+m/2,\ m-2da]\quad (m=dq\ \text {even},\ 0<da<m/2)\)

hodge/APDouble.lean

/-
  hodge/APDouble.lean — T41 cycle 286 (goal G29): for every d ∣ m (m = 2h even), every a with 0 < da < h, the
  character AP_d(a) + (da + m/2, m − 2da) = [a, a + q, …, a + (d−1)q, da + h, w]  (q = m/d, 2da + w = m)
  is balanced. d = 4 is the first pair family (APPair); d = 2 gives length 4 (surfaces, where Lefschetz (1,1) applies).

  Lean 4 core plus hodge/StdGeneral (t_sum, tsum_j, two_sum: Σ_k ⟨t(a + kq)⟩ = Σ_j (r + jq)), hodge/DupTriple
  (tsum_dup), hodge/UnitInv (inverse), hodge/UnitMul (gcd_dvd), hodge/APPair1 (dvd_gcd), hodge/TwistBal
  (all_fr_intro), ESChain (rem_eq_mod), lib/Semi (lib_nat). Per unit t: the AP contributes ⟨t·da⟩ + (d−1)m/2,
  the pair ⟨t(da + h)⟩ + ⟨tw⟩ = 3h − ⟨t·da⟩; total (d + 2)·m/2.
    apL, tsum_append, tsum_apL      the AP as a list, and its t-sum as sumTo
    unit_d                          a unit of m = dq is a unit of d
    ap_double_bal                   the theorem
-/
import hodge.DupTriple
import hodge.StdGeneral

namespace APDouble
open FTAChain FrobChain QRChain ESChain StdGeneral
open ModHand HalfGeneral Indecomp GcdHand APPair APPairIrrGen APPairGen TwistBal UnitMul UnitInv DupTriple

def apL (d a q : Nat) : List Nat := (List.range d).map (fun k => a + k * q)

theorem tsum_append (m t : Nat) : ∀ A B : List Nat, tsum m t (A ++ B) = tsum m t A + tsum m t B
  | [], B => (Nat.zero_add _).symm
  | x :: A, B => by
    show (t * x) % m + tsum m t (A ++ B) = ((t * x) % m + tsum m t A) + tsum m t B
    rw [tsum_append m t A B, Nat.add_assoc]

theorem map_append' {α β : Type} (f : α → β) : ∀ A B : List α, (A ++ B).map f = A.map f ++ B.map f
  | [], _ => rfl
  | x :: A, B => by show f x :: (A ++ B).map f = f x :: (A.map f ++ B.map f); rw [map_append' f A B]

theorem tsum_apL (m t a q : Nat) : ∀ n, tsum m t (apL n a q) = sumTo n (fun k => (t * (a + k * q)) % m)
  | 0 => rfl
  | n + 1 => by
    unfold apL
    rw [range_succ', map_append', tsum_append]
    show tsum m t (apL n a q) + ((t * (a + n * q)) % m + 0) = _
    rw [tsum_apL m t a q n]; rfl

theorem sumTo_congr (f g : Nat → Nat) (h : ∀ k, f k = g k) : ∀ n, sumTo n f = sumTo n g
  | 0 => rfl
  | n + 1 => by show sumTo n f + f n = sumTo n g + g n; rw [sumTo_congr f g h n, h n]

theorem len_apL (d a q : Nat) : (apL d a q).length = d := by
  unfold apL; rw [length_map']
  induction d with
  | zero => rfl
  | succ d ih => rw [range_succ']; exact (show (List.range d ++ [d]).length = d + 1 from by
      have e : ∀ L : List Nat, (L ++ [d]).length = L.length + 1 := by
        intro L; induction L with
        | nil => rfl
        | cons x L ihL => show (L ++ [d]).length + 1 = L.length + 1 + 1; rw [ihL]
      rw [e, ih])

/-- A unit of m = d q is a unit of d. -/
theorem unit_d (t d q : Nat) (hg : Nat.gcd t (d * q) = 1) : Nat.gcd t d = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := gcd_dvd t d
  generalize Nat.gcd t d = g at hi hj ⊢
  have ⟨c, hc⟩ := APPair1.dvd_gcd g t (d * q) ⟨i, hi⟩ ⟨j * q, by rw [hj]; lib_nat⟩
  rw [hg] at hc
  exact one_of_dvd_one g c hc

/-- **AP_d(a) + (da + m/2, m − 2da) is balanced.** (d = d″ + 2, q = q′ + 1, m = dq = 2h, 0 < da < h, 2da + w = 2h) -/
theorem ap_double_bal (d'' q' h a w : Nat) (hm : (d'' + 1 + 1) * (q' + 1) = h + h)
    (ha : 0 < (d'' + 1 + 1) * a) (hah : (d'' + 1 + 1) * a < h)
    (hw : (d'' + 1 + 1) * a + (d'' + 1 + 1) * a + w = h + h) :
    bal (h + h) (apL (d'' + 1 + 1) a (q' + 1) ++ [(d'' + 1 + 1) * a + h, w]) = true := by
  have hh : 0 < h := Nat.lt_of_le_of_lt (Nat.zero_le _) hah
  have hM0 : 0 < h + h := Nat.lt_of_lt_of_le hh (Nat.le_add_right h h)
  have hMM : (d'' + 1 + 1) * (q' + 1) = ((d'' + 1) * (q' + 1) + q') + 1 := by lib_nat
  unfold bal FermatPrime.units
  apply all_fr_intro
  intro t _ hp
  have hg := Nat.eq_of_beq_eq_true hp
  have ht : isOdd t = true := unit_isOdd h t hg
  -- inverse of t mod d
  have hgd : Nat.gcd t (d'' + 1 + 1) = 1 := unit_d t _ (q' + 1) (by rw [hm]; exact hg)
  have ⟨v, hv⟩ := inverse t d'' hgd
  have ht' : rem ((d'' + 1) + 1) (v * t) = 1 := by rw [rem_eq_mod]; exact hv
  -- x0 = ⟨ta⟩_m = r + s q
  have ⟨s, hs⟩ := decomp ((t * a) % (h + h)) (q' + 1) (Nat.succ_pos q')
  generalize hr : ((t * a) % (h + h)) % (q' + 1) = r at hs
  have hrq : r < q' + 1 := hr ▸ Nat.mod_lt _ (Nat.succ_pos q')
  have hx : rem ((d'' + 1 + 1) * (q' + 1)) (t * a) = r + s * (q' + 1) := by
    rw [hMM, rem_eq_mod, ← hMM, hm, hs, Nat.mul_comm (q' + 1) s]
  have ts := t_sum (d'' + 1) q' t v a r s (Nat.succ_pos d'') ht' hx hrq
  rw [tsum_j] at ts
  -- the AP part as tsum
  have hap : tsum (h + h) t (apL (d'' + 1 + 1) a (q' + 1))
      = (d'' + 1 + 1) * r + (q' + 1) * sumTo (d'' + 1 + 1) (fun j => j) := by
    rw [tsum_apL, ← ts, ← hm]
    apply sumTo_congr
    intro k
    rw [hMM, rem_eq_mod]
  -- ⟨t·da⟩ = d r
  have hdr : (t * ((d'' + 1 + 1) * a)) % (h + h) = (d'' + 1 + 1) * r := by
    have ⟨k, hk⟩ := decomp (t * a) (h + h) hM0
    have ⟨e, he⟩ := Nat.le.dest hrq
    apply mod_rep _ _ _ (s + (d'' + 1 + 1) * k)
    · rw [← hm, ← he]
      show (d'' + 1 + 1) * r < (d'' + 1 + 1) * (r + 1 + e)
      rw [show (d'' + 1 + 1) * (r + 1 + e) = (d'' + 1 + 1) * r + (d'' + 1 + 1 + (d'' + 1 + 1) * e) by lib_nat]
      exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos _) (Nat.le_add_right _ _))
    · rw [show t * ((d'' + 1 + 1) * a) = (d'' + 1 + 1) * (t * a) by lib_nat, hk, hs, ← hm]
      lib_nat
  -- the pair: ⟨t·da⟩ + ⟨t(da + h)⟩ + ⟨tw⟩ = 3h
  have hnd : (t * ((d'' + 1 + 1) * a)) % h ≠ 0 := by
    intro z
    have ⟨N, hN⟩ := decomp (t * ((d'' + 1 + 1) * a)) h hh
    rw [z, Nat.zero_add] at hN
    have ⟨k, hk⟩ := euclid t (h + h) h ((d'' + 1 + 1) * a) hg ⟨N, hN⟩ ⟨2 * ((d'' + 1 + 1) * a), by lib_nat⟩
    exact not_dvd_small h _ k ha hah hk
  have hdup := tsum_dup h ((d'' + 1 + 1) * a) w t hh hw ht hnd
  rw [hdr] at hdup
  -- assemble
  show Nat.beq (tsum (h + h) t (apL (d'' + 1 + 1) a (q' + 1) ++ [(d'' + 1 + 1) * a + h, w])
      + tsum (h + h) t (apL (d'' + 1 + 1) a (q' + 1) ++ [(d'' + 1 + 1) * a + h, w]))
    ((apL (d'' + 1 + 1) a (q' + 1) ++ [(d'' + 1 + 1) * a + h, w]).length * (h + h)) = true
  have hlen : (apL (d'' + 1 + 1) a (q' + 1) ++ [(d'' + 1 + 1) * a + h, w]).length = d'' + 1 + 1 + 2 := by
    have e : ∀ L : List Nat, (L ++ [(d'' + 1 + 1) * a + h, w]).length = L.length + 2 := by
      intro L; induction L with
      | nil => rfl
      | cons x L ihL => show (L ++ _).length + 1 = L.length + 1 + 2; rw [ihL]
    rw [e, len_apL]
  rw [hlen, tsum_append, hap]
  show Nat.beq ((d'' + 1 + 1) * r + (q' + 1) * sumTo (d'' + 1 + 1) (fun j => j)
      + ((t * ((d'' + 1 + 1) * a + h)) % (h + h) + ((t * w) % (h + h) + 0))
      + ((d'' + 1 + 1) * r + (q' + 1) * sumTo (d'' + 1 + 1) (fun j => j)
      + ((t * ((d'' + 1 + 1) * a + h)) % (h + h) + ((t * w) % (h + h) + 0))))
    ((d'' + 1 + 1 + 2) * (h + h)) = true
  have two := two_sum (d'' + 1 + 1)
  generalize sumTo (d'' + 1 + 1) (fun j => j) = S at two ⊢
  generalize (t * ((d'' + 1 + 1) * a + h)) % (h + h) = P at hdup ⊢
  generalize (t * w) % (h + h) = W at hdup ⊢
  have goal : (d'' + 1 + 1) * r + (q' + 1) * S + (P + (W + 0)) + ((d'' + 1 + 1) * r + (q' + 1) * S + (P + (W + 0)))
      = (d'' + 1 + 1 + 2) * (h + h) := by
    have e1 : (d'' + 1 + 1) * r + (q' + 1) * S + (P + (W + 0)) + ((d'' + 1 + 1) * r + (q' + 1) * S + (P + (W + 0)))
        = ((d'' + 1 + 1) * r + (P + W)) + ((d'' + 1 + 1) * r + (P + W)) + (q' + 1) * (S + S) := by lib_nat
    have e2 : (d'' + 1 + 1 + 2) * (h + h) = (h + h + h) + (h + h + h) + (q' + 1) * (S + S) := by
      have e3 : (d'' + 1 + 1) * (h + h) = (q' + 1) * (S + S + (d'' + 1 + 1)) := by
        rw [two, ← hm]; lib_nat
      rw [show (d'' + 1 + 1 + 2) * (h + h) = (d'' + 1 + 1) * (h + h) + (h + h) + (h + h) by lib_nat, e3,
        show (q' + 1) * (S + S + (d'' + 1 + 1)) = (q' + 1) * (S + S) + (d'' + 1 + 1) * (q' + 1) by lib_nat, hm]
      lib_nat
    rw [e1, e2, hdup]
  rw [goal]; exact beq_self _

end APDouble

#print axioms APDouble.tsum_apL
#print axioms APDouble.unit_d
#print axioms APDouble.ap_double_bal

#print axioms: 3 theorems, no axioms.

81.58 Irreducibility for \(d=3,6,8\)

The \(t=1\) reflection test separates every splitting of the AP\(_d\) + duplication-pair characters (\(a=1\)) for \(m\ge 30,78,128\). \(\text {indec}\,(30+6r)\,\cdot ,\quad \text {indec}\,(78+6r)\,\cdot ,\quad \text {indec}\,(128+8r)\,\cdot \)

hodge/APDoubleIrr.lean

/-
  hodge/APDoubleIrr.lean — T41 cycle 287 (goal G30): irreducibility of the AP_d + duplication-pair characters of
  APDouble for d = 3, 6, 8 (a = 1), symbolically in the size, by the t = 1 reflection test of APPairIrrGen.

  Lean 4 core plus hodge/APPairIrrGen (indec_lin, ev, chkSplit, small, splitsG), rfl on the coefficient lists.
    d = 3: m = 30 + 6r,  [1, 11+2r, 21+4r, 18+3r, 24+6r]                (p = 5 + r, q = 2p)
    d = 6: m = 78 + 6r,  [1 + 13k + kr (k < 6), 45+3r, 66+6r]           (q = 13 + r)
    d = 8: m = 128 + 8r, [1 + 16k + kr (k < 8), 72+4r, 112+8r]          (q = 16 + r)
  (d = 4 is APPairIrrGen; for d = 5 the t = 1 test does not separate every splitting.)
-/
import hodge.APPairIrrGen

namespace APDoubleIrr
open Indecomp APPairIrrGen

def co3 : List (Nat × Nat) := [(1, 0), (11, 2), (21, 4), (18, 3), (24, 6)]
def co6 : List (Nat × Nat) := [(1, 0), (14, 1), (27, 2), (40, 3), (53, 4), (66, 5), (45, 3), (66, 6)]
def co8 : List (Nat × Nat) := [(1, 0), (17, 1), (33, 2), (49, 3), (65, 4), (81, 5), (97, 6), (113, 7), (72, 4), (112, 8)]

theorem co3_ok : co3.all (small 30 6) = true ∧ (splitsG co3).all (chkSplit 30 6) = true := ⟨rfl, rfl⟩
set_option maxRecDepth 10000 in
theorem co6_ok : co6.all (small 78 6) = true ∧ (splitsG co6).all (chkSplit 78 6) = true := ⟨rfl, rfl⟩
set_option maxRecDepth 10000 in
theorem co8_ok : co8.all (small 128 8) = true ∧ (splitsG co8).all (chkSplit 128 8) = true := ⟨rfl, rfl⟩

theorem d3_indec (r : Nat) : indec (28 + 6 * r + 2) (co3.map (ev r)) = true :=
  indec_lin _ 30 6 r (by rw [Nat.add_right_comm]) co3 co3_ok.1 co3_ok.2

theorem d6_indec (r : Nat) : indec (76 + 6 * r + 2) (co6.map (ev r)) = true :=
  indec_lin _ 78 6 r (by rw [Nat.add_right_comm]) co6 co6_ok.1 co6_ok.2

theorem d8_indec (r : Nat) : indec (126 + 8 * r + 2) (co8.map (ev r)) = true :=
  indec_lin _ 128 8 r (by rw [Nat.add_right_comm]) co8 co8_ok.1 co8_ok.2

end APDoubleIrr

#print axioms APDoubleIrr.co3_ok
#print axioms APDoubleIrr.co6_ok
#print axioms APDoubleIrr.co8_ok
#print axioms APDoubleIrr.d3_indec
#print axioms APDoubleIrr.d6_indec
#print axioms APDoubleIrr.d8_indec

#print axioms: 6 theorems, no axioms.

81.59 Irreducibility for \(d=5\) with a second unit

With \(t_2=1+5p\) (\(p\) even) or \(2+5p\) (\(p\) odd) all residues are linear in \(p\); every splitting fails at \(t=1\) or at \(t_2\). \(\text {indec}\,(10p)\,[1,1+2p,1+4p,1+6p,1+8p,5+5p,10p-10]\quad (p\ge 9)\)

hodge/APDoubleIrr5.lean

/-
  hodge/APDoubleIrr5.lean — T41 cycle 288 (goal G31): the d = 5 member of APDouble, a = 1,
  [1, 1+2p, 1+4p, 1+6p, 1+8p, 5+5p, 10p−10] in m = 10p, is irreducible for every p ≥ 9 (both parities).

  The t = 1 test of APPairIrrGen leaves some splittings; a second unit t₂ separates them: t₂ = 1 + 5p (p even),
  t₂ = 2 + 5p (p odd). With p = 10 + 2r resp. 9 + 2r every entry, every residue ⟨t₂·e⟩_m and every quotient is
  linear in r; a row (e, res, Q) is checked by coefficient comparison of t₂·e = res + Q·m (rowOK, rfl), and every
  splitting fails the Hodge condition at t = 1 or at t = t₂ (chk2, rfl over the 128 splittings).

  Lean 4 core plus hodge/APPairIrrGen (lin_bal_false, chk, small, splitsG, …), hodge/TwistBal (all_fr_elim),
  hodge/UnitMul (gcd_dvd, one_of_dvd_one), hodge/APPair1 (dvd_sub_form), lib/NatNorm.
-/
import hodge.APPairIrrGen
import hodge.TwistIndec

namespace APDoubleIrr5
open ModHand HalfGeneral Indecomp GcdHand APPair APPairIrrGen TwistBal UnitMul

abbrev Row := (Nat × Nat) × (Nat × Nat) × (Nat × Nat)

def rowOK (t0 t1 m0 m1 : Nat) (w : Row) : Bool :=
  Nat.beq (t0 * w.1.1) (w.2.1.1 + w.2.2.1 * m0) &&
  Nat.beq (t0 * w.1.2 + t1 * w.1.1) (w.2.1.2 + w.2.2.1 * m1 + w.2.2.2 * m0) &&
  Nat.beq (t1 * w.1.2) (w.2.2.2 * m1) && small m0 m1 w.2.1

theorem and4 {a b c d : Bool} (h : (a && b && c && d) = true) : a = true ∧ b = true ∧ c = true ∧ d = true := by
  cases a <;> cases b <;> cases c <;> cases d <;> first | exact ⟨rfl, rfl, rfl, rfl⟩ | exact Bool.noConfusion h

theorem row_res (t0 t1 m0 m1 r : Nat) (w : Row) (h : rowOK t0 t1 m0 m1 w = true) :
    ((t0 + t1 * r) * ev r w.1) % (m0 + m1 * r) = ev r w.2.1 := by
  have ⟨h1, h2, h3, h4⟩ := and4 h
  have e1 := Nat.eq_of_beq_eq_true h1
  have e2 := Nat.eq_of_beq_eq_true h2
  have e3 := Nat.eq_of_beq_eq_true h3
  have hs : w.2.1.1 < m0 ∧ w.2.1.2 ≤ m1 := by
    have h4' : (Nat.blt w.2.1.1 m0 && Nat.ble w.2.1.2 m1) = true := h4
    cases b1 : Nat.blt w.2.1.1 m0 <;> cases b2 : Nat.ble w.2.1.2 m1 <;> rw [b1, b2] at h4'
    · exact Bool.noConfusion h4'
    · exact Bool.noConfusion h4'
    · exact Bool.noConfusion h4'
    · exact ⟨Nat.le_of_ble_eq_true b1, Nat.le_of_ble_eq_true b2⟩
  apply mod_rep _ _ _ (w.2.2.1 + w.2.2.2 * r) (lt_lin _ _ _ _ r hs.1 hs.2)
  show (t0 + t1 * r) * (w.1.1 + w.1.2 * r) = w.2.1.1 + w.2.1.2 * r + (w.2.2.1 + w.2.2.2 * r) * (m0 + m1 * r)
  rw [((show ((t0) + (t1)*(r))*((w.1.1) + (w.1.2)*(r)) = (t0)*(w.1.1) + ((t0)*(w.1.2) + (t1)*(w.1.1))*(r) + (t1)*(w.1.2)*(r)*(r) from NatNorm.sound [t0, t1, w.1.1, w.1.2, r] (.mul (.add (.var 0) (.mul (.var 1) (.var 4))) (.add (.var 2) (.mul (.var 3) (.var 4)))) (.add (.add (.mul (.var 0) (.var 2)) (.mul (.add (.mul (.var 0) (.var 3)) (.mul (.var 1) (.var 2))) (.var 4))) (.mul (.mul (.mul (.var 1)  -- (+50 chars; full line in the Zenodo source)
  exact ((show (w.2.1.1) + (w.2.2.1)*(m0) + ((w.2.1.2) + (w.2.2.1)*(m1) + (w.2.2.2)*(m0))*(r) + (w.2.2.2)*(m1)*(r)*(r) = (w.2.1.1) + (w.2.1.2)*(r) + ((w.2.2.1) + (w.2.2.2)*(r))*((m0) + (m1)*(r)) from NatNorm.sound [w.2.1.1, w.2.1.2, w.2.2.1, w.2.2.2, m0, m1, r] (.add (.add (.add (.var 0) (.mul (.var 2) (.var 4))) (.mul (.add (.add (.var 1) (.mul (.var 2) (.var 5))) (.mul (.var 3) (.var 4))) (.var   -- (+205 chars; full line in the Zenodo source)

def evE (r : Nat) (w : Row) : Nat := ev r w.1
def evR (r : Nat) (w : Row) : Nat := ev r w.2.1

theorem tsum_rows (t0 t1 m0 m1 r : Nat) : ∀ S : List Row, S.all (rowOK t0 t1 m0 m1) = true →
    tsum (m0 + m1 * r) (t0 + t1 * r) (S.map (evE r)) = sumL (S.map (evR r))
  | [], _ => rfl
  | w :: S, h => by
    have h' : (rowOK t0 t1 m0 m1 w && S.all (rowOK t0 t1 m0 m1)) = true := h
    cases a : rowOK t0 t1 m0 m1 w with
    | false => rw [a] at h'; exact Bool.noConfusion h'
    | true =>
      rw [a] at h'
      show ((t0 + t1 * r) * ev r w.1) % (m0 + m1 * r) + tsum _ _ (S.map (evE r)) = ev r w.2.1 + sumL (S.map (evR r))
      rw [row_res t0 t1 m0 m1 r w a, tsum_rows t0 t1 m0 m1 r S h']

theorem map_map' {α β γ : Type} (f : α → β) (g : β → γ) : ∀ l : List α, (l.map f).map g = l.map (fun x => g (f x))
  | [] => rfl
  | x :: l => by show g (f x) :: (l.map f).map g = g (f x) :: l.map _; rw [map_map' f g l]

/-- the linear contradiction: 2·Σ(α + βr) = |S|(m₀ + m₁r) is impossible when chk holds -/
theorem lin_contra (m0 m1 r : Nat) (S : List (Nat × Nat)) (hc : chk m0 m1 S = true)
    (e : sumL (S.map (ev r)) + sumL (S.map (ev r)) = S.length * (m0 + m1 * r)) : False := by
  rw [sumL_map] at e
  have e2 : 2 * sA S + 2 * sB S * r = S.length * m0 + S.length * m1 * r := by
    rw [((show 2*(sA S) + 2*(sB S)*(r) = (sA S) + (sB S)*(r) + ((sA S) + (sB S)*(r)) from NatNorm.sound [sA S, sB S, r] (.add (.mul (.lit 2) (.var 0)) (.mul (.mul (.lit 2) (.var 1)) (.var 2))) (.add (.add (.var 0) (.mul (.var 1) (.var 2))) (.add (.var 0) (.mul (.var 1) (.var 2)))) rfl)), e]
    exact ((show (S.length)*((m0) + (m1)*(r)) = (S.length)*(m0) + (S.length)*(m1)*(r) from NatNorm.sound [S.length, m0, m1, r] (.mul (.var 0) (.add (.var 1) (.mul (.var 2) (.var 3)))) (.add (.mul (.var 0) (.var 1)) (.mul (.mul (.var 0) (.var 2)) (.var 3))) rfl))
  have hc' : ((Nat.blt (2 * sA S) (S.length * m0) && Nat.ble (2 * sB S) (S.length * m1)) ||
      (Nat.blt (S.length * m0) (2 * sA S) && Nat.ble (S.length * m1) (2 * sB S))) = true := hc
  cases c1 : Nat.blt (2 * sA S) (S.length * m0) <;> cases c2 : Nat.ble (2 * sB S) (S.length * m1) <;>
    cases c3 : Nat.blt (S.length * m0) (2 * sA S) <;> cases c4 : Nat.ble (S.length * m1) (2 * sB S) <;>
    rw [c1, c2, c3, c4] at hc' <;> first
      | exact Bool.noConfusion hc'
      | exact absurd (e2 ▸ lt_lin _ _ _ _ r (Nat.le_of_ble_eq_true c1) (Nat.le_of_ble_eq_true c2)) (Nat.lt_irrefl _)
      | exact absurd (e2 ▸ lt_lin _ _ _ _ r (Nat.le_of_ble_eq_true c3) (Nat.le_of_ble_eq_true c4)) (Nat.lt_irrefl _)

theorem len_map {α β : Type} (f : α → β) : ∀ l : List α, (l.map f).length = l.length := length_map' f

/-- bal fails when the residues under the unit t₂ fail the linear test -/
theorem bal_false_t2 (n t0 t1 m0 m1 r : Nat) (hm : m0 + m1 * r = n + 2)
    (hu : Nat.gcd (t0 + t1 * r) (n + 2) = 1) (hlt : t0 + t1 * r < n + 2) (S : List Row)
    (hrows : S.all (rowOK t0 t1 m0 m1) = true) (hc : chk m0 m1 (S.map (fun w => w.2.1)) = true) :
    bal (n + 2) (S.map (evE r)) = false := by
  cases hb : bal (n + 2) (S.map (evE r)) with
  | false => rfl
  | true =>
    unfold bal FermatPrime.units at hb
    have h := all_fr_elim _ _ (n + 2) hb (t0 + t1 * r) hlt (by rw [hu]; rfl)
    have e := Nat.eq_of_beq_eq_true h
    rw [← hm, tsum_rows t0 t1 m0 m1 r S hrows, len_map] at e
    exact (lin_contra m0 m1 r (S.map (fun w => w.2.1)) hc (by rw [map_map', len_map]; exact e)).elim

def chk2 (m0 m1 : Nat) (p : List Row × List Row) : Bool :=
  p.1.isEmpty || p.2.isEmpty || chk m0 m1 (p.1.map (fun w => w.1)) || chk m0 m1 (p.2.map (fun w => w.1)) ||
    chk m0 m1 (p.1.map (fun w => w.2.1)) || chk m0 m1 (p.2.map (fun w => w.2.1))

def okRow (t0 t1 m0 m1 : Nat) (w : Row) : Bool := rowOK t0 t1 m0 m1 w && small m0 m1 w.1

theorem okRow_parts (t0 t1 m0 m1 : Nat) : ∀ S : List Row, S.all (okRow t0 t1 m0 m1) = true →
    S.all (rowOK t0 t1 m0 m1) = true ∧ (S.map (fun w => w.1)).all (small m0 m1) = true
  | [], _ => ⟨rfl, rfl⟩
  | w :: S, h => by
    have h' : ((rowOK t0 t1 m0 m1 w && small m0 m1 w.1) && S.all (okRow t0 t1 m0 m1)) = true := h
    cases c : S.all (okRow t0 t1 m0 m1) with
    | false =>
      rw [c] at h'
      cases a : rowOK t0 t1 m0 m1 w <;> cases b : small m0 m1 w.1 <;> rw [a, b] at h' <;> exact Bool.noConfusion h'
    | true =>
      have ⟨i1, i2⟩ := okRow_parts t0 t1 m0 m1 S c
      rw [c] at h'
      cases a : rowOK t0 t1 m0 m1 w <;> cases b : small m0 m1 w.1 <;> rw [a, b] at h'
      · exact Bool.noConfusion h'
      · exact Bool.noConfusion h'
      · exact Bool.noConfusion h'
      · exact ⟨by show (rowOK t0 t1 m0 m1 w && S.all _) = true; rw [a, i1]; rfl,
               by show (small m0 m1 w.1 && (S.map _).all _) = true; rw [b, i2]; rfl⟩

/-- **Reflection with two units.** -/
theorem indec_two (n t0 t1 m0 m1 r : Nat) (hm : m0 + m1 * r = n + 2)
    (hu : Nat.gcd (t0 + t1 * r) (n + 2) = 1) (hlt : t0 + t1 * r < n + 2) (co : List Row)
    (hok : co.all (okRow t0 t1 m0 m1) = true) (hsp : (splitsG co).all (chk2 m0 m1) = true) :
    indec (n + 2) (co.map (evE r)) = true := by
  unfold indec
  rw [splits_eq, splits_map]
  have hb := all_and _ _ _ (TwistIndec.splits_all _ co hok) hsp
  rw [Reach49.all_map]
  apply all_imp _ _ _ _ hb
  intro p hp
  have hp' : ((p.1.all (okRow t0 t1 m0 m1) && p.2.all (okRow t0 t1 m0 m1)) && chk2 m0 m1 p) = true := hp
  cases s1 : p.1.all (okRow t0 t1 m0 m1) <;> cases s2 : p.2.all (okRow t0 t1 m0 m1) <;> rw [s1, s2] at hp'
  · exact Bool.noConfusion hp'
  · exact Bool.noConfusion hp'
  · exact Bool.noConfusion hp'
  · have ⟨r1, q1⟩ := okRow_parts _ _ _ _ p.1 s1
    have ⟨r2, q2⟩ := okRow_parts _ _ _ _ p.2 s2
    have em : ∀ l : List Row, (l.map (evE r)).isEmpty = l.isEmpty := fun l => by cases l <;> rfl
    have f1 : ∀ S : List Row, (S.map (fun w => w.1)).all (small m0 m1) = true →
        chk m0 m1 (S.map (fun w => w.1)) = true → bal (n + 2) (S.map (evE r)) = false := by
      intro S hs hc
      have := lin_bal_false n m0 m1 r hm _ hs hc
      rw [map_map'] at this; exact this
    have f2 : ∀ S : List Row, S.all (rowOK t0 t1 m0 m1) = true →
        chk m0 m1 (S.map (fun w => w.2.1)) = true → bal (n + 2) (S.map (evE r)) = false :=
      fun S hs hc => bal_false_t2 n t0 t1 m0 m1 r hm hu hlt S hs hc
    show ((p.1.map (evE r)).isEmpty || (p.2.map (evE r)).isEmpty ||
      !(bal (n + 2) (p.1.map (evE r)) && bal (n + 2) (p.2.map (evE r)))) = true
    rw [em, em]
    have hc : (p.1.isEmpty || p.2.isEmpty || chk m0 m1 (p.1.map (fun w => w.1)) || chk m0 m1 (p.2.map (fun w => w.1)) ||
      chk m0 m1 (p.1.map (fun w => w.2.1)) || chk m0 m1 (p.2.map (fun w => w.2.1))) = true := hp'
    cases e1 : p.1.isEmpty <;> cases e2 : p.2.isEmpty <;> rw [e1, e2] at hc <;> try rfl
    cases k1 : chk m0 m1 (p.1.map (fun w => w.1))
    · cases k2 : chk m0 m1 (p.2.map (fun w => w.1))
      · cases k3 : chk m0 m1 (p.1.map (fun w => w.2.1))
        · cases k4 : chk m0 m1 (p.2.map (fun w => w.2.1))
          · rw [k1, k2, k3, k4] at hc; exact Bool.noConfusion hc
          · rw [f2 p.2 r2 k4]; cases bal (n + 2) (p.1.map (evE r)) <;> rfl
        · rw [f2 p.1 r1 k3]; rfl
      · rw [f1 p.2 q2 k2]; cases bal (n + 2) (p.1.map (evE r)) <;> rfl
    · rw [f1 p.1 q1 k1]; rfl

def coE : List Row := [((1,0), (51,10), (0,0)), ((21,4), (71,14), (10,2)), ((41,8), (91,18), (20,4)), ((61,12), (11,2), (31,6)), ((81,16), (31,6), (41,8)), ((55,10), (5,0), (28,5)), ((90,20), (90,20), (45,10))]
def coO : List Row := [((1,0), (47,10), (0,0)), ((19,4), (83,18), (9,2)), ((37,8), (29,6), (19,4)), ((55,12), (65,14), (28,6)), ((73,16), (11,2), (38,8)), ((50,10), (10,0), (26,5)), ((80,20), (70,20), (41,10))]

set_option maxRecDepth 20000 in
theorem coE_ok : coE.all (okRow 51 10 100 20) = true ∧ (splitsG coE).all (chk2 100 20) = true := ⟨rfl, rfl⟩
set_option maxRecDepth 20000 in
theorem coO_ok : coO.all (okRow 47 10 90 20) = true ∧ (splitsG coO).all (chk2 90 20) = true := ⟨rfl, rfl⟩

/-- d ∣ 2·t − m with 2·t = m + c ⇒ d ∣ c -/
theorem unit_of_rel (t m c g : Nat) (hrel : t + t = m + c) (ht : ∃ i, t = g * i) (hm : ∃ j, m = g * j) :
    ∃ k, c = g * k := by
  have ⟨i, hi⟩ := ht
  have ⟨j, hj⟩ := hm
  apply APPair1.dvd_sub_form g c j (i + i)
  rw [((show (g)*((i) + (i)) = (g)*(i) + (g)*(i) from NatNorm.sound [g, i] (.mul (.var 0) (.add (.var 1) (.var 1))) (.add (.mul (.var 0) (.var 1)) (.mul (.var 0) (.var 1))) rfl)), ← hi, hrel, hj, Nat.add_comm]

theorem odd_not_even (x y : Nat) : 2 * x + 1 ≠ 2 * y := TorsionImage.odd_ne_even x y

/-- gcd(51 + 10r, 100 + 20r) = 1 -/
theorem unitE (r : Nat) : Nat.gcd (51 + 10 * r) (98 + 20 * r + 2) = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := gcd_dvd (51 + 10 * r) (98 + 20 * r + 2)
  generalize Nat.gcd (51 + 10 * r) (98 + 20 * r + 2) = g at hi hj ⊢
  have ⟨k, hk⟩ := unit_of_rel _ _ 2 g (by exact ((show 51 + 10*(r) + (51 + 10*(r)) = 98 + 20*(r) + 2 + 2 from NatNorm.sound [r] (.add (.add (.lit 51) (.mul (.lit 10) (.var 0))) (.add (.lit 51) (.mul (.lit 10) (.var 0)))) (.add (.add (.add (.lit 98) (.mul (.lit 20) (.var 0))) (.lit 2)) (.lit 2)) rfl))) ⟨i, hi⟩ ⟨j, hj⟩
  -- g ∣ 2, g ∣ odd ⇒ g = 1
  cases g with
  | zero => rw [Nat.zero_mul] at hk; exact Nat.noConfusion hk
  | succ g =>
    cases g with
    | zero => rfl
    | succ g =>
      cases g with
      | zero =>
        exact absurd (show 2 * (25 + 5 * r) + 1 = 2 * i by rw [← hi]; exact ((show 2*(25 + 5*(r)) + 1 = 51 + 10*(r) from NatNorm.sound [r] (.add (.mul (.lit 2) (.add (.lit 25) (.mul (.lit 5) (.var 0)))) (.lit 1)) (.add (.lit 51) (.mul (.lit 10) (.var 0))) rfl))) (odd_not_even _ _)
      | succ g =>
        cases k with
        | zero => rw [Nat.mul_zero] at hk; exact Nat.noConfusion hk
        | succ k =>
          have : 2 = g + 3 + (g + 3) * k := by rw [hk]; exact ((show ((g) + 1 + 1 + 1)*((k) + 1) = (g) + 3 + ((g) + 3)*(k) from NatNorm.sound [g, k] (.mul (.add (.add (.add (.var 0) (.lit 1)) (.lit 1)) (.lit 1)) (.add (.var 1) (.lit 1))) (.add (.add (.var 0) (.lit 3)) (.mul (.add (.var 0) (.lit 3)) (.var 1))) rfl))
          exact absurd (this ▸ Nat.le_add_right (g + 3) _) (by exact fun h => Nat.lt_irrefl 2 (Nat.lt_of_lt_of_le (Nat.lt_of_lt_of_le (Nat.lt_succ_self 2) (Nat.le_add_left 3 g)) h))

/-- gcd(47 + 10r, 90 + 20r) = 1 -/
theorem unitO (r : Nat) : Nat.gcd (47 + 10 * r) (88 + 20 * r + 2) = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := gcd_dvd (47 + 10 * r) (88 + 20 * r + 2)
  generalize Nat.gcd (47 + 10 * r) (88 + 20 * r + 2) = g at hi hj ⊢
  have ⟨k, hk⟩ := unit_of_rel _ _ 4 g (by exact ((show 47 + 10*(r) + (47 + 10*(r)) = 88 + 20*(r) + 2 + 4 from NatNorm.sound [r] (.add (.add (.lit 47) (.mul (.lit 10) (.var 0))) (.add (.lit 47) (.mul (.lit 10) (.var 0)))) (.add (.add (.add (.lit 88) (.mul (.lit 20) (.var 0))) (.lit 2)) (.lit 4)) rfl))) ⟨i, hi⟩ ⟨j, hj⟩
  have hodd : ∀ i', 47 + 10 * r ≠ 2 * i' := fun i' h =>
    odd_not_even (23 + 5 * r) i' (by rw [← h]; exact ((show 2*(23 + 5*(r)) + 1 = 47 + 10*(r) from NatNorm.sound [r] (.add (.mul (.lit 2) (.add (.lit 23) (.mul (.lit 5) (.var 0)))) (.lit 1)) (.add (.lit 47) (.mul (.lit 10) (.var 0))) rfl)))
  cases g with
  | zero => rw [Nat.zero_mul] at hk; exact Nat.noConfusion hk
  | succ g =>
    cases g with
    | zero => rfl
    | succ g =>
      cases g with
      | zero => exact absurd hi (hodd i)
      | succ g =>
        cases g with
        | zero =>
          -- g = 3: 3 k = 4 impossible
          cases k with
          | zero => exact Nat.noConfusion hk
          | succ k => cases k with
            | zero => exact Nat.noConfusion (Nat.succ.inj (Nat.succ.inj (Nat.succ.inj hk)))
            | succ k =>
              have : 4 = 6 + 3 * k := by rw [hk]; exact ((show (0 + 1 + 1 + 1)*((k) + 1 + 1) = 6 + 3*(k) from NatNorm.sound [k] (.mul (.add (.add (.add (.lit 0) (.lit 1)) (.lit 1)) (.lit 1)) (.add (.add (.var 0) (.lit 1)) (.lit 1))) (.add (.lit 6) (.mul (.lit 3) (.var 0))) rfl))
              exact absurd (this ▸ Nat.le_add_right 6 _) (fun h => Nat.lt_irrefl 4 (Nat.lt_of_lt_of_le (Nat.le_add_left 5 0 |> Nat.lt_of_lt_of_le (Nat.lt_succ_self 4)) (Nat.le_trans (Nat.le_add_left 5 1) h)))
        | succ g =>
          cases g with
          | zero => exact absurd (show 47 + 10 * r = 2 * (2 * i) by rw [hi]; exact ((show (0 + 1 + 1 + 1 + 1)*(i) = 2*(2*(i)) from NatNorm.sound [i] (.mul (.add (.add (.add (.add (.lit 0) (.lit 1)) (.lit 1)) (.lit 1)) (.lit 1)) (.var 0)) (.mul (.lit 2) (.mul (.lit 2) (.var 0))) rfl))) (hodd _)
          | succ g =>
            cases k with
            | zero => rw [Nat.mul_zero] at hk; exact Nat.noConfusion hk
            | succ k =>
              have : 4 = g + 5 + (g + 5) * k := by rw [hk]; exact ((show ((g) + 1 + 1 + 1 + 1 + 1)*((k) + 1) = (g) + 5 + ((g) + 5)*(k) from NatNorm.sound [g, k] (.mul (.add (.add (.add (.add (.add (.var 0) (.lit 1)) (.lit 1)) (.lit 1)) (.lit 1)) (.lit 1)) (.add (.var 1) (.lit 1))) (.add (.add (.var 0) (.lit 5)) (.mul (.add (.var 0) (.lit 5)) (.var 1))) rfl))
              exact absurd (this ▸ Nat.le_add_right (g + 5) _) (fun h => Nat.lt_irrefl 4 (Nat.lt_of_lt_of_le (Nat.lt_of_lt_of_le (Nat.lt_succ_self 4) (Nat.le_add_left 5 g)) h))

/-- **p = 10 + 2r (even): irreducible.** -/
theorem d5_even (r : Nat) : indec (98 + 20 * r + 2) (coE.map (evE r)) = true :=
  indec_two (98 + 20 * r) 51 10 100 20 r ((show 100 + 20*(r) = 98 + 20*(r) + 2 from NatNorm.sound [r] (.add (.lit 100) (.mul (.lit 20) (.var 0))) (.add (.add (.lit 98) (.mul (.lit 20) (.var 0))) (.lit 2)) rfl)) (unitE r)
    (by rw [((show 98 + 20*(r) + 2 = 51 + 10*(r) + (49 + 10*(r)) from NatNorm.sound [r] (.add (.add (.lit 98) (.mul (.lit 20) (.var 0))) (.lit 2)) (.add (.add (.lit 51) (.mul (.lit 10) (.var 0))) (.add (.lit 49) (.mul (.lit 10) (.var 0)))) rfl))]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 48) (Nat.le_add_right 49 _)))
    coE coE_ok.1 coE_ok.2

/-- **p = 9 + 2r (odd): irreducible.** -/
theorem d5_odd (r : Nat) : indec (88 + 20 * r + 2) (coO.map (evE r)) = true :=
  indec_two (88 + 20 * r) 47 10 90 20 r ((show 90 + 20*(r) = 88 + 20*(r) + 2 from NatNorm.sound [r] (.add (.lit 90) (.mul (.lit 20) (.var 0))) (.add (.add (.lit 88) (.mul (.lit 20) (.var 0))) (.lit 2)) rfl)) (unitO r)
    (by rw [((show 88 + 20*(r) + 2 = 47 + 10*(r) + (43 + 10*(r)) from NatNorm.sound [r] (.add (.add (.lit 88) (.mul (.lit 20) (.var 0))) (.lit 2)) (.add (.add (.lit 47) (.mul (.lit 10) (.var 0))) (.add (.lit 43) (.mul (.lit 10) (.var 0)))) rfl))]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 42) (Nat.le_add_right 43 _)))
    coO coO_ok.1 coO_ok.2

end APDoubleIrr5

#print axioms APDoubleIrr5.row_res
#print axioms APDoubleIrr5.bal_false_t2
#print axioms APDoubleIrr5.indec_two
#print axioms APDoubleIrr5.coE_ok
#print axioms APDoubleIrr5.coO_ok
#print axioms APDoubleIrr5.unitE
#print axioms APDoubleIrr5.unitO
#print axioms APDoubleIrr5.d5_even
#print axioms APDoubleIrr5.d5_odd

#print axioms: 9 theorems, no axioms.

81.60 Balanced and irreducible together, \(d=3,6,8\)

The APDouble balance and the reflection irreducibility for the same lists, symbolic in \(r\). \(\text {bal}\wedge \text {indec}\ \text {for}\ m=30+6r,\ 78+6r,\ 128+8r\)

hodge/APDoubleAll.lean

/-
  hodge/APDoubleAll.lean — T41 cycle 289 (goal G32): the AP_d + duplication-pair characters (a = 1) are balanced and
  irreducible, symbolically in r: d = 3 (m = 30 + 6r), d = 6 (m = 78 + 6r), d = 8 (m = 128 + 8r). Balance from
  APDouble.ap_double_bal, irreducibility from APDoubleIrr; the lists are matched by NatNorm.
-/
import hodge.APDouble
import hodge.APDoubleIrr

namespace APDoubleAll
open Indecomp APPairIrrGen APDouble


theorem d3_list (r : Nat) : apL (1 + 1 + 1) 1 (9 + 2 * r + 1) ++ [(1 + 1 + 1) * 1 + (15 + 3 * r), 24 + 6 * r]
    = APDoubleIrr.co3.map (ev r) := by
  show [1 + 0 * (9 + 2 * r + 1), 1 + 1 * (9 + 2 * r + 1), 1 + 2 * (9 + 2 * r + 1), (1 + 1 + 1) * 1 + (15 + 3 * r), 24 + 6 * r] = [1 + 0 * r, 11 + 2 * r, 21 + 4 * r, 18 + 3 * r, 24 + 6 * r]
  rw [(show 1 + 0*(9 + 2*(r) + 1) = 1 + 0*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 0) (.add (.add (.lit 9) (.mul (.lit 2) (.var 0))) (.lit 1)))) (.add (.lit 1) (.mul (.lit 0) (.var 0))) rfl), (show 1 + 1*(9 + 2*(r) + 1) = 11 + 2*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 1) (.add (.add (.lit 9) (.mul (.lit 2) (.var 0))) (.lit 1)))) (.add (.lit 11) (.mul (.lit 2) (.var 0)))   -- (+431 chars; full line in the Zenodo source)

/-- **d = 3: balanced and irreducible.** -/
theorem d3_both (r : Nat) :
    bal (15 + 3 * r + (15 + 3 * r)) (APDoubleIrr.co3.map (ev r)) = true ∧
    indec (28 + 6 * r + 2) (APDoubleIrr.co3.map (ev r)) = true := by
  refine ⟨?_, APDoubleIrr.d3_indec r⟩
  rw [← d3_list r]
  exact ap_double_bal 1 (9 + 2 * r) (15 + 3 * r) 1 (24 + 6 * r)
    (show (1 + 1 + 1)*(9 + 2*(r) + 1) = 15 + 3*(r) + (15 + 3*(r)) from NatNorm.sound [r] (.mul (.add (.add (.lit 1) (.lit 1)) (.lit 1)) (.add (.add (.lit 9) (.mul (.lit 2) (.var 0))) (.lit 1))) (.add (.add (.lit 15) (.mul (.lit 3) (.var 0))) (.add (.lit 15) (.mul (.lit 3) (.var 0)))) rfl)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_left 1 _))
    (by rw [(show (15 + 3*(r)) = (1 + 1 + 1)*1 + (1 + (11 + 3*(r))) from NatNorm.sound [r] (.add (.lit 15) (.mul (.lit 3) (.var 0))) (.add (.mul (.add (.add (.lit 1) (.lit 1)) (.lit 1)) (.lit 1)) (.add (.lit 1) (.add (.lit 11) (.mul (.lit 3) (.var 0))))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (1 + 1 + 1)*1 + (1 + 1 + 1)*1 + (24 + 6*(r)) = 15 + 3*(r) + (15 + 3*(r)) from NatNorm.sound [r] (.add (.add (.mul (.add (.add (.lit 1) (.lit 1)) (.lit 1)) (.lit 1)) (.mul (.add (.add (.lit 1) (.lit 1)) (.lit 1)) (.lit 1))) (.add (.lit 24) (.mul (.lit 6) (.var 0)))) (.add (.add (.lit 15) (.mul (.lit 3) (.var 0))) (.add (.lit 15) (.mul (.lit 3) (.var 0)))) rfl)


set_option maxHeartbeats 4000000 in
theorem d6_list (r : Nat) : apL (4 + 1 + 1) 1 (12 + 1 * r + 1) ++ [(4 + 1 + 1) * 1 + (39 + 3 * r), 66 + 6 * r]
    = APDoubleIrr.co6.map (ev r) := by
  show [1 + 0 * (12 + 1 * r + 1), 1 + 1 * (12 + 1 * r + 1), 1 + 2 * (12 + 1 * r + 1), 1 + 3 * (12 + 1 * r + 1), 1 + 4 * (12 + 1 * r + 1), 1 + 5 * (12 + 1 * r + 1), (4 + 1 + 1) * 1 + (39 + 3 * r), 66 + 6 * r] = [1 + 0 * r, 14 + 1 * r, 27 + 2 * r, 40 + 3 * r, 53 + 4 * r, 66 + 5 * r, 45 + 3 * r, 66 + 6 * r]
  rw [(show 1 + 0*(12 + 1*(r) + 1) = 1 + 0*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 0) (.add (.add (.lit 12) (.mul (.lit 1) (.var 0))) (.lit 1)))) (.add (.lit 1) (.mul (.lit 0) (.var 0))) rfl), (show 1 + 1*(12 + 1*(r) + 1) = 14 + 1*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 1) (.add (.add (.lit 12) (.mul (.lit 1) (.var 0))) (.lit 1)))) (.add (.lit 14) (.mul (.lit 1) (.var 0  -- (+1046 chars; full line in the Zenodo source)

/-- **d = 6: balanced and irreducible.** -/
theorem d6_both (r : Nat) :
    bal (39 + 3 * r + (39 + 3 * r)) (APDoubleIrr.co6.map (ev r)) = true ∧
    indec (76 + 6 * r + 2) (APDoubleIrr.co6.map (ev r)) = true := by
  refine ⟨?_, APDoubleIrr.d6_indec r⟩
  rw [← d6_list r]
  exact ap_double_bal 4 (12 + 1 * r) (39 + 3 * r) 1 (66 + 6 * r)
    (show (4 + 1 + 1)*(12 + 1*(r) + 1) = 39 + 3*(r) + (39 + 3*(r)) from NatNorm.sound [r] (.mul (.add (.add (.lit 4) (.lit 1)) (.lit 1)) (.add (.add (.lit 12) (.mul (.lit 1) (.var 0))) (.lit 1))) (.add (.add (.lit 39) (.mul (.lit 3) (.var 0))) (.add (.lit 39) (.mul (.lit 3) (.var 0)))) rfl)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_left 1 _))
    (by rw [(show (39 + 3*(r)) = (4 + 1 + 1)*1 + (1 + (32 + 3*(r))) from NatNorm.sound [r] (.add (.lit 39) (.mul (.lit 3) (.var 0))) (.add (.mul (.add (.add (.lit 4) (.lit 1)) (.lit 1)) (.lit 1)) (.add (.lit 1) (.add (.lit 32) (.mul (.lit 3) (.var 0))))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (4 + 1 + 1)*1 + (4 + 1 + 1)*1 + (66 + 6*(r)) = 39 + 3*(r) + (39 + 3*(r)) from NatNorm.sound [r] (.add (.add (.mul (.add (.add (.lit 4) (.lit 1)) (.lit 1)) (.lit 1)) (.mul (.add (.add (.lit 4) (.lit 1)) (.lit 1)) (.lit 1))) (.add (.lit 66) (.mul (.lit 6) (.var 0)))) (.add (.add (.lit 39) (.mul (.lit 3) (.var 0))) (.add (.lit 39) (.mul (.lit 3) (.var 0)))) rfl)


set_option maxHeartbeats 4000000 in
theorem d8_list (r : Nat) : apL (6 + 1 + 1) 1 (15 + 1 * r + 1) ++ [(6 + 1 + 1) * 1 + (64 + 4 * r), 112 + 8 * r]
    = APDoubleIrr.co8.map (ev r) := by
  show [1 + 0 * (15 + 1 * r + 1), 1 + 1 * (15 + 1 * r + 1), 1 + 2 * (15 + 1 * r + 1), 1 + 3 * (15 + 1 * r + 1), 1 + 4 * (15 + 1 * r + 1), 1 + 5 * (15 + 1 * r + 1), 1 + 6 * (15 + 1 * r + 1), 1 + 7 * (15 + 1 * r + 1), (6 + 1 + 1) * 1 + (64 + 4 * r), 112 + 8 * r] = [1 + 0 * r, 17 + 1 * r, 33 + 2 * r, 49 + 3 * r, 65 + 4 * r, 81 + 5 * r, 97 + 6 * r, 113 + 7 * r, 72 + 4 * r, 112 + 8 * r]
  rw [(show 1 + 0*(15 + 1*(r) + 1) = 1 + 0*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 0) (.add (.add (.lit 15) (.mul (.lit 1) (.var 0))) (.lit 1)))) (.add (.lit 1) (.mul (.lit 0) (.var 0))) rfl), (show 1 + 1*(15 + 1*(r) + 1) = 17 + 1*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 1) (.add (.add (.lit 15) (.mul (.lit 1) (.var 0))) (.lit 1)))) (.add (.lit 17) (.mul (.lit 1) (.var 0  -- (+1454 chars; full line in the Zenodo source)

/-- **d = 8: balanced and irreducible.** -/
theorem d8_both (r : Nat) :
    bal (64 + 4 * r + (64 + 4 * r)) (APDoubleIrr.co8.map (ev r)) = true ∧
    indec (126 + 8 * r + 2) (APDoubleIrr.co8.map (ev r)) = true := by
  refine ⟨?_, APDoubleIrr.d8_indec r⟩
  rw [← d8_list r]
  exact ap_double_bal 6 (15 + 1 * r) (64 + 4 * r) 1 (112 + 8 * r)
    (show (6 + 1 + 1)*(15 + 1*(r) + 1) = 64 + 4*(r) + (64 + 4*(r)) from NatNorm.sound [r] (.mul (.add (.add (.lit 6) (.lit 1)) (.lit 1)) (.add (.add (.lit 15) (.mul (.lit 1) (.var 0))) (.lit 1))) (.add (.add (.lit 64) (.mul (.lit 4) (.var 0))) (.add (.lit 64) (.mul (.lit 4) (.var 0)))) rfl)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_left 1 _))
    (by rw [(show (64 + 4*(r)) = (6 + 1 + 1)*1 + (1 + (55 + 4*(r))) from NatNorm.sound [r] (.add (.lit 64) (.mul (.lit 4) (.var 0))) (.add (.mul (.add (.add (.lit 6) (.lit 1)) (.lit 1)) (.lit 1)) (.add (.lit 1) (.add (.lit 55) (.mul (.lit 4) (.var 0))))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (6 + 1 + 1)*1 + (6 + 1 + 1)*1 + (112 + 8*(r)) = 64 + 4*(r) + (64 + 4*(r)) from NatNorm.sound [r] (.add (.add (.mul (.add (.add (.lit 6) (.lit 1)) (.lit 1)) (.lit 1)) (.mul (.add (.add (.lit 6) (.lit 1)) (.lit 1)) (.lit 1))) (.add (.lit 112) (.mul (.lit 8) (.var 0)))) (.add (.add (.lit 64) (.mul (.lit 4) (.var 0))) (.add (.lit 64) (.mul (.lit 4) (.var 0)))) rfl)

end APDoubleAll

#print axioms APDoubleAll.d3_both
#print axioms APDoubleAll.d6_both
#print axioms APDoubleAll.d8_both

#print axioms: 3 theorems, no axioms.

81.61 Balanced and irreducible together, \(d=5\)

Both parities of \(p\ge 9\). \(\text {bal}\wedge \text {indec}\ \text {for}\ m=100+20r,\ 90+20r\)

hodge/APDoubleAll5.lean

/-
  hodge/APDoubleAll5.lean — T41 cycle 290 (goal G33): the d = 5 APDouble character (a = 1) is balanced and
  irreducible for every p ≥ 9: m = 100 + 20r (p = 10 + 2r) and m = 90 + 20r (p = 9 + 2r).
-/
import hodge.APDouble
import hodge.APDoubleIrr5

namespace APDoubleAll5
open Indecomp APPairIrrGen APDouble APDoubleIrr5


set_option maxHeartbeats 4000000 in
theorem d5e_list (r : Nat) : apL (3 + 1 + 1) 1 (19 + 4 * r + 1) ++ [(3 + 1 + 1) * 1 + (50 + 10 * r), 90 + 20 * r]
    = APDoubleIrr5.coE.map (evE r) := by
  show [1 + 0 * (19 + 4 * r + 1), 1 + 1 * (19 + 4 * r + 1), 1 + 2 * (19 + 4 * r + 1), 1 + 3 * (19 + 4 * r + 1), 1 + 4 * (19 + 4 * r + 1), (3 + 1 + 1) * 1 + (50 + 10 * r), 90 + 20 * r] = [1 + 0 * r, 21 + 4 * r, 41 + 8 * r, 61 + 12 * r, 81 + 16 * r, 55 + 10 * r, 90 + 20 * r]
  rw [(show 1 + 0*(19 + 4*(r) + 1) = 1 + 0*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 0) (.add (.add (.lit 19) (.mul (.lit 4) (.var 0))) (.lit 1)))) (.add (.lit 1) (.mul (.lit 0) (.var 0))) rfl), (show 1 + 1*(19 + 4*(r) + 1) = 21 + 4*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 1) (.add (.add (.lit 19) (.mul (.lit 4) (.var 0))) (.lit 1)))) (.add (.lit 21) (.mul (.lit 4) (.var 0  -- (+851 chars; full line in the Zenodo source)

theorem d5e_both (r : Nat) :
    bal (50 + 10 * r + (50 + 10 * r)) (APDoubleIrr5.coE.map (evE r)) = true ∧
    indec (98 + 20 * r + 2) (APDoubleIrr5.coE.map (evE r)) = true := by
  refine ⟨?_, APDoubleIrr5.d5_even r⟩
  rw [← d5e_list r]
  exact ap_double_bal 3 (19 + 4 * r) (50 + 10 * r) 1 (90 + 20 * r)
    (show (3 + 1 + 1)*(19 + 4*(r) + 1) = 50 + 10*(r) + (50 + 10*(r)) from NatNorm.sound [r] (.mul (.add (.add (.lit 3) (.lit 1)) (.lit 1)) (.add (.add (.lit 19) (.mul (.lit 4) (.var 0))) (.lit 1))) (.add (.add (.lit 50) (.mul (.lit 10) (.var 0))) (.add (.lit 50) (.mul (.lit 10) (.var 0)))) rfl)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_left 1 _))
    (by rw [(show (50 + 10*(r)) = (3 + 1 + 1)*1 + (1 + (44 + 10*(r))) from NatNorm.sound [r] (.add (.lit 50) (.mul (.lit 10) (.var 0))) (.add (.mul (.add (.add (.lit 3) (.lit 1)) (.lit 1)) (.lit 1)) (.add (.lit 1) (.add (.lit 44) (.mul (.lit 10) (.var 0))))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (3 + 1 + 1)*1 + (3 + 1 + 1)*1 + (90 + 20*(r)) = 50 + 10*(r) + (50 + 10*(r)) from NatNorm.sound [r] (.add (.add (.mul (.add (.add (.lit 3) (.lit 1)) (.lit 1)) (.lit 1)) (.mul (.add (.add (.lit 3) (.lit 1)) (.lit 1)) (.lit 1))) (.add (.lit 90) (.mul (.lit 20) (.var 0)))) (.add (.add (.lit 50) (.mul (.lit 10) (.var 0))) (.add (.lit 50) (.mul (.lit 10) (.var 0)))) rfl)


set_option maxHeartbeats 4000000 in
theorem d5o_list (r : Nat) : apL (3 + 1 + 1) 1 (17 + 4 * r + 1) ++ [(3 + 1 + 1) * 1 + (45 + 10 * r), 80 + 20 * r]
    = APDoubleIrr5.coO.map (evE r) := by
  show [1 + 0 * (17 + 4 * r + 1), 1 + 1 * (17 + 4 * r + 1), 1 + 2 * (17 + 4 * r + 1), 1 + 3 * (17 + 4 * r + 1), 1 + 4 * (17 + 4 * r + 1), (3 + 1 + 1) * 1 + (45 + 10 * r), 80 + 20 * r] = [1 + 0 * r, 19 + 4 * r, 37 + 8 * r, 55 + 12 * r, 73 + 16 * r, 50 + 10 * r, 80 + 20 * r]
  rw [(show 1 + 0*(17 + 4*(r) + 1) = 1 + 0*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 0) (.add (.add (.lit 17) (.mul (.lit 4) (.var 0))) (.lit 1)))) (.add (.lit 1) (.mul (.lit 0) (.var 0))) rfl), (show 1 + 1*(17 + 4*(r) + 1) = 19 + 4*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 1) (.add (.add (.lit 17) (.mul (.lit 4) (.var 0))) (.lit 1)))) (.add (.lit 19) (.mul (.lit 4) (.var 0  -- (+851 chars; full line in the Zenodo source)

theorem d5o_both (r : Nat) :
    bal (45 + 10 * r + (45 + 10 * r)) (APDoubleIrr5.coO.map (evE r)) = true ∧
    indec (88 + 20 * r + 2) (APDoubleIrr5.coO.map (evE r)) = true := by
  refine ⟨?_, APDoubleIrr5.d5_odd r⟩
  rw [← d5o_list r]
  exact ap_double_bal 3 (17 + 4 * r) (45 + 10 * r) 1 (80 + 20 * r)
    (show (3 + 1 + 1)*(17 + 4*(r) + 1) = 45 + 10*(r) + (45 + 10*(r)) from NatNorm.sound [r] (.mul (.add (.add (.lit 3) (.lit 1)) (.lit 1)) (.add (.add (.lit 17) (.mul (.lit 4) (.var 0))) (.lit 1))) (.add (.add (.lit 45) (.mul (.lit 10) (.var 0))) (.add (.lit 45) (.mul (.lit 10) (.var 0)))) rfl)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_left 1 _))
    (by rw [(show (45 + 10*(r)) = (3 + 1 + 1)*1 + (1 + (39 + 10*(r))) from NatNorm.sound [r] (.add (.lit 45) (.mul (.lit 10) (.var 0))) (.add (.mul (.add (.add (.lit 3) (.lit 1)) (.lit 1)) (.lit 1)) (.add (.lit 1) (.add (.lit 39) (.mul (.lit 10) (.var 0))))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (3 + 1 + 1)*1 + (3 + 1 + 1)*1 + (80 + 20*(r)) = 45 + 10*(r) + (45 + 10*(r)) from NatNorm.sound [r] (.add (.add (.mul (.add (.add (.lit 3) (.lit 1)) (.lit 1)) (.lit 1)) (.mul (.add (.add (.lit 3) (.lit 1)) (.lit 1)) (.lit 1))) (.add (.lit 80) (.mul (.lit 20) (.var 0)))) (.add (.add (.lit 45) (.mul (.lit 10) (.var 0))) (.add (.lit 45) (.mul (.lit 10) (.var 0)))) rfl)

end APDoubleAll5

#print axioms APDoubleAll5.d5e_both
#print axioms APDoubleAll5.d5o_both

#print axioms: 2 theorems, no axioms.

81.62 Balanced and irreducible, \(d=7,9,10\)

The same reflection with 9, 11 and 12 entries. \(\text {bal}\wedge \text {indec}\ \text {for}\ m=182+14r,\ 306+18r,\ 200+10r\)

hodge/APDoubleMore.lean

/-
  hodge/APDoubleMore.lean — T41 cycle 291 (goal G34): the APDouble character (a = 1) is balanced and irreducible for
  d = 7 (q = 26 + 2r), d = 9 (q = 34 + 2r), d = 10 (q = 20 + r), every r — the t = 1 reflection test of APPairIrrGen
  (rfl over all splittings) and APDouble.ap_double_bal.
-/
import hodge.APDouble
import hodge.APPairIrrGen

namespace APDoubleMore
open Indecomp APPairIrrGen APDouble


def co7 : List (Nat × Nat) := [(1, 0), (27, 2), (53, 4), (79, 6), (105, 8), (131, 10), (157, 12), (98, 7), (168, 14)]

set_option maxRecDepth 200000 in
theorem co7_ok : co7.all (small 182 14) = true ∧ (splitsG co7).all (chkSplit 182 14) = true := ⟨rfl, rfl⟩

set_option maxHeartbeats 8000000 in
set_option maxRecDepth 200000 in
theorem d7_list (r : Nat) : apL (5 + 1 + 1) 1 (25 + 2 * r + 1) ++ [(5 + 1 + 1) * 1 + (91 + 7 * r), 168 + 14 * r]
    = co7.map (ev r) := by
  show [1 + 0 * (25 + 2 * r + 1), 1 + 1 * (25 + 2 * r + 1), 1 + 2 * (25 + 2 * r + 1), 1 + 3 * (25 + 2 * r + 1), 1 + 4 * (25 + 2 * r + 1), 1 + 5 * (25 + 2 * r + 1), 1 + 6 * (25 + 2 * r + 1), (5 + 1 + 1) * 1 + (91 + 7 * r), 168 + 14 * r] = [1 + 0 * r, 27 + 2 * r, 53 + 4 * r, 79 + 6 * r, 105 + 8 * r, 131 + 10 * r, 157 + 12 * r, 98 + 7 * r, 168 + 14 * r]
  rw [(show 1 + 0*(25 + 2*(r) + 1) = 1 + 0*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 0) (.add (.add (.lit 25) (.mul (.lit 2) (.var 0))) (.lit 1)))) (.add (.lit 1) (.mul (.lit 0) (.var 0))) rfl), (show 1 + 1*(25 + 2*(r) + 1) = 27 + 2*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 1) (.add (.add (.lit 25) (.mul (.lit 2) (.var 0))) (.lit 1)))) (.add (.lit 27) (.mul (.lit 2) (.var 0  -- (+1259 chars; full line in the Zenodo source)

set_option maxRecDepth 200000 in
/-- **d = 7: balanced and irreducible.** -/
theorem d7_both (r : Nat) :
    bal (91 + 7 * r + (91 + 7 * r)) (co7.map (ev r)) = true ∧
    indec (180 + 14 * r + 2) (co7.map (ev r)) = true := by
  refine ⟨?_, indec_lin _ 182 14 r (show 182 + 14*(r) = 180 + 14*(r) + 2 from NatNorm.sound [r] (.add (.lit 182) (.mul (.lit 14) (.var 0))) (.add (.add (.lit 180) (.mul (.lit 14) (.var 0))) (.lit 2)) rfl) co7 co7_ok.1 co7_ok.2⟩
  rw [← d7_list r]
  exact ap_double_bal 5 (25 + 2 * r) (91 + 7 * r) 1 (168 + 14 * r)
    (show (5 + 1 + 1)*(25 + 2*(r) + 1) = 91 + 7*(r) + (91 + 7*(r)) from NatNorm.sound [r] (.mul (.add (.add (.lit 5) (.lit 1)) (.lit 1)) (.add (.add (.lit 25) (.mul (.lit 2) (.var 0))) (.lit 1))) (.add (.add (.lit 91) (.mul (.lit 7) (.var 0))) (.add (.lit 91) (.mul (.lit 7) (.var 0)))) rfl)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_left 1 _))
    (by rw [(show (91 + 7*(r)) = (5 + 1 + 1)*1 + (1 + (83 + 7*(r))) from NatNorm.sound [r] (.add (.lit 91) (.mul (.lit 7) (.var 0))) (.add (.mul (.add (.add (.lit 5) (.lit 1)) (.lit 1)) (.lit 1)) (.add (.lit 1) (.add (.lit 83) (.mul (.lit 7) (.var 0))))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (5 + 1 + 1)*1 + (5 + 1 + 1)*1 + (168 + 14*(r)) = 91 + 7*(r) + (91 + 7*(r)) from NatNorm.sound [r] (.add (.add (.mul (.add (.add (.lit 5) (.lit 1)) (.lit 1)) (.lit 1)) (.mul (.add (.add (.lit 5) (.lit 1)) (.lit 1)) (.lit 1))) (.add (.lit 168) (.mul (.lit 14) (.var 0)))) (.add (.add (.lit 91) (.mul (.lit 7) (.var 0))) (.add (.lit 91) (.mul (.lit 7) (.var 0)))) rfl)


def co9 : List (Nat × Nat) := [(1, 0), (35, 2), (69, 4), (103, 6), (137, 8), (171, 10), (205, 12), (239, 14), (273, 16), (162, 9), (288, 18)]

set_option maxRecDepth 200000 in
theorem co9_ok : co9.all (small 306 18) = true ∧ (splitsG co9).all (chkSplit 306 18) = true := ⟨rfl, rfl⟩

set_option maxHeartbeats 8000000 in
set_option maxRecDepth 200000 in
theorem d9_list (r : Nat) : apL (7 + 1 + 1) 1 (33 + 2 * r + 1) ++ [(7 + 1 + 1) * 1 + (153 + 9 * r), 288 + 18 * r]
    = co9.map (ev r) := by
  show [1 + 0 * (33 + 2 * r + 1), 1 + 1 * (33 + 2 * r + 1), 1 + 2 * (33 + 2 * r + 1), 1 + 3 * (33 + 2 * r + 1), 1 + 4 * (33 + 2 * r + 1), 1 + 5 * (33 + 2 * r + 1), 1 + 6 * (33 + 2 * r + 1), 1 + 7 * (33 + 2 * r + 1), 1 + 8 * (33 + 2 * r + 1), (7 + 1 + 1) * 1 + (153 + 9 * r), 288 + 18 * r] = [1 + 0 * r, 35 + 2 * r, 69 + 4 * r, 103 + 6 * r, 137 + 8 * r, 171 + 10 * r, 205 + 12 * r, 239 + 14 * r, 273 +  -- (+35 chars; full line in the Zenodo source)
  rw [(show 1 + 0*(33 + 2*(r) + 1) = 1 + 0*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 0) (.add (.add (.lit 33) (.mul (.lit 2) (.var 0))) (.lit 1)))) (.add (.lit 1) (.mul (.lit 0) (.var 0))) rfl), (show 1 + 1*(33 + 2*(r) + 1) = 35 + 2*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 1) (.add (.add (.lit 33) (.mul (.lit 2) (.var 0))) (.lit 1)))) (.add (.lit 35) (.mul (.lit 2) (.var 0  -- (+1679 chars; full line in the Zenodo source)

set_option maxRecDepth 200000 in
/-- **d = 9: balanced and irreducible.** -/
theorem d9_both (r : Nat) :
    bal (153 + 9 * r + (153 + 9 * r)) (co9.map (ev r)) = true ∧
    indec (304 + 18 * r + 2) (co9.map (ev r)) = true := by
  refine ⟨?_, indec_lin _ 306 18 r (show 306 + 18*(r) = 304 + 18*(r) + 2 from NatNorm.sound [r] (.add (.lit 306) (.mul (.lit 18) (.var 0))) (.add (.add (.lit 304) (.mul (.lit 18) (.var 0))) (.lit 2)) rfl) co9 co9_ok.1 co9_ok.2⟩
  rw [← d9_list r]
  exact ap_double_bal 7 (33 + 2 * r) (153 + 9 * r) 1 (288 + 18 * r)
    (show (7 + 1 + 1)*(33 + 2*(r) + 1) = 153 + 9*(r) + (153 + 9*(r)) from NatNorm.sound [r] (.mul (.add (.add (.lit 7) (.lit 1)) (.lit 1)) (.add (.add (.lit 33) (.mul (.lit 2) (.var 0))) (.lit 1))) (.add (.add (.lit 153) (.mul (.lit 9) (.var 0))) (.add (.lit 153) (.mul (.lit 9) (.var 0)))) rfl)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_left 1 _))
    (by rw [(show (153 + 9*(r)) = (7 + 1 + 1)*1 + (1 + (143 + 9*(r))) from NatNorm.sound [r] (.add (.lit 153) (.mul (.lit 9) (.var 0))) (.add (.mul (.add (.add (.lit 7) (.lit 1)) (.lit 1)) (.lit 1)) (.add (.lit 1) (.add (.lit 143) (.mul (.lit 9) (.var 0))))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (7 + 1 + 1)*1 + (7 + 1 + 1)*1 + (288 + 18*(r)) = 153 + 9*(r) + (153 + 9*(r)) from NatNorm.sound [r] (.add (.add (.mul (.add (.add (.lit 7) (.lit 1)) (.lit 1)) (.lit 1)) (.mul (.add (.add (.lit 7) (.lit 1)) (.lit 1)) (.lit 1))) (.add (.lit 288) (.mul (.lit 18) (.var 0)))) (.add (.add (.lit 153) (.mul (.lit 9) (.var 0))) (.add (.lit 153) (.mul (.lit 9) (.var 0)))) rfl)


def co10 : List (Nat × Nat) := [(1, 0), (21, 1), (41, 2), (61, 3), (81, 4), (101, 5), (121, 6), (141, 7), (161, 8), (181, 9), (110, 5), (180, 10)]

set_option maxRecDepth 200000 in
theorem co10_ok : co10.all (small 200 10) = true ∧ (splitsG co10).all (chkSplit 200 10) = true := ⟨rfl, rfl⟩

set_option maxHeartbeats 8000000 in
set_option maxRecDepth 200000 in
theorem d10_list (r : Nat) : apL (8 + 1 + 1) 1 (19 + 1 * r + 1) ++ [(8 + 1 + 1) * 1 + (100 + 5 * r), 180 + 10 * r]
    = co10.map (ev r) := by
  show [1 + 0 * (19 + 1 * r + 1), 1 + 1 * (19 + 1 * r + 1), 1 + 2 * (19 + 1 * r + 1), 1 + 3 * (19 + 1 * r + 1), 1 + 4 * (19 + 1 * r + 1), 1 + 5 * (19 + 1 * r + 1), 1 + 6 * (19 + 1 * r + 1), 1 + 7 * (19 + 1 * r + 1), 1 + 8 * (19 + 1 * r + 1), 1 + 9 * (19 + 1 * r + 1), (8 + 1 + 1) * 1 + (100 + 5 * r), 180 + 10 * r] = [1 + 0 * r, 21 + 1 * r, 41 + 2 * r, 61 + 3 * r, 81 + 4 * r, 101 + 5 * r, 121 + 6 *   -- (+68 chars; full line in the Zenodo source)
  rw [(show 1 + 0*(19 + 1*(r) + 1) = 1 + 0*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 0) (.add (.add (.lit 19) (.mul (.lit 1) (.var 0))) (.lit 1)))) (.add (.lit 1) (.mul (.lit 0) (.var 0))) rfl), (show 1 + 1*(19 + 1*(r) + 1) = 21 + 1*(r) from NatNorm.sound [r] (.add (.lit 1) (.mul (.lit 1) (.add (.add (.lit 19) (.mul (.lit 1) (.var 0))) (.lit 1)))) (.add (.lit 21) (.mul (.lit 1) (.var 0  -- (+1872 chars; full line in the Zenodo source)

set_option maxRecDepth 200000 in
/-- **d = 10: balanced and irreducible.** -/
theorem d10_both (r : Nat) :
    bal (100 + 5 * r + (100 + 5 * r)) (co10.map (ev r)) = true ∧
    indec (198 + 10 * r + 2) (co10.map (ev r)) = true := by
  refine ⟨?_, indec_lin _ 200 10 r (show 200 + 10*(r) = 198 + 10*(r) + 2 from NatNorm.sound [r] (.add (.lit 200) (.mul (.lit 10) (.var 0))) (.add (.add (.lit 198) (.mul (.lit 10) (.var 0))) (.lit 2)) rfl) co10 co10_ok.1 co10_ok.2⟩
  rw [← d10_list r]
  exact ap_double_bal 8 (19 + 1 * r) (100 + 5 * r) 1 (180 + 10 * r)
    (show (8 + 1 + 1)*(19 + 1*(r) + 1) = 100 + 5*(r) + (100 + 5*(r)) from NatNorm.sound [r] (.mul (.add (.add (.lit 8) (.lit 1)) (.lit 1)) (.add (.add (.lit 19) (.mul (.lit 1) (.var 0))) (.lit 1))) (.add (.add (.lit 100) (.mul (.lit 5) (.var 0))) (.add (.lit 100) (.mul (.lit 5) (.var 0)))) rfl)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_left 1 _))
    (by rw [(show (100 + 5*(r)) = (8 + 1 + 1)*1 + (1 + (89 + 5*(r))) from NatNorm.sound [r] (.add (.lit 100) (.mul (.lit 5) (.var 0))) (.add (.mul (.add (.add (.lit 8) (.lit 1)) (.lit 1)) (.lit 1)) (.add (.lit 1) (.add (.lit 89) (.mul (.lit 5) (.var 0))))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (8 + 1 + 1)*1 + (8 + 1 + 1)*1 + (180 + 10*(r)) = 100 + 5*(r) + (100 + 5*(r)) from NatNorm.sound [r] (.add (.add (.mul (.add (.add (.lit 8) (.lit 1)) (.lit 1)) (.lit 1)) (.mul (.add (.add (.lit 8) (.lit 1)) (.lit 1)) (.lit 1))) (.add (.lit 180) (.mul (.lit 10) (.var 0)))) (.add (.add (.lit 100) (.mul (.lit 5) (.var 0))) (.add (.lit 100) (.mul (.lit 5) (.var 0)))) rfl)

end APDoubleMore

#print axioms APDoubleMore.d7_both
#print axioms APDoubleMore.d9_both
#print axioms APDoubleMore.d10_both

#print axioms: 3 theorems, no axioms.

81.63 Every start \(a\), \(d=2,3,6\)

Homogeneous in \((a,r)\): the coefficient lists serve unchanged in two variables. \(\text {bal}\wedge \text {indec}\ \text {for}\ q=10a+2r\ (d=3),\ q=13a+r\ (d=6)\)

hodge/APDoubleGenA.lean

/-
  hodge/APDoubleGenA.lean — T41 cycle 292 (goal G35): the APDouble character is balanced and irreducible for every
  start a ≥ 1, d = 2, 3, 6 here (7, 8: APDoubleGenA2, Kamiak), q = q₀a + q₁r: with every entry homogeneous in (a, r) the coefficient lists of
  APDoubleIrr/APDoubleMore serve unchanged (APPairIrrGen2.indec_lin2), and APDouble.ap_double_bal gives the balance.
-/
import hodge.APDoubleAll
import hodge.APDoubleMore
import hodge.APPairIrrGen2
import hodge.APDouble2
import lib.Semi

namespace APDoubleGenA
open Indecomp APPairIrrGen APPairIrrGen2 APDouble


set_option maxHeartbeats 8000000 in
set_option maxRecDepth 200000 in
theorem d3_list (k r : Nat) : apL (1 + 1 + 1) (k + 1) (10 * k + 2 * r + 9 + 1) ++ [(1 + 1 + 1) * (k + 1) + (15 * (k + 1) + 3 * r), 24 * (k + 1) + 6 * r]
    = APDoubleIrr.co3.map (ev2 (k + 1) r) := by
  show [(k + 1) + 0 * (10 * k + 2 * r + 9 + 1), (k + 1) + 1 * (10 * k + 2 * r + 9 + 1), (k + 1) + 2 * (10 * k + 2 * r + 9 + 1), (1 + 1 + 1) * (k + 1) + (15 * (k + 1) + 3 * r), 24 * (k + 1) + 6 * r] = [1 * (k + 1) + 0 * r, 11 * (k + 1) + 2 * r, 21 * (k + 1) + 4 * r, 18 * (k + 1) + 3 * r, 24 * (k + 1) + 6 * r]
  rw [(show ((k) + 1) + 0*(10*(k) + 2*(r) + 9 + 1) = 1*((k) + 1) + 0*(r) from NatNorm.sound [k, r] (.add (.add (.var 0) (.lit 1)) (.mul (.lit 0) (.add (.add (.add (.mul (.lit 10) (.var 0)) (.mul (.lit 2) (.var 1))) (.lit 9)) (.lit 1)))) (.add (.mul (.lit 1) (.add (.var 0) (.lit 1))) (.mul (.lit 0) (.var 1))) rfl), (show ((k) + 1) + 1*(10*(k) + 2*(r) + 9 + 1) = 11*((k) + 1) + 2*(r) from NatNorm.sou  -- (+875 chars; full line in the Zenodo source)

set_option maxRecDepth 200000 in
/-- **d = 3, start a = k + 1, q = 10a + 2r: balanced and irreducible.** -/
theorem d3_both (k r : Nat) :
    bal ((15 * (k + 1) + 3 * r) + (15 * (k + 1) + 3 * r)) (APDoubleIrr.co3.map (ev2 (k + 1) r)) = true ∧
    indec (30 * k + 6 * r + 28 + 2) (APDoubleIrr.co3.map (ev2 (k + 1) r)) = true := by
  refine ⟨?_, indec_lin2 _ 30 6 (k + 1) r (Nat.succ_pos k)
    (show 30*((k) + 1) + 6*(r) = 30*(k) + 6*(r) + 28 + 2 from NatNorm.sound [k, r] (.add (.mul (.lit 30) (.add (.var 0) (.lit 1))) (.mul (.lit 6) (.var 1))) (.add (.add (.add (.mul (.lit 30) (.var 0)) (.mul (.lit 6) (.var 1))) (.lit 28)) (.lit 2)) rfl) APDoubleIrr.co3 APDoubleIrr.co3_ok.1 APDoubleIrr.co3_ok.2⟩
  rw [← d3_list k r]
  exact ap_double_bal 1 (10 * k + 2 * r + 9) (15 * (k + 1) + 3 * r) (k + 1) (24 * (k + 1) + 6 * r)
    (show (1 + 1 + 1)*(10*(k) + 2*(r) + 9 + 1) = 15*((k) + 1) + 3*(r) + (15*((k) + 1) + 3*(r)) from NatNorm.sound [k, r] (.mul (.add (.add (.lit 1) (.lit 1)) (.lit 1)) (.add (.add (.add (.mul (.lit 10) (.var 0)) (.mul (.lit 2) (.var 1))) (.lit 9)) (.lit 1))) (.add (.add (.mul (.lit 15) (.add (.var 0) (.lit 1))) (.mul (.lit 3) (.var 1))) (.add (.mul (.lit 15) (.add (.var 0) (.lit 1))) (.mul (.lit 3  -- (+18 chars; full line in the Zenodo source)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (by rw [(show (1 + 1 + 1)*((k) + 1) = 1 + (2 + 3*(k)) from NatNorm.sound [k] (.mul (.add (.add (.lit 1) (.lit 1)) (.lit 1)) (.add (.var 0) (.lit 1))) (.add (.lit 1) (.add (.lit 2) (.mul (.lit 3) (.var 0)))) rfl)]; exact Nat.le_add_right 1 _))
    (by rw [(show 15*((k) + 1) + 3*(r) = (1 + 1 + 1)*((k) + 1) + (1 + (11 + 12*(k) + 3*(r))) from NatNorm.sound [k, r] (.add (.mul (.lit 15) (.add (.var 0) (.lit 1))) (.mul (.lit 3) (.var 1))) (.add (.mul (.add (.add (.lit 1) (.lit 1)) (.lit 1)) (.add (.var 0) (.lit 1))) (.add (.lit 1) (.add (.add (.lit 11) (.mul (.lit 12) (.var 0))) (.mul (.lit 3) (.var 1))))) rfl)]; exact Nat.lt_add_of_pos_right  -- (+62 chars; full line in the Zenodo source)
    (show (1 + 1 + 1)*((k) + 1) + (1 + 1 + 1)*((k) + 1) + (24*((k) + 1) + 6*(r)) = 15*((k) + 1) + 3*(r) + (15*((k) + 1) + 3*(r)) from NatNorm.sound [k, r] (.add (.add (.mul (.add (.add (.lit 1) (.lit 1)) (.lit 1)) (.add (.var 0) (.lit 1))) (.mul (.add (.add (.lit 1) (.lit 1)) (.lit 1)) (.add (.var 0) (.lit 1)))) (.add (.mul (.lit 24) (.add (.var 0) (.lit 1))) (.mul (.lit 6) (.var 1)))) (.add (.add  -- (+148 chars; full line in the Zenodo source)


set_option maxHeartbeats 8000000 in
set_option maxRecDepth 200000 in
theorem d6_list (k r : Nat) : apL (4 + 1 + 1) (k + 1) (13 * k + 1 * r + 12 + 1) ++ [(4 + 1 + 1) * (k + 1) + (39 * (k + 1) + 3 * r), 66 * (k + 1) + 6 * r]
    = APDoubleIrr.co6.map (ev2 (k + 1) r) := by
  show [(k + 1) + 0 * (13 * k + 1 * r + 12 + 1), (k + 1) + 1 * (13 * k + 1 * r + 12 + 1), (k + 1) + 2 * (13 * k + 1 * r + 12 + 1), (k + 1) + 3 * (13 * k + 1 * r + 12 + 1), (k + 1) + 4 * (13 * k + 1 * r + 12 + 1), (k + 1) + 5 * (13 * k + 1 * r + 12 + 1), (4 + 1 + 1) * (k + 1) + (39 * (k + 1) + 3 * r), 66 * (k + 1) + 6 * r] = [1 * (k + 1) + 0 * r, 14 * (k + 1) + 1 * r, 27 * (k + 1) + 2 * r, 40 * (k   -- (+101 chars; full line in the Zenodo source)
  rw [(show ((k) + 1) + 0*(13*(k) + 1*(r) + 12 + 1) = 1*((k) + 1) + 0*(r) from NatNorm.sound [k, r] (.add (.add (.var 0) (.lit 1)) (.mul (.lit 0) (.add (.add (.add (.mul (.lit 13) (.var 0)) (.mul (.lit 1) (.var 1))) (.lit 12)) (.lit 1)))) (.add (.mul (.lit 1) (.add (.var 0) (.lit 1))) (.mul (.lit 0) (.var 1))) rfl), (show ((k) + 1) + 1*(13*(k) + 1*(r) + 12 + 1) = 14*((k) + 1) + 1*(r) from NatNorm.  -- (+1823 chars; full line in the Zenodo source)

set_option maxRecDepth 200000 in
/-- **d = 6, start a = k + 1, q = 13a + 1r: balanced and irreducible.** -/
theorem d6_both (k r : Nat) :
    bal ((39 * (k + 1) + 3 * r) + (39 * (k + 1) + 3 * r)) (APDoubleIrr.co6.map (ev2 (k + 1) r)) = true ∧
    indec (78 * k + 6 * r + 76 + 2) (APDoubleIrr.co6.map (ev2 (k + 1) r)) = true := by
  refine ⟨?_, indec_lin2 _ 78 6 (k + 1) r (Nat.succ_pos k)
    (show 78*((k) + 1) + 6*(r) = 78*(k) + 6*(r) + 76 + 2 from NatNorm.sound [k, r] (.add (.mul (.lit 78) (.add (.var 0) (.lit 1))) (.mul (.lit 6) (.var 1))) (.add (.add (.add (.mul (.lit 78) (.var 0)) (.mul (.lit 6) (.var 1))) (.lit 76)) (.lit 2)) rfl) APDoubleIrr.co6 APDoubleIrr.co6_ok.1 APDoubleIrr.co6_ok.2⟩
  rw [← d6_list k r]
  exact ap_double_bal 4 (13 * k + 1 * r + 12) (39 * (k + 1) + 3 * r) (k + 1) (66 * (k + 1) + 6 * r)
    (show (4 + 1 + 1)*(13*(k) + 1*(r) + 12 + 1) = 39*((k) + 1) + 3*(r) + (39*((k) + 1) + 3*(r)) from NatNorm.sound [k, r] (.mul (.add (.add (.lit 4) (.lit 1)) (.lit 1)) (.add (.add (.add (.mul (.lit 13) (.var 0)) (.mul (.lit 1) (.var 1))) (.lit 12)) (.lit 1))) (.add (.add (.mul (.lit 39) (.add (.var 0) (.lit 1))) (.mul (.lit 3) (.var 1))) (.add (.mul (.lit 39) (.add (.var 0) (.lit 1))) (.mul (.lit  -- (+20 chars; full line in the Zenodo source)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (by rw [(show (4 + 1 + 1)*((k) + 1) = 1 + (5 + 6*(k)) from NatNorm.sound [k] (.mul (.add (.add (.lit 4) (.lit 1)) (.lit 1)) (.add (.var 0) (.lit 1))) (.add (.lit 1) (.add (.lit 5) (.mul (.lit 6) (.var 0)))) rfl)]; exact Nat.le_add_right 1 _))
    (by rw [(show 39*((k) + 1) + 3*(r) = (4 + 1 + 1)*((k) + 1) + (1 + (32 + 33*(k) + 3*(r))) from NatNorm.sound [k, r] (.add (.mul (.lit 39) (.add (.var 0) (.lit 1))) (.mul (.lit 3) (.var 1))) (.add (.mul (.add (.add (.lit 4) (.lit 1)) (.lit 1)) (.add (.var 0) (.lit 1))) (.add (.lit 1) (.add (.add (.lit 32) (.mul (.lit 33) (.var 0))) (.mul (.lit 3) (.var 1))))) rfl)]; exact Nat.lt_add_of_pos_right  -- (+62 chars; full line in the Zenodo source)
    (show (4 + 1 + 1)*((k) + 1) + (4 + 1 + 1)*((k) + 1) + (66*((k) + 1) + 6*(r)) = 39*((k) + 1) + 3*(r) + (39*((k) + 1) + 3*(r)) from NatNorm.sound [k, r] (.add (.add (.mul (.add (.add (.lit 4) (.lit 1)) (.lit 1)) (.add (.var 0) (.lit 1))) (.mul (.add (.add (.lit 4) (.lit 1)) (.lit 1)) (.add (.var 0) (.lit 1)))) (.add (.mul (.lit 66) (.add (.var 0) (.lit 1))) (.mul (.lit 6) (.var 1)))) (.add (.add  -- (+148 chars; full line in the Zenodo source)


/-- **d = 2, start a = k + 1, h = 5a + r: balanced and irreducible.** -/
theorem d2_both (k r : Nat) :
    bal ((5 * (k + 1) + r) + (5 * (k + 1) + r)) (APDouble2.co2.map (ev2 (k + 1) r)) = true ∧
    indec (10 * k + 2 * r + 8 + 2) (APDouble2.co2.map (ev2 (k + 1) r)) = true := by
  refine ⟨?_, indec_lin2 _ 10 2 (k + 1) r (Nat.succ_pos k) (by lib_nat) APDouble2.co2
    APDouble2.co2_ok.1 APDouble2.co2_ok.2⟩
  have hl : apL (0 + 1 + 1) (k + 1) (5 * k + r + 4 + 1) ++ [(0 + 1 + 1) * (k + 1) + (5 * (k + 1) + r), 6 * (k + 1) + 2 * r]
      = APDouble2.co2.map (ev2 (k + 1) r) := by
    show [(k + 1) + 0 * (5 * k + r + 4 + 1), (k + 1) + 1 * (5 * k + r + 4 + 1),
        (0 + 1 + 1) * (k + 1) + (5 * (k + 1) + r), 6 * (k + 1) + 2 * r]
      = [1 * (k + 1) + 0 * r, 6 * (k + 1) + 1 * r, 7 * (k + 1) + 1 * r, 6 * (k + 1) + 2 * r]
    rw [show (k + 1) + 0 * (5 * k + r + 4 + 1) = 1 * (k + 1) + 0 * r by lib_nat,
      show (k + 1) + 1 * (5 * k + r + 4 + 1) = 6 * (k + 1) + 1 * r by lib_nat,
      show (0 + 1 + 1) * (k + 1) + (5 * (k + 1) + r) = 7 * (k + 1) + 1 * r by lib_nat]
  rw [← hl]
  exact ap_double_bal 0 (5 * k + r + 4) (5 * (k + 1) + r) (k + 1) (6 * (k + 1) + 2 * r) (by lib_nat)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (by rw [show (0 + 1 + 1) * (k + 1) = 1 + (1 + 2 * k) by lib_nat]; exact Nat.le_add_right 1 _))
    (by rw [show 5 * (k + 1) + r = (0 + 1 + 1) * (k + 1) + (1 + (2 + 3 * k + r)) by lib_nat]
        exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (by lib_nat)

end APDoubleGenA
#print axioms APDoubleGenA.d3_both
#print axioms APDoubleGenA.d6_both
#print axioms APDoubleGenA.d2_both

#print axioms: 3 theorems, no axioms.

81.64 Irreducible Hodge characters for infinitely many \(m\), lengths 4, 5, 6, 7, 8, 10

Existence, with the explicit witness of the first pair family. \(\forall q\ge 8\ \exists c,\ |c|=6\wedge \text {bal}\,(4q)\,c\wedge \text {indec}\,(4q)\,c\)

hodge/ExistsIrr.lean

/-
  hodge/ExistsIrr.lean — T41 cycle 295 (goal G38): for every m = 4q ≥ 32 the Fermat variety has a balanced (Hodge)
  irreducible character of length 6, explicitly AP(m/4) + (m/2 + 4, m − 8).

  Lean 4 core plus hodge/APPairGen (ap_pair_bal_gen), hodge/APPairIrrGen (fam1_indec_q), lib/Semi (lib_nat).
-/
import hodge.APPairGen
import hodge.APPairIrrGen
import hodge.APDoubleAll
import hodge.APDoubleAll5
import hodge.APDouble2

namespace ExistsIrr
open Indecomp

theorem exists_irr (q : Nat) (hq : 8 ≤ q) :
    ∃ c : List Nat, c.length = 6 ∧ bal (4 * q) c = true ∧ indec (4 * q) c = true := by
  have ⟨r, hr⟩ := Nat.le.dest hq
  have hb : 8 * 1 + (24 + 4 * r) = 4 * q := by rw [← hr]; lib_nat
  have hb' : 8 + (24 + 4 * r) = 4 * q := by rw [← hr]; lib_nat
  refine ⟨[1, 1 + q, 1 + 2 * q, 1 + 3 * q, 2 * q + 4 * 1, 24 + 4 * r], rfl, ?_, ?_⟩
  · exact APPairGen.ap_pair_bal_gen q 1 (24 + 4 * r) (Nat.succ_pos 0)
      (Nat.lt_of_lt_of_le (Nat.lt_of_lt_of_le (Nat.lt_succ_self 2) (Nat.le_add_left 3 5)) hq) hb
  · have := APPairIrrGen.fam1_indec_q q (24 + 4 * r) hq hb'
    rw [show 2 * q + 4 * 1 = 2 * q + 4 by lib_nat]; exact this

/-- **Threefolds (length 5): every m = 30 + 6r.** -/
theorem exists_irr5 (r : Nat) :
    ∃ c : List Nat, c.length = 5 ∧ bal (30 + 6 * r) c = true ∧ indec (30 + 6 * r) c = true := by
  have ⟨h1, h2⟩ := APDoubleAll.d3_both r
  refine ⟨APDoubleIrr.co3.map (APPairIrrGen.ev r), rfl, ?_, ?_⟩
  · rw [show 30 + 6 * r = 15 + 3 * r + (15 + 3 * r) by lib_nat]; exact h1
  · rw [show 30 + 6 * r = 28 + 6 * r + 2 by lib_nat]; exact h2

/-- **Fivefolds (length 7): every m = 10p, p ≥ 9.** -/
theorem exists_irr7_even (r : Nat) :
    ∃ c : List Nat, c.length = 7 ∧ bal (100 + 20 * r) c = true ∧ indec (100 + 20 * r) c = true := by
  have ⟨h1, h2⟩ := APDoubleAll5.d5e_both r
  refine ⟨APDoubleIrr5.coE.map (APDoubleIrr5.evE r), rfl, ?_, ?_⟩
  · rw [show 100 + 20 * r = 50 + 10 * r + (50 + 10 * r) by lib_nat]; exact h1
  · rw [show 100 + 20 * r = 98 + 20 * r + 2 by lib_nat]; exact h2

theorem exists_irr7_odd (r : Nat) :
    ∃ c : List Nat, c.length = 7 ∧ bal (90 + 20 * r) c = true ∧ indec (90 + 20 * r) c = true := by
  have ⟨h1, h2⟩ := APDoubleAll5.d5o_both r
  refine ⟨APDoubleIrr5.coO.map (APDoubleIrr5.evE r), rfl, ?_, ?_⟩
  · rw [show 90 + 20 * r = 45 + 10 * r + (45 + 10 * r) by lib_nat]; exact h1
  · rw [show 90 + 20 * r = 88 + 20 * r + 2 by lib_nat]; exact h2

/-- **Length 8: every m = 78 + 6r.** -/
theorem exists_irr8 (r : Nat) :
    ∃ c : List Nat, c.length = 8 ∧ bal (78 + 6 * r) c = true ∧ indec (78 + 6 * r) c = true := by
  have ⟨h1, h2⟩ := APDoubleAll.d6_both r
  refine ⟨APDoubleIrr.co6.map (APPairIrrGen.ev r), rfl, ?_, ?_⟩
  · rw [show 78 + 6 * r = 39 + 3 * r + (39 + 3 * r) by lib_nat]; exact h1
  · rw [show 78 + 6 * r = 76 + 6 * r + 2 by lib_nat]; exact h2

/-- **Length 10: every m = 128 + 8r.** -/
theorem exists_irr10 (r : Nat) :
    ∃ c : List Nat, c.length = 10 ∧ bal (128 + 8 * r) c = true ∧ indec (128 + 8 * r) c = true := by
  have ⟨h1, h2⟩ := APDoubleAll.d8_both r
  refine ⟨APDoubleIrr.co8.map (APPairIrrGen.ev r), rfl, ?_, ?_⟩
  · rw [show 128 + 8 * r = 64 + 4 * r + (64 + 4 * r) by lib_nat]; exact h1
  · rw [show 128 + 8 * r = 126 + 8 * r + 2 by lib_nat]; exact h2

/-- **Length 4 (surfaces): every m = 10 + 2r.** -/
theorem exists_irr4 (r : Nat) :
    ∃ c : List Nat, c.length = 4 ∧ bal (10 + 2 * r) c = true ∧ indec (10 + 2 * r) c = true := by
  have ⟨h1, h2⟩ := APDouble2.d2_both r
  refine ⟨APDouble2.co2.map (APPairIrrGen.ev r), rfl, ?_, ?_⟩
  · rw [show 10 + 2 * r = 5 + r + (5 + r) by lib_nat]; exact h1
  · rw [show 10 + 2 * r = 8 + 2 * r + 2 by lib_nat]; exact h2

end ExistsIrr

#print axioms ExistsIrr.exists_irr
#print axioms ExistsIrr.exists_irr5
#print axioms ExistsIrr.exists_irr7_even
#print axioms ExistsIrr.exists_irr7_odd
#print axioms ExistsIrr.exists_irr8
#print axioms ExistsIrr.exists_irr10
#print axioms ExistsIrr.exists_irr4

#print axioms: 7 theorems, no axioms.

81.65 The case \(d=2\) (surfaces)

\([1,1+h,2+h,2h-4]\) is balanced and irreducible for every \(h\ge 5\). \(\text {bal}\wedge \text {indec}\ \text {for}\ m=10+2r\)

hodge/APDouble2.lean

/-
  hodge/APDouble2.lean — T41 cycle 299 (goal G42): the d = 2 APDouble character [1, 1+h, 2+h, 2h−4] (length 4, m = 2h)
  is balanced and irreducible for every h ≥ 5 (h = 5 + r), by APDouble.ap_double_bal and the t = 1 reflection.
  (Length 4 = Fermat surfaces, where these classes are algebraic by Lefschetz (1,1).)
-/
import hodge.APDouble
import hodge.APPairIrrGen

namespace APDouble2
open Indecomp APPairIrrGen APDouble

def co2 : List (Nat × Nat) := [(1, 0), (6, 1), (7, 1), (6, 2)]

theorem co2_ok : co2.all (small 10 2) = true ∧ (splitsG co2).all (chkSplit 10 2) = true := ⟨rfl, rfl⟩

theorem d2_list (r : Nat) : apL (0 + 1 + 1) 1 (4 + r + 1) ++ [(0 + 1 + 1) * 1 + (5 + r), 6 + 2 * r] = co2.map (ev r) := by
  show [1 + 0 * (4 + r + 1), 1 + 1 * (4 + r + 1), (0 + 1 + 1) * 1 + (5 + r), 6 + 2 * r]
    = [1 + 0 * r, 6 + 1 * r, 7 + 1 * r, 6 + 2 * r]
  rw [show 1 + 0 * (4 + r + 1) = 1 + 0 * r by lib_nat, show 1 + 1 * (4 + r + 1) = 6 + 1 * r by lib_nat,
    show (0 + 1 + 1) * 1 + (5 + r) = 7 + 1 * r by lib_nat]

theorem d2_both (r : Nat) :
    bal (5 + r + (5 + r)) (co2.map (ev r)) = true ∧ indec (8 + 2 * r + 2) (co2.map (ev r)) = true := by
  refine ⟨?_, indec_lin _ 10 2 r (by lib_nat) co2 co2_ok.1 co2_ok.2⟩
  rw [← d2_list r]
  exact ap_double_bal 0 (4 + r) (5 + r) 1 (6 + 2 * r) (by lib_nat)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_left 1 _))
    (by rw [show 5 + r = (0 + 1 + 1) * 1 + (1 + (2 + r)) by lib_nat]
        exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (by lib_nat)

end APDouble2

#print axioms APDouble2.d2_both

#print axioms: 1 theorem, no axioms.

81.66 Unreached characters at \(m=112\)

Eight Galois orbits (84 characters), all irreducible; two AP orbits are the first pair family with \(a=1,2\). \(8\ \text {orbits},\ 84,\ \text {all irreducible}\)

hodge/Unreached112.lean

/-
  hodge/Unreached112.lean — T41 cycle 300 (goal G18): the unreached characters of length 6 at m = 112 (a2_reach112,
  work/data/ckpt/agent2_T41/reach/all_112.jsonl).

  Lean 4 core plus hodge/Unreached80 (hasAP), hodge/OrbitDecomp (union), hodge/Indecomp (indec), rfl.
    size112, irr112     8 Galois orbits give the 84 unreached characters, all irreducible
    ap112               3 of the orbits (24 characters) carry an AP of step 28; two are the first pair family
                        (a = 1: [1, 29, 57, 85, 60, 104]; a = 2: [2, 30, 58, 86, 64, 96]) — balanced and irreducible
                        for all sizes by APPairGen / APPairIrrGen2 / TwistIndec
-/
import hodge.Unreached80

namespace Unreached112
open Orbits Indecomp OrbitDecomp Unreached80

def reps112 : List (List Nat) := [[1,  29,  57,  60,  85,  104],  [2,  18,  58,  74,  84,  100],  [2,  20,  58,  72,  84,  100],  [2,  30,  58,  64,  86,  96],  [2,  30,  58,  72,  86,  88],  [2,  36,  42,  58,  98,  100],  [2,  36,  58,  68,  84,  88],  [4,  20,  42,  68,  98,  104]]
def apreps112 : List (List Nat) := [[1,  29,  57,  60,  85,  104],  [2,  30,  58,  64,  86,  96],  [2,  30,  58,  72,  86,  88]]

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size112 : Nat.beq (union 112 reps112).length 84 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr112 : (union 112 reps112).all (indec 112) = true := rfl

set_option maxRecDepth 400000 in
theorem ap112 : Nat.beq (union 112 apreps112).length 24 = true && (union 112 apreps112).all (hasAP 112) = true := rfl

end Unreached112

#print axioms Unreached112.size112
#print axioms Unreached112.irr112
#print axioms Unreached112.ap112

#print axioms: 3 theorems, no axioms.

81.67 Unreached characters at \(m=120\)

Six AP orbits (44 characters, one the first pair family) and 24 reducible ones (\(60\) plus a 5-list) among 670. \(|\,\text {AP orbits}\,|=44,\quad c=60::c'\)

hodge/Unreached120.lean

/-
  hodge/Unreached120.lean — T41 cycle 301 (goal G18, m = 120): the AP orbits and the reducible characters among the
  670 unreached length-6 characters at m = 120 (a2_reach112, all_120.jsonl; 50 orbits, 646 irreducible).

  Lean 4 core plus hodge/Unreached80 (hasAP), hodge/OrbitDecomp (union), hodge/HalfSplit (rest), rfl.
    size120ap, irr120ap, ap120   6 orbits give 44 unreached characters with an AP of step 30, all irreducible
                                 ([1, 31, 61, 91, 64, 112] is the first pair family, a = 1)
    red120_ok, red120_count      the 24 reducible ones are 60 plus an irreducible balanced 5-list
  The full set (670 characters, 50 orbits): hodge/OrbitDecomp6 (Kamiak).
-/
import hodge.Unreached80

namespace Unreached120
open Orbits Indecomp OrbitDecomp HalfSplit Unreached80

def apreps120 : List (List Nat) := [[1,  31,  61,  64,  91,  112],  [1,  31,  61,  68,  91,  108],  [1,  31,  61,  76,  91,  100],  [1,  31,  61,  84,  91,  92],  [3,  33,  52,  63,  93,  116],  [3,  33,  63,  64,  93,  104]]

set_option maxRecDepth 400000 in
theorem size120ap : Nat.beq (union 120 apreps120).length 44 = true := rfl

set_option maxRecDepth 400000 in
theorem irr120ap : (union 120 apreps120).all (indec 120) = true := rfl

set_option maxRecDepth 400000 in
theorem ap120 : (union 120 apreps120).all (hasAP 120) = true := rfl

def red120 : List (List Nat) := [[1,  41,  60,  63,  96,  99],  [1,  49,  60,  73,  80,  97],  [3,  17,  60,  72,  97,  111],  [3,  39,  60,  61,  96,  101],  [7,  31,  60,  79,  80,  103],  [7,  47,  60,  72,  81,  93],  [9,  11,  60,  91,  93,  96],  [9,  23,  48,  60,  103,  117],  [11,  40,  59,  60,  83,  107],  [13,  37,  60,  61,  80,  109],  [13,  48,  53,  60,  87,  99],  [17,  40,  41,    -- (+407 chars; full line in the Zenodo source)

set_option maxRecDepth 100000 in
theorem red120_ok : red120.all (fun c => c.any (fun a => Nat.beq a 60) && bal 120 (rest 120 c) && indec 120 (rest 120 c)
    && !(indec 120 c)) = true := rfl

theorem red120_count : red120.length = 24 := rfl

end Unreached120

#print axioms Unreached120.size120ap
#print axioms Unreached120.irr120ap
#print axioms Unreached120.ap120
#print axioms Unreached120.red120_ok
#print axioms Unreached120.red120_count

#print axioms: 5 theorems, no axioms.

81.68 Balanced and irreducible, \(d=11,12\)

The same reflection over 8192 and 16384 splittings (checked on Kamiak). \(\text {bal}\wedge \text {indec}\ \text {for}\ m=462+22r,\ 288+12r\)

hodge/APDoubleMore2.lean

/-
  hodge/APDoubleMore2.lean — T41 cycle 298 (goal G41, Kamiak): the APDouble character (a = 1) is balanced and
  irreducible for d = 11 (q = 42 + 2r) and d = 12 (q = 24 + r), every r — t = 1 reflection over 8192 and 16384
  splittings (rfl, checked on Kamiak) and APDouble.ap_double_bal.
-/
import hodge.APDouble
import hodge.APPairIrrGen
import lib.Semi

namespace APDoubleMore2
open Indecomp APPairIrrGen APDouble


def co11 : List (Nat × Nat) := [(1, 0), (43, 2), (85, 4), (127, 6), (169, 8), (211, 10), (253, 12), (295, 14), (337, 16), (379, 18), (421, 20), (242, 11), (440, 22)]

set_option maxRecDepth 2000000 in
theorem co11_ok : co11.all (small 462 22) = true ∧ (splitsG co11).all (chkSplit 462 22) = true := ⟨rfl, rfl⟩

set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
theorem d11_list (r : Nat) : apL (9 + 1 + 1) 1 (41 + 2 * r + 1) ++ [(9 + 1 + 1) * 1 + (231 + 11 * r), 440 + 22 * r]
    = co11.map (ev r) := by
  show [1 + 0 * (41 + 2 * r + 1), 1 + 1 * (41 + 2 * r + 1), 1 + 2 * (41 + 2 * r + 1), 1 + 3 * (41 + 2 * r + 1), 1 + 4 * (41 + 2 * r + 1), 1 + 5 * (41 + 2 * r + 1), 1 + 6 * (41 + 2 * r + 1), 1 + 7 * (41 + 2 * r + 1), 1 + 8 * (41 + 2 * r + 1), 1 + 9 * (41 + 2 * r + 1), 1 + 10 * (41 + 2 * r + 1), (9 + 1 + 1) * 1 + (231 + 11 * r), 440 + 22 * r] = [1 + 0 * r, 43 + 2 * r, 85 + 4 * r, 127 + 6 * r, 169 +   -- (+118 chars; full line in the Zenodo source)
  rw [(show 1 + 0*(41 + 2*(r) + 1) = 1 + 0*(r) by lib_nat), (show 1 + 1*(41 + 2*(r) + 1) = 43 + 2*(r) by lib_nat), (show 1 + 2*(41 + 2*(r) + 1) = 85 + 4*(r) by lib_nat), (show 1 + 3*(41 + 2*(r) + 1) = 127 + 6*(r) by lib_nat), (show 1 + 4*(41 + 2*(r) + 1) = 169 + 8*(r) by lib_nat), (show 1 + 5*(41 + 2*(r) + 1) = 211 + 10*(r) by lib_nat), (show 1 + 6*(41 + 2*(r) + 1) = 253 + 12*(r) by lib_nat), (sho  -- (+289 chars; full line in the Zenodo source)

set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
theorem d11_both (r : Nat) :
    bal (231 + 11 * r + (231 + 11 * r)) (co11.map (ev r)) = true ∧
    indec (460 + 22 * r + 2) (co11.map (ev r)) = true := by
  refine ⟨?_, indec_lin _ 462 22 r (show 462 + 22*(r) = 460 + 22*(r) + 2 by lib_nat) co11 co11_ok.1 co11_ok.2⟩
  rw [← d11_list r]
  exact ap_double_bal 9 (41 + 2 * r) (231 + 11 * r) 1 (440 + 22 * r)
    (show (9 + 1 + 1)*(41 + 2*(r) + 1) = 231 + 11*(r) + (231 + 11*(r)) by lib_nat)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_left 1 _))
    (by rw [(show (231 + 11*(r)) = (9 + 1 + 1)*1 + (1 + (219 + 11*(r))) by lib_nat)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (9 + 1 + 1)*1 + (9 + 1 + 1)*1 + (440 + 22*(r)) = 231 + 11*(r) + (231 + 11*(r)) by lib_nat)


def co12 : List (Nat × Nat) := [(1, 0), (25, 1), (49, 2), (73, 3), (97, 4), (121, 5), (145, 6), (169, 7), (193, 8), (217, 9), (241, 10), (265, 11), (156, 6), (264, 12)]

set_option maxRecDepth 2000000 in
theorem co12_ok : co12.all (small 288 12) = true ∧ (splitsG co12).all (chkSplit 288 12) = true := ⟨rfl, rfl⟩

set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
theorem d12_list (r : Nat) : apL (10 + 1 + 1) 1 (23 + 1 * r + 1) ++ [(10 + 1 + 1) * 1 + (144 + 6 * r), 264 + 12 * r]
    = co12.map (ev r) := by
  show [1 + 0 * (23 + 1 * r + 1), 1 + 1 * (23 + 1 * r + 1), 1 + 2 * (23 + 1 * r + 1), 1 + 3 * (23 + 1 * r + 1), 1 + 4 * (23 + 1 * r + 1), 1 + 5 * (23 + 1 * r + 1), 1 + 6 * (23 + 1 * r + 1), 1 + 7 * (23 + 1 * r + 1), 1 + 8 * (23 + 1 * r + 1), 1 + 9 * (23 + 1 * r + 1), 1 + 10 * (23 + 1 * r + 1), 1 + 11 * (23 + 1 * r + 1), (10 + 1 + 1) * 1 + (144 + 6 * r), 264 + 12 * r] = [1 + 0 * r, 25 + 1 * r, 49 +  -- (+151 chars; full line in the Zenodo source)
  rw [(show 1 + 0*(23 + 1*(r) + 1) = 1 + 0*(r) by lib_nat), (show 1 + 1*(23 + 1*(r) + 1) = 25 + 1*(r) by lib_nat), (show 1 + 2*(23 + 1*(r) + 1) = 49 + 2*(r) by lib_nat), (show 1 + 3*(23 + 1*(r) + 1) = 73 + 3*(r) by lib_nat), (show 1 + 4*(23 + 1*(r) + 1) = 97 + 4*(r) by lib_nat), (show 1 + 5*(23 + 1*(r) + 1) = 121 + 5*(r) by lib_nat), (show 1 + 6*(23 + 1*(r) + 1) = 145 + 6*(r) by lib_nat), (show 1   -- (+339 chars; full line in the Zenodo source)

set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
theorem d12_both (r : Nat) :
    bal (144 + 6 * r + (144 + 6 * r)) (co12.map (ev r)) = true ∧
    indec (286 + 12 * r + 2) (co12.map (ev r)) = true := by
  refine ⟨?_, indec_lin _ 288 12 r (show 288 + 12*(r) = 286 + 12*(r) + 2 by lib_nat) co12 co12_ok.1 co12_ok.2⟩
  rw [← d12_list r]
  exact ap_double_bal 10 (23 + 1 * r) (144 + 6 * r) 1 (264 + 12 * r)
    (show (10 + 1 + 1)*(23 + 1*(r) + 1) = 144 + 6*(r) + (144 + 6*(r)) by lib_nat)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_left 1 _))
    (by rw [(show (144 + 6*(r)) = (10 + 1 + 1)*1 + (1 + (131 + 6*(r))) by lib_nat)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (10 + 1 + 1)*1 + (10 + 1 + 1)*1 + (264 + 12*(r)) = 144 + 6*(r) + (144 + 6*(r)) by lib_nat)

end APDoubleMore2

#print axioms APDoubleMore2.d11_both
#print axioms APDoubleMore2.d12_both

#print axioms: 2 theorems, no axioms.

81.69 Orbit decomposition, \(m=120\)

The 670 unreached characters at \(m=120\) form 50 Galois orbits. \(50\ \text {orbits},\ 670,\ 646\ \text {irreducible}\)

hodge/OrbitDecomp6.lean

/-
  hodge/OrbitDecomp6.lean — T41 cycle 301: Galois orbit decomposition of the full unreached set at m = 120.

  Lean 4 core plus hodge/OrbitDecomp (union), hodge/Indecomp (indec), rfl (Kamiak). The twist orbits of the 50
  representatives give the 670 unreached characters of length 6 at m = 120 (all_120.jsonl); 646 of them have no
  balanced splitting (the other 24: Unreached120.red120).
-/
import hodge.OrbitDecomp

namespace OrbitDecomp6
open Orbits Indecomp OrbitDecomp

def reps120 : List (List Nat) := [[1,  6,  19,  99,  117,  118],  [1,  11,  26,  97,  107,  118],  [1,  19,  42,  82,  99,  117],  [1,  22,  49,  73,  97,  118],  [1,  24,  49,  73,  97,  116],  [1,  25,  49,  61,  109,  115],  [1,  27,  31,  77,  107,  117],  [1,  30,  49,  61,  109,  110],  [1,  30,  49,  73,  97,  110],  [1,  31,  61,  64,  91,  112],  [1,  31,  61,  68,  91,  108],  [1,  31,    -- (+1237 chars; full line in the Zenodo source)

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size120 : Nat.beq (union 120 reps120).length 670 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr120 : Nat.beq ((union 120 reps120).filter (indec 120)).length 646 = true := rfl

end OrbitDecomp6

#print axioms OrbitDecomp6.size120
#print axioms OrbitDecomp6.irr120

#print axioms: 2 theorems, no axioms.

81.70 Every start \(a\), \(d=7,8\)

Checked on Kamiak. \(\text {bal}\wedge \text {indec}\ \text {for}\ q=26a+2r\ (d=7),\ q=16a+r\ (d=8)\)

hodge/APDoubleGenA2.lean

/-
  hodge/APDoubleGenA2.lean — T41 cycle 292 (goal G35, Kamiak part): the APDouble character is balanced and irreducible for every
  start a ≥ 1, d = 7, 8 (d = 9, 10: kernel timeout on the list matching), q = q₀a + q₁r: with every entry homogeneous in (a, r) the coefficient lists of
  APDoubleIrr/APDoubleMore serve unchanged (APPairIrrGen2.indec_lin2), and APDouble.ap_double_bal gives the balance.
-/
import hodge.APDoubleAll
import hodge.APDoubleMore
import hodge.APPairIrrGen2
import lib.Semi

namespace APDoubleGenA2
open Indecomp APPairIrrGen APPairIrrGen2 APDouble


set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
theorem d7_list (k r : Nat) : apL (5 + 1 + 1) (k + 1) (26 * k + 2 * r + 25 + 1) ++ [(5 + 1 + 1) * (k + 1) + (91 * (k + 1) + 7 * r), 168 * (k + 1) + 14 * r]
    = APDoubleMore.co7.map (ev2 (k + 1) r) := by
  show [(k + 1) + 0 * (26 * k + 2 * r + 25 + 1), (k + 1) + 1 * (26 * k + 2 * r + 25 + 1), (k + 1) + 2 * (26 * k + 2 * r + 25 + 1), (k + 1) + 3 * (26 * k + 2 * r + 25 + 1), (k + 1) + 4 * (26 * k + 2 * r + 25 + 1), (k + 1) + 5 * (26 * k + 2 * r + 25 + 1), (k + 1) + 6 * (26 * k + 2 * r + 25 + 1), (5 + 1 + 1) * (k + 1) + (91 * (k + 1) + 7 * r), 168 * (k + 1) + 14 * r] = [1 * (k + 1) + 0 * r, 27 * (k +  -- (+173 chars; full line in the Zenodo source)
  rw [(show ((k) + 1) + 0*(26*(k) + 2*(r) + 25 + 1) = 1*((k) + 1) + 0*(r) by lib_nat), (show ((k) + 1) + 1*(26*(k) + 2*(r) + 25 + 1) = 27*((k) + 1) + 2*(r) by lib_nat), (show ((k) + 1) + 2*(26*(k) + 2*(r) + 25 + 1) = 53*((k) + 1) + 4*(r) by lib_nat), (show ((k) + 1) + 3*(26*(k) + 2*(r) + 25 + 1) = 79*((k) + 1) + 6*(r) by lib_nat), (show ((k) + 1) + 4*(26*(k) + 2*(r) + 25 + 1) = 105*((k) + 1) + 8*(  -- (+272 chars; full line in the Zenodo source)

set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
/-- **d = 7, start a = k + 1, q = 26a + 2r: balanced and irreducible.** -/
theorem d7_both (k r : Nat) :
    bal ((91 * (k + 1) + 7 * r) + (91 * (k + 1) + 7 * r)) (APDoubleMore.co7.map (ev2 (k + 1) r)) = true ∧
    indec (182 * k + 14 * r + 180 + 2) (APDoubleMore.co7.map (ev2 (k + 1) r)) = true := by
  refine ⟨?_, indec_lin2 _ 182 14 (k + 1) r (Nat.succ_pos k)
    (show 182*((k) + 1) + 14*(r) = 182*(k) + 14*(r) + 180 + 2 by lib_nat) APDoubleMore.co7 APDoubleMore.co7_ok.1 APDoubleMore.co7_ok.2⟩
  rw [← d7_list k r]
  exact ap_double_bal 5 (26 * k + 2 * r + 25) (91 * (k + 1) + 7 * r) (k + 1) (168 * (k + 1) + 14 * r)
    (show (5 + 1 + 1)*(26*(k) + 2*(r) + 25 + 1) = 91*((k) + 1) + 7*(r) + (91*((k) + 1) + 7*(r)) by lib_nat)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (by rw [(show (5 + 1 + 1)*((k) + 1) = 1 + (6 + 7*(k)) by lib_nat)]; exact Nat.le_add_right 1 _))
    (by rw [(show 91*((k) + 1) + 7*(r) = (5 + 1 + 1)*((k) + 1) + (1 + (83 + 84*(k) + 7*(r))) by lib_nat)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (5 + 1 + 1)*((k) + 1) + (5 + 1 + 1)*((k) + 1) + (168*((k) + 1) + 14*(r)) = 91*((k) + 1) + 7*(r) + (91*((k) + 1) + 7*(r)) by lib_nat)


set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
theorem d8_list (k r : Nat) : apL (6 + 1 + 1) (k + 1) (16 * k + 1 * r + 15 + 1) ++ [(6 + 1 + 1) * (k + 1) + (64 * (k + 1) + 4 * r), 112 * (k + 1) + 8 * r]
    = APDoubleIrr.co8.map (ev2 (k + 1) r) := by
  show [(k + 1) + 0 * (16 * k + 1 * r + 15 + 1), (k + 1) + 1 * (16 * k + 1 * r + 15 + 1), (k + 1) + 2 * (16 * k + 1 * r + 15 + 1), (k + 1) + 3 * (16 * k + 1 * r + 15 + 1), (k + 1) + 4 * (16 * k + 1 * r + 15 + 1), (k + 1) + 5 * (16 * k + 1 * r + 15 + 1), (k + 1) + 6 * (16 * k + 1 * r + 15 + 1), (k + 1) + 7 * (16 * k + 1 * r + 15 + 1), (6 + 1 + 1) * (k + 1) + (64 * (k + 1) + 4 * r), 112 * (k + 1) +   -- (+230 chars; full line in the Zenodo source)
  rw [(show ((k) + 1) + 0*(16*(k) + 1*(r) + 15 + 1) = 1*((k) + 1) + 0*(r) by lib_nat), (show ((k) + 1) + 1*(16*(k) + 1*(r) + 15 + 1) = 17*((k) + 1) + 1*(r) by lib_nat), (show ((k) + 1) + 2*(16*(k) + 1*(r) + 15 + 1) = 33*((k) + 1) + 2*(r) by lib_nat), (show ((k) + 1) + 3*(16*(k) + 1*(r) + 15 + 1) = 49*((k) + 1) + 3*(r) by lib_nat), (show ((k) + 1) + 4*(16*(k) + 1*(r) + 15 + 1) = 65*((k) + 1) + 4*(r  -- (+350 chars; full line in the Zenodo source)

set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
/-- **d = 8, start a = k + 1, q = 16a + 1r: balanced and irreducible.** -/
theorem d8_both (k r : Nat) :
    bal ((64 * (k + 1) + 4 * r) + (64 * (k + 1) + 4 * r)) (APDoubleIrr.co8.map (ev2 (k + 1) r)) = true ∧
    indec (128 * k + 8 * r + 126 + 2) (APDoubleIrr.co8.map (ev2 (k + 1) r)) = true := by
  refine ⟨?_, indec_lin2 _ 128 8 (k + 1) r (Nat.succ_pos k)
    (show 128*((k) + 1) + 8*(r) = 128*(k) + 8*(r) + 126 + 2 by lib_nat) APDoubleIrr.co8 APDoubleIrr.co8_ok.1 APDoubleIrr.co8_ok.2⟩
  rw [← d8_list k r]
  exact ap_double_bal 6 (16 * k + 1 * r + 15) (64 * (k + 1) + 4 * r) (k + 1) (112 * (k + 1) + 8 * r)
    (show (6 + 1 + 1)*(16*(k) + 1*(r) + 15 + 1) = 64*((k) + 1) + 4*(r) + (64*((k) + 1) + 4*(r)) by lib_nat)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (by rw [(show (6 + 1 + 1)*((k) + 1) = 1 + (7 + 8*(k)) by lib_nat)]; exact Nat.le_add_right 1 _))
    (by rw [(show 64*((k) + 1) + 4*(r) = (6 + 1 + 1)*((k) + 1) + (1 + (55 + 56*(k) + 4*(r))) by lib_nat)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1 _)))
    (show (6 + 1 + 1)*((k) + 1) + (6 + 1 + 1)*((k) + 1) + (112*((k) + 1) + 8*(r)) = 64*((k) + 1) + 4*(r) + (64*((k) + 1) + 4*(r)) by lib_nat)



end APDoubleGenA2
#print axioms APDoubleGenA2.d7_both
#print axioms APDoubleGenA2.d8_both

#print axioms: 2 theorems, no axioms.

81.71 Every start \(a\), \(d=9,10\)

With a linear normaliser keeping numeric coefficients (lib/LinNorm). \(\text {bal}\wedge \text {indec}\ \text {for}\ q=34a+2r\ (d=9),\ q=20a+r\ (d=10)\)

hodge/APDoubleGenA3.lean

/-
  hodge/APDoubleGenA3.lean — T41 cycle 310 (goal G48): d = 9 (q = 34a + 2r) and d = 10 (q = 20a + r), every start
  a ≥ 1: balanced and irreducible. As APDoubleGenA2, with the linear identities checked by lib/LinNorm (numeric
  coefficients; NatNorm and lib_nat timed out in the kernel on the large numerals).
-/
import hodge.APDoubleMore
import hodge.APPairIrrGen2
import lib.LinNorm

namespace APDoubleGenA3
open Indecomp APPairIrrGen APPairIrrGen2 APDouble


set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
theorem d9_list (k r : Nat) : apL (7 + 1 + 1) (k + 1) (34 * k + 2 * r + 33 + 1) ++ [(7 + 1 + 1) * (k + 1) + (153 * (k + 1) + 9 * r), 288 * (k + 1) + 18 * r]
    = APDoubleMore.co9.map (ev2 (k + 1) r) := by
  show [(k + 1) + 0 * (34 * k + 2 * r + 33 + 1), (k + 1) + 1 * (34 * k + 2 * r + 33 + 1), (k + 1) + 2 * (34 * k + 2 * r + 33 + 1), (k + 1) + 3 * (34 * k + 2 * r + 33 + 1), (k + 1) + 4 * (34 * k + 2 * r + 33 + 1), (k + 1) + 5 * (34 * k + 2 * r + 33 + 1), (k + 1) + 6 * (34 * k + 2 * r + 33 + 1), (k + 1) + 7 * (34 * k + 2 * r + 33 + 1), (k + 1) + 8 * (34 * k + 2 * r + 33 + 1), (7 + 1 + 1) * (k + 1) +  -- (+306 chars; full line in the Zenodo source)
  rw [(show ((k) + 1) + 0*(34*(k) + 2*(r) + 33 + 1) = 1*((k) + 1) + 0*(r) from LinNorm.sound [k, r] 2 (.add (.add (.var 0) (.lit 1)) (.smul 0 (.add (.add (.add (.smul 34 (.var 0)) (.smul 2 (.var 1))) (.lit 33)) (.lit 1)))) (.add (.smul 1 (.add (.var 0) (.lit 1))) (.smul 0 (.var 1))) rfl), (show ((k) + 1) + 1*(34*(k) + 2*(r) + 33 + 1) = 35*((k) + 1) + 2*(r) from LinNorm.sound [k, r] 2 (.add (.add (  -- (+2477 chars; full line in the Zenodo source)

set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
theorem d9_both (k r : Nat) :
    bal ((153 * (k + 1) + 9 * r) + (153 * (k + 1) + 9 * r)) (APDoubleMore.co9.map (ev2 (k + 1) r)) = true ∧
    indec (306 * k + 18 * r + 304 + 2) (APDoubleMore.co9.map (ev2 (k + 1) r)) = true := by
  refine ⟨?_, indec_lin2 _ 306 18 (k + 1) r (Nat.succ_pos k)
    (show 306*((k) + 1) + 18*(r) = 306*(k) + 18*(r) + 304 + 2 from LinNorm.sound [k, r] 2 (.add (.smul 306 (.add (.var 0) (.lit 1))) (.smul 18 (.var 1))) (.add (.add (.add (.smul 306 (.var 0)) (.smul 18 (.var 1))) (.lit 304)) (.lit 2)) rfl) APDoubleMore.co9 APDoubleMore.co9_ok.1 APDoubleMore.co9_ok.2⟩
  rw [← d9_list k r]
  exact ap_double_bal 7 (34 * k + 2 * r + 33) (153 * (k + 1) + 9 * r) (k + 1) (288 * (k + 1) + 18 * r)
    (show (7 + 1 + 1)*(34*(k) + 2*(r) + 33 + 1) = 153*((k) + 1) + 9*(r) + (153*((k) + 1) + 9*(r)) from LinNorm.sound [k, r] 2 (.smul 9 (.add (.add (.add (.smul 34 (.var 0)) (.smul 2 (.var 1))) (.lit 33)) (.lit 1))) (.add (.add (.smul 153 (.add (.var 0) (.lit 1))) (.smul 9 (.var 1))) (.add (.smul 153 (.add (.var 0) (.lit 1))) (.smul 9 (.var 1)))) rfl)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (by rw [(show (7 + 1 + 1)*((k) + 1) = 1 + (8 + 9*(k)) from LinNorm.sound [k] 1 (.smul 9 (.add (.var 0) (.lit 1))) (.add (.lit 1) (.add (.lit 8) (.smul 9 (.var 0)))) rfl)]; exact Nat.le_add_right 1 _))
    (by rw [(show 153*((k) + 1) + 9*(r) = (7 + 1 + 1)*((k) + 1) + (1 + (143 + 144*(k) + 9*(r))) from LinNorm.sound [k, r] 2 (.add (.smul 153 (.add (.var 0) (.lit 1))) (.smul 9 (.var 1))) (.add (.smul 9 (.add (.var 0) (.lit 1))) (.add (.lit 1) (.add (.add (.lit 143) (.smul 144 (.var 0))) (.smul 9 (.var 1))))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_righ  -- (+8 chars; full line in the Zenodo source)
    (show (7 + 1 + 1)*((k) + 1) + (7 + 1 + 1)*((k) + 1) + (288*((k) + 1) + 18*(r)) = 153*((k) + 1) + 9*(r) + (153*((k) + 1) + 9*(r)) from LinNorm.sound [k, r] 2 (.add (.add (.smul 9 (.add (.var 0) (.lit 1))) (.smul 9 (.add (.var 0) (.lit 1)))) (.add (.smul 288 (.add (.var 0) (.lit 1))) (.smul 18 (.var 1)))) (.add (.add (.smul 153 (.add (.var 0) (.lit 1))) (.smul 9 (.var 1))) (.add (.smul 153 (.add  -- (+46 chars; full line in the Zenodo source)


set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
theorem d10_list (k r : Nat) : apL (8 + 1 + 1) (k + 1) (20 * k + 1 * r + 19 + 1) ++ [(8 + 1 + 1) * (k + 1) + (100 * (k + 1) + 5 * r), 180 * (k + 1) + 10 * r]
    = APDoubleMore.co10.map (ev2 (k + 1) r) := by
  show [(k + 1) + 0 * (20 * k + 1 * r + 19 + 1), (k + 1) + 1 * (20 * k + 1 * r + 19 + 1), (k + 1) + 2 * (20 * k + 1 * r + 19 + 1), (k + 1) + 3 * (20 * k + 1 * r + 19 + 1), (k + 1) + 4 * (20 * k + 1 * r + 19 + 1), (k + 1) + 5 * (20 * k + 1 * r + 19 + 1), (k + 1) + 6 * (20 * k + 1 * r + 19 + 1), (k + 1) + 7 * (20 * k + 1 * r + 19 + 1), (k + 1) + 8 * (20 * k + 1 * r + 19 + 1), (k + 1) + 9 * (20 * k +  -- (+364 chars; full line in the Zenodo source)
  rw [(show ((k) + 1) + 0*(20*(k) + 1*(r) + 19 + 1) = 1*((k) + 1) + 0*(r) from LinNorm.sound [k, r] 2 (.add (.add (.var 0) (.lit 1)) (.smul 0 (.add (.add (.add (.smul 20 (.var 0)) (.smul 1 (.var 1))) (.lit 19)) (.lit 1)))) (.add (.smul 1 (.add (.var 0) (.lit 1))) (.smul 0 (.var 1))) rfl), (show ((k) + 1) + 1*(20*(k) + 1*(r) + 19 + 1) = 21*((k) + 1) + 1*(r) from LinNorm.sound [k, r] 2 (.add (.add (  -- (+2754 chars; full line in the Zenodo source)

set_option maxHeartbeats 0 in
set_option maxRecDepth 200000 in
theorem d10_both (k r : Nat) :
    bal ((100 * (k + 1) + 5 * r) + (100 * (k + 1) + 5 * r)) (APDoubleMore.co10.map (ev2 (k + 1) r)) = true ∧
    indec (200 * k + 10 * r + 198 + 2) (APDoubleMore.co10.map (ev2 (k + 1) r)) = true := by
  refine ⟨?_, indec_lin2 _ 200 10 (k + 1) r (Nat.succ_pos k)
    (show 200*((k) + 1) + 10*(r) = 200*(k) + 10*(r) + 198 + 2 from LinNorm.sound [k, r] 2 (.add (.smul 200 (.add (.var 0) (.lit 1))) (.smul 10 (.var 1))) (.add (.add (.add (.smul 200 (.var 0)) (.smul 10 (.var 1))) (.lit 198)) (.lit 2)) rfl) APDoubleMore.co10 APDoubleMore.co10_ok.1 APDoubleMore.co10_ok.2⟩
  rw [← d10_list k r]
  exact ap_double_bal 8 (20 * k + 1 * r + 19) (100 * (k + 1) + 5 * r) (k + 1) (180 * (k + 1) + 10 * r)
    (show (8 + 1 + 1)*(20*(k) + 1*(r) + 19 + 1) = 100*((k) + 1) + 5*(r) + (100*((k) + 1) + 5*(r)) from LinNorm.sound [k, r] 2 (.smul 10 (.add (.add (.add (.smul 20 (.var 0)) (.smul 1 (.var 1))) (.lit 19)) (.lit 1))) (.add (.add (.smul 100 (.add (.var 0) (.lit 1))) (.smul 5 (.var 1))) (.add (.smul 100 (.add (.var 0) (.lit 1))) (.smul 5 (.var 1)))) rfl)
    (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (by rw [(show (8 + 1 + 1)*((k) + 1) = 1 + (9 + 10*(k)) from LinNorm.sound [k] 1 (.smul 10 (.add (.var 0) (.lit 1))) (.add (.lit 1) (.add (.lit 9) (.smul 10 (.var 0)))) rfl)]; exact Nat.le_add_right 1 _))
    (by rw [(show 100*((k) + 1) + 5*(r) = (8 + 1 + 1)*((k) + 1) + (1 + (89 + 90*(k) + 5*(r))) from LinNorm.sound [k, r] 2 (.add (.smul 100 (.add (.var 0) (.lit 1))) (.smul 5 (.var 1))) (.add (.smul 10 (.add (.var 0) (.lit 1))) (.add (.lit 1) (.add (.add (.lit 89) (.smul 90 (.var 0))) (.smul 5 (.var 1))))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_add_right 1  -- (+5 chars; full line in the Zenodo source)
    (show (8 + 1 + 1)*((k) + 1) + (8 + 1 + 1)*((k) + 1) + (180*((k) + 1) + 10*(r)) = 100*((k) + 1) + 5*(r) + (100*((k) + 1) + 5*(r)) from LinNorm.sound [k, r] 2 (.add (.add (.smul 10 (.add (.var 0) (.lit 1))) (.smul 10 (.add (.var 0) (.lit 1)))) (.add (.smul 180 (.add (.var 0) (.lit 1))) (.smul 10 (.var 1)))) (.add (.add (.smul 100 (.add (.var 0) (.lit 1))) (.smul 5 (.var 1))) (.add (.smul 100 (.a  -- (+48 chars; full line in the Zenodo source)

end APDoubleGenA3

#print axioms APDoubleGenA3.d9_both
#print axioms APDoubleGenA3.d10_both

#print axioms: 2 theorems, no axioms.

81.72 Lengths 9, 11, 12

Irreducible Hodge characters for every \(m=182+14r\), \(306+18r\), \(200+10r\). \(\exists c,\ |c|\in \{9,11,12\}\wedge \text {bal}\wedge \text {indec}\)

hodge/ExistsIrr2.lean

/-
  hodge/ExistsIrr2.lean — T41 cycle 312 (goal G50): balanced irreducible characters of lengths 9, 11, 12 for every
  m = 182 + 14r, 306 + 18r, 200 + 10r (APDoubleMore, a = 1). With ExistsIrr: lengths 4–12 all covered; 13, 14
  (d = 11, 12: APDoubleMore2, Kamiak).
-/
import hodge.APDoubleMore

namespace ExistsIrr2
open Indecomp


theorem exists_irr9 (r : Nat) :
    ∃ c : List Nat, c.length = 9 ∧ bal (182 + 14 * r) c = true ∧ indec (182 + 14 * r) c = true := by
  have ⟨h1, h2⟩ := APDoubleMore.d7_both r
  refine ⟨APDoubleMore.co7.map (APPairIrrGen.ev r), rfl, ?_, ?_⟩
  · rw [show 182 + 14 * r = 91 + 7 * r + (91 + 7 * r) by lib_nat]; exact h1
  · rw [show 182 + 14 * r = 180 + 14 * r + 2 by lib_nat]; exact h2


theorem exists_irr11 (r : Nat) :
    ∃ c : List Nat, c.length = 11 ∧ bal (306 + 18 * r) c = true ∧ indec (306 + 18 * r) c = true := by
  have ⟨h1, h2⟩ := APDoubleMore.d9_both r
  refine ⟨APDoubleMore.co9.map (APPairIrrGen.ev r), rfl, ?_, ?_⟩
  · rw [show 306 + 18 * r = 153 + 9 * r + (153 + 9 * r) by lib_nat]; exact h1
  · rw [show 306 + 18 * r = 304 + 18 * r + 2 by lib_nat]; exact h2


theorem exists_irr12 (r : Nat) :
    ∃ c : List Nat, c.length = 12 ∧ bal (200 + 10 * r) c = true ∧ indec (200 + 10 * r) c = true := by
  have ⟨h1, h2⟩ := APDoubleMore.d10_both r
  refine ⟨APDoubleMore.co10.map (APPairIrrGen.ev r), rfl, ?_, ?_⟩
  · rw [show 200 + 10 * r = 100 + 5 * r + (100 + 5 * r) by lib_nat]; exact h1
  · rw [show 200 + 10 * r = 198 + 10 * r + 2 by lib_nat]; exact h2

end ExistsIrr2

#print axioms ExistsIrr2.exists_irr9
#print axioms ExistsIrr2.exists_irr11
#print axioms ExistsIrr2.exists_irr12

#print axioms: 3 theorems, no axioms.

81.73 Balance and irreducibility depend only on the multiset

Every splitting of a permuted list is a permutation of a splitting of the original. \(c\sim c'\Rightarrow (\text {bal}\,m\,c=\text {bal}\,m\,c')\wedge (\text {indec}\,m\,c\Rightarrow \text {indec}\,m\,c')\)

hodge/IndecPerm.lean

/-
  hodge/IndecPerm.lean — T41 cycle 313 (goal G51): balance and irreducibility depend only on the multiset of
  entries (List.Perm), every m, axiom-free.

  Lean 4 core plus hodge/APPairIrrGen (splitsG, splits_eq), hodge/Indecomp (bal, indec, tsum), lib/Semi.
    perm_len, perm_nil      own versions (core's Perm.length_eq / isEmpty_eq use propext)
    tsum_perm', bal_perm    T_t and bal are Perm-invariant
    mem_flatMap'            hand membership in flatMap
    splits_perm             every splitting of c' is a Perm-image of a splitting of c (c ~ c')
    indec_perm              c ~ c' ⇒ (indec m c = true → indec m c' = true)
-/
import hodge.APPairIrrGen

namespace IndecPerm
open Indecomp APPairIrrGen

theorem perm_len {α : Type} {a b : List α} (h : a.Perm b) : a.length = b.length := by
  induction h with
  | nil => rfl
  | cons x _ ih => show _ + 1 = _ + 1; rw [ih]
  | swap x y l => rfl
  | trans _ _ ih1 ih2 => exact ih1.trans ih2

theorem perm_isEmpty {α : Type} {a b : List α} (h : a.Perm b) : a.isEmpty = b.isEmpty := by
  induction h with
  | nil => rfl
  | cons x _ _ => rfl
  | swap x y l => rfl
  | trans _ _ ih1 ih2 => exact ih1.trans ih2

theorem tsum_perm' (m t : Nat) {a b : List Nat} (h : a.Perm b) : tsum m t a = tsum m t b := by
  induction h with
  | nil => rfl
  | cons x _ ih => show (t * x) % m + tsum m t _ = (t * x) % m + tsum m t _; rw [ih]
  | swap x y l => show (t * y) % m + ((t * x) % m + tsum m t l) = (t * x) % m + ((t * y) % m + tsum m t l); lib_nat
  | trans _ _ ih1 ih2 => exact ih1.trans ih2

theorem all_congr' {α : Type} (f g : α → Bool) (h : ∀ x, f x = g x) : ∀ l : List α, l.all f = l.all g
  | [] => rfl
  | x :: l => by show (f x && l.all f) = (g x && l.all g); rw [h x, all_congr' f g h l]

theorem bal_perm (m : Nat) {a b : List Nat} (h : a.Perm b) : bal m a = bal m b := by
  unfold bal
  rw [perm_len h]
  exact all_congr' _ _ (fun t => by rw [tsum_perm' m t h]) _

theorem mem_append_l {α : Type} {x : α} : ∀ {l1 : List α} (l2 : List α), x ∈ l1 → x ∈ l1 ++ l2
  | _ :: _, _, List.Mem.head _ => List.Mem.head _
  | _ :: _, l2, List.Mem.tail _ m => List.Mem.tail _ (mem_append_l l2 m)

theorem mem_append_r {α : Type} {x : α} : ∀ (l1 : List α) {l2 : List α}, x ∈ l2 → x ∈ l1 ++ l2
  | [], _, m => m
  | _ :: l1, _, m => List.Mem.tail _ (mem_append_r l1 m)

theorem mem_append_or {α : Type} {x : α} : ∀ (l1 l2 : List α), x ∈ l1 ++ l2 → x ∈ l1 ∨ x ∈ l2
  | [], _, m => Or.inr m
  | _ :: _, _, List.Mem.head _ => Or.inl (List.Mem.head _)
  | _ :: l1, l2, List.Mem.tail _ m => (mem_append_or l1 l2 m).elim (fun h => Or.inl (List.Mem.tail _ h)) Or.inr

theorem mem_flatMap_of {α β : Type} (f : α → List β) {y : β} {x : α} : ∀ {l : List α}, x ∈ l → y ∈ f x → y ∈ l.flatMap f
  | _ :: _, List.Mem.head _, hy => by
    show y ∈ f x ++ List.flatMap f _
    exact mem_append_l _ hy
  | z :: l, List.Mem.tail _ m, hy => by
    show y ∈ f z ++ List.flatMap f l
    exact mem_append_r _ (mem_flatMap_of f m hy)

theorem of_mem_flatMap {α β : Type} (f : α → List β) {y : β} : ∀ (l : List α), y ∈ l.flatMap f → ∃ x, x ∈ l ∧ y ∈ f x
  | [], m => by cases m
  | z :: l, m => by
    have m' : y ∈ f z ++ List.flatMap f l := m
    cases mem_append_or _ _ m' with
    | inl h => exact ⟨z, List.Mem.head _, h⟩
    | inr h =>
      have ⟨x, hx, hy⟩ := of_mem_flatMap f l h
      exact ⟨x, List.Mem.tail _ hx, hy⟩

/-- the two ways to place an entry into a splitting -/
def place {α : Type} (x : α) (p : List α × List α) : List (List α × List α) := [(x :: p.1, p.2), (p.1, x :: p.2)]

theorem splitsG_cons {α : Type} (x : α) (l : List α) : splitsG (x :: l) = (splitsG l).flatMap (place x) := rfl

def PP {α : Type} (p q : List α × List α) : Prop := p.1.Perm q.1 ∧ p.2.Perm q.2

/-- **Every splitting of c' is a Perm-image of one of c.** -/
theorem splits_perm {α : Type} {c c' : List α} (h : c.Perm c') :
    ∀ p', p' ∈ splitsG c' → ∃ p, p ∈ splitsG c ∧ PP p p' := by
  induction h with
  | nil => intro p' hp; exact ⟨p', hp, List.Perm.refl _, List.Perm.refl _⟩
  | cons x _ ih =>
    intro p' hp
    rw [splitsG_cons] at hp
    have ⟨q', hq', hp'⟩ := of_mem_flatMap _ _ hp
    have ⟨q, hq, h1, h2⟩ := ih q' hq'
    cases hp' with
    | head => exact ⟨(x :: q.1, q.2), mem_flatMap_of _ hq (List.Mem.head _), h1.cons x, h2⟩
    | tail _ hp'' =>
      cases hp'' with
      | head => exact ⟨(q.1, x :: q.2), mem_flatMap_of _ hq (List.Mem.tail _ (List.Mem.head _)), h1, h2.cons x⟩
      | tail _ h3 => cases h3
  | swap x y l =>
    intro p' hp
    rw [splitsG_cons, splitsG_cons] at hp
    have ⟨q1, hq1, hp1⟩ := of_mem_flatMap _ _ hp
    have ⟨q, hq, hq1'⟩ := of_mem_flatMap _ _ hq1
    -- q1 is q with y placed, p' is q1 with x placed; build the same with x first then y
    have mem2 : ∀ r, r ∈ place y q → ∀ s, s ∈ place x r →
        ∃ p, p ∈ ((splitsG l).flatMap (place x)).flatMap (place y) ∧ PP p s := by
      intro r hr s hs
      cases hr with
      | head =>
        cases hs with
        | head => exact ⟨(y :: x :: q.1, q.2), mem_flatMap_of _ (mem_flatMap_of _ hq (List.Mem.head _)) (List.Mem.head _),
            List.Perm.swap x y q.1, List.Perm.refl _⟩
        | tail _ hs' => cases hs' with
          | head => exact ⟨(y :: q.1, x :: q.2),
              mem_flatMap_of _ (mem_flatMap_of _ hq (List.Mem.tail _ (List.Mem.head _))) (List.Mem.head _),
              List.Perm.refl _, List.Perm.refl _⟩
          | tail _ h3 => cases h3
      | tail _ hr' => cases hr' with
        | head =>
          cases hs with
          | head => exact ⟨(x :: q.1, y :: q.2),
              mem_flatMap_of _ (mem_flatMap_of _ hq (List.Mem.head _)) (List.Mem.tail _ (List.Mem.head _)),
              List.Perm.refl _, List.Perm.refl _⟩
          | tail _ hs' => cases hs' with
            | head => exact ⟨(q.1, y :: x :: q.2),
                mem_flatMap_of _ (mem_flatMap_of _ hq (List.Mem.tail _ (List.Mem.head _))) (List.Mem.tail _ (List.Mem.head _)),
                List.Perm.refl _, List.Perm.swap x y q.2⟩
            | tail _ h3 => cases h3
        | tail _ h3 => cases h3
    have ⟨p, hp0, hpp⟩ := mem2 q1 hq1' p' hp1
    exact ⟨p, by rw [splitsG_cons, splitsG_cons]; exact hp0, hpp⟩
  | trans _ _ ih1 ih2 =>
    intro p'' hp''
    have ⟨p', hp', h1, h2⟩ := ih2 p'' hp''
    have ⟨p, hp, h3, h4⟩ := ih1 p' hp'
    exact ⟨p, hp, h3.trans h1, h4.trans h2⟩

theorem all_of_mem {α : Type} (f : α → Bool) : ∀ (l : List α), (∀ x, x ∈ l → f x = true) → l.all f = true
  | [], _ => rfl
  | x :: l, h => by
    show (f x && l.all f) = true
    rw [h x (List.Mem.head _), all_of_mem f l (fun y hy => h y (List.Mem.tail _ hy))]; rfl

theorem mem_of_all {α : Type} (f : α → Bool) {x : α} : ∀ {l : List α}, l.all f = true → x ∈ l → f x = true
  | _ :: _, h, List.Mem.head _ => by
    have h' : (f x && _) = true := h
    cases e : f x with
    | true => rfl
    | false => rw [e] at h'; exact Bool.noConfusion h'
  | y :: l, h, List.Mem.tail _ m => by
    have h' : (f y && l.all f) = true := h
    cases e : l.all f with
    | true => exact mem_of_all f e m
    | false => rw [e] at h'; cases e2 : f y <;> rw [e2] at h' <;> exact Bool.noConfusion h'

/-- **Irreducibility is invariant under reordering.** -/
theorem indec_perm (m : Nat) {c c' : List Nat} (h : c.Perm c') (hc : indec m c = true) : indec m c' = true := by
  unfold indec at *
  rw [splits_eq] at *
  apply all_of_mem
  intro p' hp'
  have ⟨p, hp, h1, h2⟩ := splits_perm h p' hp'
  have := mem_of_all _ hc hp
  rw [← perm_isEmpty h1, ← perm_isEmpty h2, ← bal_perm m h1, ← bal_perm m h2]
  exact this

end IndecPerm

#print axioms IndecPerm.bal_perm
#print axioms IndecPerm.splits_perm
#print axioms IndecPerm.indec_perm

#print axioms: 3 theorems, no axioms.

81.74 \(d=5\) with starts \(a=3,7,9\)

The two-unit reflection with new coefficient rows, both parities of \(p\) from explicit bounds. \(\text {indec}\,(10p)\,[a,a+2p,\dots ,a+8p,5a+5p,10p-10a],\ a\in \{3,7,9\}\)

hodge/APDoubleIrr5b.lean

/-
  hodge/APDoubleIrr5b.lean — T41 cycle 315 (goal G53): the d = 5 APDouble character with start a = 3, 7, 9,
  [a, a+2p, a+4p, a+6p, a+8p, 5a+5p, 10p−10a] in m = 10p, is irreducible for every p from an explicit bound on
  (both parities), by the two-unit reflection of APDoubleIrr5 (t₂ = 1 + 5p or 2 + 5p; rows computed in Python).
    unit2, unit4   t odd, 2t = m + 2 (resp. m + 4) ⇒ gcd t m = 1      (general forms of APDoubleIrr5.unitE/O)
-/
import hodge.APDoubleIrr5
import lib.LinNorm

namespace APDoubleIrr5b
open Indecomp APPairIrrGen APDoubleIrr5 UnitMul

theorem unit2 (t n2 : Nat) (hrel : t + t = (n2 + 2) + 2) (hodd : ∀ i, t ≠ 2 * i) : Nat.gcd t (n2 + 2) = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := gcd_dvd t (n2 + 2)
  generalize Nat.gcd t (n2 + 2) = g at hi hj ⊢
  have ⟨k, hk⟩ := unit_of_rel _ _ 2 g hrel ⟨i, hi⟩ ⟨j, hj⟩
  cases g with
  | zero => rw [Nat.zero_mul] at hk; exact Nat.noConfusion hk
  | succ g =>
    cases g with
    | zero => rfl
    | succ g =>
      cases g with
      | zero => exact absurd hi (hodd i)
      | succ g =>
        cases k with
        | zero => rw [Nat.mul_zero] at hk; exact Nat.noConfusion hk
        | succ k =>
          have : 2 = g + 3 + (g + 3) * k := by rw [hk]; lib_nat
          exact absurd (this ▸ Nat.le_add_right (g + 3) _) (fun h => Nat.lt_irrefl 2 (Nat.lt_of_lt_of_le (Nat.lt_of_lt_of_le (Nat.lt_succ_self 2) (Nat.le_add_left 3 g)) h))

theorem unit4 (t n2 : Nat) (hrel : t + t = (n2 + 2) + 4) (hodd : ∀ i, t ≠ 2 * i) : Nat.gcd t (n2 + 2) = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := gcd_dvd t (n2 + 2)
  generalize Nat.gcd t (n2 + 2) = g at hi hj ⊢
  have ⟨k, hk⟩ := unit_of_rel _ _ 4 g hrel ⟨i, hi⟩ ⟨j, hj⟩
  cases g with
  | zero => rw [Nat.zero_mul] at hk; exact Nat.noConfusion hk
  | succ g =>
    cases g with
    | zero => rfl
    | succ g =>
      cases g with
      | zero => exact absurd hi (hodd i)
      | succ g =>
        cases g with
        | zero =>
          cases k with
          | zero => exact Nat.noConfusion hk
          | succ k => cases k with
            | zero => exact Nat.noConfusion (Nat.succ.inj (Nat.succ.inj (Nat.succ.inj hk)))
            | succ k =>
              have : 4 = 6 + 3 * k := by rw [hk]; lib_nat
              exact absurd (this ▸ Nat.le_add_right 6 _) (fun h => Nat.lt_irrefl 4 (Nat.lt_of_lt_of_le (Nat.le_add_left 5 0 |> Nat.lt_of_lt_of_le (Nat.lt_succ_self 4)) (Nat.le_trans (Nat.le_add_left 5 1) h)))
        | succ g =>
          cases g with
          | zero => exact absurd (show t = 2 * (2 * i) by rw [hi]; lib_nat) (hodd _)
          | succ g =>
            cases k with
            | zero => rw [Nat.mul_zero] at hk; exact Nat.noConfusion hk
            | succ k =>
              have : 4 = g + 5 + (g + 5) * k := by rw [hk]; lib_nat
              exact absurd (this ▸ Nat.le_add_right (g + 5) _) (fun h => Nat.lt_irrefl 4 (Nat.lt_of_lt_of_le (Nat.lt_of_lt_of_le (Nat.lt_succ_self 4) (Nat.le_add_left 5 g)) h))


def co_a3e : List Row := [((3,0), (133,10), (1,0)), ((55,4), (185,14), (27,2)), ((107,8), (237,18), (53,4)), ((159,12), (29,2), (80,6)), ((211,16), (81,6), (106,8)), ((145,10), (15,0), (73,5)), ((230,20), (230,20), (115,10))]

set_option maxRecDepth 20000 in
theorem co_a3e_ok : co_a3e.all (okRow 131 10 260 20) = true ∧ (splitsG co_a3e).all (chk2 260 20) = true := ⟨rfl, rfl⟩

theorem a3e (r : Nat) : indec (258 + 20 * r + 2) (co_a3e.map (evE r)) = true :=
  indec_two (258 + 20 * r) 131 10 260 20 r (show 260 + 20*(r) = 258 + 20*(r) + 2 from LinNorm.sound [r] 1 (.add (.lit 260) (.smul 20 (.var 0))) (.add (.add (.lit 258) (.smul 20 (.var 0))) (.lit 2)) rfl)
    (unit2 _ _ (show 131 + 10*(r) + (131 + 10*(r)) = 258 + 20*(r) + 2 + 2 from LinNorm.sound [r] 1 (.add (.add (.lit 131) (.smul 10 (.var 0))) (.add (.lit 131) (.smul 10 (.var 0)))) (.add (.add (.add (.lit 258) (.smul 20 (.var 0))) (.lit 2)) (.lit 2)) rfl)
      (fun i h => odd_not_even (65 + 5 * r) i (by rw [← h]; exact (show 2*(65 + 5*(r)) + 1 = 131 + 10*(r) from LinNorm.sound [r] 1 (.add (.smul 2 (.add (.lit 65) (.smul 5 (.var 0)))) (.lit 1)) (.add (.lit 131) (.smul 10 (.var 0))) rfl))))
    (by rw [(show 258 + 20*(r) + 2 = 131 + 10*(r) + (129 + 10*(r)) from LinNorm.sound [r] 1 (.add (.add (.lit 258) (.smul 20 (.var 0))) (.lit 2)) (.add (.add (.lit 131) (.smul 10 (.var 0))) (.add (.lit 129) (.smul 10 (.var 0)))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 128) (Nat.le_add_right 129 _)))
    co_a3e co_a3e_ok.1 co_a3e_ok.2


def co_a3o : List Row := [((3,0), (61,10), (1,0)), ((25,4), (105,18), (12,2)), ((47,8), (39,6), (24,4)), ((69,12), (83,14), (35,6)), ((91,16), (17,2), (47,8)), ((70,10), (30,0), (36,5)), ((80,20), (50,20), (41,10))]

set_option maxRecDepth 20000 in
theorem co_a3o_ok : co_a3o.all (okRow 57 10 110 20) = true ∧ (splitsG co_a3o).all (chk2 110 20) = true := ⟨rfl, rfl⟩

theorem a3o (r : Nat) : indec (108 + 20 * r + 2) (co_a3o.map (evE r)) = true :=
  indec_two (108 + 20 * r) 57 10 110 20 r (show 110 + 20*(r) = 108 + 20*(r) + 2 from LinNorm.sound [r] 1 (.add (.lit 110) (.smul 20 (.var 0))) (.add (.add (.lit 108) (.smul 20 (.var 0))) (.lit 2)) rfl)
    (unit4 _ _ (show 57 + 10*(r) + (57 + 10*(r)) = 108 + 20*(r) + 2 + 4 from LinNorm.sound [r] 1 (.add (.add (.lit 57) (.smul 10 (.var 0))) (.add (.lit 57) (.smul 10 (.var 0)))) (.add (.add (.add (.lit 108) (.smul 20 (.var 0))) (.lit 2)) (.lit 4)) rfl)
      (fun i h => odd_not_even (28 + 5 * r) i (by rw [← h]; exact (show 2*(28 + 5*(r)) + 1 = 57 + 10*(r) from LinNorm.sound [r] 1 (.add (.smul 2 (.add (.lit 28) (.smul 5 (.var 0)))) (.lit 1)) (.add (.lit 57) (.smul 10 (.var 0))) rfl))))
    (by rw [(show 108 + 20*(r) + 2 = 57 + 10*(r) + (53 + 10*(r)) from LinNorm.sound [r] 1 (.add (.add (.lit 108) (.smul 20 (.var 0))) (.lit 2)) (.add (.add (.lit 57) (.smul 10 (.var 0))) (.add (.lit 53) (.smul 10 (.var 0)))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 52) (Nat.le_add_right 53 _)))
    co_a3o co_a3o_ok.1 co_a3o_ok.2


def co_a7e : List Row := [((7,0), (297,10), (3,0)), ((123,4), (413,14), (61,2)), ((239,8), (529,18), (119,4)), ((355,12), (65,2), (178,6)), ((471,16), (181,6), (236,8)), ((325,10), (35,0), (163,5)), ((510,20), (510,20), (255,10))]

set_option maxRecDepth 20000 in
theorem co_a7e_ok : co_a7e.all (okRow 291 10 580 20) = true ∧ (splitsG co_a7e).all (chk2 580 20) = true := ⟨rfl, rfl⟩

theorem a7e (r : Nat) : indec (578 + 20 * r + 2) (co_a7e.map (evE r)) = true :=
  indec_two (578 + 20 * r) 291 10 580 20 r (show 580 + 20*(r) = 578 + 20*(r) + 2 from LinNorm.sound [r] 1 (.add (.lit 580) (.smul 20 (.var 0))) (.add (.add (.lit 578) (.smul 20 (.var 0))) (.lit 2)) rfl)
    (unit2 _ _ (show 291 + 10*(r) + (291 + 10*(r)) = 578 + 20*(r) + 2 + 2 from LinNorm.sound [r] 1 (.add (.add (.lit 291) (.smul 10 (.var 0))) (.add (.lit 291) (.smul 10 (.var 0)))) (.add (.add (.add (.lit 578) (.smul 20 (.var 0))) (.lit 2)) (.lit 2)) rfl)
      (fun i h => odd_not_even (145 + 5 * r) i (by rw [← h]; exact (show 2*(145 + 5*(r)) + 1 = 291 + 10*(r) from LinNorm.sound [r] 1 (.add (.smul 2 (.add (.lit 145) (.smul 5 (.var 0)))) (.lit 1)) (.add (.lit 291) (.smul 10 (.var 0))) rfl))))
    (by rw [(show 578 + 20*(r) + 2 = 291 + 10*(r) + (289 + 10*(r)) from LinNorm.sound [r] 1 (.add (.add (.lit 578) (.smul 20 (.var 0))) (.lit 2)) (.add (.add (.lit 291) (.smul 10 (.var 0))) (.add (.lit 289) (.smul 10 (.var 0)))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 288) (Nat.le_add_right 289 _)))
    co_a7e co_a7e_ok.1 co_a7e_ok.2


def co_a7o : List Row := [((7,0), (129,10), (3,0)), ((53,4), (221,18), (26,2)), ((99,8), (83,6), (50,4)), ((145,12), (175,14), (73,6)), ((191,16), (37,2), (97,8)), ((150,10), (70,0), (76,5)), ((160,20), (90,20), (81,10))]

set_option maxRecDepth 20000 in
theorem co_a7o_ok : co_a7o.all (okRow 117 10 230 20) = true ∧ (splitsG co_a7o).all (chk2 230 20) = true := ⟨rfl, rfl⟩

theorem a7o (r : Nat) : indec (228 + 20 * r + 2) (co_a7o.map (evE r)) = true :=
  indec_two (228 + 20 * r) 117 10 230 20 r (show 230 + 20*(r) = 228 + 20*(r) + 2 from LinNorm.sound [r] 1 (.add (.lit 230) (.smul 20 (.var 0))) (.add (.add (.lit 228) (.smul 20 (.var 0))) (.lit 2)) rfl)
    (unit4 _ _ (show 117 + 10*(r) + (117 + 10*(r)) = 228 + 20*(r) + 2 + 4 from LinNorm.sound [r] 1 (.add (.add (.lit 117) (.smul 10 (.var 0))) (.add (.lit 117) (.smul 10 (.var 0)))) (.add (.add (.add (.lit 228) (.smul 20 (.var 0))) (.lit 2)) (.lit 4)) rfl)
      (fun i h => odd_not_even (58 + 5 * r) i (by rw [← h]; exact (show 2*(58 + 5*(r)) + 1 = 117 + 10*(r) from LinNorm.sound [r] 1 (.add (.smul 2 (.add (.lit 58) (.smul 5 (.var 0)))) (.lit 1)) (.add (.lit 117) (.smul 10 (.var 0))) rfl))))
    (by rw [(show 228 + 20*(r) + 2 = 117 + 10*(r) + (113 + 10*(r)) from LinNorm.sound [r] 1 (.add (.add (.lit 228) (.smul 20 (.var 0))) (.lit 2)) (.add (.add (.lit 117) (.smul 10 (.var 0))) (.add (.lit 113) (.smul 10 (.var 0)))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 112) (Nat.le_add_right 113 _)))
    co_a7o co_a7o_ok.1 co_a7o_ok.2


def co_a9e : List Row := [((9,0), (379,10), (4,0)), ((157,4), (527,14), (78,2)), ((305,8), (675,18), (152,4)), ((453,12), (83,2), (227,6)), ((601,16), (231,6), (301,8)), ((415,10), (45,0), (208,5)), ((650,20), (650,20), (325,10))]

set_option maxRecDepth 20000 in
theorem co_a9e_ok : co_a9e.all (okRow 371 10 740 20) = true ∧ (splitsG co_a9e).all (chk2 740 20) = true := ⟨rfl, rfl⟩

theorem a9e (r : Nat) : indec (738 + 20 * r + 2) (co_a9e.map (evE r)) = true :=
  indec_two (738 + 20 * r) 371 10 740 20 r (show 740 + 20*(r) = 738 + 20*(r) + 2 from LinNorm.sound [r] 1 (.add (.lit 740) (.smul 20 (.var 0))) (.add (.add (.lit 738) (.smul 20 (.var 0))) (.lit 2)) rfl)
    (unit2 _ _ (show 371 + 10*(r) + (371 + 10*(r)) = 738 + 20*(r) + 2 + 2 from LinNorm.sound [r] 1 (.add (.add (.lit 371) (.smul 10 (.var 0))) (.add (.lit 371) (.smul 10 (.var 0)))) (.add (.add (.add (.lit 738) (.smul 20 (.var 0))) (.lit 2)) (.lit 2)) rfl)
      (fun i h => odd_not_even (185 + 5 * r) i (by rw [← h]; exact (show 2*(185 + 5*(r)) + 1 = 371 + 10*(r) from LinNorm.sound [r] 1 (.add (.smul 2 (.add (.lit 185) (.smul 5 (.var 0)))) (.lit 1)) (.add (.lit 371) (.smul 10 (.var 0))) rfl))))
    (by rw [(show 738 + 20*(r) + 2 = 371 + 10*(r) + (369 + 10*(r)) from LinNorm.sound [r] 1 (.add (.add (.lit 738) (.smul 20 (.var 0))) (.lit 2)) (.add (.add (.lit 371) (.smul 10 (.var 0))) (.add (.lit 369) (.smul 10 (.var 0)))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 368) (Nat.le_add_right 369 _)))
    co_a9e co_a9e_ok.1 co_a9e_ok.2


def co_a9o : List Row := [((9,0), (163,10), (4,0)), ((67,4), (279,18), (33,2)), ((125,8), (105,6), (63,4)), ((183,12), (221,14), (92,6)), ((241,16), (47,2), (122,8)), ((190,10), (90,0), (96,5)), ((200,20), (110,20), (101,10))]

set_option maxRecDepth 20000 in
theorem co_a9o_ok : co_a9o.all (okRow 147 10 290 20) = true ∧ (splitsG co_a9o).all (chk2 290 20) = true := ⟨rfl, rfl⟩

theorem a9o (r : Nat) : indec (288 + 20 * r + 2) (co_a9o.map (evE r)) = true :=
  indec_two (288 + 20 * r) 147 10 290 20 r (show 290 + 20*(r) = 288 + 20*(r) + 2 from LinNorm.sound [r] 1 (.add (.lit 290) (.smul 20 (.var 0))) (.add (.add (.lit 288) (.smul 20 (.var 0))) (.lit 2)) rfl)
    (unit4 _ _ (show 147 + 10*(r) + (147 + 10*(r)) = 288 + 20*(r) + 2 + 4 from LinNorm.sound [r] 1 (.add (.add (.lit 147) (.smul 10 (.var 0))) (.add (.lit 147) (.smul 10 (.var 0)))) (.add (.add (.add (.lit 288) (.smul 20 (.var 0))) (.lit 2)) (.lit 4)) rfl)
      (fun i h => odd_not_even (73 + 5 * r) i (by rw [← h]; exact (show 2*(73 + 5*(r)) + 1 = 147 + 10*(r) from LinNorm.sound [r] 1 (.add (.smul 2 (.add (.lit 73) (.smul 5 (.var 0)))) (.lit 1)) (.add (.lit 147) (.smul 10 (.var 0))) rfl))))
    (by rw [(show 288 + 20*(r) + 2 = 147 + 10*(r) + (143 + 10*(r)) from LinNorm.sound [r] 1 (.add (.add (.lit 288) (.smul 20 (.var 0))) (.lit 2)) (.add (.add (.lit 147) (.smul 10 (.var 0))) (.add (.lit 143) (.smul 10 (.var 0)))) rfl)]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.succ_pos 142) (Nat.le_add_right 143 _)))
    co_a9o co_a9o_ok.1 co_a9o_ok.2

end APDoubleIrr5b

#print axioms APDoubleIrr5b.a3e
#print axioms APDoubleIrr5b.a3o
#print axioms APDoubleIrr5b.a7e
#print axioms APDoubleIrr5b.a7o
#print axioms APDoubleIrr5b.a9e
#print axioms APDoubleIrr5b.a9o

#print axioms: 6 theorems, no axioms.

81.75 Whole Galois orbits

A balanced irreducible character has a whole orbit of them; e.g. every unit twist of the \(d=5\) character. \(\gcd (t,m)=1\Rightarrow \text {bal}\,m\,(t\cdot c)\wedge \text {indec}\,m\,(t\cdot c)\)

hodge/OrbitGood.lean

/-
  hodge/OrbitGood.lean — T41 cycle 316 (goal G54): a balanced irreducible character with entries < m has a whole
  Galois orbit of balanced irreducible characters; applied to the d = 5 family (APDoubleAll5).

  Lean 4 core plus hodge/TwistBal (bal_twist, tw), hodge/TwistIndec (indec_twist), hodge/APDoubleAll5.
-/
import hodge.TwistIndec
import hodge.APDoubleAll5

namespace OrbitGood
open Indecomp TwistBal TwistIndec

theorem orbit_good (m' t : Nat) (ht : Nat.gcd t (m' + 1 + 1) = 1) (c : List Nat)
    (hlt : c.all (fun x => Nat.blt x (m' + 1 + 1)) = true)
    (hb : bal (m' + 1 + 1) c = true) (hi : indec (m' + 1 + 1) c = true) :
    bal (m' + 1 + 1) (tw (m' + 1 + 1) t c) = true ∧ indec (m' + 1 + 1) (tw (m' + 1 + 1) t c) = true :=
  ⟨bal_twist _ t (Nat.succ_pos _) ht c hb, indec_twist m' t ht c hlt hi⟩

/-- **The whole orbit of the d = 5 character (p = 10 + 2r) is balanced and irreducible.** -/
theorem d5e_orbit (r t : Nat) (ht : Nat.gcd t (98 + 20 * r + 1 + 1) = 1) :
    bal (98 + 20 * r + 1 + 1) (tw (98 + 20 * r + 1 + 1) t (APDoubleIrr5.coE.map (APDoubleIrr5.evE r))) = true ∧
    indec (98 + 20 * r + 1 + 1) (tw (98 + 20 * r + 1 + 1) t (APDoubleIrr5.coE.map (APDoubleIrr5.evE r))) = true := by
  have ⟨h1, h2⟩ := APDoubleAll5.d5e_both r
  have e : 50 + 10 * r + (50 + 10 * r) = 98 + 20 * r + 1 + 1 := by lib_nat
  rw [e] at h1
  have hlt : (APDoubleIrr5.coE.map (APDoubleIrr5.evE r)).all (fun x => Nat.blt x (98 + 20 * r + 1 + 1)) = true := by
    have := (APDoubleIrr5.okRow_parts 51 10 100 20 APDoubleIrr5.coE APDoubleIrr5.coE_ok.1).2
    have s := APPairIrrGen.small_lt 100 20 r _ this
    rw [APDoubleIrr5.map_map', show 100 + 20 * r = 98 + 20 * r + 1 + 1 by lib_nat] at s
    exact s
  exact orbit_good _ t ht _ hlt h1 h2

end OrbitGood

#print axioms OrbitGood.orbit_good
#print axioms OrbitGood.d5e_orbit

#print axioms: 2 theorems, no axioms.

81.76 Small sizes: complete classification for \(d=3,5\)

With the symbolic theorems: irreducible exactly for \(p\ne 2,4\) (\(d=3\)) and \(p\ne 2,3,6\) (\(d=5\)). \(\text {indec}\,(6p)\,f_3(p)\iff p\notin \{2,4\},\quad \text {indec}\,(10p)\,f_5(p)\iff p\notin \{2,3,6\}\)

hodge/APDoubleSmall.lean

/-
  hodge/APDoubleSmall.lean — T41 cycle 320 (goal G55): the small sizes of the d = 3 and d = 5 APDouble families (a = 1),
  by rfl, completing the classification with APDoubleIrr (d = 3, p ≥ 5) and APDoubleIrr5 (d = 5, p ≥ 9):
    d = 3, m = 6p:  [1, 1+2p, 1+4p, 3+3p, 6p−6] is irreducible exactly for p ≠ 2, 4 (p ≥ 2)
    d = 5, m = 10p: [1, 1+2p, …, 1+8p, 5+5p, 10p−10] is irreducible exactly for p ≠ 2, 3, 6 (p ≥ 2)
  (balanced for every p ≥ 2 by APDouble.)
-/
import hodge.Indecomp

namespace APDoubleSmall
open Indecomp

def f3 (p : Nat) : List Nat := [1, 1 + 2 * p, 1 + 4 * p, 3 + 3 * p, 6 * p - 6]
def f5 (p : Nat) : List Nat := [1, 1 + 2 * p, 1 + 4 * p, 1 + 6 * p, 1 + 8 * p, 5 + 5 * p, 10 * p - 10]

set_option maxRecDepth 100000 in
theorem d3_small : [3].all (fun p => indec (6 * p) (f3 p)) = true ∧
    [2, 4].all (fun p => !(indec (6 * p) (f3 p))) = true := ⟨rfl, rfl⟩

set_option maxRecDepth 100000 in
theorem d5_small : [4, 5, 7, 8].all (fun p => indec (10 * p) (f5 p)) = true ∧
    [2, 3, 6].all (fun p => !(indec (10 * p) (f5 p))) = true := ⟨rfl, rfl⟩

end APDoubleSmall

#print axioms APDoubleSmall.d3_small
#print axioms APDoubleSmall.d5_small

#print axioms: 2 theorems, no axioms.

81.77 Small sizes: complete classification for \(d=6,8\)

Irreducible exactly for \(q\in \{6,9,12\}\cup [13,\infty )\) (\(d=6\)) and \(q\in \{8,10,\dots ,14\}\cup [16,\infty )\) (\(d=8\)). \(\text {indec}\,(6q)\,f_6(q),\quad \text {indec}\,(8q)\,f_8(q)\)

hodge/APDoubleSmall2.lean

/-
  hodge/APDoubleSmall2.lean — T41 cycle 321 (goal G56): the small sizes of the d = 6 and d = 8 APDouble families
  (a = 1), by rfl; with APDoubleIrr (d = 6: q ≥ 13; d = 8: q ≥ 16) the classification is complete:
    d = 6, m = 6q: [1 + kq (k < 6), 6 + 3q, 6q − 12] is irreducible exactly for q ∈ {6, 9, 12} ∪ [13, ∞)  (q ≥ 3)
    d = 8, m = 8q: [1 + kq (k < 8), 8 + 4q, 8q − 16] is irreducible exactly for q ∈ {8, 10, …, 14} ∪ [16, ∞)  (q ≥ 3)
-/
import hodge.Indecomp

namespace APDoubleSmall2
open Indecomp

def f6 (q : Nat) : List Nat := [1, 1 + q, 1 + 2 * q, 1 + 3 * q, 1 + 4 * q, 1 + 5 * q, 6 + 3 * q, 6 * q - 12]
def f8 (q : Nat) : List Nat := [1, 1 + q, 1 + 2 * q, 1 + 3 * q, 1 + 4 * q, 1 + 5 * q, 1 + 6 * q, 1 + 7 * q, 8 + 4 * q, 8 * q - 16]

set_option maxRecDepth 200000 in
set_option maxHeartbeats 0 in
theorem d6_small : [6, 9, 12].all (fun q => indec (6 * q) (f6 q)) = true ∧
    [3, 4, 5, 7, 8, 10, 11].all (fun q => !(indec (6 * q) (f6 q))) = true := ⟨rfl, rfl⟩

set_option maxRecDepth 200000 in
set_option maxHeartbeats 0 in
theorem d8_small : [8, 10, 11, 12, 13, 14].all (fun q => indec (8 * q) (f8 q)) = true ∧
    [3, 4, 5, 6, 7, 9, 15].all (fun q => !(indec (8 * q) (f8 q))) = true := ⟨rfl, rfl⟩

end APDoubleSmall2

#print axioms APDoubleSmall2.d6_small
#print axioms APDoubleSmall2.d8_small

#print axioms: 2 theorems, no axioms.

81.78 Small sizes: complete classification for \(d=7\)

Irreducible exactly for even \(q\in \{8,\dots ,14,18,\dots ,24\}\cup [26,\infty )\); \(q=4,6,16\) split. \(\text {indec}\,(7q)\,f_7(q)\)

hodge/APDoubleSmall3.lean

/-
  hodge/APDoubleSmall3.lean — T41 cycle 322 (goal G57): the small sizes of the d = 7 APDouble family (a = 1, m = 7q,
  q even), by rfl; with APDoubleMore (q ≥ 26) the classification is complete: irreducible exactly for even
  q ∈ {8, 10, 12, 14, 18, 20, 22, 24} ∪ [26, ∞) (q = 4, 6, 16 split).
-/
import hodge.Indecomp

namespace APDoubleSmall3
open Indecomp

def f7 (q : Nat) : List Nat :=
  [1, 1 + q, 1 + 2 * q, 1 + 3 * q, 1 + 4 * q, 1 + 5 * q, 1 + 6 * q, 7 + 7 * q / 2, 7 * q - 14]

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem d7_small : [8, 10, 12, 14, 18, 20, 22, 24].all (fun q => indec (7 * q) (f7 q)) = true ∧
    [4, 6, 16].all (fun q => !(indec (7 * q) (f7 q))) = true := ⟨rfl, rfl⟩

end APDoubleSmall3

#print axioms APDoubleSmall3.d7_small

#print axioms: 1 theorem, no axioms.

81.79 Small sizes: complete classification for \(d=9,10\)

Checked on Kamiak; with APDoubleMore the families are classified for every size. \(\text {indec}\,(9q)\,f_9(q),\quad \text {indec}\,(10q)\,f_{10}(q)\)

hodge/APDoubleSmall4.lean

/-
  hodge/APDoubleSmall4.lean — T41 cycle 323 (goal G58, Kamiak): the small sizes of the d = 9 (m = 9q, q even) and
  d = 10 (m = 10q) APDouble families (a = 1), by rfl; with APDoubleMore (d = 9: q ≥ 34; d = 10: q ≥ 20):
    d = 9:  irreducible exactly for even q ∈ {6, 12, 16, 18, 22, 24, …, 32} ∪ [34, ∞)   (q = 4, 8, 10, 14, 20 split)
    d = 10: irreducible exactly for q ∈ {5, 8, 10, 13, …, 18} ∪ [20, ∞)                (q = 3, 4, 6, 7, 9, 11, 12, 19 split)
-/
import hodge.Indecomp

namespace APDoubleSmall4
open Indecomp

def f9 (q : Nat) : List Nat :=
  [1, 1 + q, 1 + 2 * q, 1 + 3 * q, 1 + 4 * q, 1 + 5 * q, 1 + 6 * q, 1 + 7 * q, 1 + 8 * q, 9 + 9 * q / 2, 9 * q - 18]
def f10 (q : Nat) : List Nat :=
  [1, 1 + q, 1 + 2 * q, 1 + 3 * q, 1 + 4 * q, 1 + 5 * q, 1 + 6 * q, 1 + 7 * q, 1 + 8 * q, 1 + 9 * q, 10 + 5 * q, 10 * q - 20]

set_option maxRecDepth 2000000 in
set_option maxHeartbeats 0 in
theorem d9_small : [6, 12, 16, 18, 22, 24, 26, 28, 30, 32].all (fun q => indec (9 * q) (f9 q)) = true ∧
    [4, 8, 10, 14, 20].all (fun q => !(indec (9 * q) (f9 q))) = true := ⟨rfl, rfl⟩

set_option maxRecDepth 2000000 in
set_option maxHeartbeats 0 in
theorem d10_small : [5, 8, 10, 13, 14, 15, 16, 17, 18].all (fun q => indec (10 * q) (f10 q)) = true ∧
    [3, 4, 6, 7, 9, 11, 12, 19].all (fun q => !(indec (10 * q) (f10 q))) = true := ⟨rfl, rfl⟩

end APDoubleSmall4

#print axioms APDoubleSmall4.d9_small
#print axioms APDoubleSmall4.d10_small

#print axioms: 2 theorems, no axioms.

81.80 Lengths 13, 14

Irreducible Hodge characters for every \(m=462+22r\) and \(288+12r\) (Kamiak); lengths 4–14 now all covered. \(\exists c,\ |c|\in \{13,14\}\wedge \text {bal}\wedge \text {indec}\)

hodge/ExistsIrr3.lean

/-
  hodge/ExistsIrr3.lean — T41 cycle 331 (goal G66, Kamiak): balanced irreducible characters of lengths 13 and 14 for
  every m = 462 + 22r and 288 + 12r (APDoubleMore2, d = 11, 12, a = 1). With ExistsIrr/ExistsIrr2: lengths 4–14.
-/
import hodge.APDoubleMore2

namespace ExistsIrr3
open Indecomp


theorem exists_irr13 (r : Nat) :
    ∃ c : List Nat, c.length = 13 ∧ bal (462 + 22 * r) c = true ∧ indec (462 + 22 * r) c = true := by
  have ⟨h1, h2⟩ := APDoubleMore2.d11_both r
  refine ⟨APDoubleMore2.co11.map (APPairIrrGen.ev r), rfl, ?_, ?_⟩
  · rw [show 462 + 22 * r = 231 + 11 * r + (231 + 11 * r) by lib_nat]; exact h1
  · rw [show 462 + 22 * r = 460 + 22 * r + 2 by lib_nat]; exact h2


theorem exists_irr14 (r : Nat) :
    ∃ c : List Nat, c.length = 14 ∧ bal (288 + 12 * r) c = true ∧ indec (288 + 12 * r) c = true := by
  have ⟨h1, h2⟩ := APDoubleMore2.d12_both r
  refine ⟨APDoubleMore2.co12.map (APPairIrrGen.ev r), rfl, ?_, ?_⟩
  · rw [show 288 + 12 * r = 144 + 6 * r + (144 + 6 * r) by lib_nat]; exact h1
  · rw [show 288 + 12 * r = 286 + 12 * r + 2 by lib_nat]; exact h2

end ExistsIrr3

#print axioms ExistsIrr3.exists_irr13
#print axioms ExistsIrr3.exists_irr14

#print axioms: 2 theorems, no axioms.

81.81 Unreached characters at \(m=128\): all from the first pair family

28 characters in 3 orbits, all irreducible; their representatives are the first pair family with \(q=32\), \(a=1,2,4\). \(\text {unreached}(128)=\bigcup _{a\in \{1,2,4\}}\text {orbit}\,[a,a+q,a+2q,a+3q,2q+4a,4q-8a]\)

hodge/Unreached128.lean

/-
  hodge/Unreached128.lean — T41 cycle 360 (goal G46, m = 128): the unreached characters of length 6 at m = 128
  (Kamiak a2_reach128, all_128.jsonl): 28 characters in 3 Galois orbits, all irreducible, and every one is in the
  first pair family AP(a) + (2q + 4a, 4q − 8a) with q = 32 and a = 1, 2, 4 — so by APPairGen, APPairIrrGen2 and
  TwistBal/TwistIndec the whole unreached set at m = 128 is explained by that family.
-/
import hodge.Unreached80

namespace Unreached128
open Orbits Indecomp OrbitDecomp Unreached80

def reps128 : List (List Nat) := [[1, 33, 65, 97, 68, 120], [2, 34, 66, 98, 72, 112], [4, 36, 68, 100, 80, 96]]

set_option maxRecDepth 400000 in
theorem size128 : Nat.beq (union 128 reps128).length 28 = true := rfl

set_option maxRecDepth 400000 in
theorem irr128 : (union 128 reps128).all (indec 128) = true := rfl

set_option maxRecDepth 400000 in
theorem ap128 : (union 128 reps128).all (hasAP 128) = true := rfl

/-- the representatives are the first pair family [a, a+q, a+2q, a+3q, 2q+4a, 4q−8a], q = 32, a = 1, 2, 4 -/
theorem fam128 : reps128 = [1, 2, 4].map (fun a => [a, a + 32, a + 64, a + 96, 64 + 4 * a, 128 - 8 * a]) := rfl

end Unreached128

#print axioms Unreached128.size128
#print axioms Unreached128.irr128
#print axioms Unreached128.ap128
#print axioms Unreached128.fam128

#print axioms: 4 theorems, no axioms.

81.82 Unreached characters at \(m=132\): the AP part

Of the 1058 unreached characters (55 orbits, all irreducible), the 30 with an AP of step 33 are the first pair family, \(a=1,3\). \(\text {AP part}=\bigcup _{a\in \{1,3\}}\text {orbit}\,[a,a+q,a+2q,a+3q,2q+4a,4q-8a],\ q=33\)

hodge/Unreached132.lean

/-
  hodge/Unreached132.lean — T41 cycle 368 (goal G46, m = 132): the AP orbits among the 1058 unreached length-6
  characters at m = 132 (Kamiak a2_reach128, all_132.jsonl; 55 orbits, all irreducible, none reducible). The 30
  characters with an AP of step 33 form 2 orbits, and both representatives are the first pair family (q = 33, a = 1, 3).
  The full set: hodge/OrbitDecomp7 (Kamiak).
-/
import hodge.Unreached80

namespace Unreached132
open Orbits Indecomp OrbitDecomp Unreached80

def apreps132 : List (List Nat) := [[1, 34, 67, 100, 70, 124], [3, 36, 69, 102, 78, 108]]

set_option maxRecDepth 400000 in
theorem size132ap : Nat.beq (union 132 apreps132).length 30 = true := rfl

set_option maxRecDepth 400000 in
theorem irr132ap : (union 132 apreps132).all (indec 132) = true := rfl

set_option maxRecDepth 400000 in
theorem ap132 : (union 132 apreps132).all (hasAP 132) = true := rfl

theorem fam132 : apreps132 = [1, 3].map (fun a => [a, a + 33, a + 66, a + 99, 66 + 4 * a, 132 - 8 * a]) := rfl

end Unreached132

#print axioms Unreached132.size132ap
#print axioms Unreached132.irr132ap
#print axioms Unreached132.ap132
#print axioms Unreached132.fam132

#print axioms: 4 theorems, no axioms.

81.83 Unreached characters at \(m=136\)

The 32 unreached characters (2 orbits, all irreducible) are exactly the first pair family with \(q=34\), \(a=1,2\). \(\text {unreached}=\bigcup _{a\in \{1,2\}}\text {orbit}\,[a,a+q,a+2q,a+3q,2q+4a,4q-8a]\)

hodge/Unreached136.lean

/-
  hodge/Unreached136.lean — T41 cycle 389 (goal G46, m = 136): the unreached characters of length 6 at m = 136
  (Kamiak a2_reach128, all_136.jsonl): 32 characters in 2 Galois orbits, all irreducible, and every one is in the
  first pair family AP(a) + (2q + 4a, 4q − 8a) with q = 34 and a = 1, 2.
-/
import hodge.Unreached80

namespace Unreached136
open Orbits Indecomp OrbitDecomp Unreached80

def reps136 : List (List Nat) := [[1, 35, 69, 103, 72, 128], [2, 36, 70, 104, 76, 120]]

set_option maxRecDepth 400000 in
theorem size136 : Nat.beq (union 136 reps136).length 32 = true := rfl

set_option maxRecDepth 400000 in
theorem irr136 : (union 136 reps136).all (indec 136) = true := rfl

set_option maxRecDepth 400000 in
theorem ap136 : (union 136 reps136).all (hasAP 136) = true := rfl

/-- the representatives are the first pair family [a, a+q, a+2q, a+3q, 2q+4a, 4q−8a], q = 34, a = 1, 2 -/
theorem fam136 : reps136 = [1, 2].map (fun a => [a, a + 34, a + 68, a + 102, 68 + 4 * a, 136 - 8 * a]) := rfl

end Unreached136

#print axioms Unreached136.size136
#print axioms Unreached136.irr136
#print axioms Unreached136.ap136
#print axioms Unreached136.fam136

#print axioms: 4 theorems, no axioms.

81.84 Orbit decomposition at \(m=132\) (Kamiak)

The 1058 unreached length-6 characters at \(m=132\) are the union of 55 twist orbits, all irreducible. \(|\bigcup _{r\in \text {reps}}\text {orbit}(r)|=1058,\ \text {all indec}\)

hodge/OrbitDecomp7.lean

/-
  hodge/OrbitDecomp7.lean — T41 cycle 368: Galois orbit decomposition of the full unreached set at m = 132.

  Lean 4 core plus hodge/OrbitDecomp (union), hodge/Indecomp (indec), rfl (Kamiak). The twist orbits of the 55
  representatives give the 1058 unreached characters of length 6 at m = 132 (all_132.jsonl); all are irreducible.
-/
import hodge.OrbitDecomp

namespace OrbitDecomp7
open Orbits Indecomp OrbitDecomp

def reps132 : List (List Nat) := [[1,  6,  21,  109,  129,  130],  [1,  16,  67,  88,  100,  124],  [1,  20,  67,  90,  92,  126],  [1,  21,  46,  90,  109,  129],  [1,  21,  69,  86,  89,  130],  [1,  21,  69,  89,  90,  126],  [1,  23,  67,  89,  90,  126],  [1,  25,  67,  88,  91,  124],  [1,  33,  50,  67,  121,  124],  [1,  33,  67,  74,  100,  121],  [1,  34,  67,  70,  100,  124],  [1,  44,  -- (+1434 chars; full line in the Zenodo source)

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size132 : Nat.beq (union 132 reps132).length 1058 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr132 : (union 132 reps132).all (indec 132) = true := rfl

end OrbitDecomp7

#print axioms OrbitDecomp7.size132
#print axioms OrbitDecomp7.irr132

#print axioms: 2 theorems, no axioms.

81.85 Unreached characters at \(m=140\)

114 unreached characters in 7 orbits: 108 irreducible (6 orbits, one of them the first pair family, \(q=35\), \(a=1\)) and one reducible orbit of 6 through \(m/2=70\), splitting as \(\{70\}\sqcup [2,58,86,90,114]\). \(\text {unreached}=\bigcup _{r\in \text {reps}}\text {orbit}(r),\ |{\cdot }|=114\)

hodge/Unreached140.lean

/-
  hodge/Unreached140.lean — T41 cycle 401 (goal G46, m = 140): the unreached characters of length 6 at m = 140
  (Kamiak a2_reach128, all_140.jsonl): 114 characters in 7 Galois orbits (sizes 24, 24, 24, 24, 6, 6, 6). Six orbits
  (108 characters) are irreducible; the orbit of [2, 58, 70, 86, 90, 114] (6 characters, containing m/2 = 70) is
  reducible (indec fails on all 6). One orbit (24) is the first pair family AP(a) + (2q + 4a, 4q − 8a), q = 35, a = 1.
-/
import hodge.Unreached80

namespace Unreached140
open Orbits Indecomp OrbitDecomp Unreached80

def reps140 : List (List Nat) :=
  [[1, 36, 71, 106, 74, 132], [1, 58, 71, 86, 90, 114], [2, 12, 86, 90, 114, 116], [2, 40, 48, 84, 122, 124],
   [2, 40, 58, 86, 114, 120], [2, 45, 58, 86, 114, 115], [2, 58, 70, 86, 90, 114]]

set_option maxRecDepth 400000 in
theorem size140 : Nat.beq (union 140 reps140).length 114 = true := rfl

set_option maxRecDepth 400000 in
theorem irr140 : (union 140 (reps140.take 6)).all (indec 140) = true := rfl

set_option maxRecDepth 400000 in
theorem red140 : (union 140 [[2, 58, 70, 86, 90, 114]]).all (fun c => !(indec 140 c)) = true := rfl

set_option maxRecDepth 400000 in
theorem size140red : Nat.beq (union 140 [[2, 58, 70, 86, 90, 114]]).length 6 = true := rfl

set_option maxRecDepth 400000 in
theorem fam140 : Nat.beq (union 140 [[1, 35 + 1, 70 + 1, 105 + 1, 70 + 4, 140 - 8]]).length 24 = true := rfl

set_option maxRecDepth 400000 in
theorem ap140 : (union 140 [[1, 36, 71, 106, 74, 132]]).all (hasAP 140) = true := rfl

/-- the reducible orbit splits as {m/2} ⊔ a balanced length-5 character (gcd 2, i.e. from m = 70) -/
theorem split140 : bal 140 [70] = true ∧ bal 140 [2, 58, 86, 90, 114] = true := ⟨rfl, rfl⟩

end Unreached140

#print axioms Unreached140.size140
#print axioms Unreached140.irr140
#print axioms Unreached140.red140
#print axioms Unreached140.size140red
#print axioms Unreached140.fam140
#print axioms Unreached140.ap140
#print axioms Unreached140.split140

#print axioms: 7 theorems, no axioms.

81.86 Unreached characters at \(m=144\)

796 unreached characters in 52 orbits: the first pair family (\(q=36\), \(a=1,2,3\)) gives 22, all irreducible; two orbits (20) through \(72\) are reducible, \(\{72\}\sqcup \) a balanced length-5 character. \(\text {fam}=\bigcup _{a\le 3}\text {orbit}\,[a,a+q,a+2q,a+3q,2q+4a,4q-8a]\)

hodge/Unreached144.lean

/-
  hodge/Unreached144.lean — T41 cycle 418 (goal G46, m = 144): the unreached characters of length 6 at m = 144
  (Kamiak a2_reach128, all_144.jsonl): 796 characters in 52 Galois orbits. The first pair family AP(a) + (2q + 4a,
  4q − 8a), q = 36, gives 22 of them (a = 1, 2, 3: orbits of 12, 6, 4), all irreducible. Two orbits (8 + 12
  characters) through m/2 = 72 are reducible, each = {72} ⊔ a balanced length-5 character, as at m = 140.
  The full decomposition (796 = 52 orbits, 50 irreducible): hodge/OrbitDecomp8 (Kamiak).
-/
import hodge.Unreached80

namespace Unreached144
open Orbits Indecomp OrbitDecomp Unreached80

/-- the first pair family [a, a+q, a+2q, a+3q, 2q+4a, 4q−8a], q = 36, a = 1, 2, 3 -/
def fam144 : List (List Nat) := [1, 2, 3].map (fun a => [a, a + 36, a + 72, a + 108, 72 + 4 * a, 144 - 8 * a])

set_option maxRecDepth 400000 in
theorem size144fam : Nat.beq (union 144 fam144).length 22 = true := rfl

set_option maxRecDepth 400000 in
theorem irr144fam : (union 144 fam144).all (indec 144) = true := rfl

set_option maxRecDepth 400000 in
theorem ap144fam : (union 144 fam144).all (hasAP 144) = true := rfl

def red144 : List (List Nat) := [[3, 51, 72, 81, 108, 117], [4, 20, 72, 100, 108, 128]]

set_option maxRecDepth 400000 in
theorem size144red : Nat.beq (union 144 red144).length 20 = true := rfl

set_option maxRecDepth 400000 in
theorem red144all : (union 144 red144).all (fun c => !(indec 144 c)) = true := rfl

theorem split144 : bal 144 [72] = true ∧ bal 144 [3, 51, 81, 108, 117] = true ∧ bal 144 [4, 20, 100, 108, 128] = true :=
  ⟨rfl, rfl, rfl⟩

end Unreached144

#print axioms Unreached144.size144fam
#print axioms Unreached144.irr144fam
#print axioms Unreached144.ap144fam
#print axioms Unreached144.size144red
#print axioms Unreached144.red144all
#print axioms Unreached144.split144

#print axioms: 6 theorems, no axioms.

81.87 Orbit decomposition at \(m=144\) (Kamiak)

The 796 unreached length-6 characters at \(m=144\) are 52 twist orbits; the 50 orbits other than Unreached144.red144 are irreducible. \(|\bigcup _{r\in \text {reps}}\text {orbit}(r)|=796\)

hodge/OrbitDecomp8.lean

/-
  hodge/OrbitDecomp8.lean — T41 cycle 418: Galois orbit decomposition of the unreached set at m = 144 (Kamiak).
  Lean 4 core plus hodge/OrbitDecomp (union), hodge/Indecomp (indec), rfl. The twist orbits of the 52 representatives
  give the 796 unreached characters of length 6 at m = 144 (all_144.jsonl); the 50 orbits of irr reps are irreducible
  (the other two, Unreached144.red144, are reducible).
-/
import hodge.OrbitDecomp

namespace OrbitDecomp8
open Orbits Indecomp OrbitDecomp

def reps144 : List (List Nat) := [[1, 6, 23, 119, 141, 142], [1, 22, 73, 98, 100, 138], [1, 23, 50, 98, 119, 141], [1, 25, 73, 97, 98, 138], [1, 37, 73, 76, 109, 136], [1, 50, 52, 73, 118, 138], [1, 50, 69, 73, 98, 141], [1, 50, 73, 78, 98, 132], [1, 50, 73, 96, 98, 114], [1, 50, 73, 98, 102, 108], [2, 12, 22, 118, 138, 140], [2, 20, 50, 114, 118, 128], [2, 20, 74, 100, 104, 132], [2, 20, 74, 100,  -- (+1055 chars; full line in the Zenodo source)

def irrReps144 : List (List Nat) := [[1, 6, 23, 119, 141, 142], [1, 22, 73, 98, 100, 138], [1, 23, 50, 98, 119, 141], [1, 25, 73, 97, 98, 138], [1, 37, 73, 76, 109, 136], [1, 50, 52, 73, 118, 138], [1, 50, 69, 73, 98, 141], [1, 50, 73, 78, 98, 132], [1, 50, 73, 96, 98, 114], [1, 50, 73, 98, 102, 108], [2, 12, 22, 118, 138, 140], [2, 20, 50, 114, 118, 128], [2, 20, 74, 100, 104, 132], [2, 20, 74, 1  -- (+1003 chars; full line in the Zenodo source)

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem size144 : Nat.beq (union 144 reps144).length 796 = true := rfl

set_option maxRecDepth 400000 in
set_option maxHeartbeats 0 in
theorem irr144 : (union 144 irrReps144).all (indec 144) = true := rfl

end OrbitDecomp8

#print axioms OrbitDecomp8.size144
#print axioms OrbitDecomp8.irr144

#print axioms: 2 theorems, no axioms.

81.88 The \(m/2\) split is an equivalence

For every even \(m=2h\) and every list \(B\): \(h::B\) is balanced iff \(B\) is balanced.

hodge/HalfIff.lean

/-
  hodge/HalfIff.lean — T41 cycle 700 (goal G413): the m/2 split is an equivalence, for every even m.

  Lean 4 core plus hodge/GcdHand (units_odd, rest_bal_even), hodge/HalfGeneral (half_mul), lib/Semi (lib_nat).
  For m = h + h, h > 0, and any list B:
    all_and        l.all p ∧ l.all q ⇒ l.all (p && q)
    half_cons_bal  B balanced ⇒ h :: B balanced
    half_iff       h :: B balanced ⇔ B balanced
  So a character through m/2 is Hodge exactly when the rest (of odd length for length-6 characters) is balanced:
  the ODD rule of hodge_reach_odd.py (goal G153) adds no new Hodge characters and misses none.
-/
import hodge.GcdHand
import lib.Semi

namespace HalfIff
open Indecomp HalfGeneral GcdHand

theorem all_and {α : Type} (p q : α → Bool) :
    ∀ l : List α, l.all p = true → l.all q = true → l.all (fun x => p x && q x) = true
  | [], _, _ => rfl
  | x :: l, h1, h2 => by
    have h1' : (p x && l.all p) = true := h1
    have h2' : (q x && l.all q) = true := h2
    cases a : p x <;> cases b : q x <;> rw [a] at h1' <;> rw [b] at h2'
    · exact Bool.noConfusion h1'
    · exact Bool.noConfusion h1'
    · exact Bool.noConfusion h2'
    · show ((p x && q x) && l.all _) = true
      rw [a, b, all_and p q l h1' h2']; rfl

theorem half_cons_bal (h : Nat) (hh : 0 < h) (B : List Nat) (hb : bal (h + h) B = true) :
    bal (h + h) (h :: B) = true := by
  unfold bal at hb ⊢
  have both := all_and _ _ _ (units_odd h) hb
  apply all_imp _ _ _ _ both
  intro t hboth
  have hb' : (isOdd t && Nat.beq (tsum (h + h) t B + tsum (h + h) t B) (B.length * (h + h))) = true := hboth
  cases a : isOdd t with
  | false => rw [a] at hb'; exact Bool.noConfusion hb'
  | true =>
    rw [a] at hb'
    have e := Nat.eq_of_beq_eq_true hb'
    show Nat.beq (t * h % (h + h) + tsum (h + h) t B + (t * h % (h + h) + tsum (h + h) t B))
      ((B.length + 1) * (h + h)) = true
    rw [half_mul h t hh a]
    have e2 : h + tsum (h + h) t B + (h + tsum (h + h) t B)
        = (tsum (h + h) t B + tsum (h + h) t B) + (h + h) := by lib_nat
    have e3 : (B.length + 1) * (h + h) = B.length * (h + h) + (h + h) := by lib_nat
    rw [e2, e3, e]
    exact beq_self _

theorem half_iff (h : Nat) (hh : 0 < h) (B : List Nat) :
    bal (h + h) (h :: B) = true ↔ bal (h + h) B = true :=
  ⟨rest_bal_even h hh B, half_cons_bal h hh B⟩

end HalfIff

#print axioms HalfIff.all_and
#print axioms HalfIff.half_cons_bal
#print axioms HalfIff.half_iff

#print axioms: 3 theorems, no axioms.

81.89 Balanced lists: append and cancel

Balanced lists are closed under \(\sqcup \) and cancellative, for every \(m\). \(A,B\) balanced \(\Rightarrow A\sqcup B\) balanced; \(A\), \(A\sqcup B\) balanced \(\Rightarrow B\) balanced.

hodge/BalAppend.lean

/-
  hodge/BalAppend.lean — T41 cycle 704 (goal G417): balanced lists form a cancellative monoid under ⊔, every m.

  Lean 4 core plus hodge/HalfIff (all_and), hodge/HalfGeneral (all_imp, beq_self), lib/Semi (lib_nat).
    tsum_app     T_t(A ++ B) = T_t(A) + T_t(B)
    len_app      |A ++ B| = |A| + |B|
    bal_append   A, B balanced ⇒ A ++ B balanced
    bal_cancel   A balanced, A ++ B balanced ⇒ B balanced
  So a Hodge character with a balanced sub-list A splits as A ⊔ B with B Hodge: reduction along any
  balanced block (pairs, m/2, longer blocks) is exact, in both directions.
-/
import hodge.HalfIff

namespace BalAppend
open Indecomp HalfGeneral HalfIff

theorem tsum_app (m t : Nat) : ∀ A B : List Nat, tsum m t (A ++ B) = tsum m t A + tsum m t B
  | [], B => (Nat.zero_add _).symm
  | a :: A, B => by
    show (t * a) % m + tsum m t (A ++ B) = ((t * a) % m + tsum m t A) + tsum m t B
    rw [tsum_app m t A B, Nat.add_assoc]

theorem len_app {α : Type} : ∀ A B : List α, (A ++ B).length = A.length + B.length
  | [], B => (Nat.zero_add _).symm
  | _ :: A, B => by
    show (A ++ B).length + 1 = (A.length + 1) + B.length
    rw [len_app A B]; lib_nat

theorem add_cancel (k : Nat) : ∀ x y : Nat, k + x = k + y → x = y := by
  induction k with
  | zero => intro x y h; rw [Nat.zero_add, Nat.zero_add] at h; exact h
  | succ k ih =>
    intro x y h
    apply ih
    have h' : (k + x) + 1 = (k + y) + 1 := by
      have e1 : k + 1 + x = (k + x) + 1 := by lib_nat
      have e2 : k + 1 + y = (k + y) + 1 := by lib_nat
      rw [← e1, ← e2]; exact h
    exact Nat.succ.inj h'

theorem bal_append (m : Nat) (A B : List Nat) (ha : bal m A = true) (hb : bal m B = true) :
    bal m (A ++ B) = true := by
  unfold bal at ha hb ⊢
  have both := all_and _ _ _ ha hb
  apply all_imp _ _ _ _ both
  intro t hboth
  have h2 : (Nat.beq (tsum m t A + tsum m t A) (A.length * m)
      && Nat.beq (tsum m t B + tsum m t B) (B.length * m)) = true := hboth
  cases a : Nat.beq (tsum m t A + tsum m t A) (A.length * m) with
  | false => rw [a] at h2; exact Bool.noConfusion h2
  | true =>
    rw [a] at h2
    have e1 := Nat.eq_of_beq_eq_true a
    have e2 := Nat.eq_of_beq_eq_true h2
    show Nat.beq (tsum m t (A ++ B) + tsum m t (A ++ B)) ((A ++ B).length * m) = true
    rw [tsum_app, len_app]
    have e3 : tsum m t A + tsum m t B + (tsum m t A + tsum m t B)
        = (tsum m t A + tsum m t A) + (tsum m t B + tsum m t B) := by lib_nat
    have e4 : (A.length + B.length) * m = A.length * m + B.length * m := by lib_nat
    rw [e3, e4, e1, e2]
    exact beq_self _

theorem bal_cancel (m : Nat) (A B : List Nat) (ha : bal m A = true) (hab : bal m (A ++ B) = true) :
    bal m B = true := by
  unfold bal at ha hab ⊢
  have both := all_and _ _ _ ha hab
  apply all_imp _ _ _ _ both
  intro t hboth
  have h2 : (Nat.beq (tsum m t A + tsum m t A) (A.length * m)
      && Nat.beq (tsum m t (A ++ B) + tsum m t (A ++ B)) ((A ++ B).length * m)) = true := hboth
  cases a : Nat.beq (tsum m t A + tsum m t A) (A.length * m) with
  | false => rw [a] at h2; exact Bool.noConfusion h2
  | true =>
    rw [a] at h2
    have e1 := Nat.eq_of_beq_eq_true a
    have e2 := Nat.eq_of_beq_eq_true h2
    rw [tsum_app, len_app] at e2
    have e3 : tsum m t A + tsum m t B + (tsum m t A + tsum m t B)
        = (tsum m t A + tsum m t A) + (tsum m t B + tsum m t B) := by lib_nat
    have e4 : (A.length + B.length) * m = A.length * m + B.length * m := by lib_nat
    rw [e3, e4, e1] at e2
    rw [add_cancel _ _ _ e2]
    exact beq_self _

end BalAppend

#print axioms BalAppend.tsum_app
#print axioms BalAppend.len_app
#print axioms BalAppend.add_cancel
#print axioms BalAppend.bal_append
#print axioms BalAppend.bal_cancel

#print axioms: 5 theorems, no axioms.

81.90 Complementary pairs are balanced

Every list of complementary pairs \(\{x,m-x\}\) is balanced, for every \(m\). \(x+y=m,\ 0<x,\ 0<y\Rightarrow [x,y]\) balanced; concatenations of such pairs are balanced.

hodge/PairBal.lean

/-
  hodge/PairBal.lean — T41 cycle 707 (goal G420): complementary pairs are balanced, and so is every list of them,
  for every m.

  Lean 4 core plus hodge/TwistBal (all_fr_intro), hodge/APPairGen (euclid), hodge/InductiveStep (pair_m),
  hodge/BalAppend (bal_append), lib/Semi (lib_nat).
    not_dv      gcd t m = 1, 0 < x < m  ⇒  m ∤ t·x
    pair_bal    x + y = m, 0 < x, 0 < y  ⇒  [x, y] balanced
    bal_nil     [] balanced
    pairs_bal   every concatenation of complementary pairs is balanced
  The pair part of Shioda's inductive structure at character level: every product of pair classes is Hodge.
-/
import hodge.TwistBal
import hodge.InductiveStep
import hodge.BalAppend

namespace PairBal
open FTAChain Indecomp HalfGeneral APPairGen TwistBal BalAppend

theorem not_dv (m' t x : Nat) (ht : Nat.gcd t (m' + 1) = 1) (hx0 : 0 < x) (hxm : x < m' + 1) :
    ¬ Dv (m' + 1) (t * x) := by
  intro hd
  cases hd with
  | intro q hq =>
    have e := euclid t (m' + 1) (m' + 1) x ht ⟨q, by rw [hq, Nat.mul_comm]⟩ ⟨x, rfl⟩
    cases e with
    | intro k hk =>
      match k, hk with
      | 0, hk => rw [hk] at hx0; exact Nat.lt_irrefl 0 hx0
      | k + 1, hk =>
        have g : m' + 1 ≤ (m' + 1) * (k + 1) := by
          have e2 : (m' + 1) * (k + 1) = (m' + 1) * k + (m' + 1) := rfl
          rw [e2]; exact Nat.le_add_left _ _
        rw [← hk] at g
        exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le hxm g)

theorem pair_bal (m' x y : Nat) (hxy : x + y = m' + 1) (hx0 : 0 < x) (hy0 : 0 < y) :
    bal (m' + 1) [x, y] = true := by
  unfold bal FermatPrime.units
  apply all_fr_intro
  intro t _ hp
  have ht : Nat.gcd t (m' + 1) = 1 := Nat.eq_of_beq_eq_true hp
  have hxm : x < m' + 1 := by rw [← hxy]; exact Nat.lt_add_of_pos_right hy0
  have pm := InductiveStep.pair_m m' t x y hxy (not_dv m' t x ht hx0 hxm)
  show Nat.beq ((t * x) % (m' + 1) + ((t * y) % (m' + 1) + 0) + ((t * x) % (m' + 1) + ((t * y) % (m' + 1) + 0)))
    (2 * (m' + 1)) = true
  generalize (t * x) % (m' + 1) = a at pm ⊢
  generalize (t * y) % (m' + 1) = b at pm ⊢
  have e : a + (b + 0) + (a + (b + 0)) = (a + b) + (a + b) := by lib_nat
  have e2 : m' + 1 + (m' + 1) = 2 * (m' + 1) := by lib_nat
  rw [e, pm, e2]; exact beq_self _

theorem bal_nil (m : Nat) : bal m [] = true := by
  unfold bal
  apply all_imp (fun _ => true) _ _ _ (all_true _)
  intro t _
  show Nat.beq (0 + 0) (0 * m) = true
  rw [Nat.zero_mul]; rfl
where
  all_true : ∀ l : List Nat, l.all (fun _ => true) = true
    | [] => rfl
    | _ :: l => all_true l

def flat : List (Nat × Nat) → List Nat
  | [] => []
  | (x, y) :: ps => [x, y] ++ flat ps

theorem pairs_bal (m' : Nat) : ∀ ps : List (Nat × Nat),
    (∀ p, p ∈ ps → p.1 + p.2 = m' + 1 ∧ 0 < p.1 ∧ 0 < p.2) → bal (m' + 1) (flat ps) = true
  | [], _ => bal_nil _
  | (x, y) :: ps, h => by
    have h0 := h (x, y) (List.Mem.head _)
    exact bal_append _ _ _ (pair_bal m' x y h0.1 h0.2.1 h0.2.2)
      (pairs_bal m' ps (fun p hp => h p (List.Mem.tail _ hp)))

end PairBal

#print axioms PairBal.not_dv
#print axioms PairBal.pair_bal
#print axioms PairBal.bal_nil
#print axioms PairBal.pairs_bal

#print axioms: 4 theorems, no axioms.

81.91 Two-element characters

A two-element character is balanced exactly when it is a complementary pair, every \(m\ge 2\). \(0<x,y<m:\ [x,y]\) balanced \(\Leftrightarrow x+y=m\).

hodge/PairIff.lean

/-
  hodge/PairIff.lean — T41 cycle 710 (goal G423): a two-element character is balanced exactly when it is a
  complementary pair, for every m ≥ 2.

  Lean 4 core plus hodge/PairBal (pair_bal), hodge/APPairIrrGen (gcd_one), hodge/TwistBal (all_fr_elim),
  hodge/ModHand (mod_lt'), lib/Semi (lib_nat).
    dbl_inj    a + a = b + b ⇒ a = b
    pair_iff   0 < x, y < m:  [x, y] balanced  ⇔  x + y = m
  So the length-2 Hodge classes on X^1 are exactly Shioda's pair classes (t = 1 alone decides).
-/
import hodge.PairBal

namespace PairIff
open FTAChain Indecomp HalfGeneral APPairGen TwistBal BalAppend PairBal ModHand

theorem dbl_inj : ∀ a b : Nat, a + a = b + b → a = b
  | 0, 0, _ => rfl
  | 0, b + 1, h => by
    have e : b + 1 + (b + 1) = (b + b + 1) + 1 := by lib_nat
    rw [e] at h; exact Nat.noConfusion h
  | a + 1, 0, h => by
    have e : a + 1 + (a + 1) = (a + a + 1) + 1 := by lib_nat
    rw [e] at h; exact Nat.noConfusion h
  | a + 1, b + 1, h => by
    have e1 : a + 1 + (a + 1) = (a + a + 1) + 1 := by lib_nat
    have e2 : b + 1 + (b + 1) = (b + b + 1) + 1 := by lib_nat
    rw [e1, e2] at h
    rw [dbl_inj a b (Nat.succ.inj (Nat.succ.inj h))]

theorem pair_iff (n x y : Nat) (hx0 : 0 < x) (hy0 : 0 < y) (hx : x < n + 2) (hy : y < n + 2) :
    bal (n + 2) [x, y] = true ↔ x + y = n + 2 := by
  constructor
  · intro hb
    unfold bal FermatPrime.units at hb
    have h1 := all_fr_elim _ _ (n + 2) hb 1 (Nat.lt_of_lt_of_le (Nat.lt_succ_self 1) (Nat.le_add_left 2 n))
      (by show Nat.beq (Nat.gcd 1 (n + 2)) 1 = true; rw [APPairIrrGen.gcd_one]; rfl)
    have e := Nat.eq_of_beq_eq_true h1
    have e' : (1 * x) % (n + 2) + ((1 * y) % (n + 2) + 0) + ((1 * x) % (n + 2) + ((1 * y) % (n + 2) + 0))
        = 2 * (n + 2) := e
    rw [Nat.one_mul, Nat.one_mul, mod_lt' x _ hx, mod_lt' y _ hy] at e'
    have e2 : x + (y + 0) + (x + (y + 0)) = (x + y) + (x + y) := by lib_nat
    have e3 : 2 * (n + 2) = (n + 2) + (n + 2) := by lib_nat
    rw [e2, e3] at e'
    exact dbl_inj _ _ e'
  · intro h
    exact pair_bal (n + 1) x y h hx0 hy0

end PairIff

#print axioms PairIff.dbl_inj
#print axioms PairIff.pair_iff

#print axioms: 2 theorems, no axioms.

81.92 Pair reduction and one-element characters

Stripping a complementary pair is exact; the one-element balanced characters are exactly \(\{m/2\}\). \([x,m-x]\sqcup B\) balanced \(\Leftrightarrow B\) balanced; \([x]\) balanced \(\Leftrightarrow 2x=m\).

hodge/PairReduce.lean

/-
  hodge/PairReduce.lean — T41 cycle 713 (goal G426): pair reduction is exact and the one-element characters are
  exactly {m/2}, for every m.

  Lean 4 core plus hodge/PairIff, hodge/GcdHand (half_bal_even), hodge/ModHand (mod_lt'), lib/Semi (lib_nat).
    pair_reduce  x + y = m, 0 < x, y:  [x, y] ++ B balanced ⇔ B balanced
    single_iff   0 < x < m:  [x] balanced ⇔ x + x = m
  With HalfIff and BalAppend: stripping complementary pairs and m/2 from a character never changes whether it is Hodge.
-/
import hodge.PairIff

namespace PairReduce
open FTAChain Indecomp HalfGeneral APPairGen TwistBal BalAppend PairBal PairIff ModHand GcdHand

theorem pair_reduce (m' x y : Nat) (hxy : x + y = m' + 1) (hx0 : 0 < x) (hy0 : 0 < y) (B : List Nat) :
    bal (m' + 1) ([x, y] ++ B) = true ↔ bal (m' + 1) B = true :=
  ⟨bal_cancel _ _ _ (pair_bal m' x y hxy hx0 hy0), bal_append _ _ _ (pair_bal m' x y hxy hx0 hy0)⟩

theorem single_iff (n x : Nat) (hx0 : 0 < x) (hx : x < n + 2) :
    bal (n + 2) [x] = true ↔ x + x = n + 2 := by
  constructor
  · intro hb
    unfold bal FermatPrime.units at hb
    have h1 := all_fr_elim _ _ (n + 2) hb 1 (Nat.lt_of_lt_of_le (Nat.lt_succ_self 1) (Nat.le_add_left 2 n))
      (by show Nat.beq (Nat.gcd 1 (n + 2)) 1 = true; rw [APPairIrrGen.gcd_one]; rfl)
    have e := Nat.eq_of_beq_eq_true h1
    have e' : (1 * x) % (n + 2) + 0 + ((1 * x) % (n + 2) + 0) = 1 * (n + 2) := e
    rw [Nat.one_mul, Nat.one_mul, mod_lt' x _ hx, Nat.add_zero] at e'
    exact e'
  · intro h
    rw [← h]
    exact half_bal_even x hx0

end PairReduce

#print axioms PairReduce.pair_reduce
#print axioms PairReduce.single_iff

#print axioms: 2 theorems, no axioms.

81.93 The complement map keeps balance

The conjugate character \(m-c\) of a balanced \(c\) (entries in \((0,m)\)) is balanced, every \(m\). \(T_t(c)+T_t(m-c)=|c|\,m\) for units \(t\); \(c\) balanced \(\Rightarrow m-c\) balanced.

hodge/NegBal.lean

/-
  hodge/NegBal.lean — T41 cycle 716 (goal G429): the complement map x ↦ m − x preserves balance, every m.

  Lean 4 core plus hodge/PairReduce (PairBal.not_dv, InductiveStep.pair_m, BalAppend.add_cancel),
  hodge/TwistBal (all_fr_elim, all_fr_intro), hodge/GcdHand (sub_add'), hodge/APPairIrrGen (length_map').
    tsum_neg   unit t, 0 < x < m on c:  T_t(c) + T_t(m − c) = |c|·m
    neg_bal    c balanced  ⇒  m − c balanced
  The complex-conjugate character: its Hodge type is swapped (p, q) ↦ (q, p) and balance is kept.
-/
import hodge.PairReduce

namespace NegBal
open FTAChain Indecomp HalfGeneral APPairGen TwistBal BalAppend PairBal ModHand GcdHand APPairIrrGen

def neg (M : Nat) (c : List Nat) : List Nat := c.map (fun x => M - x)

theorem tsum_neg (m' t : Nat) (ht : Nat.gcd t (m' + 1) = 1) :
    ∀ c : List Nat, (∀ x, x ∈ c → 0 < x ∧ x < m' + 1) →
      tsum (m' + 1) t c + tsum (m' + 1) t (neg (m' + 1) c) = c.length * (m' + 1)
  | [], _ => by show 0 + 0 = 0 * (m' + 1); rw [Nat.zero_mul]
  | x :: c, h => by
    have hx := h x (List.Mem.head _)
    have ih := tsum_neg m' t ht c (fun y hy => h y (List.Mem.tail _ hy))
    have hs : x + (m' + 1 - x) = m' + 1 := by
      rw [Nat.add_comm]; exact sub_add' x (m' + 1) (Nat.le_of_lt hx.2)
    have pm := InductiveStep.pair_m m' t x (m' + 1 - x) hs (not_dv m' t x ht hx.1 hx.2)
    show (t * x) % (m' + 1) + tsum (m' + 1) t c
        + ((t * (m' + 1 - x)) % (m' + 1) + tsum (m' + 1) t (neg (m' + 1) c)) = (c.length + 1) * (m' + 1)
    generalize (t * x) % (m' + 1) = p at pm ⊢
    generalize (t * (m' + 1 - x)) % (m' + 1) = q at pm ⊢
    generalize tsum (m' + 1) t c = a at ih ⊢
    generalize tsum (m' + 1) t (neg (m' + 1) c) = b at ih ⊢
    have e : p + a + (q + b) = (p + q) + (a + b) := by lib_nat
    have e2 : (c.length + 1) * (m' + 1) = c.length * (m' + 1) + (m' + 1) := by lib_nat
    rw [e, pm, ih, e2, Nat.add_comm]

theorem neg_bal (m' : Nat) (c : List Nat) (hc : ∀ x, x ∈ c → 0 < x ∧ x < m' + 1)
    (hb : bal (m' + 1) c = true) : bal (m' + 1) (neg (m' + 1) c) = true := by
  unfold bal FermatPrime.units at *
  apply all_fr_intro
  intro t ht hp
  have h := Nat.eq_of_beq_eq_true (all_fr_elim _ _ (m' + 1) hb t ht hp)
  have hs := tsum_neg m' t (Nat.eq_of_beq_eq_true hp) c hc
  show Nat.beq (tsum (m' + 1) t (neg (m' + 1) c) + tsum (m' + 1) t (neg (m' + 1) c))
    ((neg (m' + 1) c).length * (m' + 1)) = true
  have hl : (neg (m' + 1) c).length = c.length := length_map' _ c
  rw [hl]
  rw [← h] at hs
  have e := add_cancel _ _ _ hs
  rw [e, h]
  exact beq_self _

end NegBal

#print axioms NegBal.tsum_neg
#print axioms NegBal.neg_bal

#print axioms: 2 theorems, no axioms.

81.94 The units \(t\) and \(m-t\) give the same condition

Balance needs checking only for units \(t<m/2\), every \(m\). \(T_t(c)+T_{m-t}(c)=|c|\,m\); \(2T_t(c)=|c|m\Leftrightarrow 2T_{m-t}(c)=|c|m\).

hodge/UnitSym.lean

/-
  hodge/UnitSym.lean — T41 cycle 720 (goal G434): the balance conditions for t and m − t are equivalent, so only
  the units t < m/2 need checking, every m.

  Lean 4 core plus hodge/NegBal (PairBal.not_dv, InductiveStep.pair_m, BalAppend.add_cancel), lib/Semi (lib_nat).
    tsum_sym   unit t, 0 < x < m on c:  T_t(c) + T_{m−t}(c) = |c|·m
    unit_sym   2T_t(c) = |c|m  ⇔  2T_{m−t}(c) = |c|m
-/
import hodge.NegBal

namespace UnitSym
open FTAChain Indecomp HalfGeneral BalAppend PairBal GcdHand

theorem tsum_sym (m' t : Nat) (ht : Nat.gcd t (m' + 1) = 1) (htm : t < m' + 1) :
    ∀ c : List Nat, (∀ x, x ∈ c → 0 < x ∧ x < m' + 1) →
      tsum (m' + 1) t c + tsum (m' + 1) (m' + 1 - t) c = c.length * (m' + 1)
  | [], _ => by show 0 + 0 = 0 * (m' + 1); rw [Nat.zero_mul]
  | x :: c, h => by
    have hx := h x (List.Mem.head _)
    have ih := tsum_sym m' t ht htm c (fun y hy => h y (List.Mem.tail _ hy))
    have hs : t + (m' + 1 - t) = m' + 1 := by
      rw [Nat.add_comm]; exact sub_add' t (m' + 1) (Nat.le_of_lt htm)
    have nd : ¬ Dv (m' + 1) (x * t) := by
      rw [Nat.mul_comm]; exact not_dv m' t x ht hx.1 hx.2
    have pm := InductiveStep.pair_m m' x t (m' + 1 - t) hs nd
    rw [Nat.mul_comm x t, Nat.mul_comm x (m' + 1 - t)] at pm
    show (t * x) % (m' + 1) + tsum (m' + 1) t c
        + (((m' + 1 - t) * x) % (m' + 1) + tsum (m' + 1) (m' + 1 - t) c) = (c.length + 1) * (m' + 1)
    generalize (t * x) % (m' + 1) = p at pm ⊢
    generalize ((m' + 1 - t) * x) % (m' + 1) = q at pm ⊢
    generalize tsum (m' + 1) t c = a at ih ⊢
    generalize tsum (m' + 1) (m' + 1 - t) c = b at ih ⊢
    have e : p + a + (q + b) = (p + q) + (a + b) := by lib_nat
    have e2 : (c.length + 1) * (m' + 1) = c.length * (m' + 1) + (m' + 1) := by lib_nat
    rw [e, pm, ih, e2, Nat.add_comm]

theorem unit_sym (m' t : Nat) (ht : Nat.gcd t (m' + 1) = 1) (htm : t < m' + 1) (c : List Nat)
    (hc : ∀ x, x ∈ c → 0 < x ∧ x < m' + 1) :
    tsum (m' + 1) t c + tsum (m' + 1) t c = c.length * (m' + 1) ↔
      tsum (m' + 1) (m' + 1 - t) c + tsum (m' + 1) (m' + 1 - t) c = c.length * (m' + 1) := by
  have hs := tsum_sym m' t ht htm c hc
  constructor
  · intro h
    rw [← h] at hs
    have e := add_cancel _ _ _ hs
    rw [e]; exact h
  · intro h
    rw [← h, Nat.add_comm] at hs
    have e := add_cancel _ _ _ hs
    rw [e]; exact h

end UnitSym

#print axioms UnitSym.tsum_sym
#print axioms UnitSym.unit_sym

#print axioms: 2 theorems, no axioms.

81.95 Half of the units suffice

The balance test restricted to units \(t\) with \(2t\le m\) already implies balance, every \(m\). \(\gcd (t,m)=1\Rightarrow \gcd (m-t,m)=1\); \(\mathrm {balH}\,m\,c\Rightarrow \mathrm {bal}\,m\,c\).

hodge/HalfUnits.lean

/-
  hodge/HalfUnits.lean — T41 cycle 723 (goal G436): balance can be checked on the units t with 2t ≤ m only,
  every m.

  Lean 4 core plus hodge/UnitSym (unit_sym), hodge/UnitMul (gcd_dvd, one_of_dvd_one), hodge/APPair1 (dvd_gcd),
  hodge/TwistBal (all_fr_elim, all_fr_intro), hodge/GcdHand (sub_add'), hodge/ModHand (add_sub').
    dvd_of_add  x + g·i = g·j ⇒ g ∣ x
    gcd_sub     gcd t m = 1, t ≤ m ⇒ gcd (m − t) m = 1
    balH        the balance test restricted to units t with 2t ≤ m
    bal_half    balH m c ⇒ bal m c     (entries of c in (0, m))
-/
import hodge.UnitSym

namespace HalfUnits
open FTAChain Indecomp HalfGeneral BalAppend PairBal GcdHand ModHand TwistBal UnitSym UnitMul

theorem dvd_of_add (g : Nat) : ∀ (i j x : Nat), x + g * i = g * j → ∃ c, x = g * c
  | 0, j, x, h => ⟨j, h⟩
  | i + 1, 0, x, h => by
    have e : x + g * (i + 1) = (x + g * i) + g := by lib_nat
    rw [e] at h
    have h0 : (x + g * i) + g = 0 := h
    cases g with
    | zero =>
      have h1 : x + 0 * i = 0 := h0
      rw [Nat.zero_mul] at h1
      exact ⟨0, h1⟩
    | succ g => exact Nat.noConfusion h0
  | i + 1, j + 1, x, h => by
    have e : x + g * (i + 1) = (x + g * i) + g := by lib_nat
    have e2 : g * (j + 1) = g * j + g := rfl
    rw [e, e2, Nat.add_comm (x + g * i), Nat.add_comm (g * j)] at h
    exact dvd_of_add g i j x (add_cancel g _ _ h)

theorem gcd_sub (t m : Nat) (ht : Nat.gcd t m = 1) (hle : t ≤ m) : Nat.gcd (m - t) m = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := gcd_dvd (m - t) m
  generalize Nat.gcd (m - t) m = g at hi hj ⊢
  have hs : t + (m - t) = m := by rw [Nat.add_comm]; exact sub_add' t m hle
  have ht' : ∃ c, t = g * c := by
    apply dvd_of_add g i j t
    rw [← hi, ← hj]; exact hs
  have ⟨c, hc⟩ := APPair1.dvd_gcd g t m ht' ⟨j, hj⟩
  rw [ht] at hc
  exact one_of_dvd_one g c hc

theorem sub_sub' (m t : Nat) (h : t ≤ m) : m - (m - t) = t := by
  have e : m = (m - t) + t := (sub_add' t m h).symm
  have e2 : m - (m - t) = ((m - t) + t) - (m - t) := by rw [← e]
  rw [e2, Nat.add_comm, add_sub']

def balH (m : Nat) (A : List Nat) : Bool :=
  ((List.range m).filter (fun t => Nat.beq (Nat.gcd t m) 1 && Nat.ble (t + t) m)).all
    (fun t => Nat.beq (tsum m t A + tsum m t A) (A.length * m))

theorem bal_half (m' : Nat) (c : List Nat) (hc : ∀ x, x ∈ c → 0 < x ∧ x < m' + 1)
    (hb : balH (m' + 1) c = true) : bal (m' + 1) c = true := by
  unfold bal FermatPrime.units
  apply all_fr_intro
  intro t htm hp
  have hg : Nat.gcd t (m' + 1) = 1 := Nat.eq_of_beq_eq_true hp
  cases hl : Nat.ble (t + t) (m' + 1) with
  | true =>
    exact all_fr_elim _ _ (m' + 1) hb t htm (by rw [hp, hl]; rfl)
  | false =>
    have nle : ¬ (t + t ≤ m' + 1) := fun q => by rw [Nat.ble_eq_true_of_le q] at hl; exact Bool.noConfusion hl
    have hle : t ≤ m' + 1 := Nat.le_of_lt htm
    have hs : (m' + 1 - t) + t = m' + 1 := sub_add' t (m' + 1) hle
    generalize ht' : m' + 1 - t = u at hs
    have hlt : u < t := by
      cases Nat.lt_or_ge u t with
      | inl q => exact q
      | inr q => exact absurd (by rw [← hs]; exact Nat.add_le_add_right q t) nle
    have huu : u + u ≤ m' + 1 := by rw [← hs]; exact Nat.add_le_add_left (Nat.le_of_lt hlt) u
    have hum : u < m' + 1 := Nat.lt_of_lt_of_le hlt hle
    have hgu : Nat.gcd u (m' + 1) = 1 := by rw [← ht']; exact gcd_sub t (m' + 1) hg hle
    have hbu := Nat.eq_of_beq_eq_true (all_fr_elim _ _ (m' + 1) hb u hum
      (by show (Nat.beq (Nat.gcd u (m' + 1)) 1 && Nat.ble (u + u) (m' + 1)) = true
          rw [hgu, Nat.ble_eq_true_of_le huu]; rfl))
    have hsym := (unit_sym m' u hgu hum c hc).1 hbu
    have hmu : m' + 1 - u = t := by rw [← ht']; exact sub_sub' (m' + 1) t hle
    rw [hmu] at hsym
    rw [hsym]; exact beq_self _

end HalfUnits

#print axioms HalfUnits.dvd_of_add
#print axioms HalfUnits.gcd_sub
#print axioms HalfUnits.sub_sub'
#print axioms HalfUnits.bal_half

#print axioms: 4 theorems, no axioms.

81.96 Balance equals the half-unit test

For entries in \((0,m)\) the full and half-unit tests agree; an \(m=96\) character checked by the half test. \(\mathrm {bal}\,m\,c\Leftrightarrow \mathrm {balH}\,m\,c\); \([1,25,49,73,46,94]\) balanced for \(m=96\).

hodge/HalfUnitsIff.lean

/-
  hodge/HalfUnitsIff.lean — T41 cycle 726 (goal G439): balance ⇔ the half-unit test, and the half test in use.

  Lean 4 core plus hodge/HalfUnits (balH, bal_half), hodge/TwistBal (all_fr_elim, all_fr_intro).
    balH_of_bal   bal m c ⇒ balH m c
    bal_iff_balH  entries in (0, m):  bal m c ⇔ balH m c
    ex96          the m = 96 character [1, 25, 49, 73, 46, 94] (APPair2) by the half test (rfl) and bal_half
-/
import hodge.HalfUnits

namespace HalfUnitsIff
open Indecomp HalfGeneral TwistBal HalfUnits

theorem balH_of_bal (m : Nat) (c : List Nat) (hb : bal m c = true) : balH m c = true := by
  unfold bal FermatPrime.units at hb
  unfold balH
  apply all_fr_intro
  intro t ht hp
  have hp' : (Nat.beq (Nat.gcd t m) 1 && Nat.ble (t + t) m) = true := hp
  cases q : Nat.beq (Nat.gcd t m) 1 with
  | false => rw [q] at hp'; exact Bool.noConfusion hp'
  | true => exact all_fr_elim _ _ m hb t ht q

theorem bal_iff_balH (m' : Nat) (c : List Nat) (hc : ∀ x, x ∈ c → 0 < x ∧ x < m' + 1) :
    bal (m' + 1) c = true ↔ balH (m' + 1) c = true :=
  ⟨balH_of_bal _ c, bal_half m' c hc⟩

theorem mem_range (c : List Nat) (m' : Nat) (h : c.all (fun x => Nat.ble 1 x && Nat.ble (x + 1) (m' + 1)) = true) :
    ∀ x, x ∈ c → 0 < x ∧ x < m' + 1 := by
  intro x hx
  induction c with
  | nil => cases hx
  | cons y l ih =>
    have h' : ((Nat.ble 1 y && Nat.ble (y + 1) (m' + 1)) && l.all _) = true := h
    cases a : (Nat.ble 1 y && Nat.ble (y + 1) (m' + 1)) with
    | false => rw [a] at h'; exact Bool.noConfusion h'
    | true =>
      rw [a] at h'
      cases hx with
      | head =>
        cases b : Nat.ble 1 x with
        | false => rw [b] at a; exact Bool.noConfusion a
        | true =>
          rw [b] at a
          exact ⟨Nat.le_of_ble_eq_true b, Nat.le_of_ble_eq_true a⟩
      | tail _ hx' => exact ih h' hx'

theorem ex96 : bal 96 [1, 25, 49, 73, 46, 94] = true :=
  bal_half 95 _ (mem_range _ 95 rfl) rfl

end HalfUnitsIff

#print axioms HalfUnitsIff.balH_of_bal
#print axioms HalfUnitsIff.bal_iff_balH
#print axioms HalfUnitsIff.mem_range
#print axioms HalfUnitsIff.ex96

#print axioms: 4 theorems, no axioms.

81.97 A three-term family for every even \(m\)

For \(m=2h\) and \(0<a<h\) the character \([a,\,h+a,\,2h-2a]\) is balanced. \(\langle ta\rangle +\langle t(h+a)\rangle +\langle t(2h-2a)\rangle =3h\) for every unit \(t\).

hodge/Triple.lean

/-
  hodge/Triple.lean — T41 cycle 729 (goal G442): the three-term family [a, h + a, 2h − 2a] is balanced for every
  even m = 2h and every 0 < a < h (numerically: all length-3 balanced lists without m/2 for m ≤ 60 include it).

  Lean 4 core plus hodge/PairBal (not_dv), hodge/InductiveStep (pair_m), hodge/GcdHand (unit_isOdd, parity, div_mod,
  sub_add'), hodge/ModHand (mod_lt', add_mod', add_mul_mod'), hodge/TwistBal (all_fr_intro), lib/Semi (lib_nat).
    odd_form    isOdd t ⇒ t = 2s + 1
    le_dest     m ≤ p ⇒ m + d = p
    triple_bal  0 < a < h  ⇒  [a, h + a, 2h − 2a] balanced for m = 2h
  Proof per unit t (odd): with r = ⟨ta⟩ ≠ h, ⟨t(h+a)⟩ = ⟨r + h⟩, ⟨t(2h−2a)⟩ = m − ⟨2r⟩, and the sum is 3h in both
  cases r < h, r > h.
-/
import hodge.PairBal

namespace Triple
open FTAChain Indecomp HalfGeneral GcdHand ModHand TwistBal PairBal TorsionImage

theorem isOdd_even : ∀ c, isOdd (2 * c) = false
  | 0 => rfl
  | c + 1 => by rw [show 2 * (c + 1) = 2 * c + 2 by lib_nat]; exact isOdd_even c

theorem odd_form (t : Nat) (h : isOdd t = true) : ∃ s, t = 2 * s + 1 := by
  have ⟨c, hc⟩ := parity t
  cases hc with
  | inl e => rw [e, isOdd_even] at h; exact Bool.noConfusion h
  | inr e => exact ⟨c, e⟩

theorem le_dest {m p : Nat} (h : m ≤ p) : ∃ d, m + d = p := by
  induction h with
  | refl => exact ⟨0, rfl⟩
  | step _ ih =>
    cases ih with
    | intro d hd => exact ⟨d + 1, by rw [← hd]; rfl⟩

theorem triple_bal (h0 a : Nat) (ha0 : 0 < a) (hah : a < h0 + 1) :
    bal ((h0 + 1) + (h0 + 1)) [a, (h0 + 1) + a, ((h0 + 1) + (h0 + 1)) - (a + a)] = true := by
  generalize hH : h0 + 1 = h at hah
  have hpos : 0 < h := by rw [← hH]; exact Nat.succ_pos h0
  have hM : 0 < h + h := Nat.lt_of_lt_of_le hpos (Nat.le_add_right h h)
  have haa : a + a ≤ h + h := Nat.add_le_add (Nat.le_of_lt hah) (Nat.le_of_lt hah)
  generalize hz : (h + h) - (a + a) = z
  have hza : z + (a + a) = h + h := by rw [← hz]; exact sub_add' _ _ haa
  have hz0 : 0 < z := by
    cases z with
    | zero =>
      rw [Nat.zero_add] at hza
      exact absurd hza (Nat.ne_of_lt (Nat.add_lt_add hah hah))
    | succ z => exact Nat.succ_pos z
  have hzm : z < h + h := by
    rw [← hza]; exact Nat.lt_add_of_pos_right (Nat.add_pos_left ha0 a)
  unfold bal FermatPrime.units
  apply all_fr_intro
  intro t _ hp
  have hg : Nat.gcd t (h + h) = 1 := Nat.eq_of_beq_eq_true hp
  have ⟨s, hs⟩ := odd_form t (unit_isOdd h t hg)
  have ⟨q, hq⟩ := div_mod (h + h) hM (t * a + 1) (t * a) (Nat.lt_succ_self _)
  generalize hr : (t * a) % (h + h) = r at hq
  have hrm : r < h + h := by rw [← hr]; exact Nat.mod_lt _ hM
  -- ⟨t(h+a)⟩ = ⟨r + h⟩ and ⟨t(a+a)⟩ = ⟨r + r⟩
  have e1 : (t * (h + a)) % (h + h) = (r + h) % (h + h) := by
    have : t * (h + a) = (r + h) + (s + q) * (h + h) := by
      have x1 : t * (h + a) = t * a + t * h := by lib_nat
      rw [x1, hq, hs]; lib_nat
    rw [this]; exact add_mul_mod' _ _ hM _
  have e2 : (t * (a + a)) % (h + h) = (r + r) % (h + h) := by
    have : t * (a + a) = (r + r) + (q + q) * (h + h) := by
      have x1 : t * (a + a) = t * a + t * a := by lib_nat
      rw [x1, hq]; lib_nat
    rw [this]; exact add_mul_mod' _ _ hM _
  -- ⟨tz⟩ + ⟨t(a+a)⟩ = m
  have hm' : ∃ m', h + h = m' + 1 := by
    cases hH; exact ⟨h0 + 1 + h0, rfl⟩
  have ⟨m', hm'e⟩ := hm'
  have pm : (t * z) % (h + h) + (t * (a + a)) % (h + h) = h + h := by
    rw [hm'e] at hza hzm hg ⊢
    exact InductiveStep.pair_m m' t z (a + a) hza (not_dv m' t z hg hz0 hzm)
  rw [e2] at pm
  have hu : (t * z) % (h + h) < h + h := Nat.mod_lt _ hM
  show Nat.beq ((t * a) % (h + h) + ((t * (h + a)) % (h + h) + ((t * z) % (h + h) + 0))
      + ((t * a) % (h + h) + ((t * (h + a)) % (h + h) + ((t * z) % (h + h) + 0)))) (3 * (h + h)) = true
  rw [e1, hr]
  generalize (t * z) % (h + h) = u at pm hu ⊢
  cases Nat.lt_or_ge r h with
  | inl lt =>
    have a1 : (r + h) % (h + h) = r + h := mod_lt' _ _ (Nat.add_lt_add_right lt h)
    have a2 : (r + r) % (h + h) = r + r := mod_lt' _ _ (Nat.add_lt_add lt lt)
    rw [a1]; rw [a2] at pm
    have x : r + (r + h + (u + 0)) + (r + (r + h + (u + 0))) = (u + (r + r)) + (u + (r + r)) + (h + h) := by lib_nat
    rw [x, pm]
    have y : h + h + (h + h) + (h + h) = 3 * (h + h) := by lib_nat
    rw [y]; exact beq_self _
  | inr ge =>
    have ⟨e, he⟩ := le_dest ge
    rw [← he] at hrm ⊢; rw [← he] at pm
    cases e with
    | zero =>
      have a2 : (h + 0 + (h + 0)) % (h + h) = 0 := by
        rw [show h + 0 + (h + 0) = 0 + (h + h) by lib_nat, add_mod' _ _ hM]; rfl
      rw [a2, Nat.add_zero] at pm
      rw [pm] at hu; exact absurd hu (Nat.lt_irrefl _)
    | succ e =>
      have elt : e + 1 < h := by
        have : h + (e + 1) < h + h := hrm
        exact Nat.lt_of_add_lt_add_left this
      have a1 : (h + (e + 1) + h) % (h + h) = e + 1 := by
        rw [show h + (e + 1) + h = (e + 1) + (h + h) by lib_nat, add_mod' _ _ hM]
        exact mod_lt' _ _ (Nat.lt_of_lt_of_le elt (Nat.le_add_right h h))
      have a2 : (h + (e + 1) + (h + (e + 1))) % (h + h) = (e + 1) + (e + 1) := by
        rw [show h + (e + 1) + (h + (e + 1)) = ((e + 1) + (e + 1)) + (h + h) by lib_nat, add_mod' _ _ hM]
        exact mod_lt' _ _ (Nat.add_lt_add elt elt)
      rw [a1]; rw [a2] at pm
      have x : h + (e + 1) + (e + 1 + (u + 0)) + (h + (e + 1) + (e + 1 + (u + 0)))
          = (u + ((e + 1) + (e + 1))) + (u + ((e + 1) + (e + 1))) + (h + h) := by lib_nat
      rw [x, pm]
      have y : h + h + (h + h) + (h + h) = 3 * (h + h) := by lib_nat
      rw [y]; exact beq_self _

end Triple

#print axioms Triple.isOdd_even
#print axioms Triple.odd_form
#print axioms Triple.le_dest
#print axioms Triple.triple_bal

#print axioms: 4 theorems, no axioms.

81.98 Scaling balanced characters

A balanced character for \(m\) scaled by \(d\) is balanced for \(dm\), every \(d>0\). \(\mathrm {bal}\,m\,c\Rightarrow \mathrm {bal}\,(dm)\,(d\,c)\); \([2,18,22]\) for \(m=28\) from \([1,9,11]\) for \(m=14\).

hodge/ScaleBal.lean

/-
  hodge/ScaleBal.lean — T41 cycle 732 (goal G445): scaling a balanced character, c balanced for m ⇒ d·c balanced
  for d·m (every d > 0). So the sporadic length-3 characters at m = 14 (e.g. [1, 9, 11]) give [2, 18, 22] at 28,
  [4, 36, 44] at 56, … (as in the computed lists).

  Lean 4 core plus hodge/HalfUnitsIff, hodge/UnitMul (gcd_dvd, one_of_dvd_one, unit_mul), hodge/APPair1 (dvd_gcd),
  hodge/TwistBal (mul_mod_right, all_fr_intro, all_fr_elim), hodge/GcdHand (div_mod), hodge/ModHand.
    mod_scale    (d·y) mod (d·m) = d·(y mod m)
    gcd_down     gcd t (d·m) = 1 ⇒ gcd t m = 1
    tsum_red     T_t(c) = T_{t mod m}(c)  (mod m)
    tsum_scale   T^{dm}_t(d·c) = d·T^m_t(c)
    scale_bal    bal m c ⇒ bal (d·m) (d·c)
-/
import hodge.HalfUnitsIff

namespace ScaleBal
open FTAChain Indecomp HalfGeneral GcdHand ModHand TwistBal UnitMul

theorem mod_scale (d m y : Nat) (hd : 0 < d) (hm : 0 < m) : (d * y) % (d * m) = d * (y % m) := by
  have ⟨q, hq⟩ := div_mod m hm (y + 1) y (Nat.lt_succ_self y)
  have hr : y % m < m := Nat.mod_lt _ hm
  have hdm : 0 < d * m := Nat.mul_pos hd hm
  have e : d * y = d * (y % m) + q * (d * m) := by
    have : d * y = d * (y % m + m * q) := by rw [← hq]
    rw [this]; lib_nat
  rw [e, add_mul_mod' _ _ hdm]
  exact mod_lt' _ _ (Nat.mul_lt_mul_of_pos_left hr hd)

theorem gcd_down (t d m : Nat) (h : Nat.gcd t (d * m) = 1) : Nat.gcd t m = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := gcd_dvd t m
  generalize Nat.gcd t m = g at hi hj ⊢
  have ⟨c, hc⟩ := APPair1.dvd_gcd g t (d * m) ⟨i, hi⟩ ⟨d * j, by rw [hj]; lib_nat⟩
  rw [h] at hc
  exact one_of_dvd_one g c hc

theorem tsum_red (m t : Nat) (hm : 0 < m) : ∀ c, tsum m t c = tsum m (t % m) c
  | [] => rfl
  | x :: c => by
    show (t * x) % m + tsum m t c = ((t % m) * x) % m + tsum m (t % m) c
    rw [tsum_red m t hm c, Nat.mul_comm (t % m) x, mul_mod_right x t m hm, Nat.mul_comm x t]

def scl (d : Nat) (c : List Nat) : List Nat := c.map (fun x => d * x)

theorem tsum_scale (d m t : Nat) (hd : 0 < d) (hm : 0 < m) : ∀ c,
    tsum (d * m) t (scl d c) = d * tsum m t c
  | [] => rfl
  | x :: c => by
    show (t * (d * x)) % (d * m) + tsum (d * m) t (scl d c) = d * ((t * x) % m + tsum m t c)
    rw [tsum_scale d m t hd hm c, show t * (d * x) = d * (t * x) by lib_nat, mod_scale d m _ hd hm]
    lib_nat

theorem scale_bal (d m : Nat) (hd : 0 < d) (hm : 0 < m) (c : List Nat) (hb : bal m c = true) :
    bal (d * m) (scl d c) = true := by
  unfold bal FermatPrime.units at *
  apply all_fr_intro
  intro t _ hp
  have hg : Nat.gcd t (d * m) = 1 := Nat.eq_of_beq_eq_true hp
  have hgm := gcd_down t d m hg
  have hu : Nat.gcd ((1 * t) % m) m = 1 := unit_mul 1 t m hm (APPairIrrGen.gcd_one m) hgm
  rw [Nat.one_mul] at hu
  have h1 := Nat.eq_of_beq_eq_true (all_fr_elim _ _ m hb (t % m) (Nat.mod_lt _ hm) (by rw [hu]; rfl))
  rw [← tsum_red m t hm] at h1
  show Nat.beq (tsum (d * m) t (scl d c) + tsum (d * m) t (scl d c)) ((scl d c).length * (d * m)) = true
  rw [tsum_scale d m t hd hm, show (scl d c).length = c.length from APPairIrrGen.length_map' _ c]
  have e : d * tsum m t c + d * tsum m t c = d * (tsum m t c + tsum m t c) := by lib_nat
  have e2 : c.length * (d * m) = d * (c.length * m) := by lib_nat
  rw [e, e2, h1]; exact beq_self _

theorem ex28 : bal 28 [2, 18, 22] = true := scale_bal 2 14 (Nat.succ_pos 1) (Nat.succ_pos 13) [1, 9, 11] rfl

end ScaleBal

#print axioms ScaleBal.mod_scale
#print axioms ScaleBal.gcd_down
#print axioms ScaleBal.tsum_red
#print axioms ScaleBal.tsum_scale
#print axioms ScaleBal.scale_bal
#print axioms ScaleBal.ex28

#print axioms: 6 theorems, no axioms.

81.99 All balanced length-3 characters for \(m\le 24\)

Complete lists of balanced \([x,y,z]\) (\(x\le y\le z\)) for \(3\le m\le 24\) by rfl; none for odd \(m\). Counts for \(m=4,6,\dots ,24\): \(2,5,6,9,14,15,14,23,26,21,34\).

hodge/Len3Class.lean

/-
  hodge/Len3Class.lean — T41 cycle 735 (goal G448): complete list of balanced length-3 characters (x ≤ y ≤ z,
  entries in (0, m)) for every 3 ≤ m ≤ 24, by rfl. Odd m: none (OddLength). Even m: the Triple family
  [a, h+a, 2h−2a], the m/2-entries {h} ⊔ pair, and sporadic ones only at m = 12, 14, 18, 20, 24.

  Lean 4 core plus hodge/Indecomp (bal), rfl.
-/
import hodge.Indecomp

namespace Len3Class
open Indecomp

def zs (m x y : Nat) : List (List Nat) := ((List.range m).filter (fun z => Nat.ble y z && Nat.ble 1 z)).map (fun z => [x, y, z])
def ys (m x : Nat) : List (List Nat) := (((List.range m).filter (fun y => Nat.ble x y)).map (fun y => zs m x y)).flatten
def triples (m : Nat) : List (List Nat) := (((List.range m).filter (fun x => Nat.ble 1 x)).map (fun x => ys m x)).flatten
def cls (m : Nat) : List (List Nat) := (triples m).filter (bal m)

set_option maxRecDepth 100000 in
theorem cls3 : cls 3 = [] := rfl
set_option maxRecDepth 100000 in
theorem cls4 : cls 4 = [[1, 2, 3], [2, 2, 2]] := rfl
set_option maxRecDepth 100000 in
theorem cls5 : cls 5 = [] := rfl
set_option maxRecDepth 100000 in
theorem cls6 : cls 6 = [[1, 3, 5], [1, 4, 4], [2, 2, 5], [2, 3, 4], [3, 3, 3]] := rfl
set_option maxRecDepth 100000 in
theorem cls7 : cls 7 = [] := rfl
set_option maxRecDepth 100000 in
theorem cls8 : cls 8 = [[1, 4, 7], [1, 5, 6], [2, 3, 7], [2, 4, 6], [3, 4, 5], [4, 4, 4]] := rfl
set_option maxRecDepth 100000 in
theorem cls9 : cls 9 = [] := rfl
set_option maxRecDepth 100000 in
theorem cls10 : cls 10 = [[1, 5, 9], [1, 6, 8], [2, 4, 9], [2, 5, 8], [2, 6, 7], [3, 4, 8], [3, 5, 7], [4, 5, 6], [5, 5, 5]] := rfl
set_option maxRecDepth 100000 in
theorem cls11 : cls 11 = [] := rfl
set_option maxRecDepth 100000 in
theorem cls12 : cls 12 = [[1, 6, 11], [1, 7, 10], [1, 8, 9], [2, 5, 11], [2, 6, 10], [2, 8, 8], [3, 4, 11], [3, 6, 9], [3, 7, 8], [4, 4, 10], [4, 5, 9], [4, 6, 8], [5, 6, 7], [6, 6, 6]] := rfl
set_option maxRecDepth 100000 in
theorem cls13 : cls 13 = [] := rfl
set_option maxRecDepth 100000 in
theorem cls14 : cls 14 = [[1, 7, 13], [1, 8, 12], [1, 9, 11], [2, 6, 13], [2, 7, 12], [2, 9, 10], [3, 5, 13], [3, 7, 11], [3, 8, 10], [4, 5, 12], [4, 6, 11], [4, 7, 10], [5, 7, 9], [6, 7, 8], [7, 7, 7]] := rfl
set_option maxRecDepth 100000 in
theorem cls15 : cls 15 = [] := rfl
set_option maxRecDepth 100000 in
theorem cls16 : cls 16 = [[1, 8, 15], [1, 9, 14], [2, 7, 15], [2, 8, 14], [2, 10, 12], [3, 8, 13], [3, 10, 11], [4, 6, 14], [4, 8, 12], [5, 6, 13], [5, 8, 11], [6, 8, 10], [7, 8, 9], [8, 8, 8]] := rfl
set_option maxRecDepth 100000 in
theorem cls17 : cls 17 = [] := rfl
set_option maxRecDepth 100000 in
theorem cls18 : cls 18 = [[1, 9, 17], [1, 10, 16], [1, 12, 14], [2, 8, 17], [2, 9, 16], [2, 11, 14], [2, 12, 13], [3, 9, 15], [3, 12, 12], [4, 6, 17], [4, 7, 16], [4, 9, 14], [4, 10, 13], [5, 6, 16], [5, 8, 14], [5, 9, 13], [6, 6, 15], [6, 9, 12], [6, 10, 11], [7, 8, 12], [7, 9, 11], [8, 9, 10], [9, 9, 9]] := rfl
set_option maxRecDepth 100000 in
theorem cls19 : cls 19 = [] := rfl
set_option maxRecDepth 100000 in
theorem cls20 : cls 20 = [[1, 10, 19], [1, 11, 18], [1, 12, 17], [1, 13, 16], [2, 9, 19], [2, 10, 18], [2, 12, 16], [3, 8, 19], [3, 10, 17], [3, 11, 16], [3, 13, 14], [4, 7, 19], [4, 8, 18], [4, 9, 17], [4, 10, 16], [4, 12, 14], [5, 10, 15], [6, 7, 17], [6, 8, 16], [6, 10, 14], [7, 10, 13], [7, 11, 12], [8, 9, 13], [8, 10, 12], [9, 10, 11], [10, 10, 10]] := rfl
set_option maxRecDepth 100000 in
theorem cls21 : cls 21 = [] := rfl
set_option maxRecDepth 100000 in
theorem cls22 : cls 22 = [[1, 11, 21], [1, 12, 20], [2, 10, 21], [2, 11, 20], [2, 13, 18], [3, 11, 19], [3, 14, 16], [4, 9, 20], [4, 11, 18], [4, 14, 15], [5, 11, 17], [5, 12, 16], [6, 8, 19], [6, 10, 17], [6, 11, 16], [7, 8, 18], [7, 11, 15], [8, 11, 14], [9, 11, 13], [10, 11, 12], [11, 11, 11]] := rfl
set_option maxRecDepth 100000 in
theorem cls23 : cls 23 = [] := rfl
set_option maxRecDepth 100000 in
theorem cls24 : cls 24 = [[1, 12, 23], [1, 13, 22], [1, 16, 19], [1, 17, 18], [2, 11, 23], [2, 12, 22], [2, 14, 20], [2, 16, 18], [3, 12, 21], [3, 15, 18], [4, 10, 22], [4, 12, 20], [4, 16, 16], [5, 8, 23], [5, 12, 19], [5, 13, 18], [5, 14, 17], [6, 7, 23], [6, 8, 22], [6, 9, 21], [6, 11, 19], [6, 12, 18], [6, 14, 16], [7, 10, 19], [7, 12, 17], [7, 13, 16], [8, 8, 20], [8, 10, 18], [8, 11, 17], [8  -- (+72 chars; full line in the Zenodo source)

end Len3Class

#print axioms Len3Class.cls3
#print axioms Len3Class.cls4
#print axioms Len3Class.cls5
#print axioms Len3Class.cls6
#print axioms Len3Class.cls7
#print axioms Len3Class.cls8
#print axioms Len3Class.cls9
#print axioms Len3Class.cls10
#print axioms Len3Class.cls11
#print axioms Len3Class.cls12
#print axioms Len3Class.cls13
#print axioms Len3Class.cls14
#print axioms Len3Class.cls15
#print axioms Len3Class.cls16
#print axioms Len3Class.cls17
#print axioms Len3Class.cls18
#print axioms Len3Class.cls19
#print axioms Len3Class.cls20
#print axioms Len3Class.cls21
#print axioms Len3Class.cls22
#print axioms Len3Class.cls23
#print axioms Len3Class.cls24

#print axioms: 22 theorems, no axioms.

81.100 All balanced length-4 characters for \(m\le 16\)

Complete lists of balanced \([x,y,z,w]\) (\(x\le y\le z\le w\)) for \(3\le m\le 16\) by rfl. Counts for \(m=3,\dots ,16\): \(1,3,3,8,6,12,12,23,15,37,21,42,40,46\).

hodge/Len4Class.lean

/-
  hodge/Len4Class.lean — T41 cycle 738 (goal G451): complete list of balanced length-4 characters
  (x ≤ y ≤ z ≤ w, entries in (0, m)) for every 3 ≤ m ≤ 16, by rfl.

  Lean 4 core plus hodge/Len3Class (list builders), hodge/Indecomp (bal), rfl.
-/
import hodge.Len3Class

namespace Len4Class
open Indecomp Len3Class

def quads (m : Nat) : List (List Nat) :=
  (((List.range m).filter (fun x => Nat.ble 1 x)).map (fun x => ((triples m).filter (fun l => match l with
    | y :: _ => Nat.ble x y
    | [] => false)).map (fun l => x :: l))).flatten
def cls4 (m : Nat) : List (List Nat) := (quads m).filter (bal m)

set_option maxRecDepth 100000 in
theorem c4_3 : cls4 3 = [[1, 1, 2, 2]] := rfl
set_option maxRecDepth 100000 in
theorem c4_4 : cls4 4 = [[1, 1, 3, 3], [1, 2, 2, 3], [2, 2, 2, 2]] := rfl
set_option maxRecDepth 100000 in
theorem c4_5 : cls4 5 = [[1, 1, 4, 4], [1, 2, 3, 4], [2, 2, 3, 3]] := rfl
set_option maxRecDepth 100000 in
theorem c4_6 : cls4 6 = [[1, 1, 5, 5], [1, 2, 4, 5], [1, 3, 3, 5], [1, 3, 4, 4], [2, 2, 3, 5], [2, 2, 4, 4], [2, 3, 3, 4], [3, 3, 3, 3]] := rfl
set_option maxRecDepth 100000 in
theorem c4_7 : cls4 7 = [[1, 1, 6, 6], [1, 2, 5, 6], [1, 3, 4, 6], [2, 2, 5, 5], [2, 3, 4, 5], [3, 3, 4, 4]] := rfl
set_option maxRecDepth 100000 in
theorem c4_8 : cls4 8 = [[1, 1, 7, 7], [1, 2, 6, 7], [1, 3, 5, 7], [1, 4, 4, 7], [1, 4, 5, 6], [2, 2, 6, 6], [2, 3, 4, 7], [2, 3, 5, 6], [2, 4, 4, 6], [3, 3, 5, 5], [3, 4, 4, 5], [4, 4, 4, 4]] := rfl
set_option maxRecDepth 100000 in
theorem c4_9 : cls4 9 = [[1, 1, 8, 8], [1, 2, 7, 8], [1, 3, 6, 8], [1, 4, 5, 8], [1, 4, 6, 7], [2, 2, 7, 7], [2, 3, 5, 8], [2, 3, 6, 7], [2, 4, 5, 7], [3, 3, 6, 6], [3, 4, 5, 6], [4, 4, 5, 5]] := rfl
set_option maxRecDepth 100000 in
theorem c4_10 : cls4 10 = [[1, 1, 9, 9], [1, 2, 8, 9], [1, 3, 7, 9], [1, 3, 8, 8], [1, 4, 6, 9], [1, 5, 5, 9], [1, 5, 6, 8], [1, 6, 6, 7], [2, 2, 7, 9], [2, 2, 8, 8], [2, 3, 7, 8], [2, 4, 5, 9], [2, 4, 6, 8], [2, 5, 5, 8], [2, 5, 6, 7], [3, 3, 7, 7], [3, 4, 4, 9], [3, 4, 5, 8], [3, 4, 6, 7], [3, 5, 5, 7], [4, 4, 6, 6], [4, 5, 5, 6], [5, 5, 5, 5]] := rfl
set_option maxRecDepth 100000 in
theorem c4_11 : cls4 11 = [[1, 1, 10, 10], [1, 2, 9, 10], [1, 3, 8, 10], [1, 4, 7, 10], [1, 5, 6, 10], [2, 2, 9, 9], [2, 3, 8, 9], [2, 4, 7, 9], [2, 5, 6, 9], [3, 3, 8, 8], [3, 4, 7, 8], [3, 5, 6, 8], [4, 4, 7, 7], [4, 5, 6, 7], [5, 5, 6, 6]] := rfl
set_option maxRecDepth 100000 in
theorem c4_12 : cls4 12 = [[1, 1, 11, 11], [1, 2, 10, 11], [1, 3, 9, 11], [1, 4, 8, 11], [1, 4, 9, 10], [1, 5, 7, 11], [1, 5, 9, 9], [1, 6, 6, 11], [1, 6, 7, 10], [1, 6, 8, 9], [1, 7, 8, 8], [2, 2, 10, 10], [2, 3, 8, 11], [2, 3, 9, 10], [2, 4, 8, 10], [2, 5, 6, 11], [2, 5, 7, 10], [2, 5, 8, 9], [2, 6, 6, 10], [2, 6, 8, 8], [3, 3, 7, 11], [3, 3, 9, 9], [3, 4, 6, 11], [3, 4, 7, 10], [3, 4, 8, 9], [3  -- (+174 chars; full line in the Zenodo source)
set_option maxRecDepth 100000 in
theorem c4_13 : cls4 13 = [[1, 1, 12, 12], [1, 2, 11, 12], [1, 3, 10, 12], [1, 4, 9, 12], [1, 5, 8, 12], [1, 6, 7, 12], [2, 2, 11, 11], [2, 3, 10, 11], [2, 4, 9, 11], [2, 5, 8, 11], [2, 6, 7, 11], [3, 3, 10, 10], [3, 4, 9, 10], [3, 5, 8, 10], [3, 6, 7, 10], [4, 4, 9, 9], [4, 5, 8, 9], [4, 6, 7, 9], [5, 5, 8, 8], [5, 6, 7, 8], [6, 6, 7, 7]] := rfl
set_option maxRecDepth 100000 in
theorem c4_14 : cls4 14 = [[1, 1, 13, 13], [1, 2, 12, 13], [1, 3, 11, 13], [1, 4, 10, 13], [1, 4, 11, 12], [1, 5, 9, 13], [1, 6, 8, 13], [1, 7, 7, 13], [1, 7, 8, 12], [1, 7, 9, 11], [1, 8, 9, 10], [2, 2, 12, 12], [2, 3, 10, 13], [2, 3, 11, 12], [2, 4, 10, 12], [2, 5, 9, 12], [2, 6, 7, 13], [2, 6, 8, 12], [2, 6, 9, 11], [2, 7, 7, 12], [2, 7, 9, 10], [3, 3, 11, 11], [3, 4, 10, 11], [3, 5, 7, 13], [3  -- (+269 chars; full line in the Zenodo source)
set_option maxRecDepth 100000 in
theorem c4_15 : cls4 15 = [[1, 1, 14, 14], [1, 2, 13, 14], [1, 3, 12, 14], [1, 4, 11, 14], [1, 5, 10, 14], [1, 6, 9, 14], [1, 6, 10, 13], [1, 6, 11, 12], [1, 7, 8, 14], [1, 7, 10, 12], [2, 2, 13, 13], [2, 3, 12, 13], [2, 4, 11, 13], [2, 5, 9, 14], [2, 5, 10, 13], [2, 5, 11, 12], [2, 6, 9, 13], [2, 7, 8, 13], [2, 7, 9, 12], [3, 3, 12, 12], [3, 4, 9, 14], [3, 4, 10, 13], [3, 4, 11, 12], [3, 5, 8, 14  -- (+250 chars; full line in the Zenodo source)
set_option maxRecDepth 100000 in
theorem c4_16 : cls4 16 = [[1, 1, 15, 15], [1, 2, 14, 15], [1, 3, 13, 15], [1, 4, 12, 15], [1, 5, 11, 15], [1, 6, 10, 15], [1, 7, 9, 15], [1, 8, 8, 15], [1, 8, 9, 14], [1, 9, 10, 12], [2, 2, 14, 14], [2, 3, 13, 14], [2, 4, 12, 14], [2, 5, 11, 14], [2, 5, 12, 13], [2, 6, 10, 14], [2, 7, 8, 15], [2, 7, 9, 14], [2, 8, 8, 14], [2, 8, 10, 12], [3, 3, 13, 13], [3, 4, 11, 14], [3, 4, 12, 13], [3, 5, 11,   -- (+346 chars; full line in the Zenodo source)

end Len4Class

#print axioms Len4Class.c4_3
#print axioms Len4Class.c4_4
#print axioms Len4Class.c4_5
#print axioms Len4Class.c4_6
#print axioms Len4Class.c4_7
#print axioms Len4Class.c4_8
#print axioms Len4Class.c4_9
#print axioms Len4Class.c4_10
#print axioms Len4Class.c4_11
#print axioms Len4Class.c4_12
#print axioms Len4Class.c4_13
#print axioms Len4Class.c4_14
#print axioms Len4Class.c4_15
#print axioms Len4Class.c4_16

#print axioms: 14 theorems, no axioms.

81.101 Indecomposable characters of length 3 and 4

The balanced characters with no splitting into two balanced parts: length 3 for \(m\le 24\), length 4 for \(m\le 16\), by rfl. Length 4: none for \(m\le 8\); \(2,4,8,6,12,4\) for \(m=9,10,12,14,15,16\).

hodge/IndecSmall.lean

/-
  hodge/IndecSmall.lean — T41 cycle 741 (goal G454): the indecomposable balanced characters of length 3 (m ≤ 24) and
  length 4 (m ≤ 16): those with no splitting into two nonempty balanced parts, by rfl.

  Lean 4 core plus hodge/Len4Class (cls, cls4), hodge/Indecomp (indec), rfl.
  These are the characters the inductive (pair / m/2 / block) method cannot reach at these m.
-/
import hodge.Len4Class

namespace IndecSmall
open Indecomp Len3Class Len4Class

set_option maxRecDepth 100000 in
theorem i3_3 : (cls 3).filter (indec 3) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_4 : (cls 4).filter (indec 4) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_5 : (cls 5).filter (indec 5) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_6 : (cls 6).filter (indec 6) = [[1, 4, 4], [2, 2, 5]] := rfl
set_option maxRecDepth 100000 in
theorem i3_7 : (cls 7).filter (indec 7) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_8 : (cls 8).filter (indec 8) = [[1, 5, 6], [2, 3, 7]] := rfl
set_option maxRecDepth 100000 in
theorem i3_9 : (cls 9).filter (indec 9) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_10 : (cls 10).filter (indec 10) = [[1, 6, 8], [2, 4, 9], [2, 6, 7], [3, 4, 8]] := rfl
set_option maxRecDepth 100000 in
theorem i3_11 : (cls 11).filter (indec 11) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_12 : (cls 12).filter (indec 12) = [[1, 7, 10], [1, 8, 9], [2, 5, 11], [2, 8, 8], [3, 4, 11], [3, 7, 8], [4, 4, 10], [4, 5, 9]] := rfl
set_option maxRecDepth 100000 in
theorem i3_13 : (cls 13).filter (indec 13) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_14 : (cls 14).filter (indec 14) = [[1, 8, 12], [1, 9, 11], [2, 6, 13], [2, 9, 10], [3, 5, 13], [3, 8, 10], [4, 5, 12], [4, 6, 11]] := rfl
set_option maxRecDepth 100000 in
theorem i3_15 : (cls 15).filter (indec 15) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_16 : (cls 16).filter (indec 16) = [[1, 9, 14], [2, 7, 15], [2, 10, 12], [3, 10, 11], [4, 6, 14], [5, 6, 13]] := rfl
set_option maxRecDepth 100000 in
theorem i3_17 : (cls 17).filter (indec 17) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_18 : (cls 18).filter (indec 18) = [[1, 10, 16], [1, 12, 14], [2, 8, 17], [2, 11, 14], [2, 12, 13], [3, 12, 12], [4, 6, 17], [4, 7, 16], [4, 10, 13], [5, 6, 16], [5, 8, 14], [6, 6, 15], [6, 10, 11], [7, 8, 12]] := rfl
set_option maxRecDepth 100000 in
theorem i3_19 : (cls 19).filter (indec 19) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_20 : (cls 20).filter (indec 20) = [[1, 11, 18], [1, 12, 17], [1, 13, 16], [2, 9, 19], [2, 12, 16], [3, 8, 19], [3, 11, 16], [3, 13, 14], [4, 7, 19], [4, 8, 18], [4, 9, 17], [4, 12, 14], [6, 7, 17], [6, 8, 16], [7, 11, 12], [8, 9, 13]] := rfl
set_option maxRecDepth 100000 in
theorem i3_21 : (cls 21).filter (indec 21) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_22 : (cls 22).filter (indec 22) = [[1, 12, 20], [2, 10, 21], [2, 13, 18], [3, 14, 16], [4, 9, 20], [4, 14, 15], [5, 12, 16], [6, 8, 19], [6, 10, 17], [7, 8, 18]] := rfl
set_option maxRecDepth 100000 in
theorem i3_23 : (cls 23).filter (indec 23) = [] := rfl
set_option maxRecDepth 100000 in
theorem i3_24 : (cls 24).filter (indec 24) = [[1, 13, 22], [1, 16, 19], [1, 17, 18], [2, 11, 23], [2, 14, 20], [2, 16, 18], [3, 15, 18], [4, 10, 22], [4, 16, 16], [5, 8, 23], [5, 13, 18], [5, 14, 17], [6, 7, 23], [6, 8, 22], [6, 9, 21], [6, 11, 19], [6, 14, 16], [7, 10, 19], [7, 13, 16], [8, 8, 20], [8, 10, 18], [8, 11, 17]] := rfl
set_option maxRecDepth 100000 in
theorem i4_3 : (cls4 3).filter (indec 3) = [] := rfl
set_option maxRecDepth 100000 in
theorem i4_4 : (cls4 4).filter (indec 4) = [] := rfl
set_option maxRecDepth 100000 in
theorem i4_5 : (cls4 5).filter (indec 5) = [] := rfl
set_option maxRecDepth 100000 in
theorem i4_6 : (cls4 6).filter (indec 6) = [] := rfl
set_option maxRecDepth 100000 in
theorem i4_7 : (cls4 7).filter (indec 7) = [] := rfl
set_option maxRecDepth 100000 in
theorem i4_8 : (cls4 8).filter (indec 8) = [] := rfl
set_option maxRecDepth 100000 in
theorem i4_9 : (cls4 9).filter (indec 9) = [[1, 4, 6, 7], [2, 3, 5, 8]] := rfl
set_option maxRecDepth 100000 in
theorem i4_10 : (cls4 10).filter (indec 10) = [[1, 3, 8, 8], [1, 6, 6, 7], [2, 2, 7, 9], [3, 4, 4, 9]] := rfl
set_option maxRecDepth 100000 in
theorem i4_11 : (cls4 11).filter (indec 11) = [] := rfl
set_option maxRecDepth 100000 in
theorem i4_12 : (cls4 12).filter (indec 12) = [[1, 4, 9, 10], [1, 5, 9, 9], [1, 7, 8, 8], [2, 3, 8, 11], [2, 5, 8, 9], [3, 3, 7, 11], [3, 4, 7, 10], [4, 4, 5, 11]] := rfl
set_option maxRecDepth 100000 in
theorem i4_13 : (cls4 13).filter (indec 13) = [] := rfl
set_option maxRecDepth 100000 in
theorem i4_14 : (cls4 14).filter (indec 14) = [[1, 4, 11, 12], [1, 8, 9, 10], [2, 3, 10, 13], [2, 6, 9, 11], [3, 5, 8, 12], [4, 5, 6, 13]] := rfl
set_option maxRecDepth 100000 in
theorem i4_15 : (cls4 15).filter (indec 15) = [[1, 6, 10, 13], [1, 6, 11, 12], [1, 7, 10, 12], [2, 5, 9, 14], [2, 5, 11, 12], [2, 7, 9, 12], [3, 4, 9, 14], [3, 4, 10, 13], [3, 5, 8, 14], [3, 6, 8, 13], [4, 7, 9, 10], [5, 6, 8, 11]] := rfl
set_option maxRecDepth 100000 in
theorem i4_16 : (cls4 16).filter (indec 16) = [[1, 9, 10, 12], [2, 5, 12, 13], [3, 4, 11, 14], [4, 6, 7, 15]] := rfl

end IndecSmall

#print axioms IndecSmall.i3_3
#print axioms IndecSmall.i3_4
#print axioms IndecSmall.i3_5
#print axioms IndecSmall.i3_6
#print axioms IndecSmall.i3_7
#print axioms IndecSmall.i3_8
#print axioms IndecSmall.i3_9
#print axioms IndecSmall.i3_10
#print axioms IndecSmall.i3_11
#print axioms IndecSmall.i3_12
#print axioms IndecSmall.i3_13
#print axioms IndecSmall.i3_14
#print axioms IndecSmall.i3_15
#print axioms IndecSmall.i3_16
#print axioms IndecSmall.i3_17
#print axioms IndecSmall.i3_18
#print axioms IndecSmall.i3_19
#print axioms IndecSmall.i3_20
#print axioms IndecSmall.i3_21
#print axioms IndecSmall.i3_22
#print axioms IndecSmall.i3_23
#print axioms IndecSmall.i3_24
#print axioms IndecSmall.i4_3
#print axioms IndecSmall.i4_4
#print axioms IndecSmall.i4_5
#print axioms IndecSmall.i4_6
#print axioms IndecSmall.i4_7
#print axioms IndecSmall.i4_8
#print axioms IndecSmall.i4_9
#print axioms IndecSmall.i4_10
#print axioms IndecSmall.i4_11
#print axioms IndecSmall.i4_12
#print axioms IndecSmall.i4_13
#print axioms IndecSmall.i4_14
#print axioms IndecSmall.i4_15
#print axioms IndecSmall.i4_16

#print axioms: 36 theorems, no axioms.

81.102 Three-element characters without \(m/2\) are indecomposable

A balanced \([x,y,z]\) with no entry \(m/2\) has no splitting into two balanced parts, every \(m\ge 2\). \(2x,2y,2z\ne m\Rightarrow \mathrm {indec}\,m\,[x,y,z]\).

hodge/IndecTriple.lean

/-
  hodge/IndecTriple.lean — T41 cycle 744 (goal G457): a three-element character with no entry m/2 is
  indecomposable, for every m ≥ 2; so every Triple-family character [a, h+a, 2h−2a] with no entry equal to h is
  indecomposable.

  Lean 4 core plus hodge/PairReduce (single_iff), hodge/Triple (triple_bal), hodge/Indecomp (indec, splits).
    indec3_eq     indec m [x, y, z] as an explicit Boolean formula (rfl: splits of a 3-list)
    and_false'    b && false = false
    single_false  0 < x < m, x + x ≠ m ⇒ bal m [x] = false
    indec_triple  no entry equals m/2 ⇒ indec m [x, y, z] = true
-/
import hodge.PairReduce
import hodge.Triple

namespace IndecTriple
open Indecomp PairReduce

theorem indec3_eq (m x y z : Nat) : indec m [x, y, z] =
    (true && (!(bal m [y, z] && bal m [x]) && (!(bal m [x, z] && bal m [y]) && (!(bal m [z] && bal m [x, y])
      && (!(bal m [x, y] && bal m [z]) && (!(bal m [y] && bal m [x, z]) && (!(bal m [x] && bal m [y, z])
      && (true && true)))))))) := rfl

theorem and_false' (b : Bool) : (b && false) = false := by cases b <;> rfl

theorem single_false (n x : Nat) (hx0 : 0 < x) (hx : x < n + 2) (hne : x + x ≠ n + 2) :
    bal (n + 2) [x] = false := by
  cases e : bal (n + 2) [x] with
  | false => rfl
  | true => exact absurd ((single_iff n x hx0 hx).1 e) hne

theorem indec_triple (n x y z : Nat) (hx0 : 0 < x) (hx : x < n + 2) (hy0 : 0 < y) (hy : y < n + 2)
    (hz0 : 0 < z) (hz : z < n + 2) (nx : x + x ≠ n + 2) (ny : y + y ≠ n + 2) (nz : z + z ≠ n + 2) :
    indec (n + 2) [x, y, z] = true := by
  rw [indec3_eq, single_false n x hx0 hx nx, single_false n y hy0 hy ny, single_false n z hz0 hz nz,
    and_false', and_false', and_false']
  rfl

end IndecTriple

#print axioms IndecTriple.indec3_eq
#print axioms IndecTriple.and_false'
#print axioms IndecTriple.single_false
#print axioms IndecTriple.indec_triple

#print axioms: 4 theorems, no axioms.

81.103 Fermat fourfolds of degree \(m\le 12\): every character decomposes

Every balanced length-6 character for \(3\le m\le 12\) splits into two nonempty balanced parts, by rfl. \(\{c:\ \mathrm {bal}\,m\,c\wedge \mathrm {indec}\,m\,c\}=\varnothing \) for \(3\le m\le 12\).

hodge/Len6Decomp.lean

/-
  hodge/Len6Decomp.lean — T41 cycle 747 (goal G460): for 3 ≤ m ≤ 12 every balanced length-6 character (sorted,
  entries in (0, m)) of the Fermat fourfold of degree m splits into two nonempty balanced parts, by rfl.
  So at these degrees every Hodge character is reached by the inductive structure from curves and surfaces
  (where the Hodge conjecture holds: Lefschetz (1,1)). First indecomposable ones: m = 15 (6), m = 18 (18).

  Lean 4 core plus hodge/Len4Class (quads), hodge/Indecomp (bal, indec), rfl.
-/
import hodge.Len4Class

namespace Len6Decomp
open Indecomp Len3Class Len4Class

def ext (m : Nat) (L : List (List Nat)) : List (List Nat) :=
  (((List.range m).filter (fun x => Nat.ble 1 x)).map (fun x => (L.filter (fun l => match l with
    | y :: _ => Nat.ble x y
    | [] => false)).map (fun l => x :: l))).flatten
def quints (m : Nat) : List (List Nat) := ext m (quads m)
def sexts (m : Nat) : List (List Nat) := ext m (quints m)
def bad (m : Nat) : List (List Nat) := (sexts m).filter (fun c => bal m c && indec m c)

set_option maxRecDepth 200000 in
theorem d3 : bad 3 = [] := rfl
set_option maxRecDepth 200000 in
theorem d4 : bad 4 = [] := rfl
set_option maxRecDepth 200000 in
theorem d5 : bad 5 = [] := rfl
set_option maxRecDepth 200000 in
theorem d6 : bad 6 = [] := rfl
set_option maxRecDepth 200000 in
theorem d7 : bad 7 = [] := rfl
set_option maxRecDepth 200000 in
theorem d8 : bad 8 = [] := rfl
set_option maxRecDepth 200000 in
theorem d9 : bad 9 = [] := rfl
set_option maxRecDepth 200000 in
theorem d10 : bad 10 = [] := rfl
set_option maxRecDepth 200000 in
theorem d11 : bad 11 = [] := rfl
set_option maxRecDepth 200000 in
theorem d12 : bad 12 = [] := rfl

end Len6Decomp

#print axioms Len6Decomp.d3
#print axioms Len6Decomp.d4
#print axioms Len6Decomp.d5
#print axioms Len6Decomp.d6
#print axioms Len6Decomp.d7
#print axioms Len6Decomp.d8
#print axioms Len6Decomp.d9
#print axioms Len6Decomp.d10
#print axioms Len6Decomp.d11
#print axioms Len6Decomp.d12

#print axioms: 10 theorems, no axioms.

81.104 A four-term family for every \(m=3k\)

For \(m=3k\) and \(0<a<k\) the character \([a,\,a+k,\,a+2k,\,3k-3a]\) is balanced. For a unit \(t\equiv e\pmod 3\) the first three residues are \(u+k\{j,\,j+e,\,j+2e\}\bmod 3\) and the fourth is \(m-3u\).

hodge/ThirdFam.lean

/-
  hodge/ThirdFam.lean — T41 cycle 751 (goal G464): for m = 3k and 0 < a < k the four-term character
  [a, a + k, a + 2k, 3k − 3a] is balanced (computation: every m = 3k < 60, every admissible a; the μ₃-orbit
  analogue of the Triple family and of Shioda's standard (a, a + m/2, −2a, m/2)).

  Lean 4 core plus hodge/Triple (le_dest), hodge/PairBal (not_dv), hodge/InductiveStep (pair_m), hodge/UnitMul
  (gcd_dvd), hodge/APPair1 (dvd_gcd), hodge/GcdHand (div_mod, sub_add'), hodge/ModHand, hodge/TwistBal, lib/Semi.
    three_sum   j < 3, e ∈ {1, 2}:  j%3 + (j+e)%3 + (j+2e)%3 = 3
    unit3       gcd t (3k) = 1 ⇒ t = 3s + e, e ∈ {1, 2}
    red3        ⟨u + k·i⟩_{3k} = u + k·(i % 3)   (u < k)
    third_bal   the statement
-/
import hodge.Triple

namespace ThirdFam
open FTAChain Indecomp HalfGeneral GcdHand ModHand TwistBal PairBal UnitMul Triple

theorem lt3' (j : Nat) : j < 3 ∨ 3 ≤ j := Nat.lt_or_ge j 3

theorem lt3 : ∀ j : Nat, j < 3 → j = 0 ∨ j = 1 ∨ j = 2
  | 0, _ => Or.inl rfl
  | 1, _ => Or.inr (Or.inl rfl)
  | 2, _ => Or.inr (Or.inr rfl)
  | j + 3, h => absurd (Nat.lt_of_succ_lt_succ (Nat.lt_of_succ_lt_succ (Nat.lt_of_succ_lt_succ h))) (Nat.not_lt_zero j)

theorem three_sum (j e : Nat) (hj : j < 3) (he : e = 1 ∨ e = 2) : j % 3 + (j + e) % 3 + (j + e + e) % 3 = 3 := by
  cases he with
  | inl h1 =>
    rw [h1]
    cases lt3 j hj with
    | inl a => rw [a]
    | inr b => cases b with
      | inl a => rw [a]
      | inr a => rw [a]
  | inr h2 =>
    rw [h2]
    cases lt3 j hj with
    | inl a => rw [a]
    | inr b => cases b with
      | inl a => rw [a]
      | inr a => rw [a]

theorem unit3 (t k : Nat) (hg : Nat.gcd t (k + k + k) = 1) : ∃ s e, t = 3 * s + e ∧ (e = 1 ∨ e = 2) := by
  have ⟨q, hq⟩ := div_mod 3 (Nat.succ_pos 2) (t + 1) t (Nat.lt_succ_self t)
  have hl : t % 3 < 3 := Nat.mod_lt _ (Nat.succ_pos 2)
  generalize t % 3 = e at hq hl
  refine ⟨q, e, by rw [hq]; lib_nat, ?_⟩
  cases lt3 e hl with
  | inl a =>
    exfalso
    rw [a] at hq
    have ⟨c, hc⟩ := APPair1.dvd_gcd 3 t (k + k + k) ⟨q, by rw [hq]; lib_nat⟩ ⟨k, by lib_nat⟩
    rw [hg] at hc
    exact absurd (one_of_dvd_one 3 c hc) (fun h => Nat.noConfusion (Nat.succ.inj h))
  | inr b => exact b

theorem red3 (k u : Nat) (hu : u < k) (i : Nat) : (u + k * i) % (k + k + k) = u + k * (i % 3) := by
  have hk : 0 < k + k + k := Nat.lt_of_lt_of_le (Nat.lt_of_le_of_lt (Nat.zero_le u) hu) (Nat.le_add_left k (k + k))
  have ⟨q, hq⟩ := div_mod 3 (Nat.succ_pos 2) (i + 1) i (Nat.lt_succ_self i)
  have hl : i % 3 < 3 := Nat.mod_lt _ (Nat.succ_pos 2)
  generalize i % 3 = j at hq hl ⊢
  have e : u + k * i = (u + k * j) + q * (k + k + k) := by rw [hq]; lib_nat
  rw [e, add_mul_mod' _ _ hk]
  apply mod_lt'
  have : u + k * j < k + k * j := Nat.add_lt_add_right hu _
  apply Nat.lt_of_lt_of_le this
  cases lt3 j hl with
  | inl a => rw [a, Nat.mul_zero, Nat.add_zero]; exact Nat.le_trans (Nat.le_add_right k k) (Nat.le_add_right _ k)
  | inr b => cases b with
    | inl a => rw [a, Nat.mul_one]; exact Nat.le_add_right _ k
    | inr a => rw [a, show k * 2 = k + k by lib_nat, ← Nat.add_assoc]; exact Nat.le_refl _

theorem third_bal (k a : Nat) (ha0 : 0 < a) (hak : a < k) :
    bal (k + k + k) [a, a + k, a + k + k, (k + k + k) - (a + a + a)] = true := by
  have hk0 : 0 < k := Nat.lt_of_le_of_lt (Nat.zero_le a) hak
  have hM : 0 < k + k + k := Nat.lt_of_lt_of_le hk0 (Nat.le_add_left k (k + k))
  have h3a : a + a + a ≤ k + k + k := Nat.add_le_add (Nat.add_le_add (Nat.le_of_lt hak) (Nat.le_of_lt hak)) (Nat.le_of_lt hak)
  generalize hz : (k + k + k) - (a + a + a) = z
  have hza : z + (a + a + a) = k + k + k := by rw [← hz]; exact sub_add' _ _ h3a
  have hz0 : 0 < z := by
    cases z with
    | zero =>
      rw [Nat.zero_add] at hza
      exact absurd hza (Nat.ne_of_lt (Nat.add_lt_add (Nat.add_lt_add hak hak) hak))
    | succ z => exact Nat.succ_pos z
  have hzm : z < k + k + k := by
    rw [← hza]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le ha0 (Nat.le_add_left a (a + a)))
  unfold bal FermatPrime.units
  apply all_fr_intro
  intro t _ hp
  have hg : Nat.gcd t (k + k + k) = 1 := Nat.eq_of_beq_eq_true hp
  have ⟨s, e, hs, he⟩ := unit3 t k hg
  have ⟨q, hq⟩ := div_mod (k + k + k) hM (t * a + 1) (t * a) (Nat.lt_succ_self _)
  have hrm : (t * a) % (k + k + k) < k + k + k := Nat.mod_lt _ hM
  generalize (t * a) % (k + k + k) = r at hq hrm
  have ⟨j, hj⟩ := div_mod k hk0 (r + 1) r (Nat.lt_succ_self _)
  have hu : r % k < k := Nat.mod_lt _ hk0
  generalize r % k = u at hj hu
  have hj3 : j < 3 := by
    cases lt3' j with
    | inl l => exact l
    | inr g =>
      exfalso
      have : k * 3 ≤ k * j := Nat.mul_le_mul_left k g
      have : k + k + k ≤ r := by
        rw [hj, show k + k + k = k * 3 by lib_nat]
        exact Nat.le_trans this (Nat.le_add_left _ _)
      exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le hrm this)
  -- the three shifted residues
  have m0 : (t * a) % (k + k + k) = u + k * (j % 3) := by
    rw [show t * a = (u + k * j) + q * (k + k + k) by rw [hq, hj]; lib_nat, add_mul_mod' _ _ hM, red3 k u hu j]
  have m1 : (t * (a + k)) % (k + k + k) = u + k * ((j + e) % 3) := by
    rw [show t * (a + k) = (u + k * (j + e)) + (q + s) * (k + k + k) by
      rw [show t * (a + k) = t * a + t * k by lib_nat, hq, hj, hs]; lib_nat, add_mul_mod' _ _ hM, red3 k u hu]
  have m2 : (t * (a + k + k)) % (k + k + k) = u + k * ((j + e + e) % 3) := by
    rw [show t * (a + k + k) = (u + k * (j + e + e)) + (q + s + s) * (k + k + k) by
      rw [show t * (a + k + k) = t * a + t * k + t * k by lib_nat, hq, hj, hs]; lib_nat, add_mul_mod' _ _ hM, red3 k u hu]
  have m3 : (t * (a + a + a)) % (k + k + k) = u + u + u := by
    rw [show t * (a + a + a) = (u + u + u) + (q + q + q + j) * (k + k + k) by
      rw [show t * (a + a + a) = t * a + t * a + t * a by lib_nat, hq, hj]; lib_nat, add_mul_mod' _ _ hM]
    exact mod_lt' _ _ (Nat.add_lt_add (Nat.add_lt_add hu hu) hu)
  have hm' : ∃ m', k + k + k = m' + 1 := by
    cases k with
    | zero => exact absurd hk0 (Nat.lt_irrefl 0)
    | succ k0 => exact ⟨k0 + 1 + (k0 + 1) + k0, rfl⟩
  have ⟨m', hm'e⟩ := hm'
  have pm : (t * z) % (k + k + k) + (t * (a + a + a)) % (k + k + k) = k + k + k := by
    rw [hm'e] at hza hzm hg ⊢
    exact InductiveStep.pair_m m' t z (a + a + a) hza (not_dv m' t z hg hz0 hzm)
  rw [m3] at pm
  show Nat.beq ((t * a) % (k + k + k) + ((t * (a + k)) % (k + k + k) + ((t * (a + k + k)) % (k + k + k)
      + ((t * z) % (k + k + k) + 0)))
      + ((t * a) % (k + k + k) + ((t * (a + k)) % (k + k + k) + ((t * (a + k + k)) % (k + k + k)
      + ((t * z) % (k + k + k) + 0))))) (4 * (k + k + k)) = true
  rw [m0, m1, m2]
  generalize (t * z) % (k + k + k) = w at pm ⊢
  have ts := three_sum j e hj3 he
  have x : u + k * (j % 3) + (u + k * ((j + e) % 3) + (u + k * ((j + e + e) % 3) + (w + 0)))
      = (w + (u + u + u)) + k * (j % 3 + (j + e) % 3 + (j + e + e) % 3) := by lib_nat
  rw [x, pm, ts]
  have y : k + k + k + k * 3 + (k + k + k + k * 3) = 4 * (k + k + k) := by lib_nat
  rw [y]; exact beq_self _

end ThirdFam

#print axioms ThirdFam.lt3
#print axioms ThirdFam.three_sum
#print axioms ThirdFam.unit3
#print axioms ThirdFam.lt3'
#print axioms ThirdFam.red3
#print axioms ThirdFam.third_bal

#print axioms: 6 theorems, no axioms.

81.105 Four-element characters without \(m/2\) and complementary pairs

A four-element character with no entry \(m/2\) and no two entries summing to \(m\) is indecomposable, every \(m\ge 2\). \(2v\ne m,\ u+v\ne m\Rightarrow \mathrm {indec}\,m\,[w,x,y,z]\).

hodge/Indec4.lean

/-
  hodge/Indec4.lean — T41 cycle 754 (goal G467): a four-element character with no entry m/2 and no two entries
  summing to m is indecomposable, every m ≥ 2. In particular the ThirdFam characters [a, a+k, a+2k, 3k−3a] for odd
  m = 3k (e.g. [1, 4, 6, 7] at m = 9, as in IndecSmall) are indecomposable when no two entries sum to m.

  Lean 4 core plus hodge/IndecTriple (and_false', single_false), hodge/PairIff (pair_iff), hodge/Indecomp.
    indec4_eq     indec m [w, x, y, z] as an explicit Boolean formula (rfl)
    indec4_of     singletons and pairs unbalanced ⇒ indecomposable
    pair_false    0 < u, v < m, u + v ≠ m ⇒ bal m [u, v] = false
    indec4        the arithmetic form
-/
import hodge.IndecTriple

namespace Indec4
open Indecomp IndecTriple PairIff

theorem indec4_eq (m w x y z : Nat) : indec m [w, x, y, z] = (true && (!(bal m [x, y, z] && bal m [w]) && (!(bal m [w, y, z] && bal m [x]) && (!(bal m [y, z] && bal m [w, x]) && (!(bal m [w, x, z] && bal m [y]) && (!(bal m [x, z] && bal m [w, y]) && (!(bal m [w, z] && bal m [x, y]) && (!(bal m [z] && bal m [w, x, y]) && (!(bal m [w, x, y] && bal m [z]) && (!(bal m [x, y] && bal m [w, z]) && (!(bal  -- (+210 chars; full line in the Zenodo source)

theorem indec4_of (m w x y z : Nat)
    (sw : bal m [w] = false) (sx : bal m [x] = false) (sy : bal m [y] = false) (sz : bal m [z] = false)
    (pwx : bal m [w, x] = false) (pwy : bal m [w, y] = false) (pwz : bal m [w, z] = false)
    (pxy : bal m [x, y] = false) (pxz : bal m [x, z] = false) (pyz : bal m [y, z] = false) :
    indec m [w, x, y, z] = true := by
  rw [indec4_eq, sw, sx, sy, sz, pwx, pwy, pwz, pxy, pxz, pyz, and_false', and_false', and_false', and_false', and_false' (bal m [w, x, y])]
  rfl

theorem pair_false (n u v : Nat) (hu0 : 0 < u) (hv0 : 0 < v) (hu : u < n + 2) (hv : v < n + 2)
    (hne : u + v ≠ n + 2) : bal (n + 2) [u, v] = false := by
  cases e : bal (n + 2) [u, v] with
  | false => rfl
  | true => exact absurd ((pair_iff n u v hu0 hv0 hu hv).1 e) hne

theorem indec4 (n w x y z : Nat) (hw0 : 0 < w) (hx0 : 0 < x) (hy0 : 0 < y) (hz0 : 0 < z)
    (hw : w < n + 2) (hx : x < n + 2) (hy : y < n + 2) (hz : z < n + 2)
    (nw : w + w ≠ n + 2) (nx : x + x ≠ n + 2) (ny : y + y ≠ n + 2) (nz : z + z ≠ n + 2)
    (qwx : w + x ≠ n + 2) (qwy : w + y ≠ n + 2) (qwz : w + z ≠ n + 2)
    (qxy : x + y ≠ n + 2) (qxz : x + z ≠ n + 2) (qyz : y + z ≠ n + 2) :
    indec (n + 2) [w, x, y, z] = true :=
  indec4_of _ w x y z (single_false n w hw0 hw nw) (single_false n x hx0 hx nx) (single_false n y hy0 hy ny)
    (single_false n z hz0 hz nz) (pair_false n w x hw0 hx0 hw hx qwx) (pair_false n w y hw0 hy0 hw hy qwy)
    (pair_false n w z hw0 hz0 hw hz qwz) (pair_false n x y hx0 hy0 hx hy qxy) (pair_false n x z hx0 hz0 hx hz qxz)
    (pair_false n y z hy0 hz0 hy hz qyz)

end Indec4

#print axioms Indec4.indec4_eq
#print axioms Indec4.indec4_of
#print axioms Indec4.pair_false
#print axioms Indec4.indec4

#print axioms: 4 theorems, no axioms.

81.106 The \(\mu _q\)-orbit sum

An exact identity with no units, every \(q,k>0\) and every \(y\). \(\sum _{i<q}\langle y+ik\rangle _{qk}=q\langle y\rangle _k+k\sum _{i<q}i\).

hodge/OrbitSum.lean

/-
  hodge/OrbitSum.lean — T41 cycle 757 (goal G470): the μ_q-orbit sum, an exact identity with no units:
    Σ_{i<q} ⟨y + i·k⟩_{qk} = q·⟨y⟩_k + k·Σ_{i<q} i        (k, q > 0).
  First step toward the general family [a, a+k, …, a+(q−1)k, qk − qa] (balanced for every q ≤ 7, k < 15 by
  computation; q = 2 Triple, q = 3 ThirdFam).

  Lean 4 core plus hodge/ThirdFam (div_mod, mod_lt', add_mul_mod', add_mod'), lib/Semi (lib_nat).
    sumF          Σ_{i<n} f i
    tele          Σ_{i<n} f (i+1) + f 0 = Σ_{i<n} f i + f n
    shift_inv     Σ_{i<q} (j+1+i) mod q = Σ_{i<q} (j+i) mod q
    cyc           Σ_{i<q} (j+i) mod q = Σ_{i<q} i
    redq          ⟨u + k·i⟩_{qk} = u + k·(i mod q)   (u < k)
    orbit_sum     the identity
-/
import hodge.ThirdFam

namespace OrbitSum
open GcdHand ModHand

def sumF (f : Nat → Nat) : Nat → Nat
  | 0 => 0
  | n + 1 => sumF f n + f n

theorem tele (f : Nat → Nat) : ∀ n, sumF (fun i => f (i + 1)) n + f 0 = sumF f n + f n
  | 0 => by show 0 + f 0 = 0 + f 0; rfl
  | n + 1 => by
    show sumF (fun i => f (i + 1)) n + f (n + 1) + f 0 = sumF f n + f n + f (n + 1)
    have ih := tele f n
    have e : sumF (fun i => f (i + 1)) n + f (n + 1) + f 0 = (sumF (fun i => f (i + 1)) n + f 0) + f (n + 1) := by
      lib_nat
    rw [e, ih]

theorem sumF_ext (f g : Nat → Nat) : ∀ n, (∀ i, i < n → f i = g i) → sumF f n = sumF g n
  | 0, _ => rfl
  | n + 1, h => by
    show sumF f n + f n = sumF g n + g n
    rw [sumF_ext f g n (fun i hi => h i (Nat.lt_succ_of_lt hi)), h n (Nat.lt_succ_self n)]

theorem shift_inv (q j : Nat) (hq : 0 < q) :
    sumF (fun i => (j + 1 + i) % q) q = sumF (fun i => (j + i) % q) q := by
  have t := tele (fun i => (j + i) % q) q
  have e1 : sumF (fun i => (j + (i + 1)) % q) q = sumF (fun i => (j + 1 + i) % q) q :=
    sumF_ext _ _ q (fun i _ => by rw [show j + (i + 1) = j + 1 + i by lib_nat])
  have e2 : (j + q) % q = (j + 0) % q := by rw [Nat.add_zero, add_mod' _ _ hq]
  rw [e1, e2] at t
  exact BalAppend.add_cancel _ _ _ (by rw [Nat.add_comm _ ((j + 0) % q), Nat.add_comm _ ((j + 0) % q)] at t; exact t)

theorem cyc (q : Nat) (hq : 0 < q) : ∀ j, sumF (fun i => (j + i) % q) q = sumF (fun i => i) q
  | 0 => sumF_ext _ _ q (fun i hi => by rw [Nat.zero_add]; exact mod_lt' _ _ hi)
  | j + 1 => by rw [shift_inv q j hq]; exact cyc q hq j

theorem redq (q k u : Nat) (hq : 0 < q) (hu : u < k) (i : Nat) : (u + k * i) % (q * k) = u + k * (i % q) := by
  have hk : 0 < k := Nat.lt_of_le_of_lt (Nat.zero_le u) hu
  have hqk : 0 < q * k := Nat.mul_pos hq hk
  have ⟨p, hp⟩ := div_mod q hq (i + 1) i (Nat.lt_succ_self i)
  have hl : i % q < q := Nat.mod_lt _ hq
  generalize i % q = j at hp hl ⊢
  have e : u + k * i = (u + k * j) + p * (q * k) := by rw [hp]; lib_nat
  rw [e, add_mul_mod' _ _ hqk]
  apply mod_lt'
  have ⟨d, hd⟩ := Triple.le_dest hl
  have : u + k * j < k + k * j := Nat.add_lt_add_right hu _
  apply Nat.lt_of_lt_of_le this
  rw [← hd]
  have e2 : (j + 1 + d) * k = k + k * j + d * k := by lib_nat
  rw [e2]; exact Nat.le_add_right _ _

theorem sum_lin (u k : Nat) (g : Nat → Nat) : ∀ n, sumF (fun i => u + k * g i) n = n * u + k * sumF g n
  | 0 => by show 0 = 0 * u + k * 0; rw [Nat.zero_mul, Nat.mul_zero]
  | n + 1 => by
    show sumF (fun i => u + k * g i) n + (u + k * g n) = (n + 1) * u + k * (sumF g n + g n)
    rw [sum_lin u k g n]; lib_nat

theorem orbit_sum (q k y : Nat) (hq : 0 < q) (hk : 0 < k) :
    sumF (fun i => (y + i * k) % (q * k)) q = q * (y % k) + k * sumF (fun i => i) q := by
  have ⟨j, hj⟩ := div_mod k hk (y + 1) y (Nat.lt_succ_self y)
  have hu : y % k < k := Nat.mod_lt _ hk
  generalize y % k = u at hj hu ⊢
  have e : sumF (fun i => (y + i * k) % (q * k)) q = sumF (fun i => u + k * ((j + i) % q)) q :=
    sumF_ext _ _ q (fun i _ => by
      rw [show y + i * k = u + k * (j + i) by rw [hj]; lib_nat, redq q k u hq hu])
  rw [e, sum_lin, cyc q hq j]

end OrbitSum

#print axioms OrbitSum.tele
#print axioms OrbitSum.sumF_ext
#print axioms OrbitSum.shift_inv
#print axioms OrbitSum.cyc
#print axioms OrbitSum.redq
#print axioms OrbitSum.sum_lin
#print axioms OrbitSum.orbit_sum

#print axioms: 7 theorems, no axioms.

81.107 Units permute \(\mathbb Z/q\) (sum form)

For \(\gcd (e,q)=1\) the residues \((j+ei)\bmod q\), \(i<q\), have the full sum; via a hand pigeonhole principle. \(\sum _{i<q}(j+ei)\bmod q=\sum _{i<q}i\).

hodge/PermSum.lean

/-
  hodge/PermSum.lean — T41 cycle 761 (goal G470b): multiplication by a unit permutes ℤ/q, in sum form:
    gcd e q = 1  ⇒  Σ_{i<q} (j + e·i) mod q = Σ_{i<q} i.
  Via a hand pigeonhole: a list of q values < q with no repeats has sum Σ_{i<q} i.

  Lean 4 core plus hodge/OrbitSum (sumF, cyc), hodge/APPairGen (euclid), hodge/GcdHand (div_mod), lib/Semi.
    cnt, rmv          occurrences / removal of a value
    len_le            no repeats, all < q ⇒ length ≤ q        (pigeonhole)
    sum_full          no repeats, all < q, length q ⇒ sum = Σ_{i<q} i
    inj_mod           gcd e q = 1, i, i' < q, (j + e i) mod q = (j + e i') mod q ⇒ i = i'
    perm_sum          the statement
-/
import hodge.OrbitSum

namespace PermSum
open GcdHand ModHand OrbitSum APPairGen

def cnt (v : Nat) : List Nat → Nat
  | [] => 0
  | x :: l => (if Nat.beq x v then 1 else 0) + cnt v l

def rmv (v : Nat) : List Nat → List Nat
  | [] => []
  | x :: l => if Nat.beq x v then rmv v l else x :: rmv v l

def lsum : List Nat → Nat
  | [] => 0
  | x :: l => x + lsum l

theorem beq_cases (x v : Nat) : (Nat.beq x v = true ∧ x = v) ∨ (Nat.beq x v = false ∧ x ≠ v) := by
  cases e : Nat.beq x v with
  | true => exact Or.inl ⟨rfl, Nat.eq_of_beq_eq_true e⟩
  | false => exact Or.inr ⟨rfl, fun h => by rw [h, HalfGeneral.beq_self] at e; exact Bool.noConfusion e⟩

theorem len_rmv (v : Nat) : ∀ L : List Nat, (rmv v L).length + cnt v L = L.length
  | [] => rfl
  | x :: l => by
    have ih := len_rmv v l
    cases beq_cases x v with
    | inl h =>
      show (if Nat.beq x v = true then rmv v l else x :: rmv v l).length + ((if Nat.beq x v = true then 1 else 0) + cnt v l) = l.length + 1
      rw [h.1]; show (rmv v l).length + (1 + cnt v l) = l.length + 1
      rw [← ih]; lib_nat
    | inr h =>
      show (if Nat.beq x v = true then rmv v l else x :: rmv v l).length + ((if Nat.beq x v = true then 1 else 0) + cnt v l) = l.length + 1
      rw [h.1]; show (rmv v l).length + 1 + (0 + cnt v l) = l.length + 1
      rw [← ih]; lib_nat

theorem sum_rmv (v : Nat) : ∀ L : List Nat, lsum (rmv v L) + v * cnt v L = lsum L
  | [] => rfl
  | x :: l => by
    have ih := sum_rmv v l
    cases beq_cases x v with
    | inl h =>
      show lsum (if Nat.beq x v = true then rmv v l else x :: rmv v l) + v * ((if Nat.beq x v = true then 1 else 0) + cnt v l) = x + lsum l
      rw [h.1, h.2]; show lsum (rmv v l) + v * (1 + cnt v l) = v + lsum l
      rw [← ih]; lib_nat
    | inr h =>
      show lsum (if Nat.beq x v = true then rmv v l else x :: rmv v l) + v * ((if Nat.beq x v = true then 1 else 0) + cnt v l) = x + lsum l
      rw [h.1]; show x + lsum (rmv v l) + v * (0 + cnt v l) = x + lsum l
      rw [← ih]; lib_nat

theorem mem_rmv (v : Nat) : ∀ (L : List Nat) (y : Nat), y ∈ rmv v L → y ∈ L ∧ y ≠ v
  | [], _, h => by cases h
  | x :: l, y, h => by
    cases beq_cases x v with
    | inl hx =>
      have h' : y ∈ rmv v l := by
        have : rmv v (x :: l) = rmv v l := by show (if Nat.beq x v = true then _ else _) = _; rw [hx.1]; rfl
        rw [this] at h; exact h
      have r := mem_rmv v l y h'
      exact ⟨List.Mem.tail _ r.1, r.2⟩
    | inr hx =>
      have h' : y ∈ x :: rmv v l := by
        have : rmv v (x :: l) = x :: rmv v l := by show (if Nat.beq x v = true then _ else _) = _; rw [hx.1]; rfl
        rw [this] at h; exact h
      cases h' with
      | head => exact ⟨List.Mem.head _, hx.2⟩
      | tail _ h2 =>
        have r := mem_rmv v l y h2
        exact ⟨List.Mem.tail _ r.1, r.2⟩

theorem cnt_rmv_le (v w : Nat) : ∀ L : List Nat, cnt w (rmv v L) ≤ cnt w L
  | [] => Nat.le_refl _
  | x :: l => by
    have ih := cnt_rmv_le v w l
    cases beq_cases x v with
    | inl hx =>
      have : rmv v (x :: l) = rmv v l := by show (if Nat.beq x v = true then _ else _) = _; rw [hx.1]; rfl
      rw [this]; exact Nat.le_trans ih (Nat.le_add_left _ _)
    | inr hx =>
      have : rmv v (x :: l) = x :: rmv v l := by show (if Nat.beq x v = true then _ else _) = _; rw [hx.1]; rfl
      rw [this]; exact Nat.add_le_add_left ih _

theorem len_le : ∀ (q : Nat) (L : List Nat), (∀ v, cnt v L ≤ 1) → (∀ x, x ∈ L → x < q) → L.length ≤ q
  | 0, [], _, _ => Nat.le_refl 0
  | 0, x :: _, _, h => absurd (h x (List.Mem.head _)) (Nat.not_lt_zero x)
  | q + 1, L, hn, hb => by
    have l1 := len_le q (rmv q L) (fun v => Nat.le_trans (cnt_rmv_le q v L) (hn v)) (fun x hx => by
      have r := mem_rmv q L x hx
      have := hb x r.1
      cases Nat.lt_or_ge x q with
      | inl l => exact l
      | inr g => exact absurd (Nat.le_antisymm (Nat.le_of_lt_succ this) g) r.2)
    rw [← len_rmv q L]
    exact Nat.add_le_add l1 (hn q)

theorem sum_full : ∀ (q : Nat) (L : List Nat), (∀ v, cnt v L ≤ 1) → (∀ x, x ∈ L → x < q) → L.length = q →
    lsum L = sumF (fun i => i) q
  | 0, [], _, _, _ => rfl
  | 0, _ :: _, _, _, h => Nat.noConfusion h
  | q + 1, L, hn, hb, hl => by
    have hlt : ∀ x, x ∈ rmv q L → x < q := fun x hx => by
      have r := mem_rmv q L x hx
      have := hb x r.1
      cases Nat.lt_or_ge x q with
      | inl l => exact l
      | inr g => exact absurd (Nat.le_antisymm (Nat.le_of_lt_succ this) g) r.2
    have hn' : ∀ v, cnt v (rmv q L) ≤ 1 := fun v => Nat.le_trans (cnt_rmv_le q v L) (hn v)
    have lr := len_rmv q L
    have c1 : cnt q L = 1 := by
      cases Nat.lt_or_ge (cnt q L) 1 with
      | inl l0 =>
        exfalso
        have c0 : cnt q L = 0 := Nat.eq_zero_of_le_zero (Nat.le_of_lt_succ l0)
        rw [c0, Nat.add_zero, hl] at lr
        have := len_le q (rmv q L) hn' hlt
        rw [lr] at this; exact Nat.not_succ_le_self q this
      | inr g => exact Nat.le_antisymm (hn q) g
    rw [c1, hl] at lr
    have lq : (rmv q L).length = q := Nat.succ.inj lr
    have s := sum_rmv q L
    rw [c1, Nat.mul_one, sum_full q (rmv q L) hn' hlt lq] at s
    rw [← s]; rfl

def gl (g : Nat → Nat) : Nat → List Nat
  | 0 => []
  | n + 1 => g n :: gl g n

theorem gl_len (g : Nat → Nat) : ∀ n, (gl g n).length = n
  | 0 => rfl
  | n + 1 => by show (gl g n).length + 1 = n + 1; rw [gl_len g n]

theorem gl_sum (g : Nat → Nat) : ∀ n, lsum (gl g n) = sumF g n
  | 0 => rfl
  | n + 1 => by show g n + lsum (gl g n) = sumF g n + g n; rw [gl_sum g n, Nat.add_comm]

theorem gl_mem (g : Nat → Nat) : ∀ n y, y ∈ gl g n → ∃ i, i < n ∧ g i = y
  | 0, _, h => by cases h
  | n + 1, y, h => by
    cases h with
    | head => exact ⟨n, Nat.lt_succ_self n, rfl⟩
    | tail _ h2 =>
      have ⟨i, hi, e⟩ := gl_mem g n y h2
      exact ⟨i, Nat.lt_succ_of_lt hi, e⟩

theorem cnt_zero (g : Nat → Nat) (v : Nat) : ∀ n, (∀ i, i < n → g i ≠ v) → cnt v (gl g n) = 0
  | 0, _ => rfl
  | n + 1, h => by
    show (if Nat.beq (g n) v = true then 1 else 0) + cnt v (gl g n) = 0
    cases beq_cases (g n) v with
    | inl hx => exact absurd hx.2 (h n (Nat.lt_succ_self n))
    | inr hx => rw [hx.1, cnt_zero g v n (fun i hi => h i (Nat.lt_succ_of_lt hi))]; rfl

theorem cnt_inj (g : Nat → Nat) (n0 : Nat) (hinj : ∀ i i', i < i' → i' < n0 → g i ≠ g i') (v : Nat) :
    ∀ n, n ≤ n0 → cnt v (gl g n) ≤ 1
  | 0, _ => Nat.zero_le _
  | n + 1, hn => by
    show (if Nat.beq (g n) v = true then 1 else 0) + cnt v (gl g n) ≤ 1
    cases beq_cases (g n) v with
    | inl hx =>
      rw [hx.1, cnt_zero g v n (fun i hi e => hinj i n hi hn (by rw [e, hx.2]))]
      exact Nat.le_refl 1
    | inr hx =>
      rw [hx.1]
      show 0 + cnt v (gl g n) ≤ 1
      rw [Nat.zero_add]; exact cnt_inj g n0 hinj v n (Nat.le_of_succ_le hn)

theorem inj_mod (q e j i d : Nat) (hq : 0 < q) (hg : Nat.gcd e q = 1) (hd0 : 0 < d) (hdq : i + d < q)
    (h : (j + e * i) % q = (j + e * (i + d)) % q) : False := by
  have ⟨p, hp⟩ := div_mod q hq (j + e * i + 1) (j + e * i) (Nat.lt_succ_self _)
  have ⟨p', hp'⟩ := div_mod q hq (j + e * (i + d) + 1) (j + e * (i + d)) (Nat.lt_succ_self _)
  rw [← h] at hp'
  generalize (j + e * i) % q = r at hp hp'
  have e1 : r + q * p + e * d = r + q * p' := by rw [← hp, ← hp']; lib_nat
  have e2 : q * p + e * d = q * p' := by
    have : r + (q * p + e * d) = r + q * p' := by rw [← e1]; lib_nat
    exact BalAppend.add_cancel _ _ _ this
  have hpp : q * p ≤ q * p' := by rw [← e2]; exact Nat.le_add_right _ _
  have ⟨w, hw⟩ := Triple.le_dest (Nat.le_of_mul_le_mul_left hpp hq)
  rw [← hw, show q * (p + w) = q * p + q * w by lib_nat] at e2
  have e3 : e * d = q * w := BalAppend.add_cancel _ _ _ e2
  have ⟨c, hc⟩ := euclid e q q d hg ⟨w, e3⟩ ⟨d, rfl⟩
  cases c with
  | zero => rw [Nat.mul_zero] at hc; rw [hc] at hd0; exact Nat.lt_irrefl 0 hd0
  | succ c =>
    have : q ≤ d := by rw [hc, show q * (c + 1) = q + q * c by lib_nat]; exact Nat.le_add_right _ _
    exact Nat.lt_irrefl q (Nat.lt_of_le_of_lt (Nat.le_trans this (Nat.le_add_left d i)) hdq)

theorem perm_sum (q e j : Nat) (hq : 0 < q) (hg : Nat.gcd e q = 1) :
    sumF (fun i => (j + e * i) % q) q = sumF (fun i => i) q := by
  rw [← gl_sum]
  apply sum_full q
  · exact fun v => cnt_inj _ q (fun i i' hii' hi'q eq => by
      have ⟨d, hd⟩ := Triple.le_dest hii'
      exact inj_mod q e j i (d + 1) hq hg (Nat.succ_pos d)
        (by rw [show i + (d + 1) = i + 1 + d by lib_nat, hd]; exact hi'q)
        (by rw [← hd] at eq; rw [show i + (d + 1) = i + 1 + d by lib_nat]; exact eq)) v q (Nat.le_refl q)
  · intro x hx
    have ⟨i, _, e⟩ := gl_mem _ q x hx
    rw [← e]; exact Nat.mod_lt _ hq
  · exact gl_len _ q

end PermSum

#print axioms PermSum.beq_cases
#print axioms PermSum.len_rmv
#print axioms PermSum.sum_rmv
#print axioms PermSum.mem_rmv
#print axioms PermSum.cnt_rmv_le
#print axioms PermSum.len_le
#print axioms PermSum.sum_full
#print axioms PermSum.gl_len
#print axioms PermSum.gl_sum
#print axioms PermSum.gl_mem
#print axioms PermSum.cnt_zero
#print axioms PermSum.cnt_inj
#print axioms PermSum.inj_mod
#print axioms PermSum.perm_sum

#print axioms: 14 theorems, no axioms.

81.108 The \(\mu _q\)-orbit family

For \(m=qk\) and \(0<a<k\) the character \([a+ik\ (i<q)]\sqcup [qk-qa]\) is balanced, every \(q,k\ge 1\). \(\sum _{i<q}\langle t(a+ik)\rangle +\langle t(qk-qa)\rangle =k\sum _{i<q}i+qk=\tfrac {q+1}{2}\,m\) for every unit \(t\).

hodge/QFam.lean

/-
  hodge/QFam.lean — T41 cycle 764 (goal G470c): the μ_q-orbit family. For m = q·k (q, k ≥ 1) and 0 < a < k the
  character [a + i·k (i < q)] ⊔ [qk − qa] is balanced. q = 1: complementary pair; q = 2: Triple; q = 3: ThirdFam;
  computation: every q ≤ 7, k < 15.

  Lean 4 core plus hodge/PermSum (perm_sum, gl), hodge/OrbitSum (redq, sumF), hodge/ScaleBal (gcd_down),
  hodge/UnitMul (unit_mul), hodge/PairBal (not_dv), hodge/InductiveStep (pair_m), hodge/TwistBal, lib/Semi.
    tsum_gl     T_t(gl g q) = Σ_{i<q} ⟨t·g i⟩
    tri_id      Σ_{i<q} i + Σ_{i<q} i + q = q·q
    qfam_bal    the statement
-/
import hodge.PermSum
import hodge.ScaleBal

namespace QFam
open FTAChain Indecomp HalfGeneral GcdHand ModHand TwistBal PairBal UnitMul OrbitSum PermSum

theorem tsum_gl (m t : Nat) (g : Nat → Nat) : ∀ q, tsum m t (gl g q) = sumF (fun i => (t * g i) % m) q
  | 0 => rfl
  | q + 1 => by
    show (t * g q) % m + tsum m t (gl g q) = sumF (fun i => (t * g i) % m) q + (t * g q) % m
    rw [tsum_gl m t g q, Nat.add_comm]

theorem tri_id : ∀ q, sumF (fun i => i) q + sumF (fun i => i) q + q = q * q
  | 0 => rfl
  | q + 1 => by
    show sumF (fun i => i) q + q + (sumF (fun i => i) q + q) + (q + 1) = (q + 1) * (q + 1)
    have ih := tri_id q
    have e : sumF (fun i => i) q + q + (sumF (fun i => i) q + q) + (q + 1)
        = (sumF (fun i => i) q + sumF (fun i => i) q + q) + (q + q + 1) := by lib_nat
    rw [e, ih]; lib_nat

theorem len_gl (g : Nat → Nat) (q : Nat) : (gl g q ++ [0]).length = q + 1 := by
  rw [BalAppend.len_app, gl_len]; rfl

theorem qfam_bal (q k a : Nat) (hq : 0 < q) (ha0 : 0 < a) (hak : a < k) :
    bal (q * k) (gl (fun i => a + i * k) q ++ [q * k - q * a]) = true := by
  have hk : 0 < k := Nat.lt_of_le_of_lt (Nat.zero_le a) hak
  have hM : 0 < q * k := Nat.mul_pos hq hk
  have hqa : q * a ≤ q * k := Nat.mul_le_mul_left q (Nat.le_of_lt hak)
  generalize hz : q * k - q * a = z
  have hza : z + q * a = q * k := by rw [← hz]; exact sub_add' _ _ hqa
  have hz0 : 0 < z := by
    cases z with
    | zero =>
      rw [Nat.zero_add] at hza
      have := Nat.le_of_mul_le_mul_left (Nat.le_of_eq hza.symm) hq
      exact absurd this (Nat.not_le_of_lt hak)
    | succ z => exact Nat.succ_pos z
  have hzm : z < q * k := by
    rw [← hza]; exact Nat.lt_add_of_pos_right (Nat.mul_pos hq ha0)
  unfold bal FermatPrime.units
  apply all_fr_intro
  intro t _ hp
  have hg : Nat.gcd t (q * k) = 1 := Nat.eq_of_beq_eq_true hp
  -- t mod q is a unit of q
  have hgq : Nat.gcd t q = 1 := ScaleBal.gcd_down t k q (by rw [Nat.mul_comm]; exact hg)
  have hu1 : Nat.gcd ((1 * t) % q) q = 1 := unit_mul 1 t q hq (APPairIrrGen.gcd_one q) hgq
  rw [Nat.one_mul] at hu1
  have ⟨s, hs⟩ := div_mod q hq (t + 1) t (Nat.lt_succ_self t)
  generalize t % q = e at hs hu1
  -- ta = u + k j + (q k) p
  have ⟨p, hp0⟩ := div_mod (q * k) hM (t * a + 1) (t * a) (Nat.lt_succ_self _)
  have hrm : (t * a) % (q * k) < q * k := Nat.mod_lt _ hM
  generalize (t * a) % (q * k) = r at hp0 hrm
  have ⟨j, hj⟩ := div_mod k hk (r + 1) r (Nat.lt_succ_self _)
  have hu : r % k < k := Nat.mod_lt _ hk
  generalize r % k = u at hj hu
  -- the q orbit residues
  have orb : sumF (fun i => (t * (a + i * k)) % (q * k)) q = q * u + k * sumF (fun i => i) q := by
    have e1 : sumF (fun i => (t * (a + i * k)) % (q * k)) q = sumF (fun i => u + k * ((j + e * i) % q)) q :=
      sumF_ext _ _ q (fun i _ => by
        rw [show t * (a + i * k) = (u + k * (j + e * i)) + (p + s * i) * (q * k) by
          rw [show t * (a + i * k) = t * a + t * i * k by lib_nat, hp0, hj, hs]; lib_nat,
          add_mul_mod' _ _ hM, Nat.mul_comm q k, ← Nat.mul_comm q k, redq q k u hq hu])
    rw [e1, sum_lin, perm_sum q e j hq hu1]
  have hm' : ∃ m', q * k = m' + 1 := by
    cases hqk : q * k with
    | zero => rw [hqk] at hM; exact absurd hM (Nat.lt_irrefl 0)
    | succ m' => exact ⟨m', rfl⟩
  have ⟨m', hm'e⟩ := hm'
  have pm : (t * z) % (q * k) + (t * (q * a)) % (q * k) = q * k := by
    rw [hm'e] at hza hzm hg ⊢
    exact InductiveStep.pair_m m' t z (q * a) hza (not_dv m' t z hg hz0 hzm)
  have mq : (t * (q * a)) % (q * k) = q * u := by
    rw [show t * (q * a) = q * u + (j + q * p) * (q * k) by
      rw [show t * (q * a) = q * (t * a) by lib_nat, hp0, hj]; lib_nat, add_mul_mod' _ _ hM]
    exact mod_lt' _ _ (Nat.mul_lt_mul_of_pos_left hu hq)
  rw [mq] at pm
  show Nat.beq (tsum (q * k) t (gl (fun i => a + i * k) q ++ [z]) + tsum (q * k) t (gl (fun i => a + i * k) q ++ [z]))
    ((gl (fun i => a + i * k) q ++ [z]).length * (q * k)) = true
  rw [BalAppend.tsum_app, BalAppend.len_app, gl_len, tsum_gl, orb]
  show Nat.beq (q * u + k * sumF (fun i => i) q + ((t * z) % (q * k) + 0)
      + (q * u + k * sumF (fun i => i) q + ((t * z) % (q * k) + 0))) ((q + 1) * (q * k)) = true
  generalize (t * z) % (q * k) = w at pm ⊢
  have ti := tri_id q
  have key : q * u + k * sumF (fun i => i) q + (w + 0) + (q * u + k * sumF (fun i => i) q + (w + 0))
      = (q + 1) * (q * k) := by
    apply BalAppend.add_cancel (k * q)
    have l : k * q + (q * u + k * sumF (fun i => i) q + (w + 0) + (q * u + k * sumF (fun i => i) q + (w + 0)))
        = (w + q * u) + (w + q * u) + k * (sumF (fun i => i) q + sumF (fun i => i) q + q) := by lib_nat
    rw [l, pm, ti]; lib_nat
  rw [key]; exact beq_self _

end QFam

#print axioms QFam.tsum_gl
#print axioms QFam.tri_id
#print axioms QFam.len_gl
#print axioms QFam.qfam_bal

#print axioms: 4 theorems, no axioms.

81.109 Unreached orbits at \(m=140,144,148,152\) after the \(m/2\) rule

With the odd-length rule (\(c=\{m/2\}\sqcup B\), \(B\) balanced) no reducible unreached orbit remains; the irreducible ones are listed. Orbits: \(6\) (\(m=140\)), \(50\) (\(m=144\)), \(1\) (\(m=148\)), \(2\) (\(m=152\)); representatives balanced and indecomposable by rfl.

hodge/Open148.lean

/-
  hodge/Open148.lean — T41 goal G153: after the odd-length rule (c = {m/2} ⊔ B, B balanced; HalfIff), the length-6
  Hodge characters not reached by the inductive method at m = 148 form one unit orbit (36 characters) and at
  m = 152 two orbits (36 characters), all indecomposable (Kamiak a2_rodd 31945365, 8 shards per m; at m = 140, 144
  the reducible unreached orbits vanish: 108 = 6 orbits, 776 = 50 orbits, none reducible). Orbit representatives:
  balanced and indecomposable, by rfl.

  Lean 4 core plus hodge/Indecomp (bal, indec), rfl.
-/
import hodge.Indecomp

namespace Open148
open Indecomp

set_option maxRecDepth 100000 in
theorem rep148_0 : bal 148 [1, 38, 75, 78, 112, 140] = true ∧ indec 148 [1, 38, 75, 78, 112, 140] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem rep152_0 : bal 152 [1, 39, 77, 80, 115, 144] = true ∧ indec 152 [1, 39, 77, 80, 115, 144] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem rep152_1 : bal 152 [2, 40, 78, 84, 116, 136] = true ∧ indec 152 [2, 40, 78, 84, 116, 136] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem rep140_0 : bal 140 [1, 36, 71, 74, 106, 132] = true ∧ indec 140 [1, 36, 71, 74, 106, 132] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem rep140_1 : bal 140 [1, 58, 71, 86, 90, 114] = true ∧ indec 140 [1, 58, 71, 86, 90, 114] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem rep140_2 : bal 140 [2, 12, 86, 90, 114, 116] = true ∧ indec 140 [2, 12, 86, 90, 114, 116] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem rep140_3 : bal 140 [2, 40, 48, 84, 122, 124] = true ∧ indec 140 [2, 40, 48, 84, 122, 124] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem rep140_4 : bal 140 [2, 40, 58, 86, 114, 120] = true ∧ indec 140 [2, 40, 58, 86, 114, 120] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem rep140_5 : bal 140 [2, 45, 58, 86, 114, 115] = true ∧ indec 140 [2, 45, 58, 86, 114, 115] = true := ⟨rfl, rfl⟩

end Open148

#print axioms Open148.rep148_0
#print axioms Open148.rep152_0
#print axioms Open148.rep152_1
#print axioms Open148.rep140_0
#print axioms Open148.rep140_1
#print axioms Open148.rep140_2
#print axioms Open148.rep140_3
#print axioms Open148.rep140_4
#print axioms Open148.rep140_5

#print axioms: 9 theorems, no axioms.

81.110 The \(\mu _q\) family with the \(m/2\) twist

For \(m=qk=2h\), \(0<a<k\), \(0<qa<h\): \([a+ik\ (i<q)]\sqcup [h+qa,\,m-2qa]\) is balanced (QFam \(\sqcup \) Triple, pair cancelled). The open \(m=148\) orbit \([1,38,75,112,78,140]\) is the case \(q=4\), \(k=37\), \(a=1\).

hodge/QFamHalf.lean

/-
  hodge/QFamHalf.lean — T41 cycle 768 (goal G479): for m = q·k = 2h and 0 < a < k with 0 < q·a < h, the character
  [a + i·k (i < q)] ⊔ [h + q·a, m − 2q·a] is balanced (computation: q = 2, 4, 6, 8, k < 40, no exception). It is
  QFam ⊔ Triple(q·a) with the complementary pair {q·a, m − q·a} cancelled — the m = 148 open orbit
  [1, 38, 75, 112, 78, 140] (Open148) is q = 4, k = 37, a = 1: balanced by this family, indecomposable by rfl.

  Lean 4 core plus hodge/QFam, hodge/Triple, hodge/PairBal (pair_bal), hodge/BalAppend, hodge/HalfGeneral (all_imp).
    bal_congr    same length and the same T_t for every t ⇒ same balance
    qfam_half    the statement
-/
import hodge.QFam

namespace QFamHalf
open Indecomp HalfGeneral BalAppend PairBal PermSum QFam GcdHand

theorem bal_congr (m : Nat) (X Y : List Nat) (ht : ∀ t, tsum m t X = tsum m t Y) (hl : X.length = Y.length)
    (hx : bal m X = true) : bal m Y = true := by
  unfold bal at *
  exact all_imp _ _ (fun t h => by rw [← ht t, ← hl]; exact h) _ hx

theorem qfam_half (q k a h : Nat) (hq : 0 < q) (hqk : q * k = h + h) (ha0 : 0 < a) (hak : a < k)
    (hqa0 : 0 < q * a) (hqa : q * a < h) :
    bal (q * k) (gl (fun i => a + i * k) q ++ [h + q * a, (h + h) - (q * a + q * a)]) = true := by
  have A := qfam_bal q k a hq ha0 hak
  have hh : 0 < h := Nat.lt_of_le_of_lt (Nat.zero_le _) hqa
  have ⟨h0, hh0⟩ : ∃ h0, h = h0 + 1 := by
    cases h with
    | zero => exact absurd hh (Nat.lt_irrefl 0)
    | succ h0 => exact ⟨h0, rfl⟩
  have B := Triple.triple_bal h0 (q * a) hqa0 (by rw [← hh0]; exact hqa)
  rw [← hh0, ← hqk] at B
  have AB := bal_append _ _ _ A B
  have hle : q * a ≤ q * k := by rw [hqk]; exact Nat.le_trans (Nat.le_of_lt hqa) (Nat.le_add_right h h)
  rw [← hqk]
  have hM : 0 < q * k := Nat.lt_of_lt_of_le hqa0 hle
  have ⟨m', hm'⟩ : ∃ m', q * k = m' + 1 := by
    cases hc : q * k with
    | zero => rw [hc] at hM; exact absurd hM (Nat.lt_irrefl 0)
    | succ m' => exact ⟨m', rfl⟩
  have hz : q * a + (q * k - q * a) = q * k := by rw [Nat.add_comm]; exact sub_add' _ _ hle
  have hz0 : 0 < q * k - q * a := by
    cases hc : q * k - q * a with
    | zero =>
      rw [hc, Nat.add_zero, hqk] at hz
      exact absurd hz (Nat.ne_of_lt (Nat.lt_of_lt_of_le hqa (Nat.le_add_right h h)))
    | succ c => exact Nat.succ_pos c
  have P : bal (q * k) [q * a, q * k - q * a] = true := by
    rw [hm'] at hz ⊢; exact pair_bal m' _ _ hz hqa0 (by rw [← hm']; exact hz0)
  apply bal_cancel _ [q * a, q * k - q * a] _ P
  apply bal_congr _ _ _ _ _ AB
  · intro t
    rw [tsum_app, tsum_app, tsum_app, tsum_app]
    show tsum (q * k) t (gl (fun i => a + i * k) q) + ((t * (q * k - q * a)) % (q * k) + 0)
        + ((t * (q * a)) % (q * k) + ((t * (h + q * a)) % (q * k) + ((t * (q * k - (q * a + q * a))) % (q * k) + 0)))
      = (t * (q * a)) % (q * k) + ((t * (q * k - q * a)) % (q * k) + 0)
        + (tsum (q * k) t (gl (fun i => a + i * k) q) + ((t * (h + q * a)) % (q * k) + ((t * (q * k - (q * a + q * a))) % (q * k) + 0)))
    lib_nat
  · rw [len_app, len_app, len_app, len_app, gl_len]
    show q + 1 + 3 = 2 + (q + 2)
    lib_nat

end QFamHalf

#print axioms QFamHalf.bal_congr
#print axioms QFamHalf.qfam_half

#print axioms: 2 theorems, no axioms.

81.111 Unreached orbits in the \(\mu _4\) family

The unreached orbits at \(m=148,152\) (all) and at \(m=140\) (1 of 6), \(m=144\) (3 of 50) are QFamHalf instances with \(q=4\). \([a+ik\ (i<4)]\sqcup [m/2+4a,\,m-8a]\), \(m=4k\).

hodge/OpenFam.lean

/-
  hodge/OpenFam.lean — T41 cycle 771 (goal G479b): the unreached orbits of Open148 that are QFamHalf instances
  (q = 4): all of m = 148 (1 orbit) and m = 152 (2 orbits), one of the 6 at m = 140, three of the 50 at m = 144
  (a = 1, 2, 3 at k = 36). For each, the family list (as computed by gl) and its balance from QFamHalf.qfam_half.

  Lean 4 core plus hodge/QFamHalf, rfl for the list values.
-/
import hodge.QFamHalf

namespace OpenFam
open Indecomp PermSum QFamHalf

theorem f140_1_list : gl (fun i => 1 + i * 35) 4 ++ [70 + 4 * 1, (70 + 70) - (4 * 1 + 4 * 1)] = [106, 71, 36, 1, 74, 132] := rfl
theorem f140_1 : bal (4 * 35) (gl (fun i => 1 + i * 35) 4 ++ [70 + 4 * 1, (70 + 70) - (4 * 1 + 4 * 1)]) = true :=
  qfam_half 4 35 1 70 (Nat.succ_pos 3) rfl (Nat.succ_pos 0) (by show 1 < 35; exact Nat.lt_of_lt_of_le (Nat.lt_succ_self 1) (Nat.le_of_ble_eq_true rfl)) (Nat.succ_pos 3) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 4) (Nat.le_of_ble_eq_true rfl))
theorem f144_1_list : gl (fun i => 1 + i * 36) 4 ++ [72 + 4 * 1, (72 + 72) - (4 * 1 + 4 * 1)] = [109, 73, 37, 1, 76, 136] := rfl
theorem f144_1 : bal (4 * 36) (gl (fun i => 1 + i * 36) 4 ++ [72 + 4 * 1, (72 + 72) - (4 * 1 + 4 * 1)]) = true :=
  qfam_half 4 36 1 72 (Nat.succ_pos 3) rfl (Nat.succ_pos 0) (by show 1 < 36; exact Nat.lt_of_lt_of_le (Nat.lt_succ_self 1) (Nat.le_of_ble_eq_true rfl)) (Nat.succ_pos 3) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 4) (Nat.le_of_ble_eq_true rfl))
theorem f144_2_list : gl (fun i => 2 + i * 36) 4 ++ [72 + 4 * 2, (72 + 72) - (4 * 2 + 4 * 2)] = [110, 74, 38, 2, 80, 128] := rfl
theorem f144_2 : bal (4 * 36) (gl (fun i => 2 + i * 36) 4 ++ [72 + 4 * 2, (72 + 72) - (4 * 2 + 4 * 2)]) = true :=
  qfam_half 4 36 2 72 (Nat.succ_pos 3) rfl (Nat.succ_pos 1) (by show 2 < 36; exact Nat.lt_of_lt_of_le (Nat.lt_succ_self 2) (Nat.le_of_ble_eq_true rfl)) (Nat.succ_pos 7) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 8) (Nat.le_of_ble_eq_true rfl))
theorem f144_3_list : gl (fun i => 3 + i * 36) 4 ++ [72 + 4 * 3, (72 + 72) - (4 * 3 + 4 * 3)] = [111, 75, 39, 3, 84, 120] := rfl
theorem f144_3 : bal (4 * 36) (gl (fun i => 3 + i * 36) 4 ++ [72 + 4 * 3, (72 + 72) - (4 * 3 + 4 * 3)]) = true :=
  qfam_half 4 36 3 72 (Nat.succ_pos 3) rfl (Nat.succ_pos 2) (by show 3 < 36; exact Nat.lt_of_lt_of_le (Nat.lt_succ_self 3) (Nat.le_of_ble_eq_true rfl)) (Nat.succ_pos 11) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 12) (Nat.le_of_ble_eq_true rfl))
theorem f148_1_list : gl (fun i => 1 + i * 37) 4 ++ [74 + 4 * 1, (74 + 74) - (4 * 1 + 4 * 1)] = [112, 75, 38, 1, 78, 140] := rfl
theorem f148_1 : bal (4 * 37) (gl (fun i => 1 + i * 37) 4 ++ [74 + 4 * 1, (74 + 74) - (4 * 1 + 4 * 1)]) = true :=
  qfam_half 4 37 1 74 (Nat.succ_pos 3) rfl (Nat.succ_pos 0) (by show 1 < 37; exact Nat.lt_of_lt_of_le (Nat.lt_succ_self 1) (Nat.le_of_ble_eq_true rfl)) (Nat.succ_pos 3) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 4) (Nat.le_of_ble_eq_true rfl))
theorem f152_1_list : gl (fun i => 1 + i * 38) 4 ++ [76 + 4 * 1, (76 + 76) - (4 * 1 + 4 * 1)] = [115, 77, 39, 1, 80, 144] := rfl
theorem f152_1 : bal (4 * 38) (gl (fun i => 1 + i * 38) 4 ++ [76 + 4 * 1, (76 + 76) - (4 * 1 + 4 * 1)]) = true :=
  qfam_half 4 38 1 76 (Nat.succ_pos 3) rfl (Nat.succ_pos 0) (by show 1 < 38; exact Nat.lt_of_lt_of_le (Nat.lt_succ_self 1) (Nat.le_of_ble_eq_true rfl)) (Nat.succ_pos 3) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 4) (Nat.le_of_ble_eq_true rfl))
theorem f152_2_list : gl (fun i => 2 + i * 38) 4 ++ [76 + 4 * 2, (76 + 76) - (4 * 2 + 4 * 2)] = [116, 78, 40, 2, 84, 136] := rfl
theorem f152_2 : bal (4 * 38) (gl (fun i => 2 + i * 38) 4 ++ [76 + 4 * 2, (76 + 76) - (4 * 2 + 4 * 2)]) = true :=
  qfam_half 4 38 2 76 (Nat.succ_pos 3) rfl (Nat.succ_pos 1) (by show 2 < 38; exact Nat.lt_of_lt_of_le (Nat.lt_succ_self 2) (Nat.le_of_ble_eq_true rfl)) (Nat.succ_pos 7) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 8) (Nat.le_of_ble_eq_true rfl))

end OpenFam

#print axioms OpenFam.f140_1_list
#print axioms OpenFam.f140_1
#print axioms OpenFam.f144_1_list
#print axioms OpenFam.f144_1
#print axioms OpenFam.f144_2_list
#print axioms OpenFam.f144_2
#print axioms OpenFam.f144_3_list
#print axioms OpenFam.f144_3
#print axioms OpenFam.f148_1_list
#print axioms OpenFam.f148_1
#print axioms OpenFam.f152_1_list
#print axioms OpenFam.f152_1
#print axioms OpenFam.f152_2_list
#print axioms OpenFam.f152_2

#print axioms: 14 theorems, no axioms.

81.112 Gluing along a complementary pair

The character form of the inductive structure for lists of any length, every \(m\). \(X\sqcup [z]\), \(Y\sqcup [m-z]\) balanced, \(0<z<m\Rightarrow X\sqcup Y\) balanced.

hodge/Glue.lean

/-
  hodge/Glue.lean — T41 cycle 774 (goal G485): gluing balanced characters along a complementary pair (the
  character form of Shioda's inductive structure, for lists of any length):
    X ⊔ [z] balanced, Y ⊔ [m − z] balanced, 0 < z < m  ⇒  X ⊔ Y balanced.
  Computation (Open148 data): 3 of the 6 unreached orbits at m = 140 and 32 of the 50 at m = 144 are
  [a, a + m/2] ⊔ R with R ⊔ [2a] balanced, i.e. Triple(a) glued to a length-5 character along {2a, m − 2a}.

  Lean 4 core plus hodge/QFamHalf (bal_congr), hodge/PairBal (pair_bal), hodge/BalAppend, lib/Semi.
    glue         the statement
-/
import hodge.QFamHalf

namespace Glue
open Indecomp HalfGeneral BalAppend PairBal QFamHalf GcdHand

theorem glue (m' z : Nat) (X Y : List Nat) (hz0 : 0 < z) (hzm : z < m' + 1)
    (hX : bal (m' + 1) (X ++ [z]) = true) (hY : bal (m' + 1) (Y ++ [m' + 1 - z]) = true) :
    bal (m' + 1) (X ++ Y) = true := by
  have hs : z + (m' + 1 - z) = m' + 1 := by rw [Nat.add_comm]; exact sub_add' _ _ (Nat.le_of_lt hzm)
  have hw0 : 0 < m' + 1 - z := by
    cases hc : m' + 1 - z with
    | zero => rw [hc, Nat.add_zero] at hs; rw [hs] at hzm; exact absurd hzm (Nat.lt_irrefl _)
    | succ c => exact Nat.succ_pos c
  have P := pair_bal m' z (m' + 1 - z) hs hz0 hw0
  have XY := bal_append _ _ _ hX hY
  apply bal_cancel _ [z, m' + 1 - z] _ P
  apply bal_congr _ _ _ _ _ XY
  · intro t
    rw [tsum_app, tsum_app, tsum_app, tsum_app, tsum_app]
    show tsum (m' + 1) t X + ((t * z) % (m' + 1) + 0) + (tsum (m' + 1) t Y + ((t * (m' + 1 - z)) % (m' + 1) + 0))
      = (t * z) % (m' + 1) + ((t * (m' + 1 - z)) % (m' + 1) + 0) + (tsum (m' + 1) t X + tsum (m' + 1) t Y)
    lib_nat
  · rw [len_app, len_app, len_app, len_app, len_app]
    show X.length + 1 + (Y.length + 1) = 2 + (X.length + Y.length)
    lib_nat

end Glue

#print axioms Glue.glue

#print axioms: 1 theorem, no axioms.

81.113 Length-5 pieces of the unreached orbits

The odd-length characters left after removing Triple\((a)\) by gluing: 2 orbits at \(m=140\), 24 at \(m=144\), all balanced and indecomposable. \(\{a,a+m/2\}\sqcup R\) with \(R\sqcup [2a]\) balanced of length 5.

hodge/Pieces5.lean

/-
  hodge/Pieces5.lean — T41 cycle 777 (goal G488): the length-5 pieces of the unreached orbits. For 3 of the 6
  orbits at m = 140 and 32 of the 50 at m = 144 the representative is Triple(a) glued (Glue) to a balanced length-5
  character R ⊔ [2a]; the distinct unit-orbits of these pieces are listed here with balance and indecomposability by
  rfl. They are odd-length balanced characters without m/2 at even m (not QFam / QFamHalf), the new input the reach
  search lacked; iterated Triple-gluing does not reduce them further (computation).

  Lean 4 core plus hodge/Indecomp (bal, indec), rfl.
-/
import hodge.Indecomp

namespace Pieces5
open Indecomp

set_option maxRecDepth 100000 in
theorem p140_0 : bal 140 [2, 18, 88, 106, 136] = true ∧ indec 140 [2, 18, 88, 106, 136] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p140_1 : bal 140 [2, 58, 86, 90, 114] = true ∧ indec 140 [2, 58, 86, 90, 114] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_0 : bal 144 [1, 50, 73, 98, 138] = true ∧ indec 144 [1, 50, 73, 98, 138] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_1 : bal 144 [1, 73, 74, 76, 136] = true ∧ indec 144 [1, 73, 74, 76, 136] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_2 : bal 144 [2, 22, 78, 118, 140] = true ∧ indec 144 [2, 22, 78, 118, 140] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_3 : bal 144 [2, 50, 69, 98, 141] = true ∧ indec 144 [2, 50, 69, 98, 141] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_4 : bal 144 [2, 50, 78, 98, 132] = true ∧ indec 144 [2, 50, 78, 98, 132] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_5 : bal 144 [2, 50, 96, 98, 114] = true ∧ indec 144 [2, 50, 96, 98, 114] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_6 : bal 144 [2, 50, 98, 102, 108] = true ∧ indec 144 [2, 50, 98, 102, 108] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_7 : bal 144 [2, 52, 74, 100, 132] = true ∧ indec 144 [2, 52, 74, 100, 132] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_8 : bal 144 [2, 74, 76, 80, 128] = true ∧ indec 144 [2, 74, 76, 80, 128] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_9 : bal 144 [2, 74, 76, 96, 112] = true ∧ indec 144 [2, 74, 76, 96, 112] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_10 : bal 144 [3, 32, 75, 114, 136] = true ∧ indec 144 [3, 32, 75, 114, 136] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_11 : bal 144 [3, 48, 75, 114, 120] = true ∧ indec 144 [3, 48, 75, 114, 120] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_12 : bal 144 [3, 51, 81, 108, 117] = true ∧ indec 144 [3, 51, 81, 108, 117] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_13 : bal 144 [3, 54, 75, 102, 126] = true ∧ indec 144 [3, 54, 75, 102, 126] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_14 : bal 144 [3, 75, 78, 84, 120] = true ∧ indec 144 [3, 75, 78, 84, 120] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_15 : bal 144 [4, 20, 84, 116, 136] = true ∧ indec 144 [4, 20, 84, 116, 136] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_16 : bal 144 [4, 20, 100, 108, 128] = true ∧ indec 144 [4, 20, 100, 108, 128] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_17 : bal 144 [4, 52, 66, 100, 138] = true ∧ indec 144 [4, 52, 66, 100, 138] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_18 : bal 144 [4, 52, 84, 100, 120] = true ∧ indec 144 [4, 52, 84, 100, 120] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_19 : bal 144 [4, 52, 96, 100, 108] = true ∧ indec 144 [4, 52, 96, 100, 108] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_20 : bal 144 [4, 56, 76, 104, 120] = true ∧ indec 144 [4, 56, 76, 104, 120] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_21 : bal 144 [6, 54, 63, 102, 135] = true ∧ indec 144 [6, 54, 63, 102, 135] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_22 : bal 144 [8, 56, 60, 104, 132] = true ∧ indec 144 [8, 56, 60, 104, 132] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem p144_23 : bal 144 [9, 48, 81, 90, 132] = true ∧ indec 144 [9, 48, 81, 90, 132] = true := ⟨rfl, rfl⟩

end Pieces5

#print axioms Pieces5.p140_0
#print axioms Pieces5.p140_1
#print axioms Pieces5.p144_0
#print axioms Pieces5.p144_1
#print axioms Pieces5.p144_2
#print axioms Pieces5.p144_3
#print axioms Pieces5.p144_4
#print axioms Pieces5.p144_5
#print axioms Pieces5.p144_6
#print axioms Pieces5.p144_7
#print axioms Pieces5.p144_8
#print axioms Pieces5.p144_9
#print axioms Pieces5.p144_10
#print axioms Pieces5.p144_11
#print axioms Pieces5.p144_12
#print axioms Pieces5.p144_13
#print axioms Pieces5.p144_14
#print axioms Pieces5.p144_15
#print axioms Pieces5.p144_16
#print axioms Pieces5.p144_17
#print axioms Pieces5.p144_18
#print axioms Pieces5.p144_19
#print axioms Pieces5.p144_20
#print axioms Pieces5.p144_21
#print axioms Pieces5.p144_22
#print axioms Pieces5.p144_23

#print axioms: 26 theorems, no axioms.

81.114 Most length-5 pieces are scalings

22 of the 26 pieces are \(d\cdot c\) with \(c\) balanced for \(m/d\) (\(d=2,3\)): from \(m=70\), \(72\), \(48\); four primitive pieces at \(m=144\) remain. \(\mathrm {bal}\,(m/d)\,c\Rightarrow \mathrm {bal}\,m\,(d\,c)\) (ScaleBal).

hodge/Pieces5Scale.lean

/-
  hodge/Pieces5Scale.lean — T41 cycle 780 (goal G491): 22 of the 26 length-5 pieces of Pieces5 are scalings of
  balanced length-5 characters of m/2 or m/3 (ScaleBal): both pieces at m = 140 come from m = 70, and at m = 144
  14 from m = 72 and 6 from m = 48; the 4 primitive ones (gcd 1) at m = 144 remain.

  Lean 4 core plus hodge/ScaleBal (scale_bal, scl), rfl for the small balances and the list identities.
-/
import hodge.ScaleBal

namespace Pieces5Scale
open Indecomp ScaleBal

theorem s140_0_eq : scl 2 [1, 9, 44, 53, 68] = [2, 18, 88, 106, 136] := rfl
set_option maxRecDepth 100000 in
theorem s140_0 : bal (2 * 70) (scl 2 [1, 9, 44, 53, 68]) = true :=
  scale_bal 2 70 (Nat.succ_pos 1) (Nat.succ_pos 69) [1, 9, 44, 53, 68] rfl
theorem s140_1_eq : scl 2 [1, 29, 43, 45, 57] = [2, 58, 86, 90, 114] := rfl
set_option maxRecDepth 100000 in
theorem s140_1 : bal (2 * 70) (scl 2 [1, 29, 43, 45, 57]) = true :=
  scale_bal 2 70 (Nat.succ_pos 1) (Nat.succ_pos 69) [1, 29, 43, 45, 57] rfl
theorem s144_2_eq : scl 2 [1, 11, 39, 59, 70] = [2, 22, 78, 118, 140] := rfl
set_option maxRecDepth 100000 in
theorem s144_2 : bal (2 * 72) (scl 2 [1, 11, 39, 59, 70]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [1, 11, 39, 59, 70] rfl
theorem s144_4_eq : scl 2 [1, 25, 39, 49, 66] = [2, 50, 78, 98, 132] := rfl
set_option maxRecDepth 100000 in
theorem s144_4 : bal (2 * 72) (scl 2 [1, 25, 39, 49, 66]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [1, 25, 39, 49, 66] rfl
theorem s144_5_eq : scl 2 [1, 25, 48, 49, 57] = [2, 50, 96, 98, 114] := rfl
set_option maxRecDepth 100000 in
theorem s144_5 : bal (2 * 72) (scl 2 [1, 25, 48, 49, 57]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [1, 25, 48, 49, 57] rfl
theorem s144_6_eq : scl 2 [1, 25, 49, 51, 54] = [2, 50, 98, 102, 108] := rfl
set_option maxRecDepth 100000 in
theorem s144_6 : bal (2 * 72) (scl 2 [1, 25, 49, 51, 54]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [1, 25, 49, 51, 54] rfl
theorem s144_7_eq : scl 2 [1, 26, 37, 50, 66] = [2, 52, 74, 100, 132] := rfl
set_option maxRecDepth 100000 in
theorem s144_7 : bal (2 * 72) (scl 2 [1, 26, 37, 50, 66]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [1, 26, 37, 50, 66] rfl
theorem s144_8_eq : scl 2 [1, 37, 38, 40, 64] = [2, 74, 76, 80, 128] := rfl
set_option maxRecDepth 100000 in
theorem s144_8 : bal (2 * 72) (scl 2 [1, 37, 38, 40, 64]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [1, 37, 38, 40, 64] rfl
theorem s144_9_eq : scl 2 [1, 37, 38, 48, 56] = [2, 74, 76, 96, 112] := rfl
set_option maxRecDepth 100000 in
theorem s144_9 : bal (2 * 72) (scl 2 [1, 37, 38, 48, 56]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [1, 37, 38, 48, 56] rfl
theorem s144_11_eq : scl 3 [1, 16, 25, 38, 40] = [3, 48, 75, 114, 120] := rfl
set_option maxRecDepth 100000 in
theorem s144_11 : bal (3 * 48) (scl 3 [1, 16, 25, 38, 40]) = true :=
  scale_bal 3 48 (Nat.succ_pos 2) (Nat.succ_pos 47) [1, 16, 25, 38, 40] rfl
theorem s144_12_eq : scl 3 [1, 17, 27, 36, 39] = [3, 51, 81, 108, 117] := rfl
set_option maxRecDepth 100000 in
theorem s144_12 : bal (3 * 48) (scl 3 [1, 17, 27, 36, 39]) = true :=
  scale_bal 3 48 (Nat.succ_pos 2) (Nat.succ_pos 47) [1, 17, 27, 36, 39] rfl
theorem s144_13_eq : scl 3 [1, 18, 25, 34, 42] = [3, 54, 75, 102, 126] := rfl
set_option maxRecDepth 100000 in
theorem s144_13 : bal (3 * 48) (scl 3 [1, 18, 25, 34, 42]) = true :=
  scale_bal 3 48 (Nat.succ_pos 2) (Nat.succ_pos 47) [1, 18, 25, 34, 42] rfl
theorem s144_14_eq : scl 3 [1, 25, 26, 28, 40] = [3, 75, 78, 84, 120] := rfl
set_option maxRecDepth 100000 in
theorem s144_14 : bal (3 * 48) (scl 3 [1, 25, 26, 28, 40]) = true :=
  scale_bal 3 48 (Nat.succ_pos 2) (Nat.succ_pos 47) [1, 25, 26, 28, 40] rfl
theorem s144_15_eq : scl 2 [2, 10, 42, 58, 68] = [4, 20, 84, 116, 136] := rfl
set_option maxRecDepth 100000 in
theorem s144_15 : bal (2 * 72) (scl 2 [2, 10, 42, 58, 68]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [2, 10, 42, 58, 68] rfl
theorem s144_16_eq : scl 2 [2, 10, 50, 54, 64] = [4, 20, 100, 108, 128] := rfl
set_option maxRecDepth 100000 in
theorem s144_16 : bal (2 * 72) (scl 2 [2, 10, 50, 54, 64]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [2, 10, 50, 54, 64] rfl
theorem s144_17_eq : scl 2 [2, 26, 33, 50, 69] = [4, 52, 66, 100, 138] := rfl
set_option maxRecDepth 100000 in
theorem s144_17 : bal (2 * 72) (scl 2 [2, 26, 33, 50, 69]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [2, 26, 33, 50, 69] rfl
theorem s144_18_eq : scl 2 [2, 26, 42, 50, 60] = [4, 52, 84, 100, 120] := rfl
set_option maxRecDepth 100000 in
theorem s144_18 : bal (2 * 72) (scl 2 [2, 26, 42, 50, 60]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [2, 26, 42, 50, 60] rfl
theorem s144_19_eq : scl 2 [2, 26, 48, 50, 54] = [4, 52, 96, 100, 108] := rfl
set_option maxRecDepth 100000 in
theorem s144_19 : bal (2 * 72) (scl 2 [2, 26, 48, 50, 54]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [2, 26, 48, 50, 54] rfl
theorem s144_20_eq : scl 2 [2, 28, 38, 52, 60] = [4, 56, 76, 104, 120] := rfl
set_option maxRecDepth 100000 in
theorem s144_20 : bal (2 * 72) (scl 2 [2, 28, 38, 52, 60]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [2, 28, 38, 52, 60] rfl
theorem s144_21_eq : scl 3 [2, 18, 21, 34, 45] = [6, 54, 63, 102, 135] := rfl
set_option maxRecDepth 100000 in
theorem s144_21 : bal (3 * 48) (scl 3 [2, 18, 21, 34, 45]) = true :=
  scale_bal 3 48 (Nat.succ_pos 2) (Nat.succ_pos 47) [2, 18, 21, 34, 45] rfl
theorem s144_22_eq : scl 2 [4, 28, 30, 52, 66] = [8, 56, 60, 104, 132] := rfl
set_option maxRecDepth 100000 in
theorem s144_22 : bal (2 * 72) (scl 2 [4, 28, 30, 52, 66]) = true :=
  scale_bal 2 72 (Nat.succ_pos 1) (Nat.succ_pos 71) [4, 28, 30, 52, 66] rfl
theorem s144_23_eq : scl 3 [3, 16, 27, 30, 44] = [9, 48, 81, 90, 132] := rfl
set_option maxRecDepth 100000 in
theorem s144_23 : bal (3 * 48) (scl 3 [3, 16, 27, 30, 44]) = true :=
  scale_bal 3 48 (Nat.succ_pos 2) (Nat.succ_pos 47) [3, 16, 27, 30, 44] rfl

end Pieces5Scale

#print axioms Pieces5Scale.s140_0_eq
#print axioms Pieces5Scale.s140_0
#print axioms Pieces5Scale.s140_1_eq
#print axioms Pieces5Scale.s140_1
#print axioms Pieces5Scale.s144_2_eq
#print axioms Pieces5Scale.s144_2
#print axioms Pieces5Scale.s144_4_eq
#print axioms Pieces5Scale.s144_4
#print axioms Pieces5Scale.s144_5_eq
#print axioms Pieces5Scale.s144_5
#print axioms Pieces5Scale.s144_6_eq
#print axioms Pieces5Scale.s144_6
#print axioms Pieces5Scale.s144_7_eq
#print axioms Pieces5Scale.s144_7
#print axioms Pieces5Scale.s144_8_eq
#print axioms Pieces5Scale.s144_8
#print axioms Pieces5Scale.s144_9_eq
#print axioms Pieces5Scale.s144_9
#print axioms Pieces5Scale.s144_11_eq
#print axioms Pieces5Scale.s144_11
#print axioms Pieces5Scale.s144_12_eq
#print axioms Pieces5Scale.s144_12
#print axioms Pieces5Scale.s144_13_eq
#print axioms Pieces5Scale.s144_13
#print axioms Pieces5Scale.s144_14_eq
#print axioms Pieces5Scale.s144_14
#print axioms Pieces5Scale.s144_15_eq
#print axioms Pieces5Scale.s144_15
#print axioms Pieces5Scale.s144_16_eq
#print axioms Pieces5Scale.s144_16
#print axioms Pieces5Scale.s144_17_eq
#print axioms Pieces5Scale.s144_17
#print axioms Pieces5Scale.s144_18_eq
#print axioms Pieces5Scale.s144_18
#print axioms Pieces5Scale.s144_19_eq
#print axioms Pieces5Scale.s144_19
#print axioms Pieces5Scale.s144_20_eq
#print axioms Pieces5Scale.s144_20
#print axioms Pieces5Scale.s144_21_eq
#print axioms Pieces5Scale.s144_21
#print axioms Pieces5Scale.s144_22_eq
#print axioms Pieces5Scale.s144_22
#print axioms Pieces5Scale.s144_23_eq
#print axioms Pieces5Scale.s144_23

#print axioms: 44 theorems, no axioms.

81.115 The primitive length-5 pieces at \(m=144\)

Each is Triple\((x)\) glued to a balanced length-4 character (QFam / QFamHalf twists, or a scaling from \(m=72\)). \([x,x+72]\sqcup R\) with \(R\sqcup [2x]\) balanced (Glue).

hodge/Prim144.lean

/-
  hodge/Prim144.lean — T41 cycle 784 (goal G495 = G491b): the four primitive length-5 pieces at m = 144 are each
  Triple(x) glued (Glue) to a balanced length-4 character: [x, x + 72] ⊔ R with R ⊔ [2x] balanced. For three of
  them R ⊔ [2x] is a twist of QFam (q = 3) or QFamHalf (q = 2) (computation); for the fourth it is
  [6, 32, 114, 136] = 2·[3, 16, 57, 68] (m = 72). Leaves by rfl, assembly by Glue.glue.

  Lean 4 core plus hodge/Glue, rfl.
-/
import hodge.Glue

namespace Prim144
open Indecomp Glue

set_option maxRecDepth 100000 in
theorem prim0 : bal 144 ([1, 73] ++ [50, 98, 138]) = true :=
  glue 143 142 [1, 73] [50, 98, 138] (Nat.succ_pos 141) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 142) (Nat.le_of_ble_eq_true rfl)) rfl rfl
set_option maxRecDepth 100000 in
theorem prim1 : bal 144 ([1, 73] ++ [74, 76, 136]) = true :=
  glue 143 142 [1, 73] [74, 76, 136] (Nat.succ_pos 141) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 142) (Nat.le_of_ble_eq_true rfl)) rfl rfl
set_option maxRecDepth 100000 in
theorem prim2 : bal 144 ([69, 141] ++ [2, 50, 98]) = true :=
  glue 143 6 [69, 141] [2, 50, 98] (Nat.succ_pos 5) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 6) (Nat.le_of_ble_eq_true rfl)) rfl rfl
set_option maxRecDepth 100000 in
theorem prim3 : bal 144 ([3, 75] ++ [32, 114, 136]) = true :=
  glue 143 138 [3, 75] [32, 114, 136] (Nat.succ_pos 137) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 138) (Nat.le_of_ble_eq_true rfl)) rfl rfl

end Prim144

#print axioms Prim144.prim0
#print axioms Prim144.prim1
#print axioms Prim144.prim2
#print axioms Prim144.prim3

#print axioms: 4 theorems, no axioms.

81.116 Seeds of the open part at \(m=140,144\)

After all proved rules, the open orbits reduce to 22 indecomposable length-5 seeds at \(m=48\) (6), \(70\) (2), \(72\) (14). Each seed is balanced and indecomposable (rfl).

hodge/Seeds5.lean

/-
  hodge/Seeds5.lean — T41 cycle 787 (goal G498): the seeds of the open part at m = 140, 144. Rerunning the
  explanation with all proved rules (pairs, m/2, Triple-gluing, QFam / QFamHalf up to twist, scaling, any split)
  leaves 5 of 6 orbits at m = 140 and 37 of 50 at m = 144 unexplained (148, 152: none). They reduce by
  Triple-gluing and scaling to length-5 balanced characters at m = 70, 72, 48; the distinct unit-orbits of those
  seeds are listed here, balanced (rfl) with their indecomposability flag (rfl).

  Lean 4 core plus hodge/Indecomp (bal, indec), rfl.
-/
import hodge.Indecomp

namespace Seeds5
open Indecomp

set_option maxRecDepth 100000 in
theorem seed48_0 : bal 48 [1, 16, 25, 38, 40] = true ∧ indec 48 [1, 16, 25, 38, 40] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed48_1 : bal 48 [1, 17, 27, 36, 39] = true ∧ indec 48 [1, 17, 27, 36, 39] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed48_2 : bal 48 [1, 18, 25, 34, 42] = true ∧ indec 48 [1, 18, 25, 34, 42] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed48_3 : bal 48 [1, 25, 26, 28, 40] = true ∧ indec 48 [1, 25, 26, 28, 40] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed48_4 : bal 48 [2, 18, 21, 34, 45] = true ∧ indec 48 [2, 18, 21, 34, 45] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed48_5 : bal 48 [3, 16, 27, 30, 44] = true ∧ indec 48 [3, 16, 27, 30, 44] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed70_6 : bal 70 [1, 9, 44, 53, 68] = true ∧ indec 70 [1, 9, 44, 53, 68] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed70_7 : bal 70 [1, 29, 43, 45, 57] = true ∧ indec 70 [1, 29, 43, 45, 57] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_8 : bal 72 [1, 11, 39, 59, 70] = true ∧ indec 72 [1, 11, 39, 59, 70] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_9 : bal 72 [1, 25, 39, 49, 66] = true ∧ indec 72 [1, 25, 39, 49, 66] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_10 : bal 72 [1, 25, 48, 49, 57] = true ∧ indec 72 [1, 25, 48, 49, 57] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_11 : bal 72 [1, 25, 49, 51, 54] = true ∧ indec 72 [1, 25, 49, 51, 54] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_12 : bal 72 [1, 26, 37, 50, 66] = true ∧ indec 72 [1, 26, 37, 50, 66] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_13 : bal 72 [1, 37, 38, 40, 64] = true ∧ indec 72 [1, 37, 38, 40, 64] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_14 : bal 72 [1, 37, 38, 48, 56] = true ∧ indec 72 [1, 37, 38, 48, 56] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_15 : bal 72 [2, 10, 42, 58, 68] = true ∧ indec 72 [2, 10, 42, 58, 68] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_16 : bal 72 [2, 10, 50, 54, 64] = true ∧ indec 72 [2, 10, 50, 54, 64] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_17 : bal 72 [2, 26, 33, 50, 69] = true ∧ indec 72 [2, 26, 33, 50, 69] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_18 : bal 72 [2, 26, 42, 50, 60] = true ∧ indec 72 [2, 26, 42, 50, 60] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_19 : bal 72 [2, 26, 48, 50, 54] = true ∧ indec 72 [2, 26, 48, 50, 54] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_20 : bal 72 [2, 28, 38, 52, 60] = true ∧ indec 72 [2, 28, 38, 52, 60] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem seed72_21 : bal 72 [4, 28, 30, 52, 66] = true ∧ indec 72 [4, 28, 30, 52, 66] = true := ⟨rfl, rfl⟩

end Seeds5

#print axioms Seeds5.seed48_0
#print axioms Seeds5.seed48_1
#print axioms Seeds5.seed48_2
#print axioms Seeds5.seed48_3
#print axioms Seeds5.seed48_4
#print axioms Seeds5.seed48_5
#print axioms Seeds5.seed70_6
#print axioms Seeds5.seed70_7
#print axioms Seeds5.seed72_8
#print axioms Seeds5.seed72_9
#print axioms Seeds5.seed72_10
#print axioms Seeds5.seed72_11
#print axioms Seeds5.seed72_12
#print axioms Seeds5.seed72_13
#print axioms Seeds5.seed72_14
#print axioms Seeds5.seed72_15
#print axioms Seeds5.seed72_16
#print axioms Seeds5.seed72_17
#print axioms Seeds5.seed72_18
#print axioms Seeds5.seed72_19
#print axioms Seeds5.seed72_20
#print axioms Seeds5.seed72_21

#print axioms: 22 theorems, no axioms.

81.117 A character relation for the \(m=70\) seed

\([1,29,43,45,57]\sqcup [15,25,65]=\mathrm {QFam}(5,14,1)\sqcup [25,45]\) with \([15,25,65]=5\cdot [3,5,13]_{14}\); balance by cancellation. The seed carries 5 of the 6 open orbits at \(m=140\) (Triple-gluing, scaling by 2).

hodge/Seed70.lean

/-
  hodge/Seed70.lean — T41 cycle 790 (goal G501): the m = 70 seed [1, 29, 43, 45, 57] (Seeds5; it carries 5 of the
  6 open orbits at m = 140 through Triple-gluing and scaling by 2) satisfies
    seed ⊔ [15, 25, 65]  =  QFam(q = 5, k = 14, a = 1) ⊔ [25, 45]          (as multisets),
  with [15, 25, 65] = 5·[3, 5, 13] (the sporadic m = 14 triple of Len3Class, ScaleBal) and [25, 45] a
  complementary pair. A relation among characters (all of odd length 3, 5 or of length 6, 2 — not all are cycle
  classes); balance of the seed follows by cancellation (bal_cancel), with no rfl over m = 70 units.

  Lean 4 core plus hodge/QFam (qfam_bal), hodge/ScaleBal (scale_bal), hodge/QFamHalf (bal_congr), hodge/PairBal.
-/
import hodge.QFamHalf

namespace Seed70
open Indecomp HalfGeneral BalAppend PairBal PermSum QFam QFamHalf ScaleBal

set_option maxRecDepth 100000 in
theorem tri14 : bal 14 [3, 5, 13] = true := rfl

theorem t70 : bal (5 * 14) (scl 5 [3, 5, 13]) = true := scale_bal 5 14 (Nat.succ_pos 4) (Nat.succ_pos 13) _ tri14

theorem q70 : bal (5 * 14) (gl (fun i => 1 + i * 14) 5 ++ [5 * 14 - 5 * 1]) = true :=
  qfam_bal 5 14 1 (Nat.succ_pos 4) (Nat.succ_pos 0) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 1) (Nat.le_of_ble_eq_true rfl))

theorem p70 : bal 70 [25, 45] = true := pair_bal 69 25 45 rfl (Nat.succ_pos 24) (Nat.succ_pos 44)

theorem seed70 : bal 70 [1, 29, 43, 45, 57] = true := by
  have big := bal_append _ _ _ q70 p70
  have T : bal 70 [15, 25, 65] = true := t70
  apply bal_cancel _ [15, 25, 65] _ T
  apply bal_congr _ _ _ _ _ big
  · intro t
    show tsum 70 t ([57, 43, 29, 15, 1] ++ [65] ++ [25, 45]) = tsum 70 t ([15, 25, 65] ++ [1, 29, 43, 45, 57])
    rw [tsum_app, tsum_app, tsum_app]
    show (t * 57) % 70 + ((t * 43) % 70 + ((t * 29) % 70 + ((t * 15) % 70 + ((t * 1) % 70 + 0))))
        + ((t * 65) % 70 + 0) + ((t * 25) % 70 + ((t * 45) % 70 + 0))
      = (t * 15) % 70 + ((t * 25) % 70 + ((t * 65) % 70 + 0))
        + ((t * 1) % 70 + ((t * 29) % 70 + ((t * 43) % 70 + ((t * 45) % 70 + ((t * 57) % 70 + 0)))))
    lib_nat
  · rfl

end Seed70

#print axioms Seed70.tri14
#print axioms Seed70.t70
#print axioms Seed70.q70
#print axioms Seed70.p70
#print axioms Seed70.seed70

#print axioms: 5 theorems, no axioms.

81.118 Seeds at \(m=48,72\) by gluing

15 of the 20 seeds are \((F-z)\sqcup (G-(m-z))\) with \(F\) a length-4 family character and \(G\) a Triple-type character. With general gluing the open orbits at \(m=144\) drop from 37 to 21.

hodge/SeedGlue.lean

/-
  hodge/SeedGlue.lean — T41 cycle 983 (goals G498b, G510b): two of the four open length-5 seeds split along a
  connecting value b (b ≡ −ΣS mod m) into a balanced triple of the Triple family and a balanced quadruple
  (a Hodge character of a Fermat surface, algebraic by Lefschetz (1,1), cited):
    m = 70: [1, 9, 44, 53, 68] = [1, 53, 68 | 18] ⊔ [9, 44 | 52],   [9, 44, 52] = Triple(9)
    m = 48: [1, 16, 25, 38, 40] = [1, 25, 38 | 32] ⊔ [16, 40 | 16],  [16, 16, 40] = Triple(16)
  The other two seeds (m = 70: [1, 29, 43, 45, 57]; m = 72: [2, 10, 50, 54, 64]) have only the trivial splits
  (a singleton with its complement), computed over all 2⁵ subsets.

  Lean 4 core plus hodge/CurveSplit20 (lsum), hodge/Indecomp (bal), rfl.
-/
import hodge.CurveSplit20

namespace SeedGlue
open Indecomp CurveSplit20

/-- S ⊔ T = c (up to order), b ≡ −ΣS, (S, b) and (T, m − b) balanced -/
def glueOK (m : Nat) (c S T : List Nat) (b : Nat) : Bool :=
  Nat.beq ((lsum S + b) % m) 0 && !(Nat.beq b 0) && Nat.blt b m &&
  bal m (S ++ [b]) && bal m (T ++ [m - b]) && List.isPerm (S ++ T) c

theorem seed70 : glueOK 70 [1, 9, 44, 53, 68] [1, 53, 68] [9, 44] 18 = true := rfl
theorem seed48 : glueOK 48 [1, 16, 25, 38, 40] [1, 25, 38] [16, 40] 32 = true := rfl

end SeedGlue

#print axioms SeedGlue.seed70
#print axioms SeedGlue.seed48

#print axioms: 15 theorems, no axioms.

81.119 A character relation for an \(m=48\) seed

\([1,17,27,36,39]\sqcup [3,15,33,45]=[1,17,33,45]\sqcup [3,15,27,36,39]\), the right side family twists; balance by cancellation. Two seeds remain without such a relation (\(|T|\le 4\)): \([1,16,25,38,40]_{48}\), \([2,10,50,54,64]_{72}\).

hodge/Seed48.lean

/-
  hodge/Seed48.lean — T41 cycle 798 (goal G510 = G504b): add-and-subtract for the m = 48 seed [1, 17, 27, 36, 39]:
    seed ⊔ [3, 15, 33, 45]  =  [1, 17, 33, 45] ⊔ [3, 15, 27, 36, 39]      (as multisets),
  both right-hand parts being unit twists of family characters (QFam / QFamHalf). Balance of the seed follows by
  cancellation (bal_cancel) from rfl balances of the three family-type pieces. A character relation (odd lengths
  occur), not a statement about cycle classes. Remaining seeds with no relation of this size (|T| ≤ 4, search):
  [1, 16, 25, 38, 40] at m = 48 and [2, 10, 50, 54, 64] at m = 72.

  Lean 4 core plus hodge/QFamHalf (bal_congr), hodge/BalAppend, rfl leaves.
-/
import hodge.QFamHalf

namespace Seed48
open Indecomp HalfGeneral BalAppend QFamHalf

set_option maxRecDepth 100000 in
theorem F1 : bal 48 [1, 17, 33, 45] = true := rfl
set_option maxRecDepth 100000 in
theorem F2 : bal 48 [3, 15, 27, 36, 39] = true := rfl
set_option maxRecDepth 100000 in
theorem T48 : bal 48 [3, 15, 33, 45] = true := rfl

theorem seed48 : bal 48 [1, 17, 27, 36, 39] = true := by
  have big := bal_append _ _ _ F1 F2
  apply bal_cancel _ [3, 15, 33, 45] _ T48
  apply bal_congr _ _ _ _ _ big
  · intro t
    rw [tsum_app, tsum_app]
    show (t * 1) % 48 + ((t * 17) % 48 + ((t * 33) % 48 + ((t * 45) % 48 + 0)))
        + ((t * 3) % 48 + ((t * 15) % 48 + ((t * 27) % 48 + ((t * 36) % 48 + ((t * 39) % 48 + 0)))))
      = (t * 3) % 48 + ((t * 15) % 48 + ((t * 33) % 48 + ((t * 45) % 48 + 0)))
        + ((t * 1) % 48 + ((t * 17) % 48 + ((t * 27) % 48 + ((t * 36) % 48 + ((t * 39) % 48 + 0)))))
    lib_nat
  · rfl

end Seed48

#print axioms Seed48.F1
#print axioms Seed48.F2
#print axioms Seed48.T48
#print axioms Seed48.seed48

#print axioms: 4 theorems, no axioms.

81.120 Gluing is an equivalence

Given \(X\sqcup [z]\) balanced, \(X\sqcup Y\) is balanced exactly when \(Y\sqcup [m-z]\) is, every \(m\). \(\mathrm {bal}(X\sqcup Y)\Leftrightarrow \mathrm {bal}(Y\sqcup [m-z])\).

hodge/Unglue.lean

/-
  hodge/Unglue.lean — T41 cycle 804 (goal G516): the converse of Glue. If X ⊔ Y and X ⊔ [z] are balanced
  (0 < z < m), then Y ⊔ [m − z] is balanced. So, given one glued piece, gluing is an equivalence:
    X ⊔ Y balanced  ⇔  Y ⊔ [m − z] balanced        (when X ⊔ [z] is balanced).

  Lean 4 core plus hodge/Glue (glue), hodge/QFamHalf (bal_congr), hodge/PairBal (pair_bal), hodge/BalAppend.
    unglue      the converse
    glue_iff    the equivalence
-/
import hodge.Glue

namespace Unglue
open Indecomp HalfGeneral BalAppend PairBal QFamHalf GcdHand Glue

theorem unglue (m' z : Nat) (X Y : List Nat) (hz0 : 0 < z) (hzm : z < m' + 1)
    (hX : bal (m' + 1) (X ++ [z]) = true) (hXY : bal (m' + 1) (X ++ Y) = true) :
    bal (m' + 1) (Y ++ [m' + 1 - z]) = true := by
  have hs : z + (m' + 1 - z) = m' + 1 := by rw [Nat.add_comm]; exact sub_add' _ _ (Nat.le_of_lt hzm)
  have hw0 : 0 < m' + 1 - z := by
    cases hc : m' + 1 - z with
    | zero => rw [hc, Nat.add_zero] at hs; rw [hs] at hzm; exact absurd hzm (Nat.lt_irrefl _)
    | succ c => exact Nat.succ_pos c
  have P := pair_bal m' z (m' + 1 - z) hs hz0 hw0
  have big := bal_append _ _ _ hXY P
  apply bal_cancel _ (X ++ [z]) _ hX
  apply bal_congr _ _ _ _ _ big
  · intro t
    rw [tsum_app, tsum_app, tsum_app, tsum_app, tsum_app]
    show tsum (m' + 1) t X + tsum (m' + 1) t Y + ((t * z) % (m' + 1) + ((t * (m' + 1 - z)) % (m' + 1) + 0))
      = tsum (m' + 1) t X + ((t * z) % (m' + 1) + 0) + (tsum (m' + 1) t Y + ((t * (m' + 1 - z)) % (m' + 1) + 0))
    lib_nat
  · rw [len_app, len_app, len_app, len_app, len_app]
    show X.length + Y.length + 2 = X.length + 1 + (Y.length + 1)
    lib_nat

theorem glue_iff (m' z : Nat) (X Y : List Nat) (hz0 : 0 < z) (hzm : z < m' + 1)
    (hX : bal (m' + 1) (X ++ [z]) = true) :
    bal (m' + 1) (X ++ Y) = true ↔ bal (m' + 1) (Y ++ [m' + 1 - z]) = true :=
  ⟨unglue m' z X Y hz0 hzm hX, glue m' z X Y hz0 hzm hX⟩

end Unglue

#print axioms Unglue.unglue
#print axioms Unglue.glue_iff

#print axioms: 2 theorems, no axioms.

81.121 Decomposability is carried by unit twists

If \(c\) splits into two nonempty balanced parts, so does \(t\cdot c\) (\(\gcd (t,m)=1\)); so indecomposability is a property of unit orbits. \(\mathrm {indec}\,m\,(t\cdot c)\Rightarrow \mathrm {indec}\,m\,c\).

hodge/TwistDecomp.lean

/-
  hodge/TwistDecomp.lean — T41 cycle 807 (goal G517): decomposability is carried by unit twists, every m:
  if c splits into two nonempty balanced parts, so does t·c (gcd t m = 1). Hence indec m (t·c) ⇒ indec m c, and
  the indecomposable lists (IndecSmall, Open148, Seeds5) are unions of unit orbits.

  Lean 4 core plus hodge/TwistBal (tw, bal_twist), hodge/Indecomp (splits, indec).
    splits_map     splits (map f c) = map (map f × map f) (splits c)
    all_false      l.all g = false ⇔ some element fails (Bool, by induction)
    decomp_twist   indec m (tw m t c) = true ⇒ indec m c = true
-/
import hodge.TwistBal

namespace TwistDecomp
open Indecomp TwistBal

def pm (f : Nat → Nat) (p : List Nat × List Nat) : List Nat × List Nat := (p.1.map f, p.2.map f)

theorem flatMap_map (f : Nat → Nat) : ∀ (L : List (List Nat × List Nat)) (x : Nat),
    (L.map (pm f)).flatMap (fun p => [(f x :: p.1, p.2), (p.1, f x :: p.2)])
      = (L.flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])).map (pm f)
  | [], _ => rfl
  | p :: L, x => by
    show (f x :: (p.1.map f), p.2.map f) :: (p.1.map f, f x :: p.2.map f) ::
        (L.map (pm f)).flatMap (fun p => [(f x :: p.1, p.2), (p.1, f x :: p.2)])
      = (pm f (x :: p.1, p.2)) :: (pm f (p.1, x :: p.2)) ::
        (L.flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])).map (pm f)
    rw [flatMap_map f L x]; rfl

theorem splits_map (f : Nat → Nat) : ∀ c : List Nat, splits (c.map f) = (splits c).map (pm f)
  | [] => rfl
  | x :: c => by
    show (splits (c.map f)).flatMap (fun p => [(f x :: p.1, p.2), (p.1, f x :: p.2)])
      = ((splits c).flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])).map (pm f)
    rw [splits_map f c, flatMap_map]

theorem all_map {α β : Type} (f : α → β) (g : β → Bool) : ∀ L : List α, (L.map f).all g = L.all (fun a => g (f a))
  | [] => rfl
  | a :: L => by show (g (f a) && (L.map f).all g) = (g (f a) && L.all _); rw [all_map f g L]

theorem all_imp' {α : Type} (p q : α → Bool) (h : ∀ x, p x = true → q x = true) :
    ∀ L : List α, L.all p = true → L.all q = true :=
  HalfGeneral.all_imp p q h

theorem isEmpty_map (f : Nat → Nat) : ∀ l : List Nat, (l.map f).isEmpty = l.isEmpty
  | [] => rfl
  | _ :: _ => rfl

theorem decomp_twist (m t : Nat) (hm : 0 < m) (ht : Nat.gcd t m = 1) (c : List Nat)
    (h : indec m (tw m t c) = true) : indec m c = true := by
  unfold indec at *
  unfold tw at h
  rw [splits_map, all_map] at h
  apply all_imp' _ _ _ _ h
  intro p hp
  have hp' : ((p.1.map (fun x => (t * x) % m)).isEmpty || (p.2.map (fun x => (t * x) % m)).isEmpty
      || !(bal m (p.1.map (fun x => (t * x) % m)) && bal m (p.2.map (fun x => (t * x) % m)))) = true := hp
  rw [isEmpty_map, isEmpty_map] at hp'
  cases e1 : p.1.isEmpty with
  | true => show (true || _ || _) = true; rfl
  | false =>
    cases e2 : p.2.isEmpty with
    | true => show (false || true || _) = true; rfl
    | false =>
      rw [e1, e2] at hp'
      show (false || false || !(bal m p.1 && bal m p.2)) = true
      cases b1 : bal m p.1 with
      | false => rfl
      | true =>
        cases b2 : bal m p.2 with
        | false => rfl
        | true =>
          have t1 := bal_twist m t hm ht p.1 b1
          have t2 := bal_twist m t hm ht p.2 b2
          unfold tw at t1 t2
          rw [t1, t2] at hp'
          exact Bool.noConfusion hp'

end TwistDecomp

#print axioms TwistDecomp.flatMap_map
#print axioms TwistDecomp.splits_map
#print axioms TwistDecomp.all_map
#print axioms TwistDecomp.all_imp'
#print axioms TwistDecomp.isEmpty_map
#print axioms TwistDecomp.decomp_twist

#print axioms: 6 theorems, no axioms.

81.122 Fermat fourfolds of degree \(13\le m\le 18\) (Kamiak)

Indecomposable balanced length-6 characters: none for \(m=13,14,16,17\); six for \(m=15\), eighteen for \(m=18\) (rfl).

hodge/Len6Decomp2.lean

/-
  hodge/Len6Decomp2.lean — T41 goal G460b (Kamiak): the indecomposable balanced length-6 characters for
  13 ≤ m ≤ 18, by rfl: none for m = 13, 14, 16, 17; six for m = 15, eighteen for m = 18.

  Lean 4 core plus hodge/Len6Decomp (bad), rfl.
-/
import hodge.Len6Decomp

namespace Len6Decomp2
open Len6Decomp

set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem e13 : bad 13 = [] := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem e14 : bad 14 = [] := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem e15 : bad 15 = [[1, 2, 7, 11, 12, 12], [1, 4, 7, 10, 10, 13], [1, 6, 6, 8, 11, 13], [2, 4, 7, 9, 9, 14], [2, 5, 5, 8, 11, 14], [3, 3, 4, 8, 13, 14]] := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem e16 : bad 16 = [] := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem e17 : bad 17 = [] := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem e18 : bad 18 = [[1, 1, 7, 14, 15, 16], [1, 1, 10, 13, 14, 15], [1, 2, 8, 14, 14, 15], [1, 2, 10, 13, 13, 15], [1, 7, 7, 8, 15, 16], [2, 2, 8, 13, 14, 15], [2, 3, 4, 11, 17, 17], [2, 3, 10, 11, 11, 17], [2, 4, 7, 13, 13, 15], [2, 7, 8, 8, 14, 15], [3, 4, 4, 10, 16, 17], [3, 4, 5, 8, 17, 17], [3, 4, 5, 10, 16, 16], [3, 4, 10, 10, 11, 16], [3, 5, 5, 8, 16, 17], [3, 5, 5, 11, 14, 16], [3, 5, 1  -- (+44 chars; full line in the Zenodo source)

end Len6Decomp2

#print axioms Len6Decomp2.e13
#print axioms Len6Decomp2.e14
#print axioms Len6Decomp2.e15
#print axioms Len6Decomp2.e16
#print axioms Len6Decomp2.e17
#print axioms Len6Decomp2.e18

#print axioms: 6 theorems, no axioms.

81.123 The indecomposable fourfold characters at \(m=15,18\) explained

\([1,4,7,10,10,13]_{15}=\mathrm {QFam}(5,3,1)\); the other orbit representatives are glued from family/Triple-type pieces. Leaves by rfl, assembly by Glue and QFam.

hodge/Len6Explain.lean

/-
  hodge/Len6Explain.lean — T41 cycle 811 (goal G519): the indecomposable length-6 characters of the Fermat
  fourfolds of degree 15 and 18 (Len6Decomp2: 2 unit-orbits at m = 15, 3 at m = 18) are all explained by the
  proved rules: [1, 4, 7, 10, 10, 13] (m = 15) is QFam(q = 5, k = 3, a = 1); the other four orbit representatives
  are glued (Glue) from two shorter characters along {z, m − z}, both of which are family twists or Triple-type
  (computation). Leaves by rfl.

  Lean 4 core plus hodge/Glue, hodge/QFam, rfl.
-/
import hodge.Glue

namespace Len6Explain
open Indecomp Glue PermSum QFam

theorem fam15 : bal (5 * 3) (gl (fun i => 1 + i * 3) 5 ++ [5 * 3 - 5 * 1]) = true :=
  qfam_bal 5 3 1 (Nat.succ_pos 4) (Nat.succ_pos 0) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 1) (Nat.le_of_ble_eq_true rfl))

theorem fam15_list : gl (fun i => 1 + i * 3) 5 ++ [5 * 3 - 5 * 1] = [13, 10, 7, 4, 1, 10] := rfl

set_option maxRecDepth 100000 in
theorem glue15_0 : bal 15 ([1, 11, 12] ++ [2, 7, 12]) = true :=
  glue 14 6 [1, 11, 12] [2, 7, 12] (Nat.succ_pos 5) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 6) (Nat.le_of_ble_eq_true rfl)) rfl rfl
set_option maxRecDepth 100000 in
theorem glue18_1 : bal 18 ([1, 16] ++ [1, 7, 14, 15]) = true :=
  glue 17 10 [1, 16] [1, 7, 14, 15] (Nat.succ_pos 9) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 10) (Nat.le_of_ble_eq_true rfl)) rfl rfl
set_option maxRecDepth 100000 in
theorem glue18_2 : bal 18 ([1, 10] ++ [1, 13, 14, 15]) = true :=
  glue 17 16 [1, 10] [1, 13, 14, 15] (Nat.succ_pos 15) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 16) (Nat.le_of_ble_eq_true rfl)) rfl rfl
set_option maxRecDepth 100000 in
theorem glue18_3 : bal 18 ([2, 14] ++ [1, 8, 14, 15]) = true :=
  glue 17 11 [2, 14] [1, 8, 14, 15] (Nat.succ_pos 10) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 11) (Nat.le_of_ble_eq_true rfl)) rfl rfl

end Len6Explain

#print axioms Len6Explain.fam15
#print axioms Len6Explain.fam15_list
#print axioms Len6Explain.glue15_0
#print axioms Len6Explain.glue18_1
#print axioms Len6Explain.glue18_2
#print axioms Len6Explain.glue18_3

#print axioms: 6 theorems, no axioms.

81.124 Odd prime degrees: every fourfold character splits as \(2+4\)

For \(m=3,5,7,9,11,13\) every balanced length-6 character contains a complementary pair whose removal leaves a balanced length-4 character. Point \(\times \) surface in the inductive structure (surfaces: Lefschetz (1,1), cited); rfl, 16 s.

hodge/Split24.lean

/-
  hodge/Split24.lean — T41 cycle 815 (goal G526): for m = 3, 5, 7, 9, 11, 13 every balanced length-6 character
  (sorted, entries in (0, m)) contains a complementary pair {x, m − x} whose removal leaves a balanced length-4
  character: a 2 + 4 split (point × surface in the inductive structure; Hodge classes of Fermat surfaces are
  algebraic by Lefschetz (1,1), cited). Computation: the same holds for m = 17 and fails first at m = 6 (Triple ⊔
  Triple, a 3 + 3 split) — for odd prime degrees ≤ 17 the fourfold characters reduce to surfaces. By rfl.

  Lean 4 core plus hodge/Len6Decomp (sexts), hodge/Indecomp (bal), rfl.
-/
import hodge.Len6Decomp

namespace Split24
open Indecomp Len6Decomp

def has24 (m : Nat) (c : List Nat) : Bool :=
  c.any (fun x => let r := c.erase x; r.contains (m - x) && bal m (r.erase (m - x)))

def bad24 (m : Nat) : List (List Nat) := (sexts m).filter (fun c => bal m c && !has24 m c)

set_option maxRecDepth 200000 in
theorem s3 : bad24 3 = [] := rfl
set_option maxRecDepth 200000 in
theorem s5 : bad24 5 = [] := rfl
set_option maxRecDepth 200000 in
theorem s7 : bad24 7 = [] := rfl
set_option maxRecDepth 200000 in
theorem s9 : bad24 9 = [] := rfl
set_option maxRecDepth 200000 in
theorem s11 : bad24 11 = [] := rfl
set_option maxRecDepth 200000 in
theorem s13 : bad24 13 = [] := rfl

end Split24

#print axioms Split24.s3
#print axioms Split24.s5
#print axioms Split24.s7
#print axioms Split24.s9
#print axioms Split24.s11
#print axioms Split24.s13

#print axioms: 6 theorems, no axioms.

81.125 Prime degrees: every fourfold character is three pairs

For \(p=5,7,11,13\) every balanced length-6 character is a union of three complementary pairs (rfl); count \(\binom {(p+3)/2}{3}\) for all primes \(p\le 47\) (computation). The pair classes are algebraic (linear subvarieties); \(p=17,19\) on Kamiak.

hodge/Pairs6Small.lean

/-
  hodge/Pairs6Small.lean — T41 cycle 818 (goal G529): for the primes p = 5, 7, 11, 13 every balanced length-6
  character of the degree-p Fermat fourfold is a union of three complementary pairs (rfl; p = 17, 19 in
  hodge/Pairs6 on Kamiak). Computation: count C((p+3)/2, 3) for every prime p ≤ 47.

  Lean 4 core plus hodge/Len6Decomp (sexts), rfl.
-/
import hodge.Len6Decomp

namespace Pairs6Small
open Indecomp Len6Decomp

def allPairs (m : Nat) : Nat → List Nat → Bool
  | 0, _ => false
  | _, [] => true
  | f + 1, x :: l => l.contains (m - x) && allPairs m f (l.erase (m - x))

def badP (m : Nat) : List (List Nat) := (sexts m).filter (fun c => bal m c && !allPairs m 7 c)

set_option maxRecDepth 200000 in
theorem q5 : badP 5 = [] := rfl
set_option maxRecDepth 200000 in
theorem q7 : badP 7 = [] := rfl
set_option maxRecDepth 200000 in
theorem q11 : badP 11 = [] := rfl
set_option maxRecDepth 200000 in
theorem q13 : badP 13 = [] := rfl

end Pairs6Small

#print axioms Pairs6Small.q5
#print axioms Pairs6Small.q7
#print axioms Pairs6Small.q11
#print axioms Pairs6Small.q13

#print axioms: 4 theorems, no axioms.

81.126 Prime degrees: every surface character is two pairs

For \(p\le 19\) prime every balanced length-4 character is a union of two complementary pairs (rfl). The general prime case needs \(B_{1,\chi }\ne 0\) for odd \(\chi \) (open in Lean).

hodge/Pairs4.lean

/-
  hodge/Pairs4.lean — T41 cycle 821 (goal G532): for the primes p ≤ 19 every balanced length-4 character of the
  degree-p Fermat surface is a union of two complementary pairs (rfl). The general statement for every prime
  (G529b, and its length-6 form) is equivalent to the symmetry of multisets with constant fractional-part sums over
  all units, whose standard proof uses L(1, χ) ≠ 0 for the odd characters χ mod p — recorded in OPEN_LEMMAS_HODGE.

  Lean 4 core plus hodge/Len4Class (quads), hodge/Pairs6Small (allPairs), rfl.
-/
import hodge.Len4Class
import hodge.Pairs6Small

namespace Pairs4
open Indecomp Len4Class Pairs6Small

def badQ (m : Nat) : List (List Nat) := (quads m).filter (fun c => bal m c && !allPairs m 5 c)

set_option maxRecDepth 200000 in
theorem r5 : badQ 5 = [] := rfl
set_option maxRecDepth 200000 in
theorem r7 : badQ 7 = [] := rfl
set_option maxRecDepth 200000 in
theorem r11 : badQ 11 = [] := rfl
set_option maxRecDepth 200000 in
theorem r13 : badQ 13 = [] := rfl
set_option maxRecDepth 200000 in
theorem r17 : badQ 17 = [] := rfl
set_option maxRecDepth 200000 in
theorem r19 : badQ 19 = [] := rfl

end Pairs4

#print axioms Pairs4.r5
#print axioms Pairs4.r7
#print axioms Pairs4.r11
#print axioms Pairs4.r13
#print axioms Pairs4.r17
#print axioms Pairs4.r19

#print axioms: 6 theorems, no axioms.

81.127 Unions of complementary pairs are balanced

Soundness of the pair test, every \(m\): \(\mathrm {allPairs}\,c\Rightarrow \mathrm {bal}\,c\); with the rfl lists, balanced \(\Leftrightarrow \) union of pairs at the listed primes. Own erase/contains lemmas (the core ones use propext).

hodge/PairsSound.lean

/-
  hodge/PairsSound.lean — T41 cycle 824 (goal G535): soundness of the pair test. If allPairs m f c = true (c is a
  union of complementary pairs {x, m − x}, 0 < x < m), then c is balanced, every m. With Pairs6Small / Pairs4 this
  makes those rfl lists full classifications (balanced ⇔ union of pairs) at the listed primes.

  Lean 4 core plus hodge/Pairs6Small (allPairs), hodge/PairBal (pair_bal), hodge/BalAppend, hodge/QFamHalf
  (bal_congr). Own erase/contains reasoning (core List.perm_cons_erase and contains_iff_mem use propext).
    erase_tsum    y ∈ l (contains) ⇒ T_t(l) = ⟨ty⟩ + T_t(l.erase y), |l| = |l.erase y| + 1
    pairs_sound   the statement
-/
import hodge.Pairs6Small
import hodge.QFamHalf

namespace PairsSound
open Indecomp HalfGeneral BalAppend PairBal QFamHalf Pairs6Small GcdHand

theorem beq_nat (x y : Nat) : (x == y) = Nat.beq x y := rfl

theorem erase_tsum (m t y : Nat) : ∀ l : List Nat, l.contains y = true →
    tsum m t l = (t * y) % m + tsum m t (l.erase y) ∧ l.length = (l.erase y).length + 1
  | [], h => Bool.noConfusion h
  | x :: l, h => by
    cases e : Nat.beq x y with
    | true =>
      have xy : x = y := Nat.eq_of_beq_eq_true e
      have er : (x :: l).erase y = l := by
        show (match x == y with | true => l | false => x :: l.erase y) = l
        rw [beq_nat, e]
      rw [er, xy]; exact ⟨rfl, rfl⟩
    | false =>
      have er : (x :: l).erase y = x :: l.erase y := by
        show (match x == y with | true => l | false => x :: l.erase y) = x :: l.erase y
        rw [beq_nat, e]
      have hc : l.contains y = true := by
        have eyx : Nat.beq y x = false := by
          cases q : Nat.beq y x with
          | false => rfl
          | true => rw [Nat.eq_of_beq_eq_true q, HalfGeneral.beq_self] at e; exact Bool.noConfusion e
        have h' : (match y == x with | true => true | false => List.elem y l) = true := h
        rw [beq_nat, eyx] at h'; exact h'
      have ih := erase_tsum m t y l hc
      rw [er]
      refine ⟨?_, ?_⟩
      · show (t * x) % m + tsum m t l = (t * y) % m + ((t * x) % m + tsum m t (l.erase y))
        rw [ih.1]; lib_nat
      · show l.length + 1 = (l.erase y).length + 1 + 1
        rw [ih.2]

theorem pairs_sound (m' : Nat) : ∀ (f : Nat) (c : List Nat), (∀ x, x ∈ c → 0 < x ∧ x < m' + 1) →
    allPairs (m' + 1) f c = true → bal (m' + 1) c = true
  | 0, _, _, h => Bool.noConfusion h
  | _ + 1, [], _, _ => PairBal.bal_nil _
  | f + 1, x :: l, hr, h => by
    have h' : (l.contains (m' + 1 - x) && allPairs (m' + 1) f (l.erase (m' + 1 - x))) = true := h
    cases e : l.contains (m' + 1 - x) with
    | false => rw [e] at h'; exact Bool.noConfusion h'
    | true =>
      rw [e] at h'
      have hx := hr x (List.Mem.head _)
      have hs : x + (m' + 1 - x) = m' + 1 := by rw [Nat.add_comm]; exact sub_add' _ _ (Nat.le_of_lt hx.2)
      have hy0 : 0 < m' + 1 - x := by
        cases hc : m' + 1 - x with
        | zero => rw [hc, Nat.add_zero] at hs; rw [hs] at hx; exact absurd hx.2 (Nat.lt_irrefl _)
        | succ c => exact Nat.succ_pos c
      have P := pair_bal m' x (m' + 1 - x) hs hx.1 hy0
      -- the rest is balanced by induction; members of l.erase are members of l
      have mem_er : ∀ z, z ∈ l.erase (m' + 1 - x) → z ∈ l := fun z hz => mem_erase' z l hz
      have R := pairs_sound m' f (l.erase (m' + 1 - x)) (fun z hz => hr z (List.Mem.tail _ (mem_er z hz))) h'
      have big := bal_append _ _ _ P R
      have es := erase_tsum (m' + 1) 0 (m' + 1 - x) l e
      apply bal_congr _ _ _ _ _ big
      · intro t
        have es := erase_tsum (m' + 1) t (m' + 1 - x) l e
        show tsum (m' + 1) t ([x, m' + 1 - x] ++ l.erase (m' + 1 - x)) = (t * x) % (m' + 1) + tsum (m' + 1) t l
        rw [tsum_app, es.1]
        show (t * x) % (m' + 1) + ((t * (m' + 1 - x)) % (m' + 1) + 0) + tsum (m' + 1) t (l.erase (m' + 1 - x))
          = (t * x) % (m' + 1) + ((t * (m' + 1 - x)) % (m' + 1) + tsum (m' + 1) t (l.erase (m' + 1 - x)))
        lib_nat
      · show ([x, m' + 1 - x] ++ l.erase (m' + 1 - x)).length = l.length + 1
        rw [len_app, es.2]; show 2 + (l.erase (m' + 1 - x)).length = (l.erase (m' + 1 - x)).length + 1 + 1
        lib_nat
where
  mem_erase' (z : Nat) : ∀ (l : List Nat) {y : Nat}, z ∈ l.erase y → z ∈ l
    | [], _, h => by cases h
    | a :: l, y, h => by
      cases e : Nat.beq a y with
      | true =>
        have er : (a :: l).erase y = l := by
          show (match a == y with | true => l | false => a :: l.erase y) = l
          rw [beq_nat, e]
        rw [er] at h; exact List.Mem.tail _ h
      | false =>
        have er : (a :: l).erase y = a :: l.erase y := by
          show (match a == y with | true => l | false => a :: l.erase y) = a :: l.erase y
          rw [beq_nat, e]
        rw [er] at h
        cases h with
        | head => exact List.Mem.head _
        | tail _ h2 => exact List.Mem.tail _ (mem_erase' z l h2)

end PairsSound

#print axioms PairsSound.erase_tsum
#print axioms PairsSound.pairs_sound

#print axioms: 2 theorems, no axioms.

81.128 Surface characters outside the families

For \(m\le 30\), 156 of the 180 indecomposable length-4 characters outside QFam/QFamHalf are glued from two balanced triples; the rest occur at odd \(m\). Examples at \(m=12,18,20\) by Glue with rfl leaves.

hodge/Glue4.lean

/-
  hodge/Glue4.lean — T41 cycle 828 (goal G538): length-4 indecomposable characters outside the QFam / QFamHalf
  families. Computation (m ≤ 30): 180 such characters, 156 of them glued (Glue) from two balanced length-3
  characters along {z, m − z}; the other 24 occur at odd m (no balanced odd-length pieces there). Here: the four
  at m = 12 and examples at m = 18, 20, glued with rfl leaves. (Surface classes: algebraic by Lefschetz (1,1).)

  Lean 4 core plus hodge/Glue, rfl.
-/
import hodge.Glue

namespace Glue4
open Indecomp Glue

set_option maxRecDepth 100000 in
theorem g4_12_0 : bal 12 ([1, 9] ++ [4, 10]) = true :=
  glue 11 8 [1, 9] [4, 10] (Nat.succ_pos 7) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 8) (Nat.le_of_ble_eq_true rfl)) rfl rfl
set_option maxRecDepth 100000 in
theorem g4_12_1 : bal 12 ([2, 8] ++ [3, 11]) = true :=
  glue 11 8 [2, 8] [3, 11] (Nat.succ_pos 7) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 8) (Nat.le_of_ble_eq_true rfl)) rfl rfl
set_option maxRecDepth 100000 in
theorem g4_12_2 : bal 12 ([2, 5] ++ [8, 9]) = true :=
  glue 11 11 [2, 5] [8, 9] (Nat.succ_pos 10) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 11) (Nat.le_of_ble_eq_true rfl)) rfl rfl
set_option maxRecDepth 100000 in
theorem g4_12_3 : bal 12 ([3, 4] ++ [7, 10]) = true :=
  glue 11 11 [3, 4] [7, 10] (Nat.succ_pos 10) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 11) (Nat.le_of_ble_eq_true rfl)) rfl rfl
set_option maxRecDepth 100000 in
theorem g4_18_4 : bal 18 ([1, 14] ++ [6, 15]) = true :=
  glue 17 12 [1, 14] [6, 15] (Nat.succ_pos 11) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 12) (Nat.le_of_ble_eq_true rfl)) rfl rfl
set_option maxRecDepth 100000 in
theorem g4_20_5 : bal 20 ([1, 17] ++ [4, 18]) = true :=
  glue 19 12 [1, 17] [4, 18] (Nat.succ_pos 11) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 12) (Nat.le_of_ble_eq_true rfl)) rfl rfl

end Glue4

#print axioms Glue4.g4_12_0
#print axioms Glue4.g4_12_1
#print axioms Glue4.g4_12_2
#print axioms Glue4.g4_12_3
#print axioms Glue4.g4_18_4
#print axioms Glue4.g4_20_5

#print axioms: 6 theorems, no axioms.

81.129 The first unexplained fourfold characters

Beyond the proved rules, the first indecomposable fourfold characters appear at \(m=20\) (1 orbit), \(21\) (2), \(24\) (6); none for \(m\le 19\) or \(m=22\). Representatives balanced and indecomposable by rfl.

hodge/Open20.lean

/-
  hodge/Open20.lean — T41 cycle 831 (goal G541): the first fourfold characters not explained by the proved rules
  (pairs, m/2, QFam / QFamHalf up to twist, gluing, scaling, splits; add-and-subtract with |T| ≤ 3). Computation:
  none for m ≤ 19 and m = 22; one unit-orbit at m = 20, two at m = 21, six at m = 24. Representatives: balanced
  and indecomposable by rfl. (Candidates for Aoki-type exceptional classes; their algebraicity is open here.)

  Lean 4 core plus hodge/Indecomp (bal, indec), rfl.
-/
import hodge.Indecomp

namespace Open20
open Indecomp

set_option maxRecDepth 100000 in
theorem o20_0 : bal 20 [1, 1, 6, 17, 17, 18] = true ∧ indec 20 [1, 1, 6, 17, 17, 18] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem o21_1 : bal 21 [1, 4, 9, 15, 16, 18] = true ∧ indec 21 [1, 4, 9, 15, 16, 18] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem o21_2 : bal 21 [1, 4, 10, 13, 16, 19] = true ∧ indec 21 [1, 4, 10, 13, 16, 19] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem o24_3 : bal 24 [1, 1, 10, 19, 19, 22] = true ∧ indec 24 [1, 1, 10, 19, 19, 22] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem o24_4 : bal 24 [1, 1, 13, 18, 19, 20] = true ∧ indec 24 [1, 1, 13, 18, 19, 20] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem o24_5 : bal 24 [1, 1, 14, 17, 17, 22] = true ∧ indec 24 [1, 1, 14, 17, 17, 22] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem o24_6 : bal 24 [1, 1, 14, 17, 19, 20] = true ∧ indec 24 [1, 1, 14, 17, 19, 20] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem o24_7 : bal 24 [1, 4, 6, 17, 22, 22] = true ∧ indec 24 [1, 4, 6, 17, 22, 22] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem o24_8 : bal 24 [1, 8, 9, 13, 20, 21] = true ∧ indec 24 [1, 8, 9, 13, 20, 21] = true := ⟨rfl, rfl⟩

end Open20

#print axioms Open20.o20_0
#print axioms Open20.o21_1
#print axioms Open20.o21_2
#print axioms Open20.o24_3
#print axioms Open20.o24_4
#print axioms Open20.o24_5
#print axioms Open20.o24_6
#print axioms Open20.o24_7
#print axioms Open20.o24_8

#print axioms: 9 theorems, no axioms.

81.130 An \(m=21\) orbit is a family minus a pair

\([7,14]\sqcup [1,4,10,13,16,19]=\mathrm {QFam}(7,3,1)\): balance by cancellation. The \(m=20\) orbit, the other \(m=21\) orbit and the six \(m=24\) orbits have no such relation.

hodge/Open21.lean

/-
  hodge/Open21.lean — T41 cycle 834 (goal G544 = G541b, partial): the m = 21 orbit [1, 4, 10, 13, 16, 19] of Open20
  is QFam(q = 7, k = 3, a = 1) = [1, 4, 7, 10, 13, 16, 19] ⊔ [14] with the complementary pair {7, 14} removed:
    [7, 14] ⊔ [1, 4, 10, 13, 16, 19]  =  QFam(7, 3, 1)       (as multisets),
  so its balance follows by cancellation from qfam_bal. (A character relation; [7, 14] is a pair class.)
  The m = 20 orbit, the other m = 21 orbit and the six m = 24 orbits have no relation of this kind (computation).

  Lean 4 core plus hodge/QFam (qfam_bal), hodge/QFamHalf (bal_congr), hodge/PairBal, hodge/BalAppend.
-/
import hodge.QFamHalf

namespace Open21
open Indecomp HalfGeneral BalAppend PairBal PermSum QFam QFamHalf

theorem q21 : bal (7 * 3) (gl (fun i => 1 + i * 3) 7 ++ [7 * 3 - 7 * 1]) = true :=
  qfam_bal 7 3 1 (Nat.succ_pos 6) (Nat.succ_pos 0) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 1) (Nat.le_of_ble_eq_true rfl))

theorem p21 : bal 21 [7, 14] = true := pair_bal 20 7 14 rfl (Nat.succ_pos 6) (Nat.succ_pos 13)

theorem o21 : bal 21 [1, 4, 10, 13, 16, 19] = true := by
  apply bal_cancel _ [7, 14] _ p21
  apply bal_congr _ _ _ _ _ q21
  · intro t
    show tsum 21 t ([19, 16, 13, 10, 7, 4, 1] ++ [14]) = tsum 21 t ([7, 14] ++ [1, 4, 10, 13, 16, 19])
    rw [tsum_app, tsum_app]
    show (t * 19) % 21 + ((t * 16) % 21 + ((t * 13) % 21 + ((t * 10) % 21 + ((t * 7) % 21 + ((t * 4) % 21
        + ((t * 1) % 21 + 0)))))) + ((t * 14) % 21 + 0)
      = (t * 7) % 21 + ((t * 14) % 21 + 0)
        + ((t * 1) % 21 + ((t * 4) % 21 + ((t * 10) % 21 + ((t * 13) % 21 + ((t * 16) % 21 + ((t * 19) % 21 + 0))))))
    lib_nat
  · rfl

end Open21

#print axioms Open21.q21
#print axioms Open21.p21
#print axioms Open21.o21

#print axioms: 3 theorems, no axioms.

81.131 An invariant of the \(\mu _q\) families; the residual seeds

Twisted orbits keep \(q\) entries in one class mod \(k\): \(((t(a+ik))\bmod qk)\bmod k=(ta)\bmod k\). The residual seeds \([1,16,25,38,40]_{48}\), \([2,10,50,54,64]_{72}\) have at most 2 entries per class (rfl): not family twists.

hodge/FamInvariant.lean

/-
  hodge/FamInvariant.lean — T41 cycle 837 (goal G547): an invariant of the μ_q-orbit families. For m = q·k and any
  t (no unit condition needed), every entry of the twisted orbit t·[a + ik (i < q)] reduces mod k to (t·a) mod k:
    ((t·(a + ik)) mod qk) mod k = (t·a) mod k.
  So every unit twist of QFam(q, k, a) / QFamHalf(q, k, a) has q entries in one residue class mod k. The residual
  seeds [1, 16, 25, 38, 40] (m = 48) and [2, 10, 50, 54, 64] (m = 72) have at most 2 entries in any class mod 12, 16
  (resp. 18, 24) (rfl), hence are not twists of the length-5 family members (q = 4 / q = 3 at these m).
  (a2_seed: no add-and-subtract relation with |T| ≤ 6 at m = 48, |T| ≤ 5 at m = 72.)

  Lean 4 core plus hodge/ModHand (add_mul_mod'), hodge/GcdHand (div_mod), lib/Semi.
    mod_mod_dvd   (x mod qk) mod k = x mod k
    orbit_class   the invariant
-/
import hodge.GcdHand

namespace FamInvariant
open GcdHand ModHand

theorem mod_mod_dvd (q k x : Nat) (hq : 0 < q) (hk : 0 < k) : (x % (q * k)) % k = x % k := by
  have ⟨p, hp⟩ := div_mod (q * k) (Nat.mul_pos hq hk) (x + 1) x (Nat.lt_succ_self x)
  have e : x = x % (q * k) + (p * q) * k := by
    have t : x % (q * k) + q * k * p = x % (q * k) + (p * q) * k := by lib_nat
    exact hp.trans t
  conv => rhs; rw [e]
  rw [add_mul_mod' _ _ hk]

theorem orbit_class (q k a t i : Nat) (hq : 0 < q) (hk : 0 < k) :
    ((t * (a + i * k)) % (q * k)) % k = (t * a) % k := by
  rw [mod_mod_dvd q k _ hq hk, show t * (a + i * k) = t * a + (t * i) * k by lib_nat, add_mul_mod' _ _ hk]

def classCount (k r : Nat) : List Nat → Nat
  | [] => 0
  | x :: l => (if Nat.beq (x % k) r then 1 else 0) + classCount k r l

def maxClass (k : Nat) (l : List Nat) : Nat := ((List.range k).map (fun r => classCount k r l)).foldl Nat.max 0

theorem seed48_12 : maxClass 12 [1, 16, 25, 38, 40] = 2 := rfl
theorem seed48_16 : maxClass 16 [1, 16, 25, 38, 40] = 1 := rfl
theorem seed72_18 : maxClass 18 [2, 10, 50, 54, 64] = 2 := rfl
theorem seed72_24 : maxClass 24 [2, 10, 50, 54, 64] = 2 := rfl

end FamInvariant

#print axioms FamInvariant.mod_mod_dvd
#print axioms FamInvariant.orbit_class
#print axioms FamInvariant.seed48_12
#print axioms FamInvariant.seed48_16
#print axioms FamInvariant.seed72_18
#print axioms FamInvariant.seed72_24

#print axioms: 6 theorems, no axioms.

81.132 The \(m=20\) open orbit is not a family twist

At most 4 entries per class mod 4 and 3 per class mod 5, while twisted QFam\((5,4)\), QFamHalf\((4,5)\) need 5 and 4. rfl with the family invariant.

hodge/Open20Inv.lean

/-
  hodge/Open20Inv.lean — T41 cycle 840 (goal G550): the m = 20 open orbit [1, 1, 6, 17, 17, 18] (Open20) is not a
  unit twist of a length-6 family member: the length-6 members at m = 20 are QFam(q = 5, k = 4) (5 entries in one
  class mod 4 after any twist, FamInvariant.orbit_class) and QFamHalf(q = 4, k = 5) (4 entries in one class mod 5),
  while the orbit has at most 4 entries per class mod 4 and at most 3 per class mod 5 (rfl). (Kamiak a2_seed also
  found no add-and-subtract relation for the residual m = 48, 72 seeds up to |T| = 6.)

  Lean 4 core plus hodge/FamInvariant (maxClass), rfl.
-/
import hodge.FamInvariant

namespace Open20Inv
open FamInvariant

theorem cls4 : maxClass 4 [1, 1, 6, 17, 17, 18] = 4 := rfl
theorem cls5 : maxClass 5 [1, 1, 6, 17, 17, 18] = 3 := rfl

end Open20Inv

#print axioms Open20Inv.cls4
#print axioms Open20Inv.cls5

#print axioms: 2 theorems, no axioms.

81.133 Surface characters at \(p=23,29\)

Every balanced length-4 character of the degree-\(p\) Fermat surface is two complementary pairs, \(p=23,29\) (rfl, 25 s).

hodge/Pairs4b.lean

/-
  hodge/Pairs4b.lean — T41 cycle 843 (goal G553): Pairs4 extended to the primes p = 23, 29: every balanced
  length-4 character of the degree-p Fermat surface is a union of two complementary pairs (rfl, no heartbeat limit).

  Lean 4 core plus hodge/Pairs4 (badQ), rfl.
-/
import hodge.Pairs4

namespace Pairs4b
open Pairs4

set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem r23 : badQ 23 = [] := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem r29 : badQ 29 = [] := rfl

end Pairs4b

#print axioms Pairs4b.r23
#print axioms Pairs4b.r29

#print axioms: 2 theorems, no axioms.

81.134 The \(\mu _3\) family is indecomposable for odd \(k\)

For odd \(k\) and \(0<a<k\), \([a,a+k,a+2k,3k-3a]\) is indecomposable: \(m=3k\) odd, and no two entries sum to \(m\). By Indec4, every \(m=3k\) with \(k\) odd.

hodge/ThirdIndec.lean

/-
  hodge/ThirdIndec.lean — T41 cycle 847 (goal G557): for odd k and 0 < a < k the ThirdFam character
  [a, a + k, a + 2k, 3k − 3a] (balanced, ThirdFam) is indecomposable, by Indec4: m = 3k is odd, so no entry is m/2,
  and no two entries sum to m (each pair sum equals m only if a = 0, a = k or 2a = k).

  Lean 4 core plus hodge/Indec4 (indec4), hodge/ThirdFam, hodge/PairIff (dbl_inj), bsd/TorsionImage (odd_ne_even),
  hodge/BalAppend (add_cancel), lib/Semi.
-/
import hodge.Indec4
import hodge.ThirdFam

namespace ThirdIndec
open Indecomp Indec4 TorsionImage BalAppend GcdHand PairIff

theorem canc (c x y : Nat) (h : x + c = y + c) : x = y := add_cancel c x y (by rw [Nat.add_comm c x, Nat.add_comm c y]; exact h)

theorem third_indec (n j a : Nat) (hm : n + 2 = (2 * j + 1) + (2 * j + 1) + (2 * j + 1)) (ha0 : 0 < a)
    (hak : a < 2 * j + 1) :
    indec (n + 2) [a, a + (2 * j + 1), a + (2 * j + 1) + (2 * j + 1),
      ((2 * j + 1) + (2 * j + 1) + (2 * j + 1)) - (a + a + a)] = true := by
  generalize hk : 2 * j + 1 = k at hm hak
  have h3a : a + a + a ≤ k + k + k := Nat.add_le_add (Nat.add_le_add (Nat.le_of_lt hak) (Nat.le_of_lt hak)) (Nat.le_of_lt hak)
  generalize hz : (k + k + k) - (a + a + a) = z
  have hza : z + (a + a + a) = k + k + k := by rw [← hz]; exact sub_add' _ _ h3a
  have odd_m : ∀ v, v + v ≠ n + 2 := by
    intro v e
    rw [hm, ← hk] at e
    exact odd_ne_even (3 * j + 1) v (by rw [show 2 * (3 * j + 1) + 1 = 2 * j + 1 + (2 * j + 1) + (2 * j + 1) by lib_nat, ← e]; lib_nat)
  have k_odd : ∀ v, v + v ≠ k := by
    intro v e; rw [← hk] at e; exact odd_ne_even j v (by rw [← e]; lib_nat)
  have a_ne_k : a ≠ k := Nat.ne_of_lt hak
  have a_ne_0 : a ≠ 0 := Nat.ne_of_gt ha0
  have hz0 : 0 < z := by
    cases z with
    | zero => rw [Nat.zero_add] at hza; exact absurd hza (Nat.ne_of_lt (Nat.add_lt_add (Nat.add_lt_add hak hak) hak))
    | succ z => exact Nat.succ_pos z
  have lt_m : ∀ v, v < k → v < n + 2 := fun v hv => by
    rw [hm]; exact Nat.lt_of_lt_of_le hv (Nat.le_trans (Nat.le_add_right k k) (Nat.le_add_right _ k))
  apply indec4 n
  · exact ha0
  · exact Nat.lt_of_lt_of_le ha0 (Nat.le_add_right a _)
  · exact Nat.lt_of_lt_of_le ha0 (Nat.le_trans (Nat.le_add_right a _) (Nat.le_add_right _ _))
  · exact hz0
  · exact lt_m a hak
  · rw [hm]; exact Nat.add_lt_add_right (Nat.lt_of_lt_of_le hak (Nat.le_add_right k k)) k
  · rw [hm]; exact Nat.add_lt_add_right (Nat.add_lt_add_right hak k) k
  · rw [hm, ← hza]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le ha0 (Nat.le_add_left a (a + a)))
  · exact odd_m a
  · exact odd_m _
  · exact odd_m _
  · exact odd_m z
  · -- w + x: a + (a + k) = 3k ⇒ a = k
    intro e; rw [hm] at e
    have t : a + a + k = k + k + k := by rw [show a + a + k = a + (a + k) by lib_nat]; exact e
    exact a_ne_k (dbl_inj a k (canc k _ _ t))
  · -- w + y: a + (a + k + k) = 3k ⇒ a + a = k
    intro e; rw [hm] at e
    have t : a + a + (k + k) = k + (k + k) := by rw [show a + a + (k + k) = a + (a + k + k) by lib_nat, e]; lib_nat
    exact k_odd a (canc (k + k) _ _ t)
  · -- w + z: a + z = 3k = z + 3a ⇒ a + a = 0
    intro e; rw [hm] at e
    have t1 : a + z = z + (a + a + a) := e.trans hza.symm
    have t2 : 0 + a = (a + a) + a := canc z _ _ (by rw [show 0 + a + z = a + z by lib_nat, t1]; lib_nat)
    have : a + a = 0 := (canc a _ _ t2).symm
    exact a_ne_0 (Nat.eq_zero_of_add_eq_zero_left this)
  · -- x + y: (a + k) + (a + k + k) = 3k ⇒ a + a = 0
    intro e; rw [hm] at e
    have t : a + a + (k + k + k) = 0 + (k + k + k) := by
      rw [show a + a + (k + k + k) = a + k + (a + k + k) by lib_nat, e]; lib_nat
    have : a + a = 0 := canc (k + k + k) _ _ t
    exact a_ne_0 (Nat.eq_zero_of_add_eq_zero_left this)
  · -- x + z: (a + k) + z = z + 3a ⇒ k = a + a
    intro e; rw [hm] at e
    have t : k + (a + z) = (a + a) + (a + z) := by
      rw [show k + (a + z) = a + k + z by lib_nat, e, ← hza]; lib_nat
    exact k_odd a (canc (a + z) _ _ t).symm
  · -- y + z: (a + k + k) + z = z + 3a ⇒ k = a
    intro e; rw [hm] at e
    have t : k + k + (a + z) = (a + a) + (a + z) := by
      rw [show k + k + (a + z) = a + k + k + z by lib_nat, e, ← hza]; lib_nat
    exact a_ne_k (dbl_inj k a (canc (a + z) _ _ t)).symm

end ThirdIndec

#print axioms ThirdIndec.canc
#print axioms ThirdIndec.third_indec

#print axioms: 2 theorems, no axioms.

81.135 Prime degrees 17, 19: fourfold characters are three pairs (Kamiak)

Every balanced length-6 character of the degree-\(p\) Fermat fourfold is a union of three complementary pairs, \(p=17,19\) (rfl, 579 s on Kamiak).

hodge/Pairs6.lean

/-
  hodge/Pairs6.lean — T41 goal G529 (Kamiak): for the primes p = 17, 19 every balanced length-6 character of the
  Fermat fourfold of degree p is a union of three complementary pairs {x, p − x} (so its count is C((p+3)/2, 3) —
  computation: the same count holds for every prime p ≤ 47). By rfl.

  Lean 4 core plus hodge/Len6Decomp (sexts), hodge/Indecomp (bal), rfl.
-/
import hodge.Len6Decomp

namespace Pairs6
open Indecomp Len6Decomp

def allPairs (m : Nat) : Nat → List Nat → Bool
  | 0, _ => false
  | _, [] => true
  | f + 1, x :: l => l.contains (m - x) && allPairs m f (l.erase (m - x))

def badP (m : Nat) : List (List Nat) := (sexts m).filter (fun c => bal m c && !allPairs m 7 c)

set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem p17 : badP 17 = [] := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem p19 : badP 19 = [] := rfl

end Pairs6

#print axioms Pairs6.p17
#print axioms Pairs6.p19

#print axioms: 2 theorems, no axioms.

81.136 Surface characters at \(p=31\)

Every balanced length-4 character of the degree-31 Fermat surface is two complementary pairs (rfl, 27 s).

hodge/Pairs4c.lean

/-
  hodge/Pairs4c.lean — T41 cycle 999 (goal G529b, finite path): Pairs4 extended to the prime p = 31: every balanced
  length-4 character of the degree-31 Fermat surface is a union of two complementary pairs (rfl, no heartbeat limit).
  With Pairs4 / Pairs4b: length 4 settled for all odd primes p ≤ 31.

  Lean 4 core plus hodge/Pairs4 (badQ), rfl.
-/
import hodge.Pairs4

namespace Pairs4c
open Pairs4

set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem r31 : badQ 31 = [] := rfl

end Pairs4c

#print axioms Pairs4c.r31

#print axioms: 1 theorem, no axioms.

81.137 The \(q=2\) half-twisted family is indecomposable

For \(m=2k\), \(0<a\), \(2a<k\): \([a,a+k,k+2a,2k-4a]\) is indecomposable exactly when \(3a\ne k\) and \(4a\ne k\) (proved direction; computation: \(k<40\), both). By Indec4.

hodge/HalfIndec.lean

/-
  hodge/HalfIndec.lean — T41 cycle 857 (goal G566): the q = 2 member of the QFamHalf family for m = 2k,
  [a, a + k, k + 2a, 2k − 4a] (0 < a, 2a < k; balanced by QFamHalf), is indecomposable whenever 3a ≠ k and 4a ≠ k
  (computation: those are exactly the decomposable cases). By Indec4.

  Lean 4 core plus hodge/Indec4, hodge/ThirdIndec (canc), hodge/PairIff (dbl_inj), lib/Semi.
-/
import hodge.Indec4
import hodge.ThirdIndec

namespace HalfIndec
open Indecomp Indec4 BalAppend GcdHand PairIff ThirdIndec

theorem zero_of_sum (a s : Nat) (h : s + a = 0) : a = 0 := by
  cases a with
  | zero => rfl
  | succ a => exact Nat.noConfusion h

theorem half_indec (n k a : Nat) (hm : n + 2 = k + k) (ha0 : 0 < a) (h2 : a + a < k)
    (h3 : a + a + a ≠ k) (h4 : a + a + a + a ≠ k) :
    indec (n + 2) [a, a + k, k + (a + a), (k + k) - (a + a + a + a)] = true := by
  have h4le : a + a + a + a ≤ k + k := by
    have := Nat.add_le_add (Nat.le_of_lt h2) (Nat.le_of_lt h2)
    rw [show a + a + a + a = (a + a) + (a + a) by lib_nat]; exact this
  generalize hz : (k + k) - (a + a + a + a) = z
  have hza : z + (a + a + a + a) = k + k := by rw [← hz]; exact sub_add' _ _ h4le
  have ha_ne : a ≠ 0 := Nat.ne_of_gt ha0
  have hz0 : 0 < z := by
    cases z with
    | zero =>
      rw [Nat.zero_add] at hza
      exact absurd hza (Nat.ne_of_lt (by rw [show a + a + a + a = (a + a) + (a + a) by lib_nat]; exact Nat.add_lt_add h2 h2))
    | succ z => exact Nat.succ_pos z
  have hk : 0 < k := Nat.lt_of_le_of_lt (Nat.zero_le _) h2
  have lt_m : ∀ v, v < k → v < n + 2 := fun v hv => by rw [hm]; exact Nat.lt_of_lt_of_le hv (Nat.le_add_right k k)
  apply indec4 n
  · exact ha0
  · exact Nat.lt_of_lt_of_le ha0 (Nat.le_add_right a k)
  · exact Nat.lt_of_lt_of_le hk (Nat.le_add_right k _)
  · exact hz0
  · exact lt_m a (Nat.lt_of_le_of_lt (Nat.le_add_right a a) h2)
  · rw [hm, Nat.add_comm a k]; exact Nat.add_lt_add_left (Nat.lt_of_le_of_lt (Nat.le_add_right a a) h2) k
  · rw [hm]; exact Nat.add_lt_add_left h2 k
  · rw [hm, ← hza]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le ha0 (Nat.le_add_left a _))
  -- singletons: v + v ≠ k + k
  · rw [hm]; intro e; exact Nat.ne_of_lt (Nat.lt_of_le_of_lt (Nat.le_add_right a a) h2) (dbl_inj a k e)
  · rw [hm]; intro e
    have t : (a + a) + (k + k) = 0 + (k + k) := by rw [show a + a + (k + k) = a + k + (a + k) by lib_nat, e]; lib_nat
    exact ha_ne (zero_of_sum a a (canc (k + k) _ _ t))
  · rw [hm]; intro e
    have t : (a + a + (a + a)) + (k + k) = 0 + (k + k) := by
      rw [show a + a + (a + a) + (k + k) = k + (a + a) + (k + (a + a)) by lib_nat, e]; lib_nat
    exact ha_ne (zero_of_sum a (a + a + a) (by rw [show a + a + a + a = a + a + (a + a) by lib_nat]; exact canc (k + k) _ _ t))
  · rw [hm]; intro e
    -- z + z = k + k and z + 4a = k + k ⇒ z = 4a ⇒ 4a + 4a = 2k ⇒ 4a = k
    have t : z + z = (a + a + a + a) + z := by rw [e, ← hza]; lib_nat
    have zz : z = a + a + a + a := canc z _ _ t
    rw [zz] at e
    exact h4 (dbl_inj _ _ e)
  -- pairs
  · rw [hm]; intro e
    exact Nat.ne_of_lt h2 (canc k _ _ (by rw [show a + a + k = a + (a + k) by lib_nat, e]))
  · rw [hm]; intro e
    exact h3 (canc k _ _ (by rw [show a + a + a + k = a + (k + (a + a)) by lib_nat, e]))
  · rw [hm]; intro e
    -- a + z = z + 4a ⇒ 0 = 3a
    have t1 : a + z = z + (a + a + a + a) := e.trans hza.symm
    have t2 : 0 + a = (a + a + a) + a := canc z _ _ (by rw [show 0 + a + z = a + z by lib_nat, t1]; lib_nat)
    exact ha_ne (zero_of_sum a (a + a) (canc a _ _ t2).symm)
  · rw [hm]; intro e
    have t : (a + a + a) + (k + k) = 0 + (k + k) := by rw [show a + a + a + (k + k) = a + k + (k + (a + a)) by lib_nat, e]; lib_nat
    exact ha_ne (zero_of_sum a (a + a) (canc (k + k) _ _ t))
  · rw [hm]; intro e
    -- (a + k) + z = z + 4a ⇒ k = 3a
    have t : k + (a + z) = (a + a + a) + (a + z) := by rw [show k + (a + z) = a + k + z by lib_nat, e, ← hza]; lib_nat
    exact h3 (canc (a + z) _ _ t).symm
  · rw [hm]; intro e
    -- (k + 2a) + z = z + 4a ⇒ k = 2a
    have t : k + (a + a + z) = (a + a) + (a + a + z) := by rw [show k + (a + a + z) = k + (a + a) + z by lib_nat, e, ← hza]; lib_nat
    exact Nat.ne_of_lt h2 (canc (a + a + z) _ _ t).symm

end HalfIndec

#print axioms HalfIndec.zero_of_sum
#print axioms HalfIndec.half_indec

#print axioms: 2 theorems, no axioms.

81.138 The \(q=2\) half-twisted family: the decomposable cases

\(k=3a\): \(\{a,5a\}\sqcup \{4a,2a\}\) (two pairs); \(k=4a\): \(\{4a\}\sqcup \{a,5a,6a\}\) (\(m/2\) and Triple). With HalfIndec: indecomposable \(\Leftrightarrow 3a\ne k\wedge 4a\ne k\).

hodge/HalfIndecIff.lean

/-
  hodge/HalfIndecIff.lean — T41 cycle 860 (goal G569): the converse of HalfIndec. For the q = 2 half-twisted
  character [a, a + k, k + 2a, 2k − 4a] at m = 2k:
    k = 3a  ⇒  it splits as {a, 5a} ⊔ {4a, 2a}  (two complementary pairs, m = 6a),
    k = 4a  ⇒  it splits as {4a} ⊔ {a, 5a, 6a}  (m/2 and Triple(a), m = 8a),
  so indec = false. With HalfIndec: indecomposable ⇔ 3a ≠ k ∧ 4a ≠ k (for 0 < a, 2a < k).

  Lean 4 core plus hodge/HalfIndec, hodge/Indec4 (indec4_eq), hodge/PairBal (pair_bal), hodge/GcdHand (half_bal_even),
  hodge/Triple (triple_bal), hodge/IndecTriple (and_false').
-/
import hodge.HalfIndec

namespace HalfIndecIff
open Indecomp Indec4 PairBal GcdHand IndecTriple

theorem false_and' (b : Bool) : (false && b) = false := rfl

theorem dec3 (m' a z : Nat) (hm : m' + 1 = (a + a + a) + (a + a + a)) (ha : 0 < a)
    (hz : z + (a + a + a + a) = (a + a + a) + (a + a + a)) :
    indec (m' + 1) [a, a + (a + a + a), (a + a + a) + (a + a), z] = false := by
  have hz0 : 0 < z := by
    cases z with
    | zero => rw [Nat.zero_add] at hz; exact absurd hz (Nat.ne_of_lt (by
        rw [show a + a + a + (a + a + a) = (a + a + a + a) + (a + a) by lib_nat]
        exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le ha (Nat.le_add_right a a))))
    | succ z => exact Nat.succ_pos z
  have p1 : bal (m' + 1) [a + (a + a + a), z] = true :=
    pair_bal m' _ _ (by rw [hm, ← hz]; lib_nat) (Nat.lt_of_lt_of_le ha (Nat.le_add_right a _)) hz0
  have p2 : bal (m' + 1) [a, (a + a + a) + (a + a)] = true :=
    pair_bal m' _ _ (by rw [hm]; lib_nat) ha (by
      have t := Nat.le_add_left a (a + a + a + a)
      rw [show a + a + a + a + a = a + a + a + (a + a) by lib_nat] at t
      exact Nat.lt_of_lt_of_le ha t)
  rw [indec4_eq, p1, p2, show (!(true && true)) = false from rfl, false_and']
  rw [and_false', and_false', and_false', and_false']
  rfl

theorem dec4 (h0 a z : Nat) (hh : h0 + 1 = a + a + a + a) (ha : 0 < a)
    (hz : z + (a + a + a + a) = (h0 + 1) + (h0 + 1)) :
    indec ((h0 + 1) + (h0 + 1)) [a, a + (a + a + a + a), (a + a + a + a) + (a + a), z] = false := by
  have zh : z = h0 + 1 := by
    have : z + (h0 + 1) = (h0 + 1) + (h0 + 1) := by rw [hh]; exact hz.trans (by rw [hh])
    exact ThirdIndec.canc (h0 + 1) _ _ this
  have s1 : bal ((h0 + 1) + (h0 + 1)) [z] = true := by rw [zh]; exact half_bal_even (h0 + 1) (Nat.succ_pos h0)
  have t1 : bal ((h0 + 1) + (h0 + 1)) [a, a + (a + a + a + a), (a + a + a + a) + (a + a)] = true := by
    have tb := Triple.triple_bal h0 a ha (by
      rw [hh]
      have t := Nat.le_add_right (a + a) (a + a)
      rw [show a + a + (a + a) = a + a + a + a by lib_nat] at t
      exact Nat.lt_of_lt_of_le (Nat.lt_add_of_pos_right ha) t)
    have e1 : h0 + 1 + a = a + (a + a + a + a) := by rw [hh]; lib_nat
    have e2 : h0 + 1 + (h0 + 1) - (a + a) = (a + a + a + a) + (a + a) := by
      rw [hh]
      have : a + a + a + a + (a + a + a + a) = (a + a + a + a + (a + a)) + (a + a) := by lib_nat
      rw [this, ModHand.add_sub']
    rw [e1, e2] at tb; exact tb
  rw [indec4_eq, s1, t1, show (!(true && true)) = false from rfl, false_and']
  rw [and_false', and_false', and_false', and_false', and_false', and_false', and_false']

end HalfIndecIff

#print axioms HalfIndecIff.false_and'
#print axioms HalfIndecIff.dec3
#print axioms HalfIndecIff.dec4

#print axioms: 3 theorems, no axioms.

81.139 Sporadic length-3 characters

For \(m\le 60\) every balanced \([x,y,z]\) is a twist of Triple, \(\{m/2\}\sqcup \)pair, or a scaling — except 16 unit orbits at \(m=12,14,18,20,24,30,42,60\). Representatives balanced and indecomposable (rfl).

hodge/Sporadic3.lean

/-
  hodge/Sporadic3.lean — T41 cycle 863 (goal G572): the sporadic balanced length-3 characters. Computation (m ≤ 60):
  every balanced [x, y, z] is a unit twist of Triple(a), or {m/2} ⊔ pair, or a scaling from a smaller m, except the
  unit orbits listed here, which occur only for m = 12, 14, 18, 20, 24, 30, 42, 60 (1, 1, 1, 1, 2, 4, 4, 2 orbits) —
  the exceptional degrees of Fermat curve characters (cf. Koblitz–Rohrlich, Aoki). Representatives balanced and
  indecomposable by rfl.

  Lean 4 core plus hodge/Indecomp (bal, indec), rfl.
-/
import hodge.Indecomp

namespace Sporadic3
open Indecomp

set_option maxRecDepth 100000 in
theorem s12_0 : bal 12 [1, 8, 9] = true ∧ indec 12 [1, 8, 9] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s14_1 : bal 14 [1, 9, 11] = true ∧ indec 14 [1, 9, 11] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s18_2 : bal 18 [1, 12, 14] = true ∧ indec 18 [1, 12, 14] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s20_3 : bal 20 [1, 12, 17] = true ∧ indec 20 [1, 12, 17] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s24_4 : bal 24 [1, 16, 19] = true ∧ indec 24 [1, 16, 19] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s24_5 : bal 24 [1, 17, 18] = true ∧ indec 24 [1, 17, 18] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s30_6 : bal 30 [1, 17, 27] = true ∧ indec 30 [1, 17, 27] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s30_7 : bal 30 [1, 19, 25] = true ∧ indec 30 [1, 19, 25] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s30_8 : bal 30 [1, 20, 24] = true ∧ indec 30 [1, 20, 24] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s30_9 : bal 30 [2, 21, 22] = true ∧ indec 30 [2, 21, 22] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s42_10 : bal 42 [1, 24, 38] = true ∧ indec 42 [1, 24, 38] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s42_11 : bal 42 [1, 25, 37] = true ∧ indec 42 [1, 25, 37] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s42_12 : bal 42 [1, 29, 33] = true ∧ indec 42 [1, 29, 33] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s42_13 : bal 42 [1, 30, 32] = true ∧ indec 42 [1, 30, 32] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s60_14 : bal 60 [1, 40, 49] = true ∧ indec 60 [1, 40, 49] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem s60_15 : bal 60 [1, 41, 48] = true ∧ indec 60 [1, 41, 48] = true := ⟨rfl, rfl⟩

end Sporadic3

#print axioms Sporadic3.s12_0
#print axioms Sporadic3.s14_1
#print axioms Sporadic3.s18_2
#print axioms Sporadic3.s20_3
#print axioms Sporadic3.s24_4
#print axioms Sporadic3.s24_5
#print axioms Sporadic3.s30_6
#print axioms Sporadic3.s30_7
#print axioms Sporadic3.s30_8
#print axioms Sporadic3.s30_9
#print axioms Sporadic3.s42_10
#print axioms Sporadic3.s42_11
#print axioms Sporadic3.s42_12
#print axioms Sporadic3.s42_13
#print axioms Sporadic3.s60_14
#print axioms Sporadic3.s60_15

#print axioms: 16 theorems, no axioms.

81.140 The Triple criterion

For \(m=2h\), \(0<a<h\): Triple\((a)\) is decomposable exactly when \(2a=h\), as \(\{h\}\sqcup \{a,h+a\}\); otherwise indecomposable (IndecTriple).

hodge/TripleIff.lean

/-
  hodge/TripleIff.lean — T41 cycle 866 (goal G575): the Triple criterion. For m = 2h and 0 < a < h, the character
  [a, h + a, 2h − 2a] is decomposable exactly when 2a = h: then 2h − 2a = h and the split is {h} ⊔ {a, h + a}
  (m/2 and a complementary pair). Otherwise no entry is m/2 and IndecTriple gives indecomposability.

  Lean 4 core plus hodge/IndecTriple (indec3_eq, indec_triple), hodge/PairBal (pair_bal), hodge/GcdHand
  (half_bal_even), hodge/HalfIndecIff (false_and').
-/
import hodge.HalfIndecIff

namespace TripleIff
open Indecomp IndecTriple PairBal GcdHand HalfIndecIff

theorem triple_dec (h0 a : Nat) (ha : 0 < a) (h2 : a + a = h0 + 1) :
    indec ((h0 + 1) + (h0 + 1)) [a, (h0 + 1) + a, (h0 + 1)] = false := by
  have s1 : bal ((h0 + 1) + (h0 + 1)) [h0 + 1] = true := half_bal_even (h0 + 1) (Nat.succ_pos h0)
  have p1 : bal ((h0 + 1) + (h0 + 1)) [a, (h0 + 1) + a] = true :=
    pair_bal (h0 + 1 + h0) a (h0 + 1 + a) (by rw [show a + (h0 + 1 + a) = (a + a) + (h0 + 1) by lib_nat, h2]; lib_nat)
      ha (Nat.lt_of_lt_of_le ha (Nat.le_add_left a _))
  rw [indec3_eq, s1, p1, show (!(true && true)) = false from rfl, false_and']
  rw [and_false', and_false']
  rfl

end TripleIff

#print axioms TripleIff.triple_dec

#print axioms: 1 theorem, no axioms.

81.141 Unscaling

If every unit of \(m\) is a unit of \(dm\) (e.g. the primes of \(d\) divide \(m\)): \(\mathrm {bal}\,(dm)\,(d\,c)\Rightarrow \mathrm {bal}\,m\,c\) — scaling is then an equivalence.

hodge/Unscale.lean

/-
  hodge/Unscale.lean — T41 cycle 869 (goal G578): the converse of ScaleBal. If every unit of m is a unit of d·m
  (true e.g. when every prime factor of d divides m, as for d = 2, m even, or d = 3, 3 | m), then
    bal (d·m) (d·c) ⇒ bal m c.
  So scaling is an equivalence in those cases: the Pieces5Scale seeds at m = 70, 72, 48 and their scalings at
  m = 140, 144 have the same balance status.

  Lean 4 core plus hodge/ScaleBal (tsum_scale, scl), hodge/TwistBal (all_fr_intro, all_fr_elim), hodge/HalfGeneral.
-/
import hodge.ScaleBal

namespace Unscale
open Indecomp HalfGeneral TwistBal ScaleBal

theorem mul_cancel (d x y : Nat) (hd : 0 < d) (h : d * x = d * y) : x = y :=
  Nat.le_antisymm (Nat.le_of_mul_le_mul_left (Nat.le_of_eq h) hd) (Nat.le_of_mul_le_mul_left (Nat.le_of_eq h.symm) hd)

theorem unscale_bal (d m : Nat) (hd : 0 < d) (hm : 0 < m) (c : List Nat)
    (hu : ∀ t, Nat.gcd t m = 1 → Nat.gcd t (d * m) = 1)
    (hb : bal (d * m) (scl d c) = true) : bal m c = true := by
  unfold bal FermatPrime.units at *
  apply all_fr_intro
  intro t ht hp
  have hg : Nat.gcd t m = 1 := Nat.eq_of_beq_eq_true hp
  have htdm : t < d * m := Nat.lt_of_lt_of_le ht (by
    have := Nat.mul_le_mul_right m (Nat.succ_le_of_lt hd)
    rw [Nat.one_mul] at this; exact this)
  have e := Nat.eq_of_beq_eq_true (all_fr_elim _ _ (d * m) hb t htdm (by rw [hu t hg]; rfl))
  rw [tsum_scale d m t hd hm, show (scl d c).length = c.length from APPairIrrGen.length_map' _ c] at e
  have e2 : d * (tsum m t c + tsum m t c) = d * (c.length * m) := by
    have : d * tsum m t c + d * tsum m t c = c.length * (d * m) := e
    rw [show d * (tsum m t c + tsum m t c) = d * tsum m t c + d * tsum m t c by lib_nat, this]; lib_nat
  rw [mul_cancel d _ _ hd e2]; exact beq_self _

end Unscale

#print axioms Unscale.mul_cancel
#print axioms Unscale.unscale_bal

#print axioms: 2 theorems, no axioms.

81.142 Surface characters at \(p=37\)

Every balanced length-4 character of the degree-37 Fermat surface is two complementary pairs (rfl, 63 s; built on Kamiak).

hodge/Pairs4d.lean

/-
  hodge/Pairs4d.lean — T41 cycle 1001 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 37: every balanced
  length-4 character of the degree-37 Fermat surface is a union of two complementary pairs (rfl, no heartbeat limit).
  With Pairs4, Pairs4b, Pairs4c: length 4 settled for all odd primes p ≤ 37.

  Lean 4 core plus hodge/Pairs4 (badQ), rfl.
-/
import hodge.Pairs4

namespace Pairs4d
open Pairs4

set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem r37 : badQ 37 = [] := rfl

end Pairs4d

#print axioms Pairs4d.r37

#print axioms: 1 theorem, no axioms.

81.143 Length-5 characters at \(m=2\cdot \)odd

For \(m\le 70\) the indecomposable orbits not explained by the rules occur at \(m=18,30,42,54,62,66,70\) only; for \(m=2p\), \(p\ne 31\) prime, all are explained. Representatives at 18, 62, 70 by rfl.

hodge/Len5Odd2.lean

/-
  hodge/Len5Odd2.lean — T41 cycle 879 (goal G588): balanced length-5 characters without m/2 at m = 2·odd.
  Computation (m ≤ 70): indecomposable unit-orbits not explained by the proved rules (families up to twist,
  gluing, scaling, splits) occur only at m = 18 (2), 30 (23), 42 (33), 54 (5), 62 (1), 66 (5), 70 (1); for
  m = 2p with p prime ≠ 31 every indecomposable orbit is explained. The m = 62 orbit [1, 33, 35, 39, 47] is the
  5-list of Indecomp/Reduce62 and the m = 70 orbit is Seed70. Representatives at m = 18, 62, 70: balanced and
  indecomposable by rfl.

  Lean 4 core plus hodge/Indecomp (bal, indec), rfl.
-/
import hodge.Indecomp

namespace Len5Odd2
open Indecomp

set_option maxRecDepth 100000 in
theorem u18_0 : bal 18 [1, 1, 14, 14, 15] = true ∧ indec 18 [1, 1, 14, 14, 15] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem u18_1 : bal 18 [1, 6, 7, 15, 16] = true ∧ indec 18 [1, 6, 7, 15, 16] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem u62_2 : bal 62 [1, 33, 35, 39, 47] = true ∧ indec 62 [1, 33, 35, 39, 47] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem u70_3 : bal 70 [1, 29, 43, 45, 57] = true ∧ indec 70 [1, 29, 43, 45, 57] = true := ⟨rfl, rfl⟩

end Len5Odd2

#print axioms Len5Odd2.u18_0
#print axioms Len5Odd2.u18_1
#print axioms Len5Odd2.u62_2
#print axioms Len5Odd2.u70_3

#print axioms: 4 theorems, no axioms.

81.144 Split criterion and the decomposable \(q=4\) orbit characters

A split into two nonempty balanced characters gives \(\mathrm {indec}=\mathrm {false}\); the \(q=4\) family \([a+ik]\sqcup [4k-4a]\) splits for \(k=2a\), \(k=3a\), \(2k=3a\).

hodge/SplitFalse.lean

/-
  hodge/SplitFalse.lean — T41 cycle 883 (goal G587): a general decomposability criterion and the decomposable
  members of the q = 4 orbit family. For any m and any character c:
    split_false   if c is obtained by distributing its entries into two nonempty balanced characters A, B
                  (in the order of `splits`), then indec m c = false.
  For QFam with q = 4 ([a + i·k (i < 4)] ⊔ [4k − 4a] at m = 4k), computation for k < 40 gives
    decomposable  ⇔  k = 2a  ∨  k = 3a  ∨  2k = 3a,
  and the three decompositions are proved here (with a = b, k as stated):
    k = 2b (m = 8b):   {7b, b} ⊔ {5b, 3b, 4b}
    k = 3b (m = 12b):  {10b, 7b, b} ⊔ {4b, 8b}
    k = 3b, a = 2b:    {11b, 5b, 2b} ⊔ {8b, 4b}

  Lean 4 core plus hodge/Indecomp (splits, indec), hodge/PairBal, hodge/Triple, hodge/BalAppend, hodge/GcdHand.
-/
import hodge.HalfIndecIff
import hodge.BalAppend
import hodge.IndecPerm
import hodge.QFam

namespace SplitFalse
open Indecomp PairBal GcdHand BalAppend PermSum

theorem mem_app_left {α : Type} (y : α) : ∀ (l r : List α), y ∈ l → y ∈ l ++ r
  | [], _, h => nomatch h
  | _ :: l, r, h => by
    cases h with
    | head => exact List.Mem.head _
    | tail _ h' => exact List.Mem.tail _ (mem_app_left y l r h')

theorem mem_app_right {α : Type} (y : α) : ∀ (l r : List α), y ∈ r → y ∈ l ++ r
  | [], _, h => h
  | _ :: l, r, h => List.Mem.tail _ (mem_app_right y l r h)

theorem mem_flatMap {α β : Type} (f : α → List β) (y : β) : ∀ (l : List α) (p : α), p ∈ l → y ∈ f p → y ∈ l.flatMap f
  | [], _, h, _ => nomatch h
  | q :: l, p, h, hy => by
    show y ∈ f q ++ l.flatMap f
    cases h with
    | head => exact mem_app_left y _ _ hy
    | tail _ h' => exact mem_app_right y _ _ (mem_flatMap f y l p h' hy)

theorem mem_left (x : Nat) (l A B : List Nat) (h : (A, B) ∈ splits l) : (x :: A, B) ∈ splits (x :: l) :=
  mem_flatMap _ _ (splits l) (A, B) h (List.Mem.head _)

theorem mem_right (x : Nat) (l A B : List Nat) (h : (A, B) ∈ splits l) : (A, x :: B) ∈ splits (x :: l) :=
  mem_flatMap _ _ (splits l) (A, B) h (List.Mem.tail _ (List.Mem.head _))

theorem mem_nil : (([] : List Nat), ([] : List Nat)) ∈ splits [] := List.Mem.head _

theorem all_elim {α : Type} (f : α → Bool) : ∀ (l : List α) (x : α), l.all f = true → x ∈ l → f x = true
  | [], _, _, h => nomatch h
  | y :: l, x, ha, h => by
    have ha' : (f y && l.all f) = true := ha
    cases hy : f y with
    | false => rw [hy] at ha'; exact nomatch ha'
    | true =>
      rw [hy] at ha'
      cases h with
      | head => exact hy
      | tail _ h' => exact all_elim f l x ha' h'

theorem split_false (m : Nat) (c A B : List Nat) (hmem : (A, B) ∈ splits c) (ha0 : A ≠ []) (hb0 : B ≠ [])
    (ha : bal m A = true) (hb : bal m B = true) : indec m c = false := by
  cases hi : indec m c with
  | false => rfl
  | true =>
    have e := all_elim _ (splits c) (A, B) hi hmem
    cases A with
    | nil => exact absurd rfl ha0
    | cons x A' => cases B with
      | nil => exact absurd rfl hb0
      | cons y B' =>
        have e' : (false || false || !(bal m (x :: A') && bal m (y :: B'))) = true := e
        rw [ha, hb] at e'; exact nomatch e'


theorem pair_bal' (M x y : Nat) (hxy : x + y = M) (hx0 : 0 < x) (hy0 : 0 < y) : bal M [x, y] = true := by
  cases M with
  | zero => rw [← Nat.add_zero 0] at hxy; exact absurd (Nat.le_antisymm (Nat.le_of_lt_succ (by
      have t := Nat.le_add_right x y; rw [hxy] at t; exact Nat.lt_succ_of_le t)) (Nat.zero_le x)) (Nat.ne_of_gt hx0)
  | succ m' => exact pair_bal m' x y hxy hx0 hy0

theorem pos_mul (c b : Nat) (hc : 0 < c) (hb : 0 < b) : 0 < c * b := Nat.mul_pos hc hb

/-- QFam q = 4, k = 2b: the character splits as {7b, b} ⊔ {5b, 3b, 4b}. -/
theorem q4_half (b : Nat) (hb : 0 < b) :
    indec (4 * (2 * b)) (gl (fun i => b + i * (2 * b)) 4 ++ [4 * (2 * b) - 4 * b]) = false := by
  have e : gl (fun i => b + i * (2 * b)) 4 ++ [4 * (2 * b) - 4 * b] = [7 * b, 5 * b, 3 * b, b, 4 * b] := by
    show [b + 3 * (2 * b), b + 2 * (2 * b), b + 1 * (2 * b), b + 0 * (2 * b), 4 * (2 * b) - 4 * b] = _
    have e4 : 4 * (2 * b) - 4 * b = 4 * b := by
      rw [show 4 * (2 * b) = 4 * b + 4 * b by lib_nat]; exact ModHand.add_sub' _ _
    rw [e4, show b + 3 * (2 * b) = 7 * b by lib_nat, show b + 2 * (2 * b) = 5 * b by lib_nat,
      show b + 1 * (2 * b) = 3 * b by lib_nat, show b + 0 * (2 * b) = b by lib_nat]
  rw [e]
  have hm : 4 * (2 * b) = 4 * b + 4 * b := by lib_nat
  apply split_false _ _ [7 * b, b] [5 * b, 3 * b, 4 * b]
    (mem_left _ _ _ _ (mem_right _ _ _ _ (mem_right _ _ _ _ (mem_left _ _ _ _ (mem_right _ _ _ _ mem_nil)))))
    (fun h => nomatch h) (fun h => nomatch h)
  · exact pair_bal' _ _ _ (by lib_nat) (pos_mul 7 b (Nat.succ_pos 6) hb) hb
  · have p1 := pair_bal' (4 * (2 * b)) (5 * b) (3 * b) (by lib_nat) (pos_mul 5 b (Nat.succ_pos 4) hb) (pos_mul 3 b (Nat.succ_pos 2) hb)
    have p2 : bal (4 * (2 * b)) [4 * b] = true := by rw [hm]; exact half_bal_even _ (pos_mul 4 b (Nat.succ_pos 3) hb)
    exact bal_append _ [5 * b, 3 * b] [4 * b] p1 p2

theorem rev3 (x y z : Nat) : List.Perm [z, y, x] [x, y, z] :=
  List.Perm.trans (List.Perm.swap y z [x]) (List.Perm.trans (List.Perm.cons y (List.Perm.swap x z [])) (List.Perm.swap x y [z]))

/-- The Triple(x) character at m = 12b with h = 6b. -/
theorem tri12 (b x : Nat) (hb : 0 < b) (hx0 : 0 < x) (hx : x < 6 * b) :
    bal (12 * b) [x, 6 * b + x, 12 * b - (x + x)] = true := by
  cases b with
  | zero => exact absurd hb (Nat.lt_irrefl 0)
  | succ b' =>
    have t := Triple.triple_bal (6 * b' + 5) x hx0 (by
      rw [show 6 * b' + 5 + 1 = 6 * (b' + 1) by lib_nat]; exact hx)
    rw [show 6 * b' + 5 + 1 = 6 * (b' + 1) by lib_nat, show 6 * (b' + 1) + 6 * (b' + 1) = 12 * (b' + 1) by lib_nat] at t
    exact t

/-- QFam q = 4, k = 3b, a = b: {10b, 7b, b} ⊔ {4b, 8b}. -/
theorem q4_third (b : Nat) (hb : 0 < b) :
    indec (4 * (3 * b)) (gl (fun i => b + i * (3 * b)) 4 ++ [4 * (3 * b) - 4 * b]) = false := by
  have e : gl (fun i => b + i * (3 * b)) 4 ++ [4 * (3 * b) - 4 * b] = [10 * b, 7 * b, 4 * b, b, 8 * b] := by
    show [b + 3 * (3 * b), b + 2 * (3 * b), b + 1 * (3 * b), b + 0 * (3 * b), 4 * (3 * b) - 4 * b] = _
    have e4 : 4 * (3 * b) - 4 * b = 8 * b := by
      rw [show 4 * (3 * b) = 8 * b + 4 * b by lib_nat]; exact ModHand.add_sub' _ _
    rw [e4, show b + 3 * (3 * b) = 10 * b by lib_nat, show b + 2 * (3 * b) = 7 * b by lib_nat,
      show b + 1 * (3 * b) = 4 * b by lib_nat, show b + 0 * (3 * b) = b by lib_nat]
  rw [e, show 4 * (3 * b) = 12 * b by lib_nat]
  apply split_false _ _ [10 * b, 7 * b, b] [4 * b, 8 * b]
    (mem_left _ _ _ _ (mem_left _ _ _ _ (mem_right _ _ _ _ (mem_left _ _ _ _ (mem_right _ _ _ _ mem_nil)))))
    (fun h => nomatch h) (fun h => nomatch h)
  · have t := tri12 b b hb hb (by
      rw [show 6 * b = b + 5 * b by lib_nat]; exact Nat.lt_add_of_pos_right (pos_mul 5 b (Nat.succ_pos 4) hb))
    rw [show 6 * b + b = 7 * b by lib_nat, show 12 * b - (b + b) = 10 * b by
      rw [show 12 * b = 10 * b + (b + b) by lib_nat]; exact ModHand.add_sub' _ _] at t
    rw [← t]; exact IndecPerm.bal_perm _ (rev3 _ _ _)
  · exact pair_bal' _ _ _ (by lib_nat) (pos_mul 4 b (Nat.succ_pos 3) hb) (pos_mul 8 b (Nat.succ_pos 7) hb)

/-- QFam q = 4, k = 3b, a = 2b (2k = 3a): {11b, 5b, 2b} ⊔ {8b, 4b}. -/
theorem q4_twothird (b : Nat) (hb : 0 < b) :
    indec (4 * (3 * b)) (gl (fun i => 2 * b + i * (3 * b)) 4 ++ [4 * (3 * b) - 4 * (2 * b)]) = false := by
  have e : gl (fun i => 2 * b + i * (3 * b)) 4 ++ [4 * (3 * b) - 4 * (2 * b)] = [11 * b, 8 * b, 5 * b, 2 * b, 4 * b] := by
    show [2 * b + 3 * (3 * b), 2 * b + 2 * (3 * b), 2 * b + 1 * (3 * b), 2 * b + 0 * (3 * b), 4 * (3 * b) - 4 * (2 * b)] = _
    have e4 : 4 * (3 * b) - 4 * (2 * b) = 4 * b := by
      rw [show 4 * (3 * b) = 4 * b + 4 * (2 * b) by lib_nat]; exact ModHand.add_sub' _ _
    rw [e4, show 2 * b + 3 * (3 * b) = 11 * b by lib_nat, show 2 * b + 2 * (3 * b) = 8 * b by lib_nat,
      show 2 * b + 1 * (3 * b) = 5 * b by lib_nat, show 2 * b + 0 * (3 * b) = 2 * b by lib_nat]
  rw [e, show 4 * (3 * b) = 12 * b by lib_nat]
  apply split_false _ _ [11 * b, 5 * b, 2 * b] [8 * b, 4 * b]
    (mem_left _ _ _ _ (mem_right _ _ _ _ (mem_left _ _ _ _ (mem_left _ _ _ _ (mem_right _ _ _ _ mem_nil)))))
    (fun h => nomatch h) (fun h => nomatch h)
  · have t := tri12 b (5 * b) hb (pos_mul 5 b (Nat.succ_pos 4) hb) (by
      rw [show 6 * b = 5 * b + b by lib_nat]; exact Nat.lt_add_of_pos_right hb)
    rw [show 6 * b + 5 * b = 11 * b by lib_nat, show 12 * b - (5 * b + 5 * b) = 2 * b by
      rw [show 12 * b = 2 * b + (5 * b + 5 * b) by lib_nat]; exact ModHand.add_sub' _ _] at t
    rw [← t]; exact IndecPerm.bal_perm _ (List.Perm.swap (5 * b) (11 * b) [2 * b])
  · exact pair_bal' _ _ _ (by lib_nat) (pos_mul 8 b (Nat.succ_pos 7) hb) (pos_mul 4 b (Nat.succ_pos 3) hb)

end SplitFalse

#print axioms SplitFalse.mem_flatMap
#print axioms SplitFalse.all_elim
#print axioms SplitFalse.split_false
#print axioms SplitFalse.q4_half
#print axioms SplitFalse.q4_third
#print axioms SplitFalse.q4_twothird

#print axioms: 6 theorems, no axioms.

81.145 Length-6 characters, \(m=25\) to \(30\)

Unexplained indecomposable orbits: none for \(m=25,26,27,29\); three at \(m=28\), 29 at \(m=30\). Representatives by rfl.

hodge/Len6Scan.lean

/-
  hodge/Len6Scan.lean — T41 cycle 888 (goal G584): balanced indecomposable length-6 characters, m = 25–30.
  Computation (all multisets, all splits): number of indecomposable unit-orbits not explained by the proved rules
  (families up to twist, gluing, scaling, splits): m = 25: 0 (1 orbit, explained), 26: 0, 27: 0, 29: none at all,
  28: 3, 30: 29. Representatives of the three m = 28 orbits and one m = 30 orbit: balanced and indecomposable (rfl).

  Lean 4 core plus hodge/Indecomp (bal, indec), rfl.
-/
import hodge.Indecomp

namespace Len6Scan
open Indecomp

set_option maxRecDepth 100000 in
theorem u28_0 : bal 28 [1, 5, 6, 21, 25, 26] = true ∧ indec 28 [1, 5, 6, 21, 25, 26] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem u28_1 : bal 28 [1, 5, 8, 21, 24, 25] = true ∧ indec 28 [1, 5, 8, 21, 24, 25] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem u28_2 : bal 28 [1, 9, 11, 15, 23, 25] = true ∧ indec 28 [1, 9, 11, 15, 23, 25] = true := ⟨rfl, rfl⟩
set_option maxRecDepth 100000 in
theorem u30_3 : bal 30 [1, 1, 8, 25, 27, 28] = true ∧ indec 30 [1, 1, 8, 25, 27, 28] = true := ⟨rfl, rfl⟩

end Len6Scan

#print axioms Len6Scan.u28_0
#print axioms Len6Scan.u28_1
#print axioms Len6Scan.u28_2
#print axioms Len6Scan.u30_3

#print axioms: 4 theorems, no axioms.

81.146 Fourfold characters at \(p\le 13\) as statements

For \(p=5,7,11,13\) and every sorted length-6 character \(c\): \(\mathrm {bal}\,p\,c\Rightarrow c\) is three complementary pairs.

hodge/Pairs6Iff.lean

/-
  hodge/Pairs6Iff.lean — T41 cycle 890 (goal G586): the Pairs6Small computations as statements. For p = 5, 7, 11, 13
  and every c in `sexts p` (the sorted length-6 characters of the degree-p Fermat fourfold):
    bal p c = true  →  allPairs p 7 c = true
  i.e. every balanced fourfold character is three complementary pairs.

  Lean 4 core plus hodge/Pairs6Small (badP, q5 … q13).
-/
import hodge.Pairs6Small

namespace Pairs6Iff
open Indecomp Len6Decomp Pairs6Small

theorem mem_filter_of {α : Type} (f : α → Bool) (x : α) : ∀ l : List α, x ∈ l → f x = true → x ∈ l.filter f
  | [], h, _ => nomatch h
  | y :: l, h, hf => by
    cases hy : f y with
    | true =>
      have e : (y :: l).filter f = y :: l.filter f := by
        show (match f y with | true => y :: l.filter f | false => l.filter f) = _
        rw [hy]
      rw [e]
      cases h with
      | head => exact List.Mem.head _
      | tail _ h' => exact List.Mem.tail _ (mem_filter_of f x l h' hf)
    | false =>
      have e : (y :: l).filter f = l.filter f := by
        show (match f y with | true => y :: l.filter f | false => l.filter f) = _
        rw [hy]
      rw [e]
      cases h with
      | head => rw [hy] at hf; exact nomatch hf
      | tail _ h' => exact mem_filter_of f x l h' hf

theorem of_bad_nil (p : Nat) (hb : badP p = []) (c : List Nat) (hc : c ∈ sexts p) (hbal : bal p c = true) :
    allPairs p 7 c = true := by
  cases ha : allPairs p 7 c with
  | true => rfl
  | false =>
    have hm := mem_filter_of (fun c => bal p c && !allPairs p 7 c) c (sexts p) hc (by
      show (bal p c && !allPairs p 7 c) = true
      rw [hbal, ha]; rfl)
    have hm' : c ∈ badP p := hm
    rw [hb] at hm'; exact nomatch hm'

theorem pairs5 (c : List Nat) (hc : c ∈ sexts 5) (h : bal 5 c = true) : allPairs 5 7 c = true := of_bad_nil 5 q5 c hc h
theorem pairs7 (c : List Nat) (hc : c ∈ sexts 7) (h : bal 7 c = true) : allPairs 7 7 c = true := of_bad_nil 7 q7 c hc h
theorem pairs11 (c : List Nat) (hc : c ∈ sexts 11) (h : bal 11 c = true) : allPairs 11 7 c = true := of_bad_nil 11 q11 c hc h
theorem pairs13 (c : List Nat) (hc : c ∈ sexts 13) (h : bal 13 c = true) : allPairs 13 7 c = true := of_bad_nil 13 q13 c hc h

end Pairs6Iff

#print axioms Pairs6Iff.mem_filter_of
#print axioms Pairs6Iff.of_bad_nil
#print axioms Pairs6Iff.pairs5
#print axioms Pairs6Iff.pairs7
#print axioms Pairs6Iff.pairs11
#print axioms Pairs6Iff.pairs13

#print axioms: 6 theorems, no axioms.

81.147 The \(q=4\) criterion for \(k\le 40\)

For \(2\le k\le 40\), \(0<a<k\): \([a+ik]_{i<4}\sqcup [4k-4a]\) is indecomposable iff \(2a\ne k\), \(3a\ne k\), \(3a\ne 2k\) (rfl).

hodge/Q4Range.lean

/-
  hodge/Q4Range.lean — T41 cycle 897 (goal G587b, finite range): for the q = 4 orbit-family character
    c(k, a) = [a + 3k, a + 2k, a + k, a] ⊔ [4k − 4a]   at m = 4k,
  for every 2 ≤ k ≤ 40 and 0 < a < k:  indec (4k) c(k, a) = true  ⇔  2a ≠ k ∧ 3a ≠ k ∧ 3a ≠ 2k  (rfl).
  The decompositions in the excluded cases are SplitFalse.q4_half, q4_third, q4_twothird for every k.

  Lean 4 core plus hodge/Indecomp (indec), rfl.
-/
import hodge.Indecomp

namespace Q4Range
open Indecomp

def c4 (k a : Nat) : List Nat := [a + 3 * k, a + 2 * k, a + k, a, 4 * k - 4 * a]

def crit (k a : Nat) : Bool := !(Nat.beq (2 * a) k || Nat.beq (3 * a) k || Nat.beq (3 * a) (2 * k))

def okK (k : Nat) : Bool := (List.range' 1 (k - 1)).all (fun a => Bool.beq (indec (4 * k) (c4 k a)) (crit k a))

set_option maxRecDepth 200000 in
theorem range40 : (List.range' 2 39).all okK = true := rfl

end Q4Range

#print axioms Q4Range.range40

#print axioms: 1 theorem, no axioms.

81.148 Fourfold characters at \(p=17,19\) as statements

For \(p=17,19\) and every sorted length-6 character: balanced implies three complementary pairs (built on Kamiak).

hodge/Pairs6Iff2.lean

/-
  hodge/Pairs6Iff2.lean — T41 cycle 908 (goal G529b, statements for p = 17, 19): from hodge/Pairs6 (Kamiak rfl),
  for every c in `sexts p`: bal p c = true → allPairs p 7 c = true (three complementary pairs), p = 17, 19.
  Built on Kamiak with hodge/Pairs6 (listed in KAMIAK_BUILD_ROOTS).

  Lean 4 core plus hodge/Pairs6 (badP, p17, p19), hodge/Pairs6Iff (mem_filter_of).
-/
import hodge.Pairs6
import hodge.Pairs6Iff

namespace Pairs6Iff2
open Indecomp Len6Decomp Pairs6

theorem of_bad_nil (p : Nat) (hb : badP p = []) (c : List Nat) (hc : c ∈ sexts p) (hbal : bal p c = true) :
    allPairs p 7 c = true := by
  cases ha : allPairs p 7 c with
  | true => rfl
  | false =>
    have hm := Pairs6Iff.mem_filter_of (fun c => bal p c && !allPairs p 7 c) c (sexts p) hc (by
      show (bal p c && !allPairs p 7 c) = true
      rw [hbal, ha]; rfl)
    have hm' : c ∈ badP p := hm
    rw [hb] at hm'; exact nomatch hm'

theorem pairs17 (c : List Nat) (hc : c ∈ sexts 17) (h : bal 17 c = true) : allPairs 17 7 c = true := of_bad_nil 17 p17 c hc h
theorem pairs19 (c : List Nat) (hc : c ∈ sexts 19) (h : bal 19 c = true) : allPairs 19 7 c = true := of_bad_nil 19 p19 c hc h

end Pairs6Iff2

#print axioms Pairs6Iff2.of_bad_nil
#print axioms Pairs6Iff2.pairs17
#print axioms Pairs6Iff2.pairs19

#print axioms: 3 theorems, no axioms.

81.149 The \(k=2a\) member of every orbit family decomposes

For every \(q\ge 2\), \(a>0\): \([a+2ia]_{i<q}\sqcup [2qa-qa]\) at \(m=2qa\) splits off the pair \(\{(2q-1)a,a\}\).

hodge/HalfKDec.lean

/-
  hodge/HalfKDec.lean — T41 cycle 913 (goal G610): for every q ≥ 2 and a > 0 the μ_q-orbit character at k = 2a,
    [a + i·2a (i < q)] ⊔ [q·2a − q·a]   at m = 2qa,
  is decomposable: it splits as the complementary pair {(2q − 1)a, a} ⊔ the rest (the rest is balanced because the
  whole is (QFam.qfam_bal) and the pair is (BalAppend.bal_cancel)). Computation (q = 4, 5, k < 40) shows k = 2a is
  among the decomposable cases for every q; this proves it for all q.

  Lean 4 core plus hodge/QFam (qfam_bal, gl), hodge/SplitFalse (split_false, mem_left, mem_right, pair_bal'),
  hodge/QFamHalf (bal_congr), hodge/BalAppend (bal_cancel, tsum_app).
-/
import hodge.SplitFalse
import hodge.QFamHalf

namespace HalfKDec
open Indecomp PermSum QFam SplitFalse BalAppend QFamHalf

theorem gl_snoc (g : Nat → Nat) : ∀ n, gl g (n + 1) = gl (fun i => g (i + 1)) n ++ [g 0]
  | 0 => rfl
  | n + 1 => by
    show g (n + 1) :: gl g (n + 1) = g (n + 1) :: (gl (fun i => g (i + 1)) n ++ [g 0])
    rw [gl_snoc g n]

theorem app_assoc' {α : Type} : ∀ (l1 l2 l3 : List α), (l1 ++ l2) ++ l3 = l1 ++ (l2 ++ l3)
  | [], _, _ => rfl
  | x :: l1, l2, l3 => by
    show x :: ((l1 ++ l2) ++ l3) = x :: (l1 ++ (l2 ++ l3))
    rw [app_assoc' l1 l2 l3]

theorem mem_all_right : ∀ l : List Nat, (([] : List Nat), l) ∈ splits l
  | [] => mem_nil
  | x :: l => mem_right x l [] l (mem_all_right l)

theorem mem_one_mid (y : Nat) (l2 : List Nat) : ∀ l1 : List Nat, ([y], l1 ++ l2) ∈ splits (l1 ++ y :: l2)
  | [] => mem_left y l2 [] l2 (mem_all_right l2)
  | x :: l1 => mem_right x (l1 ++ y :: l2) [y] (l1 ++ l2) (mem_one_mid y l2 l1)

theorem tsum_mid (m t x y : Nat) (l1 l2 : List Nat) :
    tsum m t (x :: (l1 ++ y :: l2)) = tsum m t ([x, y] ++ (l1 ++ l2)) := by
  show (t * x) % m + tsum m t (l1 ++ y :: l2) = (t * x) % m + ((t * y) % m + tsum m t (l1 ++ l2))
  rw [tsum_app, tsum_app]
  show (t * x) % m + (tsum m t l1 + ((t * y) % m + tsum m t l2)) = (t * x) % m + ((t * y) % m + (tsum m t l1 + tsum m t l2))
  generalize (t * x) % m = u; generalize (t * y) % m = v; generalize tsum m t l1 = s1; generalize tsum m t l2 = s2
  lib_nat

theorem len_mid (x y : Nat) (l1 l2 : List Nat) : (x :: (l1 ++ y :: l2)).length = ([x, y] ++ (l1 ++ l2)).length := by
  show (l1 ++ y :: l2).length + 1 = ([x, y] ++ (l1 ++ l2)).length
  rw [len_app, len_app, len_app]
  show l1.length + (l2.length + 1) + 1 = 2 + (l1.length + l2.length)
  lib_nat

/-- **The k = 2a member of every μ_q-orbit family (q ≥ 2) decomposes.** -/
theorem half_k_dec (r a : Nat) (ha : 0 < a) :
    indec ((r + 2) * (a + a)) (gl (fun i => a + i * (a + a)) (r + 2) ++ [(r + 2) * (a + a) - (r + 2) * a]) = false := by
  have hc := qfam_bal (r + 2) (a + a) a (Nat.succ_pos _) ha (Nat.lt_add_of_pos_right ha)
  generalize hL : (r + 2) * (a + a) - (r + 2) * a = L at hc ⊢
  have e : gl (fun i => a + i * (a + a)) (r + 2) ++ [L]
      = (a + (r + 1) * (a + a)) :: (gl (fun i => a + (i + 1) * (a + a)) r ++ (a + 0 * (a + a)) :: [L]) := by
    show (a + (r + 1) * (a + a)) :: gl (fun i => a + i * (a + a)) (r + 1) ++ [L] = _
    rw [gl_snoc (fun i => a + i * (a + a)) r]
    show (a + (r + 1) * (a + a)) :: ((gl (fun i => a + (i + 1) * (a + a)) r ++ [a + 0 * (a + a)]) ++ [L]) = _
    rw [app_assoc']; rfl
  rw [e] at hc ⊢
  generalize gl (fun i => a + (i + 1) * (a + a)) r = l1 at hc ⊢
  have hA : bal ((r + 2) * (a + a)) [a + (r + 1) * (a + a), a + 0 * (a + a)] = true :=
    pair_bal' _ _ _ (by lib_nat) (Nat.lt_of_lt_of_le ha (Nat.le_add_right a _)) (Nat.lt_of_lt_of_le ha (Nat.le_add_right a _))
  have hAB := bal_congr _ _ _ (fun t => tsum_mid _ t _ _ l1 [L]) (len_mid _ _ l1 [L]) hc
  have hB := bal_cancel _ _ _ hA hAB
  exact split_false _ _ _ _ (mem_left _ _ _ _ (mem_one_mid _ [L] l1)) (fun h => nomatch h)
    (fun h => by cases l1 with
      | nil => exact nomatch h
      | cons _ _ => exact nomatch h) hA hB

end HalfKDec

#print axioms HalfKDec.gl_snoc
#print axioms HalfKDec.mem_one_mid
#print axioms HalfKDec.tsum_mid
#print axioms HalfKDec.half_k_dec

#print axioms: 4 theorems, no axioms.

81.150 Orbit characters with prime \(k>q\) (finite ranges)

QFam\((q,k,a)\) is indecomposable for every \(a\) when \(k\) is prime and \(q<k\): certified for \(q=4,\dots ,7\) and \(k\le 13\) by rfl.

hodge/PrimeKIndec.lean

/-
  hodge/PrimeKIndec.lean — T41 cycle 917 (goal G612, finite part): for the μ_q-orbit characters
    QFam(q, k, a) = [a + i·k (i < q)] ⊔ [qk − qa]   at m = qk,
  every member with k prime, q < k is indecomposable, for the ranges certified here by rfl:
    q = 4: k = 5, 7, 11, 13;   q = 5: k = 7, 11, 13;   q = 6: k = 7, 11;   q = 7: k = 11.
  Computation (Python): the same holds for q = 4, 5 (k < 40) and q = 6, 8 (k < 25).

  Lean 4 core plus hodge/QFam (gl), hodge/Indecomp (indec), rfl.
-/
import hodge.QFam

namespace PrimeKIndec
open Indecomp PermSum

def qchar (q k a : Nat) : List Nat := gl (fun i => a + i * k) q ++ [q * k - q * a]

def allIndec (q k : Nat) : Bool := (List.range' 1 (k - 1)).all (fun a => indec (q * k) (qchar q k a))

set_option maxRecDepth 200000 in
theorem q4 : [5, 7, 11, 13].all (allIndec 4) = true := rfl
set_option maxRecDepth 200000 in
theorem q5 : [7, 11, 13].all (allIndec 5) = true := rfl
set_option maxRecDepth 200000 in
theorem q6 : [7, 11].all (allIndec 6) = true := rfl
set_option maxRecDepth 200000 in
theorem q7 : [11].all (allIndec 7) = true := rfl

end PrimeKIndec

#print axioms PrimeKIndec.q4
#print axioms PrimeKIndec.q5
#print axioms PrimeKIndec.q6
#print axioms PrimeKIndec.q7

#print axioms: 4 theorems, no axioms.

81.151 Even \(q\), \(k=3a\): the orbit character contains a Triple

For even \(q\ge 4\): QFam\((q,3a,a)\) contains \(\{a,m/2+a,m-2a\}\) (members \(0\), \(q/2\), \(q-1\)); for even \(q\ge 6\) and \(2k=3a\) (members \(0\), \(q/2\), \(q-2\)). Both decompose.

hodge/EvenThird.lean

/-
  hodge/EvenThird.lean — T41 cycle 928 (goal G620): for every even q ≥ 4 and a > 0 the μ_q-orbit character at
  k = 3a,
    QFam(q, 3a, a) = [a + i·3a (i < q)] ⊔ [3qa − qa]   at m = 3qa,
  contains Triple(a) = {a, m/2 + a, m − 2a} (the members i = 0, q/2, q − 1) and therefore decomposes
  (the rest is balanced by BalAppend.bal_cancel). Computation: q = 4, 6, 8 (k < 25) — k = 3a is always decomposable
  for even q; for q = 5 it is not (k = 6, a = 2).

  Lean 4 core plus hodge/HalfKDec (gl_snoc, app_assoc', mem_all_right), hodge/SplitFalse (split_false, mem_left,
  rev3), hodge/IndecPerm (bal_perm, indec_perm), hodge/Triple (triple_bal), hodge/QFam (qfam_bal).
-/
import hodge.HalfKDec

namespace EvenThird
open Indecomp PermSum QFam SplitFalse BalAppend HalfKDec

theorem gl_add (g : Nat → Nat) (m : Nat) : ∀ n, gl g (n + m) = gl (fun i => g (i + m)) n ++ gl g m
  | 0 => by rw [Nat.zero_add]; rfl
  | n + 1 => by
    rw [show n + 1 + m = (n + m) + 1 by lib_nat]
    show g (n + m) :: gl g (n + m) = g (n + m) :: (gl (fun i => g (i + m)) n ++ gl g m)
    rw [gl_add g m n]

theorem triple_bal' (h a : Nat) (hh : 0 < h) (ha0 : 0 < a) (hah : a < h) :
    bal (h + h) [a, h + a, (h + h) - (a + a)] = true := by
  cases h with
  | zero => exact absurd hh (Nat.lt_irrefl 0)
  | succ h0 => exact Triple.triple_bal h0 a ha0 hah

theorem not_indec_of_perm (m : Nat) {c c' : List Nat} (hp : c.Perm c') (h : indec m c' = false) : indec m c = false := by
  cases hc : indec m c with
  | false => rfl
  | true => rw [IndecPerm.indec_perm m hp hc] at h; exact nomatch h

/-- **Even q ≥ 4, k = 3a: the orbit character decomposes.** q = 2r + 4. -/
theorem even_third (r a : Nat) (ha : 0 < a) :
    indec ((2 * r + 4) * (3 * a)) (gl (fun i => a + i * (3 * a)) (2 * r + 4) ++ [(2 * r + 4) * (3 * a) - (2 * r + 4) * a]) = false := by
  have hak : a < 3 * a := by
    rw [show 3 * a = a + (a + a) by lib_nat]; exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le ha (Nat.le_add_right a a))
  have hc := qfam_bal (2 * r + 4) (3 * a) a (Nat.succ_pos _) ha hak
  generalize hL : (2 * r + 4) * (3 * a) - (2 * r + 4) * a = L at hc ⊢
  let g : Nat → Nat := fun i => a + i * (3 * a)
  have e : gl g (2 * r + 4) ++ [L]
      = g (2 * r + 3) :: (gl (fun i => g (i + (r + 3))) r ++ g (r + 2) :: (gl (fun i => g (i + 1)) (r + 1) ++ g 0 :: [L])) := by
    show g (2 * r + 3) :: gl g (2 * r + 3) ++ [L] = _
    rw [show 2 * r + 3 = r + (r + 3) by lib_nat, gl_add g (r + 3) r]
    show g (r + (r + 3)) :: ((gl (fun i => g (i + (r + 3))) r ++ (g (r + 2) :: gl g (r + 2))) ++ [L]) = _
    rw [gl_snoc g (r + 1), show r + (r + 3) = 2 * r + 3 by lib_nat, app_assoc']
    show g (2 * r + 3) :: (gl (fun i => g (i + (r + 3))) r ++ g (r + 2) :: ((gl (fun i => g (i + 1)) (r + 1) ++ [g 0]) ++ [L])) = _
    rw [app_assoc']; rfl
  have hc' : bal ((2 * r + 4) * (3 * a)) (gl g (2 * r + 4) ++ [L]) = true := hc
  show indec ((2 * r + 4) * (3 * a)) (gl g (2 * r + 4) ++ [L]) = false
  rw [e] at hc' ⊢
  generalize gl (fun i => g (i + (r + 3))) r = X at hc' ⊢
  generalize gl (fun i => g (i + 1)) (r + 1) = Y at hc' ⊢
  -- permute the three Triple members to the front
  have p1 : List.Perm (X ++ g (r + 2) :: (Y ++ g 0 :: [L])) (g (r + 2) :: g 0 :: ((X ++ Y) ++ [L])) := by
    refine List.Perm.trans List.perm_middle (List.Perm.cons _ ?_)
    rw [← app_assoc']
    exact List.perm_middle
  have pc : List.Perm (g (2 * r + 3) :: (X ++ g (r + 2) :: (Y ++ g 0 :: [L])))
      ([g (2 * r + 3), g (r + 2), g 0] ++ ((X ++ Y) ++ [L])) := List.Perm.cons _ p1
  have hm : (2 * r + 4) * (3 * a) = (r + 2) * (3 * a) + (r + 2) * (3 * a) := by lib_nat
  have hpos : 0 < (r + 2) * (3 * a) := Nat.mul_pos (Nat.succ_pos _) (Nat.lt_of_lt_of_le ha (Nat.le_of_lt hak))
  have hlt : a < (r + 2) * (3 * a) := Nat.lt_of_lt_of_le hak (by
    have := Nat.mul_le_mul_right (3 * a) (show 1 ≤ r + 2 from Nat.succ_le_succ (Nat.zero_le _))
    rw [Nat.one_mul] at this; exact this)
  have tb := triple_bal' _ a hpos ha hlt
  have e1 : (r + 2) * (3 * a) + a = g (r + 2) := by show _ = a + (r + 2) * (3 * a); lib_nat
  have e2 : (r + 2) * (3 * a) + (r + 2) * (3 * a) - (a + a) = g (2 * r + 3) := by
    show _ = a + (2 * r + 3) * (3 * a)
    rw [show (r + 2) * (3 * a) + (r + 2) * (3 * a) = (a + (2 * r + 3) * (3 * a)) + (a + a) by lib_nat]
    exact ModHand.add_sub' _ _
  have e0 : g 0 = a := by show a + 0 * (3 * a) = a; lib_nat
  rw [e1, e2, ← hm] at tb
  have tb' : bal ((2 * r + 4) * (3 * a)) [g 0, g (r + 2), g (2 * r + 3)] = true := by rw [e0]; exact tb
  have hA : bal ((2 * r + 4) * (3 * a)) [g (2 * r + 3), g (r + 2), g 0] = true := by
    rw [← tb']; exact IndecPerm.bal_perm _ (rev3 _ _ _)
  have hAB : bal ((2 * r + 4) * (3 * a)) ([g (2 * r + 3), g (r + 2), g 0] ++ ((X ++ Y) ++ [L])) = true := by
    rw [← IndecPerm.bal_perm _ pc]; exact hc'
  have hB := bal_cancel _ _ _ hA hAB
  apply not_indec_of_perm _ pc
  exact split_false _ _ _ _ (mem_left _ _ _ _ (mem_left _ _ _ _ (mem_left _ _ _ _ (mem_all_right _))))
    (fun h => nomatch h) (fun h => by
      cases X with
      | nil => cases Y with
        | nil => exact nomatch h
        | cons _ _ => exact nomatch h
      | cons _ _ => exact nomatch h) hA hB

/-- **Even q ≥ 6, 2k = 3a (k = 3b, a = 2b): the orbit character decomposes.** q = 2r + 6; the Triple members are
    i = 0, q/2, q − 2. (For q = 4 the members q/2 and q − 2 coincide; that case is SplitFalse.q4_twothird.) -/
theorem even_twothird (r b : Nat) (hb : 0 < b) :
    indec ((2 * r + 6) * (3 * b)) (gl (fun i => 2 * b + i * (3 * b)) (2 * r + 6) ++ [(2 * r + 6) * (3 * b) - (2 * r + 6) * (2 * b)]) = false := by
  have hak : 2 * b < 3 * b := by
    rw [show 3 * b = 2 * b + b by lib_nat]; exact Nat.lt_add_of_pos_right hb
  have ha : 0 < 2 * b := Nat.mul_pos (Nat.succ_pos 1) hb
  have hc := qfam_bal (2 * r + 6) (3 * b) (2 * b) (Nat.succ_pos _) ha hak
  generalize hL : (2 * r + 6) * (3 * b) - (2 * r + 6) * (2 * b) = L at hc ⊢
  let g : Nat → Nat := fun i => 2 * b + i * (3 * b)
  have e : gl g (2 * r + 6) ++ [L]
      = g (2 * r + 5) :: g (2 * r + 4) :: (gl (fun i => g (i + (r + 4))) r ++ g (r + 3) :: (gl (fun i => g (i + 1)) (r + 2) ++ g 0 :: [L])) := by
    show g (2 * r + 5) :: g (2 * r + 4) :: gl g (2 * r + 4) ++ [L] = _
    rw [show 2 * r + 4 = r + (r + 4) by lib_nat, gl_add g (r + 4) r]
    show g (2 * r + 5) :: g (r + (r + 4)) :: ((gl (fun i => g (i + (r + 4))) r ++ (g (r + 3) :: gl g (r + 3))) ++ [L]) = _
    rw [gl_snoc g (r + 2), show r + (r + 4) = 2 * r + 4 by lib_nat, app_assoc']
    show g (2 * r + 5) :: g (2 * r + 4) :: (gl (fun i => g (i + (r + 4))) r ++ g (r + 3) :: ((gl (fun i => g (i + 1)) (r + 2) ++ [g 0]) ++ [L])) = _
    rw [app_assoc']; rfl
  have hc' : bal ((2 * r + 6) * (3 * b)) (gl g (2 * r + 6) ++ [L]) = true := hc
  show indec ((2 * r + 6) * (3 * b)) (gl g (2 * r + 6) ++ [L]) = false
  rw [e] at hc' ⊢
  generalize gl (fun i => g (i + (r + 4))) r = X at hc' ⊢
  generalize gl (fun i => g (i + 1)) (r + 2) = Y at hc' ⊢
  have p1 : List.Perm (X ++ g (r + 3) :: (Y ++ g 0 :: [L])) (g (r + 3) :: g 0 :: ((X ++ Y) ++ [L])) := by
    refine List.Perm.trans List.perm_middle (List.Perm.cons _ ?_)
    rw [← app_assoc']
    exact List.perm_middle
  have p2 : List.Perm (g (2 * r + 5) :: g (r + 3) :: g 0 :: ((X ++ Y) ++ [L]))
      (g (r + 3) :: g 0 :: g (2 * r + 5) :: ((X ++ Y) ++ [L])) :=
    (List.perm_middle (a := g (2 * r + 5)) (l₁ := [g (r + 3), g 0]) (l₂ := (X ++ Y) ++ [L])).symm
  have pc : List.Perm (g (2 * r + 5) :: g (2 * r + 4) :: (X ++ g (r + 3) :: (Y ++ g 0 :: [L])))
      ([g (2 * r + 4), g (r + 3), g 0] ++ (g (2 * r + 5) :: ((X ++ Y) ++ [L]))) :=
    List.Perm.trans (List.Perm.swap _ _ _) (List.Perm.cons _ (List.Perm.trans (List.Perm.cons _ p1) p2))
  have hm : (2 * r + 6) * (3 * b) = (r + 3) * (3 * b) + (r + 3) * (3 * b) := by lib_nat
  have hpos : 0 < (r + 3) * (3 * b) := Nat.mul_pos (Nat.succ_pos _) (Nat.lt_of_lt_of_le ha (Nat.le_of_lt hak))
  have hlt : 2 * b < (r + 3) * (3 * b) := Nat.lt_of_lt_of_le hak (by
    have := Nat.mul_le_mul_right (3 * b) (show 1 ≤ r + 3 from Nat.succ_le_succ (Nat.zero_le _))
    rw [Nat.one_mul] at this; exact this)
  have tb := triple_bal' _ (2 * b) hpos ha hlt
  have e1 : (r + 3) * (3 * b) + 2 * b = g (r + 3) := by show _ = 2 * b + (r + 3) * (3 * b); lib_nat
  have e2 : (r + 3) * (3 * b) + (r + 3) * (3 * b) - (2 * b + 2 * b) = g (2 * r + 4) := by
    show _ = 2 * b + (2 * r + 4) * (3 * b)
    rw [show (r + 3) * (3 * b) + (r + 3) * (3 * b) = (2 * b + (2 * r + 4) * (3 * b)) + (2 * b + 2 * b) by lib_nat]
    exact ModHand.add_sub' _ _
  have e0 : g 0 = 2 * b := by show 2 * b + 0 * (3 * b) = 2 * b; lib_nat
  rw [e1, e2, ← hm] at tb
  have tb' : bal ((2 * r + 6) * (3 * b)) [g 0, g (r + 3), g (2 * r + 4)] = true := by rw [e0]; exact tb
  have hA : bal ((2 * r + 6) * (3 * b)) [g (2 * r + 4), g (r + 3), g 0] = true := by
    rw [← tb']; exact IndecPerm.bal_perm _ (rev3 _ _ _)
  have hAB : bal ((2 * r + 6) * (3 * b)) ([g (2 * r + 4), g (r + 3), g 0] ++ (g (2 * r + 5) :: ((X ++ Y) ++ [L]))) = true := by
    rw [← IndecPerm.bal_perm _ pc]; exact hc'
  have hB := bal_cancel _ _ _ hA hAB
  apply not_indec_of_perm _ pc
  exact split_false _ _ _ _ (mem_left _ _ _ _ (mem_left _ _ _ _ (mem_left _ _ _ _ (mem_all_right _))))
    (fun h => nomatch h) (fun h => nomatch h) hA hB

end EvenThird

#print axioms EvenThird.gl_add
#print axioms EvenThird.not_indec_of_perm
#print axioms EvenThird.even_third
#print axioms EvenThird.even_twothird

#print axioms: 4 theorems, no axioms.

81.152 The complete \(q=4\) criterion

For every \(0<a<k\): QFam\((4,k,a)\) is decomposable only if \(k=2a\), \(k=3a\) or \(2k=3a\) (an equivalence with the three splits); hence indecomposable for every \(a\) when \(\gcd (k,6)=1\).

hodge/Q4Conv.lean

/-
  hodge/Q4Conv.lean — T41 cycle 932 (goal G587b, general k): the converse of the q = 4 criterion. Write k = a + e
  (0 < a, 0 < e). The q = 4 orbit character is
    c = [4a + 3e, 3a + 2e, 2a + e, a, 4e]   at m = 4a + 4e        (= QFam(4, a + e, a))
  and if it is decomposable then a = e (k = 2a), e = 2a (k = 3a) or a = 2e (2k = 3a). With SplitFalse (q4_half,
  q4_third, q4_twothird) this is the complete criterion for every k:
    indecomposable  ⇔  k ≠ 2a ∧ k ≠ 3a ∧ 2k ≠ 3a.
  Proof: a split has a part of length 1 or 2 (5 = 1 + 4 = 2 + 3); a balanced singleton is m/2 and a balanced pair
  sums to m (PairReduce.single_iff, PairIff.pair_iff); the 5 singletons and 25 ordered pairs are settled by linear
  arithmetic in a, e (generated case list, hand proofs).

  Lean 4 core plus hodge/SplitFalse, hodge/PairReduce, hodge/Unscale (mul_cancel), hodge/BalAppend (add_cancel).
-/
import hodge.SplitFalse
import hodge.PairReduce
import hodge.Unscale

namespace Q4Conv
open Indecomp SplitFalse

theorem big (S T d : Nat) (h : S = T + d) (hd : 0 < d) : S ≠ T := by
  intro e; rw [e] at h
  have : T + 0 = T + d := by rw [Nat.add_zero]; exact h
  exact absurd (BalAppend.add_cancel _ _ _ this).symm (Nat.ne_of_gt hd)

theorem small (S T d : Nat) (h : T = S + d) (hd : 0 < d) : S ≠ T := by
  intro e; rw [e] at h
  have : T + 0 = T + d := by rw [Nat.add_zero]; exact h
  exact absurd (BalAppend.add_cancel _ _ _ this).symm (Nat.ne_of_gt hd)

def L (a e : Nat) : List Nat := [4 * a + 3 * e, 3 * a + 2 * e, 2 * a + e, a, 4 * e]

theorem mem5 {x v0 v1 v2 v3 v4 : Nat} (h : x ∈ [v0, v1, v2, v3, v4]) :
    x = v0 ∨ x = v1 ∨ x = v2 ∨ x = v3 ∨ x = v4 := by
  cases h with
  | head => exact Or.inl rfl
  | tail _ h => cases h with
    | head => exact Or.inr (Or.inl rfl)
    | tail _ h => cases h with
      | head => exact Or.inr (Or.inr (Or.inl rfl))
      | tail _ h => cases h with
        | head => exact Or.inr (Or.inr (Or.inr (Or.inl rfl)))
        | tail _ h => cases h with
          | head => exact Or.inr (Or.inr (Or.inr (Or.inr rfl)))
          | tail _ h => exact nomatch h

theorem pair_cases (a e x y : Nat) (ha : 0 < a) (he : 0 < e) (hx : x ∈ L a e) (hy : y ∈ L a e)
    (h : x + y = 4 * a + 4 * e) : a = e ∨ e = a + a ∨ a = e + e := by
  rcases mem5 hx with hx | hx | hx | hx | hx <;> rcases mem5 hy with hy | hy | hy | hy | hy <;> rw [hx, hy] at h
  · exact absurd h (big _ _ _ (by lib_nat : (4 * a + 3 * e) + (4 * a + 3 * e) = (4 * a + 4 * e) + (4 * a + 2 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 3) ha) (Nat.le_add_right _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (4 * a + 3 * e) + (3 * a + 2 * e) = (4 * a + 4 * e) + (3 * a + 1 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (4 * a + 3 * e) + (2 * a + e) = (4 * a + 4 * e) + (2 * a + 0 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _)))
  · have h2 : (4 * a + 3 * e) + a = (4 * a + 3 * e) + e := by rw [show (4 * a + 3 * e) + a = (4 * a + 3 * e) + a by lib_nat, h]; lib_nat
    exact Or.inl (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (big _ _ _ (by lib_nat : (4 * a + 3 * e) + (4 * e) = (4 * a + 4 * e) + (0 * a + 3 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) he) (Nat.le_add_left _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (3 * a + 2 * e) + (4 * a + 3 * e) = (4 * a + 4 * e) + (3 * a + 1 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (3 * a + 2 * e) + (3 * a + 2 * e) = (4 * a + 4 * e) + (2 * a + 0 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _)))
  · have h2 : (4 * a + 3 * e) + a = (4 * a + 3 * e) + e := by rw [show (4 * a + 3 * e) + a = (3 * a + 2 * e) + (2 * a + e) by lib_nat, h]; lib_nat
    exact Or.inl (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (small _ _ _ (by lib_nat : 4 * a + 4 * e = ((3 * a + 2 * e) + a) + (0 * a + 2 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) he) (Nat.le_add_left _ _)))
  · have h2 : (3 * a + 4 * e) + (e + e) = (3 * a + 4 * e) + a := by rw [show (3 * a + 4 * e) + (e + e) = (3 * a + 2 * e) + (4 * e) by lib_nat, h]; lib_nat
    exact Or.inr (Or.inr (BalAppend.add_cancel _ _ _ h2).symm)
  · exact absurd h (big _ _ _ (by lib_nat : (2 * a + e) + (4 * a + 3 * e) = (4 * a + 4 * e) + (2 * a + 0 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _)))
  · have h2 : (4 * a + 3 * e) + a = (4 * a + 3 * e) + e := by rw [show (4 * a + 3 * e) + a = (2 * a + e) + (3 * a + 2 * e) by lib_nat, h]; lib_nat
    exact Or.inl (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (small _ _ _ (by lib_nat : 4 * a + 4 * e = ((2 * a + e) + (2 * a + e)) + (0 * a + 2 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) he) (Nat.le_add_left _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 4 * a + 4 * e = ((2 * a + e) + a) + (1 * a + 3 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 0) ha) (Nat.le_add_right _ _)))
  · have h2 : (2 * a + 4 * e) + e = (2 * a + 4 * e) + (a + a) := by rw [show (2 * a + 4 * e) + e = (2 * a + e) + (4 * e) by lib_nat, h]; lib_nat
    exact Or.inr (Or.inl (BalAppend.add_cancel _ _ _ h2))
  · have h2 : (4 * a + 3 * e) + a = (4 * a + 3 * e) + e := by rw [show (4 * a + 3 * e) + a = a + (4 * a + 3 * e) by lib_nat, h]; lib_nat
    exact Or.inl (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (small _ _ _ (by lib_nat : 4 * a + 4 * e = (a + (3 * a + 2 * e)) + (0 * a + 2 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) he) (Nat.le_add_left _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 4 * a + 4 * e = (a + (2 * a + e)) + (1 * a + 3 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 0) ha) (Nat.le_add_right _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 4 * a + 4 * e = (a + a) + (2 * a + 4 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 4 * a + 4 * e = (a + (4 * e)) + (3 * a + 0 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (4 * e) + (4 * a + 3 * e) = (4 * a + 4 * e) + (0 * a + 3 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) he) (Nat.le_add_left _ _)))
  · have h2 : (3 * a + 4 * e) + (e + e) = (3 * a + 4 * e) + a := by rw [show (3 * a + 4 * e) + (e + e) = (4 * e) + (3 * a + 2 * e) by lib_nat, h]; lib_nat
    exact Or.inr (Or.inr (BalAppend.add_cancel _ _ _ h2).symm)
  · have h2 : (2 * a + 4 * e) + e = (2 * a + 4 * e) + (a + a) := by rw [show (2 * a + 4 * e) + e = (4 * e) + (2 * a + e) by lib_nat, h]; lib_nat
    exact Or.inr (Or.inl (BalAppend.add_cancel _ _ _ h2))
  · exact absurd h (small _ _ _ (by lib_nat : 4 * a + 4 * e = ((4 * e) + a) + (3 * a + 0 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _)))
  · have h2 : (4 * e) + (4 * e) = (4 * e) + (4 * a) := by rw [show (4 * e) + (4 * e) = (4 * e) + (4 * e) by lib_nat, h]; lib_nat
    exact Or.inl (Unscale.mul_cancel 4 _ _ (Nat.succ_pos 3) (BalAppend.add_cancel _ _ _ h2)).symm

theorem single_case (a e x : Nat) (ha : 0 < a) (he : 0 < e) (hx : x ∈ L a e) (h : x + x = 4 * a + 4 * e) :
    a = e ∨ e = a + a ∨ a = e + e :=
  pair_cases a e x x ha he hx hx h

theorem mem_app_inv {α : Type} (y : α) : ∀ (l r : List α), y ∈ l ++ r → y ∈ l ∨ y ∈ r
  | [], _, h => Or.inr h
  | _ :: l, r, h => by
    cases h with
    | head => exact Or.inl (List.Mem.head _)
    | tail _ h' => cases mem_app_inv y l r h' with
      | inl h1 => exact Or.inl (List.Mem.tail _ h1)
      | inr h2 => exact Or.inr h2

theorem mem_flatMap_inv {α β : Type} (f : α → List β) (y : β) : ∀ l : List α, y ∈ l.flatMap f → ∃ p, p ∈ l ∧ y ∈ f p
  | [], h => nomatch h
  | q :: l, h => by
    have h' : y ∈ f q ++ l.flatMap f := h
    cases mem_app_inv y _ _ h' with
    | inl h1 => exact ⟨q, List.Mem.head _, h1⟩
    | inr h2 => cases mem_flatMap_inv f y l h2 with
      | intro p hp => exact ⟨p, List.Mem.tail _ hp.1, hp.2⟩

theorem splits_props : ∀ (l A B : List Nat), (A, B) ∈ splits l →
    A.length + B.length = l.length ∧ (∀ x, x ∈ A → x ∈ l) ∧ (∀ x, x ∈ B → x ∈ l)
  | [], A, B, h => by
    have e : (A, B) = (([] : List Nat), ([] : List Nat)) := by
      cases h with
      | head => rfl
      | tail _ h' => exact nomatch h'
    injection e with e1 e2
    subst e1; subst e2
    refine ⟨rfl, ?_, ?_⟩
    · intro x hx; cases hx
    · intro x hx; cases hx
  | z :: l, A, B, h => by
    cases mem_flatMap_inv _ _ (splits l) h with
    | intro p hp =>
      have ih := splits_props l p.1 p.2 hp.1
      cases hp.2 with
      | head =>
        refine ⟨?_, fun x hx => ?_, fun x hx => List.Mem.tail _ (ih.2.2 x hx)⟩
        · show (p.1.length + 1) + p.2.length = l.length + 1
          rw [← ih.1]; exact Nat.succ_add _ _
        · cases hx with
          | head => exact List.Mem.head _
          | tail _ hx' => exact List.Mem.tail _ (ih.2.1 x hx')
      | tail _ h2 => cases h2 with
        | head =>
          refine ⟨?_, fun x hx => List.Mem.tail _ (ih.2.1 x hx), fun x hx => ?_⟩
          · show p.1.length + (p.2.length + 1) = l.length + 1
            rw [← ih.1]; rfl
          · cases hx with
            | head => exact List.Mem.head _
            | tail _ hx' => exact List.Mem.tail _ (ih.2.2 x hx')
        | tail _ h3 => exact nomatch h3

theorem all_false {α : Type} (f : α → Bool) : ∀ l : List α, l.all f = false → ∃ x, x ∈ l ∧ f x = false
  | [], h => nomatch h
  | y :: l, h => by
    cases hy : f y with
    | false => exact ⟨y, List.Mem.head _, hy⟩
    | true =>
      have h' : (f y && l.all f) = false := h
      rw [hy] at h'
      cases all_false f l h' with
      | intro x hx => exact ⟨x, List.Mem.tail _ hx.1, hx.2⟩

/-- A decomposable character has a nonempty balanced part of length 1 or 2 when its length is 5. -/
theorem small_part (m : Nat) (c : List Nat) (hl : c.length = 5) (h : indec m c = false) :
    (∃ x, bal m [x] = true ∧ x ∈ c) ∨ (∃ x y, bal m [x, y] = true ∧ x ∈ c ∧ y ∈ c) := by
  cases all_false _ (splits c) h with
  | intro sp hsp =>
    have hp := splits_props c sp.1 sp.2 hsp.1
    have hf : (sp.1.isEmpty || sp.2.isEmpty || !(bal m sp.1 && bal m sp.2)) = false := hsp.2
    cases h1 : sp.1.isEmpty with
    | true => rw [h1] at hf; exact nomatch hf
    | false => cases h2 : sp.2.isEmpty with
      | true => rw [h1, h2] at hf; exact nomatch hf
      | false =>
        cases hA : bal m sp.1 with
        | false => rw [h1, h2, hA] at hf; exact nomatch hf
        | true => cases hB : bal m sp.2 with
          | false => rw [h1, h2, hA, hB] at hf; exact nomatch hf
          | true =>
            have hsum := hp.1
            rw [hl] at hsum
            -- lengths: both ≥ 1, sum 5
            cases hA1 : sp.1 with
            | nil => rw [hA1] at h1; exact nomatch h1
            | cons x1 t1 => cases t1 with
              | nil => exact Or.inl ⟨x1, by rw [← hA1]; exact hA, hp.2.1 x1 (by rw [hA1]; exact List.Mem.head _)⟩
              | cons x2 t2 => cases t2 with
                | nil => exact Or.inr ⟨x1, x2, by rw [← hA1]; exact hA, hp.2.1 x1 (by rw [hA1]; exact List.Mem.head _),
                    hp.2.1 x2 (by rw [hA1]; exact List.Mem.tail _ (List.Mem.head _))⟩
                | cons x3 t3 =>
                  cases hB1 : sp.2 with
                  | nil => rw [hB1] at h2; exact nomatch h2
                  | cons y1 u1 => cases u1 with
                    | nil => exact Or.inl ⟨y1, by rw [← hB1]; exact hB, hp.2.2 y1 (by rw [hB1]; exact List.Mem.head _)⟩
                    | cons y2 u2 => cases u2 with
                      | nil => exact Or.inr ⟨y1, y2, by rw [← hB1]; exact hB, hp.2.2 y1 (by rw [hB1]; exact List.Mem.head _),
                          hp.2.2 y2 (by rw [hB1]; exact List.Mem.tail _ (List.Mem.head _))⟩
                      | cons y3 u3 =>
                        rw [hA1, hB1] at hsum
                        have : t3.length + 3 + (u3.length + 3) = 5 := hsum
                        have h6 : 6 ≤ t3.length + 3 + (u3.length + 3) :=
                          Nat.add_le_add (Nat.le_add_left 3 _) (Nat.le_add_left 3 _)
                        rw [this] at h6
                        exact absurd h6 (Nat.not_le_of_lt (Nat.lt_succ_self 5))

theorem mem_bounds (a e x : Nat) (ha : 0 < a) (he : 0 < e) (hx : x ∈ L a e) : 0 < x ∧ x < 4 * a + 4 * e := by
  rcases mem5 hx with h | h | h | h | h <;> rw [h]
  · exact ⟨Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 3) ha) (Nat.le_add_right _ _),
      Nat.add_lt_add_left (Nat.mul_lt_mul_of_pos_right (Nat.lt_succ_self 3) he) _⟩
  · exact ⟨Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _),
      Nat.add_lt_add (Nat.mul_lt_mul_of_pos_right (Nat.lt_succ_self 3) ha) (Nat.mul_lt_mul_of_pos_right (Nat.lt_of_lt_of_le (Nat.lt_succ_self 2) (Nat.le_succ 3)) he)⟩
  · exact ⟨Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _),
      Nat.add_lt_add (Nat.mul_lt_mul_of_pos_right (Nat.lt_of_lt_of_le (Nat.lt_succ_self 2) (Nat.le_succ 3)) ha)
        (by rw [show 4 * e = e + 3 * e by lib_nat]; exact Nat.lt_add_of_pos_right (Nat.mul_pos (Nat.succ_pos 2) he))⟩
  · refine ⟨ha, ?_⟩
    rw [show 4 * a + 4 * e = a + (3 * a + 4 * e) by lib_nat]
    exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _))
  · refine ⟨Nat.mul_pos (Nat.succ_pos 3) he, ?_⟩
    rw [Nat.add_comm]
    exact Nat.lt_add_of_pos_right (Nat.mul_pos (Nat.succ_pos 3) ha)

theorem m_form (a e : Nat) (ha : 0 < a) : 4 * a + 4 * e = (4 * (a - 1) + 4 * e + 2) + 2 := by
  cases a with
  | zero => exact absurd ha (Nat.lt_irrefl 0)
  | succ a' => show 4 * (a' + 1) + 4 * e = (4 * a' + 4 * e + 2) + 2; lib_nat

/-- **Converse of the q = 4 criterion, every k = a + e.** -/
theorem q4_converse (a e : Nat) (ha : 0 < a) (he : 0 < e) (h : indec (4 * a + 4 * e) (L a e) = false) :
    a = e ∨ e = a + a ∨ a = e + e := by
  have hm := m_form a e ha
  cases small_part _ (L a e) rfl h with
  | inl h1 =>
    cases h1 with
    | intro x hx =>
      have bx := mem_bounds a e x ha he hx.2
      have hb := hx.1
      rw [hm] at hb
      have s := (PairReduce.single_iff _ x bx.1 (by rw [← hm]; exact bx.2)).1 hb
      rw [← hm] at s
      exact single_case a e x ha he hx.2 s
  | inr h2 =>
    cases h2 with
    | intro x hx => cases hx with
      | intro y hy =>
        have bx := mem_bounds a e x ha he hy.2.1
        have byy := mem_bounds a e y ha he hy.2.2
        have hb := hy.1
        rw [hm] at hb
        have s := (PairIff.pair_iff _ x y bx.1 byy.1 (by rw [← hm]; exact bx.2) (by rw [← hm]; exact byy.2)).1 hb
        rw [← hm] at s
        exact pair_cases a e x y ha he hy.2.1 hy.2.2 s

/-- L a e is the q = 4 orbit character QFam(4, a + e, a). -/
theorem L_eq (a e : Nat) : PermSum.gl (fun i => a + i * (a + e)) 4 ++ [4 * (a + e) - 4 * a] = L a e := by
  show [a + 3 * (a + e), a + 2 * (a + e), a + 1 * (a + e), a + 0 * (a + e), 4 * (a + e) - 4 * a] = L a e
  have e4 : 4 * (a + e) - 4 * a = 4 * e := by
    rw [show 4 * (a + e) = 4 * e + 4 * a by lib_nat]; exact ModHand.add_sub' _ _
  rw [e4, show a + 3 * (a + e) = 4 * a + 3 * e by lib_nat, show a + 2 * (a + e) = 3 * a + 2 * e by lib_nat,
    show a + 1 * (a + e) = 2 * a + e by lib_nat, show a + 0 * (a + e) = a by lib_nat]
  rfl

/-- **Corollary (G612 for q = 4).** If k = a + e is neither even nor a multiple of 3 (e.g. k prime ≥ 5), the q = 4
    orbit character is indecomposable for every a. -/
theorem q4_coprime6 (a e : Nat) (ha : 0 < a) (he : 0 < e) (h2 : ∀ j, a + e ≠ j + j) (h3 : ∀ j, a + e ≠ 3 * j) :
    indec (4 * a + 4 * e) (L a e) = true := by
  cases hi : indec (4 * a + 4 * e) (L a e) with
  | true => rfl
  | false =>
    cases q4_converse a e ha he hi with
    | inl h => exact absurd (by rw [h]) (h2 e)
    | inr h => cases h with
      | inl h => exact absurd (by rw [h]; lib_nat) (h3 a)
      | inr h => exact absurd (by rw [h]; lib_nat) (h3 e)

end Q4Conv

#print axioms Q4Conv.pair_cases
#print axioms Q4Conv.single_case
#print axioms Q4Conv.splits_props
#print axioms Q4Conv.small_part
#print axioms Q4Conv.mem_bounds
#print axioms Q4Conv.m_form
#print axioms Q4Conv.q4_converse
#print axioms Q4Conv.L_eq
#print axioms Q4Conv.q4_coprime6

#print axioms: 9 theorems, no axioms.

81.153 The Open20 orbits via the inductive structure

Each of the nine Open20 orbits (\(m=20,21,24\)) splits as curve \(\times \) curve (zero-sum triples, fractional sums \(\{m,2m\}\)) or surface \(\times \) surface (balanced quadruples with a connecting value). Certificates by rfl; algebraicity then by Shioda’s inductive structure and Lefschetz (1,1) (cited).

hodge/CurveSplit20.lean

/-
  hodge/CurveSplit20.lean — T41 cycle 946 (goal G585 / G544b): six of the nine Open20 orbits are curve × curve.
  A fourfold character c = β ⊔ γ with |β| = |γ| = 3 and Σβ ≡ Σγ ≡ 0 (mod m) comes, by Shioda's inductive
  structure (cited, not formalized here), from H¹(C) ⊗ H¹(C) on a product of two Fermat curves of degree m.
  There it is a class of type (1,1) exactly when, for every unit t, the two fractional sums are {m, 2m}:
    tsum t β = m ∧ tsum t γ = 2m   or   tsum t β = 2m ∧ tsum t γ = m,
  and then it is algebraic by the Lefschetz (1,1) theorem (cited). The checks below are rfl:
    m = 20: [1, 1, 18] ⊔ [6, 17, 17]
    m = 21: [1, 4, 16] ⊔ [9, 15, 18],  [1, 4, 16] ⊔ [10, 13, 19]
    m = 24: [1, 1, 22] ⊔ [10, 19, 19], [1, 1, 22] ⊔ [14, 17, 17], [1, 6, 17] ⊔ [4, 22, 22]
  The m = 24 orbits [1, 1, 13, 18, 19, 20], [1, 1, 14, 17, 19, 20], [1, 8, 9, 13, 20, 21] have no zero-sum triple;
  they split as S ⊔ T with a connecting value b ≡ −ΣS, and (S, b), (T, m − b) balanced surface characters — the
  surface × surface case of the inductive structure (Hodge classes on Fermat surfaces, Lefschetz (1,1); cited):
    [1, 13, 18 | 16] ⊔ [1, 19, 20 | 8],  [1, 14, 17 | 16] ⊔ [1, 19, 20 | 8],  [1, 8, 20 | 19] ⊔ [9, 13, 21 | 5].
  So every Open20 orbit is reached by the inductive structure from curves and surfaces.

  Lean 4 core plus hodge/Indecomp (tsum), hodge/FermatPrime (units), rfl.
-/
import hodge.Indecomp

namespace CurveSplit20
open Indecomp

def lsum : List Nat → Nat
  | [] => 0
  | a :: l => a + lsum l

/-- curve × curve test: both triples sum to 0 mod m and every unit gives fractional sums {m, 2m} -/
def ccTest (m : Nat) (b g : List Nat) : Bool :=
  Nat.beq b.length 3 && Nat.beq g.length 3 && Nat.beq (lsum b % m) 0 && Nat.beq (lsum g % m) 0 &&
  (FermatPrime.units m).all (fun t =>
    (Nat.beq (tsum m t b) m && Nat.beq (tsum m t g) (2 * m)) ||
    (Nat.beq (tsum m t b) (2 * m) && Nat.beq (tsum m t g) m))

/-- the orbit representative is the concatenation, up to order -/
def splitOK (m : Nat) (c b g : List Nat) : Bool := ccTest m b g && List.isPerm (b ++ g) c

/-- surface × surface test with connecting value b: (S, b) and (T, m − b) balanced, b ≡ −ΣS, b ≠ 0 -/
def ssOK (m : Nat) (c S T : List Nat) (b : Nat) : Bool :=
  Nat.beq S.length 3 && Nat.beq T.length 3 && Nat.beq ((lsum S + b) % m) 0 && !(Nat.beq b 0) && Nat.blt b m &&
  bal m (S ++ [b]) && bal m (T ++ [m - b]) && List.isPerm (S ++ T) c

theorem cc20_0 : splitOK 20 [1, 1, 6, 17, 17, 18] [1, 1, 18] [6, 17, 17] = true := rfl
theorem cc21_1 : splitOK 21 [1, 4, 9, 15, 16, 18] [1, 4, 16] [9, 15, 18] = true := rfl
theorem cc21_2 : splitOK 21 [1, 4, 10, 13, 16, 19] [1, 4, 16] [10, 13, 19] = true := rfl
theorem cc24_3 : splitOK 24 [1, 1, 10, 19, 19, 22] [1, 1, 22] [10, 19, 19] = true := rfl
theorem cc24_5 : splitOK 24 [1, 1, 14, 17, 17, 22] [1, 1, 22] [14, 17, 17] = true := rfl
theorem cc24_7 : splitOK 24 [1, 4, 6, 17, 22, 22] [1, 6, 17] [4, 22, 22] = true := rfl

theorem ss24_4 : ssOK 24 [1, 1, 13, 18, 19, 20] [1, 13, 18] [1, 19, 20] 16 = true := rfl
theorem ss24_6 : ssOK 24 [1, 1, 14, 17, 19, 20] [1, 14, 17] [1, 19, 20] 16 = true := rfl
theorem ss24_8 : ssOK 24 [1, 8, 9, 13, 20, 21] [1, 8, 20] [9, 13, 21] 19 = true := rfl

end CurveSplit20

#print axioms CurveSplit20.cc20_0
#print axioms CurveSplit20.cc21_1
#print axioms CurveSplit20.cc21_2
#print axioms CurveSplit20.cc24_3
#print axioms CurveSplit20.cc24_5
#print axioms CurveSplit20.cc24_7
#print axioms CurveSplit20.ss24_4
#print axioms CurveSplit20.ss24_6
#print axioms CurveSplit20.ss24_8

#print axioms: 9 theorems, no axioms.

81.154 Splitting the length-6 pair check by the first entry

\(\mathrm {badP}\,m\) is the concatenation of the pieces \(\mathrm {badAt}\,m\,x\), \(1\le x<m\); checked end to end for \(m=7\). Own filter lemmas; the pieces for \(p=23\) are separate rfl modules.

hodge/Pairs6Split.lean

/-
  hodge/Pairs6Split.lean — T41 cycle 953 (goal G560): splitting the length-6 pair check by the first entry.
  sexts m = ext m (quints m) is the concatenation over the first entry x of x :: l (l ∈ quints m, head l ≥ x), so
    badP_split   badP m = flatten [badAt m x | 1 ≤ x < m]
  and badP m = [] follows from the pieces badAt m x = [], each a smaller rfl (the single rfl for p = 23 exceeded
  the recursion limit on Kamiak). Own filter lemmas (core List.filter_append, filter_cons use propext).

  Lean 4 core plus hodge/Len6Decomp (quints, sexts, ext), hodge/Indecomp (bal).
-/
import hodge.Len6Decomp

namespace Pairs6Split
open Indecomp Len6Decomp

/-- copies of Pairs6.allPairs / Pairs6.badP (Pairs6 itself is a Kamiak-only build); definitionally equal -/
def allPairs (m : Nat) : Nat → List Nat → Bool
  | 0, _ => false
  | _, [] => true
  | f + 1, x :: l => l.contains (m - x) && allPairs m f (l.erase (m - x))

def badP (m : Nat) : List (List Nat) := (sexts m).filter (fun c => bal m c && !allPairs m 7 c)

def headGe (x : Nat) (l : List Nat) : Bool := match l with
  | y :: _ => Nat.ble x y
  | [] => false

def badAt (m x : Nat) : List (List Nat) :=
  (((quints m).filter (headGe x)).map (fun l => x :: l)).filter (fun c => bal m c && !allPairs m 7 c)

theorem filter_cons2 {α : Type} (p : α → Bool) (x : α) (l : List α) :
    List.filter p (x :: l) = cond (p x) (x :: List.filter p l) (List.filter p l) := by
  show (match p x with | true => x :: List.filter p l | false => List.filter p l) = _
  cases p x <;> rfl

theorem filter_app {α : Type} (p : α → Bool) : ∀ (a b : List α), (a ++ b).filter p = a.filter p ++ b.filter p
  | [], _ => rfl
  | x :: a, b => by
    show List.filter p (x :: (a ++ b)) = List.filter p (x :: a) ++ List.filter p b
    rw [filter_cons2, filter_cons2, filter_app p a b]
    cases p x <;> rfl

theorem filter_flat_map {α β : Type} (p : α → Bool) (g : β → List α) :
    ∀ (L : List β), ((L.map g).flatten).filter p = (L.map (fun x => (g x).filter p)).flatten
  | [] => rfl
  | x :: L => by
    show (g x ++ (L.map g).flatten).filter p = (g x).filter p ++ (L.map (fun x => (g x).filter p)).flatten
    rw [filter_app, filter_flat_map p g L]

theorem badP_split (m : Nat) :
    badP m = (((List.range m).filter (fun x => Nat.ble 1 x)).map (badAt m)).flatten :=
  filter_flat_map _ _ _

theorem p7 : badP 7 = [] := by
  rw [badP_split]
  show badAt 7 1 ++ (badAt 7 2 ++ (badAt 7 3 ++ (badAt 7 4 ++ (badAt 7 5 ++ (badAt 7 6 ++ []))))) = []
  rfl

end Pairs6Split

#print axioms Pairs6Split.filter_app
#print axioms Pairs6Split.badP_split
#print axioms Pairs6Split.p7

#print axioms: 3 theorems, no axioms.

81.155 The \(q=5\) orbit characters for odd \(k\)

For odd \(k=a+e\), the character \([a,2a+e,3a+2e,4a+3e,5a+4e,5e]\) at \(m=5k\) is indecomposable. For odd \(m\) balanced parts have even length, so a split contains a pair summing to \(m\); the 36 pairs force \(k\) even.

hodge/Q5Odd.lean

/-
  hodge/Q5Odd.lean — T41 cycle 965 (goal G612, q = 5): for odd k every q = 5 orbit character is indecomposable.
  Write k = a + e (0 < a, 0 < e), m = 5k. The character is
    c = [a, 2a + e, 3a + 2e, 4a + 3e, 5a + 4e, 5e]      (= QFam(5, a + e, a))
  For odd m a balanced character has even length (t = 1 and OddLength.odd_len), so a split of the length-6 c is
  2 + 4 and has a balanced pair, i.e. two entries summing to m (PairIff.pair_iff). The 36 ordered pairs give, by
  linear arithmetic in a, e, only a = e, e = 3a or a = 3e — each makes k = a + e even. Hence for all odd k (in
  particular every prime k > 5) and all 0 < a < k, QFam(5, k, a) is indecomposable (computed: odd k < 30).

  Lean 4 core plus hodge/Q4Conv (splits_props, all_false, big, small), hodge/PairIff, hodge/OddLength,
  hodge/APPairIrrGen (units_one), hodge/Unscale (mul_cancel), hodge/BalAppend (add_cancel).
-/
import hodge.Q4Conv
import hodge.APPairIrrGen
import hodge.OddLength

namespace Q5Odd
open Indecomp Q4Conv

def L (a e : Nat) : List Nat := [1 * a + 0 * e, 2 * a + 1 * e, 3 * a + 2 * e, 4 * a + 3 * e, 5 * a + 4 * e, 0 * a + 5 * e]

/-- for odd m = n + 2 a balanced list has even length (the unit t = 1) -/
theorem even_parts (n j : Nat) (hm : n + 2 = j + j + 1) (A : List Nat) (hb : bal (n + 2) A = true) :
    ∃ q, A.length = q + q := by
  have g := APPairIrrGen.units_one n (fun t => Nat.beq (tsum (n + 2) t A + tsum (n + 2) t A) (A.length * (n + 2))) hb
  have e := Nat.eq_of_beq_eq_true g
  rw [hm] at e
  exact OddLength.odd_len j _ _ e

theorem small_part6 (n j : Nat) (hm : n + 2 = j + j + 1) (c : List Nat) (hl : c.length = 6)
    (h : indec (n + 2) c = false) : ∃ x y, bal (n + 2) [x, y] = true ∧ x ∈ c ∧ y ∈ c := by
  cases all_false _ (splits c) h with
  | intro sp hsp =>
    have hp := splits_props c sp.1 sp.2 hsp.1
    have hf : (sp.1.isEmpty || sp.2.isEmpty || !(bal (n + 2) sp.1 && bal (n + 2) sp.2)) = false := hsp.2
    cases h1 : sp.1.isEmpty with
    | true => rw [h1] at hf; exact nomatch hf
    | false => cases h2 : sp.2.isEmpty with
      | true => rw [h1, h2] at hf; exact nomatch hf
      | false =>
        cases hA : bal (n + 2) sp.1 with
        | false => rw [h1, h2, hA] at hf; exact nomatch hf
        | true => cases hB : bal (n + 2) sp.2 with
          | false => rw [h1, h2, hA, hB] at hf; exact nomatch hf
          | true =>
            have hsum := hp.1
            rw [hl] at hsum
            have evA := even_parts n j hm _ hA
            have evB := even_parts n j hm _ hB
            cases hA1 : sp.1 with
            | nil => rw [hA1] at h1; exact nomatch h1
            | cons x1 t1 => cases t1 with
              | nil =>
                rw [hA1] at evA
                have ⟨q, hq⟩ := evA
                exact absurd hq.symm (OddLength.even_ne_odd q 0)
              | cons x2 t2 => cases t2 with
                | nil => exact ⟨x1, x2, by rw [← hA1]; exact hA, hp.2.1 x1 (by rw [hA1]; exact List.Mem.head _),
                    hp.2.1 x2 (by rw [hA1]; exact List.Mem.tail _ (List.Mem.head _))⟩
                | cons x3 t3 => cases t3 with
                  | nil =>
                    rw [hA1] at evA
                    have ⟨q, hq⟩ := evA
                    exact absurd hq.symm (OddLength.even_ne_odd q 1)
                  | cons x4 t4 =>
                    cases hB1 : sp.2 with
                    | nil => rw [hB1] at h2; exact nomatch h2
                    | cons y1 u1 => cases u1 with
                      | nil =>
                        rw [hB1] at evB
                        have ⟨q, hq⟩ := evB
                        exact absurd hq.symm (OddLength.even_ne_odd q 0)
                      | cons y2 u2 => cases u2 with
                        | nil => exact ⟨y1, y2, by rw [← hB1]; exact hB, hp.2.2 y1 (by rw [hB1]; exact List.Mem.head _),
                            hp.2.2 y2 (by rw [hB1]; exact List.Mem.tail _ (List.Mem.head _))⟩
                        | cons y3 u3 =>
                          rw [hA1, hB1] at hsum
                          have : t4.length + 4 + (u3.length + 3) = 6 := hsum
                          have h7 : 7 ≤ t4.length + 4 + (u3.length + 3) :=
                            Nat.add_le_add (Nat.le_add_left 4 _) (Nat.le_add_left 3 _)
                          rw [this] at h7
                          exact absurd h7 (Nat.not_le_of_lt (Nat.lt_succ_self 6))

theorem mem6 {x v0 v1 v2 v3 v4 v5 : Nat} (h : x ∈ [v0, v1, v2, v3, v4, v5]) :
    x = v0 ∨ x = v1 ∨ x = v2 ∨ x = v3 ∨ x = v4 ∨ x = v5 := by
  cases h with
  | head => exact Or.inl rfl
  | tail _ h => cases h with
    | head => exact Or.inr (Or.inl rfl)
    | tail _ h => cases h with
      | head => exact Or.inr (Or.inr (Or.inl rfl))
      | tail _ h => cases h with
        | head => exact Or.inr (Or.inr (Or.inr (Or.inl rfl)))
        | tail _ h => cases h with
          | head => exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))
          | tail _ h => cases h with
            | head => exact Or.inr (Or.inr (Or.inr (Or.inr (Or.inr rfl))))
            | tail _ h => exact nomatch h

theorem r11 (a e : Nat) (h : 1 * a = 1 * e) : a = e ∨ e = 3 * a ∨ a = 3 * e := by
  rw [Nat.one_mul, Nat.one_mul] at h; exact Or.inl h
theorem r13 (a e : Nat) (h : 1 * a = 3 * e) : a = e ∨ e = 3 * a ∨ a = 3 * e := by
  rw [Nat.one_mul] at h; exact Or.inr (Or.inr h)
theorem r31 (a e : Nat) (h : 3 * a = 1 * e) : a = e ∨ e = 3 * a ∨ a = 3 * e := by
  rw [Nat.one_mul] at h; exact Or.inr (Or.inl h.symm)
theorem r22 (a e : Nat) (h : 2 * a = 2 * e) : a = e ∨ e = 3 * a ∨ a = 3 * e :=
  Or.inl (Unscale.mul_cancel 2 a e (Nat.succ_pos 1) h)
theorem r55 (a e : Nat) (h : 5 * a = 5 * e) : a = e ∨ e = 3 * a ∨ a = 3 * e :=
  Or.inl (Unscale.mul_cancel 5 a e (Nat.succ_pos 4) h)

theorem pair_cases (a e x y : Nat) (ha : 0 < a) (he : 0 < e) (hx : x ∈ L a e) (hy : y ∈ L a e)
    (h : x + y = 5 * a + 5 * e) : a = e ∨ e = 3 * a ∨ a = 3 * e := by
  rcases mem6 hx with hx | hx | hx | hx | hx | hx <;> rcases mem6 hy with hy | hy | hy | hy | hy | hy <;> rw [hx, hy] at h
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((1 * a + 0 * e) + (1 * a + 0 * e)) + (3 * a + 5 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((1 * a + 0 * e) + (2 * a + 1 * e)) + (2 * a + 4 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((1 * a + 0 * e) + (3 * a + 2 * e)) + (1 * a + 3 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 0) ha) (Nat.le_add_right _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((1 * a + 0 * e) + (4 * a + 3 * e)) + (0 * a + 2 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) he) (Nat.le_add_left _ _)))
  · have h2 : (5 * a + 5 * e) + 1 * a = (5 * a + 5 * e) + 1 * e := by rw [show (5 * a + 5 * e) + 1 * e = ((1 * a + 0 * e) + (5 * a + 4 * e)) + 1 * e by rw [h], show ((1 * a + 0 * e) + (5 * a + 4 * e)) + 1 * e = (5 * a + 5 * e) + 1 * a by lib_nat]
    exact r11 a e (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((1 * a + 0 * e) + (0 * a + 5 * e)) + (4 * a + 0 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 3) ha) (Nat.le_add_right _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((2 * a + 1 * e) + (1 * a + 0 * e)) + (2 * a + 4 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((2 * a + 1 * e) + (2 * a + 1 * e)) + (1 * a + 3 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 0) ha) (Nat.le_add_right _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((2 * a + 1 * e) + (3 * a + 2 * e)) + (0 * a + 2 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) he) (Nat.le_add_left _ _)))
  · have h2 : (5 * a + 5 * e) + 1 * a = (5 * a + 5 * e) + 1 * e := by rw [show (5 * a + 5 * e) + 1 * e = ((2 * a + 1 * e) + (4 * a + 3 * e)) + 1 * e by rw [h], show ((2 * a + 1 * e) + (4 * a + 3 * e)) + 1 * e = (5 * a + 5 * e) + 1 * a by lib_nat]
    exact r11 a e (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (big _ _ _ (by lib_nat : (2 * a + 1 * e) + (5 * a + 4 * e) = (5 * a + 5 * e) + (2 * a + 0 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _)))
  · have h2 : (5 * a + 5 * e) + 3 * a = (5 * a + 5 * e) + 1 * e := by rw [show (5 * a + 5 * e) + 3 * a = ((2 * a + 1 * e) + (0 * a + 5 * e)) + 3 * a by rw [h], show ((2 * a + 1 * e) + (0 * a + 5 * e)) + 3 * a = (5 * a + 5 * e) + 1 * e by lib_nat]
    exact r31 a e (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((3 * a + 2 * e) + (1 * a + 0 * e)) + (1 * a + 3 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 0) ha) (Nat.le_add_right _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((3 * a + 2 * e) + (2 * a + 1 * e)) + (0 * a + 2 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) he) (Nat.le_add_left _ _)))
  · have h2 : (5 * a + 5 * e) + 1 * a = (5 * a + 5 * e) + 1 * e := by rw [show (5 * a + 5 * e) + 1 * e = ((3 * a + 2 * e) + (3 * a + 2 * e)) + 1 * e by rw [h], show ((3 * a + 2 * e) + (3 * a + 2 * e)) + 1 * e = (5 * a + 5 * e) + 1 * a by lib_nat]
    exact r11 a e (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (big _ _ _ (by lib_nat : (3 * a + 2 * e) + (4 * a + 3 * e) = (5 * a + 5 * e) + (2 * a + 0 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (3 * a + 2 * e) + (5 * a + 4 * e) = (5 * a + 5 * e) + (3 * a + 1 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _)))
  · have h2 : (5 * a + 5 * e) + 2 * a = (5 * a + 5 * e) + 2 * e := by rw [show (5 * a + 5 * e) + 2 * a = ((3 * a + 2 * e) + (0 * a + 5 * e)) + 2 * a by rw [h], show ((3 * a + 2 * e) + (0 * a + 5 * e)) + 2 * a = (5 * a + 5 * e) + 2 * e by lib_nat]
    exact r22 a e (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((4 * a + 3 * e) + (1 * a + 0 * e)) + (0 * a + 2 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) he) (Nat.le_add_left _ _)))
  · have h2 : (5 * a + 5 * e) + 1 * a = (5 * a + 5 * e) + 1 * e := by rw [show (5 * a + 5 * e) + 1 * e = ((4 * a + 3 * e) + (2 * a + 1 * e)) + 1 * e by rw [h], show ((4 * a + 3 * e) + (2 * a + 1 * e)) + 1 * e = (5 * a + 5 * e) + 1 * a by lib_nat]
    exact r11 a e (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (big _ _ _ (by lib_nat : (4 * a + 3 * e) + (3 * a + 2 * e) = (5 * a + 5 * e) + (2 * a + 0 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (4 * a + 3 * e) + (4 * a + 3 * e) = (5 * a + 5 * e) + (3 * a + 1 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (4 * a + 3 * e) + (5 * a + 4 * e) = (5 * a + 5 * e) + (4 * a + 2 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 3) ha) (Nat.le_add_right _ _)))
  · have h2 : (5 * a + 5 * e) + 1 * a = (5 * a + 5 * e) + 3 * e := by rw [show (5 * a + 5 * e) + 1 * a = ((4 * a + 3 * e) + (0 * a + 5 * e)) + 1 * a by rw [h], show ((4 * a + 3 * e) + (0 * a + 5 * e)) + 1 * a = (5 * a + 5 * e) + 3 * e by lib_nat]
    exact r13 a e (BalAppend.add_cancel _ _ _ h2)
  · have h2 : (5 * a + 5 * e) + 1 * a = (5 * a + 5 * e) + 1 * e := by rw [show (5 * a + 5 * e) + 1 * e = ((5 * a + 4 * e) + (1 * a + 0 * e)) + 1 * e by rw [h], show ((5 * a + 4 * e) + (1 * a + 0 * e)) + 1 * e = (5 * a + 5 * e) + 1 * a by lib_nat]
    exact r11 a e (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (big _ _ _ (by lib_nat : (5 * a + 4 * e) + (2 * a + 1 * e) = (5 * a + 5 * e) + (2 * a + 0 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (5 * a + 4 * e) + (3 * a + 2 * e) = (5 * a + 5 * e) + (3 * a + 1 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (5 * a + 4 * e) + (4 * a + 3 * e) = (5 * a + 5 * e) + (4 * a + 2 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 3) ha) (Nat.le_add_right _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (5 * a + 4 * e) + (5 * a + 4 * e) = (5 * a + 5 * e) + (5 * a + 3 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 4) ha) (Nat.le_add_right _ _)))
  · exact absurd h (big _ _ _ (by lib_nat : (5 * a + 4 * e) + (0 * a + 5 * e) = (5 * a + 5 * e) + (0 * a + 4 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 3) he) (Nat.le_add_left _ _)))
  · exact absurd h (small _ _ _ (by lib_nat : 5 * a + 5 * e = ((0 * a + 5 * e) + (1 * a + 0 * e)) + (4 * a + 0 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 3) ha) (Nat.le_add_right _ _)))
  · have h2 : (5 * a + 5 * e) + 3 * a = (5 * a + 5 * e) + 1 * e := by rw [show (5 * a + 5 * e) + 3 * a = ((0 * a + 5 * e) + (2 * a + 1 * e)) + 3 * a by rw [h], show ((0 * a + 5 * e) + (2 * a + 1 * e)) + 3 * a = (5 * a + 5 * e) + 1 * e by lib_nat]
    exact r31 a e (BalAppend.add_cancel _ _ _ h2)
  · have h2 : (5 * a + 5 * e) + 2 * a = (5 * a + 5 * e) + 2 * e := by rw [show (5 * a + 5 * e) + 2 * a = ((0 * a + 5 * e) + (3 * a + 2 * e)) + 2 * a by rw [h], show ((0 * a + 5 * e) + (3 * a + 2 * e)) + 2 * a = (5 * a + 5 * e) + 2 * e by lib_nat]
    exact r22 a e (BalAppend.add_cancel _ _ _ h2)
  · have h2 : (5 * a + 5 * e) + 1 * a = (5 * a + 5 * e) + 3 * e := by rw [show (5 * a + 5 * e) + 1 * a = ((0 * a + 5 * e) + (4 * a + 3 * e)) + 1 * a by rw [h], show ((0 * a + 5 * e) + (4 * a + 3 * e)) + 1 * a = (5 * a + 5 * e) + 3 * e by lib_nat]
    exact r13 a e (BalAppend.add_cancel _ _ _ h2)
  · exact absurd h (big _ _ _ (by lib_nat : (0 * a + 5 * e) + (5 * a + 4 * e) = (5 * a + 5 * e) + (0 * a + 4 * e)) (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 3) he) (Nat.le_add_left _ _)))
  · have h2 : (5 * a + 5 * e) + 5 * a = (5 * a + 5 * e) + 5 * e := by rw [show (5 * a + 5 * e) + 5 * a = ((0 * a + 5 * e) + (0 * a + 5 * e)) + 5 * a by rw [h], show ((0 * a + 5 * e) + (0 * a + 5 * e)) + 5 * a = (5 * a + 5 * e) + 5 * e by lib_nat]
    exact r55 a e (BalAppend.add_cancel _ _ _ h2)

theorem mem_bounds6 (a e x : Nat) (ha : 0 < a) (he : 0 < e) (hx : x ∈ L a e) : 0 < x ∧ x < 5 * a + 5 * e := by
  rcases mem6 hx with h | h | h | h | h | h <;> rw [h]
  · refine ⟨(Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 0) ha) (Nat.le_add_right _ _)), ?_⟩
    rw [show 5 * a + 5 * e = (1 * a + 0 * e) + (4 * a + 5 * e) by lib_nat]
    exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 3) ha) (Nat.le_add_right _ _))
  · refine ⟨(Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _)), ?_⟩
    rw [show 5 * a + 5 * e = (2 * a + 1 * e) + (3 * a + 4 * e) by lib_nat]
    exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _))
  · refine ⟨(Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 2) ha) (Nat.le_add_right _ _)), ?_⟩
    rw [show 5 * a + 5 * e = (3 * a + 2 * e) + (2 * a + 3 * e) by lib_nat]
    exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 1) ha) (Nat.le_add_right _ _))
  · refine ⟨(Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 3) ha) (Nat.le_add_right _ _)), ?_⟩
    rw [show 5 * a + 5 * e = (4 * a + 3 * e) + (1 * a + 2 * e) by lib_nat]
    exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 0) ha) (Nat.le_add_right _ _))
  · refine ⟨(Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 4) ha) (Nat.le_add_right _ _)), ?_⟩
    rw [show 5 * a + 5 * e = (5 * a + 4 * e) + (0 * a + 1 * e) by lib_nat]
    exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 0) he) (Nat.le_add_left _ _))
  · refine ⟨(Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 4) he) (Nat.le_add_left _ _)), ?_⟩
    rw [show 5 * a + 5 * e = (0 * a + 5 * e) + (5 * a + 0 * e) by lib_nat]
    exact Nat.lt_add_of_pos_right (Nat.lt_of_lt_of_le (Nat.mul_pos (Nat.succ_pos 4) ha) (Nat.le_add_right _ _))

/-- G612 for q = 5: QFam(5, k, a) is indecomposable for every odd k = a + e -/
theorem q5_odd (a e h : Nat) (ha : 0 < a) (he : 0 < e) (hk : a + e = h + h + 1) : indec (5 * a + 5 * e) (L a e) = true := by
  cases a with
  | zero => exact absurd ha (Nat.lt_irrefl 0)
  | succ a' =>
    have hm : 5 * (a' + 1) + 5 * e = (5 * a' + 5 * e + 3) + 2 := by lib_nat
    have hodd : (5 * a' + 5 * e + 3) + 2 = (5 * h + 2) + (5 * h + 2) + 1 := by
      rw [← hm, show 5 * (a' + 1) + 5 * e = 5 * ((a' + 1) + e) by lib_nat, hk]; lib_nat
    cases hi : indec (5 * (a' + 1) + 5 * e) (L (a' + 1) e) with
    | true => rfl
    | false =>
      rw [hm] at hi
      have ⟨x, y, hb, hx, hy⟩ := small_part6 _ _ hodd (L (a' + 1) e) rfl hi
      have bx := mem_bounds6 _ _ _ ha he hx
      have by' := mem_bounds6 _ _ _ ha he hy
      rw [hm] at bx by'
      have hs := (PairIff.pair_iff _ x y bx.1 by'.1 bx.2 by'.2).mp hb
      rw [← hm] at hs
      rcases pair_cases _ _ _ _ ha he hx hy hs with r | r | r
      · rw [r] at hk; exact absurd hk (OddLength.even_ne_odd e h)
      · rw [r] at hk
        have : (a' + 1) + 3 * (a' + 1) = ((a' + 1) + (a' + 1)) + ((a' + 1) + (a' + 1)) := by lib_nat
        rw [this] at hk; exact absurd hk (OddLength.even_ne_odd _ h)
      · rw [r] at hk
        have : 3 * e + e = (e + e) + (e + e) := by lib_nat
        rw [this] at hk; exact absurd hk (OddLength.even_ne_odd _ h)

end Q5Odd

#print axioms Q5Odd.even_parts
#print axioms Q5Odd.small_part6
#print axioms Q5Odd.pair_cases
#print axioms Q5Odd.mem_bounds6
#print axioms Q5Odd.q5_odd

#print axioms: 5 theorems, no axioms.

81.156 Two length-5 seeds split along a connecting value

\([1,9,44,53,68]\) (\(m=70\)) and \([1,16,25,38,40]\) (\(m=48\)) split into a Triple-family triple and a balanced quadruple joined by a connecting value. Certificates by rfl; the other two seeds have only trivial splits (computed).

hodge/SeedGlue.lean

/-
  hodge/SeedGlue.lean — T41 cycle 983 (goals G498b, G510b): two of the four open length-5 seeds split along a
  connecting value b (b ≡ −ΣS mod m) into a balanced triple of the Triple family and a balanced quadruple
  (a Hodge character of a Fermat surface, algebraic by Lefschetz (1,1), cited):
    m = 70: [1, 9, 44, 53, 68] = [1, 53, 68 | 18] ⊔ [9, 44 | 52],   [9, 44, 52] = Triple(9)
    m = 48: [1, 16, 25, 38, 40] = [1, 25, 38 | 32] ⊔ [16, 40 | 16],  [16, 16, 40] = Triple(16)
  The other two seeds (m = 70: [1, 29, 43, 45, 57]; m = 72: [2, 10, 50, 54, 64]) have only the trivial splits
  (a singleton with its complement), computed over all 2⁵ subsets.

  Lean 4 core plus hodge/CurveSplit20 (lsum), hodge/Indecomp (bal), rfl.
-/
import hodge.CurveSplit20

namespace SeedGlue
open Indecomp CurveSplit20

/-- S ⊔ T = c (up to order), b ≡ −ΣS, (S, b) and (T, m − b) balanced -/
def glueOK (m : Nat) (c S T : List Nat) (b : Nat) : Bool :=
  Nat.beq ((lsum S + b) % m) 0 && !(Nat.beq b 0) && Nat.blt b m &&
  bal m (S ++ [b]) && bal m (T ++ [m - b]) && List.isPerm (S ++ T) c

theorem seed70 : glueOK 70 [1, 9, 44, 53, 68] [1, 53, 68] [9, 44] 18 = true := rfl
theorem seed48 : glueOK 48 [1, 16, 25, 38, 40] [1, 25, 38] [16, 40] 32 = true := rfl

end SeedGlue

#print axioms SeedGlue.seed70
#print axioms SeedGlue.seed48

#print axioms: 2 theorems, no axioms.

81.157 Balanced surface characters for \(p=31\)

Every balanced length-4 character of the degree-31 Fermat surface is two complementary pairs. With the earlier checks: all odd primes \(p\le 31\).

hodge/Pairs4c.lean

/-
  hodge/Pairs4c.lean — T41 cycle 999 (goal G529b, finite path): Pairs4 extended to the prime p = 31: every balanced
  length-4 character of the degree-31 Fermat surface is a union of two complementary pairs (rfl, no heartbeat limit).
  With Pairs4 / Pairs4b: length 4 settled for all odd primes p ≤ 31.

  Lean 4 core plus hodge/Pairs4 (badQ), rfl.
-/
import hodge.Pairs4

namespace Pairs4c
open Pairs4

set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem r31 : badQ 31 = [] := rfl

end Pairs4c

#print axioms Pairs4c.r31

#print axioms: 1 theorem, no axioms.

81.158 No complementary pair in the odd orbit characters

For odd \(q\ge 3\) and a prime \(k>q\), no two entries of \(\mathrm {QFam}(q,k,a)\) sum to \(qk\). So every decomposition splits into balanced parts of even length at least 4.

hodge/QOddPair.lean

/-
  hodge/QOddPair.lean — T41 cycle 1003 (goal G612, all odd q): for odd q ≥ 3 and a prime k > q (any 0 < a < k) no
  two entries of the orbit character QFam(q, k, a) = [a + i k (i < q), L],  L = q(k − a),  sum to m = q k:
    entry_entry   (a + i k) + (a + j k) ≠ q k          (k odd; any i, j)
    entry_last    (a + i k) + L ≠ q k                   (k prime > q; i < q)
    last_last     L + L ≠ q k                           (k odd)
  So no balanced pair (PairIff) and, m being odd, no balanced part of odd length (OddLength): every decomposition of
  QFam(q, k, a) splits into balanced parts of even length ≥ 4. For q = 5 this finishes the proof (Q5Odd); for q ≥ 7
  the remaining case is pair-free balanced parts of length ≥ 4 (G612b).

  Lean 4 core plus lib/Gcd (euclid_prime), hodge/OddLength (even_ne_odd), hodge/BalAppend (add_cancel),
  hodge/Unscale (mul_cancel), lib/Semi (lib_nat).
-/
import lib.Gcd
import hodge.OddLength
import hodge.BalAppend
import hodge.Unscale

namespace QOddPair

theorem not_dvd_small {k x : Nat} (hx : 0 < x) (hxk : x < k) (h : k ∣ x) : False := by
  cases h with
  | intro c hc =>
    cases c with
    | zero => rw [Nat.mul_zero] at hc; rw [hc] at hx; exact Nat.lt_irrefl 0 hx
    | succ c =>
      have : k ≤ x := by rw [hc, Nat.mul_succ]; exact Nat.le_add_left _ _
      exact Nat.lt_irrefl x (Nat.lt_of_lt_of_le hxk this)

theorem entry_entry (q k a i j h : Nat) (ha : 0 < a) (hak : a < k) (hodd : k = h + h + 1) : (a + i * k) + (a + j * k) ≠ q * k := by
  intro e
  have e1 : (a + a) + (i + j) * k = q * k := by rw [← e]; lib_nat
  cases Nat.lt_or_ge (i + j) q with
  | inr hge =>
    -- (a + a) + (i + j) k ≥ (a + a) + q k > q k
    have : q * k ≤ (i + j) * k := Nat.mul_le_mul_right k hge
    have h2 : q * k < (a + a) + (i + j) * k :=
      Nat.lt_of_lt_of_le (Nat.lt_add_of_pos_left (Nat.add_pos_left ha a)) (Nat.add_le_add_left this _)
    rw [e1] at h2; exact Nat.lt_irrefl _ h2
  | inl hlt =>
    cases Nat.eq_or_lt_of_le (Nat.succ_le_of_lt hlt) with
    | inl eq =>
      -- i + j + 1 = q: (a + a) + (i + j) k = (i + j) k + k ⇒ a + a = k
      rw [← eq] at e1
      have e2 : (i + j) * k + (a + a) = (i + j) * k + k := by rw [Nat.add_comm, e1, Nat.succ_mul]
      have e3 := BalAppend.add_cancel _ _ _ e2
      rw [hodd] at e3
      exact OddLength.even_ne_odd a h e3
    | inr lt2 =>
      -- i + j + 2 ≤ q: (a + a) + (i + j) k < (i + j + 2) k ≤ q k
      have h3 : (a + a) + (i + j) * k < (i + j + 2) * k := by
        rw [show (i + j + 2) * k = (k + k) + (i + j) * k by rw [Nat.succ_mul, Nat.succ_mul]; lib_nat]
        exact Nat.add_lt_add_right (Nat.add_lt_add hak hak) _
      have h4 : (i + j + 2) * k ≤ q * k := Nat.mul_le_mul_right k lt2
      have h5 := Nat.lt_of_lt_of_le h3 h4
      rw [e1] at h5; exact Nat.lt_irrefl _ h5

theorem entry_last (q k a i L : Nat) (ha : 0 < a) (hak : a < k) (hi : i < q) (hq : 2 ≤ q) (hqk : q < k)
    (hp : ∀ d, d ∣ k → d = 1 ∨ d = k) (hL : L + q * a = q * k) : (a + i * k) + L ≠ q * k := by
  intro e
  -- a + i k + L = L + q a  ⇒  a + i k = q a
  have e1 : L + (a + i * k) = L + q * a := by rw [Nat.add_comm, e, hL]
  have e2 := BalAppend.add_cancel _ _ _ e1
  -- q = q' + 1: a + i k = q' a + a ⇒ i k = q' a
  cases q with
  | zero => exact absurd hq (Nat.not_succ_le_zero 1)
  | succ q' =>
    have e3 : a + i * k = a + q' * a := by rw [e2, Nat.succ_mul, Nat.add_comm]
    have e4 := BalAppend.add_cancel _ _ _ e3
    -- k ∣ q' · a
    have hd : k ∣ q' * a := ⟨i, by rw [← e4, Nat.mul_comm]⟩
    cases LibGcd.euclid_prime hp hd with
    | inl h1 =>
      have hq'0 : 0 < q' := Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_of_succ_le_succ hq)
      exact not_dvd_small hq'0 (Nat.lt_trans (Nat.lt_succ_self q') hqk) h1
    | inr h2 => exact not_dvd_small ha hak h2

theorem last_last (q k a L h : Nat) (hq : 0 < q) (hodd : k = h + h + 1) (hL : L + q * a = q * k) : L + L ≠ q * k := by
  intro e
  have e1 : L + L = L + q * a := by rw [e, hL]
  have e2 := BalAppend.add_cancel _ _ _ e1
  -- q a + q a = q k ⇒ q (a + a) = q k ⇒ a + a = k
  have e3 : q * (a + a) = q * k := by rw [← e, e2]; lib_nat
  have e4 := Unscale.mul_cancel q _ _ hq e3
  rw [hodd] at e4
  exact OddLength.even_ne_odd a h e4

end QOddPair

#print axioms QOddPair.entry_entry
#print axioms QOddPair.entry_last
#print axioms QOddPair.last_last

#print axioms: 3 theorems, no axioms.

81.159 Balanced surface characters for \(p=37\) (Kamiak)

Every balanced length-4 character of the degree-37 Fermat surface is two complementary pairs. Length 4 is now settled for all odd primes \(p\le 37\).

hodge/Pairs4d.lean

/-
  hodge/Pairs4d.lean — T41 cycle 1001 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 37: every balanced
  length-4 character of the degree-37 Fermat surface is a union of two complementary pairs (rfl, no heartbeat limit).
  With Pairs4, Pairs4b, Pairs4c: length 4 settled for all odd primes p ≤ 37.

  Lean 4 core plus hodge/Pairs4 (badQ), rfl.
-/
import hodge.Pairs4

namespace Pairs4d
open Pairs4

set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem r37 : badQ 37 = [] := rfl

end Pairs4d

#print axioms Pairs4d.r37

#print axioms: 1 theorem, no axioms.

81.160 The orbit characters are indecomposable for prime \(k>q+1\)

For every \(q\ge 1\), prime \(k>q+1\) and \(0<a<k\), the character \([a+ik\ (i<q)]\sqcup [qk-qa]\) at \(m=qk\) has no split into two balanced parts. Only the unit \(t=1\) is used: padding each entry to a multiple of \(k\) forces a balanced part to be empty or everything.

hodge/QFamPrime.lean

/-
  hodge/QFamPrime.lean — T41 cycle 1011 (goal G612): the μ_q-orbit characters are indecomposable for every prime
  k > q + 1. For m = q k, 0 < a < k and the balanced character (QFam.qfam_bal)
    c = [a + i k (i < q)] ⊔ [L],   L = q k − q a,
  no split c = A ⊔ B has both parts balanced (qfam_indec). Proof with the unit t = 1 only:
    • every entry x has a pad p(x) with k ∣ x + p(x): p(a + i k) = k − a, p(L) = q a;
    • A balanced gives 2·ΣA = |A|·q k, so k ∣ 2·Σ_A p = 2(e·q a + s·(k − a)), e = #L in A ∈ {0, 1}, s = |A| − e;
    • e = 0: k ∣ 2 s (k − a) forces k ∣ s, impossible for 0 < s ≤ q < k;
      e = 1: k ∣ 2((q − s) a + s k) forces k ∣ q − s, impossible for 0 < q − s ≤ q < k.
  (Computed first: q ≤ 9, prime k < 30, all a.) This settles the conjecture G612 for k prime > q + 1.

  Lean 4 core plus hodge/QFam (gl), hodge/Q4Conv (splits_props, all_false, mem_flatMap_inv),
  hodge/APPairIrrGen (units_one), hodge/ModHand (mod_lt'), lib/Gcd (euclid_prime, IDv), hodge/BalAppend.
-/
import hodge.QFam
import hodge.Q4Conv
import hodge.APPairIrrGen
import hodge.QOddPair
import lib.IntRing

namespace QFamPrime
open Indecomp Q4Conv PermSum LibGcd

/-- Σ_{x ∈ A} g x -/
def gs (g : Nat → Nat) : List Nat → Nat
  | [] => 0
  | x :: l => g x + gs g l

theorem gs_app (g : Nat → Nat) : ∀ (A B : List Nat), gs g (A ++ B) = gs g A + gs g B
  | [], B => (Nat.zero_add _).symm
  | x :: A, B => by show g x + gs g (A ++ B) = g x + gs g A + gs g B; rw [gs_app g A B, Nat.add_assoc]

/-- additivity over splits -/
theorem splits_gs (g : Nat → Nat) : ∀ (l A B : List Nat), (A, B) ∈ splits l → gs g A + gs g B = gs g l
  | [], A, B, h => by
    have e : (A, B) = ([], []) := by cases h with
      | head => rfl
      | tail _ h' => exact nomatch h'
    cases e; rfl
  | z :: l, A, B, h => by
    cases mem_flatMap_inv _ _ (splits l) h with
    | intro p hp =>
      have ih := splits_gs g l p.1 p.2 hp.1
      cases hp.2 with
      | head =>
        show g z + gs g p.1 + gs g p.2 = g z + gs g l
        rw [Nat.add_assoc, ih]
      | tail _ h2 => cases h2 with
        | head =>
          show gs g p.1 + (g z + gs g p.2) = g z + gs g l
          rw [← ih, Nat.add_left_comm]
        | tail _ h3 => exact nomatch h3

theorem len_app1 (x : Nat) : ∀ (l : List Nat), (l ++ [x]).length = l.length + 1
  | [] => rfl
  | _ :: l => by show (l ++ [x]).length + 1 = l.length + 1 + 1; rw [len_app1 x l]

theorem dvd_of_add (k X Y : Nat) (h1 : k ∣ X + Y) (h2 : k ∣ Y) : k ∣ X := by
  have i1 := idv_of_nat h1
  have i2 := idv_of_nat h2
  have i3 := idv_lin i1 i2 1 (-1)
  have e : (1 : Int) * Int.ofNat (X + Y) + (-1) * Int.ofNat Y = Int.ofNat X := by
    show (1 : Int) * (Int.ofNat X + Int.ofNat Y) + (-1) * Int.ofNat Y = Int.ofNat X
    lib_int
  rw [e] at i3
  exact idv_nat i3

theorem not_dvd_small {k x : Nat} (hx : 0 < x) (hxk : x < k) (h : k ∣ x) : False := QOddPair.not_dvd_small hx hxk h

section Fam
variable (q k a : Nat)

def L : Nat := q * k - q * a
def orb : List Nat := gl (fun i => a + i * k) q
def cc : List Nat := orb q k a ++ [L q k a]

/-- indicator of the last entry -/
def isL (x : Nat) : Nat := cond (Nat.beq x (L q k a)) 1 0
def notL (x : Nat) : Nat := cond (Nat.beq x (L q k a)) 0 1
def pad (x : Nat) : Nat := cond (Nat.beq x (L q k a)) (q * a) (k - a)

theorem L_add (hak : a < k) : L q k a + q * a = q * k := by
  show q * k - q * a + q * a = q * k
  have hle : q * a ≤ q * k := Nat.mul_le_mul_left q (Nat.le_of_lt hak)
  have ⟨d, hd⟩ := LibGcd.le_dest hle
  rw [hd, Nat.add_comm (q * a) d, ModHand.add_sub' d (q * a)]

theorem beq_false {x y : Nat} (h : x ≠ y) : Nat.beq x y = false := by
  cases hb : Nat.beq x y with
  | false => rfl
  | true => exact absurd (Nat.eq_of_beq_eq_true hb) h

theorem beq_self (x : Nat) : Nat.beq x x = true := by
  cases hb : Nat.beq x x with
  | true => rfl
  | false => exact absurd rfl (Nat.ne_of_beq_eq_false hb)

variable (hp : ∀ d, d ∣ k → d = 1 ∨ d = k) (hqk : q + 1 < k) (ha : 0 < a) (hak : a < k)

include hp hqk ha hak in
theorem orb_ne (i : Nat) (hi : i < q) : a + i * k ≠ L q k a := by
  intro e
  have h1 := L_add q k a hak
  rw [← e] at h1
  -- q = i + 1 + j
  have ⟨j, hj⟩ := LibGcd.le_dest (Nat.succ_le_of_lt hi)
  rw [hj] at h1
  have h1' : a + i * k + (i + 1 + j) * a = (i + 1 + j) * k := h1
  -- a + i k + (i+1+j) a = (i+1+j) k  ⇒  (i+1+j+1) a = (1+j) k
  have e2 : i * k + ((i + 1 + j + 1) * a) = i * k + ((1 + j) * k) := by
    calc i * k + ((i + 1 + j + 1) * a) = a + i * k + (i + 1 + j) * a := by lib_nat
      _ = (i + 1 + j) * k := h1'
      _ = i * k + ((1 + j) * k) := by lib_nat
  have e3 := BalAppend.add_cancel _ _ _ e2
  have hd : k ∣ (i + 1 + j + 1) * a := ⟨1 + j, by rw [e3, Nat.mul_comm]⟩
  cases euclid_prime hp hd with
  | inl h =>
    have hq1 : i + 1 + j + 1 = q + 1 := by rw [hj]
    rw [hq1] at h
    exact not_dvd_small (Nat.succ_pos q) hqk h
  | inr h => exact not_dvd_small ha hak h

theorem mem_cc (x : Nat) (hx : x ∈ cc q k a) : (∃ i, i < q ∧ a + i * k = x) ∨ x = L q k a := by
  cases mem_app_inv x _ _ hx with
  | inl h => exact Or.inl (gl_mem _ q x h)
  | inr h => cases h with
    | head => exact Or.inr rfl
    | tail _ h' => exact nomatch h'

include hp hqk ha hak in
theorem pad_dvd (x : Nat) (hx : x ∈ cc q k a) : k ∣ x + pad q k a x := by
  cases mem_cc q k a x hx with
  | inl h =>
    have ⟨i, hi, e⟩ := h
    have hne : x ≠ L q k a := by rw [← e]; exact orb_ne q k a hp hqk ha hak i hi
    show k ∣ x + cond (Nat.beq x (L q k a)) (q * a) (k - a)
    rw [beq_false hne, ← e]
    have ⟨d, hd⟩ := LibGcd.le_dest (Nat.le_of_lt hak)
    show k ∣ a + i * k + (k - a)
    rw [hd, Nat.add_comm a d, ModHand.add_sub' d a]
    exact ⟨i + 1, by lib_nat⟩
  | inr h =>
    show k ∣ x + cond (Nat.beq x (L q k a)) (q * a) (k - a)
    rw [h, beq_self, show cond true (q * a) (k - a) = q * a from rfl, L_add q k a hak]
    exact ⟨q, Nat.mul_comm _ _⟩

include hp hqk ha hak in
theorem sum_pad_dvd : ∀ (A : List Nat), (∀ x, x ∈ A → x ∈ cc q k a) → k ∣ gs (fun x => x) A + gs (pad q k a) A
  | [], _ => ⟨0, rfl⟩
  | x :: A, h => by
    have h1 := pad_dvd q k a hp hqk ha hak x (h x (List.Mem.head _))
    have h2 := sum_pad_dvd A (fun y hy => h y (List.Mem.tail _ hy))
    have e : gs (fun x => x) (x :: A) + gs (pad q k a) (x :: A)
        = (x + pad q k a x) + (gs (fun x => x) A + gs (pad q k a) A) := by
      show x + gs (fun x => x) A + (pad q k a x + gs (pad q k a) A) = _; lib_nat
    rw [e]; exact dvd_add' h1 h2

theorem pad_split : ∀ (A : List Nat),
    gs (pad q k a) A = gs (isL q k a) A * (q * a) + gs (notL q k a) A * (k - a)
  | [] => by show 0 = 0 * (q * a) + 0 * (k - a); lib_nat
  | x :: A => by
    show pad q k a x + gs (pad q k a) A = (isL q k a x + gs (isL q k a) A) * (q * a) + (notL q k a x + gs (notL q k a) A) * (k - a)
    rw [pad_split A]
    show cond (Nat.beq x (L q k a)) (q * a) (k - a) + _
      = (cond (Nat.beq x (L q k a)) 1 0 + _) * (q * a) + (cond (Nat.beq x (L q k a)) 0 1 + _) * (k - a)
    cases Nat.beq x (L q k a) with
    | true => show q * a + _ = (1 + _) * (q * a) + (0 + _) * (k - a); lib_nat
    | false => show k - a + _ = (0 + _) * (q * a) + (1 + _) * (k - a); lib_nat

theorem len_split : ∀ (A : List Nat), gs (isL q k a) A + gs (notL q k a) A = A.length
  | [] => rfl
  | x :: A => by
    show isL q k a x + gs (isL q k a) A + (notL q k a x + gs (notL q k a) A) = A.length + 1
    rw [← len_split A]
    show cond (Nat.beq x (L q k a)) 1 0 + _ + (cond (Nat.beq x (L q k a)) 0 1 + _) = _
    cases Nat.beq x (L q k a) with
    | true => show 1 + _ + (0 + _) = _; lib_nat
    | false => show 0 + _ + (1 + _) = _; lib_nat

include hp hqk ha hak in
theorem isL_cc : gs (isL q k a) (cc q k a) = 1 := by
  have orb0 : ∀ n, n ≤ q → gs (isL q k a) (gl (fun i => a + i * k) n) = 0 := by
    intro n
    induction n with
    | zero => intro _; rfl
    | succ n ih =>
      intro hn
      show cond (Nat.beq (a + n * k) (L q k a)) 1 0 + gs (isL q k a) (gl (fun i => a + i * k) n) = 0
      rw [beq_false (orb_ne q k a hp hqk ha hak n hn), ih (Nat.le_of_succ_le hn)]
      rfl
  show gs (isL q k a) (gl (fun i => a + i * k) q ++ [L q k a]) = 1
  rw [gs_app, orb0 q (Nat.le_refl q)]
  show 0 + (cond (Nat.beq (L q k a) (L q k a)) 1 0 + 0) = 1
  rw [beq_self]
  rfl

theorem tsum_one (m : Nat) : ∀ (A : List Nat), (∀ x, x ∈ A → x < m) → tsum m 1 A = gs (fun x => x) A
  | [], _ => rfl
  | x :: A, h => by
    show (1 * x) % m + tsum m 1 A = x + gs (fun x => x) A
    rw [Nat.one_mul, ModHand.mod_lt' x m (h x (List.Mem.head _)), tsum_one m A (fun y hy => h y (List.Mem.tail _ hy))]

include ha hak in
theorem mem_lt (hq : 1 ≤ q) (x : Nat) (hx : x ∈ cc q k a) : x < q * k := by
  cases mem_cc q k a x hx with
  | inl h =>
    have ⟨i, hi, e⟩ := h
    rw [← e]
    have h1 : a + i * k < (i + 1) * k := by rw [Nat.succ_mul, Nat.add_comm (i * k) k]; exact Nat.add_lt_add_right hak _
    exact Nat.lt_of_lt_of_le h1 (Nat.mul_le_mul_right k (Nat.succ_le_of_lt hi))
  | inr h =>
    rw [h]
    have e := L_add q k a hak
    have hqa : 0 < q * a := Nat.mul_pos (Nat.lt_of_lt_of_le (Nat.succ_pos 0) hq) ha
    rw [← e]; exact Nat.lt_add_of_pos_right hqa

include hp hqk ha hak in
/-- G612 for prime k > q + 1: the μ_q-orbit character is indecomposable -/
theorem qfam_indec (hq : 1 ≤ q) : indec (q * k) (cc q k a) = true := by
  cases hind : indec (q * k) (cc q k a) with
  | true => rfl
  | false =>
    exfalso
    cases all_false _ (splits (cc q k a)) hind with
    | intro sp hsp =>
      have hpr := splits_props (cc q k a) sp.1 sp.2 hsp.1
      have hf : (sp.1.isEmpty || sp.2.isEmpty || !(bal (q * k) sp.1 && bal (q * k) sp.2)) = false := hsp.2
      cases h1 : sp.1.isEmpty with
      | true => rw [h1] at hf; exact nomatch hf
      | false => cases h2 : sp.2.isEmpty with
        | true => rw [h1, h2] at hf; exact nomatch hf
        | false => cases hA : bal (q * k) sp.1 with
          | false => rw [h1, h2, hA] at hf; exact nomatch hf
          | true =>
            -- qk = n + 2
            have hk3 : 2 ≤ q * k := Nat.le_trans (Nat.le_of_lt (Nat.lt_of_le_of_lt (Nat.succ_le_succ hq) hqk))
              (by have := Nat.mul_le_mul_right k hq; rw [Nat.one_mul] at this; exact this)
            have ⟨n, hn⟩ := LibGcd.le_dest hk3
            have hA' : bal (n + 2) sp.1 = true := by rw [Nat.add_comm n 2, ← hn]; exact hA
            have g1 := APPairIrrGen.units_one n
              (fun t => Nat.beq (tsum (n + 2) t sp.1 + tsum (n + 2) t sp.1) (sp.1.length * (n + 2))) hA'
            have eq1 := Nat.eq_of_beq_eq_true g1
            rw [show n + 2 = q * k by rw [hn, Nat.add_comm]] at eq1
            rw [tsum_one (q * k) sp.1 (fun x hx => mem_lt q k a ha hak hq x (hpr.2.1 x hx))] at eq1
            -- k ∣ 2 Σ pad
            have d1 := sum_pad_dvd q k a hp hqk ha hak sp.1 hpr.2.1
            have d2 : k ∣ (gs (fun x => x) sp.1 + gs (fun x => x) sp.1) + (gs (pad q k a) sp.1 + gs (pad q k a) sp.1) := by
              have := dvd_add' d1 d1
              rw [show gs (fun x => x) sp.1 + gs (pad q k a) sp.1 + (gs (fun x => x) sp.1 + gs (pad q k a) sp.1)
                = (gs (fun x => x) sp.1 + gs (fun x => x) sp.1) + (gs (pad q k a) sp.1 + gs (pad q k a) sp.1) by lib_nat] at this
              exact this
            have d3 : k ∣ gs (fun x => x) sp.1 + gs (fun x => x) sp.1 := ⟨sp.1.length * q, by rw [eq1]; lib_nat⟩
            have d4 := dvd_of_add k _ _ (by rw [Nat.add_comm] at d2; exact d2) d3
            -- counts
            have hsum := splits_gs (isL q k a) (cc q k a) sp.1 sp.2 hsp.1
            rw [isL_cc q k a hp hqk ha hak] at hsum
            have hlen := len_split q k a sp.1
            have hlc : (cc q k a).length = q + 1 := by
              show (gl (fun i => a + i * k) q ++ [L q k a]).length = q + 1
              rw [len_app1, gl_len]
            have hAB := hpr.1
            rw [hlc] at hAB
            rw [pad_split q k a sp.1] at d4
            have ⟨d, hd⟩ := LibGcd.le_dest (Nat.le_of_lt hak)
            have hka : k - a = d := by rw [hd, Nat.add_comm a d, ModHand.add_sub' d a]
            rw [hka] at d4
            -- B nonempty: |A| ≤ q; A nonempty: |A| ≥ 1
            have hBpos : 1 ≤ sp.2.length := by
              cases hB0 : sp.2 with
              | nil => rw [hB0] at h2; exact nomatch h2
              | cons _ _ => exact Nat.succ_le_succ (Nat.zero_le _)
            have hApos : 1 ≤ sp.1.length := by
              cases hA0 : sp.1 with
              | nil => rw [hA0] at h1; exact nomatch h1
              | cons _ _ => exact Nat.succ_le_succ (Nat.zero_le _)
            have hAq : sp.1.length ≤ q := by
              have : sp.1.length + 1 ≤ sp.1.length + sp.2.length := Nat.add_le_add_left hBpos _
              rw [hAB] at this; exact Nat.le_of_succ_le_succ this
            have hk2 : ¬ (k ∣ 2) := fun h => not_dvd_small (Nat.succ_pos 1)
              (Nat.lt_of_le_of_lt (Nat.succ_le_succ hq) hqk) h
            generalize he : gs (isL q k a) sp.1 = e at hsum hlen d4
            generalize hs : gs (notL q k a) sp.1 = s at hlen d4
            cases e with
            | zero =>
              -- k ∣ 2 s d with 0 < s ≤ q < k, 0 < d < k
              have hs' : s = sp.1.length := by rw [← hlen]; exact (Nat.zero_add s).symm
              have e5 : 0 * (q * a) + s * d + (0 * (q * a) + s * d) = 2 * (s * d) := by lib_nat
              rw [e5] at d4
              cases euclid_prime hp d4 with
              | inl h => exact hk2 h
              | inr h => cases euclid_prime hp h with
                | inl h' =>
                  rw [hs'] at h'
                  exact not_dvd_small (Nat.lt_of_lt_of_le (Nat.succ_pos 0) hApos)
                    (Nat.lt_of_le_of_lt hAq (Nat.lt_trans (Nat.lt_succ_self q) hqk)) h'
                | inr h' =>
                  have dpos : 0 < d := by
                    cases d with
                    | zero => rw [Nat.add_zero] at hd; rw [hd] at hak; exact absurd hak (Nat.lt_irrefl a)
                    | succ d => exact Nat.succ_pos d
                  have dlt : d < k := by rw [hd]; exact Nat.lt_add_of_pos_left ha
                  exact not_dvd_small dpos dlt h'
            | succ e' =>
              cases e' with
              | succ e'' =>
                -- e ≥ 2 contradicts e_A + e_B = 1
                have : 2 ≤ 1 := by rw [← hsum]; exact Nat.le_trans (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le e''))) (Nat.le_add_right _ _)
                exact absurd this (Nat.not_succ_le_self 1)
              | zero =>
                -- e = 1, s = |A| − 1 ≤ q − 1: q = s + r with r ≥ 1
                have hsq : s + 1 ≤ q := by
                  have : 1 + s = sp.1.length := hlen
                  rw [Nat.add_comm] at this; rw [this]; exact hAq
                have ⟨r, hr⟩ := LibGcd.le_dest hsq
                -- 2(q a + s d) = 2((r+1) a) + 2 s k
                have e6 : (0 + 1) * (q * a) + s * d + ((0 + 1) * (q * a) + s * d) = 2 * ((r + 1) * a) + (2 * s) * k := by
                  rw [hr, hd]; lib_nat
                rw [e6] at d4
                have d5 := dvd_of_add k _ _ d4 ⟨2 * s, Nat.mul_comm _ _⟩
                cases euclid_prime hp d5 with
                | inl h => exact hk2 h
                | inr h => cases euclid_prime hp h with
                  | inl h' =>
                    have rle : r + 1 ≤ q := by
                      rw [hr, show s + 1 + r = (r + 1) + s by lib_nat]; exact Nat.le_add_right _ _
                    exact not_dvd_small (Nat.succ_pos r) (Nat.lt_of_le_of_lt rle (Nat.lt_trans (Nat.lt_succ_self q) hqk)) h'
                  | inr h' => exact not_dvd_small ha hak h'

end Fam

end QFamPrime

#print axioms QFamPrime.splits_gs
#print axioms QFamPrime.dvd_of_add
#print axioms QFamPrime.orb_ne
#print axioms QFamPrime.pad_dvd
#print axioms QFamPrime.sum_pad_dvd
#print axioms QFamPrime.pad_split
#print axioms QFamPrime.len_split
#print axioms QFamPrime.isL_cc
#print axioms QFamPrime.tsum_one
#print axioms QFamPrime.mem_lt
#print axioms QFamPrime.qfam_indec

#print axioms: 12 theorems, no axioms.

81.161 The case \(k=q+1\)

When \(k=q+1\) is prime (\(q\ge 2\)), \(\mathrm {QFam}(q,k,a)\) is indecomposable: all entries are \(\equiv a\pmod k\), so a balanced part has size divisible by \(k\). With the previous subsection: indecomposable for every prime \(k>q\).

hodge/QFamPrimeQ1.lean

/-
  hodge/QFamPrimeQ1.lean — T41 cycle 1013 (goal G612c): the remaining case k = q + 1 prime of G612. Then L = qk − qa
  ≡ a (mod k), so every entry x of c = [a + i k (i < q)] ⊔ [L] has the same pad: k ∣ x + (k − a). A balanced part A has
  2ΣA = |A|qk, hence k ∣ 2|A|(k − a), so k ∣ |A| — impossible for 0 < |A| ≤ q < k. Hence QFam(q, q+1, a) is
  indecomposable for prime q + 1 ≥ 3 (computed first: q = 2, 4, 6, 10). With QFamPrime: G612 holds for every prime
  k > q.

  Lean 4 core plus hodge/QFamPrime (gs, tsum_one, mem_cc, mem_lt, dvd_of_add, splits machinery).
-/
import hodge.QFamPrime

namespace QFamPrimeQ1
open Indecomp Q4Conv PermSum LibGcd QFamPrime

theorem pad1_dvd (q k a : Nat) (hk : k = q + 1) (hak : a < k) (x : Nat) (hx : x ∈ cc q k a) : k ∣ x + (k - a) := by
  have ⟨d, hd⟩ := LibGcd.le_dest (Nat.le_of_lt hak)
  have hka : k - a = d := by rw [hd, Nat.add_comm a d, ModHand.add_sub' d a]
  rw [hka]
  cases mem_cc q k a x hx with
  | inl h =>
    have ⟨i, _, e⟩ := h
    rw [← e]; exact ⟨i + 1, by rw [hd]; lib_nat⟩
  | inr h =>
    rw [h]
    have e := L_add q k a hak
    -- L + qa = qk, k = a + d, k = q + 1  ⇒  L + d = k d
    refine ⟨d, ?_⟩
    have e2 : (L q k a + d) + (q + 1) * a = k * d + (q + 1) * a := by
      have e3 : (L q k a + d) + (q + 1) * a = (L q k a + q * a) + (a + d) := by lib_nat
      rw [e3, e, ← hd]
      rw [show q * k + k = (q + 1) * k by lib_nat, ← hk, hd]; lib_nat
    exact (BalAppend.add_cancel _ _ _ (by rw [Nat.add_comm _ ((q + 1) * a), Nat.add_comm (k * d)] at e2; exact e2))

theorem sum_pad1 (q k a : Nat) (hk : k = q + 1) (hak : a < k) :
    ∀ (A : List Nat), (∀ x, x ∈ A → x ∈ cc q k a) → k ∣ gs (fun x => x) A + A.length * (k - a)
  | [], _ => ⟨0, by show 0 + 0 * (k - a) = k * 0; lib_nat⟩
  | x :: A, h => by
    have h1 := pad1_dvd q k a hk hak x (h x (List.Mem.head _))
    have h2 := sum_pad1 q k a hk hak A (fun y hy => h y (List.Mem.tail _ hy))
    have e : gs (fun x => x) (x :: A) + (A.length + 1) * (k - a)
        = (x + (k - a)) + (gs (fun x => x) A + A.length * (k - a)) := by
      show x + gs (fun x => x) A + (A.length + 1) * (k - a) = _; rw [Nat.succ_mul]; lib_nat
    show k ∣ gs (fun x => x) (x :: A) + (A.length + 1) * (k - a)
    rw [e]; exact dvd_add' h1 h2

/-- G612c: QFam(q, q + 1, a) is indecomposable when q + 1 is prime (q ≥ 2) -/
theorem qfam_indec_q1 (q k a : Nat) (hk : k = q + 1) (hq : 2 ≤ q) (hp : ∀ d, d ∣ k → d = 1 ∨ d = k)
    (ha : 0 < a) (hak : a < k) : indec (q * k) (cc q k a) = true := by
  have hq1 : 1 ≤ q := Nat.le_trans (Nat.le_succ 1) hq
  cases hind : indec (q * k) (cc q k a) with
  | true => rfl
  | false =>
    exfalso
    cases all_false _ (splits (cc q k a)) hind with
    | intro sp hsp =>
      have hpr := splits_props (cc q k a) sp.1 sp.2 hsp.1
      have hf : (sp.1.isEmpty || sp.2.isEmpty || !(bal (q * k) sp.1 && bal (q * k) sp.2)) = false := hsp.2
      cases h1 : sp.1.isEmpty with
      | true => rw [h1] at hf; exact nomatch hf
      | false => cases h2 : sp.2.isEmpty with
        | true => rw [h1, h2] at hf; exact nomatch hf
        | false => cases hA : bal (q * k) sp.1 with
          | false => rw [h1, h2, hA] at hf; exact nomatch hf
          | true =>
            have hk3 : 2 ≤ q * k := Nat.le_trans hq (by
              have := Nat.mul_le_mul_left q (show 1 ≤ k by rw [hk]; exact Nat.succ_le_succ (Nat.zero_le q))
              rw [Nat.mul_one] at this; exact this)
            have ⟨n, hn⟩ := LibGcd.le_dest hk3
            have hA' : bal (n + 2) sp.1 = true := by rw [Nat.add_comm n 2, ← hn]; exact hA
            have g1 := APPairIrrGen.units_one n
              (fun t => Nat.beq (tsum (n + 2) t sp.1 + tsum (n + 2) t sp.1) (sp.1.length * (n + 2))) hA'
            have eq1 := Nat.eq_of_beq_eq_true g1
            rw [show n + 2 = q * k by rw [hn, Nat.add_comm]] at eq1
            rw [tsum_one (q * k) sp.1 (fun x hx => mem_lt q k a ha hak hq1 x (hpr.2.1 x hx))] at eq1
            have d1 := sum_pad1 q k a hk hak sp.1 hpr.2.1
            have d2 := dvd_add' d1 d1
            rw [show gs (fun x => x) sp.1 + sp.1.length * (k - a) + (gs (fun x => x) sp.1 + sp.1.length * (k - a))
              = (gs (fun x => x) sp.1 + gs (fun x => x) sp.1) + 2 * (sp.1.length * (k - a)) by lib_nat] at d2
            have d3 : k ∣ gs (fun x => x) sp.1 + gs (fun x => x) sp.1 := ⟨sp.1.length * q, by rw [eq1]; lib_nat⟩
            have d4 := dvd_of_add k _ _ (by rw [Nat.add_comm] at d2; exact d2) d3
            have ⟨d, hd⟩ := LibGcd.le_dest (Nat.le_of_lt hak)
            have hka : k - a = d := by rw [hd, Nat.add_comm a d, ModHand.add_sub' d a]
            rw [hka] at d4
            have hlc : (cc q k a).length = q + 1 := by
              show (gl (fun i => a + i * k) q ++ [L q k a]).length = q + 1
              rw [len_app1, gl_len]
            have hAB := hpr.1
            rw [hlc] at hAB
            have hBpos : 1 ≤ sp.2.length := by
              cases hB0 : sp.2 with
              | nil => rw [hB0] at h2; exact nomatch h2
              | cons _ _ => exact Nat.succ_le_succ (Nat.zero_le _)
            have hApos : 0 < sp.1.length := by
              cases hA0 : sp.1 with
              | nil => rw [hA0] at h1; exact nomatch h1
              | cons _ _ => exact Nat.succ_pos _
            have hAq : sp.1.length < k := by
              have : sp.1.length + 1 ≤ sp.1.length + sp.2.length := Nat.add_le_add_left hBpos _
              rw [hAB, ← hk] at this; exact this
            cases euclid_prime hp d4 with
            | inl h => exact not_dvd_small (Nat.succ_pos 1) (by rw [hk]; exact Nat.succ_lt_succ hq) h
            | inr h => cases euclid_prime hp h with
              | inl h' => exact not_dvd_small hApos hAq h'
              | inr h' =>
                have dpos : 0 < d := by
                  cases d with
                  | zero => rw [Nat.add_zero] at hd; rw [hd] at hak; exact absurd hak (Nat.lt_irrefl a)
                  | succ d => exact Nat.succ_pos d
                exact not_dvd_small dpos (by rw [hd]; exact Nat.lt_add_of_pos_left ha) h'

end QFamPrimeQ1

#print axioms QFamPrimeQ1.pad1_dvd
#print axioms QFamPrimeQ1.sum_pad1
#print axioms QFamPrimeQ1.qfam_indec_q1

#print axioms: 3 theorems, no axioms.

81.162 The half-twisted orbit characters are indecomposable for prime \(k>2q+1\)

For even \(q\), prime \(k>2q+1\): \([a+ik\ (i<q)]\sqcup [h+qa,\,m-2qa]\) (\(m=qk=2h\), \(qa<h\)) has no split into two balanced parts. Same \(t=1\) padding argument with three residue classes \(a,\ qa,\ -2qa\) modulo \(k\).

hodge/QFamHalfPrime.lean

/-
  hodge/QFamHalfPrime.lean — T41 cycle 1015 (goal G667): the half-twisted orbit characters are indecomposable for
  prime k > 2q + 1. For even q = 2r, m = q k = h + h (h = r k), 0 < a < k with q a < h, the balanced character
  (QFamHalf.qfam_half)
    c = [a + i k (i < q)] ⊔ [V₁, V₂],   V₁ = h + q a,   V₂ = m − 2 q a
  has no split into two balanced parts (qfamhalf_indec). Same t = 1 padding argument as QFamPrime, with
  d = k − a: pads d (orbit), q d (V₁: V₁ + q d = (r + q) k), 2 q a (V₂: V₂ + 2 q a = q k). For a balanced part A with
  e₁ = #V₁, e₂ = #V₂, s = #orbit entries:
    e₂ = 0:  k ∣ 2 (s + e₁ q) d   ⇒ s + e₁ q = 0 (0 < s + e₁q ≤ 2q < k otherwise) ⇒ A = ∅;
    e₂ = 1:  k ∣ 2 w d with w = 2q − s − e₁ q ⇒ w = 0 ⇒ s = q, e₁ = 1 ⇒ B = ∅.
  The three values are distinct because k ∤ q − 1, k ∤ 2q + 1, k ∤ 3q. Computed first: q = 2, 4, 6, prime k < 40.

  Lean 4 core plus hodge/QFamPrime (gs, splits_gs, dvd_of_add, tsum_one, beq lemmas), hodge/QFamHalf.
-/
import hodge.QFamPrime
import hodge.QFamHalf

namespace QFamHalfPrime
open Indecomp Q4Conv PermSum LibGcd QFamPrime

section Fam
variable (r k a : Nat)

def V1 : Nat := r * k + (r + r) * a
def V2 : Nat := (r * k + r * k) - ((r + r) * a + (r + r) * a)
def ch : List Nat := gl (fun i => a + i * k) (r + r) ++ [V1 r k a, V2 r k a]

def is1 (x : Nat) : Nat := cond (Nat.beq x (V1 r k a)) 1 0
def is2 (x : Nat) : Nat := cond (Nat.beq x (V1 r k a)) 0 (cond (Nat.beq x (V2 r k a)) 1 0)
def isO (x : Nat) : Nat := cond (Nat.beq x (V1 r k a)) 0 (cond (Nat.beq x (V2 r k a)) 0 1)
def padH (x : Nat) : Nat :=
  cond (Nat.beq x (V1 r k a)) ((r + r) * (k - a)) (cond (Nat.beq x (V2 r k a)) (2 * ((r + r) * a)) (k - a))

theorem V2_add (hqa : (r + r) * a + (r + r) * a ≤ r * k + r * k) :
    V2 r k a + 2 * ((r + r) * a) = (r + r) * k := by
  show (r * k + r * k) - ((r + r) * a + (r + r) * a) + 2 * ((r + r) * a) = (r + r) * k
  have ⟨d, hd⟩ := LibGcd.le_dest hqa
  rw [hd, Nat.add_comm ((r + r) * a + (r + r) * a) d, ModHand.add_sub' d]
  have : d + 2 * ((r + r) * a) = (r + r) * a + (r + r) * a + d := by lib_nat
  rw [this, ← hd]; lib_nat

variable (hp : ∀ d, d ∣ k → d = 1 ∨ d = k) (hk : 2 * (r + r) + 1 < k) (hr : 1 ≤ r) (ha : 0 < a) (hak : a < k)
  (hqa : (r + r) * a < r * k)

theorem hqa_le (hqa : (r + r) * a < r * k) : (r + r) * a + (r + r) * a ≤ r * k + r * k :=
  Nat.add_le_add (Nat.le_of_lt hqa) (Nat.le_of_lt hqa)

theorem kd (hak : a < k) : ∃ d, k = a + d ∧ k - a = d ∧ 0 < d := by
  have ⟨d, hd⟩ := LibGcd.le_dest (Nat.le_of_lt hak)
  refine ⟨d, hd, by rw [hd, Nat.add_comm a d, ModHand.add_sub' d a], ?_⟩
  cases d with
  | zero => rw [Nat.add_zero] at hd; rw [hd] at hak; exact absurd hak (Nat.lt_irrefl a)
  | succ d => exact Nat.succ_pos d

theorem small_ndvd (x : Nat) (hx : 0 < x) (hxk : x < k) : ¬ k ∣ x := fun h => not_dvd_small hx hxk h

include hp hk hr ha hak in
theorem ne1 (i : Nat) (hi : i < r + r) : a + i * k ≠ V1 r k a := by
  intro e
  have e' : a + i * k = r * k + (r + r) * a := e
  -- q − 1 = r + r1 with r = r1 + 1
  cases r with
  | zero => exact absurd hr (Nat.lt_irrefl 0)
  | succ r1 =>
    cases Nat.lt_or_ge i (r1 + 1) with
    | inl hlt =>
      -- i k < (r1+1) k ≤ rhs − a
      have h1 : i * k < (r1 + 1) * k := Nat.mul_lt_mul_of_pos_right hlt (Nat.lt_trans ha hak)
      have h2 : a + i * k < a + (r1 + 1) * k := Nat.add_lt_add_left h1 a
      have h3 : a + (r1 + 1) * k ≤ (r1 + 1) * k + (r1 + 1 + (r1 + 1)) * a := by
        rw [Nat.add_comm a]
        exact Nat.add_le_add_left (by
          rw [show (r1 + 1 + (r1 + 1)) * a = a + (r1 + r1 + 1) * a by lib_nat]; exact Nat.le_add_right a _) _
      rw [e'] at h2; exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le h2 h3)
    | inr hge =>
      have ⟨j, hj⟩ := LibGcd.le_dest hge
      rw [hj] at e'
      -- a + (r1+1+j) k = (r1+1) k + (2r1+2) a  ⇒  j k = (2 r1 + 1) a
      have e2 : (r1 + 1) * k + a + j * k = (r1 + 1) * k + a + (r1 + r1 + 1) * a := by
        calc (r1 + 1) * k + a + j * k = a + (r1 + 1 + j) * k := by lib_nat
          _ = (r1 + 1) * k + (r1 + 1 + (r1 + 1)) * a := e'
          _ = _ := by lib_nat
      have e3 := BalAppend.add_cancel _ _ _ e2
      have hd : k ∣ (r1 + r1 + 1) * a := ⟨j, by rw [← e3, Nat.mul_comm]⟩
      cases euclid_prime hp hd with
      | inl h =>
        have lt1 : r1 + r1 + 1 < 2 * (r1 + 1 + (r1 + 1)) + 1 := by
          rw [show 2 * (r1 + 1 + (r1 + 1)) + 1 = (r1 + r1 + 1) + ((r1 + r1 + 3) + 1) by lib_nat]
          exact Nat.lt_add_of_pos_right (Nat.succ_pos _)
        exact small_ndvd k _ (Nat.succ_pos _) (Nat.lt_trans lt1 hk) h
      | inr h => exact small_ndvd k a ha hak h

include hp hk ha hak hqa in
theorem ne2 (i : Nat) (hi : i < r + r) : a + i * k ≠ V2 r k a := by
  intro e
  have h1 := V2_add r k a (hqa_le r k a hqa)
  rw [← e] at h1
  have ⟨j, hj⟩ := LibGcd.le_dest (Nat.succ_le_of_lt hi)
  have e2 : i * k + (2 * (r + r) + 1) * a = i * k + (1 + j) * k := by
    calc i * k + (2 * (r + r) + 1) * a = a + i * k + 2 * ((r + r) * a) := by lib_nat
      _ = (r + r) * k := h1
      _ = (i + 1 + j) * k := by rw [← hj]
      _ = _ := by lib_nat
  have e3 := BalAppend.add_cancel _ _ _ e2
  have hd : k ∣ (2 * (r + r) + 1) * a := ⟨1 + j, by rw [e3, Nat.mul_comm]⟩
  cases euclid_prime hp hd with
  | inl h => exact small_ndvd k _ (Nat.succ_pos _) hk h
  | inr h => exact small_ndvd k a ha hak h

include hp hk hr ha hak hqa in
theorem ne12 : V1 r k a ≠ V2 r k a := by
  intro e
  have h1 := V2_add r k a (hqa_le r k a hqa)
  rw [← e] at h1
  have e2 : r * k + 3 * ((r + r) * a) = r * k + r * k := by
    calc r * k + 3 * ((r + r) * a) = V1 r k a + 2 * ((r + r) * a) := by show _ = r * k + (r + r) * a + _; lib_nat
      _ = (r + r) * k := h1
      _ = _ := by lib_nat
  have e3 := BalAppend.add_cancel _ _ _ e2
  have hd : k ∣ 3 * ((r + r) * a) := ⟨r, by rw [e3, Nat.mul_comm]⟩
  have hq0 : 0 < r + r := Nat.lt_of_lt_of_le hr (Nat.le_add_right r r)
  have hqk : r + r < k := Nat.lt_trans (Nat.lt_of_lt_of_le (Nat.lt_succ_self _)
    (show r + r + 1 ≤ 2 * (r + r) + 1 by rw [show 2 * (r + r) + 1 = (r + r + 1) + (r + r) by lib_nat]; exact Nat.le_add_right _ _)) hk
  cases euclid_prime hp hd with
  | inl h =>
    have h3le : 3 ≤ 2 * (r + r) + 1 := by
      have ⟨t, ht⟩ := LibGcd.le_dest hr
      rw [ht, show 2 * (1 + t + (1 + t)) + 1 = 3 + (4 * t + 2) by lib_nat]
      exact Nat.le_add_right _ _
    have h3 : 3 < k := Nat.lt_of_le_of_lt h3le hk
    exact small_ndvd k 3 (Nat.succ_pos 2) h3 h
  | inr h => cases euclid_prime hp h with
    | inl h' => exact small_ndvd k _ hq0 hqk h'
    | inr h' => exact small_ndvd k a ha hak h'

theorem mem_ch (x : Nat) (hx : x ∈ ch r k a) : (∃ i, i < r + r ∧ a + i * k = x) ∨ x = V1 r k a ∨ x = V2 r k a := by
  cases mem_app_inv x _ _ hx with
  | inl h => exact Or.inl (gl_mem _ (r + r) x h)
  | inr h => cases h with
    | head => exact Or.inr (Or.inl rfl)
    | tail _ h' => cases h' with
      | head => exact Or.inr (Or.inr rfl)
      | tail _ h'' => exact nomatch h''

include hp hk hr ha hak hqa in
theorem padH_dvd (x : Nat) (hx : x ∈ ch r k a) : k ∣ x + padH r k a x := by
  have ⟨d, hd, hkd, _⟩ := kd k a hak
  cases mem_ch r k a x hx with
  | inl h =>
    have ⟨i, hi, e⟩ := h
    have n1 : x ≠ V1 r k a := by rw [← e]; exact ne1 r k a hp hk hr ha hak i hi
    have n2 : x ≠ V2 r k a := by rw [← e]; exact ne2 r k a hp hk ha hak hqa i hi
    show k ∣ x + cond (Nat.beq x (V1 r k a)) _ (cond (Nat.beq x (V2 r k a)) _ (k - a))
    rw [beq_false n1, beq_false n2]
    show k ∣ x + (k - a)
    rw [hkd, ← e]
    exact ⟨i + 1, by rw [hd]; lib_nat⟩
  | inr h => cases h with
    | inl h1 =>
      show k ∣ x + cond (Nat.beq x (V1 r k a)) ((r + r) * (k - a)) _
      rw [h1, beq_self, hkd]
      exact ⟨r + (r + r), by show r * k + (r + r) * a + (r + r) * d = _; rw [hd]; lib_nat⟩
    | inr h2 =>
      show k ∣ x + cond (Nat.beq x (V1 r k a)) _ (cond (Nat.beq x (V2 r k a)) (2 * ((r + r) * a)) _)
      rw [h2, beq_false (fun e => ne12 r k a hp hk hr ha hak hqa e.symm), beq_self]
      show k ∣ V2 r k a + 2 * ((r + r) * a)
      rw [V2_add r k a (hqa_le r k a hqa)]
      exact ⟨r + r, Nat.mul_comm _ _⟩

include hp hk hr ha hak hqa in
theorem sum_padH_dvd : ∀ (A : List Nat), (∀ x, x ∈ A → x ∈ ch r k a) → k ∣ gs (fun x => x) A + gs (padH r k a) A
  | [], _ => ⟨0, rfl⟩
  | x :: A, h => by
    have h1 := padH_dvd r k a hp hk hr ha hak hqa x (h x (List.Mem.head _))
    have h2 := sum_padH_dvd A (fun y hy => h y (List.Mem.tail _ hy))
    have e : gs (fun x => x) (x :: A) + gs (padH r k a) (x :: A)
        = (x + padH r k a x) + (gs (fun x => x) A + gs (padH r k a) A) := by
      show x + gs (fun x => x) A + (padH r k a x + gs (padH r k a) A) = _; lib_nat
    rw [e]; exact dvd_add' h1 h2

theorem padH_split : ∀ (A : List Nat),
    gs (padH r k a) A = gs (is1 r k a) A * ((r + r) * (k - a)) + gs (is2 r k a) A * (2 * ((r + r) * a))
      + gs (isO r k a) A * (k - a)
  | [] => by show 0 = 0 * _ + 0 * _ + 0 * _; lib_nat
  | x :: A => by
    show padH r k a x + gs (padH r k a) A = (is1 r k a x + gs (is1 r k a) A) * ((r + r) * (k - a))
      + (is2 r k a x + gs (is2 r k a) A) * (2 * ((r + r) * a)) + (isO r k a x + gs (isO r k a) A) * (k - a)
    rw [padH_split A]
    show cond (Nat.beq x (V1 r k a)) _ (cond (Nat.beq x (V2 r k a)) _ _) + _
      = (cond (Nat.beq x (V1 r k a)) 1 0 + _) * _ + (cond (Nat.beq x (V1 r k a)) 0 (cond (Nat.beq x (V2 r k a)) 1 0) + _) * _
        + (cond (Nat.beq x (V1 r k a)) 0 (cond (Nat.beq x (V2 r k a)) 0 1) + _) * _
    cases Nat.beq x (V1 r k a) with
    | true => show (r + r) * (k - a) + _ = (1 + _) * _ + (0 + _) * _ + (0 + _) * _; lib_nat
    | false =>
      cases Nat.beq x (V2 r k a) with
      | true => show 2 * ((r + r) * a) + _ = (0 + _) * _ + (1 + _) * _ + (0 + _) * _; lib_nat
      | false => show k - a + _ = (0 + _) * _ + (0 + _) * _ + (1 + _) * _; lib_nat

theorem len3 : ∀ (A : List Nat), gs (is1 r k a) A + gs (is2 r k a) A + gs (isO r k a) A = A.length
  | [] => rfl
  | x :: A => by
    show is1 r k a x + gs (is1 r k a) A + (is2 r k a x + gs (is2 r k a) A) + (isO r k a x + gs (isO r k a) A) = A.length + 1
    rw [← len3 A]
    show cond (Nat.beq x (V1 r k a)) 1 0 + _ + (cond (Nat.beq x (V1 r k a)) 0 (cond (Nat.beq x (V2 r k a)) 1 0) + _)
      + (cond (Nat.beq x (V1 r k a)) 0 (cond (Nat.beq x (V2 r k a)) 0 1) + _) = _
    cases Nat.beq x (V1 r k a) with
    | true => show 1 + _ + (0 + _) + (0 + _) = _; lib_nat
    | false =>
      cases Nat.beq x (V2 r k a) with
      | true => show 0 + _ + (1 + _) + (0 + _) = _; lib_nat
      | false => show 0 + _ + (0 + _) + (1 + _) = _; lib_nat

include hp hk hr ha hak hqa in
theorem counts_ch : gs (is1 r k a) (ch r k a) = 1 ∧ gs (is2 r k a) (ch r k a) = 1 := by
  have orb0 : ∀ n, n ≤ r + r → gs (is1 r k a) (gl (fun i => a + i * k) n) = 0 ∧ gs (is2 r k a) (gl (fun i => a + i * k) n) = 0 := by
    intro n
    induction n with
    | zero => intro _; exact ⟨rfl, rfl⟩
    | succ n ih =>
      intro hn
      have ⟨i1, i2⟩ := ih (Nat.le_of_succ_le hn)
      have b1 := beq_false (ne1 r k a hp hk hr ha hak n hn)
      have b2 := beq_false (ne2 r k a hp hk ha hak hqa n hn)
      constructor
      · show cond (Nat.beq (a + n * k) (V1 r k a)) 1 0 + gs (is1 r k a) (gl (fun i => a + i * k) n) = 0
        rw [b1, i1]; rfl
      · show cond (Nat.beq (a + n * k) (V1 r k a)) 0 (cond (Nat.beq (a + n * k) (V2 r k a)) 1 0)
          + gs (is2 r k a) (gl (fun i => a + i * k) n) = 0
        rw [b1, b2, i2]; rfl
  have ⟨o1, o2⟩ := orb0 (r + r) (Nat.le_refl _)
  have n12 := beq_false (fun e => ne12 r k a hp hk hr ha hak hqa e.symm)
  constructor
  · show gs (is1 r k a) (gl (fun i => a + i * k) (r + r) ++ [V1 r k a, V2 r k a]) = 1
    rw [gs_app, o1]
    show 0 + (cond (Nat.beq (V1 r k a) (V1 r k a)) 1 0 + (cond (Nat.beq (V2 r k a) (V1 r k a)) 1 0 + 0)) = 1
    rw [beq_self, n12]; rfl
  · show gs (is2 r k a) (gl (fun i => a + i * k) (r + r) ++ [V1 r k a, V2 r k a]) = 1
    rw [gs_app, o2]
    show 0 + (cond (Nat.beq (V1 r k a) (V1 r k a)) 0 (cond (Nat.beq (V1 r k a) (V2 r k a)) 1 0)
      + (cond (Nat.beq (V2 r k a) (V1 r k a)) 0 (cond (Nat.beq (V2 r k a) (V2 r k a)) 1 0) + 0)) = 1
    rw [beq_self, n12, beq_self]; rfl

include hr ha hak hqa in
theorem memH_lt (x : Nat) (hx : x ∈ ch r k a) : x < (r + r) * k := by
  cases mem_ch r k a x hx with
  | inl h =>
    have ⟨i, hi, e⟩ := h
    rw [← e]
    have h1 : a + i * k < (i + 1) * k := by rw [Nat.succ_mul, Nat.add_comm (i * k) k]; exact Nat.add_lt_add_right hak _
    exact Nat.lt_of_lt_of_le h1 (Nat.mul_le_mul_right k (Nat.succ_le_of_lt hi))
  | inr h => cases h with
    | inl h1 =>
      rw [h1]; show r * k + (r + r) * a < (r + r) * k
      rw [show (r + r) * k = r * k + r * k by lib_nat]
      exact Nat.add_lt_add_left hqa _
    | inr h2 =>
      rw [h2]
      have e := V2_add r k a (hqa_le r k a hqa)
      have hpos : 0 < 2 * ((r + r) * a) :=
        Nat.mul_pos (Nat.succ_pos 1) (Nat.mul_pos (Nat.lt_of_lt_of_le hr (Nat.le_add_right r r)) ha)
      rw [← e]; exact Nat.lt_add_of_pos_right hpos

theorem len_app2 (x y : Nat) : ∀ (l : List Nat), (l ++ [x, y]).length = l.length + 2
  | [] => rfl
  | _ :: l => by show (l ++ [x, y]).length + 1 = l.length + 1 + 2; rw [len_app2 x y l]

include hp hk hr ha hak hqa in
/-- G667: the half-twisted orbit character is indecomposable for prime k > 2q + 1 (q = 2r even) -/
theorem qfamhalf_indec : indec ((r + r) * k) (ch r k a) = true := by
  have hq2 : 2 ≤ r + r := Nat.add_le_add hr hr
  have h2q : (r + r) + (r + r) < k := Nat.lt_of_lt_of_le
    (show (r + r) + (r + r) < 2 * (r + r) + 1 by rw [show 2 * (r + r) + 1 = ((r + r) + (r + r)) + 1 by lib_nat]; exact Nat.lt_succ_self _)
    (Nat.le_of_lt hk)
  have ⟨d, hd, hkd, dpos⟩ := kd k a hak
  have dlt : d < k := by rw [hd]; exact Nat.lt_add_of_pos_left ha
  have hk2 : ¬ k ∣ 2 := small_ndvd k 2 (Nat.succ_pos 1) (Nat.lt_of_le_of_lt hq2 (Nat.lt_of_le_of_lt (Nat.le_add_right _ _) h2q))
  cases hind : indec ((r + r) * k) (ch r k a) with
  | true => rfl
  | false =>
    exfalso
    cases all_false _ (splits (ch r k a)) hind with
    | intro sp hsp =>
      have hpr := splits_props (ch r k a) sp.1 sp.2 hsp.1
      have hf : (sp.1.isEmpty || sp.2.isEmpty || !(bal ((r + r) * k) sp.1 && bal ((r + r) * k) sp.2)) = false := hsp.2
      cases h1 : sp.1.isEmpty with
      | true => rw [h1] at hf; exact nomatch hf
      | false => cases h2 : sp.2.isEmpty with
        | true => rw [h1, h2] at hf; exact nomatch hf
        | false => cases hA : bal ((r + r) * k) sp.1 with
          | false => rw [h1, h2, hA] at hf; exact nomatch hf
          | true =>
            have hk3 : 2 ≤ (r + r) * k := Nat.le_trans hq2 (by
              have := Nat.mul_le_mul_left (r + r) (Nat.succ_le_of_lt (Nat.lt_of_le_of_lt (Nat.zero_le a) hak)); rw [Nat.mul_one] at this; exact this)
            have ⟨n, hn⟩ := LibGcd.le_dest hk3
            have hA' : bal (n + 2) sp.1 = true := by rw [Nat.add_comm n 2, ← hn]; exact hA
            have g1 := APPairIrrGen.units_one n
              (fun t => Nat.beq (tsum (n + 2) t sp.1 + tsum (n + 2) t sp.1) (sp.1.length * (n + 2))) hA'
            have eq1 := Nat.eq_of_beq_eq_true g1
            rw [show n + 2 = (r + r) * k by rw [hn, Nat.add_comm]] at eq1
            rw [tsum_one ((r + r) * k) sp.1 (fun x hx => memH_lt r k a hr ha hak hqa x (hpr.2.1 x hx))] at eq1
            have d1 := sum_padH_dvd r k a hp hk hr ha hak hqa sp.1 hpr.2.1
            have d2 := dvd_add' d1 d1
            rw [show gs (fun x => x) sp.1 + gs (padH r k a) sp.1 + (gs (fun x => x) sp.1 + gs (padH r k a) sp.1)
              = (gs (fun x => x) sp.1 + gs (fun x => x) sp.1) + (gs (padH r k a) sp.1 + gs (padH r k a) sp.1) by lib_nat] at d2
            have d3 : k ∣ gs (fun x => x) sp.1 + gs (fun x => x) sp.1 := ⟨sp.1.length * (r + r), by rw [eq1]; lib_nat⟩
            have d4 := dvd_of_add k _ _ (by rw [Nat.add_comm] at d2; exact d2) d3
            rw [padH_split r k a sp.1, hkd] at d4
            have ⟨c1, c2⟩ := counts_ch r k a hp hk hr ha hak hqa
            have s1 := splits_gs (is1 r k a) (ch r k a) sp.1 sp.2 hsp.1
            have s2 := splits_gs (is2 r k a) (ch r k a) sp.1 sp.2 hsp.1
            rw [c1] at s1; rw [c2] at s2
            have hl3 := len3 r k a sp.1
            have hlc : (ch r k a).length = (r + r) + 2 := by
              show (gl (fun i => a + i * k) (r + r) ++ [V1 r k a, V2 r k a]).length = _
              rw [len_app2, gl_len]
            have hAB := hpr.1
            rw [hlc] at hAB
            have hBpos : 1 ≤ sp.2.length := by
              cases hB0 : sp.2 with
              | nil => rw [hB0] at h2; exact nomatch h2
              | cons _ _ => exact Nat.succ_le_succ (Nat.zero_le _)
            have hApos : 1 ≤ sp.1.length := by
              cases hA0 : sp.1 with
              | nil => rw [hA0] at h1; exact nomatch h1
              | cons _ _ => exact Nat.succ_le_succ (Nat.zero_le _)
            have hAq : sp.1.length ≤ (r + r) + 1 := by
              have : sp.1.length + 1 ≤ sp.1.length + sp.2.length := Nat.add_le_add_left hBpos _
              rw [hAB] at this; exact Nat.le_of_succ_le_succ this
            generalize gs (is1 r k a) sp.1 = e1 at s1 hl3 d4
            generalize gs (is2 r k a) sp.1 = e2 at s2 hl3 d4
            generalize gs (isO r k a) sp.1 = s at hl3 d4
            generalize r + r = q at hq2 h2q hk2 hAq hAB d4 hk3 d3 eq1 ⊢
            have hq0 : 0 < q := Nat.lt_of_lt_of_le (Nat.succ_pos 1) hq2
            have hqk : q < k := Nat.lt_of_le_of_lt (Nat.le_add_right q q) h2q
            -- e1, e2 ∈ {0, 1}
            have b1 : e1 ≤ 1 := by rw [← s1]; exact Nat.le_add_right _ _
            have b2 : e2 ≤ 1 := by rw [← s2]; exact Nat.le_add_right _ _
            cases e2 with
            | succ e2' =>
              cases e2' with
              | succ _ => exact absurd b2 (Nat.not_succ_le_self 1 |> fun h => by
                  intro hh; exact h (Nat.le_trans (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le _))) hh))
              | zero =>
                -- e2 = 1
                cases e1 with
                | succ e1' =>
                  cases e1' with
                  | succ _ => exact absurd b1 (by intro hh; exact Nat.not_succ_le_self 1 (Nat.le_trans (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le _))) hh))
                  | zero =>
                    -- e1 = 1, e2 = 1: s + 1 ≤ q
                    have hs : s + 1 ≤ q := by
                      have : 0 + 1 + (0 + 1) + s ≤ q + 1 := by rw [hl3]; exact hAq
                      rw [show 0 + 1 + (0 + 1) + s = (s + 1) + 1 by lib_nat] at this
                      exact Nat.le_of_succ_le_succ this
                    have ⟨t, ht⟩ := LibGcd.le_dest hs
                    have e6 : (0 + 1) * (q * d) + (0 + 1) * (2 * (q * a)) + s * d
                        + ((0 + 1) * (q * d) + (0 + 1) * (2 * (q * a)) + s * d) + 2 * ((1 + t) * d) = (4 * q) * k := by
                      rw [hd, ht]; lib_nat
                    have d5 : k ∣ ((0 + 1) * (q * d) + (0 + 1) * (2 * (q * a)) + s * d
                        + ((0 + 1) * (q * d) + (0 + 1) * (2 * (q * a)) + s * d)) + 2 * ((1 + t) * d) := by
                      rw [e6]; exact ⟨4 * q, Nat.mul_comm _ _⟩
                    have d6 := dvd_of_add k _ _ (by rw [Nat.add_comm] at d5; exact d5) d4
                    cases euclid_prime hp d6 with
                    | inl h => exact hk2 h
                    | inr h => cases euclid_prime hp h with
                      | inl h' =>
                        have : 1 + t ≤ q := by rw [ht, show s + 1 + t = (1 + t) + s by lib_nat]; exact Nat.le_add_right _ _
                        exact small_ndvd k _ (by rw [Nat.add_comm]; exact Nat.succ_pos t) (Nat.lt_of_le_of_lt this hqk) h'
                      | inr h' => exact small_ndvd k d dpos dlt h'
                | zero =>
                  -- e1 = 0, e2 = 1: s ≤ q
                  have hs : s ≤ q := by
                    have : 0 + (0 + 1) + s ≤ q + 1 := by rw [hl3]; exact hAq
                    rw [show 0 + (0 + 1) + s = s + 1 by lib_nat] at this
                    exact Nat.le_of_succ_le_succ this
                  have ⟨t, ht⟩ := LibGcd.le_dest hs
                  have e6 : 0 * (q * d) + (0 + 1) * (2 * (q * a)) + s * d
                      + (0 * (q * d) + (0 + 1) * (2 * (q * a)) + s * d) + 2 * ((q + t) * d) = (4 * q) * k := by
                    rw [hd, ht]; lib_nat
                  have d5 : k ∣ (0 * (q * d) + (0 + 1) * (2 * (q * a)) + s * d
                      + (0 * (q * d) + (0 + 1) * (2 * (q * a)) + s * d)) + 2 * ((q + t) * d) := by
                    rw [e6]; exact ⟨4 * q, Nat.mul_comm _ _⟩
                  have d6 := dvd_of_add k _ _ (by rw [Nat.add_comm] at d5; exact d5) d4
                  cases euclid_prime hp d6 with
                  | inl h => exact hk2 h
                  | inr h => cases euclid_prime hp h with
                    | inl h' =>
                      have tq : t ≤ q := by rw [ht]; exact Nat.le_add_left t s
                      have : q + t ≤ q + q := Nat.add_le_add_left tq q
                      exact small_ndvd k _ (Nat.lt_of_lt_of_le hq0 (Nat.le_add_right q t)) (Nat.lt_of_le_of_lt this h2q) h'
                    | inr h' => exact small_ndvd k d dpos dlt h'
            | zero =>
              -- e2 = 0
              cases e1 with
              | succ e1' =>
                cases e1' with
                | succ _ => exact absurd b1 (by intro hh; exact Nat.not_succ_le_self 1 (Nat.le_trans (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le _))) hh))
                | zero =>
                  -- k ∣ 2 (q + s) d with s ≤ q
                  have hs : s ≤ q := by
                    have : 0 + 1 + 0 + s ≤ q + 1 := by rw [hl3]; exact hAq
                    rw [show 0 + 1 + 0 + s = s + 1 by lib_nat] at this
                    exact Nat.le_of_succ_le_succ this
                  rw [show (0 + 1) * (q * d) + 0 * (2 * (q * a)) + s * d + ((0 + 1) * (q * d) + 0 * (2 * (q * a)) + s * d)
                    = 2 * ((q + s) * d) by lib_nat] at d4
                  cases euclid_prime hp d4 with
                  | inl h => exact hk2 h
                  | inr h => cases euclid_prime hp h with
                    | inl h' =>
                      exact small_ndvd k _ (Nat.lt_of_lt_of_le hq0 (Nat.le_add_right q s))
                        (Nat.lt_of_le_of_lt (Nat.add_le_add_left hs q) h2q) h'
                    | inr h' => exact small_ndvd k d dpos dlt h'
              | zero =>
                -- e1 = e2 = 0: k ∣ 2 s d, 0 < s = |A| ≤ q + 1 < k
                have hsA : s = sp.1.length := by rw [← hl3]; lib_nat
                rw [show 0 * (q * d) + 0 * (2 * (q * a)) + s * d + (0 * (q * d) + 0 * (2 * (q * a)) + s * d)
                  = 2 * (s * d) by lib_nat] at d4
                cases euclid_prime hp d4 with
                | inl h => exact hk2 h
                | inr h => cases euclid_prime hp h with
                  | inl h' =>
                    rw [hsA] at h'
                    exact small_ndvd k _ (Nat.lt_of_lt_of_le (Nat.succ_pos 0) hApos)
                      (Nat.lt_of_le_of_lt hAq (Nat.lt_of_le_of_lt (Nat.add_le_add_left (Nat.succ_le_of_lt hq0) q) h2q)) h'
                  | inr h' => exact small_ndvd k d dpos dlt h'

end Fam

end QFamHalfPrime

#print axioms QFamHalfPrime.V2_add
#print axioms QFamHalfPrime.ne1
#print axioms QFamHalfPrime.ne2
#print axioms QFamHalfPrime.ne12
#print axioms QFamHalfPrime.padH_dvd
#print axioms QFamHalfPrime.sum_padH_dvd
#print axioms QFamHalfPrime.padH_split
#print axioms QFamHalfPrime.len3
#print axioms QFamHalfPrime.counts_ch
#print axioms QFamHalfPrime.memH_lt
#print axioms QFamHalfPrime.qfamhalf_indec

#print axioms: 15 theorems, no axioms.

81.163 The padding criterion

If \(k\mid m\), every entry has a pad \(P\) with \(k\mid x+P(x)\), and no nontrivial split has \(k\mid 2\sum _AP\), the character is indecomposable. Only the unit \(t=1\) is used; the orbit-family results are instances.

hodge/PadCriterion.lean

/-
  hodge/PadCriterion.lean — T41 cycle 1017 (goal G672): the padding criterion for indecomposability, abstract form.
  Let k ∣ m, 2 ≤ m, every entry x of c satisfy x < m and k ∣ x + P(x) for a pad function P. If no split (A, B) of c
  with A, B nonempty has k ∣ 2·Σ_{x∈A} P(x), then c is indecomposable:
    pad_indec   (∀ splits, A ≠ ∅, B ≠ ∅ → ¬ k ∣ 2 Σ_A P) ⇒ indec m c = true.
  Proof: a balanced A has 2ΣA = |A|m (unit t = 1), so k ∣ 2ΣA, and k ∣ ΣA + Σ_A P, hence k ∣ 2Σ_A P.
  QFamPrime, QFamPrimeQ1 and QFamHalfPrime are instances (with the count arithmetic as the criterion).
    sum_indec   the same with the plain sums: no nontrivial split has k ∣ 2ΣA ⇒ indecomposable
                (for an odd prime k: zero-sum-free modulo k; e.g. Open148's m = 68, 76, 148 orbits mod 17, 19, 37).

  Lean 4 core plus hodge/QFamPrime (gs, tsum_one, dvd_of_add), hodge/Q4Conv (splits_props, all_false).
-/
import hodge.QFamPrime

namespace PadCriterion
open Indecomp Q4Conv LibGcd QFamPrime

theorem sum_pad (k : Nat) (P : Nat → Nat) (c : List Nat) (hpad : ∀ x, x ∈ c → k ∣ x + P x) :
    ∀ (A : List Nat), (∀ x, x ∈ A → x ∈ c) → k ∣ gs (fun x => x) A + gs P A
  | [], _ => ⟨0, rfl⟩
  | x :: A, h => by
    have h1 := hpad x (h x (List.Mem.head _))
    have h2 := sum_pad k P c hpad A (fun y hy => h y (List.Mem.tail _ hy))
    have e : gs (fun x => x) (x :: A) + gs P (x :: A) = (x + P x) + (gs (fun x => x) A + gs P A) := by
      show x + gs (fun x => x) A + (P x + gs P A) = _; lib_nat
    rw [e]; exact dvd_add' h1 h2

theorem pad_indec (m k : Nat) (c : List Nat) (P : Nat → Nat) (hm : 2 ≤ m) (hkm : k ∣ m)
    (hlt : ∀ x, x ∈ c → x < m) (hpad : ∀ x, x ∈ c → k ∣ x + P x)
    (hcrit : ∀ A B, (A, B) ∈ splits c → A.isEmpty = false → B.isEmpty = false → ¬ k ∣ gs P A + gs P A) :
    indec m c = true := by
  cases hind : indec m c with
  | true => rfl
  | false =>
    exfalso
    cases all_false _ (splits c) hind with
    | intro sp hsp =>
      have hpr := splits_props c sp.1 sp.2 hsp.1
      have hf : (sp.1.isEmpty || sp.2.isEmpty || !(bal m sp.1 && bal m sp.2)) = false := hsp.2
      cases h1 : sp.1.isEmpty with
      | true => rw [h1] at hf; exact nomatch hf
      | false => cases h2 : sp.2.isEmpty with
        | true => rw [h1, h2] at hf; exact nomatch hf
        | false => cases hA : bal m sp.1 with
          | false => rw [h1, h2, hA] at hf; exact nomatch hf
          | true =>
            have ⟨n, hn⟩ := LibGcd.le_dest hm
            have hA' : bal (n + 2) sp.1 = true := by rw [Nat.add_comm n 2, ← hn]; exact hA
            have g1 := APPairIrrGen.units_one n
              (fun t => Nat.beq (tsum (n + 2) t sp.1 + tsum (n + 2) t sp.1) (sp.1.length * (n + 2))) hA'
            have eq1 := Nat.eq_of_beq_eq_true g1
            rw [show n + 2 = m by rw [hn, Nat.add_comm]] at eq1
            rw [tsum_one m sp.1 (fun x hx => hlt x (hpr.2.1 x hx))] at eq1
            have d1 := sum_pad k P c hpad sp.1 hpr.2.1
            have d2 := dvd_add' d1 d1
            rw [show gs (fun x => x) sp.1 + gs P sp.1 + (gs (fun x => x) sp.1 + gs P sp.1)
              = (gs P sp.1 + gs P sp.1) + (gs (fun x => x) sp.1 + gs (fun x => x) sp.1) by lib_nat] at d2
            have ⟨w, hw⟩ := hkm
            have d3 : k ∣ gs (fun x => x) sp.1 + gs (fun x => x) sp.1 := ⟨sp.1.length * w, by rw [eq1, hw]; lib_nat⟩
            exact hcrit sp.1 sp.2 hsp.1 h1 h2 (dvd_of_add k _ _ d2 d3)

/-- the sum criterion: if k ∣ m and no nontrivial split has k ∣ 2ΣA, the character is indecomposable
  (for an odd prime k: no proper nonempty sub-multiset sums to 0 mod k) -/
theorem sum_indec (m k : Nat) (c : List Nat) (hm : 2 ≤ m) (hkm : k ∣ m) (hlt : ∀ x, x ∈ c → x < m)
    (hcrit : ∀ A B, (A, B) ∈ splits c → A.isEmpty = false → B.isEmpty = false →
      ¬ k ∣ gs (fun x => x) A + gs (fun x => x) A) :
    indec m c = true := by
  cases hind : indec m c with
  | true => rfl
  | false =>
    exfalso
    cases all_false _ (splits c) hind with
    | intro sp hsp =>
      have hpr := splits_props c sp.1 sp.2 hsp.1
      have hf : (sp.1.isEmpty || sp.2.isEmpty || !(bal m sp.1 && bal m sp.2)) = false := hsp.2
      cases h1 : sp.1.isEmpty with
      | true => rw [h1] at hf; exact nomatch hf
      | false => cases h2 : sp.2.isEmpty with
        | true => rw [h1, h2] at hf; exact nomatch hf
        | false => cases hA : bal m sp.1 with
          | false => rw [h1, h2, hA] at hf; exact nomatch hf
          | true =>
            have ⟨n, hn⟩ := LibGcd.le_dest hm
            have hA' : bal (n + 2) sp.1 = true := by rw [Nat.add_comm n 2, ← hn]; exact hA
            have g1 := APPairIrrGen.units_one n
              (fun t => Nat.beq (tsum (n + 2) t sp.1 + tsum (n + 2) t sp.1) (sp.1.length * (n + 2))) hA'
            have eq1 := Nat.eq_of_beq_eq_true g1
            rw [show n + 2 = m by rw [hn, Nat.add_comm]] at eq1
            rw [tsum_one m sp.1 (fun x hx => hlt x (hpr.2.1 x hx))] at eq1
            have ⟨w, hw⟩ := hkm
            exact hcrit sp.1 sp.2 hsp.1 h1 h2 ⟨sp.1.length * w, by rw [eq1, hw]; lib_nat⟩

end PadCriterion

#print axioms PadCriterion.sum_pad
#print axioms PadCriterion.pad_indec
#print axioms PadCriterion.sum_indec

#print axioms: 3 theorems, no axioms.

81.164 Orbit characters for composite \(k\)

If a prime \(p>q+1\) divides \(k\) but not \(a\), then \(\mathrm {QFam}(q,k,a)\) is indecomposable. The same pads read modulo \(p\) through the padding criterion.

hodge/QFamPrimeGen.lean

/-
  hodge/QFamPrimeGen.lean — T41 cycle 1019 (goal G678): G612 for composite k. If some prime p divides k with
  p > q + 1 and p ∤ a, then QFam(q, k, a) = [a + i k (i < q)] ⊔ [qk − qa] is indecomposable (qfam_indec_gen).
  Same pads as QFamPrime (k − a on the orbit, q a on L), now read modulo p via PadCriterion.pad_indec:
    e = #L in A = 0:  p ∣ 2 s (k − a) and p ∤ k − a (as p ∣ k, p ∤ a) ⇒ p ∣ s, 0 < s ≤ q < p;
    e = 1:            p ∣ 2 (r + 1) a with q = s + 1 + r ⇒ p ∣ r + 1, 0 < r + 1 ≤ q < p.
  Computed first: q = 2, 3, 4 with k = 25, 35, 49, 55, 77 (all a) indecomposable.

  Lean 4 core plus hodge/PadCriterion, hodge/QFamPrime.
-/
import hodge.PadCriterion

namespace QFamPrimeGen
open Indecomp Q4Conv PermSum LibGcd QFamPrime PadCriterion

section Fam
variable (q k a p : Nat) (hp : ∀ d, d ∣ p → d = 1 ∨ d = p) (hpk : p ∣ k) (hqp : q + 1 < p) (hpa : ¬ p ∣ a)
  (ha : 0 < a) (hak : a < k)

include hp hpk hqp hpa hak in
theorem orb_ne_gen (i : Nat) (hi : i < q) : a + i * k ≠ L q k a := by
  intro e
  have h1 := L_add q k a hak
  rw [← e] at h1
  have ⟨j, hj⟩ := LibGcd.le_dest (Nat.succ_le_of_lt hi)
  rw [hj] at h1
  have h1' : a + i * k + (i + 1 + j) * a = (i + 1 + j) * k := h1
  have e2 : i * k + ((i + 1 + j + 1) * a) = i * k + ((1 + j) * k) := by
    calc i * k + ((i + 1 + j + 1) * a) = a + i * k + (i + 1 + j) * a := by lib_nat
      _ = (i + 1 + j) * k := h1'
      _ = i * k + ((1 + j) * k) := by lib_nat
  have e3 := BalAppend.add_cancel _ _ _ e2
  have hd : p ∣ (i + 1 + j + 1) * a := by
    have ⟨w, hw⟩ := hpk
    exact ⟨(1 + j) * w, by rw [e3, hw]; lib_nat⟩
  cases euclid_prime hp hd with
  | inl h =>
    have hq1 : i + 1 + j + 1 = q + 1 := by rw [hj]
    rw [hq1] at h
    exact not_dvd_small (Nat.succ_pos q) hqp h
  | inr h => exact hpa h

include hp hpk hqp hpa hak in
theorem pad_dvd_gen (x : Nat) (hx : x ∈ cc q k a) : k ∣ x + pad q k a x := by
  cases mem_cc q k a x hx with
  | inl h =>
    have ⟨i, hi, e⟩ := h
    have hne : x ≠ L q k a := by rw [← e]; exact orb_ne_gen q k a p hp hpk hqp hpa hak i hi
    show k ∣ x + cond (Nat.beq x (L q k a)) (q * a) (k - a)
    rw [beq_false hne, ← e]
    have ⟨d, hd⟩ := LibGcd.le_dest (Nat.le_of_lt hak)
    show k ∣ a + i * k + (k - a)
    rw [hd, Nat.add_comm a d, ModHand.add_sub' d a]
    exact ⟨i + 1, by lib_nat⟩
  | inr h =>
    show k ∣ x + cond (Nat.beq x (L q k a)) (q * a) (k - a)
    rw [h, beq_self, show cond true (q * a) (k - a) = q * a from rfl, L_add q k a hak]
    exact ⟨q, Nat.mul_comm _ _⟩

include hp hpk hqp hpa hak in
theorem isL_cc_gen : gs (isL q k a) (cc q k a) = 1 := by
  have orb0 : ∀ n, n ≤ q → gs (isL q k a) (gl (fun i => a + i * k) n) = 0 := by
    intro n
    induction n with
    | zero => intro _; rfl
    | succ n ih =>
      intro hn
      show cond (Nat.beq (a + n * k) (L q k a)) 1 0 + gs (isL q k a) (gl (fun i => a + i * k) n) = 0
      rw [beq_false (orb_ne_gen q k a p hp hpk hqp hpa hak n hn), ih (Nat.le_of_succ_le hn)]
      rfl
  show gs (isL q k a) (gl (fun i => a + i * k) q ++ [L q k a]) = 1
  rw [gs_app, orb0 q (Nat.le_refl q)]
  show 0 + (cond (Nat.beq (L q k a) (L q k a)) 1 0 + 0) = 1
  rw [beq_self]
  rfl

include hp hpk hqp hpa ha hak in
/-- G678: indecomposable whenever a prime p > q + 1 divides k but not a -/
theorem qfam_indec_gen (hq : 1 ≤ q) : indec (q * k) (cc q k a) = true := by
  have hk0 : 0 < k := Nat.lt_of_le_of_lt (Nat.zero_le a) hak
  have hp2 : ¬ p ∣ 2 := fun h => not_dvd_small (Nat.succ_pos 1)
    (Nat.lt_of_le_of_lt (Nat.succ_le_succ hq) hqp) h
  have ⟨d, hd⟩ := LibGcd.le_dest (Nat.le_of_lt hak)
  have hka : k - a = d := by rw [hd, Nat.add_comm a d, ModHand.add_sub' d a]
  have hpd : ¬ p ∣ d := fun h => hpa (dvd_of_add p a d (by rw [← hd]; exact hpk) h)
  have hpk' : p ≤ k := by
    have ⟨w, hw⟩ := hpk
    cases w with
    | zero => rw [Nat.mul_zero] at hw; rw [hw] at hk0; exact absurd hk0 (Nat.lt_irrefl 0)
    | succ w => rw [hw, Nat.mul_succ]; exact Nat.le_add_left _ _
  have hk2 : 2 ≤ k := Nat.le_trans (Nat.le_trans (Nat.succ_le_succ hq) (Nat.le_of_lt hqp)) hpk'
  have hm2 : 2 ≤ q * k := Nat.le_trans hk2 (by have := Nat.mul_le_mul_right k hq; rw [Nat.one_mul] at this; exact this)
  refine pad_indec (q * k) p (cc q k a) (pad q k a) hm2
    (dvd_trans' hpk ⟨q, Nat.mul_comm _ _⟩)
    (fun x hx => mem_lt q k a ha hak hq x hx)
    (fun x hx => dvd_trans' hpk (pad_dvd_gen q k a p hp hpk hqp hpa hak x hx)) ?_
  intro A B hs hA hB
  intro dv
  have hsum := splits_gs (isL q k a) (cc q k a) A B hs
  rw [isL_cc_gen q k a p hp hpk hqp hpa hak] at hsum
  have hlen := len_split q k a A
  have hlc : (cc q k a).length = q + 1 := by
    show (gl (fun i => a + i * k) q ++ [L q k a]).length = q + 1
    rw [len_app1, gl_len]
  have hAB := (splits_props _ A B hs).1
  rw [hlc] at hAB
  have hBpos : 1 ≤ B.length := by
    cases hB0 : B with
    | nil => rw [hB0] at hB; exact nomatch hB
    | cons _ _ => exact Nat.succ_le_succ (Nat.zero_le _)
  have hApos : 1 ≤ A.length := by
    cases hA0 : A with
    | nil => rw [hA0] at hA; exact nomatch hA
    | cons _ _ => exact Nat.succ_le_succ (Nat.zero_le _)
  have hAq : A.length ≤ q := by
    have : A.length + 1 ≤ A.length + B.length := Nat.add_le_add_left hBpos _
    rw [hAB] at this; exact Nat.le_of_succ_le_succ this
  rw [pad_split q k a A, hka] at dv
  generalize gs (isL q k a) A = e at hsum hlen dv
  generalize gs (notL q k a) A = s at hlen dv
  cases e with
  | zero =>
    have hs' : s = A.length := by rw [← hlen]; exact (Nat.zero_add s).symm
    rw [show 0 * (q * a) + s * d + (0 * (q * a) + s * d) = 2 * (s * d) by lib_nat] at dv
    cases euclid_prime hp dv with
    | inl h => exact hp2 h
    | inr h => cases euclid_prime hp h with
      | inl h' =>
        rw [hs'] at h'
        exact not_dvd_small (Nat.lt_of_lt_of_le (Nat.succ_pos 0) hApos)
          (Nat.lt_of_le_of_lt hAq (Nat.lt_trans (Nat.lt_succ_self q) hqp)) h'
      | inr h' => exact hpd h'
  | succ e' =>
    cases e' with
    | succ e'' =>
      have : 2 ≤ 1 := by rw [← hsum]; exact Nat.le_trans (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le e''))) (Nat.le_add_right _ _)
      exact absurd this (Nat.not_succ_le_self 1)
    | zero =>
      have hsq : s + 1 ≤ q := by
        have : 1 + s = A.length := hlen
        rw [Nat.add_comm] at this; rw [this]; exact hAq
      have ⟨r, hr⟩ := LibGcd.le_dest hsq
      have e6 : (0 + 1) * (q * a) + s * d + ((0 + 1) * (q * a) + s * d) = 2 * ((r + 1) * a) + (2 * s) * k := by
        rw [hr, hd]; lib_nat
      rw [e6] at dv
      have d5 := dvd_of_add p _ _ dv (dvd_trans' hpk ⟨2 * s, Nat.mul_comm _ _⟩)
      cases euclid_prime hp d5 with
      | inl h => exact hp2 h
      | inr h => cases euclid_prime hp h with
        | inl h' =>
          have rle : r + 1 ≤ q := by
            rw [hr, show s + 1 + r = (r + 1) + s by lib_nat]; exact Nat.le_add_right _ _
          exact not_dvd_small (Nat.succ_pos r) (Nat.lt_of_le_of_lt rle (Nat.lt_trans (Nat.lt_succ_self q) hqp)) h'
        | inr h' => exact hpa h'

end Fam

end QFamPrimeGen

#print axioms QFamPrimeGen.orb_ne_gen
#print axioms QFamPrimeGen.pad_dvd_gen
#print axioms QFamPrimeGen.isL_cc_gen
#print axioms QFamPrimeGen.qfam_indec_gen

#print axioms: 4 theorems, no axioms.

81.165 Balanced surface characters for \(p=41,43\) (Kamiak)

Every balanced length-4 character of the degree-\(p\) Fermat surface is two complementary pairs, \(p=41,43\). Length 4 is now settled for all odd primes \(p\le 43\).

hodge/Pairs4e.lean

/-
  hodge/Pairs4e.lean — T41 cycle 1008 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 41:
  every balanced length-4 character of the degree-p Fermat surface is a union of two complementary pairs (rfl, no
  heartbeat limit). With Pairs4, Pairs4b, Pairs4c, Pairs4d: length 4 settled for all odd primes p ≤ 41 (p = 43 in Pairs4f).

  Lean 4 core plus hodge/Pairs4 (badQ), rfl.
-/
import hodge.Pairs4

namespace Pairs4e
open Pairs4

set_option maxHeartbeats 0 in
set_option maxRecDepth 400000 in
theorem r41 : badQ 41 = [] := rfl

end Pairs4e

#print axioms Pairs4e.r41

hodge/Pairs4f.lean

/-
  hodge/Pairs4f.lean — T41 cycle 1037 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 43:
  every balanced length-4 character of the degree-43 Fermat surface is a union of two complementary pairs (rfl, no
  heartbeat limit). With Pairs4, Pairs4b, Pairs4c, Pairs4d: length 4 settled for all odd primes p ≤ 43.

  Lean 4 core plus hodge/Pairs4 (badQ), rfl.
-/
import hodge.Pairs4

namespace Pairs4f
open Pairs4

set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem r43 : badQ 43 = [] := rfl

end Pairs4f

#print axioms Pairs4f.r43

#print axioms: 2 theorems, no axioms.

81.166 Half-twisted orbit characters for composite \(k\)

If a prime \(p>2q+1\) divides \(k\) but not \(a\), the half-twisted orbit character is indecomposable. Covers the Open148 representatives at \(m=148\) (\(k=37\)) and \(m=152\) (\(k=38\), \(p=19\)).

hodge/QFamHalfGen.lean

/-
  hodge/QFamHalfGen.lean — T41 cycle 1051 (goal G699): the half-twisted orbit characters for composite k. If a prime
  p > 2q + 1 divides k (q = 2r) and p ∤ a, then [a + i k (i < q)] ⊔ [h + q a, m − 2 q a] (m = q k = 2h, q a < h) is
  indecomposable (qfamhalf_indec_gen). The pads of QFamHalfPrime read modulo p via PadCriterion.pad_indec;
  p ∤ k − a since p ∣ k and p ∤ a. Covers the Open148 m = 152 representatives (k = 38, p = 19).

  Lean 4 core plus hodge/QFamHalfPrime (V1, V2, ch, padH, padH_split, len3, memH_lt), hodge/PadCriterion.
-/
import hodge.QFamHalfPrime
import hodge.PadCriterion

namespace QFamHalfGen
open Indecomp Q4Conv PermSum LibGcd QFamPrime QFamHalfPrime PadCriterion

section Fam
variable (r k a p : Nat) (hp : ∀ d, d ∣ p → d = 1 ∨ d = p) (hpk : p ∣ k) (hk : 2 * (r + r) + 1 < p) (hpa : ¬ p ∣ a)
  (hr : 1 ≤ r) (ha : 0 < a) (hak : a < k) (hqa : (r + r) * a < r * k)

include hp hpk hk hpa hr ha hak in
theorem ne1g (i : Nat) (hi : i < r + r) : a + i * k ≠ V1 r k a := by
  intro e
  have e' : a + i * k = r * k + (r + r) * a := e
  -- q − 1 = r + r1 with r = r1 + 1
  cases r with
  | zero => exact absurd hr (Nat.lt_irrefl 0)
  | succ r1 =>
    cases Nat.lt_or_ge i (r1 + 1) with
    | inl hlt =>
      -- i k < (r1+1) k ≤ rhs − a
      have h1 : i * k < (r1 + 1) * k := Nat.mul_lt_mul_of_pos_right hlt (Nat.lt_trans ha hak)
      have h2 : a + i * k < a + (r1 + 1) * k := Nat.add_lt_add_left h1 a
      have h3 : a + (r1 + 1) * k ≤ (r1 + 1) * k + (r1 + 1 + (r1 + 1)) * a := by
        rw [Nat.add_comm a]
        exact Nat.add_le_add_left (by
          rw [show (r1 + 1 + (r1 + 1)) * a = a + (r1 + r1 + 1) * a by lib_nat]; exact Nat.le_add_right a _) _
      rw [e'] at h2; exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le h2 h3)
    | inr hge =>
      have ⟨j, hj⟩ := LibGcd.le_dest hge
      rw [hj] at e'
      -- a + (r1+1+j) k = (r1+1) k + (2r1+2) a  ⇒  j k = (2 r1 + 1) a
      have e2 : (r1 + 1) * k + a + j * k = (r1 + 1) * k + a + (r1 + r1 + 1) * a := by
        calc (r1 + 1) * k + a + j * k = a + (r1 + 1 + j) * k := by lib_nat
          _ = (r1 + 1) * k + (r1 + 1 + (r1 + 1)) * a := e'
          _ = _ := by lib_nat
      have e3 := BalAppend.add_cancel _ _ _ e2
      have hd : p ∣ (r1 + r1 + 1) * a := dvd_trans' hpk ⟨j, by rw [← e3, Nat.mul_comm]⟩
      cases euclid_prime hp hd with
      | inl h =>
        have lt1 : r1 + r1 + 1 < 2 * (r1 + 1 + (r1 + 1)) + 1 := by
          rw [show 2 * (r1 + 1 + (r1 + 1)) + 1 = (r1 + r1 + 1) + ((r1 + r1 + 3) + 1) by lib_nat]
          exact Nat.lt_add_of_pos_right (Nat.succ_pos _)
        exact small_ndvd p _ (Nat.succ_pos _) (Nat.lt_trans lt1 hk) h
      | inr h => exact hpa h

include hp hpk hk hpa hqa in
theorem ne2g (i : Nat) (hi : i < r + r) : a + i * k ≠ V2 r k a := by
  intro e
  have h1 := V2_add r k a (hqa_le r k a hqa)
  rw [← e] at h1
  have ⟨j, hj⟩ := LibGcd.le_dest (Nat.succ_le_of_lt hi)
  have e2 : i * k + (2 * (r + r) + 1) * a = i * k + (1 + j) * k := by
    calc i * k + (2 * (r + r) + 1) * a = a + i * k + 2 * ((r + r) * a) := by lib_nat
      _ = (r + r) * k := h1
      _ = (i + 1 + j) * k := by rw [← hj]
      _ = _ := by lib_nat
  have e3 := BalAppend.add_cancel _ _ _ e2
  have hd : p ∣ (2 * (r + r) + 1) * a := dvd_trans' hpk ⟨1 + j, by rw [e3, Nat.mul_comm]⟩
  cases euclid_prime hp hd with
  | inl h => exact small_ndvd p _ (Nat.succ_pos _) hk h
  | inr h => exact hpa h

include hp hpk hk hpa hr hqa in
theorem ne12g : V1 r k a ≠ V2 r k a := by
  intro e
  have h1 := V2_add r k a (hqa_le r k a hqa)
  rw [← e] at h1
  have e2 : r * k + 3 * ((r + r) * a) = r * k + r * k := by
    calc r * k + 3 * ((r + r) * a) = V1 r k a + 2 * ((r + r) * a) := by show _ = r * k + (r + r) * a + _; lib_nat
      _ = (r + r) * k := h1
      _ = _ := by lib_nat
  have e3 := BalAppend.add_cancel _ _ _ e2
  have hd : p ∣ 3 * ((r + r) * a) := dvd_trans' hpk ⟨r, by rw [e3, Nat.mul_comm]⟩
  have hq0 : 0 < r + r := Nat.lt_of_lt_of_le hr (Nat.le_add_right r r)
  have hqk : r + r < p := Nat.lt_trans (Nat.lt_of_lt_of_le (Nat.lt_succ_self _)
    (show r + r + 1 ≤ 2 * (r + r) + 1 by rw [show 2 * (r + r) + 1 = (r + r + 1) + (r + r) by lib_nat]; exact Nat.le_add_right _ _)) hk
  cases euclid_prime hp hd with
  | inl h =>
    have h3le : 3 ≤ 2 * (r + r) + 1 := by
      have ⟨t, ht⟩ := LibGcd.le_dest hr
      rw [ht, show 2 * (1 + t + (1 + t)) + 1 = 3 + (4 * t + 2) by lib_nat]
      exact Nat.le_add_right _ _
    have h3 : 3 < p := Nat.lt_of_le_of_lt h3le hk
    exact small_ndvd p 3 (Nat.succ_pos 2) h3 h
  | inr h => cases euclid_prime hp h with
    | inl h' => exact small_ndvd p _ hq0 hqk h'
    | inr h' => exact hpa h'

include hp hpk hk hpa hr ha hak hqa in
theorem padH_dvdg (x : Nat) (hx : x ∈ ch r k a) : k ∣ x + padH r k a x := by
  have ⟨d, hd, hkd, _⟩ := kd k a hak
  cases mem_ch r k a x hx with
  | inl h =>
    have ⟨i, hi, e⟩ := h
    have n1 : x ≠ V1 r k a := by rw [← e]; exact ne1g r k a p hp hpk hk hpa hr ha hak i hi
    have n2 : x ≠ V2 r k a := by rw [← e]; exact ne2g r k a p hp hpk hk hpa hqa i hi
    show k ∣ x + cond (Nat.beq x (V1 r k a)) _ (cond (Nat.beq x (V2 r k a)) _ (k - a))
    rw [beq_false n1, beq_false n2]
    show k ∣ x + (k - a)
    rw [hkd, ← e]
    exact ⟨i + 1, by rw [hd]; lib_nat⟩
  | inr h => cases h with
    | inl h1 =>
      show k ∣ x + cond (Nat.beq x (V1 r k a)) ((r + r) * (k - a)) _
      rw [h1, beq_self, hkd]
      exact ⟨r + (r + r), by show r * k + (r + r) * a + (r + r) * d = _; rw [hd]; lib_nat⟩
    | inr h2 =>
      show k ∣ x + cond (Nat.beq x (V1 r k a)) _ (cond (Nat.beq x (V2 r k a)) (2 * ((r + r) * a)) _)
      rw [h2, beq_false (fun e => ne12g r k a p hp hpk hk hpa hr hqa e.symm), beq_self]
      show k ∣ V2 r k a + 2 * ((r + r) * a)
      rw [V2_add r k a (hqa_le r k a hqa)]
      exact ⟨r + r, Nat.mul_comm _ _⟩

include hp hpk hk hpa hr ha hak hqa in
theorem counts_chg : gs (is1 r k a) (ch r k a) = 1 ∧ gs (is2 r k a) (ch r k a) = 1 := by
  have orb0 : ∀ n, n ≤ r + r → gs (is1 r k a) (gl (fun i => a + i * k) n) = 0 ∧ gs (is2 r k a) (gl (fun i => a + i * k) n) = 0 := by
    intro n
    induction n with
    | zero => intro _; exact ⟨rfl, rfl⟩
    | succ n ih =>
      intro hn
      have ⟨i1, i2⟩ := ih (Nat.le_of_succ_le hn)
      have b1 := beq_false (ne1g r k a p hp hpk hk hpa hr ha hak n hn)
      have b2 := beq_false (ne2g r k a p hp hpk hk hpa hqa n hn)
      constructor
      · show cond (Nat.beq (a + n * k) (V1 r k a)) 1 0 + gs (is1 r k a) (gl (fun i => a + i * k) n) = 0
        rw [b1, i1]; rfl
      · show cond (Nat.beq (a + n * k) (V1 r k a)) 0 (cond (Nat.beq (a + n * k) (V2 r k a)) 1 0)
          + gs (is2 r k a) (gl (fun i => a + i * k) n) = 0
        rw [b1, b2, i2]; rfl
  have ⟨o1, o2⟩ := orb0 (r + r) (Nat.le_refl _)
  have n12 := beq_false (fun e => ne12g r k a p hp hpk hk hpa hr hqa e.symm)
  constructor
  · show gs (is1 r k a) (gl (fun i => a + i * k) (r + r) ++ [V1 r k a, V2 r k a]) = 1
    rw [gs_app, o1]
    show 0 + (cond (Nat.beq (V1 r k a) (V1 r k a)) 1 0 + (cond (Nat.beq (V2 r k a) (V1 r k a)) 1 0 + 0)) = 1
    rw [beq_self, n12]; rfl
  · show gs (is2 r k a) (gl (fun i => a + i * k) (r + r) ++ [V1 r k a, V2 r k a]) = 1
    rw [gs_app, o2]
    show 0 + (cond (Nat.beq (V1 r k a) (V1 r k a)) 0 (cond (Nat.beq (V1 r k a) (V2 r k a)) 1 0)
      + (cond (Nat.beq (V2 r k a) (V1 r k a)) 0 (cond (Nat.beq (V2 r k a) (V2 r k a)) 1 0) + 0)) = 1
    rw [beq_self, n12, beq_self]; rfl


include hp hpk hk hpa hr ha hak hqa in
/-- G699: indecomposable whenever a prime p > 2q + 1 divides k but not a (q = 2r) -/
theorem qfamhalf_indec_gen : indec ((r + r) * k) (ch r k a) = true := by
  have hq2 : 2 ≤ r + r := Nat.add_le_add hr hr
  have h2q : (r + r) + (r + r) < p := Nat.lt_of_lt_of_le
    (show (r + r) + (r + r) < 2 * (r + r) + 1 by rw [show 2 * (r + r) + 1 = ((r + r) + (r + r)) + 1 by lib_nat]; exact Nat.lt_succ_self _)
    (Nat.le_of_lt hk)
  have ⟨d, hd, hkd, dpos⟩ := kd k a hak
  have hpd : ¬ p ∣ d := fun h => hpa (dvd_of_add p a d (by rw [← hd]; exact hpk) h)
  have hp2 : ¬ p ∣ 2 := small_ndvd p 2 (Nat.succ_pos 1) (Nat.lt_of_le_of_lt hq2 (Nat.lt_of_le_of_lt (Nat.le_add_right _ _) h2q))
  have hk0 : 0 < k := Nat.lt_of_le_of_lt (Nat.zero_le a) hak
  have hm2 : 2 ≤ (r + r) * k := Nat.le_trans hq2 (by
    have := Nat.mul_le_mul_left (r + r) (Nat.succ_le_of_lt hk0); rw [Nat.mul_one] at this; exact this)
  refine pad_indec ((r + r) * k) p (ch r k a) (padH r k a) hm2 (dvd_trans' hpk ⟨r + r, Nat.mul_comm _ _⟩)
    (fun x hx => memH_lt r k a hr ha hak hqa x hx)
    (fun x hx => dvd_trans' hpk (padH_dvdg r k a p hp hpk hk hpa hr ha hak hqa x hx)) ?_
  intro A B hs hA hB dv
  rw [padH_split r k a A, hkd] at dv
  have ⟨c1, c2⟩ := counts_chg r k a p hp hpk hk hpa hr ha hak hqa
  have s1 := splits_gs (is1 r k a) (ch r k a) A B hs
  have s2 := splits_gs (is2 r k a) (ch r k a) A B hs
  rw [c1] at s1; rw [c2] at s2
  have hl3 := len3 r k a A
  have hlc : (ch r k a).length = (r + r) + 2 := by
    show (gl (fun i => a + i * k) (r + r) ++ [V1 r k a, V2 r k a]).length = _
    rw [len_app2, gl_len]
  have hAB := (splits_props _ A B hs).1
  rw [hlc] at hAB
  have hBpos : 1 ≤ B.length := by
    cases hB0 : B with
    | nil => rw [hB0] at hB; exact nomatch hB
    | cons _ _ => exact Nat.succ_le_succ (Nat.zero_le _)
  have hApos : 1 ≤ A.length := by
    cases hA0 : A with
    | nil => rw [hA0] at hA; exact nomatch hA
    | cons _ _ => exact Nat.succ_le_succ (Nat.zero_le _)
  have hAq : A.length ≤ (r + r) + 1 := by
    have : A.length + 1 ≤ A.length + B.length := Nat.add_le_add_left hBpos _
    rw [hAB] at this; exact Nat.le_of_succ_le_succ this
  generalize gs (is1 r k a) A = e1 at s1 hl3 dv
  generalize gs (is2 r k a) A = e2 at s2 hl3 dv
  generalize gs (isO r k a) A = s at hl3 dv
  generalize r + r = q at hq2 h2q hp2 hAq hAB dv hm2 ⊢
  have hq0 : 0 < q := Nat.lt_of_lt_of_le (Nat.succ_pos 1) hq2
  have hqp : q < p := Nat.lt_of_le_of_lt (Nat.le_add_right q q) h2q
  have b1 : e1 ≤ 1 := by rw [← s1]; exact Nat.le_add_right _ _
  have b2 : e2 ≤ 1 := by rw [← s2]; exact Nat.le_add_right _ _
  have no2 : ∀ x, 2 + x ≤ 1 → False := fun x hx =>
    Nat.not_succ_le_self 1 (Nat.le_trans (Nat.le_add_right 2 x) hx)
  cases e2 with
  | succ e2' =>
    cases e2' with
    | succ x => exact no2 x (by rw [show 2 + x = x + 1 + 1 by lib_nat]; exact b2)
    | zero =>
      cases e1 with
      | succ e1' =>
        cases e1' with
        | succ x => exact no2 x (by rw [show 2 + x = x + 1 + 1 by lib_nat]; exact b1)
        | zero =>
          have hs' : s + 1 ≤ q := by
            have : 0 + 1 + (0 + 1) + s ≤ q + 1 := by rw [hl3]; exact hAq
            rw [show 0 + 1 + (0 + 1) + s = (s + 1) + 1 by lib_nat] at this
            exact Nat.le_of_succ_le_succ this
          have ⟨t, ht⟩ := LibGcd.le_dest hs'
          have e6 : (0 + 1) * (q * d) + (0 + 1) * (2 * (q * a)) + s * d
              + ((0 + 1) * (q * d) + (0 + 1) * (2 * (q * a)) + s * d) + 2 * ((1 + t) * d) = (4 * q) * k := by
            rw [hd, ht]; lib_nat
          have d5 : p ∣ ((0 + 1) * (q * d) + (0 + 1) * (2 * (q * a)) + s * d
              + ((0 + 1) * (q * d) + (0 + 1) * (2 * (q * a)) + s * d)) + 2 * ((1 + t) * d) := by
            rw [e6]; exact dvd_trans' hpk ⟨4 * q, Nat.mul_comm _ _⟩
          have d6 := dvd_of_add p _ _ (by rw [Nat.add_comm] at d5; exact d5) dv
          cases euclid_prime hp d6 with
          | inl h => exact hp2 h
          | inr h => cases euclid_prime hp h with
            | inl h' =>
              have : 1 + t ≤ q := by rw [ht, show s + 1 + t = (1 + t) + s by lib_nat]; exact Nat.le_add_right _ _
              exact small_ndvd p _ (by rw [Nat.add_comm]; exact Nat.succ_pos t) (Nat.lt_of_le_of_lt this hqp) h'
            | inr h' => exact hpd h'
      | zero =>
        have hs' : s ≤ q := by
          have : 0 + (0 + 1) + s ≤ q + 1 := by rw [hl3]; exact hAq
          rw [show 0 + (0 + 1) + s = s + 1 by lib_nat] at this
          exact Nat.le_of_succ_le_succ this
        have ⟨t, ht⟩ := LibGcd.le_dest hs'
        have e6 : 0 * (q * d) + (0 + 1) * (2 * (q * a)) + s * d
            + (0 * (q * d) + (0 + 1) * (2 * (q * a)) + s * d) + 2 * ((q + t) * d) = (4 * q) * k := by
          rw [hd, ht]; lib_nat
        have d5 : p ∣ (0 * (q * d) + (0 + 1) * (2 * (q * a)) + s * d
            + (0 * (q * d) + (0 + 1) * (2 * (q * a)) + s * d)) + 2 * ((q + t) * d) := by
          rw [e6]; exact dvd_trans' hpk ⟨4 * q, Nat.mul_comm _ _⟩
        have d6 := dvd_of_add p _ _ (by rw [Nat.add_comm] at d5; exact d5) dv
        cases euclid_prime hp d6 with
        | inl h => exact hp2 h
        | inr h => cases euclid_prime hp h with
          | inl h' =>
            have tq : t ≤ q := by rw [ht]; exact Nat.le_add_left t s
            exact small_ndvd p _ (Nat.lt_of_lt_of_le hq0 (Nat.le_add_right q t))
              (Nat.lt_of_le_of_lt (Nat.add_le_add_left tq q) h2q) h'
          | inr h' => exact hpd h'
  | zero =>
    cases e1 with
    | succ e1' =>
      cases e1' with
      | succ x => exact no2 x (by rw [show 2 + x = x + 1 + 1 by lib_nat]; exact b1)
      | zero =>
        have hs' : s ≤ q := by
          have : 0 + 1 + 0 + s ≤ q + 1 := by rw [hl3]; exact hAq
          rw [show 0 + 1 + 0 + s = s + 1 by lib_nat] at this
          exact Nat.le_of_succ_le_succ this
        rw [show (0 + 1) * (q * d) + 0 * (2 * (q * a)) + s * d + ((0 + 1) * (q * d) + 0 * (2 * (q * a)) + s * d)
          = 2 * ((q + s) * d) by lib_nat] at dv
        cases euclid_prime hp dv with
        | inl h => exact hp2 h
        | inr h => cases euclid_prime hp h with
          | inl h' =>
            exact small_ndvd p _ (Nat.lt_of_lt_of_le hq0 (Nat.le_add_right q s))
              (Nat.lt_of_le_of_lt (Nat.add_le_add_left hs' q) h2q) h'
          | inr h' => exact hpd h'
    | zero =>
      have hsA : s = A.length := by rw [← hl3]; lib_nat
      rw [show 0 * (q * d) + 0 * (2 * (q * a)) + s * d + (0 * (q * d) + 0 * (2 * (q * a)) + s * d)
        = 2 * (s * d) by lib_nat] at dv
      cases euclid_prime hp dv with
      | inl h => exact hp2 h
      | inr h => cases euclid_prime hp h with
        | inl h' =>
          rw [hsA] at h'
          exact small_ndvd p _ (Nat.lt_of_lt_of_le (Nat.succ_pos 0) hApos)
            (Nat.lt_of_le_of_lt hAq (Nat.lt_of_le_of_lt (Nat.add_le_add_left (Nat.succ_le_of_lt hq0) q) h2q)) h'
        | inr h' => exact hpd h'

end Fam

end QFamHalfGen

#print axioms QFamHalfGen.ne1g
#print axioms QFamHalfGen.ne2g
#print axioms QFamHalfGen.ne12g
#print axioms QFamHalfGen.padH_dvdg
#print axioms QFamHalfGen.counts_chg
#print axioms QFamHalfGen.qfamhalf_indec_gen

#print axioms: 6 theorems, no axioms.

81.167 Balanced fourfold characters for \(p=23\) are three pairs (Kamiak)

Every balanced length-6 character of the degree-23 Fermat fourfold is a union of three complementary pairs. Split by the first entry into 22 rfl pieces (hodge/Pairs6bP1–22); the bridge identifies the two filter definitions without evaluation.

hodge/Pairs6Bridge.lean

/-
  hodge/Pairs6Bridge.lean — T41 goal G560/G697 (Kamiak): Pairs6.badP m = Pairs6Split.badP m without evaluation — the
  two allPairs functions agree pointwise (same equations, induction), and filters with pointwise equal predicates
  agree. Used by Pairs6b / Pairs6c to move from the piece-wise checks to Pairs6.badP.

  Lean 4 core plus hodge/Pairs6 (badP, allPairs), hodge/Pairs6Split.
-/
import hodge.Pairs6
import hodge.Pairs6Split

namespace Pairs6Bridge

theorem allPairs_eq (m : Nat) : ∀ (f : Nat) (l : List Nat), Pairs6.allPairs m f l = Pairs6Split.allPairs m f l
  | 0, _ => rfl
  | _ + 1, [] => rfl
  | f + 1, x :: l => by
    show (l.contains (m - x) && Pairs6.allPairs m f (l.erase (m - x)))
      = (l.contains (m - x) && Pairs6Split.allPairs m f (l.erase (m - x)))
    rw [allPairs_eq m f (l.erase (m - x))]

theorem filter_congr' {α : Type} (p q : α → Bool) (h : ∀ x, p x = q x) : ∀ (l : List α), l.filter p = l.filter q
  | [] => rfl
  | x :: l => by
    rw [Pairs6Split.filter_cons2, Pairs6Split.filter_cons2, h x, filter_congr' p q h l]

theorem badP_eq (m : Nat) : Pairs6.badP m = Pairs6Split.badP m :=
  filter_congr' _ _ (fun c => by
    show (Indecomp.bal m c && !Pairs6.allPairs m 7 c) = (Indecomp.bal m c && !Pairs6Split.allPairs m 7 c)
    rw [allPairs_eq]) _

end Pairs6Bridge

#print axioms Pairs6Bridge.allPairs_eq
#print axioms Pairs6Bridge.filter_congr'
#print axioms Pairs6Bridge.badP_eq

hodge/Pairs6b.lean

/-
  hodge/Pairs6b.lean — T41 goal G560 (Kamiak): for p = 23 every balanced length-6 character of the degree-23 Fermat
  fourfold is a union of three complementary pairs (p ≤ 19 in Pairs6Small / Pairs6). The single rfl exceeded the
  recursion limit, so the check is split by the first entry (Pairs6Split.badP_split) into 22 pieces
  hodge/Pairs6bP1 … Pairs6bP22, each rfl.

  Lean 4 core plus hodge/Pairs6 (badP), hodge/Pairs6Split, hodge/Pairs6bP1–22.
-/
import hodge.Pairs6
import hodge.Pairs6Bridge
import hodge.Pairs6bP1
import hodge.Pairs6bP2
import hodge.Pairs6bP3
import hodge.Pairs6bP4
import hodge.Pairs6bP5
import hodge.Pairs6bP6
import hodge.Pairs6bP7
import hodge.Pairs6bP8
import hodge.Pairs6bP9
import hodge.Pairs6bP10
import hodge.Pairs6bP11
import hodge.Pairs6bP12
import hodge.Pairs6bP13
import hodge.Pairs6bP14
import hodge.Pairs6bP15
import hodge.Pairs6bP16
import hodge.Pairs6bP17
import hodge.Pairs6bP18
import hodge.Pairs6bP19
import hodge.Pairs6bP20
import hodge.Pairs6bP21
import hodge.Pairs6bP22

namespace Pairs6b
open Pairs6Split

set_option maxHeartbeats 0 in
set_option maxRecDepth 1000000 in
theorem p23 : Pairs6.badP 23 = [] := by
  rw [Pairs6Bridge.badP_eq, badP_split]
  show badAt 23 1 ++ (badAt 23 2 ++ (badAt 23 3 ++ (badAt 23 4 ++ (badAt 23 5 ++ (badAt 23 6 ++ (badAt 23 7 ++ (badAt 23 8 ++ (badAt 23 9 ++ (badAt 23 10 ++ (badAt 23 11 ++ (badAt 23 12 ++ (badAt 23 13 ++ (badAt 23 14 ++ (badAt 23 15 ++ (badAt 23 16 ++ (badAt 23 17 ++ (badAt 23 18 ++ (badAt 23 19 ++ (badAt 23 20 ++ (badAt 23 21 ++ (badAt 23 22 ++ ([])))))))))))))))))))))) = []
  rw [Pairs6bP1.piece, Pairs6bP2.piece, Pairs6bP3.piece, Pairs6bP4.piece, Pairs6bP5.piece, Pairs6bP6.piece, Pairs6bP7.piece, Pairs6bP8.piece, Pairs6bP9.piece, Pairs6bP10.piece, Pairs6bP11.piece, Pairs6bP12.piece, Pairs6bP13.piece, Pairs6bP14.piece, Pairs6bP15.piece, Pairs6bP16.piece, Pairs6bP17.piece, Pairs6bP18.piece, Pairs6bP19.piece, Pairs6bP20.piece, Pairs6bP21.piece, Pairs6bP22.piece]
  rfl

end Pairs6b

#print axioms Pairs6b.p23

#print axioms: 4 theorems (and 22 pieces), no axioms.

81.168 Balanced surface characters for \(p=47\) (Kamiak)

Every balanced length-4 character of the degree-47 Fermat surface is two complementary pairs; length 4 settled for all odd primes \(p\le 47\).

hodge/Pairs4g.lean

/-
  hodge/Pairs4g.lean — T41 cycle 1073 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 47:
  every balanced length-4 character of the degree-47 Fermat surface is a union of two complementary pairs (rfl, no
  heartbeat limit). With Pairs4, Pairs4b, Pairs4c, Pairs4d: length 4 settled for all odd primes p ≤ 47.

  Lean 4 core plus hodge/Pairs4 (badQ), rfl.
-/
import hodge.Pairs4

namespace Pairs4g
open Pairs4

set_option maxHeartbeats 0 in
set_option maxRecDepth 4000000 in
theorem r47 : badQ 47 = [] := rfl

end Pairs4g

#print axioms Pairs4g.r47

#print axioms: 1 theorem, no axioms.

81.169 Balanced surface characters for \(p=53\) (Kamiak)

Every balanced length-4 character of the degree-53 Fermat surface is two complementary pairs; length 4 settled for all odd primes \(p\le 53\).

hodge/Pairs4h.lean

/-
  hodge/Pairs4h.lean — T41 cycle 1085 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 53:
  every balanced length-4 character of the degree-53 Fermat surface is a union of two complementary pairs (rfl, no
  heartbeat limit). With Pairs4, Pairs4b, Pairs4c, Pairs4d: length 4 settled for all odd primes p ≤ 53.

  Lean 4 core plus hodge/Pairs4 (badQ), rfl.
-/
import hodge.Pairs4

namespace Pairs4h
open Pairs4

set_option maxHeartbeats 0 in
set_option maxRecDepth 8000000 in
theorem r53 : badQ 53 = [] := rfl

end Pairs4h

#print axioms Pairs4h.r53

#print axioms: 1 theorem, no axioms.

81.170 A family through the \(m=70\) seed

\(F_p\): the coset \(\{1+14k\}\subset \mathbb Z/14p\) with its multiple of \(p\) moved by \(6p\); balanced and indecomposable for \(p=3,5\), balanced for \(p=17,19\). \(F_5\) is the open length-5 seed \([1,29,43,45,57]\) at \(m=70\).

hodge/SeedFam.lean

/-
  hodge/SeedFam.lean — T41 cycle 1145 (goal G749a): the first members of the family F_p through the m = 70 seed.
  For an odd prime p ≠ 7, F_p ⊂ Z/14p is the coset {1 + 14k : k < p} with its element x ≡ 0 (mod p) replaced by
  x + 6p. Balanced exactly when p mod 14 ∈ {1, 3, 5} (computation, p ≤ 89); here, by rfl:
    f3    F_3 = [1, 29, 33] at m = 42:   balanced and indecomposable
    f5    F_5 = [1, 29, 43, 45, 57] at m = 70 (the open seed of G498c):   balanced and indecomposable
    f17b  F_17 at m = 238:   balanced
    f19b  F_19 at m = 266:   balanced
  (indecomposability of F_17, F_19: hodge/SeedFamK, Kamiak).

  Lean 4 core plus hodge/Indecomp (bal, indec), rfl.
-/
import hodge.Indecomp

namespace SeedFam
open Indecomp

set_option maxRecDepth 100000 in
theorem f3 : bal 42 [1, 29, 33] = true ∧ indec 42 [1, 29, 33] = true := ⟨rfl, rfl⟩

set_option maxRecDepth 100000 in
theorem f5 : bal 70 [1, 29, 43, 45, 57] = true ∧ indec 70 [1, 29, 43, 45, 57] = true := ⟨rfl, rfl⟩

set_option maxRecDepth 100000 in
theorem f17b : bal 238 [1, 15, 29, 43, 57, 71, 99, 113, 127, 141, 155, 169, 183, 187, 197, 211, 225] = true := rfl

set_option maxRecDepth 100000 in
theorem f19b : bal 266 [1, 15, 29, 43, 71, 85, 99, 113, 127, 141, 155, 169, 171, 183, 197, 211, 225, 239, 253] = true := rfl

end SeedFam

#print axioms SeedFam.f3
#print axioms SeedFam.f5
#print axioms SeedFam.f17b
#print axioms SeedFam.f19b

#print axioms: 4 theorems, no axioms.

81.171 Unit sums of a coset modulo \(14p\)

\((r+14X)\bmod 14p=r+14(X\bmod p)\), and \(\sum _{k<p}(t(1+14k)\bmod 14p)=p\,(t\bmod 14)+14\sum _{i<p}i\) for \(\gcd (t,p)=1\). First half of the balancedness of the family \(F_p\).

hodge/FamMod.lean

/-
  hodge/FamMod.lean — T41 cycle 1147 (goal G749b, step 1): the Chinese-remainder split of a residue mod 14p.
    mod_split   r < 14, 0 < p  ⇒  (r + 14·X) % (14·p) = r + 14·(X % p)
    coset_sum   for a unit-type multiplier: Σ_{k<p} (r + 14·((a + t·k) % p)) = p·r + 14·Σ_{i<p} i   (gcd t p = 1)
    mod_pmul    (p·Z) % (14·p) = p·(Z % 14)
    fcond_table the finite condition r + ((r s + 6r) mod 14) = 7 + (r s mod 14) for all units r mod 14 holds iff s ∈ {1,3,5}
  The unit-t sum of the coset {1 + 14k : k < p} ⊂ Z/14p is therefore p·r + 14·p(p−1)/2 with r = t mod 14
  (PermSum.perm_sum), the first half of the balancedness of the family F_p (G749b).

  Lean 4 core plus hodge/PermSum (perm_sum, sumF), hodge/GcdHand (div_mod), hodge/ModHand.
-/
import hodge.PermSum

namespace FamMod
open GcdHand ModHand OrbitSum APPairGen PermSum

theorem mod_split (r X p : Nat) (hp : 0 < p) (hr : r < 14) : (r + 14 * X) % (14 * p) = r + 14 * (X % p) := by
  have hs : X % p < p := Nat.mod_lt _ hp
  have ⟨q, hq⟩ := div_mod p hp (X + 1) X (Nat.lt_succ_self X)
  generalize X % p = s at hs hq ⊢
  subst hq
  have e : r + 14 * (s + p * q) = (r + 14 * s) + q * (14 * p) := by lib_nat
  rw [e, add_mul_mod' _ _ (Nat.mul_pos (Nat.succ_pos 13) hp)]
  apply mod_lt'
  have h1 : r + 14 * s < 14 + 14 * s := Nat.add_lt_add_right hr _
  have h2 : 14 + 14 * s ≤ 14 * p := by
    have : 14 * (s + 1) ≤ 14 * p := Nat.mul_le_mul_left 14 hs
    have e2 : 14 * (s + 1) = 14 + 14 * s := by lib_nat
    rw [e2] at this; exact this
  exact Nat.lt_of_lt_of_le h1 h2

theorem sumF_congr (f g : Nat → Nat) (h : ∀ i, f i = g i) : ∀ n, sumF f n = sumF g n
  | 0 => rfl
  | n + 1 => by show sumF f n + f n = sumF g n + g n; rw [sumF_congr f g h n, h n]

theorem sumF_lin (r : Nat) (f : Nat → Nat) : ∀ n, sumF (fun i => r + 14 * f i) n = n * r + 14 * sumF f n
  | 0 => by show 0 = 0 * r + 14 * 0; lib_nat
  | n + 1 => by
    show sumF (fun i => r + 14 * f i) n + (r + 14 * f n) = (n + 1) * r + 14 * (sumF f n + f n)
    rw [sumF_lin r f n]; lib_nat

/-- the unit-t sum of the coset {1 + 14k : k < p} in Z/14p -/
theorem coset_sum (t p : Nat) (hp : 0 < p) (hg : Nat.gcd t p = 1) :
    sumF (fun k => (t * (1 + 14 * k)) % (14 * p)) p = p * (t % 14) + 14 * sumF (fun i => i) p := by
  have hr : t % 14 < 14 := Nat.mod_lt _ (Nat.succ_pos 13)
  have ⟨q, hq⟩ := div_mod 14 (Nat.succ_pos 13) (t + 1) t (Nat.lt_succ_self t)
  have e : ∀ k, (t * (1 + 14 * k)) % (14 * p) = t % 14 + 14 * ((q + t * k) % p) := by
    intro k
    have e1 : t * (1 + 14 * k) = t % 14 + 14 * (q + t * k) := by
      calc t * (1 + 14 * k) = t + 14 * (t * k) := by lib_nat
        _ = (t % 14 + 14 * q) + 14 * (t * k) := by rw [← hq]
        _ = _ := by lib_nat
    rw [e1, mod_split _ _ _ hp hr]
  rw [sumF_congr _ _ e p, sumF_lin, perm_sum p t q hp hg]

theorem mod_pmul (p Z : Nat) (hp : 0 < p) : (p * Z) % (14 * p) = p * (Z % 14) := by
  have hs : Z % 14 < 14 := Nat.mod_lt _ (Nat.succ_pos 13)
  have ⟨q, hq⟩ := div_mod 14 (Nat.succ_pos 13) (Z + 1) Z (Nat.lt_succ_self Z)
  generalize Z % 14 = s at hs hq ⊢
  subst hq
  have e : p * (s + 14 * q) = p * s + q * (14 * p) := by lib_nat
  rw [e, add_mul_mod' _ _ (Nat.mul_pos (Nat.succ_pos 13) hp)]
  apply mod_lt'
  have : p * s < p * 14 := Nat.mul_lt_mul_of_le_of_lt (Nat.le_refl p) hs hp
  have e2 : p * 14 = 14 * p := by lib_nat
  rw [e2] at this; exact this

/-- the finite condition: for the units r mod 14 and the inverse class s = x₀ mod 14,
  r − (r·s mod 14) + ((r·s + 6r) mod 14) = 7 -/
def fcond (s : Nat) : Bool :=
  [1, 3, 5, 9, 11, 13].all (fun r => Nat.beq (r + (r * s + 6 * r) % 14) (7 + (r * s) % 14))

/-- it holds exactly for s ∈ {1, 3, 5} (s = p⁻¹ mod 14, i.e. p mod 14 ∈ {1, 5, 3}) -/
theorem fcond_table : (fcond 1, fcond 3, fcond 5, fcond 9, fcond 11, fcond 13) = (true, true, true, false, false, false) := rfl

end FamMod

#print axioms FamMod.mod_split
#print axioms FamMod.sumF_congr
#print axioms FamMod.sumF_lin
#print axioms FamMod.coset_sum
#print axioms FamMod.mod_pmul
#print axioms FamMod.fcond_table

#print axioms: 6 theorems, no axioms.

81.172 Arithmetic for the family \(F_p\)

Units of \(14p\) are prime to \(p\) and lie in \(\{1,3,5,9,11,13\}\) mod \(14\); hand \(\bmod \) of products; unit sums of a list with one replaced entry. Hand lemmas (core \(\gcd \)/\(\bmod \) lemmas carry axioms).

hodge/FamArith.lean

/-
  hodge/FamArith.lean — T41 cycle 1151 (goal G749b, step 3a): arithmetic for the balancedness of the family F_p.
    cop_right    gcd t (a·p) = 1  ⇒  gcd t p = 1          cop_left   ⇒  gcd t a = 1
    mul_mod'     (t·x) % n = ((t % n)·(x % n)) % n         (hand, n > 0)
    lin_mod'     (t·x + 6t) % n = ((t % n)·(x % n) + 6·(t % n)) % n
    unit14       gcd t 14 = 1  ⇒  t % 14 ∈ [1, 3, 5, 9, 11, 13]
    gl_tsum      tsum m t (gl g n) = Σ_{k<n} (t·g k) % m
    sumF_replace f = g off the index i₀ < n  ⇒  Σ_{k<n} f + g i₀ = Σ_{k<n} g + f i₀

  Lean 4 core plus hodge/FamMod, hodge/UnitMul (gcd_dvd, one_of_dvd_one), hodge/APPair1 (dvd_gcd), hodge/Indecomp (tsum).
-/
import hodge.FamMod
import hodge.UnitMul
import hodge.Indecomp

namespace FamArith
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod Indecomp

theorem cop_right (t a p : Nat) (h : Nat.gcd t (a * p) = 1) : Nat.gcd t p = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := UnitMul.gcd_dvd t p
  have ⟨c, hc⟩ := APPair1.dvd_gcd (Nat.gcd t p) t (a * p) ⟨i, hi⟩ ⟨a * j, by
    calc a * p = a * (Nat.gcd t p * j) := by rw [← hj]
      _ = Nat.gcd t p * (a * j) := by lib_nat⟩
  rw [h] at hc
  exact UnitMul.one_of_dvd_one _ c hc

theorem cop_left (t a p : Nat) (h : Nat.gcd t (a * p) = 1) : Nat.gcd t a = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := UnitMul.gcd_dvd t a
  have ⟨c, hc⟩ := APPair1.dvd_gcd (Nat.gcd t a) t (a * p) ⟨i, hi⟩ ⟨j * p, by
    calc a * p = (Nat.gcd t a * j) * p := by rw [← hj]
      _ = Nat.gcd t a * (j * p) := by lib_nat⟩
  rw [h] at hc
  exact UnitMul.one_of_dvd_one _ c hc

theorem mul_mod' (n t x : Nat) (hn : 0 < n) : (t * x) % n = ((t % n) * (x % n)) % n := by
  have ⟨a, ha⟩ := div_mod n hn (t + 1) t (Nat.lt_succ_self t)
  have ⟨b, hb⟩ := div_mod n hn (x + 1) x (Nat.lt_succ_self x)
  generalize t % n = r at ha ⊢
  generalize x % n = s at hb ⊢
  subst ha; subst hb
  have e : (r + n * a) * (s + n * b) = r * s + (a * s + r * b + n * a * b) * n := by lib_nat
  rw [e, add_mul_mod' _ _ hn]

theorem lin_mod' (n t x : Nat) (hn : 0 < n) : (t * x + 6 * t) % n = ((t % n) * (x % n) + 6 * (t % n)) % n := by
  have ⟨a, ha⟩ := div_mod n hn (t + 1) t (Nat.lt_succ_self t)
  have ⟨b, hb⟩ := div_mod n hn (x + 1) x (Nat.lt_succ_self x)
  generalize t % n = r at ha ⊢
  generalize x % n = s at hb ⊢
  subst ha; subst hb
  have e : (r + n * a) * (s + n * b) + 6 * (r + n * a) = (r * s + 6 * r) + (a * s + r * b + n * a * b + 6 * a) * n := by lib_nat
  rw [e, add_mul_mod' _ _ hn]

theorem no_common (t d e f : Nat) (h : Nat.gcd t 14 = 1) (ht : t = d * e) (h14 : 14 = d * f) (hd : 2 ≤ d) : False := by
  have ⟨c, hc⟩ := APPair1.dvd_gcd d t 14 ⟨e, ht⟩ ⟨f, h14⟩
  rw [h] at hc
  exact APPair1.one_eq_mul d c hc hd

theorem unit14 (t : Nat) (h : Nat.gcd t 14 = 1) : t % 14 ∈ [1, 3, 5, 9, 11, 13] := by
  have hr : t % 14 < 14 := Nat.mod_lt _ (Nat.succ_pos 13)
  have ⟨q, hq⟩ := div_mod 14 (Nat.succ_pos 13) (t + 1) t (Nat.lt_succ_self t)
  generalize t % 14 = r at hr hq ⊢
  have two : 2 ≤ 2 := Nat.le_refl 2
  have seven : 2 ≤ 7 := Nat.le_succ_of_le (Nat.le_succ_of_le (Nat.le_succ_of_le (Nat.le_succ_of_le (Nat.le_succ_of_le (Nat.le_refl 2)))))
  match r, hr with
  | 0, _ => exact (no_common t 2 (7 * q) 7 h (by rw [hq]; lib_nat) rfl two).elim
  | 1, _ => exact List.Mem.head _
  | 2, _ => exact (no_common t 2 (1 + 7 * q) 7 h (by rw [hq]; lib_nat) rfl two).elim
  | 3, _ => exact List.Mem.tail _ (List.Mem.head _)
  | 4, _ => exact (no_common t 2 (2 + 7 * q) 7 h (by rw [hq]; lib_nat) rfl two).elim
  | 5, _ => exact List.Mem.tail _ (List.Mem.tail _ (List.Mem.head _))
  | 6, _ => exact (no_common t 2 (3 + 7 * q) 7 h (by rw [hq]; lib_nat) rfl two).elim
  | 7, _ => exact (no_common t 7 (1 + 2 * q) 2 h (by rw [hq]; lib_nat) rfl seven).elim
  | 8, _ => exact (no_common t 2 (4 + 7 * q) 7 h (by rw [hq]; lib_nat) rfl two).elim
  | 9, _ => exact List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.head _)))
  | 10, _ => exact (no_common t 2 (5 + 7 * q) 7 h (by rw [hq]; lib_nat) rfl two).elim
  | 11, _ => exact List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.head _))))
  | 12, _ => exact (no_common t 2 (6 + 7 * q) 7 h (by rw [hq]; lib_nat) rfl two).elim
  | 13, _ => exact List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.tail _ (List.Mem.head _)))))
  | r + 14, hr' => exact absurd hr' (Nat.not_lt.mpr (Nat.le_add_left 14 r))

theorem gl_tsum (m t : Nat) (g : Nat → Nat) : ∀ n, tsum m t (gl g n) = sumF (fun k => (t * g k) % m) n
  | 0 => rfl
  | n + 1 => by
    show (t * g n) % m + tsum m t (gl g n) = sumF (fun k => (t * g k) % m) n + (t * g n) % m
    rw [gl_tsum m t g n]; lib_nat

theorem sumF_congr_lt (f g : Nat → Nat) : ∀ n, (∀ k, k < n → f k = g k) → sumF f n = sumF g n
  | 0, _ => rfl
  | n + 1, h => by
    show sumF f n + f n = sumF g n + g n
    rw [sumF_congr_lt f g n (fun k hk => h k (Nat.lt_succ_of_lt hk)), h n (Nat.lt_succ_self n)]

theorem sumF_replace (f g : Nat → Nat) (i0 : Nat) (h : ∀ k, k ≠ i0 → f k = g k) : ∀ n, i0 < n →
    sumF f n + g i0 = sumF g n + f i0
  | 0, hi => absurd hi (Nat.not_lt_zero _)
  | n + 1, hi => by
    show sumF f n + f n + g i0 = sumF g n + g n + f i0
    cases Nat.lt_or_ge i0 n with
    | inl hlt =>
      have ih := sumF_replace f g i0 h n hlt
      have e := h n (fun e => Nat.lt_irrefl n (e ▸ hlt))
      rw [e]
      calc sumF f n + g n + g i0 = (sumF f n + g i0) + g n := by lib_nat
        _ = (sumF g n + f i0) + g n := by rw [ih]
        _ = _ := by lib_nat
    | inr hge =>
      have e0 : i0 = n := Nat.le_antisymm (Nat.le_of_lt_succ hi) hge
      subst e0
      rw [sumF_congr_lt f g i0 (fun k hk => h k (fun e => Nat.lt_irrefl k (e ▸ hk)))]
      lib_nat

end FamArith

#print axioms FamArith.cop_right
#print axioms FamArith.cop_left
#print axioms FamArith.mul_mod'
#print axioms FamArith.lin_mod'
#print axioms FamArith.no_common
#print axioms FamArith.unit14
#print axioms FamArith.gl_tsum
#print axioms FamArith.sumF_congr_lt
#print axioms FamArith.sumF_replace

#print axioms: 9 theorems, no axioms.

81.173 The family \(F_p\) is balanced

For \(1+14i_0=px_0\) with \(x_0\bmod 14\in \{1,3,5\}\), the coset \(\{1+14k\}\subset \mathbb Z/14p\) with \(1+14i_0\) moved by \(6p\) is balanced, for every \(p\). Covers the open \(m=70\) seed (\(p=5\)); instances \(p=17,29\).

hodge/FamBal.lean

/-
  hodge/FamBal.lean — T41 cycle 1153 (goal G749b — the balancedness of the family): for every p > 0 and index i₀ < p
  with 1 + 14·i₀ = p·x₀ and x₀ mod 14 ∈ {1, 3, 5} (i.e. p mod 14 ∈ {1, 5, 3} when gcd(p, 14) = 1), the character
    F_p = {1 + 14k : k < p, k ≠ i₀} ∪ {1 + 14·i₀ + 6p}  ⊂ Z/14p
  is balanced:
    fam_bal   bal (14p) (fam p i₀) = true.
  For every unit t of 14p (r = t mod 14 ∈ {1,3,5,9,11,13}, gcd(t, p) = 1) the unit sum is
  Σ_coset − p·(rs mod 14) + p·((rs + 6r) mod 14) = 7p + 14·Σ_{i<p} i = 7p² by FamMod.coset_sum and the finite
  table FamMod.fcond. With hodge/SeedFam this covers the open m = 70 seed (p = 5) and m = 42, 238, 266, … .

  Lean 4 core plus hodge/FamArith, hodge/FamMod, hodge/FermatPrime (units).
-/
import hodge.FamArith

namespace FamBal
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp

def fam (p i0 : Nat) : List Nat := gl (fun k => if Nat.beq k i0 then 1 + 14 * k + 6 * p else 1 + 14 * k) p

theorem add_right_cancel' (n k : Nat) : ∀ m, n + m = k + m → n = k
  | 0, h => h
  | m + 1, h => add_right_cancel' n k m (Nat.succ.inj h)

theorem beq_refl' : ∀ n : Nat, Nat.beq n n = true
  | 0 => rfl
  | n + 1 => beq_refl' n

theorem all_filter (pr P : Nat → Bool) (h : ∀ t, pr t = true → P t = true) : ∀ l : List Nat, (l.filter pr).all P = true
  | [] => rfl
  | x :: l => by
    cases hx : pr x with
    | false =>
      have e : (x :: l).filter pr = l.filter pr := by show (match pr x with | true => x :: l.filter pr | false => l.filter pr) = _; rw [hx]
      rw [e]; exact all_filter pr P h l
    | true =>
      have e : (x :: l).filter pr = x :: l.filter pr := by show (match pr x with | true => x :: l.filter pr | false => l.filter pr) = _; rw [hx]
      rw [e]
      show (P x && (l.filter pr).all P) = true
      rw [h x hx, all_filter pr P h l]; rfl

theorem all_mem (P : Nat → Bool) : ∀ (l : List Nat), l.all P = true → ∀ r, r ∈ l → P r = true
  | [], _, _, h => nomatch h
  | x :: l, hl, r, hr => by
    have hx : P x = true ∧ l.all P = true := by
      cases e1 : P x with
      | false => rw [show (x :: l).all P = (P x && l.all P) from rfl, e1] at hl; exact nomatch hl
      | true => rw [show (x :: l).all P = (P x && l.all P) from rfl, e1] at hl; exact ⟨rfl, hl⟩
    cases hr with
    | head => exact hx.1
    | tail _ h' => exact all_mem P l hx.2 r h'

theorem sum_id : ∀ p, sumF (fun i => i) p + sumF (fun i => i) p + p = p * p
  | 0 => rfl
  | p + 1 => by
    show (sumF (fun i => i) p + p) + (sumF (fun i => i) p + p) + (p + 1) = (p + 1) * (p + 1)
    have ih := sum_id p
    calc (sumF (fun i => i) p + p) + (sumF (fun i => i) p + p) + (p + 1)
        = (sumF (fun i => i) p + sumF (fun i => i) p + p) + (p + p + 1) := by lib_nat
      _ = p * p + (p + p + 1) := by rw [ih]
      _ = _ := by lib_nat

/-- the unit sum of F_p for one unit t -/
theorem fam_tsum (p i0 x0 t : Nat) (hp : 0 < p) (hi : i0 < p) (hx : 1 + 14 * i0 = p * x0)
    (hs : fcond (x0 % 14) = true) (ht : Nat.gcd t (14 * p) = 1) :
    tsum (14 * p) t (fam p i0) + tsum (14 * p) t (fam p i0) = p * (14 * p) := by
  have htp : Nat.gcd t p = 1 := cop_right t 14 p ht
  have ht14 : Nat.gcd t 14 = 1 := cop_left t 14 p ht
  have hr := unit14 t ht14
  have h14 : 0 < 14 := Nat.succ_pos 13
  -- the condition for r = t mod 14
  have cond := Nat.eq_of_beq_eq_true (all_mem _ [1, 3, 5, 9, 11, 13] hs (t % 14) hr)
  -- the sum as sumF, and the replacement
  unfold fam
  rw [gl_tsum]
  have rep := sumF_replace (fun k => (t * (if Nat.beq k i0 then 1 + 14 * k + 6 * p else 1 + 14 * k)) % (14 * p))
    (fun k => (t * (1 + 14 * k)) % (14 * p)) i0 (fun k hk => by
      have : Nat.beq k i0 = false := by
        cases e : Nat.beq k i0 with
        | false => rfl
        | true => exact absurd (Nat.eq_of_beq_eq_true e) hk
      show (t * (if Nat.beq k i0 = true then _ else _)) % _ = _
      rw [this]; rfl) p hi
  rw [coset_sum t p hp htp] at rep
  have bi : Nat.beq i0 i0 = true := beq_refl' i0
  have f0 : (t * (if Nat.beq i0 i0 = true then 1 + 14 * i0 + 6 * p else 1 + 14 * i0)) % (14 * p)
      = p * (((t % 14) * (x0 % 14) + 6 * (t % 14)) % 14) := by
    rw [bi]
    show (t * (1 + 14 * i0 + 6 * p)) % (14 * p) = _
    have e : t * (1 + 14 * i0 + 6 * p) = p * (t * x0 + 6 * t) := by
      calc t * (1 + 14 * i0 + 6 * p) = t * (1 + 14 * i0) + 6 * p * t := by lib_nat
        _ = t * (p * x0) + 6 * p * t := by rw [hx]
        _ = _ := by lib_nat
    rw [e, mod_pmul p _ hp, lin_mod' 14 t x0 h14]
  have g0 : (t * (1 + 14 * i0)) % (14 * p) = p * (((t % 14) * (x0 % 14)) % 14) := by
    have e : t * (1 + 14 * i0) = p * (t * x0) := by rw [hx]; lib_nat
    rw [e, mod_pmul p _ hp, mul_mod' 14 t x0 h14]
  have rep' : sumF (fun k => (t * (if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k)) % (14 * p)) p
      + (t * (1 + 14 * i0)) % (14 * p)
      = p * (t % 14) + 14 * sumF (fun i => i) p + (t * (if Nat.beq i0 i0 = true then 1 + 14 * i0 + 6 * p else 1 + 14 * i0)) % (14 * p) := rep
  rw [f0, g0] at rep'
  -- rep' : T + p·u = p·r + 14·S + p·u'   with   r + u' = 7 + u
  generalize sumF (fun k => (t * (if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k)) % (14 * p)) p = T at rep' ⊢
  generalize ((t % 14) * (x0 % 14)) % 14 = u at rep' cond
  generalize ((t % 14) * (x0 % 14) + 6 * (t % 14)) % 14 = u' at rep' cond
  generalize t % 14 = r at rep' cond
  have sid := sum_id p
  generalize sumF (fun i => i) p = S at rep' sid
  have hT : T = 7 * p + 14 * S := by
    apply add_right_cancel' T (7 * p + 14 * S) (p * u)
    calc T + p * u = p * r + 14 * S + p * u' := rep'
      _ = p * (r + u') + 14 * S := by lib_nat
      _ = p * (7 + u) + 14 * S := by rw [cond]
      _ = _ := by lib_nat
  rw [hT]
  calc 7 * p + 14 * S + (7 * p + 14 * S) = 14 * (S + S + p) := by lib_nat
    _ = 14 * (p * p) := by rw [sid]
    _ = _ := by lib_nat

/-- **The family F_p is balanced.** -/
theorem fam_bal (p i0 x0 : Nat) (hp : 0 < p) (hi : i0 < p) (hx : 1 + 14 * i0 = p * x0)
    (hs : fcond (x0 % 14) = true) : bal (14 * p) (fam p i0) = true := by
  unfold bal FermatPrime.units
  apply all_filter
  intro t ht
  have hg : Nat.gcd t (14 * p) = 1 := Nat.eq_of_beq_eq_true ht
  have e := fam_tsum p i0 x0 t hp hi hx hs hg
  have hl : (fam p i0).length = p := gl_len _ p
  rw [hl, e]
  exact beq_refl' _

/-- instances: p = 5 (the m = 70 seed), p = 17 (m = 238), p = 29 (m = 406) -/
theorem inst5 : bal 70 (fam 5 1) = true := fam_bal 5 1 3 (Nat.succ_pos 4) (Nat.succ_lt_succ (Nat.succ_pos 3)) rfl rfl
theorem inst17 : bal 238 (fam 17 6) = true := fam_bal 17 6 5 (Nat.succ_pos 16) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 6) (Nat.le_add_left 7 10)) rfl rfl
theorem inst29 : bal 406 (fam 29 2) = true := fam_bal 29 2 1 (Nat.succ_pos 28) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 2) (Nat.le_add_left 3 26)) rfl rfl
theorem fam5_eq : fam 5 1 = [57, 43, 29, 45, 1] := rfl

end FamBal

#print axioms FamBal.add_right_cancel'
#print axioms FamBal.beq_refl'
#print axioms FamBal.all_filter
#print axioms FamBal.all_mem
#print axioms FamBal.sum_id
#print axioms FamBal.fam_tsum
#print axioms FamBal.fam_bal
#print axioms FamBal.inst5
#print axioms FamBal.inst17
#print axioms FamBal.inst29
#print axioms FamBal.fam5_eq

#print axioms: 11 theorems, no axioms.

81.174 Unit sums over \(t\equiv 1\pmod {14}\)

For \(x=1+14k\) prime to \(p\): \(\sum _{i<p}\langle (1+14i)x\rangle _{14p}=p+14\sum _{i<p}i\), and the term at \(t^*=1+14i_0=px_0\) is \(t^*\). Averaging input for the indecomposability of \(F_p\).

hodge/FamIndec1.lean

/-
  hodge/FamIndec1.lean — T41 cycle 1157 (goal G749c, piece K2): the unit sums of a coset element over the units
  t_i = 1 + 14i of Z/14p. For x = 1 + 14k with gcd(x, p) = 1, and t* = 1 + 14·i₀ = p·x₀ (i₀ < p):
    avg_all    Σ_{i<p} ⟨(1 + 14i)·x⟩_{14p} = p + 14·Σ_{i<p} i
    omit_term  ⟨t*·x⟩_{14p} = t*
    avg_omit   Σ_{i<p, i≠i₀} ⟨(1 + 14i)·x⟩_{14p} + t* = p + 14·Σ_{i<p} i
  Averaging the balance condition of a split part over these p − 1 units (FamIndec2) forces t* = p.

  Lean 4 core plus hodge/FamArith (sumF_replace), hodge/FamMod (mod_split), hodge/PermSum (perm_sum).
-/
import hodge.FamBal

namespace FamIndec1
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp

theorem avg_all (p k : Nat) (hp : 0 < p) (hx : Nat.gcd (1 + 14 * k) p = 1) :
    sumF (fun i => ((1 + 14 * i) * (1 + 14 * k)) % (14 * p)) p = p + 14 * sumF (fun i => i) p := by
  have e : ∀ i, ((1 + 14 * i) * (1 + 14 * k)) % (14 * p) = 1 + 14 * ((k + (1 + 14 * k) * i) % p) := by
    intro i
    have e1 : (1 + 14 * i) * (1 + 14 * k) = 1 + 14 * (k + (1 + 14 * k) * i) := by lib_nat
    rw [e1, mod_split 1 _ p hp (Nat.succ_lt_succ (Nat.succ_pos 12))]
  rw [sumF_congr _ _ e p, sumF_lin, perm_sum p (1 + 14 * k) k hp hx]
  lib_nat

theorem omit_term (p i0 x0 k : Nat) (hi : i0 < p) (ht : 1 + 14 * i0 = p * x0) :
    ((1 + 14 * i0) * (1 + 14 * k)) % (14 * p) = 1 + 14 * i0 := by
  have hp : 0 < p := Nat.lt_of_le_of_lt (Nat.zero_le i0) hi
  have e : (1 + 14 * i0) * (1 + 14 * k) = (1 + 14 * i0) + (k * x0) * (14 * p) := by
    calc (1 + 14 * i0) * (1 + 14 * k) = (1 + 14 * i0) + 14 * k * (1 + 14 * i0) := by lib_nat
      _ = (1 + 14 * i0) + 14 * k * (p * x0) := by rw [ht]
      _ = _ := by lib_nat
  rw [e, add_mul_mod' _ _ (Nat.mul_pos (Nat.succ_pos 13) hp)]
  apply mod_lt'
  have h1 : 1 + 14 * i0 < 14 + 14 * i0 := Nat.add_lt_add_right (Nat.succ_lt_succ (Nat.succ_pos 12)) _
  have h2 : 14 + 14 * i0 ≤ 14 * p := by
    have : 14 * (i0 + 1) ≤ 14 * p := Nat.mul_le_mul_left 14 hi
    have e2 : 14 * (i0 + 1) = 14 + 14 * i0 := by lib_nat
    rw [e2] at this; exact this
  exact Nat.lt_of_lt_of_le h1 h2

/-- the sum over the units t_i, i ≠ i₀ (as a sumF with the i₀ term set to 0) -/
def omitS (p i0 k : Nat) : Nat :=
  sumF (fun i => if Nat.beq i i0 then 0 else ((1 + 14 * i) * (1 + 14 * k)) % (14 * p)) p

theorem avg_omit (p i0 x0 k : Nat) (hi : i0 < p) (ht : 1 + 14 * i0 = p * x0) (hx : Nat.gcd (1 + 14 * k) p = 1) :
    omitS p i0 k + (1 + 14 * i0) = p + 14 * sumF (fun i => i) p := by
  have hp : 0 < p := Nat.lt_of_le_of_lt (Nat.zero_le i0) hi
  have rep := sumF_replace (fun i => if Nat.beq i i0 then 0 else ((1 + 14 * i) * (1 + 14 * k)) % (14 * p))
    (fun i => ((1 + 14 * i) * (1 + 14 * k)) % (14 * p)) i0 (fun i hne => by
      have : Nat.beq i i0 = false := by
        cases e : Nat.beq i i0 with
        | false => rfl
        | true => exact absurd (Nat.eq_of_beq_eq_true e) hne
      show (if Nat.beq i i0 = true then 0 else _) = _
      rw [this]; rfl) p hi
  have rep' : omitS p i0 k + ((1 + 14 * i0) * (1 + 14 * k)) % (14 * p)
      = sumF (fun i => ((1 + 14 * i) * (1 + 14 * k)) % (14 * p)) p + (if Nat.beq i0 i0 = true then 0 else ((1 + 14 * i0) * (1 + 14 * k)) % (14 * p)) := rep
  rw [FamBal.beq_refl' i0, omit_term p i0 x0 k hi ht, avg_all p k hp hx] at rep'
  exact rep'

end FamIndec1

#print axioms FamIndec1.avg_all
#print axioms FamIndec1.omit_term
#print axioms FamIndec1.avg_omit

#print axioms: 3 theorems, no axioms.

81.175 The units \(1+14i\) of \(\mathbb Z/14p\)

For a prime \(p\) prime to \(14\) and \(p\mid 1+14i_0\): \(1+14i\) (\(i\ne i_0\)) is a unit of \(14p\), and \(1+14k\) (\(k\ne i_0\)) is prime to \(p\). Hand divisibility; \(i_0\) is unique below \(p\).

hodge/FamIndec2.lean

/-
  hodge/FamIndec2.lean — T41 cycle 1159 (goal G749c, piece K3): the units t_i = 1 + 14i of Z/14p for a prime p with
  gcd(14, p) = 1 and the unique index i₀ < p with p ∣ 1 + 14i₀:
    mod_zero     p ∣ n  ⇒  n % p = 0
    idx_unique   p ∣ 1 + 14i, i < p  ⇒  i = i₀
    cop_coset    k < p, k ≠ i₀  ⇒  gcd(1 + 14k, p) = 1
    unit_t       i < p, i ≠ i₀  ⇒  gcd(1 + 14i, 14p) = 1
  (hand divisibility: GcdHand, UnitMul, APPair1, LibGcd.gauss, PermSum.inj_mod).

  Lean 4 core plus hodge/FamIndec1, hodge/UnitMul, lib/Gcd.
-/
import hodge.FamIndec1
import hodge.UnitMul
import lib.Gcd

namespace FamIndec2
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp

theorem mod_zero (p n : Nat) (hp : 0 < p) (h : p ∣ n) : n % p = 0 := by
  have ⟨c, hc⟩ := h
  have e : n = 0 + c * p := by rw [hc]; lib_nat
  rw [e, add_mul_mod' _ _ hp]
  exact mod_lt' 0 p hp

theorem idx_unique (p i i0 : Nat) (hp : 0 < p) (h14 : Nat.gcd 14 p = 1) (hi : i < p) (hi0 : i0 < p)
    (h : p ∣ 1 + 14 * i) (h0 : p ∣ 1 + 14 * i0) : i = i0 := by
  have a := mod_zero p _ hp h
  have b := mod_zero p _ hp h0
  cases Nat.lt_or_ge i i0 with
  | inl hlt =>
    have ⟨d, hd⟩ := LibGcd.le_dest hlt
    -- i0 = (i + 1) + d
    exfalso
    apply inj_mod p 14 1 i (d + 1) hp h14 (Nat.succ_pos d)
    · rw [show i + (d + 1) = i + 1 + d by lib_nat, ← hd]; exact hi0
    · rw [a, show i + (d + 1) = i + 1 + d by lib_nat, ← hd, b]
  | inr hge =>
    cases Nat.lt_or_ge i0 i with
    | inl hlt =>
      have ⟨d, hd⟩ := LibGcd.le_dest hlt
      exfalso
      apply inj_mod p 14 1 i0 (d + 1) hp h14 (Nat.succ_pos d)
      · rw [show i0 + (d + 1) = i0 + 1 + d by lib_nat, ← hd]; exact hi
      · rw [b, show i0 + (d + 1) = i0 + 1 + d by lib_nat, ← hd, a]
    | inr hge' => exact Nat.le_antisymm hge' hge

theorem gcd_one_of (t n : Nat) (h : ∀ d, d ∣ t → d ∣ n → d = 1) : Nat.gcd t n = 1 := by
  have ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := UnitMul.gcd_dvd t n
  exact h _ ⟨i, hi⟩ ⟨j, hj⟩

theorem cop_coset (p k i0 : Nat) (hp : 0 < p) (hpr : ∀ d, d ∣ p → d = 1 ∨ d = p) (h14 : Nat.gcd 14 p = 1)
    (hk : k < p) (hi0 : i0 < p) (h0 : p ∣ 1 + 14 * i0) (hne : k ≠ i0) : Nat.gcd (1 + 14 * k) p = 1 := by
  apply gcd_one_of
  intro d hd1 hd2
  cases hpr d hd2 with
  | inl e => exact e
  | inr e =>
    rw [e] at hd1
    exact absurd (idx_unique p k i0 hp h14 hk hi0 hd1 h0) hne

theorem dvd_one_of (d i : Nat) (h1 : d ∣ 14) (h2 : d ∣ 1 + 14 * i) : d = 1 := by
  have a := LibGcd.idv_lin (LibGcd.idv_of_nat h2) (LibGcd.idv_of_nat h1) 1 (-(Int.ofNat i))
  have e : (1 : Int) * Int.ofNat (1 + 14 * i) + -(Int.ofNat i) * Int.ofNat 14 = Int.ofNat 1 := by
    show (1 : Int) * Int.ofNat (1 + 14 * i) + -(Int.ofNat i) * Int.ofNat 14 = Int.ofNat 1
    rw [show Int.ofNat (1 + 14 * i) = Int.ofNat 1 + Int.ofNat 14 * Int.ofNat i from rfl]
    lib_int
  rw [e] at a
  exact LibGcd.dvd_one' (LibGcd.idv_nat a)

theorem unit_t (p i i0 : Nat) (hp : 0 < p) (hpr : ∀ d, d ∣ p → d = 1 ∨ d = p) (h14 : Nat.gcd 14 p = 1)
    (hi : i < p) (hi0 : i0 < p) (h0 : p ∣ 1 + 14 * i0) (hne : i ≠ i0) : Nat.gcd (1 + 14 * i) (14 * p) = 1 := by
  apply gcd_one_of
  intro d hd1 hd2
  -- q = gcd d p is 1 or p
  have ⟨⟨a, ha⟩, ⟨b, hb⟩⟩ := UnitMul.gcd_dvd d p
  cases hpr (Nat.gcd d p) ⟨b, hb⟩ with
  | inr e =>
    rw [e] at ha
    exact absurd (idx_unique p i i0 hp h14 hi hi0 (LibGcd.dvd_trans' ⟨a, ha⟩ hd1) h0) hne
  | inl e =>
    have hc : ∀ f, f ∣ d → f ∣ p → f = 1 := by
      intro f hf1 hf2
      have ⟨c, hc⟩ := APPair1.dvd_gcd f d p (let ⟨u, hu⟩ := hf1; ⟨u, hu⟩) (let ⟨u, hu⟩ := hf2; ⟨u, hu⟩)
      rw [e] at hc
      exact UnitMul.one_of_dvd_one f c hc
    have h14d : d ∣ 14 := LibGcd.gauss hc (by rw [show 14 * p = 14 * p from rfl]; exact hd2)
    exact dvd_one_of d i h14d hd1

end FamIndec2

#print axioms FamIndec2.mod_zero
#print axioms FamIndec2.idx_unique
#print axioms FamIndec2.gcd_one_of
#print axioms FamIndec2.cop_coset
#print axioms FamIndec2.dvd_one_of
#print axioms FamIndec2.unit_t

#print axioms: 6 theorems, no axioms.

81.176 The family \(F_p\) is indecomposable

For a prime \(p\) prime to \(14\) with \(x_0\ne 1\) (\(p\not \equiv 1\bmod 14\)), \(F_p\) is indecomposable: averaging a split part over the units \(1+14i\) forces \(x_0=1\). Together with balancedness: an infinite family of balanced indecomposable characters.

hodge/FamIndec3.lean

/-
  hodge/FamIndec3.lean — T41 cycle 1161 (goal G749c — indecomposability of the family): for a prime p with
  gcd(14, p) = 1, i₀ < p, 1 + 14i₀ = p·x₀ and x₀ ≠ 1 (i.e. p ≢ 1 mod 14),
    fam_indec   indec (14p) (fam p i₀) = true.
  Proof: in a split (A, B) of F_p into two balanced nonempty parts, one part P avoids the unique element ≡ 0 (mod p)
  (an additive count over the split). Every member of P is a coset element 1 + 14k (k ≠ i₀). Summing the balance
  condition of P over the p − 1 units t_i = 1 + 14i (i ≠ i₀) and using FamIndec1.avg_omit element by element gives
  |P|·(p − 1)·14p + 2|P|·t* = |P|·(2p + 28·Σ_{i<p} i), hence t* = p and x₀ = 1.
  With FamBal.fam_bal: F_p is a balanced indecomposable character of the degree-14p Fermat variety for every prime
  p ≡ 3, 5 (mod 14) — an infinite family through the open m = 70 seed (p = 5).

  Lean 4 core plus hodge/FamIndec2, hodge/FamBal, hodge/Q4Conv (splits).
-/
import hodge.FamIndec2
import hodge.QFamPrime

namespace FamIndec3
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp FamBal FamIndec1 FamIndec2 Q4Conv QFamPrime

theorem splits_gs (f : Nat → Nat) : ∀ (l A B : List Nat), (A, B) ∈ splits l → gs f A + gs f B = gs f l
  | [], A, B, h => by
    have e : (A, B) = (([] : List Nat), ([] : List Nat)) := by
      cases h with
      | head => rfl
      | tail _ h' => exact nomatch h'
    injection e with e1 e2
    subst e1; subst e2; rfl
  | z :: l, A, B, h => by
    cases mem_flatMap_inv _ _ (splits l) h with
    | intro p hp =>
      have ih := splits_gs f l p.1 p.2 hp.1
      cases hp.2 with
      | head =>
        show (f z + gs f p.1) + gs f p.2 = f z + gs f l
        rw [← ih]; lib_nat
      | tail _ h2 => cases h2 with
        | head =>
          show gs f p.1 + (f z + gs f p.2) = f z + gs f l
          rw [← ih]; lib_nat
        | tail _ h3 => exact nomatch h3

theorem tsum_gs (m t : Nat) : ∀ P : List Nat, tsum m t P = gs (fun x => (t * x) % m) P
  | [] => rfl
  | x :: P => by show (t * x) % m + tsum m t P = (t * x) % m + gs _ P; rw [tsum_gs m t P]

theorem gs_zero (g : Nat → Nat) : ∀ P : List Nat, gs g P = 0 → ∀ x, x ∈ P → g x = 0
  | [], _, _, h => nomatch h
  | y :: P, h, x, hx => by
    have h' : g y + gs g P = 0 := h
    have a : g y = 0 := by
      cases e : g y with
      | zero => rfl
      | succ n => rw [e, Nat.succ_add] at h'; exact Nat.noConfusion h'
    have b : gs g P = 0 := by rw [a, Nat.zero_add] at h'; exact h'
    cases hx with
    | head => exact a
    | tail _ hx' => exact gs_zero g P b x hx'

theorem mem_filter' (pr : Nat → Bool) (t : Nat) (hp : pr t = true) : ∀ l : List Nat, t ∈ l → t ∈ l.filter pr
  | [], h => nomatch h
  | x :: l, h => by
    cases hx : pr x with
    | false =>
      have e : (x :: l).filter pr = l.filter pr := by show (match pr x with | true => x :: l.filter pr | false => l.filter pr) = _; rw [hx]
      rw [e]
      cases h with
      | head => rw [hp] at hx; exact nomatch hx
      | tail _ h' => exact mem_filter' pr t hp l h'
    | true =>
      have e : (x :: l).filter pr = x :: l.filter pr := by show (match pr x with | true => x :: l.filter pr | false => l.filter pr) = _; rw [hx]
      rw [e]
      cases h with
      | head => exact List.Mem.head _
      | tail _ h' => exact List.Mem.tail _ (mem_filter' pr t hp l h')

theorem mem_loop : ∀ (n : Nat) (acc : List Nat) (t : Nat), (t < n ∨ t ∈ acc) → t ∈ List.range.loop n acc
  | 0, acc, t, h => by
    cases h with
    | inl h => exact absurd h (Nat.not_lt_zero t)
    | inr h => exact h
  | n + 1, acc, t, h => by
    show t ∈ List.range.loop n (n :: acc)
    apply mem_loop n (n :: acc) t
    cases h with
    | inr h => exact Or.inr (List.Mem.tail _ h)
    | inl h =>
      cases Nat.lt_or_ge t n with
      | inl h' => exact Or.inl h'
      | inr h' =>
        have e : t = n := Nat.le_antisymm (Nat.le_of_lt_succ h) h'
        rw [e]; exact Or.inr (List.Mem.head _)

theorem mem_range' (m t : Nat) (h : t < m) : t ∈ List.range m := by
  show t ∈ List.range.loop m []
  exact mem_loop m [] t (Or.inl h)

theorem bal_unit (m t : Nat) (P : List Nat) (hb : bal m P = true) (ht : t < m) (hg : Nat.gcd t m = 1) :
    tsum m t P + tsum m t P = P.length * m := by
  have hm : t ∈ FermatPrime.units m := mem_filter' _ t (by rw [hg]; rfl) _ (mem_range' m t ht)
  exact Nat.eq_of_beq_eq_true (all_mem _ _ hb t hm)

theorem sumF_add (f g : Nat → Nat) : ∀ n, sumF (fun i => f i + g i) n = sumF f n + sumF g n
  | 0 => rfl
  | n + 1 => by
    show sumF (fun i => f i + g i) n + (f n + g n) = (sumF f n + f n) + (sumF g n + g n)
    rw [sumF_add f g n]; lib_nat

/-- swap a sum over i with a sum over a list -/
theorem swap (F : Nat → Nat → Nat) (n : Nat) : ∀ P : List Nat,
    sumF (fun i => gs (F i) P) n = gs (fun x => sumF (fun i => F i x) n) P
  | [] => by
    show sumF (fun _ => 0) n = 0
    induction n with
    | zero => rfl
    | succ n ih => show sumF (fun _ => 0) n + 0 = 0; rw [ih]
  | x :: P => by
    show sumF (fun i => F i x + gs (F i) P) n = sumF (fun i => F i x) n + gs (fun x => sumF (fun i => F i x) n) P
    rw [sumF_add, swap F n P]

theorem gs_ite (c : Bool) (g : Nat → Nat) : ∀ P : List Nat,
    (if c = true then 0 else gs g P) = gs (fun x => if c = true then 0 else g x) P := by
  intro P
  cases c with
  | true =>
    show 0 = gs (fun _ => 0) P
    induction P with
    | nil => rfl
    | cons x P ih => show 0 = 0 + gs (fun _ => 0) P; rw [← ih]
  | false => rfl

theorem gs_const_len (c : Nat) (g : Nat → Nat) : ∀ P : List Nat, (∀ x, x ∈ P → g x = c) → gs g P = P.length * c
  | [], _ => by show 0 = 0 * c; lib_nat
  | x :: P, h => by
    show g x + gs g P = (P.length + 1) * c
    rw [h x (List.Mem.head _), gs_const_len c g P (fun y hy => h y (List.Mem.tail _ hy))]; lib_nat

theorem gs_add_const (g : Nat → Nat) (c : Nat) : ∀ P : List Nat, gs (fun x => g x + c) P = gs g P + P.length * c
  | [] => by show 0 = 0 + 0 * c; lib_nat
  | x :: P => by
    show (g x + c) + gs (fun x => g x + c) P = (g x + gs g P) + (P.length + 1) * c
    rw [gs_add_const g c P]; lib_nat

theorem ite_two (c : Bool) (a : Nat) : (if c = true then 0 else a + a) = (if c = true then 0 else a) + (if c = true then 0 else a) := by
  cases c with
  | true => rfl
  | false => rfl

/-- the core contradiction: a balanced nonempty part of coset elements (k ≠ i₀) forces x₀ = 1 -/
theorem coset_part (p i0 x0 : Nat) (hp : 0 < p) (hpr : ∀ d, d ∣ p → d = 1 ∨ d = p) (h14 : Nat.gcd 14 p = 1)
    (hi : i0 < p) (hx : 1 + 14 * i0 = p * x0) (P : List Nat) (hne : 0 < P.length)
    (hmem : ∀ x, x ∈ P → ∃ k, k < p ∧ k ≠ i0 ∧ x = 1 + 14 * k) (hb : bal (14 * p) P = true) : x0 = 1 := by
  have h0 : p ∣ 1 + 14 * i0 := ⟨x0, hx⟩
  have hne_i : ∀ i, Nat.beq i i0 = false ↔ i ≠ i0 := by
    intro i
    constructor
    · intro h e; rw [e, beq_refl'] at h; exact nomatch h
    · intro h
      cases e : Nat.beq i i0 with
      | false => rfl
      | true => exact absurd (Nat.eq_of_beq_eq_true e) h
  -- E1: Σ_{i≠i₀} 2·tsum(t_i, P) + |P|·14p = p·|P|·14p
  have E1 : sumF (fun i => if Nat.beq i i0 = true then 0 else tsum (14 * p) (1 + 14 * i) P + tsum (14 * p) (1 + 14 * i) P) p
      + P.length * (14 * p) = p * (P.length * (14 * p)) := by
    have c1 : sumF (fun i => if Nat.beq i i0 = true then 0 else tsum (14 * p) (1 + 14 * i) P + tsum (14 * p) (1 + 14 * i) P) p
        = sumF (fun i => if Nat.beq i i0 = true then 0 else P.length * (14 * p)) p := by
      apply sumF_congr_lt; intro i hip
      cases e : Nat.beq i i0 with
      | true => rfl
      | false =>
        show tsum (14 * p) (1 + 14 * i) P + tsum (14 * p) (1 + 14 * i) P = P.length * (14 * p)
        have hlt : 1 + 14 * i < 14 * p := by
          have h1 : 1 + 14 * i < 14 + 14 * i := Nat.add_lt_add_right (Nat.succ_lt_succ (Nat.succ_pos 12)) _
          have h2 : 14 + 14 * i ≤ 14 * p := by
            have : 14 * (i + 1) ≤ 14 * p := Nat.mul_le_mul_left 14 hip
            rw [show 14 * (i + 1) = 14 + 14 * i by lib_nat] at this; exact this
          exact Nat.lt_of_lt_of_le h1 h2
        exact bal_unit _ _ P hb hlt (unit_t p i i0 hp hpr h14 hip hi h0 ((hne_i i).1 e))
    have r := sumF_replace (fun i => if Nat.beq i i0 = true then 0 else P.length * (14 * p)) (fun _ => P.length * (14 * p)) i0
      (fun k hk => by
        show (if Nat.beq k i0 = true then 0 else _) = _
        rw [(hne_i k).2 hk]; rfl) p hi
    have r' : sumF (fun i => if Nat.beq i i0 = true then 0 else P.length * (14 * p)) p + P.length * (14 * p)
        = sumF (fun _ => P.length * (14 * p)) p + (if Nat.beq i0 i0 = true then 0 else P.length * (14 * p)) := r
    rw [beq_refl'] at r'
    have sc : ∀ n, sumF (fun _ => P.length * (14 * p)) n = n * (P.length * (14 * p)) := by
      intro n; induction n with
      | zero => show 0 = 0 * _; lib_nat
      | succ n ih =>
        show sumF (fun _ => P.length * (14 * p)) n + P.length * (14 * p) = (n + 1) * (P.length * (14 * p))
        rw [ih]; lib_nat
    rw [c1, r', sc]; rfl
  -- Φ₁ elementwise
  have E2 : sumF (fun i => if Nat.beq i i0 = true then 0 else tsum (14 * p) (1 + 14 * i) P) p + P.length * (1 + 14 * i0)
      = P.length * (p + 14 * sumF (fun i => i) p) := by
    have sw : sumF (fun i => if Nat.beq i i0 = true then 0 else tsum (14 * p) (1 + 14 * i) P) p
        = gs (fun x => sumF (fun i => if Nat.beq i i0 = true then 0 else ((1 + 14 * i) * x) % (14 * p)) p) P := by
      rw [← swap]
      apply sumF_congr; intro i
      rw [tsum_gs, gs_ite]
    rw [sw, ← gs_add_const]
    apply gs_const_len
    intro x hxP
    have ⟨k, hk, hk0, e⟩ := hmem x hxP
    subst e
    exact avg_omit p i0 x0 k hi hx (cop_coset p k i0 hp hpr h14 hk hi h0 hk0)
  have E3 := sum_id p
  -- combine: 2|P|·t* = 2|P|·p
  have hsplit : sumF (fun i => if Nat.beq i i0 = true then 0 else tsum (14 * p) (1 + 14 * i) P + tsum (14 * p) (1 + 14 * i) P) p
      = sumF (fun i => if Nat.beq i i0 = true then 0 else tsum (14 * p) (1 + 14 * i) P) p
        + sumF (fun i => if Nat.beq i i0 = true then 0 else tsum (14 * p) (1 + 14 * i) P) p := by
    rw [← sumF_add]; apply sumF_congr; intro i; exact ite_two _ _
  rw [hsplit] at E1
  generalize sumF (fun i => if Nat.beq i i0 = true then 0 else tsum (14 * p) (1 + 14 * i) P) p = F at E1 E2
  generalize sumF (fun i => i) p = S at E2 E3
  generalize P.length = L at E1 E2 hne
  have key : (L + L) * (1 + 14 * i0) = (L + L) * p := by
    apply add_right_cancel' _ _ (F + F + L * (14 * p))
    calc (L + L) * (1 + 14 * i0) + (F + F + L * (14 * p))
        = (F + L * (1 + 14 * i0)) + (F + L * (1 + 14 * i0)) + L * (14 * p) := by lib_nat
      _ = L * (p + 14 * S) + L * (p + 14 * S) + L * (14 * p) := by rw [E2]
      _ = (L + L) * p + 14 * L * (S + S + p) := by lib_nat
      _ = (L + L) * p + 14 * L * (p * p) := by rw [E3]
      _ = (L + L) * p + p * (L * (14 * p)) := by lib_nat
      _ = (L + L) * p + (F + F + L * (14 * p)) := by rw [E1]
  have hL : 0 < L + L := Nat.lt_of_lt_of_le hne (Nat.le_add_right L L)
  have ht := Nat.eq_of_mul_eq_mul_left hL key
  rw [hx] at ht
  exact Nat.eq_of_mul_eq_mul_left hp (by rw [ht]; lib_nat)

def ind (p x : Nat) : Nat := if Nat.beq (x % p) 0 then 1 else 0

theorem gl_gs (g f : Nat → Nat) : ∀ n, gs g (gl f n) = sumF (fun k => g (f k)) n
  | 0 => rfl
  | n + 1 => by
    show g (f n) + gs g (gl f n) = sumF (fun k => g (f k)) n + g (f n)
    rw [gl_gs g f n]; lib_nat

theorem len_pos : ∀ P : List Nat, P.isEmpty = false → 0 < P.length
  | [], h => nomatch h
  | _ :: _, _ => Nat.succ_pos _

/-- **The family F_p is indecomposable** (p prime, gcd(14, p) = 1, x₀ ≠ 1). -/
theorem fam_indec (p i0 x0 : Nat) (hp : 0 < p) (hpr : ∀ d, d ∣ p → d = 1 ∨ d = p) (h14 : Nat.gcd 14 p = 1)
    (hi : i0 < p) (hx : 1 + 14 * i0 = p * x0) (hx1 : x0 ≠ 1) : indec (14 * p) (fam p i0) = true := by
  have h0 : p ∣ 1 + 14 * i0 := ⟨x0, hx⟩
  -- the indicator of the multiples of p sums to 1 over F_p
  have hfk : ∀ k, k < p → ind p ((fun k => if Nat.beq k i0 then 1 + 14 * k + 6 * p else 1 + 14 * k) k)
      = (if Nat.beq k i0 then 1 else 0) := by
    intro k hk
    cases e : Nat.beq k i0 with
    | true =>
      have ek := Nat.eq_of_beq_eq_true e
      subst ek
      show ind p (if Nat.beq k k = true then 1 + 14 * k + 6 * p else 1 + 14 * k) = 1
      rw [e]
      show (if Nat.beq ((1 + 14 * k + 6 * p) % p) 0 = true then 1 else 0) = 1
      have : (1 + 14 * k + 6 * p) % p = 0 := mod_zero p _ hp ⟨x0 + 6, by rw [hx]; lib_nat⟩
      rw [this]; rfl
    | false =>
      show ind p (if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k) = 0
      rw [e]
      show (if Nat.beq ((1 + 14 * k) % p) 0 = true then 1 else 0) = 0
      cases e2 : Nat.beq ((1 + 14 * k) % p) 0 with
      | false => rfl
      | true =>
        exfalso
        have z := Nat.eq_of_beq_eq_true e2
        have ⟨q, hq⟩ := div_mod p hp (1 + 14 * k + 1) (1 + 14 * k) (Nat.lt_succ_self _)
        rw [z, Nat.zero_add] at hq
        have hk0 : k ≠ i0 := fun h => by rw [h, beq_refl'] at e; exact nomatch e
        exact hk0 (idx_unique p k i0 hp h14 hk hi ⟨q, hq⟩ h0)
  have tot : gs (ind p) (fam p i0) = 1 := by
    unfold fam
    rw [gl_gs, sumF_congr_lt _ _ p hfk]
    have r := sumF_replace (fun k => if Nat.beq k i0 = true then 1 else 0) (fun _ => 0) i0 (fun k hk => by
      cases e : Nat.beq k i0 with
      | true => exact absurd (Nat.eq_of_beq_eq_true e) hk
      | false => rfl) p hi
    have r' : sumF (fun k => if Nat.beq k i0 = true then 1 else 0) p + 0 = sumF (fun _ => 0) p + (if Nat.beq i0 i0 = true then 1 else 0) := r
    rw [beq_refl'] at r'
    have z : ∀ n, sumF (fun _ => 0) n = 0 := by
      intro n; induction n with
      | zero => rfl
      | succ n ih => show sumF (fun _ => 0) n + 0 = 0; rw [ih]
    rw [z] at r'
    exact r'
  -- a decomposition gives a balanced nonempty part without the multiple of p
  cases hind : indec (14 * p) (fam p i0) with
  | true => rfl
  | false =>
    exfalso
    cases all_false _ (splits (fam p i0)) hind with
    | intro sp hsp =>
      have hpr' := splits_props (fam p i0) sp.1 sp.2 hsp.1
      have hf : (sp.1.isEmpty || sp.2.isEmpty || !(bal (14 * p) sp.1 && bal (14 * p) sp.2)) = false := hsp.2
      have hsum := splits_gs (ind p) (fam p i0) sp.1 sp.2 hsp.1
      rw [tot] at hsum
      cases h1 : sp.1.isEmpty with
      | true => rw [h1] at hf; exact nomatch hf
      | false => cases h2 : sp.2.isEmpty with
        | true => rw [h1, h2] at hf; exact nomatch hf
        | false => cases hA : bal (14 * p) sp.1 with
          | false => rw [h1, h2, hA] at hf; exact nomatch hf
          | true => cases hB : bal (14 * p) sp.2 with
            | false => rw [h1, h2, hA, hB] at hf; exact nomatch hf
            | true =>
              -- the part P with gs ind P = 0
              have part : ∀ P : List Nat, (∀ x, x ∈ P → x ∈ fam p i0) → gs (ind p) P = 0 → P.isEmpty = false →
                  bal (14 * p) P = true → False := by
                intro P hPm hP0 hPne hPb
                apply hx1
                apply coset_part p i0 x0 hp hpr h14 hi hx P (len_pos P hPne) _ hPb
                intro x hxP
                have ⟨k, hk, ek⟩ := gl_mem _ p x (hPm x hxP)
                have hk0 : k ≠ i0 := by
                  intro e
                  have := gs_zero (ind p) P hP0 x hxP
                  rw [← ek, hfk k hk, e, beq_refl'] at this
                  exact nomatch this
                refine ⟨k, hk, hk0, ?_⟩
                rw [← ek]
                show (if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k) = 1 + 14 * k
                cases e : Nat.beq k i0 with
                | true => exact absurd (Nat.eq_of_beq_eq_true e) hk0
                | false => rfl
              cases ea : gs (ind p) sp.1 with
              | zero => exact part sp.1 hpr'.2.1 ea h1 hA
              | succ a =>
                have eb : gs (ind p) sp.2 = 0 := by
                  rw [ea] at hsum
                  cases e2 : gs (ind p) sp.2 with
                  | zero => rfl
                  | succ b =>
                    rw [e2] at hsum
                    exfalso
                    have e3 : (a + b + 1) + 1 = 0 + 1 := by
                      calc (a + b + 1) + 1 = (a + 1) + (b + 1) := by lib_nat
                        _ = 1 := hsum
                    exact Nat.noConfusion (Nat.succ.inj e3)
                exact part sp.2 hpr'.2.2 eb h2 hB

end FamIndec3
#print axioms FamIndec3.splits_gs
#print axioms FamIndec3.tsum_gs
#print axioms FamIndec3.gs_zero
#print axioms FamIndec3.mem_filter'
#print axioms FamIndec3.mem_loop
#print axioms FamIndec3.mem_range'
#print axioms FamIndec3.bal_unit
#print axioms FamIndec3.sumF_add
#print axioms FamIndec3.swap
#print axioms FamIndec3.gs_ite
#print axioms FamIndec3.gs_const_len
#print axioms FamIndec3.gs_add_const
#print axioms FamIndec3.ite_two
#print axioms FamIndec3.coset_part
#print axioms FamIndec3.gl_gs
#print axioms FamIndec3.len_pos
#print axioms FamIndec3.fam_indec

#print axioms: 17 theorems, no axioms.

81.177 Instances of the family \(F_p\)

A Bool primality certificate and an instance builder; \(F_p\) balanced and indecomposable for every prime \(p\equiv 3,5\pmod {14}\) below \(400\). \(F_5=[57,43,29,45,1]\) is the \(m=70\) seed.

hodge/FamInst.lean

/-
  hodge/FamInst.lean — T41 cycle 1163 (goal G749 — instances): a Bool primality certificate and the family F_p as
  balanced indecomposable characters for p = 3, 5, 17, 19, 31, 47, 59, 61, 73, 89, 101, 103, 131, 157, 173, 199:
    prime_of     primeB n = true, 1 < n  ⇒  ∀ d, d ∣ n → d = 1 ∨ d = n
    fp3 … fp31   bal (14p) (fam p i₀) = true ∧ indec (14p) (fam p i₀) = true      (FamBal.fam_bal, FamIndec3.fam_indec)
  F_5 = [57, 43, 29, 45, 1] is the open m = 70 seed of G498c.

  Lean 4 core plus hodge/FamIndec3, hodge/FamBal.
-/
import hodge.FamIndec3

namespace FamInst
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp FamBal FamIndec1 FamIndec2 FamIndec3

def primeB (n : Nat) : Bool := (List.range n).all (fun d => Nat.blt d 2 || !Nat.beq (n % d) 0)

theorem le_of_dvd' (d n : Nat) (hn : 0 < n) (h : d ∣ n) : d ≤ n := by
  have ⟨c, hc⟩ := h
  cases c with
  | zero => rw [Nat.mul_zero] at hc; rw [hc] at hn; exact absurd hn (Nat.lt_irrefl 0)
  | succ c => rw [hc, show d * (c + 1) = d + d * c by lib_nat]; exact Nat.le_add_right _ _

theorem prime_of (n : Nat) (hb : primeB n = true) (hn : 1 < n) : ∀ d, d ∣ n → d = 1 ∨ d = n := by
  intro d hd
  have hn0 : 0 < n := Nat.lt_of_lt_of_le (Nat.zero_lt_one) (Nat.le_of_lt hn)
  have hle := le_of_dvd' d n hn0 hd
  cases Nat.lt_or_ge d n with
  | inr hge => exact Or.inr (Nat.le_antisymm hle hge)
  | inl hlt =>
    have hc := all_mem _ _ hb d (mem_range' n d hlt)
    cases d with
    | zero =>
      have ⟨c, hc'⟩ := hd
      rw [Nat.zero_mul] at hc'; rw [hc'] at hn0; exact absurd hn0 (Nat.lt_irrefl 0)
    | succ d =>
      cases d with
      | zero => exact Or.inl rfl
      | succ d =>
        exfalso
        have z := mod_zero (d + 2) n (Nat.succ_pos _) hd
        have hlt2 : Nat.blt (d + 2) 2 = false := rfl
        rw [hlt2, z] at hc
        exact nomatch hc

theorem p3 : ∀ d, d ∣ 3 → d = 1 ∨ d = 3 := prime_of 3 rfl (Nat.succ_lt_succ (Nat.succ_pos 1))
theorem p5 : ∀ d, d ∣ 5 → d = 1 ∨ d = 5 := prime_of 5 rfl (Nat.succ_lt_succ (Nat.succ_pos 3))
theorem p17 : ∀ d, d ∣ 17 → d = 1 ∨ d = 17 := prime_of 17 rfl (Nat.succ_lt_succ (Nat.succ_pos 15))
theorem p19 : ∀ d, d ∣ 19 → d = 1 ∨ d = 19 := prime_of 19 rfl (Nat.succ_lt_succ (Nat.succ_pos 17))
theorem p31 : ∀ d, d ∣ 31 → d = 1 ∨ d = 31 := prime_of 31 rfl (Nat.succ_lt_succ (Nat.succ_pos 29))

theorem ne1 (x : Nat) (h : Nat.beq x 1 = false) : x ≠ 1 := fun e => by rw [e] at h; exact nomatch h

/-- F_3 = fam 3 1 (1 + 14 = 3·5), F_5 = fam 5 1 (15 = 5·3), F_17 = fam 17 6 (85 = 17·5), F_19 = fam 19 4 (57 = 19·3),
  F_31 = fam 31 11 (155 = 31·5) -/
theorem fp3 : bal 42 (fam 3 1) = true ∧ indec 42 (fam 3 1) = true :=
  ⟨fam_bal 3 1 5 (Nat.succ_pos 2) (Nat.succ_lt_succ (Nat.succ_pos 1)) rfl rfl,
   fam_indec 3 1 5 (Nat.succ_pos 2) p3 rfl (Nat.succ_lt_succ (Nat.succ_pos 1)) rfl (ne1 5 rfl)⟩
theorem fp5 : bal 70 (fam 5 1) = true ∧ indec 70 (fam 5 1) = true :=
  ⟨fam_bal 5 1 3 (Nat.succ_pos 4) (Nat.succ_lt_succ (Nat.succ_pos 3)) rfl rfl,
   fam_indec 5 1 3 (Nat.succ_pos 4) p5 rfl (Nat.succ_lt_succ (Nat.succ_pos 3)) rfl (ne1 3 rfl)⟩
theorem fp17 : bal 238 (fam 17 6) = true ∧ indec 238 (fam 17 6) = true :=
  ⟨fam_bal 17 6 5 (Nat.succ_pos 16) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 6) (Nat.le_add_left 7 10)) rfl rfl,
   fam_indec 17 6 5 (Nat.succ_pos 16) p17 rfl (Nat.lt_of_lt_of_le (Nat.lt_succ_self 6) (Nat.le_add_left 7 10)) rfl (ne1 5 rfl)⟩
theorem fp19 : bal 266 (fam 19 4) = true ∧ indec 266 (fam 19 4) = true :=
  ⟨fam_bal 19 4 3 (Nat.succ_pos 18) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 4) (Nat.le_add_left 5 14)) rfl rfl,
   fam_indec 19 4 3 (Nat.succ_pos 18) p19 rfl (Nat.lt_of_lt_of_le (Nat.lt_succ_self 4) (Nat.le_add_left 5 14)) rfl (ne1 3 rfl)⟩
theorem fp31 : bal 434 (fam 31 11) = true ∧ indec 434 (fam 31 11) = true :=
  ⟨fam_bal 31 11 5 (Nat.succ_pos 30) (Nat.lt_of_lt_of_le (Nat.lt_succ_self 11) (Nat.le_add_left 12 19)) rfl rfl,
   fam_indec 31 11 5 (Nat.succ_pos 30) p31 rfl (Nat.lt_of_lt_of_le (Nat.lt_succ_self 11) (Nat.le_add_left 12 19)) rfl (ne1 5 rfl)⟩

theorem fam5_seed : fam 5 1 = [57, 43, 29, 45, 1] := rfl

/-- the instance builder: all hypotheses are Bool checks (rfl) -/
theorem fp_inst (p i0 x0 : Nat) (hb : primeB p = true) (h2 : Nat.ble 2 p = true) (hi : Nat.ble (i0 + 1) p = true)
    (hx : 1 + 14 * i0 = p * x0) (h14 : Nat.gcd 14 p = 1) (hs : fcond (x0 % 14) = true) (hx1 : Nat.beq x0 1 = false) :
    bal (14 * p) (fam p i0) = true ∧ indec (14 * p) (fam p i0) = true := by
  have hp2 : 2 ≤ p := Nat.le_of_ble_eq_true h2
  have hp : 0 < p := Nat.lt_of_lt_of_le (Nat.succ_pos 1) hp2
  have hi' : i0 < p := Nat.le_of_ble_eq_true hi
  exact ⟨fam_bal p i0 x0 hp hi' hx hs, fam_indec p i0 x0 hp (prime_of p hb hp2) h14 hi' hx (ne1 x0 hx1)⟩

theorem fp47 : bal 658 (fam 47 10) = true ∧ indec 658 (fam 47 10) = true := fp_inst 47 10 3 rfl rfl rfl rfl rfl rfl rfl
theorem fp59 : bal 826 (fam 59 21) = true ∧ indec 826 (fam 59 21) = true := fp_inst 59 21 5 rfl rfl rfl rfl rfl rfl rfl
theorem fp61 : bal 854 (fam 61 13) = true ∧ indec 854 (fam 61 13) = true := fp_inst 61 13 3 rfl rfl rfl rfl rfl rfl rfl
theorem fp73 : bal 1022 (fam 73 26) = true ∧ indec 1022 (fam 73 26) = true := fp_inst 73 26 5 rfl rfl rfl rfl rfl rfl rfl
theorem fp89 : bal 1246 (fam 89 19) = true ∧ indec 1246 (fam 89 19) = true := fp_inst 89 19 3 rfl rfl rfl rfl rfl rfl rfl
theorem fp101 : bal 1414 (fam 101 36) = true ∧ indec 1414 (fam 101 36) = true := fp_inst 101 36 5 rfl rfl rfl rfl rfl rfl rfl
theorem fp103 : bal 1442 (fam 103 22) = true ∧ indec 1442 (fam 103 22) = true := fp_inst 103 22 3 rfl rfl rfl rfl rfl rfl rfl

set_option maxRecDepth 100000 in
theorem fp131 : bal 1834 (fam 131 28) = true ∧ indec 1834 (fam 131 28) = true := fp_inst 131 28 3 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 100000 in
theorem fp157 : bal 2198 (fam 157 56) = true ∧ indec 2198 (fam 157 56) = true := fp_inst 157 56 5 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 100000 in
theorem fp173 : bal 2422 (fam 173 37) = true ∧ indec 2422 (fam 173 37) = true := fp_inst 173 37 3 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 100000 in
theorem fp199 : bal 2786 (fam 199 71) = true ∧ indec 2786 (fam 199 71) = true := fp_inst 199 71 5 rfl rfl rfl rfl rfl rfl rfl

set_option maxRecDepth 200000 in
theorem fp227 : bal 3178 (fam 227 81) = true ∧ indec 3178 (fam 227 81) = true := fp_inst 227 81 5 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp229 : bal 3206 (fam 229 49) = true ∧ indec 3206 (fam 229 49) = true := fp_inst 229 49 3 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp241 : bal 3374 (fam 241 86) = true ∧ indec 3374 (fam 241 86) = true := fp_inst 241 86 5 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp257 : bal 3598 (fam 257 55) = true ∧ indec 3598 (fam 257 55) = true := fp_inst 257 55 3 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp269 : bal 3766 (fam 269 96) = true ∧ indec 3766 (fam 269 96) = true := fp_inst 269 96 5 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp271 : bal 3794 (fam 271 58) = true ∧ indec 3794 (fam 271 58) = true := fp_inst 271 58 3 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp283 : bal 3962 (fam 283 101) = true ∧ indec 3962 (fam 283 101) = true := fp_inst 283 101 5 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp311 : bal 4354 (fam 311 111) = true ∧ indec 4354 (fam 311 111) = true := fp_inst 311 111 5 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp313 : bal 4382 (fam 313 67) = true ∧ indec 4382 (fam 313 67) = true := fp_inst 313 67 3 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp353 : bal 4942 (fam 353 126) = true ∧ indec 4942 (fam 353 126) = true := fp_inst 353 126 5 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp367 : bal 5138 (fam 367 131) = true ∧ indec 5138 (fam 367 131) = true := fp_inst 367 131 5 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp383 : bal 5362 (fam 383 82) = true ∧ indec 5362 (fam 383 82) = true := fp_inst 383 82 3 rfl rfl rfl rfl rfl rfl rfl
set_option maxRecDepth 200000 in
theorem fp397 : bal 5558 (fam 397 85) = true ∧ indec 5558 (fam 397 85) = true := fp_inst 397 85 3 rfl rfl rfl rfl rfl rfl rfl

end FamInst
#print axioms FamInst.le_of_dvd'
#print axioms FamInst.prime_of
#print axioms FamInst.p3
#print axioms FamInst.p5
#print axioms FamInst.p17
#print axioms FamInst.p19
#print axioms FamInst.p31
#print axioms FamInst.ne1
#print axioms FamInst.fp3
#print axioms FamInst.fp5
#print axioms FamInst.fp17
#print axioms FamInst.fp19
#print axioms FamInst.fp31
#print axioms FamInst.fam5_seed
#print axioms FamInst.fp_inst
#print axioms FamInst.fp47
#print axioms FamInst.fp59
#print axioms FamInst.fp61
#print axioms FamInst.fp73
#print axioms FamInst.fp89
#print axioms FamInst.fp101
#print axioms FamInst.fp103
#print axioms FamInst.fp131
#print axioms FamInst.fp157
#print axioms FamInst.fp173
#print axioms FamInst.fp199
#print axioms FamInst.fp227
#print axioms FamInst.fp229
#print axioms FamInst.fp241
#print axioms FamInst.fp257
#print axioms FamInst.fp269
#print axioms FamInst.fp271
#print axioms FamInst.fp283
#print axioms FamInst.fp311
#print axioms FamInst.fp313
#print axioms FamInst.fp353
#print axioms FamInst.fp367
#print axioms FamInst.fp383
#print axioms FamInst.fp397

#print axioms: 39 theorems, no axioms.

81.178 Subgroup-average criterion

If no split part \(A\) has \(2\sum _{x\in A}D(x)=|A|\,|H|\,m\) with \(D(x)=\sum _{t\in H}\langle tx\rangle _m\) for a list \(H\) of units, the character is indecomposable; Bool certificate and the \(m=72\) seed. Generalises the sum criterion (\(H=\{1\}\)) and the proof for \(F_p\).

hodge/AvgIndec.lean

/-
  hodge/AvgIndec.lean — T41 cycle 1167 (goal G757): the subgroup-average criterion for indecomposability, generalising
  PadCriterion.sum_indec (H = {1}) and the argument of FamIndec3. For a list H of units of m and
  D(x) = Σ_{t∈H} ⟨t·x⟩_m:
    hsum_gs    Σ_{t∈H} tsum m t A = Σ_{x∈A} D(x)
    avg_indec  if no split (A, B) of c with A, B nonempty has 2·Σ_{x∈A} D(x) = |A|·|H|·m, then c is indecomposable.
  A balanced part satisfies 2·tsum = |A|·m for every unit t, hence for the sum over H. The per-split test needs only
  the precomputed values D(x) (for the m = 72 seed with H = ⟨5, 13⟩ ⊂ (Z/36)ˣ only the split {32} | rest survives).

  Lean 4 core plus hodge/FamIndec3 (bal_unit, splits lemmas), hodge/QFamPrime (gs).
-/
import hodge.FamIndec3

namespace AvgIndec
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp FamBal FamIndec3 Q4Conv QFamPrime

def hs (m : Nat) (H : List Nat) (A : List Nat) : Nat := gs (fun t => tsum m t A) H

def D (m : Nat) (H : List Nat) (x : Nat) : Nat := gs (fun t => (t * x) % m) H

theorem gs_addf (f g : Nat → Nat) : ∀ H : List Nat, gs (fun t => f t + g t) H = gs f H + gs g H
  | [] => rfl
  | t :: H => by
    show (f t + g t) + gs (fun t => f t + g t) H = (f t + gs f H) + (g t + gs g H)
    rw [gs_addf f g H]; lib_nat

theorem hsum_gs (m : Nat) (H : List Nat) : ∀ A : List Nat, hs m H A = gs (D m H) A
  | [] => by
    show gs (fun _ => 0) H = 0
    induction H with
    | nil => rfl
    | cons t H ih => show 0 + gs (fun _ => 0) H = 0; rw [ih]
  | x :: A => by
    show gs (fun t => (t * x) % m + tsum m t A) H = D m H x + gs (D m H) A
    rw [gs_addf, ← hsum_gs m H A]; rfl

theorem bal_hs (m : Nat) (H : List Nat) (hH : ∀ t, t ∈ H → t < m ∧ Nat.gcd t m = 1) (A : List Nat)
    (hb : bal m A = true) : ∀ H' : List Nat, (∀ t, t ∈ H' → t ∈ H) → hs m H' A + hs m H' A = A.length * (H'.length * m)
  | [], _ => by show 0 + 0 = A.length * (0 * m); lib_nat
  | t :: H', hsub => by
    have ih := bal_hs m H hH A hb H' (fun s hs' => hsub s (List.Mem.tail _ hs'))
    have ht := hH t (hsub t (List.Mem.head _))
    have e := bal_unit m t A hb ht.1 ht.2
    show (tsum m t A + hs m H' A) + (tsum m t A + hs m H' A) = A.length * ((H'.length + 1) * m)
    calc (tsum m t A + hs m H' A) + (tsum m t A + hs m H' A)
        = (tsum m t A + tsum m t A) + (hs m H' A + hs m H' A) := by lib_nat
      _ = A.length * m + A.length * (H'.length * m) := by rw [e, ih]
      _ = _ := by lib_nat

/-- **the subgroup-average criterion** -/
theorem avg_indec (m : Nat) (c H : List Nat) (hH : ∀ t, t ∈ H → t < m ∧ Nat.gcd t m = 1)
    (hcrit : ∀ A B, (A, B) ∈ splits c → A.isEmpty = false → B.isEmpty = false →
      gs (D m H) A + gs (D m H) A ≠ A.length * (H.length * m)) : indec m c = true := by
  cases hind : indec m c with
  | true => rfl
  | false =>
    exfalso
    cases all_false _ (splits c) hind with
    | intro sp hsp =>
      have hf : (sp.1.isEmpty || sp.2.isEmpty || !(bal m sp.1 && bal m sp.2)) = false := hsp.2
      cases h1 : sp.1.isEmpty with
      | true => rw [h1] at hf; exact nomatch hf
      | false => cases h2 : sp.2.isEmpty with
        | true => rw [h1, h2] at hf; exact nomatch hf
        | false => cases hA : bal m sp.1 with
          | false => rw [h1, h2, hA] at hf; exact nomatch hf
          | true =>
            have e := bal_hs m H hH sp.1 hA H (fun t ht => ht)
            rw [hsum_gs] at e
            exact hcrit sp.1 sp.2 hsp.1 h1 h2 e

/-- a Bool certificate for avg_indec -/
def unitsOK (m : Nat) (H : List Nat) : Bool := H.all (fun t => Nat.blt t m && Nat.beq (Nat.gcd t m) 1)

def splitOK (m : Nat) (H : List Nat) (sp : List Nat × List Nat) : Bool :=
  sp.1.isEmpty || sp.2.isEmpty || !Nat.beq (gs (D m H) sp.1 + gs (D m H) sp.1) (sp.1.length * (H.length * m))

def avgCheck (m : Nat) (c H : List Nat) : Bool := unitsOK m H && (splits c).all (splitOK m H)

theorem all_mem' {α : Type} (P : α → Bool) : ∀ (l : List α), l.all P = true → ∀ r, r ∈ l → P r = true
  | [], _, _, h => nomatch h
  | x :: l, hl, r, hr => by
    have hx : P x = true ∧ l.all P = true := by
      cases e1 : P x with
      | false => rw [show (x :: l).all P = (P x && l.all P) from rfl, e1] at hl; exact nomatch hl
      | true => rw [show (x :: l).all P = (P x && l.all P) from rfl, e1] at hl; exact ⟨rfl, hl⟩
    cases hr with
    | head => exact hx.1
    | tail _ h' => exact all_mem' P l hx.2 r h'

theorem avg_sound (m : Nat) (c H : List Nat) (h : avgCheck m c H = true) : indec m c = true := by
  have h12 : unitsOK m H = true ∧ (splits c).all (splitOK m H) = true := by
    cases e1 : unitsOK m H with
    | false => rw [show avgCheck m c H = (unitsOK m H && (splits c).all (splitOK m H)) from rfl, e1] at h; exact nomatch h
    | true => rw [show avgCheck m c H = (unitsOK m H && (splits c).all (splitOK m H)) from rfl, e1] at h; exact ⟨rfl, h⟩
  apply avg_indec m c H
  · intro t ht
    have u := all_mem' _ H h12.1 t ht
    cases e1 : Nat.blt t m with
    | false => rw [e1] at u; exact nomatch u
    | true =>
      rw [e1] at u
      exact ⟨Nat.le_of_ble_eq_true e1, Nat.eq_of_beq_eq_true u⟩
  · intro A B hAB hA hB heq
    have u := all_mem' _ _ h12.2 (A, B) hAB
    have u' : (A.isEmpty || B.isEmpty || !Nat.beq (gs (D m H) A + gs (D m H) A) (A.length * (H.length * m))) = true := u
    rw [hA, hB, heq, beq_refl'] at u'
    exact nomatch u'

/-- the m = 72 seed of G510b, certified with H = {t : t mod 36 ∈ ⟨5, 13⟩} ∪ {1} -/
theorem seed72 : indec 72 [2, 10, 50, 54, 64] = true :=
  avg_sound 72 _ [1, 5, 13, 17, 25, 29, 37, 41, 49, 53, 61, 65, 1] rfl

end AvgIndec

#print axioms AvgIndec.gs_addf
#print axioms AvgIndec.hsum_gs
#print axioms AvgIndec.bal_hs
#print axioms AvgIndec.avg_indec
#print axioms AvgIndec.all_mem'
#print axioms AvgIndec.avg_sound
#print axioms AvgIndec.seed72

#print axioms: 7 theorems, no axioms.

81.179 Primality is needed for \(F_p\)

For \(p=87=3\cdot 29\) the member \(F_{87}\) (\(m=1218\)) splits into two balanced parts: the elements sharing a factor with \(87\) and those prime to \(87\). Contrast with the indecomposability for prime \(p\).

hodge/FamComposite.lean

/-
  hodge/FamComposite.lean — T41 cycle 1183 (after G749): primality is needed for the indecomposability of F_p.
  For p = 87 = 3·29 (p ≡ 3 mod 14, i₀ = 31, x₀ = 5) the family member F_87 at m = 1218 is balanced (FamBal) but splits
  into two balanced parts: S = the 31 elements sharing a factor with 87 (including the moved element 957) and the 56
  elements prime to 87:
    f87_split   bal 1218 S = true ∧ bal 1218 T = true      (rfl)
  (contrast FamIndec3.fam_indec for prime p).

  Lean 4 core plus hodge/Indecomp (bal), rfl.
-/
import hodge.Indecomp

namespace FamComposite
open Indecomp

set_option maxRecDepth 100000 in
theorem f87_split : bal 1218 [15, 29, 57, 99, 141, 183, 225, 267, 309, 351, 393, 957, 477, 519, 561, 603, 645, 687, 729, 771, 813, 841, 855, 897, 939, 981, 1023, 1065, 1107, 1149, 1191] = true ∧
    bal 1218 [1, 43, 71, 85, 113, 127, 155, 169, 197, 211, 239, 253, 281, 295, 323, 337, 365, 379, 407, 421, 449, 463, 491, 505, 533, 547, 575, 589, 617, 631, 659, 673, 701, 715, 743, 757, 785, 799, 827, 869, 883, 911, 925, 953, 967, 995, 1009, 1037, 1051, 1079, 1093, 1121, 1135, 1163, 1177, 1205] = true := ⟨rfl, rfl⟩

end FamComposite

#print axioms FamComposite.f87_split

#print axioms: 1 theorem, no axioms.

81.180 Galois orbit of \(F_p\)

The units fixing \(F_p\) are exactly those \(\equiv 1\pmod {14}\) (\(p=3,5,17\) by rfl), so the orbit of \(F_p\) has \(\varphi (14)=6\) members. Computed also for \(p=19,31\).

hodge/FamOrbit.lean

/-
  hodge/FamOrbit.lean — T41 cycle 1195 (goal G770): the Galois orbit of the family F_p. With
  stabB m c t = (t·c ⊆ c) ∧ (c ⊆ t·c) as a Bool test (lists without repetitions), by rfl:
    stab3, stab5, stab17   the units t of 14p with t·F_p = F_p are exactly the units ≡ 1 (mod 14):
                           [1, 29] (p = 3), [1, 29, 43, 57] (p = 5), 16 units (p = 17)
  so the Galois orbit of F_p has φ(14) = 6 members (computed also for p = 19, 31). Reason: t ≡ 1 (mod 14) fixes the
  moved element (≡ 0 mod p) and permutes the coset; any other t changes the residue mod 14.

  Lean 4 core plus hodge/FamBal (fam), hodge/FermatPrime (units), hodge/TwistBal (tw).
-/
import hodge.FamBal
import hodge.TwistBal

namespace FamOrbit
open Indecomp FamBal

def stabB (m : Nat) (c : List Nat) (t : Nat) : Bool :=
  (TwistBal.tw m t c).all (fun x => c.contains x) && c.all (fun x => (TwistBal.tw m t c).contains x)

theorem stab3 : (FermatPrime.units 42).filter (stabB 42 (fam 3 1)) = [1, 29] := rfl
theorem stab5 : (FermatPrime.units 70).filter (stabB 70 (fam 5 1)) = [1, 29, 43, 57] := rfl
theorem stab17 : (FermatPrime.units 238).filter (stabB 238 (fam 17 6))
    = [1, 15, 29, 43, 57, 71, 99, 113, 127, 141, 155, 169, 183, 197, 211, 225] := rfl
theorem units_count : ((FermatPrime.units 42).length, (FermatPrime.units 70).length, (FermatPrime.units 238).length) = (12, 24, 96) := rfl

end FamOrbit

#print axioms FamOrbit.stab3
#print axioms FamOrbit.stab5
#print axioms FamOrbit.stab17
#print axioms FamOrbit.units_count

#print axioms: 4 theorems, no axioms.

81.181 The character carried by the seed \(F_p\)

\(G_p=\{14p\}\sqcup 2F_p\) is a balanced length-\((p+1)\) character at \(m'=28p\) for every member \(F_p\); \(G_5=[70,114,86,58,90,2]\) at \(m=140\). Its seed \(F_p\) is indecomposable for primes \(p\equiv 3,5\pmod {14}\).

hodge/FamDouble.lean

/-
  hodge/FamDouble.lean — T41 cycle 1199 (after G749): the Fermat character carried by the seed F_p. At m' = 28p,
    G_p = 14p :: 2·F_p      (length p + 1, entry sum ≡ 0 mod m')
    gp_bal   G_p is balanced at 28p whenever F_p satisfies the hypotheses of FamBal.fam_bal
  (for t a unit of 28p: t is odd, ⟨t·14p⟩ = 14p, ⟨t·2x⟩_{28p} = 2⟨tx⟩_{14p}, so the unit sum is 14p + 2·7p²
  = (p + 1)·14p). With FamIndec3 the seed F_p of G_p is indecomposable for primes p ≡ 3, 5 (mod 14).

  Lean 4 core plus hodge/FamBal, hodge/FamArith (cop_left/right), hodge/APPair1 (dvd_gcd).
-/
import hodge.FamBal

namespace FamDouble
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp FamBal

theorem mod_double (y M : Nat) (hM : 0 < M) : (2 * y) % (2 * M) = 2 * (y % M) := by
  have hs : y % M < M := Nat.mod_lt _ hM
  have ⟨q, hq⟩ := div_mod M hM (y + 1) y (Nat.lt_succ_self y)
  generalize y % M = s at hs hq ⊢
  subst hq
  have e : 2 * (s + M * q) = 2 * s + q * (2 * M) := by lib_nat
  rw [e, add_mul_mod' _ _ (Nat.mul_pos (Nat.succ_pos 1) hM)]
  apply mod_lt'
  exact Nat.mul_lt_mul_of_le_of_lt (Nat.le_refl 2) hs (Nat.succ_pos 1)

theorem odd_of_cop (t : Nat) (h : Nat.gcd t 2 = 1) : ∃ s, t = 2 * s + 1 := by
  have ⟨q, hq⟩ := div_mod 2 (Nat.succ_pos 1) (t + 1) t (Nat.lt_succ_self t)
  have hr : t % 2 < 2 := Nat.mod_lt _ (Nat.succ_pos 1)
  generalize t % 2 = r at hq hr
  match r, hr with
  | 0, _ =>
    exfalso
    have ⟨c, hc⟩ := APPair1.dvd_gcd 2 t 2 ⟨q, by rw [hq]; lib_nat⟩ ⟨1, rfl⟩
    rw [h] at hc
    exact APPair1.one_eq_mul 2 c hc (Nat.le_refl 2)
  | 1, _ => exact ⟨q, by rw [hq]; lib_nat⟩
  | r + 2, hr' => exact absurd hr' (Nat.not_lt.mpr (Nat.le_add_left 2 r))

theorem half_term (t p : Nat) (hp : 0 < p) (ht : Nat.gcd t 2 = 1) : (t * (14 * p)) % (28 * p) = 14 * p := by
  have ⟨s, hs⟩ := odd_of_cop t ht
  subst hs
  have e : (2 * s + 1) * (14 * p) = 14 * p + s * (28 * p) := by lib_nat
  rw [e, add_mul_mod' _ _ (Nat.mul_pos (Nat.succ_pos 27) hp)]
  apply mod_lt'
  have : 14 * p < 14 * p + 14 * p := Nat.lt_add_of_pos_right (Nat.mul_pos (Nat.succ_pos 13) hp)
  rw [show 14 * p + 14 * p = 28 * p by lib_nat] at this; exact this

theorem len_map (f : Nat → Nat) : ∀ L : List Nat, (L.map f).length = L.length
  | [] => rfl
  | _ :: L => by show (L.map f).length + 1 = L.length + 1; rw [len_map f L]

theorem tsum_map2 (M t : Nat) (hM : 0 < M) : ∀ L : List Nat, tsum (2 * M) t (L.map (fun x => 2 * x)) = 2 * tsum M t L
  | [] => rfl
  | x :: L => by
    show (t * (2 * x)) % (2 * M) + tsum (2 * M) t (L.map (fun x => 2 * x)) = 2 * ((t * x) % M + tsum M t L)
    rw [tsum_map2 M t hM L, show t * (2 * x) = 2 * (t * x) by lib_nat, mod_double _ _ hM]; lib_nat

/-- **G_p = 14p :: 2·F_p is balanced at 28p.** -/
theorem gp_bal (p i0 x0 : Nat) (hp : 0 < p) (hi : i0 < p) (hx : 1 + 14 * i0 = p * x0)
    (hs : fcond (x0 % 14) = true) : bal (28 * p) (14 * p :: (fam p i0).map (fun x => 2 * x)) = true := by
  unfold bal FermatPrime.units
  apply all_filter
  intro t ht
  have hg : Nat.gcd t (2 * (14 * p)) = 1 := by
    have := Nat.eq_of_beq_eq_true ht
    rw [show 2 * (14 * p) = 28 * p by lib_nat]; exact this
  have h14 : Nat.gcd t (14 * p) = 1 := cop_right t 2 (14 * p) hg
  have h2 : Nat.gcd t 2 = 1 := cop_left t 2 (14 * p) hg
  have e := fam_tsum p i0 x0 t hp hi hx hs h14
  have hl : ((fam p i0).map (fun x => 2 * x)).length = p := by
    rw [len_map]; exact gl_len _ p
  show Nat.beq (((t * (14 * p)) % (28 * p) + tsum (28 * p) t ((fam p i0).map (fun x => 2 * x)))
      + ((t * (14 * p)) % (28 * p) + tsum (28 * p) t ((fam p i0).map (fun x => 2 * x))))
    ((((fam p i0).map (fun x => 2 * x)).length + 1) * (28 * p)) = true
  rw [half_term t p hp h2, hl, show 28 * p = 2 * (14 * p) by lib_nat, tsum_map2 (14 * p) t (Nat.mul_pos (Nat.succ_pos 13) hp)]
  have goal : 14 * p + 2 * tsum (14 * p) t (fam p i0) + (14 * p + 2 * tsum (14 * p) t (fam p i0)) = (p + 1) * (2 * (14 * p)) := by
    calc 14 * p + 2 * tsum (14 * p) t (fam p i0) + (14 * p + 2 * tsum (14 * p) t (fam p i0))
        = 28 * p + 2 * (tsum (14 * p) t (fam p i0) + tsum (14 * p) t (fam p i0)) := by lib_nat
      _ = 28 * p + 2 * (p * (14 * p)) := by rw [e]
      _ = _ := by lib_nat
  rw [goal]; exact beq_refl' _

theorem g5 : bal 140 (70 :: (fam 5 1).map (fun x => 2 * x)) = true :=
  gp_bal 5 1 3 (Nat.succ_pos 4) (Nat.succ_lt_succ (Nat.succ_pos 3)) rfl rfl
theorem g5_eq : (70 :: (fam 5 1).map (fun x => 2 * x)) = [70, 114, 86, 58, 90, 2] := rfl

end FamDouble

#print axioms FamDouble.mod_double
#print axioms FamDouble.odd_of_cop
#print axioms FamDouble.half_term
#print axioms FamDouble.len_map
#print axioms FamDouble.tsum_map2
#print axioms FamDouble.gp_bal
#print axioms FamDouble.g5
#print axioms FamDouble.g5_eq

#print axioms: 8 theorems, no axioms.

81.182 Stability of \(F_p\) under \(t\equiv 1\pmod {14}\)

For every prime \(p\) (with \(x_0+6<14\)) and every unit \(t\equiv 1\pmod {14}\) prime to \(p\): \(t\cdot F_p\subseteq F_p\). Conversely a unit fixing \(F_p\) is \(\equiv 1\pmod {14}\): the Galois orbit of \(F_p\) has exactly \(\varphi (14)=6\) members, for every such \(p\).

hodge/FamStab.lean

/-
  hodge/FamStab.lean — T41 cycle 1205 (goal G770b): F_p is stable under the units ≡ 1 (mod 14), for every prime p with
  gcd(14, p) = 1, i₀ < p, 1 + 14i₀ = p·x₀:
    gl_mem'     k < n ⇒ f k ∈ gl f n
    fam_stab    t = 1 + 14j with gcd(t, p) = 1  ⇒  ∀ x ∈ F_p, (t·x) mod 14p ∈ F_p
  (the moved element y = p(x₀ + 6) is fixed: t·y ≡ y; a coset element 1 + 14k goes to 1 + 14·((k + j(1+14k)) mod p),
  which is not the omitted index i₀ since p ∤ t(1 + 14k)).
    stab_sub    a unit t prime to p with t mod 14p ∈ F_p is ≡ 1 (mod 14) (so t ≢ 1 moves 1 ∈ F_p off F_p).
  With FamOrbit: the Galois orbit of F_p has at most
  φ(14) = 6 members for every such p — exactly 6 by stab_sub.

  Lean 4 core plus hodge/FamIndec3, lib/Gcd (euclid_prime).
-/
import hodge.FamIndec3

namespace FamStab
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp FamBal FamIndec1 FamIndec2 FamIndec3

theorem gl_mem' (f : Nat → Nat) : ∀ n k, k < n → f k ∈ gl f n
  | 0, k, h => absurd h (Nat.not_lt_zero k)
  | n + 1, k, h => by
    cases Nat.lt_or_ge k n with
    | inl hlt => exact List.Mem.tail _ (gl_mem' f n k hlt)
    | inr hge =>
      have e : k = n := Nat.le_antisymm (Nat.le_of_lt_succ h) hge
      subst e; exact List.Mem.head _

theorem fam_stab (p i0 x0 j : Nat) (hp1 : 1 < p) (hpr : ∀ d, d ∣ p → d = 1 ∨ d = p) (h14 : Nat.gcd 14 p = 1)
    (hi : i0 < p) (hx : 1 + 14 * i0 = p * x0) (hx6 : x0 + 6 < 14) (ht : Nat.gcd (1 + 14 * j) p = 1) :
    ∀ x, x ∈ fam p i0 → ((1 + 14 * j) * x) % (14 * p) ∈ fam p i0 := by
  intro x hxm
  have hp : 0 < p := Nat.lt_of_le_of_lt (Nat.zero_le 1) hp1
  have h0 : p ∣ 1 + 14 * i0 := ⟨x0, hx⟩
  have hm : 0 < 14 * p := Nat.mul_pos (Nat.succ_pos 13) hp
  have ⟨k, hk, ek⟩ := gl_mem _ p x hxm
  cases e : Nat.beq k i0 with
  | true =>
    have ek0 := Nat.eq_of_beq_eq_true e
    subst ek0
    have ex : x = 1 + 14 * k + 6 * p := by
      rw [← ek]; show (if Nat.beq k k = true then 1 + 14 * k + 6 * p else 1 + 14 * k) = _; rw [beq_refl']; rfl
    have hxy : x = p * (x0 + 6) := by rw [ex, hx]; lib_nat
    have hlt : x < 14 * p := by
      rw [hxy, show 14 * p = p * 14 by lib_nat]
      exact Nat.mul_lt_mul_of_le_of_lt (Nat.le_refl p) hx6 hp
    have e2 : (1 + 14 * j) * x = x + (j * (x0 + 6)) * (14 * p) := by
      calc (1 + 14 * j) * x = x + 14 * j * x := by lib_nat
        _ = x + 14 * j * (p * (x0 + 6)) := by rw [← hxy]
        _ = _ := by lib_nat
    rw [e2, add_mul_mod' _ _ hm, mod_lt' x _ hlt, ex]
    have := gl_mem' (fun k' => if Nat.beq k' k then 1 + 14 * k' + 6 * p else 1 + 14 * k') p k hk
    have hv : (if Nat.beq k k = true then 1 + 14 * k + 6 * p else 1 + 14 * k) = 1 + 14 * k + 6 * p := by
      rw [beq_refl']; rfl
    rw [hv] at this; exact this
  | false =>
    have hk0 : k ≠ i0 := fun h => by rw [h, beq_refl'] at e; exact nomatch e
    have ex : x = 1 + 14 * k := by
      rw [← ek]; show (if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k) = _; rw [e]; rfl
    have hk' : (k + j * x) % p < p := Nat.mod_lt _ hp
    have e1 : (1 + 14 * j) * x = 1 + 14 * (k + j * x) := by rw [ex]; lib_nat
    rw [e1, mod_split 1 _ p hp (Nat.succ_lt_succ (Nat.succ_pos 12))]
    generalize hkk : (k + j * x) % p = k' at hk'
    have hne : k' ≠ i0 := by
      intro hki
      -- p ∣ (1 + 14j)·x
      have ⟨q, hq⟩ := div_mod p hp (k + j * x + 1) (k + j * x) (Nat.lt_succ_self _)
      rw [hkk, hki] at hq
      have hdv : p ∣ (1 + 14 * j) * x := ⟨x0 + 14 * q, by
        rw [e1, hq]
        calc 1 + 14 * (i0 + p * q) = (1 + 14 * i0) + 14 * p * q := by lib_nat
          _ = p * x0 + 14 * p * q := by rw [hx]
          _ = _ := by lib_nat⟩
      cases LibGcd.euclid_prime hpr hdv with
      | inl hpt =>
        have ⟨c, hc⟩ := APPair1.dvd_gcd p (1 + 14 * j) p (let ⟨u, hu⟩ := hpt; ⟨u, hu⟩) ⟨1, by lib_nat⟩
        rw [ht] at hc
        exact APPair1.one_eq_mul p c hc hp1
      | inr hpx =>
        rw [ex] at hpx
        exact hk0 (idx_unique p k i0 hp h14 hk hi hpx h0)
    have hb : Nat.beq k' i0 = false := by
      cases e3 : Nat.beq k' i0 with
      | false => rfl
      | true => exact absurd (Nat.eq_of_beq_eq_true e3) hne
    have := gl_mem' (fun k'' => if Nat.beq k'' i0 then 1 + 14 * k'' + 6 * p else 1 + 14 * k'') p k' hk'
    have hv : (if Nat.beq k' i0 = true then 1 + 14 * k' + 6 * p else 1 + 14 * k') = 1 + 14 * k' := by
      rw [hb]; rfl
    rw [hv] at this; exact this

/-- conversely, a unit t (prime to p) with t mod 14p ∈ F_p (e.g. one fixing F_p, which contains 1) is ≡ 1 (mod 14) -/
theorem stab_sub (p i0 x0 t : Nat) (hp1 : 1 < p) (hx : 1 + 14 * i0 = p * x0) (ht : Nat.gcd t p = 1)
    (hmem : t % (14 * p) ∈ fam p i0) : t % 14 = 1 := by
  have hp : 0 < p := Nat.lt_of_le_of_lt (Nat.zero_le 1) hp1
  have ⟨k, _, ek⟩ := gl_mem _ p _ hmem
  have ⟨q, hq⟩ := div_mod (14 * p) (Nat.mul_pos (Nat.succ_pos 13) hp) (t + 1) t (Nat.lt_succ_self t)
  cases e : Nat.beq k i0 with
  | true =>
    exfalso
    have ek0 := Nat.eq_of_beq_eq_true e
    subst ek0
    have ev : t % (14 * p) = p * (x0 + 6) := by
      rw [← ek]; show (if Nat.beq k k = true then 1 + 14 * k + 6 * p else 1 + 14 * k) = _
      rw [beq_refl']; show 1 + 14 * k + 6 * p = _; rw [hx]; lib_nat
    rw [ev] at hq
    have ⟨c, hc⟩ := APPair1.dvd_gcd p t p ⟨x0 + 6 + 14 * q, by rw [hq]; lib_nat⟩ ⟨1, by lib_nat⟩
    rw [ht] at hc
    exact APPair1.one_eq_mul p c hc hp1
  | false =>
    have ev : t % (14 * p) = 1 + 14 * k := by
      rw [← ek]; show (if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k) = _; rw [e]; rfl
    rw [ev] at hq
    have e2 : t = 1 + (k + p * q) * 14 := by rw [hq]; lib_nat
    rw [e2, add_mul_mod' _ _ (Nat.succ_pos 13)]

end FamStab

#print axioms FamStab.gl_mem'
#print axioms FamStab.fam_stab
#print axioms FamStab.stab_sub

#print axioms: 3 theorems, no axioms.

81.183 The case \(p\equiv 1\pmod {14}\)

If \(1+14i_0=p\) the moved element of \(F_p\) is \(7p=m/2\), balanced by itself: the hypothesis \(x_0\ne 1\) of the indecomposability is necessary. Examples \(p=29,43,71\).

hodge/FamHalf.lean

/-
  hodge/FamHalf.lean — T41 cycle 1213 (after G749): the hypothesis x₀ ≠ 1 of FamIndec3.fam_indec is necessary.
  If 1 + 14·i₀ = p (x₀ = 1, i.e. p ≡ 1 mod 14), the moved element of F_p is 7p = m/2, which is balanced by itself:
    half_mem   7p ∈ fam p i₀
    half_bal7  bal (14p) [7p] = true
  so F_p = [7p] ⊔ (rest) splits (e.g. p = 29, 43, 71).

  Lean 4 core plus hodge/FamStab (gl_mem'), hodge/GcdHand (half_bal_even).
-/
import hodge.FamStab

namespace FamHalf
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp FamBal FamStab

theorem half_mem (p i0 : Nat) (hi : i0 < p) (hx : 1 + 14 * i0 = p) : 7 * p ∈ fam p i0 := by
  have := gl_mem' (fun k => if Nat.beq k i0 then 1 + 14 * k + 6 * p else 1 + 14 * k) p i0 hi
  have hv : (if Nat.beq i0 i0 = true then 1 + 14 * i0 + 6 * p else 1 + 14 * i0) = 7 * p := by
    rw [beq_refl']; show 1 + 14 * i0 + 6 * p = 7 * p; rw [hx]; lib_nat
  rw [hv] at this; exact this

theorem half_bal7 (p : Nat) (hp : 0 < p) : bal (14 * p) [7 * p] = true := by
  have h := half_bal_even (7 * p) (Nat.mul_pos (Nat.succ_pos 6) hp)
  rw [show 7 * p + 7 * p = 14 * p by lib_nat] at h
  exact h

end FamHalf

#print axioms FamHalf.half_mem
#print axioms FamHalf.half_bal7

#print axioms: 2 theorems, no axioms.

81.184 Balanced surface characters for \(p=59\) (Kamiak)

Every balanced length-4 character of the degree-59 Fermat surface is two complementary pairs; length 4 settled for all odd primes \(p\le 59\).

hodge/Pairs4i.lean

/-
  hodge/Pairs4i.lean — T41 cycle 1107 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 59:
  every balanced length-4 character of the degree-59 Fermat surface is a union of two complementary pairs (rfl, no
  heartbeat limit). With Pairs4, Pairs4b, Pairs4c, Pairs4d: length 4 settled for all odd primes p ≤ 59.

  Lean 4 core plus hodge/Pairs4 (badQ), rfl.
-/
import hodge.Pairs4

namespace Pairs4i
open Pairs4

set_option maxHeartbeats 0 in
set_option maxRecDepth 16000000 in
theorem r59 : badQ 59 = [] := rfl

end Pairs4i

#print axioms Pairs4i.r59

#print axioms: 1 theorem, no axioms.

81.185 Balanced surface characters for \(p=61\) (Kamiak)

Every balanced length-4 character of the degree-61 Fermat surface is two complementary pairs; length 4 settled for all odd primes \(p\le 61\).

hodge/Pairs4j.lean

/-
  hodge/Pairs4j.lean — T41 cycle 1179 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 61:
  every balanced length-4 character of the degree-61 Fermat surface is a union of two complementary pairs (rfl, no
  heartbeat limit). With Pairs4, Pairs4b, Pairs4c, Pairs4d: length 4 settled for all odd primes p ≤ 61.

  Lean 4 core plus hodge/Pairs4 (badQ), rfl.
-/
import hodge.Pairs4

namespace Pairs4j
open Pairs4

set_option maxHeartbeats 0 in
set_option maxRecDepth 16000000 in
theorem r61 : badQ 61 = [] := rfl

end Pairs4j

#print axioms Pairs4j.r61

#print axioms: 1 theorem, no axioms.

81.186 Balanced surface characters for \(p=67\) (Kamiak)

Every balanced length-4 character of the degree-67 Fermat surface is two complementary pairs; 66 first-entry pieces in 6 files. Length 4 settled for all odd primes \(p\le 67\).

hodge/Pairs4k.lean

/-
  hodge/Pairs4k.lean — T41 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 67: every
  balanced length-4 character of the degree-67 Fermat surface is a union of two complementary pairs. The single rfl
  ran out of memory at 64G, so the check is split by the first entry (Pairs4Split.badQ_split) into the pieces
  hodge/Pairs4kS1 … S6, each rfl.

  Lean 4 core plus hodge/Pairs4Split, hodge/Pairs4kS1–S6.
-/
import hodge.Pairs4Split
import hodge.Pairs4kS1
import hodge.Pairs4kS2
import hodge.Pairs4kS3
import hodge.Pairs4kS4
import hodge.Pairs4kS5
import hodge.Pairs4kS6

namespace Pairs4k

set_option maxHeartbeats 0 in
set_option maxRecDepth 1000000 in
theorem r67 : Pairs4.badQ 67 = [] := by
  rw [Pairs4Split.badQ_split]
  show Pairs4Split.badQAt 67 1 ++ (Pairs4Split.badQAt 67 2 ++ (Pairs4Split.badQAt 67 3 ++ (Pairs4Split.badQAt 67 4 ++ (Pairs4Split.badQAt 67 5 ++ (Pairs4Split.badQAt 67 6 ++ (Pairs4Split.badQAt 67 7 ++ (Pairs4Split.badQAt 67 8 ++ (Pairs4Split.badQAt 67 9 ++ (Pairs4Split.badQAt 67 10 ++ (Pairs4Split.badQAt 67 11 ++ (Pairs4Split.badQAt 67 12 ++ (Pairs4Split.badQAt 67 13 ++ (Pairs4Split.badQAt 67 14   -- (+1585 chars; full line in the Zenodo source)
  rw [Pairs4kS1.x1, Pairs4kS1.x2, Pairs4kS1.x3, Pairs4kS1.x4, Pairs4kS1.x5, Pairs4kS1.x6, Pairs4kS1.x7, Pairs4kS1.x8, Pairs4kS1.x9, Pairs4kS1.x10, Pairs4kS1.x11, Pairs4kS2.x12, Pairs4kS2.x13, Pairs4kS2.x14, Pairs4kS2.x15, Pairs4kS2.x16, Pairs4kS2.x17, Pairs4kS2.x18, Pairs4kS2.x19, Pairs4kS2.x20, Pairs4kS2.x21, Pairs4kS2.x22, Pairs4kS3.x23, Pairs4kS3.x24, Pairs4kS3.x25, Pairs4kS3.x26, Pairs4kS3.x27  -- (+586 chars; full line in the Zenodo source)
  rfl

end Pairs4k

#print axioms Pairs4k.r67

#print axioms: 1 theorem, no axioms (pieces Pairs4kS1–S6: 66 theorems, no axioms).

81.187 Balanced surface characters for \(p=71\) (Kamiak)

Every balanced length-4 character of the degree-71 Fermat surface is two complementary pairs; 70 first-entry pieces in 7 files. Length 4 settled for all odd primes \(p\le 71\).

hodge/Pairs4l.lean

/-
  hodge/Pairs4l.lean — T41 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 71: every
  balanced length-4 character of the degree-71 Fermat surface is a union of two complementary pairs. The single rfl
  ran out of memory at 64G, so the check is split by the first entry (Pairs4Split.badQ_split) into the pieces
  hodge/Pairs4lS1 … S7, each rfl.

  Lean 4 core plus hodge/Pairs4Split, hodge/Pairs4lS1–S7.
-/
import hodge.Pairs4Split
import hodge.Pairs4lS1
import hodge.Pairs4lS2
import hodge.Pairs4lS3
import hodge.Pairs4lS4
import hodge.Pairs4lS5
import hodge.Pairs4lS6
import hodge.Pairs4lS7

namespace Pairs4l

set_option maxHeartbeats 0 in
set_option maxRecDepth 1000000 in
theorem r71 : Pairs4.badQ 71 = [] := by
  rw [Pairs4Split.badQ_split]
  show Pairs4Split.badQAt 71 1 ++ (Pairs4Split.badQAt 71 2 ++ (Pairs4Split.badQAt 71 3 ++ (Pairs4Split.badQAt 71 4 ++ (Pairs4Split.badQAt 71 5 ++ (Pairs4Split.badQAt 71 6 ++ (Pairs4Split.badQAt 71 7 ++ (Pairs4Split.badQAt 71 8 ++ (Pairs4Split.badQAt 71 9 ++ (Pairs4Split.badQAt 71 10 ++ (Pairs4Split.badQAt 71 11 ++ (Pairs4Split.badQAt 71 12 ++ (Pairs4Split.badQAt 71 13 ++ (Pairs4Split.badQAt 71 14   -- (+1705 chars; full line in the Zenodo source)
  rw [Pairs4lS1.x1, Pairs4lS1.x2, Pairs4lS1.x3, Pairs4lS1.x4, Pairs4lS1.x5, Pairs4lS1.x6, Pairs4lS1.x7, Pairs4lS1.x8, Pairs4lS1.x9, Pairs4lS1.x10, Pairs4lS1.x11, Pairs4lS2.x12, Pairs4lS2.x13, Pairs4lS2.x14, Pairs4lS2.x15, Pairs4lS2.x16, Pairs4lS2.x17, Pairs4lS2.x18, Pairs4lS2.x19, Pairs4lS2.x20, Pairs4lS2.x21, Pairs4lS2.x22, Pairs4lS3.x23, Pairs4lS3.x24, Pairs4lS3.x25, Pairs4lS3.x26, Pairs4lS3.x27  -- (+646 chars; full line in the Zenodo source)
  rfl

end Pairs4l

#print axioms Pairs4l.r71

#print axioms: 1 theorem, no axioms (pieces Pairs4lS1–S7: 70 theorems, no axioms).

81.188 Balanced surface characters for \(p=73\) (Kamiak)

Every balanced length-4 character of the degree-73 Fermat surface is two complementary pairs; 72 first-entry pieces in 7 files. Length 4 settled for all odd primes \(p\le 73\).

hodge/Pairs4m.lean

/-
  hodge/Pairs4m.lean — T41 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 73: every
  balanced length-4 character of the degree-73 Fermat surface is a union of two complementary pairs. The single rfl
  ran out of memory at 64G, so the check is split by the first entry (Pairs4Split.badQ_split) into the pieces
  hodge/Pairs4mS1 … S7, each rfl.

  Lean 4 core plus hodge/Pairs4Split, hodge/Pairs4mS1–S7.
-/
import hodge.Pairs4Split
import hodge.Pairs4mS1
import hodge.Pairs4mS2
import hodge.Pairs4mS3
import hodge.Pairs4mS4
import hodge.Pairs4mS5
import hodge.Pairs4mS6
import hodge.Pairs4mS7

namespace Pairs4m

set_option maxHeartbeats 0 in
set_option maxRecDepth 1000000 in
theorem r73 : Pairs4.badQ 73 = [] := by
  rw [Pairs4Split.badQ_split]
  show Pairs4Split.badQAt 73 1 ++ (Pairs4Split.badQAt 73 2 ++ (Pairs4Split.badQAt 73 3 ++ (Pairs4Split.badQAt 73 4 ++ (Pairs4Split.badQAt 73 5 ++ (Pairs4Split.badQAt 73 6 ++ (Pairs4Split.badQAt 73 7 ++ (Pairs4Split.badQAt 73 8 ++ (Pairs4Split.badQAt 73 9 ++ (Pairs4Split.badQAt 73 10 ++ (Pairs4Split.badQAt 73 11 ++ (Pairs4Split.badQAt 73 12 ++ (Pairs4Split.badQAt 73 13 ++ (Pairs4Split.badQAt 73 14   -- (+1765 chars; full line in the Zenodo source)
  rw [Pairs4mS1.x1, Pairs4mS1.x2, Pairs4mS1.x3, Pairs4mS1.x4, Pairs4mS1.x5, Pairs4mS1.x6, Pairs4mS1.x7, Pairs4mS1.x8, Pairs4mS1.x9, Pairs4mS1.x10, Pairs4mS1.x11, Pairs4mS2.x12, Pairs4mS2.x13, Pairs4mS2.x14, Pairs4mS2.x15, Pairs4mS2.x16, Pairs4mS2.x17, Pairs4mS2.x18, Pairs4mS2.x19, Pairs4mS2.x20, Pairs4mS2.x21, Pairs4mS2.x22, Pairs4mS3.x23, Pairs4mS3.x24, Pairs4mS3.x25, Pairs4mS3.x26, Pairs4mS3.x27  -- (+676 chars; full line in the Zenodo source)
  rfl

end Pairs4m

#print axioms Pairs4m.r73

#print axioms: 1 theorem, no axioms (pieces Pairs4mS1–S7: 72 theorems, no axioms).

81.189 Length-6 pair characters for \(p=29\) (Kamiak)

Every balanced length-6 character of the degree-29 Fermat fourfold is a union of three complementary pairs; 28 first-entry pieces assembled through the bridge. Length 6 settled for all odd primes \(p\le 29\).

hodge/Pairs6c.lean

/-
  hodge/Pairs6c.lean — T41 goal G697 (Kamiak): for p = 29 every balanced length-6 character of the degree-29 Fermat
  fourfold is a union of three complementary pairs. Split by the first entry (Pairs6Split.badP_split) into 28 pieces
  hodge/Pairs6cP1 … Pairs6cP28, each rfl.

  Lean 4 core plus hodge/Pairs6 (badP), hodge/Pairs6Split, hodge/Pairs6cP1–28.
-/
import hodge.Pairs6
import hodge.Pairs6Bridge
import hodge.Pairs6cP1
import hodge.Pairs6cP2
import hodge.Pairs6cP3
import hodge.Pairs6cP4
import hodge.Pairs6cP5
import hodge.Pairs6cP6
import hodge.Pairs6cP7
import hodge.Pairs6cP8
import hodge.Pairs6cP9
import hodge.Pairs6cP10
import hodge.Pairs6cP11
import hodge.Pairs6cP12
import hodge.Pairs6cP13
import hodge.Pairs6cP14
import hodge.Pairs6cP15
import hodge.Pairs6cP16
import hodge.Pairs6cP17
import hodge.Pairs6cP18
import hodge.Pairs6cP19
import hodge.Pairs6cP20
import hodge.Pairs6cP21
import hodge.Pairs6cP22
import hodge.Pairs6cP23
import hodge.Pairs6cP24
import hodge.Pairs6cP25
import hodge.Pairs6cP26
import hodge.Pairs6cP27
import hodge.Pairs6cP28

namespace Pairs6c
open Pairs6Split

set_option maxHeartbeats 0 in
set_option maxRecDepth 1000000 in
theorem p29 : Pairs6.badP 29 = [] := by
  rw [Pairs6Bridge.badP_eq, badP_split]
  show badAt 29 1 ++ (badAt 29 2 ++ (badAt 29 3 ++ (badAt 29 4 ++ (badAt 29 5 ++ (badAt 29 6 ++ (badAt 29 7 ++ (badAt 29 8 ++ (badAt 29 9 ++ (badAt 29 10 ++ (badAt 29 11 ++ (badAt 29 12 ++ (badAt 29 13 ++ (badAt 29 14 ++ (badAt 29 15 ++ (badAt 29 16 ++ (badAt 29 17 ++ (badAt 29 18 ++ (badAt 29 19 ++ (badAt 29 20 ++ (badAt 29 21 ++ (badAt 29 22 ++ (badAt 29 23 ++ (badAt 29 24 ++ (badAt 29 25 ++ (ba  -- (+81 chars; full line in the Zenodo source)
  rw [Pairs6cP1.piece, Pairs6cP2.piece, Pairs6cP3.piece, Pairs6cP4.piece, Pairs6cP5.piece, Pairs6cP6.piece, Pairs6cP7.piece, Pairs6cP8.piece, Pairs6cP9.piece, Pairs6cP10.piece, Pairs6cP11.piece, Pairs6cP12.piece, Pairs6cP13.piece, Pairs6cP14.piece, Pairs6cP15.piece, Pairs6cP16.piece, Pairs6cP17.piece, Pairs6cP18.piece, Pairs6cP19.piece, Pairs6cP20.piece, Pairs6cP21.piece, Pairs6cP22.piece, Pairs6c  -- (+100 chars; full line in the Zenodo source)
  rfl

end Pairs6c

#print axioms Pairs6c.p29

#print axioms: 1 theorem, no axioms (pieces Pairs6cP1–P28: 1 theorem each, no axioms).

81.190 Length-6 pair characters for \(p=31\) (Kamiak)

Every balanced length-6 character of the degree-31 Fermat fourfold is a union of three complementary pairs; 30 first-entry pieces assembled through the bridge. Length 6 settled for all odd primes \(p\le 31\).

hodge/Pairs6d.lean

/-
  hodge/Pairs6d.lean — T41 goal G716 (Kamiak): for p = 31 every balanced length-6 character of the degree-31 Fermat
  fourfold is a union of three complementary pairs. 30 first-entry pieces hodge/Pairs6dP1 … Pairs6dP30, each rfl,
  assembled through Pairs6Bridge.badP_eq and Pairs6Split.badP_split.

  Lean 4 core plus hodge/Pairs6 (badP), hodge/Pairs6Bridge, hodge/Pairs6Split, hodge/Pairs6dP1–30.
-/
import hodge.Pairs6
import hodge.Pairs6Bridge
import hodge.Pairs6dP1
import hodge.Pairs6dP2
import hodge.Pairs6dP3
import hodge.Pairs6dP4
import hodge.Pairs6dP5
import hodge.Pairs6dP6
import hodge.Pairs6dP7
import hodge.Pairs6dP8
import hodge.Pairs6dP9
import hodge.Pairs6dP10
import hodge.Pairs6dP11
import hodge.Pairs6dP12
import hodge.Pairs6dP13
import hodge.Pairs6dP14
import hodge.Pairs6dP15
import hodge.Pairs6dP16
import hodge.Pairs6dP17
import hodge.Pairs6dP18
import hodge.Pairs6dP19
import hodge.Pairs6dP20
import hodge.Pairs6dP21
import hodge.Pairs6dP22
import hodge.Pairs6dP23
import hodge.Pairs6dP24
import hodge.Pairs6dP25
import hodge.Pairs6dP26
import hodge.Pairs6dP27
import hodge.Pairs6dP28
import hodge.Pairs6dP29
import hodge.Pairs6dP30

namespace Pairs6d
open Pairs6Split

set_option maxHeartbeats 0 in
set_option maxRecDepth 1000000 in
theorem p31 : Pairs6.badP 31 = [] := by
  rw [Pairs6Bridge.badP_eq, badP_split]
  show badAt 31 1 ++ (badAt 31 2 ++ (badAt 31 3 ++ (badAt 31 4 ++ (badAt 31 5 ++ (badAt 31 6 ++ (badAt 31 7 ++ (badAt 31 8 ++ (badAt 31 9 ++ (badAt 31 10 ++ (badAt 31 11 ++ (badAt 31 12 ++ (badAt 31 13 ++ (badAt 31 14 ++ (badAt 31 15 ++ (badAt 31 16 ++ (badAt 31 17 ++ (badAt 31 18 ++ (badAt 31 19 ++ (badAt 31 20 ++ (badAt 31 21 ++ (badAt 31 22 ++ (badAt 31 23 ++ (badAt 31 24 ++ (badAt 31 25 ++ (ba  -- (+115 chars; full line in the Zenodo source)
  rw [Pairs6dP1.piece, Pairs6dP2.piece, Pairs6dP3.piece, Pairs6dP4.piece, Pairs6dP5.piece, Pairs6dP6.piece, Pairs6dP7.piece, Pairs6dP8.piece, Pairs6dP9.piece, Pairs6dP10.piece, Pairs6dP11.piece, Pairs6dP12.piece, Pairs6dP13.piece, Pairs6dP14.piece, Pairs6dP15.piece, Pairs6dP16.piece, Pairs6dP17.piece, Pairs6dP18.piece, Pairs6dP19.piece, Pairs6dP20.piece, Pairs6dP21.piece, Pairs6dP22.piece, Pairs6d  -- (+136 chars; full line in the Zenodo source)
  rfl

end Pairs6d

#print axioms Pairs6d.p31

#print axioms: 1 theorem, no axioms (pieces Pairs6dP1–P30: 1 theorem each, no axioms).

81.191 Three complementary pairs give a 2+4 split

A list of complementary pairs with entries in \((0,m)\) is balanced; hence if every balanced length-6 character is three pairs (\(\texttt {badP}\,m=[]\)), every one has a \(2+4\) split: the 2+4 statement (G526b) reduces to the three-pairs statement (G529b).

hodge/PairsSplit.lean

/-
  hodge/PairsSplit.lean — T41 cycle 1363 (goal G526c): three complementary pairs give a 2 + 4 split, every m.
    pair_mod        for gcd(t, m) = 1 and 0 < x < m:  ⟨tx⟩_m + ⟨t(m − x)⟩_m = m
    tsum_erase      a ∈ l ⇒ tsum(l) = ⟨ta⟩ + tsum(l.erase a);  len_erase, all_erase alongside
    pairs_tsum      a list passing allPairs (entries in (0, m)) has 2·tsum_t = length·m for every unit t
    bal_of_pairs    hence it is balanced
    has24_of_pairs  a nonempty allPairs list has a 2 + 4 split (has24): remove the first pair, the rest is pairs
    split24_of_pairs  if Pairs6.badP m = [] then every balanced character c ∈ sexts m with entries in (0, m) has a
                    2 + 4 split — so G526b (2 + 4 split for odd primes) follows from G529b (three pairs), and the
                    Kamiak certificates Pairs6 … Pairs6c give it for every odd prime p ≤ 29 (allPairs, badP copied verbatim from
                    hodge/Pairs6, a Kamiak root; instances in hodge/PairsSplitInst).

  Lean 4 core plus hodge/Split24 (has24), hodge/Conjugate (pair_gen),
  hodge/APPairGen (euclid), hodge/FamBal (all_filter, beq_refl'), hodge/ModHand, hodge/GcdHand, hodge/BalAppend.
-/
import hodge.Split24
import hodge.Conjugate
import hodge.APPairGen
import hodge.FamBal
import hodge.ModHand
import hodge.GcdHand
import hodge.BalAppend

namespace PairsSplit
open Indecomp Len6Decomp Split24

/-- the same definitions as hodge/Pairs6 (which is a Kamiak root: its rfl proofs are heavy) -/
def allPairs (m : Nat) : Nat → List Nat → Bool
  | 0, _ => false
  | _, [] => true
  | f + 1, x :: l => l.contains (m - x) && allPairs m f (l.erase (m - x))

def badP (m : Nat) : List (List Nat) := (sexts m).filter (fun c => bal m c && !allPairs m 7 c)

theorem andL : ∀ {a b : Bool}, (a && b) = true → a = true
  | true, _, _ => rfl
  | false, _, h => Bool.noConfusion h

theorem andR : ∀ {a b : Bool}, (a && b) = true → b = true
  | true, _, h => h
  | false, _, h => Bool.noConfusion h

theorem pair_mod (m' t x : Nat) (hg : Nat.gcd t (m' + 1) = 1) (hx0 : 0 < x) (hxm : x < m' + 1) :
    (t * x) % (m' + 1) + (t * (m' + 1 - x)) % (m' + 1) = m' + 1 := by
  have hy : (m' + 1 - x) + x = m' + 1 := GcdHand.sub_add' x (m' + 1) (Nat.le_of_lt hxm)
  generalize hyd : m' + 1 - x = y at hy ⊢
  have e : t * x + t * y = 0 + t * (m' + 1) := by rw [← hy]; lib_nat
  apply Conjugate.pair_gen m' (t * x) (t * y)
  · rw [ESChain.rem_eq_mod, e, ModHand.add_mul_mod' 0 (m' + 1) (Nat.succ_pos m') t, ModHand.mod_lt' 0 (m' + 1) (Nat.succ_pos m')]
  · intro hd
    cases hd with
    | intro q hq =>
      have ⟨k, hk⟩ := APPairGen.euclid t (m' + 1) (m' + 1) y hg ⟨q, by rw [hq]; lib_nat⟩ ⟨y, by lib_nat⟩
      cases k with
      | zero =>
        rw [hk, Nat.mul_zero, Nat.zero_add] at hy
        rw [hy] at hxm
        exact Nat.lt_irrefl _ hxm
      | succ k =>
        rw [hk] at hy
        have e2 : (m' + 1) * (k + 1) + x = (m' + 1) + ((m' + 1) * k + x) := by lib_nat
        rw [e2] at hy
        have hy' : (m' + 1) + ((m' + 1) * k + x) = (m' + 1) + 0 := hy
        have z := BalAppend.add_cancel _ _ _ hy'
        have x0 : x = 0 := Nat.eq_zero_of_add_eq_zero_left z
        rw [x0] at hx0
        exact Nat.lt_irrefl _ hx0

theorem erase_head (x : Nat) (l : List Nat) : (x :: l).erase x = l := by
  show (match x == x with | true => l | false => x :: l.erase x) = l
  rw [show (x == x) = true from FamBal.beq_refl' x]

theorem beq_symm_false (a b : Nat) (h : (a == b) = false) : (b == a) = false := by
  cases e : (b == a) with
  | false => rfl
  | true =>
    have hb : b = a := Nat.eq_of_beq_eq_true e
    rw [hb, show (a == a) = true from FamBal.beq_refl' a] at h
    exact Bool.noConfusion h

theorem contains_tail (a b : Nat) (l : List Nat) (hab : (a == b) = false) (h : (b :: l).contains a = true) :
    l.contains a = true := by
  have h' : (match a == b with | true => true | false => l.contains a) = true := h
  rw [hab] at h'; exact h'

theorem erase_tail (a b : Nat) (l : List Nat) (hab : (a == b) = false) : (b :: l).erase a = b :: l.erase a := by
  show (match b == a with | true => l | false => b :: l.erase a) = _
  rw [beq_symm_false a b hab]

theorem tsum_erase (m t a : Nat) : ∀ l : List Nat, l.contains a = true → tsum m t l = (t * a) % m + tsum m t (l.erase a)
  | [], h => Bool.noConfusion h
  | b :: l, h => by
    cases hab : (a == b) with
    | true =>
      have e : a = b := Nat.eq_of_beq_eq_true hab
      rw [← e, erase_head]
      rfl
    | false =>
      rw [erase_tail a b l hab]
      show (t * b) % m + tsum m t l = (t * a) % m + ((t * b) % m + tsum m t (l.erase a))
      rw [tsum_erase m t a l (contains_tail a b l hab h)]
      lib_nat

theorem len_erase (a : Nat) : ∀ l : List Nat, l.contains a = true → (l.erase a).length + 1 = l.length
  | [], h => Bool.noConfusion h
  | b :: l, h => by
    cases hab : (a == b) with
    | true =>
      have e : a = b := Nat.eq_of_beq_eq_true hab
      rw [← e, erase_head]
      rfl
    | false =>
      rw [erase_tail a b l hab]
      show (l.erase a).length + 1 + 1 = l.length + 1
      rw [len_erase a l (contains_tail a b l hab h)]

theorem all_erase (P : Nat → Bool) (a : Nat) : ∀ l : List Nat, l.all P = true → (l.erase a).all P = true
  | [], _ => rfl
  | b :: l, h => by
    have h' : (P b && l.all P) = true := h
    cases hab : (a == b) with
    | true =>
      have e : a = b := Nat.eq_of_beq_eq_true hab
      rw [← e, erase_head]
      exact andR h'
    | false =>
      rw [erase_tail a b l hab]
      show (P b && (l.erase a).all P) = true
      rw [andL h', all_erase P a l (andR h')]
      rfl

def inR (m x : Nat) : Bool := Nat.blt 0 x && Nat.blt x m

theorem pairs_tsum (m' t : Nat) (hg : Nat.gcd t (m' + 1) = 1) : ∀ (f : Nat) (l : List Nat),
    l.all (inR (m' + 1)) = true → allPairs (m' + 1) f l = true →
    tsum (m' + 1) t l + tsum (m' + 1) t l = l.length * (m' + 1)
  | 0, _, _, h => Bool.noConfusion h
  | _ + 1, [], _, _ => by show 0 + 0 = 0 * (m' + 1); rw [Nat.zero_mul]
  | f + 1, x :: l, hr, h => by
    have h' : (l.contains (m' + 1 - x) && allPairs (m' + 1) f (l.erase (m' + 1 - x))) = true := h
    have hr' : (inR (m' + 1) x && l.all (inR (m' + 1))) = true := hr
    have hx := andL hr'
    have hx0 : 0 < x := Nat.le_of_ble_eq_true (andL hx)
    have hxm : x < m' + 1 := Nat.le_of_ble_eq_true (andR hx)
    have ih := pairs_tsum m' t hg f (l.erase (m' + 1 - x)) (all_erase _ _ l (andR hr')) (andR h')
    have pm := pair_mod m' t x hg hx0 hxm
    have te := tsum_erase (m' + 1) t (m' + 1 - x) l (andL h')
    have le := len_erase (m' + 1 - x) l (andL h')
    show (t * x) % (m' + 1) + tsum (m' + 1) t l + ((t * x) % (m' + 1) + tsum (m' + 1) t l) = (l.length + 1) * (m' + 1)
    rw [te, ← le]
    generalize tsum (m' + 1) t (l.erase (m' + 1 - x)) = R at ih ⊢
    generalize (l.erase (m' + 1 - x)).length = L at ih ⊢
    generalize (t * x) % (m' + 1) = A at pm ⊢
    generalize (t * (m' + 1 - x)) % (m' + 1) = B at pm ⊢
    rw [show A + (B + R) + (A + (B + R)) = (A + B) + (A + B) + (R + R) by lib_nat, pm, ih]
    lib_nat

theorem bal_of_pairs (m' f : Nat) (l : List Nat) (hr : l.all (inR (m' + 1)) = true) (h : allPairs (m' + 1) f l = true) :
    bal (m' + 1) l = true := by
  show ((List.range (m' + 1)).filter (fun t => Nat.beq (Nat.gcd t (m' + 1)) 1)).all
    (fun t => Nat.beq (tsum (m' + 1) t l + tsum (m' + 1) t l) (l.length * (m' + 1))) = true
  apply FamBal.all_filter
  intro t ht
  show Nat.beq (tsum (m' + 1) t l + tsum (m' + 1) t l) (l.length * (m' + 1)) = true
  rw [pairs_tsum m' t (Nat.eq_of_beq_eq_true ht) f l hr h]
  exact FamBal.beq_refl' _

theorem has24_of_pairs (m' x : Nat) (l : List Nat) (hr : (x :: l).all (inR (m' + 1)) = true)
    (h : allPairs (m' + 1) 7 (x :: l) = true) : has24 (m' + 1) (x :: l) = true := by
  have h' : (l.contains (m' + 1 - x) && allPairs (m' + 1) 6 (l.erase (m' + 1 - x))) = true := h
  have hr' : (inR (m' + 1) x && l.all (inR (m' + 1))) = true := hr
  have hb := bal_of_pairs m' 6 _ (all_erase _ _ l (andR hr')) (andR h')
  show ((((x :: l).erase x).contains (m' + 1 - x) && bal (m' + 1) (((x :: l).erase x).erase (m' + 1 - x))) || _) = true
  rw [erase_head, andL h', hb]
  rfl

theorem mem_filter_gen {α : Type} (pr : α → Bool) (t : α) (hp : pr t = true) : ∀ l : List α, t ∈ l → t ∈ l.filter pr
  | [], h => nomatch h
  | x :: l, h => by
    cases hx : pr x with
    | false =>
      have e : (x :: l).filter pr = l.filter pr := by show (match pr x with | true => x :: l.filter pr | false => l.filter pr) = _; rw [hx]
      rw [e]
      cases h with
      | head => rw [hp] at hx; exact nomatch hx
      | tail _ h' => exact mem_filter_gen pr t hp l h'
    | true =>
      have e : (x :: l).filter pr = x :: l.filter pr := by show (match pr x with | true => x :: l.filter pr | false => l.filter pr) = _; rw [hx]
      rw [e]
      cases h with
      | head => exact List.Mem.head _
      | tail _ h' => exact List.Mem.tail _ (mem_filter_gen pr t hp l h')

theorem split24_of_pairs (m' : Nat) (hP : badP (m' + 1) = []) (c : List Nat) (hc : c ∈ sexts (m' + 1))
    (hr : c.all (inR (m' + 1)) = true) (hne : c ≠ []) (hb : bal (m' + 1) c = true) : has24 (m' + 1) c = true := by
  have hp : allPairs (m' + 1) 7 c = true := by
    cases e : allPairs (m' + 1) 7 c with
    | true => rfl
    | false =>
      have hm : c ∈ badP (m' + 1) :=
        mem_filter_gen (fun c => bal (m' + 1) c && !allPairs (m' + 1) 7 c) c (by show (bal (m' + 1) c && !allPairs (m' + 1) 7 c) = true; rw [hb, e]; rfl) _ hc
      rw [hP] at hm
      exact absurd hm (List.not_mem_nil)
  cases c with
  | nil => exact absurd rfl hne
  | cons x l => exact has24_of_pairs m' x l hr hp

end PairsSplit

#print axioms PairsSplit.andL
#print axioms PairsSplit.andR
#print axioms PairsSplit.pair_mod
#print axioms PairsSplit.erase_head
#print axioms PairsSplit.beq_symm_false
#print axioms PairsSplit.contains_tail
#print axioms PairsSplit.erase_tail
#print axioms PairsSplit.tsum_erase
#print axioms PairsSplit.len_erase
#print axioms PairsSplit.all_erase
#print axioms PairsSplit.pairs_tsum
#print axioms PairsSplit.bal_of_pairs
#print axioms PairsSplit.has24_of_pairs
#print axioms PairsSplit.mem_filter_gen
#print axioms PairsSplit.split24_of_pairs

#print axioms: 15 theorems, no axioms.

81.192 Peeling a complementary pair off a balanced character

If \(c\) is balanced of degree \(m\) and contains \(x\) and \(m-x\) (\(0<x<m\)), then \(c\) with that pair removed is balanced, every \(m\).

hodge/PairPeel.lean

/-
  hodge/PairPeel.lean — T41 cycle 1367 (goal G807 — done): peeling a complementary pair off a balanced character,
  every m. If c is balanced of degree m, contains x with 0 < x < m and (after removing x) contains m − x, then
    pair_peel   c with x and m − x removed is balanced,
  since ⟨tx⟩ + ⟨t(m − x)⟩ = m for every unit t (PairsSplit.pair_mod). So a balanced character that contains a
  complementary pair splits as {x, m − x} ⊔ (balanced rest) — the reduction step behind every pair decomposition.
    all_filter_imp   an implication between two predicates, valid on the filtered elements, lifts to List.all

  Lean 4 core plus hodge/PairsSplit.
-/
import hodge.PairsSplit

namespace PairPeel
open Indecomp PairsSplit

theorem all_filter_imp (pr P Q : Nat → Bool) (h : ∀ t, pr t = true → P t = true → Q t = true) :
    ∀ l : List Nat, (l.filter pr).all P = true → (l.filter pr).all Q = true
  | [], _ => rfl
  | x :: l, hl => by
    cases hx : pr x with
    | false =>
      have e : (x :: l).filter pr = l.filter pr := by show (match pr x with | true => x :: l.filter pr | false => l.filter pr) = _; rw [hx]
      rw [e] at hl ⊢
      exact all_filter_imp pr P Q h l hl
    | true =>
      have e : (x :: l).filter pr = x :: l.filter pr := by show (match pr x with | true => x :: l.filter pr | false => l.filter pr) = _; rw [hx]
      rw [e] at hl ⊢
      have hl' : (P x && (l.filter pr).all P) = true := hl
      show (Q x && (l.filter pr).all Q) = true
      rw [h x hx (andL hl'), all_filter_imp pr P Q h l (andR hl')]
      rfl

theorem pair_peel (m' x : Nat) (c : List Nat) (hb : bal (m' + 1) c = true) (hx0 : 0 < x) (hxm : x < m' + 1)
    (h1 : c.contains x = true) (h2 : (c.erase x).contains (m' + 1 - x) = true) :
    bal (m' + 1) ((c.erase x).erase (m' + 1 - x)) = true := by
  have hb' : ((List.range (m' + 1)).filter (fun t => Nat.beq (Nat.gcd t (m' + 1)) 1)).all
      (fun t => Nat.beq (tsum (m' + 1) t c + tsum (m' + 1) t c) (c.length * (m' + 1))) = true := hb
  show ((List.range (m' + 1)).filter (fun t => Nat.beq (Nat.gcd t (m' + 1)) 1)).all
    (fun t => Nat.beq (tsum (m' + 1) t ((c.erase x).erase (m' + 1 - x)) + tsum (m' + 1) t ((c.erase x).erase (m' + 1 - x)))
      (((c.erase x).erase (m' + 1 - x)).length * (m' + 1))) = true
  refine all_filter_imp _ _ _ ?_ _ hb'
  intro t ht hP
  have hg : Nat.gcd t (m' + 1) = 1 := Nat.eq_of_beq_eq_true ht
  have hc : tsum (m' + 1) t c + tsum (m' + 1) t c = c.length * (m' + 1) := Nat.eq_of_beq_eq_true hP
  have pm := pair_mod m' t x hg hx0 hxm
  rw [tsum_erase (m' + 1) t x c h1, tsum_erase (m' + 1) t (m' + 1 - x) (c.erase x) h2,
    ← len_erase x c h1, ← len_erase (m' + 1 - x) (c.erase x) h2] at hc
  show Nat.beq (tsum (m' + 1) t ((c.erase x).erase (m' + 1 - x)) + tsum (m' + 1) t ((c.erase x).erase (m' + 1 - x)))
    (((c.erase x).erase (m' + 1 - x)).length * (m' + 1)) = true
  generalize tsum (m' + 1) t ((c.erase x).erase (m' + 1 - x)) = R at hc ⊢
  generalize ((c.erase x).erase (m' + 1 - x)).length = L at hc ⊢
  generalize (t * x) % (m' + 1) = A at pm hc
  generalize (t * (m' + 1 - x)) % (m' + 1) = B at pm hc
  have e1 : A + (B + R) + (A + (B + R)) = ((m' + 1) + (m' + 1)) + (R + R) := by
    rw [show A + (B + R) + (A + (B + R)) = (A + B) + (A + B) + (R + R) by lib_nat, pm]
  have e2 : (L + 1 + 1) * (m' + 1) = ((m' + 1) + (m' + 1)) + L * (m' + 1) := by lib_nat
  rw [e1, e2] at hc
  rw [BalAppend.add_cancel _ _ _ hc]
  exact FamBal.beq_refl' _

end PairPeel

#print axioms PairPeel.all_filter_imp
#print axioms PairPeel.pair_peel

#print axioms: 2 theorems, no axioms.

81.193 Balanced length-2 characters are complementary pairs

For \(0<a,b<m\), \(m\ge 2\): \([a,b]\) balanced implies \(a+b=m\) (the unit \(t=1\)), every degree.

hodge/Len2Pair.lean

/-
  hodge/Len2Pair.lean — T41 cycle 1369 (goal G808 — done): balanced length-2 characters are complementary pairs,
  every degree m ≥ 2. If 0 < a, b < m and [a, b] is balanced, then
    len2_pair   a + b = m
  (the unit t = 1: 2(⟨a⟩ + ⟨b⟩) = 2m). With PairsSplit.bal_of_pairs the converse holds, so the length-2 classification
  is complete for every m; with PairPeel this is the base of the pair peeling.

  Lean 4 core plus hodge/FamIndec3 (bal_unit), hodge/APPairIrrGen (gcd_one), hodge/ModHand (mod_lt'),
  hodge/BalAppend (add_cancel).
-/
import hodge.FamIndec3
import hodge.APPairIrrGen
import hodge.ModHand
import hodge.BalAppend

namespace Len2Pair
open Indecomp

theorem double_cancel : ∀ x y : Nat, x + x = y + y → x = y
  | 0, 0, _ => rfl
  | 0, y + 1, h => by
    have h' : 0 = (y + y + 1) + 1 := by rw [show y + 1 + (y + 1) = (y + y + 1) + 1 by lib_nat] at h; exact h
    exact Nat.noConfusion h'
  | x + 1, 0, h => by
    have h' : (x + x + 1) + 1 = 0 := by rw [show x + 1 + (x + 1) = (x + x + 1) + 1 by lib_nat] at h; exact h
    exact Nat.noConfusion h'
  | x + 1, y + 1, h => by
    have h' : (x + x) + 2 = (y + y) + 2 := by
      rw [show x + 1 + (x + 1) = (x + x) + 2 by lib_nat, show y + 1 + (y + 1) = (y + y) + 2 by lib_nat] at h; exact h
    have := double_cancel x y (Nat.succ.inj (Nat.succ.inj h'))
    rw [this]

theorem len2_pair (m a b : Nat) (hm : 1 < m) (ha : a < m) (hb : b < m) (hbal : bal m [a, b] = true) : a + b = m := by
  have hu := FamIndec3.bal_unit m 1 [a, b] hbal hm (APPairIrrGen.gcd_one m)
  have e : tsum m 1 [a, b] = a + b := by
    show (1 * a) % m + ((1 * b) % m + 0) = a + b
    rw [Nat.one_mul, Nat.one_mul, ModHand.mod_lt' a m ha, ModHand.mod_lt' b m hb, Nat.add_zero]
  rw [e] at hu
  have hu' : (a + b) + (a + b) = m + m := by rw [hu]; show (0 + 1 + 1) * m = m + m; lib_nat
  exact double_cancel _ _ hu'

end Len2Pair

#print axioms Len2Pair.double_cancel
#print axioms Len2Pair.len2_pair

#print axioms: 2 theorems, no axioms.

81.194 No balanced characters of odd length in odd degree

For odd \(m\ge 3\) and \(|c|\) odd, \(c\) is not balanced: at \(t=1\) the equation \(2\,\mathrm {tsum}=|c|m\) equates an even and an odd number.

hodge/OddUnbal.lean

/-
  hodge/OddUnbal.lean — T41 cycle 1371 (goal G809 — done): no balanced character of odd length in odd degree.
  For odd m ≥ 3 and any list c of odd length,
    odd_unbal   bal m c = false,
  since at the unit t = 1 the balance equation 2·tsum = |c|·m equates an even and an odd number. Geometrically: the
  odd-dimensional Fermat varieties of odd degree carry no Hodge classes in the middle (odd) degree from these
  characters; together with Len2Pair, PairPeel and the Pairs certificates this leaves only even lengths.

  Lean 4 core plus hodge/FamIndec3 (bal_unit), hodge/APPairIrrGen (gcd_one), bsd/TorsionImage (odd_ne_even).
-/
import hodge.FamIndec3
import hodge.APPairIrrGen
import bsd.TorsionImage

namespace OddUnbal
open Indecomp

theorem odd_unbal (k j : Nat) (c : List Nat) (hc : c.length = 2 * k + 1) : bal (2 * j + 3) c = false := by
  cases e : bal (2 * j + 3) c with
  | false => rfl
  | true =>
    have hu := FamIndec3.bal_unit (2 * j + 3) 1 c e (by show 2 ≤ 2 * j + 3; exact Nat.le_add_left 2 (2 * j + 1)) (APPairIrrGen.gcd_one _)
    rw [hc] at hu
    have h1 : (2 * k + 1) * (2 * j + 3) = 2 * (k * (2 * j + 3) + j + 1) + 1 := by lib_nat
    have h2 : tsum (2 * j + 3) 1 c + tsum (2 * j + 3) 1 c = 2 * tsum (2 * j + 3) 1 c := by lib_nat
    rw [h1, h2] at hu
    exact absurd hu.symm (TorsionImage.odd_ne_even _ _)

end OddUnbal

#print axioms OddUnbal.odd_unbal

#print axioms: 1 theorem, no axioms.

81.195 Length 4: one complementary pair forces two

A balanced length-4 character with entries in \((0,m)\) that contains one complementary pair is two complementary pairs, every \(m\ge 2\).

hodge/Len4OnePair.lean

/-
  hodge/Len4OnePair.lean — T41 cycle 1373 (goal G810 — done): a balanced length-4 character containing one
  complementary pair is two complementary pairs, every m ≥ 2. If |c| = 4, the entries lie in (0, m), c is balanced,
  contains x and (after removing x) m − x, then
    len4_one_pair   the remaining two entries u, v satisfy u + v = m
  (PairPeel.pair_peel, then Len2Pair.len2_pair). So for length 4 the whole question "two pairs?" is whether one
  complementary pair occurs.

  Lean 4 core plus hodge/PairPeel, hodge/Len2Pair.
-/
import hodge.PairPeel
import hodge.Len2Pair

namespace Len4OnePair
open Indecomp PairsSplit

theorem len4_one_pair (m' x : Nat) (c : List Nat) (hm : 1 < m' + 1) (hlen : c.length = 4)
    (hr : c.all (inR (m' + 1)) = true) (hb : bal (m' + 1) c = true) (hx0 : 0 < x) (hxm : x < m' + 1)
    (h1 : c.contains x = true) (h2 : (c.erase x).contains (m' + 1 - x) = true) :
    ∃ u v, (c.erase x).erase (m' + 1 - x) = [u, v] ∧ u + v = m' + 1 := by
  have hp := PairPeel.pair_peel m' x c hb hx0 hxm h1 h2
  have l1 := len_erase x c h1
  have l2 := len_erase (m' + 1 - x) (c.erase x) h2
  have hrr := all_erase _ (m' + 1 - x) _ (all_erase _ x c hr)
  generalize (c.erase x).erase (m' + 1 - x) = r at hp l2 hrr ⊢
  have l1' : (c.erase x).length + 1 = 3 + 1 := by rw [l1, hlen]
  rw [Nat.succ.inj l1'] at l2
  have e2 : r.length = 2 := Nat.succ.inj l2
  cases r with
  | nil => exact Nat.noConfusion e2
  | cons u r2 =>
    cases r2 with
    | nil => exact Nat.noConfusion (Nat.succ.inj e2)
    | cons v r3 =>
      cases r3 with
      | cons w r4 => exact Nat.noConfusion (Nat.succ.inj (Nat.succ.inj e2))
      | nil =>
        have hu : (inR (m' + 1) u && (inR (m' + 1) v && true)) = true := hrr
        have hum : u < m' + 1 := Nat.le_of_ble_eq_true (andR (andL hu))
        have hvm : v < m' + 1 := Nat.le_of_ble_eq_true (andR (andL (andR hu)))
        exact ⟨u, v, rfl, Len2Pair.len2_pair (m' + 1) u v hm hum hvm hp⟩

end Len4OnePair

#print axioms Len4OnePair.len4_one_pair

#print axioms: 1 theorem, no axioms.

81.196 Length 6: two complementary pairs force three

A balanced length-6 character with entries in \((0,m)\) containing two disjoint complementary pairs is three pairs, every \(m\ge 2\).

hodge/Len6TwoPairs.lean

/-
  hodge/Len6TwoPairs.lean — T41 cycle 1375 (goal G811 — done): a balanced length-6 character containing two
  complementary pairs is three complementary pairs, every m ≥ 2. If |c| = 6, entries in (0, m), c balanced, c
  contains x and m − x, and the rest contains y and m − y, then
    len6_two_pairs   the last two entries u, v satisfy u + v = m
  (PairPeel.pair_peel on the first pair, then Len4OnePair on the balanced length-4 rest). For G529b (length 6) the
  open part is: every balanced length-6 character of prime degree contains two disjoint complementary pairs.

  Lean 4 core plus hodge/Len4OnePair.
-/
import hodge.Len4OnePair

namespace Len6TwoPairs
open Indecomp PairsSplit

theorem len6_two_pairs (m' x y : Nat) (c : List Nat) (hm : 1 < m' + 1) (hlen : c.length = 6)
    (hr : c.all (inR (m' + 1)) = true) (hb : bal (m' + 1) c = true) (hx0 : 0 < x) (hxm : x < m' + 1)
    (h1 : c.contains x = true) (h2 : (c.erase x).contains (m' + 1 - x) = true)
    (hy0 : 0 < y) (hym : y < m' + 1)
    (h3 : ((c.erase x).erase (m' + 1 - x)).contains y = true)
    (h4 : (((c.erase x).erase (m' + 1 - x)).erase y).contains (m' + 1 - y) = true) :
    ∃ u v, (((c.erase x).erase (m' + 1 - x)).erase y).erase (m' + 1 - y) = [u, v] ∧ u + v = m' + 1 := by
  have hp := PairPeel.pair_peel m' x c hb hx0 hxm h1 h2
  have l1 := len_erase x c h1
  have l2 := len_erase (m' + 1 - x) (c.erase x) h2
  have hrr := all_erase _ (m' + 1 - x) _ (all_erase _ x c hr)
  have l1' : (c.erase x).length + 1 = 5 + 1 := by rw [l1, hlen]
  rw [Nat.succ.inj l1'] at l2
  have e4 : ((c.erase x).erase (m' + 1 - x)).length = 4 := Nat.succ.inj l2
  exact Len4OnePair.len4_one_pair m' y _ hm e4 hrr hp hy0 hym h3 h4

end Len6TwoPairs

#print axioms Len6TwoPairs.len6_two_pairs

#print axioms: 1 theorem, no axioms.

81.197 The Galois twist preserves complementary pairs

For a unit \(t\) and \(0<x<m\): \(0<\langle tx\rangle \) and \(\langle t(m-x)\rangle =m-\langle tx\rangle \), every \(m\).

hodge/PairTwist.lean

/-
  hodge/PairTwist.lean — T41 cycle 1381 (goal G814 — done): the Galois twist preserves complementary pairs, every m.
  For gcd(t, m) = 1 and 0 < x < m:
    twist_pos    0 < ⟨tx⟩_m
    twist_pair   ⟨t(m − x)⟩_m = m − ⟨tx⟩_m
  so t maps the pair {x, m − x} to the pair {⟨tx⟩, m − ⟨tx⟩} with both entries in (0, m): whether a character is a
  union of complementary pairs depends only on its Galois orbit (one representative per orbit suffices for the
  three-pairs certificates).

  Lean 4 core plus hodge/PairsSplit (pair_mod).
-/
import hodge.PairsSplit

namespace PairTwist
open PairsSplit

theorem twist_pos (m' t x : Nat) (hg : Nat.gcd t (m' + 1) = 1) (hx0 : 0 < x) (hxm : x < m' + 1) :
    0 < (t * x) % (m' + 1) := by
  have pm := pair_mod m' t x hg hx0 hxm
  have hb : (t * (m' + 1 - x)) % (m' + 1) < m' + 1 := by
    rw [← ESChain.rem_eq_mod]; exact QRChain.rem_lt' m' _
  cases e : (t * x) % (m' + 1) with
  | succ k => exact Nat.succ_pos k
  | zero =>
    rw [e, Nat.zero_add] at pm
    rw [pm] at hb
    exact absurd hb (Nat.lt_irrefl _)

theorem twist_pair (m' t x : Nat) (hg : Nat.gcd t (m' + 1) = 1) (hx0 : 0 < x) (hxm : x < m' + 1) :
    (t * (m' + 1 - x)) % (m' + 1) = m' + 1 - (t * x) % (m' + 1) := by
  have pm := pair_mod m' t x hg hx0 hxm
  generalize (t * x) % (m' + 1) = A at pm ⊢
  generalize (t * (m' + 1 - x)) % (m' + 1) = B at pm ⊢
  rw [← pm, Nat.add_comm A B, ModHand.add_sub' B A]

end PairTwist

#print axioms PairTwist.twist_pos
#print axioms PairTwist.twist_pair

#print axioms: 2 theorems, no axioms.

81.198 In odd degree, half of the entries lie above \(m/2\)

For odd \(m\ge 3\) and \(c\) balanced with entries in \((0,m)\): \(2\cdot \#\{a\in c:2a\ge m\}=|c|\) (units \(t=1\) and \(t=2\)).

hodge/HalfBig.lean

/-
  hodge/HalfBig.lean — T41 cycle 1385 (goal G817 — done): in odd degree, a balanced character has exactly half of
  its entries above m/2. For m = 2j + 3 and c balanced with entries in (0, m),
    gcd_two        gcd(2, m) = 1 (2 is a unit)
    dbl_mod        ⟨2a⟩ + m·[2a ≥ m] = 2a for 0 < a < m
    tsum_one       ⟨1·a⟩ summed is Σa for entries in (0, m)
    half_big       2·#{a ∈ c : 2a ≥ m} = |c|,
  comparing the balance equations at the units t = 1 and t = 2. A necessary condition on every Hodge character of
  odd degree (and the count of entries above m/2 is |c|/2, as for complementary pairs).

  Lean 4 core plus hodge/PairsSplit (inR, andL/andR), hodge/FamIndec2 (gcd_one_of), hodge/FamIndec3 (bal_unit),
  hodge/APPairIrrGen (gcd_one), hodge/ModHand, hodge/GcdHand, bsd/TorsionImage (odd_ne_even).
-/
import hodge.PairsSplit
import hodge.FamIndec2
import hodge.FamIndec3
import hodge.APPairIrrGen
import bsd.TorsionImage

namespace HalfBig
open Indecomp PairsSplit

def big (m : Nat) : List Nat → Nat
  | [] => 0
  | a :: l => (if Nat.ble m (2 * a) = true then 1 else 0) + big m l

theorem gcd_two (j : Nat) : Nat.gcd 2 (2 * j + 3) = 1 := by
  apply FamIndec2.gcd_one_of
  intro d h2 hm
  cases h2 with
  | intro k hk =>
    match d, k, hk with
    | 0, k, hk => rw [Nat.zero_mul] at hk; exact Nat.noConfusion hk
    | 1, _, _ => rfl
    | 2, _, _ =>
      cases hm with
      | intro q hq =>
        exact absurd (show 2 * (j + 1) + 1 = 2 * q by rw [← hq]; lib_nat) (TorsionImage.odd_ne_even _ _)
    | d + 3, 0, hk => rw [Nat.mul_zero] at hk; exact Nat.noConfusion hk
    | d + 3, k + 1, hk =>
      have e : (d + 3) * (k + 1) = ((d + 3) * k + d) + 1 + 1 + 1 := by lib_nat
      rw [e] at hk
      exact Nat.noConfusion (Nat.succ.inj (Nat.succ.inj hk))

theorem dbl_mod (m a : Nat) (ha0 : 0 < a) (ham : a < m) :
    (2 * a) % m + m * (if Nat.ble m (2 * a) = true then 1 else 0) = 2 * a := by
  have hm : 0 < m := Nat.lt_trans ha0 ham
  cases h : Nat.ble m (2 * a) with
  | true =>
    have hle : m ≤ 2 * a := Nat.le_of_ble_eq_true h
    have e := GcdHand.sub_add' m (2 * a) hle
    have hs : 2 * a - m < m := by
      have l2 : 2 * a < m + m := by rw [show 2 * a = a + a by lib_nat]; exact Nat.add_lt_add ham ham
      rw [← e] at l2
      exact Nat.lt_of_add_lt_add_right l2
    show (2 * a) % m + m * 1 = 2 * a
    rw [← e, ModHand.add_mod' _ _ hm, ModHand.mod_lt' _ _ hs, Nat.mul_one]
  | false =>
    have hlt : 2 * a < m := by
      cases Nat.lt_or_ge (2 * a) m with
      | inl hl => exact hl
      | inr hg => rw [Nat.ble_eq_true_of_le hg] at h; exact Bool.noConfusion h
    show (2 * a) % m + m * 0 = 2 * a
    rw [ModHand.mod_lt' _ _ hlt, Nat.mul_zero, Nat.add_zero]

theorem sum_rel (m : Nat) : ∀ c : List Nat, c.all (inR m) = true →
    tsum m 2 c + m * big m c = 2 * tsum m 1 c
  | [], _ => rfl
  | a :: l, h => by
    have h' : (inR m a && l.all (inR m)) = true := h
    have ha0 : 0 < a := Nat.le_of_ble_eq_true (andL (andL h'))
    have ham : a < m := Nat.le_of_ble_eq_true (andR (andL h'))
    have ih := sum_rel m l (andR h')
    have dm := dbl_mod m a ha0 ham
    have one : (1 * a) % m = a := by rw [Nat.one_mul]; exact ModHand.mod_lt' _ _ ham
    show (2 * a) % m + tsum m 2 l + m * ((if Nat.ble m (2 * a) = true then 1 else 0) + big m l)
      = 2 * ((1 * a) % m + tsum m 1 l)
    rw [one]
    generalize (if Nat.ble m (2 * a) = true then 1 else 0) = I at dm ⊢
    generalize (2 * a) % m = D at dm ⊢
    rw [show D + tsum m 2 l + m * (I + big m l) = (D + m * I) + (tsum m 2 l + m * big m l) by lib_nat, dm, ih]
    lib_nat

theorem half_big (j : Nat) (c : List Nat) (hr : c.all (inR (2 * j + 3)) = true) (hb : bal (2 * j + 3) c = true) :
    2 * big (2 * j + 3) c = c.length := by
  have h3 : 2 < 2 * j + 3 := Nat.le_add_left 3 (2 * j)
  have u1 := FamIndec3.bal_unit (2 * j + 3) 1 c hb (Nat.lt_trans (Nat.lt_succ_self 1) h3) (APPairIrrGen.gcd_one _)
  have u2 := FamIndec3.bal_unit (2 * j + 3) 2 c hb h3 (gcd_two j)
  have sr := sum_rel (2 * j + 3) c hr
  generalize tsum (2 * j + 3) 1 c = T1 at u1 sr
  generalize tsum (2 * j + 3) 2 c = T2 at u2 sr
  generalize big (2 * j + 3) c = B at sr ⊢
  generalize c.length = L at u1 u2 ⊢
  generalize 2 * j + 3 = m at u1 u2 sr h3 ⊢
  -- (T2 + T2) + 2mB = 4T1 = 2Lm,  T2 + T2 = Lm  ⇒  2mB = Lm
  have e : (T2 + T2) + (2 * B) * m = (T2 + T2) + L * m := by
    calc (T2 + T2) + (2 * B) * m = 2 * (T2 + m * B) := by lib_nat
      _ = 2 * (2 * T1) := by rw [sr]
      _ = (T1 + T1) + (T1 + T1) := by lib_nat
      _ = L * m + L * m := by rw [u1]
      _ = (T2 + T2) + L * m := by rw [u2]
  have e2 := BalAppend.add_cancel _ _ _ e
  exact Nat.eq_of_mul_eq_mul_right (Nat.lt_trans (Nat.zero_lt_succ 1) h3) e2

end HalfBig

#print axioms HalfBig.gcd_two
#print axioms HalfBig.dbl_mod
#print axioms HalfBig.sum_rel
#print axioms HalfBig.half_big

#print axioms: 4 theorems, no axioms.

81.199 The half-above-\(m/2\) law for every Galois twist

For odd \(m\), a unit \(t\) and \(c\) balanced with entries in \((0,m)\): the twist \(t\cdot c\) is balanced with entries in \((0,m)\), and \(2\cdot \#\{i:2\langle tc_i\rangle \ge m\}=|c|\) for every unit \(t\).

hodge/TwistHalf.lean

/-
  hodge/TwistHalf.lean — T41 cycle 1387 (goal G818 — done): the half-above-m/2 law for every Galois twist, odd
  degree. For m = 2j + 3, a unit t and c balanced with entries in (0, m):
    mul_red      ⟨⟨u⟩·x⟩ = ⟨u·x⟩
    tsum_red     T_{⟨u⟩}(c) = T_u(c);   tsum_tw   T_s(t·c) = T_{st}(c)
    twist_bal    t·c = (⟨t c_i⟩)_i is balanced (UnitMul.unit_mul, bal_unit)
    twist_inR    its entries lie in (0, m) (PairTwist.twist_pos)
    twist_half   2·#{i : 2⟨t c_i⟩ ≥ m} = |c|   for every unit t,
  the classical form of the Hodge condition (for every t, exactly half of the ⟨t a_i⟩ lie in the upper half), here
  derived from the balance equations (HalfBig applied to t·c).

  Lean 4 core plus hodge/HalfBig, hodge/PairTwist, hodge/GaloisOrbit (twist, mul_mod), hodge/UnitMul (unit_mul),
  hodge/Pullback (len_map).
-/
import hodge.HalfBig
import hodge.PairTwist
import hodge.GaloisOrbit
import hodge.UnitMul
import hodge.Pullback

namespace TwistHalf
open Indecomp PairsSplit HalfBig

theorem mul_red (m' u x : Nat) : ((u % (m' + 1)) * x) % (m' + 1) = (u * x) % (m' + 1) := by
  have h := GaloisOrbit.mul_mod m' x u 1
  rw [Nat.mul_one, Nat.mul_one] at h
  rw [Nat.mul_comm (u % (m' + 1)) x, h, Nat.mul_comm x u]

theorem tsum_red (m' u : Nat) : ∀ c : List Nat, tsum (m' + 1) (u % (m' + 1)) c = tsum (m' + 1) u c
  | [] => rfl
  | x :: c => by
    show ((u % (m' + 1)) * x) % (m' + 1) + tsum (m' + 1) (u % (m' + 1)) c = (u * x) % (m' + 1) + tsum (m' + 1) u c
    rw [mul_red, tsum_red m' u c]

theorem tsum_tw (m' s t : Nat) : ∀ c : List Nat,
    tsum (m' + 1) s (GaloisOrbit.twist (m' + 1) t c) = tsum (m' + 1) (s * t) c
  | [] => rfl
  | x :: c => by
    show (s * ((t * x) % (m' + 1))) % (m' + 1) + tsum (m' + 1) s (GaloisOrbit.twist (m' + 1) t c)
      = ((s * t) * x) % (m' + 1) + tsum (m' + 1) (s * t) c
    rw [GaloisOrbit.mul_mod, tsum_tw m' s t c]

theorem twist_bal (m' t : Nat) (c : List Nat) (ht : Nat.gcd t (m' + 1) = 1) (hb : bal (m' + 1) c = true) :
    bal (m' + 1) (GaloisOrbit.twist (m' + 1) t c) = true := by
  show ((List.range (m' + 1)).filter (fun s => Nat.beq (Nat.gcd s (m' + 1)) 1)).all
    (fun s => Nat.beq (tsum (m' + 1) s (GaloisOrbit.twist (m' + 1) t c) + tsum (m' + 1) s (GaloisOrbit.twist (m' + 1) t c))
      ((GaloisOrbit.twist (m' + 1) t c).length * (m' + 1))) = true
  apply FamBal.all_filter
  intro s hs
  have hs' : Nat.gcd s (m' + 1) = 1 := Nat.eq_of_beq_eq_true hs
  have hu := UnitMul.unit_mul s t (m' + 1) (Nat.succ_pos m') hs' ht
  have hlt : (s * t) % (m' + 1) < m' + 1 := by rw [← ESChain.rem_eq_mod]; exact QRChain.rem_lt' m' _
  have b := FamIndec3.bal_unit (m' + 1) ((s * t) % (m' + 1)) c hb hlt hu
  rw [tsum_red] at b
  show Nat.beq (tsum (m' + 1) s (GaloisOrbit.twist (m' + 1) t c) + tsum (m' + 1) s (GaloisOrbit.twist (m' + 1) t c))
    ((c.map (fun x => (t * x) % (m' + 1))).length * (m' + 1)) = true
  rw [tsum_tw, Pullback.len_map, b]
  exact FamBal.beq_refl' _

theorem twist_inR (m' t : Nat) (ht : Nat.gcd t (m' + 1) = 1) : ∀ c : List Nat, c.all (inR (m' + 1)) = true →
    (GaloisOrbit.twist (m' + 1) t c).all (inR (m' + 1)) = true
  | [], _ => rfl
  | x :: c, h => by
    have h' : (inR (m' + 1) x && c.all (inR (m' + 1))) = true := h
    have hx0 : 0 < x := Nat.le_of_ble_eq_true (andL (andL h'))
    have hxm : x < m' + 1 := Nat.le_of_ble_eq_true (andR (andL h'))
    have p0 := PairTwist.twist_pos m' t x ht hx0 hxm
    have pl : (t * x) % (m' + 1) < m' + 1 := by rw [← ESChain.rem_eq_mod]; exact QRChain.rem_lt' m' _
    show (inR (m' + 1) ((t * x) % (m' + 1)) && (GaloisOrbit.twist (m' + 1) t c).all (inR (m' + 1))) = true
    rw [twist_inR m' t ht c (andR h')]
    show ((Nat.blt 0 ((t * x) % (m' + 1)) && Nat.blt ((t * x) % (m' + 1)) (m' + 1)) && true) = true
    have e1 : Nat.blt 0 ((t * x) % (m' + 1)) = true := Nat.ble_eq_true_of_le p0
    have e2 : Nat.blt ((t * x) % (m' + 1)) (m' + 1) = true := Nat.ble_eq_true_of_le pl
    rw [e1, e2]
    rfl

theorem twist_half (j t : Nat) (c : List Nat) (ht : Nat.gcd t (2 * j + 3) = 1)
    (hr : c.all (inR (2 * j + 3)) = true) (hb : bal (2 * j + 3) c = true) :
    2 * big (2 * j + 3) (GaloisOrbit.twist (2 * j + 3) t c) = c.length := by
  have h := half_big j (GaloisOrbit.twist (2 * j + 3) t c) (twist_inR (2 * j + 2) t ht c hr) (twist_bal (2 * j + 2) t c ht hb)
  rw [h]
  exact Pullback.len_map _ c

end TwistHalf

#print axioms TwistHalf.mul_red
#print axioms TwistHalf.tsum_red
#print axioms TwistHalf.tsum_tw
#print axioms TwistHalf.twist_bal
#print axioms TwistHalf.twist_inR
#print axioms TwistHalf.twist_half

#print axioms: 6 theorems, no axioms.

81.200 A union of complementary pairs has even length

allPairs \(m\,f\,l\) implies \(|l|\) even.

hodge/PairsEven.lean

/-
  hodge/PairsEven.lean — T41 cycle 1389 (goal G819 — done): a union of complementary pairs has even length.
    pairs_even   allPairs m f l = true ⇒ |l| = 2k for some k
  (remove the first pair: len_erase twice). With OddUnbal (no balanced odd-length characters in odd degree) this is
  the length bookkeeping of the pair decompositions.

  Lean 4 core plus hodge/PairsSplit (allPairs, len_erase, andL/andR).
-/
import hodge.PairsSplit

namespace PairsEven
open PairsSplit

theorem pairs_even (m : Nat) : ∀ (f : Nat) (l : List Nat), allPairs m f l = true → ∃ k, l.length = 2 * k
  | 0, _, h => Bool.noConfusion h
  | _ + 1, [], _ => ⟨0, rfl⟩
  | f + 1, x :: l, h => by
    have h' : (l.contains (m - x) && allPairs m f (l.erase (m - x))) = true := h
    have ⟨k, hk⟩ := pairs_even m f (l.erase (m - x)) (andR h')
    have le := len_erase (m - x) l (andL h')
    refine ⟨k + 1, ?_⟩
    show l.length + 1 = 2 * (k + 1)
    rw [← le, hk]
    lib_nat

end PairsEven

#print axioms PairsEven.pairs_even

#print axioms: 1 theorem, no axioms.

81.201 A union of complementary pairs is half above \(m/2\)

For odd \(m\), allPairs \(m\,f\,c\) gives \(2\cdot \#\{a : 2a \ge m\} = |c|\), also after every Galois twist.

hodge/PairsHalf.lean

/-
  hodge/PairsHalf.lean — T41 cycle 1428 (goal G822 — done): a union of complementary pairs in odd degree has exactly
  half of its entries above m/2, for the identity and every Galois twist. For m = 2j + 3 and entries in (0, m):
    pairs_half        allPairs m f c ⇒ 2·#{a ∈ c : 2a ≥ m} = |c|
    pairs_twist_half  allPairs m f c, gcd(t, m) = 1 ⇒ 2·#{a ∈ t·c : 2a ≥ m} = |c|
  (pairs give balance by PairsSplit.bal_of_pairs; then HalfBig.half_big and TwistHalf.twist_half).

  Lean 4 core plus hodge/PairsSplit, hodge/HalfBig, hodge/TwistHalf.
-/
import hodge.PairsSplit
import hodge.HalfBig
import hodge.TwistHalf

namespace PairsHalf
open PairsSplit HalfBig

theorem pairs_half (j f : Nat) (c : List Nat) (hr : c.all (inR (2 * j + 3)) = true)
    (hp : allPairs (2 * j + 3) f c = true) : 2 * big (2 * j + 3) c = c.length :=
  half_big j c hr (bal_of_pairs (2 * j + 2) f c hr hp)

theorem pairs_twist_half (j f t : Nat) (c : List Nat) (ht : Nat.gcd t (2 * j + 3) = 1)
    (hr : c.all (inR (2 * j + 3)) = true) (hp : allPairs (2 * j + 3) f c = true) :
    2 * big (2 * j + 3) (GaloisOrbit.twist (2 * j + 3) t c) = c.length :=
  TwistHalf.twist_half j t c ht hr (bal_of_pairs (2 * j + 2) f c hr hp)

end PairsHalf

#print axioms PairsHalf.pairs_half
#print axioms PairsHalf.pairs_twist_half

#print axioms: 2 theorems, no axioms.

81.202 Each complementary pair has one entry above \(m/2\)

For \(m = 2j+3\) and \(x < m\), exactly one of \(x\), \(m - x\) satisfies \(2a \ge m\) (no balance hypothesis).

hodge/PairBig.lean

/-
  hodge/PairBig.lean — T41 cycle 1430 (goal G823 — done): in odd degree each complementary pair has exactly one
  entry above m/2, with no balance hypothesis. For m = 2j + 3 and x < m:
    cancel_le  a + k ≤ b + k ⇒ a ≤ b (hand proof; the core lemma uses propext)
    pair_big   #{a ∈ [x, m − x] : 2a ≥ m} = 1
  (2x = m is impossible by parity, so 2x ≥ m forces 2(m − x) < m and 2x < m forces 2(m − x) > m).
  The elementary reason behind PairsHalf.pairs_half.

  Lean 4 core plus hodge/HalfBig (big), hodge/GcdHand (sub_add'), bsd/TorsionImage (odd_ne_even).
-/
import hodge.HalfBig

namespace PairBig
open HalfBig

theorem cancel_le (a b : Nat) : ∀ k : Nat, a + k ≤ b + k → a ≤ b
  | 0, h => h
  | k + 1, h => cancel_le a b k (Nat.le_of_succ_le_succ h)

theorem pair_big (j x : Nat) (hxm : x < 2 * j + 3) :
    big (2 * j + 3) [x, 2 * j + 3 - x] = 1 := by
  have e := GcdHand.sub_add' x (2 * j + 3) (Nat.le_of_lt hxm)
  generalize 2 * j + 3 - x = y at e ⊢
  -- 2y + 2x = m + m
  have s : 2 * y + 2 * x = (2 * j + 3) + (2 * j + 3) := by rw [← e]; lib_nat
  cases h : Nat.ble (2 * j + 3) (2 * x) with
  | true =>
    have hle : 2 * j + 3 ≤ 2 * x := Nat.le_of_ble_eq_true h
    have hlt : 2 * j + 3 < 2 * x := by
      cases Nat.lt_or_ge (2 * j + 3) (2 * x) with
      | inl l => exact l
      | inr g =>
        have eq : 2 * x = 2 * (j + 1) + 1 := Nat.le_antisymm g (by rw [show 2 * (j + 1) + 1 = 2 * j + 3 by lib_nat]; exact hle)
        exact absurd eq.symm (TorsionImage.odd_ne_even _ _)
    have h2 : 2 * y + (2 * j + 3 + 1) ≤ 2 * y + 2 * x := Nat.add_le_add_left hlt _
    rw [s, show 2 * y + (2 * j + 3 + 1) = (2 * y + 1) + (2 * j + 3) by lib_nat] at h2
    have h3 : 2 * y + 1 ≤ 2 * j + 3 := cancel_le _ _ _ h2
    have hf : Nat.ble (2 * j + 3) (2 * y) = false := by
      cases hb : Nat.ble (2 * j + 3) (2 * y) with
      | false => rfl
      | true => exact absurd (Nat.lt_of_lt_of_le h3 (Nat.le_of_ble_eq_true hb)) (Nat.lt_irrefl _)
    show (if Nat.ble (2 * j + 3) (2 * x) = true then 1 else 0) + ((if Nat.ble (2 * j + 3) (2 * y) = true then 1 else 0) + 0) = 1
    rw [h, hf]
    rfl
  | false =>
    have hlt : 2 * x < 2 * j + 3 := by
      cases Nat.lt_or_ge (2 * x) (2 * j + 3) with
      | inl l => exact l
      | inr g => rw [Nat.ble_eq_true_of_le g] at h; exact Bool.noConfusion h
    have h2 : 2 * y + (2 * x + 1) ≤ 2 * y + (2 * j + 3) := Nat.add_le_add_left hlt _
    rw [show 2 * y + (2 * x + 1) = (2 * y + 2 * x) + 1 by lib_nat, s,
      show (2 * j + 3) + (2 * j + 3) + 1 = (2 * j + 3 + 1) + (2 * j + 3) by lib_nat,
      show 2 * y + (2 * j + 3) = 2 * y + (2 * j + 3) by rfl] at h2
    have h3 : 2 * j + 3 + 1 ≤ 2 * y := cancel_le _ _ _ h2
    have ht : Nat.ble (2 * j + 3) (2 * y) = true := Nat.ble_eq_true_of_le (Nat.le_of_lt h3)
    show (if Nat.ble (2 * j + 3) (2 * x) = true then 1 else 0) + ((if Nat.ble (2 * j + 3) (2 * y) = true then 1 else 0) + 0) = 1
    rw [h, ht]
    rfl

end PairBig

#print axioms PairBig.cancel_le
#print axioms PairBig.pair_big

#print axioms: 2 theorems, no axioms.

81.203 Complementing swaps the entries above and below \(m/2\)

For \(m = 2j+3\) and entries \(< m\), \(\#\mathrm {big}(m - c) + \#\mathrm {big}(c) = |c|\).

hodge/ComplBig.lean

/-
  hodge/ComplBig.lean — T41 cycle 1432 (goal G824 — done): complementing a character in odd degree swaps the
  entries above and below m/2. For m = 2j + 3 and entries < m:
    big_append   #big(l₁ ++ l₂) = #big(l₁) + #big(l₂)
    compl_big    #big(m − c) + #big(c) = |c|
  (each x contributes one to exactly one side by PairBig.pair_big). With HalfBig.half_big this says that the complement
  m − c of a balanced character is again half above m/2.

  Lean 4 core plus hodge/PairBig.
-/
import hodge.PairBig

namespace ComplBig
open HalfBig

theorem big_append (m : Nat) : ∀ l₁ l₂ : List Nat, big m (l₁ ++ l₂) = big m l₁ + big m l₂
  | [], l₂ => (Nat.zero_add _).symm
  | a :: l₁, l₂ => by
    show (if Nat.ble m (2 * a) = true then 1 else 0) + big m (l₁ ++ l₂)
      = ((if Nat.ble m (2 * a) = true then 1 else 0) + big m l₁) + big m l₂
    rw [big_append m l₁ l₂, Nat.add_assoc]

def allLt (m : Nat) : List Nat → Prop
  | [] => True
  | x :: l => x < m ∧ allLt m l

theorem compl_big (j : Nat) : ∀ c : List Nat, allLt (2 * j + 3) c →
    big (2 * j + 3) (c.map (fun x => 2 * j + 3 - x)) + big (2 * j + 3) c = c.length
  | [], _ => rfl
  | x :: c, ⟨hx, hc⟩ => by
    have p := PairBig.pair_big j x hx
    have ih := compl_big j c hc
    show ((if Nat.ble (2 * j + 3) (2 * (2 * j + 3 - x)) = true then 1 else 0)
        + big (2 * j + 3) (c.map (fun x => 2 * j + 3 - x)))
      + ((if Nat.ble (2 * j + 3) (2 * x) = true then 1 else 0) + big (2 * j + 3) c) = c.length + 1
    have p' : (if Nat.ble (2 * j + 3) (2 * x) = true then 1 else 0)
        + ((if Nat.ble (2 * j + 3) (2 * (2 * j + 3 - x)) = true then 1 else 0) + 0) = 1 := p
    generalize (if Nat.ble (2 * j + 3) (2 * x) = true then 1 else 0) = A at p' ⊢
    generalize (if Nat.ble (2 * j + 3) (2 * (2 * j + 3 - x)) = true then 1 else 0) = B at p' ⊢
    generalize big (2 * j + 3) (c.map (fun x => 2 * j + 3 - x)) = M at ih ⊢
    generalize big (2 * j + 3) c = C at ih ⊢
    rw [show B + M + (A + C) = (M + C) + (A + (B + 0)) by lib_nat, ih, p']

end ComplBig

#print axioms ComplBig.big_append
#print axioms ComplBig.compl_big

#print axioms: 2 theorems, no axioms.

81.204 Complex conjugation preserves balance

For entries in \((0, m)\), \(c\) balanced implies \(m - c\) balanced, via \(T_t(m - c) + T_t(c) = |c|\,m\) for every unit \(t\).

hodge/ComplBal.lean

/-
  hodge/ComplBal.lean — T41 cycle 1434 (goal G825 — done): complex conjugation preserves balance. For m = m' + 1,
  a unit t and entries in (0, m):
    tsum_compl    T_t(m − c) + T_t(c) = |c|·m          (PairsSplit.pair_mod entrywise)
    filter_all_imp  (filter pr l).all P ⇒ (filter pr l).all Q  when pr t ∧ P t ⇒ Q t
    compl_bal     c balanced ⇒ m − c = (m − c_i)_i balanced
  (T + T_c = T_c + T_c gives T = T_c). The conjugate of a Hodge character is a Hodge character.

  Lean 4 core plus hodge/PairsSplit, hodge/BalAppend (add_cancel), hodge/Pullback (len_map).
-/
import hodge.PairsSplit
import hodge.BalAppend
import hodge.Pullback

namespace ComplBal
open Indecomp PairsSplit

theorem tsum_compl (m' t : Nat) (hg : Nat.gcd t (m' + 1) = 1) : ∀ c : List Nat, c.all (inR (m' + 1)) = true →
    tsum (m' + 1) t (c.map (fun x => m' + 1 - x)) + tsum (m' + 1) t c = c.length * (m' + 1)
  | [], _ => by show 0 + 0 = 0 * (m' + 1); rw [Nat.zero_mul]
  | x :: c, hr => by
    have hr' : (inR (m' + 1) x && c.all (inR (m' + 1))) = true := hr
    have hx0 : 0 < x := Nat.le_of_ble_eq_true (andL (andL hr'))
    have hxm : x < m' + 1 := Nat.le_of_ble_eq_true (andR (andL hr'))
    have pm := pair_mod m' t x hg hx0 hxm
    have ih := tsum_compl m' t hg c (andR hr')
    show ((t * (m' + 1 - x)) % (m' + 1) + tsum (m' + 1) t (c.map (fun x => m' + 1 - x)))
      + ((t * x) % (m' + 1) + tsum (m' + 1) t c) = (c.length + 1) * (m' + 1)
    generalize (t * x) % (m' + 1) = A at pm ⊢
    generalize (t * (m' + 1 - x)) % (m' + 1) = B at pm ⊢
    generalize tsum (m' + 1) t (c.map (fun x => m' + 1 - x)) = M at ih ⊢
    generalize tsum (m' + 1) t c = C at ih ⊢
    rw [show B + M + (A + C) = (M + C) + (A + B) by lib_nat, ih, pm]
    lib_nat

theorem filter_all_imp (pr P Q : Nat → Bool) (h : ∀ t, pr t = true → P t = true → Q t = true) :
    ∀ l : List Nat, (l.filter pr).all P = true → (l.filter pr).all Q = true
  | [], _ => rfl
  | x :: l, hl => by
    cases hx : pr x with
    | false =>
      have e : (x :: l).filter pr = l.filter pr := by
        show (match pr x with | true => x :: l.filter pr | false => l.filter pr) = _; rw [hx]
      rw [e] at hl ⊢
      exact filter_all_imp pr P Q h l hl
    | true =>
      have e : (x :: l).filter pr = x :: l.filter pr := by
        show (match pr x with | true => x :: l.filter pr | false => l.filter pr) = _; rw [hx]
      rw [e] at hl ⊢
      have hl' : (P x && (l.filter pr).all P) = true := hl
      show (Q x && (l.filter pr).all Q) = true
      rw [h x hx (andL hl'), filter_all_imp pr P Q h l (andR hl')]
      rfl

theorem compl_bal (m' : Nat) (c : List Nat) (hr : c.all (inR (m' + 1)) = true) (hb : bal (m' + 1) c = true) :
    bal (m' + 1) (c.map (fun x => m' + 1 - x)) = true := by
  have hb' : ((List.range (m' + 1)).filter (fun t => Nat.beq (Nat.gcd t (m' + 1)) 1)).all
      (fun t => Nat.beq (tsum (m' + 1) t c + tsum (m' + 1) t c) (c.length * (m' + 1))) = true := hb
  show ((List.range (m' + 1)).filter (fun t => Nat.beq (Nat.gcd t (m' + 1)) 1)).all
    (fun t => Nat.beq (tsum (m' + 1) t (c.map (fun x => m' + 1 - x)) + tsum (m' + 1) t (c.map (fun x => m' + 1 - x)))
      ((c.map (fun x => m' + 1 - x)).length * (m' + 1))) = true
  refine filter_all_imp _ _ _ ?_ _ hb'
  intro t ht hP
  have hg : Nat.gcd t (m' + 1) = 1 := Nat.eq_of_beq_eq_true ht
  have hc : tsum (m' + 1) t c + tsum (m' + 1) t c = c.length * (m' + 1) := Nat.eq_of_beq_eq_true hP
  have tc := tsum_compl m' t hg c hr
  rw [Pullback.len_map]
  generalize tsum (m' + 1) t (c.map (fun x => m' + 1 - x)) = M at tc ⊢
  generalize tsum (m' + 1) t c = C at tc hc
  have e : C + M = C + C := by rw [Nat.add_comm C M, tc, hc]
  have e2 := BalAppend.add_cancel _ _ _ e
  rw [e2, hc]
  exact FamBal.beq_refl' _

end ComplBal

#print axioms ComplBal.tsum_compl
#print axioms ComplBal.filter_all_imp
#print axioms ComplBal.compl_bal

#print axioms: 3 theorems, no axioms.

81.205 Complex conjugation is an involution on Hodge characters

For entries in \((0, m)\), \(x \mapsto m - x\) keeps entries in \((0, m)\), is its own inverse, and maps balanced characters to balanced characters.

hodge/ComplInv.lean

/-
  hodge/ComplInv.lean — T41 cycle 1436 (goal G826 — done): complex conjugation is an involution on Hodge-type data.
  For m = m' + 1:
    sub_sub      x ≤ m ⇒ m − (m − x) = x
    compl_inR    entries in (0, m) stay in (0, m) under x ↦ m − x
    compl_compl  m − (m − c) = c for entries in (0, m)
    compl_hodge  c in (0, m) and balanced ⇒ m − c in (0, m) and balanced
  so conjugation permutes the Hodge characters of degree m and is its own inverse.

  Lean 4 core plus hodge/ComplBal, hodge/GcdHand (sub_add'), hodge/ModHand (add_sub').
-/
import hodge.ComplBal

namespace ComplInv
open Indecomp PairsSplit

theorem sub_sub (m x : Nat) (h : x ≤ m) : m - (m - x) = x := by
  have e := GcdHand.sub_add' x m h
  generalize m - x = y at e ⊢
  rw [← e, Nat.add_comm y x, ModHand.add_sub']

theorem compl_inR (m' : Nat) : ∀ c : List Nat, c.all (inR (m' + 1)) = true →
    (c.map (fun x => m' + 1 - x)).all (inR (m' + 1)) = true
  | [], _ => rfl
  | x :: c, hr => by
    have hr' : (inR (m' + 1) x && c.all (inR (m' + 1))) = true := hr
    have hx0 : 0 < x := Nat.le_of_ble_eq_true (andL (andL hr'))
    have hxm : x < m' + 1 := Nat.le_of_ble_eq_true (andR (andL hr'))
    have e := GcdHand.sub_add' x (m' + 1) (Nat.le_of_lt hxm)
    have p0 : 0 < m' + 1 - x := by
      cases ey : m' + 1 - x with
      | succ k => exact Nat.succ_pos k
      | zero =>
        rw [ey, Nat.zero_add] at e
        rw [e] at hxm
        exact absurd hxm (Nat.lt_irrefl _)
    have pl : m' + 1 - x < m' + 1 := by
      have l := Nat.add_lt_add_left hx0 (m' + 1 - x)
      rw [Nat.add_zero, e] at l
      exact l
    show (inR (m' + 1) (m' + 1 - x) && (c.map (fun x => m' + 1 - x)).all (inR (m' + 1))) = true
    rw [compl_inR m' c (andR hr')]
    show ((Nat.blt 0 (m' + 1 - x) && Nat.blt (m' + 1 - x) (m' + 1)) && true) = true
    have e1 : Nat.blt 0 (m' + 1 - x) = true := Nat.ble_eq_true_of_le p0
    have e2 : Nat.blt (m' + 1 - x) (m' + 1) = true := Nat.ble_eq_true_of_le pl
    rw [e1, e2]
    rfl

theorem compl_compl (m' : Nat) : ∀ c : List Nat, c.all (inR (m' + 1)) = true →
    (c.map (fun x => m' + 1 - x)).map (fun x => m' + 1 - x) = c
  | [], _ => rfl
  | x :: c, hr => by
    have hr' : (inR (m' + 1) x && c.all (inR (m' + 1))) = true := hr
    have hxm : x < m' + 1 := Nat.le_of_ble_eq_true (andR (andL hr'))
    show (m' + 1 - (m' + 1 - x)) :: (c.map (fun x => m' + 1 - x)).map (fun x => m' + 1 - x) = x :: c
    rw [sub_sub _ _ (Nat.le_of_lt hxm), compl_compl m' c (andR hr')]

theorem compl_hodge (m' : Nat) (c : List Nat) (hr : c.all (inR (m' + 1)) = true) (hb : bal (m' + 1) c = true) :
    (c.map (fun x => m' + 1 - x)).all (inR (m' + 1)) = true ∧ bal (m' + 1) (c.map (fun x => m' + 1 - x)) = true :=
  ⟨compl_inR m' c hr, ComplBal.compl_bal m' c hr hb⟩

end ComplInv

#print axioms ComplInv.sub_sub
#print axioms ComplInv.compl_inR
#print axioms ComplInv.compl_compl
#print axioms ComplInv.compl_hodge

#print axioms: 4 theorems, no axioms.

81.206 Complex conjugation commutes with the Galois action

For a unit \(t\) and entries in \((0, m)\), \(t\cdot (m - c) = m - t\cdot c\).

hodge/TwistCompl.lean

/-
  hodge/TwistCompl.lean — T41 cycle 1438 (goal G827 — done): complex conjugation commutes with the Galois action.
  For m = m' + 1, a unit t and entries in (0, m):
    twist_compl   t·(m − c) = m − t·c
  (PairTwist.twist_pair entrywise). So conjugation acts on Galois orbits of Hodge characters, and t ↦ −t is the
  same as conjugation on each orbit.

  Lean 4 core plus hodge/PairTwist, hodge/GaloisOrbit (twist).
-/
import hodge.PairTwist
import hodge.GaloisOrbit

namespace TwistCompl
open PairsSplit

theorem twist_compl (m' t : Nat) (hg : Nat.gcd t (m' + 1) = 1) : ∀ c : List Nat, c.all (inR (m' + 1)) = true →
    GaloisOrbit.twist (m' + 1) t (c.map (fun x => m' + 1 - x))
      = (GaloisOrbit.twist (m' + 1) t c).map (fun x => m' + 1 - x)
  | [], _ => rfl
  | x :: c, hr => by
    have hr' : (inR (m' + 1) x && c.all (inR (m' + 1))) = true := hr
    have hx0 : 0 < x := Nat.le_of_ble_eq_true (andL (andL hr'))
    have hxm : x < m' + 1 := Nat.le_of_ble_eq_true (andR (andL hr'))
    have ih := twist_compl m' t hg c (andR hr')
    show (t * (m' + 1 - x)) % (m' + 1) :: GaloisOrbit.twist (m' + 1) t (c.map (fun x => m' + 1 - x))
      = (m' + 1 - (t * x) % (m' + 1)) :: (GaloisOrbit.twist (m' + 1) t c).map (fun x => m' + 1 - x)
    rw [PairTwist.twist_pair m' t x hg hx0 hxm, ih]

end TwistCompl

#print axioms TwistCompl.twist_compl

#print axioms: 1 theorem, no axioms.

81.207 Complex conjugation is the twist by \(-1\)

For \(0 < x < m\), \(\langle (m-1)x\rangle _m = m - x\), so twisting by \(m - 1\) is \(c \mapsto m - c\).

hodge/ConjTwist.lean

/-
  hodge/ConjTwist.lean — T41 cycle 1440 (goal G828 — done): complex conjugation is the Galois twist by −1.
  For m = m' + 1 and 0 < x < m:
    neg_one_mul   ⟨(m − 1)·x⟩_m = m − x
    conj_twist    twist by m − 1 = (m − c_i)_i  for entries in (0, m)
  so the conjugation lemmas (ComplBal, ComplInv, TwistCompl) are the t = −1 case of the Galois action.

  Lean 4 core plus hodge/ModHand (add_mul_mod', mod_lt'), hodge/GcdHand (sub_add'), hodge/PairsSplit (inR),
  hodge/GaloisOrbit (twist).
-/
import hodge.PairsSplit
import hodge.GaloisOrbit

namespace ConjTwist
open PairsSplit

theorem neg_one_mul (m' x : Nat) (hx0 : 0 < x) (hxm : x < m' + 1) : (m' * x) % (m' + 1) = m' + 1 - x := by
  cases x with
  | zero => exact absurd hx0 (Nat.lt_irrefl 0)
  | succ k =>
    have hk : k ≤ m' := Nat.le_of_succ_le_succ (Nat.le_of_lt hxm)
    rw [Nat.succ_sub_succ]
    have e := GcdHand.sub_add' k m' hk
    generalize m' - k = r at e ⊢
    rw [← e]
    have h1 : (r + k) * (k + 1) = r + k * (r + k + 1) := by lib_nat
    rw [h1, ModHand.add_mul_mod' r (r + k + 1) (Nat.succ_pos _) k]
    exact ModHand.mod_lt' r (r + k + 1) (Nat.lt_succ_of_le (Nat.le_add_right r k))

theorem conj_twist (m' : Nat) : ∀ c : List Nat, c.all (inR (m' + 1)) = true →
    GaloisOrbit.twist (m' + 1) m' c = c.map (fun x => m' + 1 - x)
  | [], _ => rfl
  | x :: c, hr => by
    have hr' : (inR (m' + 1) x && c.all (inR (m' + 1))) = true := hr
    have hx0 : 0 < x := Nat.le_of_ble_eq_true (andL (andL hr'))
    have hxm : x < m' + 1 := Nat.le_of_ble_eq_true (andR (andL hr'))
    show (m' * x) % (m' + 1) :: GaloisOrbit.twist (m' + 1) m' c = (m' + 1 - x) :: c.map (fun x => m' + 1 - x)
    rw [neg_one_mul m' x hx0 hxm, conj_twist m' c (andR hr')]

end ConjTwist

#print axioms ConjTwist.neg_one_mul
#print axioms ConjTwist.conj_twist

#print axioms: 2 theorems, no axioms.

81.208 The Galois twist is a monoid action

Twisting by \(1\) fixes \(c\), twisting by \(s\) after \(t\) is twisting by \(st\), and twisting by \(m - 1\) twice is the identity.

hodge/TwistAct.lean

/-
  hodge/TwistAct.lean — T41 cycle 1442 (goal G829 — done): the Galois twist is a monoid action on characters.
  For m = m' + 1:
    twist_one    twist by 1 fixes c (entries < m)
    twist_comp   twist s (twist t c) = twist (s·t) c
    sq_mod       ⟨(m − 1)²·x⟩ = ⟨x⟩
    conj_conj    twist (m − 1) twice fixes c (entries < m) — conjugation squared is the identity
  (GaloisOrbit.mul_mod for the composition law; ⟨(m−1)²⟩ = 1).

  Lean 4 core plus hodge/GaloisOrbit, hodge/ModHand (mod_lt', add_mul_mod').
-/
import hodge.GaloisOrbit
import hodge.ModHand

namespace TwistAct

def allLt (m : Nat) : List Nat → Prop
  | [] => True
  | x :: l => x < m ∧ allLt m l

theorem twist_one (m' : Nat) : ∀ c : List Nat, allLt (m' + 1) c → GaloisOrbit.twist (m' + 1) 1 c = c
  | [], _ => rfl
  | x :: c, ⟨hx, hc⟩ => by
    show (1 * x) % (m' + 1) :: GaloisOrbit.twist (m' + 1) 1 c = x :: c
    rw [Nat.one_mul, ModHand.mod_lt' x (m' + 1) hx, twist_one m' c hc]

theorem twist_comp (m' s t : Nat) : ∀ c : List Nat,
    GaloisOrbit.twist (m' + 1) s (GaloisOrbit.twist (m' + 1) t c) = GaloisOrbit.twist (m' + 1) (s * t) c
  | [] => rfl
  | x :: c => by
    show (s * ((t * x) % (m' + 1))) % (m' + 1) :: GaloisOrbit.twist (m' + 1) s (GaloisOrbit.twist (m' + 1) t c)
      = ((s * t) * x) % (m' + 1) :: GaloisOrbit.twist (m' + 1) (s * t) c
    rw [GaloisOrbit.mul_mod, twist_comp m' s t c]

theorem sq_mod (m' x : Nat) : ((m' * m') * x) % (m' + 1) = x % (m' + 1) := by
  cases m' with
  | zero =>
    have a : (0 + (0 * 0 * x) * (0 + 1)) % (0 + 1) = 0 % (0 + 1) := ModHand.add_mul_mod' 0 (0 + 1) (Nat.succ_pos 0) _
    have b : (0 + x * (0 + 1)) % (0 + 1) = 0 % (0 + 1) := ModHand.add_mul_mod' 0 (0 + 1) (Nat.succ_pos 0) x
    rw [Nat.zero_add, Nat.mul_one] at a b
    rw [a, b]
  | succ n =>
    have e : (n + 1) * (n + 1) * x = x + (n * x) * (n + 1 + 1) := by lib_nat
    rw [e, ModHand.add_mul_mod' x (n + 1 + 1) (Nat.succ_pos _)]

theorem conj_conj (m' : Nat) : ∀ c : List Nat, allLt (m' + 1) c →
    GaloisOrbit.twist (m' + 1) m' (GaloisOrbit.twist (m' + 1) m' c) = c := by
  intro c hc
  rw [twist_comp]
  induction c with
  | nil => rfl
  | cons x c ih =>
    show ((m' * m') * x) % (m' + 1) :: GaloisOrbit.twist (m' + 1) (m' * m') c = x :: c
    rw [sq_mod, ModHand.mod_lt' x (m' + 1) hc.1, ih hc.2]

end TwistAct

#print axioms TwistAct.twist_one
#print axioms TwistAct.twist_comp
#print axioms TwistAct.sq_mod
#print axioms TwistAct.conj_conj

#print axioms: 4 theorems, no axioms.

81.209 Complementary pairs are a property of the Galois orbit

For \(m \ge 2\) and a unit \(t\), a union of complementary pairs with entries in \((0, m)\) stays one after twisting by \(t\).

hodge/TwistPairs.lean

/-
  hodge/TwistPairs.lean — T41 cycle 1446 (goal G832 — done): being a union of complementary pairs is a property of
  the Galois orbit. For m = m' + 2, a unit t and entries in (0, m):
    twist_inj      ⟨tx⟩ = ⟨ty⟩, x, y < m ⇒ x = y   (UnitInv.inverse)
    contains_map   f injective on P ⇒ (map f l).contains (f a) = l.contains a
    erase_map      f injective on P ⇒ (map f l).erase (f a) = map f (l.erase a)
    twist_pairs    allPairs m k c ⇒ allPairs m k (t·c)
  (the partner m − ⟨tx⟩ of ⟨tx⟩ is ⟨t(m − x)⟩ by PairTwist.twist_pair). So a three-pairs certificate for one
  representative covers the whole Galois orbit.

  Lean 4 core plus hodge/UnitInv, hodge/PairTwist, hodge/TwistHalf (mul_red), hodge/ComplInv (compl_inR),
  hodge/GaloisOrbit (twist, mul_mod).
-/
import hodge.UnitInv
import hodge.PairTwist
import hodge.TwistHalf
import hodge.ComplInv

namespace TwistPairs
open PairsSplit

theorem twist_inj (m' t x y : Nat) (hg : Nat.gcd t (m' + 1 + 1) = 1) (hx : x < m' + 1 + 1) (hy : y < m' + 1 + 1)
    (h : (t * x) % (m' + 1 + 1) = (t * y) % (m' + 1 + 1)) : x = y := by
  have ⟨v, hv⟩ := UnitInv.inverse t m' hg
  have a := GaloisOrbit.mul_mod (m' + 1) v t x
  have b := GaloisOrbit.mul_mod (m' + 1) v t y
  rw [h, b, ← TwistHalf.mul_red (m' + 1) (v * t) x, ← TwistHalf.mul_red (m' + 1) (v * t) y, hv,
    Nat.one_mul, Nat.one_mul, ModHand.mod_lt' x _ hx, ModHand.mod_lt' y _ hy] at a
  exact a.symm

theorem contains_map (P : Nat → Bool) (f : Nat → Nat) (hinj : ∀ a b, P a = true → P b = true → f a = f b → a = b)
    (a : Nat) (ha : P a = true) : ∀ l : List Nat, l.all P = true → (l.map f).contains (f a) = l.contains a
  | [], _ => rfl
  | b :: l, hl => by
    have hl' : (P b && l.all P) = true := hl
    show (match f a == f b with | true => true | false => (l.map f).contains (f a))
      = (match a == b with | true => true | false => l.contains a)
    cases hab : (a == b) with
    | true =>
      have e : a = b := Nat.eq_of_beq_eq_true hab
      rw [e, show (f b == f b) = true from FamBal.beq_refl' (f b)]
    | false =>
      have hf : (f a == f b) = false := by
        cases e : (f a == f b) with
        | false => rfl
        | true =>
          have eab := hinj a b ha (andL hl') (Nat.eq_of_beq_eq_true e)
          rw [eab, show (b == b) = true from FamBal.beq_refl' b] at hab
          exact Bool.noConfusion hab
      rw [hf]
      exact contains_map P f hinj a ha l (andR hl')

theorem erase_map (P : Nat → Bool) (f : Nat → Nat) (hinj : ∀ a b, P a = true → P b = true → f a = f b → a = b)
    (a : Nat) (ha : P a = true) : ∀ l : List Nat, l.all P = true → (l.map f).erase (f a) = (l.erase a).map f
  | [], _ => rfl
  | b :: l, hl => by
    have hl' : (P b && l.all P) = true := hl
    cases hab : (a == b) with
    | true =>
      have e : a = b := Nat.eq_of_beq_eq_true hab
      rw [← e]
      show (f a :: l.map f).erase (f a) = ((a :: l).erase a).map f
      rw [erase_head, erase_head]
    | false =>
      have hf : (f a == f b) = false := by
        cases e : (f a == f b) with
        | false => rfl
        | true =>
          have eab := hinj a b ha (andL hl') (Nat.eq_of_beq_eq_true e)
          rw [eab, show (b == b) = true from FamBal.beq_refl' b] at hab
          exact Bool.noConfusion hab
      show (f b :: l.map f).erase (f a) = ((b :: l).erase a).map f
      rw [erase_tail (f a) (f b) _ hf, erase_tail a b l hab]
      show f b :: (l.map f).erase (f a) = f b :: (l.erase a).map f
      rw [erase_map P f hinj a ha l (andR hl')]

theorem twist_pairs (m' t : Nat) (hg : Nat.gcd t (m' + 1 + 1) = 1) : ∀ (k : Nat) (c : List Nat),
    c.all (inR (m' + 1 + 1)) = true → allPairs (m' + 1 + 1) k c = true →
    allPairs (m' + 1 + 1) k (GaloisOrbit.twist (m' + 1 + 1) t c) = true
  | 0, _, _, h => Bool.noConfusion h
  | _ + 1, [], _, _ => rfl
  | k + 1, x :: l, hr, h => by
    have h' : (l.contains (m' + 1 + 1 - x) && allPairs (m' + 1 + 1) k (l.erase (m' + 1 + 1 - x))) = true := h
    have hr' : (inR (m' + 1 + 1) x && l.all (inR (m' + 1 + 1))) = true := hr
    have hx0 : 0 < x := Nat.le_of_ble_eq_true (andL (andL hr'))
    have hxm : x < m' + 1 + 1 := Nat.le_of_ble_eq_true (andR (andL hr'))
    have hy : inR (m' + 1 + 1) (m' + 1 + 1 - x) = true := by
      have c1 := ComplInv.compl_inR (m' + 1) [x] (by show (inR (m' + 1 + 1) x && true) = true; rw [andL hr']; rfl)
      have c2 : (inR (m' + 1 + 1) (m' + 1 + 1 - x) && true) = true := c1
      exact andL c2
    have hinj : ∀ a b, inR (m' + 1 + 1) a = true → inR (m' + 1 + 1) b = true →
        (t * a) % (m' + 1 + 1) = (t * b) % (m' + 1 + 1) → a = b :=
      fun a b ha hb e => twist_inj m' t a b hg (Nat.le_of_ble_eq_true (andR ha)) (Nat.le_of_ble_eq_true (andR hb)) e
    have tp := PairTwist.twist_pair (m' + 1) t x hg hx0 hxm
    show ((GaloisOrbit.twist (m' + 1 + 1) t l).contains (m' + 1 + 1 - (t * x) % (m' + 1 + 1))
      && allPairs (m' + 1 + 1) k ((GaloisOrbit.twist (m' + 1 + 1) t l).erase (m' + 1 + 1 - (t * x) % (m' + 1 + 1)))) = true
    rw [← tp]
    show ((l.map (fun x => (t * x) % (m' + 1 + 1))).contains ((t * (m' + 1 + 1 - x)) % (m' + 1 + 1))
      && allPairs (m' + 1 + 1) k ((l.map (fun x => (t * x) % (m' + 1 + 1))).erase ((t * (m' + 1 + 1 - x)) % (m' + 1 + 1)))) = true
    rw [contains_map _ (fun x => (t * x) % (m' + 1 + 1)) hinj _ hy l (andR hr'),
      erase_map _ (fun x => (t * x) % (m' + 1 + 1)) hinj _ hy l (andR hr'), andL h']
    exact twist_pairs m' t hg k (l.erase (m' + 1 + 1 - x)) (all_erase _ _ l (andR hr')) (andR h')

end TwistPairs

#print axioms TwistPairs.twist_inj
#print axioms TwistPairs.contains_map
#print axioms TwistPairs.erase_map
#print axioms TwistPairs.twist_pairs

#print axioms: 4 theorems, no axioms.

81.210 Pair decomposability is constant on Galois orbits

For \(m \ge 2\), a unit \(t\) and entries in \((0, m)\), allPairs \(m\,k\,(t\cdot c) = \) allPairs \(m\,k\,c\).

hodge/PairsOrbit.lean

/-
  hodge/PairsOrbit.lean — T41 cycle 1448 (goal G833 — done): "union of complementary pairs" is constant on Galois
  orbits. For m = m' + 2, a unit t and entries in (0, m):
    inR_lt       entries in (0, m) are < m
    pairs_orbit  allPairs m k (t·c) = allPairs m k c
  (forward: TwistPairs.twist_pairs; backward: twist by the inverse v of t, TwistIndec.inv_unit / untwist).
  So badP is a union of Galois orbits and one representative per orbit decides it.

  Lean 4 core plus hodge/TwistPairs, hodge/TwistIndec (inv_unit, untwist), hodge/TwistHalf (twist_inR).
-/
import hodge.TwistPairs
import hodge.TwistIndec

namespace PairsOrbit
open PairsSplit

theorem inR_lt (m : Nat) : ∀ c : List Nat, c.all (inR m) = true → c.all (fun x => Nat.blt x m) = true
  | [], _ => rfl
  | x :: c, h => by
    have h' : (inR m x && c.all (inR m)) = true := h
    show (Nat.blt x m && c.all (fun x => Nat.blt x m)) = true
    rw [andR (andL h'), inR_lt m c (andR h')]
    rfl

theorem pairs_orbit (m' t k : Nat) (c : List Nat) (hg : Nat.gcd t (m' + 1 + 1) = 1) (hr : c.all (inR (m' + 1 + 1)) = true) :
    allPairs (m' + 1 + 1) k (GaloisOrbit.twist (m' + 1 + 1) t c) = allPairs (m' + 1 + 1) k c := by
  cases h : allPairs (m' + 1 + 1) k c with
  | true => exact TwistPairs.twist_pairs m' t hg k c hr h
  | false =>
    cases h2 : allPairs (m' + 1 + 1) k (GaloisOrbit.twist (m' + 1 + 1) t c) with
    | false => rfl
    | true =>
      have ⟨v, hv⟩ := UnitInv.inverse t m' hg
      have hvu := TwistIndec.inv_unit v t _ (Nat.succ_pos _) hv
      have hr2 := TwistHalf.twist_inR (m' + 1) t hg c hr
      have b := TwistPairs.twist_pairs m' v hvu k _ hr2 h2
      have u := TwistIndec.untwist (m' + 1 + 1) t v (Nat.succ_pos _) hv c (inR_lt _ c hr)
      have u' : GaloisOrbit.twist (m' + 1 + 1) v (GaloisOrbit.twist (m' + 1 + 1) t c) = c := u
      rw [u', h] at b
      exact Bool.noConfusion b

end PairsOrbit

#print axioms PairsOrbit.inR_lt
#print axioms PairsOrbit.pairs_orbit

#print axioms: 2 theorems, no axioms.

81.211 Complex conjugation preserves pair decomposability

For \(m \ge 2\) and entries in \((0, m)\), \(\gcd (m-1, m) = 1\) and allPairs \(m\,k\,(m - c) = \) allPairs \(m\,k\,c\).

hodge/PairsConj.lean

/-
  hodge/PairsConj.lean — T41 cycle 1450 (goal G834 — done): complex conjugation preserves pair decomposability.
  For m = m' + 2 and entries in (0, m):
    gcd_pred     gcd(m − 1, m) = 1
    pairs_conj   allPairs m k (m − c) = allPairs m k c
  (m − c is the twist by m − 1 by ConjTwist.conj_twist, then PairsOrbit.pairs_orbit).

  Lean 4 core plus hodge/PairsOrbit, hodge/ConjTwist, hodge/FamIndec2 (gcd_one_of), hodge/UnitMul (one_of_dvd_one),
  hodge/BalAppend (add_cancel).
-/
import hodge.PairsOrbit
import hodge.ConjTwist

namespace PairsConj
open PairsSplit

theorem gcd_pred (m' : Nat) : Nat.gcd (m' + 1) (m' + 1 + 1) = 1 := by
  apply FamIndec2.gcd_one_of
  intro d ⟨a, ha⟩ ⟨b, hb⟩
  cases Nat.lt_or_ge a b with
  | inl hab =>
    have ⟨c, hc⟩ := Nat.le.dest hab
    rw [← hc, show d * (a + 1 + c) = d * a + d * (1 + c) by rw [show a + 1 + c = a + (1 + c) by lib_nat, Nat.mul_add],
      ← ha] at hb
    exact UnitMul.one_of_dvd_one d (1 + c) (BalAppend.add_cancel _ _ _ hb)
  | inr hba =>
    have l : d * b ≤ d * a := Nat.mul_le_mul_left d hba
    rw [← ha, ← hb] at l
    exact absurd l (Nat.not_succ_le_self _)

theorem pairs_conj (m' k : Nat) (c : List Nat) (hr : c.all (inR (m' + 1 + 1)) = true) :
    allPairs (m' + 1 + 1) k (c.map (fun x => m' + 1 + 1 - x)) = allPairs (m' + 1 + 1) k c := by
  rw [← ConjTwist.conj_twist (m' + 1) c hr]
  exact PairsOrbit.pairs_orbit m' (m' + 1) k c (gcd_pred m') hr

end PairsConj

#print axioms PairsConj.gcd_pred
#print axioms PairsConj.pairs_conj

#print axioms: 2 theorems, no axioms.

81.212 Splitting the length-4 pair check by the first entry

The list of bad length-4 characters is the concatenation of the pieces with fixed first entry \(x\), \(1 \le x < m\).

hodge/Pairs4Split.lean

/-
  hodge/Pairs4Split.lean — T41 cycle 1510 (goal G838): splitting the length-4 pair check by the first entry.
  quads m is the concatenation over the first entry x of x :: l (l ∈ triples m, head l ≥ x), so
    badQ_split   badQ m = flatten [badQAt m x | 1 ≤ x < m]
  and Pairs4.badQ m = [] follows from the pieces badQAt m x = [], each a smaller rfl (the single rfl for p = 67, 71
  ran out of memory at 64G on Kamiak).

  Lean 4 core plus hodge/Pairs4 (badQ), hodge/Pairs6Split (headGe, filter_flat_map).
-/
import hodge.Pairs4
import hodge.Pairs6Split

namespace Pairs4Split
open Indecomp Len3Class Len4Class Pairs6Small

def badQAt (m x : Nat) : List (List Nat) :=
  (((triples m).filter (Pairs6Split.headGe x)).map (fun l => x :: l)).filter (fun c => bal m c && !allPairs m 5 c)

theorem badQ_split (m : Nat) :
    Pairs4.badQ m = (((List.range m).filter (fun x => Nat.ble 1 x)).map (badQAt m)).flatten :=
  Pairs6Split.filter_flat_map _ _ _

theorem q7 : Pairs4.badQ 7 = [] := by
  rw [badQ_split]
  show badQAt 7 1 ++ (badQAt 7 2 ++ (badQAt 7 3 ++ (badQAt 7 4 ++ (badQAt 7 5 ++ (badQAt 7 6 ++ []))))) = []
  rfl

end Pairs4Split

#print axioms Pairs4Split.badQ_split
#print axioms Pairs4Split.q7

#print axioms: 2 theorems, no axioms.

81.213 Bridge between the two pair-check lists

The two copies of the bad-sextuple list agree for every \(m\), proved without evaluating either list.

hodge/PairsSplitBridge.lean

/-
  hodge/PairsSplitBridge.lean — T41 cycle 1552 (goal G526d): PairsSplit.badP m = Pairs6Split.badP m without
  evaluation (the two allPairs copies agree pointwise by induction; filters with pointwise equal predicates agree).
  With Pairs6Bridge.badP_eq this moves the three-pairs certificates Pairs6.p17 … Pairs6c.p29 to PairsSplit.badP; the
  direct definitional check in PairsSplitInst hit the recursion limit on Kamiak.

  Lean 4 core plus hodge/PairsSplit, hodge/Pairs6Split.
-/
import hodge.PairsSplit
import hodge.Pairs6Split

namespace PairsSplitBridge

theorem allPairs_eq (m : Nat) : ∀ (f : Nat) (l : List Nat), PairsSplit.allPairs m f l = Pairs6Split.allPairs m f l
  | 0, _ => rfl
  | _ + 1, [] => rfl
  | f + 1, x :: l => by
    show (l.contains (m - x) && PairsSplit.allPairs m f (l.erase (m - x)))
      = (l.contains (m - x) && Pairs6Split.allPairs m f (l.erase (m - x)))
    rw [allPairs_eq m f (l.erase (m - x))]

theorem filter_congr' {α : Type} (p q : α → Bool) (h : ∀ x, p x = q x) : ∀ (l : List α), l.filter p = l.filter q
  | [] => rfl
  | x :: l => by
    rw [Pairs6Split.filter_cons2, Pairs6Split.filter_cons2, h x, filter_congr' p q h l]

theorem badP_eq (m : Nat) : PairsSplit.badP m = Pairs6Split.badP m :=
  filter_congr' _ _ (fun c => by
    show (Indecomp.bal m c && !PairsSplit.allPairs m 7 c) = (Indecomp.bal m c && !Pairs6Split.allPairs m 7 c)
    rw [allPairs_eq]) _

end PairsSplitBridge

#print axioms PairsSplitBridge.allPairs_eq
#print axioms PairsSplitBridge.filter_congr'
#print axioms PairsSplitBridge.badP_eq

#print axioms: 3 theorems, no axioms.

81.214 The 2 + 4 split for \(p = 17, 19, 23, 29\) (Kamiak)

Every balanced length-6 character with entries in \((0, p)\) contains a complementary pair whose removal leaves a balanced length-4 character.

hodge/PairsSplitInst.lean

/-
  hodge/PairsSplitInst.lean — T41 cycle 1365 (goal G526b, finite path, Kamiak): the 2 + 4 split for the odd primes
  p = 17, 19, 23, 29, from the three-pairs certificates (Pairs6.p17, p19, Pairs6b.p23, Pairs6c.p29) through
  PairsSplit.split24_of_pairs: every balanced length-6 character c ∈ sexts p with entries in (0, p) contains a
  complementary pair whose removal leaves a balanced length-4 character. With Split24 (m ≤ 13): every odd prime p ≤ 29.

  The certificates are moved to PairsSplit.badP through PairsSplitBridge.badP_eq and Pairs6Bridge.badP_eq (the direct
  definitional check hit the recursion limit).

  Lean 4 core plus hodge/PairsSplit, hodge/Pairs6, hodge/Pairs6b, hodge/Pairs6c, hodge/Pairs6Bridge,
  hodge/PairsSplitBridge.
-/
import hodge.PairsSplit
import hodge.Pairs6
import hodge.Pairs6b
import hodge.Pairs6c
import hodge.Pairs6Bridge
import hodge.PairsSplitBridge

namespace PairsSplitInst
open Indecomp Len6Decomp Split24 PairsSplit

theorem bad_of (m : Nat) (h : Pairs6.badP m = []) : PairsSplit.badP m = [] := by
  rw [PairsSplitBridge.badP_eq, ← Pairs6Bridge.badP_eq]; exact h

theorem split17 (c : List Nat) (hc : c ∈ sexts 17) (hr : c.all (inR 17) = true) (hne : c ≠ []) (hb : bal 17 c = true) :
    has24 17 c = true := split24_of_pairs 16 (bad_of 17 Pairs6.p17) c hc hr hne hb
theorem split19 (c : List Nat) (hc : c ∈ sexts 19) (hr : c.all (inR 19) = true) (hne : c ≠ []) (hb : bal 19 c = true) :
    has24 19 c = true := split24_of_pairs 18 (bad_of 19 Pairs6.p19) c hc hr hne hb
theorem split23 (c : List Nat) (hc : c ∈ sexts 23) (hr : c.all (inR 23) = true) (hne : c ≠ []) (hb : bal 23 c = true) :
    has24 23 c = true := split24_of_pairs 22 (bad_of 23 Pairs6b.p23) c hc hr hne hb
theorem split29 (c : List Nat) (hc : c ∈ sexts 29) (hr : c.all (inR 29) = true) (hne : c ≠ []) (hb : bal 29 c = true) :
    has24 29 c = true := split24_of_pairs 28 (bad_of 29 Pairs6c.p29) c hc hr hne hb

end PairsSplitInst

#print axioms PairsSplitInst.bad_of
#print axioms PairsSplitInst.split17
#print axioms PairsSplitInst.split19
#print axioms PairsSplitInst.split23
#print axioms PairsSplitInst.split29

#print axioms: 5 theorems, no axioms.

81.215 Status

Statement

Status

Where

paired characters satisfy the Hodge condition, every \(m\), every \(n\)

proved (Lean)

paired_sum

prime \(m<100\), every \(n\): Hodge character \(\Leftrightarrow \) symmetric counts

proved (Lean)

paired_char_*, sym_hodge

first open character \(m=32\): Hodge, not standard; reach of the method for \(n=4\), \(m\le 40\)

proved (Lean) + measured

c32_hodge, NUMERIC_HODGE_REACH

standard characters Hodge, every \(m\)

proved (Lean)

std_hodge

standard characters Hodge, every \(m\le 40\)

proved (Lean)

std_hodge_le40

pullback, character level, every \(m\); \(m=12,14\), \(n=4,6\) reached

proved (Lean)

pull_hodge, reach12_*

\(\rho (X_m^2)=3(m-1)(m-2)+1\), \(\gcd (m,6)=1\), \(m\le 31\)

proved (Lean)

count_*

first open characters \(m=32,33\) certified outside the method

proved (Lean)

c33_not_reached

Galois orbit closure, every \(m\)

proved (Lean)

twist_hodge

\(m=25\), \(n=4\): all Hodge characters reached (standard base)

proved (Lean)

reach25_*

\(m=62\) open character certified

proved (Lean)

c62_not_reached

\(m=68,70\) open characters certified

proved (Lean)

c70_not_reached

conjugation closure, every \(m\)

proved (Lean)

conj_hodge

\(m=76,78\) open characters certified

proved (Lean)

c78_not_reached

pair cancellation, every \(m\)

proved (Lean)

pair_cancel

descent (converse of pullback), every \(m\)

proved (Lean)

descent

the entry \(m/2\) is neutral, every even \(m\)

proved (Lean)

half_cancel

invariance under reordering, every \(m\)

proved (Lean)

hodge_perm

\(m=62\) open character \(=31+\) balanced 5-list

proved (Lean)

rest62

open characters have no balanced splitting

proved (Lean, certificate)

indec_ok

all 126 stored open characters: 110 irreducible, 16 reduce

proved (Lean, certificate)

indec_all

odd \(m\): balanced blocks have even length

proved (Lean)

odd_len

unreached set \(=\) one Galois orbit for twelve \(m\)

proved (sizes) + measured

orbit_sizes

whole orbits irreducible (eleven \(m\))

proved (Lean, certificate)

orbit_indec

infinite family \(F_p\) (\(m=14p\), \(p\equiv 3,5\bmod 14\) prime): balanced, indecomposable

proved (Lean)

fam_bal, fam_indec

subgroup-average criterion; \(m=72\) seed certified

proved (Lean)

avg_indec, seed72

orbit decomposition of unreached sets, \(m=36\)–\(60\)

proved (Lean, certificate)

sizes, irreducible

inductive step, character level, every \(m\)

proved (Lean)

step_hodge

\(m=18,20,21\), \(n=4\): every Hodge character reached from surfaces

proved (Lean; cycle half cited)

reach*_6_*

counts of characters, Hodge, paired, eight small \((m,n)\)

proved (Lean, finite)

count_*

Lefschetz (1,1); hard Lefschetz; \(\dim X\le 3\)

cited

HODGE_MAP.md

Fermat: \(m\) prime or \(4\) (lines); \(m\le 20\), \(21\), \(27\); \(m=p^2\); \(n=4\), \((m,6)=1\)

cited

[1767, 1809, 1812,  1824]

reach of the method, \(n=4\), \(m\le 72\)

measured

fig_hodge_reach.pdf

Fermat characters, \(n=2\) (\(m\le 40\)), \(4\) (\(m\le 24\)), \(6\) (\(m\le 12\))

measured

NUMERIC_HODGE.txt

\(E^n\), \(n\le 4\): Hodge classes \(=\) products of divisors

measured (cited for all \(n\))

NUMERIC_HODGE.txt

abelian varieties: absolutely Hodge; \(\dim \le 5\) reduced to Weil classes; Weil fourfolds

cited

[1785, 1800, 1804]

all abelian fourfolds

cited (preprint)

[1801]

integral and Kähler versions false

cited

[1766, 1796, 1821]

absolute Hodge for all \(X\); variational Hodge

remaining

absolute_hodge, variational

Hodge conjecture

remaining

hodge

81.216 Machine check

The Lean file of this section is HodgeChain.lean (Listing 242). In AXIOMS.txt it has \(10\) theorems, and all \(10\) #print axioms lines read “does not depend on any axioms”. The numbers come from numeric_hodge.py (Listing 243); its output is NUMERIC_HODGE.txt.

Listing 242: HodgeChain.lean: paired characters are Hodge; counts

HodgeChain.lean

/-
  HodgeChain.lean
  Hodge classes of Fermat varieties, counted by characters (T41).

  Lean 4 core plus FTAChain (Dv, nadd_assoc). Proofs are hand-written terms and rewriting;
  no omega / simp / ring / decide / norm_num / linarith. Concrete counts use `rfl`.

  The Fermat variety X_m^n : x_0^m + … + x_{n+1}^m = 0 (n = 2p even). Its primitive middle
  cohomology splits into lines V(a), one for each character a = (a_0, …, a_{n+1}) with
  1 ≤ a_i ≤ m−1 and Σ a_i ≡ 0 (mod m) (Shioda). V(a) consists of Hodge classes iff
  Σ_i ⟨t a_i⟩ = (p+1) m for every unit t mod m, ⟨x⟩ = x mod m. A character that splits into
  pairs {b, m−b} is the class of a linear subspace (Shioda, Ran).

  Proved here:
    dv_between         m ∣ s and 0 < s < 2m  ⇒  s = m
    paired_sum         a list of pairs (x, y) with 0 < x + y < 2m and m ∣ x + y has
                       Σ (x + y) = (number of pairs) · m — for every m and every length:
                       after scaling by a unit t, a paired character of X_m^{2p} has
                       Σ ⟨t a_i⟩ = (p+1) m, i.e. it is a Hodge character
    count_*            the number of characters, of Hodge characters and of paired Hodge
                       characters for (m, n) = (3,2), (4,2), (5,2), (6,2), (7,2), (3,4), (4,4),
                       (5,4) (rfl; the same numbers as NUMERIC_HODGE.txt).
                       Quartic surface: 21 characters, 19 Hodge, all paired (Picard number
                       19 + 1 = 20); sextic surface: 85 Hodge, 61 paired (lines do not
                       span; the other 24 are the standard characters of NUMERIC_HODGE.txt)
-/
import FTAChain

namespace HodgeChain
open FTAChain

/-! ## Paired characters satisfy the Hodge condition, every m, every dimension -/

theorem dv_between (m s : Nat) (h : Dv m s) (h0 : 0 < s) (h2 : s < m + m) : s = m := by
  cases h with
  | intro q hq =>
    cases q with
    | zero =>
      rw [hq, Nat.zero_mul] at h0
      exact absurd h0 (Nat.lt_irrefl 0)
    | succ q =>
      cases q with
      | zero => rw [hq, Nat.one_mul]
      | succ k =>
        have e : (k + 1 + 1) * m = k * m + (m + m) := by
          rw [Nat.succ_mul, Nat.succ_mul, nadd_assoc]
        rw [hq, e] at h2
        exact absurd (Nat.lt_of_lt_of_le h2 (Nat.le_add_left (m + m) (k * m))) (Nat.lt_irrefl _)

def pairSum : List (Nat × Nat) → Nat
  | [] => 0
  | q :: l => q.1 + q.2 + pairSum l

def GoodPairs (m : Nat) : List (Nat × Nat) → Prop
  | [] => True
  | q :: l => (Dv m (q.1 + q.2) ∧ 0 < q.1 + q.2 ∧ q.1 + q.2 < m + m) ∧ GoodPairs m l

theorem paired_sum (m : Nat) : ∀ l : List (Nat × Nat), GoodPairs m l → pairSum l = l.length * m
  | [] => fun _ => (Nat.zero_mul m).symm
  | q :: l => fun h => by
    show q.1 + q.2 + pairSum l = (l.length + 1) * m
    rw [dv_between m _ h.1.1 h.1.2.1 h.1.2.2, paired_sum m l h.2, Nat.succ_mul, nadd_comm m]

/-! ## Finite counts -/

/-- Lists of length L over 1..m−1. -/
def tuples (m : Nat) : Nat → List (List Nat)
  | 0 => [[]]
  | L + 1 => (tuples m L).flatMap (fun a => (List.range (m - 1)).map (fun x => (x + 1) :: a))

def lsum : List Nat → Nat
  | [] => 0
  | x :: l => x + lsum l

/-- Characters of X_m^n: tuples of length n + 2 with Σ a_i ≡ 0. -/
def chars (m n : Nat) : List (List Nat) :=
  (tuples m (n + 2)).filter (fun a => Nat.beq (lsum a % m) 0)

def units (m : Nat) : List Nat := (List.range m).filter (fun t => Nat.beq (Nat.gcd t m) 1)

def hodgeB (m p : Nat) (a : List Nat) : Bool :=
  (units m).all (fun t => Nat.beq (lsum (a.map (fun x => t * x % m))) ((p + 1) * m))

/-- Remove the first occurrence of x. -/
def erase1 (x : Nat) : List Nat → Option (List Nat)
  | [] => none
  | y :: l => if Nat.beq x y then some l else (erase1 x l).map (fun r => y :: r)

/-- Splits into pairs {b, m − b}. -/
def pairedB (m : Nat) : Nat → List Nat → Bool
  | 0, _ => false
  | _, [] => true
  | f + 1, b :: l => match erase1 (m - b) l with
    | some r => pairedB m f r
    | none => false

def counts (m n : Nat) : Nat × Nat × Nat :=
  let C := chars m n
  let B := C.filter (hodgeB m (n / 2))
  (C.length, B.length, (B.filter (pairedB m (n + 2))).length)

theorem count_3_2 : counts 3 2 = (6, 6, 6) := rfl
theorem count_4_2 : counts 4 2 = (21, 19, 19) := rfl
theorem count_5_2 : counts 5 2 = (52, 36, 36) := rfl
set_option maxRecDepth 100000 in
theorem count_6_2 : counts 6 2 = (105, 85, 61) := rfl
set_option maxRecDepth 100000 in
theorem count_7_2 : counts 7 2 = (186, 90, 90) := rfl
theorem count_3_4 : counts 3 4 = (22, 20, 20) := rfl
set_option maxRecDepth 100000 in
theorem count_4_4 : counts 4 4 = (183, 141, 141) := rfl
set_option maxRecDepth 100000 in
theorem count_5_4 : counts 5 4 = (820, 400, 400) := rfl

end HodgeChain

#print axioms HodgeChain.dv_between
#print axioms HodgeChain.paired_sum
#print axioms HodgeChain.count_3_2
#print axioms HodgeChain.count_4_2
#print axioms HodgeChain.count_5_2
#print axioms HodgeChain.count_6_2
#print axioms HodgeChain.count_7_2
#print axioms HodgeChain.count_3_4
#print axioms HodgeChain.count_4_4
#print axioms HodgeChain.count_5_4

Listing 243: numeric_hodge.py: Fermat characters and products of elliptic curves

numeric_hodge.py

#!/usr/bin/env python3
"""T41 R4 numerics: Hodge classes on Fermat varieties and on products of elliptic curves.

Part A (Fermat, Shioda's character method).  X = X_m^n : x_0^m + ... + x_{n+1}^m = 0 in P^{n+1},
n = 2p even.  Characters a = (a_0..a_{n+1}) in (Z/m)^{n+2} with every a_i != 0 and sum a_i = 0
index the eigenspaces V(a) of the primitive middle cohomology (each of dimension 1).
|a| = sum <a_i>/m with <x> in {1..m-1}; V(a) has type (|a|-1, n+1-|a|).
  B   = Hodge characters:  |t a| = p + 1 for every t in (Z/m)^*
  D1  = characters that split into pairs {b, -b}: the classes of linear subspaces (Shioda, Ran)
  Dind= characters that split into blocks, each block a Hodge character of a smaller Fermat
        variety of even dimension (length >= 2, even); these come from D1 and from the
        inductive structure X^r x X^s -> X^{r+s+2} (Shioda 1979), applied to blocks already
        known to be algebraic (closure computed from the bottom)
  EXC = B minus Dind: Hodge classes not reached by this construction; for these the
        literature uses Aoki's standard cycles or Shioda's condition (P_m), see HODGE_MAP.md
Self-checks: #characters = ((m-1)^{n+2} + (m-1)(-1)^n)/m ; the Hodge numbers of the primitive
part reproduce the known ones (quartic K3: h^{2,0}=1, h^{1,1}_prim=19; cubic fourfold...).

Part B (products of elliptic curves).  H^1(E) = V = Q^2.  Hodge classes in H^{2k}(E^n) are the
invariants of the Hodge group: SL_2 acting diagonally (E without CM) or the circle U(1) given
by the complex multiplication J (E with CM), acting by derivations on Lambda^{2k}(V^n).
Compared with the span of k-fold products of divisor classes (Hodge classes of H^2, algebraic by
Lefschetz (1,1)).  Exact rational linear algebra (fractions).

Usage:  numeric_hodge.py fermat SPEC OUT.json   (SPEC like 2:40,4:20,6:10 = n:mmax)   (Kamiak for the large ranges)
        numeric_hodge.py ell NMAX OUT.json
        numeric_hodge.py report DATADIR               writes NUMERIC_HODGE.txt
"""
import itertools
import json
import math
import os
import sys
from fractions import Fraction


# ------------------------------------------------------------------------ Part A

def units(m):
    return [t for t in range(1, m) if math.gcd(t, m) == 1]


def is_hodge(a, m, p, U):
    target = (p + 1) * m
    for t in U:
        if sum((t * x) % m for x in a) != target:
            return False
    return True


def type_q(a, m):
    return sum(a) // m - 1


def multisets(m, L):
    """Sorted tuples (multisets) of length L over 1..m-1 with sum = 0 mod m, with the number of
    their orderings (each multiset stands for all its permutations)."""
    out = []
    for c in itertools.combinations_with_replacement(range(1, m), L):
        if sum(c) % m == 0:
            k = math.factorial(L)
            for v in set(c):
                k //= math.factorial(c.count(v))
            out.append((c, k))
    return out


def paired(c, m):
    """c (sorted multiset) splits into pairs {b, m-b}."""
    c = list(c)
    while c:
        b = c.pop()
        try:
            c.remove(m - b)
        except ValueError:
            return False
    return True


def std4(m):
    """Length-4 characters of the two standard shapes (a, a+m/2, -2a, m/2) (m even) and
    (a, a+m/3, a+2m/3, -3a) (3 | m), the shapes of Aoki-Shioda's standard characters on Fermat
    surfaces (the correspondence with their curves is not re-checked here)."""
    S = set()
    for a in range(1, m):
        if m % 2 == 0:
            c = tuple(sorted([a, (a + m // 2) % m, (-2 * a) % m, m // 2]))
            if 0 not in c:
                S.add(c)
        if m % 3 == 0:
            c = tuple(sorted([a, (a + m // 3) % m, (a + 2 * m // 3) % m, (-3 * a) % m]))
            if 0 not in c:
                S.add(c)
    return S


def fermat(m, n):
    """Counts for X_m^n (n even), over multisets with multiplicities (= characters)."""
    p = n // 2
    U = units(m)
    L = n + 2
    total = 0
    hodge_num = {}
    B = D1 = Dind = Dstd = 0
    exc_examples = []
    S4 = std4(m)
    # Hodge blocks of every even length <= L, for the inductive closure:
    # alg  from pairs only;  algS  from pairs and the standard length-4 shapes
    alg, algS = {}, {}
    for l in range(2, L + 1, 2):
        alg[l], algS[l] = set(), set()
        for c, k in multisets(m, l):
            if not is_hodge(c, m, l // 2 - 1, U):
                continue
            if paired(c, m) or splits(c, alg, m):
                alg[l].add(c)
            if paired(c, m) or (l == 4 and c in S4) or splits(c, algS, m):
                algS[l].add(c)
    for c, k in multisets(m, L):
        total += k
        q = type_q(c, m)
        hodge_num[q] = hodge_num.get(q, 0) + k
        if is_hodge(c, m, p, U):
            B += k
            if paired(c, m):
                D1 += k
            if c in alg[L]:
                Dind += k
            if c in algS[L]:
                Dstd += k
            elif len(exc_examples) < 3:
                exc_examples.append(c)
    expect = ((m - 1) ** L + (m - 1) * (-1) ** n) // m
    return dict(m=m, n=n, total=total, expect=expect, hodge_numbers=[hodge_num.get(q, 0) for q in range(n + 1)],
                B=B, D1=D1, Dind=Dind, Dstd=Dstd, exc=B - Dstd, exc_examples=exc_examples)


def splits(c, alg, m):
    """c splits into two nonempty sub-multisets, each in alg (even lengths)."""
    L = len(c)
    idx = list(range(L))
    for l in range(2, L - 1, 2):
        for S in itertools.combinations(idx, l):
            if 0 not in S:
                continue
            A = tuple(sorted(c[i] for i in S))
            Bt = tuple(sorted(c[i] for i in idx if i not in S))
            if sum(A) % m or sum(Bt) % m:
                continue
            if A in alg.get(l, ()) and Bt in alg.get(L - l, ()):
                return True
    return False


# ------------------------------------------------------------------------ Part B

def wedge_basis(dim, k):
    return list(itertools.combinations(range(dim), k))


def act(D, dim, k):
    """Matrix of the derivation induced by D (dim x dim, D[i][j] = coefficient of e_i in D e_j)
    on Lambda^k, in the basis wedge_basis(dim, k)."""
    basis = wedge_basis(dim, k)
    index = {b: i for i, b in enumerate(basis)}
    M = [[Fraction(0)] * len(basis) for _ in basis]
    for col, b in enumerate(basis):
        for pos, j in enumerate(b):
            for i in range(dim):
                if D[i][j] == 0:
                    continue
                nb = list(b)
                nb[pos] = i
                if len(set(nb)) < k:
                    continue
                sgn = 1
                # sort with sign
                arr = nb[:]
                for x in range(len(arr)):
                    for y in range(len(arr) - 1 - x):
                        if arr[y] > arr[y + 1]:
                            arr[y], arr[y + 1] = arr[y + 1], arr[y]
                            sgn = -sgn
                M[index[tuple(arr)]][col] += sgn * D[i][j]
    return M


def rank(rows):
    A = [r[:] for r in rows]
    rk, ncol = 0, len(A[0]) if A else 0
    for c in range(ncol):
        piv = next((r for r in range(rk, len(A)) if A[r][c] != 0), None)
        if piv is None:
            continue
        A[rk], A[piv] = A[piv], A[rk]
        for r in range(len(A)):
            if r != rk and A[r][c] != 0:
                f = A[r][c] / A[rk][c]
                A[r] = [x - f * y for x, y in zip(A[r], A[rk])]
        rk += 1
    return rk


def kernel(Ms, size):
    """Basis of the common kernel of the matrices Ms (size x size)."""
    rows = [row for M in Ms for row in M]
    A = [r[:] for r in rows]
    piv_cols, rk = [], 0
    for c in range(size):
        piv = next((r for r in range(rk, len(A)) if A[r][c] != 0), None)
        if piv is None:
            continue
        A[rk], A[piv] = A[piv], A[rk]
        pv = A[rk][c]
        A[rk] = [x / pv for x in A[rk]]
        for r in range(len(A)):
            if r != rk and A[r][c] != 0:
                f = A[r][c]
                A[r] = [x - f * y for x, y in zip(A[r], A[rk])]
        piv_cols.append(c)
        rk += 1
    free = [c for c in range(size) if c not in piv_cols]
    K = []
    for f in free:
        v = [Fraction(0)] * size
        v[f] = Fraction(1)
        for r, c in enumerate(piv_cols):
            v[c] = -A[r][f]
        K.append(v)
    return K


def wedge_vec(u, v, dim, k1, k2):
    b1, b2 = wedge_basis(dim, k1), wedge_basis(dim, k2)
    b3 = wedge_basis(dim, k1 + k2)
    idx = {b: i for i, b in enumerate(b3)}
    w = [Fraction(0)] * len(b3)
    for i, x in enumerate(u):
        if x == 0:
            continue
        for j, y in enumerate(v):
            if y == 0:
                continue
            s = b1[i] + b2[j]
            if len(set(s)) < len(s):
                continue
            arr, sgn = list(s), 1
            for a in range(len(arr)):
                for b in range(len(arr) - 1 - a):
                    if arr[b] > arr[b + 1]:
                        arr[b], arr[b + 1] = arr[b + 1], arr[b]
                        sgn = -sgn
            w[idx[tuple(arr)]] += sgn * x * y
    return w


def ell(n, cm):
    """dims of Hodge classes and of the span of products of divisors in H^{2k}(E^n), k = 0..n."""
    dim = 2 * n

    def blockdiag(D2):
        D = [[Fraction(0)] * dim for _ in range(dim)]
        for c in range(n):
            for i in range(2):
                for j in range(2):
                    D[2 * c + i][2 * c + j] = Fraction(D2[i][j])
        return D

    if cm:
        gens = [blockdiag([[0, -1], [1, 0]])]
    else:
        gens = [blockdiag([[0, 1], [0, 0]]), blockdiag([[0, 0], [1, 0]]), blockdiag([[1, 0], [0, -1]])]
    out = []
    div = kernel([act(D, dim, 2) for D in gens], len(wedge_basis(dim, 2)))
    prods = {1: div}
    for k in range(0, n + 1):
        size = len(wedge_basis(dim, 2 * k))
        if k == 0:
            out.append(dict(k=0, hodge=1, divisors=1))
            continue
        H = kernel([act(D, dim, 2 * k) for D in gens], size)
        if k >= 2:
            prev = prods[k - 1]
            P = []
            for u in prev:
                for v in div:
                    P.append(wedge_vec(u, v, dim, 2 * (k - 1), 2))
            # keep a basis
            r, basis = 0, []
            for w in P:
                if rank(basis + [w]) > r:
                    basis.append(w)
                    r += 1
            prods[k] = basis
        out.append(dict(k=k, hodge=len(H), divisors=len(prods[k]) if k in prods else 0))
    return out


# ------------------------------------------------------------------------ report

def report(datadir):
    here = os.path.dirname(os.path.abspath(__file__))
    L = ["NUMERIC_HODGE.txt  (T41; numeric_hodge.py; exact integer / rational arithmetic)", ""]
    fpath = os.path.join(datadir, "fermat.json")
    if os.path.exists(fpath):
        with open(fpath) as fh:
            F = json.load(fh)
        L.append("A. Fermat X_m^n (n even). chars = dim H^n_prim (check: formula), h^{q,n-q}_prim,")
        L.append("   B = Hodge characters, D1 = split into pairs {b,-b} (linear subspaces),")
        L.append("   Dind = split into Hodge blocks of smaller even-dimensional Fermat varieties (inductive, from pairs),")
        L.append("   Dstd = the same closure with the two standard length-4 shapes added as blocks, EXC = B - Dstd")
        L.append(" m   n | chars (formula) | h_prim^{q,n-q}, q=0..n | B | D1 | Dind | Dstd | EXC | examples of EXC")
        for r in F:
            L.append(f"{r['m']:>2} {r['n']:>3} | {r['total']} ({'ok' if r['total'] == r['expect'] else 'MISMATCH'}) | "
                     f"{r['hodge_numbers']} | {r['B']} | {r['D1']} | {r['Dind']} | {r['Dstd']} | {r['exc']} | {r['exc_examples']}")
        L.append("")
    epath = os.path.join(datadir, "ell.json")
    if os.path.exists(epath):
        with open(epath) as fh:
            E = json.load(fh)
        L.append("B. Products E^n: dim of Hodge classes in H^{2k}(E^n,Q) vs span of k-fold products of divisor classes")
        for key in sorted(E):
            L.append(f"   {key}: " + "; ".join(f"k={d['k']}: {d['hodge']} / {d['divisors']}" for d in E[key]))
        L.append("")
    txt = "\n".join(L) + "\n"
    with open(os.path.join(here, "NUMERIC_HODGE.txt"), "w") as fh:
        fh.write(txt)
    print(txt)


if __name__ == "__main__":
    cmd = sys.argv[1]
    if cmd == "fermat":
        spec = [tuple(int(y) for y in x.split(":")) for x in sys.argv[2].split(",")]
        out = sys.argv[3]
        res = []
        for n, mmax in spec:
            for m in range(3, mmax + 1):
                r = fermat(m, n)
                res.append(r)
                print(r["m"], r["n"], r["B"], r["D1"], r["Dind"], r["Dstd"], r["exc"], flush=True)
                with open(out, "w") as fh:
                    json.dump(res, fh)
    elif cmd == "ell":
        nmax = int(sys.argv[2])
        out = sys.argv[3]
        res = {}
        for n in range(1, nmax + 1):
            for cm in (False, True):
                res[f"E^{n} {'CM' if cm else 'no CM'}"] = ell(n, cm)
                print(n, cm, res[f"E^{n} {'CM' if cm else 'no CM'}"], flush=True)
        with open(out, "w") as fh:
            json.dump(res, fh)
    elif cmd == "report":
        report(sys.argv[2])

Listing 244: NUMERIC_HODGE.txt

NUMERIC_HODGE.txt

NUMERIC_HODGE.txt  (T41; numeric_hodge.py; exact integer / rational arithmetic)

A. Fermat X_m^n (n even). chars = dim H^n_prim (check: formula), h^{q,n-q}_prim,
   B = Hodge characters, D1 = split into pairs {b,-b} (linear subspaces),
   Dind = split into Hodge blocks of smaller even-dimensional Fermat varieties (inductive, from pairs),
   Dstd = the same closure with the two standard length-4 shapes added as blocks, EXC = B - Dstd
 m   n | chars (formula) | h_prim^{q,n-q}, q=0..n | B | D1 | Dind | Dstd | EXC | examples of EXC
 3   2 | 6 (ok) | [0, 6, 0] | 6 | 6 | 6 | 6 | 0 | []
 4   2 | 21 (ok) | [1, 19, 1] | 19 | 19 | 19 | 19 | 0 | []
 5   2 | 52 (ok) | [4, 44, 4] | 36 | 36 | 36 | 36 | 0 | []
 6   2 | 105 (ok) | [10, 85, 10] | 85 | 61 | 61 | 85 | 0 | []
 7   2 | 186 (ok) | [20, 146, 20] | 90 | 90 | 90 | 90 | 0 | []
 8   2 | 301 (ok) | [35, 231, 35] | 175 | 127 | 127 | 175 | 0 | []
 9   2 | 456 (ok) | [56, 344, 56] | 216 | 168 | 168 | 216 | 0 | []
10   2 | 657 (ok) | [84, 489, 84] | 361 | 217 | 217 | 313 | 48 | [[1, 3, 8, 8], [1, 6, 6, 7], [2, 2, 7, 9]]
11   2 | 910 (ok) | [120, 670, 120] | 270 | 270 | 270 | 270 | 0 | []
12   2 | 1221 (ok) | [165, 891, 165] | 643 | 331 | 331 | 427 | 216 | [[1, 4, 9, 10], [1, 6, 8, 9], [1, 7, 8, 8]]
13   2 | 1596 (ok) | [220, 1156, 220] | 396 | 396 | 396 | 396 | 0 | []
14   2 | 2041 (ok) | [286, 1469, 286] | 805 | 469 | 469 | 613 | 192 | [[1, 4, 11, 12], [1, 7, 9, 11], [1, 8, 9, 10]]
15   2 | 2562 (ok) | [364, 1834, 364] | 834 | 546 | 546 | 642 | 192 | [[1, 6, 10, 13], [1, 7, 10, 12], [2, 5, 9, 14]]
16   2 | 3165 (ok) | [455, 2255, 455] | 871 | 631 | 631 | 775 | 96 | [[1, 9, 10, 12], [2, 5, 12, 13], [3, 4, 11, 14]]
17   2 | 3856 (ok) | [560, 2736, 560] | 720 | 720 | 720 | 720 | 0 | []
18   2 | 4641 (ok) | [680, 3281, 680] | 1657 | 817 | 817 | 1081 | 576 | [[1, 5, 14, 16], [1, 6, 14, 15], [1, 7, 12, 16]]
19   2 | 5526 (ok) | [816, 3894, 816] | 918 | 918 | 918 | 918 | 0 | []
20   2 | 6517 (ok) | [969, 4579, 969] | 1987 | 1027 | 1027 | 1219 | 768 | [[1, 4, 17, 18], [1, 6, 16, 17], [1, 8, 13, 18]]
21   2 | 7620 (ok) | [1140, 5340, 1140] | 1572 | 1140 | 1140 | 1284 | 288 | [[1, 4, 18, 19], [1, 10, 12, 19], [1, 10, 15, 16]]
22   2 | 8841 (ok) | [1330, 6181, 1330] | 1741 | 1261 | 1261 | 1501 | 240 | [[1, 6, 17, 20], [1, 12, 13, 18], [2, 5, 16, 21]]
23   2 | 10186 (ok) | [1540, 7106, 1540] | 1386 | 1386 | 1386 | 1386 | 0 | []
24   2 | 11661 (ok) | [1771, 8119, 1771] | 3079 | 1519 | 1519 | 1855 | 1224 | [[1, 6, 19, 22], [1, 8, 17, 22], [1, 8, 19, 20]]
25   2 | 13272 (ok) | [2024, 9224, 2024] | 1656 | 1656 | 1656 | 1656 | 0 | []
26   2 | 15025 (ok) | [2300, 10425, 2300] | 2377 | 1801 | 1801 | 2089 | 288 | [[1, 7, 20, 24], [1, 14, 15, 22], [2, 6, 19, 25]]
27   2 | 16926 (ok) | [2600, 11726, 2600] | 2142 | 1950 | 1950 | 2142 | 0 | []
28   2 | 18981 (ok) | [2925, 13131, 2925] | 2971 | 2107 | 2107 | 2395 | 576 | [[1, 9, 21, 25], [1, 15, 16, 24], [1, 15, 18, 22]]
29   2 | 21196 (ok) | [3276, 14644, 3276] | 2268 | 2268 | 2268 | 2268 | 0 | []
30   2 | 23577 (ok) | [3654, 16269, 3654] | 5629 | 2437 | 2437 | 2941 | 2688 | [[1, 4, 27, 28], [1, 7, 25, 27], [1, 8, 23, 28]]
31   2 | 26130 (ok) | [4060, 18010, 4060] | 2610 | 2610 | 2610 | 2610 | 0 | []
32   2 | 28861 (ok) | [4495, 19871, 4495] | 3415 | 2791 | 2791 | 3127 | 288 | [[1, 17, 18, 28], [2, 9, 25, 28], [2, 18, 20, 24]]
33   2 | 31776 (ok) | [4960, 21856, 4960] | 3216 | 2976 | 2976 | 3216 | 0 | []
34   2 | 34881 (ok) | [5456, 23969, 5456] | 3937 | 3169 | 3169 | 3553 | 384 | [[1, 9, 26, 32], [1, 18, 19, 30], [2, 8, 25, 33]]
35   2 | 38182 (ok) | [5984, 26214, 5984] | 3366 | 3366 | 3366 | 3366 | 0 | []
36   2 | 41685 (ok) | [6545, 28595, 6545] | 5515 | 3571 | 3571 | 4147 | 1368 | [[1, 19, 20, 32], [1, 19, 24, 28], [2, 9, 28, 33]]
37   2 | 45396 (ok) | [7140, 31116, 7140] | 3780 | 3780 | 3780 | 3780 | 0 | []
38   2 | 49321 (ok) | [7770, 33781, 7770] | 4861 | 3997 | 3997 | 4429 | 432 | [[1, 10, 29, 36], [1, 20, 21, 34], [2, 9, 28, 37]]
39   2 | 53466 (ok) | [8436, 36594, 8436] | 4506 | 4218 | 4218 | 4506 | 0 | []
40   2 | 57837 (ok) | [9139, 39559, 9139] | 6223 | 4447 | 4447 | 4879 | 1344 | [[1, 21, 22, 36], [1, 21, 24, 34], [1, 21, 26, 32]]
 3   4 | 22 (ok) | [0, 1, 20, 1, 0] | 20 | 20 | 20 | 20 | 0 | []
 4   4 | 183 (ok) | [0, 21, 141, 21, 0] | 141 | 141 | 141 | 141 | 0 | []
 5   4 | 820 (ok) | [0, 120, 580, 120, 0] | 400 | 400 | 400 | 400 | 0 | []
 6   4 | 2605 (ok) | [1, 426, 1751, 426, 1] | 1751 | 1001 | 1001 | 1721 | 30 | [[1, 1, 4, 4, 4, 4], [2, 2, 2, 2, 5, 5]]
 7   4 | 6666 (ok) | [6, 1161, 4332, 1161, 6] | 1860 | 1860 | 1860 | 1860 | 0 | []
 8   4 | 14707 (ok) | [21, 2667, 9331, 2667, 21] | 5881 | 3301 | 3301 | 5701 | 180 | [[1, 1, 5, 5, 6, 6], [2, 2, 3, 3, 7, 7]]
 9   4 | 29128 (ok) | [56, 5432, 18152, 5432, 56] | 8000 | 5120 | 5120 | 8000 | 0 | []
10   4 | 53145 (ok) | [126, 10116, 32661, 10116, 126] | 19881 | 7761 | 7761 | 15441 | 4440 | [[1, 1, 3, 8, 8, 9], [1, 1, 6, 6, 7, 9], [1, 1, 6, 6, 8, 8]]
11   4 | 90910 (ok) | [252, 17577, 55252, 17577, 252] | 10900 | 10900 | 10900 | 10900 | 0 | []
12   4 | 147631 (ok) | [462, 28897, 88913, 28897, 462] | 52991 | 15101 | 15101 | 26021 | 26970 | [[1, 1, 4, 9, 10, 11], [1, 1, 6, 8, 9, 11], [1, 1, 6, 9, 9, 10]]
13   4 | 229692 (ok) | [792, 45408, 137292, 45408, 792] | 19920 | 19920 | 19920 | 19920 | 0 | []
14   4 | 344773 (ok) | [1287, 68718, 204763, 68718, 1287] | 77401 | 26041 | 26041 | 46201 | 31200 | [[1, 1, 4, 11, 12, 13], [1, 1, 7, 9, 11, 13], [1, 1, 8, 8, 12, 12]]
15   4 | 501970 (ok) | [2002, 100737, 296492, 100737, 2002] | 78260 | 32900 | 32900 | 47300 | 30960 | [[1, 1, 6, 10, 13, 14], [1, 1, 7, 10, 12, 14], [1, 2, 5, 9, 14, 14]]
16   4 | 711915 (ok) | [3003, 143703, 418503, 143703, 3003] | 87921 | 41301 | 41301 | 65781 | 22140 | [[1, 1, 9, 9, 14, 14], [1, 1, 9, 10, 12, 15], [1, 2, 5, 12, 13, 15]]
17   4 | 986896 (ok) | [4368, 200208, 577744, 200208, 4368] | 50560 | 50560 | 50560 | 50560 | 0 | []
18   4 | 1340977 (ok) | [6188, 273224, 782153, 273224, 6188] | 264671 | 61601 | 61601 | 114161 | 150510 | [[1, 1, 5, 14, 16, 17], [1, 1, 6, 14, 15, 17], [1, 1, 7, 12, 16, 17]]
19   4 | 1790118 (ok) | [8568, 366129, 1040724, 366129, 8568] | 73620 | 73620 | 73620 | 73620 | 0 | []
20   4 | 2352295 (ok) | [11628, 482733, 1363573, 482733, 11628] | 346381 | 87661 | 87661 | 131821 | 214560 | [[1, 1, 4, 17, 18, 19], [1, 1, 6, 16, 17, 19], [1, 1, 6, 17, 17, 18]]
21   4 | 3047620 (ok) | [15504, 627304, 1762004, 627304, 15504] | 215120 | 102800 | 102800 | 137360 | 77760 | [[1, 1, 4, 18, 19, 20], [1, 1, 10, 12, 19, 20], [1, 1, 10, 15, 16, 20]]
22   4 | 3898461 (ok) | [20349, 804594, 2248575, 804594, 20349] | 277101 | 120201 | 120201 | 182601 | 94500 | [[1, 1, 6, 17, 20, 21], [1, 1, 12, 12, 20, 20], [1, 1, 12, 13, 18, 21]]
23   4 | 4929562 (ok) | [26334, 1019865, 2837164, 1019865, 26334] | 138820 | 138820 | 138820 | 138820 | 0 | []
24   4 | 6168163 (ok) | [33649, 1278915, 3543035, 1278915, 33649] | 745211 | 159941 | 159941 | 257261 | 487950 | [[1, 1, 6, 19, 22, 23], [1, 1, 8, 17, 22, 23], [1, 1, 8, 19, 20, 23]]
 3   6 | 86 (ok) | [0, 0, 8, 70, 8, 0, 0] | 70 | 70 | 70 | 70 | 0 | []
 4   6 | 1641 (ok) | [0, 1, 266, 1107, 266, 1, 0] | 1107 | 1107 | 1107 | 1107 | 0 | []
 5   6 | 13108 (ok) | [0, 36, 2472, 8092, 2472, 36, 0] | 4900 | 4900 | 4900 | 4900 | 0 | []
 6   6 | 65105 (ok) | [0, 330, 13140, 38165, 13140, 330, 0] | 38165 | 18733 | 18733 | 37269 | 896 | [[1, 1, 1, 4, 4, 4, 4, 5], [1, 1, 2, 4, 4, 4, 4, 4], [1, 2, 2, 2, 2, 5, 5, 5]]
 7   6 | 239946 (ok) | [0, 1708, 50288, 135954, 50288, 1708, 0] | 44730 | 44730 | 44730 | 44730 | 0 | []
 8   6 | 720601 (ok) | [1, 6371, 154645, 398567, 154645, 6371, 1] | 219871 | 103279 | 103279 | 209791 | 10080 | [[1, 1, 1, 5, 5, 6, 6, 7], [1, 1, 2, 5, 5, 6, 6, 6], [1, 1, 3, 5, 5, 5, 6, 6]]
 9   6 | 1864136 (ok) | [8, 19160, 406568, 1012664, 406568, 19160, 8] | 343000 | 190120 | 190120 | 343000 | 0 | []
10   6 | 4304673 (ok) | [36, 49428, 949860, 2306025, 949860, 49428, 36] | 1225449 | 345465 | 345465 | 907929 | 317520 | [[1, 1, 1, 3, 8, 8, 9, 9], [1, 1, 1, 6, 6, 7, 9, 9], [1, 1, 1, 6, 6, 8, 8, 9]]
11   6 | 9090910 (ok) | [120, 113640, 2023680, 4816030, 2023680, 113640, 120] | 551950 | 551950 | 551950 | 551950 | 0 | []
12   6 | 17863241 (ok) | [330, 238821, 4003736, 9377467, 4003736, 238821, 330] | 4882179 | 876331 | 876331 | 2043819 | 2838360 | [[1, 1, 1, 4, 9, 10, 11, 11], [1, 1, 1, 6, 8, 9, 11, 11], [1, 1, 1, 6, 9, 9, 10, 11]]

B. Products E^n: dim of Hodge classes in H^{2k}(E^n,Q) vs span of k-fold products of divisor classes
   E^1 CM: k=0: 1 / 1; k=1: 1 / 1
   E^1 no CM: k=0: 1 / 1; k=1: 1 / 1
   E^2 CM: k=0: 1 / 1; k=1: 4 / 4; k=2: 1 / 1
   E^2 no CM: k=0: 1 / 1; k=1: 3 / 3; k=2: 1 / 1
   E^3 CM: k=0: 1 / 1; k=1: 9 / 9; k=2: 9 / 9; k=3: 1 / 1
   E^3 no CM: k=0: 1 / 1; k=1: 6 / 6; k=2: 6 / 6; k=3: 1 / 1
   E^4 CM: k=0: 1 / 1; k=1: 16 / 16; k=2: 36 / 36; k=3: 16 / 16; k=4: 1 / 1
   E^4 no CM: k=0: 1 / 1; k=1: 10 / 10; k=2: 20 / 20; k=3: 10 / 10; k=4: 1 / 1

81.217 Integer certificates for kernels (Maillet-type matrices)

If the rows of \(B\) combine the rows of \(A\) (all of length \(n\)) to \(d\cdot I\) with \(d\ne 0\), then \(Ag=0\) and \(|g|=n\) force \(g=0\). Lists over \(\mathbb Z\), hand proofs; used for the matrices \(A_{t,x}=2\langle tx\rangle -p\).

hodge/MailletLin.lean

/-
  hodge/MailletLin.lean — T41 cycle 1706 (goal G849): integer linear algebra on lists for Maillet-type certificates.
  If every row of A has length n and the rows of B combine the rows of A to d times the identity (d ≠ 0),
  then A g = 0 with |g| = n forces g = 0. Lean 4 core, hand proofs, no axioms.
-/
import lib.IntRing

namespace MailletLin
open LibInt

/-- Dot product (truncated to the shorter list). -/
def dot : List Int → List Int → Int
  | [], _ => 0
  | _ :: _, [] => 0
  | a :: as, b :: bs => a * b + dot as bs

/-- Componentwise sum (truncated). -/
def addV : List Int → List Int → List Int
  | [], _ => []
  | _ :: _, [] => []
  | a :: as, b :: bs => (a + b) :: addV as bs

/-- Scalar multiple. -/
def smul (c : Int) : List Int → List Int
  | [] => []
  | a :: as => (c * a) :: smul c as

/-- Zero vector of length n. -/
def zeros : Nat → List Int
  | 0 => []
  | n + 1 => 0 :: zeros n

/-- Linear combination Σ c_i r_i of rows (zero vector of length n when one list ends). -/
def lc (n : Nat) : List Int → List (List Int) → List Int
  | [], _ => zeros n
  | _ :: _, [] => zeros n
  | c :: cs, r :: rs => addV (smul c r) (lc n cs rs)

/-- Matrix–vector product, row by row. -/
def mv : List (List Int) → List Int → List Int
  | [], _ => []
  | r :: rs, g => dot r g :: mv rs g

/-- Rows of B · A, each as a linear combination of the rows of A. -/
def lcs (n : Nat) : List (List Int) → List (List Int) → List (List Int)
  | [], _ => []
  | b :: bs, A => lc n b A :: lcs n bs A

/-- Prepend a zero column. -/
def shift : List (List Int) → List (List Int)
  | [] => []
  | r :: rs => (0 :: r) :: shift rs

/-- d times the n × n identity. -/
def sid (d : Int) : Nat → List (List Int)
  | 0 => []
  | n + 1 => (d :: zeros n) :: shift (sid d n)

/-- Every row has length n (Boolean, for rfl certificates). -/
def allLen (n : Nat) : List (List Int) → Bool
  | [] => true
  | r :: rs => Nat.beq r.length n && allLen n rs

theorem beq_eq : ∀ a b : Nat, Nat.beq a b = true → a = b
  | 0, 0, _ => rfl
  | 0, _ + 1, h => Bool.noConfusion h
  | _ + 1, 0, h => Bool.noConfusion h
  | a + 1, b + 1, h => congrArg (· + 1) (beq_eq a b h)

theorem and_left : ∀ {x y : Bool}, (x && y) = true → x = true
  | true, _, _ => rfl
  | false, _, h => Bool.noConfusion h

theorem and_right : ∀ {x y : Bool}, (x && y) = true → y = true
  | true, _, h => h
  | false, _, h => Bool.noConfusion h

theorem len_addV : ∀ u v : List Int, u.length = v.length → (addV u v).length = u.length
  | [], _, _ => rfl
  | _ :: _, [], h => Nat.noConfusion h
  | _ :: as, _ :: bs, h => congrArg (· + 1) (len_addV as bs (Nat.succ.inj h))

theorem len_smul (c : Int) : ∀ v : List Int, (smul c v).length = v.length
  | [] => rfl
  | _ :: as => congrArg (· + 1) (len_smul c as)

theorem len_zeros : ∀ n : Nat, (zeros n).length = n
  | 0 => rfl
  | n + 1 => congrArg (· + 1) (len_zeros n)

theorem len_lc (n : Nat) : ∀ (b : List Int) (A : List (List Int)), allLen n A = true → (lc n b A).length = n
  | [], _, _ => len_zeros n
  | _ :: _, [], _ => len_zeros n
  | c :: cs, r :: rs, h => by
    have hr : r.length = n := beq_eq _ _ (and_left h)
    have ih := len_lc n cs rs (and_right h)
    show (addV (smul c r) (lc n cs rs)).length = n
    rw [len_addV _ _ (by rw [len_smul, hr, ih]), len_smul, hr]

theorem dot_addV : ∀ u v g : List Int, u.length = v.length → dot (addV u v) g = dot u g + dot v g
  | [], [], _, _ => rfl
  | [], _ :: _, _, h => Nat.noConfusion h
  | _ :: _, [], _, h => Nat.noConfusion h
  | _ :: _, _ :: _, [], _ => rfl
  | a :: as, b :: bs, x :: xs, h => by
    show (a + b) * x + dot (addV as bs) xs = (a * x + dot as xs) + (b * x + dot bs xs)
    rw [dot_addV as bs xs (Nat.succ.inj h)]
    generalize dot as xs = P
    generalize dot bs xs = Q
    lib_int

theorem dot_smul (c : Int) : ∀ v g : List Int, dot (smul c v) g = c * dot v g
  | [], _ => by show (0 : Int) = c * 0; lib_int
  | _ :: _, [] => by show (0 : Int) = c * 0; lib_int
  | a :: as, x :: xs => by
    show c * a * x + dot (smul c as) xs = c * (a * x + dot as xs)
    rw [dot_smul c as xs]
    generalize dot as xs = P
    lib_int

theorem dot_zeros_left : ∀ (n : Nat) (g : List Int), dot (zeros n) g = 0
  | 0, _ => rfl
  | _ + 1, [] => rfl
  | n + 1, x :: xs => by
    show 0 * x + dot (zeros n) xs = 0
    rw [dot_zeros_left n xs]
    lib_int

theorem dot_zeros_right : ∀ (n : Nat) (b : List Int), dot b (zeros n) = 0
  | 0, [] => rfl
  | 0, _ :: _ => rfl
  | _ + 1, [] => rfl
  | n + 1, c :: cs => by
    show c * 0 + dot cs (zeros n) = 0
    rw [dot_zeros_right n cs]
    lib_int

/-- Key identity: b · (A g) = (Σ b_i A_i) · g. -/
theorem dot_mv (n : Nat) : ∀ (b : List Int) (A : List (List Int)) (g : List Int),
    allLen n A = true → dot b (mv A g) = dot (lc n b A) g
  | [], _, g, _ => (dot_zeros_left n g).symm
  | _ :: _, [], g, _ => (dot_zeros_left n g).symm
  | c :: cs, r :: rs, g, h => by
    have hr : r.length = n := beq_eq _ _ (and_left h)
    have hl := len_lc n cs rs (and_right h)
    show c * dot r g + dot cs (mv rs g) = dot (addV (smul c r) (lc n cs rs)) g
    rw [dot_addV _ _ g (by rw [len_smul, hr, hl]), dot_smul, dot_mv n cs rs g (and_right h)]

theorem mv_mv (n : Nat) (A : List (List Int)) (g : List Int) (hA : allLen n A = true) :
    ∀ B : List (List Int), mv B (mv A g) = mv (lcs n B A) g
  | [] => rfl
  | b :: bs => by
    show dot b (mv A g) :: mv bs (mv A g) = dot (lc n b A) g :: mv (lcs n bs A) g
    rw [dot_mv n b A g hA, mv_mv n A g hA bs]

theorem mv_shift : ∀ (S : List (List Int)) (x : Int) (xs : List Int), mv (shift S) (x :: xs) = mv S xs
  | [], _, _ => rfl
  | r :: rs, x, xs => by
    show (0 * x + dot r xs) :: mv (shift rs) (x :: xs) = dot r xs :: mv rs xs
    rw [mv_shift rs x xs]
    have : 0 * x + dot r xs = dot r xs := by generalize dot r xs = P; lib_int
    rw [this]

theorem mv_sid (d : Int) : ∀ (n : Nat) (g : List Int), g.length = n → mv (sid d n) g = smul d g
  | 0, [], _ => rfl
  | 0, _ :: _, h => Nat.noConfusion h
  | _ + 1, [], h => Nat.noConfusion h
  | n + 1, x :: xs, h => by
    show (d * x + dot (zeros n) xs) :: mv (shift (sid d n)) (x :: xs) = (d * x) :: smul d xs
    rw [dot_zeros_left, mv_shift, mv_sid d n xs (Nat.succ.inj h)]
    have : d * x + 0 = d * x := by lib_int
    rw [this]

theorem mv_zeros (m : Nat) : ∀ B : List (List Int), mv B (zeros m) = zeros B.length
  | [] => rfl
  | b :: bs => by
    show dot b (zeros m) :: mv bs (zeros m) = 0 :: zeros bs.length
    rw [dot_zeros_right, mv_zeros m bs]

theorem smul_zero (d : Int) (hd : d ≠ 0) : ∀ (g : List Int) (k : Nat), smul d g = zeros k → g = zeros g.length
  | [], _, _ => rfl
  | x :: xs, 0, h => by
    have h' : (d * x) :: smul d xs = [] := h
    nomatch h'
  | x :: xs, k + 1, h => by
    have h1 : d * x = 0 := List.cons.inj h |>.1
    have h2 : smul d xs = zeros k := List.cons.inj h |>.2
    have hx : x = 0 := by
      cases int_noZD d x h1 with
      | inl h => exact absurd h hd
      | inr h => exact h
    show x :: xs = 0 :: zeros xs.length
    rw [hx, smul_zero d hd xs k h2]
    rw [len_zeros]

/-- **Certificate lemma.** If the rows of B combine the rows of A (all of length n) to d · I with d ≠ 0,
    then every g of length n with A g = 0 is zero. -/
theorem kernel_zero (n : Nat) (d : Int) (hd : d ≠ 0) (A B : List (List Int))
    (hA : allLen n A = true) (hc : lcs n B A = sid d n)
    (g : List Int) (hg : g.length = n) (h0 : mv A g = zeros A.length) : g = zeros n := by
  have h1 : mv B (mv A g) = smul d g := by rw [mv_mv n A g hA, hc, mv_sid d n g hg]
  rw [h0, mv_zeros] at h1
  have h2 := smul_zero d hd g B.length h1.symm
  rw [hg] at h2
  exact h2

end MailletLin

#print axioms MailletLin.beq_eq
#print axioms MailletLin.and_left
#print axioms MailletLin.len_addV
#print axioms MailletLin.len_smul
#print axioms MailletLin.len_zeros
#print axioms MailletLin.dot_zeros_left
#print axioms MailletLin.len_lc
#print axioms MailletLin.dot_addV
#print axioms MailletLin.dot_smul
#print axioms MailletLin.dot_mv
#print axioms MailletLin.mv_mv
#print axioms MailletLin.mv_sid
#print axioms MailletLin.mv_zeros
#print axioms MailletLin.smul_zero
#print axioms MailletLin.kernel_zero

#print axioms: 15 theorems, no axioms.

81.218 Balanced characters of prime degree from a Maillet certificate

For \(p=q+1\): an invertibility certificate for \(A_{t,x}=2\langle tx\rangle -p\) and a finite check give, for every balanced list with entries in \((0,p)\), \(\#x=\#(p-x)\) for \(1\le x\le (p-1)/2\). Any length; the sum over the list is reorganised by induction on the list.

hodge/MailletBridge.lean

/-
  hodge/MailletBridge.lean — T41 cycle 1716 (goal G849c): balanced characters of degree p = q + 1 and the
  Maillet-type matrix A[t][x] = 2⟨t x⟩ − p (1 ≤ t, x ≤ h). For a list c with entries in (0, p) put
  G_x = #x(c) − #(p − x)(c). If c is balanced for 1 ≤ t ≤ h (2 T_t(c) = |c| p), then row_t · G = 0 for each t
  (given the finite check deltaOK: row_t · D(y) = 2⟨t y⟩ − p for 1 ≤ y ≤ q, where D(y) is G of the one-entry list).
  With an integer certificate B · A = d · I (hodge/MailletLin) this forces G = 0: every x has as many copies as
  p − x, i.e. c is a union of complementary pairs — at every length. Lean 4 core, hand proofs, no axioms.
-/
import hodge.MailletLin

namespace MailletBridge
open MailletLin LibInt

/-- s, s+1, …, s+k−1. -/
def rng : Nat → Nat → List Nat
  | _, 0 => []
  | s, k + 1 => s :: rng (s + 1) k

/-- Number of copies of x in a list. -/
def cnt (x : Nat) : List Nat → Nat
  | [] => 0
  | y :: l => cond (Nat.beq x y) 1 0 + cnt x l

def ind (b : Bool) : Int := cond b 1 0

/-- The sum T_t(c) = Σ ⟨t c_i⟩. -/
def tsum (m t : Nat) : List Nat → Nat
  | [] => 0
  | a :: l => (t * a) % m + tsum m t l

def rowA (p t : Nat) (xs : List Nat) : List Int := xs.map (fun x => 2 * (((t * x) % p : Nat) : Int) - p)

def Gv (p : Nat) (xs c : List Nat) : List Int := xs.map (fun x => (cnt x c : Int) - (cnt (p - x) c : Int))

def Dv (p : Nat) (xs : List Nat) (y : Nat) : List Int := xs.map (fun x => ind (Nat.beq x y) - ind (Nat.beq (p - x) y))

def sumT (p t : Nat) : List Nat → Int
  | [] => 0
  | y :: l => (2 * (((t * y) % p : Nat) : Int) - p) + sumT p t l

/-- Finite check for p = q + 1: row_t · D(y) = 2⟨t y⟩ − p for 1 ≤ t ≤ h, 1 ≤ y ≤ q. -/
def deltaOK (q h : Nat) : Bool :=
  (rng 1 h).all (fun t => (rng 1 q).all (fun y =>
    decide (dot (rowA (q + 1) t (rng 1 h)) (Dv (q + 1) (rng 1 h) y) = 2 * (((t * y) % (q + 1) : Nat) : Int) - (q + 1 : Nat))))

theorem len_map {α β : Type} (f : α → β) : ∀ xs : List α, (xs.map f).length = xs.length
  | [] => rfl
  | _ :: xs => congrArg (· + 1) (len_map f xs)

theorem len_rng : ∀ s k : Nat, (rng s k).length = k
  | _, 0 => rfl
  | s, k + 1 => congrArg (· + 1) (len_rng (s + 1) k)

theorem and_true_left : ∀ {a b : Bool}, (a && b) = true → a = true
  | true, _, _ => rfl
  | false, _, h => Bool.noConfusion h

theorem and_true_right : ∀ {a b : Bool}, (a && b) = true → b = true
  | true, _, h => h
  | false, _, h => Bool.noConfusion h

theorem le_cases {s y : Nat} (h : s ≤ y) : y = s ∨ s + 1 ≤ y := by
  cases h with
  | refl => exact Or.inl rfl
  | step h' => exact Or.inr (Nat.succ_le_succ h')

theorem succ_add' (s k : Nat) : s + 1 + k = s + (k + 1) := by
  induction k with
  | zero => rfl
  | succ k ih => exact congrArg (· + 1) ih

theorem lt_irrefl' : ∀ s : Nat, ¬ s < s
  | 0, h => Nat.noConfusion (Nat.eq_zero_of_le_zero h)
  | s + 1, h => lt_irrefl' s (Nat.le_of_succ_le_succ h)

/-- Every element of rng s k satisfies P when the Boolean check holds. -/
theorem all_rng (P : Nat → Bool) : ∀ (k s y : Nat), (rng s k).all P = true → s ≤ y → y < s + k → P y = true
  | 0, s, y, _, h1, h2 => absurd (Nat.lt_of_lt_of_le h2 h1) (lt_irrefl' y)
  | k + 1, s, y, h, h1, h2 => by
    have h' : (P s && (rng (s + 1) k).all P) = true := h
    cases le_cases h1 with
    | inl e => rw [e]; exact and_true_left h'
    | inr e =>
      apply all_rng P k (s + 1) y (and_true_right h') e
      rw [succ_add']; exact h2

theorem natCast_add (a b : Nat) : ((a + b : Nat) : Int) = (a : Int) + (b : Int) := rfl

theorem natCast_mul (a b : Nat) : ((a * b : Nat) : Int) = (a : Int) * (b : Int) := rfl

theorem cond_cast (b : Bool) : ((cond b 1 0 : Nat) : Int) = ind b := by
  cases b <;> rfl

theorem G_nil (p : Nat) : ∀ xs : List Nat, Gv p xs [] = zeros xs.length
  | [] => rfl
  | _ :: xs => by
    show (((0 : Nat) : Int) - ((0 : Nat) : Int)) :: Gv p xs [] = 0 :: zeros xs.length
    rw [G_nil p xs]
    rfl

theorem G_cons (p y : Nat) (l : List Nat) : ∀ xs : List Nat, Gv p xs (y :: l) = addV (Gv p xs l) (Dv p xs y)
  | [] => rfl
  | x :: xs => by
    show (((cond (Nat.beq x y) 1 0 + cnt x l : Nat) : Int) - ((cond (Nat.beq (p - x) y) 1 0 + cnt (p - x) l : Nat) : Int))
        :: Gv p xs (y :: l)
      = (((cnt x l : Int) - (cnt (p - x) l : Int)) + (ind (Nat.beq x y) - ind (Nat.beq (p - x) y)))
        :: addV (Gv p xs l) (Dv p xs y)
    rw [G_cons p y l xs, natCast_add, natCast_add, cond_cast, cond_cast]
    generalize ind (Nat.beq x y) = a
    generalize ind (Nat.beq (p - x) y) = b
    generalize ((cnt x l : Nat) : Int) = u
    generalize ((cnt (p - x) l : Nat) : Int) = v
    have e : a + u - (b + v) = u - v + (a - b) := by lib_int
    rw [e]

theorem dot_addV_r : ∀ r u v : List Int, u.length = v.length → dot r (addV u v) = dot r u + dot r v
  | [], _, _, _ => by
    show (0 : Int) = 0 + 0
    rfl
  | _ :: _, [], [], _ => by
    show (0 : Int) = 0 + 0
    rfl
  | _ :: _, [], _ :: _, h => Nat.noConfusion h
  | _ :: _, _ :: _, [], h => Nat.noConfusion h
  | a :: rs, x :: xs, y :: ys, h => by
    show a * (x + y) + dot rs (addV xs ys) = (a * x + dot rs xs) + (a * y + dot rs ys)
    rw [dot_addV_r rs xs ys (Nat.succ.inj h)]
    generalize dot rs xs = P
    generalize dot rs ys = Q
    lib_int

theorem decide_eq {a b : Int} (h : decide (a = b) = true) : a = b := of_decide_eq_true h

/-- row_t · G(c) = Σ_{y ∈ c} (2⟨t y⟩ − p), given the finite check. -/
theorem dot_G (q h t : Nat) (hD : deltaOK q h = true) (ht1 : 1 ≤ t) (ht2 : t < 1 + h) :
    ∀ c : List Nat, (∀ y, y ∈ c → 1 ≤ y ∧ y < 1 + q) →
      dot (rowA (q + 1) t (rng 1 h)) (Gv (q + 1) (rng 1 h) c) = sumT (q + 1) t c
  | [], _ => by
    rw [G_nil]
    exact dot_zeros_right _ _
  | y :: l, hc => by
    have hy := hc y (List.Mem.head l)
    have hl : ∀ z, z ∈ l → 1 ≤ z ∧ z < 1 + q := fun z hz => hc z (List.Mem.tail y hz)
    have hrow := all_rng _ h 1 t hD ht1 ht2
    have hdy := decide_eq (all_rng _ q 1 y hrow hy.1 hy.2)
    rw [G_cons, dot_addV_r _ _ _ (by rw [Gv, Dv, len_map, len_map]), hdy, dot_G q h t hD ht1 ht2 l hl]
    show sumT (q + 1) t l + (2 * (((t * y) % (q + 1) : Nat) : Int) - ((q + 1 : Nat) : Int))
      = (2 * (((t * y) % (q + 1) : Nat) : Int) - ((q + 1 : Nat) : Int)) + sumT (q + 1) t l
    exact i_add_comm _ _

theorem sumT_eq (p t : Nat) : ∀ c : List Nat,
    sumT p t c = ((tsum p t c : Nat) : Int) + ((tsum p t c : Nat) : Int) - ((c.length * p : Nat) : Int)
  | [] => by
    show (0 : Int) = 0 + 0 - 0 * ((p : Nat) : Int)
    generalize ((p : Nat) : Int) = P
    lib_int
  | y :: l => by
    show (2 * (((t * y) % p : Nat) : Int) - ((p : Nat) : Int)) + sumT p t l = _
    rw [sumT_eq p t l]
    show (2 * (((t * y) % p : Nat) : Int) - ((p : Nat) : Int))
        + (((tsum p t l : Nat) : Int) + ((tsum p t l : Nat) : Int) - ((l.length : Nat) : Int) * ((p : Nat) : Int))
      = (((t * y) % p : Nat) : Int) + ((tsum p t l : Nat) : Int) + ((((t * y) % p : Nat) : Int) + ((tsum p t l : Nat) : Int))
        - (((l.length : Nat) : Int) + 1) * ((p : Nat) : Int)
    generalize (((t * y) % p : Nat) : Int) = r
    generalize ((tsum p t l : Nat) : Int) = T
    generalize ((l.length : Nat) : Int) = L
    generalize ((p : Nat) : Int) = P
    lib_int

theorem sumT_zero (p t : Nat) (c : List Nat) (hb : tsum p t c + tsum p t c = c.length * p) : sumT p t c = 0 := by
  rw [sumT_eq, ← natCast_add, hb]
  generalize ((c.length * p : Nat) : Int) = z
  lib_int

/-- Rows with zero dot product give the zero vector. -/
theorem mv_rows (row : Nat → List Int) (g : List Int) :
    ∀ (k s : Nat), (∀ t, s ≤ t → t < s + k → dot (row t) g = 0) → mv ((rng s k).map row) g = zeros k
  | 0, _, _ => rfl
  | k + 1, s, hz => by
    show dot (row s) g :: mv ((rng (s + 1) k).map row) g = 0 :: zeros k
    have h0 : dot (row s) g = 0 := hz s (Nat.le_refl s) (Nat.succ_le_succ (Nat.le_add_right s k))
    have h1 : mv ((rng (s + 1) k).map row) g = zeros k := by
      apply mv_rows row g k (s + 1)
      intro t ht1 ht2
      apply hz t (Nat.le_of_succ_le ht1)
      rw [← succ_add']; exact ht2
    rw [h0, h1]

theorem beq_refl : ∀ a : Nat, Nat.beq a a = true
  | 0 => rfl
  | a + 1 => beq_refl a

theorem sub_zero_eq (a b : Nat) (h : (a : Int) - (b : Int) = 0) : a = b := by
  have e : (a : Int) = ((a : Int) - (b : Int)) + (b : Int) := by
    generalize (a : Int) = u
    generalize (b : Int) = v
    lib_int
  rw [h] at e
  have e2 : (a : Int) = (b : Int) := by
    rw [e]
    generalize (b : Int) = v
    lib_int
  exact Int.ofNat.inj e2

theorem all_of_zero (p : Nat) (c : List Nat) : ∀ xs : List Nat, Gv p xs c = zeros xs.length →
    xs.all (fun x => Nat.beq (cnt x c) (cnt (p - x) c)) = true
  | [], _ => rfl
  | x :: xs, h => by
    have h1 : (cnt x c : Int) - (cnt (p - x) c : Int) = 0 := (List.cons.inj h).1
    have h2 : Gv p xs c = zeros xs.length := (List.cons.inj h).2
    show (Nat.beq (cnt x c) (cnt (p - x) c) && xs.all (fun x => Nat.beq (cnt x c) (cnt (p - x) c))) = true
    rw [sub_zero_eq _ _ h1, beq_refl, all_of_zero p c xs h2]
    rfl

/-- **Bridge.** For p = q + 1, an invertibility certificate for A[t][x] = 2⟨t x⟩ − p (1 ≤ t, x ≤ h) and the
    finite check deltaOK, every list with entries in (0, p) that is balanced for 1 ≤ t ≤ h has
    #x = #(p − x) for 1 ≤ x ≤ h: it is a union of complementary pairs. -/
theorem pairs_of_bal (q h : Nat) (d : Int) (hd : d ≠ 0) (A B : List (List Int))
    (hA : allLen h A = true) (hc : lcs h B A = sid d h)
    (hAdef : A = (rng 1 h).map (fun t => rowA (q + 1) t (rng 1 h))) (hD : deltaOK q h = true)
    (c : List Nat) (hr : ∀ y, y ∈ c → 0 < y ∧ y < q + 1)
    (hb : ∀ t, 1 ≤ t → t < 1 + h → tsum (q + 1) t c + tsum (q + 1) t c = c.length * (q + 1)) :
    (rng 1 h).all (fun x => Nat.beq (cnt x c) (cnt (q + 1 - x) c)) = true := by
  have hr' : ∀ y, y ∈ c → 1 ≤ y ∧ y < 1 + q := fun y hy =>
    ⟨(hr y hy).1, by rw [Nat.add_comm]; exact (hr y hy).2⟩
  have hz : mv A (Gv (q + 1) (rng 1 h) c) = zeros A.length := by
    rw [hAdef, len_map, len_rng]
    apply mv_rows _ _ h 1
    intro t ht1 ht2
    rw [dot_G q h t hD ht1 ht2 c hr']
    exact sumT_zero _ _ _ (hb t ht1 ht2)
  have hg : (Gv (q + 1) (rng 1 h) c).length = h := by rw [Gv, len_map, len_rng]
  have h0 := kernel_zero h d hd A B hA hc _ hg hz
  apply all_of_zero (q + 1) c (rng 1 h)
  rw [len_rng]; exact h0

end MailletBridge

#print axioms MailletBridge.all_rng
#print axioms MailletBridge.G_cons
#print axioms MailletBridge.dot_addV_r
#print axioms MailletBridge.dot_G
#print axioms MailletBridge.sumT_eq
#print axioms MailletBridge.sumT_zero
#print axioms MailletBridge.mv_rows
#print axioms MailletBridge.sub_zero_eq
#print axioms MailletBridge.all_of_zero
#print axioms MailletBridge.pairs_of_bal

#print axioms: 10 theorems, no axioms.

81.219 Length-4 pair characters for \(p=79\) (Kamiak)

Every balanced length-4 character of the degree-79 Fermat surface is two complementary pairs; 78 first-entry pieces in 8 files.

hodge/Pairs4n.lean

/-
  hodge/Pairs4n.lean — T41 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 79: every
  balanced length-4 character of the degree-79 Fermat surface is a union of two complementary pairs. The single rfl
  ran out of memory at 64G, so the check is split by the first entry (Pairs4Split.badQ_split) into the pieces
  hodge/Pairs4nS1 … S8, each rfl.

  Lean 4 core plus hodge/Pairs4Split, hodge/Pairs4nS1–S8.
-/
import hodge.Pairs4Split
import hodge.Pairs4nS1
import hodge.Pairs4nS2
import hodge.Pairs4nS3
import hodge.Pairs4nS4
import hodge.Pairs4nS5
import hodge.Pairs4nS6
import hodge.Pairs4nS7
import hodge.Pairs4nS8

namespace Pairs4n

set_option maxHeartbeats 0 in
set_option maxRecDepth 1000000 in
theorem r79 : Pairs4.badQ 79 = [] := by
  rw [Pairs4Split.badQ_split]
  show Pairs4Split.badQAt 79 1 ++ (Pairs4Split.badQAt 79 2 ++ (Pairs4Split.badQAt 79 3 ++ (Pairs4Split.badQAt 79 4 ++ (Pairs4Split.badQAt 79 5 ++ (Pairs4Split.badQAt 79 6 ++ (Pairs4Split.badQAt 79 7 ++ (Pairs4Split.badQAt 79 8 ++ (Pairs4Split.badQAt 79 9 ++ (Pairs4Split.badQAt 79 10 ++ (Pairs4Split.badQAt 79 11 ++ (Pairs4Split.badQAt 79 12 ++ (Pairs4Split.badQAt 79 13 ++ (Pairs4Split.badQAt 79 14   -- (+1945 chars; full line in the Zenodo source)
  rw [Pairs4nS1.x1, Pairs4nS1.x2, Pairs4nS1.x3, Pairs4nS1.x4, Pairs4nS1.x5, Pairs4nS1.x6, Pairs4nS1.x7, Pairs4nS1.x8, Pairs4nS1.x9, Pairs4nS1.x10, Pairs4nS1.x11, Pairs4nS2.x12, Pairs4nS2.x13, Pairs4nS2.x14, Pairs4nS2.x15, Pairs4nS2.x16, Pairs4nS2.x17, Pairs4nS2.x18, Pairs4nS2.x19, Pairs4nS2.x20, Pairs4nS2.x21, Pairs4nS2.x22, Pairs4nS3.x23, Pairs4nS3.x24, Pairs4nS3.x25, Pairs4nS3.x26, Pairs4nS3.x27  -- (+766 chars; full line in the Zenodo source)
  rfl

end Pairs4n

#print axioms Pairs4n.r79

#print axioms: 1 theorem, no axioms (pieces Pairs4nS1–S8: 78 theorems, no axioms).

81.220 Length-4 pair characters for \(p=83\) (Kamiak)

Every balanced length-4 character of the degree-83 Fermat surface is two complementary pairs; 82 first-entry pieces in 8 files.

hodge/Pairs4o.lean

/-
  hodge/Pairs4o.lean — T41 (goal G529b, finite path, Kamiak): Pairs4 extended to the prime p = 83: every
  balanced length-4 character of the degree-83 Fermat surface is a union of two complementary pairs. The single rfl
  ran out of memory at 64G, so the check is split by the first entry (Pairs4Split.badQ_split) into the pieces
  hodge/Pairs4oS1 … S8, each rfl.

  Lean 4 core plus hodge/Pairs4Split, hodge/Pairs4oS1–S8.
-/
import hodge.Pairs4Split
import hodge.Pairs4oS1
import hodge.Pairs4oS2
import hodge.Pairs4oS3
import hodge.Pairs4oS4
import hodge.Pairs4oS5
import hodge.Pairs4oS6
import hodge.Pairs4oS7
import hodge.Pairs4oS8

namespace Pairs4o

set_option maxHeartbeats 0 in
set_option maxRecDepth 1000000 in
theorem r83 : Pairs4.badQ 83 = [] := by
  rw [Pairs4Split.badQ_split]
  show Pairs4Split.badQAt 83 1 ++ (Pairs4Split.badQAt 83 2 ++ (Pairs4Split.badQAt 83 3 ++ (Pairs4Split.badQAt 83 4 ++ (Pairs4Split.badQAt 83 5 ++ (Pairs4Split.badQAt 83 6 ++ (Pairs4Split.badQAt 83 7 ++ (Pairs4Split.badQAt 83 8 ++ (Pairs4Split.badQAt 83 9 ++ (Pairs4Split.badQAt 83 10 ++ (Pairs4Split.badQAt 83 11 ++ (Pairs4Split.badQAt 83 12 ++ (Pairs4Split.badQAt 83 13 ++ (Pairs4Split.badQAt 83 14   -- (+2065 chars; full line in the Zenodo source)
  rw [Pairs4oS1.x1, Pairs4oS1.x2, Pairs4oS1.x3, Pairs4oS1.x4, Pairs4oS1.x5, Pairs4oS1.x6, Pairs4oS1.x7, Pairs4oS1.x8, Pairs4oS1.x9, Pairs4oS1.x10, Pairs4oS1.x11, Pairs4oS2.x12, Pairs4oS2.x13, Pairs4oS2.x14, Pairs4oS2.x15, Pairs4oS2.x16, Pairs4oS2.x17, Pairs4oS2.x18, Pairs4oS2.x19, Pairs4oS2.x20, Pairs4oS2.x21, Pairs4oS2.x22, Pairs4oS3.x23, Pairs4oS3.x24, Pairs4oS3.x25, Pairs4oS3.x26, Pairs4oS3.x27  -- (+826 chars; full line in the Zenodo source)
  rfl

end Pairs4o

#print axioms Pairs4o.r83

#print axioms: 1 theorem, no axioms (pieces Pairs4oS1–S8: 82 theorems, no axioms).

81.221 From count symmetry to complementary pairs and \(2+4\) splits

A list symmetric under \(x\mapsto m-x\) with entries in \((0,m)\), \(m\) odd, passes allPairs; a balanced symmetric 6-list has a \(2+4\) split. With the Maillet certificates this gives G529b (any length) and G526b for each certified prime.

hodge/MailletSplit.lean

/-
  hodge/MailletSplit.lean — T41 cycle 1726 (goal G849e): from the count symmetry of MailletBridge (#x = #(m − x)
  for 1 ≤ x ≤ h, m = 2h + 1) to complementary pairs in the sense of PairsSplit.allPairs, hence (length 6) to a
  2 + 4 split (has24, G526b). Lean 4 core, hand proofs, no axioms.
    sym_of_all     the Boolean check over 1 ≤ x ≤ h gives #x = #y whenever x + y = m, 0 < x, 0 < y
    cnt_erase      a ∈ l ⇒ #z(l) = #z(l.erase a) + [z = a]
    sym_erase      the symmetry survives removing one complementary pair
    pairs_of_sym   symmetric lists with entries in (0, m), m odd, pass allPairs
    split24_of_sym a symmetric balanced 6-list has a 2 + 4 split
-/
import hodge.MailletBridge
import hodge.PairsSplit
import hodge.FermatPrime

namespace MailletSplit
open MailletBridge PairsSplit

/-- Count symmetry under x ↦ m − x (positive residues). -/
def Sym (m : Nat) (c : List Nat) : Prop := ∀ x y, 0 < x → 0 < y → x + y = m → cnt x c = cnt y c

theorem beq_true {a b : Nat} (h : Nat.beq a b = true) : a = b := MailletLin.beq_eq a b h

theorem beq_false {a b : Nat} (h : a ≠ b) : Nat.beq a b = false := by
  cases e : Nat.beq a b with
  | false => rfl
  | true => exact absurd (beq_true e) h

theorem add_sub_left' : ∀ x y : Nat, (x + y) - x = y
  | 0, y => by rw [Nat.zero_add]; rfl
  | x + 1, y => by rw [Nat.succ_add, Nat.succ_sub_succ]; exact add_sub_left' x y

theorem add_sub_of_le' : ∀ x m : Nat, x ≤ m → x + (m - x) = m
  | 0, m, _ => by rw [Nat.zero_add]; rfl
  | _ + 1, 0, h => absurd h (Nat.not_succ_le_zero _)
  | x + 1, m + 1, h => by
    rw [Nat.succ_sub_succ, Nat.succ_add, add_sub_of_le' x m (Nat.le_of_succ_le_succ h)]

theorem lt_irr : ∀ n : Nat, ¬ n < n := MailletBridge.lt_irrefl'

theorem sym_half (h : Nat) (c : List Nat)
    (hall : (rng 1 h).all (fun x => Nat.beq (cnt x c) (cnt (h + h + 1 - x) c)) = true)
    (x y : Nat) (hx : 0 < x) (hxh : x < h + 1) (hxy : x + y = h + h + 1) : cnt x c = cnt y c := by
  have hb := all_rng _ h 1 x hall hx (by rw [Nat.add_comm]; exact hxh)
  have e := beq_true hb
  rw [← hxy, add_sub_left'] at e
  exact e

theorem sym_of_all (h : Nat) (c : List Nat)
    (hall : (rng 1 h).all (fun x => Nat.beq (cnt x c) (cnt (h + h + 1 - x) c)) = true) : Sym (h + h + 1) c := by
  intro x y hx hy hxy
  cases Nat.lt_or_ge x (h + 1) with
  | inl hl => exact sym_half h c hall x y hx hl hxy
  | inr hg =>
    cases Nat.lt_or_ge y (h + 1) with
    | inl hl => exact (sym_half h c hall y x hy hl (by rw [Nat.add_comm]; exact hxy)).symm
    | inr hg' =>
      have s := Nat.add_le_add hg hg'
      rw [hxy] at s
      have e : h + 1 + (h + 1) = (h + h + 1) + 1 := by lib_nat
      rw [e] at s
      exact absurd s (lt_irr _)

theorem cnt_pos_contains (y : Nat) : ∀ l : List Nat, 0 < cnt y l → l.contains y = true
  | [], h => absurd h (lt_irr 0)
  | b :: l, h => by
    cases hyb : Nat.beq y b with
    | true =>
      have e : y = b := beq_true hyb
      rw [← e]
      show (match y == y with | true => true | false => l.contains y) = true
      rw [show (y == y) = true from FamBal.beq_refl' y]
    | false =>
      have h' : 0 < cond (Nat.beq y b) 1 0 + cnt y l := h
      rw [hyb] at h'
      have h2 : 0 < cnt y l := by
        rw [show (cond false 1 0 : Nat) + cnt y l = cnt y l from Nat.zero_add _] at h'
        exact h'
      have hb : (y == b) = false := hyb
      show (match y == b with | true => true | false => l.contains y) = true
      rw [hb]
      exact cnt_pos_contains y l h2

theorem cnt_erase (z a : Nat) : ∀ l : List Nat, l.contains a = true →
    cnt z l = cnt z (l.erase a) + cond (Nat.beq z a) 1 0
  | [], h => Bool.noConfusion h
  | b :: l, h => by
    cases hab : (a == b) with
    | true =>
      have e : a = b := Nat.eq_of_beq_eq_true hab
      rw [← e, erase_head]
      show cond (Nat.beq z a) 1 0 + cnt z l = cnt z l + cond (Nat.beq z a) 1 0
      exact Nat.add_comm _ _
    | false =>
      rw [erase_tail a b l hab]
      show cond (Nat.beq z b) 1 0 + cnt z l = (cond (Nat.beq z b) 1 0 + cnt z (l.erase a)) + cond (Nat.beq z a) 1 0
      rw [cnt_erase z a l (contains_tail a b l hab h), Nat.add_assoc]

/-- z + w = x + y: z = x exactly when w = y. -/
theorem cond_match (x y z w : Nat) (e : z + w = x + y) : cond (Nat.beq z x) 1 0 = cond (Nat.beq w y) 1 0 := by
  cases hz : Nat.beq z x with
  | true =>
    have ez : z = x := beq_true hz
    rw [ez] at e
    rw [BalAppend.add_cancel x w y e, FamBal.beq_refl']
  | false =>
    cases hw : Nat.beq w y with
    | false => rfl
    | true =>
      have ew : w = y := beq_true hw
      rw [ew, Nat.add_comm z y, Nat.add_comm x y] at e
      have ez := BalAppend.add_cancel y z x e
      rw [ez, FamBal.beq_refl'] at hz
      exact Bool.noConfusion hz

theorem sym_erase (m x y : Nat) (l : List Nat) (hxy : x + y = m) (hs : Sym m (x :: l)) (hc : l.contains y = true) :
    Sym m (l.erase y) := by
  intro z w hz hw hzw
  have h1 := hs z w hz hw hzw
  have h1' : cond (Nat.beq z x) 1 0 + cnt z l = cond (Nat.beq w x) 1 0 + cnt w l := h1
  rw [cnt_erase z y l hc, cnt_erase w y l hc] at h1'
  have a1 : cond (Nat.beq z x) 1 0 = cond (Nat.beq w y) 1 0 := cond_match x y z w (by rw [hzw, hxy])
  have a2 : cond (Nat.beq z y) 1 0 = cond (Nat.beq w x) 1 0 :=
    cond_match y x z w (by rw [hzw, ← hxy, Nat.add_comm])
  rw [a1, a2] at h1'
  have e1 : cond (Nat.beq w y) 1 0 + (cnt z (l.erase y) + cond (Nat.beq w x) 1 0)
      = (cond (Nat.beq w y) 1 0 + cond (Nat.beq w x) 1 0) + cnt z (l.erase y) := by lib_nat
  have e2 : cond (Nat.beq w x) 1 0 + (cnt w (l.erase y) + cond (Nat.beq w y) 1 0)
      = (cond (Nat.beq w y) 1 0 + cond (Nat.beq w x) 1 0) + cnt w (l.erase y) := by lib_nat
  rw [e1, e2] at h1'
  exact BalAppend.add_cancel _ _ _ h1'

theorem inR_pos {m x : Nat} (h : inR m x = true) : 0 < x := Nat.le_of_ble_eq_true (andL h)

theorem inR_lt {m x : Nat} (h : inR m x = true) : x < m := Nat.le_of_ble_eq_true (andR h)

/-- Symmetric lists with entries in (0, m), m odd, are unions of complementary pairs. -/
theorem pairs_of_sym (m : Nat) (hodd : ∀ x, x + x ≠ m) : ∀ (f : Nat) (c : List Nat), c.length ≤ f →
    c.all (inR m) = true → Sym m c → allPairs m (f + 1) c = true
  | _, [], _, _, _ => rfl
  | 0, _ :: _, hl, _, _ => absurd hl (Nat.not_succ_le_zero _)
  | f + 1, x :: l, hl, hr, hs => by
    have hr' : (inR m x && l.all (inR m)) = true := hr
    have hx0 := inR_pos (andL hr')
    have hxm := inR_lt (andL hr')
    have hxy : x + (m - x) = m := add_sub_of_le' x m (Nat.le_of_lt hxm)
    have hy0 : 0 < m - x := by
      cases Nat.eq_zero_or_pos (m - x) with
      | inl e => rw [e, Nat.add_zero] at hxy; rw [hxy] at hxm; exact absurd hxm (lt_irr m)
      | inr p => exact p
    have hne : m - x ≠ x := fun e => hodd x (by rw [e] at hxy; exact hxy)
    have hc1 : cnt (m - x) (x :: l) = cnt x (x :: l) := (hs x (m - x) hx0 hy0 hxy).symm
    have hc2 : cnt x (x :: l) = 1 + cnt x l := by
      show cond (Nat.beq x x) 1 0 + cnt x l = 1 + cnt x l
      rw [FamBal.beq_refl']; rfl
    have hc3 : cnt (m - x) (x :: l) = cnt (m - x) l := by
      show cond (Nat.beq (m - x) x) 1 0 + cnt (m - x) l = cnt (m - x) l
      rw [beq_false hne]
      exact Nat.zero_add _
    have hpos : 0 < cnt (m - x) l := by
      rw [← hc3, hc1, hc2, Nat.add_comm]; exact Nat.succ_pos _
    have hcon := cnt_pos_contains (m - x) l hpos
    have hl' : (l.erase (m - x)).length ≤ f := by
      have e := len_erase (m - x) l hcon
      have hl2 : l.length ≤ f := Nat.le_of_succ_le_succ hl
      rw [← e] at hl2
      exact Nat.le_of_succ_le hl2
    have ih := pairs_of_sym m hodd f (l.erase (m - x)) hl' (all_erase _ _ l (andR hr'))
      (sym_erase m x (m - x) l hxy hs hcon)
    show (l.contains (m - x) && allPairs m (f + 1) (l.erase (m - x))) = true
    rw [hcon, ih]
    rfl

/-- **2 + 4 split from the symmetry.** -/
theorem split24_of_sym (m' : Nat) (hodd : ∀ x, x + x ≠ m' + 1) (c : List Nat) (h6 : c.length = 6)
    (hr : c.all (inR (m' + 1)) = true) (hs : Sym (m' + 1) c) : Split24.has24 (m' + 1) c = true := by
  have hp := pairs_of_sym (m' + 1) hodd 6 c (by rw [h6]; exact Nat.le_refl 6) hr hs
  cases c with
  | nil => exact Nat.noConfusion h6
  | cons x l => exact has24_of_pairs m' x l hr hp

theorem odd_ne : ∀ x h : Nat, x + x ≠ h + h + 1
  | 0, h, e => by
    have e' : 0 = (h + h) + 1 := e
    exact Nat.noConfusion e'
  | x + 1, 0, e => by
    have e' : (x + x + 1) + 1 = 0 + 1 := by rw [← e]; lib_nat
    have e2 := Nat.succ.inj e'
    exact Nat.noConfusion e2
  | x + 1, h + 1, e => by
    have e' : (x + x) + 2 = (h + h + 1) + 2 := by
      have a : (x + 1) + (x + 1) = (x + x) + 2 := by lib_nat
      have b : (h + 1) + (h + 1) + 1 = (h + h + 1) + 2 := by lib_nat
      rw [← a, ← b]; exact e
    exact odd_ne x h (Nat.succ.inj (Nat.succ.inj e'))

theorem all_mem (P : Nat → Bool) (y : Nat) : ∀ l : List Nat, l.all P = true → y ∈ l → P y = true
  | [], _, hm => nomatch hm
  | b :: l, h, hm => by
    have h' : (P b && l.all P) = true := h
    cases hm with
    | head => exact andL h'
    | tail _ hm' => exact all_mem P y l (andR h') hm'

theorem all_contains (P : Nat → Bool) (t : Nat) : ∀ l : List Nat, l.all P = true → l.contains t = true → P t = true
  | [], _, hc => Bool.noConfusion hc
  | b :: l, h, hc => by
    have h' : (P b && l.all P) = true := h
    cases htb : (t == b) with
    | true =>
      have e : t = b := Nat.eq_of_beq_eq_true htb
      rw [e]; exact andL h'
    | false => exact all_contains P t l (andR h') (contains_tail t b l htb hc)

theorem tsum_same (m t : Nat) : ∀ c : List Nat, Indecomp.tsum m t c = MailletBridge.tsum m t c
  | [] => rfl
  | a :: l => by
    show (t * a) % m + Indecomp.tsum m t l = (t * a) % m + MailletBridge.tsum m t l
    rw [tsum_same m t l]

/-- Balance over all units gives the balance for 1 ≤ t ≤ h, once those t are checked to be units. -/
theorem bal_half (m h : Nat) (hU : (rng 1 h).all (fun t => (FermatPrime.units m).contains t) = true)
    (c : List Nat) (hb : Indecomp.bal m c = true) :
    ∀ t, 1 ≤ t → t < 1 + h → MailletBridge.tsum m t c + MailletBridge.tsum m t c = c.length * m := by
  intro t h1 h2
  have hu := all_rng _ h 1 t hU h1 h2
  have hb' := all_contains _ t _ hb hu
  have e := beq_true hb'
  rw [tsum_same] at e
  exact e

theorem inR_all (m : Nat) (c : List Nat) (hr : c.all (inR m) = true) : ∀ y, y ∈ c → 0 < y ∧ y < m :=
  fun y hy => ⟨inR_pos (all_mem _ y c hr hy), inR_lt (all_mem _ y c hr hy)⟩

end MailletSplit

#print axioms MailletSplit.add_sub_left'
#print axioms MailletSplit.add_sub_of_le'
#print axioms MailletSplit.sym_of_all
#print axioms MailletSplit.cnt_pos_contains
#print axioms MailletSplit.cnt_erase
#print axioms MailletSplit.cond_match
#print axioms MailletSplit.sym_erase
#print axioms MailletSplit.pairs_of_sym
#print axioms MailletSplit.split24_of_sym
#print axioms MailletSplit.odd_ne
#print axioms MailletSplit.all_mem
#print axioms MailletSplit.all_contains
#print axioms MailletSplit.tsum_same
#print axioms MailletSplit.bal_half
#print axioms MailletSplit.inR_all

#print axioms: 15 theorems, no axioms.

81.222 Maillet certificates for odd primes \(p\le 97\) (Kamiak)

For each odd prime \(p\le 97\): \(B\cdot A=d\cdot I\) for \(A_{t,x}=2\langle tx\rangle -p\), the finite check, and pairs: balanced lists are symmetric under \(x\mapsto p-x\) at every length. Generated by tools/maillet_cert.py; the largest (\(p=97\), \(48\times 48\)) checks in about four minutes.

hodge/MailletCert13.lean

/-
  hodge/MailletCert13.lean — T41 (goals G849b, G849c): for p = 13 the 6 × 6 matrix A[t][x] = 2⟨t x⟩ − p (1 ≤ t, x ≤ 6)
  is invertible over ℚ: an integer matrix B with B · A = d · I, d = 26 (tools/maillet_cert.py). With the finite
  check deltaOK and hodge/MailletBridge: every balanced list with entries in (0, 13) is a union of complementary
  pairs, at every length. Lean 4 core, rfl.
-/
import hodge.MailletBridge

set_option maxHeartbeats 0

namespace MailletCert13
open MailletLin MailletBridge

def A : List (List Int) := [
  [-11, -9, -7, -5, -3, -1],
  [-9, -5, -1, 3, 7, 11],
  [-7, -1, 5, 11, -9, -3],
  [-5, 3, 11, -7, 1, 9],
  [-3, 7, -9, 1, 11, -5],
  [-1, 11, -3, 9, -5, 7]]

def B : List (List Int) := [
  [-1, 0, -1, -1, -1, 0],
  [0, -1, 0, 1, 1, 1],
  [-1, 0, 1, 1, 0, -1],
  [-1, 1, 1, -1, 0, 0],
  [-1, 1, 0, 0, 1, -1],
  [0, 1, -1, 0, -1, 1]]

theorem A_def : A = (rng 1 6).map (fun t => rowA (12 + 1) t (rng 1 6)) := rfl
theorem len : allLen 6 A = true := rfl
set_option maxRecDepth 100000 in
theorem cert : lcs 6 B A = sid 26 6 := rfl

theorem d_ne : (26 : Int) ≠ 0 := by
  intro h
  have h' : false = true := congrArg (fun z : Int => Nat.beq z.natAbs 0) h
  exact Bool.noConfusion h'

/-- Every g of length 6 with A g = 0 is zero. -/
theorem kernel (g : List Int) (hg : g.length = 6) (h0 : mv A g = zeros 6) : g = zeros 6 :=
  kernel_zero 6 26 d_ne A B len cert g hg h0

set_option maxRecDepth 100000 in
theorem delta : deltaOK 12 6 = true := rfl

/-- **Balanced ⇒ pairs for p = 13.** A list with entries in (0, 13) that is balanced for 1 ≤ t ≤ 6
    has as many copies of x as of 13 − x for every 1 ≤ x ≤ 6 (any length). -/
theorem pairs (c : List Nat) (hr : ∀ y, y ∈ c → 0 < y ∧ y < 13)
    (hb : ∀ t, 1 ≤ t → t < 1 + 6 → tsum 13 t c + tsum 13 t c = c.length * 13) :
    (rng 1 6).all (fun x => Nat.beq (cnt x c) (cnt (13 - x) c)) = true :=
  pairs_of_bal 12 6 26 d_ne A B len cert A_def delta c hr hb

end MailletCert13

#print axioms MailletCert13.A_def
#print axioms MailletCert13.len
#print axioms MailletCert13.cert
#print axioms MailletCert13.d_ne
#print axioms MailletCert13.kernel
#print axioms MailletCert13.delta
#print axioms MailletCert13.pairs

#print axioms: 24 files, 7 theorems each, no axioms.

81.223 Maillet certificates for \(101\le p\le 113\) (Kamiak)

The same certificates for \(p=101,103,107,109,113\): \(B\cdot A=d\cdot I\), the finite check, and pairs. Shown for \(p=101\).

hodge/MailletCert101.lean

/-
  hodge/MailletCert101.lean — T41 (goals G849b, G849c): for p = 101 the 50 × 50 matrix A[t][x] = 2⟨t x⟩ − p (1 ≤ t, x ≤ 50)
  is invertible over ℚ: an integer matrix B with B · A = d · I, d = 28663027375250 (tools/maillet_cert.py). With the finite
  check deltaOK and hodge/MailletBridge: every balanced list with entries in (0, 101) is a union of complementary
  pairs, at every length. Lean 4 core, rfl.
-/
import hodge.MailletBridge

set_option maxHeartbeats 0

namespace MailletCert101
open MailletLin MailletBridge

def A : List (List Int) := [
  [-99, -97, -95, -93, -91, -89, -87, -85, -83, -81, -79, -77, -75, -73, -71, -69, -67, -65, -63, -61, -59, -57, -55, -53, -51, -49, -47, -45, -43, -41, -39, -37, -35, -33, -31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1],
  [-97, -93, -89, -85, -81, -77, -73, -69, -65, -61, -57, -53, -49, -45, -41, -37, -33, -29, -25, -21, -17, -13, -9, -5, -1, 3, 7, 11, 15, 19, 23, 27, 31, 35, 39, 43, 47, 51, 55, 59, 63, 67, 71, 75, 79, 83, 87, 91, 95, 99],
  [-95, -89, -83, -77, -71, -65, -59, -53, -47, -41, -35, -29, -23, -17, -11, -5, 1, 7, 13, 19, 25, 31, 37, 43, 49, 55, 61, 67, 73, 79, 85, 91, 97, -99, -93, -87, -81, -75, -69, -63, -57, -51, -45, -39, -33, -27, -21, -15, -9, -3],
  [-93, -85, -77, -69, -61, -53, -45, -37, -29, -21, -13, -5, 3, 11, 19, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, -95, -87, -79, -71, -63, -55, -47, -39, -31, -23, -15, -7, 1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97],
  [-91, -81, -71, -61, -51, -41, -31, -21, -11, -1, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, -93, -83, -73, -63, -53, -43, -33, -23, -13, -3, 7, 17, 27, 37, 47, 57, 67, 77, 87, 97, -95, -85, -75, -65, -55, -45, -35, -25, -15, -5],
  [-89, -77, -65, -53, -41, -29, -17, -5, 7, 19, 31, 43, 55, 67, 79, 91, -99, -87, -75, -63, -51, -39, -27, -15, -3, 9, 21, 33, 45, 57, 69, 81, 93, -97, -85, -73, -61, -49, -37, -25, -13, -1, 11, 23, 35, 47, 59, 71, 83, 95],
  [-87, -73, -59, -45, -31, -17, -3, 11, 25, 39, 53, 67, 81, 95, -93, -79, -65, -51, -37, -23, -9, 5, 19, 33, 47, 61, 75, 89, -99, -85, -71, -57, -43, -29, -15, -1, 13, 27, 41, 55, 69, 83, 97, -91, -77, -63, -49, -35, -21, -7],
  [-85, -69, -53, -37, -21, -5, 11, 27, 43, 59, 75, 91, -95, -79, -63, -47, -31, -15, 1, 17, 33, 49, 65, 81, 97, -89, -73, -57, -41, -25, -9, 7, 23, 39, 55, 71, 87, -99, -83, -67, -51, -35, -19, -3, 13, 29, 45, 61, 77, 93],
  [-83, -65, -47, -29, -11, 7, 25, 43, 61, 79, 97, -87, -69, -51, -33, -15, 3, 21, 39, 57, 75, 93, -91, -73, -55, -37, -19, -1, 17, 35, 53, 71, 89, -95, -77, -59, -41, -23, -5, 13, 31, 49, 67, 85, -99, -81, -63, -45, -27, -9],
  [-81, -61, -41, -21, -1, 19, 39, 59, 79, 99, -83, -63, -43, -23, -3, 17, 37, 57, 77, 97, -85, -65, -45, -25, -5, 15, 35, 55, 75, 95, -87, -67, -47, -27, -7, 13, 33, 53, 73, 93, -89, -69, -49, -29, -9, 11, 31, 51, 71, 91],
  [-79, -57, -35, -13, 9, 31, 53, 75, 97, -83, -61, -39, -17, 5, 27, 49, 71, 93, -87, -65, -43, -21, 1, 23, 45, 67, 89, -91, -69, -47, -25, -3, 19, 41, 63, 85, -95, -73, -51, -29, -7, 15, 37, 59, 81, -99, -77, -55, -33, -11],
  [-77, -53, -29, -5, 19, 43, 67, 91, -87, -63, -39, -15, 9, 33, 57, 81, -97, -73, -49, -25, -1, 23, 47, 71, 95, -83, -59, -35, -11, 13, 37, 61, 85, -93, -69, -45, -21, 3, 27, 51, 75, 99, -79, -55, -31, -7, 17, 41, 65, 89],
  [-75, -49, -23, 3, 29, 55, 81, -95, -69, -43, -17, 9, 35, 61, 87, -89, -63, -37, -11, 15, 41, 67, 93, -83, -57, -31, -5, 21, 47, 73, 99, -77, -51, -25, 1, 27, 53, 79, -97, -71, -45, -19, 7, 33, 59, 85, -91, -65, -39, -13],
  [-73, -45, -17, 11, 39, 67, 95, -79, -51, -23, 5, 33, 61, 89, -85, -57, -29, -1, 27, 55, 83, -91, -63, -35, -7, 21, 49, 77, -97, -69, -41, -13, 15, 43, 71, 99, -75, -47, -19, 9, 37, 65, 93, -81, -53, -25, 3, 31, 59, 87],
  [-71, -41, -11, 19, 49, 79, -93, -63, -33, -3, 27, 57, 87, -85, -55, -25, 5, 35, 65, 95, -77, -47, -17, 13, 43, 73, -99, -69, -39, -9, 21, 51, 81, -91, -61, -31, -1, 29, 59, 89, -83, -53, -23, 7, 37, 67, 97, -75, -45, -15],
  [-69, -37, -5, 27, 59, 91, -79, -47, -15, 17, 49, 81, -89, -57, -25, 7, 39, 71, -99, -67, -35, -3, 29, 61, 93, -77, -45, -13, 19, 51, 83, -87, -55, -23, 9, 41, 73, -97, -65, -33, -1, 31, 63, 95, -75, -43, -11, 21, 53, 85],
  [-67, -33, 1, 35, 69, -99, -65, -31, 3, 37, 71, -97, -63, -29, 5, 39, 73, -95, -61, -27, 7, 41, 75, -93, -59, -25, 9, 43, 77, -91, -57, -23, 11, 45, 79, -89, -55, -21, 13, 47, 81, -87, -53, -19, 15, 49, 83, -85, -51, -17],
  [-65, -29, 7, 43, 79, -87, -51, -15, 21, 57, 93, -73, -37, -1, 35, 71, -95, -59, -23, 13, 49, 85, -81, -45, -9, 27, 63, 99, -67, -31, 5, 41, 77, -89, -53, -17, 19, 55, 91, -75, -39, -3, 33, 69, -97, -61, -25, 11, 47, 83],
  [-63, -25, 13, 51, 89, -75, -37, 1, 39, 77, -87, -49, -11, 27, 65, -99, -61, -23, 15, 53, 91, -73, -35, 3, 41, 79, -85, -47, -9, 29, 67, -97, -59, -21, 17, 55, 93, -71, -33, 5, 43, 81, -83, -45, -7, 31, 69, -95, -57, -19],
  [-61, -21, 19, 59, 99, -63, -23, 17, 57, 97, -65, -25, 15, 55, 95, -67, -27, 13, 53, 93, -69, -29, 11, 51, 91, -71, -31, 9, 49, 89, -73, -33, 7, 47, 87, -75, -35, 5, 45, 85, -77, -37, 3, 43, 83, -79, -39, 1, 41, 81],
  [-59, -17, 25, 67, -93, -51, -9, 33, 75, -85, -43, -1, 41, 83, -77, -35, 7, 49, 91, -69, -27, 15, 57, 99, -61, -19, 23, 65, -95, -53, -11, 31, 73, -87, -45, -3, 39, 81, -79, -37, 5, 47, 89, -71, -29, 13, 55, 97, -63, -21],
  [-57, -13, 31, 75, -83, -39, 5, 49, 93, -65, -21, 23, 67, -91, -47, -3, 41, 85, -73, -29, 15, 59, -99, -55, -11, 33, 77, -81, -37, 7, 51, 95, -63, -19, 25, 69, -89, -45, -1, 43, 87, -71, -27, 17, 61, -97, -53, -9, 35, 79],
  [-55, -9, 37, 83, -73, -27, 19, 65, -91, -45, 1, 47, 93, -63, -17, 29, 75, -81, -35, 11, 57, -99, -53, -7, 39, 85, -71, -25, 21, 67, -89, -43, 3, 49, 95, -61, -15, 31, 77, -79, -33, 13, 59, -97, -51, -5, 41, 87, -69, -23],
  [-53, -5, 43, 91, -63, -15, 33, 81, -73, -25, 23, 71, -83, -35, 13, 61, -93, -45, 3, 51, 99, -55, -7, 41, 89, -65, -17, 31, 79, -75, -27, 21, 69, -85, -37, 11, 59, -95, -47, 1, 49, 97, -57, -9, 39, 87, -67, -19, 29, 77],
  [-51, -1, 49, 99, -53, -3, 47, 97, -55, -5, 45, 95, -57, -7, 43, 93, -59, -9, 41, 91, -61, -11, 39, 89, -63, -13, 37, 87, -65, -15, 35, 85, -67, -17, 33, 83, -69, -19, 31, 81, -71, -21, 29, 79, -73, -23, 27, 77, -75, -25],
  [-49, 3, 55, -95, -43, 9, 61, -89, -37, 15, 67, -83, -31, 21, 73, -77, -25, 27, 79, -71, -19, 33, 85, -65, -13, 39, 91, -59, -7, 45, 97, -53, -1, 51, -99, -47, 5, 57, -93, -41, 11, 63, -87, -35, 17, 69, -81, -29, 23, 75],
  [-47, 7, 61, -87, -33, 21, 75, -73, -19, 35, 89, -59, -5, 49, -99, -45, 9, 63, -85, -31, 23, 77, -71, -17, 37, 91, -57, -3, 51, -97, -43, 11, 65, -83, -29, 25, 79, -69, -15, 39, 93, -55, -1, 53, -95, -41, 13, 67, -81, -27],
  [-45, 11, 67, -79, -23, 33, 89, -57, -1, 55, -91, -35, 21, 77, -69, -13, 43, 99, -47, 9, 65, -81, -25, 31, 87, -59, -3, 53, -93, -37, 19, 75, -71, -15, 41, 97, -49, 7, 63, -83, -27, 29, 85, -61, -5, 51, -95, -39, 17, 73],
  [-43, 15, 73, -71, -13, 45, -99, -41, 17, 75, -69, -11, 47, -97, -39, 19, 77, -67, -9, 49, -95, -37, 21, 79, -65, -7, 51, -93, -35, 23, 81, -63, -5, 53, -91, -33, 25, 83, -61, -3, 55, -89, -31, 27, 85, -59, -1, 57, -87, -29],
  [-41, 19, 79, -63, -3, 57, -85, -25, 35, 95, -47, 13, 73, -69, -9, 51, -91, -31, 29, 89, -53, 7, 67, -75, -15, 45, -97, -37, 23, 83, -59, 1, 61, -81, -21, 39, 99, -43, 17, 77, -65, -5, 55, -87, -27, 33, 93, -49, 11, 71],
  [-39, 23, 85, -55, 7, 69, -71, -9, 53, -87, -25, 37, 99, -41, 21, 83, -57, 5, 67, -73, -11, 51, -89, -27, 35, 97, -43, 19, 81, -59, 3, 65, -75, -13, 49, -91, -29, 33, 95, -45, 17, 79, -61, 1, 63, -77, -15, 47, -93, -31],
  [-37, 27, 91, -47, 17, 81, -57, 7, 71, -67, -3, 61, -77, -13, 51, -87, -23, 41, -97, -33, 31, 95, -43, 21, 85, -53, 11, 75, -63, 1, 65, -73, -9, 55, -83, -19, 45, -93, -29, 35, 99, -39, 25, 89, -49, 15, 79, -59, 5, 69],
  [-35, 31, 97, -39, 27, 93, -43, 23, 89, -47, 19, 85, -51, 15, 81, -55, 11, 77, -59, 7, 73, -63, 3, 69, -67, -1, 65, -71, -5, 61, -75, -9, 57, -79, -13, 53, -83, -17, 49, -87, -21, 45, -91, -25, 41, -95, -29, 37, -99, -33],
  [-33, 35, -99, -31, 37, -97, -29, 39, -95, -27, 41, -93, -25, 43, -91, -23, 45, -89, -21, 47, -87, -19, 49, -85, -17, 51, -83, -15, 53, -81, -13, 55, -79, -11, 57, -77, -9, 59, -75, -7, 61, -73, -5, 63, -71, -3, 65, -69, -1, 67],
  [-31, 39, -93, -23, 47, -85, -15, 55, -77, -7, 63, -69, 1, 71, -61, 9, 79, -53, 17, 87, -45, 25, 95, -37, 33, -99, -29, 41, -91, -21, 49, -83, -13, 57, -75, -5, 65, -67, 3, 73, -59, 11, 81, -51, 19, 89, -43, 27, 97, -35],
  [-29, 43, -87, -15, 57, -73, -1, 71, -59, 13, 85, -45, 27, 99, -31, 41, -89, -17, 55, -75, -3, 69, -61, 11, 83, -47, 25, 97, -33, 39, -91, -19, 53, -77, -5, 67, -63, 9, 81, -49, 23, 95, -35, 37, -93, -21, 51, -79, -7, 65],
  [-27, 47, -81, -7, 67, -61, 13, 87, -41, 33, -95, -21, 53, -75, -1, 73, -55, 19, 93, -35, 39, -89, -15, 59, -69, 5, 79, -49, 25, 99, -29, 45, -83, -9, 65, -63, 11, 85, -43, 31, -97, -23, 51, -77, -3, 71, -57, 17, 91, -37],
  [-25, 51, -75, 1, 77, -49, 27, -99, -23, 53, -73, 3, 79, -47, 29, -97, -21, 55, -71, 5, 81, -45, 31, -95, -19, 57, -69, 7, 83, -43, 33, -93, -17, 59, -67, 9, 85, -41, 35, -91, -15, 61, -65, 11, 87, -39, 37, -89, -13, 63],
  [-23, 55, -69, 9, 87, -37, 41, -83, -5, 73, -51, 27, -97, -19, 59, -65, 13, 91, -33, 45, -79, -1, 77, -47, 31, -93, -15, 63, -61, 17, 95, -29, 49, -75, 3, 81, -43, 35, -89, -11, 67, -57, 21, 99, -25, 53, -71, 7, 85, -39],
  [-21, 59, -63, 17, 97, -25, 55, -67, 13, 93, -29, 51, -71, 9, 89, -33, 47, -75, 5, 85, -37, 43, -79, 1, 81, -41, 39, -83, -3, 77, -45, 35, -87, -7, 73, -49, 31, -91, -11, 69, -53, 27, -95, -15, 65, -57, 23, -99, -19, 61],
  [-19, 63, -57, 25, -95, -13, 69, -51, 31, -89, -7, 75, -45, 37, -83, -1, 81, -39, 43, -77, 5, 87, -33, 49, -71, 11, 93, -27, 55, -65, 17, 99, -21, 61, -59, 23, -97, -15, 67, -53, 29, -91, -9, 73, -47, 35, -85, -3, 79, -41],
  [-17, 67, -51, 33, -85, -1, 83, -35, 49, -69, 15, 99, -19, 65, -53, 31, -87, -3, 81, -37, 47, -71, 13, 97, -21, 63, -55, 29, -89, -5, 79, -39, 45, -73, 11, 95, -23, 61, -57, 27, -91, -7, 77, -41, 43, -75, 9, 93, -25, 59],
  [-15, 71, -45, 41, -75, 11, 97, -19, 67, -49, 37, -79, 7, 93, -23, 63, -53, 33, -83, 3, 89, -27, 59, -57, 29, -87, -1, 85, -31, 55, -61, 25, -91, -5, 81, -35, 51, -65, 21, -95, -9, 77, -39, 47, -69, 17, -99, -13, 73, -43],
  [-13, 75, -39, 49, -65, 23, -91, -3, 85, -29, 59, -55, 33, -81, 7, 95, -19, 69, -45, 43, -71, 17, -97, -9, 79, -35, 53, -61, 27, -87, 1, 89, -25, 63, -51, 37, -77, 11, 99, -15, 73, -41, 47, -67, 21, -93, -5, 83, -31, 57],
  [-11, 79, -33, 57, -55, 35, -77, 13, -99, -9, 81, -31, 59, -53, 37, -75, 15, -97, -7, 83, -29, 61, -51, 39, -73, 17, -95, -5, 85, -27, 63, -49, 41, -71, 19, -93, -3, 87, -25, 65, -47, 43, -69, 21, -91, -1, 89, -23, 67, -45],
  [-9, 83, -27, 65, -45, 47, -63, 29, -81, 11, -99, -7, 85, -25, 67, -43, 49, -61, 31, -79, 13, -97, -5, 87, -23, 69, -41, 51, -59, 33, -77, 15, -95, -3, 89, -21, 71, -39, 53, -57, 35, -75, 17, -93, -1, 91, -19, 73, -37, 55],
  [-7, 87, -21, 73, -35, 59, -49, 45, -63, 31, -77, 17, -91, 3, 97, -11, 83, -25, 69, -39, 55, -53, 41, -67, 27, -81, 13, -95, -1, 93, -15, 79, -29, 65, -43, 51, -57, 37, -71, 23, -85, 9, -99, -5, 89, -19, 75, -33, 61, -47],
  [-5, 91, -15, 81, -25, 71, -35, 61, -45, 51, -55, 41, -65, 31, -75, 21, -85, 11, -95, 1, 97, -9, 87, -19, 77, -29, 67, -39, 57, -49, 47, -59, 37, -69, 27, -79, 17, -89, 7, -99, -3, 93, -13, 83, -23, 73, -33, 63, -43, 53],
  [-3, 95, -9, 89, -15, 83, -21, 77, -27, 71, -33, 65, -39, 59, -45, 53, -51, 47, -57, 41, -63, 35, -69, 29, -75, 23, -81, 17, -87, 11, -93, 5, -99, -1, 97, -7, 91, -13, 85, -19, 79, -25, 73, -31, 67, -37, 61, -43, 55, -49],
  [-1, 99, -3, 97, -5, 95, -7, 93, -9, 91, -11, 89, -13, 87, -15, 85, -17, 83, -19, 81, -21, 79, -23, 77, -25, 75, -27, 73, -29, 71, -31, 69, -33, 67, -35, 65, -37, 63, -39, 61, -41, 59, -43, 57, -45, 55, -47, 53, -49, 51]]

def B : List (List Int) := [
  [-546525367, -8821438721, 1706237024, 5178636597, -8136279257, -9622807733, -8474069476, -14030331119, -9814463233, -5842759456, -23715470031, -6954167879, -18678810928, -11280095058, -13273537606, -9590292882, -32733293158, -3840333274, -15886215647, -16281178653, -20560493033, 3524928257, -26898089128, -11672958672, -17548541817, -18340337454, -27767352254, -8019103829, -20257331479, -91082493  -- (+269 chars; full line in the Zenodo source)
  [-8821438721, 5178636597, -9622807733, -14030331119, -5842759456, -6954167879, -11280095058, -9590292882, -3840333274, -16281178653, 3524928257, -11672958672, -18340337454, -8019103829, -9108249368, -17195685881, 3705776446, -7682894542, -12361486821, 3994857471, 2251264476, -5263281894, 7047957396, 8804890819, -497083351, 12746396833, 19833964758, 8775084428, 11483615003, 28245707156, 119657885  -- (+246 chars; full line in the Zenodo source)
  [1706237024, -9622807733, -9814463233, -6954167879, -13273537606, -3840333274, -20560493033, -11672958672, -27767352254, -9108249368, -13620436853, -7682894542, -11965788569, 2251264476, -8775084428, 8804890819, 497083351, 19833964758, 5263281894, 28245707156, 12361486821, 19901296331, 17195685881, 20257331479, 18340337454, 26898089128, 16281178653, 32733293158, 11280095058, 23715470031, 1403033  -- (+252 chars; full line in the Zenodo source)
  [5178636597, -14030331119, -6954167879, -9590292882, -16281178653, -11672958672, -8019103829, -17195685881, -7682894542, 3994857471, -5263281894, 8804890819, 12746396833, 8775084428, 28245707156, 28944322047, 13620436853, 20257331479, 17548541817, 20560493033, 32733293158, 18678810928, 9814463233, 8136279257, 546525367, 1706237024, -8474069476, -23715470031, -13273537606, -15886215647, -26898089  -- (+251 chars; full line in the Zenodo source)
  [-8136279257, -5842759456, -13273537606, -16281178653, -17548541817, -9108249368, -19901296331, 3994857471, -8775084428, -497083351, -7047957396, 28245707156, 7682894542, 27587678007, 18340337454, 20560493033, 9590292882, 23715470031, 9622807733, 546525367, 5178636597, -9814463233, -11280095058, -15886215647, -11672958672, -20257331479, 3705776446, -11965788569, -5263281894, -12746396833, 198339  -- (+255 chars; full line in the Zenodo source)
  [-9622807733, -6954167879, -3840333274, -11672958672, -9108249368, -7682894542, 2251264476, 8804890819, 19833964758, 28245707156, 19901296331, 20257331479, 26898089128, 32733293158, 23715470031, 8136279257, -546525367, -8474069476, -18678810928, -15886215647, -17548541817, -27587678007, -28944322047, -11483615003, -12746396833, -7047957396, -3994857471, -3705776446, 8019103829, -3524928257, 9590  -- (+257 chars; full line in the Zenodo source)
  [-8474069476, -11280095058, -20560493033, -8019103829, -19901296331, 2251264476, -12746396833, 8775084428, 12361486821, 27587678007, 11672958672, 32733293158, 5842759456, -1706237024, 5178636597, -23715470031, -3840333274, -17548541817, -17195685881, -11965788569, 7047957396, -8804890819, 28245707156, -3705776446, 27767352254, 16281178653, 18678810928, 9622807733, -546525367, -14030331119, -1327  -- (+254 chars; full line in the Zenodo source)
  [-14030331119, -9590292882, -11672958672, -17195685881, 3994857471, 8804890819, 8775084428, 28944322047, 20257331479, 20560493033, 18678810928, 8136279257, 1706237024, -23715470031, -15886215647, -27767352254, -19901296331, -11483615003, 497083351, -2251264476, -3705776446, 18340337454, 3840333274, 5842759456, 8821438721, -9622807733, -11280095058, 3524928257, -9108249368, -12361486821, 70479573  -- (+250 chars; full line in the Zenodo source)
  [-9814463233, -3840333274, -27767352254, -7682894542, -8775084428, 19833964758, 12361486821, 20257331479, 16281178653, 23715470031, 8821438721, -8474069476, -9590292882, -17548541817, 3705776446, -11483615003, 12746396833, -3994857471, 27587678007, -3524928257, 18678810928, -5178636597, -8136279257, -11280095058, -26898089128, -17195685881, -28245707156, -497083351, -2251264476, 13620436853, 116  -- (+255 chars; full line in the Zenodo source)
  [-5842759456, -16281178653, -9108249368, 3994857471, -497083351, 28245707156, 27587678007, 20560493033, 23715470031, 546525367, -9814463233, -15886215647, -20257331479, -11965788569, -12746396833, -2251264476, 17195685881, -3524928257, 6954167879, 8821438721, -14030331119, -3840333274, -8019103829, -12361486821, 8804890819, 11483615003, 13620436853, 26898089128, 18678810928, -1706237024, -847406  -- (+254 chars; full line in the Zenodo source)
  [-23715470031, 3524928257, -13620436853, -5263281894, -7047957396, 19901296331, 11672958672, 18678810928, 8821438721, -9814463233, -16281178653, -27587678007, 2251264476, -8804890819, 28944322047, 18340337454, 13273537606, -5178636597, -8474069476, -3840333274, -20257331479, 3994857471, 497083351, 11965788569, 8019103829, 32733293158, 9622807733, -8136279257, -9590292882, -27767352254, -12361486  -- (+252 chars; full line in the Zenodo source)
  [-6954167879, -11672958672, -7682894542, 8804890819, 28245707156, 20257331479, 32733293158, 8136279257, -8474069476, -15886215647, -27587678007, -11483615003, -7047957396, -3705776446, -3524928257, 5842759456, -8821438721, -11280095058, -18340337454, -12361486821, -497083351, 11965788569, 27767352254, 13273537606, -1706237024, -9814463233, -20560493033, -13620436853, -8775084428, 5263281894, 171  -- (+254 chars; full line in the Zenodo source)
  [-18678810928, -18340337454, -11965788569, 12746396833, 7682894542, 26898089128, 5842759456, 1706237024, -9590292882, -20257331479, 2251264476, -7047957396, 13620436853, 16281178653, 8474069476, -9622807733, -15886215647, -17195685881, -8775084428, 11483615003, 9108249368, 32733293158, -5178636597, -9814463233, 3524928257, -19901296331, 8804890819, -3994857471, 27767352254, 11280095058, 54652536  -- (+253 chars; full line in the Zenodo source)
  [-11280095058, -8019103829, 2251264476, 8775084428, 27587678007, 32733293158, -1706237024, -23715470031, -17548541817, -11965788569, -8804890819, -3705776446, 16281178653, 9622807733, -14030331119, 3524928257, -7682894542, -497083351, 28944322047, 26898089128, 9814463233, -8136279257, -15886215647, -13620436853, -19833964758, -3994857471, 18340337454, 6954167879, -8821438721, -9590292882, -91082  -- (+255 chars; full line in the Zenodo source)
  [-13273537606, -9108249368, -8775084428, 28245707156, 18340337454, 23715470031, 5178636597, -15886215647, 3705776446, -12746396833, 28944322047, -3524928257, 8474069476, -14030331119, -26898089128, -12361486821, -8804890819, 13620436853, 3840333274, -1706237024, -6954167879, -27767352254, 2251264476, 5263281894, 20257331479, 11280095058, -546525367, -9590292882, -27587678007, 7047957396, -399485  -- (+254 chars; full line in the Zenodo source)
  [-9590292882, -17195685881, 8804890819, 28944322047, 20560493033, 8136279257, -23715470031, -27767352254, -11483615003, -2251264476, 18340337454, 5842759456, -9622807733, 3524928257, -12361486821, 19833964758, 27587678007, 13273537606, -546525367, -32733293158, -13620436853, -12746396833, 7682894542, 16281178653, -5178636597, -6954167879, -8019103829, -5263281894, 28245707156, 17548541817, 98144  -- (+255 chars; full line in the Zenodo source)
  [-32733293158, 3705776446, 497083351, 13620436853, 9590292882, -546525367, -3840333274, -19901296331, 12746396833, 17195685881, 13273537606, -8821438721, -15886215647, -7682894542, -8804890819, 27587678007, 11280095058, 1706237024, -16281178653, -28944322047, 19833964758, 9108249368, 18678810928, 5178636597, -20560493033, -12361486821, -7047957396, 20257331479, 6954167879, -8136279257, 352492825  -- (+249 chars; full line in the Zenodo source)
  [-3840333274, -7682894542, 19833964758, 20257331479, 23715470031, -8474069476, -17548541817, -11483615003, -3994857471, -3524928257, -5178636597, -11280095058, -17195685881, -497083351, 13620436853, 13273537606, 1706237024, -20560493033, -11965788569, 5263281894, 18340337454, 14030331119, -5842759456, -8019103829, 7047957396, 28944322047, 15886215647, 546525367, -32733293158, -19901296331, -8804  -- (+254 chars; full line in the Zenodo source)
  [-15886215647, -12361486821, 5263281894, 17548541817, 9622807733, -18678810928, -17195685881, 497083351, 27587678007, 6954167879, -8474069476, -18340337454, -8775084428, 28944322047, 3840333274, -546525367, -16281178653, -11965788569, 11483615003, 11672958672, 8136279257, -11280095058, -13620436853, 12746396833, 9108249368, 23715470031, -14030331119, -27767352254, 7047957396, 7682894542, 3273329  -- (+251 chars; full line in the Zenodo source)
  [-16281178653, 3994857471, 28245707156, 20560493033, 546525367, -15886215647, -11965788569, -2251264476, -3524928257, 8821438721, -3840333274, -12361486821, 11483615003, 26898089128, -1706237024, -32733293158, -28944322047, 5263281894, 11672958672, -5178636597, -9590292882, -7682894542, 8775084428, 17548541817, 8136279257, -13273537606, -19901296331, -7047957396, 18340337454, 9622807733, -112800  -- (+251 chars; full line in the Zenodo source)
  [-20560493033, 2251264476, 12361486821, 32733293158, 5178636597, -17548541817, 7047957396, -3705776446, 18678810928, -14030331119, -20257331479, -497083351, 9108249368, 9814463233, -6954167879, -13620436853, 19833964758, 18340337454, 8136279257, -9590292882, -28944322047, 11483615003, -3524928257, 546525367, -16281178653, -28245707156, 11965788569, 3840333274, 1706237024, -11672958672, -87750844  -- (+251 chars; full line in the Zenodo source)
  [3524928257, -5263281894, 19901296331, 18678810928, -9814463233, -27587678007, -8804890819, 18340337454, -5178636597, -3840333274, 3994857471, 11965788569, 32733293158, -8136279257, -27767352254, -12746396833, 9108249368, 14030331119, -11280095058, -7682894542, 11483615003, 20560493033, -546525367, -26898089128, -8775084428, -3705776446, 6954167879, -5842759456, -17195685881, 19833964758, 175485  -- (+255 chars; full line in the Zenodo source)
  [-26898089128, 7047957396, 17195685881, 9814463233, -11280095058, -28944322047, 28245707156, 3840333274, -8136279257, -8019103829, 497083351, 27767352254, -5178636597, -15886215647, 2251264476, 7682894542, 18678810928, -5842759456, -13620436853, 8775084428, -3524928257, -546525367, -11672958672, -19833964758, 27587678007, 14030331119, -13273537606, -12361486821, -3994857471, 32733293158, -962280  -- (+253 chars; full line in the Zenodo source)
  [-11672958672, 8804890819, 20257331479, 8136279257, -15886215647, -11483615003, -3705776446, 5842759456, -11280095058, -12361486821, 11965788569, 13273537606, -9814463233, -13620436853, 5263281894, 16281178653, 5178636597, -8019103829, 12746396833, 17548541817, 546525367, -26898089128, -19833964758, 9108249368, 9622807733, -3840333274, 2251264476, 19901296331, 23715470031, -18678810928, -2894432  -- (+247 chars; full line in the Zenodo source)
  [-17548541817, -497083351, 18340337454, 546525367, -11672958672, -12746396833, 27767352254, 8821438721, -26898089128, 8804890819, 8019103829, -1706237024, 3524928257, -19833964758, 20257331479, -5178636597, -20560493033, 7047957396, 9108249368, 8136279257, -16281178653, -8775084428, 27587678007, 9622807733, -15886215647, -5263281894, 17195685881, 8474069476, -3840333274, -11483615003, 1362043685  -- (+251 chars; full line in the Zenodo source)
  [-18340337454, 12746396833, 26898089128, 1706237024, -20257331479, -7047957396, 16281178653, -9622807733, -17195685881, 11483615003, 32733293158, -9814463233, -19901296331, -3994857471, 11280095058, -6954167879, -12361486821, 28944322047, 23715470031, -13273537606, -28245707156, -3705776446, 14030331119, -3840333274, -5263281894, 27587678007, 8136279257, -20560493033, -19833964758, 8019103829, 8  -- (+256 chars; full line in the Zenodo source)
  [-27767352254, 19833964758, 16281178653, -8474069476, 3705776446, -3994857471, 18678810928, -11280095058, -28245707156, 13620436853, 9622807733, -20560493033, 8804890819, 18340337454, -546525367, -8019103829, -7047957396, 15886215647, -14030331119, -19901296331, 11965788569, 6954167879, -13273537606, 2251264476, 17195685881, 8136279257, 3524928257, -12746396833, 17548541817, -8821438721, -202573  -- (+252 chars; full line in the Zenodo source)
  [-8019103829, 8775084428, 32733293158, -23715470031, -11965788569, -3705776446, 9622807733, 3524928257, -497083351, 26898089128, -8136279257, -13620436853, -3994857471, 6954167879, -9590292882, -5263281894, 20257331479, 546525367, -27767352254, -7047957396, 3840333274, -5842759456, -12361486821, 19901296331, 8474069476, -20560493033, -12746396833, 11672958672, 5178636597, -17195685881, 282457071  -- (+252 chars; full line in the Zenodo source)
  [-20257331479, 11483615003, 11280095058, -13273537606, -5263281894, 8019103829, -546525367, -9108249368, -2251264476, 18678810928, -9590292882, -8775084428, 27767352254, -8821438721, -27587678007, 28245707156, 6954167879, -32733293158, 7047957396, 18340337454, 1706237024, -17195685881, -3994857471, 23715470031, -3840333274, -19833964758, 17548541817, 5178636597, -13620436853, 11965788569, 584275  -- (+254 chars; full line in the Zenodo source)
  [-9108249368, 28245707156, 23715470031, -15886215647, -12746396833, -3524928257, -14030331119, -12361486821, 13620436853, -1706237024, -27767352254, 5263281894, 11280095058, -9590292882, 7047957396, 17548541817, -8136279257, -19901296331, 7682894542, 9622807733, -11672958672, 19833964758, 32733293158, -18678810928, -11483615003, 8019103829, -8821438721, -17195685881, 11965788569, 9814463233, -20  -- (+253 chars; full line in the Zenodo source)
  [-27587678007, 11965788569, 14030331119, -26898089128, 19833964758, 9590292882, -13273537606, 7047957396, 11672958672, -8474069476, -12361486821, 17195685881, 546525367, -9108249368, -3994857471, 9814463233, 3524928257, -8804890819, 32733293158, -11280095058, -8775084428, 17548541817, -9622807733, -28944322047, 13620436853, 8821438721, -20257331479, 28245707156, 5842759456, -20560493033, 1274639  -- (+253 chars; full line in the Zenodo source)
  [-17195685881, 28944322047, 8136279257, -27767352254, -2251264476, 5842759456, 3524928257, 19833964758, 13273537606, -32733293158, -12746396833, 16281178653, -6954167879, -5263281894, 17548541817, -8474069476, -11965788569, 9108249368, -8821438721, 3705776446, 19901296331, -1706237024, -20257331479, -3994857471, 14030331119, -11672958672, 8775084428, 18678810928, -15886215647, 497083351, 3840333  -- (+250 chars; full line in the Zenodo source)
  [-13620436853, 19901296331, 8821438721, -27587678007, 28944322047, -5178636597, -20257331479, 11965788569, 9622807733, -27767352254, 28245707156, 14030331119, -17548541817, 11483615003, 5842759456, -26898089128, 8775084428, 6954167879, -20560493033, 19833964758, 11280095058, -15886215647, 12746396833, 9590292882, -32733293158, -497083351, 3840333274, -13273537606, 8804890819, 16281178653, -18678  -- (+249 chars; full line in the Zenodo source)
  [3705776446, 13620436853, -546525367, -19901296331, 17195685881, -8821438721, -7682894542, 27587678007, 1706237024, -28944322047, 9108249368, 5178636597, -12361486821, 20257331479, -8136279257, -11965788569, 8019103829, -9622807733, 3994857471, 27767352254, -8474069476, -28245707156, 18340337454, -14030331119, 2251264476, 17548541817, -9814463233, -11483615003, 11672958672, -5842759456, -5263281  -- (+254 chars; full line in the Zenodo source)
  [-19901296331, 27587678007, 5178636597, -11965788569, 27767352254, -14030331119, -11483615003, 26898089128, -6954167879, -19833964758, 15886215647, -9590292882, 497083351, 13273537606, -16281178653, -7047957396, 23715470031, -11672958672, -2251264476, 8474069476, -8019103829, 12361486821, -1706237024, -17195685881, -3705776446, -546525367, -7682894542, 9108249368, -8136279257, 3994857471, 183403  -- (+254 chars; full line in the Zenodo source)
  [-7682894542, 20257331479, -8474069476, -11483615003, -3524928257, -11280095058, -497083351, 13273537606, -20560493033, 5263281894, 14030331119, -8019103829, 28944322047, 546525367, -19901296331, 9108249368, -9622807733, 2251264476, 26898089128, -18678810928, -12746396833, 9590292882, -16281178653, 8775084428, 9814463233, -27767352254, 12361486821, 8821438721, 3705776446, 27587678007, -813627925  -- (+251 chars; full line in the Zenodo source)
  [-28944322047, 27767352254, -5842759456, -19833964758, 32733293158, -16281178653, 5263281894, 8474069476, -9108249368, -3705776446, 1706237024, 3994857471, 11672958672, -18678810928, -497083351, 11280095058, -26898089128, 28245707156, -5178636597, -13620436853, 27587678007, -9622807733, -11483615003, 20560493033, -9590292882, -8804890819, 23715470031, -18340337454, 12361486821, 546525367, -76828  -- (+253 chars; full line in the Zenodo source)
  [-12361486821, 17548541817, -18678810928, 497083351, 6954167879, -18340337454, 28944322047, -546525367, -11965788569, 11672958672, -11280095058, 12746396833, 23715470031, -27767352254, 7682894542, -8821438721, 3994857471, 26898089128, -13273537606, -8804890819, 5842759456, -8019103829, 19901296331, 1706237024, -28245707156, -3524928257, -9590292882, 19833964758, 9814463233, -20257331479, -370577  -- (+252 chars; full line in the Zenodo source)
  [-11965788569, 26898089128, -9590292882, -7047957396, 8474069476, -17195685881, 9108249368, -9814463233, 8804890819, 11280095058, -17548541817, 28944322047, -8821438721, -28245707156, 20560493033, -3840333274, 5263281894, 8136279257, 3705776446, 8019103829, -23715470031, -497083351, 6954167879, -27767352254, 19901296331, 5178636597, -11483615003, 15886215647, -16281178653, -2251264476, -17062370  -- (+252 chars; full line in the Zenodo source)
  [3994857471, 20560493033, -15886215647, -2251264476, 8821438721, -12361486821, 26898089128, -32733293158, 5263281894, -5178636597, -7682894542, 17548541817, -13273537606, -7047957396, 9622807733, 3705776446, 27767352254, -18678810928, -8804890819, 14030331119, -17195685881, 20257331479, -23715470031, 497083351, 5842759456, -9108249368, 27587678007, -9814463233, -12746396833, 6954167879, -8019103  -- (+252 chars; full line in the Zenodo source)
  [-28245707156, 15886215647, 3524928257, 12361486821, 1706237024, -5263281894, 9590292882, -17548541817, 19901296331, -9622807733, -19833964758, 18678810928, -8019103829, 17195685881, -9814463233, -497083351, 5842759456, -27587678007, 20257331479, -6954167879, -8804890819, 8474069476, 3705776446, 18340337454, -13273537606, 8775084428, -5178636597, -28944322047, 26898089128, -3840333274, -22512644  -- (+252 chars; full line in the Zenodo source)
  [2251264476, 32733293158, -17548541817, -3705776446, -14030331119, -497083351, 9814463233, -13620436853, 18340337454, -9590292882, 11483615003, 546525367, -28245707156, 3840333274, -11672958672, 19901296331, -8474069476, -12746396833, 5842759456, -17195685881, 27767352254, -13273537606, 5263281894, 8821438721, 3994857471, 15886215647, -26898089128, 7682894542, -9622807733, 8804890819, 2371547003  -- (+252 chars; full line in the Zenodo source)
  [-11483615003, 13273537606, -8019103829, 9108249368, -18678810928, 8775084428, 8821438721, -28245707156, 32733293158, -18340337454, 17195685881, -23715470031, 19833964758, -5178636597, -11965788569, 15886215647, -11672958672, -3705776446, -9814463233, 12746396833, 9622807733, -28944322047, 20560493033, 3524928257, 7682894542, -8474069476, -497083351, 14030331119, -19901296331, 26898089128, -1628  -- (+253 chars; full line in the Zenodo source)
  [-5263281894, 18678810928, -27587678007, 18340337454, -3840333274, 11965788569, -8136279257, -12746396833, 14030331119, -7682894542, 20560493033, -26898089128, -3705776446, -5842759456, 19833964758, -1706237024, -28245707156, 9590292882, -8019103829, 20257331479, -13273537606, -2251264476, -8821438721, 7047957396, 23715470031, -13620436853, 11672958672, -16281178653, 28944322047, -8474069476, 49  -- (+254 chars; full line in the Zenodo source)
  [-8775084428, 23715470031, 3705776446, -3524928257, -26898089128, 13620436853, -6954167879, 5263281894, -546525367, 7047957396, 5842759456, -19901296331, 20560493033, -11672958672, 17195685881, -18678810928, 11483615003, -8821438721, -19833964758, 9814463233, -7682894542, 16281178653, -17548541817, 27587678007, -11280095058, -2251264476, 1706237024, 8804890819, 14030331119, -28944322047, 1588621  -- (+253 chars; full line in the Zenodo source)
  [7047957396, 9814463233, -28944322047, 3840333274, -8019103829, 27767352254, -15886215647, 7682894542, -5842759456, 8775084428, -546525367, -19833964758, 14030331119, -12361486821, 32733293158, -20257331479, 18340337454, -16281178653, 19901296331, -23715470031, 5263281894, -8821438721, 8804890819, 8474069476, -11965788569, 9590292882, -9108249368, 17548541817, -20560493033, -3705776446, -6954167  -- (+250 chars; full line in the Zenodo source)
  [-19833964758, 8474069476, 3994857471, 11280095058, -13620436853, 20560493033, -18340337454, 8019103829, -15886215647, 19901296331, -6954167879, -2251264476, -8136279257, 12746396833, 8821438721, -8775084428, 9814463233, -12361486821, 9590292882, -27587678007, 26898089128, -11672958672, 9108249368, -32733293158, 28944322047, -5842759456, 5263281894, 1706237024, -497083351, -5178636597, -11483615  -- (+251 chars; full line in the Zenodo source)
  [8804890819, 8136279257, -11483615003, 5842759456, -12361486821, 13273537606, -13620436853, 16281178653, -8019103829, 17548541817, -26898089128, 9108249368, -3840333274, 19901296331, -18678810928, -3994857471, -14030331119, 8775084428, 1706237024, 497083351, 8821438721, 7047957396, 8474069476, -28245707156, 6954167879, -7682894542, 32733293158, -27587678007, -3524928257, -18340337454, 2776735225  -- (+252 chars; full line in the Zenodo source)
  [-12746396833, -1706237024, 7047957396, 9622807733, -11483615003, 9814463233, 3994857471, 6954167879, -28944322047, 13273537606, 3705776446, 3840333274, -27587678007, 20560493033, -8019103829, 11672958672, -17548541817, 27767352254, 3524928257, 9108249368, -15886215647, 13620436853, -9590292882, 7682894542, -18678810928, 11965788569, -5842759456, -2251264476, -8474069476, 8775084428, 5178636597,  -- (+251 chars; full line in the Zenodo source)
  [-497083351, 546525367, -12746396833, 8821438721, 8804890819, -1706237024, -19833964758, -5178636597, 7047957396, 8136279257, -8775084428, 9622807733, -5263281894, 8474069476, -11483615003, 14030331119, 2251264476, 9814463233, -28245707156, 5842759456, 3994857471, 23715470031, -11965788569, 6954167879, -12361486821, 18678810928, -28944322047, 11280095058, -7682894542, 13273537606, -19901296331,   -- (+250 chars; full line in the Zenodo source)

theorem A_def : A = (rng 1 50).map (fun t => rowA (100 + 1) t (rng 1 50)) := rfl
theorem len : allLen 50 A = true := rfl
set_option maxRecDepth 100000 in
theorem cert : lcs 50 B A = sid 28663027375250 50 := rfl

theorem d_ne : (28663027375250 : Int) ≠ 0 := by
  intro h
  have h' : false = true := congrArg (fun z : Int => Nat.beq z.natAbs 0) h
  exact Bool.noConfusion h'

/-- Every g of length 50 with A g = 0 is zero. -/
theorem kernel (g : List Int) (hg : g.length = 50) (h0 : mv A g = zeros 50) : g = zeros 50 :=
  kernel_zero 50 28663027375250 d_ne A B len cert g hg h0

set_option maxRecDepth 100000 in
theorem delta : deltaOK 100 50 = true := rfl

/-- **Balanced ⇒ pairs for p = 101.** A list with entries in (0, 101) that is balanced for 1 ≤ t ≤ 50
    has as many copies of x as of 101 − x for every 1 ≤ x ≤ 50 (any length). -/
theorem pairs (c : List Nat) (hr : ∀ y, y ∈ c → 0 < y ∧ y < 101)
    (hb : ∀ t, 1 ≤ t → t < 1 + 50 → tsum 101 t c + tsum 101 t c = c.length * 101) :
    (rng 1 50).all (fun x => Nat.beq (cnt x c) (cnt (101 - x) c)) = true :=
  pairs_of_bal 100 50 28663027375250 d_ne A B len cert A_def delta c hr hb

end MailletCert101

#print axioms MailletCert101.A_def
#print axioms MailletCert101.len
#print axioms MailletCert101.cert
#print axioms MailletCert101.d_ne
#print axioms MailletCert101.kernel
#print axioms MailletCert101.delta
#print axioms MailletCert101.pairs

#print axioms: 5 files, 7 theorems each, no axioms.

81.224 Maillet certificates for \(127\le p\le 157\) (Kamiak)

The same certificates for \(p=127,131,137,139,149,151,157\): \(B\cdot A=d\cdot I\), the finite check, and pairs. Shown for \(p=127\).

hodge/MailletCert127.lean

/-
  hodge/MailletCert127.lean — T41 (goals G849b, G849c): for p = 127 the 63 × 63 matrix A[t][x] = 2⟨t x⟩ − p (1 ≤ t, x ≤ 63)
  is invertible over ℚ: an integer matrix B with B · A = d · I, d = 661550413311054017530 (tools/maillet_cert.py). With the finite
  check deltaOK and hodge/MailletBridge: every balanced list with entries in (0, 127) is a union of complementary
  pairs, at every length. Lean 4 core, rfl.
-/
import hodge.MailletBridge

set_option maxHeartbeats 0

namespace MailletCert127
open MailletLin MailletBridge

def A : List (List Int) := [
  [-125, -123, -121, -119, -117, -115, -113, -111, -109, -107, -105, -103, -101, -99, -97, -95, -93, -91, -89, -87, -85, -83, -81, -79, -77, -75, -73, -71, -69, -67, -65, -63, -61, -59, -57, -55, -53, -51, -49, -47, -45, -43, -41, -39, -37, -35, -33, -31, -29, -27, -25, -23, -21, -19, -17, -15, -13, -11, -9, -7, -5, -3, -1],
  [-123, -119, -115, -111, -107, -103, -99, -95, -91, -87, -83, -79, -75, -71, -67, -63, -59, -55, -51, -47, -43, -39, -35, -31, -27, -23, -19, -15, -11, -7, -3, 1, 5, 9, 13, 17, 21, 25, 29, 33, 37, 41, 45, 49, 53, 57, 61, 65, 69, 73, 77, 81, 85, 89, 93, 97, 101, 105, 109, 113, 117, 121, 125],
  [-121, -115, -109, -103, -97, -91, -85, -79, -73, -67, -61, -55, -49, -43, -37, -31, -25, -19, -13, -7, -1, 5, 11, 17, 23, 29, 35, 41, 47, 53, 59, 65, 71, 77, 83, 89, 95, 101, 107, 113, 119, 125, -123, -117, -111, -105, -99, -93, -87, -81, -75, -69, -63, -57, -51, -45, -39, -33, -27, -21, -15, -9, -3],
  [-119, -111, -103, -95, -87, -79, -71, -63, -55, -47, -39, -31, -23, -15, -7, 1, 9, 17, 25, 33, 41, 49, 57, 65, 73, 81, 89, 97, 105, 113, 121, -125, -117, -109, -101, -93, -85, -77, -69, -61, -53, -45, -37, -29, -21, -13, -5, 3, 11, 19, 27, 35, 43, 51, 59, 67, 75, 83, 91, 99, 107, 115, 123],
  [-117, -107, -97, -87, -77, -67, -57, -47, -37, -27, -17, -7, 3, 13, 23, 33, 43, 53, 63, 73, 83, 93, 103, 113, 123, -121, -111, -101, -91, -81, -71, -61, -51, -41, -31, -21, -11, -1, 9, 19, 29, 39, 49, 59, 69, 79, 89, 99, 109, 119, -125, -115, -105, -95, -85, -75, -65, -55, -45, -35, -25, -15, -5],
  [-115, -103, -91, -79, -67, -55, -43, -31, -19, -7, 5, 17, 29, 41, 53, 65, 77, 89, 101, 113, 125, -117, -105, -93, -81, -69, -57, -45, -33, -21, -9, 3, 15, 27, 39, 51, 63, 75, 87, 99, 111, 123, -119, -107, -95, -83, -71, -59, -47, -35, -23, -11, 1, 13, 25, 37, 49, 61, 73, 85, 97, 109, 121],
  [-113, -99, -85, -71, -57, -43, -29, -15, -1, 13, 27, 41, 55, 69, 83, 97, 111, 125, -115, -101, -87, -73, -59, -45, -31, -17, -3, 11, 25, 39, 53, 67, 81, 95, 109, 123, -117, -103, -89, -75, -61, -47, -33, -19, -5, 9, 23, 37, 51, 65, 79, 93, 107, 121, -119, -105, -91, -77, -63, -49, -35, -21, -7],
  [-111, -95, -79, -63, -47, -31, -15, 1, 17, 33, 49, 65, 81, 97, 113, -125, -109, -93, -77, -61, -45, -29, -13, 3, 19, 35, 51, 67, 83, 99, 115, -123, -107, -91, -75, -59, -43, -27, -11, 5, 21, 37, 53, 69, 85, 101, 117, -121, -105, -89, -73, -57, -41, -25, -9, 7, 23, 39, 55, 71, 87, 103, 119],
  [-109, -91, -73, -55, -37, -19, -1, 17, 35, 53, 71, 89, 107, 125, -111, -93, -75, -57, -39, -21, -3, 15, 33, 51, 69, 87, 105, 123, -113, -95, -77, -59, -41, -23, -5, 13, 31, 49, 67, 85, 103, 121, -115, -97, -79, -61, -43, -25, -7, 11, 29, 47, 65, 83, 101, 119, -117, -99, -81, -63, -45, -27, -9],
  [-107, -87, -67, -47, -27, -7, 13, 33, 53, 73, 93, 113, -121, -101, -81, -61, -41, -21, -1, 19, 39, 59, 79, 99, 119, -115, -95, -75, -55, -35, -15, 5, 25, 45, 65, 85, 105, 125, -109, -89, -69, -49, -29, -9, 11, 31, 51, 71, 91, 111, -123, -103, -83, -63, -43, -23, -3, 17, 37, 57, 77, 97, 117],
  [-105, -83, -61, -39, -17, 5, 27, 49, 71, 93, 115, -117, -95, -73, -51, -29, -7, 15, 37, 59, 81, 103, 125, -107, -85, -63, -41, -19, 3, 25, 47, 69, 91, 113, -119, -97, -75, -53, -31, -9, 13, 35, 57, 79, 101, 123, -109, -87, -65, -43, -21, 1, 23, 45, 67, 89, 111, -121, -99, -77, -55, -33, -11],
  [-103, -79, -55, -31, -7, 17, 41, 65, 89, 113, -117, -93, -69, -45, -21, 3, 27, 51, 75, 99, 123, -107, -83, -59, -35, -11, 13, 37, 61, 85, 109, -121, -97, -73, -49, -25, -1, 23, 47, 71, 95, 119, -111, -87, -63, -39, -15, 9, 33, 57, 81, 105, -125, -101, -77, -53, -29, -5, 19, 43, 67, 91, 115],
  [-101, -75, -49, -23, 3, 29, 55, 81, 107, -121, -95, -69, -43, -17, 9, 35, 61, 87, 113, -115, -89, -63, -37, -11, 15, 41, 67, 93, 119, -109, -83, -57, -31, -5, 21, 47, 73, 99, 125, -103, -77, -51, -25, 1, 27, 53, 79, 105, -123, -97, -71, -45, -19, 7, 33, 59, 85, 111, -117, -91, -65, -39, -13],
  [-99, -71, -43, -15, 13, 41, 69, 97, 125, -101, -73, -45, -17, 11, 39, 67, 95, 123, -103, -75, -47, -19, 9, 37, 65, 93, 121, -105, -77, -49, -21, 7, 35, 63, 91, 119, -107, -79, -51, -23, 5, 33, 61, 89, 117, -109, -81, -53, -25, 3, 31, 59, 87, 115, -111, -83, -55, -27, 1, 29, 57, 85, 113],
  [-97, -67, -37, -7, 23, 53, 83, 113, -111, -81, -51, -21, 9, 39, 69, 99, -125, -95, -65, -35, -5, 25, 55, 85, 115, -109, -79, -49, -19, 11, 41, 71, 101, -123, -93, -63, -33, -3, 27, 57, 87, 117, -107, -77, -47, -17, 13, 43, 73, 103, -121, -91, -61, -31, -1, 29, 59, 89, 119, -105, -75, -45, -15],
  [-95, -63, -31, 1, 33, 65, 97, -125, -93, -61, -29, 3, 35, 67, 99, -123, -91, -59, -27, 5, 37, 69, 101, -121, -89, -57, -25, 7, 39, 71, 103, -119, -87, -55, -23, 9, 41, 73, 105, -117, -85, -53, -21, 11, 43, 75, 107, -115, -83, -51, -19, 13, 45, 77, 109, -113, -81, -49, -17, 15, 47, 79, 111],
  [-93, -59, -25, 9, 43, 77, 111, -109, -75, -41, -7, 27, 61, 95, -125, -91, -57, -23, 11, 45, 79, 113, -107, -73, -39, -5, 29, 63, 97, -123, -89, -55, -21, 13, 47, 81, 115, -105, -71, -37, -3, 31, 65, 99, -121, -87, -53, -19, 15, 49, 83, 117, -103, -69, -35, -1, 33, 67, 101, -119, -85, -51, -17],
  [-91, -55, -19, 17, 53, 89, 125, -93, -57, -21, 15, 51, 87, 123, -95, -59, -23, 13, 49, 85, 121, -97, -61, -25, 11, 47, 83, 119, -99, -63, -27, 9, 45, 81, 117, -101, -65, -29, 7, 43, 79, 115, -103, -67, -31, 5, 41, 77, 113, -105, -69, -33, 3, 39, 75, 111, -107, -71, -35, 1, 37, 73, 109],
  [-89, -51, -13, 25, 63, 101, -115, -77, -39, -1, 37, 75, 113, -103, -65, -27, 11, 49, 87, 125, -91, -53, -15, 23, 61, 99, -117, -79, -41, -3, 35, 73, 111, -105, -67, -29, 9, 47, 85, 123, -93, -55, -17, 21, 59, 97, -119, -81, -43, -5, 33, 71, 109, -107, -69, -31, 7, 45, 83, 121, -95, -57, -19],
  [-87, -47, -7, 33, 73, 113, -101, -61, -21, 19, 59, 99, -115, -75, -35, 5, 45, 85, 125, -89, -49, -9, 31, 71, 111, -103, -63, -23, 17, 57, 97, -117, -77, -37, 3, 43, 83, 123, -91, -51, -11, 29, 69, 109, -105, -65, -25, 15, 55, 95, -119, -79, -39, 1, 41, 81, 121, -93, -53, -13, 27, 67, 107],
  [-85, -43, -1, 41, 83, 125, -87, -45, -3, 39, 81, 123, -89, -47, -5, 37, 79, 121, -91, -49, -7, 35, 77, 119, -93, -51, -9, 33, 75, 117, -95, -53, -11, 31, 73, 115, -97, -55, -13, 29, 71, 113, -99, -57, -15, 27, 69, 111, -101, -59, -17, 25, 67, 109, -103, -61, -19, 23, 65, 107, -105, -63, -21],
  [-83, -39, 5, 49, 93, -117, -73, -29, 15, 59, 103, -107, -63, -19, 25, 69, 113, -97, -53, -9, 35, 79, 123, -87, -43, 1, 45, 89, -121, -77, -33, 11, 55, 99, -111, -67, -23, 21, 65, 109, -101, -57, -13, 31, 75, 119, -91, -47, -3, 41, 85, -125, -81, -37, 7, 51, 95, -115, -71, -27, 17, 61, 105],
  [-81, -35, 11, 57, 103, -105, -59, -13, 33, 79, 125, -83, -37, 9, 55, 101, -107, -61, -15, 31, 77, 123, -85, -39, 7, 53, 99, -109, -63, -17, 29, 75, 121, -87, -41, 5, 51, 97, -111, -65, -19, 27, 73, 119, -89, -43, 3, 49, 95, -113, -67, -21, 25, 71, 117, -91, -45, 1, 47, 93, -115, -69, -23],
  [-79, -31, 17, 65, 113, -93, -45, 3, 51, 99, -107, -59, -11, 37, 85, -121, -73, -25, 23, 71, 119, -87, -39, 9, 57, 105, -101, -53, -5, 43, 91, -115, -67, -19, 29, 77, 125, -81, -33, 15, 63, 111, -95, -47, 1, 49, 97, -109, -61, -13, 35, 83, -123, -75, -27, 21, 69, 117, -89, -41, 7, 55, 103],
  [-77, -27, 23, 73, 123, -81, -31, 19, 69, 119, -85, -35, 15, 65, 115, -89, -39, 11, 61, 111, -93, -43, 7, 57, 107, -97, -47, 3, 53, 103, -101, -51, -1, 49, 99, -105, -55, -5, 45, 95, -109, -59, -9, 41, 91, -113, -63, -13, 37, 87, -117, -67, -17, 33, 83, -121, -71, -21, 29, 79, -125, -75, -25],
  [-75, -23, 29, 81, -121, -69, -17, 35, 87, -115, -63, -11, 41, 93, -109, -57, -5, 47, 99, -103, -51, 1, 53, 105, -97, -45, 7, 59, 111, -91, -39, 13, 65, 117, -85, -33, 19, 71, 123, -79, -27, 25, 77, -125, -73, -21, 31, 83, -119, -67, -15, 37, 89, -113, -61, -9, 43, 95, -107, -55, -3, 49, 101],
  [-73, -19, 35, 89, -111, -57, -3, 51, 105, -95, -41, 13, 67, 121, -79, -25, 29, 83, -117, -63, -9, 45, 99, -101, -47, 7, 61, 115, -85, -31, 23, 77, -123, -69, -15, 39, 93, -107, -53, 1, 55, 109, -91, -37, 17, 71, 125, -75, -21, 33, 87, -113, -59, -5, 49, 103, -97, -43, 11, 65, 119, -81, -27],
  [-71, -15, 41, 97, -101, -45, 11, 67, 123, -75, -19, 37, 93, -105, -49, 7, 63, 119, -79, -23, 33, 89, -109, -53, 3, 59, 115, -83, -27, 29, 85, -113, -57, -1, 55, 111, -87, -31, 25, 81, -117, -61, -5, 51, 107, -91, -35, 21, 77, -121, -65, -9, 47, 103, -95, -39, 17, 73, -125, -69, -13, 43, 99],
  [-69, -11, 47, 105, -91, -33, 25, 83, -113, -55, 3, 61, 119, -77, -19, 39, 97, -99, -41, 17, 75, -121, -63, -5, 53, 111, -85, -27, 31, 89, -107, -49, 9, 67, 125, -71, -13, 45, 103, -93, -35, 23, 81, -115, -57, 1, 59, 117, -79, -21, 37, 95, -101, -43, 15, 73, -123, -65, -7, 51, 109, -87, -29],
  [-67, -7, 53, 113, -81, -21, 39, 99, -95, -35, 25, 85, -109, -49, 11, 71, -123, -63, -3, 57, 117, -77, -17, 43, 103, -91, -31, 29, 89, -105, -45, 15, 75, -119, -59, 1, 61, 121, -73, -13, 47, 107, -87, -27, 33, 93, -101, -41, 19, 79, -115, -55, 5, 65, 125, -69, -9, 51, 111, -83, -23, 37, 97],
  [-65, -3, 59, 121, -71, -9, 53, 115, -77, -15, 47, 109, -83, -21, 41, 103, -89, -27, 35, 97, -95, -33, 29, 91, -101, -39, 23, 85, -107, -45, 17, 79, -113, -51, 11, 73, -119, -57, 5, 67, -125, -63, -1, 61, 123, -69, -7, 55, 117, -75, -13, 49, 111, -81, -19, 43, 105, -87, -25, 37, 99, -93, -31],
  [-63, 1, 65, -125, -61, 3, 67, -123, -59, 5, 69, -121, -57, 7, 71, -119, -55, 9, 73, -117, -53, 11, 75, -115, -51, 13, 77, -113, -49, 15, 79, -111, -47, 17, 81, -109, -45, 19, 83, -107, -43, 21, 85, -105, -41, 23, 87, -103, -39, 25, 89, -101, -37, 27, 91, -99, -35, 29, 93, -97, -33, 31, 95],
  [-61, 5, 71, -117, -51, 15, 81, -107, -41, 25, 91, -97, -31, 35, 101, -87, -21, 45, 111, -77, -11, 55, 121, -67, -1, 65, -123, -57, 9, 75, -113, -47, 19, 85, -103, -37, 29, 95, -93, -27, 39, 105, -83, -17, 49, 115, -73, -7, 59, 125, -63, 3, 69, -119, -53, 13, 79, -109, -43, 23, 89, -99, -33],
  [-59, 9, 77, -109, -41, 27, 95, -91, -23, 45, 113, -73, -5, 63, -123, -55, 13, 81, -105, -37, 31, 99, -87, -19, 49, 117, -69, -1, 67, -119, -51, 17, 85, -101, -33, 35, 103, -83, -15, 53, 121, -65, 3, 71, -115, -47, 21, 89, -97, -29, 39, 107, -79, -11, 57, 125, -61, 7, 75, -111, -43, 25, 93],
  [-57, 13, 83, -101, -31, 39, 109, -75, -5, 65, -119, -49, 21, 91, -93, -23, 47, 117, -67, 3, 73, -111, -41, 29, 99, -85, -15, 55, 125, -59, 11, 81, -103, -33, 37, 107, -77, -7, 63, -121, -51, 19, 89, -95, -25, 45, 115, -69, 1, 71, -113, -43, 27, 97, -87, -17, 53, 123, -61, 9, 79, -105, -35],
  [-55, 17, 89, -93, -21, 51, 123, -59, 13, 85, -97, -25, 47, 119, -63, 9, 81, -101, -29, 43, 115, -67, 5, 77, -105, -33, 39, 111, -71, 1, 73, -109, -37, 35, 107, -75, -3, 69, -113, -41, 31, 103, -79, -7, 65, -117, -45, 27, 99, -83, -11, 61, -121, -49, 23, 95, -87, -15, 57, -125, -53, 19, 91],
  [-53, 21, 95, -85, -11, 63, -117, -43, 31, 105, -75, -1, 73, -107, -33, 41, 115, -65, 9, 83, -97, -23, 51, 125, -55, 19, 93, -87, -13, 61, -119, -45, 29, 103, -77, -3, 71, -109, -35, 39, 113, -67, 7, 81, -99, -25, 49, 123, -57, 17, 91, -89, -15, 59, -121, -47, 27, 101, -79, -5, 69, -111, -37],
  [-51, 25, 101, -77, -1, 75, -103, -27, 49, 125, -53, 23, 99, -79, -3, 73, -105, -29, 47, 123, -55, 21, 97, -81, -5, 71, -107, -31, 45, 121, -57, 19, 95, -83, -7, 69, -109, -33, 43, 119, -59, 17, 93, -85, -9, 67, -111, -35, 41, 117, -61, 15, 91, -87, -11, 65, -113, -37, 39, 115, -63, 13, 89],
  [-49, 29, 107, -69, 9, 87, -89, -11, 67, -109, -31, 47, 125, -51, 27, 105, -71, 7, 85, -91, -13, 65, -111, -33, 45, 123, -53, 25, 103, -73, 5, 83, -93, -15, 63, -113, -35, 43, 121, -55, 23, 101, -75, 3, 81, -95, -17, 61, -115, -37, 41, 119, -57, 21, 99, -77, 1, 79, -97, -19, 59, -117, -39],
  [-47, 33, 113, -61, 19, 99, -75, 5, 85, -89, -9, 71, -103, -23, 57, -117, -37, 43, 123, -51, 29, 109, -65, 15, 95, -79, 1, 81, -93, -13, 67, -107, -27, 53, -121, -41, 39, 119, -55, 25, 105, -69, 11, 91, -83, -3, 77, -97, -17, 63, -111, -31, 49, -125, -45, 35, 115, -59, 21, 101, -73, 7, 87],
  [-45, 37, 119, -53, 29, 111, -61, 21, 103, -69, 13, 95, -77, 5, 87, -85, -3, 79, -93, -11, 71, -101, -19, 63, -109, -27, 55, -117, -35, 47, -125, -43, 39, 121, -51, 31, 113, -59, 23, 105, -67, 15, 97, -75, 7, 89, -83, -1, 81, -91, -9, 73, -99, -17, 65, -107, -25, 57, -115, -33, 49, -123, -41],
  [-43, 41, 125, -45, 39, 123, -47, 37, 121, -49, 35, 119, -51, 33, 117, -53, 31, 115, -55, 29, 113, -57, 27, 111, -59, 25, 109, -61, 23, 107, -63, 21, 105, -65, 19, 103, -67, 17, 101, -69, 15, 99, -71, 13, 97, -73, 11, 95, -75, 9, 93, -77, 7, 91, -79, 5, 89, -81, 3, 87, -83, 1, 85],
  [-41, 45, -123, -37, 49, -119, -33, 53, -115, -29, 57, -111, -25, 61, -107, -21, 65, -103, -17, 69, -99, -13, 73, -95, -9, 77, -91, -5, 81, -87, -1, 85, -83, 3, 89, -79, 7, 93, -75, 11, 97, -71, 15, 101, -67, 19, 105, -63, 23, 109, -59, 27, 113, -55, 31, 117, -51, 35, 121, -47, 39, 125, -43],
  [-39, 49, -117, -29, 59, -107, -19, 69, -97, -9, 79, -87, 1, 89, -77, 11, 99, -67, 21, 109, -57, 31, 119, -47, 41, -125, -37, 51, -115, -27, 61, -105, -17, 71, -95, -7, 81, -85, 3, 91, -75, 13, 101, -65, 23, 111, -55, 33, 121, -45, 43, -123, -35, 53, -113, -25, 63, -103, -15, 73, -93, -5, 83],
  [-37, 53, -111, -21, 69, -95, -5, 85, -79, 11, 101, -63, 27, 117, -47, 43, -121, -31, 59, -105, -15, 75, -89, 1, 91, -73, 17, 107, -57, 33, 123, -41, 49, -115, -25, 65, -99, -9, 81, -83, 7, 97, -67, 23, 113, -51, 39, -125, -35, 55, -109, -19, 71, -93, -3, 87, -77, 13, 103, -61, 29, 119, -45],
  [-35, 57, -105, -13, 79, -83, 9, 101, -61, 31, 123, -39, 53, -109, -17, 75, -87, 5, 97, -65, 27, 119, -43, 49, -113, -21, 71, -91, 1, 93, -69, 23, 115, -47, 45, -117, -25, 67, -95, -3, 89, -73, 19, 111, -51, 41, -121, -29, 63, -99, -7, 85, -77, 15, 107, -55, 37, -125, -33, 59, -103, -11, 81],
  [-33, 61, -99, -5, 89, -71, 23, 117, -43, 51, -109, -15, 79, -81, 13, 107, -53, 41, -119, -25, 69, -91, 3, 97, -63, 31, 125, -35, 59, -101, -7, 87, -73, 21, 115, -45, 49, -111, -17, 77, -83, 11, 105, -55, 39, -121, -27, 67, -93, 1, 95, -65, 29, 123, -37, 57, -103, -9, 85, -75, 19, 113, -47],
  [-31, 65, -93, 3, 99, -59, 37, -121, -25, 71, -87, 9, 105, -53, 43, -115, -19, 77, -81, 15, 111, -47, 49, -109, -13, 83, -75, 21, 117, -41, 55, -103, -7, 89, -69, 27, 123, -35, 61, -97, -1, 95, -63, 33, -125, -29, 67, -91, 5, 101, -57, 39, -119, -23, 73, -85, 11, 107, -51, 45, -113, -17, 79],
  [-29, 69, -87, 11, 109, -47, 51, -105, -7, 91, -65, 33, -123, -25, 73, -83, 15, 113, -43, 55, -101, -3, 95, -61, 37, -119, -21, 77, -79, 19, 117, -39, 59, -97, 1, 99, -57, 41, -115, -17, 81, -75, 23, 121, -35, 63, -93, 5, 103, -53, 45, -111, -13, 85, -71, 27, 125, -31, 67, -89, 9, 107, -49],
  [-27, 73, -81, 19, 119, -35, 65, -89, 11, 111, -43, 57, -97, 3, 103, -51, 49, -105, -5, 95, -59, 41, -113, -13, 87, -67, 33, -121, -21, 79, -75, 25, 125, -29, 71, -83, 17, 117, -37, 63, -91, 9, 109, -45, 55, -99, 1, 101, -53, 47, -107, -7, 93, -61, 39, -115, -15, 85, -69, 31, -123, -23, 77],
  [-25, 77, -75, 27, -125, -23, 79, -73, 29, -123, -21, 81, -71, 31, -121, -19, 83, -69, 33, -119, -17, 85, -67, 35, -117, -15, 87, -65, 37, -115, -13, 89, -63, 39, -113, -11, 91, -61, 41, -111, -9, 93, -59, 43, -109, -7, 95, -57, 45, -107, -5, 97, -55, 47, -105, -3, 99, -53, 49, -103, -1, 101, -51],
  [-23, 81, -69, 35, -115, -11, 93, -57, 47, -103, 1, 105, -45, 59, -91, 13, 117, -33, 71, -79, 25, -125, -21, 83, -67, 37, -113, -9, 95, -55, 49, -101, 3, 107, -43, 61, -89, 15, 119, -31, 73, -77, 27, -123, -19, 85, -65, 39, -111, -7, 97, -53, 51, -99, 5, 109, -41, 63, -87, 17, 121, -29, 75],
  [-21, 85, -63, 43, -105, 1, 107, -41, 65, -83, 23, -125, -19, 87, -61, 45, -103, 3, 109, -39, 67, -81, 25, -123, -17, 89, -59, 47, -101, 5, 111, -37, 69, -79, 27, -121, -15, 91, -57, 49, -99, 7, 113, -35, 71, -77, 29, -119, -13, 93, -55, 51, -97, 9, 115, -33, 73, -75, 31, -117, -11, 95, -53],
  [-19, 89, -57, 51, -95, 13, 121, -25, 83, -63, 45, -101, 7, 115, -31, 77, -69, 39, -107, 1, 109, -37, 71, -75, 33, -113, -5, 103, -43, 65, -81, 27, -119, -11, 97, -49, 59, -87, 21, -125, -17, 91, -55, 53, -93, 15, 123, -23, 85, -61, 47, -99, 9, 117, -29, 79, -67, 41, -105, 3, 111, -35, 73],
  [-17, 93, -51, 59, -85, 25, -119, -9, 101, -43, 67, -77, 33, -111, -1, 109, -35, 75, -69, 41, -103, 7, 117, -27, 83, -61, 49, -95, 15, 125, -19, 91, -53, 57, -87, 23, -121, -11, 99, -45, 65, -79, 31, -113, -3, 107, -37, 73, -71, 39, -105, 5, 115, -29, 81, -63, 47, -97, 13, 123, -21, 89, -55],
  [-15, 97, -45, 67, -75, 37, -105, 7, 119, -23, 89, -53, 59, -83, 29, -113, -1, 111, -31, 81, -61, 51, -91, 21, -121, -9, 103, -39, 73, -69, 43, -99, 13, 125, -17, 95, -47, 65, -77, 35, -107, 5, 117, -25, 87, -55, 57, -85, 27, -115, -3, 109, -33, 79, -63, 49, -93, 19, -123, -11, 101, -41, 71],
  [-13, 101, -39, 75, -65, 49, -91, 23, -117, -3, 111, -29, 85, -55, 59, -81, 33, -107, 7, 121, -19, 95, -45, 69, -71, 43, -97, 17, -123, -9, 105, -35, 79, -61, 53, -87, 27, -113, 1, 115, -25, 89, -51, 63, -77, 37, -103, 11, 125, -15, 99, -41, 73, -67, 47, -93, 21, -119, -5, 109, -31, 83, -57],
  [-11, 105, -33, 83, -55, 61, -77, 39, -99, 17, -121, -5, 111, -27, 89, -49, 67, -71, 45, -93, 23, -115, 1, 117, -21, 95, -43, 73, -65, 51, -87, 29, -109, 7, 123, -15, 101, -37, 79, -59, 57, -81, 35, -103, 13, -125, -9, 107, -31, 85, -53, 63, -75, 41, -97, 19, -119, -3, 113, -25, 91, -47, 69],
  [-9, 109, -27, 91, -45, 73, -63, 55, -81, 37, -99, 19, -117, 1, 119, -17, 101, -35, 83, -53, 65, -71, 47, -89, 29, -107, 11, -125, -7, 111, -25, 93, -43, 75, -61, 57, -79, 39, -97, 21, -115, 3, 121, -15, 103, -33, 85, -51, 67, -69, 49, -87, 31, -105, 13, -123, -5, 113, -23, 95, -41, 77, -59],
  [-7, 113, -21, 99, -35, 85, -49, 71, -63, 57, -77, 43, -91, 29, -105, 15, -119, 1, 121, -13, 107, -27, 93, -41, 79, -55, 65, -69, 51, -83, 37, -97, 23, -111, 9, -125, -5, 115, -19, 101, -33, 87, -47, 73, -61, 59, -75, 45, -89, 31, -103, 17, -117, 3, 123, -11, 109, -25, 95, -39, 81, -53, 67],
  [-5, 117, -15, 107, -25, 97, -35, 87, -45, 77, -55, 67, -65, 57, -75, 47, -85, 37, -95, 27, -105, 17, -115, 7, -125, -3, 119, -13, 109, -23, 99, -33, 89, -43, 79, -53, 69, -63, 59, -73, 49, -83, 39, -93, 29, -103, 19, -113, 9, -123, -1, 121, -11, 111, -21, 101, -31, 91, -41, 81, -51, 71, -61],
  [-3, 121, -9, 115, -15, 109, -21, 103, -27, 97, -33, 91, -39, 85, -45, 79, -51, 73, -57, 67, -63, 61, -69, 55, -75, 49, -81, 43, -87, 37, -93, 31, -99, 25, -105, 19, -111, 13, -117, 7, -123, 1, 125, -5, 119, -11, 113, -17, 107, -23, 101, -29, 95, -35, 89, -41, 83, -47, 77, -53, 71, -59, 65],
  [-1, 125, -3, 123, -5, 121, -7, 119, -9, 117, -11, 115, -13, 113, -15, 111, -17, 109, -19, 107, -21, 105, -23, 103, -25, 101, -27, 99, -29, 97, -31, 95, -33, 93, -35, 91, -37, 89, -39, 87, -41, 85, -43, 83, -45, 81, -47, 79, -49, 77, -51, 75, -53, 73, -55, 71, -57, 69, -59, 67, -61, 65, -63]]

def B : List (List Int) := [
  [-55156670819013986, 423523731663564, 21738725725989106, -111068375504289971, 73160809122027446, -1033082108092629, -273996241356140274, 26150246785693679, -217509958698224981, -230366148510990569, -129242259951787706, -162597131760442844, -201130142325973006, -638248445047119, -269680195315729981, -282540906881497746, -293320036521088131, -58417272860393976, -279159016091911281, 557386849563232  -- (+887 chars; full line in the Zenodo source)
  [423523731663564, -111068375504289971, -1033082108092629, 26150246785693679, -230366148510990569, -162597131760442844, -638248445047119, -282540906881497746, -58417272860393976, 5573868495632321, -317904513517288486, -216957939838059274, -16253028158925366, -177016720114791099, -174362021604923051, -58286759022967216, -247581949089430731, -118714928011633781, -72656216396088261, -357647176832407  -- (+859 chars; full line in the Zenodo source)
  [21738725725989106, -1033082108092629, -217509958698224981, -162597131760442844, -269680195315729981, -58417272860393976, -165720672974374111, -216957939838059274, -298378729779816789, -174362021604923051, -272308542847855084, -118714928011633781, -415472753699461189, -32634406619712166, -192334347113811309, 125472560449380446, -221549260445630454, 47939211432826936, -165774142285339104, 1842153  -- (+866 chars; full line in the Zenodo source)
  [-111068375504289971, 26150246785693679, -162597131760442844, -282540906881497746, 5573868495632321, -216957939838059274, -177016720114791099, -58286759022967216, -118714928011633781, -357647176832407474, -48171318361245556, 125472560449380446, -255518677845587991, 32482617629237766, 184215345755237014, 449643663924974, 340394109744598654, 209341095190926924, 221549260445630454, 3755155562054526  -- (+865 chars; full line in the Zenodo source)
  [73160809122027446, -230366148510990569, -269680195315729981, 5573868495632321, -369047933450716911, -174362021604923051, -312381474987222826, -357647176832407474, -192334347113811309, 8235072767264459, -209341095190926924, 184215345755237014, -123140240974781729, 165774142285339104, 255518677845587991, 375515556205452651, 32634406619712166, 463102752565185131, 58286759022967216, 298378729779816  -- (+868 chars; full line in the Zenodo source)
  [-1033082108092629, -162597131760442844, -58417272860393976, -216957939838059274, -174362021604923051, -118714928011633781, -32634406619712166, 125472560449380446, 47939211432826936, 184215345755237014, 166239179406943956, 209341095190926924, 419927672724407116, 267375629807208069, 463102752565185131, 307142517691378866, 369047933450716911, 279159016091911281, 201130142325973006, 273996241356140  -- (+868 chars; full line in the Zenodo source)
  [-273996241356140274, -638248445047119, -165720672974374111, -177016720114791099, -312381474987222826, -32634406619712166, -419927672724407116, 32482617629237766, -449643663924974, 165774142285339104, -8235072767264459, 267375629807208069, 118714928011633781, 386651058991559964, 317904513517288486, 269680195315729981, -26150246785693679, 55156670819013986, -1033082108092629, -201130142325973006,  -- (+868 chars; full line in the Zenodo source)
  [26150246785693679, -282540906881497746, -216957939838059274, -58286759022967216, -357647176832407474, 125472560449380446, 32482617629237766, 449643663924974, 209341095190926924, 375515556205452651, 415472753699461189, 307142517691378866, 340814723116532389, 269680195315729981, 273996241356140274, -55156670819013986, -217509958698224981, -293320036521088131, -369047933450716911, -272308542847855  -- (+865 chars; full line in the Zenodo source)
  [-217509958698224981, -58417272860393976, -298378729779816789, -118714928011633781, -192334347113811309, 47939211432826936, -449643663924974, 209341095190926924, 190187185345915339, 463102752565185131, 177016720114791099, 279159016091911281, 230366148510990569, 55156670819013986, 26150246785693679, -293320036521088131, -16253028158925366, -312381474987222826, -48171318361245556, -245628549675748  -- (+869 chars; full line in the Zenodo source)
  [-230366148510990569, 5573868495632321, -174362021604923051, -357647176832407474, 8235072767264459, 184215345755237014, 165774142285339104, 375515556205452651, 463102752565185131, 298378729779816789, 293320036521088131, 273996241356140274, 21738725725989106, -201130142325973006, -340814723116532389, -272308542847855084, -267375629807208069, -245628549675748984, -449643663924974, -479392114328269  -- (+864 chars; full line in the Zenodo source)
  [-129242259951787706, -317904513517288486, -272308542847855084, -48171318361245556, -209341095190926924, 166239179406943956, -8235072767264459, 415472753699461189, 177016720114791099, 293320036521088131, 1033082108092629, 73160809122027446, -282540906881497746, -298378729779816789, -72656216396088261, -419927672724407116, 184215345755237014, -32482617629237766, 192334347113811309, 24758194908943  -- (+867 chars; full line in the Zenodo source)
  [-162597131760442844, -216957939838059274, -118714928011633781, 125472560449380446, 184215345755237014, 209341095190926924, 267375629807208069, 307142517691378866, 279159016091911281, 273996241356140274, 73160809122027446, -293320036521088131, -386651058991559964, -253742226192028336, -245628549675748984, -123140240974781729, -8235072767264459, 72656216396088261, 16253028158925366, 6382484450471  -- (+864 chars; full line in the Zenodo source)
  [-201130142325973006, -16253028158925366, -415472753699461189, -255518677845587991, -123140240974781729, 419927672724407116, 118714928011633781, 340814723116532389, 230366148510990569, 21738725725989106, -282540906881497746, -386651058991559964, -32634406619712166, -209341095190926924, 340394109744598654, 190187185345915339, 272308542847855084, -5573868495632321, 273996241356140274, -10330821080  -- (+869 chars; full line in the Zenodo source)
  [-638248445047119, -177016720114791099, -32634406619712166, 32482617629237766, 165774142285339104, 267375629807208069, 386651058991559964, 269680195315729981, 55156670819013986, -201130142325973006, -298378729779816789, -253742226192028336, -209341095190926924, 27607867455979464, 48171318361245556, 174362021604923051, 282540906881497746, -423523731663564, -162597131760442844, -16253028158925366,  -- (+866 chars; full line in the Zenodo source)
  [-269680195315729981, -174362021604923051, -192334347113811309, 184215345755237014, 255518677845587991, 463102752565185131, 317904513517288486, 273996241356140274, 26150246785693679, -340814723116532389, -72656216396088261, -245628549675748984, 340394109744598654, 48171318361245556, 386651058991559964, 638248445047119, -55156670819013986, -282540906881497746, -307142517691378866, -19018718534591  -- (+865 chars; full line in the Zenodo source)
  [-282540906881497746, -58286759022967216, 125472560449380446, 449643663924974, 375515556205452651, 307142517691378866, 269680195315729981, -55156670819013986, -293320036521088131, -272308542847855084, -419927672724407116, -123140240974781729, 190187185345915339, 174362021604923051, 638248445047119, 423523731663564, -58417272860393976, -247581949089430731, 8235072767264459, 166239179406943956, 19  -- (+863 chars; full line in the Zenodo source)
  [-293320036521088131, -247581949089430731, -221549260445630454, 340394109744598654, 32634406619712166, 369047933450716911, -26150246785693679, -217509958698224981, -16253028158925366, -267375629807208069, 184215345755237014, -8235072767264459, 272308542847855084, 282540906881497746, -55156670819013986, -58417272860393976, -312381474987222826, -255518677845587991, 27607867455979464, 2537422261920  -- (+869 chars; full line in the Zenodo source)
  [-58417272860393976, -118714928011633781, 47939211432826936, 209341095190926924, 463102752565185131, 279159016091911281, 55156670819013986, -293320036521088131, -312381474987222826, -245628549675748984, -32482617629237766, 72656216396088261, -5573868495632321, -423523731663564, -282540906881497746, -247581949089430731, -255518677845587991, 165774142285339104, 415472753699461189, 1657206729743741  -- (+867 chars; full line in the Zenodo source)
  [-279159016091911281, -72656216396088261, -165774142285339104, 221549260445630454, 58286759022967216, 201130142325973006, -1033082108092629, -369047933450716911, -48171318361245556, -449643663924974, 192334347113811309, 16253028158925366, 273996241356140274, -162597131760442844, -307142517691378866, 8235072767264459, 27607867455979464, 415472753699461189, -5573868495632321, 55156670819013986, -5  -- (+867 chars; full line in the Zenodo source)
  [5573868495632321, -357647176832407474, 184215345755237014, 375515556205452651, 298378729779816789, 273996241356140274, -201130142325973006, -272308542847855084, -245628549675748984, -47939211432826936, 247581949089430731, 638248445047119, -1033082108092629, -16253028158925366, -190187185345915339, 166239179406943956, 253742226192028336, 165720672974374111, 55156670819013986, -279159016091911281  -- (+870 chars; full line in the Zenodo source)
  [-165720672974374111, -32634406619712166, -449643663924974, 267375629807208069, 317904513517288486, 55156670819013986, 5573868495632321, -253742226192028336, 123140240974781729, 48171318361245556, 340814723116532389, -423523731663564, -279159016091911281, -357647176832407474, -166239179406943956, 192334347113811309, 216957939838059274, -21738725725989106, -58417272860393976, -415472753699461189,  -- (+869 chars; full line in the Zenodo source)
  [-317904513517288486, -48171318361245556, 166239179406943956, 415472753699461189, 293320036521088131, 73160809122027446, -298378729779816789, -419927672724407116, -32482617629237766, 247581949089430731, 162597131760442844, -230366148510990569, -58286759022967216, 47939211432826936, 221549260445630454, 386651058991559964, 273996241356140274, -269680195315729981, -463102752565185131, -340394109744  -- (+863 chars; full line in the Zenodo source)
  [-340814723116532389, -190187185345915339, 27607867455979464, 312381474987222826, 162597131760442844, -129242259951787706, -247581949089430731, -165774142285339104, 375515556205452651, 216957939838059274, 55156670819013986, -317904513517288486, -192334347113811309, 340394109744598654, 118714928011633781, 201130142325973006, -230366148510990569, -272308542847855084, 32482617629237766, -1254725604  -- (+868 chars; full line in the Zenodo source)
  [-216957939838059274, 125472560449380446, 209341095190926924, 307142517691378866, 273996241356140274, -293320036521088131, -253742226192028336, -123140240974781729, 72656216396088261, 638248445047119, -230366148510990569, -247581949089430731, -27607867455979464, 192334347113811309, 165720672974374111, 21738725725989106, -298378729779816789, -221549260445630454, 255518677845587991, 17701672011479  -- (+864 chars; full line in the Zenodo source)
  [-369047933450716911, 8235072767264459, 255518677845587991, 298378729779816789, -423523731663564, -340814723116532389, 125472560449380446, -47939211432826936, 386651058991559964, 111068375504289971, -165720672974374111, -190187185345915339, -32482617629237766, 307142517691378866, 1033082108092629, -279159016091911281, -48171318361245556, 27607867455979464, 272308542847855084, -26150246785693679,  -- (+871 chars; full line in the Zenodo source)
  [-16253028158925366, -255518677845587991, 419927672724407116, 340814723116532389, 21738725725989106, -386651058991559964, -209341095190926924, 190187185345915339, -5573868495632321, -1033082108092629, -58286759022967216, -27607867455979464, 267375629807208069, 293320036521088131, -217509958698224981, -312381474987222826, -166239179406943956, 357647176832407474, 638248445047119, -1625971317604428  -- (+871 chars; full line in the Zenodo source)
  [-298378729779816789, 47939211432826936, 190187185345915339, 279159016091911281, 26150246785693679, -312381474987222826, 123140240974781729, 72656216396088261, 129242259951787706, -282540906881497746, -267375629807208069, 165774142285339104, 174362021604923051, -21738725725989106, -216957939838059274, -221549260445630454, 419927672724407116, 317904513517288486, 73160809122027446, -58286759022967  -- (+862 chars; full line in the Zenodo source)
  [-177016720114791099, 32482617629237766, 267375629807208069, 269680195315729981, -201130142325973006, -253742226192028336, 27607867455979464, 174362021604923051, -423523731663564, -16253028158925366, 47939211432826936, 192334347113811309, 293320036521088131, -129242259951787706, -415472753699461189, -184215345755237014, 58286759022967216, 111068375504289971, -216957939838059274, -255518677845587  -- (+864 chars; full line in the Zenodo source)
  [-386651058991559964, -27607867455979464, 357647176832407474, 129242259951787706, -58417272860393976, -375515556205452651, 221549260445630454, 317904513517288486, -273996241356140274, -118714928011633781, -123140240974781729, 272308542847855084, 111068375504289971, -369047933450716911, 47939211432826936, 48171318361245556, 269680195315729981, -638248445047119, -267375629807208069, 20934109519092  -- (+866 chars; full line in the Zenodo source)
  [-174362021604923051, 184215345755237014, 463102752565185131, 273996241356140274, -340814723116532389, -245628549675748984, 48171318361245556, 638248445047119, -282540906881497746, -190187185345915339, 221549260445630454, 165720672974374111, -217509958698224981, -415472753699461189, 27607867455979464, 177016720114791099, 423523731663564, -58286759022967216, 123140240974781729, 312381474987222826  -- (+865 chars; full line in the Zenodo source)
  [-307142517691378866, 123140240974781729, 247581949089430731, -21738725725989106, -177016720114791099, -340394109744598654, 463102752565185131, 1033082108092629, -369047933450716911, 32482617629237766, 357647176832407474, 217509958698224981, -317904513517288486, -245628549675748984, 267375629807208069, 162597131760442844, -279159016091911281, 8235072767264459, 190187185345915339, 269680195315729  -- (+865 chars; full line in the Zenodo source)
  [-58286759022967216, 449643663924974, 307142517691378866, -55156670819013986, -272308542847855084, -123140240974781729, 174362021604923051, 423523731663564, -247581949089430731, 166239179406943956, 386651058991559964, 21738725725989106, -312381474987222826, -184215345755237014, 177016720114791099, -111068375504289971, -118714928011633781, 340394109744598654, 298378729779816789, 73160809122027446  -- (+869 chars; full line in the Zenodo source)
  [-272308542847855084, 166239179406943956, 177016720114791099, 73160809122027446, -72656216396088261, -32482617629237766, 340814723116532389, -230366148510990569, -267375629807208069, 221549260445630454, 58417272860393976, -269680195315729981, 125472560449380446, 190187185345915339, 201130142325973006, 5573868495632321, -245628549675748984, 253742226192028336, -26150246785693679, -369047933450716  -- (+866 chars; full line in the Zenodo source)
  [-247581949089430731, 340394109744598654, 369047933450716911, -217509958698224981, -267375629807208069, -8235072767264459, 282540906881497746, -58417272860393976, -255518677845587991, 253742226192028336, 273996241356140274, -298378729779816789, -166239179406943956, 58286759022967216, 423523731663564, -118714928011633781, 165774142285339104, 340814723116532389, -129242259951787706, -1923343471138  -- (+867 chars; full line in the Zenodo source)
  [-312381474987222826, 165774142285339104, 317904513517288486, -201130142325973006, 125472560449380446, 48171318361245556, 217509958698224981, -16253028158925366, -166239179406943956, 307142517691378866, -111068375504289971, -415472753699461189, 245628549675748984, 58417272860393976, -293320036521088131, -255518677845587991, 357647176832407474, -73160809122027446, -174362021604923051, -1231402409  -- (+865 chars; full line in the Zenodo source)
  [-118714928011633781, 209341095190926924, 279159016091911281, -293320036521088131, -245628549675748984, 72656216396088261, -423523731663564, -247581949089430731, 165774142285339104, 165720672974374111, -269680195315729981, -221549260445630454, 357647176832407474, 111068375504289971, -58286759022967216, 340394109744598654, 340814723116532389, -201130142325973006, -419927672724407116, 326344066197  -- (+865 chars; full line in the Zenodo source)
  [-463102752565185131, 245628549675748984, 282540906881497746, -165720672974374111, -27607867455979464, 58286759022967216, 73160809122027446, -32634406619712166, -125472560449380446, 129242259951787706, -16253028158925366, -449643663924974, 298378729779816789, -230366148510990569, -375515556205452651, 267375629807208069, 1033082108092629, -307142517691378866, 340394109744598654, 31790451351728848  -- (+867 chars; full line in the Zenodo source)
  [-72656216396088261, 221549260445630454, 201130142325973006, -369047933450716911, -449643663924974, 16253028158925366, -162597131760442844, 8235072767264459, 415472753699461189, 55156670819013986, -463102752565185131, 255518677845587991, 638248445047119, -216957939838059274, 123140240974781729, 298378729779816789, -129242259951787706, -419927672724407116, 357647176832407474, -423523731663564, -1  -- (+865 chars; full line in the Zenodo source)
  [-415472753699461189, 419927672724407116, 230366148510990569, -386651058991559964, 340394109744598654, -5573868495632321, -279159016091911281, -27607867455979464, 174362021604923051, -217509958698224981, 125472560449380446, 357647176832407474, 55156670819013986, -72656216396088261, -8235072767264459, 129242259951787706, -177016720114791099, -184215345755237014, 165720672974374111, -5841727286039  -- (+866 chars; full line in the Zenodo source)
  [-357647176832407474, 375515556205452651, 273996241356140274, -272308542847855084, -47939211432826936, 638248445047119, -16253028158925366, 166239179406943956, 165720672974374111, -279159016091911281, -340394109744598654, 177016720114791099, -162597131760442844, -255518677845587991, 312381474987222826, 73160809122027446, -192334347113811309, 32634406619712166, -423523731663564, -7265621639608826  -- (+864 chars; full line in the Zenodo source)
  [-253742226192028336, 192334347113811309, 111068375504289971, -463102752565185131, 419927672724407116, -26150246785693679, -272308542847855084, 245628549675748984, 162597131760442844, -386651058991559964, 165774142285339104, 282540906881497746, -369047933450716911, 166239179406943956, -5573868495632321, -165720672974374111, 123140240974781729, 216957939838059274, -293320036521088131, -2760786745  -- (+869 chars; full line in the Zenodo source)
  [-32634406619712166, 267375629807208069, 55156670819013986, -253742226192028336, 48171318361245556, -423523731663564, -357647176832407474, 192334347113811309, -21738725725989106, -415472753699461189, 190187185345915339, 111068375504289971, -72656216396088261, 375515556205452651, -73160809122027446, -463102752565185131, -125472560449380446, 1033082108092629, -118714928011633781, 41992767272440711  -- (+867 chars; full line in the Zenodo source)
  [-267375629807208069, 253742226192028336, 423523731663564, -192334347113811309, 415472753699461189, -111068375504289971, -375515556205452651, 463102752565185131, -1033082108092629, -419927672724407116, 312381474987222826, 26150246785693679, -221549260445630454, 272308542847855084, -230366148510990569, -245628549675748984, 307142517691378866, -162597131760442844, -209341095190926924, 386651058991  -- (+872 chars; full line in the Zenodo source)
  [-48171318361245556, 415472753699461189, 73160809122027446, -419927672724407116, 247581949089430731, -230366148510990569, 47939211432826936, 386651058991559964, -269680195315729981, -340394109744598654, 216957939838059274, 5573868495632321, 449643663924974, 279159016091911281, -369047933450716911, 27607867455979464, 638248445047119, -174362021604923051, 245628549675748984, 217509958698224981, -3  -- (+865 chars; full line in the Zenodo source)
  [-192334347113811309, 463102752565185131, 26150246785693679, -245628549675748984, 386651058991559964, -282540906881497746, -166239179406943956, 165720672974374111, -216957939838059274, 27607867455979464, 201130142325973006, -58286759022967216, -8235072767264459, -73160809122027446, -357647176832407474, 32634406619712166, 21738725725989106, 125472560449380446, 247581949089430731, -129242259951787  -- (+866 chars; full line in the Zenodo source)
  [-190187185345915339, 312381474987222826, -129242259951787706, -165774142285339104, 216957939838059274, -317904513517288486, 340394109744598654, 201130142325973006, -272308542847855084, -125472560449380446, -423523731663564, -48171318361245556, 463102752565185131, -217509958698224981, -209341095190926924, 16253028158925366, 5573868495632321, 166239179406943956, 269680195315729981, -3071425176913  -- (+868 chars; full line in the Zenodo source)
  [-375515556205452651, 272308542847855084, -638248445047119, -166239179406943956, 279159016091911281, -177016720114791099, 255518677845587991, -73160809122027446, -32634406619712166, 72656216396088261, -217509958698224981, 32482617629237766, 216957939838059274, -340814723116532389, 165774142285339104, 230366148510990569, -463102752565185131, 267375629807208069, -111068375504289971, -2215492604456  -- (+867 chars; full line in the Zenodo source)
  [125472560449380446, 307142517691378866, -293320036521088131, -123140240974781729, 638248445047119, -247581949089430731, 192334347113811309, 21738725725989106, -221549260445630454, 177016720114791099, 5573868495632321, 340394109744598654, 129242259951787706, -463102752565185131, 32634406619712166, -1033082108092629, 47939211432826936, 369047933450716911, -340814723116532389, -32482617629237766,   -- (+868 chars; full line in the Zenodo source)
  [-419927672724407116, 386651058991559964, 5573868495632321, 27607867455979464, 217509958698224981, -357647176832407474, 72656216396088261, -129242259951787706, 184215345755237014, 58417272860393976, -307142517691378866, 375515556205452651, 423523731663564, -221549260445630454, 298378729779816789, -317904513517288486, -32482617629237766, 273996241356140274, -32634406619712166, 118714928011633781,  -- (+865 chars; full line in the Zenodo source)
  [8235072767264459, 298378729779816789, -340814723116532389, -47939211432826936, 111068375504289971, -190187185345915339, 307142517691378866, -279159016091911281, 27607867455979464, -26150246785693679, -32634406619712166, 312381474987222826, -269680195315729981, -123140240974781729, 162597131760442844, -72656216396088261, 415472753699461189, -129242259951787706, -166239179406943956, 2825409068814  -- (+867 chars; full line in the Zenodo source)
  [-221549260445630454, 369047933450716911, -16253028158925366, -8235072767264459, -55156670819013986, -255518677845587991, 216957939838059274, -298378729779816789, 419927672724407116, 423523731663564, -245628549675748984, 340814723116532389, -177016720114791099, -125472560449380446, 21738725725989106, 47939211432826936, 317904513517288486, -386651058991559964, 375515556205452651, -111068375504289  -- (+868 chars; full line in the Zenodo source)
  [-255518677845587991, 340814723116532389, -386651058991559964, 190187185345915339, -1033082108092629, -27607867455979464, 293320036521088131, -312381474987222826, 357647176832407474, -162597131760442844, 449643663924974, 129242259951787706, -253742226192028336, 247581949089430731, -58417272860393976, 165774142285339104, -73160809122027446, -375515556205452651, 177016720114791099, -21695793983805  -- (+865 chars; full line in the Zenodo source)
  [-245628549675748984, 165720672974374111, -58286759022967216, 32634406619712166, -129242259951787706, 449643663924974, 230366148510990569, -267375629807208069, 307142517691378866, -317904513517288486, 255518677845587991, -55156670819013986, 47939211432826936, -5573868495632321, -272308542847855084, 253742226192028336, -162597131760442844, -123140240974781729, 217509958698224981, -481713183612455  -- (+868 chars; full line in the Zenodo source)
  [47939211432826936, 279159016091911281, -312381474987222826, 72656216396088261, -282540906881497746, 165774142285339104, -21738725725989106, -221549260445630454, 317904513517288486, -58286759022967216, 253742226192028336, -201130142325973006, -184215345755237014, 1033082108092629, 125472560449380446, 369047933450716911, -386651058991559964, 48171318361245556, -230366148510990569, 449643663924974  -- (+870 chars; full line in the Zenodo source)
  [-209341095190926924, 293320036521088131, -72656216396088261, 247581949089430731, -165720672974374111, 221549260445630454, -111068375504289971, -340394109744598654, 201130142325973006, -32634406619712166, 174362021604923051, -369047933450716911, 375515556205452651, 26150246785693679, -449643663924974, 217509958698224981, -190187185345915339, 16253028158925366, -386651058991559964, 26737562980720  -- (+866 chars; full line in the Zenodo source)
  [32482617629237766, 269680195315729981, -253742226192028336, 174362021604923051, -16253028158925366, 192334347113811309, -129242259951787706, -184215345755237014, 111068375504289971, -255518677845587991, 279159016091911281, -463102752565185131, 247581949089430731, -317904513517288486, 419927672724407116, -273996241356140274, -449643663924974, -26150246785693679, 125472560449380446, 3408147231165  -- (+868 chars; full line in the Zenodo source)
  [-165774142285339104, 201130142325973006, -48171318361245556, 16253028158925366, -307142517691378866, 415472753699461189, -58417272860393976, 255518677845587991, 73160809122027446, 123140240974781729, -26150246785693679, -419927672724407116, 165720672974374111, -118714928011633781, 247581949089430731, -340814723116532389, 375515556205452651, -230366148510990569, -184215345755237014, -21738725725  -- (+864 chars; full line in the Zenodo source)
  [-27607867455979464, 129242259951787706, -375515556205452651, 317904513517288486, -118714928011633781, 272308542847855084, -369047933450716911, 48171318361245556, -638248445047119, 209341095190926924, 21738725725989106, -166239179406943956, -26150246785693679, 8235072767264459, 279159016091911281, -415472753699461189, 174362021604923051, -177016720114791099, 253742226192028336, -2933200365210881  -- (+866 chars; full line in the Zenodo source)
  [-340394109744598654, 217509958698224981, 8235072767264459, 58417272860393976, -253742226192028336, 298378729779816789, -58286759022967216, 118714928011633781, -340814723116532389, 192334347113811309, -638248445047119, -47939211432826936, 73160809122027446, 449643663924974, 111068375504289971, -209341095190926924, 201130142325973006, -190187185345915339, 317904513517288486, -463102752565185131,   -- (+866 chars; full line in the Zenodo source)
  [184215345755237014, 273996241356140274, -245628549675748984, 638248445047119, -190187185345915339, 165720672974374111, -415472753699461189, 177016720114791099, -58286759022967216, 312381474987222826, -369047933450716911, 32634406619712166, -58417272860393976, 419927672724407116, -129242259951787706, -32482617629237766, -111068375504289971, 449643663924974, -21738725725989106, -16577414228533910  -- (+867 chars; full line in the Zenodo source)
  [-166239179406943956, -73160809122027446, 32482617629237766, 230366148510990569, -221549260445630454, 269680195315729981, -190187185345915339, -5573868495632321, -253742226192028336, 369047933450716911, -118714928011633781, 174362021604923051, -307142517691378866, 312381474987222826, -16253028158925366, 357647176832407474, -165720672974374111, 192334347113811309, -282540906881497746, -8235072767  -- (+871 chars; full line in the Zenodo source)
  [123140240974781729, -21738725725989106, -340394109744598654, 1033082108092629, 32482617629237766, 217509958698224981, -245628549675748984, 162597131760442844, 8235072767264459, 269680195315729981, -375515556205452651, 58417272860393976, -48171318361245556, 165720672974374111, -253742226192028336, 216957939838059274, -72656216396088261, 298378729779816789, -312381474987222826, 174362021604923051  -- (+863 chars; full line in the Zenodo source)
  [-449643663924974, 55156670819013986, 123140240974781729, -423523731663564, -166239179406943956, -21738725725989106, 184215345755237014, 111068375504289971, -340394109744598654, -73160809122027446, -27607867455979464, 1033082108092629, -165774142285339104, 273996241356140274, 32482617629237766, -26150246785693679, -209341095190926924, 217509958698224981, 47939211432826936, 230366148510990569, -2  -- (+866 chars; full line in the Zenodo source)

set_option maxRecDepth 100000 in
theorem A_def : A = (rng 1 63).map (fun t => rowA (126 + 1) t (rng 1 63)) := rfl
set_option maxRecDepth 100000 in
theorem len : allLen 63 A = true := rfl
set_option maxRecDepth 100000 in
theorem cert : lcs 63 B A = sid 661550413311054017530 63 := rfl

theorem d_ne : (661550413311054017530 : Int) ≠ 0 := by
  intro h
  have h' : false = true := congrArg (fun z : Int => Nat.beq z.natAbs 0) h
  exact Bool.noConfusion h'

/-- Every g of length 63 with A g = 0 is zero. -/
theorem kernel (g : List Int) (hg : g.length = 63) (h0 : mv A g = zeros 63) : g = zeros 63 :=
  kernel_zero 63 661550413311054017530 d_ne A B len cert g hg h0

set_option maxRecDepth 100000 in
theorem delta : deltaOK 126 63 = true := rfl

/-- **Balanced ⇒ pairs for p = 127.** A list with entries in (0, 127) that is balanced for 1 ≤ t ≤ 63
    has as many copies of x as of 127 − x for every 1 ≤ x ≤ 63 (any length). -/
theorem pairs (c : List Nat) (hr : ∀ y, y ∈ c → 0 < y ∧ y < 127)
    (hb : ∀ t, 1 ≤ t → t < 1 + 63 → tsum 127 t c + tsum 127 t c = c.length * 127) :
    (rng 1 63).all (fun x => Nat.beq (cnt x c) (cnt (127 - x) c)) = true :=
  pairs_of_bal 126 63 661550413311054017530 d_ne A B len cert A_def delta c hr hb

end MailletCert127

#print axioms MailletCert127.A_def
#print axioms MailletCert127.len
#print axioms MailletCert127.cert
#print axioms MailletCert127.d_ne
#print axioms MailletCert127.kernel
#print axioms MailletCert127.delta
#print axioms MailletCert127.pairs

#print axioms: 7 files, 7 theorems each, no axioms.

81.225 Balanced characters for odd primes \(p\le 113\)

For each odd prime \(p\le 113\) a balanced list with entries in \((0,p)\) is a union of complementary pairs, and a balanced 6-list has a \(2+4\) split. From the Maillet certificate of \(p\); shown for \(p=13\).

hodge/MailletSplitP13.lean

/-
  hodge/MailletSplitP13.lean — T41 (goals G529b, G526b at p = 13): balanced characters of degree 13 are unions of
  complementary pairs at every length (PairsSplit.allPairs), and length-6 ones have a 2 + 4 split. From the Maillet
  certificate MailletCert13 and hodge/MailletSplit; the units 1 ≤ t ≤ 6 are checked by rfl. Lean 4 core.
-/
import hodge.MailletCert13
import hodge.MailletSplit

namespace MailletSplitP13
open MailletBridge MailletSplit

set_option maxRecDepth 100000 in
theorem units_ok : (rng 1 6).all (fun t => (FermatPrime.units 13).contains t) = true := rfl

theorem sym (c : List Nat) (hr : c.all (PairsSplit.inR 13) = true) (hb : Indecomp.bal 13 c = true) : Sym 13 c :=
  sym_of_all 6 c (MailletCert13.pairs c (inR_all 13 c hr) (bal_half 13 6 units_ok c hb))

/-- Every balanced list with entries in (0, 13) is a union of complementary pairs. -/
theorem all_pairs (c : List Nat) (hr : c.all (PairsSplit.inR 13) = true) (hb : Indecomp.bal 13 c = true) :
    PairsSplit.allPairs 13 (c.length + 1) c = true :=
  pairs_of_sym 13 (fun x => odd_ne x 6) c.length c (Nat.le_refl _) hr (sym c hr hb)

/-- Every balanced 6-list with entries in (0, 13) has a 2 + 4 split. -/
theorem split24 (c : List Nat) (h6 : c.length = 6) (hr : c.all (PairsSplit.inR 13) = true)
    (hb : Indecomp.bal 13 c = true) : Split24.has24 13 c = true :=
  split24_of_sym 12 (fun x => odd_ne x 6) c h6 hr (sym c hr hb)

end MailletSplitP13

#print axioms MailletSplitP13.units_ok
#print axioms MailletSplitP13.all_pairs
#print axioms MailletSplitP13.split24

#print axioms: 29 files, 3 theorems each, no axioms.

81.226 \(F_{33}\) is indecomposable: a linear certificate over all units

Integer weights on 31 units give \(L\,n_k+\alpha ^-_1n_1+\alpha ^-_2n_2=\alpha ^+_1n_1+\alpha ^+_2n_2\) for the counts of a balanced part. The kernel of the unit matrix is \(\mathrm {span}(1,v)\); the four cases leave only \(\emptyset \) and \(F_{33}\).

hodge/LinCert33.lean

/-
  hodge/LinCert33.lean — T41 cycle 1868 (goals G861, G769): F_33 (m = 462, the composite member of the 1 + 14k family)
  is indecomposable, by a linear certificate over all units instead of subgroup averages.
  A balanced part A satisfies 2·T_t(A) = |A|·m for every unit t. With integer weights λ_t = lp − ln on 31 units the
  combination Σ λ_t (2⟨t·x⟩ − m) equals L·[x = c_k] − α₁[x = s₁] − α₂[x = s₂] on every element x of c (checked by
  rfl as PT x + Em x = NT x + Ep x), so the counts n_x of A satisfy L·n_k + α₁⁻n₁ + α₂⁻n₂ = α₁⁺n₁ + α₂⁺n₂
  (row_eq). The kernel of the unit matrix is span(1, v) (rank 31 of 33): the counts of the two free elements s₁, s₂
  decide all others, the two mixed cases are impossible and the two pure ones give A = ∅ or B = ∅.
    lin          gs PT A = gs NT A for balanced A
    row_eq       the count relation of each certificate row
    lincert      indec 462 F33 = true
  The weights were found by exact Gaussian elimination (tools/g861_cert.py, computation only).
  Lean 4 core plus hodge/AvgIndec.
-/
import hodge.AvgIndec

namespace LinCert33
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp FamBal FamIndec3 Q4Conv QFamPrime AvgIndec

def F33 : List Nat := [1, 15, 29, 43, 57, 71, 85, 297, 113, 127, 141, 155, 169, 183, 197, 211, 225, 239, 253, 267, 281, 295, 309, 323, 337, 351, 365, 379, 393, 407, 421, 435, 449]

structure Row where
  ck : Nat
  L : Nat
  a1p : Nat
  a1n : Nat
  a2p : Nat
  a2n : Nat
  T : List (Nat × Nat × Nat)

def ind (s x : Nat) : Nat := if Nat.beq x s = true then 1 else 0

def cnt (s : Nat) (A : List Nat) : Nat := gs (ind s) A

def PT (m : Nat) : List (Nat × Nat × Nat) → Nat → Nat
  | [], _ => 0
  | (t, lp, ln) :: T, x => (lp * ((t * x) % m + (t * x) % m) + ln * m) + PT m T x

def NT (m : Nat) : List (Nat × Nat × Nat) → Nat → Nat
  | [], _ => 0
  | (t, lp, ln) :: T, x => (ln * ((t * x) % m + (t * x) % m) + lp * m) + NT m T x

def Em (s1 s2 : Nat) (r : Row) (x : Nat) : Nat := r.a1p * ind s1 x + r.a2p * ind s2 x

def Ep (s1 s2 : Nat) (r : Row) (x : Nat) : Nat := r.L * ind r.ck x + (r.a1n * ind s1 x + r.a2n * ind s2 x)

def rowOK (m s1 s2 : Nat) (c : List Nat) (r : Row) : Bool :=
  r.T.all (fun e => Nat.blt e.1 m && Nat.beq (Nat.gcd e.1 m) 1) &&
  c.all (fun x => Nat.beq (PT m r.T x + Em s1 s2 r x) (NT m r.T x + Ep s1 s2 r x))

def allows (r : Row) (n1 n2 nk : Nat) : Bool :=
  Nat.beq (r.a1p * n1 + r.a2p * n2) (r.L * nk + (r.a1n * n1 + r.a2n * n2))

theorem add_left_cancel' (n a b : Nat) (h : n + a = n + b) : a = b :=
  add_right_cancel' a b n (by rw [Nat.add_comm a n, Nat.add_comm b n]; exact h)

theorem and_tt {a b : Bool} (h : (a && b) = true) : a = true ∧ b = true := by
  cases a with
  | false => exact nomatch h
  | true => exact ⟨rfl, h⟩

theorem gs_lin (lp ln m : Nat) (g : Nat → Nat) : ∀ A : List Nat,
    gs (fun x => lp * (g x + g x) + ln * m) A = lp * (gs g A + gs g A) + ln * (m * A.length)
  | [] => rfl
  | x :: A => by
    show (lp * (g x + g x) + ln * m) + gs (fun x => lp * (g x + g x) + ln * m) A
      = lp * ((g x + gs g A) + (g x + gs g A)) + ln * (m * (A.length + 1))
    rw [gs_lin lp ln m g A]; lib_nat

theorem gs_mul (w : Nat) (g : Nat → Nat) : ∀ A : List Nat, gs (fun x => w * g x) A = w * gs g A
  | [] => rfl
  | x :: A => by
    show w * g x + gs (fun x => w * g x) A = w * (g x + gs g A)
    rw [gs_mul w g A]; lib_nat

theorem gs_congr (f g : Nat → Nat) : ∀ A : List Nat, (∀ x, x ∈ A → f x = g x) → gs f A = gs g A
  | [], _ => rfl
  | x :: A, h => by
    show f x + gs f A = g x + gs g A
    rw [h x (List.Mem.head _), gs_congr f g A (fun y hy => h y (List.Mem.tail _ hy))]

theorem lin (m : Nat) (A : List Nat) : ∀ T : List (Nat × Nat × Nat),
    (∀ e, e ∈ T → tsum m e.1 A + tsum m e.1 A = A.length * m) → gs (PT m T) A = gs (NT m T) A
  | [], _ => by
    show gs (fun _ => 0) A = gs (fun _ => 0) A; rfl
  | (t, lp, ln) :: T, h => by
    have e1 : gs (PT m ((t, lp, ln) :: T)) A
        = gs (fun x => lp * ((t * x) % m + (t * x) % m) + ln * m) A + gs (PT m T) A :=
      gs_addf (fun x => lp * ((t * x) % m + (t * x) % m) + ln * m) (PT m T) A
    have e2 : gs (NT m ((t, lp, ln) :: T)) A
        = gs (fun x => ln * ((t * x) % m + (t * x) % m) + lp * m) A + gs (NT m T) A :=
      gs_addf (fun x => ln * ((t * x) % m + (t * x) % m) + lp * m) (NT m T) A
    have h0 := h (t, lp, ln) (List.Mem.head _)
    have ih := lin m A T (fun e he => h e (List.Mem.tail _ he))
    rw [e1, e2, gs_lin lp ln m (fun x => (t * x) % m) A, gs_lin ln lp m (fun x => (t * x) % m) A, ih]
    rw [tsum_gs] at h0
    show lp * (gs (fun x => (t * x) % m) A + gs (fun x => (t * x) % m) A) + ln * (m * A.length) + gs (NT m T) A
      = ln * (gs (fun x => (t * x) % m) A + gs (fun x => (t * x) % m) A) + lp * (m * A.length) + gs (NT m T) A
    rw [h0]; lib_nat

theorem mem_of_cnt (x : Nat) : ∀ l : List Nat, 0 < cnt x l → x ∈ l
  | [], h => nomatch h
  | y :: l, h => by
    cases hb : Nat.beq y x with
    | true => rw [Nat.eq_of_beq_eq_true hb]; exact List.Mem.head _
    | false =>
      have e : cnt x (y :: l) = cnt x l := by
        show ind x y + cnt x l = cnt x l
        unfold ind; rw [hb]; show 0 + cnt x l = cnt x l; lib_nat
      rw [e] at h
      exact List.Mem.tail _ (mem_of_cnt x l h)

theorem cnt_pos (x : Nat) : ∀ l : List Nat, x ∈ l → 0 < cnt x l
  | [], h => nomatch h
  | y :: l, h => by
    show 0 < ind x y + cnt x l
    cases h with
    | head => unfold ind; rw [beq_refl' x]; exact Nat.lt_of_lt_of_le (Nat.lt_succ_self 0) (Nat.le_add_right 1 _)
    | tail _ h' => exact Nat.lt_of_lt_of_le (cnt_pos x l h') (Nat.le_add_left _ _)

theorem mem_split (c A B : List Nat) (hs : (A, B) ∈ splits c) (x : Nat) (hx : x ∈ A) : x ∈ c := by
  have e := FamIndec3.splits_gs (ind x) c A B hs
  exact mem_of_cnt x c (Nat.lt_of_lt_of_le (cnt_pos x A hx) (by rw [show cnt x c = gs (ind x) A + gs (ind x) B from e.symm]; exact Nat.le_add_right _ _))

theorem mem_split_r (c A B : List Nat) (hs : (A, B) ∈ splits c) (x : Nat) (hx : x ∈ B) : x ∈ c := by
  have e := FamIndec3.splits_gs (ind x) c A B hs
  exact mem_of_cnt x c (Nat.lt_of_lt_of_le (cnt_pos x B hx) (by rw [show cnt x c = gs (ind x) A + gs (ind x) B from e.symm]; exact Nat.le_add_left _ _))

theorem all_mem2 {α : Type} (P : α → Bool) (l : List α) (h : l.all P = true) (r : α) (hr : r ∈ l) : P r = true :=
  all_mem' P l h r hr

theorem row_eq (m s1 s2 : Nat) (c A B : List Nat) (hs : (A, B) ∈ splits c) (hb : bal m A = true) (r : Row)
    (hr : rowOK m s1 s2 c r = true) : allows r (cnt s1 A) (cnt s2 A) (cnt r.ck A) = true := by
  have h2 := and_tt hr
  have hT : ∀ e, e ∈ r.T → tsum m e.1 A + tsum m e.1 A = A.length * m := by
    intro e he
    have u := and_tt (all_mem2 _ r.T h2.1 e he)
    exact bal_unit m e.1 A hb (Nat.le_of_ble_eq_true u.1) (Nat.eq_of_beq_eq_true u.2)
  have hl := lin m A r.T hT
  have hc : ∀ x, x ∈ A → PT m r.T x + Em s1 s2 r x = NT m r.T x + Ep s1 s2 r x := fun x hx =>
    Nat.eq_of_beq_eq_true (all_mem2 _ c h2.2 x (mem_split c A B hs x hx))
  have g := gs_congr _ _ A hc
  rw [gs_addf, gs_addf, hl] at g
  have g2 := add_left_cancel' _ _ _ g
  have eEm : gs (Em s1 s2 r) A = r.a1p * cnt s1 A + r.a2p * cnt s2 A := by
    show gs (fun x => r.a1p * ind s1 x + r.a2p * ind s2 x) A = _
    rw [gs_addf, gs_mul, gs_mul]; rfl
  have eEp : gs (Ep s1 s2 r) A = r.L * cnt r.ck A + (r.a1n * cnt s1 A + r.a2n * cnt s2 A) := by
    show gs (fun x => r.L * ind r.ck x + (r.a1n * ind s1 x + r.a2n * ind s2 x)) A = _
    rw [gs_addf, gs_addf, gs_mul, gs_mul, gs_mul]; rfl
  rw [eEm, eEp] at g2
  unfold allows; rw [g2]; exact beq_refl' _

theorem zero_or_one : ∀ a b : Nat, a + b = 1 → a = 0 ∨ a = 1
  | 0, _, _ => Or.inl rfl
  | 1, _, _ => Or.inr rfl
  | a + 2, b, h => by
    have h' : a + b + 2 = 1 := by rw [← h]; lib_nat
    exact Nat.noConfusion (Nat.succ.inj h')

theorem cnt01 (c A B : List Nat) (hs : (A, B) ∈ splits c) (x : Nat) (h1 : cnt x c = 1) : cnt x A = 0 ∨ cnt x A = 1 :=
  zero_or_one _ (cnt x B) ((FamIndec3.splits_gs (ind x) c A B hs).trans h1)

theorem any_mem {α : Type} (P : α → Bool) : ∀ l : List α, l.any P = true → ∃ r, r ∈ l ∧ P r = true
  | [], h => nomatch h
  | x :: l, h => by
    cases e : P x with
    | true => exact ⟨x, List.Mem.head _, e⟩
    | false =>
      rw [show (x :: l).any P = (P x || l.any P) from rfl, e] at h
      cases any_mem P l h with
      | intro r hr => exact ⟨r, List.Mem.tail _ hr.1, hr.2⟩

theorem mem_app {α : Type} (x : α) : ∀ l l' : List α, x ∈ l ++ l' → x ∈ l ∨ x ∈ l'
  | [], _, h => Or.inr h
  | y :: l, l', h => by
    cases h with
    | head => exact Or.inl (List.Mem.head _)
    | tail _ h' =>
      cases mem_app x l l' h' with
      | inl a => exact Or.inl (List.Mem.tail _ a)
      | inr b => exact Or.inr b

theorem mem_map' {α β : Type} (f : α → β) (y : β) : ∀ l : List α, y ∈ l.map f → ∃ r, r ∈ l ∧ f r = y
  | [], h => nomatch h
  | x :: l, h => by
    cases h with
    | head => exact ⟨x, List.Mem.head _, rfl⟩
    | tail _ h' =>
      cases mem_map' f y l h' with
      | intro r hr => exact ⟨r, List.Mem.tail _ hr.1, hr.2⟩

def rows : List Row := [
  ⟨1, 57288, 0, 0, 57288, 0, [(1, 0, 9), (5, 0, 67), (13, 0, 23), (17, 0, 40), (19, 34, 0), (23, 0, 35), (25, 10, 0), (29, 0, 8), (31, 0, 1), (37, 15, 0), (41, 0, 54), (43, 6, 0), (47, 15, 0), (53, 0, 1), (59, 30, 0), (61, 0, 27), (65, 0, 3), (67, 40, 0), (71, 30, 0), (73, 0, 19), (79, 5, 0), (83, 32, 0), (85, 0, 48), (89, 0, 23), (95, 14, 0), (97, 0, 23), (101, 15, 0), (103, 0, 10), (107, 6, 0),   -- (+29 chars; full line in the Zenodo source)
  ⟨15, 57288, 57288, 0, 0, 0, [(1, 0, 4), (5, 15, 0), (13, 69, 0), (17, 58, 0), (19, 22, 0), (23, 0, 50), (25, 0, 30), (29, 0, 7), (31, 3, 0), (37, 0, 76), (41, 38, 0), (43, 0, 80), (47, 17, 0), (53, 0, 59), (59, 3, 0), (61, 50, 0), (65, 9, 0), (67, 4, 0), (71, 0, 90), (73, 26, 0), (79, 47, 0), (83, 0, 3), (85, 0, 42), (89, 100, 0), (95, 0, 73), (97, 7, 0), (101, 17, 0), (103, 61, 0), (107, 13, 0)  -- (+31 chars; full line in the Zenodo source)
  ⟨29, 57288, 0, 0, 57288, 0, [(1, 12, 0), (5, 0, 45), (13, 41, 0), (17, 0, 50), (19, 58, 0), (23, 0, 36), (25, 0, 3), (29, 0, 10), (31, 22, 0), (37, 11, 0), (41, 0, 83), (43, 0, 39), (47, 73, 0), (53, 0, 9), (59, 53, 0), (61, 0, 26), (65, 4, 0), (67, 50, 0), (71, 0, 9), (73, 15, 0), (79, 14, 0), (83, 40, 0), (85, 0, 60), (89, 41, 0), (95, 2, 0), (97, 0, 52), (101, 42, 0), (103, 3, 0), (107, 23, 0  -- (+32 chars; full line in the Zenodo source)
  ⟨43, 57288, 0, 0, 57288, 0, [(1, 0, 46), (5, 2, 0), (13, 34, 0), (17, 16, 0), (19, 0, 26), (23, 14, 0), (25, 0, 35), (29, 0, 3), (31, 19, 0), (37, 25, 0), (41, 3, 0), (43, 0, 21), (47, 0, 6), (53, 50, 0), (59, 0, 12), (61, 48, 0), (65, 0, 5), (67, 46, 0), (71, 19, 0), (73, 0, 11), (79, 0, 33), (83, 0, 19), (85, 0, 18), (89, 0, 59), (95, 0, 49), (97, 0, 59), (101, 25, 0), (103, 66, 0), (107, 10,   -- (+33 chars; full line in the Zenodo source)
  ⟨57, 57288, 57288, 0, 0, 0, [(1, 0, 49), (5, 52, 0), (13, 16, 0), (17, 44, 0), (19, 0, 56), (23, 23, 0), (25, 0, 42), (29, 15, 0), (31, 0, 2), (37, 0, 1), (41, 16, 0), (43, 12, 0), (47, 0, 32), (53, 0, 2), (59, 0, 33), (61, 39, 0), (65, 0, 6), (67, 18, 0), (71, 0, 2), (73, 0, 7), (79, 10, 0), (83, 0, 29), (85, 28, 0), (89, 0, 15), (95, 0, 3), (97, 16, 0), (101, 0, 32), (103, 11, 0), (107, 0, 19)  -- (+30 chars; full line in the Zenodo source)
  ⟨71, 57288, 0, 0, 57288, 0, [(1, 0, 13), (5, 0, 21), (13, 77, 0), (17, 18, 0), (19, 56, 0), (23, 0, 23), (25, 0, 51), (29, 0, 15), (31, 2, 0), (37, 0, 30), (41, 0, 47), (43, 0, 43), (47, 63, 0), (53, 0, 29), (59, 2, 0), (61, 23, 0), (65, 6, 0), (67, 44, 0), (71, 0, 29), (73, 38, 0), (79, 0, 10), (83, 29, 0), (85, 0, 90), (89, 46, 0), (95, 0, 59), (97, 0, 16), (101, 32, 0), (103, 82, 0), (107, 50  -- (+35 chars; full line in the Zenodo source)
  ⟨85, 57288, 0, 0, 57288, 0, [(1, 0, 57), (5, 0, 11), (13, 0, 63), (17, 0, 26), (19, 0, 12), (23, 47, 0), (25, 53, 0), (29, 1, 0), (31, 4, 0), (37, 64, 0), (41, 0, 1), (43, 69, 0), (47, 0, 29), (53, 35, 0), (59, 4, 0), (61, 15, 0), (65, 12, 0), (67, 26, 0), (71, 35, 0), (73, 0, 48), (79, 0, 20), (83, 0, 35), (85, 6, 0), (89, 0, 94), (95, 37, 0), (97, 0, 32), (101, 2, 0), (103, 0, 22), (107, 0, 24  -- (+32 chars; full line in the Zenodo source)
  ⟨297, 57288, 114576, 0, 0, 57288, [(1, 0, 5), (5, 42, 0), (13, 94, 0), (17, 88, 0), (19, 0, 50), (23, 0, 47), (25, 0, 53), (29, 0, 32), (31, 27, 0), (37, 0, 64), (41, 63, 0), (43, 0, 69), (47, 0, 2), (53, 0, 66), (59, 0, 35), (61, 47, 0), (65, 19, 0), (67, 0, 26), (71, 0, 97), (73, 48, 0), (79, 51, 0), (83, 4, 0), (85, 0, 6), (89, 94, 0), (95, 0, 68), (97, 1, 0), (101, 29, 0), (103, 53, 0), (107  -- (+38 chars; full line in the Zenodo source)
  ⟨113, 28644, 0, 0, 28644, 0, [(1, 1, 0), (5, 4, 0), (13, 37, 0), (17, 1, 0), (19, 10, 0), (23, 0, 3), (25, 0, 39), (29, 0, 6), (31, 7, 0), (37, 0, 12), (41, 0, 25), (43, 0, 42), (47, 19, 0), (53, 7, 0), (59, 7, 0), (61, 34, 0), (65, 21, 0), (67, 30, 0), (71, 0, 24), (73, 9, 0), (79, 0, 4), (83, 0, 7), (85, 0, 36), (89, 6, 0), (95, 0, 36), (97, 0, 25), (101, 19, 0), (103, 39, 0), (107, 20, 0), (1  -- (+25 chars; full line in the Zenodo source)
  ⟨127, 28644, 0, 0, 28644, 0, [(1, 0, 13), (5, 0, 21), (13, 0, 16), (17, 0, 13), (19, 0, 6), (23, 8, 0), (25, 11, 0), (29, 16, 0), (31, 2, 0), (37, 32, 0), (41, 0, 16), (43, 19, 0), (47, 1, 0), (53, 33, 0), (59, 2, 0), (61, 0, 8), (65, 6, 0), (67, 13, 0), (71, 33, 0), (73, 0, 24), (79, 0, 10), (83, 0, 2), (85, 3, 0), (89, 0, 47), (95, 3, 0), (97, 0, 16), (101, 1, 0), (103, 0, 11), (107, 0, 12), (  -- (+27 chars; full line in the Zenodo source)
  ⟨141, 57288, 57288, 0, 0, 0, [(1, 10, 0), (5, 9, 0), (13, 29, 0), (17, 10, 0), (19, 0, 24), (23, 0, 30), (25, 13, 0), (29, 2, 0), (31, 8, 0), (37, 0, 27), (41, 29, 0), (43, 0, 17), (47, 0, 27), (53, 0, 23), (59, 0, 23), (61, 30, 0), (65, 24, 0), (67, 0, 10), (71, 0, 23), (73, 0, 3), (79, 22, 0), (83, 0, 8), (85, 12, 0), (89, 29, 0), (95, 12, 0), (97, 0, 2), (101, 4, 0), (103, 0, 13), (107, 0, 17  -- (+32 chars; full line in the Zenodo source)
  ⟨155, 57288, 0, 0, 57288, 0, [(1, 45, 0), (5, 0, 68), (13, 22, 0), (17, 0, 48), (19, 78, 0), (23, 0, 73), (25, 0, 19), (29, 0, 22), (31, 5, 0), (37, 0, 44), (41, 0, 71), (43, 0, 61), (47, 80, 0), (53, 0, 26), (59, 67, 0), (61, 0, 51), (65, 15, 0), (67, 48, 0), (71, 5, 0), (73, 2, 0), (79, 37, 0), (83, 88, 0), (85, 0, 70), (89, 84, 0), (95, 0, 8), (97, 0, 9), (101, 49, 0), (103, 19, 0), (107, 63,  -- (+34 chars; full line in the Zenodo source)
  ⟨169, 57288, 0, 0, 57288, 0, [(1, 0, 46), (5, 33, 0), (13, 3, 0), (17, 16, 0), (19, 0, 26), (23, 14, 0), (25, 0, 35), (29, 28, 0), (31, 0, 12), (37, 25, 0), (41, 3, 0), (43, 0, 21), (47, 0, 37), (53, 19, 0), (59, 19, 0), (61, 48, 0), (65, 26, 0), (67, 46, 0), (71, 19, 0), (73, 0, 11), (79, 0, 2), (83, 0, 50), (85, 0, 18), (89, 0, 59), (95, 0, 18), (97, 0, 28), (101, 0, 6), (103, 35, 0), (107, 0,  -- (+35 chars; full line in the Zenodo source)
  ⟨183, 57288, 57288, 0, 0, 0, [(1, 1, 0), (5, 4, 0), (13, 68, 0), (17, 32, 0), (19, 10, 0), (23, 0, 65), (25, 0, 39), (29, 0, 6), (31, 7, 0), (37, 0, 12), (41, 0, 25), (43, 0, 73), (47, 50, 0), (53, 0, 24), (59, 7, 0), (61, 3, 0), (65, 21, 0), (67, 30, 0), (71, 0, 55), (73, 40, 0), (79, 27, 0), (83, 24, 0), (85, 0, 36), (89, 68, 0), (95, 0, 36), (97, 0, 25), (101, 19, 0), (103, 39, 0), (107, 0, 1  -- (+32 chars; full line in the Zenodo source)
  ⟨197, 57288, 0, 0, 57288, 0, [(1, 6, 0), (5, 0, 7), (13, 67, 0), (17, 6, 0), (19, 0, 2), (23, 0, 18), (25, 0, 48), (29, 0, 5), (31, 11, 0), (37, 0, 10), (41, 0, 26), (43, 0, 66), (47, 21, 0), (53, 11, 0), (59, 11, 0), (61, 18, 0), (65, 33, 0), (67, 56, 0), (71, 0, 20), (73, 0, 8), (79, 7, 0), (83, 0, 11), (85, 0, 30), (89, 36, 0), (95, 0, 61), (97, 0, 57), (101, 21, 0), (103, 79, 0), (107, 27, 0  -- (+32 chars; full line in the Zenodo source)
  ⟨211, 57288, 0, 0, 57288, 0, [(1, 0, 51), (5, 0, 18), (13, 4, 0), (17, 0, 20), (19, 0, 14), (23, 29, 0), (25, 0, 26), (29, 27, 0), (31, 0, 16), (37, 85, 0), (41, 0, 58), (43, 34, 0), (47, 0, 8), (53, 46, 0), (59, 15, 0), (61, 33, 0), (65, 14, 0), (67, 82, 0), (71, 46, 0), (73, 0, 25), (79, 0, 44), (83, 0, 15), (85, 0, 24), (89, 0, 89), (95, 7, 0), (97, 0, 58), (101, 0, 8), (103, 0, 5), (107, 3,   -- (+33 chars; full line in the Zenodo source)
  ⟨225, 57288, 57288, 0, 0, 0, [(1, 0, 8), (5, 0, 1), (13, 45, 0), (17, 54, 0), (19, 0, 18), (23, 0, 38), (25, 0, 29), (29, 0, 14), (31, 6, 0), (37, 0, 59), (41, 45, 0), (43, 0, 5), (47, 3, 0), (53, 0, 25), (59, 0, 25), (61, 38, 0), (65, 18, 0), (67, 8, 0), (71, 0, 25), (73, 21, 0), (79, 32, 0), (83, 0, 6), (85, 0, 22), (89, 45, 0), (95, 0, 22), (97, 14, 0), (101, 0, 28), (103, 29, 0), (107, 0, 5)  -- (+31 chars; full line in the Zenodo source)
  ⟨239, 57288, 0, 0, 57288, 0, [(1, 0, 9), (5, 0, 5), (13, 0, 23), (17, 0, 40), (19, 34, 0), (23, 27, 0), (25, 10, 0), (29, 0, 8), (31, 0, 1), (37, 15, 0), (41, 0, 54), (43, 6, 0), (47, 15, 0), (53, 0, 1), (59, 30, 0), (61, 0, 27), (65, 0, 3), (67, 40, 0), (71, 30, 0), (73, 0, 19), (79, 5, 0), (83, 32, 0), (85, 14, 0), (89, 0, 23), (95, 14, 0), (97, 0, 23), (101, 15, 0), (103, 0, 10), (107, 6, 0),  -- (+30 chars; full line in the Zenodo source)
  ⟨253, 57288, 0, 57288, 114576, 0, [(1, 0, 8), (5, 0, 63), (13, 0, 79), (17, 0, 70), (19, 44, 0), (23, 24, 0), (25, 33, 0), (29, 48, 0), (31, 6, 0), (37, 65, 0), (41, 0, 79), (43, 57, 0), (47, 3, 0), (53, 37, 0), (59, 37, 0), (61, 0, 24), (65, 18, 0), (67, 70, 0), (71, 99, 0), (73, 0, 41), (79, 0, 30), (83, 0, 6), (85, 0, 22), (89, 0, 79), (95, 40, 0), (97, 0, 48), (101, 0, 28), (103, 0, 33), (10  -- (+39 chars; full line in the Zenodo source)
  ⟨267, 57288, 57288, 0, 0, 0, [(1, 13, 0), (5, 21, 0), (13, 47, 0), (17, 44, 0), (19, 6, 0), (23, 0, 39), (25, 0, 42), (29, 0, 16), (31, 29, 0), (37, 0, 63), (41, 16, 0), (43, 0, 50), (47, 0, 1), (53, 0, 33), (59, 0, 2), (61, 39, 0), (65, 25, 0), (67, 18, 0), (71, 0, 64), (73, 0, 7), (79, 41, 0), (83, 2, 0), (85, 0, 34), (89, 47, 0), (95, 0, 34), (97, 0, 15), (101, 0, 1), (103, 42, 0), (107, 12,   -- (+33 chars; full line in the Zenodo source)
  ⟨281, 57288, 0, 0, 57288, 0, [(1, 30, 0), (5, 0, 35), (13, 25, 0), (17, 0, 32), (19, 52, 0), (23, 0, 28), (25, 0, 23), (29, 6, 0), (31, 24, 0), (37, 0, 19), (41, 0, 37), (43, 0, 51), (47, 43, 0), (53, 0, 7), (59, 55, 0), (61, 0, 34), (65, 10, 0), (67, 32, 0), (71, 0, 7), (73, 0, 9), (79, 4, 0), (83, 38, 0), (85, 0, 26), (89, 25, 0), (95, 0, 26), (97, 0, 6), (101, 12, 0), (103, 23, 0), (107, 11,   -- (+33 chars; full line in the Zenodo source)
  ⟨295, 57288, 0, 0, 57288, 0, [(1, 0, 35), (5, 0, 16), (13, 0, 86), (17, 0, 4), (19, 0, 40), (23, 43, 0), (25, 63, 0), (29, 24, 0), (31, 3, 0), (37, 48, 0), (41, 7, 0), (43, 75, 0), (47, 0, 76), (53, 34, 0), (59, 3, 0), (61, 19, 0), (65, 9, 0), (67, 4, 0), (71, 65, 0), (73, 0, 36), (79, 0, 15), (83, 0, 34), (85, 20, 0), (89, 0, 86), (95, 82, 0), (97, 7, 0), (101, 0, 45), (103, 0, 63), (107, 0, 49  -- (+32 chars; full line in the Zenodo source)
  ⟨309, 57288, 57288, 0, 0, 0, [(1, 43, 0), (5, 0, 45), (13, 103, 0), (17, 12, 0), (19, 58, 0), (23, 0, 129), (25, 0, 65), (29, 0, 41), (31, 22, 0), (37, 0, 82), (41, 0, 21), (43, 0, 101), (47, 73, 0), (53, 0, 71), (59, 22, 0), (61, 5, 0), (65, 4, 0), (67, 50, 0), (71, 0, 71), (73, 46, 0), (79, 76, 0), (83, 71, 0), (85, 0, 60), (89, 134, 0), (95, 0, 91), (97, 10, 0), (101, 42, 0), (103, 96, 0), (1  -- (+40 chars; full line in the Zenodo source)
  ⟨323, 57288, 0, 0, 57288, 0, [(1, 10, 0), (5, 9, 0), (13, 29, 0), (17, 10, 0), (19, 38, 0), (23, 0, 30), (25, 0, 49), (29, 2, 0), (31, 8, 0), (37, 0, 27), (41, 0, 33), (43, 0, 79), (47, 35, 0), (53, 0, 23), (59, 39, 0), (61, 30, 0), (65, 24, 0), (67, 52, 0), (71, 0, 23), (73, 0, 3), (79, 22, 0), (83, 0, 8), (85, 0, 50), (89, 29, 0), (95, 0, 50), (97, 0, 2), (101, 4, 0), (103, 49, 0), (107, 45, 0  -- (+32 chars; full line in the Zenodo source)
  ⟨337, 28644, 0, 0, 28644, 0, [(1, 6, 0), (5, 0, 38), (13, 5, 0), (17, 0, 25), (19, 29, 0), (23, 0, 18), (25, 14, 0), (29, 0, 5), (31, 11, 0), (37, 21, 0), (41, 0, 26), (43, 0, 4), (47, 21, 0), (53, 11, 0), (59, 11, 0), (61, 0, 13), (65, 2, 0), (67, 25, 0), (71, 11, 0), (73, 0, 8), (79, 7, 0), (83, 20, 0), (85, 0, 30), (89, 5, 0), (95, 1, 0), (97, 0, 26), (101, 21, 0), (103, 0, 14), (107, 0, 4),   -- (+29 chars; full line in the Zenodo source)
  ⟨351, 57288, 57288, 0, 0, 0, [(1, 0, 10), (5, 22, 0), (13, 64, 0), (17, 52, 0), (19, 0, 38), (23, 0, 32), (25, 0, 13), (29, 0, 33), (31, 23, 0), (37, 0, 35), (41, 33, 0), (43, 0, 45), (47, 0, 4), (53, 0, 8), (59, 0, 8), (61, 32, 0), (65, 7, 0), (67, 10, 0), (71, 0, 39), (73, 3, 0), (79, 9, 0), (83, 0, 23), (85, 0, 12), (89, 33, 0), (95, 0, 43), (97, 0, 29), (101, 27, 0), (103, 44, 0), (107, 0, 1  -- (+32 chars; full line in the Zenodo source)
  ⟨365, 57288, 0, 0, 57288, 0, [(1, 9, 0), (5, 5, 0), (13, 85, 0), (17, 0, 22), (19, 28, 0), (23, 0, 27), (25, 0, 72), (29, 8, 0), (31, 1, 0), (37, 0, 15), (41, 0, 70), (43, 0, 68), (47, 47, 0), (53, 1, 0), (59, 32, 0), (61, 27, 0), (65, 3, 0), (67, 84, 0), (71, 0, 30), (73, 19, 0), (79, 0, 5), (83, 30, 0), (85, 0, 76), (89, 23, 0), (95, 0, 76), (97, 0, 39), (101, 47, 0), (103, 72, 0), (107, 56, 0  -- (+32 chars; full line in the Zenodo source)
  ⟨379, 28644, 0, 0, 28644, 0, [(1, 0, 28), (5, 0, 19), (13, 0, 13), (17, 3, 0), (19, 0, 1), (23, 22, 0), (25, 7, 0), (29, 13, 0), (31, 0, 10), (37, 26, 0), (41, 0, 13), (43, 29, 0), (47, 0, 5), (53, 21, 0), (59, 0, 10), (61, 9, 0), (65, 1, 0), (67, 28, 0), (71, 21, 0), (73, 0, 4), (79, 0, 12), (83, 0, 21), (85, 0, 15), (89, 0, 44), (95, 16, 0), (97, 0, 13), (101, 0, 5), (103, 0, 7), (107, 0, 2),   -- (+28 chars; full line in the Zenodo source)
  ⟨393, 57288, 57288, 0, 0, 0, [(1, 0, 22), (5, 36, 0), (13, 54, 0), (17, 40, 0), (19, 0, 34), (23, 4, 0), (25, 0, 41), (29, 0, 23), (31, 1, 0), (37, 0, 15), (41, 23, 0), (43, 0, 37), (47, 16, 0), (53, 0, 30), (59, 0, 30), (61, 58, 0), (65, 3, 0), (67, 22, 0), (71, 0, 61), (73, 19, 0), (79, 0, 5), (83, 0, 1), (85, 0, 14), (89, 23, 0), (95, 0, 45), (97, 0, 39), (101, 47, 0), (103, 72, 0), (107, 0,   -- (+32 chars; full line in the Zenodo source)
  ⟨407, 57288, 0, 57288, 114576, 0, [(1, 27, 0), (5, 0, 78), (13, 0, 24), (17, 0, 66), (19, 84, 0), (23, 0, 19), (25, 1, 0), (29, 24, 0), (31, 3, 0), (37, 48, 0), (41, 0, 117), (43, 13, 0), (47, 48, 0), (53, 34, 0), (59, 65, 0), (61, 0, 43), (65, 9, 0), (67, 66, 0), (71, 65, 0), (73, 0, 36), (79, 0, 15), (83, 28, 0), (85, 0, 42), (89, 0, 24), (95, 20, 0), (97, 0, 55), (101, 17, 0), (103, 0, 1), (1  -- (+41 chars; full line in the Zenodo source)
  ⟨421, 57288, 0, 0, 57288, 0, [(1, 6, 0), (5, 0, 7), (13, 67, 0), (17, 6, 0), (19, 0, 2), (23, 0, 18), (25, 0, 48), (29, 0, 5), (31, 11, 0), (37, 0, 10), (41, 0, 26), (43, 0, 66), (47, 21, 0), (53, 11, 0), (59, 11, 0), (61, 80, 0), (65, 33, 0), (67, 56, 0), (71, 0, 20), (73, 0, 8), (79, 7, 0), (83, 0, 11), (85, 0, 92), (89, 0, 26), (95, 0, 61), (97, 0, 57), (101, 21, 0), (103, 79, 0), (107, 27, 0  -- (+32 chars; full line in the Zenodo source)

def S1 : Nat := 435
def S2 : Nat := 449

theorem rows_ok : rows.all (rowOK 462 S1 S2 F33) = true := rfl
theorem c_split : F33 = rows.map (fun r => r.ck) ++ [S1, S2] := rfl
theorem c_once : F33.all (fun x => Nat.beq (cnt x F33) 1) = true := rfl
theorem mixed10 : rows.any (fun r => !allows r 1 0 0 && !allows r 1 0 1) = true := rfl
theorem mixed01 : rows.any (fun r => !allows r 0 1 0 && !allows r 0 1 1) = true := rfl
theorem pure00 : rows.all (fun r => !allows r 0 0 1) = true := rfl
theorem pure11 : rows.all (fun r => !allows r 1 1 0) = true := rfl

theorem not_tt {b : Bool} (h : (!b) = true) (h' : b = true) : False := by
  rw [h'] at h; exact nomatch h

theorem mem_app_r {α : Type} (x : α) (l' : List α) (h : x ∈ l') : ∀ l : List α, x ∈ l ++ l'
  | [] => h
  | _ :: l => List.Mem.tail _ (mem_app_r x l' h l)

theorem mem_app_l {α : Type} (x : α) (l' : List α) : ∀ l : List α, x ∈ l → x ∈ l ++ l'
  | [], h => nomatch h
  | _ :: l, h => by
    cases h with
    | head => exact List.Mem.head _
    | tail _ h' => exact List.Mem.tail _ (mem_app_l x l' l h')

theorem map_mem {α β : Type} (f : α → β) (r : α) : ∀ l : List α, r ∈ l → f r ∈ l.map f
  | [], h => nomatch h
  | _ :: l, h => by
    cases h with
    | head => exact List.Mem.head _
    | tail _ h' => exact List.Mem.tail _ (map_mem f r l h')

theorem ne_nil {α : Type} : ∀ l : List α, l.isEmpty = false → ∃ x, x ∈ l
  | [], h => nomatch h
  | x :: _, _ => ⟨x, List.Mem.head _⟩

theorem memS1 : S1 ∈ F33 := by rw [c_split]; exact mem_app_r S1 [S1, S2] (List.Mem.head _) _
theorem memS2 : S2 ∈ F33 := by rw [c_split]; exact mem_app_r S2 [S1, S2] (List.Mem.tail _ (List.Mem.head _)) _
theorem mem_ck (r : Row) (hr : r ∈ rows) : r.ck ∈ F33 := by
  rw [c_split]; exact mem_app_l r.ck [S1, S2] _ (map_mem (fun r => r.ck) r rows hr)

theorem key (x : Nat) (hx : x ∈ F33) : (∃ r, r ∈ rows ∧ r.ck = x) ∨ x = S1 ∨ x = S2 := by
  rw [c_split] at hx
  cases mem_app x _ _ hx with
  | inl h => exact Or.inl (mem_map' _ x rows h)
  | inr h =>
    cases h with
    | head => exact Or.inr (Or.inl rfl)
    | tail _ h' =>
      cases h' with
      | head => exact Or.inr (Or.inr rfl)
      | tail _ h'' => exact nomatch h''

theorem no_split (A B : List Nat) (hs : (A, B) ∈ splits F33) (hA : bal 462 A = true)
    (hAne : A.isEmpty = false) (hBne : B.isEmpty = false) : False := by
  have R : ∀ r, r ∈ rows → allows r (cnt S1 A) (cnt S2 A) (cnt r.ck A) = true := fun r hr =>
    row_eq 462 S1 S2 F33 A B hs hA r (all_mem2 _ rows rows_ok r hr)
  have once : ∀ x, x ∈ F33 → cnt x F33 = 1 := fun x hx => Nat.eq_of_beq_eq_true (all_mem2 _ F33 c_once x hx)
  have c01 : ∀ x, x ∈ F33 → cnt x A = 0 ∨ cnt x A = 1 := fun x hx => cnt01 F33 A B hs x (once x hx)
  cases c01 S1 memS1 with
  | inl a1 =>
    cases c01 S2 memS2 with
    | inl a2 =>
      cases ne_nil A hAne with
      | intro x hxA =>
        have hxF := mem_split F33 A B hs x hxA
        have pos := cnt_pos x A hxA
        cases key x hxF with
        | inl hr =>
          cases hr with
          | intro r hr =>
            have q := R r hr.1
            rw [a1, a2, hr.2] at q
            have p00 := all_mem2 _ rows pure00 r hr.1
            cases c01 x hxF with
            | inl z => rw [z] at pos; exact Nat.lt_irrefl 0 pos
            | inr o => rw [o] at q; exact not_tt p00 q
        | inr h =>
          cases h with
          | inl e => rw [e, a1] at pos; exact Nat.lt_irrefl 0 pos
          | inr e => rw [e, a2] at pos; exact Nat.lt_irrefl 0 pos
    | inr b2 =>
      cases any_mem _ rows mixed01 with
      | intro r hr =>
        have q := R r hr.1
        rw [a1, b2] at q
        have hb := and_tt hr.2
        cases c01 r.ck (mem_ck r hr.1) with
        | inl z => rw [z] at q; exact not_tt hb.1 q
        | inr o => rw [o] at q; exact not_tt hb.2 q
  | inr b1 =>
    cases c01 S2 memS2 with
    | inl a2 =>
      cases any_mem _ rows mixed10 with
      | intro r hr =>
        have q := R r hr.1
        rw [b1, a2] at q
        have hb := and_tt hr.2
        cases c01 r.ck (mem_ck r hr.1) with
        | inl z => rw [z] at q; exact not_tt hb.1 q
        | inr o => rw [o] at q; exact not_tt hb.2 q
    | inr b2 =>
      cases ne_nil B hBne with
      | intro y hyB =>
        have hyF := mem_split_r F33 A B hs y hyB
        have posB := cnt_pos y B hyB
        have sum : cnt y A + cnt y B = 1 := (FamIndec3.splits_gs (ind y) F33 A B hs).trans (once y hyF)
        have hyA1 : cnt y A = 1 := by
          cases key y hyF with
          | inl hr =>
            cases hr with
            | intro r hr =>
              have q := R r hr.1
              rw [b1, b2, hr.2] at q
              cases c01 y hyF with
              | inl z => rw [z] at q; exact (not_tt (all_mem2 _ rows pure11 r hr.1) q).elim
              | inr o => exact o
          | inr h =>
            cases h with
            | inl e => rw [e]; exact b1
            | inr e => rw [e]; exact b2
        rw [hyA1] at sum
        have z : cnt y B = 0 := add_left_cancel' 1 _ 0 (sum.trans rfl : 1 + cnt y B = 1 + 0)
        rw [z] at posB
        exact Nat.lt_irrefl 0 posB

theorem lincert : indec 462 F33 = true := by
  cases hind : indec 462 F33 with
  | true => rfl
  | false =>
    exfalso
    cases all_false _ (splits F33) hind with
    | intro sp hsp =>
      have hf : (sp.1.isEmpty || sp.2.isEmpty || !(bal 462 sp.1 && bal 462 sp.2)) = false := hsp.2
      cases h1 : sp.1.isEmpty with
      | true => rw [h1] at hf; exact nomatch hf
      | false => cases h2 : sp.2.isEmpty with
        | true => rw [h1, h2] at hf; exact nomatch hf
        | false => cases hA : bal 462 sp.1 with
          | false => rw [h1, h2, hA] at hf; exact nomatch hf
          | true => exact no_split sp.1 sp.2 hsp.1 hA h1 h2

end LinCert33

#print axioms LinCert33.gs_lin
#print axioms LinCert33.lin
#print axioms LinCert33.row_eq
#print axioms LinCert33.rows_ok
#print axioms LinCert33.no_split
#print axioms LinCert33.lincert

#print axioms: 6 theorems, no axioms.

81.227 \(F_{45}\) and \(F_{75}\) split

Balanced parts \(\{15,495,435\}\) (\(m=630\)) and \(\{15,675,435,645,855\}\) (\(m=1050\)) with balanced complements. So \(\mathrm {indec}=\mathrm {false}\) for both; with \(F_{33}\) and \(F_{87}\) every composite \(p\le 87\) of the family is decided.

hodge/FamComposite4575.lean

/-
  hodge/FamComposite4575.lean — T41 cycle 1870 (goal G769): the composite family members F_45 (m = 630) and F_75
  (m = 1050) of the 1 + 14k family are decomposable: each has a balanced part of size 3 resp. 5 whose complement is
  balanced too, so indec = false. (F_33 is indecomposable: hodge/LinCert33.) The parts were read off the kernel of
  the unit matrix (tools/g861_cert.py, computation only); here they are checked by rfl.
    sel_splits   (selT bs c, selF bs c) ∈ splits c for every Bool list bs of the same length
    split45      bal 630 (selT b45 F45) = true ∧ bal 630 (selF b45 F45) = true, both parts nonempty
    not_indec45  indec 630 F45 = false;   the same for 75.
  Lean 4 core plus hodge/FamBal, hodge/Indecomp.
-/
import hodge.FamBal

namespace FamComposite4575
open Indecomp FamBal

def selT : List Bool → List Nat → List Nat
  | [], _ => []
  | _ :: _, [] => []
  | b :: bs, x :: xs => if b = true then x :: selT bs xs else selT bs xs

def selF : List Bool → List Nat → List Nat
  | [], _ => []
  | _ :: _, [] => []
  | b :: bs, x :: xs => if b = true then selF bs xs else x :: selF bs xs

theorem mem_app_l {α : Type} (x : α) (l' : List α) : ∀ l : List α, x ∈ l → x ∈ l ++ l'
  | [], h => nomatch h
  | _ :: l, h => by
    cases h with
    | head => exact List.Mem.head _
    | tail _ h' => exact List.Mem.tail _ (mem_app_l x l' l h')

theorem mem_app_r {α : Type} (x : α) (l' : List α) (h : x ∈ l') : ∀ l : List α, x ∈ l ++ l'
  | [] => h
  | _ :: l => List.Mem.tail _ (mem_app_r x l' h l)

theorem mem_fm {α β : Type} (f : α → List β) (q : β) (p : α) (hq : q ∈ f p) : ∀ L : List α, p ∈ L → q ∈ L.flatMap f
  | [], h => nomatch h
  | a :: L, h => by
    show q ∈ f a ++ L.flatMap f
    cases h with
    | head => exact mem_app_l q _ _ hq
    | tail _ h' => exact mem_app_r q _ (mem_fm f q p hq L h') _

theorem sel_splits : ∀ (c : List Nat) (bs : List Bool), bs.length = c.length → (selT bs c, selF bs c) ∈ splits c
  | [], [], _ => List.Mem.head _
  | [], _ :: _, h => nomatch h
  | _ :: _, [], h => nomatch h
  | x :: l, b :: bs, h => by
    have ih := sel_splits l bs (Nat.succ.inj h)
    cases b with
    | true =>
      show (x :: selT bs l, selF bs l) ∈ (splits l).flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])
      exact mem_fm _ _ (selT bs l, selF bs l) (List.Mem.head _) _ ih
    | false =>
      show (selT bs l, x :: selF bs l) ∈ (splits l).flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])
      exact mem_fm _ _ (selT bs l, selF bs l) (List.Mem.tail _ (List.Mem.head _)) _ ih

theorem all_memP {α : Type} (P : α → Bool) : ∀ l : List α, l.all P = true → ∀ r, r ∈ l → P r = true
  | [], _, _, h => nomatch h
  | x :: l, hl, r, hr => by
    have hx : P x = true ∧ l.all P = true := by
      cases e1 : P x with
      | false => rw [show (x :: l).all P = (P x && l.all P) from rfl, e1] at hl; exact nomatch hl
      | true => rw [show (x :: l).all P = (P x && l.all P) from rfl, e1] at hl; exact ⟨rfl, hl⟩
    cases hr with
    | head => exact hx.1
    | tail _ h' => exact all_memP P l hx.2 r h'

theorem not_indec (m : Nat) (c : List Nat) (bs : List Bool) (hl : bs.length = c.length)
    (h : ((selT bs c).isEmpty || (selF bs c).isEmpty || !(bal m (selT bs c) && bal m (selF bs c))) = false) :
    indec m c = false := by
  cases e : indec m c with
  | false => rfl
  | true =>
    have hm := all_memP _ (splits c) e _ (sel_splits c bs hl)
    rw [h] at hm
    exact nomatch hm

def inL (S : List Nat) (x : Nat) : Bool := S.any (fun y => Nat.beq x y)

def F45 : List Nat := fam 45 16
def b45 : List Bool := F45.map (inL [15, 495, 435])
def F75 : List Nat := fam 75 16
def b75 : List Bool := F75.map (inL [15, 675, 435, 645, 855])

set_option maxRecDepth 100000 in
theorem split45 : ((selT b45 F45).isEmpty || (selF b45 F45).isEmpty || !(bal 630 (selT b45 F45) && bal 630 (selF b45 F45))) = false := rfl
set_option maxRecDepth 100000 in
theorem split75 : ((selT b75 F75).isEmpty || (selF b75 F75).isEmpty || !(bal 1050 (selT b75 F75) && bal 1050 (selF b75 F75))) = false := rfl
theorem size45 : (selT b45 F45).length = 3 := rfl
theorem size75 : (selT b75 F75).length = 5 := rfl

theorem not_indec45 : indec 630 F45 = false := not_indec 630 F45 b45 rfl split45
theorem not_indec75 : indec 1050 F75 = false := not_indec 1050 F75 b75 rfl split75

end FamComposite4575

#print axioms FamComposite4575.all_memP
#print axioms FamComposite4575.sel_splits
#print axioms FamComposite4575.split45
#print axioms FamComposite4575.split75
#print axioms FamComposite4575.not_indec45
#print axioms FamComposite4575.not_indec75

#print axioms: 6 theorems, no axioms.

81.228 \(G_5=2F_5\cup \{70\}\) is not reached at \(m=140\)

\([2,58,70,86,90,114]\) is Hodge, not standard, and the inductive closure returns false. It splits into balanced parts \(\{70\}\sqcup 2F_5\) that do not complete to reached characters.

hodge/OpenCertG5.lean

/-
  hodge/OpenCertG5.lean — T41 cycle 1874 (goal G771): the doubled family character G_5 = 2·F_5 ∪ {m/2} =
  [2, 58, 70, 86, 90, 114] at m = 140 (length 6, n = 4) is Hodge, not standard, and not reached by the inductive
  closure (Shioda standard + splitting with completion, fuel 6 as in OpenCerts), by rfl. It is the reducible
  unreached orbit of Unreached140: it splits as {70} ⊔ 2·F_5 into balanced parts, but neither part completes to a
  reached Hodge character. (G_3 = [42, 2, 58, 66] at m = 84 has length 4, the base case of the closure.)
  Lean 4 core plus hodge/OpenCerts.
-/
import hodge.OpenCerts

namespace OpenCertG5
open FermatGens Fermat25Std Fermat32Open OpenCerts

def U140 : List Nat := (List.range 140).filter (fun t => Nat.beq (Nat.gcd t 140) 1)
def g5 : List Nat := [2, 58, 70, 86, 90, 114]

theorem u140_len : U140.length = 48 := rfl
theorem g5_hodge : hodgeB 140 U140 g5 = true := rfl
set_option maxRecDepth 100000 in
theorem g5_not_std : isStd 140 g5 = false := rfl
set_option maxHeartbeats 0 in
set_option maxRecDepth 2000000 in
theorem g5_not_reached : reach 140 U140 6 g5 = false := rfl

end OpenCertG5

#print axioms OpenCertG5.u140_len
#print axioms OpenCertG5.g5_hodge
#print axioms OpenCertG5.g5_not_std
#print axioms OpenCertG5.g5_not_reached

#print axioms: 4 theorems, no axioms.

81.229 Two seed families at \(m=36k\)

\(G(m)=\{1,m/6-1,2m/3+1,2m/3+2,m-3\}\) and \(H(m)=\{1,m/3+1,2m/3+1,m/2+3,m-6\}\) are balanced and indecomposable. Checked for \(k=1,\dots ,6\).

hodge/SeedFamGH.lean

/-
  hodge/SeedFamGH.lean — T41 cycle 1882 (goal G864, instances): two families of balanced indecomposable length-5 seeds
  at m = 36k found by the geometric-triple scan (HODGE_LOG cycle 1882):
    G(m) = {1, m/6 − 1, 2m/3 + 1, 2m/3 + 2, m − 3},   H(m) = {1, m/3 + 1, 2m/3 + 1, m/2 + 3, m − 6}
  (1, r, r² with r = m/6 − 1 resp. m/3 + 1). Here bal and indec are checked by rfl for k = 1, …, 6 (m ≤ 216);
  the general proof for every k is G864.
  Lean 4 core plus hodge/Indecomp.
-/
import hodge.Indecomp

namespace SeedFamGH
open Indecomp

def G (k : Nat) : List Nat := [1, 6 * k - 1, 24 * k + 1, 24 * k + 2, 36 * k - 3]
def H (k : Nat) : List Nat := [1, 12 * k + 1, 24 * k + 1, 18 * k + 3, 36 * k - 6]
def ks : List Nat := [1, 2, 3, 4, 5, 6]

set_option maxRecDepth 100000 in
theorem g_bal : ks.all (fun k => bal (36 * k) (G k)) = true := rfl
set_option maxRecDepth 100000 in
theorem h_bal : ks.all (fun k => bal (36 * k) (H k)) = true := rfl
set_option maxRecDepth 200000 in
theorem g_indec : ks.all (fun k => indec (36 * k) (G k)) = true := rfl
set_option maxRecDepth 200000 in
theorem h_indec : ks.all (fun k => indec (36 * k) (H k)) = true := rfl
theorem g36 : G 1 = [1, 5, 25, 26, 33] := rfl
theorem h36 : H 1 = [1, 13, 25, 21, 30] := rfl

end SeedFamGH

#print axioms SeedFamGH.g_bal
#print axioms SeedFamGH.h_bal
#print axioms SeedFamGH.g_indec
#print axioms SeedFamGH.h_indec
#print axioms SeedFamGH.g36
#print axioms SeedFamGH.h36

#print axioms: 6 theorems, no axioms.

81.230 The seed families \(G\), \(H\) are indecomposable for every \(k\)

\(G(36k)\) and \(H(36k)\) have no balanced splitting for any \(k\ge 1\). Every splitting fails the Hodge condition at \(t=1\) (linear in \(k\)).

hodge/SeedFamGHIndec.lean

/-
  hodge/SeedFamGHIndec.lean — T41 cycle 1914 (goal G864, indecomposability): the seed families
    G(36K) = {1, 6K − 1, 24K + 1, 24K + 2, 36K − 3},   H(36K) = {1, 12K + 1, 24K + 1, 18K + 3, 36K − 6}
  have no balanced splitting for any K ≥ 1. With K = r + 1 every entry is α + β·r with α < 36, β ≤ 36, and every
  splitting already fails the Hodge condition at t = 1 (APPairIrrGen.indec_lin: a linear identity in r with
  incompatible coefficients, checked by rfl on (α, β)).

  Lean 4 core plus hodge/APPairIrrGen, hodge/SeedFamGH, lib/Semi (lib_nat); no axioms.
-/
import hodge.APPairIrrGen
import hodge.SeedFamGH

namespace SeedFamGHIndec
open Indecomp APPairIrrGen SeedFamGH

def coG : List (Nat × Nat) := [(1, 0), (5, 6), (25, 24), (26, 24), (33, 36)]
def coH : List (Nat × Nat) := [(1, 0), (13, 12), (25, 24), (21, 18), (30, 36)]

theorem coG_small : coG.all (small 36 36) = true := rfl
theorem coH_small : coH.all (small 36 36) = true := rfl
theorem coG_splits : (splitsG coG).all (chkSplit 36 36) = true := rfl
theorem coH_splits : (splitsG coH).all (chkSplit 36 36) = true := rfl

theorem sub_eq (a b c : Nat) (h : a = c + b) : a - b = c := by
  rw [h]; exact ModHand.add_sub' c b

theorem gR (r : Nat) : G (r + 1) = coG.map (ev r) := by
  unfold G
  show [1, 6 * (r + 1) - 1, 24 * (r + 1) + 1, 24 * (r + 1) + 2, 36 * (r + 1) - 3]
    = [1 + 0 * r, 5 + 6 * r, 25 + 24 * r, 26 + 24 * r, 33 + 36 * r]
  rw [sub_eq (6 * (r + 1)) 1 (5 + 6 * r) (by lib_nat), sub_eq (36 * (r + 1)) 3 (33 + 36 * r) (by lib_nat),
    show 1 + 0 * r = 1 by lib_nat, show 24 * (r + 1) + 1 = 25 + 24 * r by lib_nat,
    show 24 * (r + 1) + 2 = 26 + 24 * r by lib_nat]

theorem hR (r : Nat) : H (r + 1) = coH.map (ev r) := by
  unfold H
  show [1, 12 * (r + 1) + 1, 24 * (r + 1) + 1, 18 * (r + 1) + 3, 36 * (r + 1) - 6]
    = [1 + 0 * r, 13 + 12 * r, 25 + 24 * r, 21 + 18 * r, 30 + 36 * r]
  rw [sub_eq (36 * (r + 1)) 6 (30 + 36 * r) (by lib_nat),
    show 1 + 0 * r = 1 by lib_nat, show 12 * (r + 1) + 1 = 13 + 12 * r by lib_nat,
    show 24 * (r + 1) + 1 = 25 + 24 * r by lib_nat, show 18 * (r + 1) + 3 = 21 + 18 * r by lib_nat]

/-- **G(36K) is indecomposable for every K ≥ 1.** -/
theorem g_indec : ∀ K : Nat, 0 < K → indec (36 * K) (G K) = true
  | 0, hK => absurd hK (Nat.lt_irrefl 0)
  | r + 1, _ => by
    rw [gR r, show 36 * (r + 1) = 34 + 36 * r + 2 by lib_nat]
    exact indec_lin (34 + 36 * r) 36 36 r (by lib_nat) coG coG_small coG_splits

/-- **H(36K) is indecomposable for every K ≥ 1.** -/
theorem h_indec : ∀ K : Nat, 0 < K → indec (36 * K) (H K) = true
  | 0, hK => absurd hK (Nat.lt_irrefl 0)
  | r + 1, _ => by
    rw [hR r, show 36 * (r + 1) = 34 + 36 * r + 2 by lib_nat]
    exact indec_lin (34 + 36 * r) 36 36 r (by lib_nat) coH coH_small coH_splits

end SeedFamGHIndec

#print axioms SeedFamGHIndec.coG_small
#print axioms SeedFamGHIndec.coH_small
#print axioms SeedFamGHIndec.coG_splits
#print axioms SeedFamGHIndec.coH_splits
#print axioms SeedFamGHIndec.sub_eq
#print axioms SeedFamGHIndec.gR
#print axioms SeedFamGHIndec.hR
#print axioms SeedFamGHIndec.g_indec
#print axioms SeedFamGHIndec.h_indec

#print axioms: 9 theorems, no axioms.

81.231 The only balanced splitting of \(G_p\)

For \(F\) indecomposable at \(M=2k\), the only splitting of \(M::2F\) (modulus \(2M\)) into balanced parts is \(\{M\}\sqcup 2F\). Applies to \(G_p=2F_p\cup \{m/2\}\), e.g. \(p=5\).

hodge/GpSplit.lean

/-
  hodge/GpSplit.lean — T41 cycle 1914 (goal G862a, structure side): for any indecomposable F at modulus M = 2k,
  the only splitting of the doubled character G = M :: 2·F (modulus 2M) into two nonempty balanced parts is
  {M} ⊔ 2·F. With F = F_p (M = 14p) this is the split of G_p = 2F_p ∪ {m/2} used in G862.

  Proof: a part containing M is balanced iff the rest is (GcdHand.rest_bal_even); a doubled list 2·X balanced at
  2M gives X balanced at M (every unit t of M is a unit of 2M: t odd, gcd(t, 2M) odd divides M; tsum of 2·X at 2M
  is 2·tsum of X at M, FamDouble.tsum_map2); so a splitting gives a balanced splitting of F, which is trivial.

  Lean 4 core plus hodge/FamDouble, hodge/UnitMul, hodge/APPairIrrGen, hodge/FamIndec3, lib/Semi (lib_nat);
  hand proofs, no axioms.
-/
import hodge.FamDouble
import hodge.UnitMul
import hodge.APPairIrrGen
import hodge.FamIndec3

namespace GpSplit
open Indecomp ModHand GcdHand APPair1 FamBal FamDouble TorsionImage APPairIrrGen

theorem double_inj : ∀ a b : Nat, a + a = b + b → a = b
  | 0, 0, _ => rfl
  | 0, _ + 1, h => Nat.noConfusion h
  | _ + 1, 0, h => Nat.noConfusion h
  | a + 1, b + 1, h => by
    have h2 : (a + a) + 2 = (b + b) + 2 := calc
      (a + a) + 2 = (a + 1) + (a + 1) := by lib_nat
      _ = (b + 1) + (b + 1) := h
      _ = (b + b) + 2 := by lib_nat
    exact congrArg (· + 1) (double_inj a b (add_right_cancel' (a + a) (b + b) 2 h2))

/-- a unit of 2k is a unit of 4k -/
theorem unit_double (k t : Nat) (hg : Nat.gcd t (k + k) = 1) : Nat.gcd t ((k + k) + (k + k)) = 1 := by
  obtain ⟨c, hc⟩ := parity t
  cases hc with
  | inl e =>
    have ⟨d, hd⟩ := dvd_gcd 2 t (k + k) ⟨c, e⟩ ⟨k, by lib_nat⟩
    rw [hg] at hd
    exact (one_eq_mul 2 d hd (Nat.le_refl 2)).elim
  | inr e =>
    obtain ⟨⟨i, hi⟩, ⟨j, hj⟩⟩ := UnitMul.gcd_dvd t ((k + k) + (k + k))
    generalize Nat.gcd t ((k + k) + (k + k)) = g at hi hj ⊢
    obtain ⟨a, ha⟩ := parity g
    cases ha with
    | inl ga =>
      rw [ga, e] at hi
      exact (odd_ne_even c (a * i) (by rw [hi]; lib_nat)).elim
    | inr ga =>
      obtain ⟨b, hb⟩ := parity j
      cases hb with
      | inr jb =>
        rw [ga, jb] at hj
        exact (odd_ne_even (2 * a * b + a + b) (k + k)
          (by rw [show 2 * (k + k) = (k + k) + (k + k) by lib_nat, hj]; lib_nat)).elim
      | inl jb =>
        rw [jb] at hj
        have hM : k + k = g * b := double_inj _ _ (by rw [hj]; lib_nat)
        have ⟨d, hd⟩ := dvd_gcd g t (k + k) ⟨i, hi⟩ ⟨b, hM⟩
        rw [hg] at hd
        exact UnitMul.one_of_dvd_one g d hd

theorem all_app (P : Nat → Bool) : ∀ l1 l2 : List Nat, l1.all P = true → l2.all P = true → (l1 ++ l2).all P = true
  | [], _, _, h2 => h2
  | x :: l1, l2, h1, h2 => by
    have h1' : (P x && l1.all P) = true := h1
    cases hx : P x with
    | false => rw [hx] at h1'; exact Bool.noConfusion h1'
    | true =>
      rw [hx] at h1'
      show (P x && (l1 ++ l2).all P) = true
      rw [hx, all_app P l1 l2 h1' h2]; rfl

theorem all_range (pr P : Nat → Bool) : ∀ M, (∀ t, t < M → pr t = true → P t = true) →
    ((List.range M).filter pr).all P = true
  | 0, _ => rfl
  | M + 1, h => by
    rw [range_succ' M, filter_append' pr (List.range M) [M]]
    apply all_app
    · exact all_range pr P M (fun t ht hp => h t (Nat.lt_succ_of_lt ht) hp)
    · cases hM : pr M with
      | false =>
        have e : [M].filter pr = [] := by
          show (match pr M with | true => M :: [].filter pr | false => [].filter pr) = _; rw [hM]; rfl
        rw [e]; rfl
      | true =>
        have e : [M].filter pr = [M] := by
          show (match pr M with | true => M :: [].filter pr | false => [].filter pr) = _; rw [hM]; rfl
        rw [e]
        show (P M && true) = true
        rw [h M (Nat.lt_succ_self M) hM]; rfl

/-- 2·X balanced at 4k ⇒ X balanced at 2k -/
theorem half (k : Nat) (hk : 0 < k) (X : List Nat) (h : bal ((k + k) + (k + k)) (X.map (fun x => 2 * x)) = true) :
    bal (k + k) X = true := by
  have hM : 0 < k + k := Nat.lt_of_lt_of_le hk (Nat.le_add_right k k)
  unfold bal FermatPrime.units
  apply all_range
  intro t ht hp
  have hg : Nat.gcd t (k + k) = 1 := Nat.eq_of_beq_eq_true hp
  have e := FamIndec3.bal_unit _ t _ h (Nat.lt_of_lt_of_le ht (Nat.le_add_right _ _)) (unit_double k t hg)
  rw [show (k + k) + (k + k) = 2 * (k + k) by lib_nat, tsum_map2 (k + k) t hM X, len_map] at e
  have e2 : (tsum (k + k) t X + tsum (k + k) t X) + (tsum (k + k) t X + tsum (k + k) t X)
      = X.length * (k + k) + X.length * (k + k) := calc
    _ = 2 * tsum (k + k) t X + 2 * tsum (k + k) t X := by lib_nat
    _ = X.length * (2 * (k + k)) := e
    _ = X.length * (k + k) + X.length * (k + k) := by lib_nat
  rw [double_inj _ _ e2]
  exact beq_refl' _

theorem mem_fm (x : Nat) : ∀ (L : List (List Nat × List Nat)) (A B : List Nat),
    (A, B) ∈ L.flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)]) →
    ∃ A' B', (A', B') ∈ L ∧ ((A = x :: A' ∧ B = B') ∨ (A = A' ∧ B = x :: B'))
  | [], _, _, h => by cases h
  | p :: L, A, B, h => by
    have h' : (A, B) ∈ (x :: p.1, p.2) :: (p.1, x :: p.2) :: L.flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)]) := h
    cases h' with
    | head => exact ⟨p.1, p.2, List.Mem.head _, Or.inl ⟨rfl, rfl⟩⟩
    | tail _ h2 =>
      cases h2 with
      | head => exact ⟨p.1, p.2, List.Mem.head _, Or.inr ⟨rfl, rfl⟩⟩
      | tail _ h3 =>
        have ⟨A', B', hm, hc⟩ := mem_fm x L A B h3
        exact ⟨A', B', List.Mem.tail _ hm, hc⟩

theorem mem_mapP (g : Nat → Nat) : ∀ (L : List (List Nat × List Nat)) (A B : List Nat),
    (A, B) ∈ L.map (fun p => (p.1.map g, p.2.map g)) → ∃ A0 B0, (A0, B0) ∈ L ∧ A = A0.map g ∧ B = B0.map g
  | [], _, _, h => by cases h
  | p :: L, A, B, h => by
    have h' : (A, B) ∈ (p.1.map g, p.2.map g) :: L.map (fun p => (p.1.map g, p.2.map g)) := h
    cases h' with
    | head => exact ⟨p.1, p.2, List.Mem.head _, rfl, rfl⟩
    | tail _ h2 =>
      have ⟨A0, B0, hm, e1, e2⟩ := mem_mapP g L A B h2
      exact ⟨A0, B0, List.Mem.tail _ hm, e1, e2⟩

theorem all_memG {α : Type} (P : α → Bool) : ∀ (l : List α), l.all P = true → ∀ r, r ∈ l → P r = true
  | [], _, _, h => nomatch h
  | x :: l, hl, r, hr => by
    have hx : P x = true ∧ l.all P = true := by
      cases e1 : P x with
      | false => rw [show (x :: l).all P = (P x && l.all P) from rfl, e1] at hl; exact nomatch hl
      | true => rw [show (x :: l).all P = (P x && l.all P) from rfl, e1] at hl; exact ⟨rfl, hl⟩
    cases hr with
    | head => exact hx.1
    | tail _ h' => exact all_memG P l hx.2 r h'

theorem empty_or (A0 B0 : List Nat) (h : (A0.isEmpty || B0.isEmpty || !(true && true)) = true) : A0 = [] ∨ B0 = [] := by
  cases A0 with
  | nil => exact Or.inl rfl
  | cons a l =>
    cases B0 with
    | nil => exact Or.inr rfl
    | cons b l' => exact Bool.noConfusion h

/-- **The only balanced splitting of M :: 2·F (F indecomposable at M = 2k) is {M} ⊔ 2·F.** -/
theorem gp_split (k : Nat) (hk : 0 < k) (F A B : List Nat) (hF : indec (k + k) F = true)
    (hs : (A, B) ∈ splits ((k + k) :: F.map (fun x => 2 * x)))
    (hA : bal ((k + k) + (k + k)) A = true) (hB : bal ((k + k) + (k + k)) B = true)
    (hAn : A ≠ []) (hBn : B ≠ []) : A = [k + k] ∨ B = [k + k] := by
  have hM : 0 < k + k := Nat.lt_of_lt_of_le hk (Nat.le_add_right k k)
  rw [splits_eq] at hs
  obtain ⟨A', B', hm, hc⟩ := mem_fm (k + k) _ A B hs
  rw [splits_map] at hm
  obtain ⟨A0, B0, h0, e1, e2⟩ := mem_mapP (fun x => 2 * x) _ A' B' hm
  have hi := all_memG _ (splits F) hF (A0, B0) (by rw [splits_eq]; exact h0)
  have hi' : (A0.isEmpty || B0.isEmpty || !(bal (k + k) A0 && bal (k + k) B0)) = true := hi
  rcases hc with ⟨ea, eb⟩ | ⟨ea, eb⟩
  · subst ea eb e1 e2
    rw [half k hk A0 (rest_bal_even (k + k) hM _ hA), half k hk B0 hB] at hi'
    rcases empty_or A0 B0 hi' with h | h
    · subst h; exact Or.inl rfl
    · subst h; exact (hBn rfl).elim
  · subst ea eb e1 e2
    rw [half k hk A0 hA, half k hk B0 (rest_bal_even (k + k) hM _ hB)] at hi'
    rcases empty_or A0 B0 hi' with h | h
    · subst h; exact (hAn rfl).elim
    · subst h; exact Or.inr rfl

-- the case p = 5: F_5 = fam 5 1 is indecomposable at 70, so G_5 = 70 :: 2·F_5 splits only as {70} ⊔ 2·F_5
set_option maxRecDepth 100000 in
theorem f5_indec : indec (35 + 35) (fam 5 1) = true := rfl

theorem g5_split (A B : List Nat) (hs : (A, B) ∈ splits ((35 + 35) :: (fam 5 1).map (fun x => 2 * x)))
    (hA : bal ((35 + 35) + (35 + 35)) A = true) (hB : bal ((35 + 35) + (35 + 35)) B = true)
    (hAn : A ≠ []) (hBn : B ≠ []) : A = [35 + 35] ∨ B = [35 + 35] :=
  gp_split 35 (Nat.succ_pos 34) (fam 5 1) A B f5_indec hs hA hB hAn hBn

end GpSplit

#print axioms GpSplit.double_inj
#print axioms GpSplit.unit_double
#print axioms GpSplit.all_app
#print axioms GpSplit.all_range
#print axioms GpSplit.half
#print axioms GpSplit.mem_fm
#print axioms GpSplit.mem_mapP
#print axioms GpSplit.all_memG
#print axioms GpSplit.empty_or
#print axioms GpSplit.gp_split
#print axioms GpSplit.f5_indec
#print axioms GpSplit.g5_split

#print axioms: 12 theorems, no axioms.

81.232 Unit sums over the cosets of \(1+14\mathbb {Z}\)

For \(t_j=\rho +14j\) (\(j<p\)) the sum of \(\langle t_j c\rangle _{14p}\) depends only on \(\rho c \bmod 14\) when \(\gcd (c,p)=1\). The same with the term divisible by \(p\) omitted, and for \(c=pe\).

hodge/CosetAvg.lean

/-
  hodge/CosetAvg.lean — T41 cycle 1914 (goal G862c, step 1): unit sums over the cosets ρ·H of
  H = {1 + 14i} in (Z/14p)^×, written as t_j = ρ + 14j (j < p), generalising FamIndec1 from ρ = 1, x ≡ 1 (mod 14)
  to any ρ and any c:
    coset_all   gcd(c, p) = 1:  Σ_{j<p} ⟨(ρ + 14j)·c⟩_{14p} = p·⟨ρc⟩_14 + 14·Σ_{i<p} i
    coset_term  c = p·e:         ⟨(ρ + 14j)·c⟩_{14p} = p·⟨ρe⟩_14 for every j
    omit_gen    ρ + 14j₀ = p·y:  ⟨(ρ + 14j₀)·c⟩_{14p} = p·⟨yc⟩_14
    coset_omit  Σ_{j<p, j≠j₀} ⟨(ρ + 14j)·c⟩_{14p} + p·⟨yc⟩_14 = p·⟨ρc⟩_14 + 14·Σ_{i<p} i   (gcd(c, p) = 1)
  So the coset-averaged balance condition of a list depends only on residues mod 14 (HODGE_LOG cycle 1914).

  Lean 4 core plus hodge/FamIndec1 (FamMod.mod_split, PermSum.perm_sum, FamArith.sumF_replace); no axioms.
-/
import hodge.FamIndec1

namespace CosetAvg
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp

theorem lt14 (r p : Nat) (hr : r < 14) (hp : 0 < p) : p * r < 14 * p := by
  rw [Nat.mul_comm 14 p]
  exact Nat.mul_lt_mul_of_le_of_lt (Nat.le_refl p) hr hp

theorem coset_all (p ρ c : Nat) (hp : 0 < p) (hx : Nat.gcd c p = 1) :
    sumF (fun j => ((ρ + 14 * j) * c) % (14 * p)) p = p * ((ρ * c) % 14) + 14 * sumF (fun i => i) p := by
  have hr : (ρ * c) % 14 < 14 := Nat.mod_lt _ (Nat.succ_pos 13)
  obtain ⟨q, hq⟩ := div_mod 14 (Nat.succ_pos 13) (ρ * c + 1) (ρ * c) (Nat.lt_succ_self _)
  generalize (ρ * c) % 14 = r at hr hq ⊢
  have e : ∀ j, ((ρ + 14 * j) * c) % (14 * p) = r + 14 * ((q + c * j) % p) := by
    intro j
    have e1 : (ρ + 14 * j) * c = r + 14 * (q + c * j) := by
      calc (ρ + 14 * j) * c = ρ * c + 14 * (c * j) := by lib_nat
        _ = (r + 14 * q) + 14 * (c * j) := by rw [hq]
        _ = _ := by lib_nat
    rw [e1, mod_split r _ p hp hr]
  rw [sumF_congr _ _ e p, sumF_lin, perm_sum p c q hp hx]

theorem coset_term (p ρ e j : Nat) (hp : 0 < p) :
    ((ρ + 14 * j) * (p * e)) % (14 * p) = p * ((ρ * e) % 14) := by
  have hr : (ρ * e) % 14 < 14 := Nat.mod_lt _ (Nat.succ_pos 13)
  obtain ⟨q, hq⟩ := div_mod 14 (Nat.succ_pos 13) (ρ * e + 1) (ρ * e) (Nat.lt_succ_self _)
  generalize (ρ * e) % 14 = r at hr hq ⊢
  have e1 : (ρ + 14 * j) * (p * e) = p * r + (q + j * e) * (14 * p) := by
    calc (ρ + 14 * j) * (p * e) = p * (ρ * e) + 14 * p * (j * e) := by lib_nat
      _ = p * (r + 14 * q) + 14 * p * (j * e) := by rw [hq]
      _ = _ := by lib_nat
  rw [e1, add_mul_mod' _ _ (Nat.mul_pos (Nat.succ_pos 13) hp)]
  exact mod_lt' _ _ (lt14 r p hr hp)

theorem omit_gen (p ρ j0 y c : Nat) (hp : 0 < p) (ht : ρ + 14 * j0 = p * y) :
    ((ρ + 14 * j0) * c) % (14 * p) = p * ((y * c) % 14) := by
  have hr : (y * c) % 14 < 14 := Nat.mod_lt _ (Nat.succ_pos 13)
  obtain ⟨q, hq⟩ := div_mod 14 (Nat.succ_pos 13) (y * c + 1) (y * c) (Nat.lt_succ_self _)
  generalize (y * c) % 14 = r at hr hq ⊢
  have e1 : (ρ + 14 * j0) * c = p * r + q * (14 * p) := by
    rw [ht]
    calc p * y * c = p * (y * c) := by lib_nat
      _ = p * (r + 14 * q) := by rw [hq]
      _ = _ := by lib_nat
  rw [e1, add_mul_mod' _ _ (Nat.mul_pos (Nat.succ_pos 13) hp)]
  exact mod_lt' _ _ (lt14 r p hr hp)

/-- the sum over t_j = ρ + 14j, j ≠ j₀ (the j₀ term set to 0) -/
def omitR (p ρ j0 c : Nat) : Nat :=
  sumF (fun j => if Nat.beq j j0 then 0 else ((ρ + 14 * j) * c) % (14 * p)) p

theorem omitR_add (p ρ j0 c : Nat) (hi : j0 < p) :
    omitR p ρ j0 c + ((ρ + 14 * j0) * c) % (14 * p) = sumF (fun j => ((ρ + 14 * j) * c) % (14 * p)) p := by
  have rep := sumF_replace (fun j => if Nat.beq j j0 then 0 else ((ρ + 14 * j) * c) % (14 * p))
    (fun j => ((ρ + 14 * j) * c) % (14 * p)) j0 (fun j hne => by
      have : Nat.beq j j0 = false := by
        cases e : Nat.beq j j0 with
        | false => rfl
        | true => exact absurd (Nat.eq_of_beq_eq_true e) hne
      show (if Nat.beq j j0 = true then 0 else _) = _
      rw [this]; rfl) p hi
  have rep' : omitR p ρ j0 c + ((ρ + 14 * j0) * c) % (14 * p)
      = sumF (fun j => ((ρ + 14 * j) * c) % (14 * p)) p
        + (if Nat.beq j0 j0 = true then 0 else ((ρ + 14 * j0) * c) % (14 * p)) := rep
  rw [FamBal.beq_refl' j0] at rep'
  exact rep'

/-- **Coset average of a unit element.** -/
theorem coset_omit (p ρ j0 y c : Nat) (hi : j0 < p) (ht : ρ + 14 * j0 = p * y) (hx : Nat.gcd c p = 1) :
    omitR p ρ j0 c + p * ((y * c) % 14) = p * ((ρ * c) % 14) + 14 * sumF (fun i => i) p := by
  have hp : 0 < p := Nat.lt_of_le_of_lt (Nat.zero_le j0) hi
  rw [← omit_gen p ρ j0 y c hp ht, omitR_add p ρ j0 c hi, coset_all p ρ c hp hx]

theorem sumF_const (C : Nat) : ∀ n, sumF (fun _ => C) n = n * C
  | 0 => by show 0 = 0 * C; lib_nat
  | n + 1 => by show sumF (fun _ => C) n + C = (n + 1) * C; rw [sumF_const C n]; lib_nat

/-- **Coset average of a multiple of p.** -/
theorem coset_omit_div (p ρ j0 e : Nat) (hi : j0 < p) :
    omitR p ρ j0 (p * e) + p * ((ρ * e) % 14) = p * (p * ((ρ * e) % 14)) := by
  have hp : 0 < p := Nat.lt_of_le_of_lt (Nat.zero_le j0) hi
  have h := omitR_add p ρ j0 (p * e) hi
  rw [coset_term p ρ e j0 hp, sumF_congr _ _ (fun j => coset_term p ρ e j hp) p, sumF_const] at h
  exact h

end CosetAvg

#print axioms CosetAvg.lt14
#print axioms CosetAvg.coset_all
#print axioms CosetAvg.coset_term
#print axioms CosetAvg.omit_gen
#print axioms CosetAvg.omitR_add
#print axioms CosetAvg.coset_omit
#print axioms CosetAvg.sumF_const
#print axioms CosetAvg.coset_omit_div

#print axioms: 8 theorems, no axioms.

81.233 The seed families \(G\), \(H\) are balanced for every \(k\)

\(G(36k)\) and \(H(36k)\) are balanced for every \(k\ge 1\). Each unit is reduced to one of twelve strips \(\tau =6(aK+w)+\rho \), where every remainder is an affine form.

hodge/SeedFamGHGen.lean

/-
  hodge/SeedFamGHGen.lean — T41 cycle 1914 (goal G864, structure side): the two seed families
    G(m) = {1, m/6 − 1, 2m/3 + 1, 2m/3 + 2, m − 3},   H(m) = {1, m/3 + 1, 2m/3 + 1, m/2 + 3, m − 6}
  are balanced for every m = 36K (K ≥ 1), not only K ≤ 6 (hodge/SeedFamGH).

  Proof: for a unit t of m, t ≡ τ (mod m) with τ < m (tsum_shift), τ = ρ + 6(w + K·a) with ρ < 6, w < K, a < 6;
  ρ ∈ {0, 2, 3, 4} contradicts gcd(t, 36K) = 1 (APPair1.dvd_gcd), and for ρ ∈ {1, 5} the twelve strips
  (strip_ρ_a, hstrip_ρ_a; K = w + v + 1) compute every remainder τ·x mod m as an affine form in (w, v)
  (modv: a = r + q·m, r < m ⇒ a mod m = r), whose sum is 5m/2. Generated by tools/g864_cases.py, tools/mk_g864b.py.

  Lean 4 core plus hodge/SeedFamGH, hodge/APPair1, hodge/FamBal, lib/Semi (lib_nat); hand proofs, no axioms.
-/
import hodge.SeedFamGH
import hodge.APPair1
import hodge.FamBal

namespace SeedFamGHGen
open Indecomp ModHand GcdHand APPair1 FamBal SeedFamGH

theorem modv (a m q r : Nat) (h : a = r + q * m) (hr : r < m) : a % m = r := by
  rw [h, add_mul_mod' r m (Nat.lt_of_le_of_lt (Nat.zero_le r) hr) q, mod_lt' r m hr]

theorem lt_of_add (r d m : Nat) (h : r + d + 1 = m) : r < m := by
  rw [← h]; exact Nat.lt_succ_of_le (Nat.le_add_right r d)

theorem tsum_shift (m τ Q : Nat) (hm : 0 < m) : ∀ L, tsum m (τ + m * Q) L = tsum m τ L
  | [] => rfl
  | a :: L => by
    show ((τ + m * Q) * a) % m + tsum m (τ + m * Q) L = (τ * a) % m + tsum m τ L
    rw [tsum_shift m τ Q hm L, show (τ + m * Q) * a = τ * a + (Q * a) * m by lib_nat,
      add_mul_mod' (τ * a) m hm (Q * a)]

theorem lt6 : ∀ x, x < 6 → x = 0 ∨ x = 1 ∨ x = 2 ∨ x = 3 ∨ x = 4 ∨ x = 5
  | 0, _ => Or.inl rfl
  | 1, _ => Or.inr (Or.inl rfl)
  | 2, _ => Or.inr (Or.inr (Or.inl rfl))
  | 3, _ => Or.inr (Or.inr (Or.inr (Or.inl rfl)))
  | 4, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))
  | 5, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr rfl))))
  | n + 6, h => absurd h (fun h' => Nat.lt_irrefl 6 (Nat.lt_of_le_of_lt (Nat.le_add_left 6 n) h'))

theorem a_lt (ρ w K : Nat) : ∀ a, ρ + 6 * (w + K * a) < 36 * K → a < 6
  | 0, _ => Nat.le.intro (k := 5) rfl
  | 1, _ => Nat.le.intro (k := 4) rfl
  | 2, _ => Nat.le.intro (k := 3) rfl
  | 3, _ => Nat.le.intro (k := 2) rfl
  | 4, _ => Nat.le.intro (k := 1) rfl
  | 5, _ => Nat.le.intro (k := 0) rfl
  | n + 6, h => by
    have hle : 36 * K ≤ ρ + 6 * (w + K * (n + 6)) := Nat.le.intro (k := ρ + 6 * w + 6 * K * n) (by lib_nat)
    exact absurd (Nat.lt_of_le_of_lt hle h) (Nat.lt_irrefl _)

theorem bad (d x n c b : Nat) (hd : 2 ≤ d) (hx : x = d * c) (hn : n = d * b) (hg : Nat.gcd x n = 1) : False := by
  have ⟨e, he⟩ := dvd_gcd d x n ⟨c, hx⟩ ⟨b, hn⟩
  rw [hg] at he
  exact one_eq_mul d e he hd

theorem lt_dest (w K : Nat) (h : w < K) : ∃ v, K = w + v + 1 := by
  have ⟨v, hv⟩ := Nat.le.dest h
  exact ⟨v, by rw [← hv]; lib_nat⟩

theorem sub_eq (a b c : Nat) (h : a = c + b) : a - b = c := by
  rw [h]; exact ModHand.add_sub' c b

theorem gX (w v : Nat) : G (w + v + 1) =
    [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] := by
  unfold G
  rw [sub_eq (6 * (w + v + 1)) 1 (5 + 6 * w + 6 * v) (by lib_nat),
    sub_eq (36 * (w + v + 1)) 3 (33 + 36 * w + 36 * v) (by lib_nat),
    show 24 * (w + v + 1) + 1 = 25 + 24 * w + 24 * v by lib_nat,
    show 24 * (w + v + 1) + 2 = 26 + 24 * w + 24 * v by lib_nat]

theorem hX (w v : Nat) : H (w + v + 1) =
    [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] := by
  unfold H
  rw [sub_eq (36 * (w + v + 1)) 6 (30 + 36 * w + 36 * v) (by lib_nat),
    show 12 * (w + v + 1) + 1 = 13 + 12 * w + 12 * v by lib_nat,
    show 24 * (w + v + 1) + 1 = 25 + 24 * w + 24 * v by lib_nat,
    show 18 * (w + v + 1) + 3 = 21 + 18 * w + 18 * v by lib_nat]

-- expansion lemmas: products of linear forms in (w, v) with symbolic coefficients (one lib_nat each);
-- the numeric coefficients of the strips are then compared by rfl on binary numerals.
theorem quad (a0 a1 a2 b0 b1 b2 w v : Nat) :
    (a0 + a1 * w + a2 * v) * (b0 + b1 * w + b2 * v) = a0 * b0 + (a0 * b1 + a1 * b0) * w + (a0 * b2 + a2 * b0) * v
      + (a1 * b1) * (w * w) + (a1 * b2 + a2 * b1) * (w * v) + (a2 * b2) * (v * v) := by lib_nat

theorem lin1 (a0 a1 a2 w v : Nat) :
    (a0 + a1 * w + a2 * v) * 1 = a0 + a1 * w + a2 * v + 0 * (w * w) + 0 * (w * v) + 0 * (v * v) := by lib_nat

theorem add6 (r0 r1 r2 e0 e1 e2 e3 e4 e5 w v : Nat) :
    (r0 + r1 * w + r2 * v) + (e0 + e1 * w + e2 * v + e3 * (w * w) + e4 * (w * v) + e5 * (v * v))
      = (r0 + e0) + (r1 + e1) * w + (r2 + e2) * v + e3 * (w * w) + e4 * (w * v) + e5 * (v * v) := by lib_nat

theorem add3 (r0 r1 r2 d0 d1 d2 w v : Nat) :
    (r0 + r1 * w + r2 * v) + (d0 + d1 * w + d2 * v) + 1 = (r0 + d0 + 1) + (r1 + d1) * w + (r2 + d2) * v := by lib_nat

theorem sum5 (a0 a1 a2 b0 b1 b2 c0 c1 c2 d0 d1 d2 e0 e1 e2 w v : Nat) :
    (a0 + a1 * w + a2 * v) + ((b0 + b1 * w + b2 * v) + ((c0 + c1 * w + c2 * v) + ((d0 + d1 * w + d2 * v)
      + ((e0 + e1 * w + e2 * v) + 0))))
      = (a0 + b0 + c0 + d0 + e0) + (a1 + b1 + c1 + d1 + e1) * w + (a2 + b2 + c2 + d2 + e2) * v := by lib_nat

theorem strip_1_0 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (1 + 6 * w + 0 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((1 + 6 * w + 0 * v) * 1) % (36 + 36 * w + 36 * v) + (((1 + 6 * w + 0 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((1 + 6 * w + 0 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((1 + 6 * w + 0 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((1 + 6 * w + 0 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((1 + 6 * w + 0 * v) * 1) % (36 + 36 * w + 36 * v) = (1 + 6 * w + 0 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 1 6 0 w v, quad 0 0 0 36 36 36 w v, add6 1 6 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (34 + 30 * w + 36 * v) _ (by rw [add3 1 6 0 34 30 36 w v] <;> rfl))
  have e1 : ((1 + 6 * w + 0 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (5 + 0 * w + 6 * v) :=
    modv _ _ (0 + 1 * w + 0 * v) _ (by rw [quad 1 6 0 5 6 6 w v, quad 0 1 0 36 36 36 w v, add6 5 0 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (30 + 36 * w + 30 * v) _ (by rw [add3 5 0 6 30 36 30 w v] <;> rfl))
  have e2 : ((1 + 6 * w + 0 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (25 + 30 * w + 24 * v) :=
    modv _ _ (0 + 4 * w + 0 * v) _ (by rw [quad 1 6 0 25 24 24 w v, quad 0 4 0 36 36 36 w v, add6 25 30 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (10 + 6 * w + 12 * v) _ (by rw [add3 25 30 24 10 6 12 w v] <;> rfl))
  have e3 : ((1 + 6 * w + 0 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (26 + 36 * w + 24 * v) :=
    modv _ _ (0 + 4 * w + 0 * v) _ (by rw [quad 1 6 0 26 24 24 w v, quad 0 4 0 36 36 36 w v, add6 26 36 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (9 + 0 * w + 12 * v) _ (by rw [add3 26 36 24 9 0 12 w v] <;> rfl))
  have e4 : ((1 + 6 * w + 0 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (33 + 18 * w + 36 * v) :=
    modv _ _ (0 + 6 * w + 0 * v) _ (by rw [quad 1 6 0 33 36 36 w v, quad 0 6 0 36 36 36 w v, add6 33 18 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (2 + 18 * w + 0 * v) _ (by rw [add3 33 18 36 2 18 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 1 6 0 5 0 6 25 30 24 26 36 24 33 18 36 w v] <;> rfl

theorem strip_1_1 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (7 + 12 * w + 6 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((7 + 12 * w + 6 * v) * 1) % (36 + 36 * w + 36 * v) + (((7 + 12 * w + 6 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((7 + 12 * w + 6 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((7 + 12 * w + 6 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((7 + 12 * w + 6 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((7 + 12 * w + 6 * v) * 1) % (36 + 36 * w + 36 * v) = (7 + 12 * w + 6 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 7 12 6 w v, quad 0 0 0 36 36 36 w v, add6 7 12 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (28 + 24 * w + 30 * v) _ (by rw [add3 7 12 6 28 24 30 w v] <;> rfl))
  have e1 : ((7 + 12 * w + 6 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (35 + 30 * w + 36 * v) :=
    modv _ _ (0 + 2 * w + 1 * v) _ (by rw [quad 7 12 6 5 6 6 w v, quad 0 2 1 36 36 36 w v, add6 35 30 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (0 + 6 * w + 0 * v) _ (by rw [add3 35 30 36 0 6 0 w v] <;> rfl))
  have e2 : ((7 + 12 * w + 6 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (31 + 36 * w + 30 * v) :=
    modv _ _ (4 + 8 * w + 4 * v) _ (by rw [quad 7 12 6 25 24 24 w v, quad 4 8 4 36 36 36 w v, add6 31 36 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (4 + 0 * w + 6 * v) _ (by rw [add3 31 36 30 4 0 6 w v] <;> rfl))
  have e3 : ((7 + 12 * w + 6 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (2 + 12 * w + 0 * v) :=
    modv _ _ (5 + 8 * w + 4 * v) _ (by rw [quad 7 12 6 26 24 24 w v, quad 5 8 4 36 36 36 w v, add6 2 12 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (33 + 24 * w + 36 * v) _ (by rw [add3 2 12 0 33 24 36 w v] <;> rfl))
  have e4 : ((7 + 12 * w + 6 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (15 + 0 * w + 18 * v) :=
    modv _ _ (6 + 12 * w + 6 * v) _ (by rw [quad 7 12 6 33 36 36 w v, quad 6 12 6 36 36 36 w v, add6 15 0 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (20 + 36 * w + 18 * v) _ (by rw [add3 15 0 18 20 36 18 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 7 12 6 35 30 36 31 36 30 2 12 0 15 0 18 w v] <;> rfl

theorem strip_1_2 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (13 + 18 * w + 12 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((13 + 18 * w + 12 * v) * 1) % (36 + 36 * w + 36 * v) + (((13 + 18 * w + 12 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((13 + 18 * w + 12 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((13 + 18 * w + 12 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((13 + 18 * w + 12 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((13 + 18 * w + 12 * v) * 1) % (36 + 36 * w + 36 * v) = (13 + 18 * w + 12 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 13 18 12 w v, quad 0 0 0 36 36 36 w v, add6 13 18 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (22 + 18 * w + 24 * v) _ (by rw [add3 13 18 12 22 18 24 w v] <;> rfl))
  have e1 : ((13 + 18 * w + 12 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (29 + 24 * w + 30 * v) :=
    modv _ _ (1 + 3 * w + 2 * v) _ (by rw [quad 13 18 12 5 6 6 w v, quad 1 3 2 36 36 36 w v, add6 29 24 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (6 + 12 * w + 6 * v) _ (by rw [add3 29 24 30 6 12 6 w v] <;> rfl))
  have e2 : ((13 + 18 * w + 12 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (1 + 6 * w + 0 * v) :=
    modv _ _ (9 + 12 * w + 8 * v) _ (by rw [quad 13 18 12 25 24 24 w v, quad 9 12 8 36 36 36 w v, add6 1 6 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (34 + 30 * w + 36 * v) _ (by rw [add3 1 6 0 34 30 36 w v] <;> rfl))
  have e3 : ((13 + 18 * w + 12 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (14 + 24 * w + 12 * v) :=
    modv _ _ (9 + 12 * w + 8 * v) _ (by rw [quad 13 18 12 26 24 24 w v, quad 9 12 8 36 36 36 w v, add6 14 24 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (21 + 12 * w + 24 * v) _ (by rw [add3 14 24 12 21 12 24 w v] <;> rfl))
  have e4 : ((13 + 18 * w + 12 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (33 + 18 * w + 36 * v) :=
    modv _ _ (11 + 18 * w + 12 * v) _ (by rw [quad 13 18 12 33 36 36 w v, quad 11 18 12 36 36 36 w v, add6 33 18 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (2 + 18 * w + 0 * v) _ (by rw [add3 33 18 36 2 18 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 13 18 12 29 24 30 1 6 0 14 24 12 33 18 36 w v] <;> rfl

theorem strip_1_3 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (19 + 24 * w + 18 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((19 + 24 * w + 18 * v) * 1) % (36 + 36 * w + 36 * v) + (((19 + 24 * w + 18 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((19 + 24 * w + 18 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((19 + 24 * w + 18 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((19 + 24 * w + 18 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((19 + 24 * w + 18 * v) * 1) % (36 + 36 * w + 36 * v) = (19 + 24 * w + 18 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 19 24 18 w v, quad 0 0 0 36 36 36 w v, add6 19 24 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (16 + 12 * w + 18 * v) _ (by rw [add3 19 24 18 16 12 18 w v] <;> rfl))
  have e1 : ((19 + 24 * w + 18 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (23 + 18 * w + 24 * v) :=
    modv _ _ (2 + 4 * w + 3 * v) _ (by rw [quad 19 24 18 5 6 6 w v, quad 2 4 3 36 36 36 w v, add6 23 18 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (12 + 18 * w + 12 * v) _ (by rw [add3 23 18 24 12 18 12 w v] <;> rfl))
  have e2 : ((19 + 24 * w + 18 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (7 + 12 * w + 6 * v) :=
    modv _ _ (13 + 16 * w + 12 * v) _ (by rw [quad 19 24 18 25 24 24 w v, quad 13 16 12 36 36 36 w v, add6 7 12 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (28 + 24 * w + 30 * v) _ (by rw [add3 7 12 6 28 24 30 w v] <;> rfl))
  have e3 : ((19 + 24 * w + 18 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (26 + 36 * w + 24 * v) :=
    modv _ _ (13 + 16 * w + 12 * v) _ (by rw [quad 19 24 18 26 24 24 w v, quad 13 16 12 36 36 36 w v, add6 26 36 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (9 + 0 * w + 12 * v) _ (by rw [add3 26 36 24 9 0 12 w v] <;> rfl))
  have e4 : ((19 + 24 * w + 18 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (15 + 0 * w + 18 * v) :=
    modv _ _ (17 + 24 * w + 18 * v) _ (by rw [quad 19 24 18 33 36 36 w v, quad 17 24 18 36 36 36 w v, add6 15 0 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (20 + 36 * w + 18 * v) _ (by rw [add3 15 0 18 20 36 18 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 19 24 18 23 18 24 7 12 6 26 36 24 15 0 18 w v] <;> rfl

theorem strip_1_4 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (25 + 30 * w + 24 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((25 + 30 * w + 24 * v) * 1) % (36 + 36 * w + 36 * v) + (((25 + 30 * w + 24 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((25 + 30 * w + 24 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((25 + 30 * w + 24 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((25 + 30 * w + 24 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((25 + 30 * w + 24 * v) * 1) % (36 + 36 * w + 36 * v) = (25 + 30 * w + 24 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 25 30 24 w v, quad 0 0 0 36 36 36 w v, add6 25 30 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (10 + 6 * w + 12 * v) _ (by rw [add3 25 30 24 10 6 12 w v] <;> rfl))
  have e1 : ((25 + 30 * w + 24 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (17 + 12 * w + 18 * v) :=
    modv _ _ (3 + 5 * w + 4 * v) _ (by rw [quad 25 30 24 5 6 6 w v, quad 3 5 4 36 36 36 w v, add6 17 12 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (18 + 24 * w + 18 * v) _ (by rw [add3 17 12 18 18 24 18 w v] <;> rfl))
  have e2 : ((25 + 30 * w + 24 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (13 + 18 * w + 12 * v) :=
    modv _ _ (17 + 20 * w + 16 * v) _ (by rw [quad 25 30 24 25 24 24 w v, quad 17 20 16 36 36 36 w v, add6 13 18 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (22 + 18 * w + 24 * v) _ (by rw [add3 13 18 12 22 18 24 w v] <;> rfl))
  have e3 : ((25 + 30 * w + 24 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (2 + 12 * w + 0 * v) :=
    modv _ _ (18 + 20 * w + 16 * v) _ (by rw [quad 25 30 24 26 24 24 w v, quad 18 20 16 36 36 36 w v, add6 2 12 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (33 + 24 * w + 36 * v) _ (by rw [add3 2 12 0 33 24 36 w v] <;> rfl))
  have e4 : ((25 + 30 * w + 24 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (33 + 18 * w + 36 * v) :=
    modv _ _ (22 + 30 * w + 24 * v) _ (by rw [quad 25 30 24 33 36 36 w v, quad 22 30 24 36 36 36 w v, add6 33 18 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (2 + 18 * w + 0 * v) _ (by rw [add3 33 18 36 2 18 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 25 30 24 17 12 18 13 18 12 2 12 0 33 18 36 w v] <;> rfl

theorem strip_1_5 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (31 + 36 * w + 30 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((31 + 36 * w + 30 * v) * 1) % (36 + 36 * w + 36 * v) + (((31 + 36 * w + 30 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((31 + 36 * w + 30 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((31 + 36 * w + 30 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((31 + 36 * w + 30 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((31 + 36 * w + 30 * v) * 1) % (36 + 36 * w + 36 * v) = (31 + 36 * w + 30 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 31 36 30 w v, quad 0 0 0 36 36 36 w v, add6 31 36 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (4 + 0 * w + 6 * v) _ (by rw [add3 31 36 30 4 0 6 w v] <;> rfl))
  have e1 : ((31 + 36 * w + 30 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (11 + 6 * w + 12 * v) :=
    modv _ _ (4 + 6 * w + 5 * v) _ (by rw [quad 31 36 30 5 6 6 w v, quad 4 6 5 36 36 36 w v, add6 11 6 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (24 + 30 * w + 24 * v) _ (by rw [add3 11 6 12 24 30 24 w v] <;> rfl))
  have e2 : ((31 + 36 * w + 30 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (19 + 24 * w + 18 * v) :=
    modv _ _ (21 + 24 * w + 20 * v) _ (by rw [quad 31 36 30 25 24 24 w v, quad 21 24 20 36 36 36 w v, add6 19 24 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (16 + 12 * w + 18 * v) _ (by rw [add3 19 24 18 16 12 18 w v] <;> rfl))
  have e3 : ((31 + 36 * w + 30 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (14 + 24 * w + 12 * v) :=
    modv _ _ (22 + 24 * w + 20 * v) _ (by rw [quad 31 36 30 26 24 24 w v, quad 22 24 20 36 36 36 w v, add6 14 24 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (21 + 12 * w + 24 * v) _ (by rw [add3 14 24 12 21 12 24 w v] <;> rfl))
  have e4 : ((31 + 36 * w + 30 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (15 + 0 * w + 18 * v) :=
    modv _ _ (28 + 36 * w + 30 * v) _ (by rw [quad 31 36 30 33 36 36 w v, quad 28 36 30 36 36 36 w v, add6 15 0 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (20 + 36 * w + 18 * v) _ (by rw [add3 15 0 18 20 36 18 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 31 36 30 11 6 12 19 24 18 14 24 12 15 0 18 w v] <;> rfl

theorem strip_5_0 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (5 + 6 * w + 0 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((5 + 6 * w + 0 * v) * 1) % (36 + 36 * w + 36 * v) + (((5 + 6 * w + 0 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((5 + 6 * w + 0 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((5 + 6 * w + 0 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((5 + 6 * w + 0 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((5 + 6 * w + 0 * v) * 1) % (36 + 36 * w + 36 * v) = (5 + 6 * w + 0 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 5 6 0 w v, quad 0 0 0 36 36 36 w v, add6 5 6 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (30 + 30 * w + 36 * v) _ (by rw [add3 5 6 0 30 30 36 w v] <;> rfl))
  have e1 : ((5 + 6 * w + 0 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (25 + 24 * w + 30 * v) :=
    modv _ _ (0 + 1 * w + 0 * v) _ (by rw [quad 5 6 0 5 6 6 w v, quad 0 1 0 36 36 36 w v, add6 25 24 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (10 + 12 * w + 6 * v) _ (by rw [add3 25 24 30 10 12 6 w v] <;> rfl))
  have e2 : ((5 + 6 * w + 0 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (17 + 18 * w + 12 * v) :=
    modv _ _ (3 + 4 * w + 0 * v) _ (by rw [quad 5 6 0 25 24 24 w v, quad 3 4 0 36 36 36 w v, add6 17 18 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (18 + 18 * w + 24 * v) _ (by rw [add3 17 18 12 18 18 24 w v] <;> rfl))
  have e3 : ((5 + 6 * w + 0 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (22 + 24 * w + 12 * v) :=
    modv _ _ (3 + 4 * w + 0 * v) _ (by rw [quad 5 6 0 26 24 24 w v, quad 3 4 0 36 36 36 w v, add6 22 24 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (13 + 12 * w + 24 * v) _ (by rw [add3 22 24 12 13 12 24 w v] <;> rfl))
  have e4 : ((5 + 6 * w + 0 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (21 + 18 * w + 36 * v) :=
    modv _ _ (4 + 6 * w + 0 * v) _ (by rw [quad 5 6 0 33 36 36 w v, quad 4 6 0 36 36 36 w v, add6 21 18 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (14 + 18 * w + 0 * v) _ (by rw [add3 21 18 36 14 18 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 5 6 0 25 24 30 17 18 12 22 24 12 21 18 36 w v] <;> rfl

theorem strip_5_1 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (11 + 12 * w + 6 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((11 + 12 * w + 6 * v) * 1) % (36 + 36 * w + 36 * v) + (((11 + 12 * w + 6 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((11 + 12 * w + 6 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((11 + 12 * w + 6 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((11 + 12 * w + 6 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((11 + 12 * w + 6 * v) * 1) % (36 + 36 * w + 36 * v) = (11 + 12 * w + 6 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 11 12 6 w v, quad 0 0 0 36 36 36 w v, add6 11 12 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (24 + 24 * w + 30 * v) _ (by rw [add3 11 12 6 24 24 30 w v] <;> rfl))
  have e1 : ((11 + 12 * w + 6 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (19 + 18 * w + 24 * v) :=
    modv _ _ (1 + 2 * w + 1 * v) _ (by rw [quad 11 12 6 5 6 6 w v, quad 1 2 1 36 36 36 w v, add6 19 18 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (16 + 18 * w + 12 * v) _ (by rw [add3 19 18 24 16 18 12 w v] <;> rfl))
  have e2 : ((11 + 12 * w + 6 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (23 + 24 * w + 18 * v) :=
    modv _ _ (7 + 8 * w + 4 * v) _ (by rw [quad 11 12 6 25 24 24 w v, quad 7 8 4 36 36 36 w v, add6 23 24 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (12 + 12 * w + 18 * v) _ (by rw [add3 23 24 18 12 12 18 w v] <;> rfl))
  have e3 : ((11 + 12 * w + 6 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (34 + 36 * w + 24 * v) :=
    modv _ _ (7 + 8 * w + 4 * v) _ (by rw [quad 11 12 6 26 24 24 w v, quad 7 8 4 36 36 36 w v, add6 34 36 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (1 + 0 * w + 12 * v) _ (by rw [add3 34 36 24 1 0 12 w v] <;> rfl))
  have e4 : ((11 + 12 * w + 6 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (3 + 0 * w + 18 * v) :=
    modv _ _ (10 + 12 * w + 6 * v) _ (by rw [quad 11 12 6 33 36 36 w v, quad 10 12 6 36 36 36 w v, add6 3 0 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (32 + 36 * w + 18 * v) _ (by rw [add3 3 0 18 32 36 18 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 11 12 6 19 18 24 23 24 18 34 36 24 3 0 18 w v] <;> rfl

theorem strip_5_2 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (17 + 18 * w + 12 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((17 + 18 * w + 12 * v) * 1) % (36 + 36 * w + 36 * v) + (((17 + 18 * w + 12 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((17 + 18 * w + 12 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((17 + 18 * w + 12 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((17 + 18 * w + 12 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((17 + 18 * w + 12 * v) * 1) % (36 + 36 * w + 36 * v) = (17 + 18 * w + 12 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 17 18 12 w v, quad 0 0 0 36 36 36 w v, add6 17 18 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (18 + 18 * w + 24 * v) _ (by rw [add3 17 18 12 18 18 24 w v] <;> rfl))
  have e1 : ((17 + 18 * w + 12 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (13 + 12 * w + 18 * v) :=
    modv _ _ (2 + 3 * w + 2 * v) _ (by rw [quad 17 18 12 5 6 6 w v, quad 2 3 2 36 36 36 w v, add6 13 12 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (22 + 24 * w + 18 * v) _ (by rw [add3 13 12 18 22 24 18 w v] <;> rfl))
  have e2 : ((17 + 18 * w + 12 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (29 + 30 * w + 24 * v) :=
    modv _ _ (11 + 12 * w + 8 * v) _ (by rw [quad 17 18 12 25 24 24 w v, quad 11 12 8 36 36 36 w v, add6 29 30 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (6 + 6 * w + 12 * v) _ (by rw [add3 29 30 24 6 6 12 w v] <;> rfl))
  have e3 : ((17 + 18 * w + 12 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (10 + 12 * w + 0 * v) :=
    modv _ _ (12 + 12 * w + 8 * v) _ (by rw [quad 17 18 12 26 24 24 w v, quad 12 12 8 36 36 36 w v, add6 10 12 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (25 + 24 * w + 36 * v) _ (by rw [add3 10 12 0 25 24 36 w v] <;> rfl))
  have e4 : ((17 + 18 * w + 12 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (21 + 18 * w + 36 * v) :=
    modv _ _ (15 + 18 * w + 12 * v) _ (by rw [quad 17 18 12 33 36 36 w v, quad 15 18 12 36 36 36 w v, add6 21 18 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (14 + 18 * w + 0 * v) _ (by rw [add3 21 18 36 14 18 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 17 18 12 13 12 18 29 30 24 10 12 0 21 18 36 w v] <;> rfl

theorem strip_5_3 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (23 + 24 * w + 18 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((23 + 24 * w + 18 * v) * 1) % (36 + 36 * w + 36 * v) + (((23 + 24 * w + 18 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((23 + 24 * w + 18 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((23 + 24 * w + 18 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((23 + 24 * w + 18 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((23 + 24 * w + 18 * v) * 1) % (36 + 36 * w + 36 * v) = (23 + 24 * w + 18 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 23 24 18 w v, quad 0 0 0 36 36 36 w v, add6 23 24 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (12 + 12 * w + 18 * v) _ (by rw [add3 23 24 18 12 12 18 w v] <;> rfl))
  have e1 : ((23 + 24 * w + 18 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (7 + 6 * w + 12 * v) :=
    modv _ _ (3 + 4 * w + 3 * v) _ (by rw [quad 23 24 18 5 6 6 w v, quad 3 4 3 36 36 36 w v, add6 7 6 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (28 + 30 * w + 24 * v) _ (by rw [add3 7 6 12 28 30 24 w v] <;> rfl))
  have e2 : ((23 + 24 * w + 18 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (35 + 36 * w + 30 * v) :=
    modv _ _ (15 + 16 * w + 12 * v) _ (by rw [quad 23 24 18 25 24 24 w v, quad 15 16 12 36 36 36 w v, add6 35 36 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (0 + 0 * w + 6 * v) _ (by rw [add3 35 36 30 0 0 6 w v] <;> rfl))
  have e3 : ((23 + 24 * w + 18 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (22 + 24 * w + 12 * v) :=
    modv _ _ (16 + 16 * w + 12 * v) _ (by rw [quad 23 24 18 26 24 24 w v, quad 16 16 12 36 36 36 w v, add6 22 24 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (13 + 12 * w + 24 * v) _ (by rw [add3 22 24 12 13 12 24 w v] <;> rfl))
  have e4 : ((23 + 24 * w + 18 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (3 + 0 * w + 18 * v) :=
    modv _ _ (21 + 24 * w + 18 * v) _ (by rw [quad 23 24 18 33 36 36 w v, quad 21 24 18 36 36 36 w v, add6 3 0 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (32 + 36 * w + 18 * v) _ (by rw [add3 3 0 18 32 36 18 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 23 24 18 7 6 12 35 36 30 22 24 12 3 0 18 w v] <;> rfl

theorem strip_5_4 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (29 + 30 * w + 24 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((29 + 30 * w + 24 * v) * 1) % (36 + 36 * w + 36 * v) + (((29 + 30 * w + 24 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((29 + 30 * w + 24 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((29 + 30 * w + 24 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((29 + 30 * w + 24 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((29 + 30 * w + 24 * v) * 1) % (36 + 36 * w + 36 * v) = (29 + 30 * w + 24 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 29 30 24 w v, quad 0 0 0 36 36 36 w v, add6 29 30 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (6 + 6 * w + 12 * v) _ (by rw [add3 29 30 24 6 6 12 w v] <;> rfl))
  have e1 : ((29 + 30 * w + 24 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (1 + 0 * w + 6 * v) :=
    modv _ _ (4 + 5 * w + 4 * v) _ (by rw [quad 29 30 24 5 6 6 w v, quad 4 5 4 36 36 36 w v, add6 1 0 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (34 + 36 * w + 30 * v) _ (by rw [add3 1 0 6 34 36 30 w v] <;> rfl))
  have e2 : ((29 + 30 * w + 24 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (5 + 6 * w + 0 * v) :=
    modv _ _ (20 + 20 * w + 16 * v) _ (by rw [quad 29 30 24 25 24 24 w v, quad 20 20 16 36 36 36 w v, add6 5 6 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (30 + 30 * w + 36 * v) _ (by rw [add3 5 6 0 30 30 36 w v] <;> rfl))
  have e3 : ((29 + 30 * w + 24 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (34 + 36 * w + 24 * v) :=
    modv _ _ (20 + 20 * w + 16 * v) _ (by rw [quad 29 30 24 26 24 24 w v, quad 20 20 16 36 36 36 w v, add6 34 36 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (1 + 0 * w + 12 * v) _ (by rw [add3 34 36 24 1 0 12 w v] <;> rfl))
  have e4 : ((29 + 30 * w + 24 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (21 + 18 * w + 36 * v) :=
    modv _ _ (26 + 30 * w + 24 * v) _ (by rw [quad 29 30 24 33 36 36 w v, quad 26 30 24 36 36 36 w v, add6 21 18 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (14 + 18 * w + 0 * v) _ (by rw [add3 21 18 36 14 18 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 29 30 24 1 0 6 5 6 0 34 36 24 21 18 36 w v] <;> rfl

theorem strip_5_5 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (35 + 36 * w + 30 * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((35 + 36 * w + 30 * v) * 1) % (36 + 36 * w + 36 * v) + (((35 + 36 * w + 30 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) + (((35 + 36 * w + 30 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((35 + 36 * w + 30 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((35 + 36 * w + 30 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((35 + 36 * w + 30 * v) * 1) % (36 + 36 * w + 36 * v) = (35 + 36 * w + 30 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 35 36 30 w v, quad 0 0 0 36 36 36 w v, add6 35 36 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (0 + 0 * w + 6 * v) _ (by rw [add3 35 36 30 0 0 6 w v] <;> rfl))
  have e1 : ((35 + 36 * w + 30 * v) * (5 + 6 * w + 6 * v)) % (36 + 36 * w + 36 * v) = (31 + 30 * w + 36 * v) :=
    modv _ _ (4 + 6 * w + 5 * v) _ (by rw [quad 35 36 30 5 6 6 w v, quad 4 6 5 36 36 36 w v, add6 31 30 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (4 + 6 * w + 0 * v) _ (by rw [add3 31 30 36 4 6 0 w v] <;> rfl))
  have e2 : ((35 + 36 * w + 30 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (11 + 12 * w + 6 * v) :=
    modv _ _ (24 + 24 * w + 20 * v) _ (by rw [quad 35 36 30 25 24 24 w v, quad 24 24 20 36 36 36 w v, add6 11 12 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (24 + 24 * w + 30 * v) _ (by rw [add3 11 12 6 24 24 30 w v] <;> rfl))
  have e3 : ((35 + 36 * w + 30 * v) * (26 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (10 + 12 * w + 0 * v) :=
    modv _ _ (25 + 24 * w + 20 * v) _ (by rw [quad 35 36 30 26 24 24 w v, quad 25 24 20 36 36 36 w v, add6 10 12 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (25 + 24 * w + 36 * v) _ (by rw [add3 10 12 0 25 24 36 w v] <;> rfl))
  have e4 : ((35 + 36 * w + 30 * v) * (33 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (3 + 0 * w + 18 * v) :=
    modv _ _ (32 + 36 * w + 30 * v) _ (by rw [quad 35 36 30 33 36 36 w v, quad 32 36 30 36 36 36 w v, add6 3 0 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (32 + 36 * w + 18 * v) _ (by rw [add3 3 0 18 32 36 18 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 35 36 30 31 30 36 11 12 6 10 12 0 3 0 18 w v] <;> rfl

theorem hstrip_1_0 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (1 + 6 * w + 0 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((1 + 6 * w + 0 * v) * 1) % (36 + 36 * w + 36 * v) + (((1 + 6 * w + 0 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((1 + 6 * w + 0 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((1 + 6 * w + 0 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((1 + 6 * w + 0 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((1 + 6 * w + 0 * v) * 1) % (36 + 36 * w + 36 * v) = (1 + 6 * w + 0 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 1 6 0 w v, quad 0 0 0 36 36 36 w v, add6 1 6 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (34 + 30 * w + 36 * v) _ (by rw [add3 1 6 0 34 30 36 w v] <;> rfl))
  have e1 : ((1 + 6 * w + 0 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (13 + 18 * w + 12 * v) :=
    modv _ _ (0 + 2 * w + 0 * v) _ (by rw [quad 1 6 0 13 12 12 w v, quad 0 2 0 36 36 36 w v, add6 13 18 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (22 + 18 * w + 24 * v) _ (by rw [add3 13 18 12 22 18 24 w v] <;> rfl))
  have e2 : ((1 + 6 * w + 0 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (25 + 30 * w + 24 * v) :=
    modv _ _ (0 + 4 * w + 0 * v) _ (by rw [quad 1 6 0 25 24 24 w v, quad 0 4 0 36 36 36 w v, add6 25 30 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (10 + 6 * w + 12 * v) _ (by rw [add3 25 30 24 10 6 12 w v] <;> rfl))
  have e3 : ((1 + 6 * w + 0 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (21 + 36 * w + 18 * v) :=
    modv _ _ (0 + 3 * w + 0 * v) _ (by rw [quad 1 6 0 21 18 18 w v, quad 0 3 0 36 36 36 w v, add6 21 36 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (14 + 0 * w + 18 * v) _ (by rw [add3 21 36 18 14 0 18 w v] <;> rfl))
  have e4 : ((1 + 6 * w + 0 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (30 + 0 * w + 36 * v) :=
    modv _ _ (0 + 6 * w + 0 * v) _ (by rw [quad 1 6 0 30 36 36 w v, quad 0 6 0 36 36 36 w v, add6 30 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (5 + 36 * w + 0 * v) _ (by rw [add3 30 0 36 5 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 1 6 0 13 18 12 25 30 24 21 36 18 30 0 36 w v] <;> rfl

theorem hstrip_1_1 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (7 + 12 * w + 6 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((7 + 12 * w + 6 * v) * 1) % (36 + 36 * w + 36 * v) + (((7 + 12 * w + 6 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((7 + 12 * w + 6 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((7 + 12 * w + 6 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((7 + 12 * w + 6 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((7 + 12 * w + 6 * v) * 1) % (36 + 36 * w + 36 * v) = (7 + 12 * w + 6 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 7 12 6 w v, quad 0 0 0 36 36 36 w v, add6 7 12 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (28 + 24 * w + 30 * v) _ (by rw [add3 7 12 6 28 24 30 w v] <;> rfl))
  have e1 : ((7 + 12 * w + 6 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (19 + 24 * w + 18 * v) :=
    modv _ _ (2 + 4 * w + 2 * v) _ (by rw [quad 7 12 6 13 12 12 w v, quad 2 4 2 36 36 36 w v, add6 19 24 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (16 + 12 * w + 18 * v) _ (by rw [add3 19 24 18 16 12 18 w v] <;> rfl))
  have e2 : ((7 + 12 * w + 6 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (31 + 36 * w + 30 * v) :=
    modv _ _ (4 + 8 * w + 4 * v) _ (by rw [quad 7 12 6 25 24 24 w v, quad 4 8 4 36 36 36 w v, add6 31 36 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (4 + 0 * w + 6 * v) _ (by rw [add3 31 36 30 4 0 6 w v] <;> rfl))
  have e3 : ((7 + 12 * w + 6 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (3 + 18 * w + 0 * v) :=
    modv _ _ (4 + 6 * w + 3 * v) _ (by rw [quad 7 12 6 21 18 18 w v, quad 4 6 3 36 36 36 w v, add6 3 18 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (32 + 18 * w + 36 * v) _ (by rw [add3 3 18 0 32 18 36 w v] <;> rfl))
  have e4 : ((7 + 12 * w + 6 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (30 + 0 * w + 36 * v) :=
    modv _ _ (5 + 12 * w + 6 * v) _ (by rw [quad 7 12 6 30 36 36 w v, quad 5 12 6 36 36 36 w v, add6 30 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (5 + 36 * w + 0 * v) _ (by rw [add3 30 0 36 5 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 7 12 6 19 24 18 31 36 30 3 18 0 30 0 36 w v] <;> rfl

theorem hstrip_1_2 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (13 + 18 * w + 12 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((13 + 18 * w + 12 * v) * 1) % (36 + 36 * w + 36 * v) + (((13 + 18 * w + 12 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((13 + 18 * w + 12 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((13 + 18 * w + 12 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((13 + 18 * w + 12 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90   -- (+3 chars; full line in the Zenodo source)
  have e0 : ((13 + 18 * w + 12 * v) * 1) % (36 + 36 * w + 36 * v) = (13 + 18 * w + 12 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 13 18 12 w v, quad 0 0 0 36 36 36 w v, add6 13 18 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (22 + 18 * w + 24 * v) _ (by rw [add3 13 18 12 22 18 24 w v] <;> rfl))
  have e1 : ((13 + 18 * w + 12 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (25 + 30 * w + 24 * v) :=
    modv _ _ (4 + 6 * w + 4 * v) _ (by rw [quad 13 18 12 13 12 12 w v, quad 4 6 4 36 36 36 w v, add6 25 30 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (10 + 6 * w + 12 * v) _ (by rw [add3 25 30 24 10 6 12 w v] <;> rfl))
  have e2 : ((13 + 18 * w + 12 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (1 + 6 * w + 0 * v) :=
    modv _ _ (9 + 12 * w + 8 * v) _ (by rw [quad 13 18 12 25 24 24 w v, quad 9 12 8 36 36 36 w v, add6 1 6 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (34 + 30 * w + 36 * v) _ (by rw [add3 1 6 0 34 30 36 w v] <;> rfl))
  have e3 : ((13 + 18 * w + 12 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (21 + 36 * w + 18 * v) :=
    modv _ _ (7 + 9 * w + 6 * v) _ (by rw [quad 13 18 12 21 18 18 w v, quad 7 9 6 36 36 36 w v, add6 21 36 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (14 + 0 * w + 18 * v) _ (by rw [add3 21 36 18 14 0 18 w v] <;> rfl))
  have e4 : ((13 + 18 * w + 12 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (30 + 0 * w + 36 * v) :=
    modv _ _ (10 + 18 * w + 12 * v) _ (by rw [quad 13 18 12 30 36 36 w v, quad 10 18 12 36 36 36 w v, add6 30 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (5 + 36 * w + 0 * v) _ (by rw [add3 30 0 36 5 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 13 18 12 25 30 24 1 6 0 21 36 18 30 0 36 w v] <;> rfl

theorem hstrip_1_3 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (19 + 24 * w + 18 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((19 + 24 * w + 18 * v) * 1) % (36 + 36 * w + 36 * v) + (((19 + 24 * w + 18 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((19 + 24 * w + 18 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((19 + 24 * w + 18 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((19 + 24 * w + 18 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90   -- (+3 chars; full line in the Zenodo source)
  have e0 : ((19 + 24 * w + 18 * v) * 1) % (36 + 36 * w + 36 * v) = (19 + 24 * w + 18 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 19 24 18 w v, quad 0 0 0 36 36 36 w v, add6 19 24 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (16 + 12 * w + 18 * v) _ (by rw [add3 19 24 18 16 12 18 w v] <;> rfl))
  have e1 : ((19 + 24 * w + 18 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (31 + 36 * w + 30 * v) :=
    modv _ _ (6 + 8 * w + 6 * v) _ (by rw [quad 19 24 18 13 12 12 w v, quad 6 8 6 36 36 36 w v, add6 31 36 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (4 + 0 * w + 6 * v) _ (by rw [add3 31 36 30 4 0 6 w v] <;> rfl))
  have e2 : ((19 + 24 * w + 18 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (7 + 12 * w + 6 * v) :=
    modv _ _ (13 + 16 * w + 12 * v) _ (by rw [quad 19 24 18 25 24 24 w v, quad 13 16 12 36 36 36 w v, add6 7 12 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (28 + 24 * w + 30 * v) _ (by rw [add3 7 12 6 28 24 30 w v] <;> rfl))
  have e3 : ((19 + 24 * w + 18 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (3 + 18 * w + 0 * v) :=
    modv _ _ (11 + 12 * w + 9 * v) _ (by rw [quad 19 24 18 21 18 18 w v, quad 11 12 9 36 36 36 w v, add6 3 18 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (32 + 18 * w + 36 * v) _ (by rw [add3 3 18 0 32 18 36 w v] <;> rfl))
  have e4 : ((19 + 24 * w + 18 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (30 + 0 * w + 36 * v) :=
    modv _ _ (15 + 24 * w + 18 * v) _ (by rw [quad 19 24 18 30 36 36 w v, quad 15 24 18 36 36 36 w v, add6 30 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (5 + 36 * w + 0 * v) _ (by rw [add3 30 0 36 5 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 19 24 18 31 36 30 7 12 6 3 18 0 30 0 36 w v] <;> rfl

theorem hstrip_1_4 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (25 + 30 * w + 24 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((25 + 30 * w + 24 * v) * 1) % (36 + 36 * w + 36 * v) + (((25 + 30 * w + 24 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((25 + 30 * w + 24 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((25 + 30 * w + 24 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((25 + 30 * w + 24 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90   -- (+3 chars; full line in the Zenodo source)
  have e0 : ((25 + 30 * w + 24 * v) * 1) % (36 + 36 * w + 36 * v) = (25 + 30 * w + 24 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 25 30 24 w v, quad 0 0 0 36 36 36 w v, add6 25 30 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (10 + 6 * w + 12 * v) _ (by rw [add3 25 30 24 10 6 12 w v] <;> rfl))
  have e1 : ((25 + 30 * w + 24 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (1 + 6 * w + 0 * v) :=
    modv _ _ (9 + 10 * w + 8 * v) _ (by rw [quad 25 30 24 13 12 12 w v, quad 9 10 8 36 36 36 w v, add6 1 6 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (34 + 30 * w + 36 * v) _ (by rw [add3 1 6 0 34 30 36 w v] <;> rfl))
  have e2 : ((25 + 30 * w + 24 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (13 + 18 * w + 12 * v) :=
    modv _ _ (17 + 20 * w + 16 * v) _ (by rw [quad 25 30 24 25 24 24 w v, quad 17 20 16 36 36 36 w v, add6 13 18 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (22 + 18 * w + 24 * v) _ (by rw [add3 13 18 12 22 18 24 w v] <;> rfl))
  have e3 : ((25 + 30 * w + 24 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (21 + 36 * w + 18 * v) :=
    modv _ _ (14 + 15 * w + 12 * v) _ (by rw [quad 25 30 24 21 18 18 w v, quad 14 15 12 36 36 36 w v, add6 21 36 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (14 + 0 * w + 18 * v) _ (by rw [add3 21 36 18 14 0 18 w v] <;> rfl))
  have e4 : ((25 + 30 * w + 24 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (30 + 0 * w + 36 * v) :=
    modv _ _ (20 + 30 * w + 24 * v) _ (by rw [quad 25 30 24 30 36 36 w v, quad 20 30 24 36 36 36 w v, add6 30 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (5 + 36 * w + 0 * v) _ (by rw [add3 30 0 36 5 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 25 30 24 1 6 0 13 18 12 21 36 18 30 0 36 w v] <;> rfl

theorem hstrip_1_5 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (31 + 36 * w + 30 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((31 + 36 * w + 30 * v) * 1) % (36 + 36 * w + 36 * v) + (((31 + 36 * w + 30 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((31 + 36 * w + 30 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((31 + 36 * w + 30 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((31 + 36 * w + 30 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90   -- (+3 chars; full line in the Zenodo source)
  have e0 : ((31 + 36 * w + 30 * v) * 1) % (36 + 36 * w + 36 * v) = (31 + 36 * w + 30 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 31 36 30 w v, quad 0 0 0 36 36 36 w v, add6 31 36 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (4 + 0 * w + 6 * v) _ (by rw [add3 31 36 30 4 0 6 w v] <;> rfl))
  have e1 : ((31 + 36 * w + 30 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (7 + 12 * w + 6 * v) :=
    modv _ _ (11 + 12 * w + 10 * v) _ (by rw [quad 31 36 30 13 12 12 w v, quad 11 12 10 36 36 36 w v, add6 7 12 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (28 + 24 * w + 30 * v) _ (by rw [add3 7 12 6 28 24 30 w v] <;> rfl))
  have e2 : ((31 + 36 * w + 30 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (19 + 24 * w + 18 * v) :=
    modv _ _ (21 + 24 * w + 20 * v) _ (by rw [quad 31 36 30 25 24 24 w v, quad 21 24 20 36 36 36 w v, add6 19 24 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (16 + 12 * w + 18 * v) _ (by rw [add3 19 24 18 16 12 18 w v] <;> rfl))
  have e3 : ((31 + 36 * w + 30 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (3 + 18 * w + 0 * v) :=
    modv _ _ (18 + 18 * w + 15 * v) _ (by rw [quad 31 36 30 21 18 18 w v, quad 18 18 15 36 36 36 w v, add6 3 18 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (32 + 18 * w + 36 * v) _ (by rw [add3 3 18 0 32 18 36 w v] <;> rfl))
  have e4 : ((31 + 36 * w + 30 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (30 + 0 * w + 36 * v) :=
    modv _ _ (25 + 36 * w + 30 * v) _ (by rw [quad 31 36 30 30 36 36 w v, quad 25 36 30 36 36 36 w v, add6 30 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (5 + 36 * w + 0 * v) _ (by rw [add3 30 0 36 5 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 31 36 30 7 12 6 19 24 18 3 18 0 30 0 36 w v] <;> rfl

theorem hstrip_5_0 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (5 + 6 * w + 0 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((5 + 6 * w + 0 * v) * 1) % (36 + 36 * w + 36 * v) + (((5 + 6 * w + 0 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((5 + 6 * w + 0 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((5 + 6 * w + 0 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((5 + 6 * w + 0 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((5 + 6 * w + 0 * v) * 1) % (36 + 36 * w + 36 * v) = (5 + 6 * w + 0 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 5 6 0 w v, quad 0 0 0 36 36 36 w v, add6 5 6 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (30 + 30 * w + 36 * v) _ (by rw [add3 5 6 0 30 30 36 w v] <;> rfl))
  have e1 : ((5 + 6 * w + 0 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (29 + 30 * w + 24 * v) :=
    modv _ _ (1 + 2 * w + 0 * v) _ (by rw [quad 5 6 0 13 12 12 w v, quad 1 2 0 36 36 36 w v, add6 29 30 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (6 + 6 * w + 12 * v) _ (by rw [add3 29 30 24 6 6 12 w v] <;> rfl))
  have e2 : ((5 + 6 * w + 0 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (17 + 18 * w + 12 * v) :=
    modv _ _ (3 + 4 * w + 0 * v) _ (by rw [quad 5 6 0 25 24 24 w v, quad 3 4 0 36 36 36 w v, add6 17 18 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (18 + 18 * w + 24 * v) _ (by rw [add3 17 18 12 18 18 24 w v] <;> rfl))
  have e3 : ((5 + 6 * w + 0 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (33 + 36 * w + 18 * v) :=
    modv _ _ (2 + 3 * w + 0 * v) _ (by rw [quad 5 6 0 21 18 18 w v, quad 2 3 0 36 36 36 w v, add6 33 36 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (2 + 0 * w + 18 * v) _ (by rw [add3 33 36 18 2 0 18 w v] <;> rfl))
  have e4 : ((5 + 6 * w + 0 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (6 + 0 * w + 36 * v) :=
    modv _ _ (4 + 6 * w + 0 * v) _ (by rw [quad 5 6 0 30 36 36 w v, quad 4 6 0 36 36 36 w v, add6 6 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (29 + 36 * w + 0 * v) _ (by rw [add3 6 0 36 29 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 5 6 0 29 30 24 17 18 12 33 36 18 6 0 36 w v] <;> rfl

theorem hstrip_5_1 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (11 + 12 * w + 6 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((11 + 12 * w + 6 * v) * 1) % (36 + 36 * w + 36 * v) + (((11 + 12 * w + 6 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((11 + 12 * w + 6 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((11 + 12 * w + 6 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((11 + 12 * w + 6 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90 * v
  have e0 : ((11 + 12 * w + 6 * v) * 1) % (36 + 36 * w + 36 * v) = (11 + 12 * w + 6 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 11 12 6 w v, quad 0 0 0 36 36 36 w v, add6 11 12 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (24 + 24 * w + 30 * v) _ (by rw [add3 11 12 6 24 24 30 w v] <;> rfl))
  have e1 : ((11 + 12 * w + 6 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (35 + 36 * w + 30 * v) :=
    modv _ _ (3 + 4 * w + 2 * v) _ (by rw [quad 11 12 6 13 12 12 w v, quad 3 4 2 36 36 36 w v, add6 35 36 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (0 + 0 * w + 6 * v) _ (by rw [add3 35 36 30 0 0 6 w v] <;> rfl))
  have e2 : ((11 + 12 * w + 6 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (23 + 24 * w + 18 * v) :=
    modv _ _ (7 + 8 * w + 4 * v) _ (by rw [quad 11 12 6 25 24 24 w v, quad 7 8 4 36 36 36 w v, add6 23 24 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (12 + 12 * w + 18 * v) _ (by rw [add3 23 24 18 12 12 18 w v] <;> rfl))
  have e3 : ((11 + 12 * w + 6 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (15 + 18 * w + 0 * v) :=
    modv _ _ (6 + 6 * w + 3 * v) _ (by rw [quad 11 12 6 21 18 18 w v, quad 6 6 3 36 36 36 w v, add6 15 18 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (20 + 18 * w + 36 * v) _ (by rw [add3 15 18 0 20 18 36 w v] <;> rfl))
  have e4 : ((11 + 12 * w + 6 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (6 + 0 * w + 36 * v) :=
    modv _ _ (9 + 12 * w + 6 * v) _ (by rw [quad 11 12 6 30 36 36 w v, quad 9 12 6 36 36 36 w v, add6 6 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (29 + 36 * w + 0 * v) _ (by rw [add3 6 0 36 29 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 11 12 6 35 36 30 23 24 18 15 18 0 6 0 36 w v] <;> rfl

theorem hstrip_5_2 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (17 + 18 * w + 12 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((17 + 18 * w + 12 * v) * 1) % (36 + 36 * w + 36 * v) + (((17 + 18 * w + 12 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((17 + 18 * w + 12 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((17 + 18 * w + 12 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((17 + 18 * w + 12 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90   -- (+3 chars; full line in the Zenodo source)
  have e0 : ((17 + 18 * w + 12 * v) * 1) % (36 + 36 * w + 36 * v) = (17 + 18 * w + 12 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 17 18 12 w v, quad 0 0 0 36 36 36 w v, add6 17 18 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (18 + 18 * w + 24 * v) _ (by rw [add3 17 18 12 18 18 24 w v] <;> rfl))
  have e1 : ((17 + 18 * w + 12 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (5 + 6 * w + 0 * v) :=
    modv _ _ (6 + 6 * w + 4 * v) _ (by rw [quad 17 18 12 13 12 12 w v, quad 6 6 4 36 36 36 w v, add6 5 6 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (30 + 30 * w + 36 * v) _ (by rw [add3 5 6 0 30 30 36 w v] <;> rfl))
  have e2 : ((17 + 18 * w + 12 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (29 + 30 * w + 24 * v) :=
    modv _ _ (11 + 12 * w + 8 * v) _ (by rw [quad 17 18 12 25 24 24 w v, quad 11 12 8 36 36 36 w v, add6 29 30 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (6 + 6 * w + 12 * v) _ (by rw [add3 29 30 24 6 6 12 w v] <;> rfl))
  have e3 : ((17 + 18 * w + 12 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (33 + 36 * w + 18 * v) :=
    modv _ _ (9 + 9 * w + 6 * v) _ (by rw [quad 17 18 12 21 18 18 w v, quad 9 9 6 36 36 36 w v, add6 33 36 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (2 + 0 * w + 18 * v) _ (by rw [add3 33 36 18 2 0 18 w v] <;> rfl))
  have e4 : ((17 + 18 * w + 12 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (6 + 0 * w + 36 * v) :=
    modv _ _ (14 + 18 * w + 12 * v) _ (by rw [quad 17 18 12 30 36 36 w v, quad 14 18 12 36 36 36 w v, add6 6 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (29 + 36 * w + 0 * v) _ (by rw [add3 6 0 36 29 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 17 18 12 5 6 0 29 30 24 33 36 18 6 0 36 w v] <;> rfl

theorem hstrip_5_3 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (23 + 24 * w + 18 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((23 + 24 * w + 18 * v) * 1) % (36 + 36 * w + 36 * v) + (((23 + 24 * w + 18 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((23 + 24 * w + 18 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((23 + 24 * w + 18 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((23 + 24 * w + 18 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90   -- (+3 chars; full line in the Zenodo source)
  have e0 : ((23 + 24 * w + 18 * v) * 1) % (36 + 36 * w + 36 * v) = (23 + 24 * w + 18 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 23 24 18 w v, quad 0 0 0 36 36 36 w v, add6 23 24 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (12 + 12 * w + 18 * v) _ (by rw [add3 23 24 18 12 12 18 w v] <;> rfl))
  have e1 : ((23 + 24 * w + 18 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (11 + 12 * w + 6 * v) :=
    modv _ _ (8 + 8 * w + 6 * v) _ (by rw [quad 23 24 18 13 12 12 w v, quad 8 8 6 36 36 36 w v, add6 11 12 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (24 + 24 * w + 30 * v) _ (by rw [add3 11 12 6 24 24 30 w v] <;> rfl))
  have e2 : ((23 + 24 * w + 18 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (35 + 36 * w + 30 * v) :=
    modv _ _ (15 + 16 * w + 12 * v) _ (by rw [quad 23 24 18 25 24 24 w v, quad 15 16 12 36 36 36 w v, add6 35 36 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (0 + 0 * w + 6 * v) _ (by rw [add3 35 36 30 0 0 6 w v] <;> rfl))
  have e3 : ((23 + 24 * w + 18 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (15 + 18 * w + 0 * v) :=
    modv _ _ (13 + 12 * w + 9 * v) _ (by rw [quad 23 24 18 21 18 18 w v, quad 13 12 9 36 36 36 w v, add6 15 18 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (20 + 18 * w + 36 * v) _ (by rw [add3 15 18 0 20 18 36 w v] <;> rfl))
  have e4 : ((23 + 24 * w + 18 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (6 + 0 * w + 36 * v) :=
    modv _ _ (19 + 24 * w + 18 * v) _ (by rw [quad 23 24 18 30 36 36 w v, quad 19 24 18 36 36 36 w v, add6 6 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (29 + 36 * w + 0 * v) _ (by rw [add3 6 0 36 29 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 23 24 18 11 12 6 35 36 30 15 18 0 6 0 36 w v] <;> rfl

theorem hstrip_5_4 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (29 + 30 * w + 24 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((29 + 30 * w + 24 * v) * 1) % (36 + 36 * w + 36 * v) + (((29 + 30 * w + 24 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((29 + 30 * w + 24 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((29 + 30 * w + 24 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((29 + 30 * w + 24 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90   -- (+3 chars; full line in the Zenodo source)
  have e0 : ((29 + 30 * w + 24 * v) * 1) % (36 + 36 * w + 36 * v) = (29 + 30 * w + 24 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 29 30 24 w v, quad 0 0 0 36 36 36 w v, add6 29 30 24 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (6 + 6 * w + 12 * v) _ (by rw [add3 29 30 24 6 6 12 w v] <;> rfl))
  have e1 : ((29 + 30 * w + 24 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (17 + 18 * w + 12 * v) :=
    modv _ _ (10 + 10 * w + 8 * v) _ (by rw [quad 29 30 24 13 12 12 w v, quad 10 10 8 36 36 36 w v, add6 17 18 12 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (18 + 18 * w + 24 * v) _ (by rw [add3 17 18 12 18 18 24 w v] <;> rfl))
  have e2 : ((29 + 30 * w + 24 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (5 + 6 * w + 0 * v) :=
    modv _ _ (20 + 20 * w + 16 * v) _ (by rw [quad 29 30 24 25 24 24 w v, quad 20 20 16 36 36 36 w v, add6 5 6 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (30 + 30 * w + 36 * v) _ (by rw [add3 5 6 0 30 30 36 w v] <;> rfl))
  have e3 : ((29 + 30 * w + 24 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (33 + 36 * w + 18 * v) :=
    modv _ _ (16 + 15 * w + 12 * v) _ (by rw [quad 29 30 24 21 18 18 w v, quad 16 15 12 36 36 36 w v, add6 33 36 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (2 + 0 * w + 18 * v) _ (by rw [add3 33 36 18 2 0 18 w v] <;> rfl))
  have e4 : ((29 + 30 * w + 24 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (6 + 0 * w + 36 * v) :=
    modv _ _ (24 + 30 * w + 24 * v) _ (by rw [quad 29 30 24 30 36 36 w v, quad 24 30 24 36 36 36 w v, add6 6 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (29 + 36 * w + 0 * v) _ (by rw [add3 6 0 36 29 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 29 30 24 17 18 12 5 6 0 33 36 18 6 0 36 w v] <;> rfl

theorem hstrip_5_5 (w v : Nat) :
    tsum (36 + 36 * w + 36 * v) (35 + 36 * w + 30 * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v := by
  show ((35 + 36 * w + 30 * v) * 1) % (36 + 36 * w + 36 * v) + (((35 + 36 * w + 30 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) + (((35 + 36 * w + 30 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) + (((35 + 36 * w + 30 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) + (((35 + 36 * w + 30 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) + 0)))) = 90 + 90 * w + 90   -- (+3 chars; full line in the Zenodo source)
  have e0 : ((35 + 36 * w + 30 * v) * 1) % (36 + 36 * w + 36 * v) = (35 + 36 * w + 30 * v) :=
    modv _ _ (0 + 0 * w + 0 * v) _ (by rw [lin1 35 36 30 w v, quad 0 0 0 36 36 36 w v, add6 35 36 30 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (0 + 0 * w + 6 * v) _ (by rw [add3 35 36 30 0 0 6 w v] <;> rfl))
  have e1 : ((35 + 36 * w + 30 * v) * (13 + 12 * w + 12 * v)) % (36 + 36 * w + 36 * v) = (23 + 24 * w + 18 * v) :=
    modv _ _ (12 + 12 * w + 10 * v) _ (by rw [quad 35 36 30 13 12 12 w v, quad 12 12 10 36 36 36 w v, add6 23 24 18 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (12 + 12 * w + 18 * v) _ (by rw [add3 23 24 18 12 12 18 w v] <;> rfl))
  have e2 : ((35 + 36 * w + 30 * v) * (25 + 24 * w + 24 * v)) % (36 + 36 * w + 36 * v) = (11 + 12 * w + 6 * v) :=
    modv _ _ (24 + 24 * w + 20 * v) _ (by rw [quad 35 36 30 25 24 24 w v, quad 24 24 20 36 36 36 w v, add6 11 12 6 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (24 + 24 * w + 30 * v) _ (by rw [add3 11 12 6 24 24 30 w v] <;> rfl))
  have e3 : ((35 + 36 * w + 30 * v) * (21 + 18 * w + 18 * v)) % (36 + 36 * w + 36 * v) = (15 + 18 * w + 0 * v) :=
    modv _ _ (20 + 18 * w + 15 * v) _ (by rw [quad 35 36 30 21 18 18 w v, quad 20 18 15 36 36 36 w v, add6 15 18 0 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (20 + 18 * w + 36 * v) _ (by rw [add3 15 18 0 20 18 36 w v] <;> rfl))
  have e4 : ((35 + 36 * w + 30 * v) * (30 + 36 * w + 36 * v)) % (36 + 36 * w + 36 * v) = (6 + 0 * w + 36 * v) :=
    modv _ _ (29 + 36 * w + 30 * v) _ (by rw [quad 35 36 30 30 36 36 w v, quad 29 36 30 36 36 36 w v, add6 6 0 36 _ _ _ _ _ _ w v] <;> rfl)
      (lt_of_add _ (29 + 36 * w + 0 * v) _ (by rw [add3 6 0 36 29 36 0 w v] <;> rfl))
  rw [e0, e1, e2, e3, e4, sum5 35 36 30 23 24 18 11 12 6 15 18 0 6 0 36 w v] <;> rfl

/-- the general cover: a unit t of 36K reduces to τ = ρ + 6(w + K·a), ρ ∈ {1, 5}, a < 6, K = w + v + 1. -/
theorem cover (F : Nat → List Nat)
    (hgood : ∀ ρ a w v, (ρ = 1 ∨ ρ = 5) → a < 6 →
      tsum (36 * (w + v + 1)) (ρ + 6 * (w + (w + v + 1) * a)) (F (w + v + 1)) = 90 * (w + v + 1))
    (K t : Nat) (hK : 0 < K) (hg : Nat.gcd t (36 * K) = 1) : tsum (36 * K) t (F K) = 90 * K := by
  have hm : 0 < 36 * K := Nat.mul_pos (Nat.succ_pos 35) hK
  obtain ⟨Q, hQ⟩ := div_mod (36 * K) hm (t + 1) t (Nat.lt_succ_self t)
  have hτ : t % (36 * K) < 36 * K := Nat.mod_lt t hm
  generalize t % (36 * K) = τ at hQ hτ
  subst hQ
  rw [tsum_shift (36 * K) τ Q hm]
  obtain ⟨s, hs⟩ := div_mod 6 (Nat.succ_pos 5) (τ + 1) τ (Nat.lt_succ_self τ)
  have hρ : τ % 6 < 6 := Nat.mod_lt τ (Nat.succ_pos 5)
  generalize τ % 6 = ρ at hs hρ
  subst hs
  obtain ⟨a, ha⟩ := div_mod K hK (s + 1) s (Nat.lt_succ_self s)
  have hw : s % K < K := Nat.mod_lt s hK
  generalize s % K = w at ha hw
  subst ha
  have ha6 : a < 6 := a_lt ρ w K a hτ
  obtain ⟨v, hv⟩ := lt_dest w K hw
  subst hv
  rcases lt6 ρ hρ with h | h | h | h | h | h <;> subst h
  · exact (bad 2 _ _ (3 * (w + (w + v + 1) * a) + 18 * (w + v + 1) * Q) (18 * (w + v + 1)) (Nat.le_refl 2)
      (by lib_nat) (by lib_nat) hg).elim
  · exact hgood 1 a w v (Or.inl rfl) ha6
  · exact (bad 2 _ _ (1 + 3 * (w + (w + v + 1) * a) + 18 * (w + v + 1) * Q) (18 * (w + v + 1)) (Nat.le_refl 2)
      (by lib_nat) (by lib_nat) hg).elim
  · exact (bad 3 _ _ (1 + 2 * (w + (w + v + 1) * a) + 12 * (w + v + 1) * Q) (12 * (w + v + 1)) (Nat.le_succ 2)
      (by lib_nat) (by lib_nat) hg).elim
  · exact (bad 2 _ _ (2 + 3 * (w + (w + v + 1) * a) + 18 * (w + v + 1) * Q) (18 * (w + v + 1)) (Nat.le_refl 2)
      (by lib_nat) (by lib_nat) hg).elim
  · exact hgood 5 a w v (Or.inr rfl) ha6

theorem gstep (ρ j w v : Nat)
    (hs : tsum (36 + 36 * w + 36 * v) ((6 * j + ρ) + (6 * j + 6) * w + (6 * j) * v) [1, (5 + 6 * w + 6 * v), (25 + 24 * w + 24 * v), (26 + 24 * w + 24 * v), (33 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v) :
    tsum (36 * (w + v + 1)) (ρ + 6 * (w + (w + v + 1) * j)) (G (w + v + 1)) = 90 * (w + v + 1) := by
  rw [show 36 * (w + v + 1) = 36 + 36 * w + 36 * v by lib_nat,
    show ρ + 6 * (w + (w + v + 1) * j) = (6 * j + ρ) + (6 * j + 6) * w + (6 * j) * v by lib_nat, gX w v,
    show 90 * (w + v + 1) = 90 + 90 * w + 90 * v by lib_nat]
  exact hs

theorem ggood (ρ a w v : Nat) (hρ : ρ = 1 ∨ ρ = 5) (ha : a < 6) :
    tsum (36 * (w + v + 1)) (ρ + 6 * (w + (w + v + 1) * a)) (G (w + v + 1)) = 90 * (w + v + 1) := by
  rcases hρ with h | h <;> subst h <;> rcases lt6 a ha with h | h | h | h | h | h <;> subst h
  · exact gstep 1 0 w v (strip_1_0 w v)
  · exact gstep 1 1 w v (strip_1_1 w v)
  · exact gstep 1 2 w v (strip_1_2 w v)
  · exact gstep 1 3 w v (strip_1_3 w v)
  · exact gstep 1 4 w v (strip_1_4 w v)
  · exact gstep 1 5 w v (strip_1_5 w v)
  · exact gstep 5 0 w v (strip_5_0 w v)
  · exact gstep 5 1 w v (strip_5_1 w v)
  · exact gstep 5 2 w v (strip_5_2 w v)
  · exact gstep 5 3 w v (strip_5_3 w v)
  · exact gstep 5 4 w v (strip_5_4 w v)
  · exact gstep 5 5 w v (strip_5_5 w v)

/-- **G(36K) is balanced for every K ≥ 1.** -/
theorem g_bal (K : Nat) (hK : 0 < K) : bal (36 * K) (G K) = true := by
  unfold bal FermatPrime.units
  apply all_filter
  intro t ht
  have hg : Nat.gcd t (36 * K) = 1 := Nat.eq_of_beq_eq_true ht
  rw [cover G ggood K t hK hg]
  show Nat.beq (90 * K + 90 * K) (5 * (36 * K)) = true
  rw [show 5 * (36 * K) = 90 * K + 90 * K by lib_nat]
  exact beq_refl' _

theorem hstep (ρ j w v : Nat)
    (hs : tsum (36 + 36 * w + 36 * v) ((6 * j + ρ) + (6 * j + 6) * w + (6 * j) * v) [1, (13 + 12 * w + 12 * v), (25 + 24 * w + 24 * v), (21 + 18 * w + 18 * v), (30 + 36 * w + 36 * v)] = 90 + 90 * w + 90 * v) :
    tsum (36 * (w + v + 1)) (ρ + 6 * (w + (w + v + 1) * j)) (H (w + v + 1)) = 90 * (w + v + 1) := by
  rw [show 36 * (w + v + 1) = 36 + 36 * w + 36 * v by lib_nat,
    show ρ + 6 * (w + (w + v + 1) * j) = (6 * j + ρ) + (6 * j + 6) * w + (6 * j) * v by lib_nat, hX w v,
    show 90 * (w + v + 1) = 90 + 90 * w + 90 * v by lib_nat]
  exact hs

theorem hgood (ρ a w v : Nat) (hρ : ρ = 1 ∨ ρ = 5) (ha : a < 6) :
    tsum (36 * (w + v + 1)) (ρ + 6 * (w + (w + v + 1) * a)) (H (w + v + 1)) = 90 * (w + v + 1) := by
  rcases hρ with h | h <;> subst h <;> rcases lt6 a ha with h | h | h | h | h | h <;> subst h
  · exact hstep 1 0 w v (hstrip_1_0 w v)
  · exact hstep 1 1 w v (hstrip_1_1 w v)
  · exact hstep 1 2 w v (hstrip_1_2 w v)
  · exact hstep 1 3 w v (hstrip_1_3 w v)
  · exact hstep 1 4 w v (hstrip_1_4 w v)
  · exact hstep 1 5 w v (hstrip_1_5 w v)
  · exact hstep 5 0 w v (hstrip_5_0 w v)
  · exact hstep 5 1 w v (hstrip_5_1 w v)
  · exact hstep 5 2 w v (hstrip_5_2 w v)
  · exact hstep 5 3 w v (hstrip_5_3 w v)
  · exact hstep 5 4 w v (hstrip_5_4 w v)
  · exact hstep 5 5 w v (hstrip_5_5 w v)

/-- **H(36K) is balanced for every K ≥ 1.** -/
theorem h_bal (K : Nat) (hK : 0 < K) : bal (36 * K) (H K) = true := by
  unfold bal FermatPrime.units
  apply all_filter
  intro t ht
  have hg : Nat.gcd t (36 * K) = 1 := Nat.eq_of_beq_eq_true ht
  rw [cover H hgood K t hK hg]
  show Nat.beq (90 * K + 90 * K) (5 * (36 * K)) = true
  rw [show 5 * (36 * K) = 90 * K + 90 * K by lib_nat]
  exact beq_refl' _

theorem g_bal_7 : bal 252 (G 7) = true := g_bal 7 (Nat.succ_pos 6)

end SeedFamGHGen

#print axioms SeedFamGHGen.modv
#print axioms SeedFamGHGen.lt_of_add
#print axioms SeedFamGHGen.tsum_shift
#print axioms SeedFamGHGen.lt6
#print axioms SeedFamGHGen.a_lt
#print axioms SeedFamGHGen.bad
#print axioms SeedFamGHGen.lt_dest
#print axioms SeedFamGHGen.sub_eq
#print axioms SeedFamGHGen.quad
#print axioms SeedFamGHGen.lin1
#print axioms SeedFamGHGen.add6
#print axioms SeedFamGHGen.add3
#print axioms SeedFamGHGen.sum5
#print axioms SeedFamGHGen.gX
#print axioms SeedFamGHGen.hX
#print axioms SeedFamGHGen.strip_1_0
#print axioms SeedFamGHGen.strip_1_1
#print axioms SeedFamGHGen.strip_1_2
#print axioms SeedFamGHGen.strip_1_3
#print axioms SeedFamGHGen.strip_1_4
#print axioms SeedFamGHGen.strip_1_5
#print axioms SeedFamGHGen.strip_5_0
#print axioms SeedFamGHGen.strip_5_1
#print axioms SeedFamGHGen.strip_5_2
#print axioms SeedFamGHGen.strip_5_3
#print axioms SeedFamGHGen.strip_5_4
#print axioms SeedFamGHGen.strip_5_5
#print axioms SeedFamGHGen.hstrip_1_0
#print axioms SeedFamGHGen.hstrip_1_1
#print axioms SeedFamGHGen.hstrip_1_2
#print axioms SeedFamGHGen.hstrip_1_3
#print axioms SeedFamGHGen.hstrip_1_4
#print axioms SeedFamGHGen.hstrip_1_5
#print axioms SeedFamGHGen.hstrip_5_0
#print axioms SeedFamGHGen.hstrip_5_1
#print axioms SeedFamGHGen.hstrip_5_2
#print axioms SeedFamGHGen.hstrip_5_3
#print axioms SeedFamGHGen.hstrip_5_4
#print axioms SeedFamGHGen.hstrip_5_5
#print axioms SeedFamGHGen.cover
#print axioms SeedFamGHGen.gstep
#print axioms SeedFamGHGen.ggood
#print axioms SeedFamGHGen.g_bal
#print axioms SeedFamGHGen.hstep
#print axioms SeedFamGHGen.hgood
#print axioms SeedFamGHGen.h_bal
#print axioms SeedFamGHGen.g_bal_7

#print axioms: 47 theorems, no axioms.

81.234 The seed families \(G\), \(H\) for every \(k\)

\(G(36k)\) and \(H(36k)\) are balanced indecomposable seeds for every \(k\ge 1\). Combines the two previous listings.

hodge/SeedFamGHAll.lean

/-
  hodge/SeedFamGHAll.lean — T41 cycle 1914 (goal G864 closed): for every m = 36k (k ≥ 1) the seeds
    G(m) = {1, m/6 − 1, 2m/3 + 1, 2m/3 + 2, m − 3},   H(m) = {1, m/3 + 1, 2m/3 + 1, m/2 + 3, m − 6}
  are balanced and indecomposable: hodge/SeedFamGHGen (balance) and hodge/SeedFamGHIndec (indecomposability).
  Lean 4 core; no axioms.
-/
import hodge.SeedFamGHGen
import hodge.SeedFamGHIndec

namespace SeedFamGHAll
open Indecomp SeedFamGH

/-- **G(36k) is a balanced indecomposable seed for every k ≥ 1.** -/
theorem g_seed (k : Nat) (hk : 0 < k) : bal (36 * k) (G k) = true ∧ indec (36 * k) (G k) = true :=
  ⟨SeedFamGHGen.g_bal k hk, SeedFamGHIndec.g_indec k hk⟩

/-- **H(36k) is a balanced indecomposable seed for every k ≥ 1.** -/
theorem h_seed (k : Nat) (hk : 0 < k) : bal (36 * k) (H k) = true ∧ indec (36 * k) (H k) = true :=
  ⟨SeedFamGHGen.h_bal k hk, SeedFamGHIndec.h_indec k hk⟩

end SeedFamGHAll

#print axioms SeedFamGHAll.g_seed
#print axioms SeedFamGHAll.h_seed

#print axioms: 2 theorems, no axioms.

81.235 Coset units and the coset-averaged balance condition

For \(\rho \) prime to \(14\) the elements \(\rho +14j\), \(p\nmid \rho +14j\), are units of \(14p\). Averaging a balanced list over them gives \(2\sum _{x}\mathrm {omitR}(x)+|L|\cdot 14p=p\,|L|\cdot 14p\).

hodge/CosetUnit.lean

/-
  hodge/CosetUnit.lean — T41 cycle 1914 (goal G862c, step 2a): FamIndec2 for the coset ρ·H, ρ coprime to 14:
  for a prime p with gcd(14, p) = 1 and the unique j₀ < p with p ∣ ρ + 14j₀,
    idx_unique_r   p ∣ ρ + 14i, i < p  ⇒  i = j₀
    cop_coset_r    k < p, k ≠ j₀  ⇒  gcd(ρ + 14k, p) = 1
    dvd_one_of_r   d ∣ 14, d ∣ ρ + 14i, gcd(ρ, 14) = 1  ⇒  d = 1
    unit_tr        i < p, i ≠ j₀  ⇒  gcd(ρ + 14i, 14p) = 1
  so t_j = ρ + 14j (j ≠ j₀) are units of 14p, the summation range of CosetAvg.coset_omit.

  Lean 4 core plus hodge/FamIndec2; no axioms.
-/
import hodge.FamIndec2

namespace CosetUnit
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp FamIndec2

theorem idx_unique_r (p ρ i i0 : Nat) (hp : 0 < p) (h14 : Nat.gcd 14 p = 1) (hi : i < p) (hi0 : i0 < p)
    (h : p ∣ ρ + 14 * i) (h0 : p ∣ ρ + 14 * i0) : i = i0 := by
  have a := mod_zero p _ hp h
  have b := mod_zero p _ hp h0
  cases Nat.lt_or_ge i i0 with
  | inl hlt =>
    have ⟨d, hd⟩ := LibGcd.le_dest hlt
    -- i0 = (i + 1) + d
    exfalso
    apply inj_mod p 14 ρ i (d + 1) hp h14 (Nat.succ_pos d)
    · rw [show i + (d + 1) = i + 1 + d by lib_nat, ← hd]; exact hi0
    · rw [a, show i + (d + 1) = i + 1 + d by lib_nat, ← hd, b]
  | inr hge =>
    cases Nat.lt_or_ge i0 i with
    | inl hlt =>
      have ⟨d, hd⟩ := LibGcd.le_dest hlt
      exfalso
      apply inj_mod p 14 ρ i0 (d + 1) hp h14 (Nat.succ_pos d)
      · rw [show i0 + (d + 1) = i0 + 1 + d by lib_nat, ← hd]; exact hi
      · rw [b, show i0 + (d + 1) = i0 + 1 + d by lib_nat, ← hd, a]
    | inr hge' => exact Nat.le_antisymm hge' hge

theorem cop_coset_r (p ρ k i0 : Nat) (hp : 0 < p) (hpr : ∀ d, d ∣ p → d = 1 ∨ d = p) (h14 : Nat.gcd 14 p = 1)
    (hk : k < p) (hi0 : i0 < p) (h0 : p ∣ ρ + 14 * i0) (hne : k ≠ i0) : Nat.gcd (ρ + 14 * k) p = 1 := by
  apply FamIndec2.gcd_one_of
  intro d hd1 hd2
  cases hpr d hd2 with
  | inl e => exact e
  | inr e =>
    rw [e] at hd1
    exact absurd (idx_unique_r p ρ k i0 hp h14 hk hi0 hd1 h0) hne

theorem dvd_one_of_r (ρ d i : Nat) (hρ : Nat.gcd ρ 14 = 1) (h1 : d ∣ 14) (h2 : d ∣ ρ + 14 * i) : d = 1 := by
  have a := LibGcd.idv_lin (LibGcd.idv_of_nat h2) (LibGcd.idv_of_nat h1) 1 (-(Int.ofNat i))
  have e : (1 : Int) * Int.ofNat (ρ + 14 * i) + -(Int.ofNat i) * Int.ofNat 14 = Int.ofNat ρ := by
    show (1 : Int) * Int.ofNat (ρ + 14 * i) + -(Int.ofNat i) * Int.ofNat 14 = Int.ofNat ρ
    rw [show Int.ofNat (ρ + 14 * i) = Int.ofNat ρ + Int.ofNat 14 * Int.ofNat i from rfl]
    lib_int
  rw [e] at a
  have ⟨c, hc⟩ := LibGcd.idv_nat a
  have ⟨e1, he1⟩ := APPair1.dvd_gcd d ρ 14 ⟨c, hc⟩ (let ⟨u, hu⟩ := h1; ⟨u, hu⟩)
  rw [hρ] at he1
  exact UnitMul.one_of_dvd_one d e1 he1

theorem unit_tr (p ρ i i0 : Nat) (hρ : Nat.gcd ρ 14 = 1) (hp : 0 < p) (hpr : ∀ d, d ∣ p → d = 1 ∨ d = p) (h14 : Nat.gcd 14 p = 1)
    (hi : i < p) (hi0 : i0 < p) (h0 : p ∣ ρ + 14 * i0) (hne : i ≠ i0) : Nat.gcd (ρ + 14 * i) (14 * p) = 1 := by
  apply FamIndec2.gcd_one_of
  intro d hd1 hd2
  -- q = gcd d p is 1 or p
  have ⟨⟨a, ha⟩, ⟨b, hb⟩⟩ := UnitMul.gcd_dvd d p
  cases hpr (Nat.gcd d p) ⟨b, hb⟩ with
  | inr e =>
    rw [e] at ha
    exact absurd (idx_unique_r p ρ i i0 hp h14 hi hi0 (LibGcd.dvd_trans' ⟨a, ha⟩ hd1) h0) hne
  | inl e =>
    have hc : ∀ f, f ∣ d → f ∣ p → f = 1 := by
      intro f hf1 hf2
      have ⟨c, hc⟩ := APPair1.dvd_gcd f d p (let ⟨u, hu⟩ := hf1; ⟨u, hu⟩) (let ⟨u, hu⟩ := hf2; ⟨u, hu⟩)
      rw [e] at hc
      exact UnitMul.one_of_dvd_one f c hc
    have h14d : d ∣ 14 := LibGcd.gauss hc (by rw [show 14 * p = 14 * p from rfl]; exact hd2)
    exact dvd_one_of_r ρ d i hρ h14d hd1

end CosetUnit

#print axioms CosetUnit.idx_unique_r
#print axioms CosetUnit.cop_coset_r
#print axioms CosetUnit.dvd_one_of_r
#print axioms CosetUnit.unit_tr

#print axioms: 4 theorems, no axioms.

hodge/CosetBal.lean

/-
  hodge/CosetBal.lean — T41 cycle 1914 (goal G862c, step 2b): averaging the balance condition of any balanced list L
  at 14p over the coset units t_j = ρ + 14j (j ≠ j₀, ρ coprime to 14, ρ < 14, p prime with gcd(14, p) = 1):
    coset_bal   2·Σ_{x∈L} omitR(p, ρ, j₀, x) + |L|·14p = p·|L|·14p
  (CosetAvg.omitR is the sum over j ≠ j₀ of ⟨(ρ + 14j)x⟩_{14p}). With CosetAvg.coset_omit / coset_omit_div each
  omitR is a residue mod 14, so this is the coset-averaged condition of HODGE_LOG cycle 1914 (G862b).

  Lean 4 core plus hodge/FamIndec3 (swap, gs lemmas, bal_unit), hodge/CosetAvg, hodge/CosetUnit; no axioms.
-/
import hodge.FamIndec3
import hodge.CosetAvg
import hodge.CosetUnit

namespace CosetBal
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp FamIndec3 FamBal CosetAvg CosetUnit QFamPrime

theorem coset_bal (p ρ j0 : Nat) (hp : 0 < p) (hpr : ∀ d, d ∣ p → d = 1 ∨ d = p) (h14 : Nat.gcd 14 p = 1)
    (hρ14 : Nat.gcd ρ 14 = 1) (hρ : ρ < 14) (hj : j0 < p) (h0 : p ∣ ρ + 14 * j0) (L : List Nat)
    (hb : bal (14 * p) L = true) :
    gs (fun x => omitR p ρ j0 x) L + gs (fun x => omitR p ρ j0 x) L + L.length * (14 * p) = p * (L.length * (14 * p)) := by
  have hne_i : ∀ i, Nat.beq i j0 = false ↔ i ≠ j0 := by
    intro i
    constructor
    · intro h e; rw [e, beq_refl'] at h; exact nomatch h
    · intro h
      cases e : Nat.beq i j0 with
      | false => rfl
      | true => exact absurd (Nat.eq_of_beq_eq_true e) h
  have E1 : sumF (fun i => if Nat.beq i j0 = true then 0 else tsum (14 * p) (ρ + 14 * i) L + tsum (14 * p) (ρ + 14 * i) L) p
      + L.length * (14 * p) = p * (L.length * (14 * p)) := by
    have c1 : sumF (fun i => if Nat.beq i j0 = true then 0 else tsum (14 * p) (ρ + 14 * i) L + tsum (14 * p) (ρ + 14 * i) L) p
        = sumF (fun i => if Nat.beq i j0 = true then 0 else L.length * (14 * p)) p := by
      apply sumF_congr_lt; intro i hip
      cases e : Nat.beq i j0 with
      | true => rfl
      | false =>
        show tsum (14 * p) (ρ + 14 * i) L + tsum (14 * p) (ρ + 14 * i) L = L.length * (14 * p)
        have hlt : ρ + 14 * i < 14 * p := by
          have h1 : ρ + 14 * i < 14 + 14 * i := Nat.add_lt_add_right hρ _
          have h2 : 14 + 14 * i ≤ 14 * p := by
            have : 14 * (i + 1) ≤ 14 * p := Nat.mul_le_mul_left 14 hip
            rw [show 14 * (i + 1) = 14 + 14 * i by lib_nat] at this; exact this
          exact Nat.lt_of_lt_of_le h1 h2
        exact bal_unit _ _ L hb hlt (unit_tr p ρ i j0 hρ14 hp hpr h14 hip hj h0 ((hne_i i).1 e))
    have r := sumF_replace (fun i => if Nat.beq i j0 = true then 0 else L.length * (14 * p)) (fun _ => L.length * (14 * p)) j0
      (fun k hk => by
        show (if Nat.beq k j0 = true then 0 else _) = _
        rw [(hne_i k).2 hk]; rfl) p hj
    have r' : sumF (fun i => if Nat.beq i j0 = true then 0 else L.length * (14 * p)) p + L.length * (14 * p)
        = sumF (fun _ => L.length * (14 * p)) p + (if Nat.beq j0 j0 = true then 0 else L.length * (14 * p)) := r
    rw [beq_refl'] at r'
    rw [c1, r', sumF_const]; rfl
  have sw : sumF (fun i => if Nat.beq i j0 = true then 0 else tsum (14 * p) (ρ + 14 * i) L) p
      = gs (fun x => omitR p ρ j0 x) L := by
    show _ = gs (fun x => sumF (fun j => if Nat.beq j j0 = true then 0 else ((ρ + 14 * j) * x) % (14 * p)) p) L
    rw [← swap]
    apply sumF_congr; intro i
    rw [tsum_gs, gs_ite]
  have hsplit : sumF (fun i => if Nat.beq i j0 = true then 0 else tsum (14 * p) (ρ + 14 * i) L + tsum (14 * p) (ρ + 14 * i) L) p
      = sumF (fun i => if Nat.beq i j0 = true then 0 else tsum (14 * p) (ρ + 14 * i) L) p
        + sumF (fun i => if Nat.beq i j0 = true then 0 else tsum (14 * p) (ρ + 14 * i) L) p := by
    rw [← sumF_add]; apply sumF_congr; intro i; exact ite_two _ _
  rw [hsplit, sw] at E1
  exact E1

end CosetBal

#print axioms CosetBal.coset_bal

#print axioms: 1 theorem, no axioms.

81.236 Coset deviations

On a balanced list the coset-averaged condition is \(\sum _x f(x)=0\), with \(f(c)=\langle \rho c\rangle _{14}-\langle yc\rangle _{14}\) for \(p\nmid c\). For \(c=pe\), \(f(c)=(p-1)(\langle \rho e\rangle _{14}-7)\).

hodge/CosetDev.lean

/-
  hodge/CosetDev.lean — T41 cycle 1930 (goal G862c, step 3a): the coset-averaged balance condition as a sum of
  per-element deviations in Int. For ρ + 14j₀ = p·y (j₀ < p) and S = Σ_{i<p} i:
    dev_unit   gcd(c, p) = 1:  omitR(c) = 14S + p·(⟨ρc⟩_14 − ⟨yc⟩_14)
    dev_div    c = p·e:        omitR(c) = 14S + p·((p − 1)(⟨ρe⟩_14 − 7))
    part_zero  L balanced at 14p (coset units of CosetBal) and omitR(x) = 14S + p·f(x) on L  ⇒  Σ_{x∈L} f(x) = 0
  int_cancel: k > 0, k·z = 0 ⇒ z = 0 (hand proof on the constructors of Int).

  Lean 4 core plus hodge/CosetBal, lib/IntRing (lib_int); no axioms.
-/
import hodge.CosetBal
import lib.IntRing

namespace CosetDev
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp FamIndec3 FamBal CosetAvg CosetUnit CosetBal QFamPrime

theorem int_cancel (k : Nat) (z : Int) (hk : 0 < k) (h : (k : Int) * z = 0) : z = 0 := by
  cases k with
  | zero => exact absurd hk (Nat.lt_irrefl 0)
  | succ k =>
    cases z with
    | ofNat n =>
      cases n with
      | zero => rfl
      | succ n =>
        have h' : Int.ofNat ((k + 1) * (n + 1)) = Int.ofNat 0 := h
        have h'' : (k + 1) * (n + 1) = 0 := Int.ofNat.inj h'
        rw [show (k + 1) * (n + 1) = ((k + 1) * n + k) + 1 by lib_nat] at h''
        exact Nat.noConfusion h''
    | negSucc n =>
      have h' : Int.negOfNat ((k + 1) * (n + 1)) = Int.ofNat 0 := h
      rw [show (k + 1) * (n + 1) = ((k + 1) * n + k) + 1 by lib_nat] at h'
      exact Int.noConfusion h'

/-- Int-valued list sum -/
def gsI (f : Nat → Int) : List Nat → Int
  | [] => 0
  | x :: l => f x + gsI f l

theorem gs_cast (g : Nat → Nat) : ∀ L : List Nat, ((gs g L : Nat) : Int) = gsI (fun x => (g x : Int)) L
  | [] => rfl
  | x :: L => by
    show Int.ofNat (g x + gs g L) = (g x : Int) + gsI (fun x => (g x : Int)) L
    rw [← gs_cast g L]; rfl

theorem gsI_affine (g : Nat → Int) (f : Nat → Int) (a b : Int) :
    ∀ L : List Nat, (∀ x, x ∈ L → g x = a + b * f x) → gsI g L = (L.length : Int) * a + b * gsI f L
  | [], _ => by show (0 : Int) = 0 * a + b * 0; lib_int
  | x :: L, h => by
    show g x + gsI g L = (((L.length + 1 : Nat)) : Int) * a + b * (f x + gsI f L)
    rw [h x (List.Mem.head _), gsI_affine g f a b L (fun y hy => h y (List.Mem.tail _ hy))]
    show a + b * f x + ((L.length : Int) * a + b * gsI f L) = ((L.length : Int) + 1) * a + b * (f x + gsI f L)
    lib_int

theorem sumS (p : Nat) : ((sumF (fun i => i) p : Nat) : Int) + (sumF (fun i => i) p : Nat) + (p : Int) = (p : Int) * p := by
  have h := congrArg Int.ofNat (sum_id p)
  exact h

theorem dev_unit (p ρ j0 y c : Nat) (hi : j0 < p) (ht : ρ + 14 * j0 = p * y) (hx : Nat.gcd c p = 1) :
    (omitR p ρ j0 c : Int) = 14 * (sumF (fun i => i) p : Nat) + (p : Int) * (((ρ * c) % 14 : Nat) - ((y * c) % 14 : Nat)) := by
  have h := congrArg Int.ofNat (coset_omit p ρ j0 y c hi ht hx)
  have h' : (omitR p ρ j0 c : Int) + (p : Int) * ((y * c) % 14 : Nat)
      = (p : Int) * ((ρ * c) % 14 : Nat) + 14 * (sumF (fun i => i) p : Nat) := h
  generalize (omitR p ρ j0 c : Int) = O at h' ⊢
  generalize (((y * c) % 14 : Nat) : Int) = Y at h' ⊢
  generalize (((ρ * c) % 14 : Nat) : Int) = R at h' ⊢
  generalize ((sumF (fun i => i) p : Nat) : Int) = S at h' ⊢
  calc O = (O + p * Y) - p * Y := by lib_int
    _ = (p * R + 14 * S) - p * Y := by rw [h']
    _ = _ := by lib_int

theorem dev_div (p ρ j0 e : Nat) (hi : j0 < p) :
    (omitR p ρ j0 (p * e) : Int) = 14 * (sumF (fun i => i) p : Nat) + (p : Int) * (((p : Int) - 1) * (((ρ * e) % 14 : Nat) - 7)) := by
  have h := congrArg Int.ofNat (coset_omit_div p ρ j0 e hi)
  have h' : (omitR p ρ j0 (p * e) : Int) + (p : Int) * ((ρ * e) % 14 : Nat)
      = (p : Int) * ((p : Int) * ((ρ * e) % 14 : Nat)) := h
  have hS := sumS p
  generalize (omitR p ρ j0 (p * e) : Int) = O at h' ⊢
  generalize (((ρ * e) % 14 : Nat) : Int) = R at h' ⊢
  generalize ((sumF (fun i => i) p : Nat) : Int) = S at hS ⊢
  calc O = (O + p * R) - p * R := by lib_int
    _ = p * (p * R) - p * R := by rw [h']
    _ = 14 * S + p * ((p - 1) * (R - 7)) - 7 * ((S + S + p) - p * p) := by lib_int
    _ = 14 * S + p * ((p - 1) * (R - 7)) - 7 * ((p * p) - p * p) := by rw [hS]
    _ = _ := by lib_int

/-- **Coset-averaged balance as a sum of deviations.** -/
theorem part_zero (p ρ j0 : Nat) (hp : 0 < p) (hpr : ∀ d, d ∣ p → d = 1 ∨ d = p) (h14 : Nat.gcd 14 p = 1)
    (hρ14 : Nat.gcd ρ 14 = 1) (hρ : ρ < 14) (hj : j0 < p) (h0 : p ∣ ρ + 14 * j0) (L : List Nat)
    (hb : bal (14 * p) L = true) (f : Nat → Int)
    (hf : ∀ x, x ∈ L → (omitR p ρ j0 x : Int) = 14 * (sumF (fun i => i) p : Nat) + (p : Int) * f x) :
    gsI f L = 0 := by
  have h := congrArg Int.ofNat (coset_bal p ρ j0 hp hpr h14 hρ14 hρ hj h0 L hb)
  have h' : ((gs (fun x => omitR p ρ j0 x) L : Nat) : Int) + ((gs (fun x => omitR p ρ j0 x) L : Nat) : Int)
      + (L.length : Int) * (14 * p) = (p : Int) * ((L.length : Int) * (14 * p)) := h
  rw [gs_cast, gsI_affine _ f (14 * (sumF (fun i => i) p : Nat)) (p : Int) L hf] at h'
  have hS := sumS p
  apply int_cancel (2 * p) _ (Nat.mul_pos (Nat.succ_pos 1) hp)
  generalize gsI f L = F at h' ⊢
  generalize ((sumF (fun i => i) p : Nat) : Int) = S at h' hS
  generalize (L.length : Int) = n at h'
  show (2 : Int) * p * F = 0
  calc (2 : Int) * p * F
      = ((n * (14 * S) + p * F) + (n * (14 * S) + p * F) + n * (14 * p)) - 14 * n * (S + S + p) := by lib_int
    _ = p * (n * (14 * p)) - 14 * n * (S + S + p) := by rw [h']
    _ = p * (n * (14 * p)) - 14 * n * (p * p) := by rw [hS]
    _ = 0 := by lib_int

end CosetDev

#print axioms CosetDev.int_cancel
#print axioms CosetDev.gs_cast
#print axioms CosetDev.gsI_affine
#print axioms CosetDev.sumS
#print axioms CosetDev.dev_unit
#print axioms CosetDev.dev_div
#print axioms CosetDev.part_zero

#print axioms: 7 theorems, no axioms.

81.237 The coset residue tables

Eliminating the weight \(W\) between the cosets \(\rho =1,3,5\) leaves finitely many residues of the completion element. Solutions: \((W,\gamma )\in \{(-1,1),(0,0),(0,7),(1,13)\}\), or \(c=pe\) with \(W\in \{0,\pm (p-1)\}\).

hodge/CosetElim.lean

/-
  hodge/CosetElim.lean — T41 cycle 1932 (goal G862c, step 3c): the finite residue tables. With D_ρ = ρ − ⟨ρu⟩_14
  (u = x₀ mod 14 ∈ {3, 5}) and a completion element c, the coset conditions for ρ = 1, 3, 5 read
    p ∤ c, γ = c mod 14:  W·D_ρ + (⟨ργ⟩ − ⟨ρuγ⟩) = 0
    c = p·e:              W·D_ρ + (p − 1)(⟨ρe⟩ − 7) = 0
  Eliminating W between two cosets leaves a condition on γ (resp. e) alone, checked case by case:
    elim_unit  (W, γ) ∈ {(−1, 1), (0, 0), (0, 7), (1, 13)}
    elim_div   (W, e) ∈ {(0, 7), (−(p − 1), e₋), (p − 1, e₊)}, (e₋, e₊) = (5, 9) for u = 3, (3, 11) for u = 5
  Generated by tools/mk_coset_elim.py. Lean 4 core plus hodge/CosetDev (int_cancel), lib/IntRing; no axioms.
-/
import hodge.CosetDev

namespace CosetElim
open CosetDev

def D (ρ u : Nat) : Int := (ρ : Int) - (((ρ * u) % 14 : Nat) : Int)
def F (ρ u g : Nat) : Int := (((ρ * g) % 14 : Nat) : Int) - (((ρ * u * g) % 14 : Nat) : Int)
def G (ρ e : Nat) : Int := (((ρ * e) % 14 : Nat) : Int) - 7

theorem elim2 (W a b x y : Int) (h1 : W * a + x = 0) (h2 : W * b + y = 0) : b * x - a * y = 0 := by
  calc b * x - a * y = b * (W * a + x) - a * (W * b + y) := by lib_int
    _ = b * 0 - a * 0 := by rw [h1, h2]
    _ = 0 := by lib_int

theorem elim2k (W a b x y : Int) (k : Nat) (hk : 0 < k) (h1 : W * a + (k : Int) * x = 0) (h2 : W * b + (k : Int) * y = 0) :
    b * x - a * y = 0 := by
  apply int_cancel k _ hk
  calc (k : Int) * (b * x - a * y) = b * (W * a + (k : Int) * x) - a * (W * b + (k : Int) * y) := by lib_int
    _ = b * 0 - a * 0 := by rw [h1, h2]
    _ = 0 := by lib_int

theorem ne_of_dec (a b : Int) (h : decide (a = b) = false) : a ≠ b := by
  intro e; rw [e] at h
  have : decide (b = b) = true := decide_eq_true rfl
  rw [this] at h; exact Bool.noConfusion h

/-- W·a + x = 0 and w₀·a + x = 0 with a·a = k·k, k > 0 give W = w₀ -/
theorem solve (W w0 a x : Int) (k : Nat) (hk : 0 < k) (ha : a * a = (k : Int) * k) (h : W * a + x = 0) (hw : w0 * a + x = 0) :
    W = w0 := by
  have e : (k * k : Nat) * (W - w0) = 0 := by
    show (k : Int) * k * (W - w0) = 0
    calc (k : Int) * k * (W - w0) = a * a * (W - w0) := by rw [ha]
      _ = a * ((W * a + x) - (w0 * a + x)) := by lib_int
      _ = a * (0 - 0) := by rw [h, hw]
      _ = 0 := by lib_int
  have := int_cancel (k * k) _ (Nat.mul_pos hk hk) e
  calc W = (W - w0) + w0 := by lib_int
    _ = 0 + w0 := by rw [this]
    _ = w0 := by lib_int

theorem solvek (W w0 a x : Int) (k m : Nat) (hk : 0 < k) (ha : a * a = (k : Int) * k)
    (h : W * a + (m : Int) * x = 0) (hw : w0 * a + (m : Int) * x = 0) : W = w0 :=
  solve W w0 a ((m : Int) * x) k hk ha h hw

theorem lt14 : ∀ g, g < 14 → g = 0 ∨ g = 1 ∨ g = 2 ∨ g = 3 ∨ g = 4 ∨ g = 5 ∨ g = 6 ∨ g = 7 ∨ g = 8 ∨ g = 9 ∨ g = 10 ∨ g = 11 ∨ g = 12 ∨ g = 13
  | 0, _ => Or.inl rfl
  | 1, _ => Or.inr (Or.inl rfl)
  | 2, _ => Or.inr (Or.inr (Or.inl rfl))
  | 3, _ => Or.inr (Or.inr (Or.inr (Or.inl rfl)))
  | 4, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))
  | 5, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))
  | 6, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))
  | 7, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))
  | 8, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))
  | 9, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))))
  | 10, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))))
  | 11, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl)))))))))))
  | 12, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inl rfl))))))))))))
  | 13, _ => Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr (Or.inr rfl))))))))))))
  | n + 14, h => absurd h (fun h' => Nat.lt_irrefl 14 (Nat.lt_of_le_of_lt (Nat.le_add_left 14 n) h'))


theorem elim_unit3 (g : Nat) (hg : g < 14) (W : Int)
    (h1 : W * D 1 3 + F 1 3 g = 0) (h3 : W * D 3 3 + F 3 3 g = 0) (h5 : W * D 5 3 + F 5 3 g = 0) :
    (W = -1 ∧ g = 1) ∨ (W = 0 ∧ (g = 0 ∨ g = 7)) ∨ (W = 1 ∧ g = 13) := by
  rcases lt14 g hg with h | h | h | h | h | h | h | h | h | h | h | h | h | h <;> subst h
  · exact Or.inr (Or.inl ⟨solve W (0) (D 1 3) (F 1 3 0) 2 (Nat.succ_pos 1) rfl h1 rfl, Or.inl rfl⟩)
  · exact Or.inl ⟨solve W (-1) (D 1 3) (F 1 3 1) 2 (Nat.succ_pos 1) rfl h1 rfl, rfl⟩
  · exact absurd (elim2 W (D 1 3) (D 3 3) (F 1 3 2) (F 3 3 2) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 3) (D 3 3) (F 1 3 3) (F 3 3 3) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 3) (D 3 3) (F 1 3 4) (F 3 3 4) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 3) (D 3 3) (F 1 3 5) (F 3 3 5) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 3) (D 3 3) (F 1 3 6) (F 3 3 6) h1 h3) (ne_of_dec _ _ rfl)
  · exact Or.inr (Or.inl ⟨solve W (0) (D 1 3) (F 1 3 7) 2 (Nat.succ_pos 1) rfl h1 rfl, Or.inr rfl⟩)
  · exact absurd (elim2 W (D 1 3) (D 3 3) (F 1 3 8) (F 3 3 8) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 3) (D 3 3) (F 1 3 9) (F 3 3 9) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 3) (D 3 3) (F 1 3 10) (F 3 3 10) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 3) (D 3 3) (F 1 3 11) (F 3 3 11) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 3) (D 3 3) (F 1 3 12) (F 3 3 12) h1 h3) (ne_of_dec _ _ rfl)
  · exact Or.inr (Or.inr ⟨solve W (1) (D 1 3) (F 1 3 13) 2 (Nat.succ_pos 1) rfl h1 rfl, rfl⟩)

theorem elim_unit5 (g : Nat) (hg : g < 14) (W : Int)
    (h1 : W * D 1 5 + F 1 5 g = 0) (h3 : W * D 3 5 + F 3 5 g = 0) (h5 : W * D 5 5 + F 5 5 g = 0) :
    (W = -1 ∧ g = 1) ∨ (W = 0 ∧ (g = 0 ∨ g = 7)) ∨ (W = 1 ∧ g = 13) := by
  rcases lt14 g hg with h | h | h | h | h | h | h | h | h | h | h | h | h | h <;> subst h
  · exact Or.inr (Or.inl ⟨solve W (0) (D 1 5) (F 1 5 0) 4 (Nat.succ_pos 3) rfl h1 rfl, Or.inl rfl⟩)
  · exact Or.inl ⟨solve W (-1) (D 1 5) (F 1 5 1) 4 (Nat.succ_pos 3) rfl h1 rfl, rfl⟩
  · exact absurd (elim2 W (D 1 5) (D 5 5) (F 1 5 2) (F 5 5 2) h1 h5) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 5) (D 3 5) (F 1 5 3) (F 3 5 3) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 5) (D 3 5) (F 1 5 4) (F 3 5 4) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 5) (D 3 5) (F 1 5 5) (F 3 5 5) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 5) (D 5 5) (F 1 5 6) (F 5 5 6) h1 h5) (ne_of_dec _ _ rfl)
  · exact Or.inr (Or.inl ⟨solve W (0) (D 1 5) (F 1 5 7) 4 (Nat.succ_pos 3) rfl h1 rfl, Or.inr rfl⟩)
  · exact absurd (elim2 W (D 1 5) (D 5 5) (F 1 5 8) (F 5 5 8) h1 h5) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 5) (D 3 5) (F 1 5 9) (F 3 5 9) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 5) (D 3 5) (F 1 5 10) (F 3 5 10) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 5) (D 3 5) (F 1 5 11) (F 3 5 11) h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2 W (D 1 5) (D 5 5) (F 1 5 12) (F 5 5 12) h1 h5) (ne_of_dec _ _ rfl)
  · exact Or.inr (Or.inr ⟨solve W (1) (D 1 5) (F 1 5 13) 4 (Nat.succ_pos 3) rfl h1 rfl, rfl⟩)

theorem elim_div3 (e : Nat) (he : e < 14) (W : Int) (k : Nat) (hk : 0 < k)
    (h1 : W * D 1 3 + (k : Int) * G 1 e = 0) (h3 : W * D 3 3 + (k : Int) * G 3 e = 0)
    (h5 : W * D 5 3 + (k : Int) * G 5 e = 0) :
    (W = 0 ∧ e = 7) ∨ (W = -(k : Int) ∧ e = 5) ∨ (W = (k : Int) ∧ e = 9) := by
  rcases lt14 e he with h | h | h | h | h | h | h | h | h | h | h | h | h | h <;> subst h
  · exact absurd (elim2k W (D 1 3) (D 3 3) (G 1 0) (G 3 0) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 3) (D 3 3) (G 1 1) (G 3 1) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 3) (D 3 3) (G 1 2) (G 3 2) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 3) (D 3 3) (G 1 3) (G 3 3) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 3) (D 3 3) (G 1 4) (G 3 4) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact Or.inr (Or.inl ⟨solvek W (-(k : Int)) (D 1 3) (G 1 5) 2 k (Nat.succ_pos 1) rfl h1 (by show (-(k : Int)) * (-2) + (k : Int) * (-2) = 0; lib_int), rfl⟩)
  · exact absurd (elim2k W (D 1 3) (D 5 3) (G 1 6) (G 5 6) k hk h1 h5) (ne_of_dec _ _ rfl)
  · exact Or.inl ⟨solvek W 0 (D 1 3) (G 1 7) 2 k (Nat.succ_pos 1) rfl h1 (by show (0 : Int) * (-2) + (k : Int) * (0) = 0; lib_int), rfl⟩
  · exact absurd (elim2k W (D 1 3) (D 5 3) (G 1 8) (G 5 8) k hk h1 h5) (ne_of_dec _ _ rfl)
  · exact Or.inr (Or.inr ⟨solvek W ((k : Int)) (D 1 3) (G 1 9) 2 k (Nat.succ_pos 1) rfl h1 (by show ((k : Int)) * (-2) + (k : Int) * (2) = 0; lib_int), rfl⟩)
  · exact absurd (elim2k W (D 1 3) (D 3 3) (G 1 10) (G 3 10) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 3) (D 3 3) (G 1 11) (G 3 11) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 3) (D 3 3) (G 1 12) (G 3 12) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 3) (D 3 3) (G 1 13) (G 3 13) k hk h1 h3) (ne_of_dec _ _ rfl)

theorem elim_div5 (e : Nat) (he : e < 14) (W : Int) (k : Nat) (hk : 0 < k)
    (h1 : W * D 1 5 + (k : Int) * G 1 e = 0) (h3 : W * D 3 5 + (k : Int) * G 3 e = 0)
    (h5 : W * D 5 5 + (k : Int) * G 5 e = 0) :
    (W = 0 ∧ e = 7) ∨ (W = -(k : Int) ∧ e = 3) ∨ (W = (k : Int) ∧ e = 11) := by
  rcases lt14 e he with h | h | h | h | h | h | h | h | h | h | h | h | h | h <;> subst h
  · exact absurd (elim2k W (D 1 5) (D 3 5) (G 1 0) (G 3 0) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 5) (D 3 5) (G 1 1) (G 3 1) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 5) (D 3 5) (G 1 2) (G 3 2) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact Or.inr (Or.inl ⟨solvek W (-(k : Int)) (D 1 5) (G 1 3) 4 k (Nat.succ_pos 3) rfl h1 (by show (-(k : Int)) * (-4) + (k : Int) * (-4) = 0; lib_int), rfl⟩)
  · exact absurd (elim2k W (D 1 5) (D 3 5) (G 1 4) (G 3 4) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 5) (D 3 5) (G 1 5) (G 3 5) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 5) (D 3 5) (G 1 6) (G 3 6) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact Or.inl ⟨solvek W 0 (D 1 5) (G 1 7) 4 k (Nat.succ_pos 3) rfl h1 (by show (0 : Int) * (-4) + (k : Int) * (0) = 0; lib_int), rfl⟩
  · exact absurd (elim2k W (D 1 5) (D 3 5) (G 1 8) (G 3 8) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 5) (D 3 5) (G 1 9) (G 3 9) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 5) (D 3 5) (G 1 10) (G 3 10) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact Or.inr (Or.inr ⟨solvek W ((k : Int)) (D 1 5) (G 1 11) 4 k (Nat.succ_pos 3) rfl h1 (by show ((k : Int)) * (-4) + (k : Int) * (4) = 0; lib_int), rfl⟩)
  · exact absurd (elim2k W (D 1 5) (D 3 5) (G 1 12) (G 3 12) k hk h1 h3) (ne_of_dec _ _ rfl)
  · exact absurd (elim2k W (D 1 5) (D 3 5) (G 1 13) (G 3 13) k hk h1 h3) (ne_of_dec _ _ rfl)

end CosetElim

#print axioms CosetElim.elim2
#print axioms CosetElim.elim2k
#print axioms CosetElim.ne_of_dec
#print axioms CosetElim.solve
#print axioms CosetElim.solvek
#print axioms CosetElim.lt14
#print axioms CosetElim.elim_unit3
#print axioms CosetElim.elim_unit5
#print axioms CosetElim.elim_div3
#print axioms CosetElim.elim_div5

#print axioms: 10 theorems, no axioms.

81.238 Coset solutions have a part of size one

For \(p=14a+v\), \(v\in \{3,5\}\), each solution of the residue tables forces one side of the split to have at most one element besides the completion.

hodge/CosetSize.lean

/-
  hodge/CosetSize.lean — T41 cycle 1932 (goal G862c, step 3d): the solutions of CosetElim only occur for parts of
  size 1. A part c :: Q of a completed split of F_p ∪ {7p} with n₁ ordinary elements, δ special, η = [7p ∈ Q] has
  coset weight W = n₁ − δ(p − 1) and c ≡ −ΣQ ≡ −(n₁ + δ(1 + 6p) + 7pη) (mod 14). For p = 14a + v (v = 5, 3) and each
  solution (W, c mod 14) of CosetElim, either the part has n₁ + δ + η ≤ 1 elements besides c, or its complement does
  (p ≤ n₁ + δ + η). Lean 4 core plus hodge/CosetDev, lib/IntRing; no axioms.
-/
import hodge.CosetDev

namespace CosetSize
open ModHand

theorem le1 : ∀ x, x ≤ 1 → x = 0 ∨ x = 1
  | 0, _ => Or.inl rfl
  | 1, _ => Or.inr rfl
  | n + 2, h => absurd h (fun h' => Nat.lt_irrefl 1 (Nat.lt_of_lt_of_le (Nat.succ_lt_succ (Nat.succ_pos n)) h'))

theorem mod_ne (x r q : Nat) (hr : r < 14) (hr0 : r ≠ 0) (hx : x = r + q * 14) (h : x % 14 = 0) : False := by
  rw [hx, add_mul_mod' r 14 (Nat.succ_pos 13) q, mod_lt' r 14 hr] at h
  exact hr0 h

theorem size5 (a n1 δ η g : Nat) (W : Int) (hδ : δ ≤ 1) (hη : η ≤ 1) (hn : n1 + 1 ≤ 14 * a + 5)
    (hW : W = (n1 : Int) - (δ : Int) * (14 * (a : Int) + 4))
    (hg : (g + n1 + δ * (1 + 6 * (14 * a + 5)) + η * (7 * (14 * a + 5))) % 14 = 0)
    (hc : (W = -1 ∧ g = 1) ∨ W = 0 ∨ (W = 1 ∧ g = 13) ∨ (W = -(14 * (a : Int) + 4) ∧ g = 11)
      ∨ (W = 14 * (a : Int) + 4 ∧ g = 3)) :
    n1 + δ + η ≤ 1 ∨ 14 * a + 5 ≤ n1 + δ + η := by
  rcases le1 δ hδ with hd | hd <;> rcases le1 η hη with he | he <;> subst hd he
  all_goals (try rw [show ((0 : Nat) : Int) = 0 from rfl] at hW)
  all_goals (try rw [show ((1 : Nat) : Int) = 1 from rfl] at hW)
  all_goals rcases hc with ⟨h1, h2⟩ | h1 | ⟨h1, h2⟩ | ⟨h1, h2⟩ | ⟨h1, h2⟩
  · have e : (n1 : Int) = -1 := by rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]; lib_int
    exact Int.noConfusion e
  · have e : (n1 : Int) = ((0 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((0) : Nat) : Int)
      rw [show (((0) : Nat) : Int) = 0 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inl (by show 0 + 0 + 0 ≤ 1; exact Nat.zero_le 1)
  · have e : (n1 : Int) = ((1 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((1) : Nat) : Int)
      rw [show (((1) : Nat) : Int) = 1 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inl (by show 1 + 0 + 0 ≤ 1; exact Nat.le_refl 1)
  · have e : ((n1 + 14 * a + 4 : Nat) : Int) = 0 := by
      show (n1 : Int) + 14 * (a : Int) + 4 = 0
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]; lib_int
    have e' := Int.ofNat.inj e
    rw [show n1 + 14 * a + 4 = (n1 + 14 * a + 3) + 1 by lib_nat] at e'
    exact Nat.noConfusion e'
  · have e : (n1 : Int) = ((14 * a + 4 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 4) : Nat) : Int)
      rw [show (((14 * a + 4) : Nat) : Int) = 14 * (a : Int) + 4 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    subst h2
    exact mod_ne _ 7 (0 + 1 * a) (Nat.le.intro (k := 6) rfl) (by intro h; exact Nat.noConfusion h) (by lib_nat) hg
  · have e : (n1 : Int) = -1 := by rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]; lib_int
    exact Int.noConfusion e
  · have e : (n1 : Int) = ((0 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((0) : Nat) : Int)
      rw [show (((0) : Nat) : Int) = 0 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inl (by show 0 + 0 + 1 ≤ 1; exact Nat.le_refl 1)
  · have e : (n1 : Int) = ((1 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((1) : Nat) : Int)
      rw [show (((1) : Nat) : Int) = 1 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    subst h2
    exact mod_ne _ 7 (3 + 7 * a) (Nat.le.intro (k := 6) rfl) (by intro h; exact Nat.noConfusion h) (by lib_nat) hg
  · have e : ((n1 + 14 * a + 4 : Nat) : Int) = 0 := by
      show (n1 : Int) + 14 * (a : Int) + 4 = 0
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]; lib_int
    have e' := Int.ofNat.inj e
    rw [show n1 + 14 * a + 4 = (n1 + 14 * a + 3) + 1 by lib_nat] at e'
    exact Nat.noConfusion e'
  · have e : (n1 : Int) = ((14 * a + 4 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 4) : Nat) : Int)
      rw [show (((14 * a + 4) : Nat) : Int) = 14 * (a : Int) + 4 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inr (Nat.le.intro (k := 0) (by lib_nat))
  · have e : (n1 : Int) = ((14 * a + 3 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 3) : Nat) : Int)
      rw [show (((14 * a + 3) : Nat) : Int) = 14 * (a : Int) + 3 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    subst h2
    exact mod_ne _ 7 (2 + 7 * a) (Nat.le.intro (k := 6) rfl) (by intro h; exact Nat.noConfusion h) (by lib_nat) hg
  · have e : (n1 : Int) = ((14 * a + 4 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 4) : Nat) : Int)
      rw [show (((14 * a + 4) : Nat) : Int) = 14 * (a : Int) + 4 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inr (Nat.le.intro (k := 0) (by lib_nat))
  · have e : (n1 : Int) = ((14 * a + 5 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 5) : Nat) : Int)
      rw [show (((14 * a + 5) : Nat) : Int) = 14 * (a : Int) + 5 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le (Nat.lt_succ_self _) hn)
  · have e : (n1 : Int) = ((0 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((0) : Nat) : Int)
      rw [show (((0) : Nat) : Int) = 0 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inl (by show 0 + 1 + 0 ≤ 1; exact Nat.le_refl 1)
  · have e : (n1 : Int) = ((28 * a + 8 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((28 * a + 8) : Nat) : Int)
      rw [show (((28 * a + 8) : Nat) : Int) = 28 * (a : Int) + 8 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le (Nat.le.intro (k := 14 * a + 3) (by lib_nat) : 14 * a + 5 < 28 * a + 8 + 1) hn)
  · have e : (n1 : Int) = ((14 * a + 3 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 3) : Nat) : Int)
      rw [show (((14 * a + 3) : Nat) : Int) = 14 * (a : Int) + 3 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inr (Nat.le.intro (k := 0) (by lib_nat))
  · have e : (n1 : Int) = ((14 * a + 4 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 4) : Nat) : Int)
      rw [show (((14 * a + 4) : Nat) : Int) = 14 * (a : Int) + 4 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inr (Nat.le.intro (k := 1) (by lib_nat))
  · have e : (n1 : Int) = ((14 * a + 5 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 5) : Nat) : Int)
      rw [show (((14 * a + 5) : Nat) : Int) = 14 * (a : Int) + 5 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le (Nat.lt_succ_self _) hn)
  · have e : (n1 : Int) = ((0 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((0) : Nat) : Int)
      rw [show (((0) : Nat) : Int) = 0 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    subst h2
    exact mod_ne _ 7 (5 + 13 * a) (Nat.le.intro (k := 6) rfl) (by intro h; exact Nat.noConfusion h) (by lib_nat) hg
  · have e : (n1 : Int) = ((28 * a + 8 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 4) by rw [hW]; lib_int, h1]
      show _ = (((28 * a + 8) : Nat) : Int)
      rw [show (((28 * a + 8) : Nat) : Int) = 28 * (a : Int) + 8 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le (Nat.le.intro (k := 14 * a + 3) (by lib_nat) : 14 * a + 5 < 28 * a + 8 + 1) hn)

theorem size3 (a n1 δ η g : Nat) (W : Int) (hδ : δ ≤ 1) (hη : η ≤ 1) (hn : n1 + 1 ≤ 14 * a + 3)
    (hW : W = (n1 : Int) - (δ : Int) * (14 * (a : Int) + 2))
    (hg : (g + n1 + δ * (1 + 6 * (14 * a + 3)) + η * (7 * (14 * a + 3))) % 14 = 0)
    (hc : (W = -1 ∧ g = 1) ∨ W = 0 ∨ (W = 1 ∧ g = 13) ∨ (W = -(14 * (a : Int) + 2) ∧ g = 9)
      ∨ (W = 14 * (a : Int) + 2 ∧ g = 5)) :
    n1 + δ + η ≤ 1 ∨ 14 * a + 3 ≤ n1 + δ + η := by
  rcases le1 δ hδ with hd | hd <;> rcases le1 η hη with he | he <;> subst hd he
  all_goals (try rw [show ((0 : Nat) : Int) = 0 from rfl] at hW)
  all_goals (try rw [show ((1 : Nat) : Int) = 1 from rfl] at hW)
  all_goals rcases hc with ⟨h1, h2⟩ | h1 | ⟨h1, h2⟩ | ⟨h1, h2⟩ | ⟨h1, h2⟩
  · have e : (n1 : Int) = -1 := by rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]; lib_int
    exact Int.noConfusion e
  · have e : (n1 : Int) = ((0 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((0) : Nat) : Int)
      rw [show (((0) : Nat) : Int) = 0 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inl (by show 0 + 0 + 0 ≤ 1; exact Nat.zero_le 1)
  · have e : (n1 : Int) = ((1 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((1) : Nat) : Int)
      rw [show (((1) : Nat) : Int) = 1 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inl (by show 1 + 0 + 0 ≤ 1; exact Nat.le_refl 1)
  · have e : ((n1 + 14 * a + 2 : Nat) : Int) = 0 := by
      show (n1 : Int) + 14 * (a : Int) + 2 = 0
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]; lib_int
    have e' := Int.ofNat.inj e
    rw [show n1 + 14 * a + 2 = (n1 + 14 * a + 1) + 1 by lib_nat] at e'
    exact Nat.noConfusion e'
  · have e : (n1 : Int) = ((14 * a + 2 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 2) : Nat) : Int)
      rw [show (((14 * a + 2) : Nat) : Int) = 14 * (a : Int) + 2 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    subst h2
    exact mod_ne _ 7 (0 + 1 * a) (Nat.le.intro (k := 6) rfl) (by intro h; exact Nat.noConfusion h) (by lib_nat) hg
  · have e : (n1 : Int) = -1 := by rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]; lib_int
    exact Int.noConfusion e
  · have e : (n1 : Int) = ((0 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((0) : Nat) : Int)
      rw [show (((0) : Nat) : Int) = 0 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inl (by show 0 + 0 + 1 ≤ 1; exact Nat.le_refl 1)
  · have e : (n1 : Int) = ((1 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((1) : Nat) : Int)
      rw [show (((1) : Nat) : Int) = 1 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    subst h2
    exact mod_ne _ 7 (2 + 7 * a) (Nat.le.intro (k := 6) rfl) (by intro h; exact Nat.noConfusion h) (by lib_nat) hg
  · have e : ((n1 + 14 * a + 2 : Nat) : Int) = 0 := by
      show (n1 : Int) + 14 * (a : Int) + 2 = 0
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]; lib_int
    have e' := Int.ofNat.inj e
    rw [show n1 + 14 * a + 2 = (n1 + 14 * a + 1) + 1 by lib_nat] at e'
    exact Nat.noConfusion e'
  · have e : (n1 : Int) = ((14 * a + 2 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 0 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 2) : Nat) : Int)
      rw [show (((14 * a + 2) : Nat) : Int) = 14 * (a : Int) + 2 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inr (Nat.le.intro (k := 0) (by lib_nat))
  · have e : (n1 : Int) = ((14 * a + 1 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 1) : Nat) : Int)
      rw [show (((14 * a + 1) : Nat) : Int) = 14 * (a : Int) + 1 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    subst h2
    exact mod_ne _ 7 (1 + 7 * a) (Nat.le.intro (k := 6) rfl) (by intro h; exact Nat.noConfusion h) (by lib_nat) hg
  · have e : (n1 : Int) = ((14 * a + 2 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 2) : Nat) : Int)
      rw [show (((14 * a + 2) : Nat) : Int) = 14 * (a : Int) + 2 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inr (Nat.le.intro (k := 0) (by lib_nat))
  · have e : (n1 : Int) = ((14 * a + 3 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 3) : Nat) : Int)
      rw [show (((14 * a + 3) : Nat) : Int) = 14 * (a : Int) + 3 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le (Nat.lt_succ_self _) hn)
  · have e : (n1 : Int) = ((0 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((0) : Nat) : Int)
      rw [show (((0) : Nat) : Int) = 0 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inl (by show 0 + 1 + 0 ≤ 1; exact Nat.le_refl 1)
  · have e : (n1 : Int) = ((28 * a + 4 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((28 * a + 4) : Nat) : Int)
      rw [show (((28 * a + 4) : Nat) : Int) = 28 * (a : Int) + 4 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le (Nat.le.intro (k := 14 * a + 1) (by lib_nat) : 14 * a + 3 < 28 * a + 4 + 1) hn)
  · have e : (n1 : Int) = ((14 * a + 1 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 1) : Nat) : Int)
      rw [show (((14 * a + 1) : Nat) : Int) = 14 * (a : Int) + 1 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inr (Nat.le.intro (k := 0) (by lib_nat))
  · have e : (n1 : Int) = ((14 * a + 2 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 2) : Nat) : Int)
      rw [show (((14 * a + 2) : Nat) : Int) = 14 * (a : Int) + 2 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exact Or.inr (Nat.le.intro (k := 1) (by lib_nat))
  · have e : (n1 : Int) = ((14 * a + 3 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((14 * a + 3) : Nat) : Int)
      rw [show (((14 * a + 3) : Nat) : Int) = 14 * (a : Int) + 3 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le (Nat.lt_succ_self _) hn)
  · have e : (n1 : Int) = ((0 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((0) : Nat) : Int)
      rw [show (((0) : Nat) : Int) = 0 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    subst h2
    exact mod_ne _ 7 (3 + 13 * a) (Nat.le.intro (k := 6) rfl) (by intro h; exact Nat.noConfusion h) (by lib_nat) hg
  · have e : (n1 : Int) = ((28 * a + 4 : Nat) : Int) := by
      rw [show (n1 : Int) = W + 1 * (14 * (a : Int) + 2) by rw [hW]; lib_int, h1]
      show _ = (((28 * a + 4) : Nat) : Int)
      rw [show (((28 * a + 4) : Nat) : Int) = 28 * (a : Int) + 4 from rfl]; lib_int
    have hn1 := Int.ofNat.inj e
    subst hn1
    exfalso
    exact Nat.lt_irrefl _ (Nat.lt_of_lt_of_le (Nat.le.intro (k := 14 * a + 1) (by lib_nat) : 14 * a + 3 < 28 * a + 4 + 1) hn)

end CosetSize

#print axioms CosetSize.le1
#print axioms CosetSize.mod_ne
#print axioms CosetSize.size5
#print axioms CosetSize.size3

#print axioms: 4 theorems, no axioms.

81.239 Coset weights of the family elements

The deviation of an element of \(F_p\cup \{7p\}\) is its weight times \(D_\rho =\rho -\langle \rho x_0\rangle _{14}\): weight \(1\), \(-(p-1)\) or \(0\).

hodge/CosetWeight.lean

/-
  hodge/CosetWeight.lean — T41 cycle 1932 (goal G862c, step 3b): the coset deviation of each element of
  F_p ∪ {7p} is a weight times D_ρ = ρ − ⟨ρx₀⟩_14, where p·x₀ = 1 + 14i₀ and ρ + 14j₀ = p·y:
    y_mod    y ≡ ρ·x₀ (mod 14)
    f_ord    ordinary element 1 + 14k (p ∤ it):  omitR = 14S + p·(1·D_ρ)
    f_spec   special element p(x₀ + 6), given the residue identity ⟨ρ(x₀ + 6)⟩ − 7 = ⟨ρx₀⟩ − ρ:
             omitR = 14S + p·(−(p − 1)·D_ρ)
    f_half   7p, given ⟨7ρ⟩ = 7:  omitR = 14S + p·0
    tab      the residue identities hold for x₀ mod 14 ∈ {3, 5} and ρ ∈ {1, 3, 5, 9, 11, 13}   (rfl)

  Lean 4 core plus hodge/CosetDev; no axioms.
-/
import hodge.CosetDev

namespace CosetWeight
open GcdHand ModHand OrbitSum APPairGen PermSum FamMod FamArith Indecomp CosetAvg CosetDev

theorem y_mod (p ρ j0 y i0 x0 : Nat) (ht : ρ + 14 * j0 = p * y) (hx : 1 + 14 * i0 = p * x0) :
    y % 14 = (ρ * x0) % 14 := by
  have e1 : y * (p * x0) = y + (y * i0) * 14 := by rw [← hx]; lib_nat
  have e2 : y * (p * x0) = ρ * x0 + (j0 * x0) * 14 := by
    calc y * (p * x0) = (p * y) * x0 := by lib_nat
      _ = (ρ + 14 * j0) * x0 := by rw [ht]
      _ = _ := by lib_nat
  have a := add_mul_mod' y 14 (Nat.succ_pos 13) (y * i0)
  have b := add_mul_mod' (ρ * x0) 14 (Nat.succ_pos 13) (j0 * x0)
  rw [← e1, e2, b] at a
  exact a.symm

theorem ord_mod (r k : Nat) : (r * (1 + 14 * k)) % 14 = r % 14 := by
  rw [show r * (1 + 14 * k) = r + (r * k) * 14 by lib_nat]
  exact add_mul_mod' r 14 (Nat.succ_pos 13) (r * k)

theorem f_ord (p ρ j0 y i0 x0 k : Nat) (hρ : ρ < 14) (hi : j0 < p) (ht : ρ + 14 * j0 = p * y)
    (hx : 1 + 14 * i0 = p * x0) (hk : Nat.gcd (1 + 14 * k) p = 1) :
    (omitR p ρ j0 (1 + 14 * k) : Int)
      = 14 * (sumF (fun i => i) p : Nat) + (p : Int) * (1 * ((ρ : Int) - ((ρ * x0) % 14 : Nat))) := by
  rw [dev_unit p ρ j0 y (1 + 14 * k) hi ht hk, ord_mod ρ k, ord_mod y k, mod_lt' ρ 14 hρ,
    y_mod p ρ j0 y i0 x0 ht hx]
  generalize (((ρ * x0) % 14 : Nat) : Int) = R
  lib_int

theorem f_spec (p ρ j0 x0 : Nat) (hi : j0 < p)
    (hT : (((ρ * (x0 + 6)) % 14 : Nat) : Int) - 7 = (((ρ * x0) % 14 : Nat) : Int) - ρ) :
    (omitR p ρ j0 (p * (x0 + 6)) : Int)
      = 14 * (sumF (fun i => i) p : Nat) + (p : Int) * (-((p : Int) - 1) * ((ρ : Int) - ((ρ * x0) % 14 : Nat))) := by
  rw [dev_div p ρ j0 (x0 + 6) hi, hT]
  generalize (((ρ * x0) % 14 : Nat) : Int) = R
  lib_int

theorem f_half (p ρ j0 : Nat) (hi : j0 < p) (hT : (ρ * 7) % 14 = 7) :
    (omitR p ρ j0 (p * 7) : Int) = 14 * (sumF (fun i => i) p : Nat) + (p : Int) * 0 := by
  rw [dev_div p ρ j0 7 hi, hT]
  show _ = _ + (p : Int) * 0
  have : ((7 : Nat) : Int) - 7 = 0 := rfl
  rw [this]
  lib_int

/-- the residue tables (u = x₀ mod 14) -/
def specOK (u ρ : Nat) : Bool := Int.decEq ((((ρ * (u + 6)) % 14 : Nat) : Int) - 7) ((((ρ * u) % 14 : Nat) : Int) - ρ) |>.decide

theorem tab_spec : [3, 5].all (fun u => [1, 3, 5, 9, 11, 13].all (fun ρ => specOK u ρ)) = true := rfl
theorem tab_half : [1, 3, 5, 9, 11, 13].all (fun ρ => Nat.beq ((ρ * 7) % 14) 7) = true := rfl

end CosetWeight

#print axioms CosetWeight.y_mod
#print axioms CosetWeight.ord_mod
#print axioms CosetWeight.f_ord
#print axioms CosetWeight.f_spec
#print axioms CosetWeight.f_half
#print axioms CosetWeight.tab_spec
#print axioms CosetWeight.tab_half

#print axioms: 7 theorems, no axioms.

81.240 The three kinds of elements of \(7p::F_p\)

Indicators of ordinary, special and \(7p\) elements, their totals, and the sum of a sub-list modulo \(14\).

hodge/CosetSplitA.lean

/-
  hodge/CosetSplitA.lean — T41 cycle 1932 (goal G862c, step 3e, part A): the halved doubled character
  Fq = 7p :: F_p (F_p = FamBal.fam p i₀, p = 14a + v, v ∈ {3, 5}) and its three kinds of elements:
  ordinary 1 + 14k (residue 1 mod 14), special s* = 1 + 14i₀ + 6p (residue 5 or 3), and 7p (residue 7).
    io, isp, ih      indicators of the three kinds (io + isp + ih = 1 everywhere)
    fq_totals        over Fq: Σ io + 1 = p, Σ isp = 1, Σ ih = 1
    split_counts     for (A, B) ∈ splits Fq: the counts add up as above, and |A| = Σ_A io + Σ_A isp + Σ_A ih
    sum_decomp       for A ⊆ Fq: Σ_A x = n₁ + δ(1 + 6p) + η·7p + 14K
  Lean 4 core plus hodge/FamIndec3, hodge/Q4Conv (splits_props); no axioms.
-/
import hodge.FamIndec3
import hodge.Q4Conv

namespace CosetSplitA
open GcdHand ModHand OrbitSum PermSum FamMod FamArith Indecomp FamIndec3 FamBal QFamPrime

def sst (p i0 : Nat) : Nat := 1 + 14 * i0 + 6 * p
def ih (p x : Nat) : Nat := if Nat.beq x (7 * p) then 1 else 0
def isp (p i0 x : Nat) : Nat := if Nat.beq x (7 * p) then 0 else if Nat.beq x (sst p i0) then 1 else 0
def io (p i0 x : Nat) : Nat := if Nat.beq x (7 * p) then 0 else if Nat.beq x (sst p i0) then 0 else 1
def Fq (p i0 : Nat) : List Nat := 7 * p :: fam p i0

theorem res_of (x r q : Nat) (hr : r < 14) (h : x = r + q * 14) : x % 14 = r := by
  rw [h, add_mul_mod' r 14 (Nat.succ_pos 13) q, mod_lt' r 14 hr]

theorem beq_false_res (x y : Nat) (h : x % 14 ≠ y % 14) : Nat.beq x y = false := by
  cases e : Nat.beq x y with
  | false => rfl
  | true => exact absurd (by rw [Nat.eq_of_beq_eq_true e]) h

theorem res_ord (k : Nat) : (1 + 14 * k) % 14 = 1 := res_of _ 1 k (Nat.succ_lt_succ (Nat.succ_pos 12)) (by lib_nat)

theorem res_half (a v : Nat) (hv : v = 3 ∨ v = 5) : (7 * (14 * a + v)) % 14 = 7 := by
  rcases hv with h | h <;> subst h
  · exact res_of _ 7 (1 + 7 * a) (Nat.le.intro (k := 6) rfl) (by lib_nat)
  · exact res_of _ 7 (2 + 7 * a) (Nat.le.intro (k := 6) rfl) (by lib_nat)

/-- the residue of s* is 5 (v = 3) or 3 (v = 5): neither 1 nor 7 -/
theorem res_sst (a v i0 : Nat) (hv : v = 3 ∨ v = 5) :
    (sst (14 * a + v) i0) % 14 ≠ 1 ∧ (sst (14 * a + v) i0) % 14 ≠ 7 := by
  rcases hv with h | h <;> subst h
  · rw [res_of _ 5 (1 + i0 + 6 * a) (Nat.le.intro (k := 8) rfl) (by unfold sst; lib_nat)]
    exact ⟨fun e => Nat.noConfusion (Nat.succ.inj e), fun e => by
      have e' : (5 : Nat) = 7 := e
      exact Nat.noConfusion (Nat.succ.inj (Nat.succ.inj (Nat.succ.inj (Nat.succ.inj (Nat.succ.inj e')))))⟩
  · rw [res_of _ 3 (2 + i0 + 6 * a) (Nat.le.intro (k := 10) rfl) (by unfold sst; lib_nat)]
    exact ⟨fun e => Nat.noConfusion (Nat.succ.inj e), fun e => by
      have e' : (3 : Nat) = 7 := e
      exact Nat.noConfusion (Nat.succ.inj (Nat.succ.inj (Nat.succ.inj e')))⟩

theorem one_ne_seven : (1 : Nat) ≠ 7 := fun e => Nat.noConfusion (Nat.succ.inj e)

/-- the kinds of the three element types -/
theorem kind_ord (a v i0 k : Nat) (hv : v = 3 ∨ v = 5) :
    io (14 * a + v) i0 (1 + 14 * k) = 1 ∧ isp (14 * a + v) i0 (1 + 14 * k) = 0 ∧ ih (14 * a + v) (1 + 14 * k) = 0 := by
  have h7 : Nat.beq (1 + 14 * k) (7 * (14 * a + v)) = false := by
    apply beq_false_res; rw [res_ord, res_half a v hv]; exact one_ne_seven
  have hs : Nat.beq (1 + 14 * k) (sst (14 * a + v) i0) = false := by
    apply beq_false_res; rw [res_ord]; exact fun e => (res_sst a v i0 hv).1 e.symm
  unfold io isp ih; rw [h7, hs]; exact ⟨rfl, rfl, rfl⟩

theorem kind_sst (a v i0 : Nat) (hv : v = 3 ∨ v = 5) :
    io (14 * a + v) i0 (sst (14 * a + v) i0) = 0 ∧ isp (14 * a + v) i0 (sst (14 * a + v) i0) = 1
      ∧ ih (14 * a + v) (sst (14 * a + v) i0) = 0 := by
  have h7 : Nat.beq (sst (14 * a + v) i0) (7 * (14 * a + v)) = false := by
    apply beq_false_res; rw [res_half a v hv]; exact (res_sst a v i0 hv).2
  unfold io isp ih; rw [h7, beq_refl']; exact ⟨rfl, rfl, rfl⟩

theorem kind_half (a v i0 : Nat) :
    io (14 * a + v) i0 (7 * (14 * a + v)) = 0 ∧ isp (14 * a + v) i0 (7 * (14 * a + v)) = 0
      ∧ ih (14 * a + v) (7 * (14 * a + v)) = 1 := by
  unfold io isp ih; rw [beq_refl']; exact ⟨rfl, rfl, rfl⟩

theorem kind_sum (p i0 x : Nat) : io p i0 x + isp p i0 x + ih p x = 1 := by
  unfold io isp ih
  cases Nat.beq x (7 * p) <;> cases Nat.beq x (sst p i0) <;> rfl

/-- the elements of F_p -/
theorem fam_kind (p i0 x : Nat) (hx : x ∈ fam p i0) : x = sst p i0 ∨ ∃ k, k < p ∧ k ≠ i0 ∧ x = 1 + 14 * k := by
  have ⟨k, hk, ek⟩ := gl_mem _ p x hx
  cases e : Nat.beq k i0 with
  | true =>
    have ek0 := Nat.eq_of_beq_eq_true e
    left; rw [← ek]
    show (if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k) = _
    rw [e, ek0]; rfl
  | false =>
    right; refine ⟨k, hk, (fun h => by rw [h, beq_refl'] at e; exact nomatch e), ?_⟩
    rw [← ek]
    show (if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k) = _
    rw [e]; rfl

theorem gs_add3 (f g h : Nat → Nat) : ∀ L : List Nat, gs f L + gs g L + gs h L = gs (fun x => f x + g x + h x) L
  | [] => rfl
  | x :: L => by
    show (f x + gs f L) + (g x + gs g L) + (h x + gs h L) = (f x + g x + h x) + gs (fun x => f x + g x + h x) L
    rw [← gs_add3 f g h L]; lib_nat

theorem gs_one : ∀ L : List Nat, gs (fun _ => 1) L = L.length
  | [] => rfl
  | _ :: L => by show 1 + gs (fun _ => 1) L = L.length + 1; rw [gs_one L]; lib_nat

theorem gs_congr' (f g : Nat → Nat) (h : ∀ x, f x = g x) : ∀ L : List Nat, gs f L = gs g L
  | [] => rfl
  | x :: L => by show f x + gs f L = g x + gs g L; rw [h x, gs_congr' f g h L]

/-- |A| = n₁ + δ + η -/
theorem len_counts (p i0 : Nat) (L : List Nat) : gs (io p i0) L + gs (isp p i0) L + gs (ih p) L = L.length := by
  rw [gs_add3, ← gs_one L]
  exact gs_congr' _ _ (fun x => kind_sum p i0 x) L

theorem sumF_const' (C : Nat) : ∀ n, sumF (fun _ => C) n = n * C
  | 0 => by show 0 = 0 * C; lib_nat
  | n + 1 => by show sumF (fun _ => C) n + C = (n + 1) * C; rw [sumF_const' C n]; lib_nat

theorem sum_ite (α β i0 p : Nat) (hi : i0 < p) :
    sumF (fun k => if Nat.beq k i0 = true then α else β) p + β = p * β + α := by
  have r := sumF_replace (fun k => if Nat.beq k i0 = true then α else β) (fun _ => β) i0 (fun k hk => by
    cases e : Nat.beq k i0 with
    | true => exact absurd (Nat.eq_of_beq_eq_true e) hk
    | false => rfl) p hi
  have r' : sumF (fun k => if Nat.beq k i0 = true then α else β) p + β
      = sumF (fun _ => β) p + (if Nat.beq i0 i0 = true then α else β) := r
  rw [beq_refl', sumF_const'] at r'
  exact r'

/-- an indicator g composed with the family generator is α at i₀ and β elsewhere -/
theorem fam_ind (a v i0 : Nat) (g : Nat → Nat) (α β : Nat) (hs : g (sst (14 * a + v) i0) = α)
    (ho : ∀ k, g (1 + 14 * k) = β) (hi : i0 < 14 * a + v) :
    gs g (fam (14 * a + v) i0) + β = (14 * a + v) * β + α := by
  unfold fam
  rw [gl_gs]
  have e : ∀ k, k < 14 * a + v → g ((fun k => if Nat.beq k i0 then 1 + 14 * k + 6 * (14 * a + v) else 1 + 14 * k) k)
      = (if Nat.beq k i0 = true then α else β) := by
    intro k _
    cases eb : Nat.beq k i0 with
    | true =>
      have ek := Nat.eq_of_beq_eq_true eb
      subst ek
      show g (if Nat.beq k k = true then 1 + 14 * k + 6 * (14 * a + v) else 1 + 14 * k) = _
      rw [eb]; exact hs
    | false =>
      show g (if Nat.beq k i0 = true then 1 + 14 * k + 6 * (14 * a + v) else 1 + 14 * k) = _
      rw [eb]; exact ho k
  rw [sumF_congr_lt _ _ _ e]
  exact sum_ite α β i0 _ hi

theorem tot_ih (a v i0 : Nat) (hv : v = 3 ∨ v = 5) (hi : i0 < 14 * a + v) :
    gs (ih (14 * a + v)) (Fq (14 * a + v) i0) = 1 := by
  have h := fam_ind a v i0 (ih (14 * a + v)) 0 0 (kind_sst a v i0 hv).2.2 (fun k => (kind_ord a v i0 k hv).2.2) hi
  show ih (14 * a + v) (7 * (14 * a + v)) + gs (ih (14 * a + v)) (fam (14 * a + v) i0) = 1
  rw [(kind_half a v i0).2.2]
  rw [show (14 * a + v) * 0 + 0 = 0 by lib_nat] at h
  rw [show gs (ih (14 * a + v)) (fam (14 * a + v) i0) = 0 from h]

theorem tot_isp (a v i0 : Nat) (hv : v = 3 ∨ v = 5) (hi : i0 < 14 * a + v) :
    gs (isp (14 * a + v) i0) (Fq (14 * a + v) i0) = 1 := by
  have h := fam_ind a v i0 (isp (14 * a + v) i0) 1 0 (kind_sst a v i0 hv).2.1 (fun k => (kind_ord a v i0 k hv).2.1) hi
  show isp (14 * a + v) i0 (7 * (14 * a + v)) + gs (isp (14 * a + v) i0) (fam (14 * a + v) i0) = 1
  rw [(kind_half a v i0).2.1]
  rw [show (14 * a + v) * 0 + 1 = 1 by lib_nat] at h
  rw [show gs (isp (14 * a + v) i0) (fam (14 * a + v) i0) = 1 from h]

theorem tot_io (a v i0 : Nat) (hv : v = 3 ∨ v = 5) (hi : i0 < 14 * a + v) :
    gs (io (14 * a + v) i0) (Fq (14 * a + v) i0) + 1 = 14 * a + v := by
  have h := fam_ind a v i0 (io (14 * a + v) i0) 0 1 (kind_sst a v i0 hv).1 (fun k => (kind_ord a v i0 k hv).1) hi
  show io (14 * a + v) i0 (7 * (14 * a + v)) + gs (io (14 * a + v) i0) (fam (14 * a + v) i0) + 1 = 14 * a + v
  rw [(kind_half a v i0).1]
  rw [show (14 * a + v) * 1 + 0 = 14 * a + v by lib_nat] at h
  rw [show 0 + gs (io (14 * a + v) i0) (fam (14 * a + v) i0) + 1 = gs (io (14 * a + v) i0) (fam (14 * a + v) i0) + 1 by lib_nat]
  exact h

/-- Σ_A x = n₁ + δ(1 + 6p) + η·7p + 14K for A ⊆ Fq -/
theorem sum_decomp (a v i0 : Nat) (hv : v = 3 ∨ v = 5) : ∀ A : List Nat, (∀ x, x ∈ A → x ∈ Fq (14 * a + v) i0) →
    ∃ K, gs (fun x => x) A = gs (io (14 * a + v) i0) A + gs (isp (14 * a + v) i0) A * (1 + 6 * (14 * a + v))
      + gs (ih (14 * a + v)) A * (7 * (14 * a + v)) + 14 * K
  | [], _ => ⟨0, by show 0 = 0 + 0 * _ + 0 * _ + 14 * 0; lib_nat⟩
  | x :: A, hA => by
    have ⟨K, hK⟩ := sum_decomp a v i0 hv A (fun y hy => hA y (List.Mem.tail _ hy))
    have hx : x ∈ 7 * (14 * a + v) :: fam (14 * a + v) i0 := hA x (List.Mem.head _)
    show ∃ K', x + gs (fun x => x) A = (io (14 * a + v) i0 x + gs (io (14 * a + v) i0) A)
        + (isp (14 * a + v) i0 x + gs (isp (14 * a + v) i0) A) * (1 + 6 * (14 * a + v))
        + (ih (14 * a + v) x + gs (ih (14 * a + v)) A) * (7 * (14 * a + v)) + 14 * K'
    rw [hK]
    cases hx with
    | head =>
      have ⟨e1, e2, e3⟩ := kind_half a v i0
      rw [e1, e2, e3]; exact ⟨K, by lib_nat⟩
    | tail _ hf =>
      rcases fam_kind _ i0 x hf with e | ⟨k, _, _, e⟩
      · subst e
        have ⟨e1, e2, e3⟩ := kind_sst a v i0 hv
        rw [e1, e2, e3]; exact ⟨K + i0, by unfold sst; lib_nat⟩
      · subst e
        have ⟨e1, e2, e3⟩ := kind_ord a v i0 k hv
        rw [e1, e2, e3]; exact ⟨K + k, by lib_nat⟩

end CosetSplitA

#print axioms CosetSplitA.res_of
#print axioms CosetSplitA.beq_false_res
#print axioms CosetSplitA.res_ord
#print axioms CosetSplitA.res_half
#print axioms CosetSplitA.res_sst
#print axioms CosetSplitA.kind_ord
#print axioms CosetSplitA.kind_sst
#print axioms CosetSplitA.kind_half
#print axioms CosetSplitA.kind_sum
#print axioms CosetSplitA.fam_kind
#print axioms CosetSplitA.gs_add3
#print axioms CosetSplitA.gs_one
#print axioms CosetSplitA.gs_congr'
#print axioms CosetSplitA.len_counts
#print axioms CosetSplitA.sumF_const'
#print axioms CosetSplitA.sum_ite
#print axioms CosetSplitA.fam_ind
#print axioms CosetSplitA.tot_ih
#print axioms CosetSplitA.tot_isp
#print axioms CosetSplitA.tot_io
#print axioms CosetSplitA.sum_decomp

#print axioms: 21 theorems, no axioms.

81.241 The coset conditions of a completed part

On a part \(c::A\) of a completed split of \(7p::F_p\), balanced at \(14p\), the coset \(\rho \) condition reads \(W D_\rho +f_\rho (c)=0\) with \(W=n_1-\delta (p-1)\).

hodge/CosetSplitB.lean

/-
  hodge/CosetSplitB.lean — T41 cycle 1932 (goal G862c, step 3e, part B): on a part c :: A of a completed split of
  Fq = 7p :: F_p (p = 14a + v), balanced at 14p, the coset ρ condition reads
      W·D_ρ + f_ρ(c) = 0,   W = n₁ − δ(p − 1),  D_ρ = ρ − ⟨ρx₀⟩_14,
  where omitR(c) = 14S + p·f_ρ(c) (CosetDev) and n₁, δ are the counts of ordinary and special elements of A
  (CosetSplitA). Lean 4 core plus hodge/CosetWeight, hodge/CosetSplitA; no axioms.
-/
import hodge.CosetWeight
import hodge.CosetSplitA

namespace CosetSplitB
open GcdHand ModHand OrbitSum PermSum FamMod FamArith Indecomp FamIndec2 FamIndec3 FamBal QFamPrime CosetAvg CosetBal
  CosetDev CosetWeight CosetSplitA

/-- part_zero with the sum of omitR given directly -/
theorem part_zero' (p ρ j0 : Nat) (hp : 0 < p) (hpr : ∀ d, d ∣ p → d = 1 ∨ d = p) (h14 : Nat.gcd 14 p = 1)
    (hρ14 : Nat.gcd ρ 14 = 1) (hρ : ρ < 14) (hj : j0 < p) (h0 : p ∣ ρ + 14 * j0) (L : List Nat)
    (hb : bal (14 * p) L = true) (T : Int)
    (hT : gsI (fun x => (omitR p ρ j0 x : Int)) L = (L.length : Int) * (14 * (sumF (fun i => i) p : Nat)) + (p : Int) * T) :
    T = 0 := by
  have h := congrArg Int.ofNat (coset_bal p ρ j0 hp hpr h14 hρ14 hρ hj h0 L hb)
  have h' : ((gs (fun x => omitR p ρ j0 x) L : Nat) : Int) + ((gs (fun x => omitR p ρ j0 x) L : Nat) : Int)
      + (L.length : Int) * (14 * p) = (p : Int) * ((L.length : Int) * (14 * p)) := h
  rw [gs_cast, hT] at h'
  have hS := sumS p
  apply int_cancel (2 * p) _ (Nat.mul_pos (Nat.succ_pos 1) hp)
  generalize ((sumF (fun i => i) p : Nat) : Int) = S at h' hS
  generalize (L.length : Int) = n at h'
  show (2 : Int) * p * T = 0
  calc (2 : Int) * p * T
      = ((n * (14 * S) + p * T) + (n * (14 * S) + p * T) + n * (14 * p)) - 14 * n * (S + S + p) := by lib_int
    _ = p * (n * (14 * p)) - 14 * n * (S + S + p) := by rw [h']
    _ = p * (n * (14 * p)) - 14 * n * (p * p) := by rw [hS]
    _ = 0 := by lib_int

/-- the coset weight of an element: 1 (ordinary), −(p − 1) (special), 0 (7p) -/
def wI (p i0 x : Nat) : Int := (io p i0 x : Int) - (isp p i0 x : Int) * ((p : Int) - 1)

theorem gsI_wI (p i0 : Nat) : ∀ A : List Nat,
    gsI (wI p i0) A = (gs (io p i0) A : Int) - (gs (isp p i0) A : Int) * ((p : Int) - 1)
  | [] => by show (0 : Int) = ((0 : Nat) : Int) - ((0 : Nat) : Int) * _; show (0 : Int) = 0 - 0 * _; lib_int
  | x :: A => by
    show wI p i0 x + gsI (wI p i0) A = ((io p i0 x + gs (io p i0) A : Nat) : Int)
      - ((isp p i0 x + gs (isp p i0) A : Nat) : Int) * ((p : Int) - 1)
    rw [gsI_wI p i0 A]
    show (io p i0 x : Int) - (isp p i0 x : Int) * ((p : Int) - 1)
        + ((gs (io p i0) A : Int) - (gs (isp p i0) A : Int) * ((p : Int) - 1))
      = ((io p i0 x : Int) + (gs (io p i0) A : Int)) - ((isp p i0 x : Int) + (gs (isp p i0) A : Int)) * ((p : Int) - 1)
    lib_int

/-- every element of Fq has omitR = 14S + p·(w·D_ρ) -/
theorem elem_dev (a v i0 x0 ρ j0 y : Nat) (hv : v = 3 ∨ v = 5) (hpr : ∀ d, d ∣ (14 * a + v) → d = 1 ∨ d = 14 * a + v)
    (h14 : Nat.gcd 14 (14 * a + v) = 1) (hi : i0 < 14 * a + v) (hx : 1 + 14 * i0 = (14 * a + v) * x0)
    (hρ : ρ < 14) (hj : j0 < 14 * a + v) (ht : ρ + 14 * j0 = (14 * a + v) * y)
    (hT : (((ρ * (x0 + 6)) % 14 : Nat) : Int) - 7 = (((ρ * x0) % 14 : Nat) : Int) - ρ) (hT7 : (ρ * 7) % 14 = 7)
    (x : Nat) (hxF : x ∈ Fq (14 * a + v) i0) :
    (omitR (14 * a + v) ρ j0 x : Int) = 14 * (sumF (fun i => i) (14 * a + v) : Nat)
      + ((14 * a + v : Nat) : Int) * (wI (14 * a + v) i0 x * ((ρ : Int) - ((ρ * x0) % 14 : Nat))) := by
  have hp : 0 < 14 * a + v := Nat.lt_of_le_of_lt (Nat.zero_le _) hi
  have h0 : (14 * a + v) ∣ 1 + 14 * i0 := ⟨x0, hx⟩
  have hx' : x ∈ 7 * (14 * a + v) :: fam (14 * a + v) i0 := hxF
  cases hx' with
  | head =>
    have ⟨e1, e2, _⟩ := kind_half a v i0
    unfold wI; rw [e1, e2, show 7 * (14 * a + v) = (14 * a + v) * 7 by lib_nat, f_half _ ρ j0 hj hT7]
    show _ = _ + ((14 * a + v : Nat) : Int) * ((((0 : Nat) : Int) - ((0 : Nat) : Int) * _) * _)
    show _ = _ + ((14 * a + v : Nat) : Int) * (((0 : Int) - 0 * _) * _)
    lib_int
  | tail _ hf =>
    rcases fam_kind _ i0 x hf with e | ⟨k, hk, hk0, e⟩
    · subst e
      have ⟨e1, e2, _⟩ := kind_sst a v i0 hv
      unfold wI; rw [e1, e2]
      rw [show sst (14 * a + v) i0 = (14 * a + v) * (x0 + 6) by unfold sst; rw [show 1 + 14 * i0 + 6 * (14 * a + v) = (1 + 14 * i0) + 6 * (14 * a + v) by lib_nat, hx]; lib_nat]
      rw [f_spec _ ρ j0 x0 hj hT]
      show _ = _ + ((14 * a + v : Nat) : Int) * (((0 : Int) - 1 * _) * _)
      lib_int
    · subst e
      have ⟨e1, e2, _⟩ := kind_ord a v i0 k hv
      unfold wI; rw [e1, e2]
      rw [f_ord _ ρ j0 y i0 x0 k hρ hj ht hx (cop_coset _ k i0 hp hpr h14 hk hi h0 hk0)]
      show _ = _ + ((14 * a + v : Nat) : Int) * (((1 : Int) - 0 * _) * _)
      lib_int

/-- **The coset ρ condition of a part c :: A.** -/
theorem part_eq (a v i0 x0 ρ j0 y : Nat) (hv : v = 3 ∨ v = 5) (hpr : ∀ d, d ∣ (14 * a + v) → d = 1 ∨ d = 14 * a + v)
    (h14 : Nat.gcd 14 (14 * a + v) = 1) (hi : i0 < 14 * a + v) (hx : 1 + 14 * i0 = (14 * a + v) * x0)
    (hρ14 : Nat.gcd ρ 14 = 1) (hρ : ρ < 14) (hj : j0 < 14 * a + v) (ht : ρ + 14 * j0 = (14 * a + v) * y)
    (hT : (((ρ * (x0 + 6)) % 14 : Nat) : Int) - 7 = (((ρ * x0) % 14 : Nat) : Int) - ρ) (hT7 : (ρ * 7) % 14 = 7)
    (A : List Nat) (hA : ∀ x, x ∈ A → x ∈ Fq (14 * a + v) i0) (c : Nat) (fc : Int)
    (hc : (omitR (14 * a + v) ρ j0 c : Int) = 14 * (sumF (fun i => i) (14 * a + v) : Nat) + ((14 * a + v : Nat) : Int) * fc)
    (hb : bal (14 * (14 * a + v)) (c :: A) = true) :
    ((gs (io (14 * a + v) i0) A : Int) - (gs (isp (14 * a + v) i0) A : Int) * (((14 * a + v : Nat) : Int) - 1))
      * ((ρ : Int) - ((ρ * x0) % 14 : Nat)) + fc = 0 := by
  have hp : 0 < 14 * a + v := Nat.lt_of_le_of_lt (Nat.zero_le _) hi
  have h0j : (14 * a + v) ∣ ρ + 14 * j0 := ⟨y, ht⟩
  have hsumA := gsI_affine (fun x => (omitR (14 * a + v) ρ j0 x : Int))
    (fun x => wI (14 * a + v) i0 x * ((ρ : Int) - ((ρ * x0) % 14 : Nat)))
    (14 * (sumF (fun i => i) (14 * a + v) : Nat)) ((14 * a + v : Nat) : Int) A
    (fun x hxA => elem_dev a v i0 x0 ρ j0 y hv hpr h14 hi hx hρ hj ht hT hT7 x (hA x hxA))
  have hW := gsI_affine (fun x => wI (14 * a + v) i0 x * ((ρ : Int) - ((ρ * x0) % 14 : Nat)))
    (wI (14 * a + v) i0) 0 ((ρ : Int) - ((ρ * x0) % 14 : Nat)) A (fun x _ => by lib_int)
  rw [gsI_wI] at hW
  have key := part_zero' (14 * a + v) ρ j0 hp hpr h14 hρ14 hρ hj h0j (c :: A) hb
    (fc + ((gs (io (14 * a + v) i0) A : Int) - (gs (isp (14 * a + v) i0) A : Int) * (((14 * a + v : Nat) : Int) - 1))
      * ((ρ : Int) - ((ρ * x0) % 14 : Nat)))
    (by
      show (omitR (14 * a + v) ρ j0 c : Int) + gsI (fun x => (omitR (14 * a + v) ρ j0 x : Int)) A = _
      rw [hc, hsumA, hW]
      show _ = ((A.length + 1 : Nat) : Int) * _ + _
      show _ = ((A.length : Int) + 1) * _ + _
      lib_int)
  calc _ = fc + ((gs (io (14 * a + v) i0) A : Int) - (gs (isp (14 * a + v) i0) A : Int) * (((14 * a + v : Nat) : Int) - 1))
      * ((ρ : Int) - ((ρ * x0) % 14 : Nat)) := by lib_int
    _ = 0 := key

end CosetSplitB

#print axioms CosetSplitB.part_zero'
#print axioms CosetSplitB.gsI_wI
#print axioms CosetSplitB.elem_dev
#print axioms CosetSplitB.part_eq

#print axioms: 4 theorems, no axioms.

81.242 Residues of \(x_0\) and the coset index

\(x_0\bmod 14\in \{3,5\}\), the coset index \(j_0\), and the coset conditions in the form of the residue tables.

hodge/CosetSplitC.lean

/-
  hodge/CosetSplitC.lean — T41 cycle 1932 (goal G862c, step 3f): every completed split of the halved doubled
  character Fq = 7p :: F_p (p = 14a + v, v ∈ {3, 5}, p prime, FamBal data 1 + 14i₀ = p·x₀) whose part c :: A is
  balanced at 14p (c + (Σ_A x mod 14p) = 14p) has |A| ≤ 1 or |B| ≤ 1:
    split_small
  Proof: the three coset conditions ρ = 1, 3, 5 (CosetSplitB.part_eq, with c a unit mod p or a multiple of p),
  the residue tables (CosetElim), and the size arithmetic (CosetSize) with the counts of CosetSplitA.
  Lean 4 core plus hodge/CosetSplitB, hodge/CosetElim, hodge/CosetSize; no axioms.
-/
import hodge.CosetSplitB
import hodge.CosetElim
import hodge.CosetSize

namespace CosetSplitC
open GcdHand ModHand OrbitSum PermSum FamMod FamArith Indecomp FamIndec2 FamIndec3 FamBal QFamPrime CosetAvg CosetBal
  CosetDev CosetWeight CosetSplitA CosetSplitB

theorem nat_ne (a b : Nat) (h : Nat.beq a b = false) : a ≠ b := fun e => by rw [e, beq_refl'] at h; exact nomatch h

theorem mod14 (r x : Nat) (hr : r < 14) : (r * x) % 14 = (r * (x % 14)) % 14 := by
  rw [mul_mod' 14 r x (Nat.succ_pos 13), mod_lt' r 14 hr]

/-- x₀ mod 14 from p·x₀ ≡ 1 -/
theorem u_of (a v i0 x0 : Nat) (hv : v = 3 ∨ v = 5) (hx : 1 + 14 * i0 = (14 * a + v) * x0) :
    (v = 3 ∧ x0 % 14 = 5) ∨ (v = 5 ∧ x0 % 14 = 3) := by
  have h1 : ((14 * a + v) * x0) % 14 = 1 := by rw [← hx]; exact CosetSplitA.res_ord i0
  have hu : x0 % 14 < 14 := Nat.mod_lt _ (Nat.succ_pos 13)
  rcases hv with h | h <;> subst h
  · have h2 : (3 * (x0 % 14)) % 14 = 1 := by
      rw [← mod14 3 x0 (Nat.le.intro (k := 10) rfl), ← add_mul_mod' (3 * x0) 14 (Nat.succ_pos 13) (a * x0),
        show 3 * x0 + a * x0 * 14 = (14 * a + 3) * x0 by lib_nat]
      exact h1
    left; refine ⟨rfl, ?_⟩
    generalize x0 % 14 = u at h2 hu ⊢
    rcases CosetElim.lt14 u hu with e | e | e | e | e | e | e | e | e | e | e | e | e | e <;> subst e
    all_goals first | rfl | exact absurd h2 (nat_ne _ _ rfl)
  · have h2 : (5 * (x0 % 14)) % 14 = 1 := by
      rw [← mod14 5 x0 (Nat.le.intro (k := 8) rfl), ← add_mul_mod' (5 * x0) 14 (Nat.succ_pos 13) (a * x0),
        show 5 * x0 + a * x0 * 14 = (14 * a + 5) * x0 by lib_nat]
      exact h1
    right; refine ⟨rfl, ?_⟩
    generalize x0 % 14 = u at h2 hu ⊢
    rcases CosetElim.lt14 u hu with e | e | e | e | e | e | e | e | e | e | e | e | e | e <;> subst e
    all_goals first | rfl | exact absurd h2 (nat_ne _ _ rfl)

/-- the coset index j₀ = ρi₀ mod p, with p ∣ ρ + 14j₀ -/
theorem jy (p ρ i0 x0 : Nat) (hp : 0 < p) (hx : 1 + 14 * i0 = p * x0) :
    ∃ j0 y, j0 < p ∧ ρ + 14 * j0 = p * y := by
  have hj : (ρ * i0) % p < p := Nat.mod_lt _ hp
  obtain ⟨q, hq⟩ := div_mod p hp (ρ * i0 + 1) (ρ * i0) (Nat.lt_succ_self _)
  generalize (ρ * i0) % p = j0 at hq hj
  have e : p * (ρ * x0) = (ρ + 14 * j0) + p * (14 * q) := by
    calc p * (ρ * x0) = ρ * (p * x0) := by lib_nat
      _ = ρ * (1 + 14 * i0) := by rw [hx]
      _ = ρ + 14 * (ρ * i0) := by lib_nat
      _ = ρ + 14 * (j0 + p * q) := by rw [hq]
      _ = _ := by lib_nat
  have ⟨y, hy⟩ := APPair1.dvd_sub_form p (ρ + 14 * j0) (14 * q) (ρ * x0) e
  exact ⟨j0, y, hj, hy⟩

/-- the unit case of the coset equation, in the form of CosetElim -/
theorem unit_form (ρ x0 u c g y : Nat) (W : Int) (hρ : ρ < 14) (hu : x0 % 14 = u) (hg : c % 14 = g)
    (hy : y % 14 = (ρ * x0) % 14)
    (h : W * ((ρ : Int) - ((ρ * x0) % 14 : Nat)) + ((((ρ * c) % 14 : Nat) : Int) - ((y * c) % 14 : Nat)) = 0) :
    W * CosetElim.D ρ u + CosetElim.F ρ u g = 0 := by
  have e1 : (ρ * x0) % 14 = (ρ * u) % 14 := by rw [mod14 ρ x0 hρ, hu]
  have e2 : (ρ * c) % 14 = (ρ * g) % 14 := by rw [mod14 ρ c hρ, hg]
  have hg14 : g < 14 := by rw [← hg]; exact Nat.mod_lt _ (Nat.succ_pos 13)
  have e3 : (y * c) % 14 = (ρ * u * g) % 14 := by
    rw [mul_mod' 14 y c (Nat.succ_pos 13), hy, hg, e1, mul_mod' 14 (ρ * u) g (Nat.succ_pos 13), mod_lt' g 14 hg14]
  rw [e1, e2, e3] at h
  exact h

/-- the divisible case, in the form of CosetElim -/
theorem div_form (ρ x0 u e k : Nat) (W : Int) (hρ : ρ < 14) (hu : x0 % 14 = u)
    (h : W * ((ρ : Int) - ((ρ * x0) % 14 : Nat)) + (k : Int) * ((((ρ * e) % 14 : Nat) : Int) - 7) = 0) :
    W * CosetElim.D ρ u + (k : Int) * CosetElim.G ρ (e % 14) = 0 := by
  have e1 : (ρ * x0) % 14 = (ρ * u) % 14 := by rw [mod14 ρ x0 hρ, hu]
  have e2 : (ρ * e) % 14 = (ρ * (e % 14)) % 14 := mod14 ρ e hρ
  rw [e1, e2] at h
  exact h

end CosetSplitC

#print axioms CosetSplitC.nat_ne
#print axioms CosetSplitC.mod14
#print axioms CosetSplitC.u_of
#print axioms CosetSplitC.jy
#print axioms CosetSplitC.unit_form
#print axioms CosetSplitC.div_form

#print axioms: 6 theorems, no axioms.

81.243 A completed part has at most one or at least \(p\) elements

For \(c::A\) balanced at \(14p\) with \(c+\sum A\equiv 0\pmod {14}\): \(|A|\le 1\) or \(|A|\ge p\).

hodge/CosetSplitD.lean

/-
  hodge/CosetSplitD.lean — T41 cycle 1934 (goal G862c, step 3g): a completed part c :: A of the halved doubled
  character Fq = 7p :: F_p (p = 14a + v, v ∈ {3, 5}, p prime, FamBal data 1 + 14i₀ = p·x₀), balanced at 14p with
  c + Σ_A x ≡ 0 (mod 14), has |A| ≤ 1 or |A| ≥ p:
    part_small
  Proof: the coset conditions ρ = 1, 3, 5 (CosetSplitB.part_eq, c a unit mod p or c = p·e), the residue
  tables (CosetElim), and the size arithmetic (CosetSize) with the counts of CosetSplitA.
  Lean 4 core plus hodge/CosetSplitC, hodge/CosetSize; no axioms.
-/
import hodge.CosetSplitC
import hodge.CosetSize

namespace CosetSplitD
open GcdHand ModHand OrbitSum PermSum FamMod FamArith Indecomp FamIndec2 FamIndec3 FamBal QFamPrime CosetAvg CosetBal
  CosetDev CosetWeight CosetSplitA CosetSplitB CosetSplitC CosetSize

theorem add6 (x : Nat) : (x + 6) % 14 = (x % 14 + 6) % 14 := by
  have ⟨q, hq⟩ := div_mod 14 (Nat.succ_pos 13) (x + 1) x (Nat.lt_succ_self x)
  generalize x % 14 = r at hq ⊢
  rw [hq, show r + 14 * q + 6 = (r + 6) + q * 14 by lib_nat, add_mul_mod' (r + 6) 14 (Nat.succ_pos 13) q]

theorem hT_of (ρ x0 u : Nat) (hρ : ρ < 14) (hu : x0 % 14 = u)
    (hchk : ((((ρ * (u + 6)) % 14 : Nat) : Int) - 7 = (((ρ * u) % 14 : Nat) : Int) - ρ)) :
    ((((ρ * (x0 + 6)) % 14 : Nat) : Int) - 7 = (((ρ * x0) % 14 : Nat) : Int) - ρ) := by
  rw [mod14 ρ (x0 + 6) hρ, add6, hu, ← mod14 ρ (u + 6) hρ, mod14 ρ x0 hρ, hu]
  exact hchk

theorem y_res (p ρ i0 x0 j0 y : Nat) (hx : 1 + 14 * i0 = p * x0) (ht : ρ + 14 * j0 = p * y) :
    y % 14 = (ρ * x0) % 14 := by
  have e : ρ * x0 + (j0 * x0) * 14 = y + (y * i0) * 14 :=
    calc ρ * x0 + (j0 * x0) * 14 = (ρ + 14 * j0) * x0 := by lib_nat
      _ = (p * y) * x0 := by rw [ht]
      _ = y * (p * x0) := by lib_nat
      _ = y * (1 + 14 * i0) := by rw [hx]
      _ = y + (y * i0) * 14 := by lib_nat
  rw [← add_mul_mod' (ρ * x0) 14 (Nat.succ_pos 13) (j0 * x0), e, add_mul_mod' y 14 (Nat.succ_pos 13) (y * i0)]

theorem mod_cond (c n1 δ η K P Q : Nat) (hs : (c + (n1 + δ * P + η * Q + 14 * K)) % 14 = 0) :
    (c % 14 + n1 + δ * P + η * Q) % 14 = 0 := by
  have ⟨q, hq⟩ := div_mod 14 (Nat.succ_pos 13) (c + 1) c (Nat.lt_succ_self c)
  have e : c + (n1 + δ * P + η * Q + 14 * K) = (c % 14 + n1 + δ * P + η * Q) + (q + K) * 14 := by
    generalize c % 14 = r at hq ⊢
    rw [hq]; lib_nat
  rw [e, add_mul_mod' _ 14 (Nat.succ_pos 13) (q + K)] at hs
  exact hs

/-- the coset ρ condition for a completion c prime to p, in the form of CosetElim -/
theorem unit_cond (a v i0 x0 u ρ : Nat) (hv : v = 3 ∨ v = 5) (hpr : ∀ d, d ∣ (14 * a + v) → d = 1 ∨ d = 14 * a + v)
    (h14 : Nat.gcd 14 (14 * a + v) = 1) (hi : i0 < 14 * a + v) (hx : 1 + 14 * i0 = (14 * a + v) * x0)
    (hu : x0 % 14 = u) (hρ14 : Nat.gcd ρ 14 = 1) (hρ : ρ < 14)
    (hchk : ((((ρ * (u + 6)) % 14 : Nat) : Int) - 7 = (((ρ * u) % 14 : Nat) : Int) - ρ)) (hT7 : (ρ * 7) % 14 = 7)
    (A : List Nat) (hA : ∀ x, x ∈ A → x ∈ Fq (14 * a + v) i0) (c g : Nat) (hcop : Nat.gcd c (14 * a + v) = 1)
    (hg : c % 14 = g) (hb : bal (14 * (14 * a + v)) (c :: A) = true) :
    ((gs (io (14 * a + v) i0) A : Int) - (gs (isp (14 * a + v) i0) A : Int) * (((14 * a + v : Nat) : Int) - 1))
      * CosetElim.D ρ u + CosetElim.F ρ u g = 0 := by
  have hp : 0 < 14 * a + v := Nat.lt_of_le_of_lt (Nat.zero_le _) hi
  have ⟨j0, y, hj, ht⟩ := jy (14 * a + v) ρ i0 x0 hp hx
  have h := part_eq a v i0 x0 ρ j0 y hv hpr h14 hi hx hρ14 hρ hj ht (hT_of ρ x0 u hρ hu hchk) hT7 A hA c _
    (dev_unit (14 * a + v) ρ j0 y c hj ht hcop) hb
  exact unit_form ρ x0 u c g y _ hρ hu hg (y_res _ ρ i0 x0 j0 y hx ht) h

/-- the coset ρ condition for a completion c = p·e, in the form of CosetElim -/
theorem div_cond (a v i0 x0 u ρ : Nat) (hv : v = 3 ∨ v = 5) (hpr : ∀ d, d ∣ (14 * a + v) → d = 1 ∨ d = 14 * a + v)
    (h14 : Nat.gcd 14 (14 * a + v) = 1) (hi : i0 < 14 * a + v) (hx : 1 + 14 * i0 = (14 * a + v) * x0)
    (hu : x0 % 14 = u) (hρ14 : Nat.gcd ρ 14 = 1) (hρ : ρ < 14)
    (hchk : ((((ρ * (u + 6)) % 14 : Nat) : Int) - 7 = (((ρ * u) % 14 : Nat) : Int) - ρ)) (hT7 : (ρ * 7) % 14 = 7)
    (A : List Nat) (hA : ∀ x, x ∈ A → x ∈ Fq (14 * a + v) i0) (e k : Nat)
    (hk : (k : Int) = ((14 * a + v : Nat) : Int) - 1)
    (hb : bal (14 * (14 * a + v)) ((14 * a + v) * e :: A) = true) :
    ((gs (io (14 * a + v) i0) A : Int) - (gs (isp (14 * a + v) i0) A : Int) * (((14 * a + v : Nat) : Int) - 1))
      * CosetElim.D ρ u + (k : Int) * CosetElim.G ρ (e % 14) = 0 := by
  have hp : 0 < 14 * a + v := Nat.lt_of_le_of_lt (Nat.zero_le _) hi
  have ⟨j0, y, hj, ht⟩ := jy (14 * a + v) ρ i0 x0 hp hx
  have h := part_eq a v i0 x0 ρ j0 y hv hpr h14 hi hx hρ14 hρ hj ht (hT_of ρ x0 u hρ hu hchk) hT7 A hA
    ((14 * a + v) * e) _ (dev_div (14 * a + v) ρ j0 e hj) hb
  apply div_form ρ x0 u e k _ hρ hu
  rw [hk]
  exact h

/-- p = 14a + 5 (x₀ ≡ 3 mod 14) -/
theorem part_small5 (a i0 x0 : Nat) (hpr : ∀ d, d ∣ (14 * a + 5) → d = 1 ∨ d = 14 * a + 5)
    (h14 : Nat.gcd 14 (14 * a + 5) = 1) (hi : i0 < 14 * a + 5) (hx : 1 + 14 * i0 = (14 * a + 5) * x0)
    (hu : x0 % 14 = 3) (A : List Nat) (hA : ∀ x, x ∈ A → x ∈ Fq (14 * a + 5) i0)
    (hδ : gs (isp (14 * a + 5) i0) A ≤ 1) (hη : gs (ih (14 * a + 5)) A ≤ 1)
    (hn : gs (io (14 * a + 5) i0) A + 1 ≤ 14 * a + 5)
    (c : Nat) (hs : (c + gs (fun x => x) A) % 14 = 0) (hb : bal (14 * (14 * a + 5)) (c :: A) = true) :
    A.length ≤ 1 ∨ 14 * a + 5 ≤ A.length := by
  have hv : ((5 : Nat) = 3 ∨ (5 : Nat) = 5) := Or.inr rfl
  rw [← len_counts (14 * a + 5) i0 A]
  have ⟨K, hK⟩ := sum_decomp a 5 i0 hv A hA
  rw [hK] at hs
  have hgm := mod_cond c _ _ _ K _ _ hs
  have hW : ((gs (io (14 * a + 5) i0) A : Int) - (gs (isp (14 * a + 5) i0) A : Int) * (((14 * a + 5 : Nat) : Int) - 1))
      = (gs (io (14 * a + 5) i0) A : Int) - (gs (isp (14 * a + 5) i0) A : Int) * (14 * (a : Int) + 4) := by
    rw [show ((14 * a + 5 : Nat) : Int) = 14 * (a : Int) + 5 from rfl]
    lib_int
  have ⟨⟨i, hci⟩, ⟨j, hpj⟩⟩ := UnitMul.gcd_dvd c (14 * a + 5)
  rcases hpr _ ⟨j, hpj⟩ with h1 | h1
  · have hg14 : c % 14 < 14 := Nat.mod_lt _ (Nat.succ_pos 13)
    have e1 := unit_cond a 5 i0 x0 3 1 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 12) rfl) rfl rfl A hA c (c % 14) h1 rfl hb
    have e3 := unit_cond a 5 i0 x0 3 3 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 10) rfl) rfl rfl A hA c (c % 14) h1 rfl hb
    have e5 := unit_cond a 5 i0 x0 3 5 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 8) rfl) rfl rfl A hA c (c % 14) h1 rfl hb
    rcases CosetElim.elim_unit3 (c % 14) hg14 _ e1 e3 e5 with ⟨hw, hg⟩ | ⟨hw, _⟩ | ⟨hw, hg⟩
    · exact size5 a _ _ _ (c % 14) _ hδ hη hn hW hgm (Or.inl ⟨hw, hg⟩)
    · exact size5 a _ _ _ (c % 14) _ hδ hη hn hW hgm (Or.inr (Or.inl hw))
    · exact size5 a _ _ _ (c % 14) _ hδ hη hn hW hgm (Or.inr (Or.inr (Or.inl ⟨hw, hg⟩)))
  · rw [h1] at hci
    subst hci
    have hk : ((14 * a + 4 : Nat) : Int) = ((14 * a + 5 : Nat) : Int) - 1 := by
      rw [show ((14 * a + 4 : Nat) : Int) = 14 * (a : Int) + 4 from rfl,
        show ((14 * a + 5 : Nat) : Int) = 14 * (a : Int) + 5 from rfl]
      lib_int
    have hk0 : 0 < 14 * a + 4 := Nat.succ_pos _
    have he14 : i % 14 < 14 := Nat.mod_lt _ (Nat.succ_pos 13)
    have e1 := div_cond a 5 i0 x0 3 1 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 12) rfl) rfl rfl A hA i _ hk hb
    have e3 := div_cond a 5 i0 x0 3 3 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 10) rfl) rfl rfl A hA i _ hk hb
    have e5 := div_cond a 5 i0 x0 3 5 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 8) rfl) rfl rfl A hA i _ hk hb
    have hgc : ((14 * a + 5) * i) % 14 = (5 * (i % 14)) % 14 := by
      rw [show (14 * a + 5) * i = 5 * i + (a * i) * 14 by lib_nat, add_mul_mod' _ 14 (Nat.succ_pos 13),
        mod14 5 i (Nat.le.intro (k := 8) rfl)]
    rcases CosetElim.elim_div3 (i % 14) he14 _ _ hk0 e1 e3 e5 with ⟨hw, _⟩ | ⟨hw, he⟩ | ⟨hw, he⟩
    · exact size5 a _ _ _ _ _ hδ hη hn hW hgm (Or.inr (Or.inl hw))
    · exact size5 a _ _ _ _ _ hδ hη hn hW hgm
        (Or.inr (Or.inr (Or.inr (Or.inl ⟨by rw [hw] <;> rfl, by rw [hgc, he] <;> rfl⟩))))
    · exact size5 a _ _ _ _ _ hδ hη hn hW hgm
        (Or.inr (Or.inr (Or.inr (Or.inr ⟨by rw [hw] <;> rfl, by rw [hgc, he] <;> rfl⟩))))

/-- p = 14a + 3 (x₀ ≡ 5 mod 14) -/
theorem part_small3 (a i0 x0 : Nat) (hpr : ∀ d, d ∣ (14 * a + 3) → d = 1 ∨ d = 14 * a + 3)
    (h14 : Nat.gcd 14 (14 * a + 3) = 1) (hi : i0 < 14 * a + 3) (hx : 1 + 14 * i0 = (14 * a + 3) * x0)
    (hu : x0 % 14 = 5) (A : List Nat) (hA : ∀ x, x ∈ A → x ∈ Fq (14 * a + 3) i0)
    (hδ : gs (isp (14 * a + 3) i0) A ≤ 1) (hη : gs (ih (14 * a + 3)) A ≤ 1)
    (hn : gs (io (14 * a + 3) i0) A + 1 ≤ 14 * a + 3)
    (c : Nat) (hs : (c + gs (fun x => x) A) % 14 = 0) (hb : bal (14 * (14 * a + 3)) (c :: A) = true) :
    A.length ≤ 1 ∨ 14 * a + 3 ≤ A.length := by
  have hv : ((3 : Nat) = 3 ∨ (3 : Nat) = 5) := Or.inl rfl
  rw [← len_counts (14 * a + 3) i0 A]
  have ⟨K, hK⟩ := sum_decomp a 3 i0 hv A hA
  rw [hK] at hs
  have hgm := mod_cond c _ _ _ K _ _ hs
  have hW : ((gs (io (14 * a + 3) i0) A : Int) - (gs (isp (14 * a + 3) i0) A : Int) * (((14 * a + 3 : Nat) : Int) - 1))
      = (gs (io (14 * a + 3) i0) A : Int) - (gs (isp (14 * a + 3) i0) A : Int) * (14 * (a : Int) + 2) := by
    rw [show ((14 * a + 3 : Nat) : Int) = 14 * (a : Int) + 3 from rfl]
    lib_int
  have ⟨⟨i, hci⟩, ⟨j, hpj⟩⟩ := UnitMul.gcd_dvd c (14 * a + 3)
  rcases hpr _ ⟨j, hpj⟩ with h1 | h1
  · have hg14 : c % 14 < 14 := Nat.mod_lt _ (Nat.succ_pos 13)
    have e1 := unit_cond a 3 i0 x0 5 1 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 12) rfl) rfl rfl A hA c (c % 14) h1 rfl hb
    have e3 := unit_cond a 3 i0 x0 5 3 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 10) rfl) rfl rfl A hA c (c % 14) h1 rfl hb
    have e5 := unit_cond a 3 i0 x0 5 5 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 8) rfl) rfl rfl A hA c (c % 14) h1 rfl hb
    rcases CosetElim.elim_unit5 (c % 14) hg14 _ e1 e3 e5 with ⟨hw, hg⟩ | ⟨hw, _⟩ | ⟨hw, hg⟩
    · exact size3 a _ _ _ (c % 14) _ hδ hη hn hW hgm (Or.inl ⟨hw, hg⟩)
    · exact size3 a _ _ _ (c % 14) _ hδ hη hn hW hgm (Or.inr (Or.inl hw))
    · exact size3 a _ _ _ (c % 14) _ hδ hη hn hW hgm (Or.inr (Or.inr (Or.inl ⟨hw, hg⟩)))
  · rw [h1] at hci
    subst hci
    have hk : ((14 * a + 2 : Nat) : Int) = ((14 * a + 3 : Nat) : Int) - 1 := by
      rw [show ((14 * a + 2 : Nat) : Int) = 14 * (a : Int) + 2 from rfl,
        show ((14 * a + 3 : Nat) : Int) = 14 * (a : Int) + 3 from rfl]
      lib_int
    have hk0 : 0 < 14 * a + 2 := Nat.succ_pos _
    have he14 : i % 14 < 14 := Nat.mod_lt _ (Nat.succ_pos 13)
    have e1 := div_cond a 3 i0 x0 5 1 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 12) rfl) rfl rfl A hA i _ hk hb
    have e3 := div_cond a 3 i0 x0 5 3 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 10) rfl) rfl rfl A hA i _ hk hb
    have e5 := div_cond a 3 i0 x0 5 5 hv hpr h14 hi hx hu rfl (Nat.le.intro (k := 8) rfl) rfl rfl A hA i _ hk hb
    have hgc : ((14 * a + 3) * i) % 14 = (3 * (i % 14)) % 14 := by
      rw [show (14 * a + 3) * i = 3 * i + (a * i) * 14 by lib_nat, add_mul_mod' _ 14 (Nat.succ_pos 13),
        mod14 3 i (Nat.le.intro (k := 10) rfl)]
    rcases CosetElim.elim_div5 (i % 14) he14 _ _ hk0 e1 e3 e5 with ⟨hw, _⟩ | ⟨hw, he⟩ | ⟨hw, he⟩
    · exact size3 a _ _ _ _ _ hδ hη hn hW hgm (Or.inr (Or.inl hw))
    · exact size3 a _ _ _ _ _ hδ hη hn hW hgm
        (Or.inr (Or.inr (Or.inr (Or.inl ⟨by rw [hw] <;> rfl, by rw [hgc, he] <;> rfl⟩))))
    · exact size3 a _ _ _ _ _ hδ hη hn hW hgm
        (Or.inr (Or.inr (Or.inr (Or.inr ⟨by rw [hw] <;> rfl, by rw [hgc, he] <;> rfl⟩))))

/-- **A completed part of Fq has at most one element or at least p elements.** -/
theorem part_small (a v i0 x0 : Nat) (hv : v = 3 ∨ v = 5) (hpr : ∀ d, d ∣ (14 * a + v) → d = 1 ∨ d = 14 * a + v)
    (h14 : Nat.gcd 14 (14 * a + v) = 1) (hi : i0 < 14 * a + v) (hx : 1 + 14 * i0 = (14 * a + v) * x0)
    (A : List Nat) (hA : ∀ x, x ∈ A → x ∈ Fq (14 * a + v) i0)
    (hδ : gs (isp (14 * a + v) i0) A ≤ 1) (hη : gs (ih (14 * a + v)) A ≤ 1)
    (hn : gs (io (14 * a + v) i0) A + 1 ≤ 14 * a + v)
    (c : Nat) (hs : (c + gs (fun x => x) A) % 14 = 0) (hb : bal (14 * (14 * a + v)) (c :: A) = true) :
    A.length ≤ 1 ∨ 14 * a + v ≤ A.length := by
  rcases u_of a v i0 x0 hv hx with ⟨h3, hu⟩ | ⟨h5, hu⟩
  · subst h3; exact part_small3 a i0 x0 hpr h14 hi hx hu A hA hδ hη hn c hs hb
  · subst h5; exact part_small5 a i0 x0 hpr h14 hi hx hu A hA hδ hη hn c hs hb

end CosetSplitD

#print axioms CosetSplitD.add6
#print axioms CosetSplitD.hT_of
#print axioms CosetSplitD.y_res
#print axioms CosetSplitD.mod_cond
#print axioms CosetSplitD.unit_cond
#print axioms CosetSplitD.div_cond
#print axioms CosetSplitD.part_small5
#print axioms CosetSplitD.part_small3
#print axioms CosetSplitD.part_small

#print axioms: 9 theorems, no axioms.

81.244 Sub-lists, complements and splittings

Every \(A\in \mathrm {subs}\,c\) has a splitting partner \(R\) with the same additive functionals as \(\mathrm {compl}\,c\,A\); \(\mathrm {hodgeB}\) depends only on these.

hodge/SubsSum.lean

/-
  hodge/SubsSum.lean — T41 cycle 1934 (goal G862b, tool): the split step of the inductive closure (OpenCerts)
  in terms of splittings and additive functionals. For A ∈ subs c:
    subs_split   there is R with (A, R) ∈ splits c
    splits_gs    (A, R) ∈ splits c ⇒ gs f A + gs f R = gs f c for every f
    sub_spec     if A is a sub-multiset of c (in the gs sense), sub c A succeeds with the complement
    compl_spec   gs f (compl c A) = gs f R for every f
    hodgeB_congr hodgeB depends on a list only through its additive functionals; lsum_gs: lsumN = gs id
  Lean 4 core plus hodge/OpenCerts, hodge/Q4Conv, hodge/CosetSplitA; no axioms.
-/
import hodge.OpenCerts
import hodge.Q4Conv
import hodge.CosetSplitA

namespace SubsSum
open FermatGens OpenCerts Indecomp QFamPrime

theorem beq_eq_h : ∀ a b : Nat, Nat.beq a b = true → a = b
  | 0, 0, _ => rfl
  | 0, _ + 1, h => nomatch h
  | _ + 1, 0, h => nomatch h
  | a + 1, b + 1, h => congrArg Nat.succ (beq_eq_h a b h)

theorem beq_refl_h : ∀ a : Nat, Nat.beq a a = true
  | 0 => rfl
  | a + 1 => beq_refl_h a

theorem mem_map_inv (g : List Nat → List Nat) (y : List Nat) : ∀ l : List (List Nat), y ∈ l.map g → ∃ x, x ∈ l ∧ y = g x
  | [], h => nomatch h
  | x :: l, h => by
    cases h with
    | head => exact ⟨x, List.Mem.head _, rfl⟩
    | tail _ h' =>
      have ⟨z, hz, e⟩ := mem_map_inv g y l h'
      exact ⟨z, List.Mem.tail _ hz, e⟩

theorem mem_app_l {α : Type} (y : α) : ∀ (l r : List α), y ∈ l → y ∈ l ++ r
  | [], _, h => nomatch h
  | _ :: l, r, h => by
    cases h with
    | head => exact List.Mem.head _
    | tail _ h' => exact List.Mem.tail _ (mem_app_l y l r h')

theorem mem_app_r {α : Type} (y : α) : ∀ (l r : List α), y ∈ r → y ∈ l ++ r
  | [], _, h => h
  | _ :: l, r, h => List.Mem.tail _ (mem_app_r y l r h)

theorem mem_flatMap_of {α β : Type} (f : α → List β) (y : β) (p : α) (hy : y ∈ f p) :
    ∀ l : List α, p ∈ l → y ∈ l.flatMap f
  | [], h => nomatch h
  | q :: l, h => by
    show y ∈ f q ++ l.flatMap f
    cases h with
    | head => exact mem_app_l y _ _ hy
    | tail _ h' => exact mem_app_r y _ _ (mem_flatMap_of f y p hy l h')

/-- every sub-list in subs c is the first half of a splitting of c -/
theorem subs_split : ∀ (c A : List Nat), A ∈ subs c → ∃ R, (A, R) ∈ splits c
  | [], A, h => by
    cases h with
    | head => exact ⟨[], List.Mem.head _⟩
    | tail _ h' => exact nomatch h'
  | x :: l, A, h => by
    rcases Q4Conv.mem_app_inv A _ _ h with h1 | h1
    · have ⟨A', hA', e⟩ := mem_map_inv (x :: ·) A (subs l) h1
      subst e
      have ⟨R, hR⟩ := subs_split l A' hA'
      refine ⟨R, ?_⟩
      show (x :: A', R) ∈ (splits l).flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])
      exact mem_flatMap_of _ _ (A', R) (List.Mem.head _) (splits l) hR
    · have ⟨R, hR⟩ := subs_split l A h1
      refine ⟨x :: R, ?_⟩
      show (A, x :: R) ∈ (splits l).flatMap (fun p => [(x :: p.1, p.2), (p.1, x :: p.2)])
      exact mem_flatMap_of _ _ (A, R) (List.Mem.tail _ (List.Mem.head _)) (splits l) hR

theorem splits_gs (f : Nat → Nat) : ∀ (c A R : List Nat), (A, R) ∈ splits c → gs f A + gs f R = gs f c
  | [], A, R, h => by
    have e : (A, R) = (([] : List Nat), ([] : List Nat)) := by
      cases h with
      | head => rfl
      | tail _ h' => exact nomatch h'
    injection e with e1 e2
    subst e1; subst e2
    rfl
  | z :: l, A, R, h => by
    cases Q4Conv.mem_flatMap_inv _ _ (splits l) h with
    | intro p hp =>
      have ih := splits_gs f l p.1 p.2 hp.1
      cases hp.2 with
      | head =>
        show (f z + gs f p.1) + gs f p.2 = f z + gs f l
        rw [← ih]; lib_nat
      | tail _ h2 => cases h2 with
        | head =>
          show gs f p.1 + (f z + gs f p.2) = f z + gs f l
          rw [← ih]; lib_nat
        | tail _ h3 => exact nomatch h3

def ind (x z : Nat) : Nat := if Nat.beq z x then 1 else 0

theorem pos_mem (x : Nat) : ∀ l : List Nat, 0 < gs (ind x) l → x ∈ l
  | [], h => absurd h (Nat.lt_irrefl 0)
  | y :: l, h => by
    cases hb : Nat.beq y x with
    | true => rw [beq_eq_h y x hb]; exact List.Mem.head _
    | false =>
      have e : ind x y = 0 := by unfold ind; rw [hb] <;> rfl
      have h2 : 0 < ind x y + gs (ind x) l := h
      rw [e, show 0 + gs (ind x) l = gs (ind x) l by lib_nat] at h2
      have h' := h2
      exact List.Mem.tail _ (pos_mem x l h')

theorem erase1_spec (x : Nat) : ∀ l : List Nat, x ∈ l → ∃ l', erase1 x l = some l' ∧ ∀ f : Nat → Nat, f x + gs f l' = gs f l
  | [], h => nomatch h
  | y :: l, h => by
    cases hb : Nat.beq x y with
    | true =>
      have e := beq_eq_h x y hb
      refine ⟨l, ?_, fun f => by show f x + gs f l = f y + gs f l; rw [e]⟩
      show (if Nat.beq x y = true then some l else (erase1 x l).map (y :: ·)) = some l
      rw [hb] <;> rfl
    | false =>
      have hx : x ∈ l := by
        cases h with
        | head => rw [beq_refl_h x] at hb; exact nomatch hb
        | tail _ h' => exact h'
      have ⟨l', e, hf⟩ := erase1_spec x l hx
      refine ⟨y :: l', ?_, fun f => ?_⟩
      · show (if Nat.beq x y = true then some l else (erase1 x l).map (y :: ·)) = some (y :: l')
        rw [hb, e] <;> rfl
      · show f x + (f y + gs f l') = f y + gs f l
        rw [← hf f]; lib_nat

theorem sub_spec : ∀ (A c R : List Nat), (∀ f : Nat → Nat, gs f A + gs f R = gs f c) →
    ∃ B, sub c A = some B ∧ ∀ f : Nat → Nat, gs f A + gs f B = gs f c
  | [], c, _, _ => ⟨c, rfl, fun f => by show 0 + gs f c = gs f c; lib_nat⟩
  | x :: A, c, R, h => by
    have hpos : 0 < gs (ind x) c := by
      rw [← h (ind x)]
      show 0 < (ind x x + gs (ind x) A) + gs (ind x) R
      have e : ind x x = 1 := by unfold ind; rw [beq_refl_h x] <;> rfl
      rw [e]
      exact Nat.lt_of_lt_of_le (Nat.succ_pos 0) (Nat.le_trans (Nat.le_add_right 1 _) (Nat.le_add_right _ _))
    have ⟨c', e, hf⟩ := erase1_spec x c (pos_mem x c hpos)
    have h' : ∀ f : Nat → Nat, gs f A + gs f R = gs f c' := fun f =>
      BalAppend.add_cancel (f x) _ _ (by
        rw [hf f, ← h f]
        show f x + (gs f A + gs f R) = (f x + gs f A) + gs f R
        lib_nat)
    have ⟨B, hB, hB'⟩ := sub_spec A c' R h'
    refine ⟨B, ?_, fun f => ?_⟩
    · show (match erase1 x c with | none => none | some c' => sub c' A) = some B
      rw [e] <;> exact hB
    · show (f x + gs f A) + gs f B = gs f c
      rw [← hf f, ← hB' f]; lib_nat

/-- the complement computed by the closure has the same additive functionals as the splitting partner -/
theorem compl_spec (c A : List Nat) (hA : A ∈ subs c) :
    ∃ R, (A, R) ∈ splits c ∧ ∀ f : Nat → Nat, gs f (compl c A) = gs f R := by
  have ⟨R, hR⟩ := subs_split c A hA
  have hs := fun f => splits_gs f c A R hR
  have ⟨B, hB, hB'⟩ := sub_spec A c R hs
  refine ⟨R, hR, fun f => ?_⟩
  have e : compl c A = B := by show (sub c A).getD [] = B; rw [hB] <;> rfl
  rw [e]
  exact BalAppend.add_cancel (gs f A) _ _ (by rw [hB' f, hs f])

theorem tsum_gs (m t : Nat) : ∀ L : List Nat, FermatGens.tsum m t L = gs (fun x => (t * x) % m) L
  | [] => rfl
  | x :: L => by
    show (t * x) % m + FermatGens.tsum m t L = (t * x) % m + gs (fun x => (t * x) % m) L
    rw [tsum_gs m t L]

theorem lsum_gs : ∀ L : List Nat, lsumN L = gs (fun x => x) L
  | [] => rfl
  | x :: L => by
    show x + lsumN L = x + gs (fun x => x) L
    rw [lsum_gs L]

theorem all_congr (P Q : Nat → Bool) (h : ∀ t, P t = Q t) : ∀ U : List Nat, U.all P = U.all Q
  | [] => rfl
  | t :: U => by
    show (P t && U.all P) = (Q t && U.all Q)
    rw [h t, all_congr P Q h U]

theorem hodgeB_congr (m : Nat) (U L L' : List Nat) (h : ∀ f : Nat → Nat, gs f L = gs f L') :
    hodgeB m U L = hodgeB m U L' := by
  unfold hodgeB
  have hl : L.length = L'.length := by
    rw [← CosetSplitA.gs_one L, ← CosetSplitA.gs_one L', h]
  apply all_congr
  intro t
  show Nat.beq (FermatGens.tsum m t L + FermatGens.tsum m t L) (L.length * m) = Nat.beq (FermatGens.tsum m t L' + FermatGens.tsum m t L') (L'.length * m)
  rw [tsum_gs m t L, tsum_gs m t L', h, hl]

end SubsSum

#print axioms SubsSum.beq_eq_h
#print axioms SubsSum.beq_refl_h
#print axioms SubsSum.mem_map_inv
#print axioms SubsSum.mem_app_l
#print axioms SubsSum.mem_app_r
#print axioms SubsSum.mem_flatMap_of
#print axioms SubsSum.subs_split
#print axioms SubsSum.splits_gs
#print axioms SubsSum.pos_mem
#print axioms SubsSum.erase1_spec
#print axioms SubsSum.sub_spec
#print axioms SubsSum.compl_spec
#print axioms SubsSum.tsum_gs
#print axioms SubsSum.lsum_gs
#print axioms SubsSum.all_congr
#print axioms SubsSum.hodgeB_congr

#print axioms: 16 theorems, no axioms.

81.245 \(G_p\) has no split step

For every prime \(p\equiv 3,5\pmod {14}\) with \(F_p\) indecomposable, no \(A\in \mathrm {subs}\,G_p\) passes the split step at \(m=28p\).

hodge/GpNoStep.lean

/-
  hodge/GpNoStep.lean — T41 cycle 1934 (goal G862b): the doubled family character
  G_p = 14p :: 2·F_p (F_p = FamBal.fam p i₀, p = 14a + v, v ∈ {3, 5}, p prime, F_p indecomposable at 14p)
  has no split step in the inductive closure of OpenCerts at m = 28p:
    no_step   for every A ∈ subs G_p, splitOK (28p) (units 28p) rec G_p A = false
  Proof. Write A ⊔ R for the splitting behind A (SubsSum.compl_spec), halve it to A₀ ⊔ B₀ ∈ splits Fq.
  s = ΣA mod 28p = 0: both parts balanced and nonempty, so one is {14p} (GpSplit.gp_split); then s = 14p
  (A = {14p}) or s = 14p·p mod 28p = 14p (R = {14p}, ΣF_p = 7p²), not 0.
  s ≠ 0: the completed part (28p − s) :: A is 2·((14p − s/2) :: A₀), balanced at 14p (GpSplit.half), so
  |A₀| ≤ 1 or |A₀| ≥ p (CosetSplitD.part_small); both contradict the length conditions |A|, |B| < p.
  Lean 4 core plus hodge/SubsSum, hodge/CosetSplitD, hodge/GpSplit; no axioms.
-/
import hodge.SubsSum
import hodge.CosetSplitD
import hodge.GpSplit

namespace GpNoStep
open FermatGens OpenCerts Indecomp QFamPrime GcdHand ModHand OrbitSum FamArith FamBal CosetSplitA SubsSum

theorem tsum_eq (m t : Nat) : ∀ L : List Nat, Indecomp.tsum m t L = FermatGens.tsum m t L
  | [] => rfl
  | x :: L => by
    show (t * x) % m + Indecomp.tsum m t L = (t * x) % m + FermatGens.tsum m t L
    rw [tsum_eq m t L]

theorem hodge_bal (m : Nat) (L : List Nat) : hodgeB m (FermatPrime.units m) L = bal m L := by
  unfold hodgeB bal
  apply all_congr
  intro t
  show Nat.beq (FermatGens.tsum m t L + FermatGens.tsum m t L) (L.length * m)
    = Nat.beq (Indecomp.tsum m t L + Indecomp.tsum m t L) (L.length * m)
  rw [tsum_eq]

theorem gs_map (g h : Nat → Nat) : ∀ L : List Nat, gs g (L.map h) = gs (fun x => g (h x)) L
  | [] => rfl
  | x :: L => by
    show g (h x) + gs g (L.map h) = g (h x) + gs (fun x => g (h x)) L
    rw [gs_map g h L]

theorem gs_dbl : ∀ L : List Nat, gs (fun x => 2 * x) L = gs (fun x => x) L + gs (fun x => x) L
  | [] => rfl
  | x :: L => by
    show 2 * x + gs (fun x => 2 * x) L = (x + gs (fun x => x) L) + (x + gs (fun x => x) L)
    rw [gs_dbl L]; lib_nat

theorem ble_le : ∀ a b : Nat, Nat.ble a b = true → a ≤ b
  | 0, _, _ => Nat.zero_le _
  | _ + 1, 0, h => nomatch h
  | a + 1, b + 1, h => Nat.succ_le_succ (ble_le a b h)

theorem lt_of_blt' {a b : Nat} (h : Nat.blt a b = true) : a < b := ble_le (a + 1) b h

theorem len_gs (L : List Nat) : L.length = gs (fun _ => 1) L := (CosetSplitA.gs_one L).symm

theorem ne_nil_of_gs (L L' : List Nat) (h : gs (fun _ => 1) L = gs (fun _ => 1) L') (hL : L ≠ []) : L' ≠ [] := by
  intro e
  rw [e] at h
  cases L with
  | nil => exact hL rfl
  | cons x l =>
    have h3 : 1 + gs (fun _ => 1) l = 0 := h
    have h2 : gs (fun _ => 1) l + 1 = 0 := by
      rw [show gs (fun _ => 1) l + 1 = 1 + gs (fun _ => 1) l by lib_nat]; exact h3
    exact Nat.noConfusion h2

theorem ne_of_isEmpty (L : List Nat) (h : L.isEmpty = false) : L ≠ [] := by
  intro e
  subst e
  exact Bool.noConfusion h

/-- the split step is false once both branches are excluded -/
theorem splitOK_false (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c A : List Nat)
    (h0 : lsumN A % m = 0 → A ≠ [] → compl c A ≠ [] → hodgeB m U A = true → hodgeB m U (compl c A) = true → False)
    (h1 : Nat.blt (((m - lsumN A % m) :: A).length) c.length = true →
      Nat.blt (((lsumN A % m) :: compl c A).length) c.length = true →
      hodgeB m U ((m - lsumN A % m) :: A) = true → False) :
    splitOK m U rec c A = false := by
  show (if Nat.beq (lsumN A % m) 0 = true then
      (!A.isEmpty && !(compl c A).isEmpty && hodgeB m U A && hodgeB m U (compl c A) && rec A && rec (compl c A))
    else
      (Nat.blt ((m - lsumN A % m) :: A).length c.length && Nat.blt ((lsumN A % m) :: compl c A).length c.length &&
        hodgeB m U ((m - lsumN A % m) :: A) && hodgeB m U ((lsumN A % m) :: compl c A) &&
        rec ((m - lsumN A % m) :: A) && rec ((lsumN A % m) :: compl c A))) = false
  cases hs : Nat.beq (lsumN A % m) 0 with
  | true =>
    have e0 := beq_eq_h _ _ hs
    show (!A.isEmpty && !(compl c A).isEmpty && hodgeB m U A && hodgeB m U (compl c A) && rec A && rec (compl c A)) = false
    cases e1 : A.isEmpty <;> cases e2 : (compl c A).isEmpty <;> cases e3 : hodgeB m U A <;>
      cases e4 : hodgeB m U (compl c A) <;>
      first | rfl | exact (h0 e0 (ne_of_isEmpty A e1) (ne_of_isEmpty _ e2) e3 e4).elim
  | false =>
    show (Nat.blt ((m - lsumN A % m) :: A).length c.length && Nat.blt ((lsumN A % m) :: compl c A).length c.length &&
        hodgeB m U ((m - lsumN A % m) :: A) && hodgeB m U ((lsumN A % m) :: compl c A) &&
        rec ((m - lsumN A % m) :: A) && rec ((lsumN A % m) :: compl c A)) = false
    cases f1 : Nat.blt ((m - lsumN A % m) :: A).length c.length <;>
      cases f2 : Nat.blt ((lsumN A % m) :: compl c A).length c.length <;>
      cases f3 : hodgeB m U ((m - lsumN A % m) :: A) <;>
      first | rfl | exact (h1 f1 f2 f3).elim

theorem sum_lin : ∀ n, sumF (fun k => 1 + 14 * k) n = n + 14 * sumF (fun i => i) n
  | 0 => rfl
  | n + 1 => by
    show sumF (fun k => 1 + 14 * k) n + (1 + 14 * n) = (n + 1) + 14 * (sumF (fun i => i) n + n)
    rw [sum_lin n]; lib_nat

/-- Σ F_p = 7p², doubled -/
theorem sum_fam (p i0 : Nat) (hi : i0 < p) :
    gs (fun x => x) (fam p i0) + gs (fun x => x) (fam p i0) = 14 * (p * p) := by
  have eg := FamIndec3.gl_gs (fun x => x) (fun k => if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k) p
  have eg' : gs (fun x => x) (fam p i0)
      = sumF (fun k => if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k) p := eg
  rw [eg']
  have r := sumF_replace (fun k => if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k)
    (fun k => 1 + 14 * k) i0 (fun k hk => by
      show (if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k) = 1 + 14 * k
      cases e : Nat.beq k i0 with
      | true => exact absurd (beq_eq_h k i0 e) hk
      | false => rfl) p hi
  have e2 : (if Nat.beq i0 i0 = true then 1 + 14 * i0 + 6 * p else 1 + 14 * i0) = 1 + 14 * i0 + 6 * p := by
    rw [beq_refl_h i0] <;> rfl
  have r' : sumF (fun k => if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k) p + (1 + 14 * i0)
      = sumF (fun k => 1 + 14 * k) p + (1 + 14 * i0 + 6 * p) := by
    rw [← e2]; exact r
  generalize sumF (fun k => if Nat.beq k i0 = true then 1 + 14 * k + 6 * p else 1 + 14 * k) p = T at r' ⊢
  have hT : T = p + 14 * sumF (fun i => i) p + 6 * p := add_right_cancel' T _ (1 + 14 * i0) (by
    rw [r', sum_lin p]; lib_nat)
  have hS := sum_id p
  rw [hT]
  generalize sumF (fun i => i) p = S at hS ⊢
  calc p + 14 * S + 6 * p + (p + 14 * S + 6 * p) = 14 * (S + S + p) := by lib_nat
    _ = 14 * (p * p) := by rw [hS]

theorem odd_mul_mod (K j : Nat) (hK : 0 < K) : (K * (2 * j + 1)) % (K + K) = K := by
  have hKK : 0 < K + K := Nat.lt_of_lt_of_le hK (Nat.le_add_right K K)
  rw [show K * (2 * j + 1) = K + j * (K + K) by lib_nat, add_mul_mod' K (K + K) hKK j]
  exact mod_lt' K (K + K) (Nat.add_le_add_left hK K)

theorem dbl_mod (X Y : Nat) (hY : 0 < Y) : (2 * X) % (2 * Y) = 2 * (X % Y) := by
  have ⟨q, hq⟩ := div_mod Y hY (X + 1) X (Nat.lt_succ_self X)
  have hr : X % Y < Y := Nat.mod_lt _ hY
  generalize X % Y = r at hq hr ⊢
  have h2Y : 0 < 2 * Y := Nat.mul_pos (Nat.succ_pos 1) hY
  have hlt : 2 * r < 2 * Y := Nat.le_trans (Nat.le_succ _) (by
    show 2 * r + 1 + 1 ≤ 2 * Y
    rw [show 2 * r + 1 + 1 = (r + 1) + (r + 1) by lib_nat, show 2 * Y = Y + Y by lib_nat]
    exact Nat.add_le_add hr hr)
  rw [hq, show 2 * (r + Y * q) = 2 * r + q * (2 * Y) by lib_nat, add_mul_mod' _ _ h2Y q]
  exact mod_lt' _ _ hlt

/-- **G862b: G_p has no split step.** -/
theorem no_step (a v i0 x0 k : Nat) (ek : k = 7 * (14 * a + v)) (hv : v = 3 ∨ v = 5)
    (hpr : ∀ d, d ∣ (14 * a + v) → d = 1 ∨ d = 14 * a + v) (h14 : Nat.gcd 14 (14 * a + v) = 1)
    (hi : i0 < 14 * a + v) (hx : 1 + 14 * i0 = (14 * a + v) * x0)
    (hF : indec (k + k) (fam (14 * a + v) i0) = true) (rec : List Nat → Bool) (A : List Nat)
    (hA : A ∈ subs ((k + k) :: (fam (14 * a + v) i0).map (fun x => 2 * x))) :
    splitOK ((k + k) + (k + k)) (FermatPrime.units ((k + k) + (k + k))) rec
      ((k + k) :: (fam (14 * a + v) i0).map (fun x => 2 * x)) A = false := by
  have hp : 0 < 14 * a + v := Nat.lt_of_le_of_lt (Nat.zero_le _) hi
  have hk0 : 0 < k := by rw [ek]; exact Nat.mul_pos (Nat.succ_pos 6) hp
  have hkk : 0 < k + k := Nat.lt_of_lt_of_le hk0 (Nat.le_add_right k k)
  have ekk : k + k = 14 * (14 * a + v) := by rw [ek]; lib_nat
  have ec : (k + k) :: (fam (14 * a + v) i0).map (fun x => 2 * x) = (Fq (14 * a + v) i0).map (fun x => 2 * x) := by
    show (k + k) :: _ = (2 * (7 * (14 * a + v))) :: _
    rw [ek, show 2 * (7 * (14 * a + v)) = 7 * (14 * a + v) + 7 * (14 * a + v) by lib_nat]
  have ⟨R, hR, hBR⟩ := compl_spec _ A hA
  have hR' := hR
  rw [ec, APPairIrrGen.splits_eq, APPairIrrGen.splits_map] at hR
  have ⟨A0, B0, h0, eA, eR⟩ := GpSplit.mem_mapP (fun x => 2 * x) _ A R hR
  rw [← APPairIrrGen.splits_eq] at h0
  have hsum : ∀ f : Nat → Nat, gs f A0 + gs f B0 = gs f (Fq (14 * a + v) i0) := fun f => SubsSum.splits_gs f _ _ _ h0
  have hmem := (Q4Conv.splits_props _ _ _ h0).2.1
  have tI := tot_isp a v i0 hv hi
  have tH := tot_ih a v i0 hv hi
  have tO := tot_io a v i0 hv hi
  have hδ : gs (isp (14 * a + v) i0) A0 ≤ 1 :=
    Nat.le.intro (k := gs (isp (14 * a + v) i0) B0) (by rw [hsum]; exact tI)
  have hη : gs (ih (14 * a + v)) A0 ≤ 1 :=
    Nat.le.intro (k := gs (ih (14 * a + v)) B0) (by rw [hsum]; exact tH)
  have hn : gs (io (14 * a + v) i0) A0 + 1 ≤ 14 * a + v := Nat.le.intro (k := gs (io (14 * a + v) i0) B0) (by
    rw [show gs (io (14 * a + v) i0) A0 + 1 + gs (io (14 * a + v) i0) B0
        = gs (io (14 * a + v) i0) A0 + gs (io (14 * a + v) i0) B0 + 1 by lib_nat, hsum]
    exact tO)
  have lF : (Fq (14 * a + v) i0).length = 14 * a + v + 1 := by
    rw [← len_counts (14 * a + v) i0 (Fq (14 * a + v) i0), tI, tH, tO]
  have lAB : A0.length + B0.length = 14 * a + v + 1 := by
    rw [len_gs A0, len_gs B0, hsum, ← len_gs, lF]
  have lA : A.length = A0.length := by
    rw [eA, len_gs (List.map (fun x => 2 * x) A0), len_gs A0, gs_map]
  have lB : (compl ((k + k) :: (fam (14 * a + v) i0).map (fun x => 2 * x)) A).length = B0.length := by
    rw [len_gs (compl _ A), hBR (fun _ => 1), eR, gs_map, len_gs B0]
  have lc : ((k + k) :: (fam (14 * a + v) i0).map (fun x => 2 * x)).length = 14 * a + v + 1 := by
    rw [ec, len_gs (List.map (fun x => 2 * x) (Fq (14 * a + v) i0)), gs_map, ← len_gs (Fq (14 * a + v) i0), lF]
  apply splitOK_false
  · intro hs0 hAn hBn hhA hhB
    rw [hodge_bal] at hhA
    rw [hodgeB_congr _ _ _ R hBR, hodge_bal] at hhB
    have hRn : R ≠ [] := ne_nil_of_gs _ _ (hBR (fun _ => 1)) hBn
    have hlt : k + k < (k + k) + (k + k) := Nat.add_le_add_left hkk (k + k)
    rcases GpSplit.gp_split k hk0 (fam (14 * a + v) i0) A R hF hR' hhA hhB hAn hRn with e | e
    · rw [e] at hs0
      have e2 : lsumN [k + k] % ((k + k) + (k + k)) = k + k := by
        show (k + k + 0) % ((k + k) + (k + k)) = k + k
        exact mod_lt' _ _ hlt
      rw [e2] at hs0
      rw [hs0] at hkk
      exact Nat.lt_irrefl 0 hkk
    · have hsA := SubsSum.splits_gs (fun x => x) _ _ _ hR'
      rw [e] at hsA
      have e3 : gs (fun x => x) ((fam (14 * a + v) i0).map (fun x => 2 * x)) = gs (fun x => 2 * x) (fam (14 * a + v) i0) :=
        gs_map _ _ _
      have hc : gs (fun x => x) ((k + k) :: (fam (14 * a + v) i0).map (fun x => 2 * x))
          = (k + k) + (k + k) * (14 * a + v) := by
        show (k + k) + gs (fun x => x) ((fam (14 * a + v) i0).map (fun x => 2 * x)) = _
        rw [e3, gs_dbl, sum_fam _ _ hi, ek]; lib_nat
      have hAs : gs (fun x => x) A = (k + k) * (14 * a + v) := add_right_cancel' _ _ (k + k) (by
        rw [show gs (fun x => x) A + (k + k) = gs (fun x => x) A + gs (fun x => x) [k + k] from rfl, hsA, hc]
        lib_nat)
      have hodd : ∃ j, 14 * a + v = 2 * j + 1 := by
        rcases hv with h | h
        · subst h; exact ⟨7 * a + 1, by lib_nat⟩
        · subst h; exact ⟨7 * a + 2, by lib_nat⟩
      have ⟨j, hj⟩ := hodd
      rw [lsum_gs, hAs, hj, odd_mul_mod (k + k) j hkk] at hs0
      rw [hs0] at hkk
      exact Nat.lt_irrefl 0 hkk
  · intro hlA hlB hhA2
    have hlA' : A.length + 1 < ((k + k) :: (fam (14 * a + v) i0).map (fun x => 2 * x)).length :=
      lt_of_blt' hlA
    have hlB' : (compl ((k + k) :: (fam (14 * a + v) i0).map (fun x => 2 * x)) A).length + 1
        < ((k + k) :: (fam (14 * a + v) i0).map (fun x => 2 * x)).length := lt_of_blt' hlB
    rw [lA, lc] at hlA'
    rw [lB, lc] at hlB'
    have hA0 : A0.length < 14 * a + v := Nat.lt_of_succ_lt_succ hlA'
    have hB0 : B0.length < 14 * a + v := Nat.lt_of_succ_lt_succ hlB'
    rw [hodge_bal] at hhA2
    have hX : lsumN A = 2 * gs (fun x => x) A0 := by
      rw [lsum_gs, eA]
      have e3 : gs (fun x => x) (A0.map (fun x => 2 * x)) = gs (fun x => 2 * x) A0 := gs_map _ _ _
      rw [e3, gs_dbl]; lib_nat
    have hsd : lsumN A % ((k + k) + (k + k)) = 2 * (gs (fun x => x) A0 % (k + k)) := by
      rw [hX, show (k + k) + (k + k) = 2 * (k + k) by lib_nat, dbl_mod _ _ hkk]
    rw [hsd, eA] at hhA2
    have hslt : gs (fun x => x) A0 % (k + k) < k + k := Nat.mod_lt _ hkk
    have ⟨q, hq⟩ := div_mod (k + k) hkk (gs (fun x => x) A0 + 1) (gs (fun x => x) A0) (Nat.lt_succ_self _)
    generalize gs (fun x => x) A0 % (k + k) = s' at hhA2 hslt hq
    have es := sub_add' s' (k + k) (Nat.le_of_lt hslt)
    have hms : (k + k) + (k + k) - 2 * s' = 2 * (k + k - s') := by
      generalize k + k - s' = d at es ⊢
      rw [← es, show d + s' + (d + s') = 2 * d + 2 * s' by lib_nat]
      exact add_sub' (2 * d) (2 * s')
    rw [hms] at hhA2
    have hb2 : bal ((k + k) + (k + k)) (((k + k - s') :: A0).map (fun x => 2 * x)) = true := hhA2
    have hb := GpSplit.half k hk0 _ hb2
    have hs14 : ((k + k - s') + gs (fun x => x) A0) % 14 = 0 := by
      rw [hq]
      generalize k + k - s' = d at es ⊢
      rw [show d + (s' + (k + k) * q) = (d + s') + (k + k) * q by lib_nat, es, ekk,
        show 14 * (14 * a + v) + 14 * (14 * a + v) * q = 0 + ((14 * a + v) * (1 + q)) * 14 by lib_nat,
        add_mul_mod' 0 14 (Nat.succ_pos 13)] <;> rfl
    rw [ekk] at hb hs14
    rcases CosetSplitD.part_small a v i0 x0 hv hpr h14 hi hx A0 hmem hδ hη hn _ hs14 hb with h | h
    · have h2 : A0.length + B0.length ≤ 1 + B0.length := Nat.add_le_add_right h _
      rw [lAB, show 1 + B0.length = B0.length + 1 by lib_nat] at h2
      exact Nat.lt_irrefl _ (Nat.lt_of_le_of_lt (Nat.le_of_succ_le_succ h2) hB0)
    · exact Nat.lt_irrefl _ (Nat.lt_of_le_of_lt h hA0)

end GpNoStep

#print axioms GpNoStep.tsum_eq
#print axioms GpNoStep.hodge_bal
#print axioms GpNoStep.gs_map
#print axioms GpNoStep.gs_dbl
#print axioms GpNoStep.ble_le
#print axioms GpNoStep.lt_of_blt'
#print axioms GpNoStep.len_gs
#print axioms GpNoStep.ne_nil_of_gs
#print axioms GpNoStep.ne_of_isEmpty
#print axioms GpNoStep.splitOK_false
#print axioms GpNoStep.sum_lin
#print axioms GpNoStep.sum_fam
#print axioms GpNoStep.odd_mul_mod
#print axioms GpNoStep.dbl_mod
#print axioms GpNoStep.no_step

#print axioms: 15 theorems, no axioms.

81.246 Natural number division by hand

\((r+qy)/y=q\) for \(r<y\), from the fuelled loop of Nat.div.

hodge/DivHand.lean

/-
  hodge/DivHand.lean — T41 cycle 1934 (goal G862d, tool): Nat division by hand from the axiom-free unfoldings
  Nat.div.eq_def and Nat.div.go.eq_def (core's Nat.div_add_mod and its consequences use simp).
    go_val    the fuelled loop returns q on r + q·y with r < y
    div_val   (r + q·y) / y = q for r < y
    mul_div'  (q·y) / y = q
  Lean 4 core plus hodge/ModHand; no axioms.
-/
import hodge.ModHand
import lib.Semi

namespace DivHand
open ModHand

theorem go_arg (y : Nat) (hy : 0 < y) (F x x' : Nat) (h : x < F) (h' : x' < F) (e : x = x') :
    Nat.div.go y hy F x h = Nat.div.go y hy F x' h' := by
  subst e; rfl

theorem go_val (y : Nat) (hy : 0 < y) (r : Nat) (hr : r < y) :
    ∀ (q F : Nat) (h : r + q * y < F), Nat.div.go y hy F (r + q * y) h = q
  | _, 0, h => absurd h (Nat.not_lt_zero _)
  | 0, F + 1, h => by
    rw [Nat.div.go.eq_def]
    show (if hyx : y ≤ r + 0 * y then Nat.div.go y hy F (r + 0 * y - y) _ + 1 else 0) = 0
    have hn : ¬ (y ≤ r + 0 * y) := fun hle => by
      have e : r + 0 * y = r := by lib_nat
      rw [e] at hle
      exact Nat.lt_irrefl r (Nat.lt_of_lt_of_le hr hle)
    rw [dite_eq_right hn]
  | q + 1, F + 1, h => by
    rw [Nat.div.go.eq_def]
    show (if hyx : y ≤ r + (q + 1) * y then Nat.div.go y hy F (r + (q + 1) * y - y) _ + 1 else 0) = q + 1
    have hle : y ≤ r + (q + 1) * y := by
      rw [show r + (q + 1) * y = y + (r + q * y) by lib_nat]
      exact Nat.le_add_right y _
    rw [dite_eq_left hle]
    have e : r + (q + 1) * y - y = r + q * y := by
      rw [show r + (q + 1) * y = (r + q * y) + y by lib_nat]
      exact add_sub' (r + q * y) y
    have h2 : r + q * y < F := by
      have h' : r + (q + 1) * y - y < F :=
        Nat.div_rec_fuel_lemma hy hle h
      rw [e] at h'
      exact h'
    rw [go_arg y hy F _ (r + q * y) _ h2 e, go_val y hy r hr q F h2]

theorem div_val (y : Nat) (hy : 0 < y) (r q : Nat) (hr : r < y) : (r + q * y) / y = q := by
  show Nat.div (r + q * y) y = q
  rw [Nat.div.eq_def]
  show (if hy' : 0 < y then Nat.div.go y hy' (r + q * y + 1) (r + q * y) (Nat.lt_succ_self _) else 0) = q
  rw [dite_eq_left hy]
  exact go_val y hy r hr q _ _

theorem mul_div' (y : Nat) (hy : 0 < y) (q : Nat) : (q * y) / y = q := by
  have e := div_val y hy 0 q hy
  rw [show 0 + q * y = q * y by lib_nat] at e
  exact e

end DivHand

#print axioms DivHand.go_arg
#print axioms DivHand.go_val
#print axioms DivHand.div_val
#print axioms DivHand.mul_div'

#print axioms: 4 theorems, no axioms.

81.247 \(G_p\) is not standard

For \(p\equiv 3,5\pmod {14}\) the character \(G_p=14p::2F_p\) is not a Shioda-standard character at \(m=28p\): no residue class mod \(28\) holds \(p\) of its entries.

hodge/GpNotStd.lean

/-
  hodge/GpNotStd.lean — T41 cycle 1934 (goal G862d): the doubled family character G_p = 14p :: 2·F_p
  (p = 14a + v, v ∈ {3, 5}) is not Shioda-standard at m = 28p:
    not_std   isStd (28p) G_p = false
  Proof. sameMS G_p (std m d a) makes the additive functionals of the two lists equal (sub run backwards).
  Lengths give d = p, so m / d = 28 (DivHand) and the p entries (a + 28k) mod 28p of std lie in the class
  a mod 28. G_p has p − 1 entries ≡ 2 (2(1 + 14k)), one ≡ 14 (14p) and one ≡ 6 or 10 (the special entry),
  so no class mod 28 holds p of its entries.
  Lean 4 core plus hodge/GpNoStep, hodge/DivHand, hodge/CosetSplitC; no axioms.
-/
import hodge.GpNoStep
import hodge.DivHand
import hodge.CosetSplitC

namespace GpNotStd
open FermatGens OpenCerts Fermat25Std Fermat32Open Indecomp QFamPrime GcdHand ModHand OrbitSum FamArith FamBal
  CosetSplitA SubsSum GpNoStep

theorem none_ne_some (y : List Nat) (h : (none : Option (List Nat)) = some y) : False := by cases h

theorem erase1_some (x : Nat) : ∀ l l' : List Nat, erase1 x l = some l' → ∀ f : Nat → Nat, f x + gs f l' = gs f l
  | [], l', h, _ => (none_ne_some _ (show (none : Option (List Nat)) = some l' from h)).elim
  | y :: l, l', h, f => by
    have h' : (if Nat.beq x y = true then some l else (erase1 x l).map (y :: ·)) = some l' := h
    cases hb : Nat.beq x y with
    | true =>
      rw [hb] at h'
      have h2 : some l = some l' := h'
      injection h2 with h3
      subst h3
      show f x + gs f l = f y + gs f l
      rw [beq_eq_h x y hb]
    | false =>
      rw [hb] at h'
      cases he : erase1 x l with
      | none =>
        rw [he] at h'
        exact (none_ne_some _ (show (none : Option (List Nat)) = some l' from h')).elim
      | some l'' =>
        rw [he] at h'
        have h2 : some (y :: l'') = some l' := h'
        injection h2 with h3
        subst h3
        show f x + (f y + gs f l'') = f y + gs f l
        rw [← erase1_some x l l'' he f]; lib_nat

theorem sub_some : ∀ (S c B : List Nat), sub c S = some B → ∀ f : Nat → Nat, gs f S + gs f B = gs f c
  | [], c, B, h, f => by
    have h2 : some c = some B := h
    injection h2 with h3
    subst h3
    show 0 + gs f c = gs f c; lib_nat
  | x :: S, c, B, h, f => by
    have h' : (match erase1 x c with | none => none | some c' => sub c' S) = some B := h
    cases he : erase1 x c with
    | none =>
      rw [he] at h'
      exact (none_ne_some _ (show (none : Option (List Nat)) = some B from h')).elim
    | some c' =>
      rw [he] at h'
      have h2 : sub c' S = some B := h'
      show (f x + gs f S) + gs f B = gs f c
      rw [← erase1_some x c c' he f, ← sub_some S c' B h2 f]; lib_nat

theorem sameMS_gs (c S : List Nat) (h : sameMS c S = true) : ∀ f : Nat → Nat, gs f S = gs f c := by
  have h' : (sub c S == some []) = true := h
  cases hs : sub c S with
  | none =>
    rw [hs] at h'
    exact Bool.noConfusion (show false = true from h')
  | some B =>
    cases B with
    | nil =>
      intro f
      have e := sub_some S c [] hs f
      rw [← e]; show gs f S = gs f S + 0; rfl
    | cons b B' =>
      rw [hs] at h'
      exact Bool.noConfusion (show false = true from h')

theorem loop_gs (h : Nat → Nat) : ∀ (n : Nat) (acc : List Nat), gs h (List.range.loop n acc) = sumF h n + gs h acc
  | 0, acc => by show gs h acc = 0 + gs h acc; lib_nat
  | n + 1, acc => by
    show gs h (List.range.loop n (n :: acc)) = (sumF h n + h n) + gs h acc
    rw [loop_gs h n (n :: acc)]
    show sumF h n + (h n + gs h acc) = _
    lib_nat

theorem gs_range (h : Nat → Nat) (n : Nat) : gs h (List.range n) = sumF h n := by
  show gs h (List.range.loop n []) = sumF h n
  rw [loop_gs] <;> rfl

theorem gs_append (f : Nat → Nat) : ∀ L L' : List Nat, gs f (L ++ L') = gs f L + gs f L'
  | [], L' => by show gs f L' = 0 + gs f L'; lib_nat
  | x :: L, L' => by
    show f x + gs f (L ++ L') = (f x + gs f L) + gs f L'
    rw [gs_append f L L']; lib_nat

theorem gs_std (f : Nat → Nat) (m d a : Nat) :
    gs f (std m d a) = sumF (fun k => f ((a + k * (m / d)) % m)) d + f ((m * m - d * a) % m) := by
  show gs f (((List.range d).map (fun k => (a + k * (m / d)) % m)) ++ [(m * m - d * a) % m]) = _
  rw [gs_append, GpNoStep.gs_map, gs_range] <;> rfl

theorem any_false (P : Nat → Bool) (h : ∀ x, P x = false) : ∀ L : List Nat, L.any P = false
  | [] => rfl
  | x :: L => by
    show (P x || L.any P) = false
    rw [h x, any_false P h L] <;> rfl

theorem and_false' (b : Bool) : (b && false) = false := by cases b <;> rfl

theorem sumF_one (f : Nat → Nat) (h : ∀ k, f k = 1) : ∀ n, sumF f n = n
  | 0 => rfl
  | n + 1 => by show sumF f n + f n = n + 1; rw [sumF_one f h n, h n]

theorem gs_congr_mem (g h : Nat → Nat) : ∀ L : List Nat, (∀ x, x ∈ L → g x = h x) → gs g L = gs h L
  | [], _ => rfl
  | x :: L, hx => by
    show g x + gs g L = h x + gs h L
    rw [hx x (List.Mem.head _), gs_congr_mem g h L (fun y hy => hx y (List.Mem.tail _ hy))]

theorem gs_lin3 (u w z : Nat → Nat) (α β γ : Nat) : ∀ L : List Nat,
    gs (fun x => u x * α + w x * β + z x * γ) L = gs u L * α + gs w L * β + gs z L * γ
  | [] => by show 0 = 0 * α + 0 * β + 0 * γ; lib_nat
  | x :: L => by
    show (u x * α + w x * β + z x * γ) + gs (fun x => u x * α + w x * β + z x * γ) L
      = (u x + gs u L) * α + (w x + gs w L) * β + (z x + gs z L) * γ
    rw [gs_lin3 u w z α β γ L]; lib_nat

/-- class indicator mod 28 -/
def fr (r y : Nat) : Nat := if Nat.beq (y % 28) r then 1 else 0

theorem fr_congr (r y z : Nat) (h : y % 28 = z % 28) : fr r y = fr r z := by
  unfold fr; rw [h]

theorem fr_one (r y : Nat) (h : y % 28 = r) : fr r y = 1 := by
  unfold fr; rw [h, beq_refl_h r] <;> rfl

theorem fr_val (r y : Nat) (hy : y < 28) : fr r y = if Nat.beq y r then 1 else 0 := by
  unfold fr; rw [mod_lt' y 28 hy]

theorem mod_mod28 (p x : Nat) (hp : 0 < p) : (x % (28 * p)) % 28 = x % 28 := by
  have h28p : 0 < 28 * p := Nat.mul_pos (Nat.succ_pos 27) hp
  have ⟨q, hq⟩ := div_mod (28 * p) h28p (x + 1) x (Nat.lt_succ_self x)
  have e : x % 28 = (x % (28 * p) + (p * q) * 28) % 28 := by
    conv => lhs; rw [hq]
    rw [show x % (28 * p) + 28 * p * q = x % (28 * p) + (p * q) * 28 by lib_nat]
  rw [e, add_mul_mod' _ 28 (Nat.succ_pos 27)]

/-- the pointwise class of 2x for x ∈ Fq -/
theorem pt (a v i0 rs r : Nat) (hv : v = 3 ∨ v = 5) (hs : (2 * sst (14 * a + v) i0) % 28 = rs % 28)
    (hh : (2 * (7 * (14 * a + v))) % 28 = 14 % 28) :
    ∀ x, x ∈ Fq (14 * a + v) i0 → fr r (2 * x)
      = io (14 * a + v) i0 x * fr r 2 + isp (14 * a + v) i0 x * fr r rs + ih (14 * a + v) x * fr r 14 := by
  intro x hx
  have hx' : x ∈ 7 * (14 * a + v) :: fam (14 * a + v) i0 := hx
  cases hx' with
  | head =>
    have ⟨e1, e2, e3⟩ := kind_half a v i0
    rw [e1, e2, e3, fr_congr r _ 14 hh]; lib_nat
  | tail _ hf =>
    rcases fam_kind _ i0 x hf with e | ⟨k, _, _, e⟩
    · subst e
      have ⟨e1, e2, e3⟩ := kind_sst a v i0 hv
      rw [e1, e2, e3, fr_congr r _ rs hs]; lib_nat
    · subst e
      have ⟨e1, e2, e3⟩ := kind_ord a v i0 k hv
      have hk : (2 * (1 + 14 * k)) % 28 = 2 % 28 := by
        rw [show 2 * (1 + 14 * k) = 2 + k * 28 by lib_nat, add_mul_mod' 2 28 (Nat.succ_pos 27)]
      rw [e1, e2, e3, fr_congr r _ 2 hk]; lib_nat

theorem no_big (p x : Nat) (h : p + x + 1 = p) : False := by
  have h1 : p < p + x + 1 := Nat.lt_succ_of_le (Nat.le_add_right p x)
  rw [h] at h1
  exact Nat.lt_irrefl p h1

theorem small (p x c : Nat) (hp : 2 ≤ p) (hc : c ≤ 1) (h : p + x = c) : False := by
  have h1 : p ≤ c := by rw [← h]; exact Nat.le_add_right p x
  exact Nat.not_succ_le_zero 0 (Nat.le_of_succ_le_succ (Nat.le_trans hp (Nat.le_trans h1 hc)))

/-- the class count on both sides cannot match -/
theorem count_ne (p fl G rs r : Nat) (hp : 2 ≤ p) (hrs : rs = 6 ∨ rs = 10) (hG : G + 1 = p)
    (h : p + fl = G * (if Nat.beq 2 r = true then 1 else 0) + 1 * (if Nat.beq rs r = true then 1 else 0)
      + 1 * (if Nat.beq 14 r = true then 1 else 0)) : False := by
  have n2s : rs ≠ 2 := by rcases hrs with e | e <;> subst e <;> exact CosetSplitC.nat_ne _ _ rfl
  have n14s : rs ≠ 14 := by rcases hrs with e | e <;> subst e <;> exact CosetSplitC.nat_ne _ _ rfl
  have n2 : (2 : Nat) ≠ 14 := CosetSplitC.nat_ne _ _ rfl
  cases e2 : Nat.beq 2 r <;> cases es : Nat.beq rs r <;> cases e14 : Nat.beq 14 r <;> rw [e2, es, e14] at h
  · have h' : p + fl = G * 0 + 1 * 0 + 1 * 0 := h
    exact small p fl 0 hp (Nat.zero_le 1) (by rw [h']; lib_nat)
  · have h' : p + fl = G * 0 + 1 * 0 + 1 * 1 := h
    exact small p fl 1 hp (Nat.le_refl 1) (by rw [h']; lib_nat)
  · have h' : p + fl = G * 0 + 1 * 1 + 1 * 0 := h
    exact small p fl 1 hp (Nat.le_refl 1) (by rw [h']; lib_nat)
  · exact n14s ((beq_eq_h _ _ es).trans (beq_eq_h _ _ e14).symm)
  · have h' : p + fl = G * 1 + 1 * 0 + 1 * 0 := h
    exact no_big p fl (calc p + fl + 1 = (G * 1 + 1 * 0 + 1 * 0) + 1 := by rw [h']
      _ = G + 1 := by lib_nat
      _ = p := hG)
  · exact n2 ((beq_eq_h _ _ e2).trans (beq_eq_h _ _ e14).symm)
  · exact n2s ((beq_eq_h _ _ es).trans (beq_eq_h _ _ e2).symm)
  · exact n2s ((beq_eq_h _ _ es).trans (beq_eq_h _ _ e2).symm)

/-- **G862d: G_p is not standard.** -/
theorem not_std (a v i0 K : Nat) (eK : K = 7 * (14 * a + v)) (hv : v = 3 ∨ v = 5) (hi : i0 < 14 * a + v) :
    isStd ((K + K) + (K + K)) ((K + K) :: (fam (14 * a + v) i0).map (fun x => 2 * x)) = false := by
  have hp : 0 < 14 * a + v := Nat.lt_of_le_of_lt (Nat.zero_le _) hi
  have hp2 : 2 ≤ 14 * a + v := by
    rcases hv with h | h <;> subst h
    · exact Nat.le_trans (Nat.le.intro (k := 1) rfl) (Nat.le_add_left 3 (14 * a))
    · exact Nat.le_trans (Nat.le.intro (k := 3) rfl) (Nat.le_add_left 5 (14 * a))
  have ⟨rs, hrs, hs⟩ : ∃ rs, (rs = 6 ∨ rs = 10) ∧ (2 * sst (14 * a + v) i0) % 28 = rs % 28 := by
    rcases hv with h | h <;> subst h
    · refine ⟨10, Or.inr rfl, ?_⟩
      unfold sst
      rw [show 2 * (1 + 14 * i0 + 6 * (14 * a + 3)) = 10 + (1 + i0 + 6 * a) * 28 by lib_nat,
        add_mul_mod' 10 28 (Nat.succ_pos 27)]
    · refine ⟨6, Or.inl rfl, ?_⟩
      unfold sst
      rw [show 2 * (1 + 14 * i0 + 6 * (14 * a + 5)) = 6 + (2 + i0 + 6 * a) * 28 by lib_nat,
        add_mul_mod' 6 28 (Nat.succ_pos 27)]
  have hh : (2 * (7 * (14 * a + v))) % 28 = 14 % 28 := by
    rcases hv with h | h <;> subst h
    · rw [show 2 * (7 * (14 * a + 3)) = 14 + (7 * a + 1) * 28 by lib_nat, add_mul_mod' 14 28 (Nat.succ_pos 27)]
    · rw [show 2 * (7 * (14 * a + 5)) = 14 + (7 * a + 2) * 28 by lib_nat, add_mul_mod' 14 28 (Nat.succ_pos 27)]
  have em : (K + K) + (K + K) = 28 * (14 * a + v) := by rw [eK]; lib_nat
  have ec : (K + K) :: (fam (14 * a + v) i0).map (fun x => 2 * x) = (Fq (14 * a + v) i0).map (fun x => 2 * x) := by
    show (K + K) :: _ = (2 * (7 * (14 * a + v))) :: _
    rw [eK, show 2 * (7 * (14 * a + v)) = 7 * (14 * a + v) + 7 * (14 * a + v) by lib_nat]
  have tI := tot_isp a v i0 hv hi
  have tH := tot_ih a v i0 hv hi
  have tO := tot_io a v i0 hv hi
  have lF : (Fq (14 * a + v) i0).length = 14 * a + v + 1 := by
    rw [← len_counts (14 * a + v) i0 (Fq (14 * a + v) i0), tI, tH, tO]
  have same_false : ∀ d b, sameMS ((K + K) :: (fam (14 * a + v) i0).map (fun x => 2 * x))
      (std ((K + K) + (K + K)) d b) = false := by
    intro d b
    cases hsm : sameMS ((K + K) :: (fam (14 * a + v) i0).map (fun x => 2 * x)) (std ((K + K) + (K + K)) d b) with
    | false => rfl
    | true =>
      exfalso
      have G := sameMS_gs _ _ hsm
      rw [ec, em] at G
      -- lengths: d = p
      have G1 := G (fun _ => 1)
      rw [gs_std, GpNoStep.gs_map, ← len_gs, lF] at G1
      have e1 : sumF (fun _ => 1) d + 1 = 14 * a + v + 1 := G1
      rw [sumF_const' 1 d, show d * 1 = d by lib_nat] at e1
      have ed : d = 14 * a + v := Nat.succ.inj e1
      subst ed
      -- class count mod 28
      have G2 := G (fr (b % 28))
      rw [gs_std, DivHand.mul_div' _ hp 28, GpNoStep.gs_map] at G2
      have hterm : ∀ k, fr (b % 28) ((b + k * 28) % (28 * (14 * a + v))) = 1 := fun k =>
        fr_one _ _ (by rw [mod_mod28 _ _ hp, add_mul_mod' b 28 (Nat.succ_pos 27) k])
      rw [sumF_one _ hterm] at G2
      rw [gs_congr_mem _ _ _ (pt a v i0 rs (b % 28) hv hs hh), gs_lin3] at G2
      rw [tI, tH] at G2
      have hb28 : b % 28 < 28 := Nat.mod_lt _ (Nat.succ_pos 27)
      have v2 : fr (b % 28) 2 = if Nat.beq 2 (b % 28) then 1 else 0 := fr_val _ 2 (Nat.le.intro (k := 25) rfl)
      have vs : fr (b % 28) rs = if Nat.beq rs (b % 28) then 1 else 0 := by
        rcases hrs with e | e <;> subst e
        · exact fr_val _ 6 (Nat.le.intro (k := 21) rfl)
        · exact fr_val _ 10 (Nat.le.intro (k := 17) rfl)
      have v14 : fr (b % 28) 14 = if Nat.beq 14 (b % 28) then 1 else 0 := fr_val _ 14 (Nat.le.intro (k := 13) rfl)
      rw [v2, vs, v14] at G2
      exact count_ne _ _ _ rs (b % 28) hp2 hrs tO G2
  unfold isStd
  apply any_false
  intro d
  show (Nat.blt 1 d && Nat.beq (((K + K) + (K + K)) % d) 0 && (List.range ((K + K) + (K + K))).any
    (fun b => sameMS ((K + K) :: (fam (14 * a + v) i0).map (fun x => 2 * x)) (std ((K + K) + (K + K)) d b))) = false
  rw [any_false _ (fun b => same_false d b)]
  exact and_false' _

end GpNotStd

#print axioms GpNotStd.none_ne_some
#print axioms GpNotStd.erase1_some
#print axioms GpNotStd.sub_some
#print axioms GpNotStd.sameMS_gs
#print axioms GpNotStd.loop_gs
#print axioms GpNotStd.gs_range
#print axioms GpNotStd.gs_append
#print axioms GpNotStd.gs_std
#print axioms GpNotStd.any_false
#print axioms GpNotStd.and_false'
#print axioms GpNotStd.sumF_one
#print axioms GpNotStd.gs_congr_mem
#print axioms GpNotStd.gs_lin3
#print axioms GpNotStd.fr_congr
#print axioms GpNotStd.fr_one
#print axioms GpNotStd.fr_val
#print axioms GpNotStd.mod_mod28
#print axioms GpNotStd.pt
#print axioms GpNotStd.no_big
#print axioms GpNotStd.small
#print axioms GpNotStd.count_ne
#print axioms GpNotStd.not_std

#print axioms: 22 theorems, no axioms.

81.248 The family for \(p=15\)

For \(p\equiv 1\pmod {14}\) the special entry is \(7p\); for \(p=15\) the rest \(F'_{15}\) is balanced and indecomposable at \(m=210\).

hodge/FamOne15.lean

/-
  hodge/FamOne15.lean — T41 cycle 1934 (goal G865b): for p ≡ 1 (mod 14) the FamBal datum has x₀ = 1, the
  special element is 7p and F_p = {7p} ⊔ F′_p. For p = 15 (m = 14p = 210): F′_15 is balanced and
  indecomposable, by rfl (2^14 splittings). (p = 29, 43: computation tools/g865.py, meet in the middle.)
  Lean 4 core plus hodge/FamBal; no axioms.
-/
import hodge.FamBal

namespace FamOne15
open Indecomp FamBal

def f15' : List Nat := [197, 183, 169, 155, 141, 127, 113, 99, 85, 71, 57, 43, 29, 1]

theorem fam15_eq : fam 15 1 = [197, 183, 169, 155, 141, 127, 113, 99, 85, 71, 57, 43, 29, 105, 1] := rfl
theorem f15_bal : bal 210 f15' = true := rfl
set_option maxRecDepth 100000 in
theorem f15_indec : indec 210 f15' = true := rfl

end FamOne15

#print axioms FamOne15.fam15_eq
#print axioms FamOne15.f15_bal
#print axioms FamOne15.f15_indec

#print axioms: 3 theorems, no axioms.

81.249 An infinite family of Hodge characters outside the inductive closure

For every prime \(p\equiv 3,5\pmod {14}\), \(p\ge 5\): \(G_p=14p::2F_p\) is Hodge at \(m=28p\), not standard, and not reached by the inductive closure at any fuel.

hodge/GpOpen.lean

/-
  hodge/GpOpen.lean — T41 cycle 1934 (goal G862): for every prime p = 14a + v (v ∈ {3, 5}, p ≥ 5) with
  FamBal data 1 + 14i₀ = p·x₀, the doubled family character G_p = 14p :: 2·F_p at m = 28p is
    Hodge          bal (28p) G_p                         (FamDouble.gp_bal)
    not standard   isStd (28p) G_p = false               (GpNotStd.not_std)
    not reached    reach (28p) (units 28p) f G_p = false for every fuel f  (GpNoStep.no_step)
  by the inductive closure of OpenCerts (Shioda standard characters + splitting with completion).
  This is the uniform form of OpenCertG5 (p = 5, by rfl).
  Lean 4 core plus hodge/GpNotStd, hodge/FamDouble; no axioms.
-/
import hodge.GpNotStd
import hodge.FamDouble

namespace GpOpen
open FermatGens OpenCerts Indecomp FamBal CosetSplitA GpNoStep GpNotStd

theorem anySplit_false (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c : List Nat) :
    ∀ L : List (List Nat), (∀ A, A ∈ L → splitOK m U rec c A = false) → anySplit m U rec c L = false
  | [], _ => rfl
  | A :: L, h => by
    show (splitOK m U rec c A || anySplit m U rec c L) = false
    rw [h A (List.Mem.head _), anySplit_false m U rec c L (fun B hB => h B (List.Mem.tail _ hB))] <;> rfl

theorem blt5 (n : Nat) (h : 5 ≤ n) : Nat.blt n 5 = false := by
  have ⟨k, hk⟩ := Nat.le.dest h
  rw [← hk, show 5 + k = k + 5 by lib_nat]
  rfl

theorem reach_zero (m : Nat) (U c : List Nat) : reach m U 0 c = (Nat.blt c.length 5 || isStd m c) := rfl

theorem reach_succ (m : Nat) (U c : List Nat) (f : Nat) :
    reach m U (f + 1) c = (Nat.blt c.length 5 || isStd m c || anySplit m U (reach m U f) c (subs c)) := rfl

/-- **G862: G_p is Hodge, not standard, and never reached.** -/
theorem gp_open (a v i0 x0 : Nat) (hv : v = 3 ∨ v = 5) (hpr : ∀ d, d ∣ (14 * a + v) → d = 1 ∨ d = 14 * a + v)
    (h14 : Nat.gcd 14 (14 * a + v) = 1) (hi : i0 < 14 * a + v) (hx : 1 + 14 * i0 = (14 * a + v) * x0)
    (h4 : 4 ≤ 14 * a + v) :
    bal (28 * (14 * a + v)) (14 * (14 * a + v) :: (fam (14 * a + v) i0).map (fun x => 2 * x)) = true ∧
    isStd (28 * (14 * a + v)) (14 * (14 * a + v) :: (fam (14 * a + v) i0).map (fun x => 2 * x)) = false ∧
    ∀ f, reach (28 * (14 * a + v)) (FermatPrime.units (28 * (14 * a + v))) f
      (14 * (14 * a + v) :: (fam (14 * a + v) i0).map (fun x => 2 * x)) = false := by
  have hp : 0 < 14 * a + v := Nat.lt_of_le_of_lt (Nat.zero_le _) hi
  have hu := CosetSplitC.u_of a v i0 x0 hv hx
  have hfc : FamMod.fcond (x0 % 14) = true := by
    rcases hu with ⟨_, e⟩ | ⟨_, e⟩ <;> rw [e] <;> rfl
  have hx1 : x0 ≠ 1 := fun e => by
    subst e
    rcases hu with ⟨_, e⟩ | ⟨_, e⟩
    · exact CosetSplitC.nat_ne _ _ rfl e
    · exact CosetSplitC.nat_ne _ _ rfl e
  have hF := FamIndec3.fam_indec _ i0 x0 hp hpr h14 hi hx hx1
  have e1 : 7 * (14 * a + v) + 7 * (14 * a + v) = 14 * (14 * a + v) := by lib_nat
  have e2 : 14 * (14 * a + v) + 14 * (14 * a + v) = 28 * (14 * a + v) := by lib_nat
  have hF' : indec (7 * (14 * a + v) + 7 * (14 * a + v)) (fam (14 * a + v) i0) = true := by rw [e1]; exact hF
  have hstd := not_std a v i0 (7 * (14 * a + v)) rfl hv hi
  rw [e1, e2] at hstd
  have hns := fun rec A hA => no_step a v i0 x0 (7 * (14 * a + v)) rfl hv hpr h14 hi hx hF' rec A hA
  rw [e1, e2] at hns
  have lF : (Fq (14 * a + v) i0).length = 14 * a + v + 1 := by
    rw [← len_counts (14 * a + v) i0 (Fq (14 * a + v) i0), tot_isp a v i0 hv hi, tot_ih a v i0 hv hi,
      tot_io a v i0 hv hi]
  have hlen : (14 * (14 * a + v) :: (fam (14 * a + v) i0).map (fun x => 2 * x)).length = 14 * a + v + 1 := by
    show ((fam (14 * a + v) i0).map (fun x => 2 * x)).length + 1 = _
    rw [FamDouble.len_map]
    exact lF
  have hblt : Nat.blt (14 * (14 * a + v) :: (fam (14 * a + v) i0).map (fun x => 2 * x)).length 5 = false := by
    rw [hlen]; exact blt5 _ (Nat.succ_le_succ h4)
  refine ⟨FamDouble.gp_bal _ i0 x0 hp hi hx hfc, hstd, ?_⟩
  intro f
  cases f with
  | zero => rw [reach_zero, hblt, hstd] <;> rfl
  | succ f =>
    rw [reach_succ, hblt, hstd, anySplit_false _ _ _ _ _ (fun A hA => hns _ A hA)] <;> rfl

end GpOpen

#print axioms GpOpen.anySplit_false
#print axioms GpOpen.blt5
#print axioms GpOpen.reach_zero
#print axioms GpOpen.reach_succ
#print axioms GpOpen.gp_open

#print axioms: 5 theorems, no axioms.

81.250 Standard characters with first entry \(1\)

\([1,1+q,\dots ,1+(d-1)q,\,m-d]\) is balanced at \(m=dq\) (\(d,q\ge 2\)).

hodge/StdBal.lean

/-
  hodge/StdBal.lean — T41 cycle 1934 (goal G866a, tool): the Shioda standard character with first entry 1,
    std1 = [1, 1 + q, …, 1 + (d − 1)q, m − d]   (m = d·q, d ≥ 2, q ≥ 2),
  is balanced, in the `bal` form used by the reach closure: std1_bal. The per-unit identity is
  StdGeneral.std_hodge; the bridge rem ↔ % is ESChain.rem_eq_mod, the AP sum is APDouble.tsum_apL.
  Lean 4 core plus hodge/APDouble; no axioms.
-/
import hodge.APDouble

namespace StdBal
open FTAChain FrobChain QRChain ESChain StdGeneral
open ModHand HalfGeneral Indecomp GcdHand APPair APPairIrrGen APPairGen TwistBal UnitMul UnitInv APDouble

theorem len_app1 (L : List Nat) (c : Nat) : (L ++ [c]).length = L.length + 1 := by
  induction L with
  | nil => rfl
  | cons x L ihL => show (L ++ [c]).length + 1 = L.length + 1 + 1; rw [ihL]

/-- **std(m, d, 1) is balanced.** -/
theorem std1_bal (d'' q' : Nat) (hq : 0 < q') :
    bal ((d'' + 1 + 1) * (q' + 1)) (apL (d'' + 1 + 1) 1 (q' + 1) ++ [(d'' + 1 + 1) * (q' + 1) - (d'' + 1 + 1)]) = true := by
  have hMM : (d'' + 1 + 1) * (q' + 1) = ((d'' + 1) * (q' + 1) + q') + 1 := by lib_nat
  have hM0 : 0 < (d'' + 1 + 1) * (q' + 1) := by rw [hMM]; exact Nat.succ_pos _
  have hdm : (d'' + 1 + 1) ≤ (d'' + 1 + 1) * (q' + 1) := by
    rw [show (d'' + 1 + 1) * (q' + 1) = (d'' + 1 + 1) + (d'' + 1 + 1) * q' by lib_nat]
    exact Nat.le_add_right _ _
  have hcd := GcdHand.sub_add' (d'' + 1 + 1) ((d'' + 1 + 1) * (q' + 1)) hdm
  generalize (d'' + 1 + 1) * (q' + 1) - (d'' + 1 + 1) = c at hcd ⊢
  unfold bal FermatPrime.units
  apply all_fr_intro
  intro t htm hp
  have hg := Nat.eq_of_beq_eq_true hp
  have hgd : Nat.gcd t (d'' + 1 + 1) = 1 := unit_d t _ (q' + 1) hg
  have ⟨v, hv⟩ := inverse t d'' hgd
  have ht' : rem ((d'' + 1) + 1) (v * t) = 1 := by rw [rem_eq_mod]; exact hv
  have ⟨s, hs⟩ := decomp ((t * 1) % ((d'' + 1 + 1) * (q' + 1))) (q' + 1) (Nat.succ_pos q')
  generalize hr : ((t * 1) % ((d'' + 1 + 1) * (q' + 1))) % (q' + 1) = r at hs
  have hrq : r < q' + 1 := hr ▸ Nat.mod_lt _ (Nat.succ_pos q')
  have hx : rem ((d'' + 1 + 1) * (q' + 1)) (t * 1) = r + s * (q' + 1) := by
    rw [hMM, rem_eq_mod, ← hMM, hs, Nat.mul_comm (q' + 1) s]
  have hr0 : 0 < r := by
    cases r with
    | succ r' => exact Nat.succ_pos r'
    | zero =>
      exfalso
      have e1 : (t * 1) % ((d'' + 1 + 1) * (q' + 1)) = t := by
        rw [show t * 1 = t by lib_nat]; exact mod_lt' t _ htm
      rw [e1] at hs
      have ⟨cc, hcc⟩ := APPair1.dvd_gcd (q' + 1) t ((d'' + 1 + 1) * (q' + 1))
        ⟨s, by rw [hs]; lib_nat⟩ ⟨d'' + 1 + 1, by lib_nat⟩
      rw [hg] at hcc
      exact APPair1.one_eq_mul (q' + 1) cc hcc (Nat.succ_le_succ hq)
  have hc : rem ((d'' + 1 + 1) * (q' + 1)) (c + (d'' + 1 + 1) * 1) = 0 := by
    rw [show c + (d'' + 1 + 1) * 1 = c + (d'' + 1 + 1) by lib_nat, hcd, hMM, rem_eq_mod]
    have e := add_mod' 0 ((d'' + 1) * (q' + 1) + q' + 1) (Nat.succ_pos _)
    rw [show 0 + ((d'' + 1) * (q' + 1) + q' + 1) = (d'' + 1) * (q' + 1) + q' + 1 by lib_nat] at e
    rw [e]; exact mod_lt' 0 _ (Nat.succ_pos _)
  have std := std_hodge (d'' + 1) q' t v 1 c r s (Nat.succ_pos d'') ht' hc hx hrq hr0
  have hap : tsum ((d'' + 1 + 1) * (q' + 1)) t (apL (d'' + 1 + 1) 1 (q' + 1))
      = sumTo (d'' + 1 + 1) (fun k => rem ((d'' + 1 + 1) * (q' + 1)) (t * (1 + k * (q' + 1)))) := by
    rw [tsum_apL]
    apply sumTo_congr
    intro k
    rw [hMM, rem_eq_mod]
  have hcm : (t * c) % ((d'' + 1 + 1) * (q' + 1)) = rem ((d'' + 1 + 1) * (q' + 1)) (t * c) := by
    rw [hMM, rem_eq_mod]
  show Nat.beq (tsum ((d'' + 1 + 1) * (q' + 1)) t (apL (d'' + 1 + 1) 1 (q' + 1) ++ [c])
      + tsum ((d'' + 1 + 1) * (q' + 1)) t (apL (d'' + 1 + 1) 1 (q' + 1) ++ [c]))
    ((apL (d'' + 1 + 1) 1 (q' + 1) ++ [c]).length * ((d'' + 1 + 1) * (q' + 1))) = true
  rw [len_app1, len_apL, tsum_append, hap]
  show Nat.beq (sumTo (d'' + 1 + 1) (fun k => rem ((d'' + 1 + 1) * (q' + 1)) (t * (1 + k * (q' + 1))))
      + ((t * c) % ((d'' + 1 + 1) * (q' + 1)) + 0)
      + (sumTo (d'' + 1 + 1) (fun k => rem ((d'' + 1 + 1) * (q' + 1)) (t * (1 + k * (q' + 1))))
      + ((t * c) % ((d'' + 1 + 1) * (q' + 1)) + 0)))
    ((d'' + 1 + 1 + 1) * ((d'' + 1 + 1) * (q' + 1))) = true
  rw [hcm]
  generalize sumTo (d'' + 1 + 1) (fun k => rem ((d'' + 1 + 1) * (q' + 1)) (t * (1 + k * (q' + 1)))) = S at std ⊢
  generalize rem ((d'' + 1 + 1) * (q' + 1)) (t * c) = X at std ⊢
  have e : S + (X + 0) + (S + (X + 0)) = (d'' + 1 + 1 + 1) * ((d'' + 1 + 1) * (q' + 1)) := by
    rw [show S + (X + 0) + (S + (X + 0)) = 2 * (S + X) by lib_nat, std] <;> lib_nat
  rw [e]
  exact beq_self _

end StdBal

#print axioms StdBal.len_app1
#print axioms StdBal.std1_bal

#print axioms: 2 theorems, no axioms.

81.251 The seed families \(G(36k)\), \(H(36k)\) are reached

Each splits in one step into the standard character \(\mathrm {std}(36k,3,1)\) and a completed triple; the complement of a completed Hodge part of a Hodge character is Hodge.

hodge/SeedFamReach.lean

/-
  hodge/SeedFamReach.lean — T41 cycle 1934 (goal G866a): the seed families G(36k), H(36k) (SeedFamGHAll: balanced and
  indecomposable for every k ≥ 1) are reached by the inductive closure of OpenCerts in one split step:
    G(36k) = {1, 24k+1, 36k−3} ⊔ {6k−1, 24k+2}:  completions std(36k, 3, 1) and {24k−1, 6k−1, 24k+2}
    H(36k) = {1, 12k+1, 24k+1} ⊔ {18k+3, 36k−6}:  completions std(36k, 3, 1) and {3, 18k+3, 36k−6}
  Tools: compl_bal (the completed complement of a completed Hodge part of a Hodge character is Hodge),
  splitOK_true, reach_short (length < 5 is the base), reach_step (one split step), StdBal.std1_bal.
    g_reach, h_reach   reach (36k) (units 36k) (f + 1) G(36k) = true, same for H
  Lean 4 core plus hodge/GpOpen, hodge/StdBal, hodge/SeedFamGHAll, hodge/PairsSplit; no axioms.
-/
import hodge.GpOpen
import hodge.StdBal
import hodge.SeedFamGHAll
import hodge.PairsSplit

namespace SeedFamReach
open FermatGens OpenCerts Indecomp QFamPrime SubsSum GpNoStep GpOpen TwistBal ModHand APDouble

theorem bal_gs (m : Nat) (L : List Nat) (t : Nat) : Indecomp.tsum m t L = gs (fun x => (t * x) % m) L := by
  rw [tsum_eq, SubsSum.tsum_gs]

theorem bal_congr (m : Nat) (X Y : List Nat) (h : ∀ f : Nat → Nat, gs f X = gs f Y) : bal m X = bal m Y := by
  rw [← hodge_bal, ← hodge_bal]; exact hodgeB_congr m _ X Y h

/-- the completed complement of a completed Hodge part of a Hodge character is Hodge -/
theorem compl_bal (m : Nat) (G A R : List Nat) (s : Nat) (hs0 : 0 < s) (hsm : s < m)
    (hgs : ∀ f : Nat → Nat, gs f A + gs f R = gs f G) (hG : bal m G = true) (hA : bal m ((m - s) :: A) = true) :
    bal m (s :: R) = true := by
  cases m with
  | zero => exact absurd hsm (Nat.not_lt_zero s)
  | succ m' =>
  unfold bal FermatPrime.units at *
  apply all_fr_intro
  intro t ht hp
  have hg := Nat.eq_of_beq_eq_true hp
  have g1 := beq_eq_h _ _ (all_fr_elim _ _ (m' + 1) hG t ht hp)
  have g2 := beq_eq_h _ _ (all_fr_elim _ _ (m' + 1) hA t ht hp)
  have pr := PairsSplit.pair_mod m' t s hg hs0 hsm
  rw [bal_gs, len_gs] at g1
  have g2' : ((t * (m' + 1 - s)) % (m' + 1) + Indecomp.tsum (m' + 1) t A)
      + ((t * (m' + 1 - s)) % (m' + 1) + Indecomp.tsum (m' + 1) t A) = (A.length + 1) * (m' + 1) := g2
  rw [bal_gs, len_gs] at g2'
  show Nat.beq (((t * s) % (m' + 1) + Indecomp.tsum (m' + 1) t R) + ((t * s) % (m' + 1) + Indecomp.tsum (m' + 1) t R))
    ((R.length + 1) * (m' + 1)) = true
  rw [bal_gs, len_gs R]
  have hs := hgs (fun x => (t * x) % (m' + 1))
  have hl := hgs (fun _ => 1)
  generalize gs (fun x => (t * x) % (m' + 1)) A = a at g2' hs
  generalize gs (fun x => (t * x) % (m' + 1)) R = r at hs ⊢
  generalize gs (fun x => (t * x) % (m' + 1)) G = g at g1 hs
  generalize gs (fun _ => 1) A = lA at g2' hl
  generalize gs (fun _ => 1) R = lR at hl ⊢
  generalize gs (fun _ => 1) G = lG at g1 hl
  generalize (t * s) % (m' + 1) = P at pr ⊢
  generalize (t * (m' + 1 - s)) % (m' + 1) = Q at pr g2'
  subst hs hl
  have key : P + r + (P + r) = (lR + 1) * (m' + 1) := FamBal.add_right_cancel' _ _ (Q + a + (Q + a)) (by
    calc P + r + (P + r) + (Q + a + (Q + a)) = (P + Q) + (P + Q) + ((a + r) + (a + r)) := by lib_nat
      _ = (m' + 1) + (m' + 1) + (lA + lR) * (m' + 1) := by rw [pr, g1]
      _ = (lR + 1) * (m' + 1) + (lA + 1) * (m' + 1) := by lib_nat
      _ = (lR + 1) * (m' + 1) + (Q + a + (Q + a)) := by rw [g2'])
  rw [key]; exact HalfGeneral.beq_self _

theorem ble_of_le : ∀ a b : Nat, a ≤ b → Nat.ble a b = true
  | 0, _, _ => rfl
  | _ + 1, 0, h => absurd h (Nat.not_succ_le_zero _)
  | a + 1, b + 1, h => ble_of_le a b (Nat.le_of_succ_le_succ h)

theorem blt_of_lt {a b : Nat} (h : a < b) : Nat.blt a b = true := ble_of_le (a + 1) b h

theorem reach_short (m : Nat) (U L : List Nat) (hl : L.length < 5) : ∀ f, reach m U f L = true
  | 0 => by rw [reach_zero, blt_of_lt hl] <;> rfl
  | f + 1 => by rw [reach_succ, blt_of_lt hl] <;> rfl

theorem anySplit_true (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c A : List Nat) (hA : splitOK m U rec c A = true) :
    ∀ L : List (List Nat), A ∈ L → anySplit m U rec c L = true
  | [], h => nomatch h
  | B :: L, h => by
    show (splitOK m U rec c B || anySplit m U rec c L) = true
    cases h with
    | head => rw [hA] <;> rfl
    | tail _ h' => rw [anySplit_true m U rec c A hA L h'] <;> cases splitOK m U rec c B <;> rfl

theorem splitOK_true (m : Nat) (U : List Nat) (rec : List Nat → Bool) (c A : List Nat) (hs : lsumN A % m ≠ 0)
    (h1 : Nat.blt (((m - lsumN A % m) :: A).length) c.length = true)
    (h2 : Nat.blt (((lsumN A % m) :: compl c A).length) c.length = true)
    (h3 : hodgeB m U ((m - lsumN A % m) :: A) = true) (h4 : hodgeB m U ((lsumN A % m) :: compl c A) = true)
    (h5 : rec ((m - lsumN A % m) :: A) = true) (h6 : rec ((lsumN A % m) :: compl c A) = true) :
    splitOK m U rec c A = true := by
  show (if Nat.beq (lsumN A % m) 0 = true then
      (!A.isEmpty && !(compl c A).isEmpty && hodgeB m U A && hodgeB m U (compl c A) && rec A && rec (compl c A))
    else
      (Nat.blt ((m - lsumN A % m) :: A).length c.length && Nat.blt ((lsumN A % m) :: compl c A).length c.length &&
        hodgeB m U ((m - lsumN A % m) :: A) && hodgeB m U ((lsumN A % m) :: compl c A) &&
        rec ((m - lsumN A % m) :: A) && rec ((lsumN A % m) :: compl c A))) = true
  have hb : Nat.beq (lsumN A % m) 0 = false := by
    cases e : Nat.beq (lsumN A % m) 0 with
    | false => rfl
    | true => exact absurd (beq_eq_h _ _ e) hs
  rw [hb]
  show (Nat.blt ((m - lsumN A % m) :: A).length c.length && Nat.blt ((lsumN A % m) :: compl c A).length c.length &&
        hodgeB m U ((m - lsumN A % m) :: A) && hodgeB m U ((lsumN A % m) :: compl c A) &&
        rec ((m - lsumN A % m) :: A) && rec ((lsumN A % m) :: compl c A)) = true
  rw [h1, h2, h3, h4, h5, h6] <;> rfl

/-- **one split step reaches c** -/
theorem reach_step (m : Nat) (c A R0 : List Nat) (f : Nat) (hA : A ∈ subs c)
    (hR0 : ∀ g : Nat → Nat, gs g A + gs g R0 = gs g c) (hs0 : 0 < lsumN A % m) (hsm : lsumN A % m < m)
    (hc : bal m c = true) (hA2 : bal m ((m - lsumN A % m) :: A) = true)
    (hl1 : A.length + 1 < c.length) (hl2 : R0.length + 1 < c.length) (hlA : A.length + 1 < 5) (hlR : R0.length + 1 < 5) :
    reach m (FermatPrime.units m) (f + 1) c = true := by
  have ⟨R, hR, hBR⟩ := compl_spec c A hA
  have hsum := fun g => SubsSum.splits_gs g c A R hR
  have hRR : ∀ g : Nat → Nat, gs g (compl c A) = gs g R0 := fun g => by
    rw [hBR g]; exact BalAppend.add_cancel (gs g A) _ _ (by rw [hsum g, hR0 g])
  have hlen : (compl c A).length = R0.length := by rw [len_gs, hRR, ← len_gs]
  have hB2 : bal m ((lsumN A % m) :: R0) = true := compl_bal m c A R0 _ hs0 hsm hR0 hc hA2
  have hB2' : hodgeB m (FermatPrime.units m) ((lsumN A % m) :: compl c A) = true := by
    rw [hodgeB_congr m _ _ ((lsumN A % m) :: R0) (fun g => by
      show g _ + gs g (compl c A) = g _ + gs g R0
      rw [hRR g]), hodge_bal]
    exact hB2
  have ok := splitOK_true m (FermatPrime.units m) (reach m (FermatPrime.units m) f) c A
    (fun e => by rw [e] at hs0; exact Nat.lt_irrefl 0 hs0)
    (blt_of_lt hl1) (blt_of_lt (by show (compl c A).length + 1 < c.length; rw [hlen]; exact hl2))
    (by rw [hodge_bal]; exact hA2) hB2'
    (reach_short m _ ((m - lsumN A % m) :: A) hlA f) (reach_short m _ ((lsumN A % m) :: compl c A) (by show (compl c A).length + 1 < 5; rw [hlen]; exact hlR) f)
  rw [reach_succ, anySplit_true _ _ _ c A ok (subs c) hA]
  cases Nat.blt c.length 5 <;> cases isStd m c <;> rfl

theorem mem_map_cons (x : Nat) (A : List Nat) : ∀ L : List (List Nat), A ∈ L → (x :: A) ∈ L.map (x :: ·)
  | [], h => nomatch h
  | B :: L, h => by
    cases h with
    | head => exact List.Mem.head _
    | tail _ h' => exact List.Mem.tail _ (mem_map_cons x A L h')

theorem take (x : Nat) (A l : List Nat) (h : A ∈ subs l) : (x :: A) ∈ subs (x :: l) :=
  mem_app_l _ _ _ (mem_map_cons x A (subs l) h)

theorem skip (x : Nat) (A l : List Nat) (h : A ∈ subs l) : A ∈ subs (x :: l) :=
  mem_app_r _ _ _ h

theorem nil_subs : ([] : List Nat) ∈ subs [] := List.Mem.head _

/-- std(36(j+1), 3, 1) as a list -/
theorem std_list (j : Nat) : apL (1 + 1 + 1) 1 (12 * j + 11 + 1) ++ [(1 + 1 + 1) * (12 * j + 11 + 1) - (1 + 1 + 1)]
    = [1, 12 * j + 13, 24 * j + 25, 36 * j + 33] := by
  show [1 + 0 * (12 * j + 11 + 1), 1 + 1 * (12 * j + 11 + 1), 1 + 2 * (12 * j + 11 + 1)]
      ++ [(1 + 1 + 1) * (12 * j + 11 + 1) - (1 + 1 + 1)] = _
  rw [show 1 + 0 * (12 * j + 11 + 1) = 1 by lib_nat, show 1 + 1 * (12 * j + 11 + 1) = 12 * j + 13 by lib_nat,
    show 1 + 2 * (12 * j + 11 + 1) = 24 * j + 25 by lib_nat,
    show (1 + 1 + 1) * (12 * j + 11 + 1) = (36 * j + 33) + (1 + 1 + 1) by lib_nat, add_sub'] <;> rfl

theorem std_bal (j : Nat) : bal (36 * j + 36) [1, 12 * j + 13, 24 * j + 25, 36 * j + 33] = true := by
  have h := StdBal.std1_bal 1 (12 * j + 11) (Nat.succ_pos _)
  rw [std_list, show (1 + 1 + 1) * (12 * j + 11 + 1) = 36 * j + 36 by lib_nat] at h
  exact h

theorem sub1 (x : Nat) : (x + 1) - 1 = x := add_sub' x 1

theorem G_eq (j : Nat) : SeedFamGH.G (j + 1) = [1, 6 * j + 5, 24 * j + 25, 24 * j + 26, 36 * j + 33] := by
  show [1, 6 * (j + 1) - 1, 24 * (j + 1) + 1, 24 * (j + 1) + 2, 36 * (j + 1) - 3] = _
  rw [show 6 * (j + 1) = (6 * j + 5) + 1 by lib_nat, sub1, show 24 * (j + 1) + 1 = 24 * j + 25 by lib_nat,
    show 24 * (j + 1) + 2 = 24 * j + 26 by lib_nat, show 36 * (j + 1) = (36 * j + 33) + 3 by lib_nat, add_sub']

theorem H_eq (j : Nat) : SeedFamGH.H (j + 1) = [1, 12 * j + 13, 24 * j + 25, 18 * j + 21, 36 * j + 30] := by
  show [1, 12 * (j + 1) + 1, 24 * (j + 1) + 1, 18 * (j + 1) + 3, 36 * (j + 1) - 6] = _
  rw [show 12 * (j + 1) + 1 = 12 * j + 13 by lib_nat, show 24 * (j + 1) + 1 = 24 * j + 25 by lib_nat,
    show 18 * (j + 1) + 3 = 18 * j + 21 by lib_nat, show 36 * (j + 1) = (36 * j + 30) + 6 by lib_nat, add_sub']

theorem lt_m (j x : Nat) (h : x + 1 ≤ 36 * j + 36) : x < 36 * j + 36 := h

/-- **G(36k) is reached for every k ≥ 1.** -/
theorem g_reach (j f : Nat) :
    reach (36 * (j + 1)) (FermatPrime.units (36 * (j + 1))) (f + 1) (SeedFamGH.G (j + 1)) = true := by
  have hb := (SeedFamGHAll.g_seed (j + 1) (Nat.succ_pos j)).1
  rw [G_eq, show 36 * (j + 1) = 36 * j + 36 by lib_nat] at *
  have hls : lsumN [1, 24 * j + 25, 36 * j + 33] % (36 * j + 36) = 24 * j + 23 :=
    APPair.mod_rep _ _ _ 1 (lt_m j _ (Nat.le.intro (k := 12 * j + 12) (by lib_nat))) (by show 1 + (24 * j + 25 + (36 * j + 33 + 0)) = _; lib_nat)
  have hms : 36 * j + 36 - (24 * j + 23) = 12 * j + 13 := by
    rw [show 36 * j + 36 = (12 * j + 13) + (24 * j + 23) by lib_nat]; exact add_sub' _ _
  apply reach_step (36 * j + 36) _ [1, 24 * j + 25, 36 * j + 33] [6 * j + 5, 24 * j + 26] f
  · exact take _ _ _ (skip _ _ _ (take _ _ _ (skip _ _ _ (take _ _ _ nil_subs))))
  · intro g
    show (g 1 + (g (24 * j + 25) + (g (36 * j + 33) + 0))) + (g (6 * j + 5) + (g (24 * j + 26) + 0))
      = g 1 + (g (6 * j + 5) + (g (24 * j + 25) + (g (24 * j + 26) + (g (36 * j + 33) + 0))))
    lib_nat
  · rw [hls]; exact Nat.succ_pos _
  · rw [hls]; exact lt_m j _ (Nat.le.intro (k := 12 * j + 12) (by lib_nat))
  · exact hb
  · rw [hls, hms, bal_congr _ _ [1, 12 * j + 13, 24 * j + 25, 36 * j + 33] (fun g => by
      show g (12 * j + 13) + (g 1 + (g (24 * j + 25) + (g (36 * j + 33) + 0)))
        = g 1 + (g (12 * j + 13) + (g (24 * j + 25) + (g (36 * j + 33) + 0)))
      lib_nat)]
    exact std_bal j
  · exact Nat.lt_succ_self 4
  · exact Nat.le.intro (k := 1) rfl
  · exact Nat.lt_succ_self 4
  · exact Nat.le.intro (k := 1) rfl

/-- **H(36k) is reached for every k ≥ 1.** -/
theorem h_reach (j f : Nat) :
    reach (36 * (j + 1)) (FermatPrime.units (36 * (j + 1))) (f + 1) (SeedFamGH.H (j + 1)) = true := by
  have hb := (SeedFamGHAll.h_seed (j + 1) (Nat.succ_pos j)).1
  rw [H_eq, show 36 * (j + 1) = 36 * j + 36 by lib_nat] at *
  have hls : lsumN [1, 12 * j + 13, 24 * j + 25] % (36 * j + 36) = 3 :=
    APPair.mod_rep _ _ _ 1 (lt_m j _ (Nat.le.intro (k := 36 * j + 32) (by lib_nat))) (by show 1 + (12 * j + 13 + (24 * j + 25 + 0)) = _; lib_nat)
  have hms : 36 * j + 36 - 3 = 36 * j + 33 := by
    rw [show 36 * j + 36 = (36 * j + 33) + 3 by lib_nat]; exact add_sub' _ _
  apply reach_step (36 * j + 36) _ [1, 12 * j + 13, 24 * j + 25] [18 * j + 21, 36 * j + 30] f
  · exact take _ _ _ (take _ _ _ (take _ _ _ (skip _ _ _ (skip _ _ _ nil_subs))))
  · intro g
    show (g 1 + (g (12 * j + 13) + (g (24 * j + 25) + 0))) + (g (18 * j + 21) + (g (36 * j + 30) + 0))
      = g 1 + (g (12 * j + 13) + (g (24 * j + 25) + (g (18 * j + 21) + (g (36 * j + 30) + 0))))
    lib_nat
  · rw [hls]; exact Nat.succ_pos _
  · rw [hls]; exact lt_m j _ (Nat.le.intro (k := 36 * j + 32) (by lib_nat))
  · exact hb
  · rw [hls, hms, bal_congr _ _ [1, 12 * j + 13, 24 * j + 25, 36 * j + 33] (fun g => by
      show g (36 * j + 33) + (g 1 + (g (12 * j + 13) + (g (24 * j + 25) + 0)))
        = g 1 + (g (12 * j + 13) + (g (24 * j + 25) + (g (36 * j + 33) + 0)))
      lib_nat)]
    exact std_bal j
  · exact Nat.lt_succ_self 4
  · exact Nat.le.intro (k := 1) rfl
  · exact Nat.lt_succ_self 4
  · exact Nat.le.intro (k := 1) rfl

end SeedFamReach

#print axioms SeedFamReach.bal_gs
#print axioms SeedFamReach.bal_congr
#print axioms SeedFamReach.compl_bal
#print axioms SeedFamReach.ble_of_le
#print axioms SeedFamReach.blt_of_lt
#print axioms SeedFamReach.reach_short
#print axioms SeedFamReach.anySplit_true
#print axioms SeedFamReach.splitOK_true
#print axioms SeedFamReach.reach_step
#print axioms SeedFamReach.mem_map_cons
#print axioms SeedFamReach.take
#print axioms SeedFamReach.skip
#print axioms SeedFamReach.nil_subs
#print axioms SeedFamReach.std_list
#print axioms SeedFamReach.std_bal
#print axioms SeedFamReach.sub1
#print axioms SeedFamReach.G_eq
#print axioms SeedFamReach.H_eq
#print axioms SeedFamReach.lt_m
#print axioms SeedFamReach.g_reach
#print axioms SeedFamReach.h_reach

#print axioms: 21 theorems, no axioms.

81.252 Affine certificates for rank \(n-1\)

If \(BA=dI\) then \(Ag=c\) forces \(dg=Bc\); with \(Bc_\ell =W\) a balanced indicator is fixed by its last entry.

hodge/MailletLin1.lean

/-
  hodge/MailletLin1.lean — T41 cycle 2016 (goal G865d): the inhomogeneous form of MailletLin.kernel_zero, for
  rank-(n−1) certificates. If every row of A has length n and the rows of B combine the rows of A to d times the
  identity, then A g = c with |g| = n forces d·g = B c:
    kernel_affine   mv A g = c  ⇒  smul d g = mv B c.
  Use (G865d): with A the balance equations of F′_p on n − 1 columns, restricted to x ≠ ℓ, and c = −v_ℓ·(row ℓ),
  the indicator of a balanced subset is fixed by v_ℓ ∈ {0, 1}: only ∅ and (when balanced) the full set.
  Lean 4 core, hand proofs, no axioms.
-/
import hodge.MailletLin

namespace MailletLin1
open LibInt MailletLin

theorem kernel_affine (n : Nat) (d : Int) (A B : List (List Int))
    (hA : allLen n A = true) (hc : lcs n B A = sid d n)
    (g : List Int) (hg : g.length = n) (c : List Int) (h : mv A g = c) : smul d g = mv B c := by
  have h1 : mv B (mv A g) = smul d g := by rw [mv_mv n A g hA, hc, mv_sid d n g hg]
  rw [h] at h1
  exact h1.symm

end MailletLin1

#print axioms MailletLin1.kernel_affine

#print axioms: 1 theorem, no axioms.

hodge/MailletLin2.lean

/-
  hodge/MailletLin2.lean — T41 cycle 2016 (goal G865d): the affine fix of a rank-(n−1) certificate. With
  MailletLin1.kernel_affine: if mv A g = smul e cl (e the negated last entry of a 0/1 indicator) and mv B cl = W,
  then smul d g = smul e W:
    dot_smul_right   dot b (smul c v) = c·dot b v
    mv_smul          mv B (smul c v) = smul c (mv B v)
    affine_fix       the indicator's first n − 1 entries are fixed by its last entry.
  Lean 4 core, hand proofs, no axioms.
-/
import hodge.MailletLin1

namespace MailletLin2
open LibInt MailletLin MailletLin1

theorem dot_smul_right (c : Int) : ∀ b v : List Int, dot b (smul c v) = c * dot b v
  | [], _ => by show (0 : Int) = c * 0; lib_int
  | _ :: _, [] => by show (0 : Int) = c * 0; lib_int
  | a :: as, x :: xs => by
    show a * (c * x) + dot as (smul c xs) = c * (a * x + dot as xs)
    rw [dot_smul_right c as xs]
    generalize dot as xs = P
    lib_int

theorem mv_smul (c : Int) (v : List Int) : ∀ B : List (List Int), mv B (smul c v) = smul c (mv B v)
  | [] => rfl
  | b :: bs => by
    show dot b (smul c v) :: mv bs (smul c v) = (c * dot b v) :: smul c (mv bs v)
    rw [dot_smul_right c b v, mv_smul c v bs]

theorem affine_fix (n : Nat) (d e : Int) (A B : List (List Int))
    (hA : allLen n A = true) (hc : lcs n B A = sid d n) (cl W : List Int) (hW : mv B cl = W)
    (g : List Int) (hg : g.length = n) (h : mv A g = smul e cl) : smul d g = smul e W := by
  rw [kernel_affine n d A B hA hc g hg (smul e cl) h, mv_smul e cl B, hW]

end MailletLin2

#print axioms MailletLin2.dot_smul_right
#print axioms MailletLin2.mv_smul
#print axioms MailletLin2.affine_fix

#print axioms: 3 theorems, no axioms.

81.253 Rank certificates for \(F'_p\), \(p=15,29,43\)

The balance matrices of \(F'_p\) have rank \(n-1\): integer certificates \(BA=dI\), \(Bc_\ell =-d\cdot \mathbf 1\).

hodge/FamCert15.lean

/-
  hodge/FamCert15.lean — T41 (goal G865d): rank certificate for the balance matrix of F′_15 (n = 14): the rows of
  A (balance equations on 13 unit columns, restricted to the first 13 elements of F′_15) combine under the
  integer matrix B to d·I, d = 420, and B applied to the last element's column values is W (tools/g865_cert.py).
  With hodge/MailletLin1.kernel_affine: every balanced 0/1 indicator is fixed by its last entry. Lean 4 core, rfl.
-/
import hodge.MailletLin1

set_option maxHeartbeats 0
set_option maxRecDepth 100000

namespace FamCert15
open MailletLin

def A : List (List Int) := [[-208, -152, -124, -96, -68, -40, -12, 16, 44, 72, 100, 128, 156], [-188, 8, -104, 204, 92, -20, -132, 176, 64, -48, -160, 148, 36], [-184, 124, 68, 12, -44, -100, -156, 208, 152, 96, 40, -16, -72], [-176, -64, -8, 48, 104, 160, -204, -148, -92, -36, 20, 76, 132], [-172, 52, 164, -144, -32, 80, 192, -116, -4, 108, -200, -88, 24], [-164, -136, 88, -108, 116, -80, 144, -5  -- (+492 chars; full line in the Zenodo source)
def B : List (List Int) := [[0, -1, 0, -1, -1, -1, 1, 0, 0, 1, 0, 0, 0], [-1, 0, 1, 0, 1, -1, 0, 1, -1, 0, 0, 1, -1], [0, -1, 1, -1, 0, -1, 2, 0, 0, 1, 0, 0, -1], [0, 0, 0, 0, 0, -1, 1, 1, -1, 0, 0, 0, 0], [0, 0, 0, -1, -1, 0, 1, -1, 0, 1, 1, 1, 0], [-1, -1, 1, 1, 1, -2, 1, 2, -1, 0, -1, 1, -1], [0, 0, 0, -1, 1, -1, 1, 1, -1, 0, 0, 1, -1], [0, 0, 1, -1, 0, -1, 1, 0, 0, 0, 0, 1, -1], [0, -1, 1, 0,   -- (+210 chars; full line in the Zenodo source)
def cl : List Int := [184, -76, -128, 188, 136, 32, -124, -176, 88, -16, -68, -64, -116]
def W : List Int := [-420, -420, -420, -420, -420, -420, -420, -420, -420, -420, -420, -420, -420]

theorem allLen_A : allLen 13 A = true := rfl
theorem cert : lcs 13 B A = sid 420 13 := rfl
theorem w_eq : mv B cl = W := rfl

end FamCert15

#print axioms FamCert15.allLen_A
#print axioms FamCert15.cert
#print axioms FamCert15.w_eq

#print axioms: 3 theorems, no axioms.

hodge/FamCert29.lean

/-
  hodge/FamCert29.lean — T41 (goal G865d): rank certificate for the balance matrix of F′_29 (n = 28): the rows of
  A (balance equations on 27 unit columns, restricted to the first 27 elements of F′_29) combine under the
  integer matrix B to d·I, d = 37352, and B applied to the last element's column values is W (tools/g865_cert.py).
  With hodge/MailletLin1.kernel_affine: every balanced 0/1 indicator is fixed by its last entry. Lean 4 core, rfl.
-/
import hodge.MailletLin1

set_option maxHeartbeats 0
set_option maxRecDepth 100000

namespace FamCert29
open MailletLin

def A : List (List Int) := [[-404, -376, -320, -292, -264, -236, -208, -180, -152, -124, -96, -68, -40, -12, 16, 44, 72, 100, 128, 156, 184, 212, 240, 268, 296, 324, 352], [-400, -316, -148, -64, 20, 104, 188, 272, 356, -372, -288, -204, -120, -36, 48, 132, 216, 300, 384, -344, -260, -176, -92, -8, 76, 160, 244], [-396, -256, 24, 164, 304, -368, -228, -88, 52, 192, 332, -340, -200, -60, 80, 220, 3  -- (+3490 chars; full line in the Zenodo source)
def B : List (List Int) := [[92, 26, 9, -28, 11, -25, -106, -21, -71, 43, 23, 53, -56, -12, -26, -46, -76, -84, 0, 18, 0, 115, 89, 126, -24, -104, -33], [92, -24, -3, -52, -19, -7, -26, 7, -7, 1, 23, 59, -58, 4, -22, -46, -36, -18, 0, 40, 0, 69, 47, 96, -38, -42, -35], [46, 58, 13, -20, 21, -31, -102, -15, -77, 57, 23, 51, -40, -2, -12, -46, -74, -60, 0, 26, 0, 115, 103, 90, -4, -94, -17], [46, 18  -- (+2921 chars; full line in the Zenodo source)
def cl : List Int := [380, 328, 276, 172, 120, 68, 16, -36, -88, -192, -244, -296, -400, 360, 256, 204, 152, 100, 48, -4, -108, -160, -212, -264, -316, -368, 340]
def W : List Int := [-37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352, -37352]

theorem allLen_A : allLen 27 A = true := rfl
theorem cert : lcs 27 B A = sid 37352 27 := rfl
theorem w_eq : mv B cl = W := rfl

end FamCert29

#print axioms FamCert29.allLen_A
#print axioms FamCert29.cert
#print axioms FamCert29.w_eq

#print axioms: 3 theorems, no axioms.

hodge/FamCert43.lean

/-
  hodge/FamCert43.lean — T41 (goal G865d): rank certificate for the balance matrix of F′_43 (n = 42): the rows of
  A (balance equations on 41 unit columns, restricted to the first 41 elements of F′_43) combine under the
  integer matrix B to d·I, d = 100051196, and B applied to the last element's column values is W (tools/g865_cert.py).
  With hodge/MailletLin1.kernel_affine: every balanced 0/1 indicator is fixed by its last entry. Lean 4 core, rfl.
-/
import hodge.MailletLin1

set_option maxHeartbeats 0
set_option maxRecDepth 100000

namespace FamCert43
open MailletLin

def A : List (List Int) := [[-600, -572, -544, -488, -460, -432, -404, -376, -348, -320, -292, -264, -236, -208, -180, -152, -124, -96, -68, -40, -12, 16, 44, 72, 100, 128, 156, 184, 212, 240, 268, 296, 324, 352, 380, 408, 436, 464, 492, 520, 548], [-596, -512, -428, -260, -176, -92, -8, 76, 160, 244, 328, 412, 496, 580, -540, -456, -372, -288, -204, -120, -36, 48, 132, 216, 300, 384, 468, 552, -5  -- (+8649 chars; full line in the Zenodo source)
def B : List (List Int) := [[648090, -253171, -234821, -315862, -376438, 200314, 67075, -123222, -217703, -249470, 62840, 136504, 334877, 574778, 376705, -539975, -159382, 279002, 37730, -242923, 52278, -128508, 402608, 241107, -138154, 102505, 119054, -204609, -339624, -49119, 116691, -61818, -36128, -284651, 170072, 532933, -690726, -46834, -537571, 380283, 143492], [265423, -142765, -110171, -1  -- (+13215 chars; full line in the Zenodo source)
def cl : List Int := [576, 524, 472, 368, 316, 264, 212, 160, 108, 4, -48, -100, -152, -204, -256, -360, -412, -464, -568, 584, 480, 428, 376, 324, 272, 220, 116, 64, 12, -40, -92, -144, -248, -300, -352, -404, -456, -508, 592, 540, 488]
def W : List Int := [-100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051196, -100051  -- (+112 chars; full line in the Zenodo source)

theorem allLen_A : allLen 41 A = true := rfl
theorem cert : lcs 41 B A = sid 100051196 41 := rfl
theorem w_eq : mv B cl = W := rfl

end FamCert43

#print axioms FamCert43.allLen_A
#print axioms FamCert43.cert
#print axioms FamCert43.w_eq

#print axioms: 3 theorems, no axioms.

81.254 From balance to equal counts

A list balanced at every certificate column has every count equal to that of the last element.

hodge/FamBridge.lean

/-
  hodge/FamBridge.lean — T41 cycle 2018 (goal G865e): from balance to the rank certificate. For a list xs of residues
  mod M (the first n − 1 elements of F′_p), a last element ℓ ∉ xs, unit columns C, and a list S with entries in xs or
  ℓ that is balanced at every t ∈ C (2·T_t(S) = |S|·M), the counts g_x = #x(S) (x ∈ xs) and e = #ℓ(S) satisfy the
  certificate equations A g = −e·cl (A = rows 2⟨t x⟩ − M, cl = 2⟨t ℓ⟩ − M); with a certificate B A = d I, B cl = −d·1
  (hodge/FamCert<p>), MailletLin2.affine_fix gives
    fam_counts   every x ∈ xs occurs in S exactly as often as ℓ,
  i.e. a balanced subset of F′_p is ∅ or all of F′_p: F′_p is indecomposable (G865 for p = 15, 29, 43).
  Lean 4 core, hand proofs, no axioms; the per-x facts row_t · e_y are finite checks (rfl in the instance file).
-/
import hodge.MailletLin2
import hodge.MailletBridge

namespace FamBridge
open LibInt MailletLin MailletLin1 MailletLin2 MailletBridge

/-- counts of the elements of xs in S -/
def gv (xs S : List Nat) : List Int := xs.map (fun x => (cnt x S : Int))
/-- indicator of y on xs -/
def ev (xs : List Nat) (y : Nat) : List Int := xs.map (fun x => ind (Nat.beq x y))
/-- the all-ones vector -/
def ones : Nat → List Int
  | 0 => []
  | n + 1 => 1 :: ones n

theorem gv_nil : ∀ xs : List Nat, gv xs [] = zeros xs.length
  | [] => rfl
  | _ :: xs => by
    show ((0 : Nat) : Int) :: gv xs [] = 0 :: zeros xs.length
    rw [gv_nil xs]; rfl

theorem gv_cons (y : Nat) (S : List Nat) : ∀ xs : List Nat, gv xs (y :: S) = addV (gv xs S) (ev xs y)
  | [] => rfl
  | x :: xs => by
    show ((cond (Nat.beq x y) 1 0 + cnt x S : Nat) : Int) :: gv xs (y :: S)
      = ((cnt x S : Int) + ind (Nat.beq x y)) :: addV (gv xs S) (ev xs y)
    rw [gv_cons y S xs, natCast_add, cond_cast]
    generalize ind (Nat.beq x y) = a
    generalize ((cnt x S : Nat) : Int) = u
    have e : a + u = u + a := by lib_int
    rw [e]

theorem len_ones : ∀ n : Nat, (ones n).length = n
  | 0 => rfl
  | n + 1 => by show (ones n).length + 1 = n + 1; rw [len_ones n]

theorem len_gv (xs S : List Nat) : (gv xs S).length = xs.length := len_map _ xs
theorem len_ev (xs : List Nat) (y : Nat) : (ev xs y).length = xs.length := len_map _ xs

theorem beq_false_of_ne {a b : Nat} (h : a ≠ b) : Nat.beq a b = false := by
  cases e : Nat.beq a b with
  | false => rfl
  | true => exact absurd (beq_eq a b e) h

/-- Σ_{y∈S} (2⟨t y⟩ − M) splits into the xs part and the ℓ part. -/
theorem sumT_split (M t ℓ : Nat) (xs : List Nat)
    (hrow : ∀ y, y ∈ xs → dot (rowA M t xs) (ev xs y) = 2 * (((t * y) % M : Nat) : Int) - (M : Int))
    (hl : dot (rowA M t xs) (ev xs ℓ) = 0) (hne : ∀ y, y ∈ xs → ℓ ≠ y) :
    ∀ S : List Nat, (∀ y, y ∈ S → y ∈ xs ∨ y = ℓ) →
      sumT M t S = dot (rowA M t xs) (gv xs S) + (2 * (((t * ℓ) % M : Nat) : Int) - (M : Int)) * (cnt ℓ S : Int)
  | [], _ => by
    rw [gv_nil]
    show (0 : Int) = dot (rowA M t xs) (zeros xs.length) + _ * ((0 : Nat) : Int)
    rw [dot_zeros_right]
    generalize (2 * (((t * ℓ) % M : Nat) : Int) - (M : Int)) = c
    show (0 : Int) = 0 + c * 0
    lib_int
  | y :: S, hS => by
    have ih := sumT_split M t ℓ xs hrow hl hne S (fun z hz => hS z (List.Mem.tail _ hz))
    show (2 * (((t * y) % M : Nat) : Int) - (M : Int)) + sumT M t S
      = dot (rowA M t xs) (gv xs (y :: S)) + _ * ((cond (Nat.beq ℓ y) 1 0 + cnt ℓ S : Nat) : Int)
    rw [gv_cons, dot_addV_r _ _ _ (by rw [len_gv, len_ev]), natCast_add, cond_cast, ih]
    cases hS y (List.Mem.head _) with
    | inl hy =>
      rw [hrow y hy, beq_false_of_ne (hne y hy)]
      show _ = _ + _ + _ * ((0 : Int) + _)
      generalize dot (rowA M t xs) (gv xs S) = P
      generalize (2 * (((t * y) % M : Nat) : Int) - (M : Int)) = a
      generalize (2 * (((t * ℓ) % M : Nat) : Int) - (M : Int)) = c
      generalize ((cnt ℓ S : Nat) : Int) = k
      lib_int
    | inr hy =>
      subst hy
      rw [hl, beq_refl]
      show _ = _ + _ * ((1 : Int) + _)
      generalize dot (rowA M t xs) (gv xs S) = P
      generalize (2 * (((t * y) % M : Nat) : Int) - (M : Int)) = c
      generalize ((cnt y S : Nat) : Int) = k
      lib_int

/-- mv over a mapped row family -/
theorem mv_map (row : Nat → List Int) (g : List Int) : ∀ C : List Nat,
    mv (C.map row) g = C.map (fun t => dot (row t) g)
  | [] => rfl
  | t :: C => by
    show dot (row t) g :: mv (C.map row) g = dot (row t) g :: C.map (fun t => dot (row t) g)
    rw [mv_map row g C]

theorem smul_smul (a b : Int) : ∀ v : List Int, smul a (smul b v) = smul (a * b) v
  | [] => rfl
  | x :: xs => by
    show (a * (b * x)) :: smul a (smul b xs) = (a * b * x) :: smul (a * b) xs
    rw [smul_smul a b xs]
    have e : a * (b * x) = a * b * x := by lib_int
    rw [e]

theorem len_smul' (c : Int) (v : List Int) : (smul c v).length = v.length := len_smul c v

theorem smul_cancel (d : Int) (hd : d ≠ 0) : ∀ u v : List Int, u.length = v.length → smul d u = smul d v → u = v
  | [], [], _, _ => rfl
  | [], _ :: _, h, _ => Nat.noConfusion h
  | _ :: _, [], h, _ => Nat.noConfusion h
  | x :: xs, y :: ys, hl, h => by
    have h1 : d * x = d * y := List.cons.inj h |>.1
    have h2 : smul d xs = smul d ys := List.cons.inj h |>.2
    have h3 : d * (x - y) = 0 := by
      have e : d * (x - y) = d * x - d * y := by lib_int
      rw [e, h1]; lib_int
    have hxy : x = y := by
      cases int_noZD d (x - y) h3 with
      | inl h => exact absurd h hd
      | inr h =>
        calc x = (x - y) + y := by lib_int
          _ = 0 + y := by rw [h]; rfl
          _ = y := by lib_int
    rw [hxy, smul_cancel d hd xs ys (Nat.succ.inj hl) h2]

/-- the certificate equations, column by column -/
theorem cols_eq (M ℓ : Nat) (xs : List Nat) (g : List Int) (e : Int) :
    ∀ C : List Nat, (∀ t, t ∈ C → dot (rowA M t xs) g = -e * (2 * (((t * ℓ) % M : Nat) : Int) - (M : Int))) →
      C.map (fun t => dot (rowA M t xs) g) = smul (-e) (C.map (fun t => 2 * (((t * ℓ) % M : Nat) : Int) - (M : Int)))
  | [], _ => rfl
  | t :: C, h => by
    show dot (rowA M t xs) g :: C.map (fun t => dot (rowA M t xs) g)
      = (-e * (2 * (((t * ℓ) % M : Nat) : Int) - (M : Int))) :: smul (-e) (C.map (fun t => 2 * (((t * ℓ) % M : Nat) : Int) - (M : Int)))
    rw [h t (List.Mem.head _), cols_eq M ℓ xs g e C (fun t' ht' => h t' (List.Mem.tail _ ht'))]

/-- **A balanced list over xs ∪ {ℓ} has equal counts.** -/
theorem fam_counts (M ℓ : Nat) (xs C : List Nat) (d : Int) (hd : d ≠ 0) (B : List (List Int))
    (hA : allLen xs.length (C.map (fun t => rowA M t xs)) = true)
    (hc : lcs xs.length B (C.map (fun t => rowA M t xs)) = sid d xs.length)
    (hW : mv B (C.map (fun t => 2 * (((t * ℓ) % M : Nat) : Int) - (M : Int))) = smul (-d) (ones xs.length))
    (hrow : ∀ t, t ∈ C → ∀ y, y ∈ xs → dot (rowA M t xs) (ev xs y) = 2 * (((t * y) % M : Nat) : Int) - (M : Int))
    (hl : ∀ t, t ∈ C → dot (rowA M t xs) (ev xs ℓ) = 0) (hne : ∀ y, y ∈ xs → ℓ ≠ y)
    (S : List Nat) (hS : ∀ y, y ∈ S → y ∈ xs ∨ y = ℓ)
    (hbal : ∀ t, t ∈ C → tsum M t S + tsum M t S = S.length * M) :
    gv xs S = smul (cnt ℓ S : Int) (ones xs.length) := by
  have eqs : mv (C.map (fun t => rowA M t xs)) (gv xs S)
      = smul (-(cnt ℓ S : Int)) (C.map (fun t => 2 * (((t * ℓ) % M : Nat) : Int) - (M : Int))) := by
    rw [mv_map]
    apply cols_eq
    intro t ht
    have sp := sumT_split M t ℓ xs (hrow t ht) (hl t ht) hne S hS
    rw [sumT_zero M t S (hbal t ht)] at sp
    generalize dot (rowA M t xs) (gv xs S) = P at sp ⊢
    generalize (2 * (((t * ℓ) % M : Nat) : Int) - (M : Int)) = c at sp ⊢
    generalize ((cnt ℓ S : Nat) : Int) = k at sp ⊢
    have e : P = P + c * k - c * k := by lib_int
    rw [e, ← sp]; lib_int
  have af := affine_fix xs.length d (-(cnt ℓ S : Int)) _ B hA hc _ _ hW (gv xs S) (len_gv xs S) eqs
  rw [smul_smul] at af
  have e1 : -(cnt ℓ S : Int) * -d = d * (cnt ℓ S : Int) := by lib_int
  rw [e1, ← smul_smul] at af
  have hlen1 : (smul (cnt ℓ S : Int) (ones xs.length)).length = (ones xs.length).length := len_smul _ _
  have hlen : (gv xs S).length = (smul (cnt ℓ S : Int) (ones xs.length)).length := by
    rw [len_gv, hlen1, len_ones]
  exact smul_cancel d hd _ _ hlen af

end FamBridge

#print axioms FamBridge.gv_nil
#print axioms FamBridge.gv_cons
#print axioms FamBridge.len_ones
#print axioms FamBridge.len_gv
#print axioms FamBridge.len_ev
#print axioms FamBridge.beq_false_of_ne
#print axioms FamBridge.sumT_split
#print axioms FamBridge.mv_map
#print axioms FamBridge.smul_smul
#print axioms FamBridge.len_smul'
#print axioms FamBridge.smul_cancel
#print axioms FamBridge.cols_eq
#print axioms FamBridge.fam_counts

#print axioms: 13 theorems, no axioms.

81.255 \(F'_p\) is indecomposable, \(p=15,29,43\)

A balanced subset of \(F'_p\) is empty or all of \(F'_p\).

hodge/FamInst15.lean

/-
  hodge/FamInst15.lean — T41 (goal G865e): F′_15 is indecomposable. The data of the rank certificate
  hodge/FamCert15 (columns C = 13 units mod 210, the first 13 elements xs of F′_15 and the last ℓ = 197) and
  the finite checks of hodge/FamBridge.fam_counts, by rfl (tools/g865_inst.py):
    indec15   a list S over F′_15 balanced at every t ∈ C contains every element of xs exactly as often as ℓ,
  so a balanced subset of F′_15 is ∅ or F′_15. Lean 4 core.
-/
import hodge.FamCert15
import hodge.FamBridge

set_option maxHeartbeats 0
set_option maxRecDepth 100000

namespace FamInst15
open MailletLin MailletBridge FamBridge

def xs : List Nat := [1, 29, 43, 57, 71, 85, 99, 113, 127, 141, 155, 169, 183]
def C : List Nat := [1, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 59, 61]

theorem hA_def : FamCert15.A = C.map (fun t => rowA 210 t xs) := rfl
theorem hcl_def : FamCert15.cl = C.map (fun t => 2 * (((t * 197) % 210 : Nat) : Int) - ((210 : Nat) : Int)) := rfl
theorem hW_def : FamCert15.W = smul (-420) (ones 13) := rfl
theorem len_xs : xs.length = 13 := rfl

def rowChk : Bool := C.all (fun t => xs.all (fun y =>
  decide (dot (rowA 210 t xs) (ev xs y) = 2 * (((t * y) % 210 : Nat) : Int) - ((210 : Nat) : Int))))
def lastChk : Bool := C.all (fun t => decide (dot (rowA 210 t xs) (ev xs 197) = 0))
def neChk : Bool := xs.all (fun y => !(Nat.beq 197 y))

theorem rowChk_ok : rowChk = true := rfl
theorem lastChk_ok : lastChk = true := rfl
theorem neChk_ok : neChk = true := rfl

theorem all_mem {α : Type} (P : α → Bool) : ∀ (l : List α) (x : α), l.all P = true → x ∈ l → P x = true
  | [], _, _, h => nomatch h
  | y :: l, x, h, hx => by
    have h1 : P y = true := MailletBridge.and_true_left h
    have h2 : l.all P = true := MailletBridge.and_true_right h
    cases hx with
    | head => exact h1
    | tail _ hx' => exact all_mem P l x h2 hx'

theorem ne_of_beq_false {a b : Nat} (h : (!(Nat.beq a b)) = true) : a ≠ b := by
  intro e
  rw [e, beq_refl] at h
  exact nomatch h

/-- **F′_15 is indecomposable**: a list over F′_15 balanced at every t ∈ C has equal counts. -/
theorem indec15 (S : List Nat) (hS : ∀ y, y ∈ S → y ∈ xs ∨ y = 197)
    (hbal : ∀ t, t ∈ C → tsum 210 t S + tsum 210 t S = S.length * 210) :
    gv xs S = smul (cnt 197 S : Int) (ones 13) := by
  have hA : allLen xs.length (C.map (fun t => rowA 210 t xs)) = true := by
    rw [len_xs, ← hA_def]; exact FamCert15.allLen_A
  have hc : lcs xs.length FamCert15.B (C.map (fun t => rowA 210 t xs)) = sid 420 xs.length := by
    rw [len_xs, ← hA_def]; exact FamCert15.cert
  have hW : mv FamCert15.B (C.map (fun t => 2 * (((t * 197) % 210 : Nat) : Int) - ((210 : Nat) : Int)))
      = smul (-420) (ones xs.length) := by
    rw [len_xs, ← hcl_def, FamCert15.w_eq, hW_def]
  have hrow : ∀ t, t ∈ C → ∀ y, y ∈ xs →
      dot (rowA 210 t xs) (ev xs y) = 2 * (((t * y) % 210 : Nat) : Int) - ((210 : Nat) : Int) := fun t ht y hy =>
    decide_eq (all_mem _ xs y (all_mem _ C t rowChk_ok ht) hy)
  have hl : ∀ t, t ∈ C → dot (rowA 210 t xs) (ev xs 197) = 0 := fun t ht =>
    decide_eq (all_mem _ C t lastChk_ok ht)
  have hne : ∀ y, y ∈ xs → 197 ≠ y := fun y hy => ne_of_beq_false (all_mem _ xs y neChk_ok hy)
  have r := fam_counts 210 197 xs C 420 (fun h => nomatch h) FamCert15.B hA hc hW hrow hl hne S hS hbal
  rw [len_xs] at r
  exact r

end FamInst15

#print axioms FamInst15.hA_def
#print axioms FamInst15.hcl_def
#print axioms FamInst15.hW_def
#print axioms FamInst15.len_xs
#print axioms FamInst15.rowChk_ok
#print axioms FamInst15.lastChk_ok
#print axioms FamInst15.neChk_ok
#print axioms FamInst15.all_mem
#print axioms FamInst15.ne_of_beq_false
#print axioms FamInst15.indec15

#print axioms: 10 theorems, no axioms.

hodge/FamInst29.lean

/-
  hodge/FamInst29.lean — T41 (goal G865e): F′_29 is indecomposable. The data of the rank certificate
  hodge/FamCert29 (columns C = 27 units mod 406, the first 27 elements xs of F′_29 and the last ℓ = 393) and
  the finite checks of hodge/FamBridge.fam_counts, by rfl (tools/g865_inst.py):
    indec29   a list S over F′_29 balanced at every t ∈ C contains every element of xs exactly as often as ℓ,
  so a balanced subset of F′_29 is ∅ or F′_29. Lean 4 core.
-/
import hodge.FamCert29
import hodge.FamBridge

set_option maxHeartbeats 0
set_option maxRecDepth 100000

namespace FamInst29
open MailletLin MailletBridge FamBridge

def xs : List Nat := [1, 15, 43, 57, 71, 85, 99, 113, 127, 141, 155, 169, 183, 197, 211, 225, 239, 253, 267, 281, 295, 309, 323, 337, 351, 365, 379]
def C : List Nat := [1, 3, 5, 9, 11, 13, 15, 17, 19, 23, 25, 27, 31, 33, 37, 39, 41, 43, 45, 47, 51, 53, 55, 57, 59, 61, 65]

theorem hA_def : FamCert29.A = C.map (fun t => rowA 406 t xs) := rfl
theorem hcl_def : FamCert29.cl = C.map (fun t => 2 * (((t * 393) % 406 : Nat) : Int) - ((406 : Nat) : Int)) := rfl
theorem hW_def : FamCert29.W = smul (-37352) (ones 27) := rfl
theorem len_xs : xs.length = 27 := rfl

def rowChk : Bool := C.all (fun t => xs.all (fun y =>
  decide (dot (rowA 406 t xs) (ev xs y) = 2 * (((t * y) % 406 : Nat) : Int) - ((406 : Nat) : Int))))
def lastChk : Bool := C.all (fun t => decide (dot (rowA 406 t xs) (ev xs 393) = 0))
def neChk : Bool := xs.all (fun y => !(Nat.beq 393 y))

theorem rowChk_ok : rowChk = true := rfl
theorem lastChk_ok : lastChk = true := rfl
theorem neChk_ok : neChk = true := rfl

theorem all_mem {α : Type} (P : α → Bool) : ∀ (l : List α) (x : α), l.all P = true → x ∈ l → P x = true
  | [], _, _, h => nomatch h
  | y :: l, x, h, hx => by
    have h1 : P y = true := MailletBridge.and_true_left h
    have h2 : l.all P = true := MailletBridge.and_true_right h
    cases hx with
    | head => exact h1
    | tail _ hx' => exact all_mem P l x h2 hx'

theorem ne_of_beq_false {a b : Nat} (h : (!(Nat.beq a b)) = true) : a ≠ b := by
  intro e
  rw [e, beq_refl] at h
  exact nomatch h

/-- **F′_29 is indecomposable**: a list over F′_29 balanced at every t ∈ C has equal counts. -/
theorem indec29 (S : List Nat) (hS : ∀ y, y ∈ S → y ∈ xs ∨ y = 393)
    (hbal : ∀ t, t ∈ C → tsum 406 t S + tsum 406 t S = S.length * 406) :
    gv xs S = smul (cnt 393 S : Int) (ones 27) := by
  have hA : allLen xs.length (C.map (fun t => rowA 406 t xs)) = true := by
    rw [len_xs, ← hA_def]; exact FamCert29.allLen_A
  have hc : lcs xs.length FamCert29.B (C.map (fun t => rowA 406 t xs)) = sid 37352 xs.length := by
    rw [len_xs, ← hA_def]; exact FamCert29.cert
  have hW : mv FamCert29.B (C.map (fun t => 2 * (((t * 393) % 406 : Nat) : Int) - ((406 : Nat) : Int)))
      = smul (-37352) (ones xs.length) := by
    rw [len_xs, ← hcl_def, FamCert29.w_eq, hW_def]
  have hrow : ∀ t, t ∈ C → ∀ y, y ∈ xs →
      dot (rowA 406 t xs) (ev xs y) = 2 * (((t * y) % 406 : Nat) : Int) - ((406 : Nat) : Int) := fun t ht y hy =>
    decide_eq (all_mem _ xs y (all_mem _ C t rowChk_ok ht) hy)
  have hl : ∀ t, t ∈ C → dot (rowA 406 t xs) (ev xs 393) = 0 := fun t ht =>
    decide_eq (all_mem _ C t lastChk_ok ht)
  have hne : ∀ y, y ∈ xs → 393 ≠ y := fun y hy => ne_of_beq_false (all_mem _ xs y neChk_ok hy)
  have r := fam_counts 406 393 xs C 37352 (fun h => nomatch h) FamCert29.B hA hc hW hrow hl hne S hS hbal
  rw [len_xs] at r
  exact r

end FamInst29

#print axioms FamInst29.hA_def
#print axioms FamInst29.hcl_def
#print axioms FamInst29.hW_def
#print axioms FamInst29.len_xs
#print axioms FamInst29.rowChk_ok
#print axioms FamInst29.lastChk_ok
#print axioms FamInst29.neChk_ok
#print axioms FamInst29.all_mem
#print axioms FamInst29.ne_of_beq_false
#print axioms FamInst29.indec29

#print axioms: 10 theorems, no axioms.

hodge/FamInst43.lean

/-
  hodge/FamInst43.lean — T41 (goal G865e): F′_43 is indecomposable. The data of the rank certificate
  hodge/FamCert43 (columns C = 41 units mod 602, the first 41 elements xs of F′_43 and the last ℓ = 589) and
  the finite checks of hodge/FamBridge.fam_counts, by rfl (tools/g865_inst.py):
    indec43   a list S over F′_43 balanced at every t ∈ C contains every element of xs exactly as often as ℓ,
  so a balanced subset of F′_43 is ∅ or F′_43. Lean 4 core.
-/
import hodge.FamCert43
import hodge.FamBridge

set_option maxHeartbeats 0
set_option maxRecDepth 100000

namespace FamInst43
open MailletLin MailletBridge FamBridge

def xs : List Nat := [1, 15, 29, 57, 71, 85, 99, 113, 127, 141, 155, 169, 183, 197, 211, 225, 239, 253, 267, 281, 295, 309, 323, 337, 351, 365, 379, 393, 407, 421, 435, 449, 463, 477, 491, 505, 519, 533, 547, 561, 575]
def C : List Nat := [1, 3, 5, 9, 11, 13, 15, 17, 19, 23, 25, 27, 29, 31, 33, 37, 39, 41, 45, 47, 51, 53, 55, 57, 59, 61, 65, 67, 69, 71, 73, 75, 79, 81, 83, 85, 87, 89, 93, 95, 97]

theorem hA_def : FamCert43.A = C.map (fun t => rowA 602 t xs) := rfl
theorem hcl_def : FamCert43.cl = C.map (fun t => 2 * (((t * 589) % 602 : Nat) : Int) - ((602 : Nat) : Int)) := rfl
theorem hW_def : FamCert43.W = smul (-100051196) (ones 41) := rfl
theorem len_xs : xs.length = 41 := rfl

def rowChk : Bool := C.all (fun t => xs.all (fun y =>
  decide (dot (rowA 602 t xs) (ev xs y) = 2 * (((t * y) % 602 : Nat) : Int) - ((602 : Nat) : Int))))
def lastChk : Bool := C.all (fun t => decide (dot (rowA 602 t xs) (ev xs 589) = 0))
def neChk : Bool := xs.all (fun y => !(Nat.beq 589 y))

theorem rowChk_ok : rowChk = true := rfl
theorem lastChk_ok : lastChk = true := rfl
theorem neChk_ok : neChk = true := rfl

theorem all_mem {α : Type} (P : α → Bool) : ∀ (l : List α) (x : α), l.all P = true → x ∈ l → P x = true
  | [], _, _, h => nomatch h
  | y :: l, x, h, hx => by
    have h1 : P y = true := MailletBridge.and_true_left h
    have h2 : l.all P = true := MailletBridge.and_true_right h
    cases hx with
    | head => exact h1
    | tail _ hx' => exact all_mem P l x h2 hx'

theorem ne_of_beq_false {a b : Nat} (h : (!(Nat.beq a b)) = true) : a ≠ b := by
  intro e
  rw [e, beq_refl] at h
  exact nomatch h

/-- **F′_43 is indecomposable**: a list over F′_43 balanced at every t ∈ C has equal counts. -/
theorem indec43 (S : List Nat) (hS : ∀ y, y ∈ S → y ∈ xs ∨ y = 589)
    (hbal : ∀ t, t ∈ C → tsum 602 t S + tsum 602 t S = S.length * 602) :
    gv xs S = smul (cnt 589 S : Int) (ones 41) := by
  have hA : allLen xs.length (C.map (fun t => rowA 602 t xs)) = true := by
    rw [len_xs, ← hA_def]; exact FamCert43.allLen_A
  have hc : lcs xs.length FamCert43.B (C.map (fun t => rowA 602 t xs)) = sid 100051196 xs.length := by
    rw [len_xs, ← hA_def]; exact FamCert43.cert
  have hW : mv FamCert43.B (C.map (fun t => 2 * (((t * 589) % 602 : Nat) : Int) - ((602 : Nat) : Int)))
      = smul (-100051196) (ones xs.length) := by
    rw [len_xs, ← hcl_def, FamCert43.w_eq, hW_def]
  have hrow : ∀ t, t ∈ C → ∀ y, y ∈ xs →
      dot (rowA 602 t xs) (ev xs y) = 2 * (((t * y) % 602 : Nat) : Int) - ((602 : Nat) : Int) := fun t ht y hy =>
    decide_eq (all_mem _ xs y (all_mem _ C t rowChk_ok ht) hy)
  have hl : ∀ t, t ∈ C → dot (rowA 602 t xs) (ev xs 589) = 0 := fun t ht =>
    decide_eq (all_mem _ C t lastChk_ok ht)
  have hne : ∀ y, y ∈ xs → 589 ≠ y := fun y hy => ne_of_beq_false (all_mem _ xs y neChk_ok hy)
  have r := fam_counts 602 589 xs C 100051196 (fun h => nomatch h) FamCert43.B hA hc hW hrow hl hne S hS hbal
  rw [len_xs] at r
  exact r

end FamInst43

#print axioms FamInst43.hA_def
#print axioms FamInst43.hcl_def
#print axioms FamInst43.hW_def
#print axioms FamInst43.len_xs
#print axioms FamInst43.rowChk_ok
#print axioms FamInst43.lastChk_ok
#print axioms FamInst43.neChk_ok
#print axioms FamInst43.all_mem
#print axioms FamInst43.ne_of_beq_false
#print axioms FamInst43.indec43

#print axioms: 10 theorems, no axioms.

81.256 Pairing \(a\leftrightarrow p-a\)

For \(f(p-a)=-f(a)\), \(f(0)=0\), \(w(p-a)=P-w(a)\): \(\sum _{a<p}w(a)f(a)=\sum _{a\le q}(2w(a)-P)f(a)\), \(p=2q+1\).

hodge/HalfPair.lean

/-
  hodge/HalfPair.lean — T41 (goal G529b, piece: pairing a ↔ p − a), over a commutative ring. For a function f on
  0, …, p − 1 (p = 2q + 1) with f(0) = 0 and f(p − a) = −f(a), and weights w with w(p − a) = P − w(a):
    sum_shift   Σ_{i<m+1} g(i) = g(0) + Σ_{i<m} g(i + 1),
    sum_split   Σ_{i<n+m} g(i) = Σ_{i<n} g(i) + Σ_{i<m} g(n + i),
    sum_rev     Σ_{i<m} g(i) = Σ_{j<m} g′(j) when g(i) = g′(j) for i + j + 1 = m,
    half_pair   Σ_{a<p} w(a) f(a) = Σ_{a<q+1} (2w(a) − P) f(a).
  With f = χ odd and w = a this is S = 2T − pH, the first step of S·(χ̄(2) − 2) = p·H (HODGE_LOG cycle 2034).

  Lean 4 core plus NSChain (sumN), lib/RingTac.
-/
import NSChain
import lib.RingTac

namespace HalfPair
open DetChain NSChain LibRing

section Gen
variable {R : Type} (K : CRing R)

theorem sum_shift (g : Nat → R) : ∀ m : Nat, sumN K g (m + 1) = K.add (g 0) (sumN K (fun i => g (i + 1)) m)
  | 0 => by show K.add K.zero (g 0) = K.add (g 0) K.zero; lib_ring
  | m + 1 => by
    show K.add (sumN K g (m + 1)) (g (m + 1)) = K.add (g 0) (K.add (sumN K (fun i => g (i + 1)) m) (g (m + 1)))
    rw [sum_shift g m]; lib_ring

theorem sum_split (g : Nat → R) (n : Nat) : ∀ m : Nat,
    sumN K g (n + m) = K.add (sumN K g n) (sumN K (fun i => g (n + i)) m)
  | 0 => by show sumN K g n = K.add (sumN K g n) K.zero; lib_ring
  | m + 1 => by
    show K.add (sumN K g (n + m)) (g (n + m)) = K.add (sumN K g n) (K.add (sumN K (fun i => g (n + i)) m) (g (n + m)))
    rw [sum_split g n m]; lib_ring

theorem sum_rev : ∀ (m : Nat) (g g' : Nat → R), (∀ i j, i + j + 1 = m → g i = g' j) → sumN K g m = sumN K g' m
  | 0, _, _, _ => rfl
  | m + 1, g, g', h => by
    rw [sum_shift K g' m]
    have ih := sum_rev m g (fun j => g' (j + 1)) (fun i j hij => h i (j + 1) (congrArg (· + 1) hij))
    have h0 : g m = g' 0 := h m 0 rfl
    show K.add (sumN K g m) (g m) = K.add (g' 0) (sumN K (fun i => g' (i + 1)) m)
    rw [ih, h0]; lib_ring

/-- (q + 1 + i) + (j + 1) = q + q + 1 when i + j + 1 = q -/
theorem nat_pair (q i j : Nat) (h : i + j + 1 = q) : q + 1 + i + (j + 1) = q + q + 1 := by
  rw [Nat.add_assoc (q + 1) i (j + 1)]
  show q + 1 + (i + j + 1) = q + q + 1
  rw [h, Nat.add_right_comm q 1 q]

/-- **Σ_{a<p} w(a) f(a) = Σ_{a<q+1} (2w(a) − P) f(a)** (p = 2q + 1) -/
theorem half_pair (q : Nat) (f w : Nat → R) (P : R) (hf0 : f 0 = K.zero)
    (hf : ∀ a b, a + b = q + q + 1 → f b = K.neg (f a))
    (hw : ∀ a b, a + b = q + q + 1 → w b = K.add P (K.neg (w a))) :
    sumN K (fun a => K.mul (w a) (f a)) (q + 1 + q)
      = sumN K (fun a => K.mul (K.add (K.add (w a) (w a)) (K.neg P)) (f a)) (q + 1) := by
  rw [sum_split K _ (q + 1) q]
  show K.add (sumN K (fun a => K.mul (w a) (f a)) (q + 1)) (sumN K (fun i => K.mul (w (q + 1 + i)) (f (q + 1 + i))) q)
    = _
  -- reverse the upper half: index q + 1 + i ↔ j + 1 with i + j + 1 = q
  have hr := sum_rev K q (fun i => K.mul (w (q + 1 + i)) (f (q + 1 + i)))
    (fun j => K.mul (K.add P (K.neg (w (j + 1)))) (K.neg (f (j + 1))))
    (fun i j hij => by
      have e := nat_pair q i j hij
      show K.mul (w (q + 1 + i)) (f (q + 1 + i)) = K.mul (K.add P (K.neg (w (j + 1)))) (K.neg (f (j + 1)))
      rw [hw (j + 1) (q + 1 + i) ((Nat.add_comm (j + 1) (q + 1 + i)).trans e),
        hf (j + 1) (q + 1 + i) ((Nat.add_comm (j + 1) (q + 1 + i)).trans e)])
  rw [hr, sum_shift K _ q, sum_shift K _ q]
  show K.add (K.add (K.mul (w 0) (f 0)) (sumN K (fun i => K.mul (w (i + 1)) (f (i + 1))) q))
      (sumN K (fun j => K.mul (K.add P (K.neg (w (j + 1)))) (K.neg (f (j + 1)))) q)
    = K.add (K.mul (K.add (K.add (w 0) (w 0)) (K.neg P)) (f 0))
      (sumN K (fun i => K.mul (K.add (K.add (w (i + 1)) (w (i + 1))) (K.neg P)) (f (i + 1))) q)
  rw [hf0]
  have e2 : ∀ i, K.add (K.mul (w (i + 1)) (f (i + 1))) (K.mul (K.add P (K.neg (w (i + 1)))) (K.neg (f (i + 1))))
      = K.mul (K.add (K.add (w (i + 1)) (w (i + 1))) (K.neg P)) (f (i + 1)) := fun i => by lib_ring
  have hs : sumN K (fun i => K.mul (K.add (K.add (w (i + 1)) (w (i + 1))) (K.neg P)) (f (i + 1))) q
      = K.add (sumN K (fun i => K.mul (w (i + 1)) (f (i + 1))) q)
        (sumN K (fun j => K.mul (K.add P (K.neg (w (j + 1)))) (K.neg (f (j + 1)))) q) := by
    rw [← sumN_ext K _ _ e2 q]; exact sumN_add K _ _ q
  rw [hs]
  lib_ring

end Gen

end HalfPair

#print axioms HalfPair.sum_shift
#print axioms HalfPair.sum_split
#print axioms HalfPair.sum_rev
#print axioms HalfPair.nat_pair
#print axioms HalfPair.half_pair

#print axioms: 5 theorems, no axioms.

81.257 An odd number of signs

A list of \(2k+1\) signs \(\pm 1\) has unequal numbers of \(+1\) and \(-1\).

hodge/SignParity.lean

/-
  hodge/SignParity.lean — T41 (goal G529b-q, piece 3): a sum of an odd number of signs ±1 is never zero. Signs are
  a list of Booleans (true = +1, false = −1) and the sum vanishes iff the two counts agree:
    pos_add_neg  #(+1) + #(−1) = length,
    sign_ne      length = 2k + 1 ⇒ #(+1) ≠ #(−1).
  For the quadratic character mod p ≡ 3 (mod 4), H = Σ_{a<p/2} (a/p) has (p − 1)/2 (odd) terms, so H ≠ 0.

  Lean 4 core plus bsd/TorsionImage (odd_ne_even).
-/
import bsd.TorsionImage

namespace SignParity

def pos : List Bool → Nat
  | [] => 0
  | true :: l => pos l + 1
  | false :: l => pos l

def neg : List Bool → Nat
  | [] => 0
  | true :: l => neg l
  | false :: l => neg l + 1

theorem pos_add_neg : ∀ l : List Bool, pos l + neg l = l.length
  | [] => rfl
  | true :: l => by
    show pos l + 1 + neg l = l.length + 1
    rw [Nat.add_right_comm, pos_add_neg l]
  | false :: l => by
    show pos l + (neg l + 1) = l.length + 1
    rw [← Nat.add_assoc, pos_add_neg l]

theorem two_mul' : ∀ c : Nat, c + c = 2 * c
  | 0 => rfl
  | c + 1 => by
    show c + 1 + c + 1 = 2 * c + 1 + 1
    rw [← two_mul' c, Nat.add_right_comm c 1 c]

/-- **an odd number of signs ±1 does not sum to zero** -/
theorem sign_ne (l : List Bool) (k : Nat) (hl : l.length = 2 * k + 1) : pos l ≠ neg l := by
  intro h
  have e := pos_add_neg l
  rw [h, hl, two_mul'] at e
  exact TorsionImage.odd_ne_even k (neg l) e.symm

end SignParity

#print axioms SignParity.pos_add_neg
#print axioms SignParity.two_mul'
#print axioms SignParity.sign_ne

#print axioms: 3 theorems, no axioms.

81.258 Even and odd residues

With \(f(2a)=c\,f(a)\), \(w(2a)=2w(a)\): \(\sum _{b<p}w(b)f(b)=c\sum _{a\le q}(4w(a)-P)f(a)\).

hodge/HalfPair2.lean

/-
  hodge/HalfPair2.lean — T41 (goal G529b-q, piece 2): the even/odd rearrangement, over a commutative ring. For f on
  0, …, p − 1 (p = 2q + 1) with f(0) = 0, f(p − a) = −f(a), f(2a) = c·f(a), and weights with w(p − a) = P − w(a),
  w(2a) = 2w(a):
    sum_eo     Σ_{b<2m} F(b) = Σ_{a<m} (F(2a) + F(2a + 1)),
    even_odd   Σ_{b<p} w(b) f(b) = c · Σ_{a<q+1} (4w(a) − P) f(a).
  With f = χ odd, c = χ(2), w = a and HalfPair.half_pair (S = 2T − pH): S = c(4T − pH) = c(2S + pH) − cpH + … , i.e.
  S·(χ̄(2) − 2) = p·H.

  Lean 4 core plus hodge/HalfPair.
-/
import hodge.HalfPair

namespace HalfPair2
open DetChain NSChain LibRing HalfPair

section Gen
variable {R : Type} (K : CRing R)

def ev (w f : Nat → R) (c : R) (a : Nat) : R := K.mul (K.add (w a) (w a)) (K.mul c (f a))
def od (w f : Nat → R) (c P : R) (a : Nat) : R := K.mul (K.add P (K.neg (K.add (w a) (w a)))) (K.neg (K.mul c (f a)))
def tm (w f : Nat → R) (P : R) (a : Nat) : R :=
  K.mul (K.add (K.add (K.add (w a) (w a)) (K.add (w a) (w a))) (K.neg P)) (f a)

theorem sum_eo (F : Nat → R) : ∀ m : Nat, sumN K F (2 * m) = sumN K (fun a => K.add (F (2 * a)) (F (2 * a + 1))) m
  | 0 => rfl
  | m + 1 => by
    show K.add (K.add (sumN K F (2 * m)) (F (2 * m))) (F (2 * m + 1))
      = K.add (sumN K (fun a => K.add (F (2 * a)) (F (2 * a + 1))) m) (K.add (F (2 * m)) (F (2 * m + 1)))
    rw [sum_eo F m]; lib_ring

/-- 2a + 1 + 2(j + 1) = 2q + 1 when a + j + 1 = q -/
theorem nat_eo (q a j : Nat) (h : a + j + 1 = q) : 2 * a + 1 + 2 * (j + 1) = 2 * q + 1 := by
  rw [← h]
  show 2 * a + 1 + 2 * (j + 1) = 2 * (a + j) + 2 + 1
  rw [Nat.left_distrib 2 a j]
  exact congrArg (fun x => Nat.succ (Nat.succ x)) (Nat.succ_add (2 * a) (2 * j))

/-- **Σ_{b<2q+1} w(b) f(b) = c Σ_{a<q+1} (4w(a) − P) f(a)** -/
theorem even_odd (q : Nat) (f w : Nat → R) (c P : R) (hf0 : f 0 = K.zero)
    (hf : ∀ a b, a + b = 2 * q + 1 → f b = K.neg (f a))
    (hw : ∀ a b, a + b = 2 * q + 1 → w b = K.add P (K.neg (w a)))
    (h2f : ∀ a, f (2 * a) = K.mul c (f a)) (h2w : ∀ a, w (2 * a) = K.add (w a) (w a)) :
    sumN K (fun b => K.mul (w b) (f b)) (2 * q + 1) = K.mul c (sumN K (tm K w f P) (q + 1)) := by
  have hsplit : sumN K (fun b => K.mul (w b) (f b)) (2 * q + 1)
      = K.add (K.add (sumN K (fun a => K.mul (w (2 * a)) (f (2 * a))) q)
          (sumN K (fun a => K.mul (w (2 * a + 1)) (f (2 * a + 1))) q)) (K.mul (w (2 * q)) (f (2 * q))) := by
    show K.add (sumN K (fun b => K.mul (w b) (f b)) (2 * q)) (K.mul (w (2 * q)) (f (2 * q))) = _
    rw [sum_eo K _ q]
    exact congrArg (fun x => K.add x (K.mul (w (2 * q)) (f (2 * q))))
      (sumN_add K (fun a => K.mul (w (2 * a)) (f (2 * a))) (fun a => K.mul (w (2 * a + 1)) (f (2 * a + 1))) q)
  have hE : ∀ a, K.mul (w (2 * a)) (f (2 * a)) = ev K w f c a := fun a => by
    show K.mul (w (2 * a)) (f (2 * a)) = K.mul (K.add (w a) (w a)) (K.mul c (f a))
    rw [h2w a, h2f a]
  have hO := sum_rev K q (fun a => K.mul (w (2 * a + 1)) (f (2 * a + 1))) (fun j => od K w f c P (j + 1))
    (fun a j haj => by
      have e := (Nat.add_comm (2 * (j + 1)) (2 * a + 1)).trans (nat_eo q a j haj)
      show K.mul (w (2 * a + 1)) (f (2 * a + 1))
        = K.mul (K.add P (K.neg (K.add (w (j + 1)) (w (j + 1))))) (K.neg (K.mul c (f (j + 1))))
      rw [hw (2 * (j + 1)) (2 * a + 1) e, hf (2 * (j + 1)) (2 * a + 1) e, h2w (j + 1), h2f (j + 1)])
  have hG0 : od K w f c P 0 = K.zero := by
    show K.mul (K.add P (K.neg (K.add (w 0) (w 0)))) (K.neg (K.mul c (f 0))) = K.zero
    rw [hf0]; lib_ring
  have hGs := sum_shift K (od K w f c P) q
  rw [hG0] at hGs
  have hEG : ∀ a, K.add (ev K w f c a) (od K w f c P a) = K.mul c (tm K w f P a) := fun a => by
    show K.add (K.mul (K.add (w a) (w a)) (K.mul c (f a)))
        (K.mul (K.add P (K.neg (K.add (w a) (w a)))) (K.neg (K.mul c (f a))))
      = K.mul c (K.mul (K.add (K.add (K.add (w a) (w a)) (K.add (w a) (w a))) (K.neg P)) (f a))
    lib_ring
  rw [hsplit, sumN_ext K (fun a => K.mul (w (2 * a)) (f (2 * a))) (ev K w f c) hE q, hO, hE q,
    ← sumN_mul_left K c (tm K w f P) (q + 1),
    ← sumN_ext K (fun a => K.add (ev K w f c a) (od K w f c P a)) (fun n => K.mul c (tm K w f P n)) hEG (q + 1),
    sumN_add K (ev K w f c) (od K w f c P) (q + 1), hGs]
  show K.add (K.add (sumN K (ev K w f c) q) (sumN K (fun j => od K w f c P (j + 1)) q)) (ev K w f c q)
    = K.add (K.add (sumN K (ev K w f c) q) (ev K w f c q)) (K.add K.zero (sumN K (fun i => od K w f c P (i + 1)) q))
  lib_ring

end Gen

end HalfPair2

#print axioms HalfPair2.sum_eo
#print axioms HalfPair2.nat_eo
#print axioms HalfPair2.even_odd

#print axioms: 3 theorems, no axioms.

81.259 \(F'_{71}\) is indecomposable

The rank certificate hodge/FamCert71 (\(BA=dI\), 69 columns) and the bridge: a balanced subset of \(F'_{71}\) is empty or all of \(F'_{71}\).

hodge/FamInst71.lean

/-
  hodge/FamInst71.lean — T41 (goal G865e): F′_71 is indecomposable. The data of the rank certificate
  hodge/FamCert71 (columns C = 69 units mod 994, the first 69 elements xs of F′_71 and the last ℓ = 981) and
  the finite checks of hodge/FamBridge.fam_counts, by rfl (tools/g865_inst.py):
    indec71   a list S over F′_71 balanced at every t ∈ C contains every element of xs exactly as often as ℓ,
  so a balanced subset of F′_71 is ∅ or F′_71. Lean 4 core.
-/
import hodge.FamCert71
import hodge.FamBridge

set_option maxHeartbeats 0
set_option maxRecDepth 100000

namespace FamInst71
open MailletLin MailletBridge FamBridge

def xs : List Nat := [1, 15, 29, 43, 57, 85, 99, 113, 127, 141, 155, 169, 183, 197, 211, 225, 239, 253, 267, 281, 295, 309, 323, 337, 351, 365, 379, 393, 407, 421, 435, 449, 463, 477, 491, 505, 519, 533, 547, 561, 575, 589, 603, 617, 631, 645, 659, 673, 687, 701, 715, 729, 743, 757, 771, 785, 799, 813, 827, 841, 855, 869, 883, 897, 911, 925, 939, 953, 967]
def C : List Nat := [1, 3, 5, 9, 11, 13, 15, 17, 19, 23, 25, 27, 29, 31, 33, 37, 39, 41, 43, 45, 47, 51, 53, 55, 57, 59, 61, 65, 67, 69, 73, 75, 79, 81, 83, 85, 87, 89, 93, 95, 97, 99, 101, 103, 107, 109, 111, 113, 115, 117, 121, 123, 125, 127, 129, 131, 135, 137, 139, 141, 143, 145, 149, 151, 153, 155, 157, 159, 163]

theorem hA_def : FamCert71.A = C.map (fun t => rowA 994 t xs) := rfl
theorem hcl_def : FamCert71.cl = C.map (fun t => 2 * (((t * 981) % 994 : Nat) : Int) - ((994 : Nat) : Int)) := rfl
theorem hW_def : FamCert71.W = smul (-94888030305892122656) (ones 69) := rfl
theorem len_xs : xs.length = 69 := rfl

def rowChk : Bool := C.all (fun t => xs.all (fun y =>
  decide (dot (rowA 994 t xs) (ev xs y) = 2 * (((t * y) % 994 : Nat) : Int) - ((994 : Nat) : Int))))
def lastChk : Bool := C.all (fun t => decide (dot (rowA 994 t xs) (ev xs 981) = 0))
def neChk : Bool := xs.all (fun y => !(Nat.beq 981 y))

theorem rowChk_ok : rowChk = true := rfl
theorem lastChk_ok : lastChk = true := rfl
theorem neChk_ok : neChk = true := rfl

theorem all_mem {α : Type} (P : α → Bool) : ∀ (l : List α) (x : α), l.all P = true → x ∈ l → P x = true
  | [], _, _, h => nomatch h
  | y :: l, x, h, hx => by
    have h1 : P y = true := MailletBridge.and_true_left h
    have h2 : l.all P = true := MailletBridge.and_true_right h
    cases hx with
    | head => exact h1
    | tail _ hx' => exact all_mem P l x h2 hx'

theorem ne_of_beq_false {a b : Nat} (h : (!(Nat.beq a b)) = true) : a ≠ b := by
  intro e
  rw [e, beq_refl] at h
  exact nomatch h

/-- **F′_71 is indecomposable**: a list over F′_71 balanced at every t ∈ C has equal counts. -/
theorem indec71 (S : List Nat) (hS : ∀ y, y ∈ S → y ∈ xs ∨ y = 981)
    (hbal : ∀ t, t ∈ C → tsum 994 t S + tsum 994 t S = S.length * 994) :
    gv xs S = smul (cnt 981 S : Int) (ones 69) := by
  have hA : allLen xs.length (C.map (fun t => rowA 994 t xs)) = true := by
    rw [len_xs, ← hA_def]; exact FamCert71.allLen_A
  have hc : lcs xs.length FamCert71.B (C.map (fun t => rowA 994 t xs)) = sid 94888030305892122656 xs.length := by
    rw [len_xs, ← hA_def]; exact FamCert71.cert
  have hW : mv FamCert71.B (C.map (fun t => 2 * (((t * 981) % 994 : Nat) : Int) - ((994 : Nat) : Int)))
      = smul (-94888030305892122656) (ones xs.length) := by
    rw [len_xs, ← hcl_def, FamCert71.w_eq, hW_def]
  have hrow : ∀ t, t ∈ C → ∀ y, y ∈ xs →
      dot (rowA 994 t xs) (ev xs y) = 2 * (((t * y) % 994 : Nat) : Int) - ((994 : Nat) : Int) := fun t ht y hy =>
    decide_eq (all_mem _ xs y (all_mem _ C t rowChk_ok ht) hy)
  have hl : ∀ t, t ∈ C → dot (rowA 994 t xs) (ev xs 981) = 0 := fun t ht =>
    decide_eq (all_mem _ C t lastChk_ok ht)
  have hne : ∀ y, y ∈ xs → 981 ≠ y := fun y hy => ne_of_beq_false (all_mem _ xs y neChk_ok hy)
  have r := fam_counts 994 981 xs C 94888030305892122656 (fun h => nomatch h) FamCert71.B hA hc hW hrow hl hne S hS hbal
  rw [len_xs] at r
  exact r

end FamInst71

#print axioms FamInst71.hA_def
#print axioms FamInst71.hcl_def
#print axioms FamInst71.hW_def
#print axioms FamInst71.len_xs
#print axioms FamInst71.rowChk_ok
#print axioms FamInst71.lastChk_ok
#print axioms FamInst71.neChk_ok
#print axioms FamInst71.all_mem
#print axioms FamInst71.ne_of_beq_false
#print axioms FamInst71.indec71

#print axioms: 10 theorems, no axioms.

81.260 The identity \(S(\bar c-2)=PH\)

For an odd \(f\) with \(f(2a)=c f(a)\), \(c\bar c=1\): \(\bigl (\sum _{b<p}w(b)f(b)\bigr )(\bar c-2)=P\sum _{a\le q}f(a)\); for \(f=\chi \), \(w=a\): \(S(\bar \chi (2)-2)=pH\).

hodge/HalfPair3.lean

/-
  hodge/HalfPair3.lean — T41 (goal G529b-q, piece 4): the identity S·(c̄ − 2) = P·H for an odd "character" f on
  0, …, p − 1 (p = 2q + 1), over a commutative ring, from HalfPair.half_pair and HalfPair2.even_odd:
    combine      S = 2T − PH, S = c(4T − PH), c·c̄ = 1 ⇒ S(c̄ − 2) = PH,
    sum_lin2     Σ (2w − P) f = 2T − P·H,     sum_lin4   Σ (4w − P) f = 4T − P·H,
    chi_ident    Σ_{b<p} w(b) f(b) · (c̄ − 2) = P · Σ_{a<q+1} f(a).
  With f = χ odd (c = χ(2)), w = a, P = p: S·(χ̄(2) − 2) = p·H, so S ≠ 0 ⇔ H ≠ 0.

  Lean 4 core plus hodge/HalfPair, hodge/HalfPair2, hodge/SignParity (two_mul').
-/
import hodge.HalfPair
import hodge.HalfPair2
import hodge.SignParity

namespace HalfPair3
open DetChain NSChain LibRing HalfPair HalfPair2

section Gen
variable {R : Type} (K : CRing R)

/-- **S = 2T − PH, S = c(4T − PH), c c̄ = 1 ⇒ S (c̄ − 2) = PH** -/
theorem combine (S T H P c cb : R) (h1 : S = K.add (K.add T T) (K.neg (K.mul P H)))
    (h2 : S = K.mul c (K.add (K.add (K.add T T) (K.add T T)) (K.neg (K.mul P H)))) (hc : K.mul c cb = K.one) :
    K.mul S (K.add cb (K.neg (K.add K.one K.one))) = K.mul P H := by
  have hT : K.add T T = K.add S (K.mul P H) := by rw [h1]; lib_ring
  rw [hT] at h2
  have key : K.mul S cb = K.add (K.add S S) (K.mul P H) := by
    calc K.mul S cb
        = K.mul (K.mul c (K.add (K.add (K.add S (K.mul P H)) (K.add S (K.mul P H))) (K.neg (K.mul P H)))) cb :=
          congrArg (fun x => K.mul x cb) h2
      _ = K.mul (K.mul c cb) (K.add (K.add (K.add S (K.mul P H)) (K.add S (K.mul P H))) (K.neg (K.mul P H))) := by
          lib_ring
      _ = K.add (K.add S S) (K.mul P H) := by rw [hc]; lib_ring
  calc K.mul S (K.add cb (K.neg (K.add K.one K.one))) = K.add (K.mul S cb) (K.neg (K.add S S)) := by lib_ring
    _ = K.mul P H := by rw [key]; lib_ring

/-- Σ (2w − P) f = 2T − P·H -/
theorem sum_lin2 (f w : Nat → R) (P : R) (n : Nat) :
    sumN K (fun a => K.mul (K.add (K.add (w a) (w a)) (K.neg P)) (f a)) n
      = K.add (K.add (sumN K (fun a => K.mul (w a) (f a)) n) (sumN K (fun a => K.mul (w a) (f a)) n))
          (K.neg (K.mul P (sumN K f n))) := by
  have e : ∀ a, K.mul (K.add (K.add (w a) (w a)) (K.neg P)) (f a)
      = K.add (K.add (K.mul (w a) (f a)) (K.mul (w a) (f a))) (K.neg (K.mul P (f a))) := fun a => by lib_ring
  rw [sumN_ext K _ _ e n, sumN_add K, sumN_add K, sumN_neg K, sumN_mul_left K]

/-- Σ (4w − P) f = 4T − P·H -/
theorem sum_lin4 (f w : Nat → R) (P : R) (n : Nat) :
    sumN K (tm K w f P) n
      = K.add (K.add (K.add (sumN K (fun a => K.mul (w a) (f a)) n) (sumN K (fun a => K.mul (w a) (f a)) n))
          (K.add (sumN K (fun a => K.mul (w a) (f a)) n) (sumN K (fun a => K.mul (w a) (f a)) n)))
          (K.neg (K.mul P (sumN K f n))) := by
  have e : ∀ a, tm K w f P a
      = K.add (K.add (K.add (K.mul (w a) (f a)) (K.mul (w a) (f a))) (K.add (K.mul (w a) (f a)) (K.mul (w a) (f a))))
          (K.neg (K.mul P (f a))) := fun a => by
    show K.mul (K.add (K.add (K.add (w a) (w a)) (K.add (w a) (w a))) (K.neg P)) (f a) = _
    lib_ring
  rw [sumN_ext K _ _ e n, sumN_add K, sumN_add K, sumN_add K, sumN_neg K, sumN_mul_left K]

theorem nat_q (q : Nat) : q + 1 + q = 2 * q + 1 := by
  rw [Nat.add_right_comm q 1 q, SignParity.two_mul' q]

/-- **S·(c̄ − 2) = P·H** -/
theorem chi_ident (q : Nat) (f w : Nat → R) (c cb P : R) (hc : K.mul c cb = K.one) (hf0 : f 0 = K.zero)
    (hf : ∀ a b, a + b = 2 * q + 1 → f b = K.neg (f a))
    (hw : ∀ a b, a + b = 2 * q + 1 → w b = K.add P (K.neg (w a)))
    (h2f : ∀ a, f (2 * a) = K.mul c (f a)) (h2w : ∀ a, w (2 * a) = K.add (w a) (w a)) :
    K.mul (sumN K (fun b => K.mul (w b) (f b)) (2 * q + 1)) (K.add cb (K.neg (K.add K.one K.one)))
      = K.mul P (sumN K f (q + 1)) := by
  have hqq : q + q + 1 = 2 * q + 1 := congrArg (· + 1) (SignParity.two_mul' q)
  have h1 := half_pair K q f w P hf0 (fun a b h => hf a b (h.trans hqq)) (fun a b h => hw a b (h.trans hqq))
  rw [nat_q q, sum_lin2 K f w P (q + 1)] at h1
  have h2 := even_odd K q f w c P hf0 hf hw h2f h2w
  rw [sum_lin4 K f w P (q + 1)] at h2
  exact combine K _ _ _ P c cb h1 h2 hc

end Gen

end HalfPair3

#print axioms HalfPair3.combine
#print axioms HalfPair3.sum_lin2
#print axioms HalfPair3.sum_lin4
#print axioms HalfPair3.nat_q
#print axioms HalfPair3.chi_ident

#print axioms: 5 theorems, no axioms.

81.261 The quadratic case of \(B_{1,\chi }\ne 0\)

An odd number of signs \(\pm 1\) has nonzero sum; with \(S(\bar c-2)=PH\), \(P\ne 0\) and no zero divisors, \(S\ne 0\).

hodge/HalfPair4.lean

/-
  hodge/HalfPair4.lean — T41 (goal G529b-q, piece 5): the half sum of an odd number of signs is nonzero, and with
  HalfPair3.chi_ident the full weighted sum is nonzero, over a commutative ring whose natural numbers are distinct
  (castN injective) and without zero divisors:
    sign_count   f(0) = 0 and f(a) = ±1 for 1 ≤ a ≤ j ⇒ Σ_{a<j+1} f(a) = m − m′ with m + m′ = j,
    half_ne      q odd ⇒ Σ_{a<q+1} f(a) ≠ 0,
    weighted_ne  S·(c̄ − 2) = P·H, P ≠ 0, H ≠ 0 ⇒ S ≠ 0.
  For the quadratic character mod p ≡ 3 (mod 4) (q = (p − 1)/2 odd): Σ_a a·(a/p) ≠ 0, i.e. B_{1,χ} ≠ 0.

  Lean 4 core plus hodge/SignParity, NSChain, lib/RingTac.
-/
import hodge.SignParity
import NSChain
import lib.RingTac

namespace HalfPair4
open DetChain NSChain LibRing

section Gen
variable {R : Type} (K : CRing R)

/-- **Σ_{a<j+1} f(a) = m − m′ with m + m′ = j** -/
theorem sign_count (f : Nat → R) (hf0 : f 0 = K.zero) (q : Nat)
    (hs : ∀ a, 1 ≤ a → a ≤ q → f a = K.one ∨ f a = K.neg K.one) :
    ∀ j, j ≤ q → ∃ m m' : Nat, m + m' = j ∧ sumN K f (j + 1) = K.add (castN K m) (K.neg (castN K m'))
  | 0, _ => ⟨0, 0, rfl, by
      show K.add K.zero (f 0) = K.add K.zero (K.neg K.zero)
      rw [hf0]; lib_ring⟩
  | j + 1, hj => by
    have ⟨m, m', hmm, hS⟩ := sign_count f hf0 q hs j (Nat.le_of_succ_le hj)
    have hS' : sumN K f (j + 1 + 1) = K.add (sumN K f (j + 1)) (f (j + 1)) := rfl
    cases hs (j + 1) (Nat.succ_le_succ (Nat.zero_le j)) hj with
    | inl h =>
      refine ⟨m + 1, m', ?_, ?_⟩
      · rw [Nat.add_right_comm, hmm]
      · rw [hS', hS, h]
        show K.add (K.add (castN K m) (K.neg (castN K m'))) K.one
          = K.add (K.add K.one (castN K m)) (K.neg (castN K m'))
        lib_ring
    | inr h =>
      refine ⟨m, m' + 1, ?_, ?_⟩
      · show m + m' + 1 = j + 1
        rw [hmm]
      · rw [hS', hS, h]
        show K.add (K.add (castN K m) (K.neg (castN K m'))) (K.neg K.one)
          = K.add (castN K m) (K.neg (K.add K.one (castN K m')))
        lib_ring

/-- x − y = 0 ⇒ x = y -/
theorem eq_of_sub (x y : R) (h : K.add x (K.neg y) = K.zero) : x = y := by
  calc x = K.add (K.add x (K.neg y)) y := by lib_ring
    _ = K.add K.zero y := by rw [h]
    _ = y := by lib_ring

/-- **an odd number of signs does not sum to zero** -/
theorem half_ne (f : Nat → R) (hf0 : f 0 = K.zero) (k : Nat)
    (hs : ∀ a, 1 ≤ a → a ≤ 2 * k + 1 → f a = K.one ∨ f a = K.neg K.one)
    (hinj : ∀ a b : Nat, castN K a = castN K b → a = b) : sumN K f (2 * k + 1 + 1) ≠ K.zero := by
  intro h0
  have ⟨m, m', hmm, hS⟩ := sign_count K f hf0 (2 * k + 1) hs (2 * k + 1) (Nat.le_refl _)
  rw [hS] at h0
  have e := hinj m m' (eq_of_sub K _ _ h0)
  rw [e, SignParity.two_mul'] at hmm
  exact TorsionImage.odd_ne_even k m' hmm.symm

/-- **S(c̄ − 2) = PH, P ≠ 0, H ≠ 0 ⇒ S ≠ 0** -/
theorem weighted_ne (S P H d : R) (hid : K.mul S d = K.mul P H)
    (hdom : ∀ x y : R, K.mul x y = K.zero → x = K.zero ∨ y = K.zero) (hP : P ≠ K.zero) (hH : H ≠ K.zero) :
    S ≠ K.zero := by
  intro hS
  have z : K.mul P H = K.zero := by
    rw [← hid, hS]; lib_ring
  cases hdom P H z with
  | inl h => exact hP h
  | inr h => exact hH h

end Gen

end HalfPair4

#print axioms HalfPair4.sign_count
#print axioms HalfPair4.eq_of_sub
#print axioms HalfPair4.half_ne
#print axioms HalfPair4.weighted_ne

#print axioms: 4 theorems, no axioms.

81.262 The Legendre symbol modulo \(p\equiv 3\pmod 4\)

With \(f(a)\) the value of \(a^{(p-1)/2}\) in \(\{0,\pm 1\}\) (Euler’s criterion), \(f(p-a)=-f(a)\) and \(f(2a)=f(2)f(a)\). Hence \(\sum _{b<p}b\,(b/p)\ne 0\) for every prime \(p=2(2j+1)+1\).

hodge/LegendreHalf.lean

/-
  hodge/LegendreHalf.lean — T41 (goal G529b-q, instantiation): for a prime p = 2m + 1 with m = 2j + 1 odd
  (p ≡ 3 mod 4) and the quadratic character given by Euler's criterion, f(a) = leg((a mod p)^m) ∈ {0, ±1},
      Σ_{b<p} b·f(b) ≠ 0     (B_{1,χ} ≠ 0 for the quadratic character mod p ≡ 3 (mod 4)).
  Pieces:
    tri lemmas        on a commutative ring, the set {0, 1, −1} is closed under ·, −, and leg is multiplicative there
    pw_neg_odd        (−x)^(2j+1) = −x^(2j+1)
    f_vals            1 ≤ a ≤ m ⇒ f(a) = ±1 (lib/Euler.euler_pm)
    f_odd             a + b = p ⇒ f(b) = −f(a)
    f_two             f(2a) = f(2)·f(a)
    legendre_ne       Σ_{b<p} b·f(b) ≠ 0 (hodge/HalfPair3.chi_ident, hodge/HalfPair4.half_ne, weighted_ne)
  Lean 4 core plus hodge/HalfPair3, hodge/HalfPair4, lib/Euler (copied from lib_shared).
-/
import hodge.HalfPair3
import hodge.HalfPair4
import lib.Euler

namespace LegendreHalf
open DetChain NSChain LibRing LibMod LibZp LibInt

/-! ## Three-valued elements of a commutative ring -/

section Tri
variable {R : Type} (K : CRing R)

/-- y ∈ {0, 1, −1} -/
def Tri (y : R) : Prop := y = K.zero ∨ y = K.one ∨ y = K.neg K.one

theorem tri_mul {y z : R} (hy : Tri K y) (hz : Tri K z) : Tri K (K.mul y z) := by
  rcases hy with h | h | h <;> rcases hz with g | g | g <;> rw [h, g]
  · exact Or.inl (by lib_ring)
  · exact Or.inl (by lib_ring)
  · exact Or.inl (by lib_ring)
  · exact Or.inl (by lib_ring)
  · exact Or.inr (Or.inl (by lib_ring))
  · exact Or.inr (Or.inr (by lib_ring))
  · exact Or.inl (by lib_ring)
  · exact Or.inr (Or.inr (by lib_ring))
  · exact Or.inr (Or.inl (by lib_ring))

theorem tri_neg {y : R} (hy : Tri K y) : Tri K (K.neg y) := by
  rcases hy with h | h | h <;> rw [h]
  · exact Or.inl (by lib_ring)
  · exact Or.inr (Or.inr rfl)
  · exact Or.inr (Or.inl (by lib_ring))

/-- (−1)^(2j) = 1 -/
theorem pw_negone_even : ∀ j, pw K (K.neg K.one) (2 * j) = K.one
  | 0 => rfl
  | j + 1 => by
    show pw K (K.neg K.one) (2 * j + 1 + 1) = K.one
    show K.mul (K.mul (pw K (K.neg K.one) (2 * j)) (K.neg K.one)) (K.neg K.one) = K.one
    rw [pw_negone_even j]; lib_ring

theorem pw_neg_odd (x : R) (j : Nat) : pw K (K.neg x) (2 * j + 1) = K.neg (pw K x (2 * j + 1)) := by
  have e : K.neg x = K.mul (K.neg K.one) x := by lib_ring
  rw [e, LibEuler.mul_pw_r K]
  show K.mul (K.mul (pw K (K.neg K.one) (2 * j)) (K.neg K.one)) (pw K x (2 * j + 1)) = K.neg (pw K x (2 * j + 1))
  rw [pw_negone_even K j]; lib_ring

theorem pw_zero_succ (n : Nat) : pw K K.zero (n + 1) = K.zero := by
  show K.mul (pw K K.zero n) K.zero = K.zero
  lib_ring

theorem neg_unique (x y : R) (h : K.add x y = K.zero) : y = K.neg x :=
  calc y = K.add (K.add x y) (K.neg x) := by lib_ring
    _ = K.add K.zero (K.neg x) := by rw [h]
    _ = K.neg x := by lib_ring

end Tri

/-! ## The Legendre value -/

/-- 0 ↦ 0, 1 ↦ 1, anything else ↦ −1 (non-overlapping arms) -/
def legV : Nat → Int
  | 0 => 0
  | 1 => 1
  | _ + 2 => -1

section Leg
variable (j : Nat)

/-- k = p − 1 = 2m, m = 2j + 1 -/
abbrev kk : Nat := 2 * (2 * j + 1)

theorem kk_eq : kk j = 4 * j + 2 := by
  show 2 * (2 * j + 1) = 4 * j + 2
  lib_nat

theorem one_lt : 1 < kk j + 1 := by
  rw [kk_eq]; exact Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le _))

theorem two_lt : 2 < kk j + 1 := by
  rw [kk_eq]; exact Nat.succ_le_succ (Nat.succ_le_succ (Nat.succ_le_succ (Nat.zero_le _)))

def leg (x : ZN (kk j)) : Int := legV x.val

theorem leg_zero : leg j (znR (kk j)).zero = 0 := rfl

theorem leg_one : leg j (znR (kk j)).one = 1 := by
  show legV (md (kk j + 1) 1) = 1
  rw [md_of_lt (pos (kk j)) (one_lt j)] <;> rfl

theorem negone_val : ((znR (kk j)).neg (znR (kk j)).one).val = 4 * j + 2 := by
  show md (kk j + 1) (kk j * md (kk j + 1) 1) = 4 * j + 2
  rw [md_of_lt (pos (kk j)) (one_lt j), show kk j * 1 = kk j by lib_nat,
    md_of_lt (pos (kk j)) (Nat.lt_succ_self (kk j)), kk_eq]

theorem leg_negone : leg j ((znR (kk j)).neg (znR (kk j)).one) = -1 := by
  show legV ((znR (kk j)).neg (znR (kk j)).one).val = -1
  rw [negone_val] <;> rfl

theorem leg_mul {y z : ZN (kk j)} (hy : Tri (znR (kk j)) y) (hz : Tri (znR (kk j)) z) :
    leg j ((znR (kk j)).mul y z) = leg j y * leg j z := by
  rcases hy with h | h | h <;> rcases hz with g | g | g <;> rw [h, g]
  · rw [show (znR (kk j)).mul (znR (kk j)).zero (znR (kk j)).zero = (znR (kk j)).zero by lib_ring, leg_zero] <;> rfl
  · rw [show (znR (kk j)).mul (znR (kk j)).zero (znR (kk j)).one = (znR (kk j)).zero by lib_ring, leg_zero, leg_one] <;> rfl
  · rw [show (znR (kk j)).mul (znR (kk j)).zero ((znR (kk j)).neg (znR (kk j)).one) = (znR (kk j)).zero by lib_ring,
      leg_zero, leg_negone] <;> rfl
  · rw [show (znR (kk j)).mul (znR (kk j)).one (znR (kk j)).zero = (znR (kk j)).zero by lib_ring, leg_zero, leg_one] <;> rfl
  · rw [show (znR (kk j)).mul (znR (kk j)).one (znR (kk j)).one = (znR (kk j)).one by lib_ring, leg_one] <;> rfl
  · rw [show (znR (kk j)).mul (znR (kk j)).one ((znR (kk j)).neg (znR (kk j)).one) = (znR (kk j)).neg (znR (kk j)).one
      by lib_ring, leg_one, leg_negone] <;> rfl
  · rw [show (znR (kk j)).mul ((znR (kk j)).neg (znR (kk j)).one) (znR (kk j)).zero = (znR (kk j)).zero by lib_ring,
      leg_zero, leg_negone] <;> rfl
  · rw [show (znR (kk j)).mul ((znR (kk j)).neg (znR (kk j)).one) (znR (kk j)).one = (znR (kk j)).neg (znR (kk j)).one
      by lib_ring, leg_one, leg_negone] <;> rfl
  · rw [show (znR (kk j)).mul ((znR (kk j)).neg (znR (kk j)).one) ((znR (kk j)).neg (znR (kk j)).one) = (znR (kk j)).one
      by lib_ring, leg_one, leg_negone] <;> rfl

theorem leg_neg {y : ZN (kk j)} (hy : Tri (znR (kk j)) y) : leg j ((znR (kk j)).neg y) = -leg j y := by
  rcases hy with h | h | h <;> rw [h]
  · rw [show (znR (kk j)).neg (znR (kk j)).zero = (znR (kk j)).zero by lib_ring, leg_zero] <;> rfl
  · rw [leg_one, leg_negone]
  · rw [show (znR (kk j)).neg ((znR (kk j)).neg (znR (kk j)).one) = (znR (kk j)).one by lib_ring, leg_one, leg_negone] <;> rfl

/-- the power x^m, m = 2j + 1 -/
def ev (a : Nat) : ZN (kk j) := pw (znR (kk j)) (mk (kk j) a) (2 * j + 1)

/-- the quadratic character by Euler's criterion -/
def f (a : Nat) : Int := leg j (ev j a)

theorem ev_tri (hp : Prime1 (kk j)) (a : Nat) : Tri (znR (kk j)) (ev j a) := by
  cases hv : (mk (kk j) a).val with
  | zero =>
    have e : mk (kk j) a = (znR (kk j)).zero := eq_zero_of_val (kk j) hv
    exact Or.inl (by unfold ev; rw [e]; exact pw_zero_succ (znR (kk j)) (2 * j))
  | succ v =>
    have hx : mk (kk j) a ≠ (znR (kk j)).zero := fun h => by
      rw [val_of_eq_zero (kk j) h] at hv; exact Nat.noConfusion hv
    exact Or.inr (LibEuler.euler_pm (2 * j + 1) hp _ hx)

theorem f_zero : f j 0 = 0 := by
  show leg j (pw (znR (kk j)) (znR (kk j)).zero (2 * j + 1)) = 0
  rw [pw_zero_succ (znR (kk j)) (2 * j)] <;> rfl

theorem f_vals (hp : Prime1 (kk j)) (a : Nat) (h1 : 1 ≤ a) (h2 : a ≤ 2 * j + 1) : f j a = 1 ∨ f j a = -1 := by
  have hm : 2 * j + 1 ≤ kk j := by
    show 2 * j + 1 ≤ 2 * (2 * j + 1)
    rw [show 2 * (2 * j + 1) = (2 * j + 1) + (2 * j + 1) by lib_nat]
    exact Nat.le_add_right _ _
  have hlt : a < kk j + 1 := Nat.lt_succ_of_le (Nat.le_trans h2 hm)
  have hx : mk (kk j) a ≠ (znR (kk j)).zero := fun h => by
    have e := val_of_eq_zero (kk j) h
    have e2 : (mk (kk j) a).val = a := md_of_lt (pos (kk j)) hlt
    rw [e2] at e; rw [e] at h1; exact Nat.not_succ_le_zero 0 h1
  cases LibEuler.euler_pm (2 * j + 1) hp _ hx with
  | inl e => exact Or.inl (by unfold f ev; rw [e]; exact leg_one j)
  | inr e => exact Or.inr (by unfold f ev; rw [e]; exact leg_negone j)

theorem mk_add (a b : Nat) : (znR (kk j)).add (mk (kk j) a) (mk (kk j) b) = mk (kk j) (a + b) :=
  ext (kk j) (by
    show md (kk j + 1) (md (kk j + 1) a + md (kk j + 1) b) = md (kk j + 1) (a + b)
    rw [md_add_l (pos (kk j)), md_add_r (pos (kk j))])

theorem mk_mul (a b : Nat) : (znR (kk j)).mul (mk (kk j) a) (mk (kk j) b) = mk (kk j) (a * b) :=
  ext (kk j) (by
    show md (kk j + 1) (md (kk j + 1) a * md (kk j + 1) b) = md (kk j + 1) (a * b)
    rw [md_mul_l (pos (kk j)), md_mul_r (pos (kk j))])

theorem f_odd (hp : Prime1 (kk j)) (a b : Nat) (h : a + b = 2 * (2 * j + 1) + 1) : f j b = -f j a := by
  have hs : (znR (kk j)).add (mk (kk j) a) (mk (kk j) b) = (znR (kk j)).zero := by
    rw [mk_add, h]
    exact ext (kk j) (md_zero_of_dvd (pos (kk j)) ⟨1, by show 2 * (2 * j + 1) + 1 = (2 * (2 * j + 1) + 1) * 1; lib_nat⟩)
  have hb := neg_unique (znR (kk j)) _ _ hs
  show leg j (pw (znR (kk j)) (mk (kk j) b) (2 * j + 1)) = -leg j (pw (znR (kk j)) (mk (kk j) a) (2 * j + 1))
  rw [hb, pw_neg_odd]
  exact leg_neg j (ev_tri j hp a)

theorem f_two (hp : Prime1 (kk j)) (a : Nat) : f j (2 * a) = f j 2 * f j a := by
  show leg j (pw (znR (kk j)) (mk (kk j) (2 * a)) (2 * j + 1))
    = leg j (pw (znR (kk j)) (mk (kk j) 2) (2 * j + 1)) * leg j (pw (znR (kk j)) (mk (kk j) a) (2 * j + 1))
  rw [← mk_mul, LibEuler.mul_pw_r]
  exact leg_mul j (ev_tri j hp 2) (ev_tri j hp a)

end Leg

/-! ## Over Z -/

theorem castN_int : ∀ n : Nat, castN intR n = Int.ofNat n
  | 0 => rfl
  | n + 1 => by
    show intR.add intR.one (castN intR n) = Int.ofNat (n + 1)
    rw [castN_int n]
    show (1 : Int) + Int.ofNat n = Int.ofNat n + 1
    lib_int

theorem castN_inj (a b : Nat) (h : castN intR a = castN intR b) : a = b := by
  rw [castN_int, castN_int] at h; exact Int.ofNat.inj h

theorem f2_sq (j : Nat) (hp : Prime1 (kk j)) : f j 2 * f j 2 = 1 := by
  have hx : mk (kk j) 2 ≠ (znR (kk j)).zero := fun h => by
    have e1 := val_of_eq_zero (kk j) h
    rw [show (mk (kk j) 2).val = 2 from md_of_lt (pos (kk j)) (two_lt j)] at e1
    exact Nat.noConfusion e1
  show leg j (ev j 2) * leg j (ev j 2) = 1
  unfold ev
  cases LibEuler.euler_pm (2 * j + 1) hp _ hx with
  | inl e => rw [e, leg_one] <;> rfl
  | inr e => rw [e, leg_negone] <;> rfl

/-- **B_{1,χ} ≠ 0 for the quadratic character mod p ≡ 3 (mod 4).**  p = 2(2j + 1) + 1 prime ⇒ Σ_{b<p} b·(b/p) ≠ 0. -/
theorem legendre_ne (j : Nat) (hp : Prime1 (kk j)) :
    sumN intR (fun b => intR.mul (castN intR b) (f j b)) (2 * (2 * j + 1) + 1) ≠ intR.zero := by
  have hid := HalfPair3.chi_ident intR (2 * j + 1) (f j) (castN intR) (f j 2) (f j 2) (castN intR (2 * (2 * j + 1) + 1))
    (f2_sq j hp) (f_zero j) (fun a b h => f_odd j hp a b h)
    (fun a b h => by
      rw [← h, castN_int, castN_int, castN_int]
      show Int.ofNat b = Int.ofNat a + Int.ofNat b + -Int.ofNat a
      lib_int)
    (fun a => f_two j hp a)
    (fun a => by
      rw [castN_int, castN_int]
      exact congrArg Int.ofNat (show 2 * a = a + a by lib_nat))
  have hH := HalfPair4.half_ne intR (f j) (f_zero j) j (fun a h1 h2 => f_vals j hp a h1 h2) castN_inj
  have hP : castN intR (2 * (2 * j + 1) + 1) ≠ intR.zero := by
    rw [castN_int]; exact fun h => Nat.noConfusion (Int.ofNat.inj h)
  exact HalfPair4.weighted_ne intR _ _ _ _ hid int_noZD hP hH

end LegendreHalf

#print axioms LegendreHalf.Tri
#print axioms LegendreHalf.tri_mul
#print axioms LegendreHalf.tri_neg
#print axioms LegendreHalf.pw_negone_even
#print axioms LegendreHalf.pw_neg_odd
#print axioms LegendreHalf.pw_zero_succ
#print axioms LegendreHalf.neg_unique
#print axioms LegendreHalf.kk_eq
#print axioms LegendreHalf.leg_one
#print axioms LegendreHalf.negone_val
#print axioms LegendreHalf.leg_negone
#print axioms LegendreHalf.leg_mul
#print axioms LegendreHalf.leg_neg
#print axioms LegendreHalf.ev_tri
#print axioms LegendreHalf.f_zero
#print axioms LegendreHalf.f_vals
#print axioms LegendreHalf.mk_add
#print axioms LegendreHalf.mk_mul
#print axioms LegendreHalf.f_odd
#print axioms LegendreHalf.f_two
#print axioms LegendreHalf.castN_int
#print axioms LegendreHalf.castN_inj
#print axioms LegendreHalf.f2_sq
#print axioms LegendreHalf.legendre_ne

#print axioms: 24 theorems, no axioms.

81.263 Row-block splitting of integer certificates

A certificate \(B\cdot A = d\cdot I\) follows from rfl checks of row blocks of \(B\) against the corresponding rows of \(d\cdot I\).

hodge/CertSplit.lean

/-
  hodge/CertSplit.lean — T41 (goal G865g, tool): splitting an integer certificate B · A = d · I (hodge/MailletLin, used by
  FamCert<p> and MailletCert<p>) into row blocks, so that each block is checked by its own rfl (one block per file or
  per Kamiak task) and the full certificate follows by concatenation.
    lcs_append      the rows of (B₁ ++ B₂) · A are the rows of B₁ · A followed by those of B₂ · A
    take_drop'      L.take k ++ L.drop k = L
    cert_split      lcs B₁ A = (sid d n).take k  and  lcs B₂ A = (sid d n).drop k  ⇒  lcs (B₁ ++ B₂) A = sid d n
    cert_split3     the same with three blocks
  Lean 4 core plus hodge/MailletLin.
-/
import hodge.MailletLin

namespace CertSplit
open MailletLin

theorem lcs_append (n : Nat) (A : List (List Int)) :
    ∀ B1 B2 : List (List Int), lcs n (B1 ++ B2) A = lcs n B1 A ++ lcs n B2 A
  | [], _ => rfl
  | b :: bs, B2 => congrArg (lc n b A :: ·) (lcs_append n A bs B2)

theorem take_drop' {α : Type} : ∀ (k : Nat) (L : List α), L.take k ++ L.drop k = L
  | 0, _ => rfl
  | _ + 1, [] => rfl
  | k + 1, a :: l => congrArg (a :: ·) (take_drop' k l)

theorem cert_split (n k : Nat) (d : Int) (A B1 B2 : List (List Int))
    (h1 : lcs n B1 A = (sid d n).take k) (h2 : lcs n B2 A = (sid d n).drop k) :
    lcs n (B1 ++ B2) A = sid d n := by
  rw [lcs_append, h1, h2]
  exact take_drop' k (sid d n)

theorem cert_split3 (n k1 k2 : Nat) (d : Int) (A B1 B2 B3 : List (List Int))
    (h1 : lcs n B1 A = (sid d n).take k1)
    (h2 : lcs n B2 A = ((sid d n).drop k1).take k2)
    (h3 : lcs n B3 A = ((sid d n).drop k1).drop k2) :
    lcs n (B1 ++ (B2 ++ B3)) A = sid d n := by
  rw [lcs_append, lcs_append, h1, h2, h3, take_drop' k2 ((sid d n).drop k1)]
  exact take_drop' k1 (sid d n)

end CertSplit

#print axioms CertSplit.lcs_append
#print axioms CertSplit.take_drop'
#print axioms CertSplit.cert_split
#print axioms CertSplit.cert_split3

#print axioms: 4 theorems, no axioms.