l3lab/ntp-mathlib huggingface dataset:
theorem select_add_select_not : ∀ x : 𝕎 R, select P x + select (fun i => ¬P i) x = x := by
  -- Porting note: TC search was insufficient to find this instance, even though all required
  -- instances exist. See zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/WittVector.20saga/near/370073526]
  have : IsPoly p fun {R} [CommRing R] x ↦ select P x + select (fun i ↦ ¬P i) x :=
    IsPoly₂.diag (hf := IsPoly₂.comp)
  ghost_calc x
  intro n
  simp only [RingHom.map_add]
  suffices
    (bind₁ (selectPoly P)) (wittPolynomial p ℤ n) +
        (bind₁ (selectPoly fun i => ¬P i)) (wittPolynomial p ℤ n) =
      wittPolynomial p ℤ n by
    apply_fun aeval x.coeff at this
    simpa only [AlgHom.map_add, aeval_bind₁, ← coeff_select]
  simp only [wittPolynomial_eq_sum_C_mul_X_pow, selectPoly, AlgHom.map_sum, AlgHom.map_pow,
    AlgHom.map_mul, bind₁_X_right, bind₁_C_right, ← Finset.sum_add_distrib, ← mul_add]
  apply Finset.sum_congr rfl
  refine' fun m _ => mul_eq_mul_left_iff.mpr (Or.inl _)
  rw [ite_pow, zero_pow (pow_pos hp.out.pos _)]
  

Proof state:
case refine_3
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
P : ℕ → Prop
this : IsPoly p fun {R} [CommRing R] x => select P x + select (fun i => ¬P i) x
R : Type u_1
R._inst : CommRing R
x : 𝕎 R
n m : ℕ
x✝ : m ∈ Finset.range (n + 1)
⊢ (if P m then X m ^ p ^ (n - m) else 0) + (if ¬P m then X m else 0) ^ p ^ (n - m) = X m ^ p ^ (n - m)

Next tactic:
by_cases Pm : P m
theorem select_add_select_not : ∀ x : 𝕎 R, select P x + select (fun i => ¬P i) x = x := by
  -- Porting note: TC search was insufficient to find this instance, even though all required
  -- instances exist. See zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/WittVector.20saga/near/370073526]
  have : IsPoly p fun {R} [CommRing R] x ↦ select P x + select (fun i ↦ ¬P i) x :=
    IsPoly₂.diag (hf := IsPoly₂.comp)
  ghost_calc x
  intro n
  simp only [RingHom.map_add]
  suffices
    (bind₁ (selectPoly P)) (wittPolynomial p ℤ n) +
        (bind₁ (selectPoly fun i => ¬P i)) (wittPolynomial p ℤ n) =
      wittPolynomial p ℤ n by
    apply_fun aeval x.coeff at this
    simpa only [AlgHom.map_add, aeval_bind₁, ← coeff_select]
  simp only [wittPolynomial_eq_sum_C_mul_X_pow, selectPoly, AlgHom.map_sum, AlgHom.map_pow,
    AlgHom.map_mul, bind₁_X_right, bind₁_C_right, ← Finset.sum_add_distrib, ← mul_add]
  apply Finset.sum_congr rfl
  refine' fun m _ => mul_eq_mul_left_iff.mpr (Or.inl _)
  rw [ite_pow, zero_pow (pow_pos hp.out.pos _)]
  by_cases Pm : P m
  · 

Proof state:
case pos
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
P : ℕ → Prop
this : IsPoly p fun {R} [CommRing R] x => select P x + select (fun i => ¬P i) x
R : Type u_1
R._inst : CommRing R
x : 𝕎 R
n m : ℕ
x✝ : m ∈ Finset.range (n + 1)
Pm : P m
⊢ (if P m then X m ^ p ^ (n - m) else 0) + (if ¬P m then X m else 0) ^ p ^ (n - m) = X m ^ p ^ (n - m)

Next tactic:
rw [if_pos Pm, if_neg _, zero_pow, add_zero]
theorem select_add_select_not : ∀ x : 𝕎 R, select P x + select (fun i => ¬P i) x = x := by
  -- Porting note: TC search was insufficient to find this instance, even though all required
  -- instances exist. See zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/WittVector.20saga/near/370073526]
  have : IsPoly p fun {R} [CommRing R] x ↦ select P x + select (fun i ↦ ¬P i) x :=
    IsPoly₂.diag (hf := IsPoly₂.comp)
  ghost_calc x
  intro n
  simp only [RingHom.map_add]
  suffices
    (bind₁ (selectPoly P)) (wittPolynomial p ℤ n) +
        (bind₁ (selectPoly fun i => ¬P i)) (wittPolynomial p ℤ n) =
      wittPolynomial p ℤ n by
    apply_fun aeval x.coeff at this
    simpa only [AlgHom.map_add, aeval_bind₁, ← coeff_select]
  simp only [wittPolynomial_eq_sum_C_mul_X_pow, selectPoly, AlgHom.map_sum, AlgHom.map_pow,
    AlgHom.map_mul, bind₁_X_right, bind₁_C_right, ← Finset.sum_add_distrib, ← mul_add]
  apply Finset.sum_congr rfl
  refine' fun m _ => mul_eq_mul_left_iff.mpr (Or.inl _)
  rw [ite_pow, zero_pow (pow_pos hp.out.pos _)]
  by_cases Pm : P m
  · rw [if_pos Pm, if_neg _, zero_pow, add_zero]
    · 

Proof state:
case pos
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
P : ℕ → Prop
this : IsPoly p fun {R} [CommRing R] x => select P x + select (fun i => ¬P i) x
R : Type u_1
R._inst : CommRing R
x : 𝕎 R
n m : ℕ
x✝ : m ∈ Finset.range (n + 1)
Pm : P m
⊢ 0 < p ^ (n - m)

Next tactic:
exact Fin.size_positive'
theorem select_add_select_not : ∀ x : 𝕎 R, select P x + select (fun i => ¬P i) x = x := by
  -- Porting note: TC search was insufficient to find this instance, even though all required
  -- instances exist. See zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/WittVector.20saga/near/370073526]
  have : IsPoly p fun {R} [CommRing R] x ↦ select P x + select (fun i ↦ ¬P i) x :=
    IsPoly₂.diag (hf := IsPoly₂.comp)
  ghost_calc x
  intro n
  simp only [RingHom.map_add]
  suffices
    (bind₁ (selectPoly P)) (wittPolynomial p ℤ n) +
        (bind₁ (selectPoly fun i => ¬P i)) (wittPolynomial p ℤ n) =
      wittPolynomial p ℤ n by
    apply_fun aeval x.coeff at this
    simpa only [AlgHom.map_add, aeval_bind₁, ← coeff_select]
  simp only [wittPolynomial_eq_sum_C_mul_X_pow, selectPoly, AlgHom.map_sum, AlgHom.map_pow,
    AlgHom.map_mul, bind₁_X_right, bind₁_C_right, ← Finset.sum_add_distrib, ← mul_add]
  apply Finset.sum_congr rfl
  refine' fun m _ => mul_eq_mul_left_iff.mpr (Or.inl _)
  rw [ite_pow, zero_pow (pow_pos hp.out.pos _)]
  by_cases Pm : P m
  · rw [if_pos Pm, if_neg _, zero_pow, add_zero]
    · exact Fin.size_positive'
    · 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
P : ℕ → Prop
this : IsPoly p fun {R} [CommRing R] x => select P x + select (fun i => ¬P i) x
R : Type u_1
R._inst : CommRing R
x : 𝕎 R
n m : ℕ
x✝ : m ∈ Finset.range (n + 1)
Pm : P m
⊢ ¬¬P m

Next tactic:
exact not_not_intro Pm
theorem select_add_select_not : ∀ x : 𝕎 R, select P x + select (fun i => ¬P i) x = x := by
  -- Porting note: TC search was insufficient to find this instance, even though all required
  -- instances exist. See zulip: [https://leanprover.zulipchat.com/#narrow/stream/287929-mathlib4/topic/WittVector.20saga/near/370073526]
  have : IsPoly p fun {R} [CommRing R] x ↦ select P x + select (fun i ↦ ¬P i) x :=
    IsPoly₂.diag (hf := IsPoly₂.comp)
  ghost_calc x
  intro n
  simp only [RingHom.map_add]
  suffices
    (bind₁ (selectPoly P)) (wittPolynomial p ℤ n) +
        (bind₁ (selectPoly fun i => ¬P i)) (wittPolynomial p ℤ n) =
      wittPolynomial p ℤ n by
    apply_fun aeval x.coeff at this
    simpa only [AlgHom.map_add, aeval_bind₁, ← coeff_select]
  simp only [wittPolynomial_eq_sum_C_mul_X_pow, selectPoly, AlgHom.map_sum, AlgHom.map_pow,
    AlgHom.map_mul, bind₁_X_right, bind₁_C_right, ← Finset.sum_add_distrib, ← mul_add]
  apply Finset.sum_congr rfl
  refine' fun m _ => mul_eq_mul_left_iff.mpr (Or.inl _)
  rw [ite_pow, zero_pow (pow_pos hp.out.pos _)]
  by_cases Pm : P m
  · rw [if_pos Pm, if_neg _, zero_pow, add_zero]
    · exact Fin.size_positive'
    · exact not_not_intro Pm
  · 

Proof state:
case neg
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
P : ℕ → Prop
this : IsPoly p fun {R} [CommRing R] x => select P x + select (fun i => ¬P i) x
R : Type u_1
R._inst : CommRing R
x : 𝕎 R
n m : ℕ
x✝ : m ∈ Finset.range (n + 1)
Pm : ¬P m
⊢ (if P m then X m ^ p ^ (n - m) else 0) + (if ¬P m then X m else 0) ^ p ^ (n - m) = X m ^ p ^ (n - m)

Next tactic:
rwa [if_neg Pm, if_pos, zero_add]
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
⊢ coeff (x + y) n = coeff x n + coeff y n

Next tactic:
let P : ℕ → Prop := fun n => y.coeff n = 0
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
⊢ coeff (x + y) n = coeff x n + coeff y n

Next tactic:
haveI : DecidablePred P := Classical.decPred P
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
⊢ coeff (x + y) n = coeff x n + coeff y n

Next tactic:
set z := mk p fun n => if P n then x.coeff n else y.coeff n
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
⊢ coeff (x + y) n = coeff x n + coeff y n

Next tactic:
have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
⊢ select P z = x

Next tactic:
ext1 n
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; 

Proof state:
case h
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
n : ℕ
⊢ coeff (select P z) n = coeff x n

Next tactic:
rw [select, coeff_mk, coeff_mk]
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    

Proof state:
case h
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
n : ℕ
⊢ (if P n then if P n then coeff x n else coeff y n else 0) = coeff x n

Next tactic:
split_ifs with hn
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · 

Proof state:
case pos
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
n : ℕ
hn : P n
⊢ coeff x n = coeff x n

Next tactic:
rfl
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · 

Proof state:
case neg
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
n : ℕ
hn : ¬P n
⊢ 0 = coeff x n

Next tactic:
rw [(h n).resolve_right hn]
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
hx : select P z = x
⊢ coeff (x + y) n = coeff x n + coeff y n

Next tactic:
have hy : select (fun i => ¬P i) z = y := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · exact hn.symm
    · rfl
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
  have hy : select (fun i => ¬P i) z = y := by
    

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
hx : select P z = x
⊢ select (fun i => ¬P i) z = y

Next tactic:
ext1 n
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
  have hy : select (fun i => ¬P i) z = y := by
    ext1 n; 

Proof state:
case h
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
hx : select P z = x
n : ℕ
⊢ coeff (select (fun i => ¬P i) z) n = coeff y n

Next tactic:
rw [select, coeff_mk, coeff_mk]
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
  have hy : select (fun i => ¬P i) z = y := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    

Proof state:
case h
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
hx : select P z = x
n : ℕ
⊢ (if ¬P n then if P n then coeff x n else coeff y n else 0) = coeff y n

Next tactic:
split_ifs with hn
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
  have hy : select (fun i => ¬P i) z = y := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · 

Proof state:
case pos
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
hx : select P z = x
n : ℕ
hn : P n
⊢ 0 = coeff y n

Next tactic:
exact hn.symm
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
  have hy : select (fun i => ¬P i) z = y := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · exact hn.symm
    · 

Proof state:
case neg
p : ℕ
hp : Fact (Nat.Prime p)
n✝ : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
hx : select P z = x
n : ℕ
hn : ¬P n
⊢ coeff y n = coeff y n

Next tactic:
rfl
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
  have hy : select (fun i => ¬P i) z = y := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · exact hn.symm
    · rfl
  

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
hx : select P z = x
hy : select (fun i => ¬P i) z = y
⊢ coeff (x + y) n = coeff x n + coeff y n

Next tactic:
calc
    (x + y).coeff n = z.coeff n := by rw [← hx, ← hy, select_add_select_not P z]
    _ = x.coeff n + y.coeff n := by
      simp only [mk._eq_1]
      split_ifs with y0
      · rw [y0, add_zero]
      · rw [h n |>.resolve_right y0, zero_add]
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
  have hy : select (fun i => ¬P i) z = y := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · exact hn.symm
    · rfl
  calc
    (x + y).coeff n = z.coeff n := by 

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
hx : select P z = x
hy : select (fun i => ¬P i) z = y
⊢ coeff (x + y) n = coeff z n

Next tactic:
rw [← hx, ← hy, select_add_select_not P z]
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
  have hy : select (fun i => ¬P i) z = y := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · exact hn.symm
    · rfl
  calc
    (x + y).coeff n = z.coeff n := by rw [← hx, ← hy, select_add_select_not P z]
    _ = x.coeff n + y.coeff n := by
      

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
hx : select P z = x
hy : select (fun i => ¬P i) z = y
⊢ coeff z n = coeff x n + coeff y n

Next tactic:
simp only [mk._eq_1]
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
  have hy : select (fun i => ¬P i) z = y := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · exact hn.symm
    · rfl
  calc
    (x + y).coeff n = z.coeff n := by rw [← hx, ← hy, select_add_select_not P z]
    _ = x.coeff n + y.coeff n := by
      simp only [mk._eq_1]
      

Proof state:
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
hx : select P z = x
hy : select (fun i => ¬P i) z = y
⊢ (if coeff y n = 0 then coeff x n else coeff y n) = coeff x n + coeff y n

Next tactic:
split_ifs with y0
theorem coeff_add_of_disjoint (x y : 𝕎 R) (h : ∀ n, x.coeff n = 0 ∨ y.coeff n = 0) :
    (x + y).coeff n = x.coeff n + y.coeff n := by
  let P : ℕ → Prop := fun n => y.coeff n = 0
  haveI : DecidablePred P := Classical.decPred P
  set z := mk p fun n => if P n then x.coeff n else y.coeff n
  have hx : select P z = x := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · rfl
    · rw [(h n).resolve_right hn]
  have hy : select (fun i => ¬P i) z = y := by
    ext1 n; rw [select, coeff_mk, coeff_mk]
    split_ifs with hn
    · exact hn.symm
    · rfl
  calc
    (x + y).coeff n = z.coeff n := by rw [← hx, ← hy, select_add_select_not P z]
    _ = x.coeff n + y.coeff n := by
      simp only [mk._eq_1]
      split_ifs with y0
      · 

Proof state:
case pos
p : ℕ
hp : Fact (Nat.Prime p)
n : ℕ
R : Type u_1
inst✝ : CommRing R
P✝ : ℕ → Prop
x y : 𝕎 R
h : ∀ (n : ℕ), coeff x n = 0 ∨ coeff y n = 0
P : ℕ → Prop := fun n => coeff y n = 0
this : DecidablePred P
z : 𝕎 R := mk p fun n => if P n then coeff x n else coeff y n
hx : select P z = x
hy : select (fun i => ¬P i) z = y
y0 : coeff y n = 0
⊢ coeff x n = coeff x n + coeff y n

Next tactic:
rw [y0, add_zero]