%load_ext sympyprinting
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
Create symbolic states
phi, psi = Ket('phi'), Ket('psi')
alpha, beta = symbols('alpha beta', complex=True)
Create a superposition
state = alpha*psi + beta*phi; state
Dagger the superposition and multiply the original
ip = Dagger(state)*state; ip
Distribute
qapply(expand(ip))
Create symbolic operators
A = Operator('A')
B = Operator('B')
C = Operator('C')
Test commutativity
A*B == B*A
False
Distribute A+B squared
expand((A+B)**2)
Create a commutator
comm = Commutator(A,B); comm
Carry out the commutator
comm.doit()
Create a more fancy commutator
comm = Commutator(A*B,B+C); comm
Expand the commutator
comm.expand(commutator=True)
Carry out and expand the commutators
_.doit().expand()
Take the dagger
Dagger(_)