Zulip Chat Archive
Stream: Natural sciences
Topic: wrong formalization of boyle's law in lean
Bulhwi Cha (Jul 06 2023 at 19:43):
import Mathlib.Data.Real.Basic
lemma Boyle
-- Variables
(P1 P2 V1 V2 T1 T2 n1 n2 R : ℝ)
-- Assumptions
(a1 : P1 * V1 = n1 * R * T1)
(a2 : P2 * V2 = n2 * R * T2)
(a3 : T1 = T2)
(a4 : n1 = n2) :
-- Conjecture
P1 * V1 = P2 * V2 := by
rw [a3] at a1
rw [a4] at a1
exact (rfl.congr (Eq.symm a2)).mp a1
lemma just_a_random_example (x₁ x₂ y₁ y₂ z₁ z₂ w₁ w₂ k : ℝ)
(h₁ : x₁ * y₁ = w₁ * k * z₁) (h₂ : x₂ * y₂ = w₂ * k * z₂)
(h₃ : z₁ = z₂) (h₄ : w₁ = w₂) : x₁ * y₁ = x₂ * y₂ := by
rw [h₁, h₂, h₃, h₄]
theorem Boyle_is_just_a_random_example : Boyle = just_a_random_example := rfl
I think the lemma Boyle
should be removed from LeanChemicalTheories. It's not a correct formalization of Boyle's law; it's merely an example of using rewriting. We need to formally define the pressure and the volume of a confined ideal gas. Then we should use those definitions to state Boyle's law correctly in Lean. But currently, I have no idea how to define them.
Scott Morrison (Jul 06 2023 at 23:55):
Presumably one defines an ideal gas as some limit of systems with non-interacting particles with velocities assumed to follow Maxwell's distribution. (i.e. blackboxing as a hypothesis how they actually end up in that distribution). Then calculating the pressure is "just" some integration problem. I suspect mathlib is not ready to support this calculation yet, but perhaps it is close.
Yury G. Kudryashov (Jul 07 2023 at 01:03):
One can define
axiom idealGasConst : Real
structure IdealGasState where
pressure volume temperature amount : {x : Real // 0 < x}
law : pressure * volume = amount * idealGasConst * temperature
then write
theorem IdealGasState.boyle (a b : IdealGasState) (ht : a.temperature = b.temperature)
(hn : a.amount = b.amount) : a.pressure * a.volume = b.pressure * b.volume := by
rw [...]
theorem IdealGasState.charles (a b : IdealGasState) (hp : a.pressure = b.pressure)
(hn : a.amount = b.amount) : a.volume * b.temperature = b.volume * a.temperature := by
rw [...]
-- similarly for Avogadro's and Gay-Lussac's
Of course, these implications are not deep results.
Yury G. Kudryashov (Jul 07 2023 at 01:05):
(you may need R > 0
for some of these)
Yury G. Kudryashov (Jul 07 2023 at 01:07):
But this (with a couple more definitions) allows one to talk about, e.g., efficiency of different thermodynamic cycles.
Yury G. Kudryashov (Jul 07 2023 at 01:15):
Probably, a better approach would be
-- TODO: should we require positivity
structure GasState where
pressure volume temperature amount : {x : Real // 0 < x}
namespace GasState
def IsIdeal : pressure * volume = R * amount * temeperature
def IsothermalOn (f : X -> GasState) (s : Set X) : Prop :=
∀ a ∈ s, ∀ b ∈ s, (f a).temperature = (f b).temperature
theorem IsothermalOn.boyle {f : X → GasState} {s : Set X} (h : IsothermalOn f s) {a b : X}
(ha : a ∈ s) (hb : b ∈ s) (h' : (f a).amount = (f b).amount) : (f a).pressure * (f a).volume = (f b).pressure * (f b).volume :=
Yury G. Kudryashov (Jul 07 2023 at 01:17):
I guess, one can start with this and formalize, e.g., Carnot's theorem https://en.wikipedia.org/wiki/Carnot%27s_theorem_(thermodynamics)
Yury G. Kudryashov (Jul 07 2023 at 01:19):
Disclaimer: I'm very far from being an expert in chemistry or physics.
Tyler Josephson ⚛️ (Jul 07 2023 at 03:28):
@Max Bobbin pointed this out when we first wrote up that proof of Boyle's Law - indeed, this is, mathematically speaking, not that interesting. I still like it for illustrating Lean to newcomers - indeed, it only illustrates the rewrite tactic, but this is handy in an oral presentation setting to an audience with zero background in theorem proving.
We have a more rigorous treatment here, where we use structures. But we still have a long ways to go to connect this to either classical or statistical thermodynamics.
Bulhwi Cha (Jul 07 2023 at 03:39):
Tyler Josephson ⚛️ said:
Max Bobbin pointed this out when we first wrote up that proof of Boyle's Law - indeed, this is, mathematically speaking, not that interesting. I still like it for illustrating Lean to newcomers - indeed, it only illustrates the rewrite tactic, but this is handy in an oral presentation setting to an audience with zero background in theorem proving.
I think this "proof" of Boyle's law is misleading. This lemma doesn't "prove" Boyle's law; it only proves that just_a_random_example
is true.
Yury G. Kudryashov (Jul 07 2023 at 04:08):
It proves that Boyles' law follows from the ideal gas equation. The docstring should clearly indicate that.
Bulhwi Cha (Jul 07 2023 at 04:18):
It still doesn't mention the definitions of the pressure and the volume of a confined ideal gas. Without these definitions
, variables such as P1
and V1
can't have physical meanings; they become nothing but real numbers.
Bulhwi Cha (Jul 07 2023 at 05:04):
I should also point out that @David⚛️'s formalization of the Darcy-Weisbach equation has the same problem. Where's the definition of force? Premises like h₃ : F = f₁ * P * L * U^2
are not definitions. These formalizations are all underspecifications!
Tomas Skrivan said:
I'm looking forward to seeing a refactored version where it is clear what are the assumptions, definitions and empirical facts!
Shreyas Srinivas (Jul 07 2023 at 07:22):
I don't understand. In what sense is pressure or volume unspecified from a math formalisation PoV?
Shreyas Srinivas (Jul 07 2023 at 07:26):
as far as thermodynamics is concerned these are just some state variables right?
Scott Morrison (Jul 07 2023 at 07:35):
I remain pretty unclear what formalization of physics and/or chemistry is even meant to mean. Formalization of mathematical physics I think I do understand: e.g. you define symplectic manifolds "properly", and then add a paragraph to the doc-string that begins "Hamiltonian mechanics describes physical systems via a symplectic manifold ..."
Scott Morrison (Jul 07 2023 at 07:37):
Or e.g. my formalisation of the CHSH inequalities file#Algebra/Star/CHSH. It is a fact about ordered *-algebras, and then the "physics" that is not just maths all belongs in doc-strings.
Scott Morrison (Jul 07 2023 at 07:44):
I mean, there is lots of serious physics that is not formalizable because we don't understand the mathematics underlying it clearly enough yet, but I don't think this part of physics is relevant to the discussion here.
Shreyas Srinivas (Jul 07 2023 at 09:34):
I do wonder if we can have a formalization of units in lean (more specifically dimensionality analysis of an expression). I know types play a role in CS not entirely unlike units in a physics in the sense that if the types of objects don't match up then you can't perform operations on them. But units are a little more complicated than that. For each unit, you also have its inverse (second and second^{-1} I.e. hertz) further you have cancellation laws that allow you to multiply a speed object (with units m/s) with a time object (of unit s) to give a distance object (unit m)
Shreyas Srinivas (Jul 07 2023 at 09:40):
Basically such a type checking would not allow addition of two quantities of different units. But at the same time it could deduce the units of a product of quantities and allow for inverses, and require that equality only work for quantities of the same unit.
Shreyas Srinivas (Jul 07 2023 at 09:48):
To this extent a math formalization of physics would also exclude malformed equations.
Eric Wieser (Jul 07 2023 at 09:57):
There are already threads about dimensional analysis elsewhere
Bulhwi Cha (Jul 07 2023 at 11:01):
Shreyas Srinivas said:
I don't understand. In what sense is pressure or volume unspecified from a math formalisation PoV?
I'll give you an example. I think it's still an underspecification, but this is the best I can do at the moment.
Let be a gas, whatever that means. We specify the motion of the on the time interval as follows:
- is the number of the particles that make up the gas .
- is the motion of the gas on the time interval .
- is the motion of the -th particle of the gas on the time interval . It has a continuous first derivative.
- is the position of the -th particle of the gas at time .
We specify the volume of the gas as follows:
- is the bottom base of the right circular cylinder .
- is the side of the cylinder .
- is the height of the surface on the time interval . It has a continuous first derivative.
- is the top base of the control surface on the time interval .
- is the side of the control surface on the time interval .
- is the control surface of the gas on the time interval .
- is the control region of the gas on the time interval . Its boundary is the control surface .
- is the volume of the gas on the time interval .
Bulhwi Cha (Jul 07 2023 at 11:10):
Let be the height of each point in the surface on the time interval . Assume has a continuous first derivative for all .
We now specify , the motion of the control surface on the time interval . For all and , the following holds:
I'll specify later the pressure applied to the surface by the gas on the time interval . Please tell me if you find something wrong.
boyles_law.jpg pressure_and_volume.jpg
Scott Morrison (Jul 07 2023 at 11:34):
Why are you talking about all these particular surfaces? There's no cylinder in Boyle's law!
Bulhwi Cha (Jul 07 2023 at 11:35):
Shreyas Srinivas said:
I don't understand. In what sense is pressure or volume unspecified from a math formalisation PoV?
But there's a closed system that contains an ideal gas in Boyle's law. I'm only giving an example of specifying the pressure and volume of a gas.
Scott Morrison (Jul 07 2023 at 11:37):
But then you're not giving Boyle's law --- you're giving an example.
Bulhwi Cha (Jul 07 2023 at 11:37):
I know, but that's the best thing I can do now. Hmm, maybe I should change the name of the image file.
Shreyas Srinivas (Jul 07 2023 at 11:47):
None of this is necessary for Boyle's law. For starters, as soon as you build a formalisation of gases as collections of particles, you are entering the realm of statistical mechanics. While the notion of ideal gas is often introduced as a collection of particles in a container that undergo random motion with perfectly elastic collisions everywhere, you don't need any of it to describe the theory of classical thermodynamics
Shreyas Srinivas (Jul 07 2023 at 11:48):
Secondly, as Scott points out you have a definition for a very specific container.
Shreyas Srinivas (Jul 07 2023 at 11:48):
As far as I recall my classical thermodynamics, the theory works perfectly well as long as you can assign values to the state variables and process variables, without ever looking under the hood.
Bulhwi Cha (Jul 07 2023 at 11:48):
Shreyas Srinivas said:
Secondly, as Scott points out you have a definition for a very specific container.
It's an example, not a definition. I can't come up with a definition at the moment.
Shreyas Srinivas (Jul 07 2023 at 11:51):
This is not to say that these state and process variables cannot be interpreted via statistical mechanics. Just that the macroscopic theory is perfectly fine without them.
Shreyas Srinivas (Jul 07 2023 at 11:52):
From the classical perspective, concepts like pressure, volume, and temperature are state variables that can be measured in some way. Nothing more.
Bulhwi Cha (Jul 07 2023 at 11:56):
I've never taken a class on statistical mechanics. Perhaps this was the reason I was unsatisfied with the classical explanation for gas laws.
Bulhwi Cha (Jul 07 2023 at 12:02):
Shreyas Srinivas said:
None of this is necessary for Boyle's law. For starters, as soon as you build a formalisation of gases as particles, you are entering the realm of statistical mechanics.
Statistical mechanics might be what I've been wanting to study and formalize.
Bulhwi Cha (Jul 07 2023 at 12:06):
(By the way, I also need to study undergraduate and graduate mathematics properly.)
Shreyas Srinivas (Jul 07 2023 at 12:45):
There is a small caveat with the ideal gas law: you don't entirely exclude the concept of particles. The n
in PV = nRT
typically refers to the number of moles of the gas in question. But beyond that none of the statistical definitions of P, V, or T are necessary for understanding laws about ideal gases.
Bulhwi Cha (Jul 07 2023 at 12:48):
Bulhwi Cha said:
I'll specify later the pressure applied to the surface by the gas on the time interval .
- is the pressure applied to the surface by the gas on the time interval .
- is the pressure applied to the surface by the -th particle of the gas on the time interval .
- is the pressure applied to the surface by the -th particle of the gas at time . It has continuous first partial derivatives.
- is the pressure applied to the point in the surface by the -th particle of the gas at time .
- is the net pressure applied to the surface by all particles of the gas on the time interval .
Edit: I changed and to and , respectively.
Shreyas Srinivas (Jul 07 2023 at 12:52):
Okay, another issue here : what does it mean for a particle to apply pressure on some surface. why the top surface (ideal gases exert the same pressure on all sides of their container).
Shreyas Srinivas (Jul 07 2023 at 12:57):
Pressure is a macroscopic quantity that is the cumulative effect of some fraction of the gas particles colliding against the walls of the container at any given time with some velocity distribution.
Yury G. Kudryashov (Jul 07 2023 at 13:02):
Again, there are two steps:
- We say that the state of an ideal gas has parameters satisfying , where is a constant. Then we deduce Boyle's law, define isothermic/adiabatic processes, prove Carnot's theorem etc. For this part, "pressure", "volume", "work" etc can be just names.
- We start with some model (e.g., a collection of particles interacting in some ways), then define pressure, volume, temperature. Then we prove that these quantities satisfy . This step is very nontrivial but it can be done separately. Also, there are a few open problems around...
Of course, docstrings should be improved to clearly differentiate between 2 steps.
Shreyas Srinivas (Jul 07 2023 at 13:09):
Yury G. Kudryashov said:
Again, there are two steps ...
Agreed, especially with point 2. In particular the following:
it can be done separately
When Charles or Boyle developed their laws, I am not sure statistical mechanics was even a thing yet.
Bulhwi Cha (Jul 07 2023 at 13:34):
Shreyas Srinivas said:
Okay, another issue here : what does it mean for a particle to apply pressure on some surface. why the top surface (ideal gases exert the same pressure on all sides of their container).
I wanted to write an equation about the normal force . The unit normal to the surface satisfies the following:
is the normal force exerted on the surface by the gas on the time interval .
For all , the following holds:
This equation and the definition of the net pressure will help you understand what it means "for a particle to apply pressure on some surface."
Bulhwi Cha (Jul 07 2023 at 13:56):
@Scott Morrison said:
But then you're not giving Boyle's law --- you're giving an example.
Let be the area of the surface and the (average) net pressure applied to the surface by all particles of the gas on the time interval . The gas obeys Boyle's law on the time interval if and only if the following holds:
Shreyas Srinivas (Jul 07 2023 at 14:02):
Bulhwi Cha said:
Shreyas Srinivas said:
Okay, another issue here : what does it mean for a particle to apply pressure on some surface. why the top surface (ideal gases exert the same pressure on all sides of their container).
Pressure is a macroscopic quantity that is the cumulative effect of some fraction of the gas particles colliding against the walls of the container at any given time with some velocity distribution.
I wanted to write an equation about the force . The unit normal to the surface is simple:
is the force exerted on the surface by the gas on the time interval .
For all , the following holds:
These definitions are not making sense anymore. In ideal gases, you assume that the particles make perfectly elastic instantaneous collisions, which causes an instantaneous change in the momentum. How are you getting a "force" out of this? How are you making the kind of continuity assumptions you would like to have for integrals. Secondly, you will almost certainly never get Boyle's law in that form, for the simple reason that at the microscopic level, the quantities you describe are all random variables. At best you might say that in expectation, the RV corresponding to pressure is constant under equilibrium conditions.
Shreyas Srinivas (Jul 07 2023 at 14:06):
Oh, and if you want to make predictions, then usually .
Shreyas Srinivas (Jul 07 2023 at 14:10):
I guess what I really want to say is that statistical mechanics is hard enough without trying to reinvent everything from scratch.
Bulhwi Cha (Jul 07 2023 at 14:19):
Shreyas Srinivas said:
These definitions are not making sense anymore. In ideal gases, you assume that the particles make perfectly elastic instantaneous collisions, which causes an instantaneous change in the momentum. How are you getting a "force" out of this? How are you making the kind of continuity assumptions you would like to have for integrals.
Can you first show me formalized definitions of a gas, a particle, a force, pressure, and volume? Maybe then I can figure out where I got those wrong.
Bulhwi Cha (Jul 07 2023 at 14:27):
Shreyas Srinivas said:
I guess what I really want to say is that statistical mechanics is hard enough without trying to reinvent everything from scratch.
Well, I didn't plan to spend the entire day writing the above messages. Also, I didn't reinvent anything.
Shreyas Srinivas (Jul 07 2023 at 14:40):
Bulhwi Cha said:
Can you first show me formal-mathematical definitions of gas, pressure, volume, and force?
These are physical concepts. Unless you fix your model, you don't have mathematical definitions for these quantities. Fixing a model usually involves making some choices about what you "know" about the systems you analyse. For instance, choosing some elementary variables that you can measure using an instruments that follow some accepted standard of measurement, and relations between them that you deduce empirically. Using this model you make predictions for the motion of various point particles, and real bodies that might work like point particles upto suitable approximation. For another example, in your undergrad mechanics lesson, you might start with a model of point particles with masses, positions, frames of reference, and a concept of time (in the newtonian sense) and then deduce newton's laws empirically. Or you are Lagrange and decide that everything obeys the stationary action principle w.r.t some suitably defined lagrangian, which you have to choose carefully for each system.
In the case of the study of gases, the basic concepts might be some of the variables you describe like pressure, temperature and volume ,which can be measured by instruments like a barometer, thermometer, or just gradations on a transparent vessel. If you are a late 18th century natural philosopher, you might know about some earlier versions of these measurements by observation or visiting your nearest workshop. You then want to get precise in quantifying these measurements. Then you conduct experiments, and based on the results you posit some laws (Charles' law, Boyle's law etc). Or you are Ludwig Boltzmann in the late 19th century, and all this work is already available to you, along with the notion that gases are composed of elementary particles moving randomly and colliding with each other and the walls of the container (Daniel Bernoulli). You want to work out how the random behaviour of these particles gives rise to the measurements that we observe in the form of pressure and temperature. So you invent statistical mechanics that tries to quantify these properties in terms of the ensemble behaviour of these randomly moving particles and you get another set of definitions for pressure and temperature.
Bulhwi Cha (Jul 07 2023 at 14:46):
Shreyas Srinivas said:
How are you getting a "force" out of this?
Okay, then what do you mean by this?
Shreyas Srinivas (Jul 07 2023 at 14:49):
When you model an ideal gas (as Bernoulli did), you make certain idealised assumptions. See this link which is the wikipedia page for the Kinetic theory of gases.
Shreyas Srinivas (Jul 07 2023 at 14:54):
In particular, collisions are instantaneous and perfectly elastic, and it goes without saying, newtons' laws apply for the newtonian definition of "force" which equates it to the rate of change of momentum. Suppose a particle is headed towards the wall of a container, upto the instant of collision, and then, immediately after the instant of collision it is headed the other way, what force was imparted by the wall to the particle?
Bulhwi Cha (Jul 07 2023 at 15:07):
Shreyas Srinivas said:
Suppose a particle is headed towards the wall of a container, upto the instant of collision, and then, immediately after the instant of collision it is headed the other way, what force was imparted by the wall to the particle?
We don't know what the direction and magnitude of that force were. But you can divide that force vector into a normal force and a frictional force, right? We can represent the normal force exerted by the particle on the surface with which it collided as a surface integral of the pressure applied to that surface by the particle.
Bulhwi Cha (Jul 07 2023 at 15:12):
Shreyas Srinivas said:
How are you making the kind of continuity assumptions you would like to have for integrals.
By looking at my engineering mathematics textbook?
Secondly, you will almost certainly never get Boyle's law in that form,
Okay, I just adapted the statement from https://github.com/ATOMSLab/LeanChemicalTheories/blob/cec46762a297f678d171e79a45899f139b437550/src/thermodynamics/basic.lean#L44C1-L44C109.
Shreyas Srinivas (Jul 07 2023 at 15:28):
That statement makes no reference to time instants
Bulhwi Cha (Jul 07 2023 at 15:32):
I said I adapted it from LeanChemicalTheories.
Bulhwi Cha (Jul 07 2023 at 15:45):
I modified a message: I added the word "normal" to the force and changed its notation to .
Edited message
Bolton Bailey (Jul 07 2023 at 16:15):
Shreyas Srinivas said:
When you model an ideal gas (as Bernoulli did), you make certain idealised assumptions. See this link which is the wikipedia page for the Kinetic theory of gases.
I wonder what assumptions derived from the kinetic theory are needed. Clearly we need something like isotropy, otherwise in a rectangular box with one direction longer than the other, the orientation of the particle's motion affects the pressure. Do we need an assumption about the distribution of the particles speeds as well, or is it ok to assume that particles have arbitrary speeds?
Bolton Bailey (Jul 07 2023 at 16:38):
Am I right in saying there will have to be some application of the divergence theorem? We have this in mathlib, right?
Bulhwi Cha (Jul 07 2023 at 22:58):
We have Mathlib.MeasureTheory.Integral.DivergenceTheorem.
Bulhwi Cha (Jul 07 2023 at 23:07):
@Bolton Bailey I need surface integrals of scalar-valued functions, surface integrals of vector fields, and triple integrals.
Bulhwi Cha (Jul 07 2023 at 23:41):
Bulhwi Cha said:
- is the net pressure applied to the surface by the gas on the time interval .
I removed . It's weird and we don't need it.
Tyler Josephson ⚛️ (Jul 08 2023 at 00:54):
Yury G. Kudryashov said:
Of course, docstrings should be improved to clearly differentiate between 2 steps.
Indeed, we can clean up the docstring that to clarifying that this is a proof that an ideal gas obeys Boyle’s Law. It shouldn’t be seen as a derivation of either the ideal gas law or Boyle’s Law.
Tyler Josephson ⚛️ (Jul 08 2023 at 01:22):
Scott Morrison said:
I remain pretty unclear what formalization of physics and/or chemistry is even meant to mean. Formalization of mathematical physics I think I do understand: e.g. you define symplectic manifolds "properly", and then add a paragraph to the doc-string that begins "Hamiltonian mechanics describes physical systems via a symplectic manifold ..."
From my perspective, it’s clarifying to recognize the gap between physical reality and the models we use to describe reality. For now, I only hope to be formalizing those models.
After all, what if I asked the question, “Is Boyle’s Law true, in reality?” The answer is quickly “no,” at least not all the time. It might be true of ideal gases, but non-ideal gases exist that violate Boyle’s Law. In fact, no gas is actually ideal, if you were to measure its properties with sufficient precision. The ideal gas law is a useful model that describes many gases quite well, and it’s an insightful model that helps us build many other useful models. Indeed, most practicing scientists and engineers care deeply about whether a theory is accurate - I love the BET theory of adsorption and we formalized it’s derivation in Lean, but a colleague asked me “why?” because “it’s not true” (meaning it assumes things that most physical systems don’t follow). It’s an elegant theory, but how closely do physical systems follow it?
I also make a distinction between formalizing and axiomatizing in science (I came up with this distinction on my own - if someone else in literature has done this before, there might be different language out there that I should probably use). Axiomatization is essentially Hilbert’s 6th Problem - how do we define the minimal set of axioms that can describe all of physical reality, and then prove it? Formalization sets aside the goal of defining the minimal set of axioms, and instead aims to precisely define the models scientists and engineers use and show how they logically arise from certain assumptions, as well as precisely demonstrate the relationships among different models / derivations.
In the latter view, I don’t need to start with molecules or even more fundamental microstates. I can start with a chemical reactor that’s defined as X and then prove that X has properties Y and Z. Or I might start with a cell or an ecosystem or a planetary system that’s defined as X and then prove that it has properties Y and Z. If one of these X’s leverages ideas from elsewhere in science (maybe my reactor has a mixture of ideal gases), then better to show those connections, but we don’t need to have the foundation fully set before we start writing proofs.
Bulhwi Cha (Jul 08 2023 at 09:26):
Perhaps we have somewhat different goals. I want to axiomatize physics and then formalize it. No luck so far.
Tyler Josephson ⚛️ (Jul 08 2023 at 12:32):
Definitely need to read the literature on this then. Search for Hilbert’s 6th Problem and you’ll be able to find how others have made progress on this (usually without proof assistants though)
Bulhwi Cha (Jul 08 2023 at 12:47):
@Tyler Josephson ⚛️ It'll take quite a long time. I want to read the literature and relevant textbooks, but I need to learn programming first to develop a video game.
Max Bobbin (Jul 10 2023 at 15:06):
Bulhwi Cha said:
Perhaps we have somewhat different goals. I want to axiomatize physics and then formalize it. No luck so far.
Just had time to read through all of this and add some thoughts:
On Boyles Law As was pointed out, we have a different "formalization" which is "more correct." here. I put this in air quotes because I can think of other ways to go about defining thermodynamics to arrive at Boyle's Law. However, the base question becomes how do we go about defining things? I answer my thoughts on this later.
On what formalization of science looks like
I think, regardless of our current goals now, a full team working on SciLib will be, at its heart, working towards Hilbert's Sixth problem. However, I don't think that solving Hilbert's Sixth problem will be done in a linear fashion. By this I mean, it will be impossible to start SciLib by guessing a set of Axioms and attempting to build science off of it. Instead, I think the better idea is to start at the end and work backward. This entails picking an aspect of the natural sciences, defining it in its most "useless" form, and then picking parts of it to define.
For example, the original Boyle's Law was, as you said, nothing impressive. It doesn't capture anything about science and was merely a proof of the relation between equations. However, by starting with such a simple theorem, we can work backward to a more general definition. We do this by picking a part of it and asking how to define it. We can pick pressure and ask how we should define pressure instead of just postulating it as a real number. Thermodynamics is an interesting example because we instantly get to a point where we have to figure out how to define natural phenomena. The new formalization of thermodynamics defines a structure
called thermo_system
which is defined as:
structure thermo_system (α) [nontrivial α]:=
(pressure : α → ℝ)
(volume : α → ℝ)
(temperature : α → ℝ)
(substance_amount : α → ℝ)
(internal_energy : α → ℝ)
The idea here is to define a system as a set of parameters that are functions from the states of the system to the real numbers. This works when we want to capture Boyle's Law, but it doesn't seem to be good enough for other applications. For one, this definition of pressure doesn't make reference to force or a surface the force acts on. Further, this definition seems hard to work with if we wanted to implement it for other applications, like the Navier-Stokes equation. To come upon a useful definition of pressure, it helps to try to define pressure for a couple different theorems in ways that work for each theorem and then try to generalize all those definitions into one definition.
Max Bobbin (Jul 10 2023 at 15:22):
Thermodynamics is a hard example to see this full plan because we instantly run into the headache of defining pressure, volume, temperature, etc. in a general way. Take, as an example, defining a CSTR with a first-order reaction. We could start with this:
theorem CSTR
--all the variables as real numbers
(hrec: r = k*C_A)
(mass_balance: accum = in-out+gen)
(hgen: gen = V*r)
(Haccum: accum = 0)
:
goal :=
the goal here isn't important. From this, we can pick a part of it and try to generalize it. My first thought would be the reaction rate. We could start by generalizing the rate constant as something like:
def rate_constant (A E R : ℝ) := λ T : ℝ, A*exp(-E*R/T)
Our next thought could be generalizing this definition further, by recognizing that there are different functions to model the temperature dependence of the rate constant. So, we want the rate constant to be defined as some function that takes in a temperature and outputs a real number. Instead, maybe the rate constant should be incorporated in the definition of the reaction rate:
def reaction_rate {n : N} (k : ℝ→ ℝ) (f : (fin n → ℝ) → ℝ) := λ (T : ℝ) (x : fin n → ℝ), k T * f x
Tomas Skrivan (Jul 13 2023 at 15:08):
Thermodynamical system is usually determined by a function for internal energy which is as a function of entropy, volume and substance amount(s). Entropy can be converted to temperature and volume can be transformed to pressure by Legendre transform. Therefore specifying pressure
and volume
seems to me redundant.
I would define thermodynamical system as:
structure thermo_system (α) :=
(volume : α → ℝ)
(entropy : α → ℝ)
(substance_amount : α → ℝ)
(internal_energy : α → ℝ)
(entVolSubMap : ℝ×ℝ×ℝ → α)
(consistent : LeftInverse entVolSubMap (fun a => (entropy a, volume a, substance_amount a))
∧
RightInverse entVolSubMap (fun a => (entropy a, volume a, substance_amount a)))
With this definition you can define pressure as:
def pressure (s : thermo_system α) (a : α) : ℝ :=
fun a => deriv (dV : ℝ) =>
s.internal_energy entVolSubMap (s.entropy a, s.volume a + dV, s.substance_amount a)
For example, this can be taken as a starting definition to formalize all the Maxwell's relations. You probably need some convexity and smoothness condition on internal_energy
though.
Eric Wieser (Jul 13 2023 at 15:15):
What do you envisage α
being here?
Eric Wieser (Jul 13 2023 at 15:18):
Is what you have equivalent to the following?
structure thermo_state :=
(volume : ℝ)
(entropy : ℝ)
(substance_amount : ℝ)
structure thermo_system :=
(internal_energy : thermo_state → ℝ)
def pressure (s : thermo_system) (a : thermo_state) : ℝ :=
deriv $ fun (dV : ℝ) => s.internal_energy {a with volume := a.volume + dV}
Tomas Skrivan (Jul 13 2023 at 15:21):
I'm assuming that you parameterize it over a general type α
for additional flexibility.
Maybe the definition should be a little bit more complicated to render this parametrization useful. The type α
is a general state which admits decomposition α ≅ ℝ×ℝ×β
which is entropy, volume and anything extra like amounts of substances. You want to allow for arbitrary number of different substances.
Tomas Skrivan (Jul 13 2023 at 15:22):
But you are right that it might be unnecessarily complicated. It might be better to define it as:
structure thermo_state (β : Type) :=
(volume : ℝ)
(entropy : ℝ)
(extra_state : β)
structure thermo_system (β : Type) :=
(internal_energy : thermo_state β → ℝ)
Notification Bot (Jul 14 2023 at 21:10):
6 messages were moved from this topic to #Natural sciences > Bernoulli's Principle by Tyler Josephson ⚛️.
Tyler Josephson ⚛️ (Jul 15 2023 at 21:01):
I initially thought internal energy would be as relevant as V and S, but I’ve been looking into some informal efforts to formalize thermodynamics, and finding that perhaps they would be stratified like @Tomas Skrivan is suggesting. But if we really want to dig deep into the foundations (rather than build engineering-relevant proofs right away), I think this might be a good place to start: https://arxiv.org/abs/cond-mat/9708200. The literature review alone is perspective-shaping - there are many (dozens) of formalization attempts with nuanced differences and limitations.
Tyler Josephson ⚛️ (Jul 15 2023 at 21:03):
Section VII summarizes the 15 axioms required.
Last updated: Dec 20 2023 at 11:08 UTC