-- Mathlib/Algebra/MonoidAlgebra/Ideal.lean
theorem MonoidAlgebra.mem_ideal_span_of_image [Monoid G] [Semiring k] {s : Set G}
    {x : MonoidAlgebra k G} :
    x ∈ Ideal.span (MonoidAlgebra.of k G '' s) ↔ ∀ m ∈ x.support, ∃ m' ∈ s, ∃ d, m = d * m'

Proof state:
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
⊢ x ∈ Ideal.span (⇑(of k G) '' s) ↔ x ∈ RHS

Tactic:
constructor

Result:
case mp
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
⊢ x ∈ Ideal.span (⇑(of k G) '' s) → x ∈ RHS

case mpr
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
⊢ x ∈ RHS → x ∈ Ideal.span (⇑(of k G) '' s)

Proof state:
case mp
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
⊢ x ∈ Ideal.span (⇑(of k G) '' s) → x ∈ RHS

Tactic:
suffices Ideal.span (⇑(of k G) '' s) ≤ RHS from @this x

Result:
case mp
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
⊢ Ideal.span (⇑(of k G) '' s) ≤ RHS

Proof state:
case mp
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
⊢ Ideal.span (⇑(of k G) '' s) ≤ RHS

Tactic:
rw [Ideal.span_le]

Result:
case mp
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
⊢ ⇑(of k G) '' s ⊆ ↑RHS

Proof state:
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x✝ x y : MonoidAlgebra k G
hx : x ∈ {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}
hy : y ∈ {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}
m : G
hm : m ∈ (x + y).support
⊢ ∃ m' ∈ s, ∃ d, m = d * m'

Tactic:
exact (Finset.mem_union.1 <| Finsupp.support_add hm).elim (hx m) (hy m)

Result:
no goals

Proof state:
case intro.intro.intro
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
hx : x ∈ RHS
d : G
hd : d ∈ s
d2 : G
hi : d2 * d ∈ x.support
⊢ Finsupp.single (d2 * d) (x (d2 * d)) ∈ Ideal.span (⇑(of k G) '' s)

Tactic:
convert Ideal.mul_mem_left _ (id <| Finsupp.single d2 <| x (d2 * d) : MonoidAlgebra k G) _

Result:
case h.e'_5
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
hx : x ∈ RHS
d : G
hd : d ∈ s
d2 : G
hi : d2 * d ∈ x.support
⊢ Finsupp.single (d2 * d) (x (d2 * d)) = id (Finsupp.single d2 (x (d2 * d))) * ?intro.intro.intro.convert_2

case intro.intro.intro.convert_2
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
hx : x ∈ RHS
d : G
hd : d ∈ s
d2 : G
hi : d2 * d ∈ x.support
⊢ MonoidAlgebra k G

case intro.intro.intro.convert_3
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
hx : x ∈ RHS
d : G
hd : d ∈ s
d2 : G
hi : d2 * d ∈ x.support
⊢ ?intro.intro.intro.convert_2 ∈ Ideal.span (⇑(of k G) '' s)

Proof state:
case intro.intro.intro.intro
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x✝ x y : MonoidAlgebra k G
hy : y ∈ { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯ }.carrier
m xm ym : G
hym : ym ∈ y.support
hm : m ∈ (single (xm * ym) (x xm * y ym)).support
⊢ ∃ m' ∈ s, ∃ d, m = d * m'

Tactic:
obtain rfl := Finset.mem_singleton.mp (Finsupp.support_single_subset hm)

Result:
case intro.intro.intro.intro
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x✝ x y : MonoidAlgebra k G
hy : y ∈ { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯ }.carrier
xm ym : G
hym : ym ∈ y.support
hm : xm * ym ∈ (single (xm * ym) (x xm * y ym)).support
⊢ ∃ m' ∈ s, ∃ d, xm * ym = d * m'

Proof state:
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x✝ x y : MonoidAlgebra k G
hy : y ∈ { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯ }.carrier
m : G
hm : m ∈ (x • y).support
⊢ ∃ m' ∈ s, ∃ d, m = d * m'

Tactic:
rw [smul_eq_mul, mul_def] at hm

Result:
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x✝ x y : MonoidAlgebra k G
hy : y ∈ { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯ }.carrier
m : G
hm : m ∈ (Finsupp.sum x fun a₁ b₁ => Finsupp.sum y fun a₂ b₂ => single (a₁ * a₂) (b₁ * b₂)).support
⊢ ∃ m' ∈ s, ∃ d, m = d * m'

Proof state:
case mpr
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
⊢ x ∈ RHS → x ∈ Ideal.span (⇑(of k G) '' s)

Tactic:
intro hx

Result:
case mpr
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
hx : x ∈ RHS
⊢ x ∈ Ideal.span (⇑(of k G) '' s)

Proof state:
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
⊢ x ∈ Ideal.span (⇑(of k G) '' s) ↔ ∀ m ∈ x.support, ∃ m' ∈ s, ∃ d, m = d * m'

Tactic:
let RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := { p | ∀ m : G, m ∈ p.support → ∃ m' ∈ s, ∃ d, m = d * m' }
    add_mem' := fun {x y} hx hy m hm => by
      classical exact (Finset.mem_union.1 <| Finsupp.support_add hm).elim (hx m) (hy m)
    zero_mem' := fun m hm => by cases hm
    smul_mem' := fun x y hy m hm => by
      classical
      rw [smul_eq_mul, mul_def] at hm
      replace hm := Finset.mem_biUnion.mp (Finsupp.support_sum hm)
      obtain ⟨xm, -, hm⟩ := hm
      replace hm := Finset.mem_biUnion.mp (Finsupp.support_sum hm)
      obtain ⟨ym, hym, hm⟩ := hm
      obtain rfl := Finset.mem_singleton.mp (Finsupp.support_single_subset hm)
      refine (hy _ hym).imp fun sm p => And.imp_right ?_ p
      rintro ⟨d, rfl⟩
      exact ⟨xm * d, (mul_assoc _ _ _).symm⟩ }

Result:
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
RHS : Ideal (MonoidAlgebra k G) :=
  { carrier := {p | ∀ m ∈ p.support, ∃ m' ∈ s, ∃ d, m = d * m'}, add_mem' := ⋯, zero_mem' := ⋯, smul_mem' := ⋯ }
⊢ x ∈ Ideal.span (⇑(of k G) '' s) ↔ ∀ m ∈ x.support, ∃ m' ∈ s, ∃ d, m = d * m'