I thought that I could do it by tweaking with Order, i.e.
Order[F[a_], F[b_]] := -Order[a,b]
for instance.
I was hoping then that,
Times[F[a],F[b]]
would then become the canonical,
Times[F[b],F[a]],
but this doesn't happen:
: Order[F[a], F[b]]
= -1
: Times[F[b], F[a]]
= F[a] F[b]
: % // FullForm
= Times[F[a], F[b]]
Ok, so it looks like Sort, isn't paying attention to Order[]. Should
it? How do I go about changing the default sort order for a particular
function?
: Sort[{F[a], F[b]}]
= {F[a], F[b]}
Joe
p.s. I've asked for a lot of help recently, but not given much in
return. Many thanks to all of you who are helping me out with this
learning curve! :) You're all stars!
--
Josef Karthauser (j...@tao.org.uk) http://www.josef-k.net/
FreeBSD (cvs meister, admin and hacker) http://www.uk.FreeBSD.org/
Physics Particle Theory (student) http://www.pact.cpes.sussex.ac.uk/
================ An eclectic mix of fact and theory. =================
A few more details about what you are trying to achieve would probably
produce more helpful answers in this case. At any rate, if you are only
interested in the output form, you can write special rules for MakeBoxes
that will produce the output you desire. (this approach only works if you
use StandardForm or TraditionalForm). For example, if you want the order to
be reversed, then you could try:
MakeBoxes[Times[a__], f_] := RowBox[MakeBoxes[#, f] & /@ Reverse[{a}]]
Then we would have
In[11]:=
F[a]F[b]F[c]
Out[11]=
F[c]F[b]F[a]
The output has been sorted in reverse order. However, note that internally,
Mathematica still has the arguments to Times sorted in the usual way:
In[12]:=
FullForm[%11]
Out[12]//FullForm=
Times[F[a], F[b], F[c]]
If you have a more complicated sorting algorithm, just use Sort with the
appropriate sorting function instead of Reverse. Reversing the order of
output will produce ugly results (e.g. F[a] 10 instead of 10 F[a]) so you
will probably want to use Sort. Presumably you have a more limited context
where you want your sorting algorithm instead of the default. If you could
provide these details, it should be possible to achieve your sorting
criteria only where needed.
Carl Woll
"Josef Karthauser" <j...@tao.org.uk> wrote in message
news:d0mnbf$70o$1...@smc.vnet.net...