Dirac Notation in Mathematica

advertisement
Dirac Notation in Mathematica
by José Luis Gómez-Muñoz
http://homepage.cem.itesm.mx/lgomez/quantum/
jose.luis.gomez@itesm.mx
Introduction
This is a tutorial on the use of Quantum Mathematica add-on to enter kets, bras and other quantum objects in Dirac notation.
Load the Package
First load the Quantum`Notation` package. Write:
Needs["Quantum`Notation`"];
then press at the same time the keys ˜-Û to evaluate. Mathematica will load the package and print a welcome message:
Needs@"Quantum`Notation`"D
Quantum`Notation` Version 2.2.0. HJuly 2010L
A Mathematica package for Quantum calculations in Dirac bra−ket notation
by José Luis Gómez−Muñoz
Execute SetQuantumAliases@D in order to use
the keyboard to enter quantum objects in Dirac's notation
SetQuantumAliases@D must be executed again in each new
notebook that is created, only one time per notebook.
In order to use the keyboard to enter quantum objects write:
SetQuantumAliases[ ];
then press at the same time the keys ˜-Û to evaluate. Remember that SetQuantumAliases[ ] must be evaluated again in
each new notebook:
2
v7diracnotation.nb
SetQuantumAliases@D
ALIASES:
@ESCDket@ESCD
@ESCDbra@ESCD
@ESCDbraket@ESCD
@ESCDop@ESCD
@ESCD.@ESCD
@ESCDon@ESCD
@ESCDtp@ESCD
@ESCDqp@ESCD
@ESCDqs@ESCD
@ESCDsi@ESCD
@ESCDev@ESCD
@ESCDeket@ESCD
@ESCDeeket@ESCD
@ESCDeeeket@ESCD
@ESCDebra@ESCD
@ESCDeebra@ESCD
@ESCDeeebra@ESCD
@ESCDebraket@ESCD
@ESCDeebraket@ESCD
@ESCDeeebraket@ESCD
@ESCDketbra@ESCD
@ESCDeketbra@ESCD
@ESCDeeketbra@ESCD
@ESCDeeeketbra@ESCD
@ESCDher@ESCD
@ESCDcon@ESCD
@ESCDnorm@ESCD
@ESCDtrace@ESCD
@ESCDcomm@ESCD
@ESCDanti@ESCD
@ESCDsu@ESCD
@ESCDpo@ESCD
ket template
bra template
braket template
operator template
quantum concatenation infix symbol
quantum concatenation infix symbol
tensor product infix symbol
quantum product template
sigma notation for sums template
sigma notation for sums template
eigenvalue−label template
eigenstate template
two−operators−eigenstate template
three−operators−eigentstate template
bra of eigenstate template
bra of two−operators−eigenstate template
bra of three−operators−eigentstate template
braket of eigenstates template
braket of two−operators−eigenstates template
braket of three−operators−eigentstate template
operator HmatrixL element template
operator HmatrixL element template
operator HmatrixL element template
operator HmatrixL element template
hermitian conjugate template
complex conjugate template
quantum norm template
partial trace template
commutator template
anticommutator template
subscript template
power template
The quantum concatenation infix symbol @ESCDon@ESCD is
used for operator application, inner product and outer product.
SetQuantumAliases@D must be executed again in
each new notebook that is created, only one time per notebook.
Entering Kets, Bras and Brakets
In order to write a ket in Dirac's notation, place the cursor in a new Mathematica cell and press the keyboard keys:
[ESC]ket[ESC]
The ket template will appear. In order to select and fill in the "place holder" (square) press the keys:
[TAB] z
Finally press at the same time the keys[SHIFT] and[ENTER] to evaluate.
z\
z\
v7diracnotation.nb
In a similar way you can enter a bra:
[ESC]bra[ESC]
then press [TAB] and fill in the "place holder" (square) with label z:
Xz
Xz
Here is a braket:
[ESC]braket[ESC]
[TAB]a[TAB]b
Xa
b\
Xa
b\
The internal product of a bra and a ket is entered by pressing the keys:
[ESC]bra[ESC] [ESC]on[ESC] [ESC]ket[ESC]
press [TAB] one or two times to select the first "place holder" (square) and press:
a[TAB]b
finally press at the same time [SHIFT]-[ENTER]
Xa
⋅
Xa
b\
b\
Entering Kets of orthonormal states
In order to write the eigenket of operator p with eigenvalue 3, place the cursor in a new Mathematica cell and press the
keyboard keys:
[ESC]eket[ESC]
The eigenket template will appear. Next press the keys:
[TAB]3[TAB]p
Finally press at the same time the keys [SHIFT] and [ENTER] to evaluate:
3ˆp ]
3ˆp ]
In order to write the operator h acting on its eigenket with eigenvalue 3 press the keys:
[ESC]op[ESC] [ESC]on[ESC] [ESC]eket[ESC]
The operator and eigenket templates will appear. Next press [TAB] several times till the first place holder (square) is
selected. Then press the keys:
h[TAB]3[TAB]h
Finally press at the same time the keys [SHIFT] and [ENTER] to evaluate. The result of the calculation is the same ket
multiplied by its eigenvalue:
3
4
v7diracnotation.nb
ˆ
h⋅
3ˆh ]
3ˆh ]
3
In order to write a ket that is eigenket of two operators press the keys:
[ESC]eeket[ESC]
The corresponding eigenket template will appear. Next press the keys:
[TAB]3[TAB]p[TAB]1[TAB]c
Finally press at the same time the keys [SHIFT] and [ENTER] to evaluate.
3ˆp , 1ˆc ]
1ˆc , 3ˆp ]
Another example of an operator acting on its eigenket:
[ESC]op[ESC] [ESC]on[ESC] [ESC]eeeket[ESC]
The operator and eigenket templates will appear. Next press [TAB] several times till the first place holder (square) is
selected. Then press the keys:
b[TAB]2[TAB]c[TAB]3[TAB]a[TAB]4[TAB]b
Finally press at the same time the keys [SHIFT] and [ENTER] to evaluate. The result of the calculation is the same ket
multiplied by its eigenvalue:
ˆ
b⋅
4
2ˆc , 3ˆa , 4ˆb ]
3aˆ , 4ˆb , 2cˆ ]
In order to enter the bra that corresponds to an eigenket press:
[ESC]ebra[ESC]
then press [TAB] and fill in the first "place holder" (square) with 6. Press [TAB] again and fill in the second "place holder"
with m:
X6mˆ
X6mˆ
Next calculation gives one because eigenstates of the same operator are assumed to be orthonormal:
[ESC]ebra[ESC] [ESC]on[ESC] [ESC]eket[ESC]
Next press [TAB] several times till the first place holder (square) is selected. Then press:
2[TAB]m[TAB]2[TAB]m
X2mˆ
⋅
2mˆ \
1
Next calculation gives zero because eigenstates of the same operator are assumed to be orthonormal:
v7diracnotation.nb
X2mˆ
⋅
3mˆ \
0
This calculation gives a KroneckerDelta because eigenstates of the same operator are assumed to be orthonormal:
Xamˆ
⋅
bmˆ \
KroneckerDelta@a − bD
Here is a braket made of eigenstates
[ESC]eebraket[ESC]
[TAB]2[TAB]q[TAB]3[TAB]c[TAB]2[TAB]q[TAB]3[TAB]c
Y2ˆq , 3ˆc
2ˆq , 3ˆc ]
1
In order to write a tensor product of kets press the keys:
[ESC]eket[ESC] [ESC]on[ESC] [ESC]eket[ESC]
Next press[TAB] several times till the first place holder (square) is selected. Then press:
3[TAB]q[TAB]1[TAB]c
3ˆq ] ⋅
1ˆc ]
1ˆc , 3ˆq ]
Using tensor products you can generate a ket of any length:
2vˆ , 8ˆr , 9ˆt ] ⋅
5ˆa , 6ˆc ] ⋅
3ˆw , − 7ˆz , aˆf ]
5ˆa , 6ˆc , aˆf , 8ˆr , 9ˆt , 2ˆv , 3ˆw , H− 7Lˆz ]
You can apply an operator in a subspace to a ket of the space:
[ESC]eket[ESC] [ESC]on[ESC] [ESC]ebra[ESC] [ESC]on[ESC] [ESC]eeket[ESC]
Next press[TAB] several times till the first place holder (square) is selected.Then press:
a[TAB]q[TAB]j[TAB]q[TAB]0[TAB]c[TAB]j[TAB]q
and press at the same time[SHIFT]-[ENTER]
aˆq ] ⋅ Yjˆq
0ˆc , aˆq ]
⋅
0ˆc , jˆq ]
5
6
v7diracnotation.nb
Hermitian Conjugate
In order to calculate the Hermitian Conjugate of a ket press the keys:
[ESC]her[ESC] [TAB] [ESC]ket[ESC] [TAB]a
and press at the same time [SHIFT]-[ENTER]
H
a\L†
Xa
In order to calculate the Hermitian Conjugate of an expresion press the following keys (Notice that the imaginary i is entered
with two ii between two [ESC]):
[ESC]her[ESC][TAB]
(8+9[ESC]ii[ESC])*[ESC]eeket[ESC]+(5+7[ESC]ii[ESC])*[ESC]eeket[ESC]
Next press [TAB] several times till the first place holder (square) is selected. Then press:
0[TAB]c[TAB]3[TAB]q[TAB]1[TAB]c[TAB]-5[TAB]q
and press at the same time [SHIFT]-[ENTER]
IH8 + 9 L
0ˆc , 3ˆq ] + H5 + 7 L ∗
H8 − 9 L Y0ˆc , 3ˆq
1ˆc , − 5ˆq ]M
†
+ H5 − 7 L Y1ˆc , H− 5Lˆq
It also works in symbolic expressions
[ESC]her[ESC][TAB]
a[SPACE][ESC]ket[ESC]+[ESC]con[ESC][SPACE][ESC]ket[ESC]
Next press [TAB] several times till the first place holder (square) is selected. Then press:
x[TAB]b[TAB]y
and press at the same time [SHIFT]-[ENTER]
Ha
x\ + HbL∗
a∗ Xx
y\L
†
+ b Xy
Superpositions of Kets and Operators
This is the way to define a ket:
[ESC]ket[ESC]=a[ESC]eket[ESC]+b[ESC]eket[ESC]+c[ESC]eket[ESC]+d[ESC]eket[ESC]+e[ESC]eket[ESC]
Next press [TAB] several times till the first place holder (square) is selected. Then press:
[ESC]psi[ESC][TAB]1[TAB]q[TAB]2[TAB]q[TAB]3[TAB]q[TAB]4[TAB]q[TAB]5[TAB]q
finally press at the same time [SHIFT]-[ENTER]
ψ\ = a
a
1ˆq ] + b
1ˆq ] + b
2ˆq ] + c
2ˆq ] + c
3ˆq ] + d
3ˆq ] + d
4ˆq ] + e
4ˆq ] + e
5ˆq ]
5ˆq ]
v7diracnotation.nb
Mathematica calculates the corresponding bra:
[ESC]bra[ESC] [TAB] [ESC]psi[ESC]
finally press at the same time [SHIFT]-[ENTER]
Xψ
a∗ Y1ˆq
+ b∗ Y2ˆq
+ c∗ Y3ˆq
+ d∗ Y4ˆq
+ e∗ Y5ˆq
The internal product of a ket with its dual is a real number (square of its norm)
[ESC]bra[ESC] [ESC]on[ESC] [ESC]ket[ESC]
press [TAB] one or two times to select the first "place holder" (square) and press:
[ESC]psi[ESC] [TAB] [ESC]psi[ESC]
finally press at the same time [SHIFT]-[ENTER]
Xψ
⋅
ψ\
a a∗ + b b∗ + c c∗ + d d∗ + e e∗
Mathematica calculates the corresponding norm:
[ESC]norm[ESC] [TAB] [ESC]ket[ESC] [TAB] [ESC]psi[ESC]
finally press at the same time [SHIFT]-[ENTER]
∞
ψ\¥
a a∗ + b b∗ + c c∗ + d d∗ + e e∗
This external product is not immediately calculated:
ψ\ ⋅ Xψ
Ia
1ˆq ] + b
∗
Ia Y1qˆ
2ˆq ] + c
∗
+ b Y2qˆ
3ˆq ] + d
∗
+ c Y3qˆ
4ˆq ] + e
∗
+ d Y4qˆ
5ˆq ]M ⋅
∗
+ e Y5qˆ
M
The command Expand[] can be used to calculate the external product
Expand@
a a∗
da
ψ\ ⋅ Xψ D
1ˆq ] ⋅ Y1ˆq
∗
4ˆq ]
⋅
Y1ˆq
+ b a∗
+ea
2ˆq ] ⋅ Y1ˆq
∗
5ˆq ]
⋅
Y1ˆq
+ c a∗
+ab
3ˆq ] ⋅ Y1ˆq
∗
1ˆq ]
⋅
+
Y2ˆq
+
b b∗
2ˆq ] ⋅ Y2ˆq
+ c b∗
3ˆq ] ⋅ Y2ˆq
+ d b∗
4ˆq ] ⋅ Y2ˆq
+
e b∗
5ˆq ] ⋅ Y2ˆq
+ a c∗
1ˆq ] ⋅ Y3ˆq
+ b c∗
2ˆq ] ⋅ Y3ˆq
+ c c∗
3ˆq ] ⋅ Y3ˆq
+
d c∗
4ˆq ] ⋅ Y3ˆq
+ e c∗
5ˆq ] ⋅ Y3ˆq
+ a d∗
1ˆq ] ⋅ Y4ˆq
+ b d∗
2ˆq ] ⋅ Y4ˆq
+
c d∗
3ˆq ] ⋅ Y4ˆq
+ d d∗
4ˆq ] ⋅ Y4ˆq
+ e d∗
5ˆq ] ⋅ Y4ˆq
+ a e∗
1ˆq ] ⋅ Y5ˆq
+
2ˆq ] ⋅ Y5ˆq
∗
3ˆq ] ⋅ Y5ˆq
∗
4ˆq ] ⋅ Y5ˆq
∗
5ˆq ] ⋅ Y5ˆq
be
∗
+ce
+de
+ee
7
8
v7diracnotation.nb
Here we define another ket
[ESC]ket[ESC]=u[ESC]eket[ESC]+v[ESC]eket[ESC]+w[ESC]eket[ESC]+x[ESC]eket[ESC]+y[ESC]eket[ESC]
Next press [TAB] several times till the first place holder (square) is selected. Then press:
m[TAB]1[TAB]q[TAB]2[TAB]q[TAB]3[TAB]q[TAB]4[TAB]q[TAB]5[TAB]q
finally press at the same time [SHIFT]-[ENTER]
1ˆq ] + v
m\ = u
1ˆq ] + v
u
2ˆq ] + w
2ˆq ] + w
3ˆq ] + x
3ˆq ] + x
4ˆq ] + y
4ˆq ] + y
5ˆq ]
5ˆq ]
Note for advanced Mathematica users: The definition is stored as an upvalue of the variable m:
?m
Global`m
1ˆq ] + v
m\ ^= u
2ˆq ] + w
3ˆq ] + x
4ˆq ] + y
5ˆq ]
Here is an operator made of the states that were defined before:
Expand@
a u∗
ψ\ ⋅ Xm D
+ b u∗
1ˆq ] ⋅ Y1ˆq
du
∗
bv
∗
ev
∗
5qˆ ] ⋅ Y2qˆ
dw
∗
4ˆq ]
cx
∗
3ˆq ]
by
∗
2ˆq ]
4ˆq ] ⋅ Y1ˆq
2ˆq ] ⋅ Y2ˆq
⋅
Y3ˆq
⋅
Y4ˆq
⋅
Y5ˆq
2ˆq ] ⋅ Y1ˆq
+eu
∗
+cv
∗
+aw
∗
1qˆ ] ⋅ Y3qˆ
+ew
∗
5ˆq ]
+dx
∗
4ˆq ]
+cy
∗
3ˆq ]
5ˆq ] ⋅ Y1ˆq
3ˆq ] ⋅ Y2ˆq
⋅
Y3ˆq
⋅
Y4ˆq
⋅
Y5ˆq
+ c u∗
3ˆq ] ⋅ Y1ˆq
+
+av
∗
1ˆq ] ⋅ Y2ˆq
+
+dv
∗
4ˆq ] ⋅ Y2ˆq
+
+bw
∗
2qˆ ] ⋅ Y3qˆ
+ c w∗
+ax
∗
1ˆq ]
+ex
∗
5ˆq ]
+dy
∗
4ˆq ]
⋅
Y4ˆq
⋅
Y4ˆq
⋅
Y5ˆq
3qˆ ] ⋅ Y3qˆ
+
+bx
∗
2ˆq ]
⋅
Y4ˆq
+
+ay
∗
1ˆq ]
⋅
Y5ˆq
+
+ey
∗
5ˆq ]
⋅
Y5ˆq
ˆ
We can obtain the partial trace of the operator. The base-operator template is entered [ESC]op[ESC]:
QuantumPartialTraceA
ˆ
ψ\ ⋅ Xm , qE
a u∗ + b v∗ + c w∗ + d x∗ + e y∗
Here we apply the "base" operator q to the ket. Notice that q is inside the operator template [ESC]op[ESC]
ˆ
q⋅
a
ψ\
1ˆq ] + 2 b
2ˆq ] + 3 c
3ˆq ] + 4 d
4ˆq ] + 5 e
5ˆq ]
This is one way to define another operator. Notice that p is not inside the operator template:
v7diracnotation.nb
1qˆ ] ⋅ Y2qˆ
p=f
f
1ˆq ] ⋅ Y2ˆq
2qˆ ] ⋅ Y4qˆ
+g
2ˆq ] ⋅ Y4ˆq
+g
Now the operator and ket that were defined can be used. Notice that p is not inside the operator template:
p⋅
ψ\
bf
1ˆq ] + d g
2ˆq ]
Notice that p is not inside the operator template, but base operator q is inside the template:
ˆ
p⋅q⋅
ψ\
1ˆq ] + 4 d g
2bf
2ˆq ]
Hermitian conjugate
[ESC]her[ESC]
HpL†
f∗
2ˆq ] ⋅ Y1ˆq
+ g∗
4ˆq ] ⋅ Y2ˆq
An expression involving a bra, an operator and a ket:
Xψ
⋅p⋅
ψ\
b f a∗ + d g b∗
Another expression involving a bra, an operator and a ket:
Xψ
ˆ
⋅q⋅
ψ\
a a∗ + 2 b b∗ + 3 c c∗ + 4 d d∗ + 5 e e∗
Here is another operator :
ope = a
a
1ˆq , 3ˆs ] ⋅ Y1ˆq , 3ˆs
1qˆ , 3sˆ ] ⋅ Y1qˆ , 3sˆ
+b
+b
2ˆq , 4ˆs ] ⋅ Y3ˆq , 2ˆs
2qˆ , 4sˆ ] ⋅ Y3qˆ , 2sˆ
+c
+c
3ˆq , 5ˆs ] ⋅ Y4ˆq , 5ˆs
3qˆ , 5sˆ ] ⋅ Y4qˆ , 5sˆ
ˆ
Mathematica can calculate the partial trace with respect to operator q:
[ESC]trace[ESC]
9
10
v7diracnotation.nb
Trˆq @opeD
a
3ˆs ] ⋅ Y3ˆs
ˆ
Mathematica can calculate the partial trace with respect to operator s:
[ESC]trace[ESC]
Trˆs @opeD
a
1ˆq ] ⋅ Y1ˆq
+c
3ˆq ] ⋅ Y4ˆq
Undefined Symbols are Assumed to be Scalars
Any undefined name, like B, is assumed to be a complex scalar:
[ESC]her[ESC]
Clear@BD;
HXα ⋅ B ⋅
B∗ Xβ
β\L†
α\
SetQuantumObject[B] specifies that B is not a complex scalar:
SetQuantumObject@BD
The object B will Not be considered as a complex scalar
The object B@argsD will Not be considered as a complex scalar
The object Subscript@B, __D will Not be considered as a complex scalar
The object Subscript@B, __D@argsD will Not be considered as a complex scalar
The object Subscript@B@___D, __D will Not be considered as a complex scalar
The object Subscript@B@___D, __D@argsD will Not be considered as a complex scalar
After executing SetQuantumObject[B], B is considered an operator:
HXα
Xβ
⋅B⋅
⋅ B† ⋅
β\L†
α\
Finally we clear the definitions made in this document:
Clear@m, p, ope, ψ, BD
v7diracnotation.nb
11
ReplaceAll versus QuantumReplaceAll
ReplaceAll is a standard Mathematica command that can take advantage of the pattern recognitizion language of Mathematica. The "delayed rule" symbol ß can be entered by pressing the keys [ESC]:>[ESC]
φ\ + b
ReplaceAllBa
aH
0\ +
1\L
+b
ψ\,
φ\ H
0\ +
1\L í
2 F
ψ\
2
However, ReplaceAll will not make any replacement in the following case, because the expression φ\ ⊗ ψ\ evolves to
φ, ψ\, and the Mathematica command ReplaceAll does not recognize the ket φ\ in this evolved expression:
φ\ ⊗
ReplaceAllB
ψ\,
φ\ H
0\ +
1\L í
2 F
φ, ψ\
On the other hand, the Quantum Mathematica command QuantumReplace does recognize the ket and performs the
replacement:
QuantumReplaceB
0, ψ\ +
φ\ ⊗
ψ\,
φ\ H
0\ +
1\L í
2 F
1, ψ\
2
QuantumReplaceAll will also work on bras:
QuantumReplaceB
ψ\ ⋅ HX0
ψ\ ⋅ Xφ ,
φ\ H
0\ +
1\L í
2 F
+ X1 L
2
ExpandBQuantumReplaceB
ψ\ ⋅ X0
2
+
ψ\ ⋅ X1
2
ψ\ ⋅ Xφ ,
φ\ H
0\ +
1\L í
2 FF
12
v7diracnotation.nb
Questions and Exercises
1. What command is used to load the Quantum Notation package in a fresh Mathematica session?
Answer:
2. What command is used to load the Dirac Notation's keyboard aliases in a new Mathematica document (notebook)?
Answer:
3. Select the correct sentence. There is only one:
a) SetQuantumAliases[] must be executed after evaluating Needs["Quantum`Notation`"] in a fresh Mathematica session
b) SetQuantumAliases[] can be executed before evaluating Needs["Quantum`Notation`"] in a fresh Mathematica session
c) SetQuantumAliases[] must be executed before evaluating Needs["Quantum`Notation`"] in a fresh Mathematica session
The correct sentence is:_____
4. Select the correct sentence. There is only one:
a) SetQuantumAliases[] must be evaluated before executing each command in Mathematica
b) SetQuantumAliases[] must be evaluated in each new document (notebook) in Mathematica
c) SetQuantumAliases[] must be evaluated in each fresh session in Mathematica
The correct sentence is:_____
5. What combination of keys (keyboard alias) must be pressed in order to obtain the "CenterDot"
Answer:
6. Select the correct sentences for the Quantum Package. There is more than one correct sentence:
a) CenterDot · represents the internal product of a bra and a ket
b) CenterDot · represents the hermitian conjugate operation
c) CenterDot · represents the external product of a ket and a bra
d) CenterDot · represents the partial trace operation
e) CenterDot · represents the application of an operator to a ket
The correct sentences are:_____
7. What is the difference between
3\ y
3ˆA ] in the Quantum Mathematica Package?
Answer:
8. What differences are there between the Dirac notation as used in Quantum Mechanics textbooks and the notation used in
the Quantum Mathematica package?
Answer:
v7diracnotation.nb
13
9. What similarities are there between the Dirac notation as used in Quantum Mechanics textbooks and the notation used in
the Quantum Mathematica package?
Answer:
10. Why the following command generates an error message?
3\ =
a\ + b\
Why the following command does not generate the same error message?
m\ =
a\ + b\
Answer:
by José Luis Gómez-Muñoz
http://homepage.cem.itesm.mx/lgomez/quantum/
jose.luis.gomez@itesm.mx
Download