-- Mathlib/AlgebraicGeometry/StructureSheaf.lean
theorem toBasicOpen_surjective (f : R) : Function.Surjective (toBasicOpen R f)

Proof state:
R : Type u
inst✝ : CommRing R
f : R
s : ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen f)))
ι : Type u := ↥(PrimeSpectrum.basicOpen f)
a' h' : ↥(PrimeSpectrum.basicOpen f) → R
iDh' : (x : ↥(PrimeSpectrum.basicOpen f)) → PrimeSpectrum.basicOpen (h' x) ⟶ PrimeSpectrum.basicOpen f
hxDh' : ∀ (x : ↥(PrimeSpectrum.basicOpen f)), ↑x ∈ PrimeSpectrum.basicOpen (h' x)
s_eq' :
  ∀ (x : ↥(PrimeSpectrum.basicOpen f)),
    const R (a' x) (h' x) (PrimeSpectrum.basicOpen (h' x)) ⋯ =
      (ConcreteCategory.hom ((structureSheaf R).val.map (iDh' x).op)) s
⊢ ∃ a, (toBasicOpen R f) a = s

Tactic:
obtain ⟨t, ht_cover'⟩ :=
  (PrimeSpectrum.isCompact_basicOpen f).elim_finite_subcover
    (fun i : ι => PrimeSpectrum.basicOpen (h' i)) (fun i => PrimeSpectrum.isOpen_basicOpen)
    fun x hx => by rw [Set.mem_iUnion]; exact ⟨⟨x, hx⟩, hxDh' ⟨x, hx⟩⟩

Result:
case intro
R : Type u
inst✝ : CommRing R
f : R
s : ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen f)))
ι : Type u := ↥(PrimeSpectrum.basicOpen f)
a' h' : ↥(PrimeSpectrum.basicOpen f) → R
iDh' : (x : ↥(PrimeSpectrum.basicOpen f)) → PrimeSpectrum.basicOpen (h' x) ⟶ PrimeSpectrum.basicOpen f
hxDh' : ∀ (x : ↥(PrimeSpectrum.basicOpen f)), ↑x ∈ PrimeSpectrum.basicOpen (h' x)
s_eq' :
  ∀ (x : ↥(PrimeSpectrum.basicOpen f)),
    const R (a' x) (h' x) (PrimeSpectrum.basicOpen (h' x)) ⋯ =
      (ConcreteCategory.hom ((structureSheaf R).val.map (iDh' x).op)) s
t : Finset ι
ht_cover' : ↑(PrimeSpectrum.basicOpen f) ⊆ ⋃ i ∈ t, ↑(PrimeSpectrum.basicOpen (h' i))
⊢ ∃ a, (toBasicOpen R f) a = s

Proof state:
R : Type u
inst✝ : CommRing R
f : R
s : ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen f)))
ι : Type u := ↥(PrimeSpectrum.basicOpen f)
t : Finset ι
a h : ι → R
iDh : (i : ι) → PrimeSpectrum.basicOpen (h i) ⟶ PrimeSpectrum.basicOpen f
ah_ha : ∀ i ∈ t, ∀ j ∈ t, a i * h j = h i * a j
s_eq :
  ∀ i ∈ t,
    (ConcreteCategory.hom ((structureSheaf R).val.map (iDh i).op)) s =
      const R (a i) (h i) (PrimeSpectrum.basicOpen (h i)) ⋯
ht_cover : (⋃ i ∈ t, (PrimeSpectrum.zeroLocus {h i})ᶜ)ᶜ ⊆ PrimeSpectrum.zeroLocus {f}
⊢ f ∈ PrimeSpectrum.vanishingIdeal (PrimeSpectrum.zeroLocus (h '' ↑t))

Tactic:
simp_rw [Set.compl_iUnion, compl_compl, ← PrimeSpectrum.zeroLocus_iUnion,
  ← Finset.set_biUnion_coe, ← Set.image_eq_iUnion] at ht_cover

Result:
R : Type u
inst✝ : CommRing R
f : R
s : ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen f)))
ι : Type u := ↥(PrimeSpectrum.basicOpen f)
t : Finset ι
a h : ι → R
iDh : (i : ι) → PrimeSpectrum.basicOpen (h i) ⟶ PrimeSpectrum.basicOpen f
ah_ha : ∀ i ∈ t, ∀ j ∈ t, a i * h j = h i * a j
s_eq :
  ∀ i ∈ t,
    (ConcreteCategory.hom ((structureSheaf R).val.map (iDh i).op)) s =
      const R (a i) (h i) (PrimeSpectrum.basicOpen (h i)) ⋯
ht_cover : PrimeSpectrum.zeroLocus (h '' ↑t) ⊆ PrimeSpectrum.zeroLocus {f}
⊢ f ∈ PrimeSpectrum.vanishingIdeal (PrimeSpectrum.zeroLocus (h '' ↑t))

Proof state:
R : Type u
inst✝ : CommRing R
f : R
s : ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen f)))
ι : Type u := ↥(PrimeSpectrum.basicOpen f)
t : Finset ι
a h : ι → R
iDh : (i : ι) → PrimeSpectrum.basicOpen (h i) ⟶ PrimeSpectrum.basicOpen f
ah_ha : ∀ i ∈ t, ∀ j ∈ t, a i * h j = h i * a j
s_eq :
  ∀ i ∈ t,
    (ConcreteCategory.hom ((structureSheaf R).val.map (iDh i).op)) s =
      const R (a i) (h i) (PrimeSpectrum.basicOpen (h i)) ⋯
ht_cover : ↑(PrimeSpectrum.basicOpen f) ⊆ ⋃ i ∈ t, ↑(PrimeSpectrum.basicOpen (h i))
⊢ f ∈ (Ideal.span (h '' ↑t)).radical

Tactic:
rw [← PrimeSpectrum.vanishingIdeal_zeroLocus_eq_radical, PrimeSpectrum.zeroLocus_span]

Result:
R : Type u
inst✝ : CommRing R
f : R
s : ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen f)))
ι : Type u := ↥(PrimeSpectrum.basicOpen f)
t : Finset ι
a h : ι → R
iDh : (i : ι) → PrimeSpectrum.basicOpen (h i) ⟶ PrimeSpectrum.basicOpen f
ah_ha : ∀ i ∈ t, ∀ j ∈ t, a i * h j = h i * a j
s_eq :
  ∀ i ∈ t,
    (ConcreteCategory.hom ((structureSheaf R).val.map (iDh i).op)) s =
      const R (a i) (h i) (PrimeSpectrum.basicOpen (h i)) ⋯
ht_cover : ↑(PrimeSpectrum.basicOpen f) ⊆ ⋃ i ∈ t, ↑(PrimeSpectrum.basicOpen (h i))
⊢ f ∈ PrimeSpectrum.vanishingIdeal (PrimeSpectrum.zeroLocus (h '' ↑t))

Proof state:
R : Type u
inst✝ : CommRing R
f : R
s : ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen f)))
ι : Type u := ↥(PrimeSpectrum.basicOpen f)
a' h' : ↥(PrimeSpectrum.basicOpen f) → R
iDh' : (x : ↥(PrimeSpectrum.basicOpen f)) → PrimeSpectrum.basicOpen (h' x) ⟶ PrimeSpectrum.basicOpen f
hxDh' : ∀ (x : ↥(PrimeSpectrum.basicOpen f)), ↑x ∈ PrimeSpectrum.basicOpen (h' x)
s_eq' :
  ∀ (x : ↥(PrimeSpectrum.basicOpen f)),
    const R (a' x) (h' x) (PrimeSpectrum.basicOpen (h' x)) ⋯ =
      (ConcreteCategory.hom ((structureSheaf R).val.map (iDh' x).op)) s
x : PrimeSpectrum R
hx : x ∈ ↑(PrimeSpectrum.basicOpen f)
⊢ x ∈ ⋃ i, (fun i => ↑(PrimeSpectrum.basicOpen (h' i))) i

Tactic:
rw [Set.mem_iUnion]

Result:
R : Type u
inst✝ : CommRing R
f : R
s : ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen f)))
ι : Type u := ↥(PrimeSpectrum.basicOpen f)
a' h' : ↥(PrimeSpectrum.basicOpen f) → R
iDh' : (x : ↥(PrimeSpectrum.basicOpen f)) → PrimeSpectrum.basicOpen (h' x) ⟶ PrimeSpectrum.basicOpen f
hxDh' : ∀ (x : ↥(PrimeSpectrum.basicOpen f)), ↑x ∈ PrimeSpectrum.basicOpen (h' x)
s_eq' :
  ∀ (x : ↥(PrimeSpectrum.basicOpen f)),
    const R (a' x) (h' x) (PrimeSpectrum.basicOpen (h' x)) ⋯ =
      (ConcreteCategory.hom ((structureSheaf R).val.map (iDh' x).op)) s
x : PrimeSpectrum R
hx : x ∈ ↑(PrimeSpectrum.basicOpen f)
⊢ ∃ i, x ∈ ↑(PrimeSpectrum.basicOpen (h' i))

Proof state:
case h
R : Type u
inst✝ : CommRing R
f : R
s : ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen f)))
ι : Type u := ↥(PrimeSpectrum.basicOpen f)
t : Finset ι
a h : ι → R
iDh : (i : ι) → PrimeSpectrum.basicOpen (h i) ⟶ PrimeSpectrum.basicOpen f
ah_ha : ∀ i ∈ t, ∀ j ∈ t, a i * h j = h i * a j
s_eq :
  ∀ i ∈ t,
    (ConcreteCategory.hom ((structureSheaf R).val.map (iDh i).op)) s =
      const R (a i) (h i) (PrimeSpectrum.basicOpen (h i)) ⋯
ht_cover : ↑(PrimeSpectrum.basicOpen f) ⊆ ⋃ i ∈ t, ↑(PrimeSpectrum.basicOpen (h i))
n : ℕ
b : ι →₀ R
b_supp : b ∈ Finsupp.supported R R ↑t
hb : ∑ i ∈ t, b i * h i = f ^ (n + 1)
⊢ (toBasicOpen R f) (IsLocalization.mk' (Localization.Away f) (∑ i ∈ t, b i * a i) ⟨f ^ (n + 1), ⋯⟩) = s

Tactic:
rw [toBasicOpen_mk']

Result:
case h
R : Type u
inst✝ : CommRing R
f : R
s : ↑((structureSheaf R).val.obj (op (PrimeSpectrum.basicOpen f)))
ι : Type u := ↥(PrimeSpectrum.basicOpen f)
t : Finset ι
a h : ι → R
iDh : (i : ι) → PrimeSpectrum.basicOpen (h i) ⟶ PrimeSpectrum.basicOpen f
ah_ha : ∀ i ∈ t, ∀ j ∈ t, a i * h j = h i * a j
s_eq :
  ∀ i ∈ t,
    (ConcreteCategory.hom ((structureSheaf R).val.map (iDh i).op)) s =
      const R (a i) (h i) (PrimeSpectrum.basicOpen (h i)) ⋯
ht_cover : ↑(PrimeSpectrum.basicOpen f) ⊆ ⋃ i ∈ t, ↑(PrimeSpectrum.basicOpen (h i))
n : ℕ
b : ι →₀ R
b_supp : b ∈ Finsupp.supported R R ↑t
hb : ∑ i ∈ t, b i * h i = f ^ (n + 1)
⊢ const R (∑ i ∈ t, b i * a i) (↑⟨f ^ (n + 1), ⋯⟩) (PrimeSpectrum.basicOpen f) ⋯ = s