Logarithmic form v. standard form
- Last UpdatedAug 13, 2024
- 3 minute read
When Keq is very large (which can happen when a reaction leans heavily on the product side, such as with salts undergoing total dissociation), you may want to rewrite the reaction equilibrium in logarithmic form. In logarithmic form, summations replace the product operators in the law of mass action, and the equations for Keq transform into the following:


However, this transformation comes with a price. When you calculate the logarithmic form of the measure of composition, ln(fProducts) or ln(fReactants), you must apply the appropriate guards for handling the case of zero composition for any component.
For example, assume that the composition measure is activity (a):

In logarithmic form, this becomes:

While we provide ln(g) directly from the FluidState submodel (as the FluidState.lngamma variable), we need to calculate ln(x) from State.x with an equation of the following logarithmic form:

Alternatively, you can use an exponential form of the preceding equation:

In either case, you must add a small guard term (e) to State.x, because in many realistic cases, the composition of at least one component may be exactly zero (either intermittently due to bounds or at the solution). Rewriting the equations between the logarithmic form and alternative exponential form without considering e does not improve the numerical conditioning. In the logarithmic case, the logarithm of zero is negative infinity (resulting in a math exception). In the exponential case, there is no power to which we can raise e that results in exactly zero (resulting in a slow, creeping convergence). We recommend a value between 1×10-10 to 1×10-12 for e.
When you use the logarithmic formulation of the law of mass action, the choice of e directly influences the recommended lower bounds for the variables. For example, when e is 1×10-10, the lower bound for ln(x) should be -24 (ln(1×10-10) ~ -23.0259). In practice, you must provide a bound at least twice the magnitude (-48) because when one reactant is not present, the law of mass action forces one term to be strongly negative (in the logarithmic form). In a general case, we recommend that you use a lower bound of -60 to -80 for the ln(x) and ln(a) variables. However, the best choice of lower bound depends on your concrete system and you must determine optimal values by empirical analysis.
When you use the standard form of the law of mass action, the x variable should have the standard physical bounds of a mole fraction (from 0 to 1). Furthermore, you do not need to add the guard term.