Mathematica Calculating Concurrence in Mathematica: Solving 2-Qubit States | Tutorial

AI Thread Summary
The discussion focuses on calculating the concurrence for pure 2-qubit states in Mathematica, specifically using the formula C = 2|ad - bc|. Participants share their code and troubleshoot errors related to function definitions and syntax. A key point is the need to redefine functions for specific quantum calculations, such as the von Neumann entropy, which is defined as S(ρ) = -Tr{ρ ln(ρ)}. Users also seek assistance with implementing partial traces for two subsystems and ensuring their code is efficient and elegant. The conversation emphasizes collaborative problem-solving and code refinement in quantum computing contexts.
valesdn
Messages
42
Reaction score
1
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:

C = 2|ad-bc|≥0

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?

Thanks in advance.

Kind regards
 
Physics news on Phys.org
I put it into 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?
 
  • Like
Likes valesdn
Hi Dalespam,
thanks for helping me.
I put the values of a,b,c and d into the formula

C= 2 Abs [ad-bc]. (1)
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.
 
The code is as follow:

Code:
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
 
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.
 
Luckily, I have defined such a function.
Code:
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.
 
  • Like
Likes valesdn
I'll try to do my best :) Thanks Quantioner.
 
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 http://imageshack.com/a/img537/6780/SNMRUz.png
 
Last edited by a moderator:
I will reply you tomorrow.
 
  • #10
Thank you for your time and for being so helpful.
 
  • #11
5f3e4996a8685f6d.png
 
  • #12
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? )

Thanks for all the help you gave me.
 
  • #13
You're always welcome.
 
  • #14
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
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:
Ventropy[op_] := -Tr[op MatrixLog[op]]
op = ({
    {1/2, 1/3},
    {1/3, 1/2}
   });
Ventropy[op]
 
Last edited:
  • #16
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).
 
  • #18
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

Where am I wrong?
 
Last edited by a moderator:
  • #19
I'm sorry that the definition should be changed to
Code:
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.
 
Back
Top