l3lab/ntp-mathlib huggingface dataset:
theorem surjective_ofLocalizationSpan :
    RingHom.OfLocalizationSpan fun {R S} _ _ f => Function.Surjective f := by
  introv R e H
  rw [← Set.range_iff_surjective, Set.eq_univ_iff_forall]
  letI := f.toAlgebra
  intro x
  apply Submodule.mem_of_span_eq_top_of_smul_pow_mem
    (LinearMap.range (Algebra.linearMap R S)) s e
  intro r
  obtain ⟨a, e'⟩ := H r (algebraMap _ _ x)
  obtain ⟨b, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers (r : R)) a
  erw [IsLocalization.map_mk'] at e'
  rw [eq_comm, IsLocalization.eq_mk'_iff_mul_eq, Subtype.coe_mk, Subtype.coe_mk, ← map_mul] at e'
  obtain ⟨⟨_, n', rfl⟩, e''⟩ := (IsLocalization.eq_iff_exists (Submonoid.powers (f r)) _).mp e'
  dsimp only at e''
  rw [mul_comm x, ← mul_assoc, ← map_pow, ← map_mul, ← map_mul, ← pow_add] at e''
  

Proof state:
case H.intro.intro.intro.mk.intro.intro.mk.intro
R✝ S✝ : Type u
inst✝⁷ : CommRing R✝
inst✝⁶ : CommRing S✝
M : Submonoid R✝
N : Submonoid S✝
R' S' : Type u
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
f✝ : R✝ →+* S✝
inst✝³ : Algebra R✝ R'
inst✝² : Algebra S✝ S'
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
e : Ideal.span s = ⊤
H :
  ∀ (r : ↑s),
    (fun {R S} x x_1 f => Function.Surjective ⇑f) Localization.instCommRingLocalizationToCommMonoid
      Localization.instCommRingLocalizationToCommMonoid (Localization.awayMap f ↑r)
this : Algebra R S := RingHom.toAlgebra f
x : S
r : ↑s
b : R
n : ℕ
e' :
  (algebraMap S (Localization.Away (f ↑r)))
      (x *
        ↑{ val := f ↑{ val := (fun x => ↑r ^ x) n, property := (_ : ∃ y, (fun x => ↑r ^ x) y = (fun x => ↑r ^ x) n) },
            property :=
              (_ :
                ↑{ val := (fun x => ↑r ^ x) n, property := (_ : ∃ y, (fun x => ↑r ^ x) y = (fun x => ↑r ^ x) n) } ∈
                  Submonoid.comap f (Submonoid.powers (f ↑r))) }) =
    (algebraMap S (Localization.Away (f ↑r))) (f b)
n' : ℕ
e'' : f (↑r ^ (n' + n)) * x = f (↑r ^ n' * b)
⊢ ∃ n, ↑r ^ n • x ∈ LinearMap.range (Algebra.linearMap R S)

Next tactic:
exact ⟨n' + n, _, e''.symm⟩
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  

Proof state:
R S : Type u
inst✝⁵ : CommRing R
inst✝⁴ : CommRing S
M : Submonoid R
N : Submonoid S
R' S' : Type u
inst✝³ : CommRing R'
inst✝² : CommRing S'
f : R →+* S
inst✝¹ : Algebra R R'
inst✝ : Algebra S S'
⊢ RingHom.LocalizationPreserves @RingHom.Finite

Next tactic:
introv R hf
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  

Proof state:
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
hf : RingHom.Finite f
⊢ RingHom.Finite (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M)))

Next tactic:
letI := f.toAlgebra
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  

Proof state:
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
hf : RingHom.Finite f
this : Algebra R S := RingHom.toAlgebra f
⊢ RingHom.Finite (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M)))

Next tactic:
letI := ((algebraMap S S').comp f).toAlgebra
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  letI := ((algebraMap S S').comp f).toAlgebra
  

Proof state:
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
hf : RingHom.Finite f
this✝ : Algebra R S := RingHom.toAlgebra f
this : Algebra R S' := RingHom.toAlgebra (RingHom.comp (algebraMap S S') f)
⊢ RingHom.Finite (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M)))

Next tactic:
let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M)
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  letI := ((algebraMap S S').comp f).toAlgebra
  let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M)
  

Proof state:
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
hf : RingHom.Finite f
this✝ : Algebra R S := RingHom.toAlgebra f
this : Algebra R S' := RingHom.toAlgebra (RingHom.comp (algebraMap S S') f)
f' : R' →+* S' := IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))
⊢ RingHom.Finite (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M)))

Next tactic:
letI := f'.toAlgebra
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  letI := ((algebraMap S S').comp f).toAlgebra
  let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M)
  letI := f'.toAlgebra
  

Proof state:
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
hf : RingHom.Finite f
this✝¹ : Algebra R S := RingHom.toAlgebra f
this✝ : Algebra R S' := RingHom.toAlgebra (RingHom.comp (algebraMap S S') f)
f' : R' →+* S' := IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))
this : Algebra R' S' := RingHom.toAlgebra f'
⊢ RingHom.Finite (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M)))

Next tactic:
haveI : IsScalarTower R R' S' := IsScalarTower.of_algebraMap_eq'
    (IsLocalization.map_comp M.le_comap_map).symm
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  letI := ((algebraMap S S').comp f).toAlgebra
  let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M)
  letI := f'.toAlgebra
  haveI : IsScalarTower R R' S' := IsScalarTower.of_algebraMap_eq'
    (IsLocalization.map_comp M.le_comap_map).symm
  

Proof state:
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
hf : RingHom.Finite f
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : Algebra R S' := RingHom.toAlgebra (RingHom.comp (algebraMap S S') f)
f' : R' →+* S' := IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))
this✝ : Algebra R' S' := RingHom.toAlgebra f'
this : IsScalarTower R R' S'
⊢ RingHom.Finite (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M)))

Next tactic:
let fₐ : S →ₐ[R] S' := AlgHom.mk' (algebraMap S S') fun c x => RingHom.map_mul _ _ _
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  letI := ((algebraMap S S').comp f).toAlgebra
  let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M)
  letI := f'.toAlgebra
  haveI : IsScalarTower R R' S' := IsScalarTower.of_algebraMap_eq'
    (IsLocalization.map_comp M.le_comap_map).symm
  let fₐ : S →ₐ[R] S' := AlgHom.mk' (algebraMap S S') fun c x => RingHom.map_mul _ _ _
  -- We claim that if `S` is generated by `T` as an `R`-module,
  -- then `S'` is generated by `T` as an `R'`-module.
  

Proof state:
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
hf : RingHom.Finite f
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : Algebra R S' := RingHom.toAlgebra (RingHom.comp (algebraMap S S') f)
f' : R' →+* S' := IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))
this✝ : Algebra R' S' := RingHom.toAlgebra f'
this : IsScalarTower R R' S'
fₐ : S →ₐ[R] S' :=
  AlgHom.mk' (algebraMap S S')
    (_ : ∀ (c : R) (x : S), (algebraMap S S') (f c * x) = (algebraMap S S') (f c) * (algebraMap S S') x)
⊢ RingHom.Finite (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M)))

Next tactic:
obtain ⟨T, hT⟩ := hf
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  letI := ((algebraMap S S').comp f).toAlgebra
  let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M)
  letI := f'.toAlgebra
  haveI : IsScalarTower R R' S' := IsScalarTower.of_algebraMap_eq'
    (IsLocalization.map_comp M.le_comap_map).symm
  let fₐ : S →ₐ[R] S' := AlgHom.mk' (algebraMap S S') fun c x => RingHom.map_mul _ _ _
  -- We claim that if `S` is generated by `T` as an `R`-module,
  -- then `S'` is generated by `T` as an `R'`-module.
  obtain ⟨T, hT⟩ := hf
  

Proof state:
case mk.intro
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : Algebra R S' := RingHom.toAlgebra (RingHom.comp (algebraMap S S') f)
f' : R' →+* S' := IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))
this✝ : Algebra R' S' := RingHom.toAlgebra f'
this : IsScalarTower R R' S'
fₐ : S →ₐ[R] S' :=
  AlgHom.mk' (algebraMap S S')
    (_ : ∀ (c : R) (x : S), (algebraMap S S') (f c * x) = (algebraMap S S') (f c) * (algebraMap S S') x)
T : Finset S
hT : Submodule.span R ↑T = ⊤
⊢ RingHom.Finite (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M)))

Next tactic:
use T.image (algebraMap S S')
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  letI := ((algebraMap S S').comp f).toAlgebra
  let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M)
  letI := f'.toAlgebra
  haveI : IsScalarTower R R' S' := IsScalarTower.of_algebraMap_eq'
    (IsLocalization.map_comp M.le_comap_map).symm
  let fₐ : S →ₐ[R] S' := AlgHom.mk' (algebraMap S S') fun c x => RingHom.map_mul _ _ _
  -- We claim that if `S` is generated by `T` as an `R`-module,
  -- then `S'` is generated by `T` as an `R'`-module.
  obtain ⟨T, hT⟩ := hf
  use T.image (algebraMap S S')
  

Proof state:
case h
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : Algebra R S' := RingHom.toAlgebra (RingHom.comp (algebraMap S S') f)
f' : R' →+* S' := IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))
this✝ : Algebra R' S' := RingHom.toAlgebra f'
this : IsScalarTower R R' S'
fₐ : S →ₐ[R] S' :=
  AlgHom.mk' (algebraMap S S')
    (_ : ∀ (c : R) (x : S), (algebraMap S S') (f c * x) = (algebraMap S S') (f c) * (algebraMap S S') x)
T : Finset S
hT : Submodule.span R ↑T = ⊤
⊢ Submodule.span R' ↑(Finset.image (⇑(algebraMap S S')) T) = ⊤

Next tactic:
rw [eq_top_iff]
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  letI := ((algebraMap S S').comp f).toAlgebra
  let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M)
  letI := f'.toAlgebra
  haveI : IsScalarTower R R' S' := IsScalarTower.of_algebraMap_eq'
    (IsLocalization.map_comp M.le_comap_map).symm
  let fₐ : S →ₐ[R] S' := AlgHom.mk' (algebraMap S S') fun c x => RingHom.map_mul _ _ _
  -- We claim that if `S` is generated by `T` as an `R`-module,
  -- then `S'` is generated by `T` as an `R'`-module.
  obtain ⟨T, hT⟩ := hf
  use T.image (algebraMap S S')
  rw [eq_top_iff]
  

Proof state:
case h
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : Algebra R S' := RingHom.toAlgebra (RingHom.comp (algebraMap S S') f)
f' : R' →+* S' := IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))
this✝ : Algebra R' S' := RingHom.toAlgebra f'
this : IsScalarTower R R' S'
fₐ : S →ₐ[R] S' :=
  AlgHom.mk' (algebraMap S S')
    (_ : ∀ (c : R) (x : S), (algebraMap S S') (f c * x) = (algebraMap S S') (f c) * (algebraMap S S') x)
T : Finset S
hT : Submodule.span R ↑T = ⊤
⊢ ⊤ ≤ Submodule.span R' ↑(Finset.image (⇑(algebraMap S S')) T)

Next tactic:
rintro x -
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  letI := ((algebraMap S S').comp f).toAlgebra
  let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M)
  letI := f'.toAlgebra
  haveI : IsScalarTower R R' S' := IsScalarTower.of_algebraMap_eq'
    (IsLocalization.map_comp M.le_comap_map).symm
  let fₐ : S →ₐ[R] S' := AlgHom.mk' (algebraMap S S') fun c x => RingHom.map_mul _ _ _
  -- We claim that if `S` is generated by `T` as an `R`-module,
  -- then `S'` is generated by `T` as an `R'`-module.
  obtain ⟨T, hT⟩ := hf
  use T.image (algebraMap S S')
  rw [eq_top_iff]
  rintro x -
  -- By the hypotheses, for each `x : S'`, we have `x = y / (f r)` for some `y : S` and `r : M`.
  -- Since `S` is generated by `T`, the image of `y` should fall in the span of the image of `T`.
  

Proof state:
case h
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : Algebra R S' := RingHom.toAlgebra (RingHom.comp (algebraMap S S') f)
f' : R' →+* S' := IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))
this✝ : Algebra R' S' := RingHom.toAlgebra f'
this : IsScalarTower R R' S'
fₐ : S →ₐ[R] S' :=
  AlgHom.mk' (algebraMap S S')
    (_ : ∀ (c : R) (x : S), (algebraMap S S') (f c * x) = (algebraMap S S') (f c) * (algebraMap S S') x)
T : Finset S
hT : Submodule.span R ↑T = ⊤
x : S'
⊢ x ∈ Submodule.span R' ↑(Finset.image (⇑(algebraMap S S')) T)

Next tactic:
obtain ⟨y, ⟨_, ⟨r, hr, rfl⟩⟩, rfl⟩ := IsLocalization.mk'_surjective (M.map f) x
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  letI := ((algebraMap S S').comp f).toAlgebra
  let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M)
  letI := f'.toAlgebra
  haveI : IsScalarTower R R' S' := IsScalarTower.of_algebraMap_eq'
    (IsLocalization.map_comp M.le_comap_map).symm
  let fₐ : S →ₐ[R] S' := AlgHom.mk' (algebraMap S S') fun c x => RingHom.map_mul _ _ _
  -- We claim that if `S` is generated by `T` as an `R`-module,
  -- then `S'` is generated by `T` as an `R'`-module.
  obtain ⟨T, hT⟩ := hf
  use T.image (algebraMap S S')
  rw [eq_top_iff]
  rintro x -
  -- By the hypotheses, for each `x : S'`, we have `x = y / (f r)` for some `y : S` and `r : M`.
  -- Since `S` is generated by `T`, the image of `y` should fall in the span of the image of `T`.
  obtain ⟨y, ⟨_, ⟨r, hr, rfl⟩⟩, rfl⟩ := IsLocalization.mk'_surjective (M.map f) x
  

Proof state:
case h.intro.intro.mk.intro.intro
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : Algebra R S' := RingHom.toAlgebra (RingHom.comp (algebraMap S S') f)
f' : R' →+* S' := IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))
this✝ : Algebra R' S' := RingHom.toAlgebra f'
this : IsScalarTower R R' S'
fₐ : S →ₐ[R] S' :=
  AlgHom.mk' (algebraMap S S')
    (_ : ∀ (c : R) (x : S), (algebraMap S S') (f c * x) = (algebraMap S S') (f c) * (algebraMap S S') x)
T : Finset S
hT : Submodule.span R ↑T = ⊤
y : S
r : R
hr : r ∈ ↑M
⊢ IsLocalization.mk' S' y { val := f r, property := (_ : ∃ a ∈ ↑M, f a = f r) } ∈
    Submodule.span R' ↑(Finset.image (⇑(algebraMap S S')) T)

Next tactic:
rw [IsLocalization.mk'_eq_mul_mk'_one, mul_comm, Finset.coe_image]
/-- If `S` is a finite `R`-algebra, then `S' = M⁻¹S` is a finite `R' = M⁻¹R`-algebra. -/
theorem localization_finite : RingHom.LocalizationPreserves @RingHom.Finite := by
  introv R hf
  -- Setting up the `algebra` and `is_scalar_tower` instances needed
  letI := f.toAlgebra
  letI := ((algebraMap S S').comp f).toAlgebra
  let f' : R' →+* S' := IsLocalization.map S' f (Submonoid.le_comap_map M)
  letI := f'.toAlgebra
  haveI : IsScalarTower R R' S' := IsScalarTower.of_algebraMap_eq'
    (IsLocalization.map_comp M.le_comap_map).symm
  let fₐ : S →ₐ[R] S' := AlgHom.mk' (algebraMap S S') fun c x => RingHom.map_mul _ _ _
  -- We claim that if `S` is generated by `T` as an `R`-module,
  -- then `S'` is generated by `T` as an `R'`-module.
  obtain ⟨T, hT⟩ := hf
  use T.image (algebraMap S S')
  rw [eq_top_iff]
  rintro x -
  -- By the hypotheses, for each `x : S'`, we have `x = y / (f r)` for some `y : S` and `r : M`.
  -- Since `S` is generated by `T`, the image of `y` should fall in the span of the image of `T`.
  obtain ⟨y, ⟨_, ⟨r, hr, rfl⟩⟩, rfl⟩ := IsLocalization.mk'_surjective (M.map f) x
  rw [IsLocalization.mk'_eq_mul_mk'_one, mul_comm, Finset.coe_image]
  

Proof state:
case h.intro.intro.mk.intro.intro
R✝ S✝ : Type u
inst✝¹³ : CommRing R✝
inst✝¹² : CommRing S✝
M✝ : Submonoid R✝
N : Submonoid S✝
R'✝ S'✝ : Type u
inst✝¹¹ : CommRing R'✝
inst✝¹⁰ : CommRing S'✝
f✝ : R✝ →+* S✝
inst✝⁹ : Algebra R✝ R'✝
inst✝⁸ : Algebra S✝ S'✝
R S : Type u_1
inst✝⁷ : CommRing R
inst✝⁶ : CommRing S
f : R →+* S
M : Submonoid R
R' S' : Type u_1
inst✝⁵ : CommRing R'
inst✝⁴ : CommRing S'
inst✝³ : Algebra R R'
inst✝² : Algebra S S'
inst✝¹ : IsLocalization M R'
inst✝ : IsLocalization (Submonoid.map f M) S'
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : Algebra R S' := RingHom.toAlgebra (RingHom.comp (algebraMap S S') f)
f' : R' →+* S' := IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))
this✝ : Algebra R' S' := RingHom.toAlgebra f'
this : IsScalarTower R R' S'
fₐ : S →ₐ[R] S' :=
  AlgHom.mk' (algebraMap S S')
    (_ : ∀ (c : R) (x : S), (algebraMap S S') (f c * x) = (algebraMap S S') (f c) * (algebraMap S S') x)
T : Finset S
hT : Submodule.span R ↑T = ⊤
y : S
r : R
hr : r ∈ ↑M
⊢ IsLocalization.mk' S' 1 { val := f r, property := (_ : ∃ a ∈ ↑M, f a = f r) } * (algebraMap S S') y ∈
    Submodule.span R' (⇑(algebraMap S S') '' ↑T)

Next tactic:
have hy : y ∈ Submodule.span R ↑T := by rw [hT]; trivial