![MathJax Logo](/templates/jsp/_style2/_tandf/pb2/images/math-jax.gif)
Abstract
Church’s simple type theory is often deemed too simple for elaborate mathematical constructions. In particular, doubts were raised whether schemes could be formalized in this setting and a challenge was issued. Schemes are sophisticated mathematical objects in algebraic geometry introduced by Alexander Grothendieck in 1960. In this article we report on a successful formalization of schemes in the simple type theory of the proof assistant Isabelle/HOL, and we discuss the design choices which make this work possible. We show in the particular case of schemes how the powerful dependent types of Coq or Lean can be traded for a minimalist apparatus called locales.
1 Introduction
1.1 A Challenge Accepted and Met
Proof assistants have made impressive progress on the formalization of algebra [Citation14]. In 2003, Laurent Chicli, as the topic of his PhD thesis [Citation7], formalized sheaves of rings and affine schemes in the proof assistant Coq [Citation9], which is based on a powerful dependent type theory known as the Calculus of Inductive Constructions [Citation10, Citation11]. However, Chicli’s Coq code certainly became deprecated long ago. More recently, in 2019 Grothendieck’s schemes [Citation15] have been formalized by a group of six mathematicians led by Kevin Buzzard [Citation6], with additional insights from Reid Barton and Mario Carneiro, using the brave new Lean theorem prover, which is based on a similar dependent type theory [Citation12]. For the reader unfamiliar with schemes we will quote Kevin Buzzard.
Schemes are the fundamental objects of study in algebraic geometry. They were discovered (in their current form) by Grothendieck in the late 1950s and early 1960s and they revolutionised the theory of algebraic geometry.Footnote1
and
A scheme is a mathematical object whose definition and basic properties are usually taught at MSc or early PhD level in a typical mathematics department.
Kevin Buzzard in 2017 proposed the formalization of schemes
as basically a challenge to see if Lean can handle such a complex definition.Footnote2
We should note that the Isabelle proof assistant is based on a much more minimalist type theory, known as simple type theory. As a consequence, many users of dependent type theories see Isabelle’s type theory as a far less expressive system for formalizing advanced mathematics. These doubts have been expressed by Kevin Buzzard on his blog:
What can Isabelle/HOL actually do before it breaks? Nobody knows. […] But do you people want to attract working mathematicians? Then where are the schemes? Can your system even do schemes? I don’t know. Does anyone know? If it cannot then this would be very valuable to know because it will help mathematician early adopters to make an informed decision about which system to use.Footnote3
Even the status of sheaves of rings, a prerequisite for schemes, was unclear:
I am not sure that it is even possible to write this code in Isabelle/HOL in such a way that it will run in finite time, […], and a sheaf is a dependent type, and your clever HOL workarounds will not let you use typeclasses […]Footnote4
In this article we present a formalization of sheaves of rings and schemes in Isabelle/HOL reaching the benchmark result set by [Citation6]: an affine scheme is a scheme.
1.2 Toward a Discipline of Formalizing
To achieve this result, we tried to bridge the gap between set theory and type theory within the simple type theory of Isabelle/HOL, while forgoing the extension of Isabelle’s logic with a new rule for type definition as proposed by Kunčar and Popescu in their types-to-sets framework [Citation19]. We avoided Isabelle’s type classes and type declarations whenever possible and relied on Isabelle’s module system called locales, whose modern incarnation appeared in 2006 [1]. Locales pervade our development and we exemplify their use in topology, abstract algebra and algebraic geometry. In particular, the present work makes a triple contribution to Isabelle/HOL: a first building block toward a new topology library, a new building block toward a library for abstract algebra and finally a formalization of schemes. The formalized material has a size of 7300 lines of code [Citation5], including material in commutative algebra (prime and maximal ideals, localization of a ring) and our partial reconstruction of the topology library (down to the notion of a topological space). Our experiment meets the challenge of formalizing for the first time schemes in simple type theory and by doing so it demonstrates that intricate dependencies of mathematical structures can be managed in this formal logical system. In Section 4 the current limitations of locales are addressed and we point out possible improvements to make formal statements handled with locales more concise. Our approach through locales allows for intricate definitions as well as proofs where the efficient proof automation of Isabelle/HOL kicks in. We hope this work will help mathematicians interested in the formalization of mathematics to evaluate the formal systems available to them.
2 A World Without Dependent Types: Problems and solutions
2.1 Isabelle/HOL and Simple Type Theory
Isabelle/HOL [Citation22] is a proof assistant for higher-order logic—Church’s simple type theory [Citation8]—and is therefore based on the typed λ-calculus with Boolean and function types. A Boolean-valued function is a predicate, which yields a simple typed set theory that is expressive enough to express abstract mathematics, as we demonstrate below.
In Church’s original conception, the sole purpose of types is to prevent inconsistency, all collections being represented as sets. People today, influenced by programming languages, prefer to give types a more dominant role. They expect to have numeric types like int, nat, real, complex and for types to play a major role in logical reasoning. For example, an expression like x+y should be interpreted with respect to the types of x and y. Isabelle/HOL’s type classes [Citation24] support this sort of type-based disambiguation in a strong sense, so that x+y refers to the correct instance of addition. Type classes work for such trivialities as the basic laws for addition and multiplication (with the help of type classes for groups and rings) and for more advanced topological properties [Citation17]. A new type, once proved to be a topological space, instantly inherits such concepts as limits and continuity along with all theorems proved about them.
The drawback of type classes is simply that they refer to types. Mathematical constructions are generally too complex to formalize as types. Even the carrier of a group can be a complex object. Moving to a stronger type system, as done in Coq or Lean, brings issues of its own. Our solution is to define what we need using the naive set theory that comes with higher-order logic, through the mechanism of locales. Footnote5
2.2 Locales
A locale [Citation2] represents an Isabelle/HOL proof context. It can take parameters and instances of other locales. It can declare components constrained by assumptions. Thus they correspond directly to the mathematical practice of defining a monoid, say, as a tuple satisfying the obvious properties. A locale can inherit multiple instances, as when we define a monoid homomorphism with respect to two monoids.
Logically, a locale is nothing but a predicate; their power comes from Isabelle’s mechanisms for creating, managing and using locale hierarchies. If we work in a particular locale, we can refer to its components and assumptions. But we can also prove membership of a locale, which means to exhibit particular constructions—say a purported monoid carrier along with its multiplication and identity—and prove that they satisfy the locale’s assumptions. Sublocale declarations provide a means of proving inclusions between locales, for instance to prove once and for all that every submonoid is in particular a monoid. We found that locales handled the tangle of definitions building up to schemes faithfully.
However, the right way to formalize advanced algebra is not obvious. During the formal development the user has to decide how mathematical structures should be best organized in the proof assistant so that they can be used mechanically in an efficient way. It is well-known in the Isabelle community that the main algebra library needs to be rebuilt from scratch. In fact, there are many libraries for algebra in Isabelle: HOL-AlgebraFootnote6 from the previous millennium (1999), the more recent HOL-Computational_AlgebraFootnote7, and moreover some entries in the Archive of Formal ProofsFootnote8 like Groups, Rings and Modules [Citation18] and Vector Spaces [Citation21] among others. As a result, there is a lot of overlapping material, which makes the status of algebra confusing and unclear for the newcomer in the Isabelle world. And while these formalizations constitute an impressive body of work, parts of it are deprecated code not using locales or the Isar language, an additional layer of vernacular which allows for structured proofs making them more legible and easier to maintain. Despite these problems, there are noteworthy achievements like the formalization of the algebraic closure of a field [Citation13].
Even using locales, we can still go wrong. The root of the problems in HOL-Algebra is the desire to refer to a structure such as a group with its components using a single variable, as a record data structure. The new (at the time) extensible records seemed perfect for the task. But they led to some peculiarities: notably, the locale abelian_group (in Theory Ring) which presents the odd twist of requiring a ring structure. The lack of multiple inheritance for records seems to have required the awkward use of the ring record for abelian groups. However, Clemens Ballarin recently conducted an experiment [Citation3] showing that locales, without records, allow for a smooth handling of basic algebraic structures in Isabelle such as monoids, groups and rings. We decided to base our formal development on this experiment. In the next section we introduce schemes and their formal counterparts in simple type theory, replacing the dependent types of Buzzard et al. [Citation6] by Isabelle’s locales.
3 Schemes in Isabelle/HOL
3.1 Elements of Topology
We seized the opportunity of formalizing schemes to build a new topology library despite the two existing formalizations of topology in Isabelle/HOL, namely HOL-Topological_Spaces.thyFootnote9 and HOL-Analysis/Abstract_Topology.Footnote10 Our new topology library is entirely built on locales without using type classes or type declarations (via the typedef command). In particular, our topological spaces have explicit carrier sets as part of their data instead of using UNIV, the set of all elements of some type, or having to define it later as the union of all the open sets.
locale topological_space = fixes S:: "’a set" and is_open:: "’a set ⇒ bool" assumes open_space [simp, intro]: "is_open S" and open_empty [simp, intro]: "is_open {}" and open_imp_subset: "is_open U ⇒ U ⊆ S" and open_inter [intro]: "[[is_open U; is_open V]] ⇒ is_open (U ∩ V)" and open_union [intro]: "∧ F::(’a set) set. (∧ x. x ∈ F ⇒ is_open x) ⇒ is_open (∪ x∈F. x)"The token ’a set denotes the type of sets of elements of type ’a, this last type being the type of the elements of the carrier S of our topological space. Within the locale for topological spaces the axiom open_imp_subset enforces that an open is automatically a subset of the ambient space. This is a welcome addition, since it avoids having to add this assumption in every lemma mentioning an open set among its assumptions, making the economy of dozens of trivial assumptions.
Then we define the topology generated by a family of subsets of a given set,
inductive generated_topology:: "’a set ⇒ ’a set set ⇒ ’a set ⇒ bool" for S:: "’a set" and B:: "’a set set" where UNIV: "generated_topology S B S" | Int: "generated_topology S B (U ∩ V)" if "generated_topology S B U" and "generated_topology S B V" | UN: "generated_topology S B (∪ K)" if "(∧ U. U ∈ K _⇒ generated_topology S B U)" | Basis: "generated_topology S B b" if "b ∈ B ∧ b ⊆ S"where ’a set set denotes the type of sets of elements of type ’a set. The fact that the generated topology is indeed a topology is established as one of our first lemmas.
lemma generated_topology_is_topology: fixes S:: "’a set" and B:: "’a set set" shows "topological_space S (generated_topology S B)"Covers in topology are an interesting example, since they illustrate how locales can be nested like matryoshka dolls.
locale cover_of_subset = fixes X:: "’a set" and U:: "’a set" and index:: "real set" and cover:: "real ⇒ ’a set" cover:: "real ⇒ ’a set" assumes "U ⊆ X" and "∧ i. i ∈ index ⇒ cover i ⊆ X" and "U ⊆ (∪ i ∈ index. cover i)" locale open_cover_of_subset = topological_space X is_open + cover_of_subset X U I C for X and is_open and U and I and C + assumes "∧ i. i∈I ⇒ is_open (C i)" locale open_cover_of_open_subset = open_cover_of_subset X is_open U I C for X and is_open and U and I and C + assumes "is_open U"Above, each locale builds on the previous one to define eventually an open cover of an open subset. The token “+” is used to declare a mathematical structure which was previously introduced and also to add possibly a list of assumptions. Our library includes also basic elements like homeomorphisms and the subspace topology induced on a subset.
3.2 Elements of Algebraic Geometry
Our presentation follows the classic graduate textbook of Hartshorne [Citation16]. For the remainder of this text fix a ring R. The reader can safely assume that R is commutative.
3.2.1 The Zariski Topology
The definitions of a ring R and of an ideal of R were introduced in [Citation3]. Note that in Isabelle we do not assume from the start that R is commutative, since we strive for generality. In formal mathematics, adding an axiom later is easier than removing one!
Definition 3.1
(ideal). An ideal of R is a subset of R which is an additive subgroup such that
.
The token subgroup_of_additive_group_of_ring is the way to introduce in Isabelle a ring R and an additive subgroup of R using Isabelle’s locale mechanism. Note that in the code above the ideal is denoted I while gothic letters are sometimes used for denoting ideals. In our code we use both depending on the situation. One easily checks that and R are ideals of R. In our formalization this translates as follows.
The token “in comm_ring” allows to open a context where a commutative ring, here denoted R, has been previously declared in Isabelle. Given and
two ideals of R, one defines
to be the ideal whose underlying set is
Actually, is the smallest ideal generated by the set
One easily checks is an ideal.
This ideal can be characterized as the intersection of all ideals of R containing the set
Given a family of ideals of R indexed by an arbitrary set I, one defines the set
to be the set
of all finite sums of elements belonging to some ideals of the family. The set
, seen as an additive subgroup, is again an ideal of R.
The so-called prime ideals are an important class of ideals.
Definition 3.2
(prime ideal). A prime ideal is an ideal such that
implies
or
for every elements x and y in R.
Our locale pr_ideal builds upon the locale ideal for ideals (introduced previously in [Citation3]) which does not assume the commutativity of the ring R. As a consequence, in order to assume the commutativity of the ring, we have to declare afresh the parameters of the locale instead of simply writing
locale pr_ideal = ideal + assumes carrier_neq: "I ≠ R" and absorbent: "[[x ∈ R; y ∈ R]] ⇒ (x ・y ∈ I) _⇒ (x ∈ I ∨ y ∈ I)"as our locale, although this last locale would be syntactically correct.
Note that if is a prime ideal, then
.
Let be a prime ideal and S be the complement of
in R, we prove S is a multiplicative submonoid of R.
If is an ideal of R,
will denote the set of all prime ideals of R which contain
.
Note that and
is the set of all prime ideals of R, abbreviated Spec in our code.
Next, we define on the set of all primes ideals of R the so-called Zariski topology given by the subsets of the form as the closed subsets. We then prove in Isabelle that the set
together with its Zariski topology is a topological space.
In the rest of this text will denote the set of all prime ideals of R equipped with its Zariski topology.
3.2.2 Sheaves of Rings
We now teach Isabelle what presheaves of rings are.
Definition 3.3
(presheaf of rings). Let X be a topological space. A presheaf of rings on X consists of the following data:
for every open set U, a ring
for every inclusion
of open subsets, a morphism of rings
ρUU is the identity map for every open subset U
If
are three open subsets, then
.
Within the locale the sets ’s are endowed with ring structures using the functional add_str (resp. mult_str, zero_str, one_str) that takes an open subset U and outputs the addition (resp. the multiplication, the additive unit, the multiplicative unit) on the set
. Ring homomorphisms have been defined in [Citation3] as follows.
As expected the source and target of a ring homomorphism are rings. As a consequence, the condition is_ring_morphism within the locale presheaf_of_rings, requiring ρUV to be a ring homomorphism, implies that together with its structure is a ring for every open subset U of the underlying topological space.
Notation 1. The elements of are sometimes called the sections of the presheaf
over U and given
denotes the element
.
Of course, we have the corresponding notion of morphisms.
Definition 3.4
(morphism of presheaves of rings). A morphism of presheaves of rings on a topological space X is given by a morphism
for each open subset U of X such that the following diagram commutes
for every inclusion
.
In the snippet of code above, we see the inheritance of locales in action. Indeed, the locale presheaf_of_rings inherits multiple instances, one for the source and one for the target of the notion of morphism being defined. The notion of composition for morphisms of presheaves is straightforward and we check in Isabelle without any difficulty that the composition is again a morphism between presheaves of rings.
Indeed, let (resp.
) be a morphism of presheaves of rings on a topological space X. One defines the composition
from
to
as
for every open subset U of X.
The syntax , used in the last line of the above code, is simply some syntactic sugar for the definition of the composition
of two maps f and g on the domain D.
Remark 3.5.
Given a presheaf on X, let us define
as the identity morphism of
for every open subset U of X. The family
is obviously a morphism of presheaves from
to itself. A morphism
of presheaves of rings is an isomorphism if and only if there exists a morphism
such that
and
.locale iso_presheaves_of_rings
Now, we introduce the notion of a sheaf of rings.
Definition 3.6
(sheaf of rings). A sheaf of rings on a topological space X is a presheaf of rings on X that satisfies the following additional properties:
(locality)Given an open set U, an open covering of U and
such that
for all i, then one has s = 0.
(glueing)Given an open set U, an open covering of U and elements
satisfying the property
for all i and j, then there exists an element
such that
for all i.
The resulting formalization of sheaves of rings in Isabelle is concise (10 lines), tidy and almost transparent with respect to the pen-and-paper definition.
locale sheaf_of_rings = presheaf_of_rings + assumes locality: "∧ U I V s. open_cover_of_open_subset S is_open U I V ⇒ (∧ i. i∈I ⇒ V i ⊆ U) ⇒ s ∈A morphism (resp. an isomorphism) of sheaves of rings is nothing but a morphism (resp. an isomorphism) of presheaves of rings, hence the following locale in Isabelle.
locale morphism_sheaves_of_rings = morphism_presheaves_of_ringsLet X be a topological space, a sheaf of rings on X and U an open subset of X, one proves that the restriction of
to U, seen as a topological subspace with respect to the induced topology, is a sheaf of rings. In our formal development this sheaf is called the induced sheaf and shorten ind_sheaf. We encapsulate the relevant mathematical context (the “let be” part) in a dedicated locale and formalize within this locale the relevant definitions and we eventually prove the induced sheaf
is indeed a sheaf of rings.
In the code above the interpretation mechanism for locales makes possible to instantiate the locale ind_topology, for the induced topology on a subset, with a list of arguments. Then it becomes possible to refer later to the induced topology on the open subset U with the abbreviation it.
We introduce a second construction that takes as input a given sheaf of rings and outputs a new sheaf of rings. Let be a continuous map between topological spaces and
a sheaf of rings on X. Given an open subset V of Y, define
to be
. We then prove that
, together with the obvious structure, is a sheaf of rings on the topological space Y. The sheaf
is called the direct image of
.
As can been seen in the snippet of code above, we encapsulate again the context of the construction in a dedicated locale and this lets us formalize the relevant definitions in this context and we eventually prove the direct image of a sheaf is again a sheaf.
3.2.3 Localizations of Rings
Next, we introduce the localization of commutative rings. Let S be a multiplicative submonoid of R. We consider pairs (r, s) with and
and we define the following relation on them
if and only if there exists
such that
. One checks that the relation ∼ is an equivalence relation. The equivalence class of a pair (r, s) is denoted by r / s and the set of equivalence classes is denoted by
. We define the following addition on
.
We also define the following multiplication on .
One checks these operations are well-defined with forming a ring. Following Serge Lang [Citation20, II.4] we call the new ring
the quotient ring of R by SFootnote11. This construction translates into the following locale.
The code above ends with a proof that the locale quotient_ring is a sublocale of the locale comm_ring, i.e., a proof that the quotient of a commutative ring by a multiplicative submonoid is a commutative ring. Remember that the complement of a prime ideal in R is a multiplicative submonoid, hence we can apply the previous construction with
. The resulting ring
is called the local ring of R at
.
This allows us to introduce the next construction.
3.2.4 The Spectrum of a Ring
Let U be an open subset of . We define
to be the set of all functions
such that
for every
and such that for every
, there exist a neighborhood V of
, contained in U, and elements
, such that for each
and
. We can prove that
is closed under the addition and multiplication of such functions and we take for the additive unit (resp. multiplicative unit) the function that maps each
on the additive unit (resp. multiplicative unit) of
. Last, if
, then the morphism of rings
maps each
on its restriction to V. One checks
is a sheaf of rings on
and the pair
is called the spectrum of the ring R. This last construction translates smoothly in Isabelle.
Next, we introduce ringed spaces and their morphisms.
3.2.5 Ringed Spaces
Definition 3.7
(ringed space). A ringed space is a pair , where X is a topological space and
is a sheaf of rings on X.
Definition 3.8
(morphism of ringed spaces). A morphism of ringed spaces from to
is a pair
consisting of a continuous map
between topological spaces and a morphism
of sheaves of rings.
A classic and ubiquitous notion in mathematics is the direct limit of a family of structured sets, here a family of rings.Footnote12
3.2.6 Direct Limit of a Presheaf of Rings
Let X be a topological space and a presheaf of rings on X. The set I will denote a subset of the set of all open subsets of X such that for every U and V in I there exists W in I with
. Given
and
, we say that
if and only if there exists
such that
and
. One checks that ∼ is an equivalence relation. Now, we consider the quotient of the disjoint union of the
’s.
Last, we define the following binary operations on :
for some
such that
and where the symbol
denotes the equivalence class of an element. These operations are well-defined, and assuming
one can prove that
is a ring.
Definition 3.9
(direct limit of a presheaf of rings). Let X be a topological space, a presheaf of rings on X and I a set of open subsets of X. The direct limit of
over I is the ring
, denoted simply
if I is clear from the context.
The definition above, which could naively appear as a dependent type, gives rise to a smooth translation in Isabelle using the locale mechanism.
locale direct_lim = sheaf_of_rings + fixes I:: "’a set set" assumes subset_of_opens: "∧ U. U ∈I _⇒ is_open U" and has_lower_bound: "∧ U V. [[U ∈I; V ∈I]] ⇒ ∃W ∈I. W ⊆ U ∩ V" begin definition rel:: "(’a set × ’b) ⇒ (’a set ×’b) ⇒ bool" (infix "∼" 80) where "x ∼ y ≡ (fst x ∈ I ∧ fst y ∈ I) ∧ (snd x ∈For every , there is a canonical map from
to
.
The direct limit of a presheaf of rings satisfies a useful universal property. Indeed, for every ring A equipped with ring morphisms for
satisfying
for every inclusion
, there exists a unique ring morphism u making the following diagram commute.
The counterpart in Isabelle is as follows.
proposition (in direct_lim) universal_property: fixes A:: "’c set" and ψ:: "’a set ⇒ (’b ⇒ ’c)" and add:: "’c ⇒ ’c ⇒ ’c" and mult:: "’c ⇒ ’c ⇒ ’c" and zero:: "’c" and one:: "’c" assumes "ring A add mult zero one" and "∧ U. U ∈ I _⇒ ring_homomorphism (ψ U) (One can instantiate direct limits in the following particular case.
3.2.7 Stalks of a Presheaf of Rings
Definition 3.10
(stalks of a presheaf). Let X be a topological space, a presheaf of rings on X and x an element of X. The stalk
of
at x is the direct limit of
over the set of all the open neighborhoods of x.
One further step towards schemes consists in introducing local rings.
3.2.8 Local Rings
First, one needs to teach Isabelle simple facts about maximal ideals, starting with their definition.
Definition 3.11
(maximal ideal). Let be an ideal of R. The ideal
is maximal if
and there is no ideal
such that
.
Classic facts about maximal ideals include the fact that every maximal ideal is prime.
proposition (in max_ideal) is_pr_ideal: "pr_ideal R I (+) (・) 0 1"We then introduce the notion of a local ring.
Definition 3.12
(local ring). A ring is a local ring if it has a unique maximal left ideal.
locale local_ring = ring + assumes is_unique: "∧ I J. max_lideal I R (+) (・) 0 1 ⇒ max_lideal J R (+) (・) 0 1 ⇒ I = J" and has_max_lideal: "∃ω. max_lideal ω R (+) (・) 0 1"Two remarks are in order. First, note that the property of being a local ring does not require the ring to be commutative. As a consequence, for generality, we do not assume the commutativity of the ring in the above definition and in its locale counterpart: hence the use of left ideals instead of two-sided ideals. Using right ideals would give rise to an equivalent definition. Second, we recall the following result which can be obtained using Zorn’s lemma. Let R be a unital ring, every proper ideal of R lies in a maximal ideal of R. As a corollary, every nonzero unital ring has a maximal ideal, hence, we could dispense with the property has_max_lideal in the locale local_ring, but only by adding the extra assumption that R is nonzero. Moreover, our formulation of this locale works as a convenient shortcut, avoiding the cost of formalizing the result recalled above.
We prove as expected that the local ring of R at , previously denoted
, is a local ring.
Local rings have their corresponding notion of morphisms.
Definition 3.13
(local homomorphism). Let A and B be two local rings and their respective maximal ideals. A local homomorphism
is a morphism of rings such that
.
Remark.
The inclusion implies the equality
.
Finally, we are able to introduce locally ringed spaces.
3.2.9 Locally Ringed Spaces
Definition 3.14
(locally ringed space). A locally ringed space is a ringed space such that the stalk
at x is a local ring for every
.
Moreover, one has the following result.
Proposition 3.15.
For every , the stalk
is isomorphic as a ring to
.
Proof.
See [16, Prop. 2.2.(a)]. □
locale key_map = comm_ring + fixes π:: "’a set" assumes is_prime: "π ∈ Spec" begin interpretation pi:pr_ideal R π "(+)" "(・)" 0 1 interpretation st: stalk "Spec" is_zariski_open sheaf_spec sheaf_spec_morphisms Οb add_sheaf_spec mult_sheaf_spec zero_sheaf_spec one_sheaf_spec "{U. is_zariski_open U ∧ π∈U}" π lemma stalk_at_prime_is_iso_to_local_ring_at_prime: assumes "is_zariski_open V" and "π ∈ V" shows "∃ ϕ. ring_isomorphism ϕ st.carrier_stalk st.add_stalk st.mult_stalk (st.zero_stalk V) (st.one_stalk V) (R π (+) (・) 0) (pi.add_local_ring_at) (pi.mult_local_ring_at) (pi.zero_local_ring_at) (pi.one_local_ring_at)" endNow, it suffices to teach Isabelle that a ring which is isomorphic to a local ring is local.
lemma isomorphic_to_local_is_local: assumes "local_ring B addB multB zeroB oneB" and "ring_isomorphism f A addA multA zeroA oneA B addB multB zeroB oneB" shows "local_ring A addA multA zeroA oneA"Corollary 3.16.
is a locally ringed space.
As a sanity check for our formal definitions, we eventually prove in Isabelle that the spectrum of a commutative ring is indeed a locally ringed space, a result that required some amount of formal machinery, especially to prove the key proposition 3.15.
lemma (in comm_ring) spec_is_locally_ringed_space: shows "locally_ringed_space Spec is_zariski_open sheaf_spec sheaf_spec_morphisms Οb add_sheaf_spec mult_sheaf_spec zero_sheaf_spec one_sheaf_spec"The required formal machinery and our formalization as a whole benefited from the interpretation mechanism in order to prevent statements and proof scripts from becoming too unwieldy. Without this mechanism the terms involved in the statements and proof scripts of such an intricate hierarchy of nested algebraic structures would have to be fed with many arguments, cluttering these statements and proof scripts to the point where they would become unreadable and difficult to use. Fortunately, the interpretation mechanism that comes with locales allows for reasonably concise and manageable terms with many implicit arguments which are declared beforehand using the interpretation mechanism and its command interpretation.
Now, we introduce our last construction. Let be two ringed spaces and
a morphism between them. Given
, consider
Since we have a morphism of sheaves on Y, we get a map between the direct limits over I.
Last, there is a natural inclusion from to
, since as V ranges over I,
ranges over a subset of all the open neighborhoods of x. So, eventually we get an induced morphism of rings from
to
which we will denote
. As usual we embed this construction into a dedicated locale in Isabelle.
This last construction is required to define morphisms between locally ringed spaces.
Definition 3.17
(morphism of locally ringed spaces). A morphism of locally ringed spaces from to
is a morphism
between locally ringed spaces such that the induced map of local rings
is a local homomorphism for every
.
Remark 3.18.
A morphism between locally ringed spaces is an isomorphism if and only if f is an isomorphism between topological spaces, i.e., a homeomorphism, and
is an isomorphism between sheaves of rings.
Ultimately, we reach our goal: teaching schemes to Isabelle.
3.2.10 Schemes
Definition 3.19
(affine scheme). An affine scheme is a locally ringed space which is isomorphic (as a locally ringed space) to the spectrum
for some commutative ring R.
Of course, spectra of commutative rings being locally ringed spaces provide a class of affine schemes.
lemma (in comm_ring) spec_is_affine_scheme: shows "affine_scheme R (+) (・) 0 1 Spec is_zariski_open sheaf_spec sheaf_spec_morphisms Οb (λU. add_sheaf_spec U) (λU. mult_sheaf_spec U) (λU. zero_sheaf_spec U) (λU. one_sheaf_spec U) (identity Spec) (λU. identity (Ο U))"Definition 3.20
(scheme). A scheme is a locally ringed space in which every point has an open neighborhood U such that the topological space U, together with the sheaf
, is an affine scheme.
The only purpose of the variable univ in the locale scheme is to introduce properly a new type variable, in addition to the type variables from the carriers of X and of the rings , to be used in the type of R, the carrier of the ring which is introduced by an existential quantification in the assumption are_affine_schemes once an open neighborhood U of a given element x in X has been fixed. As the name univ suggests, and as can be seen in the two lemmas below, this variable univ should be instantiated with UNIV, the set of all elements of a given type, while proving that a pair
is a scheme. The condition
in the locale scheme is then trivially satisfied and it introduces no additional constraint other than a type constraint on the carrier of the ring R as required by Isabelle type system.
To match what was achieved using Lean [Citation6], we finally prove in Isabelle that an affine scheme is a scheme and we give the example of the empty scheme , where
is the zero ring
.
4 Concluding Thoughts
4.1 Current Limitations of Locales
Our wish to avoid Isabelle’s records stemmed from their lack of multiple inheritance, as discussed above (Section 2.2). While locales possess multiple inheritance, locales without records make our formalization unnecessarily verbose in some places. The mechanism for locale interpretation is currently missing a convenient way to bundle up a list of arguments in order to prevent argument lists from becoming unwieldy. Such a bundling would ideally still allow easy access to any component of a list. However, these practical limitations are not fundamental; they are engineering issues that could be tackled in the near future.
4.2 The Song of the Sirens
It seems that our experience in Isabelle to formalize schemes was less tumultuous than the corresponding one in Lean, since Kevin Buzzard reported on his blog the difficulties he faced during his formalization in Lean:
The project is completely incompatible with modern Lean and mathlib, but if you compile it then you get a sorry-free proof that an affine scheme is a scheme. During our proof we ran into a huge problem because our blueprint, the Stacks Project, assumed that , and this turns out to be unprovable for Lean’s version of equality […]. The Lean community wrestled with this idea, and has ultimately come up with a beefed-up notion of equality for which the identity is now true.Footnote13
This difficulty basically comes from defining the sheaf structure of first on the basis given by the so-called basic open sets before extending it to all open subsets. We did not meet this difficulty in Isabelle, since we did not follow this sheaf-on-a-basis approach and the sheaves in our library are always defined from the get-go on all open subsets instead. Also, Buzzard et al. mention another difficulty encountered when proving that an affine scheme is a scheme.
This means that rewriting the equality can cause technical problems with data-carrying types such as
which depends on
(although in our case they were surmountable). This is a technical issue with dependent type theory and can sometimes indicate that one is working with the wrong definitions. [6, 3.5]
where is here simply the identity map. If, again, we gave a slightly different formulation for the definition of a scheme, following Hartshorne [Citation16] instead of the Stacks project [Citation23] as they did, it seems that this difficulty cannot possibly have a direct counterpart in Isabelle, since it arose from the difference between the so-called equality types, also known as identity types, and the definitional equality, a difference which is peculiar to dependent type theories. This difficulty was eventually overcome in Lean using a trick.
Fortunately, in our case, Reid Barton pointed out the following extraordinary trick to us: we can define the map using restriction rather than trying to force it to be the identity! [6, 3.5.]
The gap between the type theories of Lean and Isabelle/HOL called for the very different approach of the present work. If our approach based on Isabelle’s locales required some craftsmanship, locales offered enough flexibility to avoid dead ends. While dependent types are expressive, expert users know they should be used with parsimony and some issues have been highlighted for instance in the context of formalizing analysis in the proof assistant Coq [4, p. 42]. Moreover, in the age of machine learning, one may expect there is a tradeoff between the expressiveness of a type theory and one’s ability to subject it to automation, for instance through SMT solvers and the so-called hammers embedded in some proof assistants. How deep one can go formalizing mathematics in simple type theory? This work provides a first hint at an answer that should not be ruled out: simple type theory is not too simple.
Acknowledgments
We thank Kevin Buzzard for his stimulating wit and his communicative energy and André Hirschowitz who commented on a draft of this document. We also thank the reviewers, one of whom noticed an inaccuracy (fortunately easy to correct) in the formal translation into Isabelle of Definition 3.21.
Additional information
Funding
Notes
5 Not to be confused with the locales of point-free topology!
11 It is also called the ring of fractions of R by S or the localization of R at S. No confusion with the factor ring should be possible, since S is not an ideal of R but a multiplicative submonoid.
12 In more modern parlance it is called a colimit.
References
- Ballarin, C. (2006). Interpretation of locales in isabelle: Theories and proof contexts. In: Borwein, J. M., Farmer, W. M., eds. International Conference on Mathematical Knowledge Management. Berlin: Springer, pp. 31–43.
- Ballarin, C. (2014). Locales: A module system for mathematical theories. J. Autom. Reason. 52(2): 123–153.
- Ballarin, C. (2020). Exploring the structure of an algebra text with locales. J. Autom. Reason. 64(6): 1093–1121.
- Boldo, S., Lelay, C., Melquiond, G. (2015). Coquelicot: A user-friendly library of real analysis for coq. Math. Comput. Sci. 9(1): 41–62.
- Bordg, A., Paulson, L., Li, W. (2021). Grothendieck’s schemes in algebraic geometry. Archive of Formal Proofs, March 2021. Available at https://isa-afp.org/entries/Grothendieck_Schemes.html, Formal proof development.
- Buzzard, K., Hughes, C., Lau, K., Livingston, A., Mir, R. F., Morrison, S. (2021). Schemes in Lean. Available at https://arxiv.org/abs/2101.02602. doi:https://doi.org/10.1080/10586458.2021.1983489
- Chicli, L. I. (2003). Sur la Formalisation des Mathématiques dans le Calcul des Constructions inductives. PhD thesis. Université Côte d’Azur. 2003NICE4088.
- Church, A. (1940). A formulation of the simple theory of types. J. Symb. Logic 5: 56–68. doi:https://doi.org/10.2307/2266170
- The Coq Development Team. The Coq Proof Assistant Reference Manual. Available at http://coq.inria.fr.
- Coquand, T., Huet, G. (1986). The calculus of constructions. PhD thesis. INRIA.
- Coquand, T., Paulin, C. (1988). Inductively defined types. In: Martin-Löf, P., Mints, G., eds. International Conference on Computer Logic. Berlin: Springer, pp. 50–66.
- de Moura, L., Kong, S., Avigad, J., Van Doorn, F., von Raumer, J. (2015). The lean theorem prover (system description). In: International Conference on Automated Deduction. Springer, pp. 378–388.
- de Vilhena, P. E., Paulson, L. C. (2020). Algebraically closed fields in Isabelle/HOL. In: International Joint Conference on Automated Reasoning. Springer pp. 204–220.
- Gonthier, G., Asperti, A., Avigad, J., Bertot, Y., Cohen, C., Garillot, F., Le Roux, S., Mahboubi, A., O’Connor, R., Biha, S. O., Pasca, I., Rideau, L., Solovyev, A., Tassi, E., Théry, L. (2013). A machine-checked proof of the odd order theorem. In: Blazy, S., Paulin-Mohring, C., and Pichardie, D., eds, Interactive Theorem Proving. Berlin: Springer, pp. 163–179.
- Grothendieck, A. (1960). Éléments de géométrie algébrique: I. le langage des schémas. Publications Mathématiques de l’IHÉS, 4: 5–228.
- Hartshorne, R. (1977). Algebraic Geometry. Graduate Texts in Mathematics. New York: Springer.
- Hölzl, J., Immler, F., and Huffman, B. (2013). Type classes and filters for mathematical analysis in Isabelle/HOL. In: Blazy, S., Paulin-Mohring, C., Pichardie, D., eds. ITP, LNCS 7998. Springer, pp. 279–294.
- Kobayashi, H., Chen, L., Murao, H. (2004). Groups, rings and modules. Archive of Formal Proofs, May 2004. Available at https://isa-afp.org/entries/Group-Ring-Module.html, Formal proof development.
- Kunčar, O., Popescu, A. (2019). From types to sets by local type definition in higher-order logic. J. Autom. Reason. 62(2): 237–260.
- Lang, S. (2002). Algebra. Graduate Texts in Mathematics. New York: Springer.
- Lee, H. (2014). Vector spaces. Archive of Formal Proofs. Available at https://isa-afp.org/entries/VectorSpace.html, Formal proof development.
- Nipkow, T., Paulson, L. C., Wenzel, M. (2002). Isabelle/HOL: A Proof Assistant for Higher-Order Logic. Berlin: Springer. Available at http://isabelle.in.tum.de/dist/Isabelle/doc/tutorial.pdf.
- The Stacks Project Authors. (2018). Stacks Project. Available at https://stacks.math.columbia.edu.
- Wenzel, M. (1997). Type classes and overloading in higher-order logic. In Gunter, E. L., and Felty, A., eds. Theorem Proving in Higher Order Logics: TPHOLs ’97, LNCS 1275. Berlin: Springer, pp. 307–322.