# Singular

#### D.8.2.12 sortvars

Procedure from library `presolve.lib` (see presolve_lib).

Usage:
sortvars(id[,n1,p1,n2,p2,...]);
id=poly/ideal/vector/module,
p1,p2,...= polynomials (product of vars),
n1,n2,...= integers
(default: p1=product of all vars, n1=0)
the last pi (containing the remaining vars) may be omitted

Compute:
sort variables with respect to their complexity in id

Return:
list of two elements, an ideal and a list:
 ``` [1]: ideal, variables of basering sorted w.r.t their complexity in id ni controls the ordering in i-th block (= vars occuring in pi): ni=0 (resp. ni!=0) means that less (resp. more) complex vars come first [2]: a list with 4 entries for each pi: _[1]: ideal ai : vars of pi in correct order, _[2]: intvec vi: permutation vector describing the ordering in ai, _[3]: intmat Mi: valuation matrix of ai, the columns of Mi being the valuation vectors of the vars in ai _[4]: intvec wi: size of 1-st, 2-nd,... block of identical columns of Mi (vars with same valuation) ```

Note:
We define a variable x to be more complex than y (with respect to id) if val(x) > val(y) lexicographically, where val(x) denotes the valuation vector of x:
consider id as list of polynomials in x with coefficients in the remaining variables. Then:
val(x) = (maximal occuring power of x, # of all monomials in leading coefficient, # of all monomials in coefficient of next smaller power of x,...).

Example:
 ```LIB "presolve.lib"; ring s=0,(x,y,z,w),dp; ideal i = x3+y2+yw2,xz+z2,xyz-w2; sortvars(i,0,xy,1,zw); ==> [1]: ==> _[1]=x ==> _[2]=y ==> _[3]=z ==> _[4]=w ==> [2]: ==> [1]: ==> _[1]=y ==> _[2]=x ==> [2]: ==> 2,1 ==> [3]: ==> 2,3, ==> 1,1, ==> 2,0, ==> 0,2 ==> [4]: ==> 1,1 ==> [5]: ==> _[1]=w ==> _[2]=z ==> [6]: ==> 2,1 ==> [7]: ==> 2,2, ==> 2,1, ==> 0,2 ==> [8]: ==> 1,1 ```