def _get_constant_term(p, x):
 R = p.ring
 zm = R.zero_monom
 i = R.gens.index(x)
 zm = R.zero_monom
 a = ([0] * R.ngens)
 a[i] = 1
 miv = tuple(a)
 c = 0
 for expv in p:
  if (monomial_min(expv, miv) == zm):
   c += R({expv: p[expv]})
 return c

def _get_constant_term ( p , x ) : R = p . ring zm = R . zero_monom i = R . gens . index ( x ) zm = R . zero_monom a = ( [ 0 ] * R . ngens ) a [ i ] = 1 miv = tuple ( a ) c = 0 for expv in p : if ( monomial_min ( expv , miv ) == zm ) : c += R ( { expv : p [ expv ] } ) return c
return constant term in p with respect to x note that it is not simply p[r .