Skip to content
This repository

Tr printing, Tr partial trace #1396

Merged
merged 14 commits into from almost 2 years ago

10 participants

Guru Devanla Stefan Krastanov Don't Add Me To Your Organization a.k.a The Travis Bot Ondřej Čertík Aaron Meurer Sean Vig Brian E. Granger Julien Rioux Aleksandar Makelov Christopher Smith
Guru Devanla

This PR implements printing operations for Tr operators and partial trace operations. Also cycle permutes are fixed for consistency. Some changes added to Density class to enable partial trace operations. Also, new set of Notebook examples have been provided.

@ellisonbg , @flacjacket, could you please review the design.

Guru Devanla

The printing currently does not print out the indices that are provided as part of object creation. We need to figure out a way to output this along with all other arguments to Tr. Should it just be a [list] displayed after all other arguments to Tr or some super-script/subscript?

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYm5seDA

Interpreter: /opt/pym32/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (32-bit)
Cache: yes
Test command: setup.py test
master hash: d136cb7
branch hash: 11bb365

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYxYseDA

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: d136cb7
branch hash: 11bb365

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYqJMeDA

Interpreter: /usr/bin/python3 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: d136cb7
branch hash: 11bb365

Automatic review by SymPy Bot.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 11bb3652 into d136cb7).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged ed384052 into d136cb7).

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 88eed960 into d136cb7).

Ondřej Čertík
Owner
certik commented July 02, 2012

@gdevanla, there are failures caused by your pull request:

________________________________________________________________________________
2575____________ sympy/physics/quantum/tests/test_density.py:test_doit _____________
2576  File "/home/vagrant/virtualenv/python2.5/lib/python2.5/site-packages/sympy/physics/quantum/tests/test_density.py", line 49, in test_doit
2577    assert d.doit() == (1.0*A*C*Dagger(C)*Dagger(A) +
2578  File "/home/vagrant/virtualenv/python2.5/lib/python2.5/site-packages/sympy/physics/quantum/density.py", line 167, in doit
2579    for arg in itertools.product(state.args, repeat=2):
2580AttributeError: 'module' object has no attribute 'product'
2581________________________________________________________________________________
2582______ sympy/physics/quantum/tests/test_tensorproduct.py:test_eval_trace _______
2583  File "/home/vagrant/virtualenv/python2.5/lib/python2.5/site-packages/sympy/physics/quantum/tests/test_tensorproduct.py", line 94, in test_eval_trace
2584    assert t.doit() == ( 1.0*Tr(A*Dagger(A))*Tr(B*Dagger(B)) +
2585  File "/home/vagrant/virtualenv/python2.5/lib/python2.5/site-packages/sympy/core/trace.py", line 146, in doit
2586    return self.args[0]._eval_trace(indices=self.args[1])
2587  File "/home/vagrant/virtualenv/python2.5/lib/python2.5/site-packages/sympy/physics/quantum/density.py", line 193, in _eval_trace
2588    return Tr(self.doit(), indices).doit()
2589  File "/home/vagrant/virtualenv/python2.5/lib/python2.5/site-packages/sympy/physics/quantum/density.py", line 167, in doit
2590    for arg in itertools.product(state.args, repeat=2):
2591AttributeError: 'module' object has no attribute 'product'

Only the last failure was already in master, and the pull request #1398 fixes that one.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYnJseDA

Interpreter: /opt/pym32/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (32-bit)
Cache: yes
Test command: setup.py test
master hash: 9ba3cb3
branch hash: 88eed96

Automatic review by SymPy Bot.

Guru Devanla

Ok, the error message is since itertools.product is not supported in Python 2.5 Will fix that soon.

Aaron Meurer
Owner

There's probably a replacement in the compatibility file.

Aaron Meurer
Owner

I'm curious why the trace stuff is in the core.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY8fsdDA

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 9ba3cb3
branch hash: 88eed96

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYlekeDA

Interpreter: /usr/bin/python3 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 0930232
branch hash: 88eed96

Automatic review by SymPy Bot.

Guru Devanla

@asmeurer The Tr module implemented currently is generic and does not have to belong to the physics module. The module in turn calls _eval_trace() methods in objects passed as 'args' to Tr. For now, yes _eval_trace() methods are defined for objects under physics/quantum module, but that need not be true always.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged b01f7e5 into 0930232).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :eight_spoked_asterisk: All tests have passed.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY8_sdDA

Interpreter: /opt/pym32/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (32-bit)
Cache: yes
Test command: setup.py test
master hash: 0930232
branch hash: b01f7e5

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYruwdDA

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 0930232
branch hash: b01f7e5

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY2NwdDA

Interpreter: /usr/bin/python3 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 0930232
branch hash: b01f7e5

Automatic review by SymPy Bot.

Aaron Meurer
Owner

I agree it is general enough to not be in the physics module, but that doesn't mean it belongs in the core. Only very basic stuff that is used by everything should be in the core. Trace I think belongs somewhere else.

Guru Devanla

Yes, one could say it is not a core operation. Do you have any suggestion on where it should go?

@ellisonbg Do you have any suggestion, based how the Tr operator would be used in the future?

Sean Vig
Collaborator

functions.elementary might be a good place for it.

Aaron Meurer
Owner

I'd put it somewhere other than elementary. That's supposed to be only elementary functions. See http://code.google.com/p/sympy/issues/detail?id=2149.

Sean Vig flacjacket commented on the diff July 06, 2012
examples/notebooks/density.ipynb
((16 lines not shown))
  441
+     "source": [
  442
+      "## Density operators with Tensor Products as args"
  443
+     ]
  444
+    }, 
  445
+    {
  446
+     "cell_type": "code", 
  447
+     "collapsed": false, 
  448
+     "input": [
  449
+      "from sympy.core.trace import Tr", 
  450
+      "", 
  451
+      "A, B, C, D = symbols('A B C D',commutative=False)", 
  452
+      "", 
  453
+      "t1 = TensorProduct(A,B,C)", 
  454
+      "", 
  455
+      "d = Density([t1, 1.0])", 
  456
+      "d.doit()", 
1
Sean Vig Collaborator
flacjacket added a note July 06, 2012

To display this result, you'll either need to split the cell here or use display() from IPython.core.display

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Sean Vig
Collaborator

The rest of the changes seem alright to me, once we figure out a better place for trace to go.

Guru Devanla

I have other changes siting in the follow up branch. I will move the discussion on where Tr should go to the mailing list. I can submit a separate PR with just the re-factored changes. Will that work?

Alternatively, the one place I can think of after looking at existing folder structures is at : sympy/matrices/expressions. This folder already has modules for matadd, matmul, matpow, inverse and transpose.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request passes (merged e1a3a01 into 0930232).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :eight_spoked_asterisk: All tests have passed.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY6YMeDA

Interpreter: /opt/pym32/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (32-bit)
Cache: yes
Test command: setup.py test
master hash: 424160a
branch hash: e1a3a01

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY6oMeDA

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 424160a
branch hash: e1a3a01

Automatic review by SymPy Bot.

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYuewdDA

Interpreter: /usr/bin/python3 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes
Test command: setup.py test
master hash: 424160a
branch hash: e1a3a01

Automatic review by SymPy Bot.

Sean Vig
Collaborator

Guru, have you sent a message to the list? I feel like since the damage was done and trace.py was put in core in the last PR, it should be alright to merge this and fix it in a later PR when a good spot is found. @asmeurer: what do you think about that?

@ellisonbg have you taken a look at this yet?

Aaron Meurer
Owner

That should be fine.

Guru Devanla

Ok, once @ellisonbg is fine with these changes, this can go.

I will start the mailing thread to discuss the where the Tr module should go.

Brian E. Granger
Owner
Brian E. Granger
Owner

I think this looks good. I will give some feedback on individual lines. My broad comment is that all your tests and notebook examples use symbols instead of bras/kets. Please include some tests with actual bras/kets and use bras/kets in the notebook examples.

sympy/core/trace.py
((23 lines not shown))
78 105
         expr = args[0]
79  
-        indices = args[1] if len(args) == 2 else -1 #-1 indicates full trace
  106
+        indices = args[1] if len(args) == 2 else []
2
Brian E. Granger Owner
ellisonbg added a note July 12, 2012

@flacjacket do you think we should wrap indices here in a sympy Tuple?

Sean Vig Collaborator
flacjacket added a note July 12, 2012

Yes, we should. I'm not sure why this doesn't trip the test_args test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Brian E. Granger ellisonbg commented on the diff July 12, 2012
sympy/core/trace.py
((5 lines not shown))
130 154
         return True
  155
+
  156
+
  157
+    #TODO: Review if the permute method is needed
  158
+    # and if it needs to return a new instance
  159
+    #def permute(self, pos):
2
Brian E. Granger Owner
ellisonbg added a note July 12, 2012

I would like to have the permute method and it should return a new instance.

Guru Devanla
gdevanla added a note July 13, 2012

@ellisonbg Actually, I had started a discussion on this on the mailing list. http://bit.ly/M7D9wF

I can work on this and see how we can achieve this. I will add to my TODO. In the subsequent PR, I will update this method based on how we decide to do it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Brian E. Granger ellisonbg commented on the diff July 12, 2012
sympy/physics/quantum/density.py
((5 lines not shown))
160 163
         terms = []
161 164
         for (state, prob) in self.args:
162  
-            terms.append(prob*(state*Dagger(state)))
  165
+            state = state.expand() # needed to break up (a+b)*c
  166
+            if (isinstance(state, Add)):
  167
+                for arg in product(state.args, repeat=2):
  168
+                    terms.append(prob *
  169
+                                 self._generate_outer_prod(arg[0], arg[1]))
2
Brian E. Granger Owner
ellisonbg added a note July 12, 2012

The _generate_outer_product method should be called _generate_tensor_product to be consistent with our naming. Also, can you summarize what this method does and why it is needed?

Guru Devanla
gdevanla added a note July 13, 2012

@ellisonbg I am guessing you were commenting on the _generate_outer_prod in tensor_product. I plan to remove that function.

The function here is just to reuse code needed within the for and if constructs. Am I in sync?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
sympy/physics/quantum/tensorproduct.py
@@ -196,6 +197,18 @@ def expand(self, **hints):
196 197
         tp = TensorProduct(*[sympify(item).expand(**hints) for item in self.args])
197 198
         return Expr.expand(tp, **hints)
198 199
 
  200
+    def _generate_outer_prod(self,arg):
2
Brian E. Granger Owner
ellisonbg added a note July 12, 2012

Minimally we need docs to describe why this is needed. Why can we just call tensor_product_simp directly?

Guru Devanla
gdevanla added a note July 13, 2012

Agreed, the redirection is not needed. I will invoke tensor_product_simp directly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Brian E. Granger
Owner

This can come in a later PR, but I would like to see some tests with Traces of density matrices of tensor products of spin states to make sure the logic works when the representations are matrices.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged bcd53e1 into 0930232).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test command: setup.py test
master hash: 387547b
branch hash: bcd53e1

Interpreter 1: :red_circle: There were test failures.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYya8fDA

Interpreter 2: :red_circle: There were test failures.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY8ZwgDA

Interpreter 3: :red_circle: There were test failures.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY7vUfDA

Build HTML Docs: :red_circle: There were test failures.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYm-YfDA

Automatic review by SymPy Bot.

Don't Add Me To Your Organization a.k.a The Travis Bot

This pull request fails (merged 4f3405d into 0930232).

Stefan Krastanov
Collaborator

SymPy Bot Summary: :red_circle: There were test failures.

@gdevanla: Please fix the test failures.

Test command: setup.py test
master hash: 0abed0f
branch hash: 4f3405d

Interpreter 1: :red_circle: There were test failures.

Interpreter: /usr/local/bin/python2.5 (2.5.6-final-0)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYn-YfDA

Interpreter 2: :red_circle: There were test failures.

Interpreter: /usr/bin/python2.7 (2.7.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYk_EeDA

Interpreter 3: :red_circle: There were test failures.

Interpreter: /usr/bin/python3.2 (3.2.3-candidate-2)
Architecture: Linux (64-bit)
Cache: yes

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYkJUgDA

Build HTML Docs: :red_circle: There were test failures.

Docs build command: make html-errors
Sphinx version: 1.1.3

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sYzq8fDA

Automatic review by SymPy Bot.

Julien Rioux
Collaborator
jrioux commented July 15, 2012

SymPy Bot Summary: :eight_spoked_asterisk: All tests have passed.

Test results html report: http://reviews.sympy.org/report/agZzeW1weTNyDAsSBFRhc2sY66cfDA

Interpreter: /usr/bin/python (2.7.0-final-0)
Architecture: Linux (32-bit)
Cache: yes
Test command: setup.py test
master hash: fb35324
branch hash: 4f3405d

Automatic review by SymPy Bot.

Brian E. Granger
Owner

This is ready for merge, and the latest test run seems to pass. But the previous one had lots of failures that seem unrelated to this PR. Do anyone understand those failures?

Julien Rioux
Collaborator
jrioux commented July 16, 2012

There was a failure in test_gruntz in the master branch, which has since been fixed. There are still failures related to hash randomization in master, which makes it hard to evaluate whether any failure is introduced by this pull request or not. Judging by the latest test results here, I would say it is safe to merge this pull request.

Brian E. Granger ellisonbg merged commit b33c1ed into from July 16, 2012
Brian E. Granger ellisonbg closed this July 16, 2012
Aleksandar Makelov

I'm not sure if this is relevant, but a recent run of travisbot on one of my PRs brought up an error in test_density.py. Here's the pull request: #1406 and the error report: http://travis-ci.org/#!/sympy/sympy/builds/1879684

Julien Rioux jrioux commented on the diff July 16, 2012
sympy/physics/quantum/tests/test_density.py
((22 lines not shown))
  65
+
  66
+    d = Density([t2, 0.5], [t3, 0.5])
  67
+    assert d.doit() == (0.5 * TensorProduct(A*Dagger(A), B*Dagger(B)) +
  68
+                        0.5 * TensorProduct(C*Dagger(C), D*Dagger(D)))
  69
+
  70
+    #Density with mixed states
  71
+    d = Density([t2+t3,1.0])
  72
+    assert d.doit() == (1.0 * TensorProduct(A*Dagger(A), B*Dagger(B)) +
  73
+                        1.0 * TensorProduct(A*Dagger(C), B*Dagger(D)) +
  74
+                        1.0 * TensorProduct(C*Dagger(A), D*Dagger(B)) +
  75
+                        1.0 * TensorProduct(C*Dagger(C), D*Dagger(D)))
  76
+
  77
+
  78
+    #Density operators with spin states
  79
+    tp1 = TensorProduct(JzKet(1,1), JzKet(1,-1))
  80
+    tp2 = TensorProduct(JzKet(1,-1/2), JzKet(1,-1/2))
2
Julien Rioux Collaborator
jrioux added a note July 16, 2012

To avoid the python 3 problem this could be written tp2 = TensorProduct(JzKet(1,-S(1)/2), JzKet(1,-S(1)/2))

Aaron Meurer Owner
asmeurer added a note July 16, 2012

Note that in Python 2, this is giving 0, because you aren't using future division. Try adding from __future__ import division to the top of file.

I guess the question is if you want this to work with floating point half numbers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Christopher Smith
Collaborator
smichr commented July 16, 2012

The problem (according to the error message) is that j and m are not both integer (or both half-integer). The message could be rewritten from "Both j and m must be integer or half-integer" to "j and m must both be integer or both be half-integer"

Guru Devanla

I submitted a follow-up pull request to address this issue at #1425

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
303  examples/notebooks/density.ipynb
@@ -28,7 +28,7 @@
28 28
      ], 
29 29
      "language": "python", 
30 30
      "outputs": [], 
31  
-     "prompt_number": 22
  31
+     "prompt_number": 3
32 32
     }, 
33 33
     {
34 34
      "cell_type": "code", 
@@ -38,7 +38,7 @@
38 38
      ], 
39 39
      "language": "python", 
40 40
      "outputs": [], 
41  
-     "prompt_number": 23
  41
+     "prompt_number": 4
42 42
     }, 
43 43
     {
44 44
      "cell_type": "markdown", 
@@ -55,7 +55,7 @@
55 55
      ], 
56 56
      "language": "python", 
57 57
      "outputs": [], 
58  
-     "prompt_number": 24
  58
+     "prompt_number": 5
59 59
     }, 
60 60
     {
61 61
      "cell_type": "code", 
@@ -70,13 +70,13 @@
70 70
         "$$\\rho\\left(\\begin{pmatrix}{\\left|\\psi\\right\\rangle }, & 0.5\\end{pmatrix},\\begin{pmatrix}{\\left|\\phi\\right\\rangle }, & 0.5\\end{pmatrix}\\right)$$"
71 71
        ], 
72 72
        "output_type": "pyout", 
73  
-       "prompt_number": 25, 
  73
+       "prompt_number": 6, 
74 74
        "text": [
75 75
         "\u03c1((\u2758\u03c8\u27e9, 0.5),(\u2758\u03c6\u27e9, 0.5))"
76 76
        ]
77 77
       }
78 78
      ], 
79  
-     "prompt_number": 25
  79
+     "prompt_number": 6
80 80
     }, 
81 81
     {
82 82
      "cell_type": "code", 
@@ -93,7 +93,7 @@
93 93
        ]
94 94
       }
95 95
      ], 
96  
-     "prompt_number": 26
  96
+     "prompt_number": 7
97 97
     }, 
98 98
     {
99 99
      "cell_type": "code", 
@@ -108,13 +108,13 @@
108 108
         "$$\\begin{pmatrix}{\\left|\\psi\\right\\rangle }, & {\\left|\\phi\\right\\rangle }\\end{pmatrix}$$"
109 109
        ], 
110 110
        "output_type": "pyout", 
111  
-       "prompt_number": 27, 
  111
+       "prompt_number": 8, 
112 112
        "text": [
113 113
         "(\u2758\u03c8\u27e9, \u2758\u03c6\u27e9)"
114 114
        ]
115 115
       }
116 116
      ], 
117  
-     "prompt_number": 27
  117
+     "prompt_number": 8
118 118
     }, 
119 119
     {
120 120
      "cell_type": "code", 
@@ -129,13 +129,13 @@
129 129
         "$$\\begin{pmatrix}0.5, & 0.5\\end{pmatrix}$$"
130 130
        ], 
131 131
        "output_type": "pyout", 
132  
-       "prompt_number": 28, 
  132
+       "prompt_number": 9, 
133 133
        "text": [
134 134
         "(0.5, 0.5)"
135 135
        ]
136 136
       }
137 137
      ], 
138  
-     "prompt_number": 28
  138
+     "prompt_number": 9
139 139
     }, 
140 140
     {
141 141
      "cell_type": "code", 
@@ -151,13 +151,13 @@
151 151
        ], 
152 152
        "output_type": "pyout", 
153 153
        "png": "iVBORw0KGgoAAAANSUhEUgAAAKoAAAAXCAYAAACbItQpAAAABHNCSVQICAgIfAhkiAAABZhJREFU\naIHt2m2IHdUZB/DfNoYYk1ijgVRtUFpL0ITUVK00GkwQCrVtaPohEVETo7aQUGxDQRFsaSn0Sw1E\nQdRgu2nVFqHS4JdWgm6rokaE+Ja+qEgt1cZopfXdaNIPz8zu3Lln7s7dO7t3U+4flrtzznPm/8x/\nzstznjMMMMAAbbgZJ/bbiZo4knwdD0fqs4z6/YlSxafxa2zDD/ETnFDjhvfhN1iDhbgKD2BTyW4e\nZtV0cnuibB1W1Wz/Axw/QR6687VXTCfd4WeJssnQvhMfBb+LHXUGRvAgtuJHWfnd2jt06obrsQv/\nwg48gp934WwZRyXK7sOGGm2PES//3xPkmUpMN91hZqJsMrTvxNeCohAXYxHuKpTtxJexsQbZTfit\nEHoFbqjrZQKn4flE+Xv4Z1bfCRvwqx54esUXurCdTrrD5/C3RHnT2o/HV4m9Ytko40XcO07bkZoc\nwzi1ht2VOLOi7iTc2KHtEO6s6U8nnmH1fE1hpAvb6aQ7fAunV9Q1qX0dvmGZ3/mMehSWSc8uL6gf\nmzSFpXi6ou4VzMEnK+q/gt83wDMVmG66w2L8uaKuSe3r8I0ij88WitHwdsLmHcwXQe0HHe61Xix5\nQ2Ij8Ev8sb6/zhZL3au4ALdm3D/GmyXbO8RsuC1xn3W4uiGeyUa/dD8Gm3EuduO2Qt2hwv/D+FDM\nej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vgm0wqr1RtcvWrf\nLd8oprqjHtKeksixVMRXnTBbpDheGMduJy7vgYfOvo6HdRNsN1kY71lOFJ8JdkIT2nfDR8Hvqf4W\n8xqRV0vhI51PYYi4bWcNnnfxD3EkV/4usg4PnX090tDpWWZJH+GW0YT23fDx//UOBhhggAEGGGCA\n+vgfqAPSYqWMIZsAAAAASUVORK5CYII=\n", 
154  
-       "prompt_number": 29, 
  154
+       "prompt_number": 10, 
155 155
        "text": [
156 156
         "0.5\u22c5\u2758\u03c6\u27e9\u27e8\u03c6\u2758 + 0.5\u22c5\u2758\u03c8\u27e9\u27e8\u03c8\u2758"
157 157
        ]
158 158
       }
159 159
      ], 
160  
-     "prompt_number": 29
  160
+     "prompt_number": 10
161 161
     }, 
162 162
     {
163 163
      "cell_type": "code", 
@@ -172,13 +172,13 @@
172 172
         "$$\\rho\\left(\\begin{pmatrix}{\\left|\\psi\\right\\rangle }, & 0.5\\end{pmatrix},\\begin{pmatrix}{\\left|\\phi\\right\\rangle }, & 0.5\\end{pmatrix}\\right)$$"
173 173
        ], 
174 174
        "output_type": "pyout", 
175  
-       "prompt_number": 30, 
  175
+       "prompt_number": 11, 
176 176
        "text": [
177 177
         "\u03c1((\u2758\u03c8\u27e9, 0.5),(\u2758\u03c6\u27e9, 0.5))"
178 178
        ]
179 179
       }
180 180
      ], 
181  
-     "prompt_number": 30
  181
+     "prompt_number": 11
182 182
     }, 
183 183
     {
184 184
      "cell_type": "code", 
@@ -188,7 +188,7 @@
188 188
      ], 
189 189
      "language": "python", 
190 190
      "outputs": [], 
191  
-     "prompt_number": 31
  191
+     "prompt_number": 12
192 192
     }, 
193 193
     {
194 194
      "cell_type": "code", 
@@ -203,13 +203,13 @@
203 203
         "$$\\rho\\left(\\begin{pmatrix}A {\\left|\\psi\\right\\rangle }, & 0.5\\end{pmatrix},\\begin{pmatrix}A {\\left|\\phi\\right\\rangle }, & 0.5\\end{pmatrix}\\right)$$"
204 204
        ], 
205 205
        "output_type": "pyout", 
206  
-       "prompt_number": 32, 
  206
+       "prompt_number": 13, 
207 207
        "text": [
208 208
         "\u03c1((A\u22c5\u2758\u03c8\u27e9, 0.5),(A\u22c5\u2758\u03c6\u27e9, 0.5))"
209 209
        ]
210 210
       }
211 211
      ], 
212  
-     "prompt_number": 32
  212
+     "prompt_number": 13
213 213
     }, 
214 214
     {
215 215
      "cell_type": "markdown", 
@@ -226,7 +226,7 @@
226 226
      ], 
227 227
      "language": "python", 
228 228
      "outputs": [], 
229  
-     "prompt_number": 33
  229
+     "prompt_number": 14
230 230
     }, 
231 231
     {
232 232
      "cell_type": "code", 
@@ -241,13 +241,13 @@
241 241
         "$$\\rho\\left(\\begin{pmatrix}{\\left|\\frac{1}{2},\\frac{1}{2}\\right\\rangle }, & 0.5\\end{pmatrix},\\begin{pmatrix}{\\left|\\frac{1}{2},- \\frac{1}{2}\\right\\rangle }, & 0.5\\end{pmatrix}\\right)$$"
242 242
        ], 
243 243
        "output_type": "pyout", 
244  
-       "prompt_number": 34, 
  244
+       "prompt_number": 15, 
245 245
        "text": [
246 246
         "\u03c1((\u27581/2,1/2\u27e9, 0.5),(\u27581/2,-1/2\u27e9, 0.5))"
247 247
        ]
248 248
       }
249 249
      ], 
250  
-     "prompt_number": 34
  250
+     "prompt_number": 15
251 251
     }, 
252 252
     {
253 253
      "cell_type": "code", 
@@ -262,7 +262,7 @@
262 262
         "$$\\left[\\begin{smallmatrix}0.5 & 0\\\\0 & 0.5\\end{smallmatrix}\\right]$$"
263 263
        ], 
264 264
        "output_type": "pyout", 
265  
-       "prompt_number": 35, 
  265
+       "prompt_number": 16, 
266 266
        "text": [
267 267
         "", 
268 268
         "\u23a10.5   0 \u23a4", 
@@ -271,7 +271,7 @@
271 271
        ]
272 272
       }
273 273
      ], 
274  
-     "prompt_number": 35
  274
+     "prompt_number": 16
275 275
     }, 
276 276
     {
277 277
      "cell_type": "code", 
@@ -286,7 +286,7 @@
286 286
         "$$\\rho\\left(\\begin{pmatrix}J_z {\\left|\\frac{1}{2},\\frac{1}{2}\\right\\rangle }, & 0.5\\end{pmatrix},\\begin{pmatrix}J_z {\\left|\\frac{1}{2},- \\frac{1}{2}\\right\\rangle }, & 0.5\\end{pmatrix}\\right)$$"
287 287
        ], 
288 288
        "output_type": "pyout", 
289  
-       "prompt_number": 36, 
  289
+       "prompt_number": 17, 
290 290
        "text": [
291 291
         "", 
292 292
         "\u03c1\u239b\u239bJ \u22c5\u27581/2,1/2\u27e9, 0.5\u239e,\u239bJ \u22c5\u27581/2,-1/2\u27e9, 0.5\u239e\u239e", 
@@ -294,7 +294,7 @@
294 294
        ]
295 295
       }
296 296
      ], 
297  
-     "prompt_number": 36
  297
+     "prompt_number": 17
298 298
     }, 
299 299
     {
300 300
      "cell_type": "code", 
@@ -309,7 +309,7 @@
309 309
         "$$\\rho\\left(\\begin{pmatrix}\\frac{1}{2} \\hbar {\\left|\\frac{1}{2},\\frac{1}{2}\\right\\rangle }, & 0.5\\end{pmatrix},\\begin{pmatrix}- \\frac{1}{2} \\hbar {\\left|\\frac{1}{2},- \\frac{1}{2}\\right\\rangle }, & 0.5\\end{pmatrix}\\right)$$"
310 310
        ], 
311 311
        "output_type": "pyout", 
312  
-       "prompt_number": 37, 
  312
+       "prompt_number": 18, 
313 313
        "text": [
314 314
         "", 
315 315
         " \u239b\u239b\u210f\u22c5\u27581/2,1/2\u27e9     \u239e \u239b-\u210f\u22c5\u27581/2,-1/2\u27e9     \u239e\u239e", 
@@ -318,7 +318,7 @@
318 318
        ]
319 319
       }
320 320
      ], 
321  
-     "prompt_number": 37
  321
+     "prompt_number": 18
322 322
     }, 
323 323
     {
324 324
      "cell_type": "code", 
@@ -334,7 +334,7 @@
334 334
        ], 
335 335
        "output_type": "pyout", 
336 336
        "png": "iVBORw0KGgoAAAANSUhEUgAAAZ0AAAAlCAYAAACZMTQOAAAABHNCSVQICAgIfAhkiAAACElJREFU\neJztnWeMFkUYgB/OO0VBxFgQ2w9RVCxYYtTYTkXsJRorNkw0miixxBbr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ZYRt1/0c+lYKdyPrFK62ilI4AtkeJE+yirULGa833TtpIbLo0JQQ6zTNkNEF2O29\nVibq6GgRnpXdsVw8KeNL3JYg+1GdQN94cy/27x5PYmdk00OQru48zN4zE6UH2BN5wJsnWcQKMm13\nYeMYJswCjrE4foh1moaplHNfOhPq6GgRnpXdsTJ44o2t6P/e8NlIA2+H7V3UevSfCTQTeMCiPMgY\nuctGj7ZkESvI1hs2d9bDsVuXEWKdhjYNOErdHC3Cs7I7FpQnByI78IJM8fuWgdNFo6T5pTZB1jCM\ncizvE9dYh+N2FzoT2avLlhDqFCoiU07U2VGfnlXFsdp7sjrypsPjkWGITzrkd/2lhgGPAls6lPVN\nmlhPB85wKDceu3euQDh1ChWRKSfq6qhvz6rgWFCedAE3INM2k3D5pQYjr/sd2fh5jGV5n6SNdSFy\nF2ZLF/AKMovFhJDqFComU07UydEiPCu7Y5l7UsaJBEORAEcgu+seTOcGbUs3MvPmdmTq6Ujkjq2M\npI11DDKN1uSdK60sR17aZDK9MqQ6DZ06OlqUZ2V2LBhPepA57qcgi9JGG5TZHlkkZ8pNDNwVNW6r\n/zKQNtZJyGwVVzYGrjXIF1KdNrFtd3Whjo4W6VlZHQvOkzL2whRF6UMdVRRFURRFURRFURRFURRF\nURRFUZQa8j/bVKmwXxjmUgAAAABJRU5ErkJggg==\n", 
337  
-       "prompt_number": 38, 
  337
+       "prompt_number": 19, 
338 338
        "text": [
339 339
         "", 
340 340
         "0.5\u22c5J \u22c5\u27581/2,-1/2\u27e9\u27e81/2,-1/2\u2758 + 0.5\u22c5J \u22c5\u27581/2,1/2\u27e9\u27e81/2,1/2\u2758", 
@@ -342,12 +342,12 @@
342 342
        ]
343 343
       }
344 344
      ], 
345  
-     "prompt_number": 38
  345
+     "prompt_number": 19
346 346
     }, 
347 347
     {
348 348
      "cell_type": "markdown", 
349 349
      "source": [
350  
-      "Evaluate entropy of the density matrices"
  350
+      "## Evaluate entropy of the density matrices"
351 351
      ]
352 352
     }, 
353 353
     {
@@ -364,7 +364,7 @@
364 364
        ], 
365 365
        "output_type": "pyout", 
366 366
        "png": "iVBORw0KGgoAAAANSUhEUgAAAEUAAAAiCAYAAAAJfBTLAAAABHNCSVQICAgIfAhkiAAAA+RJREFU\naIHt2HuIVVUUx/GPw4w5TtmkZTVmNSkRJTlkRVmYGFH0+qOggoygwv8qIaI/sockTERlEVH0/Ksw\nKeglg1lCRlSERJAUNOlYGoWpPaSHPaY/1jncfe/cO9eZ5sytvF+43LP3WfucddZZ+7f2PjT5RxyC\n1kY78W/hACzAZhzbWFfGh5Z9sLkSB6G7YF/+kwxqZsr+SzMoVSi6mszFhZiGt/FawfebiL1J+2Jc\nJKb+BqzBT8PYo/hM2YOfcQvmFXyvI3Bd0l6JhbgPq7BUBObwxOZWEZhRMUFEe7QVaDvuHu3N94EW\nPKaU+YvwcoXNMeIlbUj6ZuOJaherx7V4GhvRKyI+Un4fxZiRcA3W44+sfSk6lFfLrfgQ89GZ9fVj\nG3oK9q8qA4rNlHXKp8HjIrNvrrB7Nus/O+mbgydTo0Yu2+cJEZyIL7AWX1fYtIgsOBNfYjUOxVXY\niXswBW3KBXMZPsCLFdebJYKyKenrF8Vg3BlQnim3iUo0NWvPwrs4I7FpwSvow3Qcj0+zcTOy4zZR\n4Vbtgw8zReBer3JuM9orOwcL+KUMKAXlPPwm3njKAuzCcVl7YXadxYnNA/hFbDtyFgnNq8dTIrtm\nVjm3XrwYlIR2QgG/WizDx/iuov8d8bBXZO08sNsTm+8xSSnD4IcaD5pyCS4TL+SrKuePVL5+GRcG\nRKZMwI94s4bdLiGaORvFVMt5A+9XjDkMW4a590lCs2qtk1qxW1KJx1toB8WDH1zlXKf4ZrMn6XtV\naElv9r9DKZNydohsaRdTK2U6nhElOhfXGaJ0f5u1u0WW/pUPakT1WSfSOV8Q5vQk53M6cL14i9W0\nKud5oUlrk752UYJvUF5tLheZmgdlIZ4b4TOMCQNKQjtbLJgWV9jcJcpomkWfKQnvcEwSAcnXKi14\nCfeK8p3/rhZZkdtNzcYNp4FVaceNWIElRrZXmIv7RWpuEXuNVqH0fXg0c3a5WFNMqRi/En+KKbVb\nBGmNEMxKenBTdrxc7ar4eTJmhaTq5NSLUAsewZ2ZUw/iVJyTOVuPbiF0KX3J2E6ciI8M1YNFYiO5\nWpTSNhyd2S8RwXyhYswMUa1OU77xS9mJ97LjmapXo2GZg0+EYEGXiPZZI73QKOjH6TXOPaT6ImxM\nqLch3CqE79esnW+42opyKGGT8hVuyhRDS/OYMVKBWSrEar7id75H4Q5Mxlv4Rmz/zxfZ22volBt3\nThD7k65xvm8HTsa5mQ+j/ig01nSJjzF5udzvv+1Ow+1KOnIKLmicO8VTT1MOFEK7V2k12SXK5bYC\n/Woo9Zb5k/FwRd+g/3FAmjRp0mSs+Rvvgds8ldAxMgAAAABJRU5ErkJggg==\n", 
367  
-       "prompt_number": 39, 
  367
+       "prompt_number": 20, 
368 368
        "text": [
369 369
         "", 
370 370
         "log(2)", 
@@ -373,7 +373,7 @@
373 373
        ]
374 374
       }
375 375
      ], 
376  
-     "prompt_number": 39
  376
+     "prompt_number": 20
377 377
     }, 
378 378
     {
379 379
      "cell_type": "code", 
@@ -389,7 +389,7 @@
389 389
        ], 
390 390
        "output_type": "pyout", 
391 391
        "png": "iVBORw0KGgoAAAANSUhEUgAAAEUAAAAiCAYAAAAJfBTLAAAABHNCSVQICAgIfAhkiAAAA+RJREFU\naIHt2HuIVVUUx/GPw4w5TtmkZTVmNSkRJTlkRVmYGFH0+qOggoygwv8qIaI/sockTERlEVH0/Ksw\nKeglg1lCRlSERJAUNOlYGoWpPaSHPaY/1jncfe/cO9eZ5sytvF+43LP3WfucddZZ+7f2PjT5RxyC\n1kY78W/hACzAZhzbWFfGh5Z9sLkSB6G7YF/+kwxqZsr+SzMoVSi6mszFhZiGt/FawfebiL1J+2Jc\nJKb+BqzBT8PYo/hM2YOfcQvmFXyvI3Bd0l6JhbgPq7BUBObwxOZWEZhRMUFEe7QVaDvuHu3N94EW\nPK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\n", 
392  
-       "prompt_number": 40, 
  392
+       "prompt_number": 21, 
393 393
        "text": [
394 394
         "", 
395 395
         "log(2)", 
@@ -398,7 +398,7 @@
398 398
        ]
399 399
       }
400 400
      ], 
401  
-     "prompt_number": 40
  401
+     "prompt_number": 21
402 402
     }, 
403 403
     {
404 404
      "cell_type": "code", 
@@ -410,13 +410,13 @@
410 410
      "outputs": [
411 411
       {
412 412
        "output_type": "pyout", 
413  
-       "prompt_number": 41, 
  413
+       "prompt_number": 22, 
414 414
        "text": [
415 415
         "(0.69314718056-0j)"
416 416
        ]
417 417
       }
418 418
      ], 
419  
-     "prompt_number": 41
  419
+     "prompt_number": 22
420 420
     }, 
421 421
     {
422 422
      "cell_type": "code", 
@@ -428,13 +428,240 @@
428 428
      "outputs": [
429 429
       {
430 430
        "output_type": "pyout", 
431  
-       "prompt_number": 42, 
  431
+       "prompt_number": 23, 
432 432
        "text": [
433 433
         "(0.69314718056-0j)"
434 434
        ]
435 435
       }
436 436
      ], 
437  
-     "prompt_number": 42
  437
+     "prompt_number": 23
  438
+    }, 
  439
+    {
  440
+     "cell_type": "markdown", 
  441
+     "source": [
  442
+      "## Density operators with Tensor Products as args"
  443
+     ]
  444
+    }, 
  445
+    {
  446
+     "cell_type": "code", 
  447
+     "collapsed": false, 
  448
+     "input": [
  449
+      "from sympy.core.trace import Tr", 
  450
+      "", 
  451
+      "A, B, C, D = symbols('A B C D',commutative=False)", 
  452
+      "", 
  453
+      "t1 = TensorProduct(A,B,C)", 
  454
+      "", 
  455
+      "d = Density([t1, 1.0])", 
  456
+      "d.doit()", 
  457
+      "", 
  458
+      "t2 = TensorProduct(A,B)", 
  459
+      "t3 = TensorProduct(C,D)", 
  460
+      "", 
  461
+      "d = Density([t2, 0.5], [t3, 0.5])", 
  462
+      "d.doit() "
  463
+     ], 
  464
+     "language": "python", 
  465
+     "outputs": [
  466
+      {
  467
+       "latex": [
  468
+        "$$0.5 \\left({A A^{\\dagger}}\\right)\\otimes \\left({B B^{\\dagger}}\\right) + 0.5 \\left({C C^{\\dagger}}\\right)\\otimes \\left({D D^{\\dagger}}\\right)$$"
  469
+       ], 
  470
+       "output_type": "pyout", 
  471
+       "png": "iVBORw0KGgoAAAANSUhEUgAAAUkAAAAaCAYAAAA6565FAAAABHNCSVQICAgIfAhkiAAACTZJREFU\neJztnHuMHVUdxz93i1sW21Ity2tbsCVaRFo1UF6pbW1BNDwkRFAJ0Rof0CogFDSkFZcVC20o4aFE\nUR4tAeVl1NS3KS0qCCrFEnkoyNqGVwElYK0PyvrHdyZ37uw5M2dmzrCz4XySm/bOOb8z537nN2d+\n53fOLAQCgUCgkfQDE0e6E8AY4KGcOrsBF7wGfTHRT9CpSfQzstej6dehn2b4a5JKmnV5744bK4F1\nwIsjdP4kO4CXcuo8H9U5vf7udBB0ahZNuB5Nvg5N0MdEkzUzMg+4bKQ7kWKFQ50xwH3A7Jr7EjOP\noFOTmEdzrkcTr8M8mqOPiSZqZqQF3A3sM5KdSPAT4EZgDbAW+FpO/VnA9+ruFEGnptGU69HU69AU\nfUzUplkPGlVd6bEc3zn1/TDgZwXaTTOhJtsLC7TzADClQj9ccNGpG5ic8RlXg23TdEpS1GdjGxM+\n/XYCGkRczutq17Tr4KLPROz+tofjeaq0UVqznVKFM1HIfC+wHdgXuAj4W06jP0I33s2R7XHAR4EB\n4KZEvWOAewp0NsnxwBXA1BpsDyjQ1uPAJ9BvqwsXnWYAS4Aj0HW6G3g4KmsB84H/oET6dz3ZNk0n\nKO+zUI/fvgFYCMwB3gY8CfQCG4HzgWnAecDHKtg17Tq46HMK8F7gBDTu3Aq8HJX1ooWT+4FL0G/3\n3YYXzcYCTwMnJ44tQXP07pxG1wNDic8rwGmGer8Bji3Q2ZhdgEHg3zXZFhm4LwZuK9GPIhTRaQ36\nbenorwu4A3gVONqTbd06zQD2KlC/is+Cf7+diaKQ7wAH07kw+h7g51F/P1/RbrT66xi0OLLOUNYD\n3IB0yJoFlW3Di2anA9uQ48VMQc5zZk6j69FT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bgH+AVaqfRl+1pRJCcZU9ZnobrfJjkK5bOOQBHN48Cd6L3rOux8Upe/3oIG2PjaDNLe\n19qDpud3Ip+z5Rl9tFEJ27uiAT9MRZtfD0CRy19R5FP0nebXC6eiQaLsX4oKVCP4ayAQCAQCgUAg\nEAgEAoFAIBAIBAKBQKC5/B+xC2qm0KevJwAAAABJRU5ErkJggg==\n", 
  472
+       "prompt_number": 24, 
  473
+       "text": [
  474
+        "", 
  475
+        "    \u239b   \u2020\u239e  \u239b   \u2020\u239e       \u239b   \u2020\u239e  \u239b   \u2020\u239e", 
  476
+        "0.5\u22c5\u239dA\u22c5A \u23a0\u2a02 \u239dB\u22c5B \u23a0 + 0.5\u22c5\u239dC\u22c5C \u23a0\u2a02 \u239dD\u22c5D \u23a0"
  477
+       ]
  478
+      }
  479
+     ], 
  480
+     "prompt_number": 24
  481
+    }, 
  482
+    {
  483
+     "cell_type": "code", 
  484
+     "collapsed": false, 
  485
+     "input": [
  486
+      "#mixed states", 
  487
+      "d = Density([t2+t3, 1.0])", 
  488
+      "d.doit() "
  489
+     ], 
  490
+     "language": "python", 
  491
+     "outputs": [
  492
+      {
  493
+       "latex": [
  494
+        "$$1.0 \\left({A A^{\\dagger}}\\right)\\otimes \\left({B B^{\\dagger}}\\right) + 1.0 \\left({A C^{\\dagger}}\\right)\\otimes \\left({B D^{\\dagger}}\\right) + 1.0 \\left({C A^{\\dagger}}\\right)\\otimes \\left({D B^{\\dagger}}\\right) + 1.0 \\left({C C^{\\dagger}}\\right)\\otimes \\left({D D^{\\dagger}}\\right)$$"
  495
+       ], 
  496
+       "output_type": "pyout", 
  497
+       "png": "iVBORw0KGgoAAAANSUhEUgAAAqYAAAAaCAYAAABl7J64AAAABHNCSVQICAgIfAhkiAAAC35JREFU\neJztnXusHUUZwH+3LW0ttsWUPrQUbQleKLQGpYoEb28ALVpTH7FqkKCYiBafUbAhbfByFdTGGgVs\nGl9AVTQ1PjD1rZVKFAWkFRVErUKLlpdF6gPFQv3j283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b\n5G0I9zTnCm2726V8G8LbqPLuJGTMwyFkEtg8cxDZ3plZdhXyCK90rMjbkLvOyubZWsfou/AWIAN9\nTePLQE5p70J24HwyrFPWhtmYO9/EZCR+ry/Z5jjkKMHm+en5OIFMzXIImUoiy2xEkseQO/4OZyx1\nylbhEicTvknSx1lo31uA9yNPzVjFyFii+cjZhY9hHl9kw3hydnNS9sTc8mOQG0n2Io8R9KWut9Bb\nd0N4C/7uNZlvXfsipLumGIVwT3PuCG2725V8G8Lb1vJu9okDc5Bnlc5hRJKDyNxSV1D+yKpJyDNl\nlyB3Zc1E7iy7x7KBVyNPWuhDjmjWMfr08QXIwOBZyfsHkTFNF9cs2xRTgfciCXor8HsklguBFyGD\n3IeRqUNcWIMkufnJZxxgZO6vPmSnugm5NHJ9wLK9wnW8Ux1noV1vs7wQOYtwKnKWaTfwIySB94oY\nnb0SOfNyZLLtvYzc9TkNcWU7Eqf9ju0KTS/drettFlf3upJvQ7inOXcsbbpbt1xImsq3IbxtPe+6\nPMtUcWchckSxGBk/80dk0PLNbTYqYs5BkkTRYG6ledRZP9Td9lF33VFv20WdVRRFURRFURRFURRF\nURRFURRFURRFURRFURRFURRFURRFURRFURRF+X/hf2jkcJDynyQoAAAAAElFTkSuQmCC\n", 
  498
+       "prompt_number": 25, 
  499
+       "text": [
  500
+        "", 
  501
+        "    \u239b   \u2020\u239e  \u239b   \u2020\u239e       \u239b   \u2020\u239e  \u239b   \u2020\u239e       \u239b   \u2020\u239e  \u239b   \u2020\u239e       \u239b   \u2020\u239e  \u239b  ", 
  502
+        "1.0\u22c5\u239dA\u22c5A \u23a0\u2a02 \u239dB\u22c5B \u23a0 + 1.0\u22c5\u239dA\u22c5C \u23a0\u2a02 \u239dB\u22c5D \u23a0 + 1.0\u22c5\u239dC\u22c5A \u23a0\u2a02 \u239dD\u22c5B \u23a0 + 1.0\u22c5\u239dC\u22c5C \u23a0\u2a02 \u239dD\u22c5", 
  503
+        "", 
  504
+        " \u2020\u239e", 
  505
+        "D \u23a0"
  506
+       ]
  507
+      }
  508
+     ], 
  509
+     "prompt_number": 25
  510
+    }, 
  511
+    {
  512
+     "cell_type": "markdown", 
  513
+     "source": [
  514
+      "## Trace operators on Density Operators with Spin States"
  515
+     ]
  516
+    }, 
  517
+    {
  518
+     "cell_type": "code", 
  519
+     "collapsed": false, 
  520
+     "input": [
  521
+      "from sympy.physics.quantum.density import Density", 
  522
+      "from sympy.physics.quantum.spin import (", 
  523
+      "    Jx, Jy, Jz, Jplus, Jminus, J2,", 
  524
+      "    JxBra, JyBra, JzBra,", 
  525
+      "    JxKet, JyKet, JzKet,", 
  526
+      ")", 
  527
+      "from sympy.core.trace import Tr", 
  528
+      "", 
  529
+      "d = Density([JzKet(1,1),0.5],[JzKet(1,-1),0.5]);", 
  530
+      "t = Tr(d); ", 
  531
+      "", 
  532
+      "display_pretty(t)", 
  533
+      "print t.doit()"
  534
+     ], 
  535
+     "language": "python", 
  536
+     "outputs": [
  537
+      {
  538
+       "output_type": "display_data", 
  539
+       "text": [
  540
+        "Tr(\u03c1((\u27581,1\u27e9, 0.5),(\u27581,-1\u27e9, 0.5)))"
  541
+       ]
  542
+      }, 
  543
+      {
  544
+       "output_type": "stream", 
  545
+       "stream": "stdout", 
  546
+       "text": [
  547
+        "1.00000000000000"
  548
+       ]
  549
+      }
  550
+     ], 
  551
+     "prompt_number": 26
  552
+    }, 
  553
+    {
  554
+     "cell_type": "markdown", 
  555
+     "source": [
  556
+      "## Partial Trace on Density Operators with Mixed State"
  557
+     ]
  558
+    }, 
  559
+    {
  560
+     "cell_type": "code", 
  561
+     "collapsed": false, 
  562
+     "input": [
  563
+      "#Partial trace on mixed state", 
  564
+      "from sympy.core.trace import Tr", 
  565
+      "", 
  566
+      "A, B, C, D = symbols('A B C D',commutative=False)", 
  567
+      "", 
  568
+      "t1 = TensorProduct(A,B,C)", 
  569
+      "", 
  570
+      "d = Density([t1, 1.0])", 
  571
+      "d.doit()", 
  572
+      "", 
  573
+      "t2 = TensorProduct(A,B)", 
  574
+      "t3 = TensorProduct(C,D)", 
  575
+      "", 
  576
+      "d = Density([t2, 0.5], [t3, 0.5])", 
  577
+      "", 
  578
+      "", 
  579
+      "tr = Tr(d,[1])", 
  580
+      "tr.doit()"
  581
+     ], 
  582
+     "language": "python", 
  583
+     "outputs": [
  584
+      {
  585
+       "latex": [
  586
+        "$$0.5 A A^{\\dagger} \\mbox{Tr}\\left(B B^{\\dagger}\\right) + 0.5 C C^{\\dagger} \\mbox{Tr}\\left(D D^{\\dagger}\\right)$$"
  587
+       ], 
  588
+       "output_type": "pyout", 
  589
+       "prompt_number": 27, 
  590
+       "text": [
  591
+        "", 
  592
+        "       \u2020       \u2020           \u2020       \u2020 ", 
  593
+        "0.5\u22c5A\u22c5A \u22c5Tr(B\u22c5B ) + 0.5\u22c5C\u22c5C \u22c5Tr(D\u22c5D )"
  594
+       ]
  595
+      }
  596
+     ], 
  597
+     "prompt_number": 27
  598
+    }, 
  599
+    {
  600
+     "cell_type": "markdown", 
  601
+     "source": [
  602
+      "## Partial Trace on Density Operators with Spin states"
  603
+     ]
  604
+    }, 
  605
+    {
  606
+     "cell_type": "code", 
  607
+     "collapsed": false, 
  608
+     "input": [
  609
+      "from sympy.physics.quantum.density import Density", 
  610
+      "from sympy.physics.quantum.spin import (", 
  611
+      "    Jx, Jy, Jz, Jplus, Jminus, J2,", 
  612
+      "    JxBra, JyBra, JzBra,", 
  613
+      "    JxKet, JyKet, JzKet,", 
  614
+      ")", 
  615
+      "from sympy.core.trace import Tr", 
  616
+      "", 
  617
+      "tp1 = TensorProduct(JzKet(1,1), JzKet(1,-1))", 
  618
+      "", 
  619
+      "#trace out 0 index", 
  620
+      "d = Density([tp1,1]);", 
  621
+      "t = Tr(d,[0]); ", 
  622
+      "", 
  623
+      "display_pretty(t)", 
  624
+      "display_pretty(t.doit())", 
  625
+      "", 
  626
+      "#trace out 1 index", 
  627
+      "t = Tr(d,[1])", 
  628
+      "display_pretty(t)", 
  629
+      "t.doit()", 
  630
+      ""
  631
+     ], 
  632
+     "language": "python", 
  633
+     "outputs": [
  634
+      {
  635
+       "output_type": "display_data", 
  636
+       "text": [
  637
+        "Tr((\u27581,1\u27e9\u2a02 \u27581,-1\u27e9, 1))"
  638
+       ]
  639
+      }, 
  640
+      {
  641
+       "output_type": "display_data", 
  642
+       "text": [
  643
+        "\u27581,-1\u27e9\u27e81,-1\u2758"
  644
+       ]
  645
+      }, 
  646
+      {
  647
+       "output_type": "display_data", 
  648
+       "text": [
  649
+        "Tr((\u27581,1\u27e9\u2a02 \u27581,-1\u27e9, 1))"
  650
+       ]
  651
+      }, 
  652
+      {
  653
+       "latex": [
  654
+        "$${\\left|1,1\\right\\rangle }{\\left\\langle 1,1\\right|}$$"
  655
+       ], 
  656
+       "output_type": "pyout", 
  657
+       "png": "iVBORw0KGgoAAAANSUhEUgAAAEwAAAAXCAYAAACh3qkfAAAABHNCSVQICAgIfAhkiAAAAedJREFU\nWIXt2D+I1EAUx/GPB+ohCqIiKqKNFjanveXaKNhaeI2Kglpb2Z2FnYKVgoqNeCDYXecfUgoWgoJy\nCGJhIQhiYWexFtksa8hO/kzYm2K/TSbz8t77zeMxyYQ5UbzYaAGJMq7LQsmwu+Lh/VjHlo7JQv63\nsKdhnHsdc9TRxLeqLiCbGG/DKXzCEIsthTTxX8LNBrFO4EbHHDH6CrJiUO6wgiNYxQA/W4ho6/8B\nx7C5Jt4VPOpRY+z6xmQVcw9067Cm/mexHPDfhzuROWJ9s2IwrcNmyRrOBOxX5YtKghQKNsRbnKyw\nLeIQvsxUUYAUCgZPcKFifhnPZislTCoF+4NfOFyaH+DV7OVMJ5WCwX1cm7gf4M0GaZlKSgUbYtPE\nfUraxqQk6rq8ywpeyrssKfoo2IEeYmyXH5G+leZfy7/GY+lDI5oVbNfourfCdhzf8bijf8FF+Zuy\nzFOcrxNYk6NOYxN9U8lG152j8bp8bxniN97h0sTzB/EVH/2//zT1N/JbDWhawdGK+RiNbfRRfQIK\nG2pY6ehHs6PR3Yj4BTEas2LQ16YfE+ccngfsP7BV3hUx9LLWcpC/HWKcxvuO+ZfwuUHeh7jcMQdx\nGgno29Ey0AJuRwjp6wdiiFiNtK/LnDlzZsM/36lpQdemeFcAAAAASUVORK5CYII=\n", 
  658
+       "prompt_number": 28, 
  659
+       "text": [
  660
+        "\u27581,1\u27e9\u27e81,1\u2758"
  661
+       ]
  662
+      }
  663
+     ], 
  664
+     "prompt_number": 28
438 665
     }, 
439 666
     {
440 667
      "cell_type": "code", 
@@ -442,7 +669,7 @@
442 669
      "input": [], 
443 670
      "language": "python", 
444 671
      "outputs": [], 
445  
-     "prompt_number": 42
  672
+     "prompt_number": 28
446 673
     }
447 674
    ]
448 675
   }
264  examples/notebooks/trace.ipynb
... ...
@@ -0,0 +1,264 @@
  1
+{
  2
+ "metadata": {
  3
+  "name": "trace"
  4
+ }, 
  5
+ "nbformat": 2, 
  6
+ "worksheets": [
  7
+  {
  8
+   "cells": [
  9
+    {
  10
+     "cell_type": "code", 
  11
+     "collapsed": true, 
  12
+     "input": [
  13
+      "from sympy import symbols", 
  14
+      "from sympy.core.trace import Tr", 
  15
+      "from sympy.matrices.matrices import Matrix", 
  16
+      "from IPython.core.display import display_pretty", 
  17
+      "from sympy.printing.latex import *", 
  18
+      "", 
  19
+      "%load_ext sympyprinting"
  20
+     ], 
  21
+     "language": "python", 
  22
+     "outputs": [], 
  23
+     "prompt_number": 2
  24
+    }, 
  25
+    {
  26
+     "cell_type": "markdown", 
  27
+     "source": [
  28
+      "###Basic Examples"
  29
+     ]
  30
+    }, 
  31
+    {
  32
+     "cell_type": "code", 
  33
+     "collapsed": true, 
  34
+     "input": [
  35
+      "a, b, c, d = symbols('a b c d'); ", 
  36
+      "A, B = symbols('A B', commutative=False)", 
  37
+      "t = Tr(A*B)"
  38
+     ], 
  39
+     "language": "python", 
  40
+     "outputs": [], 
  41
+     "prompt_number": 3
  42
+    }, 
  43
+    {
  44
+     "cell_type": "code", 
  45
+     "collapsed": false, 
  46
+     "input": [
  47
+      "t"
  48
+     ], 
  49
+     "language": "python", 
  50
+     "outputs": [
  51
+      {
  52
+       "latex": [
  53
+        "$$\\mbox{Tr}\\left(A B\\right)$$"
  54
+       ], 
  55
+       "output_type": "pyout", 
  56
+       "prompt_number": 4, 
  57
+       "text": [
  58
+        "Tr(A\u22c5B)"
  59
+       ]
  60
+      }
  61
+     ], 
  62
+     "prompt_number": 4
  63
+    }, 
  64
+    {
  65
+     "cell_type": "code", 
  66
+     "collapsed": false, 
  67
+     "input": [
  68
+      "latex(t)"
  69
+     ], 
  70
+     "language": "python", 
  71
+     "outputs": [
  72
+      {
  73
+       "output_type": "pyout", 
  74
+       "prompt_number": 5, 
  75
+       "text": [
  76
+        "\\mbox{Tr}\\left(A B\\right)"
  77
+       ]
  78
+      }
  79
+     ], 
  80
+     "prompt_number": 5
  81
+    }, 
  82
+    {
  83
+     "cell_type": "code", 
  84
+     "collapsed": false, 
  85
+     "input": [
  86
+      "display_pretty(t)"
  87
+     ], 
  88
+     "language": "python", 
  89
+     "outputs": [
  90
+      {
  91
+       "output_type": "display_data", 
  92
+       "text": [
  93
+        "Tr(\u03c1((\u27581,1\u27e9, 0.5),(\u27581,-1\u27e9, 0.5)))"
  94
+       ]
  95
+      }
  96
+     ], 
  97
+     "prompt_number": 14
  98
+    }, 
  99
+    {
  100
+     "cell_type": "markdown", 
  101
+     "source": [
  102
+      "### Using Matrices"
  103
+     ]
  104
+    }, 
  105
+    {
  106
+     "cell_type": "code", 
  107
+     "collapsed": true, 
  108
+     "input": [
  109
+      "t = Tr ( Matrix([ [2,3], [3,4] ]))"
  110
+     ], 
  111
+     "language": "python", 
  112
+     "outputs": [], 
  113
+     "prompt_number": 15
  114
+    }, 
  115
+    {
  116
+     "cell_type": "code", 
  117
+     "collapsed": false, 
  118
+     "input": [
  119
+      "t"
  120
+     ], 
  121
+     "language": "python", 
  122
+     "outputs": [
  123
+      {
  124
+       "latex": [
  125
+        "$$6$$"
  126
+       ], 
  127
+       "output_type": "pyout", 
  128
+       "png": "iVBORw0KGgoAAAANSUhEUgAAAAwAAAASCAYAAABvqT8MAAAABHNCSVQICAgIfAhkiAAAAO5JREFU\nKJHN0r1KQ0EQhuHnhAgBhaiIFpLOxs5O8CIsFG/A1spCL0CwsUtnaat4C7aWNooiCAEJKBb+oMGg\nSCzOHlyWlWDnV+3M7vvN7O7wRxWZXAs7+MIL3rCHXs5gGh0shXgS19isDtQSYB9tnIa4jgZec+5r\n+MD4sHtUOsTlsEP1aL2AeyxiGbNoYgs3KTiqfJVzbET5FTxhLgVmMEAfY1G+FqoepcBIAC4ybZ8p\n/6KoHOATd6F8ql5oeSIG4ARTGaCBLh7TjVW8V05BBZ5xkDECx9j1M2PruIpN0uFrYhvzofcH5ajc\n/lbhH+gb6f4rZTpaz0QAAAAASUVORK5CYII=\n", 
  129
+       "prompt_number": 16, 
  130
+       "text": [
  131
+        "6"
  132
+       ]
  133
+      }
  134
+     ], 
  135
+     "prompt_number": 16
  136
+    }, 
  137
+    {
  138
+     "cell_type": "markdown", 
  139
+     "source": [
  140
+      "### Example using modules in physics.quantum"
  141
+     ]
  142
+    }, 
  143
+    {
  144
+     "cell_type": "code", 
  145
+     "collapsed": true, 
  146
+     "input": [
  147
+      "from sympy.physics.quantum.density import Density", 
  148
+      "from sympy.physics.quantum.spin import (", 
  149
+      "    Jx, Jy, Jz, Jplus, Jminus, J2,", 
  150
+      "    JxBra, JyBra, JzBra,", 
  151
+      "    JxKet, JyKet, JzKet,", 
  152
+      ")"
  153
+     ], 
  154
+     "language": "python", 
  155
+     "outputs": [], 
  156
+     "prompt_number": 7
  157
+    }, 
  158
+    {
  159
+     "cell_type": "code", 
  160
+     "collapsed": false, 
  161
+     "input": [
  162
+      "d = Density([JzKet(1,1),0.5],[JzKet(1,-1),0.5]); d"
  163
+     ], 
  164
+     "language": "python", 
  165
+     "outputs": [
  166
+      {
  167
+       "latex": [
  168
+        "$$\\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)$$"
  169
+       ], 
  170
+       "output_type": "pyout", 
  171
+       "prompt_number": 8, 
  172
+       "text": [
  173
+        "\u03c1((\u27581,1\u27e9, 0.5),(\u27581,-1\u27e9, 0.5))"
  174
+       ]
  175
+      }
  176
+     ], 
  177
+     "prompt_number": 8
  178
+    }, 
  179
+    {
  180
+     "cell_type": "code", 
  181
+     "collapsed": true, 
  182
+     "input": [
  183
+      "t = Tr(d)"
  184
+     ], 
  185
+     "language": "python", 
  186
+     "outputs": [], 
  187
+     "prompt_number": 9
  188
+    }, 
  189
+    {
  190
+     "cell_type": "code", 
  191
+     "collapsed": false, 
  192
+     "input": [
  193
+      "t"
  194
+     ], 
  195
+     "language": "python", 
  196
+     "outputs": [
  197
+      {
  198
+       "latex": [
  199
+        "$$\\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)$$"
  200
+       ], 
  201
+       "output_type": "pyout", 
  202
+       "prompt_number": 10, 
  203
+       "text": [
  204
+        "Tr(\u03c1((\u27581,1\u27e9, 0.5),(\u27581,-1\u27e9, 0.5)))"
  205
+       ]
  206
+      }
  207
+     ], 
  208
+     "prompt_number": 10
  209
+    }, 
  210
+    {
  211
+     "cell_type": "code", 
  212
+     "collapsed": false, 
  213
+     "input": [
  214
+      "latex(t)"
  215
+     ], 
  216
+     "language": "python", 
  217
+     "outputs": [
  218
+      {
  219
+       "output_type": "pyout", 
  220
+       "prompt_number": 11, 
  221
+       "text": [
  222
+        "", 
  223
+        "\\mbox{Tr}\\left(\\rho\\left(\\begin{pmatrix}{\\left|1,1\\right\\rangle }, & 0.5\\end{p", 
  224
+        "matrix},\\begin{pmatrix}{\\left|1,-1\\right\\rangle }, & 0.5\\end{pmatrix}\\right)\\r", 
  225
+        "ight)"
  226
+       ]
  227
+      }
  228
+     ], 
  229
+     "prompt_number": 11
  230
+    }, 
  231
+    {
  232
+     "cell_type": "code", 
  233
+     "collapsed": false, 
  234
+     "input": [
  235
+      "t.doit()"
  236
+     ], 
  237
+     "language": "python", 
  238
+     "outputs": [
  239
+      {
  240
+       "latex": [
  241
+        "$$1.0$$"
  242
+       ], 
  243
+       "output_type": "pyout", 
  244
+       "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", 
  245
+       "prompt_number": 12, 
  246
+       "text": [
  247
+        "1.00000000000000"
  248
+       ]
  249
+      }
  250
+     ], 
  251
+     "prompt_number": 12
  252
+    }, 
  253
+    {
  254
+     "cell_type": "code", 
  255
+     "collapsed": true, 
  256
+     "input": [], 
  257
+     "language": "python", 
  258
+     "outputs": [], 
  259
+     "prompt_number": 12
  260
+    }
  261
+   ]
  262
+  }
  263
+ ]
  264
+}
30  sympy/core/tests/test_trace.py
... ...
@@ -1,4 +1,4 @@
1  
-from sympy import S, Symbol, symbols, Matrix
  1
+from sympy import S, Symbol, symbols, Matrix, Tuple
2 2
 from sympy.core.trace import Tr
3 3
 
4 4
 def test_trace_new():
@@ -19,6 +19,8 @@ def test_trace_new():
19 19
     assert Tr(a*C*A*D*B*2) == 2*a*Tr(A*D*B*C)
20 20
     assert Tr(B*A*C*B*A) == Tr(A*C*B*A*B)
21 21
     assert Tr(A*C*B*A*B) == Tr(A*B*A*C*B)
  22
+    assert Tr(A*A*B*B) == Tr(A**2*B**2)