# Examples for `sympy.physics.quantum` section


```
%matplotlib inline
from matplotlib import pyplot as plt
```


```
from sympy.physics.quantum import Commutator, Dagger, Operator, Ket, qapply
A = Operator('A')
B = Operator('B')
C = Operator('C')
D = Operator('D')
a = Ket('a')
comm = Commutator(A, B)
comm
```




    [A,B]




```
qapply(Dagger(comm*a)).doit()
```




    -<a|*(Dagger(A)*Dagger(B) - Dagger(B)*Dagger(A))




```
Commutator(C+B, A*D).expand(commutator=True)
```




    -[A,B]*D - [A,C]*D + A*[B,D] + A*[C,D]




```
from sympy.physics.quantum.qubit import Qubit
q = Qubit('0101')
q
```




    |0101>




```
q.flip(1)
```




    |0111>




```
Dagger(q)
```




    <0101|




```
ip = Dagger(q)*q
ip
```




    <0101|0101>




```
ip.doit()
```




    1




```
from sympy.physics.quantum.qubit import Qubit, measure_all
from sympy.physics.quantum.gate import H, X, Y, Z
from sympy.physics.quantum.qapply import qapply
c = H(0)*H(1)*Qubit('00')
c
```




    H(0)*H(1)*|00>




```
q = qapply(c)
measure_all(q)
```




    [(|00>, 1/4), (|01>, 1/4), (|10>, 1/4), (|11>, 1/4)]




```
from sympy.physics.quantum.qft import QFT
from sympy.physics.quantum.circuitplot import circuit_plot
```


```
fourier = QFT(0,3).decompose()
fourier
```




    SWAP(0,2)*H(0)*C((0),S(1))*H(1)*C((0),T(2))*C((1),S(2))*H(2)




```
circuit_plot(fourier, nqubits=3);
%mkdir -p './images'
plt.savefig('./images/fig1-circuitplot-qft.pdf', format='pdf')
```

92f2e01bbd7312ea534052cacf3f1998fb3d9366
ipynb
Jupyter Notebook
quantum_examples.ipynb
ProgZone/sympy-paper
b3b85809cc92d1fd588971f944abda9fa995a426
MIT
2016-03-27T06:55:25.000Z
2021-03-22T18:42:39.000Z
quantum_examples.ipynb
ProgZone/sympy-paper
b3b85809cc92d1fd588971f944abda9fa995a426
MIT
2016-03-17T03:08:15.000Z
2020-10-01T17:09:29.000Z
quantum_examples.ipynb
ProgZone/sympy-paper
b3b85809cc92d1fd588971f944abda9fa995a426
MIT
2016-03-17T16:02:22.000Z
2021-07-15T15:06:54.000Z
Qwen/Qwen-72B
1. YES
2. YES