A new computer program, called immobilized pH gradients (IPG) simulator, is proposed for calculating and optimizing any recipe for use in isoelectric focusing in immobilized pH gradients. Unlike our previous monoprotic electrolyte gradient simulation (MGS) and polyelectrolyte gradient simulation (PGS) programs, based on minimizing CV(beta), the present program has a target function the minimization of the quadratic moment around zero of the residuals (mu 2). With this algorithm it is possible to formulate IPG recipes which have deviations from linearity well below 1% of the given pH interval (a limit set with the previous MGS and PGS programs), in fact, as small as 0.1-0.2% (in pH units). The new simulator performs 2-3 times better than the previous ones in the pH 4-10 range, and is absolutely necessary when working outside this range, at extreme pH values, where CV(beta) cannot work against the buffering power of bulk water, thus generating pH recipes with huge deviations from linearity. In the latter cases, mu 2 performs 10 times better than CV(beta). When utilizing strong titrants for extended pH intervals, the "all or none" rule has been discovered: such titrants should always be used in tandem, since omission of one of the two at either the acidic or basic extremes produces strongly distorted pH profiles. Our new, most powerful simulator also contains equations for creating nonlinear gradients, notably: concave and convex exponentials and sigmoidal (see the companion paper: Righetti, P. G. and Tonani, C., Electrophoresis 1991, 12, 1021-1027).