Introduction

Weak acids are important physical systems of interest in chemistry, biochemistry, chemical engineering, and physiology. A weak acid is a substance that undergone partial protolysis in water to produce undissociated acid molecules, hydronium ions, \({\textrm{H}_{3}\textrm{O}^{+}}\), and the acid conjugate base. An aqueous weak acid buffer solution is formed by a weak acid and one, or several, of its soluble salts. The equilibrium of a weak acid, or a weak acid buffer, involves four chemical substances and four equations: the dissociation of the acid, the autoionization of water, and the balances of charge and matter. In principle it is possible to obtain the equilibrium concentrations of all the chemical species for the weak acid dissociation or the buffer solution by solving these systems of equations. In practice, these systems of equations involve nonlinear terms making it difficult to obtain exact mathematical expressions for the concentrations. The algebraic manipulation of the systems of equations for the weak acid dissociation or the buffer solution give cubic equations for the concentration of \({\textrm{H}_{3}\textrm{O}^{+}}\) [1,2,3]. The equilibrium concentration of \({\textrm{H}_{3}\textrm{O}^{+}}\) is obtained by finding the roots of these cubic equations. Although there exists a cubic formula that gives the explicit roots of a cubic equation, it is not practical to use because of its complexity [4,5,6]. The crude use of the cubic formula requires more than 30 arithmetic operations, making its use for hand calculation impractical [6,7,8]. Macleod and Barling [6, 9, 10] have already reported mathematical formulas for the pH of weak acid solutions. Although Macleod’s [9] expressions are exact, they show numerical rounding errors, so the Newton–Raphson numerical method is used to calculate the pH. Numerical difficulties with the pH formulas have been observed also in titration models of weak acids [11]. In this work exact simplified formulas for the pH of a weak acid and its buffer are shown and evaluated without numerical rounding errors.

A quadratic equation is obtained for the hydronium ion if the autoionization of water is ignored. Under this approximation, the equilibrium concentration of the \({\textrm{H}_{3}\textrm{O}^{+}}\) is obtained simply by solving a quadratic equation. The approximation of ignoring water autoionization displays a relative error greater than 10% for weak acids with \(K_\textrm{a}<10^{-6}\), and at low analytical concentrations of the acid or the salt of the acid, \(C_\textrm{a,s}<10^{-6}\,\textrm{M}\), with \({1\,\textrm{M}=1\,\mathrm {mol\,L^{-1}}}\). Although the concentrations used in the general chemistry laboratory are generally above \(10^{-2}\,\textrm{M}\), there may be situations in chemical analysis where very low concentrations are handled [1, 3, 7, 8].

General purpose computer algebra systems (CAS) allow the algebraic manipulation of equations and inequalities [12]. The use of CAS in mathematical software, with user-friendly graphical interfaces, has extended the use of CAS to all fields of knowledge. Examples of free and non-free CAS are Maple [13], Wolfram Mathematica [14], Maxima [15], and SageMath [16]. Today mathematical software with CAS capability is easily found in research and academic laboratories and classrooms. Complex problems that were considered beyond the scope of the researchers or students can be solved today on the computer by using CAS mathematical software. The mathematical solution of the aqueous dissociation of weak acids or buffer solutions requires functions available in mathematical software. These functions are mainly (i) the simplification and algebraic manipulations of large equations, and inequalities, and (ii) the use of complex analysis, and graphical representation of functions, inequalities, and implicit regions. In this work, Wolfram Mathematica is employed to obtain simplified closed-form expressions for the equilibrium concentrations of the chemical species of four aqueous systems: the weak acid dissociation and its titration by a strong base, the buffer solution and its titration by a strong base [1,2,3, 17]. The cubic equations for the hydronium ion are analyzed, their roots are obtained by the use of the classical Cardano’s method for the associated depressed cubic equations [18, 19]. The direct results of Cardano’s method are the cube roots of two complex numbers. The polar representation of these cube roots allows one to obtain only three real roots. These roots are simplified and reduced to closed-form expressions that are simple enough to allow exact pH calculations with only a handheld scientific calculator. The use of Descartes’ rule of signs [18,19,20] allows one to demonstrate that only one root is positive. The pH stability is measured as the change of the pH as the strong base is added. Finally, a general equation for the concentration of \({\textrm{H}_{3}\textrm{O}^{+}}\) is presented. This general equation gives the pH for any of the four systems studied in this work in terms of an effective acid constant and an effective acid concentration.

Theory and methods

General equation for the concentration of \({[{\hbox {H}}_{3}{\hbox {O}}^{+}]}\)

The aqueous dissociation equilibrium of a weak acid \(\hbox {HB}\) is given by the chemical equations

$$\begin{aligned} \hbox {HB} + \hbox {H}_2\hbox {O}&\leftrightarrows \hbox {H}_{3}\hbox {O}^{+} + \hbox {B}^{-}, \end{aligned}$$
(1)
$$\begin{aligned} 2 \hbox {H}_{2}\hbox {O}&\leftrightarrows \hbox {H}_{3}\hbox {O}^{+} + \hbox {OH}^{-}. \end{aligned}$$
(2)

These equilibria are altered by the addition of a salt \(\hbox {NaB}\) or the addition of a strong base, e.g., \(\hbox {NaOH}\). The salt and the strong base dissociate completely in water to produce the ions \({\hbox {Na}^{+}}\), \({\hbox {B}^{-}}\), and \({\hbox {OH}^{-}}\), through the reactions

$$\begin{aligned} \hbox {NaB}&{\mathop {\rightarrow }\limits ^{\mathrm {H_2O}}} \hbox {Na}^{+} + \hbox {B}^{-},\end{aligned}$$
(3)
$$\begin{aligned} \hbox {NaOH}&{\mathop {\rightarrow }\limits ^{\mathrm {H_2O}}} \hbox {Na}^{+} + \hbox {OH}^{-}. \end{aligned}$$
(4)

The addition of the salt forms a buffer solution meanwhile the addition of the strong base neutralizes the acidity of the solution. Relevant chemical species are \({\textrm{H}_{3}\textrm{O}^+}\), \({\hbox {OH}^{-}}\), \(\hbox {HB}\), \({\hbox {B}^{-}}\) , and \({\hbox {Na}^{+}}\), with molar concentrations \([\textrm{H}_{3}\textrm{O}^+]\), \({[\hbox {OH}^{-}]}\), \([\hbox {HB}]\), \({[\hbox {B}^{-}]}\) , and \({[\hbox {Na}^{+}]}\) respectively [1,2,3].

A solution of the acid \(\hbox {HB}\), the salt \(\hbox {NaB}\), and the strong base \(\hbox {NaOH}\), with concentrations \(C_\textrm{a}\), \(C_\textrm{s}\), and \(C_\textrm{b}\) , respectively, reaches chemical equilibrium. This equilibrium is quantitatively given by five equations [3]. These are the dissociation of the acid \(K_\textrm{a}\), the autoionization of water \(K_\textrm{w}\), the electric neutrality, the matter balance for the acid, and the matter balance for the strong base and salt added:

$$\begin{aligned} K_\textrm{a}&=\frac{{\left[ \textrm{H}_{3}\textrm{O}^+\right] }}{C^{\circ}}\frac{{[\hbox {B}^{-}]}}{C^{\circ}}\left( \frac{[\hbox {HB}]}{C^{\circ}}\right) ^{-1},\end{aligned}$$
(5)
$$\begin{aligned} K_\textrm{w}&=\frac{{\left[ \hbox {H}_{3}\hbox {O}^+\right] }}{C^{\circ} }\frac{{[\hbox {OH}^{-}]}}{C^{\circ}},\end{aligned}$$
(6)
$$\begin{aligned} {\left[ {\hbox {H}}_{3}{\hbox {O}}^+\right] } + \left[ \hbox {Na}^{+}\right]&={[\hbox {OH}^{-}]}+{[\hbox {B}^-]},\end{aligned}$$
(7)
$$\begin{aligned} C_\textrm{a}+C_\textrm{s}&=[\hbox {HB}] + {[\hbox {B}^-]},\end{aligned}$$
(8)
$$\begin{aligned} C_\textrm{b} + C_\textrm{s}&= {[\hbox {Na}^+]}. \end{aligned}$$
(9)

with \(C^{\circ} =1\,\textrm{M}\). Acid constants \(K_\textrm{a}\) are dimensionless, with values ranging typically between \(10^{-10}\) and \(10^{-1}\). It is mathematically convenient to define the variables \({x={[\hbox {H}_{3}\hbox {O}^+]}/(C^{\circ} \sqrt{K_\textrm{w}})},\) \({y={[\hbox {OH}^-]}/(C^{\circ} \sqrt{K_\textrm{w}})},\) \({z_0=[\hbox {HB}]/(C^{\circ} \sqrt{K_\textrm{w}})},\) \({z_1={[\hbox {B}^-]}/(C^{\circ} \sqrt{K_\textrm{w}})},\) \({s={[\hbox {Na}^+]/(C^{\circ} \sqrt{K_\textrm{w}})}}\) and the dimensionless constants \({c_{\textrm{a}}=C_\textrm{a}/\sqrt{K_\textrm{w}}}\), \({c_{\textrm{b}}=C_\textrm{b}/\sqrt{K_\textrm{w}}}\), \({c_{\textrm{s}}=C_\textrm{s}/\sqrt{K_\textrm{w}}}\), \({k_{\textrm{a}}=K_\textrm{a}/\sqrt{K_\textrm{w}}}\), and \({k_\textrm{w}=1}\). In terms of these dimensionless variables and constants, Eqs. (5)–(9) are replaced by

$$\begin{aligned} k_\textrm{a}&=\frac{x z_1}{z_0},\end{aligned}$$
(10)
$$\begin{aligned} x+{\bar{c}}_\textrm{b}&=\frac{1}{x}+z_1,\end{aligned}$$
(11)
$$\begin{aligned} {\bar{c}}_\textrm{a}&=z_0+z_1, \end{aligned}$$
(12)

with effective base and acid concentrations \({\bar{c}}_\textrm{b}=c_\textrm{b}+c_\textrm{s}\), and \({\bar{c}}_\textrm{a}=c_\textrm{a}+c_\textrm{s}\). These effective concentrations are constrained to \({\bar{c}}_\textrm{b}\ge 0\) and \({\bar{c}}_\textrm{a}\ge 0\).

The combined use of Eqs. (10) and (12) in Eq. (11) produces after some algebra

$$\begin{aligned} x^2+{\bar{c}}_\textrm{b} x-1=\frac{{\bar{c}}_\textrm{a} k_\textrm{a}x}{x+k_\textrm{a}}, \end{aligned}$$
(13)

which can be conveniently rewritten as

$$\begin{aligned} \left( x-\sigma _1\right) \left( x-\sigma _2\right) \left( x+k_\textrm{a}\right) ={\bar{c}}_\textrm{a}k_\textrm{a}x, \end{aligned}$$
(14)

where \(\sigma _{1,2}=\tfrac{1}{2}\left( -{\bar{c}}_\textrm{b}\pm \sqrt{{\bar{c}}_\textrm{b}^2+4}\right)\), with \(\sigma _1\ge 1\), \(\sigma _2\le -1\), \(\sigma _1 \sigma _2=-1\), and \(\sigma _1+\sigma _2=-{\bar{c}}_\textrm{b}\).

Expansion of Eq. (13) gives the cubic equation \(P=0\), with

$$\begin{aligned} P=x^3+c_2 x^2+c_1 x + c_0, \end{aligned}$$
(15)

and coefficients

$$\begin{aligned} c_3&= 1,\end{aligned}$$
(16)
$$\begin{aligned} c_2&= k_\textrm{a}+{\bar{c}}_\textrm{b},\end{aligned}$$
(17)
$$\begin{aligned} c_1&= -1+k_\textrm{a}\left( {\bar{c}}_\textrm{b}-{\bar{c}}_\textrm{a}\right) ,\end{aligned}$$
(18)
$$\begin{aligned} c_0&= -k_\textrm{a}. \end{aligned}$$
(19)

The 4-tuple of coefficients of P \({{{\,\textrm{coef}\,}}{\left[ P\right] }=\left( c_3,c_2,c_1,c_0\right) }\) gives important information about the roots of the equation \(P=0\). The signs of the \({{\,\textrm{coef}\,}}[P]\) give the 4-tuple

$$\begin{aligned} \begin{aligned} {{\,\textrm{sgn}\,}}\left( {{\,\textrm{coef}\,}}[P]\right)&=\left({{\,\textrm{sgn}\,}}{c_3},{{\,\textrm{sgn}\,}}{c_2},{{\,\textrm{sgn}\,}}{c_1},{{\,\textrm{sgn}\,}}{c_0}\right) \\&=\left( +,+,\pm ,-\right) . \end{aligned} \end{aligned}$$
(20)

Regardless of the value of \({{\,\textrm{sgn}\,}}{c_1}\), this 4-tuple shows only one change of sign, from positive to negative. Descartes’ rule of signs states that the number of positive roots of a polynomial is, at most, equal to the number of sign changes of its ordered list of coefficients [20]. The use of Descartes’s rule indicates that \(P=0\) has only one positive root, no matter what system is dealt with—an acid solution, a buffer solution, or the neutralization of any of these solutions.

The full characterization of the roots of \(P=0\) is given by the discriminant of the polynomial (15), \(\Delta [P]\) [18, 19, 21]. The case of \(\Delta [P]>0\) indicates that the three roots of \({P=0}\) are all real and different. In the case \(\Delta [P]<0\), one of the roots is real and the other two roots are complex, which are a complex conjugate pair. The case \(\Delta [P]=0\) indicates multiple roots. Although the mathematical expression of \(\Delta [P]\) is complicated, the use of the function \(\textsf {FullSimplify}\) of Wolfram Mathematica shows that \(\Delta [P]>0\) under the assumptions \({\bar{c}}_\textrm{a}>0\), \({\bar{c}}_\textrm{b}\ge 0\), and \(k_\textrm{a}>0\).

In the supporting information it is shown that \(\rho _3\), the positive root of \(P=0\), is given by

$$\begin{aligned} \rho =2\sqrt[3]{\Vert \zeta \Vert }\cos{\left( {\theta }/{3}\right) -\frac{k_\textrm{a}+{\bar{c}}_\textrm{b}}{3}}, \end{aligned}$$
(21)

with

$$\begin{aligned} \root 3 \of {\Vert \zeta \Vert }&=\tfrac{1}{3}\sqrt{\left( k_\textrm{a}+{\bar{c}}_\textrm{b}\right) ^2+3k_\textrm{a}\left( {\bar{c}}_\textrm{a}-{\bar{c}}_\textrm{b}\right) +3},\end{aligned}$$
(22)
$$\begin{aligned} \theta&=\arctan {\left( -\frac{q}{2},\frac{\Delta [P]}{6\sqrt{3}}\right) },\end{aligned}$$
(23)
$$\begin{aligned} \Delta [P]&=-4p^3-27q^2,\end{aligned}$$
(24)
$$\begin{aligned} p&=-\tfrac{1}{3}\left( k_\textrm{a}+{\bar{c}}_\textrm{b}\right) ^2-k_\textrm{a}\left( {\bar{c}}_\textrm{a}-{\bar{c}}_\textrm{b}\right) -1,\end{aligned}$$
(25)
$$\begin{aligned} q&=\tfrac{2}{27}\left( k_\textrm{a}+{\bar{c}}_\textrm{b}\right) ^3+\frac{k_\textrm{a}}{3}\left( k_\textrm{a}+{\bar{c}}_\textrm{b}\right) \left( {\bar{c}}_\textrm{a}-{\bar{c}}_\textrm{b}\right) +\frac{{\bar{c}}_\textrm{b}-2k_\textrm{a}}{3}. \end{aligned}$$
(26)

The angle \(\theta\) given in Eq. (23) is restricted to \(\theta \in (0,\pi )\). The function \(\arctan (x,y)\) used in the definition of \(\theta\) gives the arc tangent of y/x taking into account which quadrant the point (xy) is in. This angle \(\theta\) is related to the trigonometric solution obtained by Nickalls for the roots of the cubic equation [22].

The general Eq. (21) gives the concentration \({{[\textrm{H}_{3}\textrm{O}^+]}=10^{-7} \rho }\), and an approximation to the pH,

$$\begin{aligned} \begin{aligned} \textrm{pH}&=-\log _{10}{a_{{\textrm{H}_{3}\textrm{O}^+}}}\\&\approx -\log _{10}{\frac{{\left[ \textrm{H}_{3}\textrm{O}^+\right] }}{C^{\circ} }}\\&=7-\log _{10}{\rho }, \end{aligned} \end{aligned}$$
(27)

with \(a_{{\textrm{H}_{3}\textrm{O}^+}}\) as the activity of the \({\textrm{H}_{3}\textrm{O}^+}\) ion.

Weak acid

The case of a weak acid is described by using \({\bar{c}}_\textrm{a}=c_\textrm{a}\) and \({\bar{c}}_\textrm{b}=0\) in Eq. (21),

$$\begin{aligned} \rho =\tfrac{2}{3}\sqrt{k_\textrm{a}^2+3c_\textrm{a}k_\textrm{a}+3}\cos {\left( \theta /3\right) }-\tfrac{k_\textrm{a}}{3}, \end{aligned}$$
(28)

with

$$\begin{aligned} \theta =\arctan {\left( -\frac{q}{2},\frac{\sqrt{\Delta [P]}}{6\sqrt{3}}\right) }, \end{aligned}$$
(29)

\(\Delta [P]=-4p^3-27q^2\), and

$$\begin{aligned} p&=-\frac{k_\textrm{a}^2}{3}-c_\textrm{a} k_\textrm{a}-1,\end{aligned}$$
(30)
$$\begin{aligned} q&=\frac{2k_\textrm{a}^3}{27}+\frac{c_\textrm{a}k_\textrm{a}^2}{3}-\frac{2k_\textrm{a}}{3}. \end{aligned}$$
(31)

The coefficient p is evidently negative, meanwhile q can have positive or negative values. Algebraic manipulation on the inequality \(q<0\) gives \(k_\textrm{a}^2+\tfrac{9}{2}c_\textrm{a}k_\textrm{a}-9<0\), which can be rearranged to obtain \(c_\textrm{a}<\frac{2}{9k_\textrm{a}}(k_\textrm{a}^2-9)\). The last inequality implies that negative values of q are obtained with \(k_\textrm{a}<3\), and \({c_\textrm{a}<\frac{2}{9k_\textrm{a}}\left( 9-k_\textrm{a}^2\right) }\). Very weak acids, e.g., HCN (\(k_\textrm{a}=6.2\times 10^{-3}\)) or HOCl (\(k_\textrm{a}=0.4\)), would have negative q at micromolar concentrations.

The limit of infinite dilution of \(\theta\) gives

$$\begin{aligned} \lim _{c_\textrm{a}\rightarrow 0}{\theta }=\arctan {\left( k_\textrm{a}\left( 9 -k_\textrm{a}^2\right) ,\sqrt{27}\left| k_\textrm{a}^2-1\right| \right) }. \end{aligned}$$
(32)

Figure 1 displays this limit as a function of pKa for different weak acids. In this limit of infinite dilution, \(\lim _{c_\textrm{a}\rightarrow 0}{\rho }=1\). The left and right extremes of the \(\theta\) curve shown in Fig. 1 display the infinite dilution of \(\theta\) for the case of \({\textrm{H}_{3}\textrm{O}^+}\) and \({\textrm{H}_2\textrm{O}}\) , respectively. Weak acids with higher (lower) dissociation constants are located on the left (right) of the figure. The dashed line is given by acids with \(1\le k_\textrm{a}\le 3\). The value \(k_\textrm{a}=1\) gives \(\Delta [P]=0\) and \(q<0\), hence \(\theta =0\) and \(\rho =1\). This case gives one simple root and a double root for \(P=0\). It can be shown that the simple root is \(\rho =1\), and the double root is \(\rho =-1\). The particular case of a triple root is impossible since the triple root condition \({k_\textrm{a}^2=-3(1+c_\textrm{a}k_\textrm{a})}\) cannot be fulfilled with a real \(k_\textrm{a}\). On the other hand, the value \(k_\textrm{a}=3\) produces \(q=0\) and \(\Delta [P]>0\), hence \(\theta =\pi /2\) and \(\rho =1\).

Fig. 1
figure 1

Angle \(\theta\) at infinite dilution as a function of the pKa. The dashed line gives \(\theta\) for weak acids with \(1\le k_\textrm{a}\le 3\). As the concentration of the acid increases, the value of θ tends to \(\pi /2\)

As the concentration \(c_\textrm{a}\) is increased, the angle \(\theta\) tends to \(\theta =\pi /2\) for all the acids, regardless of its p\(K_\textrm{a}\). The angle \(\theta\) displays a maximum as a function of \(c_\textrm{a}\). This maximum is obtained from the condition \({\partial \theta }/{\partial c_\textrm{a}}=0\), which can be shown to give \(c_\textrm{a}={8}/{k_\textrm{a}}\).

The concentration \({[\textrm{H}_{3}\textrm{O}^+]}\) is given by \({[\textrm{H}_{3}\textrm{O}^+]}=\sqrt{K_\textrm{w}}\rho\), and the pH is

$$\begin{aligned} \begin{aligned} \textrm{pH}&\approx -\log _{10}{\frac{{[\textrm{H}_{3}\textrm{O}^+]}}{C^{\circ} }}\\&=7-\log _{10}{\rho }, \end{aligned} \end{aligned}$$
(33)

with \(C^{{\circ}}=1\,\textrm{M}\). The low concentration and weak acid pH limits are given by \(\lim _{c_\textrm{a}\rightarrow 0}{\textrm{pH}}=7\), and \({\lim _{k_\textrm{a}\rightarrow 0}{\textrm{pH}}=7}\). Equation (33) is useful to calculate the pH of a weak acid at low concentrations (1–10 μM). We calculate the pH of a diluted (\(C_\textrm{a}=5\,\mu \textrm{M}\)) aqueous solution of acetic acid, \(K_\textrm{a}=1.75\times 10^{-5}\), as an example of the use of these equations. The concentration and dissociation constants are given by \({c_\textrm{a}=5.\times 10^{-6}/10^{-7}=50}\), and \({k_\textrm{a}=1.75\times 10^{-5}/10^{-7}=175}\). The coefficients p and q are easily calculated by the use of Eq. (30) to obtain \(p=-18959.3\) and \(q=907291.\) From the values of p and q the discriminant \(\Delta [P]\) and \(\theta\) are given by \(\Delta [P]=-4p^3-27q^2\) and Eq. (29): \(\Delta [P]=5.03444\times 10^{12}\), and \(\theta =2.69738\,\)radians. Finally, Eq. (28) gives \(\rho =40.6076\), for which \(\textrm{pH}=5.3914\). The use of the function \(\textsf {NSolve}\) of Wolfram Mathematica for \(P=0\) gives \(\rho =40.6076\). Although the numerical solution is identical to the analytical solution, the former has a small imaginary part that must be removed to calculate the pH.

Weak acid titration by a strong base

A weak acid titration by a strong base requires one to make \({\bar{c}}_\textrm{a}=c_\textrm{a}\) and \({\bar{c}}_\textrm{b}=c_\textrm{b}\) in Eq. (21),

$$\begin{aligned} \rho =2\root 3 \of {\Vert \zeta \Vert }\cos {\left( \frac{\theta }{3}\right) -\frac{k_\textrm{a}+c_\textrm{b}}{3}}, \end{aligned}$$
(34)

with

$$\begin{aligned} \root 3 \of {\Vert \zeta \Vert }&=\tfrac{1}{3}\sqrt{\left( k_\textrm{a}+c_\textrm{b}\right) ^2+3k_\textrm{a}\left( c_\textrm{a}-c_\textrm{b}\right) +3},\end{aligned}$$
(35)
$$\begin{aligned} \theta&=\arctan {\left( -\frac{q}{2},\frac{\sqrt{\Delta [P]}}{6\sqrt{3}}\right) },\end{aligned}$$
(36)
$$\begin{aligned} \Delta [P]&=-4p^3-27q^2,\end{aligned}$$
(37)
$$\begin{aligned} p&=-\tfrac{1}{3}\left( k_\textrm{a}+c_\textrm{b}\right) ^2-k_\textrm{a}\left( c_\textrm{a}-c_\textrm{b}\right) -1,\end{aligned}$$
(38)
$$\begin{aligned} q&=\frac{2}{27}\left( k_\textrm{a}+c_\textrm{b}\right) ^3+\frac{k_\textrm{a}}{3}\left( k_\textrm{a}+c_\textrm{b}\right) \left( c_\textrm{a}-c_\textrm{b}\right) +\frac{c_\textrm{b}-2 k_\textrm{a}}{3}. \end{aligned}$$
(39)

The contours of \(\textrm{pH}=7-\log _{10}{\rho }\) as a function of \(C_\textrm{a}=\sqrt{K_\textrm{w}}c_\textrm{a}\) and \(C_\textrm{b}=\sqrt{K_\textrm{w}}c_\textrm{b}\) for acetic acid, \(k_\textrm{a}=180\), are shown in Fig. 2. It is interesting to note that there is a linear relationship between base and acid concentrations at constant \(\textrm{pH}\); in fact, the \({\textrm{pH}=7}\) line has a slope of 1 and passes through the origin \({(C_\textrm{a},C_\textrm{b})=(0,0)}\). Figure 2 also shows that the \(C_\textrm{b}\)-intercept is negative for acidic \(\textrm{pH}\) and positive for basic \(\textrm{pH}\). It is also seen in this figure that the slope of the lines \(C_\textrm{b}(C_\textrm{a})\) is less than 1 for acidic \(\textrm{pH}\).

Fig. 2
figure 2

Lines of constant \(\textrm{pH}\) on the \(C_\textrm{a}\)\(C_\textrm{b}\) plane for acetic acid and a strong base, at concentrations \(C_\textrm{a}\) and \(C_\textrm{b}\) , respectively

Buffer solution

The case of a buffer solution requires one to consider \({\bar{c}}_\textrm{a}=c_\textrm{a}+c_\textrm{s}\) and \({\bar{c}}_\textrm{b}=c_\textrm{b}+c_\textrm{s}\) in Eq. (21),

$$\begin{aligned} \rho =2\root 3 \of {\Vert \zeta \Vert }\cos {\left( \frac{\theta }{3}\right) -\frac{k_\textrm{a}+c_\textrm{b}+c_\textrm{s}}{3}}, \end{aligned}$$
(40)

with

$$\begin{aligned} \root 3 \of {\Vert \zeta \Vert }&=\tfrac{1}{3}\sqrt{\left( k_\textrm{a}+c_\textrm{b}+c_\textrm{s}\right) ^2+3k_\textrm{a}(c_\textrm{a}-c_\textrm{b})+3},\end{aligned}$$
(41)
$$\begin{aligned} \theta&=\arctan {\left( -\frac{q}{2},\frac{\Delta [P]}{6\sqrt{3}}\right) },\end{aligned}$$
(42)
$$\begin{aligned} \Delta [P]&=-4p^3-27q^2,\end{aligned}$$
(43)
$$\begin{aligned} p&=-\tfrac{1}{3}\left( k_\textrm{a}+c_\textrm{b}+c_\textrm{s}\right) ^2-k_\textrm{a}\left( c_\textrm{a}-c_\textrm{b}\right) -1,\end{aligned}$$
(44)
$$\begin{aligned} q&=\tfrac{2}{27}\left( k_\textrm{a}+c_\textrm{b}+c_\textrm{s}\right) ^3+\frac{k_\textrm{a}}{3}\left( k_\textrm{a}+c_\textrm{b}+c_\textrm{s}\right) \left( c_\textrm{a}-c_\textrm{b}\right) +\frac{c_\textrm{b}+c_\textrm{s}-2k_\textrm{a}}{3}. \end{aligned}$$
(45)

By applying the logarithm of the acid dissociation constant \(K_\textrm{a}\), Eq. (5), we obtain, after some algebraic manipulation, the Henderson–Hasselbalch (HH) equation [23,24,25]

$$\begin{aligned} \textrm{pH}=\textrm{p}K_\textrm{a}+\log _{10}{\frac{{[\hbox {B}^{-}]}}{[\hbox {HB}]}}. \end{aligned}$$
(46)

The right-hand side of this equation is a function of \(\textrm{pH}\) and therefore the HH equation is not practical for direct calculation of the pH. It is common to use the approximations \({[\hbox {B}^{-}]}\approx C_\textrm{s}\) and \([\hbox {HB}]\approx C_\textrm{a}\) to obtain

$$\begin{aligned} \textrm{pH}^{\mathrm {(1)}}\approx \textrm{p}K_\textrm{a}+\log _{10}{\frac{C_\textrm{s}}{C_\textrm{a}}}. \end{aligned}$$
(47)
Fig. 3
figure 3

Absolute error \(E^{\mathrm {(pH)}}\), in the \(\textrm{pH}\) calculated by the Herderson-Hasselbalch equation for a buffer solution of chlorous acid, \(K_\textrm{a}=1.2\times 10^{-2}\), as a function of the molar concentrations of the acid \(C_\textrm{a}\) and the salt \(C_\textrm{s}\)

Figure 3 shows the absolute error of the \(\textrm{pH}\), for chlorous acid, calculated by the HH equation with respect to the pH calculated using the exact formula, Eq. (40) with \(c_\textrm{b}=0\),

$$\begin{aligned} E^{\mathrm {(pH)}}=\textrm{pH}^{\mathrm {(1)}}-\left( 7-\log _{10}{\rho }\right) , \end{aligned}$$
(48)

with \(\rho\) given by Eq. (40). Figure 3 shows that small errors, \(E^\mathrm {(pH)}<0.1\), are obtained for buffer solutions with high concentration of the salt, \(C_\textrm{s}>0.1\,\textrm{M}\), meanwhile large errors, \(E^\mathrm {(pH)}>0.5\) are obtained for buffer solutions with \(C_\textrm{s}<0.01\,\textrm{M}\).

Buffer capacity

The pH stability of an acid buffer solution is measured by adding a volume \(V_\textrm{b}\) of a strong base solution with concentration \(c_\textrm{b}^0\) [3]. The addition of this volume changes the concentrations \(c_\textrm{a}\), \(c_\textrm{s}\), and \(c_\textrm{b}\),

$$\begin{aligned} c_{\textrm{a}}&=\frac{c_{\textrm{a}}^0 V_{\textrm{a}}^0}{V_{\textrm{ab}}^0+V_{\textrm{b}}},\end{aligned}$$
(49)
$$\begin{aligned} c_{\textrm{s}}&=\frac{c_\textrm{s}^0 V_{\textrm{s}}^0}{V_{\textrm{ab}}^0+V_{\textrm{b}}},\end{aligned}$$
(50)
$$\begin{aligned} c_{\textrm{b}}&=\frac{c_\textrm{b}^0 V_{\textrm{b}}}{V_{\textrm{ab}}^0+V_{\textrm{b}}}, \end{aligned}$$
(51)

with \(c_\textrm{a}^0\), \(c_\textrm{s}^0\), and \(c_\textrm{b}^0\), as the concentrations of the acid, salt of acid, and base independent solutions, respectively. The volumes \(V_\textrm{a}^0\), \(V_\textrm{s}^0\), and \(V_\textrm{ab}^0=V_\textrm{a}^0+V_\textrm{s}^0\) are the initial volumes of the acid, salt, and acid buffer solutions, respectively.

The pH stability, \(S_\textrm{pH}\), of a buffer solution is given by

$$\begin{aligned} \begin{aligned} S_{\textrm{pH}}&=\frac{\textrm{d}\left( \textrm{pH}\right) }{\textrm{d} V_\textrm{b}}\\&=\nabla _{{\varvec{c}}}(\textrm{pH})\cdot \frac{\textrm{d}{\varvec{c}}}{\textrm{d} V_\textrm{b}}, \end{aligned} \end{aligned}$$
(52)

with \({\varvec{c}}=\left( {c_\textrm{a}},{c_\textrm{s}},{c_\textrm{b}}\right)\) as 3-vector of concentrations, and the gradient of \(\rho\), \(\nabla _{{\varvec{c}}}\rho\), given by

$$\begin{aligned} \nabla _{{\varvec{c}}}\rho =\left( \frac{\partial \rho }{\partial c_\textrm{a}},\frac{\partial \rho }{\partial c_\textrm{s}},\frac{\partial \rho }{\partial c_\textrm{b}}\right) . \end{aligned}$$
(53)

The use in Eq. (52) of the pH definition, \(\textrm{pH}=7-{\log _{10}}\rho\), and the concentrations of Eqs. (49)–(51), gives after some algebra

$$\begin{aligned} S_\textrm{pH}=\frac{1}{{\ln {10}}}\frac{1}{\left( V_\textrm{ab}^0+V_\textrm{b}\right) ^2}\frac{1}{\rho }{\nabla _{{\varvec{c}}}}\rho \cdot {{\varvec{n}}^0}, \end{aligned}$$
(54)

with

$$\begin{aligned} {\varvec{n}}^0=\begin{pmatrix} c_\textrm{a}^0V_\textrm{a}^0,&c_\textrm{s}^0V_\textrm{s}^0,&-c_\textrm{b}^0V_\textrm{ab}^0\end{pmatrix}. \end{aligned}$$
(55)

The gradient \(\nabla _{{\varvec{c}}}\rho\) is calculated with respect to the components of \({\varvec{c}}\) but it must be expressed in terms of the volume of base \(V_\textrm{b}\).

Figure 4 displays the pH stability, \(S_\textrm{pH}\), as a function of the pH of the buffer solution. Since the addition of a strong base increases monotonically the pH of the solution, the curves of Fig. 4 contain the same information as the titration curves. To simplify the analysis all the concentrations used to prepare or titrate the buffers, \(c_\textrm{a}^0\), \(c_\textrm{s}^0\) and \(c_\textrm{b}^0\), have the same value \(c^0\). Panel (a) of Fig. 4 displays \(S_\textrm{pH}/100\) for buffer solutions with concentrations \(C^0=10^{-7}\times c^0\) ranging from \(10^{-2}\) to \(10^{-1}\,\textrm{M}\) (from blue to red). Panel (b) of Fig. 4 displays \(S_\textrm{pH}\) for buffer solutions with concentrations \(C^0=10^{-7}\times c^0\) ranging from \(10^{-7}\) to \(10^{-5}\,\textrm{M}\) (from purple to red). In both panels of Fig. 4, curves with lower (higher) values of \(S_\textrm{pH}\) are for buffer solutions prepared and titrated with solutions of lower (higher) concentrations. The maximum of the curves \(S_\textrm{pH}\) is higher, and located at higher pH, for buffer solutions at higher concentrations \(C^0\). The highest concentration buffer of Fig. 4a (in red) displays numerical instability for basic pH.

Fig. 4
figure 4

pH stability \(S_\textrm{pH}\) as a function of the pH for buffer solutions of acetic acid (\(k_\textrm{a}=175\)) and sodium acetate titrated with NaOH. To simplify the analysis, the initial concentrations \(c_\textrm{a}^0\), \(c_\textrm{s}^0\), and \(c_\textrm{b}^0\), are equal to \(c^0\). Panel (a) displays \(S_\textrm{pH}/100\) for solutions with concentrations \(C^0=10^{-7}\times c^0\) from \(10^{-5}\) to \(10^{-1}\,\textrm{M}\). The lowest curves (blue color) are at lower concentrations, the highest curves (red color) are for higher concentrations. Panel (b) displays \(S_\textrm{pH}\) for solutions with concentrations \(C^0=10^{-7}\times c^0\) from \(10^{-7}\) to \(10^{-5}\,\textrm{M}\). The lowest curves (purple color) are for low concentration buffers, the highest curves (red color) for higher concentrations

Figure 5 displays the titration curves for the same buffer solutions as in Fig. 4. To simplify the analysis, the concentrations of the solutions to prepare, and titrate, the buffer are the same, \(C^0=10^{-7}c^0\). All the titration curves of panels (a) and (b) of Fig. 5 intercept at \(V_\textrm{b}=1\,\textrm{L}\) and \(\textrm{pH}=7\). Buffers of higher concentrations, in red, display the largest changes of pH as the solution is titrated with strong base. It is observed in Fig. 5(a) that the steepest change in the pH is given for \(\textrm{pH}\approx 9\), as shown in Fig. 4a.

The use of Figs. 4a and 5a indicates that the lower the concentration of the solutions of acid and salt of the acid (blue curves), the lower the change in \(\textrm{pH}\) as the base is added.

Fig. 5
figure 5

Buffer titration as a function of the volume of base added, \(V_\textrm{b}/\textrm{L}\). To simplify the analysis, the concentrations of the solutions to prepare, and titrate, the buffer are the same, \(C^0=10^{-7}c^0\). Panel (a) displays the \(\textrm{pH}\) for solutions with concentrations \(C^0=10^{-7}\times c^0\) from \(10^{-5}\) to \(10^{-1}\,\textrm{M}\). The blue blue curves are at lower concentrations, the red curves are for higher concentrations. Panel (b) displays \(\textrm{pH}\) for solutions with concentrations \(C^0=10^{-7}\times c^0\) from \(10^{-7}\) to \(10^{-5}\,\textrm{M}\). The purple curves are for low concentration buffers, the red curves for higher concentrations

Systematic analysis relating the pH expressions

The four cubic equations for \(x={{[\textrm{H}_{3}\textrm{O}^+]}}/{\sqrt{K_\textrm{w}}}\) of the systems under study can be written as

$$\begin{aligned} x^3+c_2 x^2 +c_1 x+c_0=0. \end{aligned}$$
(56)

The coefficients of the four systems under study are given by the rows of Table 1.

Table 1 Coefficients of the polynomials for the systems studied: weak acid (w.a.), weak acid titration by a strong base (w.a. + s.b.), weak acid buffer (w.a.b.) and titration of a weak acid buffer by a strong base (w.a.b. + s.b.)

The concentration x is given by the only positive root of these polynomials,

$$\begin{aligned} x=\tfrac{2}{3}\sqrt{k^2+3ck_a+3}\cos {\left( \theta /3\right) }-\tfrac{k}{3}, \end{aligned}$$
(57)

with c and k as effective concentrations and acid dissociation constants, given by the fifth and second columns of Table 1, respectively. The angle \(\theta\) is given by the expression

$$\begin{aligned} \theta =\arctan {\left( -\frac{q}{2},\frac{\sqrt{\Delta }}{6\sqrt{3}}\right) }, \end{aligned}$$
(58)

with discriminant \(\Delta =-4p^3-27q^2>0\), and

$$\begin{aligned} p&=-\tfrac{1}{3}k^2-k_\textrm{a}c-1,\end{aligned}$$
(59)
$$\begin{aligned} q&=\tfrac{2}{27}k^3+\frac{k}{3}\left( 1+k_\textrm{a}c\right) -k_\textrm{a}. \end{aligned}$$
(60)

The values of k and c from Table 1 show that \(k \ge k_\textrm{a}\) and \(c\le c_\textrm{a}\). Equations (57)–(60) with the data of Table 1 give the full description of the pH for the systems studied.

Conclusions

A systematic algebraic analysis has been applied on the ideal aqueous chemical equilibrium of three acid–base systems of academic and practical interest. The weak acid dissociation, the titration of a weak acid solution by a strong base, the acid buffer solution and its titration by a strong base have been algebraically analyzed without approximations. Simple closed-form expressions for the roots of the cubic equations for the \({[\textrm{H}_{3}\textrm{O}^+]}\) are obtained. These analytical expressions for \({[\textrm{H}_{3}\textrm{O}^+]}\) are simple enough to calculate the pH with a handheld scientific calculator. It has been shown that all the systems under study have one real positive root and two negative roots, no complex roots were obtained. The existence of only one positive root, with physical meaning, was proved in several ways: by analyzing the discriminant of the cubic polynomials, and by using Descates’ rule of signs on the polynomial and its derivative. The cubic equations for the systems of interest were solved by the method of the depressed cubic equation of Vieta and Cardano. For all the systems under study, \({[\textrm{H}_{3}\textrm{O}^+]}\) is the subtraction of two terms: the first term is the product of a trigonometric function and the square root of a quadratic form of the acid dissociation constant, \(k_\textrm{a}\), and the concentrations, \(c_\textrm{a}\), \(c_\textrm{s}\), and \(c_\textrm{b}\); the second term is simply one-third of the sum of the acid constant and the concentrations. The analytical forms of \({[\textrm{H}_{3}\textrm{O}^+]}\) for the four systems analyzed are easily related by simple mathematical substitutions.

In addition to the expression for \({[\textrm{H}_{3}\textrm{O}^+]}\), the stability of the pH \(S_\textrm{pH}\) has been obtained and studied. The expression obtained for the pH stability \(S_\textrm{pH}\) allows one to quantify precisely the pH stability of a buffer solution when a strong base is added.

The exact pH has been compared against the approximate expression commonly used for calculating the pH. The error of these approximations is analyzed in detail. It has been shown that the Henderson–Hasselbalch (HH) equation exhibits large error for buffer solutions with salt concentrations \(C_\textrm{s}<0.01\,\textrm{M}\).