Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1396 from gdevanla/trace_permute_equals
Tr printing, Tr partial trace
- Loading branch information
Showing
14 changed files
with
792 additions
and
58 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Original file line | Diff line number | Diff line change |
---|---|---|---|
@@ -0,0 +1,264 @@ | |||
{ | |||
"metadata": { | |||
"name": "trace" | |||
}, | |||
"nbformat": 2, | |||
"worksheets": [ | |||
{ | |||
"cells": [ | |||
{ | |||
"cell_type": "code", | |||
"collapsed": true, | |||
"input": [ | |||
"from sympy import symbols", | |||
"from sympy.core.trace import Tr", | |||
"from sympy.matrices.matrices import Matrix", | |||
"from IPython.core.display import display_pretty", | |||
"from sympy.printing.latex import *", | |||
"", | |||
"%load_ext sympyprinting" | |||
], | |||
"language": "python", | |||
"outputs": [], | |||
"prompt_number": 2 | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"source": [ | |||
"###Basic Examples" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": true, | |||
"input": [ | |||
"a, b, c, d = symbols('a b c d'); ", | |||
"A, B = symbols('A B', commutative=False)", | |||
"t = Tr(A*B)" | |||
], | |||
"language": "python", | |||
"outputs": [], | |||
"prompt_number": 3 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"t" | |||
], | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"latex": [ | |||
"$$\\mbox{Tr}\\left(A B\\right)$$" | |||
], | |||
"output_type": "pyout", | |||
"prompt_number": 4, | |||
"text": [ | |||
"Tr(A\u22c5B)" | |||
] | |||
} | |||
], | |||
"prompt_number": 4 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"latex(t)" | |||
], | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"output_type": "pyout", | |||
"prompt_number": 5, | |||
"text": [ | |||
"\\mbox{Tr}\\left(A B\\right)" | |||
] | |||
} | |||
], | |||
"prompt_number": 5 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"display_pretty(t)" | |||
], | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"output_type": "display_data", | |||
"text": [ | |||
"Tr(\u03c1((\u27581,1\u27e9, 0.5),(\u27581,-1\u27e9, 0.5)))" | |||
] | |||
} | |||
], | |||
"prompt_number": 14 | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"source": [ | |||
"### Using Matrices" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": true, | |||
"input": [ | |||
"t = Tr ( Matrix([ [2,3], [3,4] ]))" | |||
], | |||
"language": "python", | |||
"outputs": [], | |||
"prompt_number": 15 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"t" | |||
], | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"latex": [ | |||
"$$6$$" | |||
], | |||
"output_type": "pyout", | |||
"png": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAASCAYAAABvqT8MAAAABHNCSVQICAgIfAhkiAAAAO5JREFU\nKJHN0r1KQ0EQhuHnhAgBhaiIFpLOxs5O8CIsFG/A1spCL0CwsUtnaat4C7aWNooiCAEJKBb+oMGg\nSCzOHlyWlWDnV+3M7vvN7O7wRxWZXAs7+MIL3rCHXs5gGh0shXgS19isDtQSYB9tnIa4jgZec+5r\n+MD4sHtUOsTlsEP1aL2AeyxiGbNoYgs3KTiqfJVzbET5FTxhLgVmMEAfY1G+FqoepcBIAC4ybZ8p\n/6KoHOATd6F8ql5oeSIG4ARTGaCBLh7TjVW8V05BBZ5xkDECx9j1M2PruIpN0uFrYhvzofcH5ajc\n/lbhH+gb6f4rZTpaz0QAAAAASUVORK5CYII=\n", | |||
"prompt_number": 16, | |||
"text": [ | |||
"6" | |||
] | |||
} | |||
], | |||
"prompt_number": 16 | |||
}, | |||
{ | |||
"cell_type": "markdown", | |||
"source": [ | |||
"### Example using modules in physics.quantum" | |||
] | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": true, | |||
"input": [ | |||
"from sympy.physics.quantum.density import Density", | |||
"from sympy.physics.quantum.spin import (", | |||
" Jx, Jy, Jz, Jplus, Jminus, J2,", | |||
" JxBra, JyBra, JzBra,", | |||
" JxKet, JyKet, JzKet,", | |||
")" | |||
], | |||
"language": "python", | |||
"outputs": [], | |||
"prompt_number": 7 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"d = Density([JzKet(1,1),0.5],[JzKet(1,-1),0.5]); d" | |||
], | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"latex": [ | |||
"$$\\rho\\left(\\begin{pmatrix}{\\left|1,1\\right\\rangle }, & 0.5\\end{pmatrix},\\begin{pmatrix}{\\left|1,-1\\right\\rangle }, & 0.5\\end{pmatrix}\\right)$$" | |||
], | |||
"output_type": "pyout", | |||
"prompt_number": 8, | |||
"text": [ | |||
"\u03c1((\u27581,1\u27e9, 0.5),(\u27581,-1\u27e9, 0.5))" | |||
] | |||
} | |||
], | |||
"prompt_number": 8 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": true, | |||
"input": [ | |||
"t = Tr(d)" | |||
], | |||
"language": "python", | |||
"outputs": [], | |||
"prompt_number": 9 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"t" | |||
], | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"latex": [ | |||
"$$\\mbox{Tr}\\left(\\rho\\left(\\begin{pmatrix}{\\left|1,1\\right\\rangle }, & 0.5\\end{pmatrix},\\begin{pmatrix}{\\left|1,-1\\right\\rangle }, & 0.5\\end{pmatrix}\\right)\\right)$$" | |||
], | |||
"output_type": "pyout", | |||
"prompt_number": 10, | |||
"text": [ | |||
"Tr(\u03c1((\u27581,1\u27e9, 0.5),(\u27581,-1\u27e9, 0.5)))" | |||
] | |||
} | |||
], | |||
"prompt_number": 10 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"latex(t)" | |||
], | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"output_type": "pyout", | |||
"prompt_number": 11, | |||
"text": [ | |||
"", | |||
"\\mbox{Tr}\\left(\\rho\\left(\\begin{pmatrix}{\\left|1,1\\right\\rangle }, & 0.5\\end{p", | |||
"matrix},\\begin{pmatrix}{\\left|1,-1\\right\\rangle }, & 0.5\\end{pmatrix}\\right)\\r", | |||
"ight)" | |||
] | |||
} | |||
], | |||
"prompt_number": 11 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": false, | |||
"input": [ | |||
"t.doit()" | |||
], | |||
"language": "python", | |||
"outputs": [ | |||
{ | |||
"latex": [ | |||
"$$1.0$$" | |||
], | |||
"output_type": "pyout", | |||
"png": "iVBORw0KGgoAAAANSUhEUgAAABsAAAASCAYAAACq26WdAAAABHNCSVQICAgIfAhkiAAAASNJREFU\nOI3t1EErBGEcx/HPimLXgUiU5eKinGxyc8KLkLeDK+WqpChcpJQjBxc33JALsgfFwYrEOsws0za7\nBpOT3+U/z/eZZ77PMzPPwx8mU4P3Yg8DCZ/TjDlkUQzbqziuNyiHSZyinFAEy1iLtMdxja5aAwax\nhVkcfEPWjxdMVPErrCSdaVLZPB4Fry6aJdyioQIa/D4FXOKpip+jA0NpyrrxEMNLYe1JW1aK4RXW\nlqbsGW8xvCmsH31pyE5q8FxYb9KUHaM9hreGtZi2LB/DR3Av+FN/JcujJbw+EqxsNNLfiDEsCr5p\n3WwLNnXccVPAK3bDdgab2PA5+SnBduisJejCPs5CURl3OMR05L4+XGAmwrKCk2QdC9jB8Fcr+s+P\n8g572TfbrLZhHwAAAABJRU5ErkJggg==\n", | |||
"prompt_number": 12, | |||
"text": [ | |||
"1.00000000000000" | |||
] | |||
} | |||
], | |||
"prompt_number": 12 | |||
}, | |||
{ | |||
"cell_type": "code", | |||
"collapsed": true, | |||
"input": [], | |||
"language": "python", | |||
"outputs": [], | |||
"prompt_number": 12 | |||
} | |||
] | |||
} | |||
] | |||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.