A Wolfram Mathematica package for performing calculations involving matrices/vectors in the Dirac notation which is usually used in quantum mechanics/quantum computing. It utilises the built-in functions without predefined meanings, namely Ket[]
, Bra[]
, and CircleTimes[]
, along with their respective alias, | ⟩ ↔ escketesc
, ⟨ | ↔ escbraesc
and ⊗ ↔ escc*esc
.
The basis which this package works in is {|0⟩,|1⟩}, which is also known as the computational basis or the Z basis.
The package was written in Wolfram Mathematica version 12.2 in Windows 10 and it has zero dependencies.
Bernard Wo - [email protected]
Project Link: https://github.com/bernie-wu/BernDirac
Download BernDirac.wl and place it wherever you like. Then, in your Mathematica notebook, run the following line to load the package into your current Mathematica session:
Get[<path-to-BernDirac.wl>];
After loading BernDirac.wl into your Mathematica notebook session, the following additional functions become available to use:
The special quantities, namely the Bell states also become available to use via Ket[]
and Bra[]
(see section Bell states).
Ket[]
is used to denote a column vector. The alias | ⟩
for Ket[]
can be obtained with escketesc
.
The allowed input for Ket[]
is either 0
or 1
and the output for each case is as shown here:
Ket[]
also supports multiple inputs, as long as they are 0
and 1
.
Note that Ket[1,1,0]
is equivalent to Ket[1]⊗Ket[1]⊗Ket[0]
(see CircleTimes[]
).
Bra[]
is used to denote a row vector (i.e. | ⟩=(⟨ |)†
where †
denotes conjugate transpose). The alias ⟨ |
for Bra[]
can be obtained with escbraesc
.
The allowed input for Bra[]
is either 0
or 1
and the output for each case is as shown here:
Just like Ket[]
, Bra[]
also supports multiple inputs, as long as they are 0
and 1
.
Note that Bra[1,1,0]
is equivalent to Bra[1]⊗Bra[1]⊗Bra[0]
(see CircleTimes[]
).
The alias ⊗
for CircleTimes[]
, is used to denote the Kronecker product (sometimes also called Tensor product). Use escc*esc
to obtain the alias.
Below, we show that ⊗
works for multiple column vectors, row vectors, and square matrices.
Column vector
Row vector
Square matrix
DiracForm[]
prints the vector or matrix using the Dirac notation. It works for column vectors, row vectors, and square matrices.
Column vector
Row vector
Square matrix
By using the special letter capital dotted Φ
and subscripts, we can access the four Bell states using Ket[]
and Bra[]
. Note that the special dotted Φ
is known as FormalCapitalPhi in the documentation (for more information, see the formal letters section here).
The dotted Φ
alias can be accessed with esc.CapitalPhiesc
, and inputting subscript(s) can be achieved with ctrl+_
.
PartialTr[]
performs partial trace of a given system over the specified indices. This function takes 2 input arguments. The first input must be a density matrix (i.e. square matrix). The second input is a list of integer(s) indicating the indices where you would like to perform partial trace over.
Applying bit-flip on one qubit in a system of 3 qubits
Partial trace of a Bell state
Density matrix after measuring one qubit in a Bell state
Matrix exponential of the effective Hamiltonian of the spin states in a Mølmer-Sørensen gate
Examples in Mathematica notebook
A Mathematica notebook .nb file showing some usage examples can be found in the Example folder.
At the time of writing this I am a graduate student with homework assignments involved in heavy and tedious quantum mechanics calculations.
I created this Mathematica package to ease my life and since it helped me a tonne, I figured I should share this with the public too in case someone is also in the same boat as me.
I also know that there are other Mathematica packages out there that provides Dirac notation but those are too complicated to use for my taste, which is also partially why I made this package.
- Write better usage descriptions in BernDirac.wl.