Quantum Computing 
Discrete Quantum Mechanics  Quantum Information & Computation 
Quantum computation is the use of quantum mechanical systems to perform computations. A classical computer uses a bit of either 0 or 1. In contrast, a quantum computer commonly uses a quantum bit (qubit) which can be both 0 and 1 at the same time. This package aims to classically simulate a quantum computer using the Wolfram Language.
Discrete Quantum Mechanics
QuantumBasis  basis vectors encoding quantum states and operators 
QuantumState  quantum discrete state, defined by an association, a complex vector, or a density matrix 
QuantumOperator  quantum discrete operator, defined by an association or a matrix representation 
QuantumMeasurementOperator  quantum measurement operator, defined by a matrix, a collection of positive matrices (POVM) or an eigenbasis (projective) 
QuantumMeasurement  description of possible measurement results, containing a probability distribution as well as possible quantum states after the measurement 
Basic objects of discrete quantum mechanics.
A fundamental object in our framework is QuantumBasis. Quantum states and operators can be defined with respect to a basis. QuantumBasis can be constructed for any number of qudits, with any dimensionality. There are also a set of named basis (e.g., PauliX or Bell) builtin into the quantum framework.
Define a quantum basis by an association:
In[80]:=
QuantumBasis 
Out[80]=
QuantumBasis

There are many namedbasis built into the framework:
In[81]:=
["Computational"],
["PauliY"],
["Bell"],
["Dirac"]
QuantumBasis 
QuantumBasis 
QuantumBasis 
QuantumBasis 
Out[81]=
QuantumBasis
,QuantumBasis
,QuantumBasis
,QuantumBasis




There are many properties that can be extracted from object. For example:
QuantumBasis
In[84]:=
basis=
["Computational"];Normal/@basis["ElementAssociation"]
QuantumBasis 
Out[85]=
0〉{1,0},1〉{0,1}
With no name as the basis, it will be treated as computational:
In[402]:=
QuantumBasis 
QuantumBasis 
Out[402]=
True
QuantumBasis
2×3
In[89]:=
Normal/@
[{2,3}]["ElementAssociation"]
QuantumBasis 
Out[89]=
00〉{{1,0,0},{0,0,0}},01〉{{0,1,0},{0,0,0}},02〉{{0,0,1},{0,0,0}},10〉{{0,0,0},{1,0,0}},11〉{{0,0,0},{0,1,0}},12〉{{0,0,0},{0,0,1}}
QuantumBasis
In[405]:=
Normal/@
[3]["ElementAssociation"]
QuantumBasis 
Out[405]=
0〉{1,0,0},1〉{0,1,0},2〉{0,0,1}
After a basis objects has been defined, it is straightforward to use the basis to construct state and operator. A quantum state is represented by object and a quantum operator is represented by .
QuantumState
QuantumOperator
Define a pure 2dimensional quantum state (qubit) in PauliX basis:
In[14]:=
QuantumState 
QuantumBasis 
Out[14]=
QuantumState

If the basis is not specified, the default is the computational basis:
In[408]:=
state=
[{1/Sqrt[2],0,0,1/Sqrt[2]}];Normal/@state["Basis"]["ElementAssociation"]
QuantumState 
Out[409]=
00〉{{1,0},{0,0}},01〉{{0,1},{0,0}},10〉{{0,0},{1,0}},11〉{{0,0},{0,1}}
The default dimensionality is 2. Therefore, if the vector has more than 2 elements, it is interpreted as a multiqubit state. But, one may change the dimensionality as follows:
In[18]:=
state=
[{1/Sqrt[2],0,0,1/Sqrt[2]},4]
QuantumState 
Out[18]=
QuantumState

Within the package, many named states are available for easy access:
In[19]:=
["UniformSuperposition"],
["PsiPlus"],
["GHZ"]
QuantumState 
QuantumState 
QuantumState 
Out[19]=
QuantumState
,QuantumState
,QuantumState



We can also define a mixed state by inputting a density matrix:
In[410]:=
QuantumState 
Out[410]=
QuantumState

There are many properties that can be extracted from . For example:
QuantumState
In[411]:=
state=
["PhiMinus"];state["Amplitudes"]state["DensityMatrix"]state["Formula"]
QuantumState 
Out[412]=
00,010,100,11
1
2
1
2
Out[413]=
,0,0,,{0,0,0,0},{0,0,0,0},,0,0,
1
2
1
2
1
2
1
2
Out[414]=
00〉
2
11〉
2
Define a quantum operator by a matrix, basis, and order. The order is the information about which subsystems the operator would act on. For example order {1,2} means it would act on subsystem 1 and 2. If the basis is not specified, the default is the computational basis.
In[416]:=
QuantumOperator 
Out[416]=
QuantumOperator

Define operator by names:
In[417]:=
["H",{2}],
["CNOT"],
["Toffoli"]
QuantumOperator 
QuantumOperator 
QuantumOperator 
Out[417]=
QuantumOperator
,QuantumOperator
,QuantumOperator



Extract properties of operator:
In[418]:=
operator=
["CNOT",{1,2}];operator["MatrixRepresentation"]operator["HermitianQ"]
QuantumOperator 
Out[419]=
{{1,0,0,0},{0,1,0,0},{0,0,0,1},{0,0,1,0}}
Out[420]=
True
QuantumOperator
QuantumState
In[425]:=
QuantumOperator 
QuantumState 
Define a measurement operator by a matrix and an order (in computational basis):
Define measurement operator by names:
Define a POVM measurement:
Extract various properties of a QuantumMeasurementOperator:
We can also extract the possible states after measurement (postmeasurement states) by:
The second method is by defining a multiqubit basis and use it as the eigenbasis of the measurement. In this case, a list of eigenvalues is also needed:
Tensor product of states and bases:
Tensor product of operators (QuantumOperator or QuantumMeasurementOperator):
Basis change for a quantum state:
Basis change for a quantum operator:
One can do algebraic operations on quantum operators and the result will be a QuantumOperator:
The Berkeley B operator:
One can easily construct new quantum operator from composition of different operators:
SWAP.ControlledU.SWAP means a an upside down controlledU operator (switching control and target):
Quantum Information & Computation
Basic objects and operations in discrete quantum mechanics naturally lead to an application in quantum information and computation. Quantum Information is the study of information encoded in quantum systems. Meanwhile, quantum computation is the manipulation of quantum information to perform a computation.
Trace out the second subsystem in a twoqubit state:
Example of partial transpose:
Checking whether a subsystem 1 and 3 is entangled in "W" state:
Measuring trace distance between a pure state and a mixed state:
Example of Schmidt decomposition:
Example of spectral decomposition:
Example for the construction of quantum circuit without measurement:
Add measurement into the circuit:
Define the quantum operator v as the squareroot of u:
Construct the decomposition circuit:
Decomposition of CNOT:
A quantum gate for the magic basis transformation (transforming 2 qubit computational basis to the Bell basis):
A quantum gate with many control and targets
Example of a rewrite rule that eliminates a CNOT gate.: