(* ::Package:: *)
(*
Authors:
Bruno Julia-Diaz, Email : bjulia@gmail.com,
Department de Estructura i Constituents de la Materia,
Universitat de Barcelona, 08028 Barcelona, Spain.
Frank Tabakin, Email : tabakin@pitt.edu,
Department of Physics & Astronomy,
University of Pittsburgh, Pittsburgh, PA 15260
version 4.0, 22 Sept 2010
*)
BeginPackage["QDENSITY`Qdensity`"]
(*Begin["`Private`"];*)
rcsRevision = StringReplace["$Revision: 4.00 $", "$" -> ""];
rcsDate = StringReplace["$Date: 9-20-2010 1:00:00 $", "$" -> ""];
(*End[];*)
Print["Type \"?intro\", \"?QDENSITY`Qdensity`*\" or \"?about\ for help."];
$PrePrint = MatrixForm;
Off[General::"spell1"]
(* Begins USAGE description of Commands *)
about::usage =
" Qdensity is a Mathematica package to simulate a quantum computer
\n on a classical one. This simulation closely follows the procedures
\n that would occur in an actual quantum computer, wherein quantum
\n interference and superposition play a key role.
\n Although the main emphasis is on using a density matrix approach,
\n QDENSITY also handles state vectors. The package comes with a manual
\n and several notebooks that should allow the user to build any quantum
\n circuit out of conventional quantum gates.
\n\n The notebooks develop the most relevant quantum algorithms:
\n teleportation, searching algorithms and factoring algorithms in
\n a self contained way. Some basic cluster model examples are also provided.
\n\n We thank Joseph Burdis for his help with QDENSITY. We also acknowledge
\n the participation of Matt McHugh and Mahesh Bandi at an early stage of
\n this project. Reza Yoosoofmiya and Sushmita Biswas provided some helpful
\n suggestions on the final versions. Insightful comments by Profs. E. Gerjuoy (PITT)
\n and Robert B. Griffiths (CMU) are very much appreciated.
\n This project was supported,in part, by the N.S.F ";
intro::usage =
"The commonly used quantum gates and structures used in quantum
\n circuits are implemented in the package. Several examples including
\n teleportation circuits, Grover search algorithms and Shor's
\n factoring algorightms are included. Several additional applications are are illustrated."
(* ================================================================= *)
(* START USAGE DOCUMENTATION *)
Adj::usage=
"Adj[A]
\n\t gives the adjoint of matrix A.";
CircleTimes::usage=
"\[CircleTimes]
\n used as A \[CircleTimes] B is the tensor product of A and B.
\n When nested, care should be taken with the use of parentheses
\n e.g. use (A \[CircleTimes] B) \[CircleTimes] C instead of simply
\n A \[CircleTimes] B \[CircleTimes] C.";
Fidelity::usage=
"Fidelity[Op1,Op2] or FidelityB[Op1,Op2]
\n\t returns the concurrence of operators Op1 and Op2
\n defined as =MatrixPower[ MatrixPower[Op1,1/2].Op2.MatrixPower[Op1,1/2],1/2].
Now have FidelityB[Op1,Op2] as an alternative method which uses eigenvalues of
Op1.Op2";
ControlledX::usage=
"ControlledX[L,q1,q2]
\n\t Returns the ControlledX operator with q1 qubit as control,
\n q2 qubit as target within L qubits--same as CNOT ";
ControlledY::usage=
"ControlledY[L,q1,q2]
\n\t Returns the ControlledY operator with q1 qubit as control,
\n q2 qubit as target within L qubits";
ControlledZ::usage=
"ControlledZ[L,q1,q2]
\n\t Returns the ControlledY operator with q1 qubit as control,
\n q2 qubit as target within L qubits";
CNOT::usage=
"CNOT[L,q1,q2]
\n\t Returns the CNOT operator with q1 qubit as control,
\n q2 qubit as target within L qubits--same as ControlledX. ";
Comm::usage =
"Comm[A,B]
\n\t gives the commutator of A and B defined as AB-BA.";
CPHASE::usage=
"CPHASE[L,q1,q2]
\n\t Returns the CPHASE operator of q1 and q2 within L qubits.
\n Its action on twoqubits is |ab\[RightAngleBracket]-->(-)^(ab)|ab\[RightAngleBracket]
\n --same as ControlledZ.";
CPHASEV::usage=
"CPHASEV[q1,q2,A],
\n\t returns the CPHASE operated on the vector A, which should be a list of Lenght 2^n.";
EnTropy::usage="
EnTropy[\[Rho]],
\n\t gives the entropy of the system described by the
\n density matrix \[Rho]. Defined = -Tr[ \[Rho].Log[\[Rho],2]].";
\[ScriptCapitalH]::usage=
"The single qubit Hadamard--See Hadamard";
had::usage=
"had[L, q] where L=n_q is the total number of qubits
and q designates the single qubit on which a Hadamard acts--see Hadamard.";
Had::usage=
"see Hadamard.";
HALL::usage=
"HALL[L]
\n\t returns a Hadamard applied to each of the L qubits
\n of a L qubit system-see Hadamard.";
Hadamard::usage=
"Hadamard, had, Had, HALL:
\n\t \[ScriptCapitalH]
\n Hadamard acting on one qubit.
\n\t had[L,q] is a Hadamard acting on one qubit q out of L
\n qubits (use as had[1,1] or had[2,2]).
\n\t Had[L,Q] acts on all members of set
\n Q={q1,q2,...} of the L qubits, where qi>0 indicated that
\n the ith qubit is acted on by a Hadamard, whereas qj=0
\n designates that the jth qubit is acted on by a unit 2x2 operator.
\n\t For example, Had[3,{1,0,1}] has a Hadamard acting on
\n qubits 1 and 3 and a unit 2x2 acts on qubit 2.
\n To get a Hadamard acting on all qubits, include all
\n qubits in Q, e.g., use Q={1,1,1,....}.
\n\t HALL[L]=Had[L,{1,1,1....}] is also provided where
\n the array of 1's has length L of all the qubits";
\[DoubleStruckCapitalI]::usage="
\[DoubleStruckCapitalI]
\n returns the identity matrix for one qubit, 2x2.";
Ket::usage=
"Ket[0], Ket[1],
\n\t one qubit |0\[RightAngleBracket] and |1\[RightAngleBracket] state, respectively.";
Ket1::usage=
"Ket1[\[Theta],\[Phi]],
\n\t returns a general one qubit ket state of the form
\n =Cos[\[Theta]/2]*Exp[-\[ImaginaryI]*\[Phi]/2]*Ket[0]+Sin[\[Theta]/2]*Ket[1]*Exp[\[ImaginaryI]*\[Phi]/2] ";
KetX::usage=
"KetX[0], KetX[1],
\n\t one qubit |+\[RightAngleBracket], |-\[RightAngleBracket], states, respectively.
\n Eigenvectors of Sigma1.";
KetY::usage=
"KetY[0], KetY[1],
\n Eigenvectors of Sigma2.";
KetV::usage=
"KetV[a_] is a multi-qubit state vector ket,
\n\t variable a must be list of Length[a]=2^n. Example of
use, KetV[{0,1,1}]=(Ket[0]\[CircleTimes]Ket[1])\[CircleTimes]Ket[1].";
Bra::usage=
"Bra[0], Bra[1],
\n\t one qubit \[LeftAngleBracket]0|, \[LeftAngleBracket]1|, state, respectively.";
Bra1::usage=
"Bra1[\[Theta],\[Phi]],
\n\t returns a general one qubit bra state.";
BraX::usage=
"BraX[0], BraX[1],
\n\t one qubit \[LeftAngleBracket]+|, \[LeftAngleBracket]-|, respectively.";
BraV::usage=
"BraV[a_] is a multi-qubit state vector bra,
\n\t variable a must be list.
\n\t Example of use,
BraV[{a,b,c}]=(Bra[a]\[CircleTimes]Bra[b])\[CircleTimes]Bra[c],
with a,b and c {0,1}";
MeasureKet::usage=
"MeasureKet[V,M,MV],
\n\t Performs the measurement on qubits in list M={m1,..,mn},
\n with possible measured computational basis values input in list
\n MV={0,1,...0,0,1}, on the original ket V. The output is normalized
\n to 1.";
CompMeasureKet::usage=
"Precompiled version of MeasureKet.";
MultiProjCBasis::usage=
"MultiProjCbasis[{a1,a2,..,an}]
\n\t ai={0,1} builds the multi-qubit projector operator in the computational basis: \[ScriptCapitalP]a1 \[CircleTimes] \[ScriptCapitalP]an";
MultiQProj::usage=
"MultiQProj[{a1,a2,..,an},{b1,b2,...,bn}]
\n\t ai={0,1,2,3} and bi={0,1} builds the following multi-qubit projector
\n operator:
\n ai correspond to: (0) no measurement,(1) X, (2) Y and (3) Z.
\n bi correspond to the measured values in the same order.
\n The length of both lists should be the same. The values b
\n for the unmeasured qubits are not relevant.
\n
\n Example:
\n (((\[ScriptCapitalP]0 \[CircleTimes] \[DoubleStruckCapitalI])\[CircleTimes] PX[b])
\n
\n corresponds to MultiQProj[{3,0,1},{0,0,b}]
\n where the second 0 in the measured values matrix is
\n not taken into account.";
nq::usage =
"Returns the total number of qubits.";
nb::usage =
"Sets the basis to 2, i.e 0 and 1.";
Oracle::usage=
"Oracle[nqx,nqy,itype]
\n\nis an Oracle for nqx Qubits in x and nqy Qubits in y.
\n Oracle | x, y\[RightAngleBracket] = | x, y+f(x)\