Maxwell P.
Bobbin
a,
Samiha
Sharlin
a,
Parivash
Feyzishendi
a,
An Hong
Dang
a,
Catherine M.
Wraback
a and
Tyler R.
Josephson
*ab
aDepartment of Chemical, Biochemical, and Environmental Engineering, University of Maryland Baltimore County, 1000 Hilltop Circle, Baltimore, MD 21250, USA. E-mail: tjo@umbc.edu
bDepartment of Computer Science and Electrical Engineering, University of Maryland Baltimore County, 1000 Hilltop Circle, Baltimore, MD 21250, USA
First published on 16th November 2023
Interactive theorem provers are computer programs that check whether mathematical statements are correct. We show how the mathematics of theories in chemical physics can be written in the language of the Lean theorem prover, allowing chemical theory to be made even more rigorous and providing insight into the mathematics behind a theory. We use Lean to precisely define the assumptions and derivations of the Langmuir and BET theories of adsorption. We can also go further and create a network of definitions that build off of each other. This allows us to define a common basis for equations of motion or thermodynamics and derive many statements about them, like the kinematic equations of motion or gas laws such as Boyle's law. This approach could be extended beyond chemistry, and we propose the creation of a library of formally-proven theories in all fields of science. Furthermore, the rigorous logic of theorem provers complements the generative capabilities of AI models that generate code; we anticipate their integration to be valuable for automating the discovery of new scientific theories.
Hand-written proofs | Formal proofs |
---|---|
Informal syntax | Strict, computer language syntax |
Only for human readers | Machine-readable and executable |
Might exclude information | Cannot miss assumptions or steps |
Might contain mistakes | Rigorously verified by computer |
Requires human to proofread | Automated proof checking |
Easy to write | Challenging to write |
Scientists are generally familiar with computer algebra systems (CAS) that can symbolically manipulate mathematical expressions (see Table 3). These systems include SymPy9 and Mathematica.12 These systems are used frequently for scientific applications but come at the cost of being unsound, meaning they can have false conclusions.
Theorem provers are more rigorous than computer algebra systems, because they require computer-checked proofs before permitting operations, thereby preventing false statements from being proven. For example, a × b = b × a is true when a and b are scalars, but A × B ≠ B × A when A and B are matrices. CAS impose special conditions to disallow A × B = B × A,9 whereas theorem provers only allow changes that are proven to be valid. Theorem provers construct all of their math from a small, base kernel of mathematical axioms, requiring computer-checked proofs for objects constructed from the axioms. Even the most complicated math can be reduced back to that kernel. Since this kernel is small, verifying it by human experts or with other tools is manageable. Then, all higher-level math built and proved from the kernel is just as trustworthy. This contrasts with how CAS represent and introduce mathematics; because proofs are not required when high-level math is introduced, mistakes could enter at any level, and would require humans to catch and debug them10 (see Table 2).
Historically, interactive theorem provers have been used to logically connect advanced math theorems to the foundational axioms of mathematics.14–19 Before computers, this “axiomatization” of mathematics was developed by hand, in works like Principia Mathematica by Alfred North Whitehead and Bertrand Russell20 – the aim is to write down a minimal list of fundamental assumptions (axioms), and then systematically derive all of mathematics from those axioms. Computers play a key role in modern formalization efforts because they can store and verify massive libraries of interconnected theorems collaboratively written by hundreds of mathematicians.21
An analogous program to “axiomatize” physics was famously articulated as Hilbert's sixth problem.22 Recent reviews have discussed progress and unsolved questions on this “endless road” to describe how all of physics can be derived from a minimal set of axioms.23,24 Our vision is somewhat distinct from this – we are inspired by Paleo's ideas for formalizing physics theories25as a collection of proofs, instead of aiming to represent science as a single edifice emerging from one set of axioms (though this structure may emerge in the future). In particular, we ask “How can we formally represent a collection of proofs/derivations using an interactive theorem prover?”
Theorem provers have previously been used to formalize derivations in physics: theorems from Newton's Principia,26,27 versions of relativity theory,28,29 electromagnetic optics,30 and geometrical optics31 have been described and proved using proof assistants. Artificial intelligence tools for scientific discovery have also used theorem provers in designing optical quantum experiments,32 as well as for rediscovering and deriving scientific equations from data and background theory.33
Here we focus on formalizing fundamental theories in the chemical sciences. Progress toward axiomatizing thermodynamics began with Carathéodory in 1909,34 with recent developments by Lieb and Yngvason.35 But broadly, these questions have not been addressed using theorem provers to check the mathematics, which have seen limited use in the chemical sciences. One notable application by Bohrer36 uses a proof assistant that reasons about differential equations and control algorithms37 to describe and prove properties of chemical reactors.
We anticipate that Lean is expressive enough to formalize diverse and complex theories across quantum mechanics, fluid mechanics, reaction rate theory, statistical thermodynamics, and more. Lean gets its power from its ability to define mathematical objects and prove their properties, rather than just assuming premises for the sake of individual proofs. Lean is based on Type theory49,50 where both mathematical objects and the relation between them are modeled with types (see Fig. S1 in the ESI†). Everything in Lean is a term of a Type, and Lean checks to make sure that the Types match. Natural numbers, real numbers, functions, Booleans, and even proofs are types; examples of terms with these types include the number 1, Euler's number, f(x) = x2, TRUE, and the proof of BET theory, respectively. Lean is also expressive enough to allow us to define new types, just like mathematicians do,38 which allows us to define specific scientific theories and prove statements about them.
In this paper, we show how formalizing chemical theories may look, by demonstrating the tools of Lean through illustrative proofs in the chemical sciences. First, we introduce variables, types, premises, conjectures, and proof steps through a simple derivation of the Langmuir adsorption model. Next, we show how functions and definitions can be used to prove properties of mathematical objects by revising the Langmuir adsorption model through definitions and showing it has zero loading at zero pressure. Finally, we turn to more advanced topics, such as using geometric series to formalize the derivation of the BET equation and using structures to define and prove relationships in thermodynamics and motion.
In Section 3 we outline the proofs formalized using Lean version 3.51.1. We host proofs on a website that provides a semi-interactive platform connecting to the Lean codes in our GitHub repository (https://atomslab.github.io/LeanChemicalTheories/). An extended methods section introducing Lean is in the ESI† Section 5.1.
The Langmuir model assumes that all sites are thermodynamically equivalent, the system is at equilibrium, and that adsorption and desorption rates are first order. The adsorption and desorption rates are given by eqn (1) and eqn (2), respectively.
rad = kadpA[S] | (1) |
rd = kd[Aad] | (2) |
(3) |
Using the site balance [S0] = [S] + [Aad], where [S0] represents the total concentration of available sites, we arrive at eqn (4).
(4) |
We can rearrange eqn (4) into, eqn (5).§
(5) |
Using the definition of the fraction of adsorption, , and the definition of the equilibrium constant, , we arrive at the familiar Langmuir absorption equation, eqn (6).
(6) |
This informal proof is done in natural language, and it doesn't explicitly make clear which equations are premises to the proof and which are intermediate steps. While the key steps from the premises to the conclusion are shown, the fine details of the algebra are excluded. In contrast, Lean requires premises and conjecture to be precisely defined and requires that each rearrangement and cancellation is shown or performed computationally using a tactic. The next part shows how this proof is translated into Lean.
As shown in Fig. 1, every premise must be explicitly stated in Lean, along with the final conjecture and proof tactics used to show that the conjecture follows from the premises. Lean is an interactive theorem prover, meaning that the user is primarily responsible for setting up the theorem and writing the proof steps, while Lean continuously checks the work and provides feedback to the user. The central premises of the proof are expressions of adsorption rate (hrad), desorption rate (hrd), the equilibrium relation (hreaction), and the adsorption site balance (hS0). Additional premises include the definition of adsorption constant (hK) and surface coverage (hθ) from the first four premises, as well as mathematical constraints (hc1, hc2, and hc3) that appear during the formalization. The model assumes the system is in equilibrium, so the adsorption rate, rad = k_ad × P × S and desorption rate, rd = k_d × A are equal to each other, where kad and kd are the adsorption and desorption rate constant respectively, S is concentration of empty sites, and A is the concentration of sites occupied by A. After begin, a sequence of tactics rearranges the goal state until the conjecture is proved. Note when performing division, Lean is particular to require that the denominator terms are nonzero.
An interesting part of the proof is that only certain variables or their combinations are required to be not zero. When building this proof, Lean imports the real numbers and the formalized theorems and tactics for them in mathlib. Lean does not permit division by zero, and it will flag issues when a number is divided by another number that could be zero. Consequently, we must include additional hypotheses hc1–hc3 in order to complete the proof. These provide the minimum mathematical requirements for the proof; more strict constraints requiring rate constants and concentrations to be positive would also suffice. These ambiguities are better addressed by using definitions and structures, which enable us to prove properties about the object. Nonetheless, this version of the Langmuir proof is still a machine-readable, executable, formalized proof.
Though this is a natural way to write the proof, we can condense the premises by using local definitions. For instance, the first two premises hrad and hrd can be written into hreaction to yield k_ad × P × S = k_d × A and we can also write expressions of hθ and hK in the goal statement. While hrad, hrd, hθ, and hK each have scientific significance, in this proof, they are just combinations of real numbers. Alternative versions of this proof are described in ESI Section 5.2.1.†
Formally, a function is defined as a mapping of one set (the domain) to another set (the co-domain). The notation for a function is given by the arrow “→”. For instance, the function, conventionally written as Y = f(X) or Y(X), maps from set X to set Y is written as X → Y in arrow notion.¶
Importantly, the arrow “→” is also used to represent the conditional statement (if-then) in logic, but this is not a duplication of syntax. Because everything is a term of Type in Lean, functions map type X to type Y; when each type is a proposition, the resulting function is an if-then statement.
As stated in the introduction, Lean's power comes from the ability to define objects globally, not just postulate them for the purpose of local proof. When a mathematical object is formally defined in Lean, multiple theorems can be written about it with certainty that all proofs pertain to the same object. In Lean, we use def to define new objects and then prove statements about these objects. The def command has three parts: the arguments it takes in (the properties of the object), the type of the output, and the proof that the object has such a type. In Lean:
For instance, we can define a function that doubles a natural number:
The λ symbol comes from lambda calculus and is how an explicit function is defined. After the lambda symbol is the variable of the function, n with type . After the comma is the actual function. By hand, we would write this as f(n) = n + n. This function doubles any natural number, as the name suggests. We could use it, for example, to show:
In the previous section, we showed an easy-to-read derivation of Langmuir adsorption, and in ESI Section 5.2.1,† we improved the proof using local definitions. Here, we improve it further by defining the Langmuir model as an object in Lean and then showing the kinetic derivation of that object. This way, the object defining the single-site Langmuir model can be reused in subsequent proofs, and all are certain to refer to the same object.
We define the model as a function that takes in pressure as a variable. Given a pressure value, the function will compute the fractional occupancy of the adsorption sites. In Lean, this looks like (https://atomslab.github.io/LeanChemicalTheories/adsorption/langmuir_kinetics.html#langmuir_single_site_model):
The λ symbol comes from λ-calculus58 and is one way to construct functions. It declares that P is a real number that can be specified. When the real number is specified, it will take the place of P in the equation. The definition also requires the equilibrium constant to be specified.||
With this, the kinetic derivation of Langmuir can be set up in Lean like this (https://atomslab.github.io/LeanChemicalTheories/adsorption/langmuir_kinetics.html#langmuir_single_site_kinetic_derivation):
This derivation is almost exactly like the proof in ESI Section 5.2.1; the only difference is the use of the Langmuir model as an object. After the langmuir_single_site_model simplifies to the Langmuir equation, the proof steps are the same.
Using the definition makes it possible to write multiple theorems about the same Langmuir object. We can also prove that the Langmuir expression has zero loading at zero pressure, and in the future we can show that it has a finite loading in the limit of infinite pressure, and converges to Henry's Law in the limit of zero pressure (https://atomslab.github.io/LeanChemicalTheories/adsorption/langmuir_kinetics.html#langmuir_zero_loading_at_zero_pressure). Definitions and structures, as we will see in later sections, are crucial to building a web of interconnected scientific objects and theorems.
(7) |
(8) |
(9) |
The variables y, x and C are expressed in the original paper as shown through eqn (10)–(12):
y = PC1, where C1 = (a1/b1)eE1/RT | (10) |
x = PCL, where CL = eEL/RT/g | (11) |
C = y/x = C1/CL | (12) |
These constants, along with the surface area of the zeroth layer, given by s0, saturation pressure, and the three constraints are defined using the constant declaration in Lean. Mathematical objects can also be defined in other ways such as def, class or structure38 but for this proof we will use constant which is convenient for such simple objects. We will illustrate later in our thermodynamics proof how constants can be merged into a Lean structure for reusability.
In Lean, this is (https://atomslab.github.io/LeanChemicalTheories/adsorption/BETInfinite.html#C_L):
With these constant declarations, we can now define y, x, and C in Lean as (https://atomslab.github.io/LeanChemicalTheories/adsorption/BETInfinite.html#BET_first_layer_adsoprtion_rate):
Since y and x are both functions of pressure, their definitions require pressure as an input. Alternatively, the input can be omitted if we want to deal with x as a function rather than as a number. Notice that the symbols we declared using constant do not need to be supplied in the inputs as they already exist in the global workspace.
We formalize eqn (7) by recognizing that the main math behind the BET expression is an infinite sequence that describes the surface area of adsorbed particles for each layer. The series is defined as a function that maps the natural numbers to the real numbers; the natural numbers represent the indexing. It is defined in two cases: if the index is zero, it outputs the surface area of the zeroth layer, and if the index is the n + 1, it outputs xn+1s0C.
si = Cxis0 for i: [1,∞) | (13) |
In Lean, we define this sequence as (https://atomslab.github.io/LeanChemicalTheories/adsorption/BETInfinite.html#seq):
Where si is the surface area of the ith layer, C and x are given by eqn (12) and eqn (11), respectively, and s0 is the surface area of the zeroth layer. The zeroth layer is the base surface and is constant.
We now have the area and volume equations both in terms of geometric series with well-defined solutions. The BET equation is defined as the ratio of volume absorbed to the volume of a complete unimolecular layer, given by eqn (14).
(14) |
The main transformation in BET is simplifying this sequence into a simple fraction which involves solving the geometric series. The main math goal is given by eqn (15).
(15) |
Before doing the full derivation, we prove eqn (15), which we call sequence_math. In Lean, this is (https://atomslab.github.io/LeanChemicalTheories/adsorption/BETInfinite.html#sequence_math):
In Lean, the apostrophe after the sum symbol denotes an infinite sum, which is defined to start at zero since it is indexed by the natural numbers, which start at zero. Since the infinite sum of eqn (15) starts at one, we add one to all the indexes, k, so that when k is zero, we get one, etc. We also define two new theorems that derive the solution to these geometric series with an index starting at one. After expanding seq, we use those two theorems, and then rearrange the goal to get two sides that are equal. We also use the tag lemma instead of theorem, just to communicate that it is a lower-priority theorem, intended to prove other theorems. The tag lemma has no functional difference from theorem in Lean, it's purpose is for mathematicians to label proofs.
With this we can formalize the derivation of eqn (7). First we define eqn (7) as a new object and then prove a theorem showing we can derive this object from the sequence. In Lean, the definition looks like this (https://atomslab.github.io/LeanChemicalTheories/adsorption/BETInfinite.html#brunauer_26):
Here, we explicitly define this as a function, because we want to deal with eqn (7) normally as a function of pressure, rather then just a number. Now we can prove a theorem that formalizes the derivation of this equation (https://atomslab.github.io/LeanChemicalTheories/adsorption/BETInfinite.html#brunauer_26_from_seq):
Unlike the Langmuir proof introduced earlier in Fig. 1, the BET uses definitions that allow reusability of those definitions across the proof structure. The proof starts by showing that seq is summable. This means the sequence has some infinite sum and the ∑′ symbol is used to get the value of that infinite series. We show in the proof that both seq and k*seq is summable, where the first is needed for the area sum and the second is needed for the volume sum. After that, we simplify our definitions, move the index of the sum from zero to one so we can simplify the sequence, and apply the BET.sequence_math lemma we proved above. Finally, we use the field_simp tactic to rearrange and close the goal. With that, we formalized the derivation of eqn (7), just as Brunauer, et al. did in 1938.
In the ESI,† we continue formalizing BET theory by deriving eqn (28) from Brunauer et al.'s paper, given by eqn (16)
(16) |
This follows from recognizing that 1/CL = P0. While Brunauer, et al. attempt to show this in the paper, we discuss the trouble with implementing the logic they present. Instead, we show a similar proof that eqn (7) approaches infinity as pressure approaches 1/CL, and assume as a premise in the derivation of eqn (16) that 1/CL ≡ P0.
We can prove that the ideal gas law, PV = nRT follows Boyle's Law, P1V1 = P2V2, following the style of our derivation of Langmuir's theory: demonstrating that a conjecture follows from the premises (https://atomslab.github.io/LeanChemicalTheories/thermodynamics/boyles_law.html). However, this proof style doesn't facilitate interoperability among proofs and limits the mathematics that can be expressed. z in contrast, we can prove the same, more systematically, by first formalizing the concepts of thermodynamic systems and states, extending that system to a specific ideal gas system, defining Boyle's Law in light of these thermodynamic states, and then proving that the ideal gas obeys Boyle's Law (see Fig. 3).
Classical thermodynamics describes the macroscopic properties of thermodynamic states and relationships between them.60,61 We formalize the concept of “thermodynamic system” by defining a Lean structure called thermo_system over the real numbers, with thermodynamic properties (e.g., pressure, volume, etc.) defined as functions from a type to the real numbers . Here, α is meant to represent a general indexing type. It could be the natural numbers if we wanted to use those to represent states of the system, real numbers to represent time, or anything else. The only requirement is that α is nontrivial, meaning it has at least two different elements. In Lean, this is (https://atomslab.github.io/LeanChemicalTheories/thermodynamics/basic.html#thermo_system):
We define six descriptions of the system: isobaric (constant pressure); isochoric (constant volume); isothermal (constant temperature); adiabatic (constant energy); closed (constant mass); and isolated (constant mass and energy). Each of these conditions has the type Prop, or proposition, considering them to be assertions about the system. We formally define these by stating that, for all (∀) pairs of states n and m, the property at those states is equal. We define these six descriptions to take in a thermo_system since we need to specify what system we are ascribing this property to. In Lean, this is (https://atomslab.github.io/LeanChemicalTheories/thermodynamics/basic.html#isobaric):
We define an isolated system as just a closed system and (∧) adiabatic, rather than using the universal quantifier (∀), since it would be redundant.
Now that the basics of a thermodynamic system have been defined, we can define models that attempt to describe the system mathematically. These models can be defined as another structure, which extends the thermo_system structure. When a structure extends another structure, it inherits the properties of the structure it extended. This allows us to create a hierarchy of structures so we don't have to redefine properties repeatedly. The most well-known model is the ideal gas model, which comes with the ideal gas law equation of state. We define the ideal gas model to have two properties, the universal gas constant, R, and the ideal gas law. In the future, we plan to add more properties to the definition, especially as we expand on the idea of energy. We define the ideal gas law as an equation relating the products of pressure and volume to the product of temperature, amount of substance, and the gas constant. In Lean, this is (https://atomslab.github.io/LeanChemicalTheories/thermodynamics/basic.html#ideal_gas):
To define a system modeled as an ideal gas, we write in Lean: (M: ideal_gas). Now we have a system, M, modeled as an ideal gas.
Boyle's law states that the pressure of an ideal gas is inversely proportional to the system's volume in an isothermal and closed system.62 This is mathematically given by eqn (17), where P is pressure, V is volume, and k is a constant whose value is dependent on the system.
PV = k | (17) |
In Lean, we define Boyle's law as (https://atomslab.github.io/LeanChemicalTheories/thermodynamics/basic.html#boyles_law):
We use the existential operator (∃) on k, which can be read as there exists a k, because each system has a specific constant. We also define the existential before the universal, so it is logically correct. Right now, it reads, there exists a k, such that for all states, this relation holds. If we write it the other way, it would say for all states, there exists a k, such that this relation holds. The second way means that k is dependent on the state of the system, which isn't true. The constant is the same for any state of a system. Also, even though Boyle's law is a statement about an ideal gas, we define it as a general system so, in the future, we can look at what assumptions are needed for other models to obey Boyle's law.
Next, we prove a couple of theorems relating to the relations that can be derived from Boyle's law. From eqn (17), we can derive a relation between any two states, given by eqn (18), where n and m are two states of the system.
PnVn = PmVm | (18) |
The first theorem we prove shows how eqn (18) follows from eqn (17). In Lean this looks like (https://atomslab.github.io/LeanChemicalTheories/thermodynamics/basic.html#boyles_law_relation):
The right arrow can be read as implies, so the statement says that Boyle's law implies Boyle's relation. This is achieved using modus ponens, introducing two new names for the universal quantifier, then rewriting Boyle's law into the goal by specializing Boyle's law with n and m. We also want to show that the inverse relation holds, such that eqn (18) implies eqn (17). In Lean, this is (https://atomslab.github.io/LeanChemicalTheories/thermodynamics/basic.html#boyles_law_relation'):
We begin in the same way by using modus ponens and simplifying Boyle's law in the form of eqn (17). Next, we satisfy the existential by providing an old name. In our proof, we use P1V1 as an old name for k, then we specialize the relation with n and 1 and close the goal.
Finally, with these two theorems, we show that Boyle's law can be derived from the ideal gas law under the assumption of an isothermal and closed system. In Lean, this is (https://atomslab.github.io/LeanChemicalTheories/thermodynamics/basic.html#boyles_from_ideal_gas):
This proof is completed by using the second theorem for Boyle's relation and simplifying the ideal gas relation using the two iso constraints.
We have implemented this framework to prove both Charles' and Avogadro's law (https://atomslab.github.io/LeanChemicalTheories/thermodynamics/basic.html) illustrating the interoperability of these proofs. In the future, we plan to define energy and prove theorems relating to it, including the laws of thermodynamics.63
The equations of motion are a set of two coupled differential equations that relate the position, velocity, and acceleration of an object in an n-dimensional vector space.67 The differential equations are given by eqn (19) and (20), where x, v, and a represent position, velocity, and acceleration, respectively (bold type face signifies a vector quantity). All three variables are parametric equations, where each dimension of the vector is a function of time.**
(19) |
(20) |
As in the thermodynamics section, we can define a structure, motion, to encompass these concepts (Fig. 4). This structure defines three new elements: position, velocity, and acceleration, which are functions, and two differential equations relating these three functions. This structure also requires the vector space to form an inner product space, which is a real or complex vector space with an operator (the inner product) over the field. The inner product is a generalization of the dot product for any vector space. By requiring inner_product_space, the motion structure inherits all of inner_product_space’s properties and allows us to access the calculus theorems in mathlib. In Lean, this is (https://atomslab.github.io/LeanChemicalTheories/physics/kinematic_equations.html#motion):
In Lean, if a function is not differentiable at a point, the derivative at that point returns zero.†† During our first formalization attempt, we tried to define a function to be constant by setting its derivative to zero. However, df/dx = 0 may also arise if a function is not differentiable at that point. To avoid this edge case, we define another structure to require the equations of motion to be n-times continuously differentiable everywhere. We only require the equations to be n-times differentiable instead of infinitely differentiable for generality reasons, however, a theorem can instantiate this structure and assume infinite differentiability. We also declare this as a separate structure, instead of in the motion structure, to allow future proofs that require the equations to be n-times continuously differentiable on a set or an interval rather than everywhere (e.g., a molecular mechanics force field with a non-smoothed cutoff is not differentiable at that point). That way, depending on the theorem, the user can choose the appropriate extension. In Lean, this structure looks like (https://atomslab.github.io/LeanChemicalTheories/physics/kinematic_equations.html#motion_cont_diff_everywhere):
The field contdiff states that for all n, defined as a natural number including positive infinity, and for all m, defined as a natural number, if m is less than n, then the mth derivative of position is continuously differentiable n-times.
When acceleration is constant, this set of differential equations has four useful analytical solutions, the kinematic equations, eqn (21)–(24), where the subscript naught denotes variables evaluated at t = 0.
v(t) = at + v0 | (21) |
(22) |
(23) |
v2(t) = v02 + 2a·d | (24) |
Under the assumption of one-dimensional motion, these equations simplify to the familiar introductory kinematic equations. Eqn (24), also known as the Torricelli equation, uses the shorthand square to represent the dot product, v2(t) ≡ v(t) × v(t).
With this, we can now begin deriving the four kinematic equations. The first three derivations for eqn (21)–(23), all use the same premises, given below:
The first line contains four premises to declare the field and vector space the motion space is defined on. The next line defines a motion space, M. The third line contains two premises, a variable, A, which represents the value of constant acceleration, and n, the number of times position can be differentiated. When applying these theorems, the top function, which means positive infinity in Lean, can be used to specify n. The final line is a premise that assumes acceleration is constant. The lambda function is constant because A is not a function of t, so for any value of t, the function outputs the same value, A. The three kinematic equations in Lean (https://atomslab.github.io/LeanChemicalTheories/physics/kinematic_equations.html#const_accel) are given below (note, the premises are omitted since they have already been given above).
The · symbol indicates scalar multiplication, such as when a vector is multiplied by a scalar. We normally use the · symbol for the dot product, but Lean uses the inner function for the dot product. Also, “velocity 0” means the velocity function evaluated at 0. Lean uses parentheses for orders of operations, not for function inputs, so f(x) in normal notation converts to f x in Lean. The proofs of the first two theorems use the two differential equations from the motion structure and the antiderivative, whose formalization we explain in the ESI† (these theorems weren't available in mathlib at the time of writing, so we proved them ourselves). The third theorem is proved by rearranging the previous two theorems.
Because we declared the field is_R_or_C, the above proofs hold for both real and complex time. However, we were unable to prove eqn (24), due to the complex conjugate that arises when simplifying the proof. Eqn (24) uses the inner product, a function that takes in two vectors from a vector space and outputs a scalar. If the vector space is a Euclidean vector space, this is just the dot product. The inner product is semi-linear, linear in its first argument, eqn (25), but sesquilinear in its second argument, eqn (26).
〈ax + by,z〉 = a〈x,z〉 + b〈y,z〉 | (25) |
〈x,ay + bz〉 = ā〈x,y〉 + 〈x,z〉 | (26) |
The bar denotes the complex conjugate: for a complex number, g = a + bi, the complex conjugate is: ḡ = a − bi. If g is a real number, then g = ḡ. For the proof of eqn (24), we get to a form where one of the inner products has an addition in the second term that we have to break up, and no matter which way we rewrite the proof line, one of the inner products ends up with addition in the second term. To proceed, we instead defined the final kinematic equation to hold only for real time. In Lean, this looks like (https://atomslab.github.io/LeanChemicalTheories/physics/kinematic_equations.html#real_const_accel'''):
While we haven't proved that eqn (24) doesn't hold for complex time, we encountered difficulties and contradictions when attempting to prove the complex case. Thus, eqn (24) currently only holds for real time.
An imaginary-time framework can be used to derive equations of motion from non-standard Lagrangians69,70 to examine hidden properties in classical and quantum dynamical systems in the future. By exploring these proofs in both real and complex time, we illustrate how a proof in one case can be adapted for related cases. Here, four proofs for real numbers can be easily extended to complex numbers by changing the type declared up front, and the validity of the proofs in the more general context is immediately apparent.
Importantly, we emphasize that while our proofs are verified to be mathematically correct, this verification does not extend to the external world. This distinction between syntax (logical relationships among words and arguments in a language) and semantics (whether words are meaningful or arguments are true, according to external reality) in scientific reasoning has been emphasized by logicians such as Alfred Tarski73 and Rudolf Carnap.74,75 For scientists and engineers, whether a theory is true or meaningful is first and foremost about whether observational data support it – logical correctness of the derivation is required, of course, but this is typically assumed. Indeed, when one of us described our BET proof to an experimentalist in adsorption, their reply was, “but BET isn't accurate.” They knew that BET theory does not semantically match experiments in many contexts (in fact, much literature has discussed when BET analysis should not be applied, for instance76). BET theory has been a useful conceptual model for the field, but nonetheless relies on approximations that often drift far from reality. In this work, we only claim to rigorously establish the syntax of the theories we describe. Nonetheless, Lean operating with input/output functions can receive data from the external world, which may open possibilities for semantically grounding its logical conclusions in certain contexts, as well.
The Lean theorem prover is especially powerful, as it facilitates the re-use of theorems and the construction of higher-level mathematical objects from lower-level ones. We showed how this feature can be leveraged in science proofs; after a fundamental theory is formally verified, it can then be used in the development of other theories. This can be approached in two ways: definitions can be directly reused in subsequent proofs, and structures can enable hierarchies of related concepts, from general to more specific. Thus we have not just proved a few theorems about scientific objects but have begun to create an interconnected structure of formally verified proofs relating fields of science.
While learning Lean and writing the proofs appearing here, we routinely asked ourselves, “How do I close this goal? I wish there was a way to automate this.” In fact, the first vision for computer-assisted proofs in the 1950s and 60s was to automate the process fully;77interactive theorem provers that “merely” check human-written proofs didn't appear until later. But historically, automated theorem provers (ATPs) made progress on narrow classes of problems (e.g., problems in first-order logic78) but couldn't address proofs in advanced math (except when problems are described in such simple terms, like the Robbins Conjecture79). In short, theorem proving is like searching for a path from premises to conjecture, but in a realm with an “infinite action space48 – traditional algorithms have been inadequate. For complex proofs, interactive theorem provers (ITPs) have been more successful, because they facilitate human creativity in writing proofs, while leveraging the rigor of the computer for checking them and providing feedback to the user. Modern ITPs also use the computer for small-scale automation via tactics; the human provides strategy while the computer executes tactics. Complex tactics sometimes blur the line between automated and interactive theorem proving. For example, Isabelle (an ITP) has the Sledgehammer tactic,80 which takes the current proof state and attempts to transform it into an equivalent problem in first-order logic, which can then be efficiently solved using an ATP.
Recent approaches have leveraged machine learning to expand the capabilities of automated theorem proving. Theorem proving can be framed as a reinforcement learning problem,81,82 in which an agent is to learn an effective theorem proving policy via rewards from successfully proving theorems. “Autoformalization” refers to the translation of informal proofs into formal proofs, akin to translating text from one language to another (but with extremely strict requirements on the formal side).83 Theorem proving can also be framed as a next-word-prediction problem (“auto-complete” for math proofs) in which a database of formal math proofs is used to train a language model to predict the next word in the proof. Large language models (LLMs) like ChatGPT84,85 have some emergent reasoning abilities86 but often make mistakes and cannot be trusted. By connecting language models with ITPs to provide feedback, training them on proof databases like mathlib, and deploying them as part of traditional search algorithms, progress has been made toward automating proofs in Lean,47,87,88 even to the point of generating correct solutions to International Math Olympiad problems.89
This interplay between creative but unreliable generative algorithms and the strict logic of a proof-checking system may be a model for future AI-driven discovery in science, especially for discovering new theories. An early example of this is AI-Descartes, in which a symbolic regression algorithm generates equations to match experimental data, which is then combined with an automated theorem prover to establish the equations' “derivability” with respect to a scientific theory.33 However, in this work, each theory required human expertise to be expressed in formal language, and reliance on an automated theorem prover limited the scope of theories to those expressible in first-order logic. AI tools that can autoformalize the informal scientific literature, generate novel theories, and auto-complete complex proofs could open new avenues for automating theory discovery. LLMs have demonstrated capabilities in solving chemistry problems,90,91 as well as answering scientific question-and-answer problems invoking quantitative reasoning.92 However, LLMs are unreliable – they famously “hallucinate” (generate falsehoods) and are biased or unreliable evaluators of their own outputs.93,94 Pairing them with external tools95–97 improves their capabilities; theorem provers could play a role like that. How will these models be trained? We suggest two avenues: training on human-written databases of formal proofs in science and engineering (which are yet to be written) and leveraging interactive feedback from Lean through tools like LeanDojo.88 Beyond being formally grounded in axiomatic mathematics, formal proofs in science and engineering are machine-readable instances of correct mathematical logic that could serve as a foundation for artificial intelligences aiming to learn, reason, and discover in science.98–100
Our next goals are to continue building out classical thermodynamics, formalize statistical mechanics, and eventually construct proofs relating the two fields. We are also interested in laying the foundations for classical mechanics in Lean and formalizing more difficult proofs like Noether's theorem101 (a basis for deriving conservation laws) or establishing the 2nd law of thermodynamics axiomatically.35
The proofs in this paper were written in Lean 3,72 because the extensive mathlib library was only available in Lean 3 when we began. While Lean 3 was designed for theorem proving and management of large-scale proof libraries, the new version, Lean 4,102 is a functional programming language for writing proofs and programs, as well as proofs about programs.102,103 The Lean community finished porting mathlib to Lean 4 and Lean 3 is now deprecated; we recommend future proofs should be written in Lean 4, which is more capable, versatile, and easy to use compared to Lean 3. With Lean 4, we are bridging formally-correct proofs with executable functions for bug-free scientific computing; we will be elaborating on that in future work.
We hope these expository proofs in adsorption, thermodynamics, and kinematics will inspire others to consider what proofs and derivations could be formalized in their fields of expertise. Virtually all mathematical concepts can be established using dependent type theory; the density functionals, partial derivatives, N-dimensional integrals, and random variables appearing in our favorite theories should be expressible in Lean. Just as an ever-growing online community of mathematicians and computer scientists is building mathlib,40 we anticipate a similar group of scientists building a library of formally-verified scientific theories and engineering mathematics. To join, start learning Lean, join the online community, and see what we can prove!
Footnotes |
† Electronic supplementary information (ESI) available: Additional background on how Lean works (Section 5.1) and all the additional proofs (Section 5.2), including an improved version of Langmuir adsorption model (5.2.1), the final derived form of BET adsorption model (5.2.2), and the antiderivative proofs (5.2.3) that was used for kinematic equations. All code and proofs for this project are available in our GitHub repository (https://atomslab.github.io/LeanChemicalTheories/). See DOI: https://doi.org/10.1039/d3dd00077j |
‡ Mathematical terms that may be unfamiliar to the reader, like theorem, are defined in the glossary, cross-reference to Table 3. |
§ The manuscript we first submitted for peer review included a typo in eqn (5), with [S0] appearing as [S]. Neither the authors nor the peer reviewers detected this; it was identified by a community member who accessed the paper on arXiv. Of course, Lean catches such typos immediately. |
¶ These types are easily extended to functionals, which are central to density functional theory. A function that takes a function as an input can be defined by . |
|| This definition can be specified in multiple ways. The pressure could be required as an input like the equilibrium constant, or the equilibrium constant can be specified as a variable in the function like pressure. Any of these definitions work, and it is possible to prove congruence between them. We chose this way to purposefully show both definitions and functions in Lean. |
** These proofs could also be constructed using partial differential equations, but mathlib doesn't currently have enough theorems for partial derivatives. |
†† Likewise, division by zero is defined to return zero instead of something like “undefined” or “NaN”. In Lean and other theorem provers, the symbol/is not used for mathematical division but instead points to a function called real.div. This function returns x/y if y is not zero, and 0 if y equals 0. Another case is the real square root function (real.sqrt), which outputs a real number for any input, even negatives since it is defined as . These conventions may be unfamiliar to scientists and engineers, but they are used for convenience and won't lead to contradictions in a proof. Any invalid step in a proof involving these conventions will be caught when invoking a theorem not true for its definition. We wrestled with this convention for some time before finding clarity in this blog post archived for ref. 68. |
This journal is © The Royal Society of Chemistry 2024 |