def _to_ANP_poly(f, ring):
 domain = ring.domain
 f_ = ring.zero
 if isinstance(f.ring.domain, PolynomialRing):
  for (monom, coeff) in f.iterterms():
   for (mon, coef) in coeff.iterterms():
    m = ((monom[0],) + mon)
    c = domain(([domain.domain(coef)] + ([0] * monom[1])))
    if (m not in f_):
     f_[m] = c
    else:
     f_[m] += c
 else:
  for (monom, coeff) in f.iterterms():
   m = (monom[0],)
   c = domain(([domain.domain(coeff)] + ([0] * monom[1])))
   if (m not in f_):
    f_[m] = c
   else:
    f_[m] += c
 return f_

def _to_ANP_poly ( f , ring ) : domain = ring . domain f_ = ring . zero if isinstance ( f . ring . domain , PolynomialRing ) : for ( monom , coeff ) in f . iterterms ( ) : for ( mon , coef ) in coeff . iterterms ( ) : m = ( ( monom [ 0 ] , ) + mon ) c = domain ( ( [ domain . domain ( coef ) ] + ( [ 0 ] * monom [ 1 ] ) ) ) if ( m not in f_ ) : f_ [ m ] = c else : f_ [ m ] += c else : for ( monom , coeff ) in f . iterterms ( ) : m = ( monom [ 0 ] , ) c = domain ( ( [ domain . domain ( coeff ) ] + ( [ 0 ] * monom [ 1 ] ) ) ) if ( m not in f_ ) : f_ [ m ] = c else : f_ [ m ] += c return f_
convert a polynomial f in mathbb z[x_1 .