def _swap(f, i):
 ring = f.ring
 k = ring.ngens
 fswap = ring.zero
 for (monom, coeff) in f.iterterms():
  monomswap = (((monom[i],) + monom[:i]) + monom[(i + 1):])
  fswap[monomswap] = coeff
 return fswap

def _swap ( f , i ) : ring = f . ring k = ring . ngens fswap = ring . zero for ( monom , coeff ) in f . iterterms ( ) : monomswap = ( ( ( monom [ i ] , ) + monom [ : i ] ) + monom [ ( i + 1 ) : ] ) fswap [ monomswap ] = coeff return fswap
make the variable x_i the leading one in a multivariate polynomial f .