
initially a = |0>+|1>, b = |0>
q a b p -> a b⊕a class TwoQubit:
0 0 0 0.5 0 0 0.5 def cnot(self):
1 0 1 0 1 '''Controlled NOT operation'''
2 1 0 0.5 1 0 self.onezero, self.oneone = self.oneone, self.onezero
3 1 1 1 1 0.5 return self
Using an array: Using names for the complex amplitudes:
q[0], q[1], q[2], q[3] zerozero, zeroone, onezero, oneone
swap q[2] and q[3] Python Quantum Computing simulator, Juliana Peña, 2011.