2010年7月4日 星期日

Fwd: how to tell Mathematica to display x^-1 as x^-1 and not as 1/x

---------- Forwarded message ----------
From: "Sjoerd C. de Vries" <sjoerd.c.devr...@gmail.com>
Date: 7月4日, 下午3時08分
Subject: how to tell Mathematica to display x^-1 as x^-1 and not as 1/
x
To: comp.soft-sys.math.mathematica


Hi Nasser,

I think the construction below should work. I don't have much
experience with this, but I couldn't find any side effect.

Unprotect[Power];
Power /: MakeBoxes[Power[x_, y_], StandardForm] :=
 RowBox[{MakeBoxes[x, StandardForm], "^", MakeBoxes[y, StandardForm]}]
Protect[Power];

Cheers -- Sjoerd

On Jul 3, 2:19 pm, "Nasser M. Abbasi" <n...@12000.org> wrote:

> Hello;

> When I type

> x^-1

> Mathematica replies

> 1/x

> Is there a way to tell Mathematica to *display* terms with negative
> powers as  x^-n  and not as 1/x^n ? (i.e keep the term just like it
> would appear on paper).

> Another example, suppose I type

> expr = a*x^-2 + b *x^-1 +

> The reason I want to do this, is just for display purposes. When I print
> the expression on the screen, I'd like it to look like x^-1 and not like
> 1/x (to better match how the expression look like in the textbook)

> I am trying to avoid having to convert everything to a string, and force
> the form to the way I want.  I tried Hold functions, and
> TraditionalForm, but can't get it to print as I want.

> I am hoping there is an easy trick to do this?

> thanks
> --Nasser

沒有留言:

張貼留言