AFTD Auto-Formalizing Theoretical Domains

magic_rectangle_sos_term3

theoremverified

Let A be an ℝ-algebra and let D, C, B : Fin 3 → A satisfy D j ^ 2 = C j ^ 2 = B j ^ 2 = 1 for all j, D 0 * D 1 * D 2 = 1, C 0 * C 1 * C 2 = -1, pairwise commutativity within D and within C, and every D and C commuting with every B. Setting X j = D j + C j, Y j = D j - C j, W j = Y (j + 1) * B (j + 2) + Y (j + 2) * B (j + 1), S = ∑ j : Fin 3, X j * B j, and J = ∑ j : Fin 3, Y j * (B (j + 1) * B (j + 2) + B (j + 2) * B (j + 1)), then for any q : ℝ, ∑ j : Fin 3, (X j + q • B j - q • W j) ^ 2 = (∑ j : Fin 3, X j ^ 2) - (2 * q) • S + (3 * q ^ 2) • 1 - (2 * q ^ 2) • J + (q ^ 2) • (∑ j : Fin 3, W j ^ 2).

Statement

theorem magic_rectangle_sos_term3
    {A : Type*} [Ring A] [Algebra ℝ A]
    (D C B : Fin 3 → A)
    (hD_sq : ∀ j, D j ^ 2 = 1)
    (hC_sq : ∀ j, C j ^ 2 = 1)
    (hB_sq : ∀ j, B j ^ 2 = 1)
    (hD_prod : D 0 * D 1 * D 2 = 1)
    (hC_prod : C 0 * C 1 * C 2 = -1)
    (hD_comm : ∀ j k, D j * D k = D k * D j)
    (hC_comm : ∀ j k, C j * C k = C k * C j)
    (hDB_comm : ∀ j k, D j * B k = B k * D j)
    (hCB_comm : ∀ j k, C j * B k = B k * C j)
    (q : ℝ) :
    let X := fun j => D j + C j
    let Y := fun j => D j - C j
    let W := fun j => Y (j + 1) * B (j + 2) + Y (j + 2) * B (j + 1)
    let S := ∑ j : Fin 3, X j * B j
    let J := ∑ j : Fin 3, Y j * (B (j + 1) * B (j + 2) + B (j + 2) * B (j + 1))
    ∑ j : Fin 3, (X j + q • B j - q • W j) ^ 2 =
      (∑ j : Fin 3, X j ^ 2) - (2 * q) • S + (3 * q ^ 2) • (1 : A) -
      (2 * q ^ 2) • J + (q ^ 2) • (∑ j : Fin 3, W j ^ 2)
Source
step towards magic_rectangle_algebraic_sos_identity
Verified
18 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Built on 1
Used by 1

The proof, explained

The proof expands the sum of squares ∑ j, (X j + q • B j - q • W j) ^ 2 by distributivity into individual squares and symmetric cross-terms. The X-B cross-terms commute to yield 2 • S, and the sum of B j ^ 2 evaluates to 3 • 1. The remaining cross-terms between X and W (giving 4 • S) and between W and B (giving 2 • J) are provided by the magic rectangle anticommutator identities lemma. Combining these terms, the linear terms in q simplify via q • (2 • S) - q • (4 • S) = -(2 * q) • S, matching the desired expansion.

  1. Introduce local abbreviations for X, Y, W, S, and J, and express the target equality using them.

    The proof begins by setting up local definitions for X j = D j + C j, Y j = D j - C j, the auxiliary vector W j = Y (j + 1) * B (j + 2) + Y (j + 2) * B (j + 1), the sum S = ∑ j, X j * B j, and the anticommutator-like sum J = ∑ j, Y j * (B (j + 1) * B (j + 2) + B (j + 2) * B (j + 1)). It rephrases the goal directly in terms of these definitions.

    lines 23–31

      dsimp
      let X := fun j => D j + C j
      let Y := fun j => D j - C j
      let W := fun j => Y (j + 1) * B (j + 2) + Y (j + 2) * B (j + 1)
      let S := ∑ j : Fin 3, X j * B j
      let J := ∑ j : Fin 3, Y j * (B (j + 1) * B (j + 2) + B (j + 2) * B (j + 1))
      change (∑ j : Fin 3, (X j + q • B j - q • W j) ^ 2) =
          (∑ j : Fin 3, X j ^ 2) - (2 * q) • S + (3 * q ^ 2) • (1 : A) -
          (2 * q ^ 2) • J + (q ^ 2) • (∑ j : Fin 3, W j ^ 2)
  2. For each index j ∈ Fin 3, B j and X j commute: B j * X j = X j * B j.

    Expanding X j = D j + C j, multiplication distributes over addition. Because B j commutes with both D j and C j by hypothesis, B j * (D j + C j) = B j * D j + B j * C j = D j * B j + C j * B j = (D j + C j) * B j.

    lines 32–34

    uses mul_add, add_mul

      have hXB (j : Fin 3) : B j * X j = X j * B j := by
        dsimp [X]
        simp only [mul_add, add_mul, ← hDB_comm j j, ← hCB_comm j j]
  3. The sum of the symmetric products of X j and B j is ∑ j, (X j * B j + B j * X j) = (2 : ℝ) • S.

    Expanding the sum over Fin 3 into three components (j = 0, 1, 2) via `Fin.sum_univ_three`, each B j * X j is rewritten as X j * B j using the commutativity established in the previous step. Unfolding S and distributing scalar multiplication, this yields 2 • (X 0 * B 0 + X 1 * B 1 + X 2 * B 2) = 2 • S, which `module` verifies.

    lines 35–40

    uses Fin.sum_univ_three, smul_add

      have hXBsum : (∑ j : Fin 3, (X j * B j + B j * X j)) = (2 : ℝ) • S := by
        simp only [Fin.sum_univ_three]
        rw [hXB 0, hXB 1, hXB 2]
        dsimp [S]
        simp only [Fin.sum_univ_three, smul_add]
        module
  4. The sum of squares of B j is ∑ j, B j ^ 2 = (3 : ℝ) • 1.

    Expanding the sum over Fin 3 and using the hypothesis B j ^ 2 = 1 for each j yields 1 + 1 + 1 = (3 : ℝ) • 1.

    lines 41–43

    uses Fin.sum_univ_three

      have hBsum : (∑ j : Fin 3, B j ^ 2) = (3 : ℝ) • (1 : A) := by
        simp only [hB_sq, Fin.sum_univ_three]
        module
  5. The cross-term sums evaluate to ∑ j, (X j * W j + W j * X j) = (4 : ℝ) • S and ∑ j, (W j * B j + B j * W j) = (2 : ℝ) • J.

    The lemma `magic_rectangle_anticommutator_identities` supplies the equalities ∑ j, (X j * W j + W j * X j) = (4 : A) * S and ∑ j, (W j * B j + B j * W j) = (2 : A) * J in the ring A. Rewriting the ring multiplications by 4 and 2 into scalar multiplications by the real numbers 4 and 2 using `Algebra.smul_def` and `map_ofNat` establishes both identities in the ℝ-algebra structure.

    lines 44–51

    uses magic_rectangle_anticommutator_identities, Algebra.smul_def, map_ofNat

      have hall := magic_rectangle_anticommutator_identities D C B hD_sq hC_sq hB_sq
          hD_prod hC_prod hD_comm hC_comm hDB_comm hCB_comm
      have hXW : (∑ j : Fin 3, (X j * W j + W j * X j)) = (4 : ℝ) • S := by
        have h : (∑ j : Fin 3, (X j * W j + W j * X j)) = (4 : A) * S := hall.2.2.2
        rw [h, Algebra.smul_def, map_ofNat]
      have hWB : (∑ j : Fin 3, (W j * B j + B j * W j)) = (2 : ℝ) • J := by
        have h : (∑ j : Fin 3, (W j * B j + B j * W j)) = (2 : A) * J := hall.2.1
        rw [h, Algebra.smul_def, map_ofNat]
  6. The sum of squares ∑ j, (X j + q • B j - q • W j) ^ 2 expands into sums of squares and cross-term sums: ∑ j, X j ^ 2 + q • ∑ j, (X j * B j + B j * X j) - q • ∑ j, (X j * W j + W j * X j) + (q ^ 2) • ∑ j, B j ^ 2 - (q ^ 2) • ∑ j, (W j * B j + B j * W j) + (q ^ 2) • ∑ j, W j ^ 2.

    Expanding each squared trinomial via distributivity (`add_mul`, `mul_add`, `sub_mul`, `mul_sub`), extracting scalar factors of q and q ^ 2 (`smul_mul_assoc`, `mul_smul_comm`, `smul_smul`), distributing scalar multiplication across additions and subtractions (`smul_add`, `smul_sub`), and expanding over Fin 3 (`Fin.sum_univ_three`), the `module` decision procedure groups terms into the individual squares and symmetric anticommutator pairings.

    lines 52–60

    uses Fin.sum_univ_three, pow_two, add_mul, mul_add, sub_mul, mul_sub, smul_mul_assoc, mul_smul_comm, smul_smul, smul_add, smul_sub

      have hexpand : (∑ j : Fin 3, (X j + q • B j - q • W j) ^ 2) =
          (∑ j : Fin 3, X j ^ 2) + q • (∑ j : Fin 3, (X j * B j + B j * X j)) -
          q • (∑ j : Fin 3, (X j * W j + W j * X j)) +
          (q ^ 2) • (∑ j : Fin 3, B j ^ 2) -
          (q ^ 2) • (∑ j : Fin 3, (W j * B j + B j * W j)) +
          (q ^ 2) • (∑ j : Fin 3, W j ^ 2) := by
        simp only [Fin.sum_univ_three, pow_two, add_mul, mul_add, sub_mul, mul_sub,
          smul_mul_assoc, mul_smul_comm, smul_smul, smul_add, smul_sub]
        module
  7. The main identity holds: ∑ j, (X j + q • B j - q • W j) ^ 2 = (∑ j, X j ^ 2) - (2 * q) • S + (3 * q ^ 2) • 1 - (2 * q ^ 2) • J + (q ^ 2) • (∑ j, W j ^ 2).

    Substituting the expanded trinomial identity and replacing each cross-term sum with its evaluated counterpart (2 • S, 4 • S, 3 • 1, and 2 • J), the terms involving S combine as q • (2 • S) - q • (4 • S) = (2 * q - 4 * q) • S = -(2 * q) • S. The `module` decision procedure completes the algebraic simplification in the ℝ-module A.

    lines 61–63

    uses smul_smul

      rw [hexpand, hXBsum, hXW, hBsum, hWB]
      simp only [smul_smul]
      module
add_mul
Right distributivity of multiplication over addition: (a + b) * c = a * c + b * c.
Algebra.smul_def
Scalar multiplication of an algebra element by a scalar r equals multiplication by the image of r under the algebra map: r • x = algebraMap R A r * x.
Fin.sum_univ_three
The sum of a function over the three-element set Fin 3 equals f 0 + f 1 + f 2.
magic_rectangle_anticommutator_identities
Under the magic rectangle hypotheses, the anticommutator identities hold, including ∑ j, (X j * W j + W j * X j) = 4 * S and ∑ j, (W j * B j + B j * W j) = 2 * J.
map_ofNat
A ring homomorphism preserves numeral literals: f (OfNat.ofNat n) = OfNat.ofNat n.
mul_add
Left distributivity of multiplication over addition: a * (b + c) = a * b + a * c.
mul_smul_comm
Commutativity of ring multiplication with scalar multiplication: x * (s • y) = s • (x * y).
mul_sub
Left distributivity of multiplication over subtraction: a * (b - c) = a * b - a * c.
pow_two
The square of an element equals multiplying it by itself: a ^ 2 = a * a.
smul_add
Scalar multiplication distributes over addition: a • (b₁ + b₂) = a • b₁ + a • b₂.
smul_mul_assoc
Associativity of scalar multiplication with ring multiplication: (r • x) * y = r • (x * y).
smul_smul
Composition of scalar multiplications corresponds to multiplying the scalars: a₁ • (a₂ • b) = (a₁ * a₂) • b.
smul_sub
Scalar multiplication distributes over subtraction: r • (x - y) = r • x - r • y.
sub_mul
Right distributivity of multiplication over subtraction: (a - b) * c = a * c - b * c.

Written by a model (gemini-3.8-flash) from the Lean proof and the goal states Lean reported at each step. Lean verified the proof; this explanation is a reading aid and is not itself machine-checked.

Lean source view module on GitHub

/-- Expansion of the third sum of squares T3 in the Magic Rectangle SOS identity. -/theorem magic_rectangle_sos_term3    {A : Type*} [Ring A] [Algebra ℝ A]    (D C B : Fin 3 → A)    (hD_sq : ∀ j, D j ^ 2 = 1)    (hC_sq : ∀ j, C j ^ 2 = 1)    (hB_sq : ∀ j, B j ^ 2 = 1)    (hD_prod : D 0 * D 1 * D 2 = 1)    (hC_prod : C 0 * C 1 * C 2 = -1)    (hD_comm : ∀ j k, D j * D k = D k * D j)    (hC_comm : ∀ j k, C j * C k = C k * C j)    (hDB_comm : ∀ j k, D j * B k = B k * D j)    (hCB_comm : ∀ j k, C j * B k = B k * C j)    (q : ℝ) :    let X := fun j => D j + C j    let Y := fun j => D j - C j    let W := fun j => Y (j + 1) * B (j + 2) + Y (j + 2) * B (j + 1)    let S := ∑ j : Fin 3, X j * B j    let J := ∑ j : Fin 3, Y j * (B (j + 1) * B (j + 2) + B (j + 2) * B (j + 1))    ∑ j : Fin 3, (X j + q • B j - q • W j) ^ 2 =      (∑ j : Fin 3, X j ^ 2) - (2 * q) • S + (3 * q ^ 2) • (1 : A) -      (2 * q ^ 2) • J + (q ^ 2) • (∑ j : Fin 3, W j ^ 2) := by  dsimp  let X := fun j => D j + C j  let Y := fun j => D j - C j  let W := fun j => Y (j + 1) * B (j + 2) + Y (j + 2) * B (j + 1)  let S := ∑ j : Fin 3, X j * B j  let J := ∑ j : Fin 3, Y j * (B (j + 1) * B (j + 2) + B (j + 2) * B (j + 1))  change (∑ j : Fin 3, (X j + q • B j - q • W j) ^ 2) =      (∑ j : Fin 3, X j ^ 2) - (2 * q) • S + (3 * q ^ 2) • (1 : A) -      (2 * q ^ 2) • J + (q ^ 2) • (∑ j : Fin 3, W j ^ 2)  have hXB (j : Fin 3) : B j * X j = X j * B j := by    dsimp [X]    simp only [mul_add, add_mul, ← hDB_comm j j, ← hCB_comm j j]  have hXBsum : (∑ j : Fin 3, (X j * B j + B j * X j)) = (2 : ℝ) • S := by    simp only [Fin.sum_univ_three]    rw [hXB 0, hXB 1, hXB 2]    dsimp [S]    simp only [Fin.sum_univ_three, smul_add]    module  have hBsum : (∑ j : Fin 3, B j ^ 2) = (3 : ℝ) • (1 : A) := by    simp only [hB_sq, Fin.sum_univ_three]    module  have hall := magic_rectangle_anticommutator_identities D C B hD_sq hC_sq hB_sq      hD_prod hC_prod hD_comm hC_comm hDB_comm hCB_comm  have hXW : (∑ j : Fin 3, (X j * W j + W j * X j)) = (4 : ℝ) • S := by    have h : (∑ j : Fin 3, (X j * W j + W j * X j)) = (4 : A) * S := hall.2.2.2    rw [h, Algebra.smul_def, map_ofNat]  have hWB : (∑ j : Fin 3, (W j * B j + B j * W j)) = (2 : ℝ) • J := by    have h : (∑ j : Fin 3, (W j * B j + B j * W j)) = (2 : A) * J := hall.2.1    rw [h, Algebra.smul_def, map_ofNat]  have hexpand : (∑ j : Fin 3, (X j + q • B j - q • W j) ^ 2) =      (∑ j : Fin 3, X j ^ 2) + q • (∑ j : Fin 3, (X j * B j + B j * X j)) -      q • (∑ j : Fin 3, (X j * W j + W j * X j)) +      (q ^ 2) • (∑ j : Fin 3, B j ^ 2) -      (q ^ 2) • (∑ j : Fin 3, (W j * B j + B j * W j)) +      (q ^ 2) • (∑ j : Fin 3, W j ^ 2) := by    simp only [Fin.sum_univ_three, pow_two, add_mul, mul_add, sub_mul, mul_sub,      smul_mul_assoc, mul_smul_comm, smul_smul, smul_add, smul_sub]    module  rw [hexpand, hXBsum, hXW, hBsum, hWB]  simp only [smul_smul]  module
See it in the graphDiscuss this resultChallenge it