BernDirac
A Mathematica package for performing calculations involving matrices/vectors in the Dirac notation which is usually used in quantum mechanics/quantum computing.
Install / Use
/learn @bernwo/BernDiracREADME
BernDirac
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, <code>| ⟩ ↔ <kbd>esc</kbd>ket<kbd>esc</kbd></code>, <code>⟨ | ↔ <kbd>esc</kbd>bra<kbd>esc</kbd></code> and <code>⊗ ↔ <kbd>esc</kbd>c*<kbd>esc</kbd></code>.
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.
Contact
Bernard Wo - bernardwu+BernDirac@outlook.my
Project Link: https://github.com/bernie-wu/BernDirac
How to use?
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>];
Functions that this package provides
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[]
Ket[] is used to denote a column vector. The alias | ⟩ for Ket[] can be obtained with <code><kbd>esc</kbd>ket<kbd>esc</kbd></code>.
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[]
Bra[] is used to denote a row vector (i.e. | ⟩=(⟨ |)† where † denotes conjugate transpose). The alias ⟨ | for Bra[] can be obtained with <code><kbd>esc</kbd>bra<kbd>esc</kbd></code>.
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[]).
CircleTimes[]
The alias ⊗ for CircleTimes[], is used to denote the Kronecker product (sometimes also called Tensor product). Use <code><kbd>esc</kbd>c*<kbd>esc</kbd></code> 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[]
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
Bell states
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 <code><kbd>esc</kbd>.CapitalPhi<kbd>esc</kbd></code>, and inputting subscript(s) can be achieved with <code><kbd>ctrl</kbd>+<kbd>_</kbd></code>.
PartialTr[]
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.
Example
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
.
commit-push-pr
82.9kCommit, push, and open a PR
