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:

og{#}::LaTeXForm("\overline{g}").
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.

GPN

in General questions by (2.0k points)

1 Answer

0 votes

Hi GPN.

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 (15.0k points)

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

og{#}::LaTeXForm("\overline{g}").
ogdef := og_{\mu\nu} = g**(-1/4) g_{\mu\nu};
ex := \det{og_{\mu\nu}};
map_sympy(ex);

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
    self._execute_python(pycode)
  File "/usr/lib/python3.10/dist-packages/cadabra2_jupyter/kernel.py", line 110, in _execute_python
    self._sandbox_context(pycode)
  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

Hi GPN.

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

...