AFTD Auto-Formalizing Theoretical Domains

magic_rectangle_row_relations

theoremverified

Let A be a ring and let D, C : Fin 3 → A satisfy D j ^ 2 = 1 and C j ^ 2 = 1 for all j, D 0 * D 1 * D 2 = 1, C 0 * C 1 * C 2 = -1, and pairwise commutativity D j * D k = D k * D j and C j * C k = C k * C j for all j, k. Setting X m = D m + C m and Y m = D m - C m, for every j : Fin 3 with i = j + 1 and k = j + 2, we have X j ^ 2 + Y j ^ 2 = 4, X i * X k + Y i * Y k = 2 * Y j, and X i * Y k + Y i * X k = 2 * X j.

Statement

theorem magic_rectangle_row_relations
    {A : Type*} [Ring A]
    (D C : Fin 3 → A)
    (hD_sq : ∀ j, D j ^ 2 = 1)
    (hC_sq : ∀ j, C 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)
    (j : Fin 3) :
    let X := fun m => D m + C m
    let Y := fun m => D m - C m
    let i := j + 1
    let k := j + 2
    X j ^ 2 + Y j ^ 2 = 4 ∧
    X i * X k + Y i * Y k = 2 * Y j ∧
    X i * Y k + Y i * X k = 2 * X j
Source
arXiv:2610.12001, Eq. (11)
Verified
01 Nov 2026
Axioms
Classical.choiceQuot.soundpropext
Used by 1

Read back from the Lean

Let $A$ be a ring, and let $D, C : \text{Fin } 3 \to A$ be families of three elements in $A$. Assume the following hypotheses: 1. For all $j \in \text{Fin } 3$, $D(j)^2 = 1$; 2. For all $j \in \text{Fin } 3$, $C(j)^2 = 1$; 3. $(D(0) \cdot D(1)) \cdot D(2) = 1$; 4. $(C(0) \cdot C(1)) \cdot C(2) = -1$; 5. For all $j, k \in \text{Fin } 3$, $D(j) \cdot D(k) = D(k) \cdot D(j)$; 6. For all $j, k \in \text{Fin } 3$, $C(j) \cdot C(k) = C(k) \cdot C(j)$. Then, for any $j \in \text{Fin } 3$, defining $X(m) = D(m) + C(m)$, $Y(m) = D(m) - C(m)$, $i = j + 1$, and $k = j + 2$ (with addition modulo 3 in $\text{Fin } 3$), the following three equalities hold: - $X(j)^2 + Y(j)^2 = 4$; - $X(i) \cdot X(k) + Y(i) \cdot Y(k) = 2 \cdot Y(j)$; - $X(i) \cdot Y(k) + Y(i) \cdot X(k) = 2 \cdot X(j)$.

Written by a model that saw only the Lean, never the English above. If the two disagree, that is worth a challenge.

The proof, explained

The proof first establishes general ring lemmas showing that the sum of squares $(x+y)^2 + (x-y)^2$ equals 4 whenever $x^2 = y^2 = 1$, and that bilinear cross expressions in $(d_1 \pm c_1)$ and $(d_2 \pm c_2)$ reduce to $2(d_j \mp c_j)$ whenever $d_1 d_2 = d_j$ and $c_1 c_2 = -c_j$. Next, the row product constraints $D_0 D_1 D_2 = 1$ and $C_0 C_1 C_2 = -1$, combined with involution and pairwise commutativity, imply that each cyclic pair multiplies to the remaining element (up to a sign for $C$). Finally, the theorem is proved by case analysis over $j \in \text{Fin } 3$, instantiating the helper lemmas with the corresponding cyclic product identities in each case.

  1. If $x^2 = 1$ in a ring, then $x \cdot x = 1$.

    By definition of powers in a monoid, $x^2$ is $x \cdot x$. Rewriting the hypothesis $x^2 = 1$ using `sq` transforms it into $x \cdot x = 1$.

    lines 1–4

    uses sq

    lemma magic_rectangle_row_relations_sq_eq_mul
        {A : Type*} [Ring A] (x : A) (h : x ^ 2 = 1) : x * x = 1 := by
      rwa [sq] at h
    
  2. If $x^2 = 1$ and $y^2 = 1$ in a ring, then $(x + y)^2 + (x - y)^2 = 4$.

    Expanding the squares in a ring without assuming commutativity yields $(x + y)^2 + (x - y)^2 = 2 x^2 + 2 y^2$, because the cross-terms $x y + y x$ from the sum cancel with $- x y - y x$ from the difference. Substituting the hypotheses $x^2 = 1$ and $y^2 = 1$ gives $2 \cdot 1 + 2 \cdot 1 = 4$.

    lines 5–11

    lemma magic_rectangle_row_relations_sq_add_sq
        {A : Type*} [Ring A] (x y : A) (hx : x ^ 2 = 1) (hy : y ^ 2 = 1) :
        (x + y) ^ 2 + (x - y) ^ 2 = 4 := by
      have h : (x + y) ^ 2 + (x - y) ^ 2 = 2 * x ^ 2 + 2 * y ^ 2 := by noncomm_ring
      rw [h, hx, hy]
      norm_num
    
  3. If $d_1 d_2 = d_j$ and $c_1 c_2 = -c_j$ in a ring, then $(d_1 + c_1)(d_2 + c_2) + (d_1 - c_1)(d_2 - c_2) = 2(d_j - c_j)$.

    Expanding the two products and adding them cancels the mixed cross-terms $d_1 c_2 + c_1 d_2$ and $- d_1 c_2 - c_1 d_2$, leaving $2(d_1 d_2 + c_1 c_2)$. Substituting $d_1 d_2 = d_j$ and $c_1 c_2 = - c_j$ evaluates this to $2(d_j - c_j)$.

    lines 12–20

    lemma magic_rectangle_row_relations_cross_sum
        {A : Type*} [Ring A] (d1 d2 c1 c2 dj cj : A)
        (hd : d1 * d2 = dj) (hc : c1 * c2 = - cj) :
        (d1 + c1) * (d2 + c2) + (d1 - c1) * (d2 - c2) = 2 * (dj - cj) := by
      calc (d1 + c1) * (d2 + c2) + (d1 - c1) * (d2 - c2)
        _ = 2 * (d1 * d2 + c1 * c2) := by noncomm_ring
        _ = 2 * (dj + - cj) := by rw [hd, hc]
        _ = 2 * (dj - cj) := by noncomm_ring
    
  4. If $d_1 d_2 = d_j$ and $c_1 c_2 = -c_j$ in a ring, then $(d_1 + c_1)(d_2 - c_2) + (d_1 - c_1)(d_2 + c_2) = 2(d_j + c_j)$.

    Expanding the two products and adding them cancels the mixed terms $- d_1 c_2 + c_1 d_2$ and $d_1 c_2 - c_1 d_2$, leaving $2(d_1 d_2 - c_1 c_2)$. Substituting $d_1 d_2 = d_j$ and $c_1 c_2 = - c_j$ gives $2(d_j - (- c_j)) = 2(d_j + c_j)$.

    lines 21–29

    lemma magic_rectangle_row_relations_cross_diff
        {A : Type*} [Ring A] (d1 d2 c1 c2 dj cj : A)
        (hd : d1 * d2 = dj) (hc : c1 * c2 = - cj) :
        (d1 + c1) * (d2 - c2) + (d1 - c1) * (d2 + c2) = 2 * (dj + cj) := by
      calc (d1 + c1) * (d2 - c2) + (d1 - c1) * (d2 + c2)
        _ = 2 * (d1 * d2 - c1 * c2) := by noncomm_ring
        _ = 2 * (dj - - cj) := by rw [hd, hc]
        _ = 2 * (dj + cj) := by noncomm_ring
    
  5. For every index $m \in \{0, 1, 2\}$, $D_m \cdot D_m = 1$ and $C_m \cdot C_m = 1$.

    Applying `magic_rectangle_row_relations_sq_eq_mul` to the squaring hypotheses $D_m^2 = 1$ (`hD_sq`) and $C_m^2 = 1$ (`hC_sq`) converts them into the explicit multiplication identities $D_m \cdot D_m = 1$ and $C_m \cdot C_m = 1$.

    lines 30–51

    uses magic_rectangle_row_relations_sq_eq_mul

    /-- Row parity relations and anticommutation identities for X_j and Y_j in a ring. -/
    theorem magic_rectangle_row_relations
        {A : Type*} [Ring A]
        (D C : Fin 3 → A)
        (hD_sq : ∀ j, D j ^ 2 = 1)
        (hC_sq : ∀ j, C 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)
        (j : Fin 3) :
        let X := fun m => D m + C m
        let Y := fun m => D m - C m
        let i := j + 1
        let k := j + 2
        X j ^ 2 + Y j ^ 2 = 4 ∧
        X i * X k + Y i * Y k = 2 * Y j ∧
        X i * Y k + Y i * X k = 2 * X j := by
      have hD_sq_mul (m : Fin 3) : D m * D m = 1 :=
        magic_rectangle_row_relations_sq_eq_mul (D m) (hD_sq m)
      have hC_sq_mul (m : Fin 3) : C m * C m = 1 :=
        magic_rectangle_row_relations_sq_eq_mul (C m) (hC_sq m)
  6. The pairwise cyclic products of $D$ satisfy $D_0 D_1 = D_2$, $D_1 D_2 = D_0$, and $D_2 D_0 = D_1$.

    Each product is obtained by inserting an identity factor $D_m D_m = 1$ and applying the global product hypothesis $D_0 D_1 D_2 = 1$ (`hD_prod`). Specifically, $D_0 D_1 = (D_0 D_1)(D_2 D_2) = (D_0 D_1 D_2) D_2 = 1 \cdot D_2 = D_2$; similarly, $D_1 D_2 = (D_0 D_0)(D_1 D_2) = D_0 (D_0 D_1 D_2) = D_0 \cdot 1 = D_0$. For $D_2 D_0$, multiplying on the left by $D_1 D_1 = 1$ and using the pairwise commutativity of $D$ (`hD_comm`) allows reordering $D_1 (D_1 D_2 D_0) = D_1 (D_0 D_1 D_2) = D_1 \cdot 1 = D_1$.

    lines 52–73

      have hD01 : D 0 * D 1 = D 2 := by
        calc D 0 * D 1 = (D 0 * D 1) * 1 := by noncomm_ring
        _ = (D 0 * D 1) * (D 2 * D 2) := by rw [hD_sq_mul 2]
        _ = (D 0 * D 1 * D 2) * D 2 := by noncomm_ring
        _ = 1 * D 2 := by rw [hD_prod]
        _ = D 2 := by noncomm_ring
      have hD12 : D 1 * D 2 = D 0 := by
        calc D 1 * D 2 = 1 * (D 1 * D 2) := by noncomm_ring
        _ = (D 0 * D 0) * (D 1 * D 2) := by rw [hD_sq_mul 0]
        _ = D 0 * (D 0 * D 1 * D 2) := by noncomm_ring
        _ = D 0 * 1 := by rw [hD_prod]
        _ = D 0 := by noncomm_ring
      have hD20 : D 2 * D 0 = D 1 := by
        calc D 2 * D 0 = 1 * (D 2 * D 0) := by noncomm_ring
        _ = (D 1 * D 1) * (D 2 * D 0) := by rw [hD_sq_mul 1]
        _ = D 1 * (D 1 * (D 2 * D 0)) := by noncomm_ring
        _ = D 1 * (D 1 * (D 0 * D 2)) := by rw [hD_comm 2 0]
        _ = D 1 * ((D 1 * D 0) * D 2) := by noncomm_ring
        _ = D 1 * ((D 0 * D 1) * D 2) := by rw [hD_comm 1 0]
        _ = D 1 * (D 0 * D 1 * D 2) := by noncomm_ring
        _ = D 1 * 1 := by rw [hD_prod]
        _ = D 1 := by noncomm_ring
  7. The pairwise cyclic products of $C$ satisfy $C_0 C_1 = - C_2$, $C_1 C_2 = - C_0$, and $C_2 C_0 = - C_1$.

    The derivations mirror those for $D$, but use $C_0 C_1 C_2 = -1$ (`hC_prod`). Thus, $C_0 C_1 = (C_0 C_1)(C_2 C_2) = (C_0 C_1 C_2) C_2 = -1 \cdot C_2 = - C_2$, and $C_1 C_2 = (C_0 C_0)(C_1 C_2) = C_0 (C_0 C_1 C_2) = C_0 (-1) = - C_0$. For $C_2 C_0$, inserting $C_1 C_1 = 1$ and using the pairwise commutativity of $C$ (`hC_comm`) reorders the product to $C_1 (C_0 C_1 C_2) = C_1 (-1) = - C_1$.

    lines 74–95

      have hC01 : C 0 * C 1 = - C 2 := by
        calc C 0 * C 1 = (C 0 * C 1) * 1 := by noncomm_ring
        _ = (C 0 * C 1) * (C 2 * C 2) := by rw [hC_sq_mul 2]
        _ = (C 0 * C 1 * C 2) * C 2 := by noncomm_ring
        _ = -1 * C 2 := by rw [hC_prod]
        _ = - C 2 := by noncomm_ring
      have hC12 : C 1 * C 2 = - C 0 := by
        calc C 1 * C 2 = 1 * (C 1 * C 2) := by noncomm_ring
        _ = (C 0 * C 0) * (C 1 * C 2) := by rw [hC_sq_mul 0]
        _ = C 0 * (C 0 * C 1 * C 2) := by noncomm_ring
        _ = C 0 * (-1) := by rw [hC_prod]
        _ = - C 0 := by noncomm_ring
      have hC20 : C 2 * C 0 = - C 1 := by
        calc C 2 * C 0 = 1 * (C 2 * C 0) := by noncomm_ring
        _ = (C 1 * C 1) * (C 2 * C 0) := by rw [hC_sq_mul 1]
        _ = C 1 * (C 1 * (C 2 * C 0)) := by noncomm_ring
        _ = C 1 * (C 1 * (C 0 * C 2)) := by rw [hC_comm 2 0]
        _ = C 1 * ((C 1 * C 0) * C 2) := by noncomm_ring
        _ = C 1 * ((C 0 * C 1) * C 2) := by rw [hC_comm 1 0]
        _ = C 1 * (C 0 * C 1 * C 2) := by noncomm_ring
        _ = C 1 * (-1) := by rw [hC_prod]
        _ = - C 1 := by noncomm_ring
  8. It suffices to establish the three identities for each value of $j \in \{0, 1, 2\}$.

    We introduce the definitions of $X$, $Y$, $i = j + 1$, and $k = j + 2$, and perform exhaustive case analysis on the finite type `Fin 3` (`fin_cases j`), reducing the goal to the three cases $j = 0$, $j = 1$, and $j = 2$.

    lines 96–97

      intro X Y i k
      fin_cases j
  9. The three identities hold when $j = 0$ (where $i = 1$ and $k = 2$).

    Specialising to $j = 0$, $i = 1$, and $k = 2$: the first identity $(D_0 + C_0)^2 + (D_0 - C_0)^2 = 4$ holds by `magic_rectangle_row_relations_sq_add_sq`. The second and third identities for the cross combinations of indices $1$ and $2$ evaluate to $2(D_0 - C_0) = 2 Y_0$ and $2(D_0 + C_0) = 2 X_0$ by `magic_rectangle_row_relations_cross_sum` and `magic_rectangle_row_relations_cross_diff`, using the relations $D_1 D_2 = D_0$ (`hD12`) and $C_1 C_2 = - C_0$ (`hC12`).

    lines 98–103

    uses magic_rectangle_row_relations_sq_add_sq, magic_rectangle_row_relations_cross_sum, magic_rectangle_row_relations_cross_diff

      · change (D 0 + C 0) ^ 2 + (D 0 - C 0) ^ 2 = 4 ∧
          (D 1 + C 1) * (D 2 + C 2) + (D 1 - C 1) * (D 2 - C 2) = 2 * (D 0 - C 0) ∧
          (D 1 + C 1) * (D 2 - C 2) + (D 1 - C 1) * (D 2 + C 2) = 2 * (D 0 + C 0)
        exact ⟨magic_rectangle_row_relations_sq_add_sq (D 0) (C 0) (hD_sq 0) (hC_sq 0),
               magic_rectangle_row_relations_cross_sum (D 1) (D 2) (C 1) (C 2) (D 0) (C 0) hD12 hC12,
               magic_rectangle_row_relations_cross_diff (D 1) (D 2) (C 1) (C 2) (D 0) (C 0) hD12 hC12⟩
  10. The three identities hold when $j = 1$ (where $i = 2$ and $k = 0$).

    Specialising to $j = 1$, $i = 2$, and $k = 0$ (modulo 3): $(D_1 + C_1)^2 + (D_1 - C_1)^2 = 4$ holds by `magic_rectangle_row_relations_sq_add_sq`. The cross combinations of indices $2$ and $0$ evaluate to $2(D_1 - C_1) = 2 Y_1$ and $2(D_1 + C_1) = 2 X_1$ by `magic_rectangle_row_relations_cross_sum` and `magic_rectangle_row_relations_cross_diff`, using $D_2 D_0 = D_1$ (`hD20`) and $C_2 C_0 = - C_1$ (`hC20`).

    lines 104–109

    uses magic_rectangle_row_relations_sq_add_sq, magic_rectangle_row_relations_cross_sum, magic_rectangle_row_relations_cross_diff

      · change (D 1 + C 1) ^ 2 + (D 1 - C 1) ^ 2 = 4 ∧
          (D 2 + C 2) * (D 0 + C 0) + (D 2 - C 2) * (D 0 - C 0) = 2 * (D 1 - C 1) ∧
          (D 2 + C 2) * (D 0 - C 0) + (D 2 - C 2) * (D 0 + C 0) = 2 * (D 1 + C 1)
        exact ⟨magic_rectangle_row_relations_sq_add_sq (D 1) (C 1) (hD_sq 1) (hC_sq 1),
               magic_rectangle_row_relations_cross_sum (D 2) (D 0) (C 2) (C 0) (D 1) (C 1) hD20 hC20,
               magic_rectangle_row_relations_cross_diff (D 2) (D 0) (C 2) (C 0) (D 1) (C 1) hD20 hC20⟩
  11. The three identities hold when $j = 2$ (where $i = 0$ and $k = 1$).

    Specialising to $j = 2$, $i = 0$, and $k = 1$ (modulo 3): $(D_2 + C_2)^2 + (D_2 - C_2)^2 = 4$ holds by `magic_rectangle_row_relations_sq_add_sq`. The cross combinations of indices $0$ and $1$ evaluate to $2(D_2 - C_2) = 2 Y_2$ and $2(D_2 + C_2) = 2 X_2$ by `magic_rectangle_row_relations_cross_sum` and `magic_rectangle_row_relations_cross_diff`, using $D_0 D_1 = D_2$ (`hD01`) and $C_0 C_1 = - C_2$ (`hC01`).

    lines 110–115

    uses magic_rectangle_row_relations_sq_add_sq, magic_rectangle_row_relations_cross_sum, magic_rectangle_row_relations_cross_diff

      · change (D 2 + C 2) ^ 2 + (D 2 - C 2) ^ 2 = 4 ∧
          (D 0 + C 0) * (D 1 + C 1) + (D 0 - C 0) * (D 1 - C 1) = 2 * (D 2 - C 2) ∧
          (D 0 + C 0) * (D 1 - C 1) + (D 0 - C 0) * (D 1 + C 1) = 2 * (D 2 + C 2)
        exact ⟨magic_rectangle_row_relations_sq_add_sq (D 2) (C 2) (hD_sq 2) (hC_sq 2),
               magic_rectangle_row_relations_cross_sum (D 0) (D 1) (C 0) (C 1) (D 2) (C 2) hD01 hC01,
               magic_rectangle_row_relations_cross_diff (D 0) (D 1) (C 0) (C 1) (D 2) (C 2) hD01 hC01⟩
sq
in any monoid, the square $a^2$ is definitionally the product $a \cdot a$
magic_rectangle_row_relations_sq_eq_mul
in a ring, if an element $x$ satisfies $x^2 = 1$, then $x \cdot x = 1$
magic_rectangle_row_relations_sq_add_sq
in a ring, if two elements $x$ and $y$ satisfy $x^2 = 1$ and $y^2 = 1$, then $(x + y)^2 + (x - y)^2 = 4$
magic_rectangle_row_relations_cross_sum
in a ring, if $d_1 d_2 = d_j$ and $c_1 c_2 = -c_j$, then $(d_1 + c_1)(d_2 + c_2) + (d_1 - c_1)(d_2 - c_2) = 2(d_j - c_j)$
magic_rectangle_row_relations_cross_diff
in a ring, if $d_1 d_2 = d_j$ and $c_1 c_2 = -c_j$, then $(d_1 + c_1)(d_2 - c_2) + (d_1 - c_1)(d_2 + c_2) = 2(d_j + c_j)$

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

lemma magic_rectangle_row_relations_sq_eq_mul    {A : Type*} [Ring A] (x : A) (h : x ^ 2 = 1) : x * x = 1 := by  rwa [sq] at hlemma magic_rectangle_row_relations_sq_add_sq    {A : Type*} [Ring A] (x y : A) (hx : x ^ 2 = 1) (hy : y ^ 2 = 1) :    (x + y) ^ 2 + (x - y) ^ 2 = 4 := by  have h : (x + y) ^ 2 + (x - y) ^ 2 = 2 * x ^ 2 + 2 * y ^ 2 := by noncomm_ring  rw [h, hx, hy]  norm_numlemma magic_rectangle_row_relations_cross_sum    {A : Type*} [Ring A] (d1 d2 c1 c2 dj cj : A)    (hd : d1 * d2 = dj) (hc : c1 * c2 = - cj) :    (d1 + c1) * (d2 + c2) + (d1 - c1) * (d2 - c2) = 2 * (dj - cj) := by  calc (d1 + c1) * (d2 + c2) + (d1 - c1) * (d2 - c2)    _ = 2 * (d1 * d2 + c1 * c2) := by noncomm_ring    _ = 2 * (dj + - cj) := by rw [hd, hc]    _ = 2 * (dj - cj) := by noncomm_ringlemma magic_rectangle_row_relations_cross_diff    {A : Type*} [Ring A] (d1 d2 c1 c2 dj cj : A)    (hd : d1 * d2 = dj) (hc : c1 * c2 = - cj) :    (d1 + c1) * (d2 - c2) + (d1 - c1) * (d2 + c2) = 2 * (dj + cj) := by  calc (d1 + c1) * (d2 - c2) + (d1 - c1) * (d2 + c2)    _ = 2 * (d1 * d2 - c1 * c2) := by noncomm_ring    _ = 2 * (dj - - cj) := by rw [hd, hc]    _ = 2 * (dj + cj) := by noncomm_ring/-- Row parity relations and anticommutation identities for X_j and Y_j in a ring. -/theorem magic_rectangle_row_relations    {A : Type*} [Ring A]    (D C : Fin 3 → A)    (hD_sq : ∀ j, D j ^ 2 = 1)    (hC_sq : ∀ j, C 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)    (j : Fin 3) :    let X := fun m => D m + C m    let Y := fun m => D m - C m    let i := j + 1    let k := j + 2    X j ^ 2 + Y j ^ 2 = 4 ∧    X i * X k + Y i * Y k = 2 * Y j ∧    X i * Y k + Y i * X k = 2 * X j := by  have hD_sq_mul (m : Fin 3) : D m * D m = 1 :=    magic_rectangle_row_relations_sq_eq_mul (D m) (hD_sq m)  have hC_sq_mul (m : Fin 3) : C m * C m = 1 :=    magic_rectangle_row_relations_sq_eq_mul (C m) (hC_sq m)  have hD01 : D 0 * D 1 = D 2 := by    calc D 0 * D 1 = (D 0 * D 1) * 1 := by noncomm_ring    _ = (D 0 * D 1) * (D 2 * D 2) := by rw [hD_sq_mul 2]    _ = (D 0 * D 1 * D 2) * D 2 := by noncomm_ring    _ = 1 * D 2 := by rw [hD_prod]    _ = D 2 := by noncomm_ring  have hD12 : D 1 * D 2 = D 0 := by    calc D 1 * D 2 = 1 * (D 1 * D 2) := by noncomm_ring    _ = (D 0 * D 0) * (D 1 * D 2) := by rw [hD_sq_mul 0]    _ = D 0 * (D 0 * D 1 * D 2) := by noncomm_ring    _ = D 0 * 1 := by rw [hD_prod]    _ = D 0 := by noncomm_ring  have hD20 : D 2 * D 0 = D 1 := by    calc D 2 * D 0 = 1 * (D 2 * D 0) := by noncomm_ring    _ = (D 1 * D 1) * (D 2 * D 0) := by rw [hD_sq_mul 1]    _ = D 1 * (D 1 * (D 2 * D 0)) := by noncomm_ring    _ = D 1 * (D 1 * (D 0 * D 2)) := by rw [hD_comm 2 0]    _ = D 1 * ((D 1 * D 0) * D 2) := by noncomm_ring    _ = D 1 * ((D 0 * D 1) * D 2) := by rw [hD_comm 1 0]    _ = D 1 * (D 0 * D 1 * D 2) := by noncomm_ring    _ = D 1 * 1 := by rw [hD_prod]    _ = D 1 := by noncomm_ring  have hC01 : C 0 * C 1 = - C 2 := by    calc C 0 * C 1 = (C 0 * C 1) * 1 := by noncomm_ring    _ = (C 0 * C 1) * (C 2 * C 2) := by rw [hC_sq_mul 2]    _ = (C 0 * C 1 * C 2) * C 2 := by noncomm_ring    _ = -1 * C 2 := by rw [hC_prod]    _ = - C 2 := by noncomm_ring  have hC12 : C 1 * C 2 = - C 0 := by    calc C 1 * C 2 = 1 * (C 1 * C 2) := by noncomm_ring    _ = (C 0 * C 0) * (C 1 * C 2) := by rw [hC_sq_mul 0]    _ = C 0 * (C 0 * C 1 * C 2) := by noncomm_ring    _ = C 0 * (-1) := by rw [hC_prod]    _ = - C 0 := by noncomm_ring  have hC20 : C 2 * C 0 = - C 1 := by    calc C 2 * C 0 = 1 * (C 2 * C 0) := by noncomm_ring    _ = (C 1 * C 1) * (C 2 * C 0) := by rw [hC_sq_mul 1]    _ = C 1 * (C 1 * (C 2 * C 0)) := by noncomm_ring    _ = C 1 * (C 1 * (C 0 * C 2)) := by rw [hC_comm 2 0]    _ = C 1 * ((C 1 * C 0) * C 2) := by noncomm_ring    _ = C 1 * ((C 0 * C 1) * C 2) := by rw [hC_comm 1 0]    _ = C 1 * (C 0 * C 1 * C 2) := by noncomm_ring    _ = C 1 * (-1) := by rw [hC_prod]    _ = - C 1 := by noncomm_ring  intro X Y i k  fin_cases j  · change (D 0 + C 0) ^ 2 + (D 0 - C 0) ^ 2 = 4 ∧      (D 1 + C 1) * (D 2 + C 2) + (D 1 - C 1) * (D 2 - C 2) = 2 * (D 0 - C 0) ∧      (D 1 + C 1) * (D 2 - C 2) + (D 1 - C 1) * (D 2 + C 2) = 2 * (D 0 + C 0)    exact ⟨magic_rectangle_row_relations_sq_add_sq (D 0) (C 0) (hD_sq 0) (hC_sq 0),           magic_rectangle_row_relations_cross_sum (D 1) (D 2) (C 1) (C 2) (D 0) (C 0) hD12 hC12,           magic_rectangle_row_relations_cross_diff (D 1) (D 2) (C 1) (C 2) (D 0) (C 0) hD12 hC12⟩  · change (D 1 + C 1) ^ 2 + (D 1 - C 1) ^ 2 = 4 ∧      (D 2 + C 2) * (D 0 + C 0) + (D 2 - C 2) * (D 0 - C 0) = 2 * (D 1 - C 1) ∧      (D 2 + C 2) * (D 0 - C 0) + (D 2 - C 2) * (D 0 + C 0) = 2 * (D 1 + C 1)    exact ⟨magic_rectangle_row_relations_sq_add_sq (D 1) (C 1) (hD_sq 1) (hC_sq 1),           magic_rectangle_row_relations_cross_sum (D 2) (D 0) (C 2) (C 0) (D 1) (C 1) hD20 hC20,           magic_rectangle_row_relations_cross_diff (D 2) (D 0) (C 2) (C 0) (D 1) (C 1) hD20 hC20⟩  · change (D 2 + C 2) ^ 2 + (D 2 - C 2) ^ 2 = 4 ∧      (D 0 + C 0) * (D 1 + C 1) + (D 0 - C 0) * (D 1 - C 1) = 2 * (D 2 - C 2) ∧      (D 0 + C 0) * (D 1 - C 1) + (D 0 - C 0) * (D 1 + C 1) = 2 * (D 2 + C 2)    exact ⟨magic_rectangle_row_relations_sq_add_sq (D 2) (C 2) (hD_sq 2) (hC_sq 2),           magic_rectangle_row_relations_cross_sum (D 0) (D 1) (C 0) (C 1) (D 2) (C 2) hD01 hC01,           magic_rectangle_row_relations_cross_diff (D 0) (D 1) (C 0) (C 1) (D 2) (C 2) hD01 hC01⟩
See it in the graphDiscuss this resultChallenge it