-- Mathlib/RingTheory/Unramified/Finite.lean
lemma finite_of_free_aux (I) [DecidableEq I] (b : Basis I R S)
    (f : I →₀ S) (x : S) (a : I → I →₀ R) (ha : a = fun i ↦ b.repr (b i * x)) :
    (1 ⊗ₜ[R] x * Finsupp.sum f fun i y ↦ y ⊗ₜ[R] b i) =
      Finset.sum (f.support.biUnion fun i ↦ (a i).support) fun k ↦
    Finsupp.sum (b.repr (f.sum fun i y ↦ a i k • y)) fun j c ↦ c • b j ⊗ₜ[R] b k

Proof state:
case h_add
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
i : I
⊢ ∀ (a : I) (b₁ b₂ : R), (b₁ + b₂) • b a ⊗ₜ[R] b i = b₁ • b a ⊗ₜ[R] b i + b₂ • b a ⊗ₜ[R] b i

Tactic:
intros

Result:
case h_add
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
i a✝ : I
b₁✝ b₂✝ : R
⊢ (b₁✝ + b₂✝) • b a✝ ⊗ₜ[R] b i = b₁✝ • b a✝ ⊗ₜ[R] b i + b₂✝ • b a✝ ⊗ₜ[R] b i

Proof state:
case hg
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
h₁ :
  ∀ (k : I),
    ((f.sum fun i y => (b.repr (b i * x)) k • b.repr y).sum fun j z => z • b j ⊗ₜ[R] b k) =
      f.sum fun i y => (b.repr y).sum fun j z => (b.repr (b i * x)) k • z • b j ⊗ₜ[R] b k
h₂ : ∀ (x : S), ∑ a ∈ (b.repr x).support, (b.repr x) a • b a = x
i : I
hi : i ∈ f.support
⊢ ∀ (x_1 x_2 : I),
    ¬f x_2 = 0 →
      ¬(b.repr (b x_2 * x)) x_1 = 0 → (b.repr (b i * x)) x_1 = 0 → ((b.repr (b i * x)) x_1 • f i) ⊗ₜ[R] b x_1 = 0

Tactic:
simp (config := {contextual := true})

Result:
no goals

Proof state:
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
⊢ ∑ i ∈ f.support, 1 ⊗ₜ[R] x * f i ⊗ₜ[R] b i =
    ∑ k ∈ f.support.biUnion fun i => ((fun i => b.repr (b i * x)) i).support,
      (b.repr (f.sum fun i y => ((fun i => b.repr (b i * x)) i) k • y)).sum fun j c => c • b j ⊗ₜ[R] b k

Tactic:
conv_lhs =>
  simp only [TensorProduct.tmul_mul_tmul, one_mul, mul_comm x (b _),
    ← show ∀ i, Finsupp.linearCombination _ b (a i) = b i * x from
        fun _ ↦ b.linearCombination_repr _]

Result:
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
⊢ ∑ i ∈ f.support, f i ⊗ₜ[R] (Finsupp.linearCombination R ⇑b) (a i) =
    ∑ k ∈ f.support.biUnion fun i => ((fun i => b.repr (b i * x)) i).support,
      (b.repr (f.sum fun i y => ((fun i => b.repr (b i * x)) i) k • y)).sum fun j c => c • b j ⊗ₜ[R] b k

Proof state:
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
h₁ :
  ∀ (k : I),
    ((f.sum fun i y => (b.repr (b i * x)) k • b.repr y).sum fun j z => z • b j ⊗ₜ[R] b k) =
      f.sum fun i y => (b.repr y).sum fun j z => (b.repr (b i * x)) k • z • b j ⊗ₜ[R] b k
h₂ : ∀ (x : S), ∑ a ∈ (b.repr x).support, (b.repr x) a • b a = x
⊢ ∑ x ∈ f.support, ∑ x_1 ∈ (a x).support, ((a x) x_1 • f x) ⊗ₜ[R] b x_1 =
    ∑ k ∈ f.support.biUnion fun i => ((fun i => b.repr (b i * x)) i).support,
      (b.repr (f.sum fun i y => ((fun i => b.repr (b i * x)) i) k • y)).sum fun j c => c • b j ⊗ₜ[R] b k

Tactic:
simp_rw [map_finsupp_sum, map_smul, h₁, Finsupp.sum, Finset.sum_comm (t := f.support),
  TensorProduct.smul_tmul', ← TensorProduct.sum_tmul, ← Finset.smul_sum, h₂]

Result:
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
h₁ :
  ∀ (k : I),
    ((f.sum fun i y => (b.repr (b i * x)) k • b.repr y).sum fun j z => z • b j ⊗ₜ[R] b k) =
      f.sum fun i y => (b.repr y).sum fun j z => (b.repr (b i * x)) k • z • b j ⊗ₜ[R] b k
h₂ : ∀ (x : S), ∑ a ∈ (b.repr x).support, (b.repr x) a • b a = x
⊢ ∑ x ∈ f.support, ∑ x_1 ∈ (a x).support, ((a x) x_1 • f x) ⊗ₜ[R] b x_1 =
    ∑ x_1 ∈ f.support,
      ∑ x_2 ∈ f.support.biUnion fun i => (b.repr (b i * x)).support, ((b.repr (b x_1 * x)) x_2 • f x_1) ⊗ₜ[R] b x_2

Proof state:
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
h₁ :
  ∀ (k : I),
    ((f.sum fun i y => (a i) k • b.repr y).sum fun j z => z • b j ⊗ₜ[R] b k) =
      f.sum fun i y => (b.repr y).sum fun j z => (a i) k • z • b j ⊗ₜ[R] b k
⊢ ∀ (x : S), ∑ a ∈ (b.repr x).support, (b.repr x) a • b a = x

Tactic:
simpa only [Finsupp.linearCombination_apply, Finsupp.sum] using b.linearCombination_repr

Result:
no goals

Proof state:
case e_g
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
i : I
⊢ (fun a_1 b_1 => ((a a_1) i • b.repr b_1).sum fun j z => z • b j ⊗ₜ[R] b i) = fun i_1 y =>
    (b.repr y).sum fun j z => (a i_1) i • z • b j ⊗ₜ[R] b i

case h_zero
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
i : I
⊢ ∀ (a : I), 0 • b a ⊗ₜ[R] b i = 0

case h_add
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
i : I
⊢ ∀ (a : I) (b₁ b₂ : R), (b₁ + b₂) • b a ⊗ₜ[R] b i = b₁ • b a ⊗ₜ[R] b i + b₂ • b a ⊗ₜ[R] b i

Tactic:
ext j s

Result:
case e_g.h.h
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
i j : I
s : S
⊢ (((a j) i • b.repr s).sum fun j z => z • b j ⊗ₜ[R] b i) = (b.repr s).sum fun j_1 z => (a j) i • z • b j_1 ⊗ₜ[R] b i

case h_zero
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
i : I
⊢ ∀ (a : I), 0 • b a ⊗ₜ[R] b i = 0

case h_add
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
i : I
⊢ ∀ (a : I) (b₁ b₂ : R), (b₁ + b₂) • b a ⊗ₜ[R] b i = b₁ • b a ⊗ₜ[R] b i + b₂ • b a ⊗ₜ[R] b i

Proof state:
case e_g.h.h
R : Type u_3
S : Type u_4
inst✝³ : CommRing R
inst✝² : CommRing S
inst✝¹ : Algebra R S
I : Type u_2
inst✝ : DecidableEq I
b : Basis I R S
f : I →₀ S
x : S
a : I → I →₀ R := fun i => b.repr (b i * x)
i j : I
s : S
i✝ : I
⊢ 0 • b i✝ ⊗ₜ[R] b i = 0

Tactic:
simp only [zero_smul]

Result:
no goals