{ "metadata": { "name": "", "signature": "sha256:1e001620e2c2f0855a54c2bb9fa8aade102dd4a3f1871ea836236ddf78b6f7b2" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "\n", "
\n", "I may end up also using it for documenting sglib functions.\n", "
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n",
"You can create a state using either the col()
or the\n",
"ket()
function. In both cases, the object that gets\n",
"created is a column vector."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"col(1,0)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ket('+z')"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"When you use the col()
the parameters you give it are simply\n",
"the individual components of the column vector, separated by commas. The\n",
"vector can have any dimension. Here's one of dimension 4:"
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"col(1,0,0,0)"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The ket()
only takes a single parameter, and it needs to by\n",
"enclosed in quotes. It will recognize the basic electron states, and a\n",
"zero or one for the classical bit state."
]
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ket('-y')"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"ket('0'), ket('1')"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "code",
"collapsed": false,
"input": [
"psi = 1/sqrt(2)*ket('+z') + 1/sqrt(2)*ket('-z')\n",
"fm = latex\n",
"fm = sg_latex\n",
"fm = sg_format_state(['+z','-z'], ',').format\n",
"Print(r'$\\psi = %s$' % fm(psi))\n"
],
"language": "python",
"metadata": {},
"outputs": []
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"
" ] }, { "cell_type": "code", "collapsed": false, "input": [ "string_tensor(2, ['0','1'], separator=',', D=False)" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "These all work (March 2015)" ] }, { "cell_type": "code", "collapsed": false, "input": [ "fs1 = sg_format_state(basis=['0', '1'], separator='').format\n", "fs2 = sg_format_state(basis=['+z', '-z'], separator='').format\n", "fs3 = sg_format_state(\n", " basis=[r'\\mathrm{Heads}', '\\mathrm{Tails}'], separator='').format\n", "Print('-----------------------------------------------------------')\n", "psi = 1/sqrt(2)*col(1,0)+1/sqrt(2)*col(0,1)\n", "Print('$\\psi=%s$'%fs1(psi))\n", "Print('$\\psi=%s$'%fs2(psi))\n", "Print('$\\psi=%s$'%fs3(psi))\n", "Print('-----------------------------------------------------------')\n", "psi = 1/sqrt(2)*col(1,0)-1/sqrt(2)*col(0,1)\n", "Print('$\\psi=%s$'%fs1(psi))\n", "Print('$\\psi=%s$'%fs2(psi))\n", "Print('$\\psi=%s$'%fs3(psi))\n", "Print('-----------------------------------------------------------')\n", "psi = -1/sqrt(2)*col(1,0)+1/sqrt(2)*col(0,1)\n", "Print('$\\psi=%s$'%fs1(psi))\n", "Print('$\\psi=%s$'%fs2(psi))\n", "Print('$\\psi=%s$'%fs3(psi))\n", "Print('-----------------------------------------------------------')\n", "psi = -1/sqrt(2)*col(1,0)-1/sqrt(2)*col(0,1)\n", "Print('$\\psi=%s$'%fs1(psi))\n", "Print('$\\psi=%s$'%fs2(psi))\n", "Print('$\\psi=%s$'%fs3(psi))\n", "Print('-----------------------------------------------------------')\n", "psi = alpha*col(1,0) + beta*col(0,1)\n", "Print('$\\psi=%s$'%fs1(psi))\n", "psi = alpha*col(1,0) - beta*col(0,1)\n", "Print('$\\psi=%s$'%fs1(psi))\n", "psi = -alpha*col(1,0) + beta*col(0,1)\n", "Print('$\\psi=%s$'%fs1(psi))\n", "psi = -alpha*col(1,0) - beta*col(0,1)\n", "Print('$\\psi=%s$'%fs1(psi))" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "code", "collapsed": false, "input": [ "#\n", "# The Bell States\n", "#\n", "bell_1 = 1/sqrt(2)*TP(pZ,pZ) + 1/sqrt(2)*TP(mZ,mZ) # phi+\n", "bell_2 = 1/sqrt(2)*TP(pZ,pZ) - 1/sqrt(2)*TP(mZ,mZ) # phi-\n", "bell_3 = 1/sqrt(2)*TP(pZ,mZ) + 1/sqrt(2)*TP(mZ,pZ) # psi+ (Triplet)\n", "bell_4 = 1/sqrt(2)*TP(pZ,mZ) - 1/sqrt(2)*TP(mZ,pZ) # psi- (Singlet)\n", "#\n", "# pick a format\n", "#\n", "fs = sg_format_state(basis=['+z', '-z'], separator=',').format\n", "fs = sg_format_state(basis=['0', '1'], separator='').format\n", "Print('Bell$_1 = %s$' %(fs(bell_1)))\n", "Print('Bell$_2 = %s$' %(fs(bell_2)))\n", "Print('Bell$_3 = %s$' %(fs(bell_3)))\n", "Print('Bell$_4 = %s$' %(fs(bell_4)))" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "
\n", "The following all work right as of 05 March 2015:" ] }, { "cell_type": "code", "collapsed": false, "input": [ "foo = 1/sqrt(2)\n", "Print(r'$%s \\rightarrow %s$' %(latex(foo), myltx(foo)))\n", "foo = 1/sqrt(2)*col(1,1)\n", "Print(r'$%s \\rightarrow %s$' %(latex(foo), myltx(foo)))\n", "foo = 1/sqrt(2)*mat(1,1,1,-1)\n", "Print(r'$%s \\rightarrow %s$' %(latex(foo), myltx(foo)))\n", "\n", "foo = 1/sqrt(2)*col(alpha, beta)\n", "Print(r'$%s \\rightarrow %s$' %(latex(foo), myltx(foo)))\n", "foo = 1/sqrt(2)*mat(1,1,1,-1)\n", "Print(r'$%s \\rightarrow %s$' %(latex(foo), myltx(foo)))\n", "foo = 1/sqrt(2)*col(alpha, beta)\n" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "If there's a common denominator that not a root, then it's OK\n", "but it doesn't get reduced." ] }, { "cell_type": "code", "collapsed": false, "input": [ "state = oo = 1/sqrt(2)*col(1,1)\n", "M = OP(state,state)\n", "Print(r'$%s \\rightarrow %s$' %(latex(M), myltx(M)))\n", "state = oo = 1/sqrt(2)*col(alpha, beta)\n", "M = OP(state,state)\n", "Print(r'$%s \\rightarrow %s$' %(latex(M), myltx(M)))" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "And, numerators ..." ] }, { "cell_type": "code", "collapsed": false, "input": [ "foo = 2/sqrt(3)*mat(1,0,0,1)\n", "Print(r'$%s \\rightarrow %s$' %(latex(foo), myltx(foo)))\n", "\n", "foo = sqrt(3)*mat(1,0,0,1)\n", "Print(r'$%s \\rightarrow %s$' %(latex(foo), myltx(foo)))" ], "language": "python", "metadata": {}, "outputs": [] }, { "cell_type": "markdown", "metadata": {}, "source": [ "However, myltx() can't currently deal with the coefficient of\n", "a symbolic value" ] }, { "cell_type": "code", "collapsed": false, "input": [ "foo = 5/sqrt(2)\n", "Print(r'$%s \\rightarrow %s$' %(latex(foo), myltx(foo)))\n", "foo = alpha/sqrt(2)\n", "Print(r'$%s \\rightarrow %s$' %(latex(foo), myltx(foo)))" ], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }