Ask Your Question

# derivative of non-commuting symbolic product Consider the product rule $\frac d{dt}[A(t)B(t)]=\dot{A}(t)B(t)+A(t)\dot{B}(t)$ with $A$ and $B$ not commuting, e.g, matrix valued. I'd like to replicate this in sage, however, I don't see how I can specify that $A$ and $B$ do not commute. So far I have

var('t')
A=function('A')(t)
B=function('B')(t)
diff(A*B,t)


which yields B(t)*diff(A(t), t) + A(t)*diff(B(t), t). But here sage has assumed that the operators and their derivatives do commute. Not what I want.

I did look into sage.symbolic.function_factory.function and the like, but could not find anything about products. Am I overlooking something or is this currently not possible?

edit retag close merge delete

## 1 Answer

Sort by » oldest newest most voted 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.

more

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2017-03-20 15:57:40 +0200

Seen: 219 times

Last updated: Mar 21 '17