l3lab/ntp-mathlib huggingface dataset:
/-- Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.

Then `P` holds for every affine open of `X`.

This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/
@[elab_as_elim]
theorem of_affine_open_cover {X : Scheme} (V : X.affineOpens) (S : Set X.affineOpens)
    {P : X.affineOpens → Prop}
    (hP₁ : ∀ (U : X.affineOpens) (f : X.presheaf.obj <| op U.1), P U → P (X.affineBasicOpen f))
    (hP₂ :
      ∀ (U : X.affineOpens) (s : Finset (X.presheaf.obj <| op U))
        (_ : Ideal.span (s : Set (X.presheaf.obj <| op U)) = ⊤),
        (∀ f : s, P (X.affineBasicOpen f.1)) → P U)
    (hS : (⋃ i : S, i : Set X) = Set.univ) (hS' : ∀ U : S, P U) : P V := by
  classical
  have : ∀ (x : V.1), ∃ f : X.presheaf.obj <| op V.1,
      ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by
    intro x
    have : ↑x ∈ (Set.univ : Set X) := trivial
    rw [← hS] at this
    obtain ⟨W, hW⟩ := Set.mem_iUnion.mp this
    obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩
    refine' ⟨f, hf, _⟩
    convert hP₁ _ g (hS' W) using 1
    ext1
    exact e
  choose f hf₁ hf₂ using this
  

Proof state:
X : Scheme
V : ↑(Scheme.affineOpens X)
S : Set ↑(Scheme.affineOpens X)
P : ↑(Scheme.affineOpens X) → Prop
hP₁ : ∀ (U : ↑(Scheme.affineOpens X)) (f : ↑(X.presheaf.obj (op ↑U))), P U → P (Scheme.affineBasicOpen X f)
hP₂ :
  ∀ (U : ↑(Scheme.affineOpens X)) (s : Finset ↑(X.presheaf.obj (op ↑U))),
    Ideal.span ↑s = ⊤ → (∀ (f : { x // x ∈ s }), P (Scheme.affineBasicOpen X ↑f)) → P U
hS : ⋃ i, ↑↑↑i = Set.univ
hS' : ∀ (U : ↑S), P ↑U
f : ↥↑V → ↑(X.presheaf.obj (op ↑V))
hf₁ : ∀ (x : ↥↑V), ↑x ∈ X.basicOpen (f x)
hf₂ : ∀ (x : ↥↑V), P (Scheme.affineBasicOpen X (f x))
⊢ P V

Next tactic:
suffices Ideal.span (Set.range f) = ⊤ by
    obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this
    apply hP₂ V t ht₂
    rintro ⟨i, hi⟩
    obtain ⟨x, rfl⟩ := ht₁ hi
    exact hf₂ x
/-- Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.

Then `P` holds for every affine open of `X`.

This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/
@[elab_as_elim]
theorem of_affine_open_cover {X : Scheme} (V : X.affineOpens) (S : Set X.affineOpens)
    {P : X.affineOpens → Prop}
    (hP₁ : ∀ (U : X.affineOpens) (f : X.presheaf.obj <| op U.1), P U → P (X.affineBasicOpen f))
    (hP₂ :
      ∀ (U : X.affineOpens) (s : Finset (X.presheaf.obj <| op U))
        (_ : Ideal.span (s : Set (X.presheaf.obj <| op U)) = ⊤),
        (∀ f : s, P (X.affineBasicOpen f.1)) → P U)
    (hS : (⋃ i : S, i : Set X) = Set.univ) (hS' : ∀ U : S, P U) : P V := by
  classical
  have : ∀ (x : V.1), ∃ f : X.presheaf.obj <| op V.1,
      ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by
    intro x
    have : ↑x ∈ (Set.univ : Set X) := trivial
    rw [← hS] at this
    obtain ⟨W, hW⟩ := Set.mem_iUnion.mp this
    obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩
    refine' ⟨f, hf, _⟩
    convert hP₁ _ g (hS' W) using 1
    ext1
    exact e
  choose f hf₁ hf₂ using this
  suffices Ideal.span (Set.range f) = ⊤ by
    

Proof state:
X : Scheme
V : ↑(Scheme.affineOpens X)
S : Set ↑(Scheme.affineOpens X)
P : ↑(Scheme.affineOpens X) → Prop
hP₁ : ∀ (U : ↑(Scheme.affineOpens X)) (f : ↑(X.presheaf.obj (op ↑U))), P U → P (Scheme.affineBasicOpen X f)
hP₂ :
  ∀ (U : ↑(Scheme.affineOpens X)) (s : Finset ↑(X.presheaf.obj (op ↑U))),
    Ideal.span ↑s = ⊤ → (∀ (f : { x // x ∈ s }), P (Scheme.affineBasicOpen X ↑f)) → P U
hS : ⋃ i, ↑↑↑i = Set.univ
hS' : ∀ (U : ↑S), P ↑U
f : ↥↑V → ↑(X.presheaf.obj (op ↑V))
hf₁ : ∀ (x : ↥↑V), ↑x ∈ X.basicOpen (f x)
hf₂ : ∀ (x : ↥↑V), P (Scheme.affineBasicOpen X (f x))
this : Ideal.span (Set.range f) = ⊤
⊢ P V

Next tactic:
obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this
/-- Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.

Then `P` holds for every affine open of `X`.

This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/
@[elab_as_elim]
theorem of_affine_open_cover {X : Scheme} (V : X.affineOpens) (S : Set X.affineOpens)
    {P : X.affineOpens → Prop}
    (hP₁ : ∀ (U : X.affineOpens) (f : X.presheaf.obj <| op U.1), P U → P (X.affineBasicOpen f))
    (hP₂ :
      ∀ (U : X.affineOpens) (s : Finset (X.presheaf.obj <| op U))
        (_ : Ideal.span (s : Set (X.presheaf.obj <| op U)) = ⊤),
        (∀ f : s, P (X.affineBasicOpen f.1)) → P U)
    (hS : (⋃ i : S, i : Set X) = Set.univ) (hS' : ∀ U : S, P U) : P V := by
  classical
  have : ∀ (x : V.1), ∃ f : X.presheaf.obj <| op V.1,
      ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by
    intro x
    have : ↑x ∈ (Set.univ : Set X) := trivial
    rw [← hS] at this
    obtain ⟨W, hW⟩ := Set.mem_iUnion.mp this
    obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩
    refine' ⟨f, hf, _⟩
    convert hP₁ _ g (hS' W) using 1
    ext1
    exact e
  choose f hf₁ hf₂ using this
  suffices Ideal.span (Set.range f) = ⊤ by
    obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this
    

Proof state:
case intro.intro
X : Scheme
V : ↑(Scheme.affineOpens X)
S : Set ↑(Scheme.affineOpens X)
P : ↑(Scheme.affineOpens X) → Prop
hP₁ : ∀ (U : ↑(Scheme.affineOpens X)) (f : ↑(X.presheaf.obj (op ↑U))), P U → P (Scheme.affineBasicOpen X f)
hP₂ :
  ∀ (U : ↑(Scheme.affineOpens X)) (s : Finset ↑(X.presheaf.obj (op ↑U))),
    Ideal.span ↑s = ⊤ → (∀ (f : { x // x ∈ s }), P (Scheme.affineBasicOpen X ↑f)) → P U
hS : ⋃ i, ↑↑↑i = Set.univ
hS' : ∀ (U : ↑S), P ↑U
f : ↥↑V → ↑(X.presheaf.obj (op ↑V))
hf₁ : ∀ (x : ↥↑V), ↑x ∈ X.basicOpen (f x)
hf₂ : ∀ (x : ↥↑V), P (Scheme.affineBasicOpen X (f x))
this : Ideal.span (Set.range f) = ⊤
t : Finset ↑(X.presheaf.obj (op ↑V))
ht₁ : ↑t ⊆ Set.range f
ht₂ : Ideal.span ↑t = ⊤
⊢ P V

Next tactic:
apply hP₂ V t ht₂
/-- Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.

Then `P` holds for every affine open of `X`.

This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/
@[elab_as_elim]
theorem of_affine_open_cover {X : Scheme} (V : X.affineOpens) (S : Set X.affineOpens)
    {P : X.affineOpens → Prop}
    (hP₁ : ∀ (U : X.affineOpens) (f : X.presheaf.obj <| op U.1), P U → P (X.affineBasicOpen f))
    (hP₂ :
      ∀ (U : X.affineOpens) (s : Finset (X.presheaf.obj <| op U))
        (_ : Ideal.span (s : Set (X.presheaf.obj <| op U)) = ⊤),
        (∀ f : s, P (X.affineBasicOpen f.1)) → P U)
    (hS : (⋃ i : S, i : Set X) = Set.univ) (hS' : ∀ U : S, P U) : P V := by
  classical
  have : ∀ (x : V.1), ∃ f : X.presheaf.obj <| op V.1,
      ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by
    intro x
    have : ↑x ∈ (Set.univ : Set X) := trivial
    rw [← hS] at this
    obtain ⟨W, hW⟩ := Set.mem_iUnion.mp this
    obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩
    refine' ⟨f, hf, _⟩
    convert hP₁ _ g (hS' W) using 1
    ext1
    exact e
  choose f hf₁ hf₂ using this
  suffices Ideal.span (Set.range f) = ⊤ by
    obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this
    apply hP₂ V t ht₂
    

Proof state:
case intro.intro
X : Scheme
V : ↑(Scheme.affineOpens X)
S : Set ↑(Scheme.affineOpens X)
P : ↑(Scheme.affineOpens X) → Prop
hP₁ : ∀ (U : ↑(Scheme.affineOpens X)) (f : ↑(X.presheaf.obj (op ↑U))), P U → P (Scheme.affineBasicOpen X f)
hP₂ :
  ∀ (U : ↑(Scheme.affineOpens X)) (s : Finset ↑(X.presheaf.obj (op ↑U))),
    Ideal.span ↑s = ⊤ → (∀ (f : { x // x ∈ s }), P (Scheme.affineBasicOpen X ↑f)) → P U
hS : ⋃ i, ↑↑↑i = Set.univ
hS' : ∀ (U : ↑S), P ↑U
f : ↥↑V → ↑(X.presheaf.obj (op ↑V))
hf₁ : ∀ (x : ↥↑V), ↑x ∈ X.basicOpen (f x)
hf₂ : ∀ (x : ↥↑V), P (Scheme.affineBasicOpen X (f x))
this : Ideal.span (Set.range f) = ⊤
t : Finset ↑(X.presheaf.obj (op ↑V))
ht₁ : ↑t ⊆ Set.range f
ht₂ : Ideal.span ↑t = ⊤
⊢ ∀ (f : { x // x ∈ t }), P (Scheme.affineBasicOpen X ↑f)

Next tactic:
rintro ⟨i, hi⟩
/-- Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.

Then `P` holds for every affine open of `X`.

This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/
@[elab_as_elim]
theorem of_affine_open_cover {X : Scheme} (V : X.affineOpens) (S : Set X.affineOpens)
    {P : X.affineOpens → Prop}
    (hP₁ : ∀ (U : X.affineOpens) (f : X.presheaf.obj <| op U.1), P U → P (X.affineBasicOpen f))
    (hP₂ :
      ∀ (U : X.affineOpens) (s : Finset (X.presheaf.obj <| op U))
        (_ : Ideal.span (s : Set (X.presheaf.obj <| op U)) = ⊤),
        (∀ f : s, P (X.affineBasicOpen f.1)) → P U)
    (hS : (⋃ i : S, i : Set X) = Set.univ) (hS' : ∀ U : S, P U) : P V := by
  classical
  have : ∀ (x : V.1), ∃ f : X.presheaf.obj <| op V.1,
      ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by
    intro x
    have : ↑x ∈ (Set.univ : Set X) := trivial
    rw [← hS] at this
    obtain ⟨W, hW⟩ := Set.mem_iUnion.mp this
    obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩
    refine' ⟨f, hf, _⟩
    convert hP₁ _ g (hS' W) using 1
    ext1
    exact e
  choose f hf₁ hf₂ using this
  suffices Ideal.span (Set.range f) = ⊤ by
    obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this
    apply hP₂ V t ht₂
    rintro ⟨i, hi⟩
    

Proof state:
case intro.intro.mk
X : Scheme
V : ↑(Scheme.affineOpens X)
S : Set ↑(Scheme.affineOpens X)
P : ↑(Scheme.affineOpens X) → Prop
hP₁ : ∀ (U : ↑(Scheme.affineOpens X)) (f : ↑(X.presheaf.obj (op ↑U))), P U → P (Scheme.affineBasicOpen X f)
hP₂ :
  ∀ (U : ↑(Scheme.affineOpens X)) (s : Finset ↑(X.presheaf.obj (op ↑U))),
    Ideal.span ↑s = ⊤ → (∀ (f : { x // x ∈ s }), P (Scheme.affineBasicOpen X ↑f)) → P U
hS : ⋃ i, ↑↑↑i = Set.univ
hS' : ∀ (U : ↑S), P ↑U
f : ↥↑V → ↑(X.presheaf.obj (op ↑V))
hf₁ : ∀ (x : ↥↑V), ↑x ∈ X.basicOpen (f x)
hf₂ : ∀ (x : ↥↑V), P (Scheme.affineBasicOpen X (f x))
this : Ideal.span (Set.range f) = ⊤
t : Finset ↑(X.presheaf.obj (op ↑V))
ht₁ : ↑t ⊆ Set.range f
ht₂ : Ideal.span ↑t = ⊤
i : ↑(X.presheaf.obj (op ↑V))
hi : i ∈ t
⊢ P (Scheme.affineBasicOpen X ↑{ val := i, property := hi })

Next tactic:
obtain ⟨x, rfl⟩ := ht₁ hi
/-- Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.

Then `P` holds for every affine open of `X`.

This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/
@[elab_as_elim]
theorem of_affine_open_cover {X : Scheme} (V : X.affineOpens) (S : Set X.affineOpens)
    {P : X.affineOpens → Prop}
    (hP₁ : ∀ (U : X.affineOpens) (f : X.presheaf.obj <| op U.1), P U → P (X.affineBasicOpen f))
    (hP₂ :
      ∀ (U : X.affineOpens) (s : Finset (X.presheaf.obj <| op U))
        (_ : Ideal.span (s : Set (X.presheaf.obj <| op U)) = ⊤),
        (∀ f : s, P (X.affineBasicOpen f.1)) → P U)
    (hS : (⋃ i : S, i : Set X) = Set.univ) (hS' : ∀ U : S, P U) : P V := by
  classical
  have : ∀ (x : V.1), ∃ f : X.presheaf.obj <| op V.1,
      ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by
    intro x
    have : ↑x ∈ (Set.univ : Set X) := trivial
    rw [← hS] at this
    obtain ⟨W, hW⟩ := Set.mem_iUnion.mp this
    obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩
    refine' ⟨f, hf, _⟩
    convert hP₁ _ g (hS' W) using 1
    ext1
    exact e
  choose f hf₁ hf₂ using this
  suffices Ideal.span (Set.range f) = ⊤ by
    obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this
    apply hP₂ V t ht₂
    rintro ⟨i, hi⟩
    obtain ⟨x, rfl⟩ := ht₁ hi
    

Proof state:
case intro.intro.mk.intro
X : Scheme
V : ↑(Scheme.affineOpens X)
S : Set ↑(Scheme.affineOpens X)
P : ↑(Scheme.affineOpens X) → Prop
hP₁ : ∀ (U : ↑(Scheme.affineOpens X)) (f : ↑(X.presheaf.obj (op ↑U))), P U → P (Scheme.affineBasicOpen X f)
hP₂ :
  ∀ (U : ↑(Scheme.affineOpens X)) (s : Finset ↑(X.presheaf.obj (op ↑U))),
    Ideal.span ↑s = ⊤ → (∀ (f : { x // x ∈ s }), P (Scheme.affineBasicOpen X ↑f)) → P U
hS : ⋃ i, ↑↑↑i = Set.univ
hS' : ∀ (U : ↑S), P ↑U
f : ↥↑V → ↑(X.presheaf.obj (op ↑V))
hf₁ : ∀ (x : ↥↑V), ↑x ∈ X.basicOpen (f x)
hf₂ : ∀ (x : ↥↑V), P (Scheme.affineBasicOpen X (f x))
this : Ideal.span (Set.range f) = ⊤
t : Finset ↑(X.presheaf.obj (op ↑V))
ht₁ : ↑t ⊆ Set.range f
ht₂ : Ideal.span ↑t = ⊤
x : ↥↑V
hi : f x ∈ t
⊢ P (Scheme.affineBasicOpen X ↑{ val := f x, property := hi })

Next tactic:
exact hf₂ x
/-- Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.

Then `P` holds for every affine open of `X`.

This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/
@[elab_as_elim]
theorem of_affine_open_cover {X : Scheme} (V : X.affineOpens) (S : Set X.affineOpens)
    {P : X.affineOpens → Prop}
    (hP₁ : ∀ (U : X.affineOpens) (f : X.presheaf.obj <| op U.1), P U → P (X.affineBasicOpen f))
    (hP₂ :
      ∀ (U : X.affineOpens) (s : Finset (X.presheaf.obj <| op U))
        (_ : Ideal.span (s : Set (X.presheaf.obj <| op U)) = ⊤),
        (∀ f : s, P (X.affineBasicOpen f.1)) → P U)
    (hS : (⋃ i : S, i : Set X) = Set.univ) (hS' : ∀ U : S, P U) : P V := by
  classical
  have : ∀ (x : V.1), ∃ f : X.presheaf.obj <| op V.1,
      ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by
    intro x
    have : ↑x ∈ (Set.univ : Set X) := trivial
    rw [← hS] at this
    obtain ⟨W, hW⟩ := Set.mem_iUnion.mp this
    obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩
    refine' ⟨f, hf, _⟩
    convert hP₁ _ g (hS' W) using 1
    ext1
    exact e
  choose f hf₁ hf₂ using this
  suffices Ideal.span (Set.range f) = ⊤ by
    obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this
    apply hP₂ V t ht₂
    rintro ⟨i, hi⟩
    obtain ⟨x, rfl⟩ := ht₁ hi
    exact hf₂ x
  

Proof state:
X : Scheme
V : ↑(Scheme.affineOpens X)
S : Set ↑(Scheme.affineOpens X)
P : ↑(Scheme.affineOpens X) → Prop
hP₁ : ∀ (U : ↑(Scheme.affineOpens X)) (f : ↑(X.presheaf.obj (op ↑U))), P U → P (Scheme.affineBasicOpen X f)
hP₂ :
  ∀ (U : ↑(Scheme.affineOpens X)) (s : Finset ↑(X.presheaf.obj (op ↑U))),
    Ideal.span ↑s = ⊤ → (∀ (f : { x // x ∈ s }), P (Scheme.affineBasicOpen X ↑f)) → P U
hS : ⋃ i, ↑↑↑i = Set.univ
hS' : ∀ (U : ↑S), P ↑U
f : ↥↑V → ↑(X.presheaf.obj (op ↑V))
hf₁ : ∀ (x : ↥↑V), ↑x ∈ X.basicOpen (f x)
hf₂ : ∀ (x : ↥↑V), P (Scheme.affineBasicOpen X (f x))
⊢ Ideal.span (Set.range f) = ⊤

Next tactic:
rw [← V.prop.self_le_basicOpen_union_iff]
/-- Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.

Then `P` holds for every affine open of `X`.

This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/
@[elab_as_elim]
theorem of_affine_open_cover {X : Scheme} (V : X.affineOpens) (S : Set X.affineOpens)
    {P : X.affineOpens → Prop}
    (hP₁ : ∀ (U : X.affineOpens) (f : X.presheaf.obj <| op U.1), P U → P (X.affineBasicOpen f))
    (hP₂ :
      ∀ (U : X.affineOpens) (s : Finset (X.presheaf.obj <| op U))
        (_ : Ideal.span (s : Set (X.presheaf.obj <| op U)) = ⊤),
        (∀ f : s, P (X.affineBasicOpen f.1)) → P U)
    (hS : (⋃ i : S, i : Set X) = Set.univ) (hS' : ∀ U : S, P U) : P V := by
  classical
  have : ∀ (x : V.1), ∃ f : X.presheaf.obj <| op V.1,
      ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by
    intro x
    have : ↑x ∈ (Set.univ : Set X) := trivial
    rw [← hS] at this
    obtain ⟨W, hW⟩ := Set.mem_iUnion.mp this
    obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩
    refine' ⟨f, hf, _⟩
    convert hP₁ _ g (hS' W) using 1
    ext1
    exact e
  choose f hf₁ hf₂ using this
  suffices Ideal.span (Set.range f) = ⊤ by
    obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this
    apply hP₂ V t ht₂
    rintro ⟨i, hi⟩
    obtain ⟨x, rfl⟩ := ht₁ hi
    exact hf₂ x
  rw [← V.prop.self_le_basicOpen_union_iff]
  

Proof state:
X : Scheme
V : ↑(Scheme.affineOpens X)
S : Set ↑(Scheme.affineOpens X)
P : ↑(Scheme.affineOpens X) → Prop
hP₁ : ∀ (U : ↑(Scheme.affineOpens X)) (f : ↑(X.presheaf.obj (op ↑U))), P U → P (Scheme.affineBasicOpen X f)
hP₂ :
  ∀ (U : ↑(Scheme.affineOpens X)) (s : Finset ↑(X.presheaf.obj (op ↑U))),
    Ideal.span ↑s = ⊤ → (∀ (f : { x // x ∈ s }), P (Scheme.affineBasicOpen X ↑f)) → P U
hS : ⋃ i, ↑↑↑i = Set.univ
hS' : ∀ (U : ↑S), P ↑U
f : ↥↑V → ↑(X.presheaf.obj (op ↑V))
hf₁ : ∀ (x : ↥↑V), ↑x ∈ X.basicOpen (f x)
hf₂ : ∀ (x : ↥↑V), P (Scheme.affineBasicOpen X (f x))
⊢ ↑V ≤ ⨆ f_1, X.basicOpen ↑f_1

Next tactic:
intro x hx
/-- Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.

Then `P` holds for every affine open of `X`.

This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/
@[elab_as_elim]
theorem of_affine_open_cover {X : Scheme} (V : X.affineOpens) (S : Set X.affineOpens)
    {P : X.affineOpens → Prop}
    (hP₁ : ∀ (U : X.affineOpens) (f : X.presheaf.obj <| op U.1), P U → P (X.affineBasicOpen f))
    (hP₂ :
      ∀ (U : X.affineOpens) (s : Finset (X.presheaf.obj <| op U))
        (_ : Ideal.span (s : Set (X.presheaf.obj <| op U)) = ⊤),
        (∀ f : s, P (X.affineBasicOpen f.1)) → P U)
    (hS : (⋃ i : S, i : Set X) = Set.univ) (hS' : ∀ U : S, P U) : P V := by
  classical
  have : ∀ (x : V.1), ∃ f : X.presheaf.obj <| op V.1,
      ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by
    intro x
    have : ↑x ∈ (Set.univ : Set X) := trivial
    rw [← hS] at this
    obtain ⟨W, hW⟩ := Set.mem_iUnion.mp this
    obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩
    refine' ⟨f, hf, _⟩
    convert hP₁ _ g (hS' W) using 1
    ext1
    exact e
  choose f hf₁ hf₂ using this
  suffices Ideal.span (Set.range f) = ⊤ by
    obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this
    apply hP₂ V t ht₂
    rintro ⟨i, hi⟩
    obtain ⟨x, rfl⟩ := ht₁ hi
    exact hf₂ x
  rw [← V.prop.self_le_basicOpen_union_iff]
  intro x hx
  

Proof state:
X : Scheme
V : ↑(Scheme.affineOpens X)
S : Set ↑(Scheme.affineOpens X)
P : ↑(Scheme.affineOpens X) → Prop
hP₁ : ∀ (U : ↑(Scheme.affineOpens X)) (f : ↑(X.presheaf.obj (op ↑U))), P U → P (Scheme.affineBasicOpen X f)
hP₂ :
  ∀ (U : ↑(Scheme.affineOpens X)) (s : Finset ↑(X.presheaf.obj (op ↑U))),
    Ideal.span ↑s = ⊤ → (∀ (f : { x // x ∈ s }), P (Scheme.affineBasicOpen X ↑f)) → P U
hS : ⋃ i, ↑↑↑i = Set.univ
hS' : ∀ (U : ↑S), P ↑U
f : ↥↑V → ↑(X.presheaf.obj (op ↑V))
hf₁ : ∀ (x : ↥↑V), ↑x ∈ X.basicOpen (f x)
hf₂ : ∀ (x : ↥↑V), P (Scheme.affineBasicOpen X (f x))
x : ↑↑X.toPresheafedSpace
hx : x ∈ ↑↑V
⊢ x ∈ ↑(⨆ f_1, X.basicOpen ↑f_1)

Next tactic:
rw [iSup_range', SetLike.mem_coe, Opens.mem_iSup]
/-- Let `P` be a predicate on the affine open sets of `X` satisfying
1. If `P` holds on `U`, then `P` holds on the basic open set of every section on `U`.
2. If `P` holds for a family of basic open sets covering `U`, then `P` holds for `U`.
3. There exists an affine open cover of `X` each satisfying `P`.

Then `P` holds for every affine open of `X`.

This is also known as the **Affine communication lemma** in [*The rising sea*][RisingSea]. -/
@[elab_as_elim]
theorem of_affine_open_cover {X : Scheme} (V : X.affineOpens) (S : Set X.affineOpens)
    {P : X.affineOpens → Prop}
    (hP₁ : ∀ (U : X.affineOpens) (f : X.presheaf.obj <| op U.1), P U → P (X.affineBasicOpen f))
    (hP₂ :
      ∀ (U : X.affineOpens) (s : Finset (X.presheaf.obj <| op U))
        (_ : Ideal.span (s : Set (X.presheaf.obj <| op U)) = ⊤),
        (∀ f : s, P (X.affineBasicOpen f.1)) → P U)
    (hS : (⋃ i : S, i : Set X) = Set.univ) (hS' : ∀ U : S, P U) : P V := by
  classical
  have : ∀ (x : V.1), ∃ f : X.presheaf.obj <| op V.1,
      ↑x ∈ X.basicOpen f ∧ P (X.affineBasicOpen f) := by
    intro x
    have : ↑x ∈ (Set.univ : Set X) := trivial
    rw [← hS] at this
    obtain ⟨W, hW⟩ := Set.mem_iUnion.mp this
    obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩
    refine' ⟨f, hf, _⟩
    convert hP₁ _ g (hS' W) using 1
    ext1
    exact e
  choose f hf₁ hf₂ using this
  suffices Ideal.span (Set.range f) = ⊤ by
    obtain ⟨t, ht₁, ht₂⟩ := (Ideal.span_eq_top_iff_finite _).mp this
    apply hP₂ V t ht₂
    rintro ⟨i, hi⟩
    obtain ⟨x, rfl⟩ := ht₁ hi
    exact hf₂ x
  rw [← V.prop.self_le_basicOpen_union_iff]
  intro x hx
  rw [iSup_range', SetLike.mem_coe, Opens.mem_iSup]
  

Proof state:
X : Scheme
V : ↑(Scheme.affineOpens X)
S : Set ↑(Scheme.affineOpens X)
P : ↑(Scheme.affineOpens X) → Prop
hP₁ : ∀ (U : ↑(Scheme.affineOpens X)) (f : ↑(X.presheaf.obj (op ↑U))), P U → P (Scheme.affineBasicOpen X f)
hP₂ :
  ∀ (U : ↑(Scheme.affineOpens X)) (s : Finset ↑(X.presheaf.obj (op ↑U))),
    Ideal.span ↑s = ⊤ → (∀ (f : { x // x ∈ s }), P (Scheme.affineBasicOpen X ↑f)) → P U
hS : ⋃ i, ↑↑↑i = Set.univ
hS' : ∀ (U : ↑S), P ↑U
f : ↥↑V → ↑(X.presheaf.obj (op ↑V))
hf₁ : ∀ (x : ↥↑V), ↑x ∈ X.basicOpen (f x)
hf₂ : ∀ (x : ↥↑V), P (Scheme.affineBasicOpen X (f x))
x : ↑↑X.toPresheafedSpace
hx : x ∈ ↑↑V
⊢ ∃ i, x ∈ X.basicOpen (f i)

Next tactic:
exact ⟨_, hf₁ ⟨x, hx⟩⟩