Processing math: 100%
##// END OF EJS Templates
Fix in preparation for Python 3.3 compatibility....
r4739:c7f7b482
Show More
basic_quantum.ipynb
281 lines | 30.8 KiB | text/plain | TextLexer

Basic Symbolic Quantum Mechanics

In [18]:
%load_ext sympyprinting
In [19]:
from sympy import sqrt, symbols, Rational
from sympy import expand, Eq, Symbol, simplify, exp, sin
from sympy.physics.quantum import *
from sympy.physics.quantum.qubit import *
from sympy.physics.quantum.gate import *
from sympy.physics.quantum.grover import *
from sympy.physics.quantum.qft import QFT, IQFT, Fourier
from sympy.physics.quantum.circuitplot import circuit_plot

Bras and Kets

Create symbolic states

In [20]:
phi, psi = Ket('phi'), Ket('psi')
alpha, beta = symbols('alpha beta', complex=True)

Create a superposition

In [21]:
state = alpha*psi + beta*phi; state
Out[21]:
α|ψ+β|ϕ

Dagger the superposition and multiply the original

In [22]:
ip = Dagger(state)*state; ip
Out[22]:
(¯αψ|+¯βϕ|)(α|ψ+β|ϕ)

Distribute

In [23]:
qapply(expand(ip))
Out[23]:
α¯αψ|ψ+α¯βϕ|ψ+β¯αψ|ϕ+β¯βϕ|ϕ

Operators

Create symbolic operators

In [24]:
A = Operator('A')
B = Operator('B')
C = Operator('C')

Test commutativity

In [25]:
A*B == B*A
Out[25]:
False

Distribute A+B squared

In [26]:
expand((A+B)**2)
Out[26]:
AB+(A)2+BA+(B)2

Create a commutator

In [27]:
comm = Commutator(A,B); comm
Out[27]:
[A,B]

Carry out the commutator

In [28]:
comm.doit()
Out[28]:
ABBA

Create a more fancy commutator

In [29]:
comm = Commutator(A*B,B+C); comm
Out[29]:
[AB,B+C]

Expand the commutator

In [30]:
comm.expand(commutator=True)
Out[30]:
[A,B]B+[A,C]B+A[B,C]

Carry out and expand the commutators

In [31]:
_.doit().expand()
Out[31]:
ABC+A(B)2BABCAB

Take the dagger

In [32]:
Dagger(_)
Out[32]:
BABBAC+(B)2A+CBA