Re: Ouput Form
- To: mathgroup at smc.vnet.net
- Subject: [mg42496] Re: [mg42445] Ouput Form
- From: Omega Consulting <info at omegaconsultinggroup.com>
- Date: Fri, 11 Jul 2003 02:57:57 -0400 (EDT)
- Sender: owner-wri-mathgroup at wolfram.com
At 03:37 AM 7/8/2003, Ashraf El Ansary wrote:
>Dear All,
>I'm trying to get to give result in the form of a quotient in the following
>example
>
>In[1]:=
>\!\(Together[2 - \(n + 2\)\/2\^n]\)
>Out[1]=
>\!\(2\^\(-n\)\ \((\(-2\) + 2\^\(1 + n\) - n)\)\)
>
>
>
>I know that if n is negative the above will be true, is there a way to tell
>mathematica that n is positive number so that the output would look as
>follows:
>
>(-2+2^(1+n)-m)
>------------------ that is (-2+2^(1+n)-m)/(2^n)
>2^n
>
>rather than have a negative exponent in the numerator
>
>Thank you very much
>
>Ashraf
It's not a matter of whether n is positive or not. It's a matter of how the
expression gets formatted.
Oddly enough, InputForm and OutputForm seem to do the trick.
In[17]:=
Together[2 - (n + 2)/2^n]//InputForm
Out[17]//InputForm=
(-2 + 2^(1 + n) - n)/2^n
In[18]:=
Together[2 - (n + 2)/2^n]//OutputForm
Out[18]//OutputForm=
1 + n
-2 + 2 - n
---------------
n
2
StandardForm can also be altered by making MakeBoxes assignments.
In[25]:=
MakeBoxes[Times[Power[b_, Times[coef_?Negative, exp___]], rest___],
StandardForm] :=
FractionBox[MakeBoxes[rest, StandardForm],
ToBoxes[Power[b, Times[-coef, exp]]]]
--------------------------------------------------------------
Omega Consulting
"The final answer to your Mathematica needs"
http://omegaconsultinggroup.com