-- Mathlib/RingTheory/FreeCommRing.lean
theorem isSupported_of {p} {s : Set α} : IsSupported (of p) s ↔ p ∈ s :=
  suffices IsSupported (of p) s → p ∈ s from ⟨this, fun hps => Subring.subset_closure ⟨p, hps, rfl⟩⟩
  fun hps : IsSupported (of p) s => by
  classical
  haveI := Classical.decPred s
  have : ∀ x, IsSupported x s →
        ∃ n : ℤ, lift (fun a => if a ∈ s then (0 : ℤ[X]) else Polynomial.X) x = n

Proof state:
case h
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x : FreeCommRing α
hx : x.IsSupported s
⊢ 1 = ↑1

Tactic:
norm_cast

Result:
no goals

Proof state:
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
h : p ∉ s
w : ℤ
H : X = C ↑w
⊢ X.coeff 1 = (C w).coeff 1

Tactic:
rw [H]

Result:
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
h : p ∉ s
w : ℤ
H : X = C ↑w
⊢ (C ↑w).coeff 1 = (C w).coeff 1

Proof state:
case refine_2
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x : FreeCommRing α
hx : x.IsSupported s
⊢ ∃ n, (lift fun a => if a ∈ s then 0 else X) (-1) = ↑n

Tactic:
use -1

Result:
case h
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x : FreeCommRing α
hx : x.IsSupported s
⊢ (lift fun a => if a ∈ s then 0 else X) (-1) = ↑(-1)

Proof state:
case refine_4
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x : FreeCommRing α
hx : x.IsSupported s
⊢ ∀ {x y : FreeCommRing α},
    (∃ n, (lift fun a => if a ∈ s then 0 else X) x = ↑n) →
      (∃ n, (lift fun a => if a ∈ s then 0 else X) y = ↑n) → ∃ n, (lift fun a => if a ∈ s then 0 else X) (x + y) = ↑n

Tactic:
rintro x y ⟨q, hq⟩ ⟨r, hr⟩

Result:
case refine_4.intro.intro
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x✝ : FreeCommRing α
hx : x✝.IsSupported s
x y : FreeCommRing α
q : ℤ
hq : (lift fun a => if a ∈ s then 0 else X) x = ↑q
r : ℤ
hr : (lift fun a => if a ∈ s then 0 else X) y = ↑r
⊢ ∃ n, (lift fun a => if a ∈ s then 0 else X) (x + y) = ↑n

Proof state:
case refine_1
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x : FreeCommRing α
hx : x.IsSupported s
⊢ ∃ n, (lift fun a => if a ∈ s then 0 else X) 1 = ↑n

Tactic:
use 1

Result:
case h
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x : FreeCommRing α
hx : x.IsSupported s
⊢ (lift fun a => if a ∈ s then 0 else X) 1 = ↑1

Proof state:
case pos
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
h : p ∈ s
this : ∃ n, 0 = ↑n
⊢ p ∈ s

Tactic:
exact h

Result:
no goals

Proof state:
case refine_3.intro.intro
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x : FreeCommRing α
hx : x.IsSupported s
z : α
hzs : z ∈ s
n✝ : FreeCommRing α
a✝ : ∃ n, (lift fun a => if a ∈ s then 0 else X) n✝ = ↑n
⊢ ∃ n, (lift fun a => if a ∈ s then 0 else X) (of z * n✝) = ↑n

Tactic:
use 0

Result:
case h
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x : FreeCommRing α
hx : x.IsSupported s
z : α
hzs : z ∈ s
n✝ : FreeCommRing α
a✝ : ∃ n, (lift fun a => if a ∈ s then 0 else X) n✝ = ↑n
⊢ (lift fun a => if a ∈ s then 0 else X) (of z * n✝) = ↑0

Proof state:
case neg.intro
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
h : p ∉ s
w : ℤ
H : X = C ↑w
this : X.coeff 1 = (C w).coeff 1
⊢ 1 = 0

Tactic:
rwa [Polynomial.coeff_C, if_neg (one_ne_zero : 1 ≠ 0), Polynomial.coeff_X, if_pos rfl] at this

Result:
no goals

Proof state:
case neg
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
h : p ∉ s
this : ∃ n, X = ↑n
⊢ p ∈ s

Tactic:
exfalso

Result:
case neg
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
h : p ∉ s
this : ∃ n, X = ↑n
⊢ False

Proof state:
case neg
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
h : p ∉ s
this : ∃ n, X = ↑n
⊢ False

Tactic:
apply Ne.symm Int.zero_ne_one

Result:
case neg
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
h : p ∉ s
this : ∃ n, X = ↑n
⊢ 1 = 0

Proof state:
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
this : ∃ n, (lift fun a => if a ∈ s then 0 else X) (of p) = ↑n
⊢ p ∈ s

Tactic:
rw [lift_of] at this

Result:
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
this : ∃ n, (if p ∈ s then 0 else X) = ↑n
⊢ p ∈ s

Proof state:
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
this : ∀ (x : FreeCommRing α), x.IsSupported s → ∃ n, (lift fun a => if a ∈ s then 0 else X) x = ↑n
⊢ p ∈ s

Tactic:
specialize this (of p) hps

Result:
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
this : ∃ n, (lift fun a => if a ∈ s then 0 else X) (of p) = ↑n
⊢ p ∈ s

Proof state:
case refine_4.intro.intro
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x✝ : FreeCommRing α
hx : x✝.IsSupported s
x y : FreeCommRing α
q : ℤ
hq : (lift fun a => if a ∈ s then 0 else X) x = ↑q
r : ℤ
hr : (lift fun a => if a ∈ s then 0 else X) y = ↑r
⊢ ∃ n, (lift fun a => if a ∈ s then 0 else X) (x + y) = ↑n

Tactic:
refine ⟨q + r, ?_⟩

Result:
case refine_4.intro.intro
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x✝ : FreeCommRing α
hx : x✝.IsSupported s
x y : FreeCommRing α
q : ℤ
hq : (lift fun a => if a ∈ s then 0 else X) x = ↑q
r : ℤ
hr : (lift fun a => if a ∈ s then 0 else X) y = ↑r
⊢ (lift fun a => if a ∈ s then 0 else X) (x + y) = ↑(q + r)

Proof state:
case refine_4.intro.intro
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x✝ : FreeCommRing α
hx : x✝.IsSupported s
x y : FreeCommRing α
q : ℤ
hq : (lift fun a => if a ∈ s then 0 else X) x = ↑q
r : ℤ
hr : (lift fun a => if a ∈ s then 0 else X) y = ↑r
⊢ (lift fun a => if a ∈ s then 0 else X) (x + y) = ↑(q + r)

Tactic:
rw [RingHom.map_add, hq, hr]

Result:
case refine_4.intro.intro
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x✝ : FreeCommRing α
hx : x✝.IsSupported s
x y : FreeCommRing α
q : ℤ
hq : (lift fun a => if a ∈ s then 0 else X) x = ↑q
r : ℤ
hr : (lift fun a => if a ∈ s then 0 else X) y = ↑r
⊢ ↑q + ↑r = ↑(q + r)

Proof state:
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
⊢ p ∈ s

Tactic:
haveI := Classical.decPred s

Result:
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
⊢ p ∈ s

Proof state:
case h
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x : FreeCommRing α
hx : x.IsSupported s
z : α
hzs : z ∈ s
n✝ : FreeCommRing α
a✝ : ∃ n, (lift fun a => if a ∈ s then 0 else X) n✝ = ↑n
⊢ 0 = ↑0

Tactic:
norm_cast

Result:
no goals

Proof state:
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
⊢ ∀ (x : FreeCommRing α), x.IsSupported s → ∃ n, (lift fun a => if a ∈ s then 0 else X) x = ↑n

Tactic:
intro x hx

Result:
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x : FreeCommRing α
hx : x.IsSupported s
⊢ ∃ n, (lift fun a => if a ∈ s then 0 else X) x = ↑n

Proof state:
case h
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this : DecidablePred s
x : FreeCommRing α
hx : x.IsSupported s
⊢ (lift fun a => if a ∈ s then 0 else X) (-1) = ↑(-1)

Tactic:
rw [RingHom.map_neg, RingHom.map_one, Int.cast_neg, Int.cast_one]

Result:
no goals

Proof state:
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
this : ∃ n, (if p ∈ s then 0 else X) = ↑n
⊢ p ∈ s

Tactic:
split_ifs at this with h

Result:
case pos
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
h : p ∈ s
this : ∃ n, 0 = ↑n
⊢ p ∈ s

case neg
α : Type u
p : α
s : Set α
hps : (of p).IsSupported s
this✝ : DecidablePred s
h : p ∉ s
this : ∃ n, X = ↑n
⊢ p ∈ s