Starting from the general expression HC = 0 for any mixture of acids, bases, and salts we find the pH as the root of this expression either by bisection or by using the Newton-Raphson or Levenberg-Marquardt algorithms. All three are readily implemented on a spreadsheet.
Levie et al. (Thu,) studied this question.