# 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==1:
return args
elif args==1:
return args
elif args*args==0:
return 0
else:
pass

ncp = function('ncp', nargs=2,
tderivative_func=lambda self, *args, **kwds:\
ncp(diff(args,kwds['diff_param']),args)+ncp(args,diff(args,kwds['diff_param'])),\
eval_func=e_func,
print_func=lambda self,*args: format(args)+' . '+format(args) # 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.