l3lab/ntp-mathlib huggingface dataset:
theorem isReduced_ofLocalizationMaximal : OfLocalizationMaximal fun R hR => IsReduced R := by
  introv R h
  constructor
  intro x hx
  apply eq_zero_of_localization
  

Proof state:
case eq_zero.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 : Type u_1
inst✝ : CommRing R
h :
  ∀ (J : Ideal R) (x : Ideal.IsMaximal J),
    (fun R hR => IsReduced R) (Localization.AtPrime J) Localization.instCommRingLocalizationToCommMonoid
x : R
hx : IsNilpotent x
⊢ ∀ (J : Ideal R) (hJ : Ideal.IsMaximal J), (algebraMap R (Localization.AtPrime J)) x = 0

Next tactic:
intro J hJ
theorem isReduced_ofLocalizationMaximal : OfLocalizationMaximal fun R hR => IsReduced R := by
  introv R h
  constructor
  intro x hx
  apply eq_zero_of_localization
  intro J hJ
  

Proof state:
case eq_zero.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 : Type u_1
inst✝ : CommRing R
h :
  ∀ (J : Ideal R) (x : Ideal.IsMaximal J),
    (fun R hR => IsReduced R) (Localization.AtPrime J) Localization.instCommRingLocalizationToCommMonoid
x : R
hx : IsNilpotent x
J : Ideal R
hJ : Ideal.IsMaximal J
⊢ (algebraMap R (Localization.AtPrime J)) x = 0

Next tactic:
specialize h J hJ
theorem isReduced_ofLocalizationMaximal : OfLocalizationMaximal fun R hR => IsReduced R := by
  introv R h
  constructor
  intro x hx
  apply eq_zero_of_localization
  intro J hJ
  specialize h J hJ
  

Proof state:
case eq_zero.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 : Type u_1
inst✝ : CommRing R
x : R
hx : IsNilpotent x
J : Ideal R
hJ : Ideal.IsMaximal J
h : IsReduced (Localization.AtPrime J)
⊢ (algebraMap R (Localization.AtPrime J)) x = 0

Next tactic:
exact (hx.map <| algebraMap R <| Localization.AtPrime J).eq_zero
theorem localizationPreserves_surjective :
    RingHom.LocalizationPreserves fun {R S} _ _ f => Function.Surjective f := 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 fun {R S} x x_1 f => Function.Surjective ⇑f

Next tactic:
introv R H x
theorem localizationPreserves_surjective :
    RingHom.LocalizationPreserves fun {R S} _ _ f => Function.Surjective f := by
  introv R H x
  

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'
H : Function.Surjective ⇑f
x : S'
⊢ ∃ a, (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))) a = x

Next tactic:
obtain ⟨x, ⟨_, s, hs, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (M.map f) x
theorem localizationPreserves_surjective :
    RingHom.LocalizationPreserves fun {R S} _ _ f => Function.Surjective f := by
  introv R H x
  obtain ⟨x, ⟨_, s, hs, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (M.map f) x
  

Proof state:
case 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'
H : Function.Surjective ⇑f
x : S
s : R
hs : s ∈ ↑M
⊢ ∃ a,
    (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))) a =
      IsLocalization.mk' S' x { val := f s, property := (_ : ∃ a ∈ ↑M, f a = f s) }

Next tactic:
obtain ⟨y, rfl⟩ := H x
theorem localizationPreserves_surjective :
    RingHom.LocalizationPreserves fun {R S} _ _ f => Function.Surjective f := by
  introv R H x
  obtain ⟨x, ⟨_, s, hs, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (M.map f) x
  obtain ⟨y, rfl⟩ := H x
  

Proof state:
case intro.intro.mk.intro.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'
H : Function.Surjective ⇑f
s : R
hs : s ∈ ↑M
y : R
⊢ ∃ a,
    (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M))) a =
      IsLocalization.mk' S' (f y) { val := f s, property := (_ : ∃ a ∈ ↑M, f a = f s) }

Next tactic:
use IsLocalization.mk' R' y ⟨s, hs⟩
theorem localizationPreserves_surjective :
    RingHom.LocalizationPreserves fun {R S} _ _ f => Function.Surjective f := by
  introv R H x
  obtain ⟨x, ⟨_, s, hs, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (M.map f) x
  obtain ⟨y, rfl⟩ := H x
  use IsLocalization.mk' R' y ⟨s, hs⟩
  

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'
H : Function.Surjective ⇑f
s : R
hs : s ∈ ↑M
y : R
⊢ (IsLocalization.map S' f (_ : M ≤ Submonoid.comap f (Submonoid.map f M)))
      (IsLocalization.mk' R' y { val := s, property := hs }) =
    IsLocalization.mk' S' (f y) { val := f s, property := (_ : ∃ a ∈ ↑M, f a = f s) }

Next tactic:
rw [IsLocalization.map_mk']
theorem surjective_ofLocalizationSpan :
    RingHom.OfLocalizationSpan fun {R S} _ _ f => Function.Surjective f := 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 fun {R S} x x_1 f => Function.Surjective ⇑f

Next tactic:
introv R e H
theorem surjective_ofLocalizationSpan :
    RingHom.OfLocalizationSpan fun {R S} _ _ f => Function.Surjective f := by
  introv R e H
  

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 : 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)
⊢ Function.Surjective ⇑f

Next tactic:
rw [← Set.range_iff_surjective, Set.eq_univ_iff_forall]
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]
  

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 : 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)
⊢ ∀ (x : S), x ∈ Set.range ⇑f

Next tactic:
letI := f.toAlgebra
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
  

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 : 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), x ∈ Set.range ⇑f

Next tactic:
intro x
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
  

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 : 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
⊢ x ∈ Set.range ⇑f

Next tactic:
apply Submodule.mem_of_span_eq_top_of_smul_pow_mem
    (LinearMap.range (Algebra.linearMap R S)) s e
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
  

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
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), ∃ n, ↑r ^ n • x ∈ LinearMap.range (Algebra.linearMap R S)

Next tactic:
intro r
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
  

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
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
⊢ ∃ n, ↑r ^ n • x ∈ LinearMap.range (Algebra.linearMap R S)

Next tactic:
obtain ⟨a, e'⟩ := H r (algebraMap _ _ x)
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)
  

Proof state:
case H.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
a : Localization.Away ↑r
e' : (Localization.awayMap f ↑r) a = (algebraMap S (Localization.Away (f ↑r))) x
⊢ ∃ n, ↑r ^ n • x ∈ LinearMap.range (Algebra.linearMap R S)

Next tactic:
obtain ⟨b, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers (r : R)) a
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
  

Proof state:
case H.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'
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' :
  (Localization.awayMap f ↑r)
      (IsLocalization.mk' (Localization.Away ↑r) b
        { val := (fun x => ↑r ^ x) n, property := (_ : ∃ y, (fun x => ↑r ^ x) y = (fun x => ↑r ^ x) n) }) =
    (algebraMap S (Localization.Away (f ↑r))) x
⊢ ∃ n, ↑r ^ n • x ∈ LinearMap.range (Algebra.linearMap R S)

Next tactic:
erw [IsLocalization.map_mk'] at e'
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'
  

Proof state:
case H.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'
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' :
  IsLocalization.mk' (Localization.Away (f ↑r)) (f b)
      { 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))) x
⊢ ∃ n, ↑r ^ n • x ∈ LinearMap.range (Algebra.linearMap R S)

Next tactic:
rw [eq_comm, IsLocalization.eq_mk'_iff_mul_eq, Subtype.coe_mk, Subtype.coe_mk, ← map_mul] at e'
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'
  

Proof state:
case H.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'
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, ↑r ^ n • x ∈ LinearMap.range (Algebra.linearMap R S)

Next tactic:
obtain ⟨⟨_, n', rfl⟩, e''⟩ := (IsLocalization.eq_iff_exists (Submonoid.powers (f r)) _).mp e'
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'
  

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'' :
  ↑{ val := (fun x => f ↑r ^ x) n', property := (_ : ∃ y, (fun x => f ↑r ^ x) y = (fun x => f ↑r ^ x) n') } *
      (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))) }) =
    ↑{ val := (fun x => f ↑r ^ x) n', property := (_ : ∃ y, (fun x => f ↑r ^ x) y = (fun x => f ↑r ^ x) n') } * f b
⊢ ∃ n, ↑r ^ n • x ∈ LinearMap.range (Algebra.linearMap R S)

Next tactic:
dsimp only at e''
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''
  

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' * (x * f (↑r ^ n)) = f ↑r ^ n' * f b
⊢ ∃ n, ↑r ^ n • x ∈ LinearMap.range (Algebra.linearMap R S)

Next tactic:
rw [mul_comm x, ← mul_assoc, ← map_pow, ← map_mul, ← map_mul, ← pow_add] at e''