#%autosave 0
%matplotlib inline
import sglib
reload(sglib)
from sglib import *
from sympy import Symbol
alpha = Symbol('alpha'); beta = Symbol('beta')
You can create a state using either the col()
or the
ket()
function. In both cases, the object that gets
created is a column vector.
col(1,0)
ket('+z')
When you use the col()
the parameters you give it are simply
the individual components of the column vector, separated by commas. The
vector can have any dimension. Here's one of dimension 4:
col(1,0,0,0)
The ket()
only takes a single parameter, and it needs to by
enclosed in quotes. It will recognize the basic electron states, and a
zero or one for the classical bit state.
ket('-y')
ket('0'), ket('1')
psi = 1/sqrt(2)*ket('+z') + 1/sqrt(2)*ket('-z')
fm = latex
fm = sg_latex
fm = sg_format_state(['+z','-z'], ',').format
Print(r'$\psi = %s$' % fm(psi))
string_tensor(2, ['0','1'], separator=',', D=False)
fs1 = sg_format_state(basis=['0', '1'], separator='').format
fs2 = sg_format_state(basis=['+z', '-z'], separator='').format
fs3 = sg_format_state(
basis=[r'\mathrm{Heads}', '\mathrm{Tails}'], separator='').format
Print('-----------------------------------------------------------')
psi = 1/sqrt(2)*col(1,0)+1/sqrt(2)*col(0,1)
Print('$\psi=%s$'%fs1(psi))
Print('$\psi=%s$'%fs2(psi))
Print('$\psi=%s$'%fs3(psi))
Print('-----------------------------------------------------------')
psi = 1/sqrt(2)*col(1,0)-1/sqrt(2)*col(0,1)
Print('$\psi=%s$'%fs1(psi))
Print('$\psi=%s$'%fs2(psi))
Print('$\psi=%s$'%fs3(psi))
Print('-----------------------------------------------------------')
psi = -1/sqrt(2)*col(1,0)+1/sqrt(2)*col(0,1)
Print('$\psi=%s$'%fs1(psi))
Print('$\psi=%s$'%fs2(psi))
Print('$\psi=%s$'%fs3(psi))
Print('-----------------------------------------------------------')
psi = -1/sqrt(2)*col(1,0)-1/sqrt(2)*col(0,1)
Print('$\psi=%s$'%fs1(psi))
Print('$\psi=%s$'%fs2(psi))
Print('$\psi=%s$'%fs3(psi))
Print('-----------------------------------------------------------')
psi = alpha*col(1,0) + beta*col(0,1)
Print('$\psi=%s$'%fs1(psi))
psi = alpha*col(1,0) - beta*col(0,1)
Print('$\psi=%s$'%fs1(psi))
psi = -alpha*col(1,0) + beta*col(0,1)
Print('$\psi=%s$'%fs1(psi))
psi = -alpha*col(1,0) - beta*col(0,1)
Print('$\psi=%s$'%fs1(psi))
#
# The Bell States
#
bell_1 = 1/sqrt(2)*TP(pZ,pZ) + 1/sqrt(2)*TP(mZ,mZ) # phi+
bell_2 = 1/sqrt(2)*TP(pZ,pZ) - 1/sqrt(2)*TP(mZ,mZ) # phi-
bell_3 = 1/sqrt(2)*TP(pZ,mZ) + 1/sqrt(2)*TP(mZ,pZ) # psi+ (Triplet)
bell_4 = 1/sqrt(2)*TP(pZ,mZ) - 1/sqrt(2)*TP(mZ,pZ) # psi- (Singlet)
#
# pick a format
#
fs = sg_format_state(basis=['+z', '-z'], separator=',').format
fs = sg_format_state(basis=['0', '1'], separator='').format
Print('Bell$_1 = %s$' %(fs(bell_1)))
Print('Bell$_2 = %s$' %(fs(bell_2)))
Print('Bell$_3 = %s$' %(fs(bell_3)))
Print('Bell$_4 = %s$' %(fs(bell_4)))
foo = 1/sqrt(2)
Print(r'$%s \rightarrow %s$' %(latex(foo), myltx(foo)))
foo = 1/sqrt(2)*col(1,1)
Print(r'$%s \rightarrow %s$' %(latex(foo), myltx(foo)))
foo = 1/sqrt(2)*mat(1,1,1,-1)
Print(r'$%s \rightarrow %s$' %(latex(foo), myltx(foo)))
foo = 1/sqrt(2)*col(alpha, beta)
Print(r'$%s \rightarrow %s$' %(latex(foo), myltx(foo)))
foo = 1/sqrt(2)*mat(1,1,1,-1)
Print(r'$%s \rightarrow %s$' %(latex(foo), myltx(foo)))
foo = 1/sqrt(2)*col(alpha, beta)
If there's a common denominator that not a root, then it's OK but it doesn't get reduced.
state = oo = 1/sqrt(2)*col(1,1)
M = OP(state,state)
Print(r'$%s \rightarrow %s$' %(latex(M), myltx(M)))
state = oo = 1/sqrt(2)*col(alpha, beta)
M = OP(state,state)
Print(r'$%s \rightarrow %s$' %(latex(M), myltx(M)))
And, numerators ...
foo = 2/sqrt(3)*mat(1,0,0,1)
Print(r'$%s \rightarrow %s$' %(latex(foo), myltx(foo)))
foo = sqrt(3)*mat(1,0,0,1)
Print(r'$%s \rightarrow %s$' %(latex(foo), myltx(foo)))
However, myltx() can't currently deal with the coefficient of a symbolic value
foo = 5/sqrt(2)
Print(r'$%s \rightarrow %s$' %(latex(foo), myltx(foo)))
foo = alpha/sqrt(2)
Print(r'$%s \rightarrow %s$' %(latex(foo), myltx(foo)))