differentiation by rolf

import re
def f(x):
 a,b,c=x.groups()
 if c:c=int(c);return"%+dx"%(int(a)*c)+("^%d"%~-c)*(c>2)
 if b:return a
while 1:print re.sub("([+-]?\d+)(x\^(.)|x)?",f,raw_input()).strip("+")

Note that non-ascii characters in the above source code will be escaped (such as \x9f).

download

return to the top page