Computer software with symbolic representation of differential operator

I wrote a matlab code for curl, divergence, gradient, and laplacian as shown below. By changing the value of $h1,h2,h3$, I was able to obtain the Symbolic Representation of result in the different coordinate system, i.e. the one for cylinder coordinate was shown below.

However, I met a problem: the matlab did not assume communitive/ cancellation rule in several cases. For example, $Vx*(Vy*x+Vz)$ was not the same as $Vx*(Vy*x^2+Vz*x)/x$.

Is there a way to solve this problem? Or is there any other software could give me the satisfied result?

I know that there were several software capable to give numerical calculation, but not all of them could give the symbolic calculation like matlab. Right now its only 3 by 3 metric, but if we goes into 4*4 tensor, it's almost impossible to calculate by hand in a fair amount of time.

syms x y z p;

syms Vx(x,y,z) Vy(x,y,z) Vz(x,y,z);

A=[ Vx(x,y,z) Vy(x,y,z) Vz(x,y,z) ];

%cylinder

h1=1;

h2=x;

h3=1;

syms S(x,y,z);

B=[S(x,y,z)];

%cross product

cucurl=@(A) 1/(h1*h2*h3)[h1 (diff( h3*A(3),y) - diff( h2*A(2),z) ), - h2* (diff( h3*A(3),x) - diff( h1*A(1),z) ) , h3* (diff( h2*A(2),x) - diff( h1*A(1),y) ) ];

cugra=@(S) 1* [(1/h1*diff(S,x)) , (1/h2 *diff(S,y)) , (1/h3*diff(S,z)) ];

%Divergence

cudiv=@(A) 1/(h1*h2*h3)* [ diff( A(1)*h2*h3, x )+ diff(A(2)*h1*h3, y ) + diff(A(3)*h2*h1, z ) ];

%Laplacian

culap=@(S) cudiv( cugra(S)); pretty( subs(culap(B))) pretty( subs(cugra(B))) pretty( subs(cudiv(A))) pretty( subs(cucurl(A)))

• You might have better luck getting an answer in scicomp.stackexchange.com or even on the original stackoverflow.com . Commented Oct 12, 2017 at 21:37
• Have you tried Mathematica, which is usually more amenable to analytic derivations? Commented Oct 12, 2017 at 21:58
• Maxima is AFAIK the best general-purpose open-source computer algebra system.
– user4552
Commented Oct 12, 2017 at 22:55
• Link to Maxima's page: maxima.sourceforge.net I find the wxMaxima gui of it pretty handy. andrejv.github.io/wxmaxima Commented Oct 13, 2017 at 1:31
• You're basically looking for a computer algebra system, of which there are a variety of proprietary & freeware implementations. Commented Oct 15, 2017 at 20:24

Python sympy package, Mathematica and SageMath. With sympy package use $init_printing()$ to obtain handwriting style output.