patch for the printing of quantum.spin

Showing 1-12 of 12 messages
patch for the printing of quantum.spin Stefan Krastanov 4/1/11 7:26 AM
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

Re: patch for the printing of quantum.spin Stefan Krastanov 4/1/11 8:26 AM
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
Re: patch for the printing of quantum.spin Julien Rioux 4/1/11 9:04 AM
> *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.
Re: [sympy] Re: patch for the printing of quantum.spin Stefan Krastanov 4/1/11 9:21 AM
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.


Re: patch for the printing of quantum.spin Julien Rioux 4/1/11 9:27 AM
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⟩.
Re: [sympy] Re: patch for the printing of quantum.spin Brian Granger 4/1/11 9:29 AM

+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

Re: [sympy] Re: patch for the printing of quantum.spin Stefan Krastanov 4/1/11 9:31 AM
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
Re: patch for the printing of quantum.spin Vinzent Steinberg 4/2/11 5:25 AM
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
Re: [sympy] Re: patch for the printing of quantum.spin Stefan Krastanov 4/2/11 9:15 AM
Thanks. Brian also explained it in a private message.



--
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.


Re: [sympy] Re: patch for the printing of quantum.spin Stefan Krastanov 4/2/11 11:53 AM
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
Re: [sympy] Re: patch for the printing of quantum.spin Stefan Krastanov 4/2/11 12:15 PM
My proposition may be detrimental for _sympyrepr in qexpr.py. Is it?
Should _print_contents print the brackets or not?
Re: [sympy] Re: patch for the printing of quantum.spin Stefan Krastanov 4/2/11 2:10 PM
Ok, there is a pull request.