[C0*1, C1*X1, C2*X2, ...]where Ci are numbers and Xi are distinct variables. The first (constant) term is always present, Ci (i>=1) are nonzero.
linearize/3 converts a general arithmetic expression into a normalised linear form. The nonlinear parts are extracted using auxiliary variables, and returned as Residue, which is a list of Aux=NonLinExpr constraints.
linearize/3 understands all arithmetic expressions plus
lin(Lin)where Lin is an already normalised linear expression. All variables within Expression (which are free at linearization time) are taken to be numerical variables. If you intend to have variables which can be bound to symbolic expressions rather than numbers, they must be wrapped into an eval/1 functor.
?- linearize(3*X-7*Y+2*(X+Y), L, R). X = X Y = Y L = [0 * 1, 5 * X, -5 * Y] R = [] yes. ?- linearize(12*3, L, R). L = [36 * 1] R = [] yes. ?- linearize(X*(3+7*Y)-X, L, R). Y = Y X = X L = [0 * 1, 1 * _308, 2 * X] R = [_308 = X * (7 * Y)] yes.