Skip to content

A Mathematica package for performing calculations involving matrices/vectors in the Dirac notation which is usually used in quantum mechanics/quantum computing.

License

Notifications You must be signed in to change notification settings

bernwo/BernDirac

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

BernDirac

Wolfram Language License: GPL v3 Platforms

BernDiracLogo

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.

Contact

Bernard Wo - [email protected]
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 escketesc. The allowed input for Ket[] is either 0 or 1 and the output for each case is as shown here:

In:Ket[0]
Out:{{1},{0}}

In:Ket[1]
Out:{{0},{1}}

Ket[] also supports multiple inputs, as long as they are 0 and 1.

In:Ket[1,1,0]
Out:Ket[1,1,0]

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 escbraesc. The allowed input for Bra[] is either 0 or 1 and the output for each case is as shown here:

In:Bra[0]
Out:{{1,0}}

In:Bra[1]
Out:{{0,1}}

Just like Ket[], Bra[] also supports multiple inputs, as long as they are 0 and 1.

In:Bra[1,1,0]
Out:Bra[1,1,0]

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 escc*esc to obtain the alias. Below, we show that works for multiple column vectors, row vectors, and square matrices.
Column vector

In:Ket[1]⊗Ket[1]⊗Ket[0]
Out:Ket[1]⊗Ket[1]⊗Ket[0]

Row vector

In:Bra[1]⊗Bra[1]⊗Bra[0]
Out:Bra[1,1,0]

Square matrix

In:Ket[0].Bra[0]⊗Ket[1].Bra[1] Out:Ket[0].Bra[0]⊗Ket[1].Bra[1]

DiracForm[]

DiracForm[] prints the vector or matrix using the Dirac notation. It works for column vectors, row vectors, and square matrices.
Column vector

In:αKet[0]⊗Ket[0]+βKet[1]⊗Ket[1]
Out:αKet[0]⊗Ket[0]+βKet[1]⊗Ket[1]

Row vector

In:αBra[0]⊗Bra[0]+βBra[1]⊗Bra[1]
Out:αBra[0]⊗Bra[0]+βBra[1]⊗Bra[1]

Square matrix

In:(αKet[0]⊗Ket[0]+βKet[1]⊗Ket[1]).(αBra[0]⊗Bra[0]+βBra[1]⊗Bra[1])
Out:(αKet[0]⊗Ket[0]+βKet[1]⊗Ket[1]).(αBra[0]⊗Bra[0]+βBra[1]⊗Bra[1])

In:{{a e+b g,a f+b h},{c e+d g,c f+d h}}
Out:{{a e+b g,a f+b h},{c e+d g,c f+d h}}

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 esc.CapitalPhiesc, and inputting subscript(s) can be achieved with ctrl+_.

In:Ket[FormalCapitalPhi_00]
Out:Ket[FormalCapitalPhi_00]

In:Ket[FormalCapitalPhi_01]
Out:Ket[FormalCapitalPhi_01]

In:Ket[FormalCapitalPhi_10]
Out:Ket[FormalCapitalPhi_10]

In:Ket[FormalCapitalPhi_11]
Out:Ket[FormalCapitalPhi_11]

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.

In:PartialTr[αKet[0,1,1].Bra[0,1,1]+βKet[1,1,0].Bra[1,1,0],{1}]
Out:PartialTr[αKet[0,1,1].Bra[0,1,1]+βKet[1,1,0].Bra[1,1,0],{1}]

In:PartialTr[αKet[0,1,1].Bra[0,1,1]+βKet[1,1,0].Bra[1,1,0],{1,3}]
Out:PartialTr[αKet[0,1,1].Bra[0,1,1]+βKet[1,1,0].Bra[1,1,0],{1,3}]

In:PartialTr[αKet[0,1,1].Bra[0,1,1]+βKet[1,1,0].Bra[1,1,0],{2,3}]
Out:PartialTr[αKet[0,1,1].Bra[0,1,1]+βKet[1,1,0].Bra[1,1,0],{2,3}]

Example

Applying bit-flip on one qubit in a system of 3 qubits

In:Example1
Out:Example1

Partial trace of a Bell state

In:Example2
Out:Example2

Density matrix after measuring one qubit in a Bell state

In:Example3
Out:Example3

Matrix exponential of the effective Hamiltonian of the spin states in a Mølmer-Sørensen gate

In:Example3
Out:Example3

Examples in Mathematica notebook
A Mathematica notebook .nb file showing some usage examples can be found in the Example folder.

Who am I and why did I create this package?

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.

TO-DO