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

Hi everyone! I will demonstrate the problem on following the program code. The initialization of indices:

{x, y}::Coordinate:
{i, j, a, b}::Indices(values={x, y}, position=fixed):
\delta{#}::KroneckerDelta:
\epsilon^{i j}::EpsilonTensor(delta=\delta):

Let further introduce two matrices:

matrix1 := A_{i j}:
matrix2 := B_{i j}:
explicit1   := { A_{x x} = 1 , A_{y y} = 1};
explicit2   := { B_{x x} = 1/(-H) (-H) , B_{y y} = 1};

They are, obviously, identical. However, if I calculate their determinant with the help of the epsilon symbol, I will get different answers:

determ1 := DA = 1/2 \epsilon^{a b} \epsilon^{i j} A_{a i} A_{b j} :
evaluate(determ1, explicit1, rhsonly=True);
determ2 := DB = 1/2 \epsilon^{a b} \epsilon^{i j} B_{a i} B_{b j} :
evaluate(determ2, explicit2, rhsonly=True);

The output is DA = 1, while DB = 2. I possibly figured out the source of the problem. Consider the third matrix:

matrix3 := C_{i j}:
explicit3   := { C_{x x} = -1/-1 , C_{y y} = 1 };

A bit unexpected thing is that Cadabra interprets it as C_{x x} = -2, like -1/-1 = -1/1 -1. For example, -1/-3 will yield -4. If instead one writes -1/(-1) then the answer is correct, +1. I guess that somewhere in the internal processing (most probably, immediately after performing explicit2 statement) Cadabra looses these brackets, which further results in incorrect calculation of the determinant. Interestingly, if I use sympy to simplify the B matrix, the result would be correct.

The "big" problem is that Cadabra generates expressions like -1/-1 (which should be +1 and not -2) during processes like expand and distribute. This results in incorrect further usage of such expressions. Also, the described problem can result in incorrect calculations in other cases.

in Bug reports by (220 points)

1 Answer

+2 votes
 
Best answer

Thanks for reporting this, and for doing the digging! Yes, this is caused by a bug in the ping-pong procedure between Cadabra's internal representation and Sympy. But in fact it goes deeper: it has to do with the fact that Cadabra would not always simplify rational expressions to canonical form.

I have pushed a partial fix for this to the fix/collectcomponents branch on github. Feel free to test (it does do the right thing for your example above, but I have had no time to do more testing and checking).

by (83.1k points)
selected by
...