'Computes partial derivative in ``x``.
Examples
>>> from sympy.polys.rings import ring
>>> from sympy.polys.domains import ZZ
>>> _, x, y = ring("x,y", ZZ)
>>> p = x + x**2*y**3
>>> p.diff(x)
2*x*y**3 + 1'

def diff(f, x):

    ring = f.ring
    i = ring.index(x)
    m = ring.monomial_basis(i)
    g = ring.zero
    for (expv, coeff) in f.iterterms():
        if expv[i]:
            e = ring.monomial_ldiv(expv, m)
            g[e] = ring.domain_new((coeff * expv[i]))
    return g
