A generalized tearing procedure for solving systems of algebraic equations: applications to physical-chemical equilibria