[1]Y. Sivan

# Ballistic vs. diffusive transport in metals

I. W. Un  Key Laboratory of Atomic and Subatomic Structure and Quantum Control
(Ministry of Education), Guangdong Basic Research Center of Excellence for
Structure and Fundamental Interactions of Matter, School of Physics, South
China Normal University, Guangzhou 510006, China.  Guangdong Provincial Key
Laboratory of Quantum Engineering and Quantum Materials, Guangdong-Hong Kong
Joint Laboratory of Quantum Matter, South China Normal University, Guangzhou
510006, China.  S. Sarkar  Department of Physics and Nanotechnology, SRM
Institute of Science and Technology, Kattankulathur-603 203, India.

###### Abstract

Using the Boltzmann transport model, we show that, somewhat unintuitively,
ballistic transport of electrons in metals is weaker than diffusive transport.
This happens because the femtosecond-scale collision rates of the non-thermal
electrons makes their mean-free path negligible. Our predictions are
correlated with various photoluminescence and nonlinear optics experimental
examples both for Continuous Wave (CW) and pulsed illumination, and open the
way to easy modelling of the non-thermal electron distributions in metal
nanostructures of arbitrary complexity.

##  1 Introduction

Particle and charge transport are fundamental aspects of solid state physics.
They also have practical importance, especially in metals, which are part of
the backbone of our communications and computing technologies. The basic
characteristics of transport in metals were established already in the early
days of solid state research. Its modelling usually relied on the simple Drude
model, which accounts for (stationary) transport of the electron subsystem
assuming it is at low temperatures and in thermal equilibrium [1]. Under such
conditions, the transport is diffusive. If the electrons are subject to pulsed
illumination, then, one has to distinguish between the electron and phonon
subsystems [2, 3]. The model used to describe their dynamics, the so-called
Two Temperature Model (TTM), shows that the much smaller heat capacity of the
electrons causes them to experience stronger heating. Electron-phonon
interactions cause the temperatures of the two subsystems to equalize within a
few picoseconds; they also lock their spatial dynamics (see e.g., [4, 5, 6]).
Due to the short temporal and spatial scales associated with the electron
transport, an experimental demonstration of the differences between the
electron and phonon diffusive transport (in the direction perpendicular to the
illumination direction) was obtained only recently [7, 8, 9, 10]; the observed
non-trivial spatio-temporal dynamics was captured quantitatively within the
TTM (see e.g., [11, 12, 13, 14]).

Only a few studies attempted to describe the electron transport beyond the
above description, namely, the ballistic transport that precedes it and occurs
during the post-excitation and pre-scattering stage of the electrons. Indeed,
the experimental studies of lateral transport mentioned above were careful not
to discuss the ballistic stage111An exception are the claims in [10] which
were nevertheless based on an experimental system whose spatial and temporal
resolution were no different from those in earlier work; the likeness to
earlier results is apparent. . A somewhat refined model adopted the extension
of the TTM which includes the dynamics of the total non-thermal energy, and
included also the possibility of its diffusive expansion [12]; this approach
led to the prediction of fs-scale decay of heat and permittivity gratings in
metal layers. In the context of longitudinal transport through a thick metal
layer, there have been several studies of ultrafast heat transport (e.g. based
on a configuration in which the pump and probe are incident on opposing
interfaces of a metal film, see [15, 16]). Theoretical modelling of this
effect accounted for the transport via a 1D diffusion term, and used an
augmented penetration depth to account phenomenologically for ballistic
transport [16, 17]. Budai et al. [18] studied the same configuration with
Continuous Wave (CW) light. They also concluded that the non-thermal electrons
do not penetrate the layer thickness.

However, it was implicit from the above studies that the actual electron
transport may be faster once ballistic transport is accounted for properly. To
do that, one needs to abandon the macroscopic TTM approach in favour of a
microscopic model which accounts for the dynamics on the electron energy
level. While Khurgin showed that the non-thermal electrons are effectively
generated near the metal interfaces [19], their consequent spatio-temporal
dynamics and/or spatial steady-state distributions were not well studied [18].
Indeed, microscopic models for the non-thermal electron dynamics such as the
Boltzmann equation (BE) almost always relied on a local model (e.g., [3, 20]),
and the few studies that went beyond the BE to a fully quantum description
(e.g., [21, 22, 23], or more advanced Density functional theory (DFT) -based
calculations, e.g. [24, 25]) did not discuss spatio-temporal gradients and
currents of field and/or charge nor their dynamics in detail. However,
a-priori there is no reason to rule out such dynamics in light of the fs-scale
electron collision mechanisms and the well known diffusive expansion. In
particular, as shown in [26, 27], the steady-state distribution may differ
significantly from the non-thermal generation spectra even under uniform CW
illumination.

Several attempts to model the transport of non-thermal electrons stand out in
the literature. First, Tien et al. [28] employed the Boltzmann Transport
Equation (BTE), namely, the local Boltzmann equation augmented by the spatial
part of the hydrodynamic derivative of the electron distribution. However, the
model of [28] included a classical excitation term and a near-equilibrium
assumption in which the deviation from equilibrium is ignored, such that this
study focussed only on the (effective) electron temperature dynamics and
spatial distribution. Jermyn et al. [29] improved upon [28] by replacing the
classical approach for the photon absorption with DFT calculations with a
hydrodynamic description of the transport within the BTE. However, while this
work described some aspects of the transport undergone by thermal electrons in
great detail (e.g., the detailed absoprtion mechanisms and tracking the number
of collisions events for each electron etc.), it did not treat the non-thermal
electrons, i.e., those electrons with a high excess energy compared to the
Fermi energy which cannot be described by a the Fermi-Dirac function.

Another attempt to model the transport of non-thermal charge carriers with the
BTE was made by Rudenko et al. in [30]; it studied self-consistently the
field, electron distribution and permittivity in a small sphere. However, like
[28], it focussed on the spatio-temporal dynamics of the (effective) electron
temperature rather than on the dynamics of the non-thermal electrons.

In this work, we go beyond the above work and provide a comprehensive study of
the transport of electrons in a Drude metal, including both thermal and non-
thermal electrons during both the ballistic and diffusive stages. In Section 2
we describe our formulation. Briefly, we compute the electron collision rates
in momentum space and convert the resulting expressions to energy space; the
excitation is computed directly in energy space, without detailing the
specific mechanism as in [31, 32]; finally, the transport is described on the
hydrodynamic level via the BTE, such that this aspect is the only one that is
not given a full quantum mechanical treatment. This constitutes the simplest
model suitable to model non-thermal electron transport.

In Section 3.1, we consider the simple configuration of a thin film of Drude
metal illuminated by a CW beam. To distinguish the current study further from
earlier work, we focus on Indium-Tin oxide (ITO) as the plasmonic material.
First, we reproduce the thermal aspects of the problem, and show that they are
accompanied by an essentially negligible spatial dynamics of the non-thermal
electrons. Then, using the simple analytic solution for the steady-state
electron non-equilibrium of [27], we show that this behaviour can be explained
by the very short mean free path (MFP) of these electrons, originating from
their frequent collisions. In Section 3.2 we show the analogous results for
pulsed illumination. We again show that the transport in the ballistic stage
is weaker compared to the diffusive stage and identify the signature of the
electron-electron collision rate on the spatial broadening rate. Finally,
Section 4 reviews several experiments that are in line with our theoretical
predictions, and Section 5 summarizes the implications of our work and
provides an outlook. Primarily, we conclude that in most cases, one can
determine the non-thermal electron distribution without solving the BTE nor
the BE at all; it suffices simply to compute the electric field and
temperature. Considering that non-thermal electron research has suffered from
poor understanding of the electron distribution due to the complex momentum
space modelling (e.g., [33, 21, 31, 24, 20]), our approach has the potential
to significantly promote the comprehension of electron non-equilibrium within
the community.

##  2 Formulation

We adopt the energy-space Boltzmann formulation described in [26, 34, 35] for
the non-equilibrium electron distribution function $f$; it depends on the
electron energy $\mathcal{E}$, on time $t$ as well as on the position $r$, and
determined by electron-electron ($e-e$), electron-phonon ($e-ph$), photon-
electron ($photon-e$) and electron-impurity ($e-imp$) interactions. This
approach was shown to be suitable for metal nanostructures whose features are
no smaller than a few nm [3, 21, 36, 37] and for pulses no shorter than a few
femtosecond long. Here, however, we add the spatial part of the hydrodynamic
derivative [38], namely,

$\displaystyle\dfrac{\partial f(\mathcal{E},r,t)}{\partial
t}+\left(\dfrac{\partial f}{\partial t}\right)_{trans}=\left(\dfrac{\partial
f}{\partial t}\right)_{\textrm{e-e}}+\left(\dfrac{\partial f}{\partial
t}\right)_{\textrm{e-ph}}+\left(\dfrac{\partial f}{\partial
t}\right)_{\textrm{photon-e}}+\left(\dfrac{\partial f}{\partial
t}\right)_{e-imp}.$ (1)

The formulation of the various terms has been described previously (e.g., [26,
27]), and will not be repeated here. Note only that while we account for
momentum conservation in the calculation of e-e and e-ph interactions222Note,
however, that momentum conservation in e-ph interactions is not really
necessary for noble metals [34]. , as in [39, 26], our treatment of the
photon-e interactions ignores momentum conservation [37] (i.e., it assumed
energy-independent matrix elements); this assumption limits the quantitative
accuracy of our results, which are nevertheless qualitatively correct, as seen
is several recent experimental measurements [40, 41, 42]333Having said that,
we note that unlike in [31] where the energy states were assumed to have a
constant width, and unlike [22] which avoid broadening the energy states, but
like in [24, 34], we compute the energy state broadening in a consistent
manner.,444Also note that as in [39], we do not include the frequency-
dependence of the photon-e interaction term as done in [22], since we deal
primarily with CW; under the conditions of the pulses we do simulate below,
these effects are minor. . We also emphasize that the e-e interaction term is
computed without the relaxation time approximation (RTA); this approach is
more accurate, but mainly unavoidable, because unlike uniformly illuminated
electron systems, it is not obvious how to pre-determine the spatial
temperature profile necessary for using the RTA. Instead, we adopt a Thomas-
Fermi type interaction kernel, as in [39, 34, 35].

The only difference to previous implementations is that here we allow the
electric field profile to be non-uniform; this gives rise, naturally, also to
charge gradients and currents (i.e., transport). The transport term is
implemented in this context for the first time here; it equals
$\vec{v}(\mathcal{E})\cdot\nabla f$ where
$\vec{v}(\mathcal{E})=\partial\mathcal{E}(\vec{k})/\hbar\partial\vec{k}/m_{e}^{*}$
is the electron velocity, with $\mathcal{E}(\vec{k})$ being the electron
dispersion relation. This constitutes the Boltzmann Transport equation (BTE).
Such hydrodynamic approach is popular and successful for modelling linear and
nonlinear nonlocal optical effects in metals (e.g., [38, 43, 44, 45, 46, 47,
48]); it provide a good compromise between accuracy and simplicity.

As in [26, 27], we complement the Boltzmann formulation with an equation for
the total energy of the phonons (or equivalently, for the phonon temperature).
This enables ensuring that the photon energy that is added to the electron
subsystem upon absorption is balanced by energy transfer from the phonons to
the environment. As shown in [26, 27], this is essential in order to get
quantitatively correct results for the electron distribution near the Fermi
energy. Since on one hand the electron and phonon temperatures are similar
under CW illumination, and since we are interested only in the early stages of
the dynamics following a short pulse, we neglect phonon diffusion.

We emphasize that our approach combines elements of quantum mechanics and
classical physics. Indeed, our approach for the photon-electron interactions
reproduces the photoelectric effect and the electron collisions are treated no
differently than in more advanced models [31, 22]. Yet, the spatial part of
the hydrodynamic derivative refers to the electrons as localized entities,
i.e., as particles rather than as waves. Nevertheless, below we show that this
model not only has the advantage of relative simplicity over full-scale
quantum mechanical models, it is also capable of explaining various
experimental results, and offers a very simple approach to understand and
model quantitatively the deviation of the electron distribution from thermal
equilibrium in complex nanostructures.

##  3 Results

###  3.1 CW

First, we study the non-equilibrium electron distribution under CW
illumination. We consider a few nm thick ITO layer illuminated by a
cylindrically symmetric focused Gaussian beam at normal incidence (e.g.,
[32]); specifically, $E=E_{0}e^{-(\rho/\rho_{0})^{2}-i\omega_{0}t}$,
$\rho_{0}$ being the illuminating beam radius (henceforth, the waist). In that
regard, we assume that the illumination is uniform across the layer thickness,
and consider the charge and heat transport only in the radial direction. We
employ a perfectly matched layer (PML) at the outer edges of the domain in
order to truncate the transverse size of the computational domain, see
Appendix A. We chose $\lambda_{0}=2\pi c/\omega_{0}=1300$nm, illumination
intensity of $100KW/cm^{2}$, and waist of $\rho_{0}=\lambda$. The material
parameters are taken from [34, 35]. In practice, the steady-state is reached
by gradually turning on the electric field, until convergence.

Fig. 1(a) shows the electron distribution at the beam center and at its
spatial waist $\rho_{0}$. One can observe the step structure seen already for
uniformly illuminated systems (e.g., [49, 50, 26, 27, 42]); the height of the
non-thermal electron shoulders is lower at the waist due to the weaker
illumination at this position. Fig. 1(b) shows the spatial distribution of the
extracted effective electron temperature $T_{e}$ (based on a computation of
the Fermi energy at each point in space, and matching to the thermal
distribution with the same total electron energy); it exhibits the expected
(diffusive) broadening compared to the illumination spot that one obtains from
solving the classical heat equation (i.e., single temperature model). This
broadening naturally originates from the inclusion of the transport term.
These are the expected (thermal equilibrium) features of the problem.

Here, however, we would like to go beyond the thermal aspects, and consider
also the transport of the non-thermal part of the electron non-equilibrium
distribution. To do that, we compute the spatial width of the (steady-state)
electron distribution as a function of the electron energy, namely,

$\rho_{f}(\mathcal{E})=\left|\int\rho^{2}\left[f(\mathcal{E},\rho)-f^{T}(\mathcal{E};T_{e}=300K)\right]d^{2}\rho\
\Big{/}\int\left[f(\mathcal{E},\rho)-f^{T}(\mathcal{E};T_{e}=300K)\right]d^{2}\rho\right|,$
(2)

where $f^{T}$ is the thermal, i.e., Fermi-Dirac distribution. Fig. 1(c) indeed
shows a broadening near the Fermi energy compared to the illumination spot,
inline with the broadening of the electron temperature spot. Peculiarly, the
broadening shows some asymmetry with respect to the Fermi energy. On the other
hand, the spatial width of the non-thermal electrons, those with high excess
energy above the Fermi energy, is not much different from that of the
illumination spot. In that sense, the non-thermal electrons do not exhibit
significant transport, or equivalently, the ballistic transport effects are so
weak so that they can simply be ignored and their spatial distribution is
given by the electric field distribution. This somewhat non-intuitive
observation is the main result of this work.

Insight into the underlying physics of this result can be obtained by
comparing the magnitudes of the various terms in the BTE (1). Fig. 2 shows
that while in the absence of transport (as well as at the beam center) the
distribution near the Fermi energy is determined by the balance of e-e and
e-ph collisions (see Figs. 2(a) and (c) 555This is what happens under uniform
illumination [27]. ), when the spatial gradients are non-zero (in particular,
away from the beam center), the magnitude of the transport term is comparable
to both electron collision terms (see Figs. 2(b) and (d)). For our particular
choice of parameters, the presence of spatial gradients leads to a $3$-fold
increase of the magnitude of the e-ph term and a slight increase of the e-e
term; the transport term turns out to be comparable to the e-e term, such that
they balance together the e-ph term. To qualitatively understand this
behaviour, we recall that near the Fermi energy, the transport term can be
approximated by

$-v(\mathcal{E})\frac{\partial f}{\partial r}\sim-v(\mathcal{E})\frac{\partial
f^{T}}{\partial T_{e}}\frac{\partial T_{e}}{\partial
r}\sim-v(\mathcal{E})\frac{\mathcal{E}-\mu}{T_{e}}\frac{\partial
f^{T}}{\partial\mathcal{E}}\frac{\partial T_{e}}{\partial r}.$ (3)

Since the derivative of the Fermi-Dirac function with respect to the energy is
negative, and since the spatial derivative of the electron temperature is
negative as well, the transport term is negative below the chemical potential,
and positive above it. In that sense, it behaves like the e-e term, see Fig.
2.

These results indicate that not only the transport term causes the expected
broader spread of the electron energy in space, but it also causes a larger
amount of energy to be transferred from the electron subsystem to the phonon
subsystem. Indeed, our simulations (Fig. 1(d)) show that the inclusion of the
transport term causes the phonon temperature spot to broaden, and the overall
phonon energy (integrated across the phonon temperature spot) to increase by
$\sim 25\%$.

Fig. 2 also shows that on the other hand, at energies far from the Fermi
energy, the e-ph and transport terms decrease rapidly with energy, such that
the electron distribution is determined by the balance of photon absorption
and e-e interactions (again, as for uniformly illuminated systems, see [27]).
In fact, using the analytic solution for the steady-state non-equilibrium
electron distribution attained under these conditions (and within the RTA and
Fermi liquid theory [51]) motivates the observation of negligible transport
exhibited by the non-thermal electrons. Indeed, the deviation from equilibrium
is [26, 27]

$f(\mathcal{E})-f^{T}(\mathcal{E},T_{e})\sim\delta_{E}f^{T}(\mathcal{E}-\hbar\omega,T_{e}).$
(4)

Thus, the transport term can be approximated by $\sim
v(\mathcal{E})f(\mathcal{E})/\rho_{0}\sim
v(\mathcal{E})\delta_{E}f^{T}(\mathcal{E}-\hbar\omega)/\rho_{0}\sim
v(\mathcal{E})\tau_{e}(\mathcal{E})/\rho_{0}$ ($\delta_{E}\sim\tau_{e}|E|^{2}$
being the height of the non-thermal electron distribution, see derivation in
[27]), so that it scales with the mean-free-path of the non-thermal electrons.
As shown in Fig. 3, the mean free path decreases rapidly away from the Fermi
energy. This somewhat classical insight was already obtained in [31].

Fig. 1: (Color online) (a) The steady-state non-equilibrium electron
distribution in a thin ITO layer under CW illumination; the black (blue) lines
are taken at the beam center (waist). The illuminating beam has (spatial peak)
intensity of $100KW/cm^{2}$ and central wavelength of $1300$nm. (b) The
extracted electron temperature profile (blue); it is much wider than the
spatial profile of the extracted temperature in the absence of the transport
term (dashed blue line); it is indistinguishable from the illuminating beam
profile (dotted black line). (c) The spatial width of the non-equilibrium
electron distribution (normalized by the illuminating beam size) as a function
of the electron energy. The dashed blue line shows the width in the absence of
the transport term. (d) The spatial profile of the phonon temperature. The
dashed blue line shows the phonon temperature in the absence of transport; it
is indistinguishable from the illuminating beam profile (dotted black line).
Fig. 2: (Color online) The photon-e (black), e-e (blue), e-ph (red) and
transport terms (green) as a function of the electron energy. The top (bottom)
row shows the values on a linear ($log_{10}$) scale, whereas the left (right)
column shows the results at the beam center (spatial waist $\rho_{0}$). The
dashed lines show the various terms when the transport term is set to zero.
Fig. 3: (Color online) (a) The electron collision time, derived from the
functional derivatives of the electron scattering integrals [34] and
Matthiessen's rule, (b) the electron velocity and (c) their product, i.e., the
mean free path, all shown as a function of the electron energy. These results
are analogous to [31, Fig. 5].

###  3.2 Pulsed illumination

We now study the spatial dynamics of the electrons in the same ITO layer
following illumination by a short pulse. In particular, we now set the
illuminating electric field to be

$E=E_{0}e^{-2log(2)(t/\tau_{p})^{2}-(\rho/\rho_{0})^{2}-i\omega_{0}t},$ (5)

where the peak intensity is now set to 500 $KW/cm^{2}$ and $\tau_{p}=100$fs.

Again considering the width of the electron distribution $\rho_{f}$ (2), we
now observe in Fig. 4 monotonic expansion of the spot size at a rate which is,
somewhat surprisingly, weakly dependent on the electron energy (at least up to
$\mathcal{E}\sim\mathcal{E}_{f}+\hbar\omega$)666The higher energy electrons
follow the same step structure as for the CW case, Fig. 1(c) and similar
dynamics as those of the thermal electrons. . Further, the early stages of the
dynamics (Fig. 4(b)) show a relatively slower expansion compared to the later
diffusive stage; the effect is similar for different initial spot sizes (not
shown). This behaviour may seem to be at odds with the linear and square root
(i.e., slower) growth rates, respectively, usually associated with the
ballistic and diffusive regimes. However, this behaviour can be understood as
another manifestation of the shortness of the MFP of non-thermal electrons. In
that sense, initially the pulse generates a relatively large number of non-
thermal electrons with a large excess energy (above the Fermi level), however,
these electrons are relatively immobile. As the electron subsystems
thermalization proceeds, the high excess energy non-thermal electrons lose
their excess energy and get converted into thermal electrons, which are more
mobile; eventually, the systems settles into a constant spot growth rate (late
stages seen in Fig. 4(a)). In that regard, a more careful look at Fig. 4(d)
reveals that the electrons near the Fermi energy exhibit a somewhat stronger
expansion; this is inline with the energy dependence of the MFP, which is
dominated by $e-e$ collisions for the non-thermal electrons (Fig. 3(c)).

Fig. 4: (Color online) (a) The width of the electron distribution $f$ as a
function of time for $\mathcal{E}=0.6$ eV (black), $\mathcal{E}=0.8$ eV
(blue), $\mathcal{E}=1$ eV (red) and $\mathcal{E}=1.2$ eV (green). (b) The
time derivative of the curves in (a), zoomed-in to the early stages of the
dynamics; the dashed black line represents the temporal shape of the
illumination. (c) The width of the electron distribution $f$ as a function of
electron energy for $t=-120,-90,-60,-30,0,30$ fs (in black, blue, red, green,
magenta and cyan, respectively). (d) Same as (c) for a narrower energy range
close to the Fermi energy.

##  4 Experimental evidence

In recent years, several classes of measurements were performed in order to
identify the signature of non-thermal electrons. While contrary to earlier
claims, photocatalysis experiments were shown to be dominated almost always by
thermal effects (see, e.g., [52, 53, 54, 55]), there have been several
convincing demonstrations of non-thermal electrons in molecular junctions (see
discussion in [40]), tunnel junctions [41, 42] as well as photoluminescence
(PL) experiments. As the latter class offers the cleanest signature of the
non-thermal electrons for weak illumination [56], we now focus on PL
experiments where signatures of the weak ballistic transport predicted above
were observed.

First, the observation of the negligible transport experienced by non-thermal
electrons is inline with the measurements of the area of an illuminated Au
film from which photoluminescence (PL) emerges [32]. Indeed, this work showed
experimentally that this area is essentially similar to the illuminated area.
Since CW PL originates from the non-thermal electrons [57], this finding
implies that non-thermal electrons do not undergo any significant (ballistic)
transport. Our predictions strengthen the conclusion drawn in the original
work which was based on a calculation that neglects transport altogether.

In this respect, our calculations give rise to a prediction that could be
verified in a (indeed challenging) future experiment. Specifically, as seen in
Fig. 1(c), the spatial width of the higher energy state occupation (i.e.,
those electrons with $\mathcal{E}>\mathcal{E}_{F}+\hbar\omega$) is even
narrower than the illumination waist $\rho_{0}$. Indeed, the electron
distribution extends as $e^{-(\rho/\rho_{0})^{4}}$ and
$e^{-(\rho/\rho_{0})^{6}}$ for energies in the second and third non-thermal
electron ``shoulders'', i.e., the width of the energy distribution is
$\sim\rho_{0}/\sqrt{2}$, $\sim\rho_{0}/\sqrt{3}$, respectively. In PL
measurements, this narrowing would be hard to observe with CW illumination
since it involves frequencies deep in the anti-Stokes regime, where the signal
is weak. However, as for the electric field dependence of the PL from metals
[56], it may be observable with strong pulsed illumination.

Similarly, when the PL is dominated by interband emission (i.e., recombination
of conduction band non-thermal electrons with non-thermal holes in the valence
band; see e.g., the elaborate discussions in [58, 32]), the width of the PL
spot is primarily determined by the large number of non-thermal holes created
by interband absorption (see [32, Fig. S10b]). Since those non-thermal holes
exhibit a very short mean free path too, then, despite the wider distribution
of the electrons in the conduction band that undergo the recombination, the
width of the interband PL spot is also expected to be field-limited. This
observation a-posteriori justifies the PL-based imaging used in, e.g., [59,
60, 61, 62, 63] which all relied on interband-based PL in Au nanostructures;
in that sense, our results imply that this imaging technique would provide
lower resolution when it is based on the thermal-like emission that dominates
the PL for illumination with strong short pulses (see discussion in [56]).

##  5 Discussion and Outlook

We have provided a formulation for the calculation of the non-uniform non-
equilibrium electron distribution in illuminated metal nanostructures which
bridges the microscopic and macroscopic pictures for both the ballistic and
diffusive stages of electron transport.

We showed that, somewhat unintuitively, the ballistic transport stage is much
weaker than the diffusive stage, so that the different positions in space are
effectively decoupled, as far as the deviation from equilibrium is concerned.
Thus, as long as the inhomogeneity of the illumination is much longer than the
mean free path of the non-thermal electrons, the (steady-state) temperature of
metal nanostructures can be determined using a standard heat equation, and the
deviation from thermal equilibrium requires just the knowledge of the electric
field distribution. This makes the computation of the non-thermal electron
distribution in space nearly trivial, and in fact, means that the inclusion of
the spatial part of the hydrodynamic derivative to the formulation, or using
the BE altogether, is mostly redundant under these conditions. In that
respect, one can simply use the analytic solution for the non-equilibrium
distribution obtained in [27] for continuously and uniformly illuminated
systems also for non-uniformly illuminated structures. This solution serves
also to explain the PL under CW illumination, as well as under pulsed
illumination (as in [56]). Further, a nonthermal model that includes
(``just'') diffusive transport (e.g., as in [12]) is sufficient to capture the
electron temperature distribution and dynamics correctly.

In that respect, while for the configuration we studied (infinitely thin
layers) the ballistic transport is negligible, it could be significant when
illuminating layers whose thickness exceeds the optical penetration depth.
Indeed, in such a configuration, our calculations predict that the illuminated
facet will enjoy a relatively high density of non-thermal electrons, whereas
the regions deeper in the metal will be characterized by a thermal
distribution; The region consisting of the non-thermal electrons will be
determined by the combination of the skin depth and the (now not much smaller)
MFP of the non-thermal electrons. This is indeed in line with the results and
modelling in [18] of a constantly illuminated thick layer, as well as studies
of ballistic transport due to pulsed illumination [15, 16, 64]. On the other
hand, our predictions provide a independent explanation to the observation of
the absence of significant ballistic transport in Au-Ni [65] and Cu-Pt-Ni [66]
heterostructures.

While the predictions of our model are shown to match several experiments,
more subtle effects may require a comparison with full quantum mechanical
momentum space modelling (e.g., [20]) or even DFT-based calculation of the
matrix elements (e.g. [33, 24]); these approaches are, unfortunately, far more
demanding computationally, as they requires handling the three spatial
dimensions separately, and all possible interactions between the associated
momentum components. Other improvements of our model may involve the quantum
hydrodynamic approach of [67] which includes also quantum pressure, exchange-
correlation interactions, the Lorentz force etc. and/or going beyond the
thermal lattice assumption (e.g., as in [68, 69]). Finally, our approach may
also be the basis to extensions of models as in [70] for interband absorption
associated transport, for plasmon-induced drag [71], Fizeau drag [72], and for
the photo-Dember effect [73].

Acknowledgements. Y.S. thanks A. Yochelis for useful discussions. Y.S. was
partially funded by a Lower-Saxony - Israel collaboration grant no.
76251-99-7/20 (ZN 3637) as well as an Israel Science Foundation (ISF) grant
(340/2020). I.W.U. was funded by the Guangdong Natural Science Foundation.

##  Appendix A Numerical implementation

The details of the various terms in the BTE (1) were detailed in various
earlier work, see [34] specifically for ITO. The current work, however,
requires extending that formulation such that it can handle the spatially non-
uniform illumination. While the non-uniformity is trivially inherent to the
photon-e term, this requires, in addition, an approach to truncate the spatial
domain. We do that using a Perfectly Matched Layer (PML), as described below.

First, for simplicity of notations, we define

$g\left[f(\mathcal{E},\rho,t)\right]=\left(\dfrac{\partial
f(\mathcal{E},\rho,t)}{\partial t}\right)_{\textrm{e-e}}+\left(\dfrac{\partial
f(\mathcal{E},\rho,t)}{\partial
t}\right)_{\textrm{e-ph}}+\left(\dfrac{\partial
f(\mathcal{E},\rho,t)}{\partial
t}\right)_{\textrm{photon-e}}+\left(\dfrac{\partial
f(\mathcal{E},\rho,t)}{\partial t}\right)_{\textrm{e-imp}},$

and add to the RHS a term which is essentially zero, namely, $\partial
f^{T}/\partial t$, where $f^{T}$ is the Fermi-Dirac distribution at room
temperature (i.e., a time-independent term). We then Fourier transform Eq.
(1), introduce the PML transformation [74] $\partial/\partial
r\to\left(1+i\sigma(\rho)^{-1}/\omega\right)\partial/\partial r$, and multiply
by $\left(1+i\sigma(\rho)/\omega\right)$. This yields

$\displaystyle\left(-i\omega+\sigma(\rho)\right)\left[\hat{f}(\mathcal{E},\rho,\omega)-f^{T}(\mathcal{E},T_{e}=300K)\right)=\left(1+i\frac{\sigma(\rho)}{\omega}\right)\hat{g}[f(\mathcal{E},\rho,t)]-v(\mathcal{E})\frac{\partial\hat{f}(\mathcal{E},\rho,\omega)}{\partial
r}.$

We now define
$\hat{\psi}=i\frac{\sigma(\rho)}{\omega}\hat{g}[f(\mathcal{E},\rho,t)]$, and
then, after the inverse transform to the time domain, we get

$\displaystyle\frac{\partial f(\mathcal{E},\rho,t)}{\partial t}$
$\displaystyle=$
$\displaystyle-\sigma(\rho)\left[f(\mathcal{E},\rho,t)-f^{T}(\mathcal{E},T_{e}=300K)\right]+g[f(\mathcal{E},\rho,t)]+\psi(\mathcal{E},\rho,t)-v(\mathcal{E})\frac{\partial
f(\mathcal{E},\rho,t)}{\partial\rho},$
$\displaystyle\frac{\partial\psi(\mathcal{E},\rho,t)}{\partial t}$
$\displaystyle=$ $\displaystyle\sigma(\rho)g[f(\mathcal{E},\rho,t)].$

Specifically, we set $\sigma(\rho<\rho_{PML})=0$ and
$\sigma(\rho\geq\rho_{PML})=(\rho-\rho_{PML})^{2}/\rho_{PML}^{2}$. The left
side of the computational domain is complemented by a Neuman boundary
condition, to impose cylindrical symmetry.

## References

  * [1] N. W. Ashcroft and N. D. Mermin.  Solid State Physics.  Hartcourt College, Fort Worth, 1976.
  * [2] S. I. Anisimov, B. L. Kapeilovich, and T. I. Perelman.  Electron emission from metal surfaces exposed to ultrashort laser pulses.  Sov. Phys. JETP, 39:375–378, 1974.
  * [3] T. Stoll, P. Maioli, A. Crut, N. Del Fatti, and F. Vallée.  Advances in femto-nano-optics: ultrafast nonlinearity of metal nanoparticles.  Eur. Phys. J. B, 87:260, 2014.
  * [4] A. A. Maznev, J. A. Johnson, and K. A. Nelson.  Non-equilibrium transient thermal grating relaxation in metal.  Appl. Phys., 109:073517, 2011.
  * [5] A. Block.  Quantifying nanoscale carrier diffusion with ultrafast optical and photocurrent microscopy.  PhD Thesis, 2019.
  * [6] A. M. Berghuis, T. V. Raziman, A. Halpin, S. Wang, A. G. Curto, and J. Gomez Rivas.  Effective negative diffusion of singlet excitons in organic semiconductors.  Phys. Chem. Lett., 12:1360–1366, 2021.
  * [7] A. Block, M. Liebel, R. Yu, M. Spector, Y. Sivan, J. García de Abajo, and N. F. van Hulst.  Tracking ultrafast hot-electron diffusion in space and time by ultrafast thermomodulation microscopy.  Science Advances, 5:eaav8965, 2019.
  * [8] G. Gao, L. Jiang, B. Xue, F. Yang, T. Wang, Y. Wan, and T. Zhu.  Unconventional shrinkage of hot electron distribution in metal directly visualized by ultrafast imaging.  Small Methods, page 2201260, 2023.
  * [9] A. Block, R. Yu, I. W. Un, S. Varghese, M. Liebel, N. F. van Hulst, S. Fan, K. Y. Tielrooij, and Y. Sivan.  Observation of negative effective thermal diffusion in gold films.  ACS Photonics, 10:1150–1158, 2023.
  * [10] P. Karna, M. S. Bin Hoque, S. Thakur, P. E. Hopkins, and A. Giri.  Direct measurement of ballistic and diffusive electron transport in gold.  Nano Lett., 23:491–496, 2023.
  * [11] N. Rotenberg, J.N. Caspers, and H.M. van Driel.  Tunable ultrafast control of plasmonic coupling to gold films.  Phys. Rev. B, 80:245420, 2009.
  * [12] Y. Sivan and M. Spector.  Ultrafast dynamics of optically heat gratings in metals.  ACS Photonics, 7:1271–1279, 2020.
  * [13] M. Spector and S. Derevyanko.  Controlling surface plasmon polariton losses in the visible spectrum by temperature-induced interband transitions.  Phys. Rev. B, 106:125111, 2022.
  * [14] A. Rodríguez Echarri, F. Iyikanat, S. Boroviks, N. Asger Mortensen, J. D. Cox, and F. Javier García de Abajo.  Nonlinear photoluminescence in gold thin films.  ACS Photonics, 10:2918–2929, 2023.
  * [15] S. D. Brorson, J. G. Fujimoto, and E. P. Ippen.  Femtosecond electronic heat-transport dynamics in thin gold films.  Phys. Rev. Lett., 59:1962, 1987.
  * [16] J. Hohlfeld, H. J. Wellershoff, S. S. Gudde, J. Conrad, U. Jähnke, and E. Mathias.  Electron and lattice dynamics following optical excitation of metals.  Chem. Phys, 251:237–258, 2000.
  * [17] A. Suslova and A. Hassanein.  Numerical simulation of ballistic electron dynamics and heat transport in metallic targets exposed to ultrashort laser pulse.  J. Appl. Phys., 124:065108, 2018.
  * [18] J. Budai, Z. Papa, P. Petrik, and P. Dombi.  Ultrasensitive probing of plasmonic hot electron occupancies.  Nat. Comm., 13:6695, 2022.
  * [19] J. Khurgin.  Hot carriers generated by plasmons: Where are they are generated and where do they go from there?  Faraday Discuss., 214:35–58, 2019.
  * [20] D. M. Riffe and R. B. Wilson.  Excitation and relaxation of nonthermal electron energy distributions in metals with application to gold.  Phys. Rev. B, 107:214309, 2023.
  * [21] L. V. Besteiro, X.-T. Kong, Z. Wang, G. Hartland, and A. O. Govorov.  Understanding hot-electron generation and plasmon relaxation in metal nanocrystals: Quantum and classical mechanisms.  ACS Photonics, 4:2759–2781, 2017.
  * [22] J. R. M. Saavedra, A. Asenjo-García, and F. Javier García de Abajo.  Hot-electron dynamics and thermalization in small metallic nanoparticles.  ACS Photonics, 3:1637–1646, 2016.
  * [23] A. M. Brown, R. Sundararaman, P. Narang, A. M. Schwartzberg, W. A. Goddard, and H. A. Atwater.  Experimental and ab initio ultrafast carrier dynamics in plasmonic nanoparticles.  Phys. Rev. Lett., 118:087401, 2017.
  * [24] S. Dal Forno, L. Ranno, and J. Lischner.  Material, size and environment dependence of plasmon hot carriers in metallic nanoparticles.  J. Phys. Chem. C., 122:8517–8527, 2018.
  * [25] S. M. Joao, H. Jin, and J. C. Lischner.  Atomistic theory of hot-carrier relaxation in large plasmonic nanoparticles.  Journal of Physical Chemistry C, 127:23296–23302, 2023.
  * [26] Y. Dubi and Y. Sivan.  ``hot electrons'' in metallic nanostructures - non-thermal carriers or heating?  Light: Sci. Appl., 8:89, 2019.
  * [27] Y. Sivan, I. W. Un, and Y. Dubi.  Assistance of plasmonic nanostructures to photocatalysis - just a regular heat source.  Faraday Discuss., 214:215–233, 2019.
  * [28] T. Q. Qiu and C. L. Tien.  Heat transfer mechanisms during short-pulse laser heating of metals.  Journal of Heat Transfer, 115:835, 1993.
  * [29] A. S. Jermyn, G. Tagliabue, H. A. Atwater, W. A. Goddard, P. Narang, and R. Sundararaman.  Transport of hot carriers in plasmonic nanostructures.  Phys. Rev. Materials, 3:075201, 2019.
  * [30] A. Rudenko and J. V. Moloney.  Coupled kinetic boltzmann electromagnetic approach for intense ultrashort laser excitation of plasmonic nanostructures.  Phys. Rev. B, 104:035418, 2021.
  * [31] A. M. Brown, R. Sundararaman, P. Narang, W. A. Goddard, and H. A. Atwater.  Nonradiative plasmon decay and hot carrier dynamics: Effects of phonons, surfaces, and geometry.  ACS Nano, 10:957–966, 2016.
  * [32] A. R. Bowman, A. Rodriguez Echarri, F. Kiani, F. Iyikanat, T. V. Tsoulos, J. D. Cox, R. Sundararaman, F. Javier Garcia de Abajo, and G. Tagliabue.  Quantum-mechanical effects in photoluminescence from thin crystalline gold films.
  * [33] A. Manjavacas, J. G. Liu, V. Kulkarni, and P. Nordlander.  Plasmon-induced hot carriers in metallic nanoparticles.  ACS Nano, 8:7630–7638, 2014.
  * [34] S. Sarkar, I. W. Un, and Y. Sivan.  The electronic and thermal response of low electron density drude materials to ultrafast optical illumination.  Phys. Rev. Applied, 19:014005, 2023.
  * [35] I. W. Un, S. Sarkar, and Y. Sivan.  An electronic-based model of the optical nonlinearity of low electron density Drude materials.  Phys. Rev. Applied, 19:044043, 2023.
  * [36] J. B. Khurgin and U. Levy.  Generating hot carriers in plasmonic nanoparticles: When quantization does matter?  ACS Photonics, 7:547–553, 2020.
  * [37] Subhajit Sarkar, Ieng Wai Un, and Yonatan Sivan.  Comparative study of models of optically-induced electron non-equilibrium in drude metals.  2023\.
  * [38] A.D. Boardman.  Electromagnetic Surface Modes.  Wiley, New York, 1982.
  * [39] N. Del Fatti, C. Voisin, M. Achermann, S. Tzortzakis, D. Christofilos, and F. Valleé.  Nonequilibrium electron dynamics in noble metals.  Phys. Rev. B, 61:16956–16966, 2000.
  * [40] Y. Dubi, I. W. Un, and Y. Sivan.  Distinguishing thermal from non-thermal (``hot'') carriers in illuminated molecular junctions.  Nano Letters, 5:2127–2133, 2022.
  * [41] P. Février, J. Basset, J. Estéve, M. Aprili, and J. Gabelli.  Role of optical rectification in photon-assisted tunneling current.  Communications Physics, 6:29, 2023.
  * [42] C. Lin, F. Krecinic, H. Yoshino, A. Hammud, A. Pan, M. Wolf, M. Muüller, and T. Kumagai.  Continuous-wave multiphoton-induced electron transfer in tunnel junctions driven by intense plasmonic fields.  ACS Photonics, 10:3637–3646, 2023.
  * [43] M. Scalora, M.A. Vincenti, D. de Ceglia, V. Roppo, M. Centini, N. Akozbek, and M. J. Bloemer.  Second- and third-harmonic generation in metal-based structures.  Phys. Rev. A, 82:043828, 2010.
  * [44] S. Raza, G. Toscano, A.-P. Jauho, M. Wubs, and N. A. Mortensen.  Unusual resonances in nanoplasmonic structures due to nonlocal response.  Phys. Rev. B, 84:121412(R), 2011.
  * [45] C. Ciracì, R. Hill, J. Mock, Y. Urzhumov, A. I. Fernández-Domímguez, S. A. Maier, J.B. Pendry, A. Chilkoti, and D. R. Smith.  Probing the Ultimate Limits of Plasmonic Enhancement.  Science, 31:1072–1074, 2012.
  * [46] C. Ciracì, E. Poutrina, M. Scalora, and D. R. Smith.  Origin of second-harmonic generation enhancement in optical split-ring resonators.  Phys. Rev. B, 85:201403(R), 2012.
  * [47] K. Yoo, S. F. Becker, M. Silies, S. Yu, C. Lienau, and N. Park.  Bridging microscopic nonlinear polarizations toward far-field second harmonic radiation.  ArXiv, https://arxiv.org/abs/1711.09568.
  * [48] M. Scalora, J. Trull, D. de Ceglia, M. A. Vincenti, N. Akozbek, Z. Coppens, L. Rodríguez-Sune, and C. Cojocaru.  Electrodynamics of conductive oxides: Intensity-dependent anisotropy, reconstruction of the effective dielectric constant, and harmonic generation.  Phys. Rev. A, 101:053828, 2020.
  * [49] B. Rethfeld, A. Kaiser, M. Vicanek, and G. Simon.  Ultrafast dynamics of nonequilibrium electrons in metals under femtosecond laser irradiation.  Phys. Rev. B, 65:214303, 2002.
  * [50] L. D. Pietanza, G. Colonna, S. Longo, and M. Capitelli.  Non-equilibrium electron and phonon dynamics in metals under femtosecond laser pulses.  Eur. Phys. J. D, 45:369–389, 2007.
  * [51] P. Coleman.  Introduction to many body physics.  Cambridge University Press, Cambridge, 2015.
  * [52] Y. Sivan and Y. Dubi.  Recent developments in plasmon-assisted photocatalysis - a personal perspective.  Appl. Phys. Lett., 117:130501, 2020.
  * [53] G. Baffou, I. Bordacchini, A. Baldi, and R. Quidant.  Simple experimental procedures to discern photothermal processes in plasmon-driven chemistry.  Light: Sci. Appl., 9:108, 2020.
  * [54] P. K. Jain.  Taking the heat off of plasmonic chemistry.  J. Phys. Chem., 123:24347–24351, 2019.
  * [55] Y. Dubi, I. W. Un, J. Baraban, and Y. Sivan.  Distinguishing thermal from non-thermal contributions to plasmonic hydrodefluorination.  Nature Catalysis, 5:244–246, 2021.
  * [56] Y. Sivan, I. W. Un, I. Kalyan, K. Lin, J. Lupton, and S. Bange.  Crossover from nonthermal to thermal photoluminescence from metals excited by ultrashort light pulses.  ACS Nano, 17:11439–11453, 2023.
  * [57] Y. Sivan and Y. Dubi.  Theory of ``hot'' photoluminescence from Drude metals.  ACS Nano, 15:8724–8732, 2021.
  * [58] T. Suemoto, S. Ono, A. Asahara, T. Okuno, T. Suzuki, K. Okazaki, S. Tani, and Y. Kobayashi.  Observation of infrared interband luminescence in magnesium by femtosecond spectroscopy.  J. Appl. Phys., 134:163105, 2023.
  * [59] A. Bouhelier, R. Bachelot, G. Lerondel, S. Kostcheev, P. Royer, and G. P. Wiederrecht.  Surface plasmon characteristics of tunable photoluminescence in single gold nanorods.  Phys. Rev. Lett., 95:267405, 2005.
  * [60] A. Hohenau, J.R. Krenn, J. Beermann, S.I. Bozhevolnyi, S. G. Rodrigo, L. Martin-Moreno, and F. Garcia-Vidal.  Spectroscopy and nonlinear microscopy of Au nanoparticle arrays: Experiment and theory.  Phys. Rev. B, 73:155404, 2006.
  * [61] P. Ghenuche, S. Cherukulappurath, T. H. Taminiau, N. F. van Hulst, and R. Quidant.  Spectroscopic mode mapping of resonant plasmon nanoantennas.  Phys. Rev. Lett., 101:116805, 2008.
  * [62] M. Garai, N. Gao, and Q.-H. Xu.  Single-particle spectroscopic studies on two-photon photoluminescence of coupled au nanorod dimers.  J. Phys. Chem. C, 122:23102–23110, 2018.
  * [63] S. Hasegawa, H. Ichikawa, and K. Imura.  Selective excitation of dark plasmon modes using cylindrical vector beams studied by microscopic imaging of nonlinear photoluminescence.  J. Phys. Chem. C, 2024.
  * [64] S. Edward, A. Antoncecchi, H. Zhang, H. Sielcken, S. Witte, and P. C. M. Planken.  Detection of periodic structures through opaque metal layers by optical measurements of ultrafast electron dynamics.  Optics Express, 28:23380, 2018.
  * [65] J. Pudell, A. A. Maznev, M. Herzog, M. Kronseder, C. H. Back, G. Malinowski, A. von Reppert, and M. Bargheer.  Layer specific observation of slow thermal equilibration in ultrathin metallic nanostructures by femtosecond x-ray diffraction.  Nature Communications, 9:3335, 2018.
  * [66] Jan-Etienne Pudell, Maximilian Mattern, Michel Hehn, Grégory Malinowski, Marc Herzog, and Matias Bargheer.  Heat transport without heating?—an ultrafast x-ray perspective into a metal heterostructure.  Adv. Func. Materials, 30:2004555, 2020.
  * [67] H. M. Baghramyan, F. Della Sala, and C. Ciracì.  Laplacian-level quantum hydrodynamic theory for plasmonics.  Phys. Rev. X, 11:011049, 2021.
  * [68] V. V. Baranov and V. V. Kabanov.  Theory of the electron relaxation in metals excited by an ultrashort optical pump.  Phys. Rev. B, 84:125102, 2014.
  * [69] L. Waldecker, R. Bertoni, and R. Ernstorfer.  Electron-phonon coupling and energy flow in a simple metal beyond the two-temperature approximation.  Phys. Rev. X, 6:021003, 2016.
  * [70] V. M. Shalaev, C. Douketis, J. T. Stuckless, and M. Moskovits.  Light-induced kinetic effects in solids.  Phys. Rev. B, 53:11388, 1996.
  * [71] M. Durach and N. Noginova.  Plasmon drag effect. theory and experiment.  in S. E. Hunyadi Murph and G. K. Larsen and K. J. Coopersmith, Editors, Anisotropic and Shape-Selective Nanomaterials Structure-Property Relationships, Ch. 8, 2010.
  * [72] K. Y. Bliokh, F. J. Rodríguez-Fortuno, A. Y. Bekshaev, Y. S. Kivshar, and F. Nori.  Electric-current-induced unidirectional propagation of surface plasmon-polaritons.  Opt. Lett., 43:963–966, 2018.
  * [73] A. Reklaitis.  Terahertz emission from inas induced by photo-dember effect: Hydrodynamic analysis and monte carlo simulations.  J. Appl. Phys., 108:053102, 2010.
  * [74] W. C. Chew and W. H. Weedon.  3D perfectly matched medium from modified Maxwell’s equations with stretched coordinates.  Microwave and Optical Tech. Lett., 7:599–604, 1994.


# Schemes in Lean

Kevin Buzzard<EMAIL_ADDRESS>Department of Mathematics, Imperial
College London  ,  Chris Hughes<EMAIL_ADDRESS>Department of Mathematics, Imperial College London  ,  Kenny Lau
<EMAIL_ADDRESS>Department of Mathematics, Imperial College London  ,
Amelia Livingston<EMAIL_ADDRESS>Department of
Mathematics, Imperial College London  ,  Ramon Fernández Mir
<EMAIL_ADDRESS>School of Informatics, University of Edinburgh
and  Scott Morrison<EMAIL_ADDRESS>School of Mathematics and Statistics,
University of Sydney

###### Abstract.

We tell the story of how schemes were formalised in three different ways in
the Lean theorem prover.

The first author was supported in part by EPSRC grant EP/L025485/1.

##  1\. Introduction and overview

###  1.1. Varieties and schemes in algebraic geometry

Before 1960, algebraic geometry was done via the theory of algebraic
varieties, finite-dimensional objects defined over a fixed algebraically
closed field, or “universal domain”. The standard reference text was Weil’s
1946 book “Foundations of algebraic geometry” [Wei46], and in the final
chapter “Comments and discussions”, Weil remarks that “it would be very
convenient to have…a principle of reduction modulo $p$ ”, a phenomenon which
Weil would have known well should exist but which was extremely inconvenient
to do in this setting.

Schemes were introduced by Grothendieck in the 1960s (following earlier ideas
of Chevalley, and building on ideas of Zariski) as the building blocks for a
new algebraic geometry. Grothendieck did not need to work over a fixed base
field; his foundations worked with general commutative rings rather than
algebraically closed fields, enabling reduction modulo $p$ to become possible.
Given a general “geometric object” (for example, a topological space), one can
consider the set of continuous real-valued functions on this object, and
pointwise addition and multiplication turn this space of functions into a
commutative ring. Grothendieck’s observation was that one could make a
construction in the opposite direction: starting with an arbitrary commutative
ring $R$, he constructed a geometric object ${\operatorname{Spec}\,}(R)$
called an _affine scheme_ ; this was a topological space equipped with a sheaf
of functions $\mathcal{O}_{X}$ on this space, such that
$\mathcal{O}_{X}({\operatorname{Spec}\,}(R))$, the “allowable” functions on
${\operatorname{Spec}\,}(R)$, was $R$ again. Grothendieck defined a general
_scheme_ by gluing affine schemes together (following Weil, who in [Wei46] had
defined an abstract variety by gluing affine varieties together111Note that
Whitney had defined an abstract real manifold ten years earlier in [Whi36], by
gluing together open subsets of Euclidean space in the now familiar way.).
This new viewpoint proved incisive – ten years later the Weil conjectures,
questions about the number of points which algebraic varieties have over
finite fields, were being proved using machinery such as étale cohomology,
which had been developed using schemes.

###  1.2. Formalising schemes – the history

As mentioned in the abstract, schemes were formalised three times in Lean
[dKA+15]; each formalisation was better-behaved than the one before.

The first formalisation was by the first three authors (KB, CH, KL), and it
evolved in late 2017 and early 2018 from the Thursday evening Xena Project
meetings at Imperial College London, where undergraduates learn how to
formalise mathematics in Lean (KB is the staff member running the meetings; CH
and KL were, at the time, first year mathematics undergraduates). It started
with KL formalising the theory of localisation of rings as a project, and with
KB suggesting that schemes would be a natural way to take the theory further
in Lean. It was their first attempt to formalise anything non-trivial in a
theorem prover (and its ultimate success inspired KB to see exactly how far
Lean could be pushed, eventually resulting in [BCM20]). However some poor (in
retrospect) design decisions were made when it came to the theory of
localisation, and in this first iteration these decisions resulted in messy
infrastructure which would not scale. It quickly became clear that an
extensive rewrite was needed. It also became apparent that such a
formalisation had never been embarked upon before in any other theorem prover
(parts of the theory of affine schemes had been formalised, but nothing
approaching the definition of a scheme) – this perhaps says something about
the interests of mathematical formalisation community, at least pre-2017. The
(abandoned) project is still currently online at [BHL18].

AL and RFM then joined the project, with AL developing a very robust theory of
localisation in the form which was needed, and RFM rewriting the definition of
a scheme from scratch as part of his 2018–2019 MSc project supervised by KB.
RFM ultimately produced a definition which was usable – indeed several other
basic results from the Stacks project website [Sta21] and Hartshorne’s
algebraic geometry textbook [Har77] were also proved in this iteration, mostly
by KL. This version is currently online at [FM19].

However, sheaves were defined “by hand” in this iteration; there was one
definition for a sheaf of types (or sheaf of sets, depending on your
foundations), one for a sheaf of abelian groups and another one for a sheaf of
rings. The contribution of SM was to build enough abstract category theory in
Lean to enable a third definition using this category-theoretic language. At
this point a design change was also made; the definition of the sheaf on
${\operatorname{Spec}\,}(R)$ was changed from the definition in [Sta21] to the
equivalent definition in [Har77]. This was the version which finally made it
into Lean’s mathematics library, in commit
b79fc0379ae786153fc22ce5ee6751505e36a3d9 of mathlib [mat20,
src/algebraic_geometry/Scheme.lean]. The current mathlib documentation for
schemes (perhaps more readable for people who do not want to look directly at
the code) is available at the Lean community website.

###  1.3. Organisation of the paper.

Most of the formalisation was plain sailing, but occasionally we ran into
unexpected problems. The layout of this paper is as follows. In the next
section we go over the details of some of the mathematics involved. In the
three sections after that we explain the three approaches to formalising the
material, emphasising the parts which did not go smoothly and explaining how
this affected future design decisions.

##  2\. Mathematical details.

Convention: all rings are commutative and have a 1; all ring homomorphisms
send 1 to 1.

Let $X$ be a topological space. A _presheaf of rings_ $\mathcal{F}$ on $X$ is
a way to associate a ring $\mathcal{F}(U)$ to each open subset $U\subseteq X$,
and a ring homomorphism $\rho_{UV}:\mathcal{F}(U)\to\mathcal{F}(V)$ to each
inclusion $V\subseteq U$ of open subsets of $X$, such that $\rho_{UU}$ is the
identity for all opens $U$, and $\rho_{WU}=\rho_{VU}\circ\rho_{WV}$ if
$U\subseteq V\subseteq W$. In other words, $\mathcal{F}$ is a contravariant
functor from the category of open subsets of $X$ to the category of rings. If
$f\in\mathcal{F}(U)$ and $V\subseteq U$, we write $f|_{V}$ as shorthand for
$\rho_{UV}(f)$. The model example to keep in mind is where $\mathcal{F}(U)$ is
defined to be the ring of continuous functions $U\to{\mathbb{R}}$, and
$\rho_{VU}$ sends a continuous function on $U$ to its restriction to $V$.

A presheaf of rings $\mathcal{F}$ is said to be a _sheaf of rings_ if elements
of $\mathcal{F}(U)$ can “be defined locally”. More precisely, a presheaf of
rings $\mathcal{F}$ is a sheaf of rings if for every open set $U$ and every
open cover $U=\bigcup_{i\in I}U_{i}$ of $U$ by open sets $U_{i}$, the sequence

$None$ $0\to\mathcal{F}(U)\to\prod_{i\in I}\mathcal{F}(U_{i})\to\prod_{i,j\in
I}\mathcal{F}(U_{i}\cap U_{j})$

is exact, where the map $\mathcal{F}(U)\to\prod_{i}\mathcal{F}(U_{i})$ sends
$f$ to $(f|_{U_{i}})$, and the map
$\prod_{i}\mathcal{F}(U_{i})\to\prod_{i,j}\mathcal{F}(U_{i}\cap U_{j})$ sends
$(f_{i})$ to the element whose value at $(i,j)$ is $f_{i}|_{U_{i}\cap
U_{j}}-f_{j}|_{U_{i}\cap U_{j}}$. In words, the exactness of $({\ddagger})$ is
the assertion that if you have a collection of elements
$f_{i}\in\mathcal{F}(U_{i})$ which agree on all overlaps $U_{i}\cap U_{j}$,
then there is a unique $f\in\mathcal{F}(U)$ whose restriction to $U_{i}$ is
$f_{i}$ for all $i$. A topological space $X$ equipped with a sheaf of rings
$\mathcal{O}_{X}$ is called a _ringed space_.

If $(X,\mathcal{O}_{X})$ is a ringed space, then to each point $u\in X$ one
can associate the _stalk_ $\mathcal{O}_{X,x}:=\varinjlim_{x\in
U}\mathcal{O}_{X}(U)$ of “functions defined near $x$”, a filtered colimit of
rings and hence also a ring. If this ring is local (that is, has a unique
maximal ideal) for every $x\in X$ we say that $(X,\mathcal{O}_{X})$ is a
_locally ringed space_.

A fundamental construction in this area is the following. Given a ring $R$,
let ${\operatorname{Spec}\,}(R)$ denote the set of its prime ideals. The
Zariski topology is a natural topology on ${\operatorname{Spec}\,}(R)$: for
$I$ an ideal we define $V(I)$ to be the prime ideals of $R$ containing $I$,
and the $V(I)$ as $I$ varies are the closed sets of
${\operatorname{Spec}\,}(R)$. We shall explain later how to use the theory of
localisations of rings to construct a presheaf of rings ${\mathcal{O}}_{R}$ on
${\operatorname{Spec}\,}(R)$ and to prove that it is a sheaf. The ringed space
$({\operatorname{Spec}\,}(R),\mathcal{O}_{R})$ is locally ringed, and is
called the _affine scheme_ associated to the ring $R$.

A _scheme_ is a locally ringed space $(X,\mathcal{O}_{X})$ with the property
that $X$ can be covered by opens $U_{i}$ such that the induced locally ringed
space $(U_{i},\mathcal{O}_{X}|_{U_{i}})$ is isomorphic to
$({\operatorname{Spec}\,}(R_{i}),\mathcal{O}_{R_{i}})$ for some ring $R_{i}$.

If $R$ is a ring then ${\operatorname{Spec}\,}(R)$ is a scheme, because it can
be covered by the open affine subset $U={\operatorname{Spec}\,}(R)$.

To KB’s naive eyes in 2017, everything here looked straightforward. But in
fact there were several gotchas involved in turning this into a formal
definition. The rest of this paper describes them, and how they were dealt
with in Lean.

##  3\. The first definition.

We begin with a discussion of localisation, and the construction of the sheaf
of rings on the topological space associated to a ring. Let $R$ be a ring and
let $S$ be a submonoid of $(R,\times)$ (for some reason mathematicians often
call $S$ a “multiplicative subset”; it contains $1$ and is closed under
multiplication so it is precisely a submonoid). The _localisation_ $R[1/S]$ of
$R$ at $S$ is a ring equipped with a canonical map $i:R\to R[1/S]$ and having
the following universal property: for any ring $A$ and any map $f:R\to A$ such
that $f(s)\in A^{\times}$ for all $s\in S$, there is a unique extension
$\tilde{f}:R[1/S]\to A$ of $f$ to $R[1/S]$ making the obvious diagram

$\textstyle{R[1/S]\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{\exists!\tilde{f}}$$\textstyle{R\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{i}$$\scriptstyle{f}$$\textstyle{A}$

commute. The special case where $S$ is the submonoid
$\\{1,f,f^{2},f^{3},\ldots\\}$ generated by $f\in R$ has its own notation
$R[1/f]$.

Standard arguments involving universal objects show that $R[1/S]$ is uniquely
defined up to unique isomorphism, if it exists. In fact, these latter
arguments do not even assume that $S$ is a submonoid; in general the
localisation at a general subset $S$ of $R$ is the localisation at the
submonoid of $R$ generated by $S$. Existence is shown by an explicit
construction: one puts an appropriate equivalence relation on $R\times S$ (an
element $(r,s)$ is thought of as representing the fraction $r/s$) and puts a
ring structure on the quotient. All of this was formalised in Lean with little
fuss.

The construction of the topological space ${\operatorname{Spec}\,}(R)$ was
equally uneventful. Next, a decision had to be made about how to put a sheaf
of rings on ${\operatorname{Spec}\,}(R)$; there are several constructions in
the literature. The prevailing philosophy of KB at the time was “always follow
the Stacks project”.222The Stacks project [Sta21] covers a huge swathe of
algebraic geometry and its prerequisites. As the project was largely a
collaboration by KB with undergraduates, the fact that the Stacks project is
freely available online was helpful as it was accessible to everyone.
Moreover, the Stacks project is careful to use ‘Tags’, which never change, to
refer to particular theorems or sections of the material, so it is easy to
cross-reference. The approach in the Stacks project is as follows. Let $X$ be
a topological space. In [Sta21, Tag 009H] it is explained how to set up the
theory of presheaves and sheaves on a basis for the topology on $X$, and in
[Sta21, Tag 009N] it is shown how to extend a sheaf on a basis for $X$ to a
sheaf on $X$. Formalisation of these results, and their extension to sheaves
of rings, was straightforward. Indeed, this part of the formalisation went
like a dream – one line of very abstract categorical mathematics would
correspond to one line of Lean code. These arguments reduced the question to
defining a sheaf on the basis of ${\operatorname{Spec}\,}(R)$ consisting of
open sets of the form $D(f)$, where $f\in R$ and $D(f)$ is the set of prime
ideals not containing $f$. A set of the form $D(f)$ is called a _basic open
set_. Note that $D(f)$ is open, because it is the complement of the closed set
$V(I)$ where $I=(f)$.

###  3.1. Definition of $\mathcal{O}_{X}(D(f))$, and “canonical maps”.

This was a part of the story where things did not go as smoothly as envisaged.
The first problem was this. Say $R$ is a ring, and $f,g\in R$ have the
property that $D(f)=D(g)$, that is, a prime ideal contains $f$ if and only if
it contains $g$. This can certainly happen in non-obvious ways – for example
if $x\in R$ and $f=x^{2}$ and $g=-x^{3}$, then a prime ideal contains $g$ if
and only if it contains $x$, and so if and only if it contains $f$. The
literature happily defines $\mathcal{O}_{X}(D(f))$ to be $R[1/f]$ – see for
example this commit of [Sta21, Tag 01HT]:

> If $f,g\in R$ are such that $D(f)=D(g)$, then by Lemma 01HS above there are
> canonical maps $M_{f}\to M_{g}$ and $M_{g}\to M_{f}$ which are mutually
> inverse. Hence we may choose any $f$ such that $U=D(f)$ and define
> $\tilde{M}(U)=M_{f}$.

(Here $M_{f}$ is a module-theoretic generalisation of $R[1/f]$). No definition
of “canonical” is supplied. The same is seen in Grothendieck’s original work –
in [Gro60], section 1.3.1 of Chapter I, it is written

> on sait que $A_{f}$ et $M_{f}$ s’identifient canoniquement á
> $S_{f}^{\prime-1}A$ et $S_{f}^{\prime-1}M$

(again with no definition of “canoniquement”) and in 1.3.3 we see “un
homomorphisme canonique fonctoriel $M_{f}\to M_{g}$”, and the first usage of
“$M_{f}=M_{g}$” to denote a “canonical” isomorphism rather than a set-
theoretic identity. Having established that $R[1/f]=R[1/g]$ (for this new
“canonically isomorphic” meaning of $=$) Grothendieck defines
$\mathcal{O}_{X}(D(f))=R[1/f]$ and $\mathcal{O}_{X}(D(g))=R[1/g]$ and
continues.

This becomes an issue in Lean, because in our formalisation we have rings
$R[1/f]$ and $R[1/g]$ which are most definitely _not_ equal; certainly the
universal property gives isomorphisms between them, but one of these rings is
a quotient of $R\times\\{1,f,f^{2},f^{3},\ldots\\}$ and the other is a
quotient of $R\times\\{1,g,g^{2},g^{3},\ldots\\}$. If you like to think set-
theoretically, you can think of an element of $R[1/f]$ as being a subset (an
equivalence class) of $R\times\\{1,f,f^{2},\ldots\\}$ and an element of
$R[1/g]$ as being a subset of $R\times\\{1,g,g^{2},\ldots\\}$. In particular,
$R[1/f]$ and $R[1/g]$ are visibly not _equal_.

One solution to this problem would be to throw the axiom of choice at it. For
each open set $U\subseteq{\operatorname{Spec}\,}(R)$ which is known to be of
the form $D(f)$ for some $f$ (possibly infinitely many), we choose some
“special” $f_{U}$ such that $U=D(f_{U})$ and define
$\mathcal{O}_{X}(U):=R[1/f_{U}]$. This of course works, but we envisaged that
this definition would be frustrating to work with down the line.

Reid Barton on the Lean chat suggested the following approach instead, which
was what we ultimately chose. If the open set $U$ is known to be of the form
$D(f)$, then define $S_{U}$ to be the submonoid $\\{g\in R\,|\,U\subseteq
D(g)\\}$ of elements of $R$ which are non-zero on $U$, and define
$\mathcal{O}_{X}(U):=R[1/S_{U}]$. This has the advantage that no choices are
involved; it bears the hallmark of a construction in constructive mathematics,
where a rule of thumb is that if you can’t figure out a natural way to choose
one object from a set, then choose all of them.

This defines a presheaf of rings $\mathcal{O}_{X}$ on the basic open subsets
$D(f)$ of ${\operatorname{Spec}\,}(R)$, and by taking limits one can extend
this definition to give a presheaf of rings on all of
${\operatorname{Spec}\,}(R)$. Amusingly, we then realised that to define
schemes, this presheaf construction was all we needed.

###  3.2. Defining schemes.

We defined a scheme to be a topological space $X$ equipped with a sheaf of
rings $\mathcal{O}_{X}$, for which $X$ had a cover $X=\bigcup_{i}U_{i}$ such
that each $U_{i}$ was isomorphic to ${\operatorname{Spec}\,}(R_{i})$ for some
ring $R_{i}$.

This isomorphism is in the books usually stated as an isomorphism of locally
ringed spaces. However a locally ringed space is just a topological space
equipped with a presheaf of rings and satisfying some extra axioms, so in
particular an isomorphism of locally ringed spaces is the same as an
isomorphism of spaces equipped with presheaves of rings. We have already
defined a presheaf of rings on ${\operatorname{Spec}\,}(R)$, so we are almost
done. It remains to define the pullback presheaf of rings on $U_{i}$, and this
is easy: if $\iota:U_{i}\to X$ is the open immersion, then for $V\subseteq
V_{i}$ open, the corresponding subset $\iota(V)\subseteq X$ is an open subset
of $X$, so we define the presheaf $\iota^{*}\mathcal{O}_{X}$ by
$\iota^{*}\mathcal{O}_{X}(V)=\mathcal{O}_{X}(\iota(V))$. It was
straightforward to check that $\iota^{*}\mathcal{O}_{X}$ is a presheaf of
rings on $U_{i}$, and our definition of a scheme was complete. Note that we
did not need to demand that our original ringed space was locally ringed –
this follows from the fact that it is locally affine. In particular, our
definition is mathematically equivalent to the usual definition, although the
proof of this involves theorems which were not at this time formalised.

Our original definition was met with some scepticism by the computer
scientists in the Lean community, however, and not for this reason above. A
definition with no unit tests might contain an error. It was suggested that we
prove a theorem about schemes, to provide evidence that our definition was
correct. We decided to prove the theorem that an affine scheme was a scheme.
Although the result sounds trivial, some work remains: a scheme is a space
equipped with a sheaf of rings, and we have thus far only equipped
${\operatorname{Spec}\,}(R)$ with a presheaf of rings. To prove that affine
schemes are schemes should be essentially equivalent to proving that the
presheaf $\mathcal{O}_{X}$ of rings on ${\operatorname{Spec}\,}(R)$ is a
sheaf.

###  3.3. Proving $\mathcal{O}_{X}$ is a sheaf on
${\operatorname{Spec}\,}(R)$.

Again, we followed the Stacks project. Here we ran into a serious technical
issue, and one might even argue that this issue is typically overlooked in the
literature – it seems to be a very good example of a situation where
mathematicians pay no attention to the details of what is happening, knowing
that things are going to work out. When formalising, one has to check these
details.

Let us explain the main problem. We need to check the sheaf axiom for
$\mathcal{O}_{X}$ considered as a sheaf on the basis $D(f)$ of open sets in
${\operatorname{Spec}\,}(R)$. A formal argument involving compactness reduces
us to the case of a cover of a basic open by finitely many basic opens, so all
that remains is checking that the sheaf axiom $({\ddagger})$ holds for a cover
of a basic open set by finitely many basic open sets.

The argument in [Sta21, Tag 01HR] now proceeds like this:

Step 1: If $D(f)$ is a basic open in ${\operatorname{Spec}\,}(R)$, then $D(f)$
is canonically isomorphic to ${\operatorname{Spec}\,}(R[1/f])$, and the
isomorphism identifies basic open subsets in ${\operatorname{Spec}\,}(R[1/f])$
with the basic open subsets in ${\operatorname{Spec}\,}(R)$ contained within
$D(f)$. This reduces us to the case of checking that the sheaf axiom
$({\ddagger})$ holds for finite covers of ${\operatorname{Spec}\,}(R)$ by
basic opens;

Step 2: One can now translate the statement into a purely ring-theoretic lemma
[Sta21, Tag 00EJ].

We proceeded in reverse order, with CH proving the ring-theoretic lemma first.
Let us state it here:

######  Lemma 3.3.1 (Tag 00EJ).

Let $R$ be a ring, and say $f_{1}$, $f_{2},\ldots,f_{n}\in R$ generate the
unit ideal. Then the following sequence is exact:

$0\longrightarrow
R\stackrel{{\scriptstyle\alpha}}{{\longrightarrow}}\bigoplus_{i}R[1/f_{i}]\stackrel{{\scriptstyle\beta}}{{\longrightarrow}}\bigoplus_{i,j}R[1/f_{i}f_{j}].$

Here the map $\alpha$ is the obvious one, and the map $\beta$ sends $r_{i}$ to
the element whose $(i,j)$ component is $r_{i}-r_{j}$.

It was only after we applied this to make progress with Step 1 that we
understood the subtleties in what was left. The “canonical” identification of
basic opens in ${\operatorname{Spec}\,}(R[1/f])$ with basic opens in
${\operatorname{Spec}\,}(R)$ involved, when identifying global sections, an
identification of $R[1/f][1/g]$ with $R[1/fg]$. Of course these rings are
canonically isomorphic, but they are not equal. In short, we had a proof of
exactness of

$0\to
R[1/f]\to\bigoplus_{i}(R[1/f])[1/f_{i}]\to\bigoplus_{i,j}(R[1/f])[1/f_{i}f_{j}]$

and we needed333Strictly speaking we needed a little more than this; in our
situation $f_{i}\in R[1/f]$ rather than $R$, however this special case (a
cover of $U$ coming from a cover of $X$) is already enough to illustrate the
problem we had. a proof of exactness of

$0\to R[1/f]\to\bigoplus_{i}R[1/ff_{i}]\to\bigoplus_{i,j}R[1/ff_{i}f_{j}].$

To a mathematician, essentially nothing needs to be done here. A mathematician
might say “the diagrams are the same; one is exact, so the other is” and this
would be an acceptable proof. Pressed for more details, a mathematician might
offer the following explanation:

$\textstyle{0\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{=}$$\textstyle{R[1/f]\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{=}$$\textstyle{\bigoplus_{i}(R[1/f])[1/f_{i}]\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{=}$$\textstyle{\bigoplus_{i,j}(R[1/f])[1/f_{i}f_{j}]\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\scriptstyle{=}$$\textstyle{0\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\textstyle{R[1/f]\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\textstyle{\bigoplus_{i}R[1/ff_{i}]\ignorespaces\ignorespaces\ignorespaces\ignorespaces}$$\textstyle{\bigoplus_{i,j}R[1/ff_{i}f_{j}]}$

Here all the vertical maps are canonical and all the horizontal maps are
defined in a natural way and hence the squares will all obviously commute.

However in Lean this needs to be checked! Lean has no concept of what it means
for an isomorphism to be _canonical_ (and looking at the Wikipedia page on
canonical maps one indeed discovers that there seems to be no formal
definition of the word), and we needed to explicitly check that the squares in
the above diagram commute.

So it came to pass that one line in the Stacks project tag 01HR (“Thus we may
apply Lemma 10.22.2…We conclude that the sequence is exact”) became several
hundred lines of Lean code. In retrospect it would have been much easier to do
a diagram chase. However we had a belief that “everything would follow
immediately from the universal property” and instead went down this route,
which was more troublesome than one might expect, because for example the
homomorphism $\beta$ above is not a ring homomorphism and hence the universal
property cannot be used! We ultimately resorted to proving a lemma showing
that there was at most one $R$-algebra map from $R[1/S]$ to $R[1/T]$ and used
this to finish. We proved that the squares commuted, and deduced that the
presheaf of rings on ${\operatorname{Spec}\,}(R)$ was a sheaf. Our goal of
proving that affine schemes were schemes was now in sight.

###  3.4. Interlude: the univalence axiom.

Lean does not have the univalence axiom; indeed this axiom contradicts the
axiom in Lean saying that all proofs of a theorem of the form $A=B$ are equal.
The importance of equality in mathematics is that if $A=B$, and if $C(A)$ is
any theorem statement or proof about $A$, then because $A=B$ we have access to
the corresponding $C(B)$ about $B$. This process, in a formal proof system, is
called _substitution_ , or _rewriting_. Univalent systems have a rich concept
of equality, where things can be equal in more than one way, whilst preserving
this substitution property. The univalence axiom essentially says that if $A$
and $B$ are structures like rings then there’s a bijection between
isomorphisms $A\to B$ and proofs of $A=B$.

In particular, in a univalent system, the ring isomorphism $R[1/fg]\cong
R[1/f][1/g]$ can be promoted to an equality (for this richer concept of
equality) and now it looks on the face of it that a rewrite would be able to
make progress. However, univalence does _not_ solve the problem which we
encountered here. After the substitution in a univalent system, we would have
a proof of exactness of one diagram, and we want to prove exactness of another
diagram, and the diagrams now have the same objects, however we need to check
that they have the same morphisms! Checking this of course boils down to
checking that the squares commute, so the lion’s share of the work still needs
to be done. In our original definition of a scheme, we did the diagram chase
“manually”. However in our second iteration of the definition, we will
introduce ideas which enable us to avoid this rewriting problem completely.

###  3.5. Affine schemes are schemes.

With the proof that ${\operatorname{Spec}\,}(R)$ is a ringed space, we can now
attempt to prove that it is a scheme. This provided one final surprise in our
formalisation, and again Reid Barton explained the way around it. Our cover of
${\operatorname{Spec}\,}(R)$ by affines is just the identity map
$\iota:{\operatorname{Spec}\,}(R)\to{\operatorname{Spec}\,}(R)$, and all that
remains is to show that the presheaves $\mathcal{O}_{X}$ and
$\iota^{*}\mathcal{O}_{X}$ on ${\operatorname{Spec}\,}(R)$ are isomorphic.
This boils down to the following: if $U$ is an open subset of
${\operatorname{Spec}\,}(R)$ then we need to produce an isomorphism between
$\mathcal{O}_{X}(U)$ and $\mathcal{O}_{X}(\iota(U))$ which commutes with
restriction maps.

Our first attempt to do this was the following. Note that $\iota$ is the
identity map. Hence $\iota(U)=U$, and thus
$\mathcal{O}_{X}(\iota(U))=\mathcal{O}_{X}(U)$. Let’s define the isomorphism
to be the identity map. Checking that the diagrams commute should then be
straightforward.

But it was not straightforward; one now has to check that
$\rho_{\iota(U)\iota(V)}=\rho_{UV}$, and replacing $\iota(U)$ with $U$ in a
naive manner caused Lean to give motive is not type correct errors. Ultimately
we were able to get this working, but what is going on here? Mathematically
there seems to be no issue.

We learnt from Mario Carneiro what the problem was. The fact that $\iota(U)=U$
is a trivial theorem, but, perhaps surprisingly, it is not true by definition.
The definition of $\iota(U)$ is that it is the set of $x\in X$ such that there
exists $u\in U$ with $u=x$. Hence in particular $x\in\iota(U)\iff x\in U$
(this is true by definition), and hence $\iota(U)=U$, because two sets are
equal if and only if they have the same elements (this is the axiom of set
extensionality). We have proved that $\iota(U)=U$, but along the way we
invoked an axiom of mathematics and in particular the equality is not
definitional. This means that rewriting the equality $\iota(U)=U$ can cause
technical problems with data-carrying types such as
$\mathcal{O}_{X}(\iota(U))$ which depends on $\iota(U)$ (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.

Fortunately, in our case, Reid Barton pointed out the following extraordinary
trick to us: we can define the map
$\mathcal{O}_{X}(\iota(U))\to\mathcal{O}_{X}(U)$ using _restriction_ rather
than trying to force it to be the identity! Using restriction means that we
need to supply a proof that $U\subseteq\iota(U)$, but this is trivial (and who
cares that it uses an axiom, we are not trying to rewrite anything). The fact
that the diagram commutes now just boils down to the fact that restriction
from $\iota(U)$ to $V$ via $U$ equals restriction from $\iota(U)$ to $V$ via
$\iota(V)$, which follows from the presheaf axiom of transitivity of
restrictions. This is certainly not the way that one would usually think about
this, but it works fine.

###  3.6. Conclusions

The main problem with this first approach was the issue with localisations.
The ring $R[1/S]$ was defined as an explicit ring, and theorems were proved
about it; later on when it came to apply these theorems, it turned out that in
our application we only had a ring isomorphic to $R[1/S]$ rather than our
explicit definition on the nose. These issues were solved in our second
approach.

##  4\. The second definition.

Apparently there’s a saying in computer science: “Build one to throw away”.
Having done this, we now knew what we should be doing; we had to develop a
better theory of localisation. We now describe how we did this.

###  4.1. Localisation

The error we had initially made was to only define “the” localisation $R[1/S]$
of a ring $R$ at a submonoid $S$. The localisation is defined up to unique
isomorphism, but pinning it down as an explicit set (or more precisely an
explicit type, as Lean uses type theory rather than set theory) turned out to
be a bad idea. What we needed instead is a predicate is_localisation_by S on
ring homomorphisms $R\to T$, saying that $R\to T$ is isomorphic to $R\to
R[1/S]$ in the category of $R$-algebras, or in other words that $T$ is
isomorphic to $R[1/S]$ in a manner compatible with the $R$-algebra structure.
We will refer to this predicate by saying that the $R$-algebra $T$ is _a
localisation of $R$ at $S$_, as opposed to “the” localisation of $R$ at $S$.

AL noted that in fact localising rings at submonoids was not the primitive
notion: in fact, as Bourbaki taught us, one should be localising monoids at
submonoids, and attaching ring structures later on. AL developed an entire
formalised theory of localisation of monoids, with both the “explicit”
constructions $M[1/S]$ and the “predicate” approach, showing that the explicit
constructions satisfied the predicate, and proving universal properties both
for the explicit construction and the predicate construction. These files now
form the foundation of the theory of localisation in mathlib.

###  4.2. The sheaf on an affine scheme, again

RFM rewrote schemes from scratch, tidying up the code along the way and also
moving away from the disastrous design decision of calling Lean files by their
Stacks project tags (tags should be mentioned in docstrings, not filenames;
filenames serve a useful organisational purpose). The refactoring to using
predicates instead of explicit constructions meant that there was no longer
any need to make the substitution of $R[1/f][1/g]$ into a lemma explicitly
naming $R[1/fg]$; all one has to do is to prove that $R[1/f][1/g]$ satisfies
the predicate for being a localisation of $R$ at the submonoid generated by
$fg$, which is straightforward. This shortened the definition by hundreds of
lines of code.

The hard work, or so we thought, would be in reproving the ring-theoretic
lemma [Sta21, Tag 00EJ] (Lemma 3.3.1) in this more general form. The issue
here is that CH’s original formalisation was an explicit computation involving
the rings $R[1/f_{i}]$ and $R[1/f_{i}f_{j}]$; what we now needed was to
_reprove_ this lemma for _all_ rings satisfying the localisation predicate
instead. The beefed-up lemma would then apply in situations where the original
lemma did not, meaning that the diagram chase described in section 3.3 would
no longer be necessary.

###  4.3. The localisation predicate

Definitions are important when formalising. Here are two definitions of being
“a localisation of $R$ at $S$”:

Definition 1. An $R$-algebra $T$ is _a localisation of $R$ at $S$_ if there
exists an $R$-algebra isomorphism $T\cong R[1/S]$.

Definition 2. An $R$-algebra $T$ is _a localisation of $R$ at $S$_ if it
satisfies the universal property of $R[1/S]$: if $R\to A$ is any ring
homomorphism sending $S$ into $A^{\times}$, there exists a unique map $T\to A$
making the diagram commute.

These definitions are mathematically equivalent, so to a mathematician they
may as well both be the definition. However Neil Strickland proposed a third
definition:

Definition 3 (Strickland). An $R$-algebra $f:R\to T$ is a _localisation of $R$
at $S$_ if it satisfies the following three conditions:

  * •

$f(S)\subseteq T^{\times}$;

  * •

Every $t\in T$ can be written as $f(r)/f(s)$ for some $r\in R$ and $s\in S$;

  * •

The kernel of $f$ is the annihilator of $S$.

It is not difficult to prove that Strickland’s definition of the predicate is
equivalent to the other two. Indeed an explicit computation using the explicit
construction of $R[1/S]$ as a quotient of $R\times S$ shows that it satisfies
Strickland’s predicate, and conversely any $R$-algebra $T$ satisfying
Strickland’s predicate admits a map from $R[1/S]$ (by the universal property
and the first condition), which can be explicitly checked to be surjective
(from the second condition) and injective (from the third condition).

So which definition should one use? This is not a mathematical question, it is
what is known as an _implementation issue_ , or a design decision. Ultimately
of course the goal is to prove that all of the definitions are equivalent. But
where does one start? One would like to fix one of them and then develop an
_interface_ , or _API_ , for it. This is a collection of basic theorems about
our predicate (some deducing it, some using it) which will ultimately lead to
a formal proof that it is equivalent to the other two definitions. In
particular, one will sometimes have to _verify_ the predicate, and one will
sometimes have to _use_ it.

Strickland’s predicate had advantages over the other two definitions when it
comes to using it. In particular, it does not involve quantification over all
rings. Using a property involving quantification over all rings often involves
having to construct a ring with nice properties and then applying the
universal property to that ring. For example, we invite the reader to prove
that any $R$-algebra $T$ satisfying the universal property of being a
localisation (definition 2) also has the property that the kernel of $R\to T$
is the annihilator of $S$. The shortest way we know how to do this from first
principles is to first show that the explicitly constructed ring $R[1/S]$
satisfies the universal property, secondly to prove that two rings satisfying
the universal property are isomorphic as $R$-algebras, and finally to do an
explicit calculation of the kernel of the map $R\to R[1/S]$ to prove the
result. Of course there is no problem formalising this proof, but it gives an
idea as to how much work it is to build an API for definition 2.

Ultimately one has to fix one definition of the predicate, and then prove that
it is equivalent to the other two; there will always be some work involved.
But “API building” turned out to be easiest with Strickland’s definition,
which is the one RFM used.

###  4.4. Reproving 00EJ

What remains to be done is to reprove Lemma 3.3.1 not for our rings $R[1/f]$
but more generally for rings satisfying Strickland’s predicate. To our
surprise, this turned out to be very easy. Indeed, the _only_ facts about the
$R$-algebras $R[1/S]$ used in the Stacks project proof in 2017444note now that
the proof has been changed; the proof formalised in our project is the one
from algebra.tex in the Stacks project as it stood in late 2017 after commit
39135dd. were precisely the ones isolated by Strickland! The refactoring was
hence far easier than expected. In some sense, what happened here was that we
made the statement of the lemma more general, and noted that the same proof
still worked.

###  4.5. Definition and usage.

RFM also set up the theory of locally ringed spaces, enabling us to define a
scheme as a locally ringed space which was locally affine. The proof that an
affine scheme is a scheme now also needs a new proof, namely that the stalks
of $\mathcal{O}_{X}$ were local rings. This needed some of the theory of
filtered colimits, but this did not present any particular problems.

KL used the definitions of the project in this form to do the “gluing sheaves”
Exercise II.1.22 in Hartshorne’s algebraic geometry textbook [Har77] and also
to prove that ${\operatorname{Spec}\,}$ was adjoint to the global sections
functor on locally ringed spaces [Sta21, Tag 01I1]. However when it came to
start thinking about porting our definition into Lean’s mathematics library,
we ran into a problem. Part of our code was still sub-optimal: we had a
definition of a sheaf of types, and a definition of a sheaf of rings. These
notions should be unified under some more general notion of a sheaf of objects
in a category. Thus the third definition was born.

##  5\. The third definition: sheaves done correctly.

###  5.1. Category theory in mathlib

SM has been the main driving force behind a gigantic category theory library
in Lean. In early 2018, a combination of his work not yet being mature enough,
and there not being much infrastructure to support easily working on branches
of mathlib, meant that we had developed our own definitions of sheaves rather
than using category theory. By 2020 this was no longer the case, and SM’s
definition of a presheaf taking values in a category was the natural thing to
use for the “official” definition of a scheme. We had seen with our own eyes
the problems of having one definition of presheaves of types and another
definition of presheaves of rings – we were constantly having to prove results
for presheaves of types and then prove them again for presheaves of rings.
Ultimately we had to completely refactor the sheaf part of the story, but we
took this opportunity to introduce category theory more generally. Another
advantage of the third definition is that rather than working in a new project
with mathlib as a dependency, we worked directly on a branch of mathlib, and
ultimately the code ended up as part of mathlib meaning that it will not
quickly rot and die, as is very very common with Lean code which is not in
mathlib (mathlib is not backwards compatible – it is still in some sense an
experimental library and occasionally big design decisions are changed in an
attempt to make it better).

###  5.2. Changes made to the definition.

We go through the final definition, pointing out how it differs from the
previous version. In this definition, a scheme is an object in the category
LocallyRingedSpace which is locally isomorphic to an affine scheme. The
abstract nonsense presented no surprises; the work left, when defining a
scheme and proving that affine schemes are schemes, is to define the sheaf of
rings on ${\operatorname{Spec}\,}(R)$ in this language. This time it was
decided to not follow the Stacks project approach via sheaves on a basis, but
to instead define the sheaf directly following [Har77], where an element of
$\mathcal{O}_{X}(U)$ is a dependent function taking $u\in U$ to an element of
$R_{u}$, the localisation of $R$ at the prime ideal $u$, subject to the
condition that locally the function can be written as $r/s$ with $r,s\in R$
and $s$ not vanishing near $u$. The advantage of this approach is that it is
clear that $\mathcal{O}_{X}$ is a sheaf; the ring-theoretic Lemma 00EJ is not
used at all in this approach. Indeed, in this set-up, 00EJ is used to prove
$\mathcal{O}_{X}({\operatorname{Spec}\,}(R))=R$.

###  5.3. Sheaves and categories

SM defined the notion of a sheaf on a topological space taking values in any
category which has products. The sheaf condition on a presheaf is that the
usual “sheaf condition diagram” is an equalizer. It is then a theorem that a
sheaf of rings is a presheaf of rings whose underlying presheaf of types is a
sheaf of types. Since then, Bhavik Mehta has defined the concept of a sheaf of
types on an arbitrary site, and more generally the notion of a sheaf of
objects of an arbitrary category on a site. All of this work is now in
mathlib. These definitions open the door to defining and proving theorems
about the étale cohomology of schemes in Lean.

###  5.4. A word on mathlib

We mentioned above that this definition of a scheme made it into Lean’s
mathematics library mathlib, which means that all the code in it was subject
to scrutiny by the library maintainers. A reasonable analogy would be that
mathlib is like a journal, and the maintainers are like the editors. After
three iterations of the definition of a scheme, it was in good enough shape
for a “pull request” to be made to mathlib. (A pull request is the open source
project equivalent of submitting an article to an editor!) Note that the
multiple iteration procedure discussed in this paper is not usual – but we
were beginners in 2017 with very little information to guide us on how to make
schemes on a computer, and KB’s poor initial design decisions were because of
this. Nowadays we have a much better understanding of how to put modern
mathematics into Lean’s dependent type theory.

The advantage of getting the definition into mathlib is that now it is
guaranteed to compile for the duration of Lean 3’s lifespan, because if
someone makes changes to the library which break it, it will be down to that
same someone to fix it. This is in stark contrast to the first two
definitions, which compile with very old versions of Lean and mathlib, and
would almost certainly not compile with modern versions.

##  6\. Conclusion and acknowledgements.

We formalised the definition of a scheme, and along the way learnt a lot about
how to formalise localisation in dependent type theory. The definition is now
in Lean’s mathematics library mathlib (see here).

We are very grateful to Mario Carneiro, Reid Barton and Neil Strickland, all
of whom provided major insights to help us on our way.

## References

  * [BCM20] Kevin Buzzard, Johan Commelin, and Patrick Massot, _Formalising perfectoid spaces_ , Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2020, New Orleans, LA, USA, January 20-21, 2020, 2020, pp. 299–312.
  * [BHL18] Kevin Buzzard, Chris Hughes, and Kenny Lau, _Formal verification of parts of the Stacks project in Lean_ , https://github.com/kbuzzard/lean-stacks-project, 2018.
  * [dKA+15] Leonardo de Moura, Soonho Kong, Jeremy Avigad, Floris van Doorn, and Jakob von Raumer, _The lean theorem prover (system description)_ , Automated Deduction - CADE-25 - 25th International Conference on Automated Deduction, Berlin, Germany, August 1-7, 2015, Proceedings, 2015, pp. 378–388.
  * [FM19] Ramon Fernández Mir, _Schemes in Lean (v2)_ , https://github.com/ramonfmir/lean-scheme, 2019.
  * [Gro60] A. Grothendieck, _Éléments de géométrie algébrique. I. Le langage des schémas_ , Inst. Hautes Études Sci. Publ. Math. (1960), no. 4, 228. MR 217083
  * [Har77] Robin Hartshorne, _Algebraic geometry_ , Springer-Verlag, New York-Heidelberg, 1977, Graduate Texts in Mathematics, No. 52. MR 0463157
  * [mat20] The mathlib community, _The Lean mathematical library_ , Proceedings of the 9th ACM SIGPLAN International Conference on Certified Programs and Proofs, CPP 2020, New Orleans, LA, USA, January 20-21, 2020, 2020, pp. 367–381.
  * [Sta21] The Stacks Project Authors, _Stacks Project_ , https://stacks.math.columbia.edu, 2021.
  * [Wei46] André Weil, _Foundations of Algebraic Geometry_ , American Mathematical Society Colloquium Publications, vol. 29, American Mathematical Society, New York, 1946. MR 0023093
  * [Whi36] Hassler Whitney, _Differentiable manifolds_ , Ann. of Math. (2) 37 (1936), no. 3, 645–680. MR 1503303