Theorem: Polynomial.isUnitTrinomial_iff'
File: Mathlib/Algebra/Polynomial/UnitTrinomial.lean

tactic: rw [natDegree_mul_mirror, natTrailingDegree_mul_mirror, ← mul_add,
  Nat.mul_div_right _ zero_lt_two, coeff_mul_mirror]
state_before: p q : ℤ[X]
⊢ p.IsUnitTrinomial ↔ (p * p.mirror).coeff (((p * p.mirror).natDegree + (p * p.mirror).natTrailingDegree) / 2) = 3
state_after: p q : ℤ[X]
⊢ p.IsUnitTrinomial ↔ (p.sum fun n x => x ^ 2) = 3

tactic: refine ⟨?_, fun hp => ?_⟩
state_before: p q : ℤ[X]
⊢ p.IsUnitTrinomial ↔ (p.sum fun n x => x ^ 2) = 3
state_after: case refine_1
p q : ℤ[X]
⊢ p.IsUnitTrinomial → (p.sum fun n x => x ^ 2) = 3

case refine_2
p q : ℤ[X]
hp : (p.sum fun n x => x ^ 2) = 3
⊢ p.IsUnitTrinomial

tactic: rintro ⟨k, m, n, hkm, hmn, u, v, w, rfl⟩
state_before: case refine_1
p q : ℤ[X]
⊢ p.IsUnitTrinomial → (p.sum fun n x => x ^ 2) = 3
state_after: case refine_1.intro.intro.intro.intro.intro.intro.intro.intro
q : ℤ[X]
k m n : ℕ
hkm : k < m
hmn : m < n
u v w : ℤˣ
⊢ ((trinomial k m n ↑u ↑v ↑w).sum fun n x => x ^ 2) = 3

tactic: rw [sum_def, trinomial_support hkm hmn u.ne_zero v.ne_zero w.ne_zero,
  sum_insert (mt mem_insert.mp (not_or_of_not hkm.ne (mt mem_singleton.mp (hkm.trans hmn).ne))),
  sum_insert (mt mem_singleton.mp hmn.ne), sum_singleton, trinomial_leading_coeff' hkm hmn,
  trinomial_middle_coeff hkm hmn, trinomial_trailing_coeff' hkm hmn]
state_before: case refine_1.intro.intro.intro.intro.intro.intro.intro.intro
q : ℤ[X]
k m n : ℕ
hkm : k < m
hmn : m < n
u v w : ℤˣ
⊢ ((trinomial k m n ↑u ↑v ↑w).sum fun n x => x ^ 2) = 3
state_after: case refine_1.intro.intro.intro.intro.intro.intro.intro.intro
q : ℤ[X]
k m n : ℕ
hkm : k < m
hmn : m < n
u v w : ℤˣ
⊢ ↑u ^ 2 + (↑v ^ 2 + ↑w ^ 2) = 3

tactic: simp_rw [← Units.val_pow_eq_pow_val, Int.units_sq, Units.val_one]
state_before: case refine_1.intro.intro.intro.intro.intro.intro.intro.intro
q : ℤ[X]
k m n : ℕ
hkm : k < m
hmn : m < n
u v w : ℤˣ
⊢ ↑u ^ 2 + (↑v ^ 2 + ↑w ^ 2) = 3
state_after: case refine_1.intro.intro.intro.intro.intro.intro.intro.intro
q : ℤ[X]
k m n : ℕ
hkm : k < m
hmn : m < n
u v w : ℤˣ
⊢ 1 + (1 + 1) = 3

tactic: decide
state_before: case refine_1.intro.intro.intro.intro.intro.intro.intro.intro
q : ℤ[X]
k m n : ℕ
hkm : k < m
hmn : m < n
u v w : ℤˣ
⊢ 1 + (1 + 1) = 3
state_after: no goals

tactic: have key : ∀ k ∈ p.support, p.coeff k ^ 2 = 1 := fun k hk =>
  Int.sq_eq_one_of_sq_le_three
    ((single_le_sum (fun k _ => sq_nonneg (p.coeff k)) hk).trans hp.le) (mem_support_iff.mp hk)
state_before: case refine_2
p q : ℤ[X]
hp : (p.sum fun n x => x ^ 2) = 3
⊢ p.IsUnitTrinomial
state_after: case refine_2
p q : ℤ[X]
hp : (p.sum fun n x => x ^ 2) = 3
key : ∀ k ∈ p.support, p.coeff k ^ 2 = 1
⊢ p.IsUnitTrinomial

tactic: refine isUnitTrinomial_iff.mpr ⟨?_, fun k hk => isUnit_ofPowEqOne (key k hk) two_ne_zero⟩
state_before: case refine_2
p q : ℤ[X]
hp : (p.sum fun n x => x ^ 2) = 3
key : ∀ k ∈ p.support, p.coeff k ^ 2 = 1
⊢ p.IsUnitTrinomial
state_after: case refine_2
p q : ℤ[X]
hp : (p.sum fun n x => x ^ 2) = 3
key : ∀ k ∈ p.support, p.coeff k ^ 2 = 1
⊢ p.support.card = 3

tactic: rw [sum_def, sum_congr rfl key, sum_const, Nat.smul_one_eq_cast] at hp
state_before: case refine_2
p q : ℤ[X]
hp : (p.sum fun n x => x ^ 2) = 3
key : ∀ k ∈ p.support, p.coeff k ^ 2 = 1
⊢ p.support.card = 3
state_after: case refine_2
p q : ℤ[X]
hp : ↑p.support.card = 3
key : ∀ k ∈ p.support, p.coeff k ^ 2 = 1
⊢ p.support.card = 3

tactic: exact Nat.cast_injective hp
state_before: case refine_2
p q : ℤ[X]
hp : ↑p.support.card = 3
key : ∀ k ∈ p.support, p.coeff k ^ 2 = 1
⊢ p.support.card = 3
state_after: no goals