l3lab/ntp-mathlib huggingface dataset:
/-- The affine cover of a scheme. -/
def affineCover (X : Scheme) : OpenCover X where
  J := X.carrier
  obj x := Spec.obj <| Opposite.op (X.local_affine x).choose_spec.choose
  map x :=
    ((X.local_affine x).choose_spec.choose_spec.some.inv ≫ X.toLocallyRingedSpace.ofRestrict _ : _)
  f x := x
  IsOpen x := by
    apply (config := { allowSynthFailures := true }) PresheafedSpace.IsOpenImmersion.comp
    apply PresheafedSpace.IsOpenImmersion.ofRestrict
  Covers := by
    intro x
    erw [coe_comp]
    rw [Set.range_comp, Set.range_iff_surjective.mpr, Set.image_univ]
    erw [Subtype.range_coe_subtype]
    exact (X.local_affine x).choose.2
    rw [← TopCat.epi_iff_surjective]
    

Proof state:
C : Type u
inst✝¹ : Category.{v, u} C
X✝ Y Z : Scheme
𝒰 : OpenCover X✝
f : X✝ ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (OpenCover.map 𝒰 x ≫ f) g
X : Scheme
x : ↑↑X.toPresheafedSpace
⊢ Epi
    (Nonempty.some
            (_ :
              Nonempty
                (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                    (_ :
                      OpenEmbedding
                        ⇑(Opens.inclusion
                            (Exists.choose
                                (_ :
                                  ∃ U R,
                                    Nonempty
                                      (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                          (_ : OpenEmbedding ⇑(Opens.inclusion U.obj)) ≅
                                        Spec.toLocallyRingedSpace.obj (op R)))).obj)) ≅
                  Spec.toLocallyRingedSpace.obj
                    (op
                      (Exists.choose
                        (_ :
                          ∃ R,
                            Nonempty
                              (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                  (_ :
                                    OpenEmbedding
                                      ⇑(Opens.inclusion
                                          (Exists.choose
                                              (_ :
                                                ∃ U R,
                                                  Nonempty
                                                    (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                                        (_ : OpenEmbedding ⇑(Opens.inclusion U.obj)) ≅
                                                      Spec.toLocallyRingedSpace.obj (op R)))).obj)) ≅
                                Spec.toLocallyRingedSpace.obj (op R)))))))).inv.val.base

Next tactic:
change Epi ((SheafedSpace.forget _).map (LocallyRingedSpace.forgetToSheafedSpace.map _))
/-- The affine cover of a scheme. -/
def affineCover (X : Scheme) : OpenCover X where
  J := X.carrier
  obj x := Spec.obj <| Opposite.op (X.local_affine x).choose_spec.choose
  map x :=
    ((X.local_affine x).choose_spec.choose_spec.some.inv ≫ X.toLocallyRingedSpace.ofRestrict _ : _)
  f x := x
  IsOpen x := by
    apply (config := { allowSynthFailures := true }) PresheafedSpace.IsOpenImmersion.comp
    apply PresheafedSpace.IsOpenImmersion.ofRestrict
  Covers := by
    intro x
    erw [coe_comp]
    rw [Set.range_comp, Set.range_iff_surjective.mpr, Set.image_univ]
    erw [Subtype.range_coe_subtype]
    exact (X.local_affine x).choose.2
    rw [← TopCat.epi_iff_surjective]
    change Epi ((SheafedSpace.forget _).map (LocallyRingedSpace.forgetToSheafedSpace.map _))
    

Proof state:
C : Type u
inst✝¹ : Category.{v, u} C
X✝ Y Z : Scheme
𝒰 : OpenCover X✝
f : X✝ ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (OpenCover.map 𝒰 x ≫ f) g
X : Scheme
x : ↑↑X.toPresheafedSpace
⊢ Epi
    ((SheafedSpace.forget CommRingCat).map
      (LocallyRingedSpace.forgetToSheafedSpace.map
        (Nonempty.some
            (_ :
              Nonempty
                (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                    (_ :
                      OpenEmbedding
                        ⇑(Opens.inclusion
                            (Exists.choose
                                (_ :
                                  ∃ U R,
                                    Nonempty
                                      (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                          (_ : OpenEmbedding ⇑(Opens.inclusion U.obj)) ≅
                                        Spec.toLocallyRingedSpace.obj (op R)))).obj)) ≅
                  Spec.toLocallyRingedSpace.obj
                    (op
                      (Exists.choose
                        (_ :
                          ∃ R,
                            Nonempty
                              (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                  (_ :
                                    OpenEmbedding
                                      ⇑(Opens.inclusion
                                          (Exists.choose
                                              (_ :
                                                ∃ U R,
                                                  Nonempty
                                                    (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                                        (_ : OpenEmbedding ⇑(Opens.inclusion U.obj)) ≅
                                                      Spec.toLocallyRingedSpace.obj (op R)))).obj)) ≅
                                Spec.toLocallyRingedSpace.obj (op R)))))))).inv))

Next tactic:
infer_instance
/-- The affine cover of a scheme. -/
def affineCover (X : Scheme) : OpenCover X where
  J := X.carrier
  obj x := Spec.obj <| Opposite.op (X.local_affine x).choose_spec.choose
  map x :=
    ((X.local_affine x).choose_spec.choose_spec.some.inv ≫ X.toLocallyRingedSpace.ofRestrict _ : _)
  f x := x
  IsOpen x := by
    

Proof state:
C : Type u
inst✝¹ : Category.{v, u} C
X✝ Y Z : Scheme
𝒰 : OpenCover X✝
f : X✝ ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (OpenCover.map 𝒰 x ≫ f) g
X : Scheme
x : ↑↑X.toPresheafedSpace
⊢ IsOpenImmersion
    ((fun x =>
        (Nonempty.some
              (_ :
                Nonempty
                  (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                      (_ :
                        OpenEmbedding
                          ⇑(Opens.inclusion
                              (Exists.choose
                                  (_ :
                                    ∃ U R,
                                      Nonempty
                                        (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                            (_ : OpenEmbedding ⇑(Opens.inclusion U.obj)) ≅
                                          Spec.toLocallyRingedSpace.obj (op R)))).obj)) ≅
                    Spec.toLocallyRingedSpace.obj
                      (op
                        (Exists.choose
                          (_ :
                            ∃ R,
                              Nonempty
                                (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                    (_ :
                                      OpenEmbedding
                                        ⇑(Opens.inclusion
                                            (Exists.choose
                                                (_ :
                                                  ∃ U R,
                                                    Nonempty
                                                      (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                                          (_ : OpenEmbedding ⇑(Opens.inclusion U.obj)) ≅
                                                        Spec.toLocallyRingedSpace.obj (op R)))).obj)) ≅
                                  Spec.toLocallyRingedSpace.obj (op R)))))))).inv ≫
          LocallyRingedSpace.ofRestrict X.toLocallyRingedSpace
            (_ :
              OpenEmbedding
                ⇑(Opens.inclusion
                    (Exists.choose
                        (_ :
                          ∃ U R,
                            Nonempty
                              (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                                  (_ : OpenEmbedding ⇑(Opens.inclusion U.obj)) ≅
                                Spec.toLocallyRingedSpace.obj (op R)))).obj)))
      x)

Next tactic:
apply (config := { allowSynthFailures := true }) PresheafedSpace.IsOpenImmersion.comp
/-- The affine cover of a scheme. -/
def affineCover (X : Scheme) : OpenCover X where
  J := X.carrier
  obj x := Spec.obj <| Opposite.op (X.local_affine x).choose_spec.choose
  map x :=
    ((X.local_affine x).choose_spec.choose_spec.some.inv ≫ X.toLocallyRingedSpace.ofRestrict _ : _)
  f x := x
  IsOpen x := by
    apply (config := { allowSynthFailures := true }) PresheafedSpace.IsOpenImmersion.comp
    

Proof state:
case hg
C : Type u
inst✝¹ : Category.{v, u} C
X✝ Y Z : Scheme
𝒰 : OpenCover X✝
f : X✝ ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (OpenCover.map 𝒰 x ≫ f) g
X : Scheme
x : ↑↑X.toPresheafedSpace
⊢ PresheafedSpace.IsOpenImmersion
    (LocallyRingedSpace.ofRestrict X.toLocallyRingedSpace
        (_ :
          OpenEmbedding
            ⇑(Opens.inclusion
                (Exists.choose
                    (_ :
                      ∃ U R,
                        Nonempty
                          (LocallyRingedSpace.restrict X.toLocallyRingedSpace
                              (_ : OpenEmbedding ⇑(Opens.inclusion U.obj)) ≅
                            Spec.toLocallyRingedSpace.obj (op R)))).obj))).val

Next tactic:
apply PresheafedSpace.IsOpenImmersion.ofRestrict
/-- Given an open cover `{ Uᵢ }` of `X`, and for each `Uᵢ` an open cover, we may combine these
open covers to form an open cover of `X`.  -/
@[simps! J obj map]
def OpenCover.bind (f : ∀ x : 𝒰.J, OpenCover (𝒰.obj x)) : OpenCover X where
  J := Σ i : 𝒰.J, (f i).J
  obj x := (f x.1).obj x.2
  map x := (f x.1).map x.2 ≫ 𝒰.map x.1
  f x := ⟨_, (f _).f (𝒰.Covers x).choose⟩
  Covers x := by
    

Proof state:
C : Type u
inst✝¹ : Category.{v, u} C
X Y Z : Scheme
𝒰 : OpenCover X
f✝ : X ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (map 𝒰 x ≫ f✝) g
f : (x : 𝒰.J) → OpenCover (obj 𝒰 x)
x : ↑↑X.toPresheafedSpace
⊢ x ∈
    Set.range
      ⇑((fun x => map (f x.fst) x.snd ≫ map 𝒰 x.fst)
              ((fun x =>
                  { fst := AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x,
                    snd :=
                      AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
                        (Exists.choose
                          (_ : x ∈ Set.range ⇑(map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base)) })
                x)).val.base

Next tactic:
let y := (𝒰.Covers x).choose
/-- Given an open cover `{ Uᵢ }` of `X`, and for each `Uᵢ` an open cover, we may combine these
open covers to form an open cover of `X`.  -/
@[simps! J obj map]
def OpenCover.bind (f : ∀ x : 𝒰.J, OpenCover (𝒰.obj x)) : OpenCover X where
  J := Σ i : 𝒰.J, (f i).J
  obj x := (f x.1).obj x.2
  map x := (f x.1).map x.2 ≫ 𝒰.map x.1
  f x := ⟨_, (f _).f (𝒰.Covers x).choose⟩
  Covers x := by
    let y := (𝒰.Covers x).choose
    

Proof state:
C : Type u
inst✝¹ : Category.{v, u} C
X Y Z : Scheme
𝒰 : OpenCover X
f✝ : X ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (map 𝒰 x ≫ f✝) g
f : (x : 𝒰.J) → OpenCover (obj 𝒰 x)
x : ↑↑X.toPresheafedSpace
y : (forget TopCat).obj ↑(obj 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).toPresheafedSpace :=
  Exists.choose (_ : x ∈ Set.range ⇑(map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base)
⊢ x ∈
    Set.range
      ⇑((fun x => map (f x.fst) x.snd ≫ map 𝒰 x.fst)
              ((fun x =>
                  { fst := AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x,
                    snd :=
                      AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
                        (Exists.choose
                          (_ : x ∈ Set.range ⇑(map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base)) })
                x)).val.base

Next tactic:
have hy : (𝒰.map (𝒰.f x)).val.base y = x := (𝒰.Covers x).choose_spec
/-- Given an open cover `{ Uᵢ }` of `X`, and for each `Uᵢ` an open cover, we may combine these
open covers to form an open cover of `X`.  -/
@[simps! J obj map]
def OpenCover.bind (f : ∀ x : 𝒰.J, OpenCover (𝒰.obj x)) : OpenCover X where
  J := Σ i : 𝒰.J, (f i).J
  obj x := (f x.1).obj x.2
  map x := (f x.1).map x.2 ≫ 𝒰.map x.1
  f x := ⟨_, (f _).f (𝒰.Covers x).choose⟩
  Covers x := by
    let y := (𝒰.Covers x).choose
    have hy : (𝒰.map (𝒰.f x)).val.base y = x := (𝒰.Covers x).choose_spec
    

Proof state:
C : Type u
inst✝¹ : Category.{v, u} C
X Y Z : Scheme
𝒰 : OpenCover X
f✝ : X ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (map 𝒰 x ≫ f✝) g
f : (x : 𝒰.J) → OpenCover (obj 𝒰 x)
x : ↑↑X.toPresheafedSpace
y : (forget TopCat).obj ↑(obj 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).toPresheafedSpace :=
  Exists.choose (_ : x ∈ Set.range ⇑(map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base)
hy : (map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base y = x
⊢ x ∈
    Set.range
      ⇑((fun x => map (f x.fst) x.snd ≫ map 𝒰 x.fst)
              ((fun x =>
                  { fst := AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x,
                    snd :=
                      AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
                        (Exists.choose
                          (_ : x ∈ Set.range ⇑(map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base)) })
                x)).val.base

Next tactic:
rcases (f (𝒰.f x)).Covers y with ⟨z, hz⟩
/-- Given an open cover `{ Uᵢ }` of `X`, and for each `Uᵢ` an open cover, we may combine these
open covers to form an open cover of `X`.  -/
@[simps! J obj map]
def OpenCover.bind (f : ∀ x : 𝒰.J, OpenCover (𝒰.obj x)) : OpenCover X where
  J := Σ i : 𝒰.J, (f i).J
  obj x := (f x.1).obj x.2
  map x := (f x.1).map x.2 ≫ 𝒰.map x.1
  f x := ⟨_, (f _).f (𝒰.Covers x).choose⟩
  Covers x := by
    let y := (𝒰.Covers x).choose
    have hy : (𝒰.map (𝒰.f x)).val.base y = x := (𝒰.Covers x).choose_spec
    rcases (f (𝒰.f x)).Covers y with ⟨z, hz⟩
    

Proof state:
case intro
C : Type u
inst✝¹ : Category.{v, u} C
X Y Z : Scheme
𝒰 : OpenCover X
f✝ : X ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (map 𝒰 x ≫ f✝) g
f : (x : 𝒰.J) → OpenCover (obj 𝒰 x)
x : ↑↑X.toPresheafedSpace
y : (forget TopCat).obj ↑(obj 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).toPresheafedSpace :=
  Exists.choose (_ : x ∈ Set.range ⇑(map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base)
hy : (map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base y = x
z :
  (forget TopCat).obj
    ↑(obj (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
          (AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)) y)).toPresheafedSpace
hz :
  (map (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
            (AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)) y)).val.base
      z =
    y
⊢ x ∈
    Set.range
      ⇑((fun x => map (f x.fst) x.snd ≫ map 𝒰 x.fst)
              ((fun x =>
                  { fst := AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x,
                    snd :=
                      AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
                        (Exists.choose
                          (_ : x ∈ Set.range ⇑(map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base)) })
                x)).val.base

Next tactic:
change x ∈ Set.range ((f (𝒰.f x)).map ((f (𝒰.f x)).f y) ≫ 𝒰.map (𝒰.f x)).1.base
/-- Given an open cover `{ Uᵢ }` of `X`, and for each `Uᵢ` an open cover, we may combine these
open covers to form an open cover of `X`.  -/
@[simps! J obj map]
def OpenCover.bind (f : ∀ x : 𝒰.J, OpenCover (𝒰.obj x)) : OpenCover X where
  J := Σ i : 𝒰.J, (f i).J
  obj x := (f x.1).obj x.2
  map x := (f x.1).map x.2 ≫ 𝒰.map x.1
  f x := ⟨_, (f _).f (𝒰.Covers x).choose⟩
  Covers x := by
    let y := (𝒰.Covers x).choose
    have hy : (𝒰.map (𝒰.f x)).val.base y = x := (𝒰.Covers x).choose_spec
    rcases (f (𝒰.f x)).Covers y with ⟨z, hz⟩
    change x ∈ Set.range ((f (𝒰.f x)).map ((f (𝒰.f x)).f y) ≫ 𝒰.map (𝒰.f x)).1.base
    

Proof state:
case intro
C : Type u
inst✝¹ : Category.{v, u} C
X Y Z : Scheme
𝒰 : OpenCover X
f✝ : X ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (map 𝒰 x ≫ f✝) g
f : (x : 𝒰.J) → OpenCover (obj 𝒰 x)
x : ↑↑X.toPresheafedSpace
y : (forget TopCat).obj ↑(obj 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).toPresheafedSpace :=
  Exists.choose (_ : x ∈ Set.range ⇑(map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base)
hy : (map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base y = x
z :
  (forget TopCat).obj
    ↑(obj (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
          (AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)) y)).toPresheafedSpace
hz :
  (map (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
            (AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)) y)).val.base
      z =
    y
⊢ x ∈
    Set.range
      ⇑(map (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
                (AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)) y) ≫
              map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base

Next tactic:
use z
/-- Given an open cover `{ Uᵢ }` of `X`, and for each `Uᵢ` an open cover, we may combine these
open covers to form an open cover of `X`.  -/
@[simps! J obj map]
def OpenCover.bind (f : ∀ x : 𝒰.J, OpenCover (𝒰.obj x)) : OpenCover X where
  J := Σ i : 𝒰.J, (f i).J
  obj x := (f x.1).obj x.2
  map x := (f x.1).map x.2 ≫ 𝒰.map x.1
  f x := ⟨_, (f _).f (𝒰.Covers x).choose⟩
  Covers x := by
    let y := (𝒰.Covers x).choose
    have hy : (𝒰.map (𝒰.f x)).val.base y = x := (𝒰.Covers x).choose_spec
    rcases (f (𝒰.f x)).Covers y with ⟨z, hz⟩
    change x ∈ Set.range ((f (𝒰.f x)).map ((f (𝒰.f x)).f y) ≫ 𝒰.map (𝒰.f x)).1.base
    use z
    

Proof state:
case h
C : Type u
inst✝¹ : Category.{v, u} C
X Y Z : Scheme
𝒰 : OpenCover X
f✝ : X ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (map 𝒰 x ≫ f✝) g
f : (x : 𝒰.J) → OpenCover (obj 𝒰 x)
x : ↑↑X.toPresheafedSpace
y : (forget TopCat).obj ↑(obj 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).toPresheafedSpace :=
  Exists.choose (_ : x ∈ Set.range ⇑(map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base)
hy : (map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base y = x
z :
  (forget TopCat).obj
    ↑(obj (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
          (AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)) y)).toPresheafedSpace
hz :
  (map (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
            (AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)) y)).val.base
      z =
    y
⊢ (map (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
              (AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)) y) ≫
            map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base
      z =
    x

Next tactic:
erw [comp_apply]
/-- Given an open cover `{ Uᵢ }` of `X`, and for each `Uᵢ` an open cover, we may combine these
open covers to form an open cover of `X`.  -/
@[simps! J obj map]
def OpenCover.bind (f : ∀ x : 𝒰.J, OpenCover (𝒰.obj x)) : OpenCover X where
  J := Σ i : 𝒰.J, (f i).J
  obj x := (f x.1).obj x.2
  map x := (f x.1).map x.2 ≫ 𝒰.map x.1
  f x := ⟨_, (f _).f (𝒰.Covers x).choose⟩
  Covers x := by
    let y := (𝒰.Covers x).choose
    have hy : (𝒰.map (𝒰.f x)).val.base y = x := (𝒰.Covers x).choose_spec
    rcases (f (𝒰.f x)).Covers y with ⟨z, hz⟩
    change x ∈ Set.range ((f (𝒰.f x)).map ((f (𝒰.f x)).f y) ≫ 𝒰.map (𝒰.f x)).1.base
    use z
    erw [comp_apply]
    

Proof state:
case h
C : Type u
inst✝¹ : Category.{v, u} C
X Y Z : Scheme
𝒰 : OpenCover X
f✝ : X ⟶ Z
g : Y ⟶ Z
inst✝ : ∀ (x : 𝒰.J), HasPullback (map 𝒰 x ≫ f✝) g
f : (x : 𝒰.J) → OpenCover (obj 𝒰 x)
x : ↑↑X.toPresheafedSpace
y : (forget TopCat).obj ↑(obj 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).toPresheafedSpace :=
  Exists.choose (_ : x ∈ Set.range ⇑(map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base)
hy : (map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base y = x
z :
  (forget TopCat).obj
    ↑(obj (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
          (AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)) y)).toPresheafedSpace
hz :
  (map (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
            (AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)) y)).val.base
      z =
    y
⊢ (map 𝒰 (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)).val.base
      ((map (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x))
              (AlgebraicGeometry.Scheme.OpenCover.f (f (AlgebraicGeometry.Scheme.OpenCover.f 𝒰 x)) y)).val.base
        z) =
    x

Next tactic:
rw [hz, hy]
/-- An isomorphism `X ⟶ Y` is an open cover of `Y`. -/
@[simps J obj map]
def openCoverOfIsIso {X Y : Scheme.{u}} (f : X ⟶ Y) [IsIso f] : OpenCover Y where
  J := PUnit.{v + 1}
  obj _ := X
  map _ := f
  f _ := PUnit.unit
  Covers x := by
    

Proof state:
C : Type u
inst✝² : Category.{v, u} C
X✝ Y✝ Z : Scheme
𝒰 : OpenCover X✝
f✝ : X✝ ⟶ Z
g : Y✝ ⟶ Z
inst✝¹ : ∀ (x : 𝒰.J), HasPullback (OpenCover.map 𝒰 x ≫ f✝) g
X Y : Scheme
f : X ⟶ Y
inst✝ : IsIso f
x : ↑↑Y.toPresheafedSpace
⊢ x ∈ Set.range ⇑((fun x => f) ((fun x => PUnit.unit) x)).val.base

Next tactic:
rw [Set.range_iff_surjective.mpr]
/-- An isomorphism `X ⟶ Y` is an open cover of `Y`. -/
@[simps J obj map]
def openCoverOfIsIso {X Y : Scheme.{u}} (f : X ⟶ Y) [IsIso f] : OpenCover Y where
  J := PUnit.{v + 1}
  obj _ := X
  map _ := f
  f _ := PUnit.unit
  Covers x := by
    rw [Set.range_iff_surjective.mpr]
    

Proof state:
C : Type u
inst✝² : Category.{v, u} C
X✝ Y✝ Z : Scheme
𝒰 : OpenCover X✝
f✝ : X✝ ⟶ Z
g : Y✝ ⟶ Z
inst✝¹ : ∀ (x : 𝒰.J), HasPullback (OpenCover.map 𝒰 x ≫ f✝) g
X Y : Scheme
f : X ⟶ Y
inst✝ : IsIso f
x : ↑↑Y.toPresheafedSpace
⊢ x ∈ Set.univ
C : Type u
inst✝² : Category.{v, u} C
X✝ Y✝ Z : Scheme
𝒰 : OpenCover X✝
f✝ : X✝ ⟶ Z
g : Y✝ ⟶ Z
inst✝¹ : ∀ (x : 𝒰.J), HasPullback (OpenCover.map 𝒰 x ≫ f✝) g
X Y : Scheme
f : X ⟶ Y
inst✝ : IsIso f
x : ↑↑Y.toPresheafedSpace
⊢ Function.Surjective ⇑((fun x => f) ((fun x => PUnit.unit) x)).val.base

Next tactic:
all_goals try trivial
/-- An isomorphism `X ⟶ Y` is an open cover of `Y`. -/
@[simps J obj map]
def openCoverOfIsIso {X Y : Scheme.{u}} (f : X ⟶ Y) [IsIso f] : OpenCover Y where
  J := PUnit.{v + 1}
  obj _ := X
  map _ := f
  f _ := PUnit.unit
  Covers x := by
    rw [Set.range_iff_surjective.mpr]
    all_goals 

Proof state:
C : Type u
inst✝² : Category.{v, u} C
X✝ Y✝ Z : Scheme
𝒰 : OpenCover X✝
f✝ : X✝ ⟶ Z
g : Y✝ ⟶ Z
inst✝¹ : ∀ (x : 𝒰.J), HasPullback (OpenCover.map 𝒰 x ≫ f✝) g
X Y : Scheme
f : X ⟶ Y
inst✝ : IsIso f
x : ↑↑Y.toPresheafedSpace
⊢ x ∈ Set.univ

Next tactic:
try trivial
/-- An isomorphism `X ⟶ Y` is an open cover of `Y`. -/
@[simps J obj map]
def openCoverOfIsIso {X Y : Scheme.{u}} (f : X ⟶ Y) [IsIso f] : OpenCover Y where
  J := PUnit.{v + 1}
  obj _ := X
  map _ := f
  f _ := PUnit.unit
  Covers x := by
    rw [Set.range_iff_surjective.mpr]
    all_goals try 

Proof state:
C : Type u
inst✝² : Category.{v, u} C
X✝ Y✝ Z : Scheme
𝒰 : OpenCover X✝
f✝ : X✝ ⟶ Z
g : Y✝ ⟶ Z
inst✝¹ : ∀ (x : 𝒰.J), HasPullback (OpenCover.map 𝒰 x ≫ f✝) g
X Y : Scheme
f : X ⟶ Y
inst✝ : IsIso f
x : ↑↑Y.toPresheafedSpace
⊢ x ∈ Set.univ

Next tactic:
trivial
/-- An isomorphism `X ⟶ Y` is an open cover of `Y`. -/
@[simps J obj map]
def openCoverOfIsIso {X Y : Scheme.{u}} (f : X ⟶ Y) [IsIso f] : OpenCover Y where
  J := PUnit.{v + 1}
  obj _ := X
  map _ := f
  f _ := PUnit.unit
  Covers x := by
    rw [Set.range_iff_surjective.mpr]
    all_goals 

Proof state:
C : Type u
inst✝² : Category.{v, u} C
X✝ Y✝ Z : Scheme
𝒰 : OpenCover X✝
f✝ : X✝ ⟶ Z
g : Y✝ ⟶ Z
inst✝¹ : ∀ (x : 𝒰.J), HasPullback (OpenCover.map 𝒰 x ≫ f✝) g
X Y : Scheme
f : X ⟶ Y
inst✝ : IsIso f
x : ↑↑Y.toPresheafedSpace
⊢ Function.Surjective ⇑((fun x => f) ((fun x => PUnit.unit) x)).val.base

Next tactic:
try trivial