MathGroup Archive 2008

[Date Index] [Thread Index] [Author Index]

Search the Archive

RE: Re: Don't understand behavior of ClearAttributes[Plus,

  • To: mathgroup at smc.vnet.net
  • Subject: [mg84991] RE: [mg84918] Re: Don't understand behavior of ClearAttributes[Plus,
  • From: "Jose Luis Gomez" <jose.luis.gomez at itesm.mx>
  • Date: Tue, 22 Jan 2008 01:53:00 -0500 (EST)
  • Organization: ITESM
  • References: <200801160830.DAA10128@smc.vnet.net> <fmmk8b$epl$1@smc.vnet.net> <200801191103.GAA19949@smc.vnet.net>

Hi Alain, Daniel, everybody, I want to make a comment about this:

>> From the viewpoint of programming language semantics, one would say
>> that programs depending on specifics of such ordering do not have
>> well defined behavior.
>
>OK, but I'm only concerned with the output.  (There are probably ways
>of obtaining the order I need without changing Plus' attributes, but I
>don't have the abilities to do that.)
>

I created a package for using Quantum Dirac Notation in Mathematica.
http://homepage.cem.itesm.mx/lgomez/quantum/index.htm 
In this package, the notation of Quantum "kets" and "bras" are used to make
calculations. Internally, totally invisible for the final user, the "kets"
and "bras" have an internal name, the one that can be seen with InputForm[]
or FullForm[]. Externally, the end users sees the shape of a "ket" as in
Quantum Mechanics textbooks.
Originally, the internal names were, well, ket[] and bra[].
However with this names, when you write something like
Cos[a]*ket[0]+Sin[a]*ket[1], then Mathematica will display it in the output
as Cos[a]*ket[0]+ket[1]*Sin[a] (please imagine the actual ket of textbooks),
which look weird, because sometimes the ket is after a scalar function
(which is the usual notation in textbooks) and sometimes it is before the
scalar function.
Now, as seems to be the case of Alain, the most important contribution of my
package is output (and input), I needed the output to be as close as
possible to a textbook or paper.
My solution was "silly", but I works: I changed the internal names of my
functions to zzbra[] and zzket[].
I know, I know, I am always making silly tricks, but they do work!
Now my kets are "always" displayed after the scalar functions in linear
combinations.

If Alain or somebody else would like to use this kind of trick:
You need an "internal form" (for the programmer) and an "external form" (for
the end-user).
There are several ways to link those forms: Format[], TagBox[], MakeBoxes[],
MakeExpression[], PrecedenceForm[], etc.
However, have in mind that those specialized functions can create a real
mess when not used properly, and there is much of "try and try and try"
before you can use them correctly.
(if it is useful for you, be my guest to see the code of my Quantum package)

Best regards!
Jose 




 




  • Prev by Date: Re: Align decmal points
  • Next by Date: Re: Re: Mathematica commenting of code using (* *)
  • Previous by thread: Re: Don't understand behavior of ClearAttributes[Plus,
  • Next by thread: Re: Don't understand behavior of ClearAttributes[Plus,