physics.quantum - labels vs args - printing vs content

5 views
Skip to first unread message

krastano...@gmail.com

unread,
Mar 31, 2011, 9:00:50 AM3/31/11
to sy...@googlegroups.com
Hi,

In short: label is used by the printing functions but also it is used instead of args in some other functions

I'm trying to make the printing in physics.quantum.spin less ambiguous. According to the answer I received here http://groups.google.com/group/sympy/msg/3f8d4fe139b1884a it will be useful to add subscript (or something else) to the printed expression. Here is the problem: label is used by the printing functions but also it is used instead of args in some other functions.

The printing functions for J?Ket are derived all from KetBase which uses function derived from StateBase which uses function derived from QExpr.

My understanding is that the self.args of QExpr should be a list (tuple) of the quantum numbers and other useful sympy symbols that define the mathematical object and label should be a list (tuple) of things that must be printed to screen. So we have the JzKet(1/2,1/2) with args (1/2,1/2) and label (1/2,1/2) being printed as |1/2,1/2>. The problems are:
    - Some parts of the code use label instead of args to get the quantum numbers (j and m in J?Ket). So I can not have the label ("z",1/2,1/2). I believe that a stricter distinction should be made.
    - less important and of topic The separator "," for the label must be the same for every separation (but can be different from ket to ket). So if I want a better label like |z:1/2,1/2> I can't do it.

As it stands (at least for the spin part) QExpr defines label as property in the function "return self.args" and then the code uses label instead of args. I believe it is a bug to use label in this manner because I can not override it to have nicer printing. The default for label is ok: just print all quantum numbers. But for the spin for example I would like to have other info printed.

So am I wrong in proposing:
- Fixing the code where label is used instead of args.
- Adding a prefix/title/something field to the label so I can have |usefull_info : q_number_1, q_number_2, ...> printed to screen. That will make the base printing functions more complicated but it will not change the rest of the code. Maybe creating a QuantumLabel class would be useful.

also: All the code in quantum that deals with printing (inner product's printer for example) supposes that the rightmost char in the string of Ket will be >. So subscripts are out of the question if they are in the form |foo,bar>_subscript. That is not a problem. I am just noting this assumption that does not seem documented.

Regards
Stefan

Brian Granger

unread,
Mar 31, 2011, 12:15:56 PM3/31/11
to sy...@googlegroups.com, krastano...@gmail.com
Hi,

> In short: label is used by the printing functions but also it is used
> instead of args in some other functions

Yes, that is the case. The difference between label and args is
deliberate and important:

* label == set of things that determine which state you have ==
quantum numbers usually. This does not include things like time and
other parameters.
* args == label + time + ....

In many cases, label == args, but not in general (see TimeDepKet).

> I'm trying to make the printing in physics.quantum.spin less ambiguous.
> According to the answer I received here
> http://groups.google.com/group/sympy/msg/3f8d4fe139b1884a it will be useful
> to add subscript (or something else) to the printed expression. Here is the
> problem: label is used by the printing functions but also it is used instead
> of args in some other functions.

This is as it should be.

> The printing functions for J?Ket are derived all from KetBase which uses
> function derived from StateBase which uses function derived from QExpr.
>
> My understanding is that the self.args of QExpr should be a list (tuple) of
> the quantum numbers and other useful sympy symbols that define the
> mathematical object and label should be a list (tuple) of things that must
> be printed to screen. So we have the JzKet(1/2,1/2) with args (1/2,1/2) and
> label (1/2,1/2) being printed as |1/2,1/2>. The problems are:

Again, args also has the time, which is not in label.

>     - Some parts of the code use label instead of args to get the quantum
> numbers (j and m in J?Ket). So I can not have the label ("z",1/2,1/2). I
> believe that a stricter distinction should be made.
>     - less important and of topic The separator "," for the label must be
> the same for every separation (but can be different from ket to ket). So if
> I want a better label like |z:1/2,1/2> I can't do it.
>
> As it stands (at least for the spin part) QExpr defines label as property in
> the function "return self.args" and then the code uses label instead of
> args. I believe it is a bug to use label in this manner because I can not
> override it to have nicer printing. The default for label is ok: just print
> all quantum numbers. But for the spin for example I would like to have other
> info printed.
>
> So am I wrong in proposing:
> - Fixing the code where label is used instead of args.
> - Adding a prefix/title/something field to the label so I can have
> |usefull_info : q_number_1, q_number_2, ...> printed to screen. That will
> make the base printing functions more complicated but it will not change the
> rest of the code. Maybe creating a QuantumLabel class would be useful.
>
> also: All the code in quantum that deals with printing (inner product's
> printer for example) supposes that the rightmost char in the string of Ket
> will be >. So subscripts are out of the question if they are in the form
> |foo,bar>_subscript. That is not a problem. I am just noting this assumption
> that does not seem documented.

You can do what you want be overriding the various _print_contents
methods. I would check out how TimeDepState in state.py handles this.
I think that will answer your questions.

Cheers,

Brian

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

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

krastano...@gmail.com

unread,
Mar 31, 2011, 3:47:23 PM3/31/11
to elli...@gmail.com, sy...@googlegroups.com
Hi,

I checked out TimeDepState and I believe that I got it now and I will use it for the spins over the weekend.

Stefan

krastano...@gmail.com

unread,
Mar 31, 2011, 3:52:21 PM3/31/11
to elli...@gmail.com, sy...@googlegroups.com
I mean the style of the code, not the class, obviously :)
Reply all
Reply to author
Forward
0 new messages