A Formalization of Complete Discrete Valuation Rings and Local Fields

Local fields, and fields complete with respect to a discrete valuation, are essential objects in commutative algebra, with applications to number theory and algebraic geometry. We formalize in Lean the basic theory of discretely valued fields. In particular, we prove that the unit ball with respect to a discrete valuation on a field is a discrete valuation ring and, conversely, that the adic valuation on the field of fractions of a discrete valuation ring is discrete. We define finite extensions of valuations and of discrete valuation rings, and prove some localization results. Building on this general theory, we formalize the abstract definition and some fundamental properties of local fields. As an application, we show that finite extensions of the field ℚp of p-adic numbers and of the field Fp((X)) of Laurent series over Fp are local fields.


Introduction
The vague idea that geometric intuition and algebraic rigor can fruitfully interact is an old theme, certainly predating the modern approach by Descartes and subsequently by Newton and Leibniz.In contemporary commutative algebra, and especially after the advent of scheme theory by Grothendieck around 1960, this connection has become even tighter: geometric concepts and techniques are often borrowed for a wide range of applications.In this work we are concerned with the concept of local field, a fundamental notion in algebraic number theory whose origin, and still many applications, comes from geometry and diophantine questions.Suppose, for instance, that one is interested in the integral solutions ( 1 , 2 , 3 ) to 2  1 + 2 2 + 2 3 = 0: clearly, since for positivity reasons the only real solution is (0, 0, 0), there cannot be any other integral solutions.On the other hand, 2 1 + 2 2 −3 2 3 = 0 certainly has real solutions, yet has no nontrivial solutions in F 3 , the field with 3 elements, as can be seen by analyzing the finitely many possibilities.Hence, if ( 1 , 2 , 3 ) is an integral solution to this equation, its reduction modulo 3 must be the trivial solution in F 3 , so that 1 , 2 and 3 are all divisible by 3.This implies 1 = 2 = 3 = 0, since otherwise we would have an equality 2  1 + 2 2 = 3 2  3 , in which the highest power of 3 dividing the left hand side is even, while the highest power of 3 dividing the right hand side is odd, yielding a contradiction.
From a geometric perspective, one can regard the previous as a kind of "local analysis": interpreting the primes as the points of a geometric object attached to Z, if a "global" solution ( 1 , 2 , 3 ) ∈ Z 3 exists, then for each prime , we obtain a solution ( 1 , 2 , 3 ) ∈ F 3 by reducing the coordinates modulo -we can look at this as being a local solution "around the point " -as well as the solution (( 1 : R), ( 2 : R), ( 3 : R)) ∈ R 3 over the reals.In particular, if one of these local solutions fails to exists, this means that the equation cannot have a global solution.Yet, in this analogy, the fields F and R are very different: the former is finite, with trivial discrete geometry and of positive characteristic, while the latter has a rich metric structure and characteristic 0. Now, for every , one can rather consider the field of -adic numbers Q which is, in this perspective, a better analogue for R than F : it has a metric with respect to which it is complete (Cauchy sequences converge), and it has characteristic 0 (so, in particular, it contains Q).To define it, one observes that for every prime there exists an absolute value |•| on Q for which numbers that are highly divisible by are close to 0. Having an absolute value, it is possible to speak about convergence and about Cauchy sequences: exactly as for the euclidean absolute value, one can find Cauchy sequences that do not converge to any rational, and Q is defined as the completion of Q with respect to |•| .It is the "smallest" field where all |•| -Cauchy sequences converge.Crucially, it still bears strong connections with the prime : for instance, if a monic polynomial in Z[ ] has a simple root in F , then it also has one in Q .
The local analysis described before is an example of the "local-to-global" principle: to solve a problem in Z, or Q, one can try to solve it in Q , for all , and in R. A famous application of the local-to-global principle is the Hasse-Minkowski Theorem, which states that if ( ) is a quadratic form with rational coefficients, then the equation ( ) = 0 has a nontrivial solution over Q if and only if it has a nontrivial solution over R and over every Q .
For another notorious example, it has long been known that the so-called "first case" of Fermat's Last Theorem can be solved using class field theory (see [17]), which is a deep theory where the global theorems are obtained by a beautiful patching of the local ones: we refer to [22] for an excellent account of this example.It should also be emphasized that ultimately Wiles' very proof of Fermat's Last Theorem makes heavy use of the local-to-global principle in the framework of Galois representations: we refer to [16] for a summary of this technique.
Before describing our work, let us mention two generalizations of the -adic numbers that will guide our approach to the formalization.First of all, the field Q of rational numbers can be replaced by an arbitrary number field, or global field.We refer to [3, §2] for a brief overview of these notions in the context of formalization.Number fields are fields that can be obtained by adjoining roots of polynomials They are a key object of study in algebraic number theory and resemble in many perspectives the rational field.Every number field can be realized as the field of fractions = Frac O of a suitable subring O ⊆ , in the same vein as Q = Frac Z.These rings O are not principal, in general, but they are Dedekind domains (see Example 2.3 and the references ibid.):so, although we cannot in general define an absolute value |•| on O associated to elements ∈ O , it is possible to define an absolute value |•| associated to every maximal ideal of O .The completion procedure discussed above can then be performed analogously, and the fields obtained in this way are all finite extensions of some Q , and are the so-called mixed characteristic local fields.Analogous constructions exist when replacing Q by F ( ), leading to equal characteristic local fields, and we refer to §3.1 for more details.There is also a more abstract definition of local fields, that includes the above two, that is recalled and formalized in Definition 3.1.Secondly, unlike the euclidean metric, the -adic one carries a strong discrete flavor, in that only integral powers of can occur as values | | for ∈ Q \ {0}.This happens in other contexts, and the relevant notion is that of a discrete valuation ring; we will describe their theory in more detail in §2.3.Here we content ourselves with saying that they are a class of rings endowed with a valuation map to Z∪{∞} such that the arithmetic behavior of elements ∈ can be read on the value ( ).The relation of discrete valuation rings with local fields is deep: the completion of the fraction field of a discrete valuation ring with finite residue field (see §3) is a local field and, conversely, for every local field the subset { ∈ | | | ≤ 1} is always a discrete valuation ring, yet not every discrete valuation ring is of this form.
In this paper, we formalize in Lean 3 the definition and basic theory of local fields and their relation with discrete valuation rings.We provide both a concrete approach, defining mixed characteristic and equal characteristic local fields as finite field extensions of Q and F (( )), and a more abstract definition of local field which comprises these two special cases.
The mathlib library provides a very complete theory of general valuations, as well as the basic theory of discrete valuation rings, but the connection between these two notions is largely missing.We formalize the definition of discrete valuation and greatly expand the available theory for discrete valuation rings, their fields of fractions, and their associated discrete valuations, including theorems about completions, extensions of valuations and localizations.To the authors' best knowledge, this work constitutes the first formalization of local fields and of extensions of discrete valuations in any proof assistant.
The Lean code for our formalization is available at a public GitHub repository .Inside the folder from_mathlib we gather files that are previous work of the authors, as well as a file due to Yaël Dillies , used in this project after securing permission from them.Everything else is new, original work of the authors of this paper, totaling about 8,000 lines of code.Some of the code excerpts below have been edited for clarity, but we also provide links to the corresponding results in our repository.In some code excerpts the so-called dot notation is exhibited: for example, the call (ideal.is_primeI) can be shortened to I.is_prime.
Throughout this paper, all rings are assumed to be commutative and unitary.

Lean and mathlib
This project is formalized in the Lean 3 theorem prover [14], which is based on dependent type theory, with proof irrelevance, quotient types, and non-cumulative universes [9].
We build our work on top of the mathematical library mathlib of Lean 3, whose key properties are its unified approach to integrate different mathematical theories, and its decentralized nature, with over 300 contributors.One of the key tools for organizing mathematical hierarchies used both in Lean's core library and in mathlib is typeclass inference.By declaring certain terms as instance, Lean will automatically try to infer the relevant values during the unification procedure.We refer to [1] for a more detailed discussion of the role of instance parameters in Lean.
The formalization is in Lean 3 because at the time when we began it, almost none of its prerequisites were available in Lean 4. Now that the complete mathlib has been translated to Lean 4, we plan to port our work and start to integrate it in this library.All our future work related to this project will be directly implemented in Lean 4.

Paper outline
In §2, we treat the general theory of discrete valuations and discrete valuation rings: after presenting some background material in §2.1- §2.3, we describe our main results in §2.4,concerning completions, and §2.5, concerning extensions of valuations.In §3.1 we present our formalization of local fields, describing the equal and mixed characteristic cases in §3.1 and §3.2, respectively.We conclude in §4 with a description of future and related work and a discussion of some of our key design choices.

Discrete Valuation Rings
In this section we present our formalization of the theory of discretely valued fields and discrete valuation rings, including results about completions and extensions of valuations.As a technical prerequisite, we discuss in § 2.1 the definition and main properties of the mathlib type Z m0 , where most of the valuations that we considered take their values.

The type Z m0
There are several situations in mathematics in which additive structures get translated into multiplicative structures.For example, associated to each real number ≠ 0, there is an exponential map exp : R → R sending to .This map has the property that exp ( + ) = exp ( ) • exp ( ) and, whenever > 1, it preserves the order on R.
A second example occurs in the theory of valuations.If : → Z ∪ {∞} is an additive valuation on a ring (see Definition 2.1) and > 1 is a real number, it is common to study the associated function : → Z ∪ {0} sending to − ( ) , with the convention that −∞ = 0.Here Some abstractions that can be used to formalize this kind of translations are available in mathlib.Given any type A endowed with an additive structure, mathlib provides a new type multiplicative A that is in bijection with A and carries a multiplicative structure, together with a map of_add : A → multiplicative A satisfying of_add (x + y) = of_add x * of_add y for all x, y : A. If A is equipped with a preorder, then so is multiplicative A, and the map of_add is strictly monotone: x ≤ y is equivalent to of_add x ≤ of_add y.The map to_add : multiplicative A → A is inverse to of_add.
We are especially interested in the case A = Z.As an additive group, Z is an infinite cyclic group generated by 1 or −1.Correspondingly, the elements of_add(1) and of_add(-1) , that do not bear a specific notation, are the only generators of the cyclic group multiplicative Z. Since the map of_add preserves the unit element, we have that of_add(0) = 1 is the unit, hence Given two integers , , it holds that of_add(a * b) = of_add(a) = of_add(b) .In particular, we have the equality of_add(±1) = of_add(±n) for all (n : Z).
A new type with_zero (multiplicative Z), denoted Z m0 , can be constructed from multiplicative Z by adding an extra term 0 to multiplicative Z.The resulting type Z m0 still carries a multiplication, that extends the one on multiplicative Z and for which 0 * x = 0 for all x; moreover, setting 0 ≤ x for all x, Z m0 is endowed with an order that extends the one on multiplicative Z.The inclusion multiplicative Z → Z m0 is an order-preserving coercion that respects the multiplication on both sides, and we omit it from the notation.
The type Z m0 provides an abstraction of the structure on the set Z ∪ {0} that does not require a choice of the base , and it will be the codomain of most of the valuations that we consider in this paper.
Note that an element ∈ has additive valuation 1 if and only if it has multiplicative valuation of_add(-1).Elements of multiplicative valuation of_add(-1) will play a prominent role in §2. 3.
For example, let = Z be the ring of integers, and fix a prime number .Then, thanks to unique factorization, we can define an additive valuation : Z → Z ∪ {∞} by sending an integer to the number of times that appears in the factorization of .We can extend the function to Q by defining ( / ) := ( ) − ( ).Then is an additive valuation on Q, called the additive -adic valuation on Q.The corresponding multiplicative valuation : Q → Z m0 is called the -adic valuation.
Example 2.3 (The -adic valuation).We will often consider the following generalization of the -adic valuation.If is a Dedekind domain (see [6, Chapitre VII, §2]) which is not a field, then every nonzero ideal of can be factored as a product of maximal ideals, uniquely up to reordering.Therefore, for every maximal ideal of , we can follow an analogous construction to define an additive valuation : → Z∪{∞} on by sending 0 to ∞ and any nonzero ∈ to the number of times that appears in the factorization of the principal ideal ( ).We extend to the fraction field of by the formula ( / ) := ( ) − ( ).The corresponding multiplicative valuation = of_add • (− ) : → Z m0 on is called the -adic valuation.This valuation was formalized in [12], and is available in mathlib as the declaration is_dedekind_domain.height_one_spectrum.valuation .
While in most number theory references it is more common to work with additive valuations than with multiplicative ones, for historical reasons mathlib follows the opposite convention, and it provides a much more complete API for multiplicative valuations.Hence we use multiplicative valuations in our formalization and, throughout the paper, whenever we use the term "valuation" without further adjectives, we mean "multiplicative valuation".
Remark 2.4.(For experts) More generally, the codomain Z m0 in the definition of a (multiplicative) valuation can be replaced by Γ 0 = Γ ∪ {0}, where Γ is a linearly ordered commutative group.The order on Γ is extended to Γ 0 analogously as we did for Z m0 .Structures like Γ 0 are called "groups with zero".
An example of this situation occurs when starting with a local Dedekind domain , with unique maximal ideal and field of fractions .In this setting one can prove that the quotient map : → / × is a valuation, where the quotient / × is ordered by reverse divisibility.The group with zero / × = × / × ∪ {0} is called the value group1 of .The value group is implemented in mathlib as valuation_ring.value_group, but we mostly stick to Z m0 -valued valuations in our work.
We represent valuations using the valuation structure available in mathlib, which encodes Definition 2.2.A valuation on a ring induces a topology that is homogeneous with respect to addition (see [5, Chapitre III, §1]: every neighborhood Ω ⊆ is of the form Ω = + Ω 0 where Ω 0 is a neighborhood of 0 and ∈ Ω.In other words, addition (and subtraction) are homeomorphisms of the ring into itself.This property shows that to characterize the topology it is enough to describe the neighborhoods of 0.
When is a Dedekind domain and = is the topology associated to a maximal ideal , as defined in Example 2.3, a basis for the neighborhoods of 0 is provided by the sets In particular, two elements 1 , 2 are "close to each other" if their difference lies in a sufficiently deep neighborhood of 0, meaning that ( 1 − 2 ) ≤ for a suitable : Z m0 , ≠ 0. Given the definition of this translates into the fact that the principal ideal ( 1 − 2 ) is divisible by a high power of .Actually, the above topology is of a special kind, because the valuation defines a structure of uniform space on , as explained in [6, Chapitre VI, §5] and in the references ibid.This is a simultaneous generalization of the structure of metric space and of topological group and the topology is induced by the uniform structure.Our main reference for uniform structures is [5, Chapitre II]; for a throughout discussion of the formalization of uniform spaces, we urge the reader to consult the beautifully written [8], in particular its §5.
The mathlib library also provides the class valued , which bundles together a ring endowed with a uniform space structure and a distinguished valuation inducing it.Given a term (hv : valued R Z m0 ), these can be accessed through hv.to_uniform_space and hv.v, respectively.This class is designed for rings in which there is a preferred valuation.Recall from Example 2.3 that on a Dedekind domain , there is a valuation for each maximal ideal, and it can be shown that any nontrivial valuation on is of this form.Hence, if is local, then the only nontrivial valuation on is the -adic valuation associated to its unique maximal ideal, and we declare a valued instance on .If is not local, given any maximal ideal ⊆ we can still define a term (hv : valued R Z m0 ) representing the -adic valuation and allowing us to access the whole valued API locally.Yet, we would not declare this as a global valued instance on , since none of the -adic valuations on is preferred over the others.
Given a ring with a valuation , we can consider the unit ball of , that is the subring • of elements with valuation less than or equal to (1: Z m0 ).This subring is called v.integer in mathlib.When is a field, the subring • is a valuation subring, meaning that for every ∈ , either ∈ • or −1 ∈ • : in particular, Frac( • ).Since the definition of valuation subring involves taking inverses, it is only available for fields.Hence, when working with a general ring , we formalize • as v.integer, but when working with a field we use the richer structure v .valuation_subring, which gives us access to results about valuation subrings available in mathlib.

Discrete Valuation Rings
Our general references for the theory of discrete valuation rings are [20, Chapitres I-II] and [6, Chapitre VI].One notable difference with our language is that both references consider additive valuations, whereas we stick to the multiplicative convention introduced in §2.2, which is the approach chosen in mathlib.Mathematically, the two points of view are equivalent: one just needs to keep in mind the translation between Z∪{∞} and Z m0 .Finally, we refer to [7], in particular to [7, Chapitre IV], for the main results about ring theory and commutative algebra that we will need.
Let be a ring, as above assumed commutative and unitary.We begin by recalling the following equivalence: Theorem 2.5 ([6, Chapitre VI, §3, n • 6, Proposition 9]).Suppose is a Noetherian local ring that is not a field.The following properties are equivalent: 1.The maximal ideal of is principal; 2. is a principal ideal domain (PID); 3. is an integral domain that coincides with the unit ball of its fraction field Frac( ) with respect to a valuation : Frac → Z m0 .
A ring satisfying the equivalent properties of Theorem 2.5 is called a discrete valuation ring (often shortened as DVR).The nomenclature is motivated by point 3. ibid.: given a DVR , it is possible to find a valuation : Frac( ) → Z m0 such that = (Frac ) • : yet this valuation is not unique.Indeed, the definition of the action of Z on Z m0 shows that replacing a valuation by a power for ∈ Z >0 leaves the unit ball unchanged.For each of these valuations, the image Im( ) ⊆ Z m0 is the free group with zero generated by ( ), where is any generator of the maximal ideal of .Upon replacing by 1/ ( ) for some generator of , where denotes the additive valuation associated to , we can assume that the image is the whole Z m0 : in this case the valuation is said to be normalized, and the elements of valuation equal to (of_add(−1) : Z m0 ) are called uniformizers.
One basic result is that, for a normalized valuation on a DVR, the uniformizers are exactly the set of generators of , because properties ii) and iii) of Definition 2.2 show that an element ∈ is a unit if and only if ( ) = 1 = (of_add 0).In particular, there exists a unique normalized valuation on a DVR, since the same argument shows that every valuation is uniquely determined by its value on one, or any, generator of .Moreover, as explained in Example 2.3, any such valuation can uniquely be extended to Frac( ).We denote this normalized valuation by 0, -or simply by 0 when the DVR can be understood.
Assume now that is any integral domain (not necessarily a DVR) and that is a field of fractions for .The points of view taken in [20, Chapitre I] and in [6, Chapitre VI, §3, n • 6] concerning valuations on are not identical: in the former, the valuations occurring in point 3. of Theorem 2.5 take values in Z ∪ {∞} (or Z m0 , up to our translation), whereas in the latter they are valued in × / × ∪ {∞}, that translates to the value group / × = × / × ∪ {0} in our language, but under the assumption that there is an isomorphism × / × Z.In both cases they are called "discrete"; they are said to be normalized, as above, when they are surjective.Often results are stated assuming that the valuation is normalized, relying on the possibility of achieving this normalization simply by rescaling, so that the theory of discrete valuations is essentially the theory of normalized discrete valuations.
In the setting of a formalization work, the ambiguities described above concerning the group (with zero) Γ 0 and the normalization of the valuation call for more attention than in pen-and-paper mathematics.It is in principle possible to let Γ 0 vary, including it as a (perhaps implicit) variable: yet one must stipulate the existence of an isomorphism Γ 0 Z m0 , adding one more variable, so that we rather find it more convenient to consider only valuations that are Z m0valued, in line with the choice made when defining the adic valuation attached to a height-one prime of a Dedekind domain.Even with this choice, the above discussion about different possible normalizations of a Z m0 -valued valuations, all leading to the same mathematical object, suggests that the focus should be put on normalized valuations, rather than general ones.With this in mind, we call a valuation "discrete" when it is Z m0 -valued and also normalized, encoding this notion in the following class : Code excerpt 1. Definition of discrete valuation.
Observe that when the domain is endowed with a discrete valuation in the above sense, then it is necessarily a field.Henceforth we change perspective a bit and we focus on a topological field endowed with a valuation , letting • be its unit ball: as discussed at the end of §2.2 this is implemented by putting a valued instance hv on K and by setting Now, with our definition, a valuation is discrete only if it takes values in the type Z m0 and if there exists a uniformizer, and this we prove in the following form : The lemma exists_uniformizer_of_discrete provides the reverse implication.Similarly, the aforementioned correspondence between uniformizers for a normalized valuation and generators of takes the form lemma uniformizer_is_generator ( : uniformizer v) : maximal_ideal K 0 = ideal.span{ .1} and the declaration is_uniformizer_of_generator represents the reverse implication.From now on, we call a valued field whose valuation is discrete a discretely valued field.
The next result that we want to discuss is the formalization of [20, Chapitre I, §1, Proposition 1], stating that the unit ball of a discretely valued field is a DVR.The notion of DVR was already in mathlib at the time of our project, implemented through the class discrete_valuation_ring -this corresponds to property 2. in Theorem 2.5.Our result takes the following form : The unit ball is a DVR if the valuation is discrete.
Suppose now that is a DVR, and let be a field of fractions for .By Theorem 2.5, is a local ring that is a PID, so in particular is a Dedekind domain, and one can consider the adic valuation associated to its unique maximal ideal , as defined in Example 2.3.Now, Baanen et al. formalized in [2] and [3] the general theory of Dedekind domains, and de Frutos-Fernández formalized in [12] the main properties of adic valuations on Dedekind domains.
With these works at our disposal, our starting point is that the -adic valuation associated to the maximal ideal coincides with the normalized valuation 0 on (since is a domain, we directly extend these valuations to any of its fields of fractions).Although this is mathematically trivial, and the two functions 0 , are considered identical in pen-and-paper mathematics, they actually belong to different types and hence are different terms: in the mathlib formalization, the valuation 0 takes values in the value group / × (see Remark 2.4), while is Z m0valued .Our approach to compare them is to show that the unit balls with respect to both coincide.To do so, it is enough to show that is the unit ball of when endowed with the valuation , because this is tautologically true with respect to the valuation 0 .To prove the isomorphism • we first provide the following instance : valued K := (maximal_ideal R).adic_valued Code excerpt 3. The valued instance on the field of frations of a DVR.
giving a valued structure on by using the -adic valuation .With this definition, the whole library concerning adic valuations is at our disposal.We then show that the valuation is actually discrete (in our sense) by providing the instance : is_discrete (valued.vK Z m0 ) Code excerpt 4. The valuation on a DVR is discrete.
By combining this result with the above discussion we deduce that • is itself a DVR, and we finally prove the isomorphism • in the form of the following def dvr_equiv_unit_ball : R ≃ + * valued.v.valuation_subring Remark 2.7.When implementing valuations on a discrete valuation ring with field of fractions2 , we made the design choice to put an instance of the valued class on , but not on the ring itself.The reason is that, if needed, we can recover the uniform structure on from the one on , so we prefer not to duplicate this information.This choice is consistent with mathlib's file ring_theory.dedekind_domain.adic_valuation, in which valued instances are only put on fields.
As illustrated in the Introduction, one application of the theory of DVR's to number theory comes from the fact that every maximal ideal in a Dedekind domain induces a discrete valuation, with respect to which the unit ball is a DVR.In this context, we prove the following lemma:

Complete Discrete Valuation Rings
One setting where the theory of DVR's becomes crucialespecially for its applications to algebraic number theory and algebraic geometry -is that of (adic) completions.The completion is a general procedure that can be performed on every uniform space , as explained in [5, Chapitre II, §3].We are not providing the exact definition here; the crucial property to retain is that it yields another uniform space , containing as a dense subspace, and such that every uniformly continuous function : → , valued in any complete, separated topological space can be extended uniquely to a function : → (see [ In the special case where = is a field with a valuation (endowed with the uniform structure induced by it as explained in §2.2), the completion is again a field.We refer to [6, Chapitre VI, §5, n • 3] for the generalities concerning completions of valued fields, and to [20, Chapitre II, §1] for a shorter introduction.Applying 3 the universal property (1) to the valuation yields a map : → Z m0 that is still a valuation.Completions of uniform spaces and uniform fields have been formalized 4 , and the paper [8] contains an account of the formalization.The application of this construction in the setting of Dedekind domains is due to de Frutos-Fernández, see [12].
A prototypical example of a completion of a field is the field Q of -adic numbers, that is defined as the completion of Q endowed with the -adic valuation .Another example arises when starting with the ring [ ] of polynomials in one indeterminate over the field : being a PID, it is a Dedekind domain and the construction of Example 2.3 defines a valuation : ( ) → Z m0 attached to any maximal ideal ⊆ [ ]. Take, for instance, = ( ).Then the valuation defines a uniform structure on the field We do not describe here the topology on Z m0 , suffices it to say that it mimics the discrete one on Z.We refer the reader to the relevant mathlib file . 4Given a ring , an ideal ⊆ and an -module , mathlib contains the declaration adic_completion I M.This is defined purely algebraically as a module of "coherent sequences", a concrete incarnation of an inverse limit.A systematic comparison between this -adic completion and the uniform one has not yet been formalized.
of rational functions whose completion ( ) is isomorphic to the field (( )) of Laurent series: we discuss our formalization of this isomorphism in §3.1.1.
When completing a field endowed with a valuation , the valuation is unique under the condition of extending the one on , by (1).It follows that is always endowed with a global valued instance, even when is not.This is for example the case with Q and Q : the first has infinitely many non-equivalent valuations , and thus no global valued instance is declared for it.On the other hand, each Q has a preferred valuation and is actually a valued field.More generally, given a maximal ideal of a Dedekind domain , we can apply the above discussion to the valuation to obtain a complete valued field .We now go back to our discussion concerning DVR's.So, let be a DVR with field of fractions .We have seen in the code excerpt 3 that , endowed with the valuation , is valued and so is its completion , denoted by K_v in our code.Moreover, the valuation on is discrete (see the code excerpt 4) and the first result we obtain is that the same holds for the valuation on , which takes the following form : In particular, we can consider the ring • (denoted by R_v in our code) to find, by the discussion in §2.3, that it is itself a DVR instance : discrete_valuation_ring R_v := discrete_valuation.dvr_of_is_discrete_ with field of fractions .Thus, • is a local ring endowed with a maximal ideal, denoted .It is therefore possible to once again apply de Frutos-Fernández' work and endow = Frac • with the -adic valuation , which puts a (potentially) new valued structure on .Now, as the notation suggests, the maximal ideal , which is in particular an abelian group, actually coincides with the completion (inside the larger space ) of the abelian group .In our language, this reflects on the equality of the two valuations and on , but this equality will clearly not be a definitional one, given the different constructions that led to the two valuations.Rather, it takes the following form: lemma adic_of_compl_eq_compl_of_adic (x : K_v) : v_adic_of_compl x = v_compl_of_adic x In the above code excerpt, v_adic_of_compl represents the valuation , while v_compl_of_adic is .

Extensions of Complete Discrete Valuation Rings
The goal of this section is to prove that if is any field complete with respect to a discrete valuation and / is a finite extension of fields, then there is a unique discrete valuation on "extending" .To explain our formalization, we first need to discuss the relation between valuations and norms.A valuation : → Γ 0 valued in a group with zero Γ 0 has rank one if it is nontrivial and there exists an injective morphism of linearly ordered groups with zero from Γ 0 to R ≥0 .In particular, any nontrivial valuation : → Z m0 has rank one.The definition of rank one valuation was first formalized in [13] .
The conditions in Definitions 2.2 and 2.8 are analogousapart from the codomain of the function -and the terms "multiplicative valuation" and "nonarchimedean multiplicative norm" are often used interchangeably in the mathematical literature.While mathlib does not yet provide a way to relate these two notions, a dictionary between them has been formalized in [13].Namely, if is a field with a nonarchimedean norm, the definition valuation_from_norm yields the corresponding valuation : → R ≥0 .Conversely, if is a field with a rank one valuation, then norm_def is the corresponding norm function on .To make use of this dictionary in our project, we need to provide an injective morphism Z m0 → R ≥0 of linearly ordered groups with zero.We can define this morphism by picking any real > 1 and identifying Z m0 with the subset Z ∪ {0} of R ≥0 , via the map sending 0 to 0 and of_add(x) to , for ∈ Z.
We construct this morphism as def with_zero_mult_int_to_nnreal {n : R ≥0 } (he : n ≠ 0) : Z m0 → * 0 R ≥0 := { to_fun := x, if hx : n = 0 then 0 else n^(to_add (with_zero.unzerohx)), ... } and then we prove that this map is order-preserving whenever > 1.Each choice of gives rise to a different morphism, and hence to a different norm attached to a valuation : → Z m0 , although any two such norms define the same uniformity on .When the quotient • / • is finite of order for some prime , the standard choice is = .Otherwise there is not a preferred , so in our formalization we pick = 6.We refer to this associated to as v.base .
Let now be a complete discretely valued field and let be a finite field extension, so that / is automatically algebraic.The above discussion allows us to apply the following theorem to conclude that there is a unique norm |•| on extending the norm |•| associated with the valuation on .Theorem 2.9.Let be a field that is complete with respect to a nonarchimedean multiplicative norm |•| and let / be an algebraic extension.Then there is a unique multiplicative nonarchimedean norm on , called the spectral norm, extending the norm |•| .
In the setting that we are considering, the norm whose existence is guaranteed by Theorem 2.9 is formalized in the declaration discrete_norm_extension .
Since the extension / is algebraic, there is an explicit formula for the norm | | of an element ∈ : if has minimal polynomial We prove this in : theorem spectral_norm_eq_root_zero_coeff : spectral_norm K L x = (minpoly K x).coeff 0 ^(1/(minpoly K x).nat_degree : R) Since for every ∈ , the degree of the minimal polynomial of over divides the degree [ : ] of the extension / , we see that the norm |•| takes values in the subset Z [ : ] ∪ {0} of R ≥0 .The norm needs not surject onto that subset but, since Z is cyclic, its image is of the form Z [ : ] ∪ {0} for some ∈ Z >0 .Informally speaking, to obtain the corresponding normalized valuation we just need to rescale the norm by raising it to the ( [ : ]/ )-th power, and use the identification between Z ∪ {0} and Z m0 .
In order to formalize this idea, we have to be careful to proceed in such a way that we do not leave the type Z m0 , since taking the th -root of an element of Z m0 is not a welldefined operation.We start by constructing a map , which is well-defined by lemma unit_pow_ne_zero .Then we find the positive number exp_extension_on_units , denoted above, such that the image of pow_extension_on_unitsis generated by of_add (exp_extension_on_units : Z ).Hence, using the lemma exists_mul_exp_extension_on_units , we can obtain the natural number such that pow_extension_on_units K L x = (of_add (exp_extension_on_units))^c; which leads to our definition of the extended valuation :

mpr hx).unit).some
To connect the extended norm and the extended valuation we prove in pow_eq_pow_root_zero_coeff that for every multiple of deg , the following equality holds: Using ( 2) we deduce that extension_def K L satisfies the properties in Definition 2.2 since spectral_norm K L is a multiplicative nonarchimedean norm on (as proven in [13, §3.2]).We then prove that this valuation is discrete and that is complete with respect to the induced uniform structure .
The next theorem we prove says that the integral closure O of the unit ball • inside is again a discrete valuation ring (we refer to [6, Chapitre 5, §2, n • 1] for generalities about integral closures).This follows from the fact that O is actually equal to the unit ball with respect to the extended discrete valuation on , formalized as lemma integral_closure_eq_integer : integral_closure hv.v.valuation_subring L = (extended_valuation K L).valuation_subring

Local Fields
In this section we describe our formalization of the basic theory of local fields, a special kind of discretely valued fields which are fundamental objects of study in number theory.
For instance, given a number field with ring of integers O , one can subsequently apply the constructions of Example 2.3 to the different maximal ideals ⊆ O -thus obtaining a collection of DVR's -followed by the completion procedure described in §2.4.The resulting collection of fields are precisely the local fields occurring in the "local-toglobal" approach to class field theory briefly mentioned in the Introduction.
Before giving the definition, we make a preliminary observation.Theorem 2.5 shows that every DVR is a local ring, so it has a unique maximal ideal.On the other hand, given a field endowed with a discrete valuation, the code excerpt 2 shows that its unit ball • is a DVR, whose maximal ideal we denote • .It is then possible to unambiguously (although slightly inappropriately) speak of the residue field of to mean the field A local field can be of two kinds: of equal characteristic, if both and its residue field have characteristic for some prime number , or of mixed characteristic, if has characteristic 0 and its residue field has characteristic .Moreover, in the first case is a finite extension of F (( )) while in the second it is a finite extension of Q (see [6, Chapitre VI, §9, n • 3]); this motivates our definitions in § §3.1-3.2.

Equal characteristic
Recall that we denote by F ( ) the completion of F ( ) with respect to the maximal ideal = ( ).The first example of equal characteristic local field is F ( ) itself, and we record our proof of this in the instance FpX_completion .eq_char_local_field .Being a finite extension of the complete discretely valued field F ( ) , any equal characteristic local field is endowed with a unique nontrivial valuation, which is again discrete, and is complete with respect to it.instance : valued K Z m0 := extension.valued(FpX_completion p) K instance : complete_space K := extension.complete_space(FpX_completion p) K instance : is_discrete (eq_char_local_field.valued p K).v := extension.is_discrete_of_finite(FpX_completion p) K Remark 3.4.Given any field , the -adic completion ( ) of the field of rational functions is isomorphic to the field of Laurent series indexed by Z with only finitely many negative nonzero coefficients: Accordingly, the unit ball ( ) • is isomorphic to the ring of power series It is customary to define an equal characteristic local field as a finite extension of F (( )) rather than of F ( ) , because elements in F (( )) are explicit and it might be handier to work with them than with elements in F ( ) .While in pen-and-paper mathematics one can safely treat finite extensions of the two fields as leading to the same definition, we have to pick a choice in our formalization project.Since our development of extensions of complete DVR is very general and does not rely on any explicit description of the base field, and in analogy with our approach to the mixed characteristic case (see §3.2), we decide to use the type F ( ) as the base field in our Definition 3.5.Moreover, the isomorphism (( )) ( ) is still not available in mathlib and we describe our formalization of this isomorphism in §3.1.1.
Our next task is to show that an equal characteristic local field is a local field, in the sense of Definition 3.1.We have formalized this proof under the hypothesis that the extension / F ( ) is separable, as this is required to apply the mathlib lemma is_integral_closure.is_noetherian which we are using in our proof of the finiteness of the residue field.However, we point out that the separability assumption can be removed at the expense of a more involved proof, which we plan to formalize at a later date.
Since F ( ) is a field complete with respect to a discrete valuation and is a finite extension of F ( ) , by the discussion following (2), the -adic valuation on F ( ) induces a complete discretely valued structure on , registered in the instance eq_char_local_field.valued p K .Hence it only remains to prove that the residue field of is finite.To prove the finiteness statement, we first show that if is a field complete with respect to a discrete valuation and / is a finite separable field extension, then the residue field of is finite dimensional over the residue field of : This implies that if the residue field of is finite, then so is the residue field of .Now, it follows from the isomorphism F (( )) F ( ) discussed in §3.1.1 that = F ( ) has residue field F , so every equal characteristic local field has finite residue field, and is therefore a local field.
The ring of integers of an equal characteristic local field , denoted O , is the integral closure of F ( ) • in : The lemma integral_closure_eq_integerimplies that O = • , that is, an element of is integral over F ( ) • if and only if its valuation is less than or equal to 1.A pivotal consequence of this equality is that O is a discrete valuation ring : instance : discrete_valuation_ring (O p K) := integral_closure.dvr_of_finite_extension(FpX_completion p) K 3.1.1Formalizing the isomorphism (( )) ( ) .Due to the relatively recent appearance of the theory of adic valuations in mathlib, the isomorphism (( )) ( ) was not formalized at the time of our work.Nevertheless the API for working with completions of uniform spaces and uniform fields is quite rich, as described in §2.4.The key ingredient for the formalization is the notion of abstract completion of uniform spaces.Given a uniform space , a term pkg : abstract_completion T contains seven fields, the three most relevant for us being i) pkg.space, the underlying uniform space endowed with a map coe : pkg → T; ii) pkg.complete, which is a proof that pkg.space is complete; iii) pkg.dense_coe, which is a proof that coe is injective with dense image.
In particular, there is a term ratfunc_adic_compl_pkg whose space field represents the completion F ( ) .Now, given two terms (pkg, pkg : abstract_completion T), the declaration compare pkg pkg provides an equivalence of uniform spaces between them, which expresses the mathematical statement that "the completion of a uniform space is unique up to a unique isomorphism".The uniqueness of the extension (1) makes it easy to upgrade the equivalence to an equivalence of fields whenever both pkg.space and pkg .spaceare fields.It follows that once we prove that (( )) is also an abstract completion of ( ), it will correspond to a term laurent_series_pkg and the previous discussion produces the required isomorphism, in the form def laurent_series_ring_equiv : (laurent_series K) ≃ + * (ratfunc_adic_compl K) Code excerpt 5.The isomorphim between the Laurent series and the completion of rational functions.
To prove that (( )) is a completion of ( ), we need to show that (( )) is complete and that the image of the coercion ( ) ↩→ (( )) is dense.Ultimately, both results rely on a careful study of the interaction between the -adic valuation on ( ), the -adic valuation on (( )) 5 , and the coefficients of the corresponding series.For example, we show in the lemma lemma valuation_le_iff_coeff_zero_of_lt {D : Z} {f : laurent_series K} : v f ≤ (of_add (-D)) ↔ (∀ n : Z, n < D → f.coeff n = 0) that a Laurent series has valuation bounded by of_add (-D ) if and only if its -th coefficient vanishes for each < .
Once we can relate the valuation and the vanishing of the coefficients, the proof that ( ) has dense image in (( )) is very smooth.The proof of completeness heavily relies on the formalism of filters, as explained in [8, §4].The main ingredient is the lemma uniform_continuous_coeff (d : Z) (h : uniformity K = P id_rel) : uniform_continuous (coeff d) It shows that if is endowed with the discrete uniformity ([5, Chapitre II, §1, n • 1, Exemple 2]), the map ↦ → ( ) sending a Laurent series to its -th coefficient is uniformly continuous, for every ∈ Z.The consequence (see [5, Chapitre II, §3, n • 1, Proposition 3]) is that for every Cauchy filter F in (( )), the push-forward (F ) is a Cauchy filter of the discrete space and thus converges to a point (F ).It is then easy to combine the above results linking coefficients and valuation to show that, for every Cauchy filter F , the value (F ) vanishes for ≪ 0 and therefore In the lemma cauchy.eventually_mem_nhdswe then show that F converges to the principal filter P( (F )), proving that (( )) is complete.Finally, we can specialize to [[ ]] the equivalence laurent_series_ring_equiv to get its integral version: def power_series_ring_equiv : (power_series K) ≃ + * ((ideal_X K).adic_completion_integers (ratfunc K)) Code excerpt 6.The isomorphism between power series and the unit ball in the completion of rational functions.
In particular, we see that the residue field of ( ) is isomorphic to the residue field of (( )), hence to itself.The special case when = F yields the finiteness of the residue field of F ( ) mentioned in §3.1. 5Despite having the same name, these valuations are associated to different ideals: one is ( ) ⊆ [ ] and the other is

Mixed characteristic
The main formalization challenge we face when formalizing the definition of mixed characteristic local fields is analogous to the issue discussed in Remark 3.4.The basic API for the -adic numbers Q was already available in mathlib, but it predated the formalization of adic valuations.Since we want to take advantage of this more general theory, our approach is to define a new type Q ( ) def Q_p : Type* := adic_completion Q (p_height_one_ideal p) and to prove that it is isomorphic, as a valued field, to the field Q .This isomorphism is established in the definition padic_equiv and its construction follows the main strategy explained in §3.1.1.Namely, we provide two abstract completions padic_pkg and padic_pkg of Q and we upgrade the equivalence as uniform spaces to an isomorphism of valued fields.As a consequence, the unit ball Q ( ) • , called (Z_p p) in our code, is proved to be isomorphic to the -adic integers Z in the declaration In particular, Q ( ) is a mixed characteristic local field .We formalize the proof that any mixed characteristic local field is a local field as in Definition 3.1.The proof is analogous to the one in the equal characteristic case: the only difference is that every mixed characteristic local field is automatically separable over Q ( ) , since this holds for every algebraic extension of a field of characteristic 0. Hence, we do not need to assume separability.Finally, the ring isomorphism in the code excerpt 7 implies that the residue field of Q ( ) • is isomorphic to F , since this is the case for Z .
As above, this ensures that every mixed characteristic local field is indeed a local field according to Definition 3.1: def mixed_char_local_field.local_field : local_field K := { complete := mixed_char_local_field. complete_space p K, is_discrete := v.valuation.is_discretep K, finite_residue_field := ..., ..(mixed_char_local_field.valued p K) } The extension of the -adic valuation to is the unique nontrivial discrete valuation on , and the field is complete with respect to the induced topology .
The ring of integers O of a mixed characteristic local field is the integral closure of ( Q ( ) ) • in .
def ring_of_integers := integral_closure (Z_p p) K As in the equal characteristic case, we have that O = • , so in particular O is a discrete valuation ring .

Discussion
4.1 Future work Our next project is to prove that every local field is either a mixed characteristic local field or an equal characteristic local field, and that completions of global fields at finite places are local fields.We will then relate unramified extensions of local fields with extensions of their residue fields, showing that they are all (pro-)cyclic.This paper describes one of the first steps in a larger scale project aiming at formalizing local class field theory.We plan to formulate it in cohomological terms, relying on the recent work [18] by Livingston.

Related works
We formalize our work on top of the Lean 3 library mathlib and the Lean 3 project [13] formalizing extensions of norms.The basic theory of DVR's was available in mathlib at the start of our project.The library includes a formalization of the additive valuation on a DVR but we discuss in §4.3 our choice of working with Z m0 -valued valuations instead.
As far as other systems are concerned, the first formalization of the -adic numbers appeared in the Coq UniMath library in [19].Beyond the choice of the theorem prover, the two major differences with our work come from different axiomatization settings: the authors of [19] assume the univalence axiom and work in a constructive setting, replacing the notion of being non-zero with a property of being "apart from zero".As a consequence, their construction of the -adic integers Z follows a completely different path and involves a "carrying" operator on the ring Z[[ ]] and an equivalence relation based on univalent "paths" rather than equality.The field Q is then defined as the Heyting field of fractions of Z , a construction mimicking the usual field of fractions of an integral domain but in the setting of apartness domains.No treatment of the -adic valuation, of the -adic metric and more generally of topological properties is presented ibid.From the algebraic point of view, neither the properties of being a DVR, a Dedekind domain, or a local ring, nor algebraic extensions of Q , are approached.
The -adic numbers were later formalized in Isabelle/HOL, whose main library also contains a formalization of formal Puiseux series.The formalization of Z in [10] follows the classical path and is quite complete: both the definition as inverse limit and as completion of Z with respect to theadic valuation are formalized, together with a proof of their equivalence and of Hensel's lemma.The basic results of the topological properties of Z can also be found ibid., and the paper [11] contains deeper results: the field Q is defined as the fraction field of the ring Z formalized in the previous work, and it is endowed with both a valuation and a norm extending the previous ones on Z .Again, the main topological properties both of Q and of Q are studied.Nevertheless, neither the structure of Z as a DVR, or as a Dedekind domain, are addressed; also, there is no treatment of finite extensions of Q or of localization results.
The work [15] presents the formalization of the ring {{ }} of Puiseux series (over any commutative ring ), that are a generalization of Laurent series.Both [[ ]] and (( )) are defined and studied ibid., and are endowed with a valuation and a norm, whose basic properties are formalized and extended to The main focus of the paper is the formalization of the Newton-Puiseux' theorem stating that whenever is an algebraically closed field of characteristic 0, the same holds for {{ }}; as a consequence, few algebraic properties both of F (( )) and of F {{ }} are formalized.In particular, no formalization of the DVR structure of F [[ ]] or of field extensions of F (( )) can be found ibid.

Remarks about the Implementation
Additive and multiplicative valuations.The mathlib library prioritizes multiplicative valuations over additive ones, providing a much wider API for the first ones.For example, the general theory of valuation rings is framed in terms of multiplicative valuations.Moreover, while mathlib does not yet include the definition of discrete valuation, it does provide specific examples, such as adic valuations on Dedekind domains, which take values in Z m0 .
On the other hand, mathlib only provides the formalization of the additive valuation add_val on a discrete valuation ring, taking values in part_enat, a decidable version of the type enat= N ∪ {∞} .For consistency with the rest of the library, we propose to replace add_val with our implementation of the multiplicative valuation.

Uniformizers.
To indicate that a term ( : R) in a ring is a uniformizer for a valuation , we provide a predicate is_uniformizer : def is_uniformizer ( : R) : Prop := vR = (of_add (-1 : Z) : Z m0 ) We also provide a bundled version of this definition, called uniformizer .That is, we provide a structure uniformizer whose terms consists of two fields: an element of the ring , together with the proof that is a uniformizer for a given valuation.Since any uniformizer is necessarily a member of the unit ball, we decided to make the field in this definition a term of type vR.integer (as opposed to type R).
structure uniformizer := ( : vR.integer) (valuation_eq_neg_one : is_uniformizer vR ) The proposition is_uniformizer is useful when proving lemmas that apply to any uniformizer element, such as the lemma stating that every uniformizer is nonzero : lemma uniformizer_ne_zero { : R} (h : is_uniformizer vR ) : ≠ 0 := By contrast, the bundled definition is more convenient to prove results that involve fixing a uniformizer.For example, we use it when proving that every nonzero : • can be factored as the product of a unit by a power of a fixed uniformizer : lemma pow_uniformizer {r : 0 } (hr : r ≠ 0) ( : uniformizer v) : ∃ n : N, ∃ u : × 0 , r = .1^n* u := For an in-depth discussion of bundled versus unbundled representations in Lean and in Coq, we refer the reader to [1] or [21].
Extensions and valued instances.In §2.5 we construct, for each field complete with respect to a discrete valuation and every finite extension / , a unique valuation on , recorded as (v_L : valuation L Z m0 ).However, at this level of generality we do not put a global valued instance on : doing so would create infinitely many "diamonds", by which we mean the existence of two different procedures to endow an object with a certain mathematical structure (represented by two terms of the given structure that are propositionally, but not definitionally, equal).This leads to problems when exploiting the full force of the typeclass inference mechanism: indeed, suppose that in a given context Γ, a term : is well-typed assuming the existence of a term s:S for a certain structure S. Given two terms s 1 ,s 2 :S that are propositionally equal, the corresponding terms t 1 ,t 2 :T are different, yet carry the same mathematical information.Now, if the type-class inference mechanism can produce both terms s 1 and s 2 -say, inside a proof -the user would face the problem of having two different terms that look indistinguishable, which clearly leads to unexpected problems.In our setting, for every field that is complete with respect to a discrete valuation , the original valuation is propositionally but not definitionally equal to its trivial extension , resulting in two terms of the structure of a valued field on : to avoid any diamond, we need to exclude the second from the inference search, and therefore we need to avoid declaring a structure of valued field on the trivial extension of : this forces us to avoid declaring such a structure on every extension / .Nevertheless, we provide a lemma trivial_extension_eq_valuation proving the equality = .
We make an exception to this rule when implementing mixed and equal characteristic local fields, since we do declare valued instances for them.This creates a mild diamond for Q ( ) and F ( ) but this does not cause trouble in our formalization, thanks to the comparison lemma trivial_extension_ mentioned above.Indeed, in all cases where a the inference system would create problems, the lemma allows us to disambiguate the situation: for an example, the reader can inspect the proof of FpX_int_completion.equiv_valuation_subring, proving that the unit ball F ( ) • is isomorphic to the subring of F ( ) whose elements have ( )-adic valuation less than or equal to (1: Z m0 ).
Fraction fields.If is a discretely valued field, then • is a DVR, so we put a [valued (fraction_ring K 0 ) Z m0 ] instance on Frac( • ) .Note that, while and Frac( • ) are isomorphic, they are represented by different types in mathlib, so the above valued instance has a different type from the original [valued K Z m0 ] instance and no diamond occurs.However, it would if we had instead decided to put this valued instance on any field satisfying the condition [is_fraction_ring K 0 L], since this holds for .
The normed_field and the valued instances.Recall from §2.5 that to each discrete valuation on a field we can associate a nonarchimedean multiplicative norm |•| .
When there exists a preferred discrete valuation on , we often register it as a valued instance: In this situation, the norm |•| associated to would be the preferred nontrivial norm on , up to rescaling, and we would like to record a corresponding normed_field instance on : Note that the datum of a field is embedded into the definition of the normed_field class, while the class valued takes the field structure as an argument.It follows that declaring a normed_field instance on every field that carries a valued one leads to a loop in the typeclass inference system 6 .We discuss below a concrete example to illustrate this problem, for which we studied a trace of the instance search using the option trace.class_instances to track the typeclass inference process.
• / • .Remark 3.2.What we call "local fields" are normally referred to as "nonarchimedean local fields", to distinguish them from the archimedean local fields R and C. Since we only consider the nonarchimedean case in this work, we have opted for this simplification.Observe that the requirement that the residue field is finite is sometimes omitted.Accordingly, the completion C( ) is a valued field with residue field C that we do not qualify to be local, although this is sometimes the case in the literature.