As a warmup exercise before what I really want to do, I'm trying to compute the Laplacian operator in 2D plane polar coordinates. I do this by expressing \partial_{x}
and \partial_{y}
in terms of \partial_{r}
and \partial_{\theta}
, and then compute the sum of the squares of these operators.
Of course, operator expressions like \partial_x^2
are quickly regurgitated, so I'm trying the following alternative:
Px:= { px = \cos{\phi} \partial_{r}{f}
- \frac{\sin\phi}{r} \partial_{\phi}{f} } ;
Pxx:= { pxx = \cos{\phi} \partial_{r}{px}
- \frac{\sin\phi}{r} \partial_{\phi}{px}};
substitute(Pxx,Px);
evaluate(Pxx);
Cadabra gets the substitution correct, but evaluate() gives what looks like a sympy error:
{\color{red}{\begin{verbatim}TypeError: bad operand type for unary -: 'FunctionClass'
{\color{red}{\begin{verbatim}TypeError: bad operand type for unary -: 'FunctionClass'
TypeError: bad operand type for unary -: 'FunctionClass'
At:
Notebook Cell (Line 0):
/tmp/.mount_CadabrIqWtS3/usr/lib/python3.8/dist-packages/sympy/parsing/sympy_parser.py(909): eval_expr
/tmp/.mount_CadabrIqWtS3/usr/lib/python3.8/dist-packages/sympy/parsing/sympy_parser.py(1090): parse_expr
Notebook Cell (Line 0):
Btw, I was unable to copy and paste these red error messages out of cadabra easily by the usual highlight-and-click methods. I had to click Edit->Copy and then paste it over here, but it still omitted the first line above (which I ended up typing in by hand).