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

Consider please the following tensor density:

ogdef := og_{\mu\nu} = g**(-1/4) g_{\mu\nu};

Of course, \det{og_{\mu\nu}} = -1 follows immediately from this definition. But I haven't found a way to make Cadabra calculate this latter identity - I have had to put it in "by hand":

ogdet := \det{og_{\mu\nu}} = -1;

Is there a way for Cadabra to calculate this without putting it in by hand?

Thank you for the patience. I realise I am asking a lot of newbie questions.


in General questions by (1.2k points)

1 Answer

0 votes


To the extend of my knowledge cadabra does not calculate... I would say manipulate expressions (you assign properties to "objects" and use algorithms to manipulate them).

cadabra2.x comunicates with SymPy to evaluate expressions (in other word, calculate!). However, the comunication is not "bijective" (it is somehow incomplete), and there is a possibility that the dictionary doesn't translate the operation \det.

If you ask me... I would use substitute! (unless it is not possible)

Cheers, Dox.

by (12.5k points)

Thank you. I tried as you say, to pass this to sympy:

ogdef := og_{\mu\nu} = g**(-1/4) g_{\mu\nu};
ex := \det{og_{\mu\nu}};

However, it seems like the Cadabra2 sympy parser does not recognise the \det{} operation; any advice? The error is:

ValueError: Error from parse_expr with transformed code: "(\\det (Function ('og' )(Symbol ('DNmu' ),Symbol ('DNnu' ))))"

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/usr/lib/python3.10/dist-packages/cadabra2_jupyter/kernel.py", line 56, in do_execute
  File "/usr/lib/python3.10/dist-packages/cadabra2_jupyter/kernel.py", line 110, in _execute_python
  File "/usr/lib/python3.10/dist-packages/cadabra2_jupyter/context.py", line 51, in __call__
    exec(code, self._sandbox)
  File "<string>", line 4, in <module>
  File "/usr/lib/python3/dist-packages/sympy/parsing/sympy_parser.py", line 1026, in parse_expr
    raise e from ValueError(f"Error from parse_expr with transformed code: {code!r}")
  File "/usr/lib/python3/dist-packages/sympy/parsing/sympy_parser.py", line 1017, in parse_expr
    rv = eval_expr(code, local_dict, global_dict)
  File "/usr/lib/python3/dist-packages/sympy/parsing/sympy_parser.py", line 911, in eval_expr
    expr = eval(
  File "<string>", line 1
    (\det (Function ('og' )(Symbol ('DNmu' ),Symbol ('DNnu' ))))
SyntaxError: unexpected character after line continuation character


As I mentioned, the communication between cadabra and sympy is not "entire" (let's say it has singularities).

In your example, I'm not sure that the bridge knows how to pass the determinant to sympy.

If you ask me: I'd use substitute.

HAhahaha (I just learn that I can bold monospace fonts!).

Thank you @doxdrum