l3lab/ntp-mathlib huggingface dataset:
theorem surjective_stableUnderBaseChange : StableUnderBaseChange surjective := by
  refine' StableUnderBaseChange.mk _ surjective_respectsIso _
  classical
  introv h x
  skip
  induction x using TensorProduct.induction_on with
  | zero => exact ⟨0, map_zero _⟩
  | tmul x y =>
    obtain ⟨y, rfl⟩ := h y; use y • x; dsimp
    rw [TensorProduct.smul_tmul, Algebra.algebraMap_eq_smul_one]
  

Proof state:
case add
R S T : Type u_1
inst✝⁴ : CommRing R
inst✝³ : CommRing S
inst✝² : CommRing T
inst✝¹ : Algebra R S
inst✝ : Algebra R T
h : Function.Surjective ⇑(algebraMap R T)
x y : S ⊗[R] T
ex : ∃ a, includeLeftRingHom a = x
ey : ∃ a, includeLeftRingHom a = y
⊢ ∃ a, includeLeftRingHom a = x + y

Next tactic:
| add x y ex ey => obtain ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ := ex, ey; exact ⟨x + y, map_add _ x y⟩
theorem surjective_stableUnderBaseChange : StableUnderBaseChange surjective := by
  refine' StableUnderBaseChange.mk _ surjective_respectsIso _
  classical
  introv h x
  skip
  induction x using TensorProduct.induction_on with
  | zero => exact ⟨0, map_zero _⟩
  | tmul x y =>
    obtain ⟨y, rfl⟩ := h y; use y • x; dsimp
    rw [TensorProduct.smul_tmul, Algebra.algebraMap_eq_smul_one]
  | add x y ex ey => 

Proof state:
case add
R S T : Type u_1
inst✝⁴ : CommRing R
inst✝³ : CommRing S
inst✝² : CommRing T
inst✝¹ : Algebra R S
inst✝ : Algebra R T
h : Function.Surjective ⇑(algebraMap R T)
x y : S ⊗[R] T
ex : ∃ a, includeLeftRingHom a = x
ey : ∃ a, includeLeftRingHom a = y
⊢ ∃ a, includeLeftRingHom a = x + y

Next tactic:
obtain ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ := ex, ey
theorem surjective_stableUnderBaseChange : StableUnderBaseChange surjective := by
  refine' StableUnderBaseChange.mk _ surjective_respectsIso _
  classical
  introv h x
  skip
  induction x using TensorProduct.induction_on with
  | zero => exact ⟨0, map_zero _⟩
  | tmul x y =>
    obtain ⟨y, rfl⟩ := h y; use y • x; dsimp
    rw [TensorProduct.smul_tmul, Algebra.algebraMap_eq_smul_one]
  | add x y ex ey => obtain ⟨⟨x, rfl⟩, ⟨y, rfl⟩⟩ := ex, ey; 

Proof state:
case add.intro.intro
R S T : Type u_1
inst✝⁴ : CommRing R
inst✝³ : CommRing S
inst✝² : CommRing T
inst✝¹ : Algebra R S
inst✝ : Algebra R T
h : Function.Surjective ⇑(algebraMap R T)
x y : S
⊢ ∃ a, includeLeftRingHom a = includeLeftRingHom x + includeLeftRingHom y

Next tactic:
exact ⟨x + y, map_add _ x y⟩
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  

Proof state:
⊢ OfLocalizationSpan fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f

Next tactic:
introv R hs H
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  

Proof state:
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
⊢ Function.Surjective ⇑f

Next tactic:
skip
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  

Proof state:
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
⊢ Function.Surjective ⇑f

Next tactic:
letI := f.toAlgebra
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  

Proof state:
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
⊢ Function.Surjective ⇑f

Next tactic:
show Function.Surjective (Algebra.ofId R S)
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  

Proof state:
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
⊢ Function.Surjective ⇑(Algebra.ofId R S)

Next tactic:
rw [← Algebra.range_top_iff_surjective, eq_top_iff]
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  

Proof state:
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
⊢ ⊤ ≤ AlgHom.range (Algebra.ofId R S)

Next tactic:
rintro x -
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  

Proof state:
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
⊢ x ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by 

Proof state:
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
⊢ 1 ∈ Ideal.span s

Next tactic:
rw [hs]
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; 

Proof state:
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
⊢ 1 ∈ ⊤

Next tactic:
trivial
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  

Proof state:
case intro
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
⊢ x ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · 

Proof state:
case intro.e
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
⊢ ∑ i in l.support, f (l i) * f ↑i = 1

Next tactic:
simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; 

Proof state:
case intro.e
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
⊢ f (∑ x in l.support, l x * ↑x) = f 1

Next tactic:
exact f.congr_arg hl
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; exact f.congr_arg hl
  · 

Proof state:
case intro.hs
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
⊢ ∀ (i : ↑s), f ↑i ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
exact fun _ => Set.mem_range_self _
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; exact f.congr_arg hl
  · exact fun _ => Set.mem_range_self _
  · 

Proof state:
case intro.hl
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
⊢ ∀ (i : ↑s), f (l i) ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
exact fun _ => Set.mem_range_self _
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; exact f.congr_arg hl
  · exact fun _ => Set.mem_range_self _
  · exact fun _ => Set.mem_range_self _
  · 

Proof state:
case intro.H
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
⊢ ∀ (i : ↑s), ∃ n, f ↑i ^ n • x ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
intro r
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; exact f.congr_arg hl
  · exact fun _ => Set.mem_range_self _
  · exact fun _ => Set.mem_range_self _
  · intro r
    

Proof state:
case intro.H
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
r : ↑s
⊢ ∃ n, f ↑r ^ n • x ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
obtain ⟨y, hy⟩ := H r (IsLocalization.mk' _ x (1 : Submonoid.powers (f r)))
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; exact f.congr_arg hl
  · exact fun _ => Set.mem_range_self _
  · exact fun _ => Set.mem_range_self _
  · intro r
    obtain ⟨y, hy⟩ := H r (IsLocalization.mk' _ x (1 : Submonoid.powers (f r)))
    

Proof state:
case intro.H.intro
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
r : ↑s
y : Localization.Away ↑r
hy : (Localization.awayMap f ↑r) y = IsLocalization.mk' (Localization.Away (f ↑r)) x 1
⊢ ∃ n, f ↑r ^ n • x ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
obtain ⟨z, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers (r : R)) y
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; exact f.congr_arg hl
  · exact fun _ => Set.mem_range_self _
  · exact fun _ => Set.mem_range_self _
  · intro r
    obtain ⟨y, hy⟩ := H r (IsLocalization.mk' _ x (1 : Submonoid.powers (f r)))
    obtain ⟨z, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers (r : R)) y
    

Proof state:
case intro.H.intro.intro.intro.mk.intro
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
r : ↑s
z : R
n : ℕ
hy :
  (Localization.awayMap f ↑r)
      (IsLocalization.mk' (Localization.Away ↑r) z
        { val := (fun x => ↑r ^ x) n, property := (_ : ∃ y, (fun x => ↑r ^ x) y = (fun x => ↑r ^ x) n) }) =
    IsLocalization.mk' (Localization.Away (f ↑r)) x 1
⊢ ∃ n, f ↑r ^ n • x ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
erw [IsLocalization.map_mk', IsLocalization.eq] at hy
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; exact f.congr_arg hl
  · exact fun _ => Set.mem_range_self _
  · exact fun _ => Set.mem_range_self _
  · intro r
    obtain ⟨y, hy⟩ := H r (IsLocalization.mk' _ x (1 : Submonoid.powers (f r)))
    obtain ⟨z, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers (r : R)) y
    erw [IsLocalization.map_mk', IsLocalization.eq] at hy
    

Proof state:
case intro.H.intro.intro.intro.mk.intro
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
r : ↑s
z : R
n : ℕ
hy :
  ∃ c,
    ↑c * (↑1 * f z) =
      ↑c *
        (↑{ 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))) } *
          x)
⊢ ∃ n, f ↑r ^ n • x ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
obtain ⟨⟨_, m, rfl⟩, hm⟩ := hy
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; exact f.congr_arg hl
  · exact fun _ => Set.mem_range_self _
  · exact fun _ => Set.mem_range_self _
  · intro r
    obtain ⟨y, hy⟩ := H r (IsLocalization.mk' _ x (1 : Submonoid.powers (f r)))
    obtain ⟨z, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers (r : R)) y
    erw [IsLocalization.map_mk', IsLocalization.eq] at hy
    obtain ⟨⟨_, m, rfl⟩, hm⟩ := hy
    

Proof state:
case intro.H.intro.intro.intro.mk.intro.intro.mk.intro
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
r : ↑s
z : R
n m : ℕ
hm :
  ↑{ val := (fun x => f ↑r ^ x) m, property := (_ : ∃ y, (fun x => f ↑r ^ x) y = (fun x => f ↑r ^ x) m) } * (↑1 * f z) =
    ↑{ val := (fun x => f ↑r ^ x) m, property := (_ : ∃ y, (fun x => f ↑r ^ x) y = (fun x => f ↑r ^ x) m) } *
      (↑{ 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))) } *
        x)
⊢ ∃ n, f ↑r ^ n • x ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
refine' ⟨m + n, _⟩
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; exact f.congr_arg hl
  · exact fun _ => Set.mem_range_self _
  · exact fun _ => Set.mem_range_self _
  · intro r
    obtain ⟨y, hy⟩ := H r (IsLocalization.mk' _ x (1 : Submonoid.powers (f r)))
    obtain ⟨z, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers (r : R)) y
    erw [IsLocalization.map_mk', IsLocalization.eq] at hy
    obtain ⟨⟨_, m, rfl⟩, hm⟩ := hy
    refine' ⟨m + n, _⟩
    

Proof state:
case intro.H.intro.intro.intro.mk.intro.intro.mk.intro
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
r : ↑s
z : R
n m : ℕ
hm :
  ↑{ val := (fun x => f ↑r ^ x) m, property := (_ : ∃ y, (fun x => f ↑r ^ x) y = (fun x => f ↑r ^ x) m) } * (↑1 * f z) =
    ↑{ val := (fun x => f ↑r ^ x) m, property := (_ : ∃ y, (fun x => f ↑r ^ x) y = (fun x => f ↑r ^ x) m) } *
      (↑{ 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))) } *
        x)
⊢ f ↑r ^ (m + n) • x ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
dsimp at hm ⊢
theorem surjective_ofLocalizationSpan : OfLocalizationSpan surjective := by
  introv R hs H
  skip
  letI := f.toAlgebra
  show Function.Surjective (Algebra.ofId R S)
  rw [← Algebra.range_top_iff_surjective, eq_top_iff]
  rintro x -
  obtain ⟨l, hl⟩ :=
    (Finsupp.mem_span_iff_total R s 1).mp (show _ ∈ Ideal.span s by rw [hs]; trivial)
  fapply
    Subalgebra.mem_of_finset_sum_eq_one_of_pow_smul_mem _ l.support (fun x : s => f x) fun x : s =>
      f (l x)
  · simp_rw [← _root_.map_mul, ← map_sum, ← f.map_one]; exact f.congr_arg hl
  · exact fun _ => Set.mem_range_self _
  · exact fun _ => Set.mem_range_self _
  · intro r
    obtain ⟨y, hy⟩ := H r (IsLocalization.mk' _ x (1 : Submonoid.powers (f r)))
    obtain ⟨z, ⟨_, n, rfl⟩, rfl⟩ := IsLocalization.mk'_surjective (Submonoid.powers (r : R)) y
    erw [IsLocalization.map_mk', IsLocalization.eq] at hy
    obtain ⟨⟨_, m, rfl⟩, hm⟩ := hy
    refine' ⟨m + n, _⟩
    dsimp at hm ⊢
    

Proof state:
case intro.H.intro.intro.intro.mk.intro.intro.mk.intro
R S : Type u_1
inst✝¹ : CommRing R
inst✝ : CommRing S
f : R →+* S
s : Set R
hs : Ideal.span s = ⊤
H : ∀ (r : ↑s), (fun {X Y} [CommRing X] [CommRing Y] f => Function.Surjective ⇑f) (Localization.awayMap f ↑r)
this : Algebra R S := toAlgebra f
x : S
l : ↑s →₀ R
hl : (Finsupp.total (↑s) R R Subtype.val) l = 1
r : ↑s
z : R
n m : ℕ
hm : f ↑r ^ m * (1 * f z) = f ↑r ^ m * (f (↑r ^ n) * x)
⊢ f ↑r ^ (m + n) * x ∈ AlgHom.range (Algebra.ofId R S)

Next tactic:
simp_rw [_root_.one_mul, ← _root_.mul_assoc, ← map_pow, ← f.map_mul, ← pow_add, map_pow] at hm