MathGroup Archive 1997

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

Search the Archive

Use a nicer Format for differences

  • To: mathgroup at smc.vnet.net
  • Subject: [mg6427] Use a nicer Format for differences
  • From: Ersek_Ted%PAX1A at mr.nawcad.navy.mil
  • Date: Thu, 20 Mar 1997 00:52:24 -0500 (EST)
  • Sender: owner-wri-mathgroup at wolfram.com

If you have a difference of two terms Mma presents them so they are in 
standard order.  Consider the following:

In[1]:=  y-d

Out[1]= -d+y

It puts "-d" before "y", and most would find this unapealing.
You can get the nicer result by using TraditionalForm.

In[2]:= y-d//TraditionalForm

Out[2]=y-d

 ----------------------------------------------------------------------------  
 -----------------------
You can also get the nicer result by writing your own Format.
Dave Withoff at WRI helped me get this working.
However, he hasn't seen my latest version.

In[3]:=Unprotect[Plus];

             Format[(n_Real | n_Integer | n_Rational)*a_.+b_/;
             (Head[b]=!=Plus)&&(n<0)&&OrderedQ[{n*a,b}]]:=
             SequenceForm[b,"-",-n*a]

             Protect[Plus];

 ----------------------------------------------------------------------------  
 ----------------------
After entering In[3] any of the following are displayed as a difference in 
Out[n].
   y-d
   y-3 d
   y-2/3 d
   y-1.25 d
   y-2/3
   y-a b

Also this format is used when the difference is inside another function.
As in:    1/Log[y-3 d]

However, this format is not used when more that two terms are added / 
subtracted.
This is the way I wanted it.

Eventually I will have the above Format used automatically as soon as Mma is 
opened.  However, I have yet to figure out that part.

               Ted Ersek



  • Prev by Date: 3D Plots
  • Next by Date: fonts
  • Previous by thread: Re: Solving Underdamped Equation of motion
  • Next by thread: Re: Use a nicer Format for differences