# How can I calculate the negativity?

I tried to calculate the negativity that is defined as follows:

$$eq(1): N = Tr(Sqrt(A.A\dagger))-1$$

The result should be ~0.41 in for example r~0.01 (when r is close to 0) and it decreases versus r. The range of r is 0 to 0.8. So when r increases, the negativity should decrease. Anyway, my result is different.

Notice that first we must diagonalize the matrix p (calculating the eigenvalues). Then we take the square root of the eigenvalues. Then we need to sum the eigenvalues using the Total function (it's to calculate the trace of the diagonal matrix).

After that we need to do a sum from m = 0 to infinity (I know it's not part of the $$eq (1)$$ but we must do it. For more info look at page 5 of the article

Also notice that the matrix is equal to its dagger so $$p = p\dagger$$. So can we say based on $$eq (1)$$ the negativity can calculated like this below?

$$eq(2):N=tr(p)-1$$

Here is my code:

Off[General::precw];
a = b = 1/Sqrt[3];
r = 0.01;
Subscript[p, r] =
MatrixForm[{{((m*b^2)/Cosh[r]^4)*
Tanh[r]^(2*m - 2) + (1 - a^2 - b^2)*(Tanh[r]^(2*m)/Cosh[r]^2),
0, 0, ((b*a)/Cosh[r]^3)*Sqrt[m + 1]*Tanh[r]^(2*m)},
{0, (a^2/Cosh[r]^2)*Tanh[r]^(2*m), 0, 0}, {0,
0, (1 - a^2 - b^2)*(Tanh[r]^(2*m + 2)/
Cosh[r]^2) + (((m + 1)*b^2)/Cosh[r]^4)*Tanh[r]^(2*m), 0},
{((a*b)/Cosh[r]^3)*Sqrt[m + 1]*Tanh[r]^(2*m), 0,
0, (a^2/Cosh[r]^2)*Tanh[r]^(2*m + 2)}}];
Subscript[pp, r] = Subscript[p, r] . Subscript[p, r];
Subscript[eigen, r] = Eigenvalues[Subscript[pp, r]];
Subscript[seigen, r] = Sqrt[Subscript[eigen, r]];
Subscript[Ne, r] =
Re[NSum[Total[Subscript[seigen, r]], {m, 0, Infinity}]] - 1

• Crossposted here: community.wolfram.com/groups/-/m/t/2922466 Commented May 21, 2023 at 10:53
• Subscript[p, r] = MatrixForm[... This is wrong. Do not use MatrixForm for anything other than presentational purposes. If you use it in calculations like this, you will encounter problems. Commented May 21, 2023 at 11:34
• As @flinty points out, avoid MatrixForm in assignments. MatrixForm is a directive for rendering, not something that takes a grid of numbers and tells mathematica to treat it mathematically like a matrix. Second, you probably want to avoid Subscript. It is possible to code correctly with subscript, but it's not easy. You can instead just do eg. p[r]. Commented May 21, 2023 at 12:23

The negativity can be calculated via

negativity[A_] := Total[Sqrt[Eigenvalues[A . A\[ConjugateTranspose]]]] - 1


We can test this,

negativity[PauliMatrix[1]] (* gives 1*)
negativity[PauliMatrix[2]] (* gives 1*)

(*
gives graphics showing a distribution of negativities of 1000 matrices
with entries randomly picked from [0, 1].
*)
Histogram[negativity /@ RandomReal[{0, 1}, {1000, 100, 100}]]


You can use negativity on your matrix if you can construct it numerically.