The anion gap was too complicated, so we’re computing the Hessian of the electroneutrality equation to prove acid-base physiology is componentwise-linear

The anion gap annoys me. Working through the anion gap approach to acid base feels like reciting a series of incantations in a language I don’t understand, doing a ritual dance in front of an alien god, and praying that at the end I’ll get to a number that my attending will think makes sense.

Why do we use this particular formula for the anion gap? Who came up with it? Why is the standard range what it is? Then there are all the adjuncts that people bolt onto this in order to justify it. Winters’ formula? Albumin correction? Delta gap? Delta ratio? Delta delta? Lactate adjustment? This is no way to live.

I wanted a way to think about acids, bases, anions, and cations that didn’t involve a series of cryptic additions of terms in a manner justified by the invocation of some name I was never going to remember. I wanted to start from first principle truths about how acids and bases and ions worked in the body, and mathematically derive an understanding of acid-base physiology from that.

Turns out I wasn’t the first person to think about this, so here is a slightly more principled approach to acid base, unfortunately named after a Canadian11. Stewart, if you want spoilers. There are a lot of places describing the Stewart approach to acid-base, but I didn’t see many that actually went through the algebra and the derivation. So here we are. I need to feel alive again so we’re taking partial derivatives until our eyes bleed..

Blood has anions and cations

Take your blood. It has cations – the most famous of which are , , , , and . It also has anions, the most famous of which is . However, these anions are a little more complicated in that you also have a bunch of weak acids floating around – the most prevalent of which are albumin and – which are sometimes anions, and sometimes not. We’ll take all the non-bicarb weak acids and lump ‘em all’ together as .

Let’s start by defining some of the variables we care about. Let:

where is also sometimes called the Strong Ion Difference, or SID – the difference between the anions and cations.

Then, looking at water and carbon dioxide, we let

Last, for our weak acids, which we’re conveniently globbing together as , we have
Thus far, this is all just notation. We’ve made no claims, we’ve just slapped letters on things to make our lives a bit easier down the line.

Acids and bases in blood are at equilibrium, mostly

We’ll now define some equilibria22. Undergrad chemistry strikes again!. Apologies in advance.

First, water dissociation33. This is how we get the pH:

Second, carbon dioxide hydration44. Connecting the pCO and bicarb, absorbing in the process an aqueous solubility coefficient which we will not deign to notate:

Third, bicarbonate dissociation55. Since bicarb can also act as an acid:

Fourth, weak acid dissociation66. Think albumin, phosphate, and all the other weak acids that doctors are too tired to list out:
which gives us77. Of note, we’re modeling these weak acids with 1 titratable ionization spot, but this isn’t actually the case. Albumin has tons of histidine residues that do the hokey pokey, and phosphate has generally 1-2 hydrogen ions it can shed in a pinch. However, this makes doing the math by hand a bit more difficult. The simplification here makes notation easy, but in principle you could play this game with the full setup.

The principle of electroneutrality

This is the secret sauce. In situations of e.g. metabolic or respiratory acidosis, what we observe are changes in the distributions of anions and cations. But, no matter what, the total charge of anions and total charge of cations has to be – you can’t be wandering around with a net positive charge in your blood, else we’d all be little88. Or very big, depending on how you think about things – we probably wouldn’t have very good energy efficiency batteries. In equation form:

In this equation is your strong cations minus your strong anions, and is all of your weak anions. Strong anions plus weak anions has to equal strong cations.

There are technically some weak cations, in the sense that and are partially ionized at physiologic pH, but given their relatively small concentration compared to we can pretty reasonably ignore this99. Though with the magic of computers, we don’t have to! More on that down below..

Solving our earlier equations for the variables in the electroneutrality equations gives us

For , we have to do a bit more gymnastics:

Let’s throw this all back into the electroneutrality equation:

Expanding this minor monstrosity out, grouping terms, and calling this a function gives you1010. I promise I worked this out once on the back of a patient list:
where the parameters of the function are the pH, SID, pCO, and total weak acid. Importantly, for physiologically valid sets of 1111. More or less, where they are all greater than 0 and .

Then, solving for gives you the pH of the system (blood/plasma) as a function of the strong ion difference, pCO, and total weak acids.

This approach was developed by Canadian physiologist Peter Stewart, who hallucinated this algebraic torture in the early 1980s. The idea is to focus on 3 independent variables: the difference between strong cations and anions (strong ion difference), the pCO, and the total weak acid amount (albumin and phosphate, mostly).

The strategic stacked bar chart reserve

Importantly, look at what we aren’t directly using as a variable that affects the pH – the bicarbonate. Under this approach, the bicarb is actually a result of all of the other stuff – the strong ion difference, the pCO, and the other weak acids. The value of the bicarb is just whatever it needs to be for the whole system to play nice – it’s the dependent variable, not the independent one1212. You can also see this from the fact that the bicarb is directly computable from these parameters as .. In other words, bicarb and pH are linked by an equilibrium – and if we think of pH as the dependent variable, the result of a bunch of other processes (which we do) – then why should bicarb be any different?

You may be wondering why anyone would want to use this approach. Beyond the fact that it can make one feel smart1313. Don’t underestimate this and that it gives you a certain condescension budget which you can spend liberally on rounds1414. So long as you avoid depleting the strategic parentheses reserve, that would get the LISPers mad, it can help in a few particular scenarios where it is more useful to think about anion-cation balance than acid-base status:

  1. You don’t have to deal with an empiric formula derived from who knows where1515. Someone probably knows from where to figure out what to do with albumin or how to correct for it. Less albumin = less weak acid, which directly leads to higher bicarb to fill in the gap.
  2. Contraction alkaloses become a lot simpler – you give someone truckloads of furosemide, you lose a proportionally larger amount of chloride than sodium1616. The NKCC channels inhibited by loop diuretics move 2 chlorides for 1 sodium and 1 potassium, bicarb expands to fill in the gap and maintain electroneutrality.
  3. Giving someone a large amount of normal saline induces a hyperchloremic acidosis – you give them more chloride than is present in serum, so chloride goes up, so bicarb drops/gets squeezed out to keep things neutral.

We can visualize this acid/base balance using a Gamblegram1717. Named after physiologist James Gamble, who will hopefully become the topic of a future blog post, which maps out anions and cations on a pair of stacked bar charts:

Gamblegram
Example Gamblegram with some annotations, taken from here

The idea here is that instead of computing a series of quantities and looking at what fits in what arbitrary reference range, you can directly examine the anion-cation balance and see what’s out of whack. Are there a bunch of anions – for example, lactate or -hydroxybutyrate – that are squeezing out the bicarb? Is the chloride way too low since we over-diuresed someone, and bicarb had to expand to fill in the gap? Is there zero albumin, and so something’s gotta make up the difference? Did we flood someone with normal saline, send their chloride flying up to the sky, and then the bicarb had to go run away because there was no more space in the Gamblegram?

This turns mysterious acid-base problems with various formulae and corrections into very concrete (and simple) questions about the balance between anions and cations – and, to me, this is a much easier frame to reason about. Anions minus cations equals zero. Everything else is just bonus.

If you want to be able to build a lil Gamblegram on the fly at the bedside there are a number of apps and websites that do it. For much of my intern year I used https://medischesnippers.nl/stewart/, and then I built https://axmukund.github.io/stewart/ when UCSF briefly forgot to rate-limit the enterprise OpenAI account they gave us. They didn’t forget for very long.

The physicochemical calculator on my page does some fancy stuff to estimate ionized magnesium and calcium, uses per-residue models of albumin protonation and a full triprotic approximation of phosphate ionization, and lets you do fun things like use the BMP bicarb for the Gamblegram instead of using the inferred bicarb off a blood gas. But enough about that.

All this said, clinically speaking, the debate between the traditional approach – base excess, anion gap – and the physicochemical approach is largely academic. Assuming you work through all the relevant steps appropriately, you will get to the correct conclusion with either approach. However, only one has “intoxicating mathematical integrity”.

Derivatives of the Stewart model

Ha, no, not those derivatives1818. Though don’t worry, Figge/Fencl/Story will get their own time in the limelight. We now have a function . We write as before:

The Jacobian

The Jacobian can be written as:

where
and
We then work with the implicit function after assuming (not unreasonably) . By the implicit function theorem1919. Here, the idea being that and so on and so forth, we have:
where , which is too unwieldy to fully expand each time.

Off the bat, this gives you a) that raising the albumin and/or pCO drops the ph (); b) that raising the strong ion difference increases the pH (); and c) the effect of these changes changes as the pH changes.

Additionally, because these first order partial derivatives never change their sign2020. assuming and does not change sign, which is true in physiological regimes, the effects of the perturbations won’t flip about. As you increase the SID, the pH won’t start to go up and then all of a sudden start going down – effects are directionally stable.

The Hessian

The entries of the Hessian matrix are defined as 2121. It’s worth noting that because , – this is from Clairaut’s theorem/Schwarz’s theorem. Let’s write them out2222. This was easily my least favorite part of linear algebra. I hate doing this kind of accounting. I’m no good at it. I hate it.:

If you squint, you’ll note that all the other entries of the Hessian are zero, since the other first order partial derivatives solely depend on . Mixed second derivatives with respect to the other variables are since is independently linear2323. more specifically, affine-linear, but we’ll get to that in a second in .

So if you hold and constant, is linear in . But, the coefficients of with respect to are actually affected by and , because of nonlinearity that enters through . Let’s take, for example:

Even though , depends on ( is affected by pCO) and depends on . This is to say, all of the variables we see are coupled through , which means that is not strictly linear in . So, the effects of the SID, pCO, and weak acids are not strictly independent, though they can be thought of as locally linear if the pH doesn’t change too much2424. In practice, because of things like renal compensation, intracellular shifts, nonlinear protein buffering with e.g. albumin, there is actually some additional nonlinearity in the system. However, the system is “close enough” to linear within small neighborhoods that this approximation method is more or less on the money..

Stated alternately, the net effect we see with small perturbations can be reasonably well-approximated by the sum of the individual effects of the pCO, the weak acids, and the strong ion difference. More formally, the system permits a relatively accurate first-order Taylor approximation that decomposes acid-base disturbances into separable effects of the SID, the amount of weak acid, and the respiratory/pCO component.

TL;DR

Check this lil calculator out