def diff(y, x):
if y == x: return ONE<EOL>elif not y.args: return ZERO<EOL>else:<EOL><INDENT>u, op, v = y.args[<NUM_LIT:0>], y.op, y.args[-<NUM_LIT:1>]<EOL>if op == '<STR_LIT:+>': return diff(u, x) + diff(v, x)<EOL>elif op == '<STR_LIT:->' and len(args) == <NUM_LIT:1>: return -diff(u, x)<EOL>elif op == '<STR_LIT:->': return diff(u, x) - diff(v, x)<EOL>elif op == '<STR_LIT:*>': return u * diff(v, x) + v * diff(u, x)<EOL>elif op == '<STR_LIT:/>': return (v*diff(u, x) - u*diff(v, x)) / (v * v)<EOL>elif op == '<STR_LIT>' and isnumber(x.op):<EOL><INDENT>return (v * u ** (v - <NUM_LIT:1>) * diff(u, x))<EOL><DEDENT>elif op == '<STR_LIT>': return (v * u ** (v - <NUM_LIT:1>) * diff(u, x)<EOL>+ u ** v * Expr('<STR_LIT>')(u) * diff(v, x))<EOL>elif op == '<STR_LIT>': return diff(u, x) / u<EOL>else: raise ValueError("<STR_LIT>" % (op, y, x))<EOL><DEDENT>
Return the symbolic derivative, dy/dx, as an Expr.
    However, you probably want to simplify the results with simp.
    >>> diff(x * x, x)
    ((x * 1) + (x * 1))
    >>> simp(diff(x * x, x))
    (2 * x)