Welcome to Cadabra Q&A, where you can ask questions and receive answers from other members of the community.
+1 vote

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).

in Bug reports by (460 points)

1 Answer

+1 vote

That problem comes from the fact that you wrote \sin\phi, instead of \sin(\phi). In Cadabra you have to group function arguments. (Of course I agree the error is useless and this should be caught earlier).

by (83.1k points)

Yes, it's especially confusing because \cos(\phi) displays as cos phi without parentheses. Why do you drop the parentheses when generating the latex output?

...