Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(algebraic_geometry): Quasi-compact morphisms #11448

Closed
wants to merge 250 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
250 commits
Select commit Hold shift + click to select a range
f0f2cb9
First commit
erdOne Oct 21, 2021
985ad83
Added docs
erdOne Oct 21, 2021
4f969a9
Removed a period
erdOne Oct 21, 2021
a2ec43b
Fix stuff.
erdOne Oct 21, 2021
4dc191a
Fix more stuff.
erdOne Oct 21, 2021
44923ec
draft stash
erdOne Oct 24, 2021
7778644
Changed sets into immersions
erdOne Oct 24, 2021
a4236a9
split from #9864
erdOne Oct 26, 2021
d58c5f7
split from #9864
erdOne Oct 26, 2021
30c2800
fix
erdOne Oct 27, 2021
510362c
Apply suggestions from code review
erdOne Oct 27, 2021
d06006d
fix more
erdOne Oct 27, 2021
ab4a96c
Added statements for pushout
erdOne Oct 27, 2021
6a306cd
removed `#lint`.
erdOne Oct 27, 2021
ea090a1
commit
erdOne Oct 27, 2021
760dad2
added stuff
erdOne Oct 27, 2021
1a53778
Fix lints
erdOne Oct 27, 2021
e336dc2
Merge branch 'Top_colim_api_for_glue' into presheafed_spaces_glue
erdOne Oct 27, 2021
1ef8fca
Merge branch 'pullback_api_for_glue' into Top_colim_api_for_glue
erdOne Oct 27, 2021
4ff8b50
Added stuff
erdOne Oct 27, 2021
5dfef2a
Merge branch 'Top_colim_api_for_glue' into presheafed_spaces_glue
erdOne Oct 27, 2021
f3e1e4e
oops
erdOne Oct 27, 2021
3614f2c
Merge branch 'Top_colim_api_for_glue' into presheafed_spaces_glue
erdOne Oct 27, 2021
d758d7b
oops
erdOne Oct 27, 2021
4193611
commit
erdOne Oct 27, 2021
0971d3b
commit
erdOne Oct 27, 2021
da18476
fix
erdOne Oct 27, 2021
c88c567
Empty commit
erdOne Oct 27, 2021
704c93d
Merge remote-tracking branch 'origin/master' into presheafed_spaces_glue
erdOne Oct 27, 2021
3759f20
fix
erdOne Oct 27, 2021
00ffa8b
finished some stuff
erdOne Oct 29, 2021
35774df
Finished things about open immersions.
erdOne Oct 31, 2021
f445fae
Clean up
erdOne Oct 31, 2021
a9ed5e5
Clean up
erdOne Oct 31, 2021
3bde1ae
Fix
erdOne Oct 31, 2021
81eb7b5
Merge remote-tracking branch 'origin/pullback_api_for_glue' into Top_…
erdOne Oct 31, 2021
1718f1c
Merge branch 'Top_colim_api_for_glue' of https://github.com/leanprove…
erdOne Oct 31, 2021
ba9c331
typo
erdOne Oct 31, 2021
d066a7a
Merge branch 'master' into Top_colim_api_for_glue
erdOne Oct 31, 2021
572cd26
Merge remote-tracking branch 'origin/master' into Top_colim_api_for_glue
erdOne Oct 31, 2021
2943722
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Oct 31, 2021
7fd9250
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Oct 31, 2021
3933d1e
Rename coprod_iso_sigma to sigma_iso_sigma
erdOne Oct 31, 2021
141b40e
Changed definitions
erdOne Nov 3, 2021
2bfef11
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Nov 3, 2021
de485c7
Merge branch 'gluing_spaces' into presheafed_spaces_glue
erdOne Nov 4, 2021
17d54f6
Add file
adamtopaz Nov 4, 2021
334b0cc
Update src/category_theory/limits/shapes/binary_products.lean
erdOne Nov 4, 2021
903c1d1
fix
erdOne Nov 4, 2021
5260523
for now
erdOne Nov 4, 2021
ebcaa0f
fix
erdOne Nov 4, 2021
86c8e9c
fix style
erdOne Nov 4, 2021
33a9958
fix stuff
erdOne Nov 4, 2021
22d89c8
more fix
erdOne Nov 4, 2021
d22459c
fix
erdOne Nov 4, 2021
d8a09d9
Merge branch 'Top_colim_api_for_glue' of https://github.com/leanprove…
erdOne Nov 4, 2021
afa5fd3
Adam's comments
erdOne Nov 5, 2021
2c90ffd
Apply suggestions from code review
erdOne Nov 5, 2021
1bfbbfb
Merge branch 'Top_colim_api_for_glue' into gluing_spaces
erdOne Nov 5, 2021
9a56af4
Merge remote-tracking branch 'origin/multifork' into gluing_spaces
erdOne Nov 5, 2021
a2adaf9
Merge remote-tracking branch 'origin/master' into gluing_spaces
erdOne Nov 5, 2021
90b2912
temp fix
erdOne Nov 5, 2021
f563bcf
first commit
erdOne Nov 5, 2021
58cbd02
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Nov 5, 2021
4e1334a
fix
erdOne Nov 5, 2021
bf549d1
fix
erdOne Nov 5, 2021
f6088ad
fix
erdOne Nov 5, 2021
1e4083e
fixing
erdOne Nov 5, 2021
a9fc24e
for now
erdOne Nov 5, 2021
94d029e
Adam's comments.
erdOne Nov 5, 2021
0fc6c8b
Merge branch 'Top_colim_api_for_glue' of https://github.com/leanprove…
erdOne Nov 5, 2021
bcaaec5
Merge branch 'Top_colim_api_for_glue' into Presheafed_space_open_imme…
erdOne Nov 5, 2021
9c2a15f
for now
erdOne Nov 5, 2021
695a4df
for now
erdOne Nov 5, 2021
0a2a1ad
typo
erdOne Nov 5, 2021
8fa77ed
open immersions stable under base change
erdOne Nov 6, 2021
7845aeb
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Nov 6, 2021
650a9e5
lemmas about top limits
erdOne Nov 6, 2021
e53af9c
open immersions gives stalk iso
erdOne Nov 6, 2021
e729c9f
fix
erdOne Nov 6, 2021
054173c
Add docs and clean up.
erdOne Nov 6, 2021
e2ea9e3
clean up presheafed_space.lean
erdOne Nov 6, 2021
a8a0748
Add space
erdOne Nov 6, 2021
b826be9
Fix space
erdOne Nov 6, 2021
19c5416
fix
erdOne Nov 6, 2021
ce28998
Merge branch 'Presheafed_space_open_immersion' of https://github.com/…
erdOne Nov 6, 2021
44eef3d
Merge branch 'Presheafed_space_open_immersion' of https://github.com/…
erdOne Nov 7, 2021
7d2e261
testing ground
erdOne Nov 8, 2021
41b2284
first commit
erdOne Nov 9, 2021
c034043
fixing here and there
erdOne Nov 10, 2021
eaa8c06
new file: cone_category
erdOne Nov 10, 2021
69ec021
Merge branch 'multiequalizer_iso_equalizer' into gluing_spaces
erdOne Nov 10, 2021
e7b719e
Merge branch 'Top_colim_api_for_glue' into gluing_spaces
erdOne Nov 10, 2021
26ab0b3
fix
erdOne Nov 10, 2021
9424445
add stuff
erdOne Nov 11, 2021
a126f0c
add docs
erdOne Nov 11, 2021
c0ff2c5
add stuff
erdOne Nov 11, 2021
efdde74
Oops
erdOne Nov 11, 2021
4da6a76
Merge branch 'gluing_spaces' into presheafed_spaces_glue
erdOne Nov 11, 2021
e5b241a
fix
erdOne Nov 11, 2021
8598d8e
Merge branch 'Presheafed_space_open_immersion' into presheafed_spaces…
erdOne Nov 11, 2021
06447bb
sheaf space
erdOne Nov 11, 2021
e6679c8
Merge branch 'Presheafed_space_open_immersion' into presheafed_spaces…
erdOne Nov 11, 2021
0572262
removed stuff sadly
erdOne Nov 11, 2021
4420a52
fix
erdOne Nov 11, 2021
f720ac6
Merge branch 'Presheafed_space_open_immersion' into presheafed_spaces…
erdOne Nov 11, 2021
bd92312
fix
erdOne Nov 12, 2021
4a97239
refactor in progress
erdOne Nov 12, 2021
22f6db6
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Nov 17, 2021
8cf4f5b
add simp lemmas
erdOne Nov 17, 2021
48f041a
Finished `imm_is_open_embedding`
erdOne Nov 20, 2021
54be19c
Merge branch 'multiequalizer_iso_equalizer' into presheafed_spaces_glue
erdOne Nov 20, 2021
a8e847e
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Nov 20, 2021
2ca99ca
first commit
erdOne Nov 21, 2021
f128459
Merge branch 'Top_sheaf_limit' into presheafed_spaces_glue
erdOne Nov 21, 2021
2ab7f1e
fix
erdOne Nov 21, 2021
2804255
fix
erdOne Nov 21, 2021
067c43e
fix
erdOne Nov 21, 2021
d53727e
Added stuff for open immersions of LRS.
erdOne Nov 21, 2021
2eea0c4
Moved `open_immersion.lean`.
erdOne Nov 21, 2021
5cdfb35
fix
erdOne Nov 22, 2021
9e24939
Adding stuff for scheme
erdOne Nov 22, 2021
a7cfa3e
commit
erdOne Nov 22, 2021
a256139
add stuff
erdOne Nov 22, 2021
296310d
add stuff
erdOne Nov 23, 2021
3871a66
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Nov 23, 2021
aaf2c6d
finished for now
erdOne Nov 24, 2021
1a9dcd6
Add stuff for localization
erdOne Nov 24, 2021
a7081bd
basic open is open immersion
erdOne Nov 24, 2021
6d67d24
immersions of Schemes
erdOne Nov 24, 2021
beba162
glue Schemes
erdOne Nov 25, 2021
96d3394
finished gluing schemes
erdOne Nov 25, 2021
3d86481
Merge branch 'presheafed_spaces_glue' into open_subfunctor
erdOne Nov 25, 2021
71dc293
adding stuff here and there
erdOne Nov 26, 2021
452c63d
add stuff
erdOne Nov 26, 2021
ad1c95b
coproduct sigma is open immersion
erdOne Nov 26, 2021
c2c7bc8
finish stuff
erdOne Nov 26, 2021
3097c48
commit
erdOne Nov 26, 2021
d567cac
add stuff
erdOne Nov 26, 2021
20448f5
new stuff
erdOne Nov 27, 2021
26f5186
fix
erdOne Nov 27, 2021
7d79a86
add stuff
erdOne Nov 27, 2021
09bbd03
add stuff
erdOne Nov 27, 2021
9d4e0bf
fix
erdOne Nov 27, 2021
d2b16d3
fix
erdOne Nov 27, 2021
a1d4f80
Merge branch 'presheafed_spaces_glue' into open_subfunctor
erdOne Nov 27, 2021
671b50e
commit
erdOne Nov 30, 2021
888f43a
add stuff
erdOne Nov 30, 2021
0753067
commit
erdOne Dec 1, 2021
2eeb86d
we have fiber products!
erdOne Dec 2, 2021
17d780e
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Dec 3, 2021
519b039
fix
erdOne Dec 3, 2021
433e622
Update constructions.lean
erdOne Dec 4, 2021
26992c7
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Dec 4, 2021
b655f3c
moved lemmas to its homes
erdOne Dec 4, 2021
383951c
commented out stuff
erdOne Dec 4, 2021
1637c1a
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Dec 4, 2021
519180e
merge
erdOne Dec 4, 2021
a9ae464
fix
erdOne Dec 4, 2021
3001217
more fix
erdOne Dec 4, 2021
fd4d664
moe fix
erdOne Dec 4, 2021
aad68b2
is this faster?
erdOne Dec 4, 2021
d6a95f3
oops
erdOne Dec 4, 2021
6c3577f
rename
erdOne Dec 4, 2021
270e2e6
fix
erdOne Dec 4, 2021
67d2b64
remove comments
erdOne Dec 4, 2021
130c2a9
fix
erdOne Dec 5, 2021
23e0205
faster?
erdOne Dec 5, 2021
b5f41ce
fix
erdOne Dec 5, 2021
2e38386
why?
erdOne Dec 5, 2021
b20179c
why??
erdOne Dec 5, 2021
42a90f8
refactor open cover
erdOne Dec 6, 2021
4844b1b
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Dec 12, 2021
894c908
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Dec 14, 2021
64bca2a
fix
erdOne Dec 14, 2021
2f837c6
fix
erdOne Dec 14, 2021
70b4d9b
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Dec 20, 2021
ba55099
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Dec 20, 2021
c8f2721
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Dec 26, 2021
aa1c450
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Jan 6, 2022
b1ef2a6
update gluing.lean
erdOne Jan 6, 2022
e7a3abf
clean up
erdOne Jan 6, 2022
0c55899
clean up
erdOne Jan 6, 2022
2963fc3
fix stuff
erdOne Jan 6, 2022
206e35b
Merge branch 'master' into open_subfunctor
erdOne Jan 7, 2022
38b90a1
tidy up
erdOne Jan 7, 2022
eb2c95c
fix
erdOne Jan 7, 2022
4283e19
fix
erdOne Jan 7, 2022
522c363
first commit
erdOne Jan 8, 2022
fdebd43
add docs
erdOne Jan 9, 2022
be45bc2
add stuff
erdOne Jan 10, 2022
dcc1437
more affine stuff
erdOne Jan 12, 2022
c5bded7
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Jan 12, 2022
5b161e5
fix
erdOne Jan 12, 2022
ca9480d
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Jan 13, 2022
ab22672
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Jan 14, 2022
7315692
move stuff
erdOne Jan 14, 2022
f49386c
fix
erdOne Jan 14, 2022
4b75ad7
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Jan 14, 2022
bed58c2
tidy stuff
erdOne Jan 14, 2022
4031286
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Jan 14, 2022
047d4d2
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Jan 23, 2022
e8aa9f9
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Jan 24, 2022
7f0a865
clean up
erdOne Jan 24, 2022
edd41ee
fix
erdOne Jan 24, 2022
b3d7c95
fix lint
erdOne Jan 24, 2022
c2a7bfd
add open cover of stuff
erdOne Jan 26, 2022
40c919c
move stuff
erdOne Jan 26, 2022
87713bc
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Jan 27, 2022
4bcfe91
move stuff
erdOne Jan 27, 2022
f3f69e6
new stuff
erdOne Jan 27, 2022
3690355
add stuff
erdOne Jan 29, 2022
58cb7fd
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Jan 29, 2022
4cc29d1
add stuff
erdOne Jan 30, 2022
6e45311
rename file
erdOne Jan 30, 2022
658f1cd
Merge branch 'master' into scheme_pullback_cover
erdOne Jan 30, 2022
b353d53
fix
erdOne Jan 30, 2022
320f0d9
fix
erdOne Jan 30, 2022
da08452
Update pullbacks.lean
erdOne Jan 30, 2022
328a226
Update pullbacks.lean
erdOne Jan 30, 2022
ee30e17
Update pullbacks.lean
erdOne Jan 30, 2022
50ee629
Update pullbacks.lean
erdOne Jan 30, 2022
b47c6d6
Merge branch 'scheme_pullback_cover' into scheme_morphimsms
erdOne Jan 30, 2022
c7abc1d
Merge remote-tracking branch 'origin/scheme_pullback_cover' into sche…
erdOne Jan 30, 2022
57da8a7
add stuff
erdOne Jan 30, 2022
a82a022
fix
erdOne Jan 31, 2022
35e16a8
add more stuff
erdOne Feb 1, 2022
de4bf97
more stuff
erdOne Feb 4, 2022
3a9935b
fix
erdOne Feb 4, 2022
f0cba2a
add more
erdOne Feb 6, 2022
9a54b6a
add stuff
erdOne Feb 12, 2022
54a5f75
move stuff
erdOne Feb 12, 2022
fa5de86
fix
erdOne Feb 12, 2022
63e4fca
fix timeout
erdOne Feb 12, 2022
8852fa2
fix more
erdOne Feb 12, 2022
5f5fe57
fix & move stuff
erdOne Feb 12, 2022
1f1a55f
rename
erdOne Feb 12, 2022
159450e
fix
erdOne Feb 12, 2022
33f44ec
fix & move
erdOne Feb 12, 2022
690c92f
more new stuff
erdOne Feb 15, 2022
c75aad9
fix
erdOne Feb 15, 2022
3bc85bb
new stuff
erdOne Feb 17, 2022
d35373f
Merge branch 'master' of https://github.com/leanprover-community/math…
erdOne Feb 17, 2022
1bac5de
fix
erdOne Feb 17, 2022
870ccb3
oops
erdOne Mar 1, 2022
d882918
fix proof
erdOne Mar 1, 2022
3d969ce
add stuff
erdOne Mar 1, 2022
35756f1
rename
erdOne Mar 1, 2022
1e60798
fix stuff
erdOne Mar 1, 2022
cba7edd
new stuff
erdOne Mar 5, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/algebra/category/CommRing/basic.lean
Expand Up @@ -152,6 +152,11 @@ instance (R : CommRing) : comm_ring R := R.str

@[simp] lemma coe_of (R : Type u) [comm_ring R] : (CommRing.of R : Type u) = R := rfl

/-- A `R : CommRing` is isomorphic (actually equal) to `CommRing.of R`. -/
@[simps] def iso_of (R : CommRing) : R ≅ CommRing.of R :=
{ hom := ring_hom.id R,
inv := ring_hom.id R }

instance has_forget_to_Ring : has_forget₂ CommRing Ring := bundled_hom.forget₂ _ _

/-- The forgetful functor from commutative rings to (multiplicative) commutative monoids. -/
Expand Down
356 changes: 350 additions & 6 deletions src/algebraic_geometry/AffineScheme.lean

Large diffs are not rendered by default.

212 changes: 212 additions & 0 deletions src/algebraic_geometry/limits.lean
@@ -0,0 +1,212 @@
/-
Copyright (c) 2022 Andrew Yang. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Andrew Yang
-/
import algebraic_geometry.pullbacks
import algebraic_geometry.AffineScheme
import category_theory.limits.constructions.finite_products_of_binary_products
import category_theory.limits.constructions.equalizers

/-!
# (Co)Limits of Schemes

We construct various limits and colimits in the category of schemes.

* The existence of fibred products was shown in `algebraic_geometry/pullbacks.lean`.
* `Spec ℤ` is the terminal object.
* The preceding two results imply that `Scheme` has all finite limits.
* The empty scheme is the (strict) initial object.
* Coproducts exists (and the forgetful functors preserve them).

-/

universe u

open category_theory category_theory.limits opposite topological_space

namespace algebraic_geometry

lemma Scheme.is_iso_iff {X Y : Scheme} (f : X ⟶ Y) :
is_iso f ↔ is_iso f.1.base ∧ is_iso f.1.c :=
begin
split,
{ intro H, resetI, split; apply_instance },
{ rintro ⟨H₁, H₂⟩,
exactI @@is_iso_of_reflects_iso _ _ f (Scheme.forget_to_LocallyRingedSpace ⋙
LocallyRingedSpace.forget_to_SheafedSpace ⋙ SheafedSpace.forget_to_PresheafedSpace)
(PresheafedSpace.is_iso_of_components f.1 : _) _ }
end

lemma is_open_immersion.to_iso {X Y : Scheme} (f : X ⟶ Y) [h : is_open_immersion f]
[epi f.1.base] : is_iso f :=
@@is_iso_of_reflects_iso _ _ f (Scheme.forget_to_LocallyRingedSpace ⋙
LocallyRingedSpace.forget_to_SheafedSpace ⋙ SheafedSpace.forget_to_PresheafedSpace)
(@@PresheafedSpace.is_open_immersion.to_iso _ f.1 h _) _

lemma is_open_immersion.of_stalk_iso {X Y : Scheme} (f : X ⟶ Y) (hf : open_embedding f.1.base)
[∀ x, is_iso (PresheafedSpace.stalk_map f.1 x)] : is_open_immersion f :=
SheafedSpace.is_open_immersion.of_stalk_iso f.1 hf

instance {X Y : Scheme} (f : X ⟶ Y) (U : opens Y.carrier) [is_open_immersion f] :
is_open_immersion (f ∣_ U) := by { delta morphism_restrict, apply_instance }

lemma is_open_immersion_iff_stalk_iso {X Y : Scheme} (f : X ⟶ Y) :
is_open_immersion f ↔ open_embedding f.1.base ∧ ∀ x, is_iso (PresheafedSpace.stalk_map f.1 x) :=
⟨λ H, ⟨H.1, by exactI infer_instance⟩, λ ⟨h₁, h₂⟩, @@is_open_immersion.of_stalk_iso f h₁ h₂⟩

lemma is_iso_iff_is_open_immersion {X Y : Scheme} (f : X ⟶ Y) :
is_iso f ↔ is_open_immersion f ∧ epi f.1.base :=
⟨λ H, by exactI ⟨infer_instance, infer_instance⟩, λ ⟨h₁, h₂⟩, @@is_open_immersion.to_iso f h₁ h₂⟩

lemma is_iso_iff_stalk_iso {X Y : Scheme} (f : X ⟶ Y) :
is_iso f ↔ is_iso f.1.base ∧ ∀ x, is_iso (PresheafedSpace.stalk_map f.1 x) :=
begin
rw [is_iso_iff_is_open_immersion, is_open_immersion_iff_stalk_iso, and_comm, ← and_assoc],
refine and_congr ⟨_, _⟩ iff.rfl,
{ rintro ⟨h₁, h₂⟩,
convert_to is_iso (Top.iso_of_homeo (homeomorph.homeomorph_of_continuous_open
(equiv.of_bijective _ ⟨h₂.inj, (Top.epi_iff_surjective _).mp h₁⟩)
h₂.continuous h₂.is_open_map)).hom,
{ ext, refl },
{ apply_instance } },
{ intro H, exactI ⟨infer_instance, (Top.homeo_of_iso (as_iso f.1.base)).open_embedding⟩ }
end

lemma has_finite_limits_of_has_terminal_has_pullbacks
{C : Type*} [category C] [has_terminal C] [has_pullbacks C] : has_finite_limits C :=
@@finite_limits_from_equalizers_and_finite_products _
(@@has_finite_products_of_has_binary_and_terminal _
(has_binary_products_of_terminal_and_pullbacks C) infer_instance)
(@@has_equalizers_of_pullbacks_and_binary_products _
(has_binary_products_of_terminal_and_pullbacks C) infer_instance)

noncomputable
def Spec_Z_is_terminal : is_terminal (Scheme.Spec.obj (op $ CommRing.of ℤ)) :=
(terminal_op_of_initial CommRing.Z_is_initial).is_terminal_obj Scheme.Spec _

instance : has_terminal Scheme := has_terminal_of_has_terminal_of_preserves_limit Scheme.Spec

instance : is_affine (⊤_ Scheme.{u}) :=
is_affine_of_iso (preserves_terminal.iso Scheme.Spec).inv

instance : has_finite_limits Scheme :=
has_finite_limits_of_has_terminal_has_pullbacks

section initial

def sheaf_of_is_terminal {C A : Type*} [category C] [category A] (J : grothendieck_topology C)
{X : A} (hX : is_terminal X) :
Sheaf J A :=
{ val := (category_theory.functor.const _).obj X,
cond := λ _ _ _ _ _ _, ⟨hX.from _, λ _ _ _, hX.hom_ext _ _, λ _ _, hX.hom_ext _ _⟩ }

@[simps]
def Scheme_empty : Scheme.{u} :=
{ carrier := Top.of pempty,
presheaf := (category_theory.functor.const _).obj (CommRing.of punit),
is_sheaf := by { apply Top.presheaf.is_sheaf_spaces_of_is_sheaf_sites,
exact (sheaf_of_is_terminal _ CommRing.punit_is_terminal).cond },
local_ring := λ x, pempty.elim x,
local_affine := λ x, pempty.elim x }

@[simps]
def Scheme_empty_to (X : Scheme.{u}) : Scheme_empty ⟶ X :=
⟨{ base := ⟨λ x, pempty.elim x, by continuity⟩,
c := { app := λ U, CommRing.punit_is_terminal.from _ } }, λ x, pempty.elim x⟩

@[ext]
def Scheme_empty_ext {X : Scheme.{u}} (f g : Scheme_empty ⟶ X) : f = g :=
by { ext x, exact pempty.elim x }

@[simp]
lemma Scheme_empty_to_eq {X : Scheme.{u}} (f : Scheme_empty ⟶ X) : f = Scheme_empty_to _ :=
Scheme_empty_ext f (Scheme_empty_to X)

instance (X : Scheme.{u}) : unique (Scheme_empty ⟶ X) :=
⟨⟨Scheme_empty_to _⟩, λ _, Scheme_empty_ext _ _⟩

def empty_is_initial : is_initial Scheme_empty :=
is_initial.of_unique _

@[simp]
lemma empty_is_initial_to : empty_is_initial.to = Scheme_empty_to := rfl

instance : is_empty (Scheme.Spec.obj (op $ CommRing.of punit)).carrier :=
⟨prime_spectrum.punit⟩

lemma is_open_immersion_of_is_empty {X Y : Scheme} (f : X ⟶ Y) [is_empty X.carrier] :
is_open_immersion f :=
begin
apply_with is_open_immersion.of_stalk_iso { instances := ff },
{ apply open_embedding_of_continuous_injective_open,
{ continuity },
{ rintro (i : X.carrier), exact is_empty_elim i },
{ intros U hU, convert is_open_empty, ext, apply (iff_false _).mpr,
exact λ x, is_empty_elim (show X.carrier, from x.some) } },
{ rintro (i : X.carrier), exact is_empty_elim i }
end

instance {X : Scheme} : is_open_immersion (empty_is_initial.to X) :=
@@is_open_immersion_of_is_empty _ (by exact pempty.is_empty)

lemma is_iso_of_is_empty {X Y : Scheme} (f : X ⟶ Y) [is_empty Y.carrier] : is_iso f :=
begin
haveI : is_empty X.carrier := ⟨λ x, is_empty_elim (show Y.carrier, from f.1.base x)⟩,
apply_with is_open_immersion.to_iso { instances := ff },
{ apply is_open_immersion_of_is_empty },
{ rw Top.epi_iff_surjective, rintro (x : Y.carrier), exact is_empty_elim x }
end

instance : is_iso (empty_is_initial.to (Scheme.Spec.obj (op $ CommRing.of punit))) :=
is_iso_of_is_empty _

noncomputable
def Spec_punit_is_initial : is_initial (Scheme.Spec.obj (op $ CommRing.of punit)) :=
empty_is_initial.of_iso (as_iso $ empty_is_initial.to _)

instance : is_affine Scheme_empty :=
is_affine_of_iso (empty_is_initial.to (Scheme.Spec.obj (op $ CommRing.of punit)))

instance : has_initial Scheme :=
has_initial_of_unique Scheme_empty

instance : is_affine (⊥_ Scheme) :=
is_affine_of_iso (is_initial.unique_up_to_iso initial_is_initial empty_is_initial).hom

instance initial_is_empty : is_empty (⊥_ Scheme).carrier :=
⟨λ x, ((initial.to Scheme_empty : _).1.base x).elim⟩

instance (X : Scheme) : is_open_immersion (initial.to X) :=
is_open_immersion_of_is_empty _

lemma bot_is_affine_open (X : Scheme) : is_affine_open (⊥ : opens X.carrier) :=
begin
convert range_is_affine_open_of_open_immersion (initial.to X),
ext,
exact (false_iff _).mpr (λ x, is_empty_elim (show (⊥_ Scheme).carrier, from x.some)),
end

instance : has_strict_initial_objects Scheme :=
has_strict_initial_objects_of_initial_is_strict (λ A f, is_iso_of_is_empty f)

end initial

section coproduct

-- by showing that the coproducts of schemes in the category of locally ringed spaces is a scheme
-- (presumably using `LocallyRingedSpace.is_open_immersion.Scheme`),
-- or by showing that gluing with empty intersection is the coproduct.
instance : has_coproducts Scheme.{u} := sorry

instance (I : Type*) :
preserves_colimits_of_shape (discrete.{u} I) Scheme.forget_to_LocallyRingedSpace.{u} := sorry

noncomputable
instance (I : Type*) :
preserves_colimits_of_shape (discrete.{u} I) Scheme.forget_to_Top.{u} :=
by { delta Scheme.forget_to_Top LocallyRingedSpace.forget_to_Top, apply_instance }

end coproduct

end algebraic_geometry