MathGroup Archive 2000

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

Search the Archive

Re: I wish Descending Order Result

  • To: mathgroup at smc.vnet.net
  • Subject: [mg24011] Re: I wish Descending Order Result
  • From: Hartmut Wolf <hwolf at debis.com>
  • Date: Tue, 20 Jun 2000 03:07:29 -0400 (EDT)
  • Organization: debis Systemhaus
  • References: <8ice31$9vm@smc.vnet.net> <8ihslq$l5m@smc.vnet.net> <8ikbs4$qai@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

Dear Allan and Jens,

last year I responded to a similar question by George Szpiro. The idea was 
to just define a *printing* order. This might comply to the wishes of the 
applicant; the advantage is, that processing will not be effected. I then 
had proposed:

In[2]:= Unprotect[Plus]

In[3]:=
Format[Literal[Plus][expr_]] := 
  Infix[#, "+"] &@
    With[{expoes = Function[term, Exponent[term, #] & /@ Variables[expr]], 
        newExp = Delete[#1, Last[Position[#1, Max[#1]]]] &}, Module[{so},
        so[_, {}] := True; 
        so[x1_, x2_] := 
          With[{m1 = Max[x1], m2 = Max[x2]}, 
            If[m1 == m2, so[newExp[x1], newExp[x2]], m1 > m2]]; 
        Sort[List @@ Expand[expr], so[expoes[#1], expoes[#2]] &]]]
In[4]:=
Protect[Plus]

with that we get

In[5]:=
Expand[(1 + 2 a + 3 b)^3]
Out[5]=
\!\(\*
  InterpretationBox[\(8\ a\^3 + 27\ b\^3 + 36\ a\^2\ b + 54\ a\ b\^2 + 
      12\ a\^2 + 27\ b\^2 + 36\ a\ b + 6\ a + 9\ b + 1\),
    Infix[ {
      Times[ 8, 
        Power[ a, 3]], 
      Times[ 27, 
        Power[ b, 3]], 
      Times[ 36, 
        Power[ a, 2], b], 
      Times[ 54, a, 
        Power[ b, 2]], 
      Times[ 12, 
        Power[ a, 2]], 
      Times[ 27, 
        Power[ b, 2]], 
      Times[ 36, a, b], 
      Times[ 6, a], 
      Times[ 9, b], 1}, "+"],
    Editable->False]\)

(If you like to paste this to the notebook). Now for your test we
get:

In[7]:=
Expand[(1 + x)^2]
Out[7]=
\!\(\*
  InterpretationBox[\(x\^2 + 2\ x + 1\),
    Infix[ {
      Power[ x, 2], 
      Times[ 2, x], 1}, "+"],
    Editable->False]\)
In[8]:=
x (1 + x + x^2)
Out[8]=
\!\(\*
  RowBox[{"x", " ", 
    RowBox[{"(", 
      InterpretationBox[\(x\^2 + x + 1\),
        Infix[ {
          Power[ x, 2], x, 1}, "+"],
        Editable->False], ")"}]}]\)
In[9]:=
Expand[%]
Out[9]=
\!\(\*
  InterpretationBox[\(x\^3 + x\^2 + x\),
    Infix[ {
      Power[ x, 3], 
      Power[ x, 2], x}, "+"],
    Editable->False]\)
In[10]:=
D[%%, x]
Out[10]=
\!\(\*
  InterpretationBox[\(3\ x\^2 + 2\ x + 1\),
    Infix[ {
      Times[ 3, 
        Power[ x, 2]], 
      Times[ 2, x], 1}, "+"],
    Editable->False]\)

(Again, best to be pasted to the notebook; for your convenience this
is the last result in InputForm:

Out[10]=
Infix[{3*x^2, 2*x, 1}, "+"]

)

Kind regards,  Hartmut


Allan Hayes schrieb:
> 
> Jens,
> 
> I have used your suggestion to get a solution that deals with deeper
> polynomial parts
> 
> $Post = # //. (x_Plus /; PolynomialQ[x] :>
> Infix[Reverse[List @@ x], "+"]) &
> 
> Unfortunately, although this is fine for appearence, for further computation
> we run into problems analogous to those with Matrix form and other wrappers:
> 
> x(1 + x + x^2)
> 
> Expand[%]
> 
> D[%%]
> 
> $Post = .
> 
> So, what to do?
> 
> --
> Allan
> ---------------------
> Allan Hayes
> Mathematica Training and Consulting
> Leicester UK
> www.haystack.demon.co.uk
> hay at haystack.demon.co.uk
> Voice: +44 (0)116 271 4198
> Fax: +44 (0)870 164 0565
> 
> "Jens-Peer Kuska" <kuska at informatik.uni-leipzig.de> wrote in message
> news:8ihslq$l5m at smc.vnet.net...
> > Hi,
> >
> > $Post = If[Head[#] === Plus && PolynomialQ[#],
> >       Infix[Reverse[List @@ #], "+"], #] &
> >
> > ?
> >
> > Regards
> >   Jens
> >
> > Choi sungkwon wrote:
> > >
> > > In Mathmatica,
> > >
> > > When I Typing
> > >   Expand[(1 x)^2]
> > > Then Mathmatica Wrote 1   2 x   x^2
> > >
> > > But I Wish the result to
> > >     x^2   2 x   1
> > > ie Descending Order Result for x
> > >
> > > What can I do
> >



  • Prev by Date: Re: And, Or, Intersection, Union - no Orderless attribute
  • Next by Date: RE: Re: Functional Expression Meaning (was:A Functional Expression Trick)
  • Previous by thread: Re: I wish Descending Order Result
  • Next by thread: Fonts & Printing