patch for the printing of quantum.spin

6 views
Skip to first unread message

krastano...@gmail.com

unread,
Apr 1, 2011, 10:26:10 AM4/1/11
to sy...@googlegroups.com
Following from here http://groups.google.com/group/sympy/msg/accc99bb1030e6b2
Concerning issue http://code.google.com/p/sympy/issues/detail?id=2251

As the printing of spin states in physics.quantum is a bit ambiguous I have tried to change it. I have override the _print_content* methods to add a prefix.
As this is the first time I work with the printing system I would be grateful if someone checks the consistency of the approach. Most importantly - I do not know if my approach is what you have in mind for general spin states.

If it is consistent I will check the unit tests (it's not done for the moment)

Regards
Stefan

0001-Changing-the-printing-methods-of-quantum.Spin.patch

krastano...@gmail.com

unread,
Apr 1, 2011, 11:26:52 AM4/1/11
to sy...@googlegroups.com
By the way there is something that is not immediately obvious to me (concerning InnerProduct and a bug in my patch):

This is ok:
JzKet('1/2','1/2')   ==>  ❘z:1/2,-1/2⟩
JxKet('1/2','1/2')   ==>  ❘x:1/2,-1/2⟩
TimeDepKet('psi', 't')  ==> ❘ψ;t⟩

This is probably ok:
TimeDepKet('psi', 't').dual * TimeDepKet('psi', 't')  ==> ⟨ψ❘ψ;t⟩  # Only one t

This is NOT ok:
JxKet('1/2','1/2').dual*JzKet('1/2','1/2')  ==> ⟨1/2,-1/2❘z:1/2,-1/2⟩ # The x is lost, the output is not clear.

What should be done?

Regards
Stefan

Julien Rioux

unread,
Apr 1, 2011, 12:04:53 PM4/1/11
to sympy
> *This is NOT ok:*
> JxKet('1/2','1/2').dual*JzKet('1/2','1/2')  ==> ⟨1/2,-1/2❘z:1/2,-1/2⟩ # The
> x is lost, the output is not clear.
>
> What should be done?

.dual returns the J?Bra classes. You didn't define
_direction_string_label for these classes.

krastano...@gmail.com

unread,
Apr 1, 2011, 12:21:43 PM4/1/11
to sy...@googlegroups.com, Julien Rioux
That is not the problem _but_ It is true that I should define _direction_string_label for J?Bra for another reason.

With the patch (and no _direction_string_label for the J?Bras) I have
JxKet('1/2','1/2').dual  ==> ⟨z:1/2,-1/2❘
which is ok.

The problem is that innerproduct uses print_label and not print_content for the bra which is the way it should be, at least for TimeDepKet.

Adding _direction_string_label to J?Bra is needed because someone may define a Bra and get
JxBra('1/2','-1/2')  ==> ⟨None:1/2,-1/2❘. Otherwise it is not needed for the use of Ket.dual as the field is already defined.

Stefan


--
You received this message because you are subscribed to the Google Groups "sympy" group.
To post to this group, send email to sy...@googlegroups.com.
To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/sympy?hl=en.


Julien Rioux

unread,
Apr 1, 2011, 12:27:59 PM4/1/11
to sympy
On Apr 1, 12:21 pm, "krastanov.ste...@gmail.com"
<krastanov.ste...@gmail.com> wrote:
> The problem is that innerproduct uses print_label and not print_content for
> the bra which is the way it should be, at least for TimeDepKet.
>

I see. Well I don't agree that ⟨ψ❘ψ;t⟩ is how it should be. I think it
should be ⟨ψ;t❘ψ;t⟩.

Brian Granger

unread,
Apr 1, 2011, 12:29:00 PM4/1/11
to sy...@googlegroups.com, Julien Rioux

+1

> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>
>

--
Brian E. Granger
Cal Poly State University, San Luis Obispo
bgra...@calpoly.edu and elli...@gmail.com

krastano...@gmail.com

unread,
Apr 1, 2011, 12:31:08 PM4/1/11
to sy...@googlegroups.com, Brian Granger, Julien Rioux
If there is a consensus on this I will be happy to change it.

Otherwise is the patch ok? If it is to whom should I send it?
Here is the second part that adds _distance_string_label to the bras
0001-Changing-the-printing-methods-of-quantum.Spin.patch
0002-Changing-the-printing-methods-of-quantum.Spin-2.patch

Vinzent Steinberg

unread,
Apr 2, 2011, 8:25:25 AM4/2/11
to sympy
On 1 Apr., 18:31, "krastanov.ste...@gmail.com"
<krastanov.ste...@gmail.com> wrote:
> If there is a consensus on this I will be happy to change it.
>
> Otherwise is the patch ok? If it is to whom should I send it?
> Here is the second part that adds _distance_string_label to the bras

The preferable way is to create a pull request on github. Email
patches are fine too with me, but I don't know about the quantum guys.

Vinzent

krastano...@gmail.com

unread,
Apr 2, 2011, 12:15:52 PM4/2/11
to sy...@googlegroups.com, Vinzent Steinberg
Thanks. Brian also explained it in a private message.



--

krastano...@gmail.com

unread,
Apr 2, 2011, 2:53:47 PM4/2/11
to sy...@googlegroups.com, Vinzent Steinberg
Hi

I have a question about the behavior of _print_contents. As it stands there is no difference between _print_contents and _print main method. _print just calls _print_contents. That way _print_content must take care for the brackets. I believe this is counterintuitive. And it makes it difficult to fix the printing of InnerProduct in a clear way.

I propose that the bracket printing is done in the main method _print and that _print_contents is left printing only the content of those brackets. That way the printing of InnerProduct will be much more easy to understand.

As it stands there is no easy way to print bra*ket. If I use _print_label it will only print the quantum numbers and not the time (for TimeDepBra) or the direction string (for J?Bra). If I use _print_contents the left bracket and the vertical line are printed twice.

Stefan

krastano...@gmail.com

unread,
Apr 2, 2011, 3:15:38 PM4/2/11
to sy...@googlegroups.com, Vinzent Steinberg
My proposition may be detrimental for _sympyrepr in qexpr.py. Is it?
Should _print_contents print the brackets or not?

krastano...@gmail.com

unread,
Apr 2, 2011, 5:10:59 PM4/2/11
to sy...@googlegroups.com, Vinzent Steinberg
Ok, there is a pull request.
Reply all
Reply to author
Forward
0 new messages