# Singular

#### D.8.2.11 sortandmap

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

Usage:
sortandmap(id [,n1,p1,n2,p2...,o1,m1,o2,m2...]);
id=poly/ideal/vector/module,
p1,p2,...= polynomials (product of variables),
n1,n2,...= integers,
o1,o2,...= strings,
m1,m2,...= integers
(default: p1=product of all vars, n1=0, o1="dp",m1=0)
the last pi (containing the remaining vars) may be omitted

Return:
a ring R, in which a poly/ideal/vector/module IMAG is stored:
- the ring R differs from the active basering only in the choice of monomial ordering and in the sorting of the variables.
- IMAG is the image (under imap) of the input ideal/module id
The new monomial ordering and sorting of vars is as follows:
 ``` - each block of vars occuring in pi is sorted w.r.t. its complexity in id, - ni controls the sorting in i-th block (= vars occuring in pi): ni=0 (resp. ni!=0) means that least complex (resp. most complex) vars come first - oi and mi define the monomial ordering of the i-th block: if mi =0, oi=ordstr(i-th block) if mi!=0, the ordering of the i-th block itself is a blockordering, each subblock having ordstr=oi, such that vars of same complexity are in one block ```
Note that only simple ordstrings oi are allowed: "lp","dp","Dp", "ls","ds","Ds".

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 = 32003,(x,y,z),dp; ideal i=x3+y2,xz+z2; def R_r=sortandmap(i); ==> ==> // 'sortandmap' created a ring, in which an object IMAG is stored. ==> // To access the object, type (if the name R was assigned to the return v\ alue): ==> setring R; IMAG; show(R_r); ==> // ring: (ZZ/32003),(x,y,z),(dp(3),C); ==> // minpoly = 0 ==> // objects belonging to this ring: ==> // IMAG [0] ideal, 2 generator(s) setring R_r; IMAG; ==> IMAG[1]=x3+y2 ==> IMAG[2]=xz+z2 kill R_r; setring s; def R_r=sortandmap(i,1,xy,0,z,0,"ds",0,"lp",0); ==> ==> // 'sortandmap' created a ring, in which an object IMAG is stored. ==> // To access the object, type (if the name R was assigned to the return v\ alue): ==> setring R; IMAG; show(R_r); ==> // ring: (ZZ/32003),(x,y,z),(ds(2),lp(1),C); ==> // minpoly = 0 ==> // objects belonging to this ring: ==> // IMAG [0] ideal, 2 generator(s) setring R_r; IMAG; ==> IMAG[1]=y2+x3 ==> IMAG[2]=z2+xz kill R_r; ```