The doc string of sympy.physics.quantum.gate.CNOT contains:
"""
Two qubit controlled-NOT.

This gate performs the NOT or X gate on the target qubit if the control
qubits all have the value 1.
"""

Which I find slightly confusing.  Does this gate work on only two qubits as
the
first line indicates, or two sets of qubits, the control bits and the
singleton
target?

It *appears* that it only works on two qubits: a single control and a single
target.  However the method signatures and docs seem to indicate that it is
capable of
more.  I tried delving into the code, but got tangled up, so I thought I
would
just ask here instead.

There is example code below.  Can any one tell me if I'm reading the docs
wrong, or if CNOT is broken?


from sympy import Matrix
from sympy.physics.quantum import gate
from sympy.physics.quantum.qubit import Qubit
from sympy.physics.quantum.qapply import qapply

q = Qubit('111')
cn = gate.CNOT(2, 1, 0)
print(qapply(cn*q)) # |101> but I expected |011>, or possibly |110>

v = Matrix([0, 0, 0, 0, 0, 0, 0, 1])

## This matrix is equivalent to what the documentation implies CNOT(2, 1,
0) is
g = Matrix([[1, 0, 0, 0, 0, 0, 0, 0],
            [0, 1, 0, 0, 0, 0, 0, 0],
            [0, 0, 1, 0, 0, 0, 0, 0],
            [0, 0, 0, 0, 0, 0, 0, 1],
            [0, 0, 0, 0, 1, 0, 0, 0],
            [0, 0, 0, 0, 0, 1, 0, 0],
            [0, 0, 0, 0, 0, 0, 1, 0],
            [0, 0, 0, 1, 0, 0, 0, 0]])

print(repr(g*v)) # 0,0,0,1,0,0,0,0 which is equivalent to |011>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/sympy.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CADWsgYdkwv7cNN%2BeoT6gaN6Y%2BCsKnix9kWWSehKDacZc-%2B4U0A%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to