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
  

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
⊢ P V

Next tactic:
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]
  exact ⟨_, hf₁ ⟨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
  

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
⊢ P V

Next tactic:
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
/-- 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
    

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
⊢ ∀ (x : ↥↑V), ∃ f, ↑x ∈ X.basicOpen f ∧ P (Scheme.affineBasicOpen X f)

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

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
x : ↥↑V
⊢ ∃ f, ↑x ∈ X.basicOpen f ∧ P (Scheme.affineBasicOpen X f)

Next tactic:
have : ↑x ∈ (Set.univ : Set X) := trivial
/-- 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
    

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
x : ↥↑V
this : ↑x ∈ Set.univ
⊢ ∃ f, ↑x ∈ X.basicOpen f ∧ P (Scheme.affineBasicOpen X f)

Next tactic:
rw [← hS] at 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
    

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
x : ↥↑V
this : ↑x ∈ ⋃ i, ↑↑↑i
⊢ ∃ f, ↑x ∈ X.basicOpen f ∧ P (Scheme.affineBasicOpen X f)

Next tactic:
obtain ⟨W, hW⟩ := Set.mem_iUnion.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
    

Proof state:
case 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
x : ↥↑V
this : ↑x ∈ ⋃ i, ↑↑↑i
W : ↑S
hW : ↑x ∈ ↑↑↑W
⊢ ∃ f, ↑x ∈ X.basicOpen f ∧ P (Scheme.affineBasicOpen X f)

Next tactic:
obtain ⟨f, g, e, hf⟩ := exists_basicOpen_le_affine_inter V.prop W.1.prop x ⟨x.prop, hW⟩
/-- 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⟩
    

Proof state:
case intro.intro.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
x : ↥↑V
this : ↑x ∈ ⋃ i, ↑↑↑i
W : ↑S
hW : ↑x ∈ ↑↑↑W
f : ↑(X.presheaf.obj (op ↑V))
g : ↑(X.presheaf.obj (op ↑↑W))
e : X.basicOpen f = X.basicOpen g
hf : ↑x ∈ X.basicOpen f
⊢ ∃ f, ↑x ∈ X.basicOpen f ∧ P (Scheme.affineBasicOpen X f)

Next tactic:
refine' ⟨f, hf, _⟩
/-- 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, _⟩
    

Proof state:
case intro.intro.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
x : ↥↑V
this : ↑x ∈ ⋃ i, ↑↑↑i
W : ↑S
hW : ↑x ∈ ↑↑↑W
f : ↑(X.presheaf.obj (op ↑V))
g : ↑(X.presheaf.obj (op ↑↑W))
e : X.basicOpen f = X.basicOpen g
hf : ↑x ∈ X.basicOpen f
⊢ P (Scheme.affineBasicOpen X f)

Next tactic:
convert hP₁ _ g (hS' W) using 1
/-- 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
    

Proof state:
case h.e'_1
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
x : ↥↑V
this : ↑x ∈ ⋃ i, ↑↑↑i
W : ↑S
hW : ↑x ∈ ↑↑↑W
f : ↑(X.presheaf.obj (op ↑V))
g : ↑(X.presheaf.obj (op ↑↑W))
e : X.basicOpen f = X.basicOpen g
hf : ↑x ∈ X.basicOpen f
⊢ Scheme.affineBasicOpen X f = Scheme.affineBasicOpen X g

Next tactic:
ext1
/-- 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
    

Proof state:
case h.e'_1.a
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
x : ↥↑V
this : ↑x ∈ ⋃ i, ↑↑↑i
W : ↑S
hW : ↑x ∈ ↑↑↑W
f : ↑(X.presheaf.obj (op ↑V))
g : ↑(X.presheaf.obj (op ↑↑W))
e : X.basicOpen f = X.basicOpen g
hf : ↑x ∈ X.basicOpen f
⊢ ↑(Scheme.affineBasicOpen X f) = ↑(Scheme.affineBasicOpen X g)

Next tactic:
exact e
/-- 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
  

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
this : ∀ (x : ↥↑V), ∃ f, ↑x ∈ X.basicOpen f ∧ P (Scheme.affineBasicOpen X f)
⊢ P V

Next tactic:
choose f hf₁ hf₂ using this