Quantum Basis and Quantum State 
(19)
 

In order to use QuantumBasis, one gives dimension information as arguments, which will be interpreted as the computational basis. Alternatively, an association can be given with the basis name as the key and the corresponding basis elements as the values.
———
Define a 2D quantum basis (computational):
In[1]:=
QuantumBasis[2]
Out[1]=
QuantumBasis
Picture: Schrödinger
Rank: 1
Dimension: 2
​

Given a basis of dimension
n
, the basis elements will be indexed by the key
|
i
〉
with
i0,1,…,n-1
:
In[2]:=
Normal/@%["ElementAssociation"]
Out[2]=
|0〉{1,0},|1〉{0,1}
———
Use
QuantumBasis[n,m]
to define a basis for m qudits of dimension n (for which the overall dimension will be
m
n
). For example, define a
2×2×2
-dimensional quantum basis (with three qubits):
In[1]:=
QuantumBasis[2,3]
Out[1]=
QuantumBasis
Picture: Schrödinger
Rank: 3
Dimension: 8
​

In[2]:=
%["Dimensions"]
Out[2]=
{2,2,2}
———
Use
QuantumBasis[{
n
1
,
n
2
,…,
n
m
}]
to define an
n
1
×
n
2
×
n
3
×…×
n
m
-dimensional Hilbert space of
m
qudits as a list. For example, define a
3×5
-dimensional quantum basis (with two qudits):
In[1]:=
QuantumBasis[{3,5}]
Out[1]=
QuantumBasis
Picture: Schrödinger
Rank: 2
Dimension: 15
​

———
A basis can also be defined as an association with the basis element names as keys and the corresponding vectors as values:
In[1]:=
QuantumBasis[<|a{1,},b{2,-}|>]
Out[1]=
QuantumBasis
Picture: Schrödinger
Rank: 1
Dimension: 2
​

In[2]:=
Normal/@%["ElementAssociation"]
Out[2]=
|a〉{1,},|b〉{2,-}
———
There are many 'named' bases built into the quantum framework, including "Computational", "PauliX", "PauliY", "PauliZ", "Fourier", "Identity", "Schwinger", "Pauli", "Dirac" and "Wigner":
In[1]:=
{QuantumBasis["Computational"],QuantumBasis["PauliX"],QuantumBasis["Schwinger"],QuantumBasis["Bell"],QuantumBasis["Dirac"]}
Out[1]=
QuantumBasis
Picture: Schrödinger
Rank: 1
Dimension: 2
​
,QuantumBasis
Picture: Schrödinger
Rank: 1
Dimension: 2
​
,QuantumBasis
Picture: Schrödinger
Rank: 2
Dimension: 4
​
,QuantumBasis
Picture: Schrödinger
Rank: 1
Dimension: 4
​
,QuantumBasis
Picture: Schrödinger
Rank: 2
Dimension: 16
​

After a basis object has been defined, it is straightforward to construct quantum states and operators. A quantum state is represented by a
QuantumState
object and a quantum operator is represented by
QuantumOperator
.
A pure quantum state is represented as a vector for which the elements are amplitudes. The corresponding basis should be given in this format:
QuantumState[
arg
1
,
arg
2
]
, where
arg
1
specifies amplitudes or the density matrix, and
arg
2
specifies the basis. With no basis specified, the default basis will be the computational basis, the dimension of which depends on the amplitude vector given in arg1.
Note that the big endian convention is in use, such that qubits are labeled left-to-right, starting with 1. For example, the decimal representation of
|
x
y
z
〉
(which means
|
x
〉
1
⊗
|
y
〉
2
⊗
|
z
〉
3
) is
0
2
x+
1
2
y+
2
2
z
. Additionally, for the eigenvalues of Pauli-Z, there is:
In[2]:=
Eigensystem[PauliMatrix[3]]
Out[2]=
{{-1,1},{{0,1},{1,0}}}
Denote the eigenstate {1,0} by
|0〉
(which corresponds to +1 eigenvalue), and {0,1} by
|1〉
(which corresponds to the eigenvalue -1).
———
Define a pure 2-dimensional quantum state (qubit) in the Pauli-X basis:
In[1]:=
QuantumState[{1,-1+},QuantumBasis["PauliX"]]
Out[1]=
QuantumState
Pure state
Qudits: 1
Type: Vector
Dimension: 2
Picture: Schrödinger
​

In[2]:=
%["Formula"]
Out[2]=

ψ
x
-
-(1-)
ψ
x
+

———
If the basis is not specified, the default is the computational basis of
n
2
dimensions (
n
qubits):
In[1]:=
state=QuantumState[{3,2,1,-5}]
Out[1]=
QuantumState
Pure state
Qudits: 2
Type: Vector
Dimension: 4
Picture: Schrödinger
​

In[2]:=
state["Amplitudes"]
Out[2]=
|00〉3,|01〉2,|10〉1,|11〉-5
———
If the vector has more than 2 elements, it is interpreted as an
n
-qubit state, unless the dimension is specified. If fewer than
n
2
amplitudes are specified, right-padding is applied to reach the
n
2
"ceiling":
In[1]:=
state=QuantumState[{2,0,}]
Out[1]=
QuantumState
Pure state
Qudits: 2
Type: Vector
Dimension: 4
Picture: Schrödinger
​

In[2]:=
state["Amplitudes"]
Out[2]=
|00〉2,|01〉0,|10〉,|11〉0
Here is the same amplitude vector, but this time with the dimension specified:
In[3]:=
state=QuantumState[{2,0,},3];​​state["Amplitudes"]
Out[4]=
|0〉2,|1〉0,|2〉
———
Binary strings can also be used as inputs:
In[1]:=
QuantumState["001"]
Out[1]=
QuantumState
Pure state
Qudits: 3
Type: Vector
Dimension: 8
Picture: Schrödinger
​

———
Many "named" states are available through the framework:
In[1]:=
{QuantumState[{"UniformSuperposition",4}],QuantumState["PsiPlus"],QuantumState["GHZ"]}
Out[1]=
QuantumState
Pure state
Qudits: 4
Type: Vector
Dimension: 16
Picture: Schrödinger
​
,QuantumState
Pure state
Qudits: 2
Type: Vector
Dimension: 4
Picture: Schrödinger
​
,QuantumState
Pure state
Qudits: 3
Type: Vector
Dimension: 8
Picture: Schrödinger
​

———
Using associations, one can create a superposition of states, where the keys are lists of corresponding indexes and the values are amplitudes.
Create a superposition of 3 qubits (i.e.
QuantumBasis[2,3]
as
1
2
(|000〉+|111〉)
):
In[1]:=
ψ=QuantumState<|{0,0,0}->
1
2
,{1,1,1}->
1
2
|>,2,3
Out[1]=
QuantumState
Pure state
Qudits: 3
Type: Vector
Dimension: 8
Picture: Schrödinger
​

In[2]:=
ψ["Formula"]
Out[2]=
|000〉
2
+
|111〉
2
In[3]:=
ψ["Dimensions"]
Out[3]=
{2,2,2}
A superposition can also be created by simply adding two quantum state objects. For example, the previous state can also be constructed as follows:
In[4]:=
ψ2=(QuantumState["000"]+QuantumState["111"])
2
;​​ψ==ψ2
Out[5]=
True
———
With a built-in basis specified, amplitudes correspond to the basis elements. For example, use the Bell basis:
A state can also be defined by inputting a density matrix:
For pure states, one can get the corresponding normalized state vector:
Define a generic Bloch vector:
Test to see if it is a mixed state:
Calculate its von Neumann entropy:
Compute its purity:
Note that one can directly use a Bloch vector as an input:
Test to see if a matrix is positive semidefinite:
A matrix that is not positive semidefinite cannot be a density matrix in standard quantum mechanics (with some exceptional cases, such as ZX formalism). Here is the result when it is attempted to define a state using such a matrix:
When a matrix is given as input but no basis is given, the default basis will be computational:
Define a quantum state in 8D Hilbert space (with one 8-dimensional qudit only):
Return the amplitudes:
Note that the states are the same, but defined in different bases: