# Basic Symbolic Quantum Mechanics with [SymPy](http://sympy.org)

We first load the IPython extensions that enable LaTeX-based mathematical printing 
of SymPy objects, and then import the quantum computing libraries from SymPy.


```
%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
```

<h2>Bras and Kets</h2>

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))
```

<h2>Operators</h2>

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(_)
```

6e54c8054ddb85b09d5e34b5c4ccc8675d551470
ipynb
Jupyter Notebook
flask/share/doc/ipython/examples/notebooks/sympy_quantum_computing.ipynb
nishanthibaskar/notejam
373328e124e74f3afe484110f7ce8415d0aaeabf
MIT
2018-09-24T13:45:40.000Z
2018-09-24T13:45:40.000Z
flask/share/doc/ipython/examples/notebooks/sympy_quantum_computing.ipynb
nishanthibaskar/notejam
373328e124e74f3afe484110f7ce8415d0aaeabf
MIT
flask/share/doc/ipython/examples/notebooks/sympy_quantum_computing.ipynb
nishanthibaskar/notejam
373328e124e74f3afe484110f7ce8415d0aaeabf
MIT
Qwen/Qwen-72B
1. YES
2. YES