# Mathematica Concurrence in Mathematica

Tags:
1. Apr 28, 2015

### valesdn

Hi guys!
I have an unsolved problem. I'm going to calculate the concurrence for pure 2-qubit states:
|Ψ>=a| up up >+b|up down> +c|down up> +d | down down >
where up and down stay for uparrow and downarrow.
The concurrence is defined as:

I have found the vector Ψ3= 1/2 (1,1, cos (φ/2) - sin (φ/2), cos (φ/2) + sin (φ/2)), by the effect of an entangling gate.

I have written the single elements of the vector as

a = Flatten[Ψ3][[1]]
b = Flatten[Ψ3][[1]]
and so on

but it is wrong.
The concurrence should be C=sin(φ/2).
Could you help me?

Kind regards

2. Apr 28, 2015

### Staff: Mentor

I put it in to Mathematica just now and got Abs[Sin[φ/2]]. That seems correct to me.

Did you use capital letters for Sin and Cos, and square brackets for the function calls, and curly braces for the vector?

3. Apr 29, 2015

### valesdn

Hi Dalespam,
thanks for helping me.
I put the values of a,b,c and d into the formula

But I didn't get Abs[Sin ..].
The error occurs because C is protected but it occurs again when I change the letter C. Is it correct the code (1) that I used? Thanks in advance

Pa. Yes, I used capital letters for trigonometrical function, and so on... But an error occurs.

4. Apr 29, 2015

### Quantioner

The code is as follow:

Code (Text):
psi = {1, 1, Cos[\[Psi]/2] - Sin[\[Psi]/2],
Cos[\[Psi]/2] + Sin[\[Psi]/2]}/2;
con = 2 Abs[psi[[1]] psi[[4]] - psi[[2]] psi[[3]]] // FullSimplify

5. Apr 29, 2015

### valesdn

Many thanks, Quantioner. Now it works. I found on the net the code for the partial trace of a multiqubit system (PartialTraceGeneral[ρ,dim,sys) but there isn't a similar code in mathematica (not in mine ).
I need to find the partial trace of two subsystem, A and B, such as:

\begin{matrix} 1/2 & 1/2 \cos (\phi /2) \\ 1/2 \cos (\phi /2) & 1/2 \end{matrix}

and

\begin{matrix} 1/2 - 1/4 \sin (\phi /2) & 1/2 \cos^2 (\phi /2) \\ 1/2 \cos^2 (\phi /2) & 1/2+1/4 \sin (\phi /2) \end{matrix}

How can I find the partial traces? Is there any particular code to use ( I hope that... my teacher wants a "beautiful and refined" program, using few lines of code)?
Thanks for helping me.

6. Apr 29, 2015

### Quantioner

Luckily, I have defined such a function.
Code (Text):

ptrace[mat_, d_, k_] :=
With[{d1 = Length[mat]/d},
Table[Total[
mat[[FromDigits[({Reverse, Identity}[[k]])[{m, #}], d] - d,
FromDigits[({Reverse, Identity}[[k]])[{n, #}], d] - d]] & /@
Range[d]], {m, 1, d1}, {n, 1, d1}]]
(*partial trace mat the k-th subsystem whose dimension is d, where \
mat should be a square matrix*)

You can define functions for yourself.

7. Apr 29, 2015

### valesdn

I'll try to do my best :) Thanks Quantioner.

8. Apr 29, 2015

### valesdn

Quantioner, I'm sorry but I don't understand your code. Could you, please, explain substitutions to me? If it is possible and if you want or can do it. Thank you anyway.

P.s. There are too few arguments in the code:
http://imageshack.com/a/img905/1738/zUdlDv.png [Broken] http://imageshack.com/a/img537/6780/SNMRUz.png [Broken]

Last edited by a moderator: May 7, 2017
9. Apr 29, 2015

### Quantioner

10. Apr 29, 2015

### valesdn

11. Apr 29, 2015

### Quantioner

12. Apr 30, 2015

### valesdn

Hi Quantioner.
I apologize for my delay in answering.
I have just rewritten your code and the calculation is correct. Now, I’m trying to complete the exercise.
(If I continue to encounter difficulties, can I contact you in this topic? )

13. Apr 30, 2015

### Quantioner

You're always welcome.

14. May 2, 2015

### valesdn

Famous last words, Quantioner!
I tried to use the code for entropy ( Entropy[k, density operator]) - k is the base of the logarithm (2) - but I have this error message:
Entropy::targ: "Argument at position 2 should be a List, a SparseArray, or a String".
I need the entropy of entanglement, using the von Neumann entropy of a density operator:
S(ρ) = - Tr {ρ log2 (ρ) }
where Tr is the trace and ρ is equal to ρA (or ρB).
Could you help me?

Thanks in advance ( and again!).

15. May 2, 2015

### Quantioner

You should re-define the entropy function since the original one can not be applied in quantum case. BTW, the von Neumann entropy of a density operator $\rho$ is ${\rm Tr}[\rho \ln(\rho)]$ but not ${\rm Tr}[\rho \log_2(\rho)]$.
Code (Text):
Ventropy[op_] := -Tr[op MatrixLog[op]]
op = ({
{1/2, 1/3},
{1/3, 1/2}
});
Ventropy[op]

Last edited: May 2, 2015
16. May 3, 2015

### valesdn

Thanks, Quantioner. I forget that if there aren't "enough" functions, I'll need define new functions!
Why the von Neumann entropy is -Tr[ρ ln (ρ)] but not -Tr [ρ log2 (ρ)]? I used this formula because it is written in this way in an article.
Could you, please, explain to me why you write

op = ({
{1/2, 1/3},
{1/3, 1/2}
}); ? Is it an example (... I should substitute op with ρAB)?

I need to find the resulting entanglement entropy E(ρ3)=S(ρA)=S(ρB).

17. May 3, 2015

### Quantioner

18. May 3, 2015

### valesdn

Ok, Quantioner. I tried to substitute my density operators into your code, but I have these outputs:

http://imageshack.com/a/img537/706/bHI3WC.jpg [Broken]

Where am I wrong?

Last edited by a moderator: May 7, 2017
19. May 3, 2015

### Quantioner

I'm sorry that the definition should be changed to
Code (Text):

Ventropy[op_] := -Tr[op.MatrixLog[op]]
op = ({
{1/2, 1/3},
{1/3, 1/2}
});
Ventropy[op]

the result is
$$-\frac{2}{3} \left(\frac{\log (6)}{2}-\frac{1}{2} \log \left(\frac{6}{5}\right)\right)+\frac{\log (6)}{2}+\frac{1}{2} \log \left(\frac{6}{5}\right)$$
There is no wrong in your case when I run in my mathematica, you'd better send me your mathematica file.