[GOAL]
R : Type u_1
inst✝ : CommRing R
a b c d x y z w : R
⊢ (a * x - b * y - c * z - d * w) ^ 2 + (a * y + b * x + c * w - d * z) ^ 2 + (a * z - b * w + c * x + d * y) ^ 2 +
      (a * w + b * z - c * y + d * x) ^ 2 =
    (a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) * (x ^ 2 + y ^ 2 + z ^ 2 + w ^ 2)
[PROOFSTEP]
ring
[GOAL]
a b c d x y z w : ℕ
⊢ Int.natAbs (↑a * ↑x - ↑b * ↑y - ↑c * ↑z - ↑d * ↑w) ^ 2 + Int.natAbs (↑a * ↑y + ↑b * ↑x + ↑c * ↑w - ↑d * ↑z) ^ 2 +
        Int.natAbs (↑a * ↑z - ↑b * ↑w + ↑c * ↑x + ↑d * ↑y) ^ 2 +
      Int.natAbs (↑a * ↑w + ↑b * ↑z - ↑c * ↑y + ↑d * ↑x) ^ 2 =
    (a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) * (x ^ 2 + y ^ 2 + z ^ 2 + w ^ 2)
[PROOFSTEP]
rw [← Int.coe_nat_inj']
[GOAL]
a b c d x y z w : ℕ
⊢ ↑(Int.natAbs (↑a * ↑x - ↑b * ↑y - ↑c * ↑z - ↑d * ↑w) ^ 2 + Int.natAbs (↑a * ↑y + ↑b * ↑x + ↑c * ↑w - ↑d * ↑z) ^ 2 +
          Int.natAbs (↑a * ↑z - ↑b * ↑w + ↑c * ↑x + ↑d * ↑y) ^ 2 +
        Int.natAbs (↑a * ↑w + ↑b * ↑z - ↑c * ↑y + ↑d * ↑x) ^ 2) =
    ↑((a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) * (x ^ 2 + y ^ 2 + z ^ 2 + w ^ 2))
[PROOFSTEP]
push_cast
[GOAL]
a b c d x y z w : ℕ
⊢ |↑a * ↑x - ↑b * ↑y - ↑c * ↑z - ↑d * ↑w| ^ 2 + |↑a * ↑y + ↑b * ↑x + ↑c * ↑w - ↑d * ↑z| ^ 2 +
        |↑a * ↑z - ↑b * ↑w + ↑c * ↑x + ↑d * ↑y| ^ 2 +
      |↑a * ↑w + ↑b * ↑z - ↑c * ↑y + ↑d * ↑x| ^ 2 =
    (↑a ^ 2 + ↑b ^ 2 + ↑c ^ 2 + ↑d ^ 2) * (↑x ^ 2 + ↑y ^ 2 + ↑z ^ 2 + ↑w ^ 2)
[PROOFSTEP]
simp only [sq_abs, _root_.euler_four_squares]
[GOAL]
m x y : ℤ
h : ↑2 * m = x ^ 2 + y ^ 2
⊢ Even (x ^ 2 + y ^ 2)
[PROOFSTEP]
simp [← h, even_mul]
[GOAL]
m x y : ℤ
h : ↑2 * m = x ^ 2 + y ^ 2
this : Even (x ^ 2 + y ^ 2)
⊢ Even (x + y)
[PROOFSTEP]
simpa [sq, parity_simps]
[GOAL]
m x y : ℤ
h : ↑2 * m = x ^ 2 + y ^ 2
this : Even (x ^ 2 + y ^ 2)
hxaddy : Even (x + y)
⊢ Even (x - y)
[PROOFSTEP]
simpa [sq, parity_simps]
[GOAL]
m x y : ℤ
h : ↑2 * m = x ^ 2 + y ^ 2
this : Even (x ^ 2 + y ^ 2)
hxaddy : Even (x + y)
hxsuby : Even (x - y)
⊢ 2 * 2 ≠ 0
[PROOFSTEP]
decide
[GOAL]
m x y : ℤ
h : ↑2 * m = x ^ 2 + y ^ 2
this : Even (x ^ 2 + y ^ 2)
hxaddy : Even (x + y)
hxsuby : Even (x - y)
⊢ ↑2 * ↑2 * m = (x - y) ^ 2 + (x + y) ^ 2
[PROOFSTEP]
rw [mul_assoc, h]
[GOAL]
m x y : ℤ
h : ↑2 * m = x ^ 2 + y ^ 2
this : Even (x ^ 2 + y ^ 2)
hxaddy : Even (x + y)
hxsuby : Even (x - y)
⊢ ↑2 * (x ^ 2 + y ^ 2) = (x - y) ^ 2 + (x + y) ^ 2
[PROOFSTEP]
ring
[GOAL]
m x y : ℤ
h : ↑2 * m = x ^ 2 + y ^ 2
this : Even (x ^ 2 + y ^ 2)
hxaddy : Even (x + y)
hxsuby : Even (x - y)
⊢ (x - y) ^ 2 + (x + y) ^ 2 = (2 * ((x - y) / 2)) ^ 2 + (2 * ((x + y) / 2)) ^ 2
[PROOFSTEP]
rw [even_iff_two_dvd] at hxsuby hxaddy 
[GOAL]
m x y : ℤ
h : ↑2 * m = x ^ 2 + y ^ 2
this : Even (x ^ 2 + y ^ 2)
hxaddy : 2 ∣ x + y
hxsuby : 2 ∣ x - y
⊢ (x - y) ^ 2 + (x + y) ^ 2 = (2 * ((x - y) / 2)) ^ 2 + (2 * ((x + y) / 2)) ^ 2
[PROOFSTEP]
rw [Int.mul_ediv_cancel' hxsuby, Int.mul_ediv_cancel' hxaddy]
[GOAL]
m x y : ℤ
h : ↑2 * m = x ^ 2 + y ^ 2
this : Even (x ^ 2 + y ^ 2)
hxaddy : Even (x + y)
hxsuby : Even (x - y)
⊢ (2 * ((x - y) / 2)) ^ 2 + (2 * ((x + y) / 2)) ^ 2 = ↑2 * ↑2 * (((x - y) / 2) ^ 2 + ((x + y) / 2) ^ 2)
[PROOFSTEP]
simp [mul_add, pow_succ, mul_comm, mul_assoc, mul_left_comm]
[GOAL]
a b c d k m : ℕ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m
ha : 2 * a < m
hb : 2 * b < m
hc : 2 * c < m
hd : 2 * d < m
⊢ k < m
[PROOFSTEP]
refine lt_of_mul_lt_mul_right (lt_of_mul_lt_mul_left ?_ (zero_le (2 ^ 2))) (zero_le m)
[GOAL]
a b c d k m : ℕ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m
ha : 2 * a < m
hb : 2 * b < m
hc : 2 * c < m
hd : 2 * d < m
⊢ 2 ^ 2 * (k * m) < 2 ^ 2 * (m * m)
[PROOFSTEP]
calc
  2 ^ 2 * (k * ↑m) = ∑ i : Fin 4, (2 * ![a, b, c, d] i) ^ 2 := by
    simp [← h, Fin.sum_univ_succ, mul_add, mul_pow, add_assoc]
  _ < ∑ _i : Fin 4, m ^ 2 :=
    (Finset.sum_lt_sum_of_nonempty Finset.univ_nonempty fun i _ ↦
      by
      refine pow_lt_pow_of_lt_left ?_ (zero_le _) two_pos
      fin_cases i <;> assumption)
  _ = 2 ^ 2 * (m * m) := by simp;
    ring
      -- porting note: new theorem
[GOAL]
a b c d k m : ℕ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m
ha : 2 * a < m
hb : 2 * b < m
hc : 2 * c < m
hd : 2 * d < m
⊢ 2 ^ 2 * (k * m) = ∑ i : Fin 4, (2 * Matrix.vecCons a ![b, c, d] i) ^ 2
[PROOFSTEP]
simp [← h, Fin.sum_univ_succ, mul_add, mul_pow, add_assoc]
[GOAL]
a b c d k m : ℕ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m
ha : 2 * a < m
hb : 2 * b < m
hc : 2 * c < m
hd : 2 * d < m
i : Fin 4
x✝ : i ∈ univ
⊢ (2 * Matrix.vecCons a ![b, c, d] i) ^ 2 < m ^ 2
[PROOFSTEP]
refine pow_lt_pow_of_lt_left ?_ (zero_le _) two_pos
[GOAL]
a b c d k m : ℕ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m
ha : 2 * a < m
hb : 2 * b < m
hc : 2 * c < m
hd : 2 * d < m
i : Fin 4
x✝ : i ∈ univ
⊢ 2 * Matrix.vecCons a ![b, c, d] i < m
[PROOFSTEP]
fin_cases i
[GOAL]
case head
a b c d k m : ℕ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m
ha : 2 * a < m
hb : 2 * b < m
hc : 2 * c < m
hd : 2 * d < m
x✝ : { val := 0, isLt := (_ : 0 < 4) } ∈ univ
⊢ 2 * Matrix.vecCons a ![b, c, d] { val := 0, isLt := (_ : 0 < 4) } < m
[PROOFSTEP]
assumption
[GOAL]
case tail.head
a b c d k m : ℕ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m
ha : 2 * a < m
hb : 2 * b < m
hc : 2 * c < m
hd : 2 * d < m
x✝ : { val := 1, isLt := (_ : (fun a => a < 4) 1) } ∈ univ
⊢ 2 * Matrix.vecCons a ![b, c, d] { val := 1, isLt := (_ : (fun a => a < 4) 1) } < m
[PROOFSTEP]
assumption
[GOAL]
case tail.tail.head
a b c d k m : ℕ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m
ha : 2 * a < m
hb : 2 * b < m
hc : 2 * c < m
hd : 2 * d < m
x✝ : { val := 2, isLt := (_ : (fun a => (fun a => a < 4) a) 2) } ∈ univ
⊢ 2 * Matrix.vecCons a ![b, c, d] { val := 2, isLt := (_ : (fun a => (fun a => a < 4) a) 2) } < m
[PROOFSTEP]
assumption
[GOAL]
case tail.tail.tail.head
a b c d k m : ℕ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m
ha : 2 * a < m
hb : 2 * b < m
hc : 2 * c < m
hd : 2 * d < m
x✝ : { val := 3, isLt := (_ : (fun a => (fun a => (fun a => a < 4) a) a) 3) } ∈ univ
⊢ 2 * Matrix.vecCons a ![b, c, d] { val := 3, isLt := (_ : (fun a => (fun a => (fun a => a < 4) a) a) 3) } < m
[PROOFSTEP]
assumption
[GOAL]
a b c d k m : ℕ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m
ha : 2 * a < m
hb : 2 * b < m
hc : 2 * c < m
hd : 2 * d < m
⊢ ∑ _i : Fin 4, m ^ 2 = 2 ^ 2 * (m * m)
[PROOFSTEP]
simp
[GOAL]
a b c d k m : ℕ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k * m
ha : 2 * a < m
hb : 2 * b < m
hc : 2 * c < m
hd : 2 * d < m
⊢ 4 * m ^ 2 = 2 ^ 2 * (m * m)
[PROOFSTEP]
ring
  -- porting note: new theorem
[GOAL]
p : ℕ
hp : Fact (Nat.Prime p)
⊢ ∃ a b k, 0 < k ∧ k < p ∧ a ^ 2 + b ^ 2 + 1 = k * p
[PROOFSTEP]
rcases hp.1.eq_two_or_odd' with (rfl | hodd)
[GOAL]
case inl
hp : Fact (Nat.Prime 2)
⊢ ∃ a b k, 0 < k ∧ k < 2 ∧ a ^ 2 + b ^ 2 + 1 = k * 2
[PROOFSTEP]
use 1, 0, 1
[GOAL]
case h
hp : Fact (Nat.Prime 2)
⊢ 0 < 1 ∧ 1 < 2 ∧ 1 ^ 2 + 0 ^ 2 + 1 = 1 * 2
[PROOFSTEP]
simp
[GOAL]
case inr
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
⊢ ∃ a b k, 0 < k ∧ k < p ∧ a ^ 2 + b ^ 2 + 1 = k * p
[PROOFSTEP]
rcases Nat.sq_add_sq_zmodEq p (-1) with ⟨a, b, ha, hb, hab⟩
[GOAL]
case inr.intro.intro.intro.intro
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
⊢ ∃ a b k, 0 < k ∧ k < p ∧ a ^ 2 + b ^ 2 + 1 = k * p
[PROOFSTEP]
rcases Int.modEq_iff_dvd.1 hab.symm with ⟨k, hk⟩
[GOAL]
case inr.intro.intro.intro.intro.intro
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℤ
hk : ↑a ^ 2 + ↑b ^ 2 - -1 = ↑p * k
⊢ ∃ a b k, 0 < k ∧ k < p ∧ a ^ 2 + b ^ 2 + 1 = k * p
[PROOFSTEP]
rw [sub_neg_eq_add, mul_comm] at hk 
[GOAL]
case inr.intro.intro.intro.intro.intro
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℤ
hk : ↑a ^ 2 + ↑b ^ 2 + 1 = k * ↑p
⊢ ∃ a b k, 0 < k ∧ k < p ∧ a ^ 2 + b ^ 2 + 1 = k * p
[PROOFSTEP]
have hk₀ : 0 < k
[GOAL]
case hk₀
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℤ
hk : ↑a ^ 2 + ↑b ^ 2 + 1 = k * ↑p
⊢ 0 < k
[PROOFSTEP]
refine pos_of_mul_pos_left ?_ (Nat.cast_nonneg p)
[GOAL]
case hk₀
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℤ
hk : ↑a ^ 2 + ↑b ^ 2 + 1 = k * ↑p
⊢ 0 < k * ↑p
[PROOFSTEP]
rw [← hk]
[GOAL]
case hk₀
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℤ
hk : ↑a ^ 2 + ↑b ^ 2 + 1 = k * ↑p
⊢ 0 < ↑a ^ 2 + ↑b ^ 2 + 1
[PROOFSTEP]
positivity
[GOAL]
case inr.intro.intro.intro.intro.intro
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℤ
hk : ↑a ^ 2 + ↑b ^ 2 + 1 = k * ↑p
hk₀ : 0 < k
⊢ ∃ a b k, 0 < k ∧ k < p ∧ a ^ 2 + b ^ 2 + 1 = k * p
[PROOFSTEP]
lift k to ℕ using hk₀.le
[GOAL]
case inr.intro.intro.intro.intro.intro.intro
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℕ
hk : ↑a ^ 2 + ↑b ^ 2 + 1 = ↑k * ↑p
hk₀ : 0 < ↑k
⊢ ∃ a b k, 0 < k ∧ k < p ∧ a ^ 2 + b ^ 2 + 1 = k * p
[PROOFSTEP]
refine ⟨a, b, k, Nat.cast_pos.1 hk₀, ?_, by exact_mod_cast hk⟩
[GOAL]
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℕ
hk : ↑a ^ 2 + ↑b ^ 2 + 1 = ↑k * ↑p
hk₀ : 0 < ↑k
⊢ a ^ 2 + b ^ 2 + 1 = k * p
[PROOFSTEP]
exact_mod_cast hk
[GOAL]
case inr.intro.intro.intro.intro.intro.intro
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℕ
hk : ↑a ^ 2 + ↑b ^ 2 + 1 = ↑k * ↑p
hk₀ : 0 < ↑k
⊢ k < p
[PROOFSTEP]
replace hk : a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p
[GOAL]
case hk
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℕ
hk : ↑a ^ 2 + ↑b ^ 2 + 1 = ↑k * ↑p
hk₀ : 0 < ↑k
⊢ a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p
[PROOFSTEP]
exact_mod_cast hk
[GOAL]
case inr.intro.intro.intro.intro.intro.intro
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℕ
hk₀ : 0 < ↑k
hk : a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p
⊢ k < p
[PROOFSTEP]
refine lt_of_sum_four_squares_eq_mul hk ?_ ?_ ?_ ?_
[GOAL]
case inr.intro.intro.intro.intro.intro.intro.refine_1
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℕ
hk₀ : 0 < ↑k
hk : a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p
⊢ 2 * a < p
[PROOFSTEP]
exact (mul_le_mul' le_rfl ha).trans_lt (Nat.mul_div_lt_iff_not_dvd.2 hodd.not_two_dvd_nat)
[GOAL]
case inr.intro.intro.intro.intro.intro.intro.refine_2
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℕ
hk₀ : 0 < ↑k
hk : a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p
⊢ 2 * b < p
[PROOFSTEP]
exact (mul_le_mul' le_rfl hb).trans_lt (Nat.mul_div_lt_iff_not_dvd.2 hodd.not_two_dvd_nat)
[GOAL]
case inr.intro.intro.intro.intro.intro.intro.refine_3
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℕ
hk₀ : 0 < ↑k
hk : a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p
⊢ 2 * 1 < p
[PROOFSTEP]
exact lt_of_le_of_ne hp.1.two_le (hodd.ne_two_of_dvd_nat (dvd_refl _)).symm
[GOAL]
case inr.intro.intro.intro.intro.intro.intro.refine_4
p : ℕ
hp : Fact (Nat.Prime p)
hodd : Odd p
a b : ℕ
ha : a ≤ p / 2
hb : b ≤ p / 2
hab : ↑a ^ 2 + ↑b ^ 2 ≡ -1 [ZMOD ↑p]
k : ℕ
hk₀ : 0 < ↑k
hk : a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p
⊢ 2 * 0 < p
[PROOFSTEP]
exact hp.1.pos
[GOAL]
p : ℕ
inst✝ : Fact (Nat.Prime p)
a b k : ℕ
left✝ : 0 < k
hkp : k < p
hk : a ^ 2 + b ^ 2 + 1 = k * p
⊢ ↑a ^ 2 + ↑b ^ 2 + 1 = ↑k * ↑p
[PROOFSTEP]
exact_mod_cast hk
[GOAL]
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
⊢ ∃ w x y z, w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = m
[PROOFSTEP]
have :
  ∀ f : Fin 4 → ZMod 2,
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i : Fin 4, f i ^ 2 + f (swap i 0 1) ^ 2 = 0 ∧ f (swap i 0 2) ^ 2 + f (swap i 0 3) ^ 2 = 0 :=
  by decide
[GOAL]
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
⊢ ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
[PROOFSTEP]
decide
[GOAL]
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
⊢ ∃ w x y z, w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = m
[PROOFSTEP]
set f : Fin 4 → ℤ := ![a, b, c, d]
[GOAL]
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
⊢ ∃ w x y z, w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = m
[PROOFSTEP]
obtain ⟨i, hσ⟩ :=
  this (fun x => ↑(f x)) <|
    by
    rw [← @zero_mul (ZMod 2) _ m, ← show ((2 : ℤ) : ZMod 2) = 0 from rfl, ← Int.cast_mul, ← h]
    simp only [Int.cast_add, Int.cast_pow]
    rfl
[GOAL]
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
⊢ (fun x => ↑(f x)) 0 ^ 2 + (fun x => ↑(f x)) 1 ^ 2 + (fun x => ↑(f x)) 2 ^ 2 + (fun x => ↑(f x)) 3 ^ 2 = 0
[PROOFSTEP]
rw [← @zero_mul (ZMod 2) _ m, ← show ((2 : ℤ) : ZMod 2) = 0 from rfl, ← Int.cast_mul, ← h]
[GOAL]
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
⊢ (fun x => ↑(f x)) 0 ^ 2 + (fun x => ↑(f x)) 1 ^ 2 + (fun x => ↑(f x)) 2 ^ 2 + (fun x => ↑(f x)) 3 ^ 2 =
    ↑(a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2)
[PROOFSTEP]
simp only [Int.cast_add, Int.cast_pow]
[GOAL]
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
⊢ ↑(Matrix.vecCons a ![b, c, d] 0) ^ 2 + ↑(Matrix.vecCons a ![b, c, d] 1) ^ 2 + ↑(Matrix.vecCons a ![b, c, d] 2) ^ 2 +
      ↑(Matrix.vecCons a ![b, c, d] 3) ^ 2 =
    ↑a ^ 2 + ↑b ^ 2 + ↑c ^ 2 + ↑d ^ 2
[PROOFSTEP]
rfl
[GOAL]
case intro
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
i : Fin 4
hσ : ↑(f i) ^ 2 + ↑(f (↑(swap i 0) 1)) ^ 2 = 0 ∧ ↑(f (↑(swap i 0) 2)) ^ 2 + ↑(f (↑(swap i 0) 3)) ^ 2 = 0
⊢ ∃ w x y z, w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = m
[PROOFSTEP]
set σ := swap i 0
[GOAL]
case intro
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
i : Fin 4
σ : Perm (Fin 4) := swap i 0
hσ : ↑(f i) ^ 2 + ↑(f (↑σ 1)) ^ 2 = 0 ∧ ↑(f (↑σ 2)) ^ 2 + ↑(f (↑σ 3)) ^ 2 = 0
⊢ ∃ w x y z, w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = m
[PROOFSTEP]
obtain ⟨x, hx⟩ : (2 : ℤ) ∣ f (σ 0) ^ 2 + f (σ 1) ^ 2 :=
  (CharP.int_cast_eq_zero_iff (ZMod 2) 2 _).1 <| by
    simpa only [Int.cast_pow, Int.cast_add, Equiv.swap_apply_right, ZMod.pow_card] using hσ.1
[GOAL]
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
i : Fin 4
σ : Perm (Fin 4) := swap i 0
hσ : ↑(f i) ^ 2 + ↑(f (↑σ 1)) ^ 2 = 0 ∧ ↑(f (↑σ 2)) ^ 2 + ↑(f (↑σ 3)) ^ 2 = 0
⊢ ↑(f (↑σ 0) ^ 2 + f (↑σ 1) ^ 2) = 0
[PROOFSTEP]
simpa only [Int.cast_pow, Int.cast_add, Equiv.swap_apply_right, ZMod.pow_card] using hσ.1
[GOAL]
case intro.intro
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
i : Fin 4
σ : Perm (Fin 4) := swap i 0
hσ : ↑(f i) ^ 2 + ↑(f (↑σ 1)) ^ 2 = 0 ∧ ↑(f (↑σ 2)) ^ 2 + ↑(f (↑σ 3)) ^ 2 = 0
x : ℤ
hx : f (↑σ 0) ^ 2 + f (↑σ 1) ^ 2 = 2 * x
⊢ ∃ w x y z, w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = m
[PROOFSTEP]
obtain ⟨y, hy⟩ : (2 : ℤ) ∣ f (σ 2) ^ 2 + f (σ 3) ^ 2 :=
  (CharP.int_cast_eq_zero_iff (ZMod 2) 2 _).1 <| by simpa only [Int.cast_pow, Int.cast_add, ZMod.pow_card] using hσ.2
[GOAL]
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
i : Fin 4
σ : Perm (Fin 4) := swap i 0
hσ : ↑(f i) ^ 2 + ↑(f (↑σ 1)) ^ 2 = 0 ∧ ↑(f (↑σ 2)) ^ 2 + ↑(f (↑σ 3)) ^ 2 = 0
x : ℤ
hx : f (↑σ 0) ^ 2 + f (↑σ 1) ^ 2 = 2 * x
⊢ ↑(f (↑σ 2) ^ 2 + f (↑σ 3) ^ 2) = 0
[PROOFSTEP]
simpa only [Int.cast_pow, Int.cast_add, ZMod.pow_card] using hσ.2
[GOAL]
case intro.intro.intro
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
i : Fin 4
σ : Perm (Fin 4) := swap i 0
hσ : ↑(f i) ^ 2 + ↑(f (↑σ 1)) ^ 2 = 0 ∧ ↑(f (↑σ 2)) ^ 2 + ↑(f (↑σ 3)) ^ 2 = 0
x : ℤ
hx : f (↑σ 0) ^ 2 + f (↑σ 1) ^ 2 = 2 * x
y : ℤ
hy : f (↑σ 2) ^ 2 + f (↑σ 3) ^ 2 = 2 * y
⊢ ∃ w x y z, w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = m
[PROOFSTEP]
refine ⟨(f (σ 0) - f (σ 1)) / 2, (f (σ 0) + f (σ 1)) / 2, (f (σ 2) - f (σ 3)) / 2, (f (σ 2) + f (σ 3)) / 2, ?_⟩
[GOAL]
case intro.intro.intro
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
i : Fin 4
σ : Perm (Fin 4) := swap i 0
hσ : ↑(f i) ^ 2 + ↑(f (↑σ 1)) ^ 2 = 0 ∧ ↑(f (↑σ 2)) ^ 2 + ↑(f (↑σ 3)) ^ 2 = 0
x : ℤ
hx : f (↑σ 0) ^ 2 + f (↑σ 1) ^ 2 = 2 * x
y : ℤ
hy : f (↑σ 2) ^ 2 + f (↑σ 3) ^ 2 = 2 * y
⊢ ((f (↑σ 0) - f (↑σ 1)) / 2) ^ 2 + ((f (↑σ 0) + f (↑σ 1)) / 2) ^ 2 + ((f (↑σ 2) - f (↑σ 3)) / 2) ^ 2 +
      ((f (↑σ 2) + f (↑σ 3)) / 2) ^ 2 =
    m
[PROOFSTEP]
rw [← Int.sq_add_sq_of_two_mul_sq_add_sq hx.symm, add_assoc, ← Int.sq_add_sq_of_two_mul_sq_add_sq hy.symm, ←
  mul_right_inj' two_ne_zero, ← h, mul_add]
[GOAL]
case intro.intro.intro
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
i : Fin 4
σ : Perm (Fin 4) := swap i 0
hσ : ↑(f i) ^ 2 + ↑(f (↑σ 1)) ^ 2 = 0 ∧ ↑(f (↑σ 2)) ^ 2 + ↑(f (↑σ 3)) ^ 2 = 0
x : ℤ
hx : f (↑σ 0) ^ 2 + f (↑σ 1) ^ 2 = 2 * x
y : ℤ
hy : f (↑σ 2) ^ 2 + f (↑σ 3) ^ 2 = 2 * y
⊢ 2 * x + 2 * y = a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2
[PROOFSTEP]
have : (∑ x, f (σ x) ^ 2) = ∑ x, f x ^ 2 := Equiv.sum_comp σ (f · ^ 2)
[GOAL]
case intro.intro.intro
m a b c d : ℤ
h : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m
this✝ :
  ∀ (f : Fin 4 → ZMod 2),
    f 0 ^ 2 + f 1 ^ 2 + f 2 ^ 2 + f 3 ^ 2 = 0 →
      ∃ i, f i ^ 2 + f (↑(swap i 0) 1) ^ 2 = 0 ∧ f (↑(swap i 0) 2) ^ 2 + f (↑(swap i 0) 3) ^ 2 = 0
f : Fin 4 → ℤ := ![a, b, c, d]
i : Fin 4
σ : Perm (Fin 4) := swap i 0
hσ : ↑(f i) ^ 2 + ↑(f (↑σ 1)) ^ 2 = 0 ∧ ↑(f (↑σ 2)) ^ 2 + ↑(f (↑σ 3)) ^ 2 = 0
x : ℤ
hx : f (↑σ 0) ^ 2 + f (↑σ 1) ^ 2 = 2 * x
y : ℤ
hy : f (↑σ 2) ^ 2 + f (↑σ 3) ^ 2 = 2 * y
this : ∑ x : Fin 4, f (↑σ x) ^ 2 = ∑ x : Fin 4, f x ^ 2
⊢ 2 * x + 2 * y = a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2
[PROOFSTEP]
simpa only [← hx, ← hy, Fin.sum_univ_four, add_assoc] using this
[GOAL]
p : ℕ
hp : Prime p
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p
[PROOFSTEP]
have := Fact.mk hp
[GOAL]
p : ℕ
hp : Prime p
this : Fact (Prime p)
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p
[PROOFSTEP]
have natAbs_iff {a b c d : ℤ} {k : ℕ} :
  a.natAbs ^ 2 + b.natAbs ^ 2 + c.natAbs ^ 2 + d.natAbs ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = k := by
  rw [← @Nat.cast_inj ℤ]; push_cast [sq_abs]; rfl
[GOAL]
p : ℕ
hp : Prime p
this : Fact (Prime p)
a b c d : ℤ
k : ℕ
⊢ natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
[PROOFSTEP]
rw [← @Nat.cast_inj ℤ]
[GOAL]
p : ℕ
hp : Prime p
this : Fact (Prime p)
a b c d : ℤ
k : ℕ
⊢ ↑(natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2) = ↑k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
[PROOFSTEP]
push_cast [sq_abs]
[GOAL]
p : ℕ
hp : Prime p
this : Fact (Prime p)
a b c d : ℤ
k : ℕ
⊢ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
[PROOFSTEP]
rfl
[GOAL]
p : ℕ
hp : Prime p
this : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p
[PROOFSTEP]
have hm : ∃ m < p, 0 < m ∧ ∃ a b c d : ℕ, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
[GOAL]
case hm
p : ℕ
hp : Prime p
this : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
⊢ ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
[PROOFSTEP]
obtain ⟨a, b, k, hk₀, hkp, hk⟩ := exists_sq_add_sq_add_one_eq_mul p
[GOAL]
case hm.intro.intro.intro.intro.intro
p : ℕ
hp : Prime p
this : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
a b k : ℕ
hk₀ : 0 < k
hkp : k < p
hk : a ^ 2 + b ^ 2 + 1 = k * p
⊢ ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
[PROOFSTEP]
refine ⟨k, hkp, hk₀, a, b, 1, 0, ?_⟩
[GOAL]
case hm.intro.intro.intro.intro.intro
p : ℕ
hp : Prime p
this : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
a b k : ℕ
hk₀ : 0 < k
hkp : k < p
hk : a ^ 2 + b ^ 2 + 1 = k * p
⊢ a ^ 2 + b ^ 2 + 1 ^ 2 + 0 ^ 2 = k * p
[PROOFSTEP]
simpa
  -- Take the minimal possible `m`
[GOAL]
p : ℕ
hp : Prime p
this : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p
[PROOFSTEP]
rcases Nat.findX hm with
  ⟨m, ⟨hmp, hm₀, a, b, c, d, habcd⟩, hmin⟩
    -- If `m = 1`, then we are done
[GOAL]
case mk.intro.intro.intro.intro.intro.intro.intro
p : ℕ
hp : Prime p
this : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p
[PROOFSTEP]
rcases(Nat.one_le_iff_ne_zero.2 hm₀.ne').eq_or_gt with rfl | hm₁
[GOAL]
case mk.intro.intro.intro.intro.intro.intro.intro.inl
p : ℕ
hp : Prime p
this : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
a b c d : ℕ
hmin : ∀ (m : ℕ), m < 1 → ¬(m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p)
hmp : 1 < p
hm₀ : 0 < 1
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 1 * p
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p
[PROOFSTEP]
use a, b, c, d
[GOAL]
case h
p : ℕ
hp : Prime p
this : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
a b c d : ℕ
hmin : ∀ (m : ℕ), m < 1 → ¬(m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p)
hmp : 1 < p
hm₀ : 0 < 1
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 1 * p
⊢ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p
[PROOFSTEP]
simpa using habcd
[GOAL]
case mk.intro.intro.intro.intro.intro.intro.intro.inr
p : ℕ
hp : Prime p
this : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p
[PROOFSTEP]
exfalso
[GOAL]
case mk.intro.intro.intro.intro.intro.intro.intro.inr.h
p : ℕ
hp : Prime p
this : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
⊢ False
[PROOFSTEP]
have : NeZero m := ⟨hm₀.ne'⟩
[GOAL]
case mk.intro.intro.intro.intro.intro.intro.intro.inr.h
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
⊢ False
[PROOFSTEP]
by_cases hm : 2 ∣ m
[GOAL]
case pos
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : 2 ∣ m
⊢ False
[PROOFSTEP]
rcases hm with ⟨m, rfl⟩
[GOAL]
case pos.intro
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
a b c d m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < 2 * m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : 2 * m < p
hm₀ : 0 < 2 * m
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m * p
hm₁ : 1 < 2 * m
this : NeZero (2 * m)
⊢ False
[PROOFSTEP]
rw [zero_lt_mul_left two_pos] at hm₀ 
[GOAL]
case pos.intro
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
a b c d m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < 2 * m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : 2 * m < p
hm₀ : 0 < m
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m * p
hm₁ : 1 < 2 * m
this : NeZero (2 * m)
⊢ False
[PROOFSTEP]
have hm₂ : m < 2 * m := by simpa [two_mul]
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
a b c d m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < 2 * m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : 2 * m < p
hm₀ : 0 < m
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m * p
hm₁ : 1 < 2 * m
this : NeZero (2 * m)
⊢ m < 2 * m
[PROOFSTEP]
simpa [two_mul]
[GOAL]
case pos.intro
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
a b c d m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < 2 * m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : 2 * m < p
hm₀ : 0 < m
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 2 * m * p
hm₁ : 1 < 2 * m
this : NeZero (2 * m)
hm₂ : m < 2 * m
⊢ False
[PROOFSTEP]
apply_fun (Nat.cast : ℕ → ℤ) at habcd 
[GOAL]
case pos.intro
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
a b c d m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < 2 * m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : 2 * m < p
hm₀ : 0 < m
hm₁ : 1 < 2 * m
this : NeZero (2 * m)
hm₂ : m < 2 * m
habcd : ↑(a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) = ↑(2 * m * p)
⊢ False
[PROOFSTEP]
push_cast [mul_assoc] at habcd 
[GOAL]
case pos.intro
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
a b c d m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < 2 * m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : 2 * m < p
hm₀ : 0 < m
hm₁ : 1 < 2 * m
this : NeZero (2 * m)
hm₂ : m < 2 * m
habcd : ↑a ^ 2 + ↑b ^ 2 + ↑c ^ 2 + ↑d ^ 2 = 2 * (↑m * ↑p)
⊢ False
[PROOFSTEP]
obtain ⟨_, _, _, _, h⟩ := sum_four_squares_of_two_mul_sum_four_squares habcd
[GOAL]
case pos.intro.intro.intro.intro.intro
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
a b c d m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < 2 * m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : 2 * m < p
hm₀ : 0 < m
hm₁ : 1 < 2 * m
this : NeZero (2 * m)
hm₂ : m < 2 * m
habcd : ↑a ^ 2 + ↑b ^ 2 + ↑c ^ 2 + ↑d ^ 2 = 2 * (↑m * ↑p)
w✝³ w✝² w✝¹ w✝ : ℤ
h : w✝³ ^ 2 + w✝² ^ 2 + w✝¹ ^ 2 + w✝ ^ 2 = ↑m * ↑p
⊢ False
[PROOFSTEP]
exact hmin m hm₂ ⟨hm₂.trans hmp, hm₀, _, _, _, _, natAbs_iff.2 h⟩
[GOAL]
case neg
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
⊢ False
[PROOFSTEP]
obtain ⟨f, hf_lt, hf_mod⟩ : ∃ f : ℕ → ℤ, (∀ x, 2 * (f x).natAbs < m) ∧ ∀ x, (f x : ZMod m) = x
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
⊢ ∃ f, (∀ (x : ℕ), 2 * natAbs (f x) < m) ∧ ∀ (x : ℕ), ↑(f x) = ↑x
[PROOFSTEP]
refine ⟨fun x ↦ (x : ZMod m).valMinAbs, fun x ↦ ?_, fun x ↦ (x : ZMod m).coe_valMinAbs⟩
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
x : ℕ
⊢ 2 * natAbs ((fun x => ZMod.valMinAbs ↑x) x) < m
[PROOFSTEP]
exact
  (mul_le_mul' le_rfl (x : ZMod m).natAbs_valMinAbs_le).trans_lt
    (Nat.mul_div_lt_iff_not_dvd.2 hm)
      -- Since `|f x| ^ 2 = (f x) ^ 2 ≡ x ^ 2 [ZMOD m]`, we have
          -- `m ∣ |f a| ^ 2 + |f b| ^ 2 + |f c| ^ 2 + |f d| ^ 2`
[GOAL]
case neg.intro.intro
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
⊢ False
[PROOFSTEP]
obtain ⟨r, hr⟩ : m ∣ (f a).natAbs ^ 2 + (f b).natAbs ^ 2 + (f c).natAbs ^ 2 + (f d).natAbs ^ 2
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
⊢ m ∣ natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2
[PROOFSTEP]
simp only [← Int.coe_nat_dvd, ← ZMod.int_cast_zmod_eq_zero_iff_dvd]
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
⊢ ↑↑(natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2) = 0
[PROOFSTEP]
push_cast [hf_mod, sq_abs]
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
⊢ ↑a ^ 2 + ↑b ^ 2 + ↑c ^ 2 + ↑d ^ 2 = 0
[PROOFSTEP]
norm_cast
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
⊢ ↑(a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) = 0
[PROOFSTEP]
simp [habcd]
  -- The quotient `r` is not zero, because otherwise `f a = f b = f c = f d = 0`, hence
      -- `m` divides each `a`, `b`, `c`, `d`, thus `m ∣ p` which is impossible.
[GOAL]
case neg.intro.intro.intro
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
⊢ False
[PROOFSTEP]
rcases(zero_le r).eq_or_gt with rfl | hr₀
[GOAL]
case neg.intro.intro.intro.inl
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * 0
⊢ False
[PROOFSTEP]
replace hr : f a = 0 ∧ f b = 0 ∧ f c = 0 ∧ f d = 0
[GOAL]
case hr
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * 0
⊢ f a = 0 ∧ f b = 0 ∧ f c = 0 ∧ f d = 0
[PROOFSTEP]
simpa [and_assoc] using hr
[GOAL]
case neg.intro.intro.intro.inl
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
hr : f a = 0 ∧ f b = 0 ∧ f c = 0 ∧ f d = 0
⊢ False
[PROOFSTEP]
obtain ⟨⟨a, rfl⟩, ⟨b, rfl⟩, ⟨c, rfl⟩, ⟨d, rfl⟩⟩ : m ∣ a ∧ m ∣ b ∧ m ∣ c ∧ m ∣ d
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
hr : f a = 0 ∧ f b = 0 ∧ f c = 0 ∧ f d = 0
⊢ m ∣ a ∧ m ∣ b ∧ m ∣ c ∧ m ∣ d
[PROOFSTEP]
simp only [← ZMod.nat_cast_zmod_eq_zero_iff_dvd, ← hf_mod, hr, Int.cast_zero]
[GOAL]
case neg.intro.intro.intro.inl.intro.intro.intro.intro.intro.intro.intro
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
a b c d : ℕ
habcd : (m * a) ^ 2 + (m * b) ^ 2 + (m * c) ^ 2 + (m * d) ^ 2 = m * p
hr : f (m * a) = 0 ∧ f (m * b) = 0 ∧ f (m * c) = 0 ∧ f (m * d) = 0
⊢ False
[PROOFSTEP]
have : m * m ∣ m * p := habcd ▸ ⟨a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2, by ring⟩
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
a b c d : ℕ
habcd : (m * a) ^ 2 + (m * b) ^ 2 + (m * c) ^ 2 + (m * d) ^ 2 = m * p
hr : f (m * a) = 0 ∧ f (m * b) = 0 ∧ f (m * c) = 0 ∧ f (m * d) = 0
⊢ (m * a) ^ 2 + (m * b) ^ 2 + (m * c) ^ 2 + (m * d) ^ 2 = m * m * (a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2)
[PROOFSTEP]
ring
[GOAL]
case neg.intro.intro.intro.inl.intro.intro.intro.intro.intro.intro.intro
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
a b c d : ℕ
habcd : (m * a) ^ 2 + (m * b) ^ 2 + (m * c) ^ 2 + (m * d) ^ 2 = m * p
hr : f (m * a) = 0 ∧ f (m * b) = 0 ∧ f (m * c) = 0 ∧ f (m * d) = 0
this : m * m ∣ m * p
⊢ False
[PROOFSTEP]
rw [mul_dvd_mul_iff_left hm₀.ne'] at this 
[GOAL]
case neg.intro.intro.intro.inl.intro.intro.intro.intro.intro.intro.intro
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
a b c d : ℕ
habcd : (m * a) ^ 2 + (m * b) ^ 2 + (m * c) ^ 2 + (m * d) ^ 2 = m * p
hr : f (m * a) = 0 ∧ f (m * b) = 0 ∧ f (m * c) = 0 ∧ f (m * d) = 0
this : m ∣ p
⊢ False
[PROOFSTEP]
exact (hp.eq_one_or_self_of_dvd _ this).elim hm₁.ne' hmp.ne
[GOAL]
case neg.intro.intro.intro.inr
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
⊢ False
[PROOFSTEP]
have hrm : r < m
[GOAL]
case hrm
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
⊢ r < m
[PROOFSTEP]
rw [mul_comm] at hr 
[GOAL]
case hrm
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = r * m
hr₀ : 0 < r
⊢ r < m
[PROOFSTEP]
apply lt_of_sum_four_squares_eq_mul hr
[GOAL]
case hrm.ha
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = r * m
hr₀ : 0 < r
⊢ 2 * natAbs (f a) < m
[PROOFSTEP]
apply hf_lt
[GOAL]
case hrm.hb
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = r * m
hr₀ : 0 < r
⊢ 2 * natAbs (f b) < m
[PROOFSTEP]
apply hf_lt
[GOAL]
case hrm.hc
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = r * m
hr₀ : 0 < r
⊢ 2 * natAbs (f c) < m
[PROOFSTEP]
apply hf_lt
[GOAL]
case hrm.hd
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = r * m
hr₀ : 0 < r
⊢ 2 * natAbs (f d) < m
[PROOFSTEP]
apply hf_lt
[GOAL]
case neg.intro.intro.intro.inr
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
⊢ False
[PROOFSTEP]
rsuffices ⟨w, x, y, z, hw, hx, hy, hz, h⟩ :
  ∃ w x y z : ℤ, ↑m ∣ w ∧ ↑m ∣ x ∧ ↑m ∣ y ∧ ↑m ∣ z ∧ w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
[GOAL]
case neg.intro.intro.intro.inr.intro.intro.intro.intro.intro.intro.intro.intro
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
w x y z : ℤ
hw : ↑m ∣ w
hx : ↑m ∣ x
hy : ↑m ∣ y
hz : ↑m ∣ z
h : w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
⊢ False
[PROOFSTEP]
have : (w / m) ^ 2 + (x / m) ^ 2 + (y / m) ^ 2 + (z / m) ^ 2 = ↑(r * p)
[GOAL]
case this
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
w x y z : ℤ
hw : ↑m ∣ w
hx : ↑m ∣ x
hy : ↑m ∣ y
hz : ↑m ∣ z
h : w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
⊢ (w / ↑m) ^ 2 + (x / ↑m) ^ 2 + (y / ↑m) ^ 2 + (z / ↑m) ^ 2 = ↑(r * p)
[PROOFSTEP]
refine mul_left_cancel₀ (pow_ne_zero 2 (Nat.cast_ne_zero.2 hm₀.ne')) ?_
[GOAL]
case this
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
w x y z : ℤ
hw : ↑m ∣ w
hx : ↑m ∣ x
hy : ↑m ∣ y
hz : ↑m ∣ z
h : w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
⊢ ↑m ^ 2 * ((w / ↑m) ^ 2 + (x / ↑m) ^ 2 + (y / ↑m) ^ 2 + (z / ↑m) ^ 2) = ↑m ^ 2 * ↑(r * p)
[PROOFSTEP]
conv_rhs => rw [← Nat.cast_pow, ← Nat.cast_mul, sq m, mul_mul_mul_comm, Nat.cast_mul, ← h]
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
w x y z : ℤ
hw : ↑m ∣ w
hx : ↑m ∣ x
hy : ↑m ∣ y
hz : ↑m ∣ z
h : w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
| ↑m ^ 2 * ↑(r * p)
[PROOFSTEP]
rw [← Nat.cast_pow, ← Nat.cast_mul, sq m, mul_mul_mul_comm, Nat.cast_mul, ← h]
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
w x y z : ℤ
hw : ↑m ∣ w
hx : ↑m ∣ x
hy : ↑m ∣ y
hz : ↑m ∣ z
h : w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
| ↑m ^ 2 * ↑(r * p)
[PROOFSTEP]
rw [← Nat.cast_pow, ← Nat.cast_mul, sq m, mul_mul_mul_comm, Nat.cast_mul, ← h]
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
w x y z : ℤ
hw : ↑m ∣ w
hx : ↑m ∣ x
hy : ↑m ∣ y
hz : ↑m ∣ z
h : w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
| ↑m ^ 2 * ↑(r * p)
[PROOFSTEP]
rw [← Nat.cast_pow, ← Nat.cast_mul, sq m, mul_mul_mul_comm, Nat.cast_mul, ← h]
[GOAL]
case this
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
w x y z : ℤ
hw : ↑m ∣ w
hx : ↑m ∣ x
hy : ↑m ∣ y
hz : ↑m ∣ z
h : w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
⊢ ↑m ^ 2 * ((w / ↑m) ^ 2 + (x / ↑m) ^ 2 + (y / ↑m) ^ 2 + (z / ↑m) ^ 2) = w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2
[PROOFSTEP]
simp only [mul_add, ← mul_pow, Int.mul_ediv_cancel', *]
[GOAL]
case neg.intro.intro.intro.inr.intro.intro.intro.intro.intro.intro.intro.intro
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
w x y z : ℤ
hw : ↑m ∣ w
hx : ↑m ∣ x
hy : ↑m ∣ y
hz : ↑m ∣ z
h : w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
this : (w / ↑m) ^ 2 + (x / ↑m) ^ 2 + (y / ↑m) ^ 2 + (z / ↑m) ^ 2 = ↑(r * p)
⊢ False
[PROOFSTEP]
rw [← natAbs_iff] at this 
[GOAL]
case neg.intro.intro.intro.inr.intro.intro.intro.intro.intro.intro.intro.intro
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
w x y z : ℤ
hw : ↑m ∣ w
hx : ↑m ∣ x
hy : ↑m ∣ y
hz : ↑m ∣ z
h : w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
this : natAbs (w / ↑m) ^ 2 + natAbs (x / ↑m) ^ 2 + natAbs (y / ↑m) ^ 2 + natAbs (z / ↑m) ^ 2 = r * p
⊢ False
[PROOFSTEP]
exact
  hmin r hrm
    ⟨hrm.trans hmp, hr₀, _, _, _, _, this⟩
      -- To do the last step, we apply the Euler's four square identity once more
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
⊢ ∃ w x y z, ↑m ∣ w ∧ ↑m ∣ x ∧ ↑m ∣ y ∧ ↑m ∣ z ∧ w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
[PROOFSTEP]
replace hr : (f b) ^ 2 + (f a) ^ 2 + (f d) ^ 2 + (-f c) ^ 2 = ↑(m * r)
[GOAL]
case hr
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
⊢ f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2 = ↑(m * r)
[PROOFSTEP]
rw [← natAbs_iff, natAbs_neg, ← hr]
[GOAL]
case hr
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr : natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2 = m * r
hr₀ : 0 < r
hrm : r < m
⊢ natAbs (f b) ^ 2 + natAbs (f a) ^ 2 + natAbs (f d) ^ 2 + natAbs (f c) ^ 2 =
    natAbs (f a) ^ 2 + natAbs (f b) ^ 2 + natAbs (f c) ^ 2 + natAbs (f d) ^ 2
[PROOFSTEP]
ac_rfl
[GOAL]
p : ℕ
hp : Prime p
this✝ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr₀ : 0 < r
hrm : r < m
hr : f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2 = ↑(m * r)
⊢ ∃ w x y z, ↑m ∣ w ∧ ↑m ∣ x ∧ ↑m ∣ y ∧ ↑m ∣ z ∧ w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
[PROOFSTEP]
have := congr_arg₂ (· * Nat.cast ·) hr habcd
[GOAL]
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr₀ : 0 < r
hrm : r < m
hr : f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2 = ↑(m * r)
this :
  (fun x x_1 => x * ↑x_1) (f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2) (a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) =
    (fun x x_1 => x * ↑x_1) (↑(m * r)) (m * p)
⊢ ∃ w x y z, ↑m ∣ w ∧ ↑m ∣ x ∧ ↑m ∣ y ∧ ↑m ∣ z ∧ w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
[PROOFSTEP]
simp only [← _root_.euler_four_squares, Nat.cast_add, Nat.cast_pow] at this 
[GOAL]
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr₀ : 0 < r
hrm : r < m
hr : f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2 = ↑(m * r)
this :
  (f b * ↑a - f a * ↑b - f d * ↑c - -f c * ↑d) ^ 2 + (f b * ↑b + f a * ↑a + f d * ↑d - -f c * ↑c) ^ 2 +
        (f b * ↑c - f a * ↑d + f d * ↑a + -f c * ↑b) ^ 2 +
      (f b * ↑d + f a * ↑c - f d * ↑b + -f c * ↑a) ^ 2 =
    ↑(m * r) * ↑(m * p)
⊢ ∃ w x y z, ↑m ∣ w ∧ ↑m ∣ x ∧ ↑m ∣ y ∧ ↑m ∣ z ∧ w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2 = ↑(m * r) * ↑(m * p)
[PROOFSTEP]
refine ⟨_, _, _, _, ?_, ?_, ?_, ?_, this⟩
[GOAL]
case refine_1
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr₀ : 0 < r
hrm : r < m
hr : f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2 = ↑(m * r)
this :
  (f b * ↑a - f a * ↑b - f d * ↑c - -f c * ↑d) ^ 2 + (f b * ↑b + f a * ↑a + f d * ↑d - -f c * ↑c) ^ 2 +
        (f b * ↑c - f a * ↑d + f d * ↑a + -f c * ↑b) ^ 2 +
      (f b * ↑d + f a * ↑c - f d * ↑b + -f c * ↑a) ^ 2 =
    ↑(m * r) * ↑(m * p)
⊢ ↑m ∣ f b * ↑a - f a * ↑b - f d * ↑c - -f c * ↑d
[PROOFSTEP]
simp [← ZMod.int_cast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm]
[GOAL]
case refine_2
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr₀ : 0 < r
hrm : r < m
hr : f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2 = ↑(m * r)
this :
  (f b * ↑a - f a * ↑b - f d * ↑c - -f c * ↑d) ^ 2 + (f b * ↑b + f a * ↑a + f d * ↑d - -f c * ↑c) ^ 2 +
        (f b * ↑c - f a * ↑d + f d * ↑a + -f c * ↑b) ^ 2 +
      (f b * ↑d + f a * ↑c - f d * ↑b + -f c * ↑a) ^ 2 =
    ↑(m * r) * ↑(m * p)
⊢ ↑m ∣ f b * ↑b + f a * ↑a + f d * ↑d - -f c * ↑c
[PROOFSTEP]
suffices : ((a : ZMod m) ^ 2 + (b : ZMod m) ^ 2 + (c : ZMod m) ^ 2 + (d : ZMod m) ^ 2) = 0
[GOAL]
case refine_2
p : ℕ
hp : Prime p
this✝² : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this✝¹ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr₀ : 0 < r
hrm : r < m
hr : f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2 = ↑(m * r)
this✝ :
  (f b * ↑a - f a * ↑b - f d * ↑c - -f c * ↑d) ^ 2 + (f b * ↑b + f a * ↑a + f d * ↑d - -f c * ↑c) ^ 2 +
        (f b * ↑c - f a * ↑d + f d * ↑a + -f c * ↑b) ^ 2 +
      (f b * ↑d + f a * ↑c - f d * ↑b + -f c * ↑a) ^ 2 =
    ↑(m * r) * ↑(m * p)
this : ↑a ^ 2 + ↑b ^ 2 + ↑c ^ 2 + ↑d ^ 2 = 0
⊢ ↑m ∣ f b * ↑b + f a * ↑a + f d * ↑d - -f c * ↑c
[PROOFSTEP]
simpa [← ZMod.int_cast_zmod_eq_zero_iff_dvd, hf_mod, sq, add_comm, add_assoc, add_left_comm] using this
[GOAL]
case this
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr₀ : 0 < r
hrm : r < m
hr : f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2 = ↑(m * r)
this :
  (f b * ↑a - f a * ↑b - f d * ↑c - -f c * ↑d) ^ 2 + (f b * ↑b + f a * ↑a + f d * ↑d - -f c * ↑c) ^ 2 +
        (f b * ↑c - f a * ↑d + f d * ↑a + -f c * ↑b) ^ 2 +
      (f b * ↑d + f a * ↑c - f d * ↑b + -f c * ↑a) ^ 2 =
    ↑(m * r) * ↑(m * p)
⊢ ↑a ^ 2 + ↑b ^ 2 + ↑c ^ 2 + ↑d ^ 2 = 0
[PROOFSTEP]
norm_cast
[GOAL]
case this
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr₀ : 0 < r
hrm : r < m
hr : f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2 = ↑(m * r)
this :
  (f b * ↑a - f a * ↑b - f d * ↑c - -f c * ↑d) ^ 2 + (f b * ↑b + f a * ↑a + f d * ↑d - -f c * ↑c) ^ 2 +
        (f b * ↑c - f a * ↑d + f d * ↑a + -f c * ↑b) ^ 2 +
      (f b * ↑d + f a * ↑c - f d * ↑b + -f c * ↑a) ^ 2 =
    ↑(m * r) * ↑(m * p)
⊢ ↑(a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) = 0
[PROOFSTEP]
simp [habcd]
[GOAL]
case refine_3
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr₀ : 0 < r
hrm : r < m
hr : f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2 = ↑(m * r)
this :
  (f b * ↑a - f a * ↑b - f d * ↑c - -f c * ↑d) ^ 2 + (f b * ↑b + f a * ↑a + f d * ↑d - -f c * ↑c) ^ 2 +
        (f b * ↑c - f a * ↑d + f d * ↑a + -f c * ↑b) ^ 2 +
      (f b * ↑d + f a * ↑c - f d * ↑b + -f c * ↑a) ^ 2 =
    ↑(m * r) * ↑(m * p)
⊢ ↑m ∣ f b * ↑c - f a * ↑d + f d * ↑a + -f c * ↑b
[PROOFSTEP]
simp [← ZMod.int_cast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm]
[GOAL]
case refine_4
p : ℕ
hp : Prime p
this✝¹ : Fact (Prime p)
natAbs_iff :
  ∀ {a b c d : ℤ} {k : ℕ},
    natAbs a ^ 2 + natAbs b ^ 2 + natAbs c ^ 2 + natAbs d ^ 2 = k ↔ a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = ↑k
hm✝ : ∃ m, m < p ∧ 0 < m ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
m : ℕ
hmin : ∀ (m_1 : ℕ), m_1 < m → ¬(m_1 < p ∧ 0 < m_1 ∧ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m_1 * p)
hmp : m < p
hm₀ : 0 < m
a b c d : ℕ
habcd : a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * p
hm₁ : 1 < m
this✝ : NeZero m
hm : ¬2 ∣ m
f : ℕ → ℤ
hf_lt : ∀ (x : ℕ), 2 * natAbs (f x) < m
hf_mod : ∀ (x : ℕ), ↑(f x) = ↑x
r : ℕ
hr₀ : 0 < r
hrm : r < m
hr : f b ^ 2 + f a ^ 2 + f d ^ 2 + (-f c) ^ 2 = ↑(m * r)
this :
  (f b * ↑a - f a * ↑b - f d * ↑c - -f c * ↑d) ^ 2 + (f b * ↑b + f a * ↑a + f d * ↑d - -f c * ↑c) ^ 2 +
        (f b * ↑c - f a * ↑d + f d * ↑a + -f c * ↑b) ^ 2 +
      (f b * ↑d + f a * ↑c - f d * ↑b + -f c * ↑a) ^ 2 =
    ↑(m * r) * ↑(m * p)
⊢ ↑m ∣ f b * ↑d + f a * ↑c - f d * ↑b + -f c * ↑a
[PROOFSTEP]
simp [← ZMod.int_cast_zmod_eq_zero_iff_dvd, hf_mod, mul_comm]
[GOAL]
n : ℕ
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n
[PROOFSTEP]
induction n using Nat.recOnMul with
| h0 => exact ⟨0, 0, 0, 0, rfl⟩
| h1 => exact ⟨1, 0, 0, 0, rfl⟩
| hp p hp => exact hp.sum_four_squares
| h m n hm hn =>
  rcases hm with ⟨a, b, c, d, rfl⟩
  rcases hn with ⟨w, x, y, z, rfl⟩
  exact ⟨_, _, _, _, euler_four_squares _ _ _ _ _ _ _ _⟩
[GOAL]
n : ℕ
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n
[PROOFSTEP]
induction n using Nat.recOnMul with
| h0 => exact ⟨0, 0, 0, 0, rfl⟩
| h1 => exact ⟨1, 0, 0, 0, rfl⟩
| hp p hp => exact hp.sum_four_squares
| h m n hm hn =>
  rcases hm with ⟨a, b, c, d, rfl⟩
  rcases hn with ⟨w, x, y, z, rfl⟩
  exact ⟨_, _, _, _, euler_four_squares _ _ _ _ _ _ _ _⟩
[GOAL]
case h0
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 0
[PROOFSTEP]

| h0 => exact ⟨0, 0, 0, 0, rfl⟩
[GOAL]
case h0
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 0
[PROOFSTEP]
exact ⟨0, 0, 0, 0, rfl⟩
[GOAL]
case h1
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 1
[PROOFSTEP]

| h1 => exact ⟨1, 0, 0, 0, rfl⟩
[GOAL]
case h1
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = 1
[PROOFSTEP]
exact ⟨1, 0, 0, 0, rfl⟩
[GOAL]
case hp
p : ℕ
hp : Prime p
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p
[PROOFSTEP]

| hp p hp => exact hp.sum_four_squares
[GOAL]
case hp
p : ℕ
hp : Prime p
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = p
[PROOFSTEP]
exact hp.sum_four_squares
[GOAL]
case h
m n : ℕ
hm : ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m
hn : ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * n
[PROOFSTEP]

| h m n hm hn =>
  rcases hm with ⟨a, b, c, d, rfl⟩
  rcases hn with ⟨w, x, y, z, rfl⟩
  exact ⟨_, _, _, _, euler_four_squares _ _ _ _ _ _ _ _⟩
[GOAL]
case h
m n : ℕ
hm : ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m
hn : ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n
⊢ ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = m * n
[PROOFSTEP]
rcases hm with ⟨a, b, c, d, rfl⟩
[GOAL]
case h.intro.intro.intro.intro
n : ℕ
hn : ∃ a b c d, a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2 = n
a b c d : ℕ
⊢ ∃ a_1 b_1 c_1 d_1, a_1 ^ 2 + b_1 ^ 2 + c_1 ^ 2 + d_1 ^ 2 = (a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) * n
[PROOFSTEP]
rcases hn with ⟨w, x, y, z, rfl⟩
[GOAL]
case h.intro.intro.intro.intro.intro.intro.intro.intro
a b c d w x y z : ℕ
⊢ ∃ a_1 b_1 c_1 d_1,
    a_1 ^ 2 + b_1 ^ 2 + c_1 ^ 2 + d_1 ^ 2 = (a ^ 2 + b ^ 2 + c ^ 2 + d ^ 2) * (w ^ 2 + x ^ 2 + y ^ 2 + z ^ 2)
[PROOFSTEP]
exact ⟨_, _, _, _, euler_four_squares _ _ _ _ _ _ _ _⟩
