-- 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:
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)
⊢ ∀ (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

Tactic:
intro i

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 : I
⊢ ((f.sum fun i_1 y => (a i_1) i • b.repr y).sum fun j z => z • b j ⊗ₜ[R] b i) =
    f.sum fun i_1 y => (b.repr y).sum fun j z => (a i_1) i • z • b j ⊗ₜ[R] b i

Proof state:
case 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)
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
⊢ (a i).support ⊆ f.support.biUnion fun i => (b.repr (b i * x)).support

Tactic:
exact Finset.subset_biUnion_of_mem (fun i ↦ (a i).support) hi

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)
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
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 only [a] at 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 =
    ∑ 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
ha : a = fun i => b.repr (b i * x)
⊢ (1 ⊗ₜ[R] x * f.sum fun i y => y ⊗ₜ[R] b i) =
    ∑ k ∈ f.support.biUnion fun i => (a i).support,
      (b.repr (f.sum fun i y => (a i) k • y)).sum fun j c => c • b j ⊗ₜ[R] b k

Tactic:
rw [Finsupp.sum, Finset.mul_sum]

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
ha : a = fun i => b.repr (b i * x)
⊢ ∑ i ∈ f.support, 1 ⊗ₜ[R] x * f i ⊗ₜ[R] b i =
    ∑ k ∈ f.support.biUnion fun i => (a i).support,
      (b.repr (f.sum fun i y => (a 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
i : I
hi : i ∈ f.support
⊢ ∑ x ∈ (a i).support, ((a i) x • f i) ⊗ₜ[R] b x =
    ∑ x_1 ∈ f.support.biUnion fun i => (b.repr (b i * x)).support, ((b.repr (b i * x)) x_1 • f i) ⊗ₜ[R] b x_1

Tactic:
apply Finset.sum_subset_zero_on_sdiff

Result:
case 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)
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
⊢ (a i).support ⊆ f.support.biUnion fun i => (b.repr (b i * x)).support

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 ∈ (f.support.biUnion fun i => (b.repr (b i * x)).support) \ (a i).support,
    ((b.repr (b i * x)) x_1 • f i) ⊗ₜ[R] b x_1 = 0

case hfg
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 ∈ (a i).support, ((a i) x_1 • f i) ⊗ₜ[R] b x_1 = ((b.repr (b i * x)) x_1 • f i) ⊗ₜ[R] b x_1

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
⊢ ∑ 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:
let a i := b.repr (b i * x)

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, 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