Sage: Vectors Over the Symbolic Ring ==================================== >>> from sage.all import * # doctest: +SKIP >>> from qitensor import qubit, set_qitensor_printoptions # doctest: +SKIP >>> # use Sage's nice array formatting >>> set_qitensor_printoptions(str_use_sage=True) # doctest: +SKIP >>> ha = qubit('a', dtype=SR) # doctest: +SKIP >>> hb = qubit('b', dtype=SR) # doctest: +SKIP >>> (x, y) = var('x y') # doctest: +SKIP >>> s = ha.array([1, x]) # doctest: +SKIP >>> t = hb.array([1, y]) # doctest: +SKIP >>> s*t # doctest: +SKIP HilbertArray(|a,b>, [ 1] [ y] [---] [ x] [x*y]) >>> # density operator >>> (s*t).O # doctest: +SKIP HilbertArray(|a,b>>> # density operator with ``ha`` traced out >>> (s*t).O.trace(ha) # doctest: +SKIP HilbertArray(|b>>> # there is no entanglement for this separable state >>> (s*t).O.trace(ha).entropy(normalize=True) # doctest: +SKIP 0 >>> # this however is an entangled state >>> (ha*hb).array([[1/sqrt(5),0],[0,2/sqrt(5)]]).O.trace(ha).entropy() # doctest: +SKIP -1/5*log(1/5)/log2 - 4/5*log(4/5)/log2 >>> # The entropy from a symbolic expression is a big mess. This expression >>> # has been verified numerically, but simplify_full() gives something >>> # which does not match numerically. >>> (ha*hb).array([[1,1],[1,exp(I*pi*x)]]).normalized().O.trace(ha).entropy(checks=False) # doctest: +SKIP 1/4*((e^(I*pi*x) + 1)*sqrt(e^(I*pi*x)) - 2*e^(I*pi*x))*e^(-I*pi*x)*log(-1/4*((e^(I*pi*x) + 1)*sqrt(e^(I*pi*x)) - 2*e^(I*pi*x))*e^(-I*pi*x))/log2 - 1/4*((e^(I*pi*x) + 1)*sqrt(e^(I*pi*x)) + 2*e^(I*pi*x))*e^(-I*pi*x)*log(1/4*((e^(I*pi*x) + 1)*sqrt(e^(I*pi*x)) + 2*e^(I*pi*x))*e^(-I*pi*x))/log2 >>> U = (ha * hb).eye() # doctest: +SKIP >>> # arrays can be indexed using dictionaries >>> U[{ ha: 0, ha.H: 0, hb: 0, hb.H: 0 }] = x # doctest: +SKIP >>> U[{ ha: 0, ha.H: 0, hb: 0, hb.H: 1 }] = y # doctest: +SKIP >>> U # doctest: +SKIP HilbertArray(|a,b>>> U.I # doctest: +SKIP HilbertArray(|a,b>>> U * U.I # doctest: +SKIP HilbertArray(|a,b>>> ((U ** 3) * (U ** -3)).simplify_full() # doctest: +SKIP HilbertArray(|a,b>>> M = ha.O.array([[1,1],[1,x]]) # doctest: +SKIP >>> (W, V) = M.eig() # doctest: +SKIP >>> W # doctest: +SKIP HilbertArray(|a>>> V # doctest: +SKIP HilbertArray(|a>>> (V.H * M * V - W).apply_map(lambda s: s.subs({x: 123})).simplify_full() # doctest: +SKIP HilbertArray(|a>>> (V.H * V).apply_map(lambda s: s.subs({x: 123})).simplify_full() # doctest: +SKIP HilbertArray(|a>