Hi,
First of all, I am sorry that I left the pull request I'll be talking about halfway finished after taking so much of your time with questions about the code. I had some more urgent responsibilities lately.
I'm talking about the pull request dealing with changes in the way that quantum prints stuff. I have some questions to ask and I will also explain why my code is the way it is. All this is somewhere in the commit messages but those are not clear enough (sorry). Also an issue about this stuff is open.
https://github.com/sympy/sympy/pull/186print_repr is not tested at all. Before committing it should be tested, but I would like some pointers on this one.
The main change is in the behavior of the printing methods of QExpr:
# Printing of labels
# This should print only the quantum numbers
def _print_label(self, printer, *args):
# Printing of contents
# This prints the quantum numbers and the rest of the information
def _print_contents(self, printer, *args):
# Main methods
# They would add brackets if needed in the subclasses
def _sympystr(self, printer, *args): and others
And the brackets stuff is now only in State and TimeDepState.
The children of State and TimeDepState are not changed and from their point of view nothing has changed.
but now printing of inner product is simpler because I don't need to search for brackets and remove them.
Before this was necessary because there was no real separation between the stuff done by _print_label
and _print_content. Frequently _print_label was used for stuff that should be done by _print_content or
_print_content was adding brackets to the content.
Those changes permitted shorter and cleaner code to be written for those two problems:
First problem - printing of inner products with something more complex than the simplest Ket:
Currently we have:
In [3]: from sympy.physics.quantum import TimeDepKet
In [4]: k = TimeDepKet('psi', 't')
In [5]: k.dual*k
Out[5]: ⟨ψ❘ψ;t⟩
The output from my code is:Out[5]: ⟨ψ;t❘ψ;t⟩
The code is cleaner as there is no more hacking on characters and now not only the label but the whole content is printed. That's why the refactoring of the label and content method was necessary.
Second problem - printing of spin states is ambiguous, there is no way to distinguish Jz from Jx states:Currently:In [6]: from sympy.physics.quantum.spin import JzKet
In [7]: j = JzKet('1/2','1/2')
In [8]: j
Out[8]: ❘1/2,1/2⟩
My code:Out[8]: ❘z:1/2,1/2⟩
The same stuff.
Proof of the fact that the higher classes were not affected is that no problems were detected later, when I was adding tests.
In the pull request there are also some new tests for the printing and some cleanup on the latex stuff.
Also a small question: the pull request contains to many commits. Should I group them in bigger commits? Be aware that for some reason GitHub is not listing them chronological (at least to me).
Are there any problems with the approach I have chosen?
Should I add more tests or change something?
Stefan