-- 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:
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'

Tactic:
refine (hy _ hym).imp fun sm p => And.imp_right ?_ p

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
sm : G
p : sm ∈ s ∧ ∃ d, ym = d * sm
⊢ (∃ d, ym = d * sm) → ∃ d, xm * ym = d * sm

Proof state:
case mp.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' := ⋯ }
i : G
hi : i ∈ s
m : G
hm : m ∈ ((of k G) i).support
⊢ m = 1 * i

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

Result:
case mp.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' := ⋯ }
m : G
hi : m ∈ s
hm : m ∈ ((of k G) m).support
⊢ m = 1 * 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:
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:
no goals

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 : ∃ a ∈ x.support, m ∈ (Finsupp.sum y fun a₂ b₂ => single (a * a₂) (x a * b₂)).support
⊢ ∃ m' ∈ s, ∃ d, m = d * m'

Tactic:
obtain ⟨xm, -, hm⟩ := hm

Result:
case 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 : G
hm : m ∈ (Finsupp.sum y fun a₂ b₂ => single (xm * a₂) (x xm * b₂)).support
⊢ ∃ m' ∈ s, ∃ d, m = d * m'

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
xm ym : G
hym : ym ∈ y.support
hm : xm * ym ∈ (single (xm * ym) (x xm * y ym)).support
sm : G
p : sm ∈ s ∧ ∃ d, ym = d * sm
⊢ (∃ d, ym = d * sm) → ∃ d, xm * ym = d * sm

Tactic:
rintro ⟨d, rfl⟩

Result:
case intro.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 sm d : G
hym : d * sm ∈ y.support
hm : xm * (d * sm) ∈ (single (xm * (d * sm)) (x xm * y (d * sm))).support
p : sm ∈ s ∧ ∃ d_1, d * sm = d_1 * sm
⊢ ∃ d_1, xm * (d * sm) = d_1 * sm

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' := ⋯ }
hx : x ∈ RHS
⊢ Finsupp.sum x Finsupp.single ∈ Ideal.span (⇑(of k G) '' s)

Tactic:
apply Ideal.sum_mem _ fun i hi ↦ ?_

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' := ⋯ }
hx : x ∈ RHS
i : G
hi : i ∈ x.support
⊢ Finsupp.single i (x i) ∈ Ideal.span (⇑(of k G) '' s)

Proof state:
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))) * (of k G) d

Tactic:
rw [id, MonoidAlgebra.of_apply, MonoidAlgebra.single_mul_single, mul_one]

Result:
no goals

Proof state:
case 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 : G
hm : ∃ a ∈ y.support, m ∈ (single (xm * a) (x xm * y a)).support
⊢ ∃ m' ∈ s, ∃ d, m = d * m'

Tactic:
obtain ⟨ym, hym, hm⟩ := 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
m xm ym : G
hym : ym ∈ y.support
hm : m ∈ (single (xm * ym) (x xm * y ym)).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' := ⋯ }
hx : x ∈ RHS
i : G
hi : i ∈ x.support
⊢ Finsupp.single i (x i) ∈ Ideal.span (⇑(of k G) '' s)

Tactic:
obtain ⟨d, hd, d2, rfl⟩ := hx _ hi

Result:
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)

Proof state:
k : Type u_1
G : Type u_3
inst✝¹ : Monoid G
inst✝ : Semiring k
s : Set G
x : MonoidAlgebra k G
m : G
hm : m ∈ Finsupp.support 0
⊢ ∃ m' ∈ s, ∃ d, m = d * m'

Tactic:
cases hm

Result:
no goals

Proof state:
case mp.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' := ⋯ }
i : G
hi : i ∈ s
m : G
hm : m ∈ ((of k G) i).support
⊢ ∃ m' ∈ s, ∃ d, m = d * m'

Tactic:
refine ⟨_, hi, 1, ?_⟩

Result:
case mp.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' := ⋯ }
i : G
hi : i ∈ s
m : G
hm : m ∈ ((of k G) i).support
⊢ m = 1 * i