%autosave 0 from sglib import * from sympy.physics.quantum.qubit import matrix_to_qubit 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)) 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) 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))))