The purpose of this notebook is just to give a few examples of what you can do with multi-bit (actually 2 bit) operations in python. There is not a lot of tutorial commentary here, so if you haven't been following along with what we've done in the notebooks up to this point, it might not make too much sense. If you're interested in this, but don't get it, let me know. If could become the subject of a "lab" session in the future.
This goes with Section 9 of the notes.
Like always, you have to run the cell below to get the libraries included. The "autosave 0" line at the top prevents changes to the notebook from automatically being saved every few minutes. If you make changes you want to save you need to pull down the "File" menu and select "Save and Checkpoint"
I'm also importing a routine from one of the "sympy quantum" libraries, which prints out a bit state formatted as a ket.
%autosave 0
from sglib import *
from sympy.physics.quantum.qubit import matrix_to_qubit
Autosave disabled
I = mat(1,0,0,1)
NOT = X = sigma_x
H = mat(1,1,1,-1)/sqrt(2)
Print('$I = %s$' %myltx(I))
Print('$X = %s$' %myltx(X))
Print('$H = %s$' %myltx(H))
We didn't cover this in class. You don't need to worry about it right now.
H = 1/sqrt(2)*Matrix([(1,1),(1,-1)])
SN1 = 1/sqrt(2)*Matrix([(i,1),(1,i)])
SN2 = 1/sqrt(2)*Matrix([(1,i),(i,1)])
sg_print(H)
sg_print(SN1)
sg_print(SN2)
H*H, SN1*SN1, SN2*SN2, SN1*SN1*col(1,0)
So ... it appears that the "square root of not" only deserves that name in terms of the resulting probabilities. You can't actually square it to get a NOT matrix.
SWAP = mat(1,0,0,0, 0,0,1,0, 0,1,0,0, 0,0,0,1)
SWAP
a_1 = sy.Symbol('a_1'); a_2 = sy.Symbol('a_2');
b_1 = sy.Symbol('b_1'); b_2 = sy.Symbol('b_2')
a = col(a_1, a_2); b = col(b_1, b_2)
# NOTE: "TP" is the Tensor Product
state = TP(a,b)
Print('Before: $%s$'%latex(state))
Print('After : $%s$'%latex(SWAP*state))
zero = col(1,0); one = col(0,1)
state = TP(zero, one)
Print('SWAP $%s = %s$'
%(latex(matrix_to_qubit(state)), latex(matrix_to_qubit(SWAP*state))))
state = TP(one, zero)
Print('SWAP $%s = %s$'
%(latex(matrix_to_qubit(state)), latex(matrix_to_qubit(SWAP*state))))
CNOT = mat(1,0,0,0, 0,1,0,0, 0,0,0,1, 0,0,1,0)
CNOT
state = TP(zero, zero)
Print('CNOT $%s = %s$'
%(latex(matrix_to_qubit(state)), latex(matrix_to_qubit(CNOT*state))))
state = TP(zero, one)
Print('CNOT $%s = %s$'
%(latex(matrix_to_qubit(state)), latex(matrix_to_qubit(CNOT*state))))
state = TP(one, zero)
Print('CNOT $%s = %s$'
%(latex(matrix_to_qubit(state)), latex(matrix_to_qubit(CNOT*state))))
state = TP(one, one)
Print('CNOT $%s = %s$'
%(latex(matrix_to_qubit(state)), latex(matrix_to_qubit(CNOT*state))))