# Revision history [back]

I realise I may just define a new operation "non-commutative product" (ncp for short) that takes two arguments and respects the product rule, as well as some basic simplifications.

var('t s')

def e_func(self, *args, **kwds):
if args[0]==1:
return args[1]
elif args[1]==1:
return args[0]
elif args[0]*args[1]==0:
return 0
else:
pass

ncp = function('ncp', nargs=2,
tderivative_func=lambda self, *args, **kwds:\
ncp(diff(args[0],kwds['diff_param']),args[1])+ncp(args[0],diff(args[1],kwds['diff_param'])),\
eval_func=e_func,
print_func=lambda self,*args: format(args[0])+' . '+format(args[1]) # denote ncp by .
)

print ncp(t^2,3*s^3).derivative(t)
print ncp(t,3*s^3).derivative(t)
print ncp(t^2,3*s^3/t).derivative(t)


Which produces

t^2 . 3*s^3
2*t . 3*s^3
3*s^3
t^2 . -3*s^3/t^2 + 2*t . 3*s^3/t


I would very much prefer a more "built-in" solution over this hack. Also, without further modification this approach does not work for products of three or more factors. For that reason I'll leave the acceptance of an answer open for a more concise solution.