l3lab/ntp-mathlib huggingface dataset:
/-- If `S` is an `R' = M⁻¹R` algebra, and `x ∈ span R' s`,
then `t • x ∈ span R s` for some `t : M`.-/
theorem multiple_mem_span_of_mem_localization_span [Algebra R' S] [Algebra R S]
    [IsScalarTower R R' S] [IsLocalization M R'] (s : Set S) (x : S)
    (hx : x ∈ Submodule.span R' s) : ∃ t : M, t • x ∈ Submodule.span R s := by
  obtain ⟨s', hss', hs'⟩ := Submodule.mem_span_finite_of_mem_span hx
  rsuffices ⟨t, ht⟩ : ∃ t : M, t • x ∈ Submodule.span R (s' : Set S)
  · exact ⟨t, Submodule.span_mono hss' ht⟩
  clear hx hss' s
  induction s' using Finset.induction_on generalizing x
  · use 1; simpa using hs'
  rename_i a s _ hs
  simp only [Finset.coe_insert, Finset.image_insert, Finset.coe_image, Subtype.coe_mk,
    Submodule.mem_span_insert] at hs' ⊢
  rcases hs' with ⟨y, z, hz, rfl⟩
  rcases IsLocalization.surj M y with ⟨⟨y', s'⟩, e⟩
  replace e : _ * a = _ * a := (congr_arg (fun x => algebraMap R' S x * a) e : _)
  simp_rw [RingHom.map_mul, ← IsScalarTower.algebraMap_apply, mul_comm (algebraMap R' S y),
    mul_assoc, ← Algebra.smul_def] at e
  rcases hs _ hz with ⟨t, ht⟩
  refine' ⟨t * s', t * y', _, (Submodule.span R (s : Set S)).smul_mem s' ht, _⟩
  rw [smul_add, ← smul_smul, mul_comm, ← smul_smul, ← smul_smul, ← e]
  

Proof state:
case insert.intro.intro.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'
inst✝³ : Algebra R' S
inst✝² : Algebra R S
inst✝¹ : IsScalarTower R R' S
inst✝ : IsLocalization M R'
a : S
s : Finset S
a✝ : a ∉ s
hs : ∀ x ∈ Submodule.span R' ↑s, ∃ t, t • x ∈ Submodule.span R ↑s
y : R'
z : S
hz : z ∈ Submodule.span R' ↑s
y' : R
s' : ↥M
e : ↑s' • y • a = y' • a
t : ↥M
ht : t • z ∈ Submodule.span R ↑s
⊢ t • s' • y • a + s' • t • z = ↑t • ↑s' • y • a + ↑s' • t • z

Next tactic:
rfl
/-- If `S` is an `R' = M⁻¹R` algebra, and `x ∈ adjoin R' s`,
then `t • x ∈ adjoin R s` for some `t : M`.-/
theorem multiple_mem_adjoin_of_mem_localization_adjoin [Algebra R' S] [Algebra R S]
    [IsScalarTower R R' S] [IsLocalization M R'] (s : Set S) (x : S)
    (hx : x ∈ Algebra.adjoin R' s) : ∃ t : M, t • x ∈ Algebra.adjoin R s := 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'
inst✝³ : Algebra R' S
inst✝² : Algebra R S
inst✝¹ : IsScalarTower R R' S
inst✝ : IsLocalization M R'
s : Set S
x : S
hx : x ∈ Algebra.adjoin R' s
⊢ ∃ t, t • x ∈ Algebra.adjoin R s

Next tactic:
change ∃ t : M, t • x ∈ Subalgebra.toSubmodule (Algebra.adjoin R s)
/-- If `S` is an `R' = M⁻¹R` algebra, and `x ∈ adjoin R' s`,
then `t • x ∈ adjoin R s` for some `t : M`.-/
theorem multiple_mem_adjoin_of_mem_localization_adjoin [Algebra R' S] [Algebra R S]
    [IsScalarTower R R' S] [IsLocalization M R'] (s : Set S) (x : S)
    (hx : x ∈ Algebra.adjoin R' s) : ∃ t : M, t • x ∈ Algebra.adjoin R s := by
  change ∃ t : M, t • x ∈ Subalgebra.toSubmodule (Algebra.adjoin R s)
  

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'
inst✝³ : Algebra R' S
inst✝² : Algebra R S
inst✝¹ : IsScalarTower R R' S
inst✝ : IsLocalization M R'
s : Set S
x : S
hx : x ∈ Algebra.adjoin R' s
⊢ ∃ t, t • x ∈ Subalgebra.toSubmodule (Algebra.adjoin R s)

Next tactic:
change x ∈ Subalgebra.toSubmodule (Algebra.adjoin R' s) at hx
/-- If `S` is an `R' = M⁻¹R` algebra, and `x ∈ adjoin R' s`,
then `t • x ∈ adjoin R s` for some `t : M`.-/
theorem multiple_mem_adjoin_of_mem_localization_adjoin [Algebra R' S] [Algebra R S]
    [IsScalarTower R R' S] [IsLocalization M R'] (s : Set S) (x : S)
    (hx : x ∈ Algebra.adjoin R' s) : ∃ t : M, t • x ∈ Algebra.adjoin R s := by
  change ∃ t : M, t • x ∈ Subalgebra.toSubmodule (Algebra.adjoin R s)
  change x ∈ Subalgebra.toSubmodule (Algebra.adjoin R' s) at hx
  

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'
inst✝³ : Algebra R' S
inst✝² : Algebra R S
inst✝¹ : IsScalarTower R R' S
inst✝ : IsLocalization M R'
s : Set S
x : S
hx : x ∈ Subalgebra.toSubmodule (Algebra.adjoin R' s)
⊢ ∃ t, t • x ∈ Subalgebra.toSubmodule (Algebra.adjoin R s)

Next tactic:
simp_rw [Algebra.adjoin_eq_span] at hx ⊢
/-- If `S` is an `R' = M⁻¹R` algebra, and `x ∈ adjoin R' s`,
then `t • x ∈ adjoin R s` for some `t : M`.-/
theorem multiple_mem_adjoin_of_mem_localization_adjoin [Algebra R' S] [Algebra R S]
    [IsScalarTower R R' S] [IsLocalization M R'] (s : Set S) (x : S)
    (hx : x ∈ Algebra.adjoin R' s) : ∃ t : M, t • x ∈ Algebra.adjoin R s := by
  change ∃ t : M, t • x ∈ Subalgebra.toSubmodule (Algebra.adjoin R s)
  change x ∈ Subalgebra.toSubmodule (Algebra.adjoin R' s) at hx
  simp_rw [Algebra.adjoin_eq_span] at hx ⊢
  

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'
inst✝³ : Algebra R' S
inst✝² : Algebra R S
inst✝¹ : IsScalarTower R R' S
inst✝ : IsLocalization M R'
s : Set S
x : S
hx : x ∈ Submodule.span R' ↑(Submonoid.closure s)
⊢ ∃ t, t • x ∈ Submodule.span R ↑(Submonoid.closure s)

Next tactic:
exact multiple_mem_span_of_mem_localization_span M R' _ _ hx
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @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.OfLocalizationSpan @RingHom.Finite

Next tactic:
rw [RingHom.ofLocalizationSpan_iff_finite]
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  

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.OfLocalizationFiniteSpan @RingHom.Finite

Next tactic:
introv R hs H
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  

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
s : Finset R
hs : Ideal.span ↑s = ⊤
H : ∀ (r : { x // x ∈ s }), RingHom.Finite (Localization.awayMap f ↑r)
⊢ RingHom.Finite f

Next tactic:
letI := f.toAlgebra
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  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
s : Finset R
hs : Ideal.span ↑s = ⊤
H : ∀ (r : { x // x ∈ s }), RingHom.Finite (Localization.awayMap f ↑r)
this : Algebra R S := RingHom.toAlgebra f
⊢ RingHom.Finite f

Next tactic:
letI := fun r : s => (Localization.awayMap f r).toAlgebra
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  letI := f.toAlgebra
  letI := fun r : s => (Localization.awayMap f r).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
s : Finset R
hs : Ideal.span ↑s = ⊤
H : ∀ (r : { x // x ∈ s }), RingHom.Finite (Localization.awayMap f ↑r)
this✝ : Algebra R S := RingHom.toAlgebra f
this : (r : { x // x ∈ s }) → Algebra (Localization.Away ↑r) (Localization.Away (f ↑r)) :=
  fun r => RingHom.toAlgebra (Localization.awayMap f ↑r)
⊢ RingHom.Finite f

Next tactic:
have : ∀ r : s,
      IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) :=
    by intro r; rw [Submonoid.map_powers]; exact Localization.isLocalization
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  letI := f.toAlgebra
  letI := fun r : s => (Localization.awayMap f r).toAlgebra
  have : ∀ r : s,
      IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) :=
    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'
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Finset R
hs : Ideal.span ↑s = ⊤
H : ∀ (r : { x // x ∈ s }), RingHom.Finite (Localization.awayMap f ↑r)
this✝ : Algebra R S := RingHom.toAlgebra f
this : (r : { x // x ∈ s }) → Algebra (Localization.Away ↑r) (Localization.Away (f ↑r)) :=
  fun r => RingHom.toAlgebra (Localization.awayMap f ↑r)
⊢ ∀ (r : { x // x ∈ s }),
    IsLocalization (Submonoid.map (algebraMap R S) (Submonoid.powers ↑r)) (Localization.Away (f ↑r))

Next tactic:
intro r
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  letI := f.toAlgebra
  letI := fun r : s => (Localization.awayMap f r).toAlgebra
  have : ∀ r : s,
      IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) :=
    by intro r; 

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
s : Finset R
hs : Ideal.span ↑s = ⊤
H : ∀ (r : { x // x ∈ s }), RingHom.Finite (Localization.awayMap f ↑r)
this✝ : Algebra R S := RingHom.toAlgebra f
this : (r : { x // x ∈ s }) → Algebra (Localization.Away ↑r) (Localization.Away (f ↑r)) :=
  fun r => RingHom.toAlgebra (Localization.awayMap f ↑r)
r : { x // x ∈ s }
⊢ IsLocalization (Submonoid.map (algebraMap R S) (Submonoid.powers ↑r)) (Localization.Away (f ↑r))

Next tactic:
rw [Submonoid.map_powers]
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  letI := f.toAlgebra
  letI := fun r : s => (Localization.awayMap f r).toAlgebra
  have : ∀ r : s,
      IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) :=
    by intro r; rw [Submonoid.map_powers]; 

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
s : Finset R
hs : Ideal.span ↑s = ⊤
H : ∀ (r : { x // x ∈ s }), RingHom.Finite (Localization.awayMap f ↑r)
this✝ : Algebra R S := RingHom.toAlgebra f
this : (r : { x // x ∈ s }) → Algebra (Localization.Away ↑r) (Localization.Away (f ↑r)) :=
  fun r => RingHom.toAlgebra (Localization.awayMap f ↑r)
r : { x // x ∈ s }
⊢ IsLocalization (Submonoid.powers ((algebraMap R S) ↑r)) (Localization.Away (f ↑r))

Next tactic:
exact Localization.isLocalization
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  letI := f.toAlgebra
  letI := fun r : s => (Localization.awayMap f r).toAlgebra
  have : ∀ r : s,
      IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) :=
    by intro r; rw [Submonoid.map_powers]; exact Localization.isLocalization
  

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
s : Finset R
hs : Ideal.span ↑s = ⊤
H : ∀ (r : { x // x ∈ s }), RingHom.Finite (Localization.awayMap f ↑r)
this✝¹ : Algebra R S := RingHom.toAlgebra f
this✝ : (r : { x // x ∈ s }) → Algebra (Localization.Away ↑r) (Localization.Away (f ↑r)) :=
  fun r => RingHom.toAlgebra (Localization.awayMap f ↑r)
this :
  ∀ (r : { x // x ∈ s }),
    IsLocalization (Submonoid.map (algebraMap R S) (Submonoid.powers ↑r)) (Localization.Away (f ↑r))
⊢ RingHom.Finite f

Next tactic:
haveI : ∀ r : s, IsScalarTower R (Localization.Away (r : R)) (Localization.Away (f r)) :=
    fun r => IsScalarTower.of_algebraMap_eq'
      (IsLocalization.map_comp (Submonoid.powers (r : R)).le_comap_map).symm
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  letI := f.toAlgebra
  letI := fun r : s => (Localization.awayMap f r).toAlgebra
  have : ∀ r : s,
      IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) :=
    by intro r; rw [Submonoid.map_powers]; exact Localization.isLocalization
  haveI : ∀ r : s, IsScalarTower R (Localization.Away (r : R)) (Localization.Away (f r)) :=
    fun r => IsScalarTower.of_algebraMap_eq'
      (IsLocalization.map_comp (Submonoid.powers (r : R)).le_comap_map).symm
  -- By the hypothesis, we may find a finite generating set for each `Sᵣ`. This set can then be
  -- lifted into `R` by multiplying a sufficiently large power of `r`. I claim that the union of
  -- these generates `S`.
  

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
s : Finset R
hs : Ideal.span ↑s = ⊤
H : ∀ (r : { x // x ∈ s }), RingHom.Finite (Localization.awayMap f ↑r)
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : (r : { x // x ∈ s }) → Algebra (Localization.Away ↑r) (Localization.Away (f ↑r)) :=
  fun r => RingHom.toAlgebra (Localization.awayMap f ↑r)
this✝ :
  ∀ (r : { x // x ∈ s }),
    IsLocalization (Submonoid.map (algebraMap R S) (Submonoid.powers ↑r)) (Localization.Away (f ↑r))
this : ∀ (r : { x // x ∈ s }), IsScalarTower R (Localization.Away ↑r) (Localization.Away (f ↑r))
⊢ RingHom.Finite f

Next tactic:
constructor
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  letI := f.toAlgebra
  letI := fun r : s => (Localization.awayMap f r).toAlgebra
  have : ∀ r : s,
      IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) :=
    by intro r; rw [Submonoid.map_powers]; exact Localization.isLocalization
  haveI : ∀ r : s, IsScalarTower R (Localization.Away (r : R)) (Localization.Away (f r)) :=
    fun r => IsScalarTower.of_algebraMap_eq'
      (IsLocalization.map_comp (Submonoid.powers (r : R)).le_comap_map).symm
  -- By the hypothesis, we may find a finite generating set for each `Sᵣ`. This set can then be
  -- lifted into `R` by multiplying a sufficiently large power of `r`. I claim that the union of
  -- these generates `S`.
  constructor
  

Proof state:
case out
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 : Finset R
hs : Ideal.span ↑s = ⊤
H : ∀ (r : { x // x ∈ s }), RingHom.Finite (Localization.awayMap f ↑r)
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : (r : { x // x ∈ s }) → Algebra (Localization.Away ↑r) (Localization.Away (f ↑r)) :=
  fun r => RingHom.toAlgebra (Localization.awayMap f ↑r)
this✝ :
  ∀ (r : { x // x ∈ s }),
    IsLocalization (Submonoid.map (algebraMap R S) (Submonoid.powers ↑r)) (Localization.Away (f ↑r))
this : ∀ (r : { x // x ∈ s }), IsScalarTower R (Localization.Away ↑r) (Localization.Away (f ↑r))
⊢ Submodule.FG ⊤

Next tactic:
replace H := fun r => (H r).1
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  letI := f.toAlgebra
  letI := fun r : s => (Localization.awayMap f r).toAlgebra
  have : ∀ r : s,
      IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) :=
    by intro r; rw [Submonoid.map_powers]; exact Localization.isLocalization
  haveI : ∀ r : s, IsScalarTower R (Localization.Away (r : R)) (Localization.Away (f r)) :=
    fun r => IsScalarTower.of_algebraMap_eq'
      (IsLocalization.map_comp (Submonoid.powers (r : R)).le_comap_map).symm
  -- By the hypothesis, we may find a finite generating set for each `Sᵣ`. This set can then be
  -- lifted into `R` by multiplying a sufficiently large power of `r`. I claim that the union of
  -- these generates `S`.
  constructor
  replace H := fun r => (H r).1
  

Proof state:
case out
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 : Finset R
hs : Ideal.span ↑s = ⊤
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : (r : { x // x ∈ s }) → Algebra (Localization.Away ↑r) (Localization.Away (f ↑r)) :=
  fun r => RingHom.toAlgebra (Localization.awayMap f ↑r)
this✝ :
  ∀ (r : { x // x ∈ s }),
    IsLocalization (Submonoid.map (algebraMap R S) (Submonoid.powers ↑r)) (Localization.Away (f ↑r))
this : ∀ (r : { x // x ∈ s }), IsScalarTower R (Localization.Away ↑r) (Localization.Away (f ↑r))
H : ∀ (r : { x // x ∈ s }), Submodule.FG ⊤
⊢ Submodule.FG ⊤

Next tactic:
choose s₁ s₂ using H
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  letI := f.toAlgebra
  letI := fun r : s => (Localization.awayMap f r).toAlgebra
  have : ∀ r : s,
      IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) :=
    by intro r; rw [Submonoid.map_powers]; exact Localization.isLocalization
  haveI : ∀ r : s, IsScalarTower R (Localization.Away (r : R)) (Localization.Away (f r)) :=
    fun r => IsScalarTower.of_algebraMap_eq'
      (IsLocalization.map_comp (Submonoid.powers (r : R)).le_comap_map).symm
  -- By the hypothesis, we may find a finite generating set for each `Sᵣ`. This set can then be
  -- lifted into `R` by multiplying a sufficiently large power of `r`. I claim that the union of
  -- these generates `S`.
  constructor
  replace H := fun r => (H r).1
  choose s₁ s₂ using H
  

Proof state:
case out
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 : Finset R
hs : Ideal.span ↑s = ⊤
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : (r : { x // x ∈ s }) → Algebra (Localization.Away ↑r) (Localization.Away (f ↑r)) :=
  fun r => RingHom.toAlgebra (Localization.awayMap f ↑r)
this✝ :
  ∀ (r : { x // x ∈ s }),
    IsLocalization (Submonoid.map (algebraMap R S) (Submonoid.powers ↑r)) (Localization.Away (f ↑r))
this : ∀ (r : { x // x ∈ s }), IsScalarTower R (Localization.Away ↑r) (Localization.Away (f ↑r))
s₁ : (r : { x // x ∈ s }) → Finset (Localization.Away (f ↑r))
s₂ : ∀ (r : { x // x ∈ s }), Submodule.span (Localization.Away ↑r) ↑(s₁ r) = ⊤
⊢ Submodule.FG ⊤

Next tactic:
let sf := fun x : s => IsLocalization.finsetIntegerMultiple (Submonoid.powers (f x)) (s₁ x)
theorem finite_ofLocalizationSpan : RingHom.OfLocalizationSpan @RingHom.Finite := by
  rw [RingHom.ofLocalizationSpan_iff_finite]
  introv R hs H
  -- We first setup the instances
  letI := f.toAlgebra
  letI := fun r : s => (Localization.awayMap f r).toAlgebra
  have : ∀ r : s,
      IsLocalization ((Submonoid.powers (r : R)).map (algebraMap R S)) (Localization.Away (f r)) :=
    by intro r; rw [Submonoid.map_powers]; exact Localization.isLocalization
  haveI : ∀ r : s, IsScalarTower R (Localization.Away (r : R)) (Localization.Away (f r)) :=
    fun r => IsScalarTower.of_algebraMap_eq'
      (IsLocalization.map_comp (Submonoid.powers (r : R)).le_comap_map).symm
  -- By the hypothesis, we may find a finite generating set for each `Sᵣ`. This set can then be
  -- lifted into `R` by multiplying a sufficiently large power of `r`. I claim that the union of
  -- these generates `S`.
  constructor
  replace H := fun r => (H r).1
  choose s₁ s₂ using H
  let sf := fun x : s => IsLocalization.finsetIntegerMultiple (Submonoid.powers (f x)) (s₁ x)
  

Proof state:
case out
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 : Finset R
hs : Ideal.span ↑s = ⊤
this✝² : Algebra R S := RingHom.toAlgebra f
this✝¹ : (r : { x // x ∈ s }) → Algebra (Localization.Away ↑r) (Localization.Away (f ↑r)) :=
  fun r => RingHom.toAlgebra (Localization.awayMap f ↑r)
this✝ :
  ∀ (r : { x // x ∈ s }),
    IsLocalization (Submonoid.map (algebraMap R S) (Submonoid.powers ↑r)) (Localization.Away (f ↑r))
this : ∀ (r : { x // x ∈ s }), IsScalarTower R (Localization.Away ↑r) (Localization.Away (f ↑r))
s₁ : (r : { x // x ∈ s }) → Finset (Localization.Away (f ↑r))
s₂ : ∀ (r : { x // x ∈ s }), Submodule.span (Localization.Away ↑r) ↑(s₁ r) = ⊤
sf : { x // x ∈ s } → Finset S := fun x => IsLocalization.finsetIntegerMultiple (Submonoid.powers (f ↑x)) (s₁ x)
⊢ Submodule.FG ⊤

Next tactic:
use s.attach.biUnion sf