def rs_diff(p, x):
 R = p.ring
 n = R.gens.index(x)
 p1 = R.zero
 mn = ([0] * R.ngens)
 mn[n] = 1
 mn = tuple(mn)
 for expv in p:
  if expv[n]:
   e = monomial_ldiv(expv, mn)
   p1[e] = (p[expv] * expv[n])
 return p1

def rs_diff ( p , x ) : R = p . ring n = R . gens . index ( x ) p1 = R . zero mn = ( [ 0 ] * R . ngens ) mn [ n ] = 1 mn = tuple ( mn ) for expv in p : if expv [ n ] : e = monomial_ldiv ( expv , mn ) p1 [ e ] = ( p [ expv ] * expv [ n ] ) return p1
return partial derivative of p with respect to x .