def _integer_basis(poly):
 (monoms, coeffs) = list(zip(*poly.terms()))
 (monoms,) = list(zip(*monoms))
 coeffs = list(map(abs, coeffs))
 if (coeffs[0] < coeffs[(-1)]):
  coeffs = list(reversed(coeffs))
  n = monoms[0]
  monoms = [(n - i) for i in reversed(monoms)]
 else:
  return None
 monoms = monoms[:(-1)]
 coeffs = coeffs[:(-1)]
 divs = reversed(divisors(gcd_list(coeffs))[1:])
 try:
  div = next(divs)
 except StopIteration:
  return None
 while True:
  for (monom, coeff) in zip(monoms, coeffs):
   if ((coeff % (div ** monom)) != 0):
    try:
     div = next(divs)
    except StopIteration:
     return None
    else:
     break
  else:
   return div

def _integer_basis ( poly ) : ( monoms , coeffs ) = list ( zip ( * poly . terms ( ) ) ) ( monoms , ) = list ( zip ( * monoms ) ) coeffs = list ( map ( abs , coeffs ) ) if ( coeffs [ 0 ] < coeffs [ ( - 1 ) ] ) : coeffs = list ( reversed ( coeffs ) ) n = monoms [ 0 ] monoms = [ ( n - i ) for i in reversed ( monoms ) ] else : return None monoms = monoms [ : ( - 1 ) ] coeffs = coeffs [ : ( - 1 ) ] divs = reversed ( divisors ( gcd_list ( coeffs ) ) [ 1 : ] ) try : div = next ( divs ) except StopIteration : return None while True : for ( monom , coeff ) in zip ( monoms , coeffs ) : if ( ( coeff % ( div ** monom ) ) != 0 ) : try : div = next ( divs ) except StopIteration : return None else : break else : return div
compute coefficient basis for a polynomial over integers .