MathGroup Archive 2002

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

Search the Archive

Re: Parts in color

  • To: mathgroup at smc.vnet.net
  • Subject: [mg35922] Re: [mg35905] Parts in color
  • From: "Dott. Roberto Cavaliere - SciSoft s.r.l" <rcavaliere at scisoft.it>
  • Date: Thu, 8 Aug 2002 06:06:12 -0400 (EDT)
  • References: <200208070959.FAA04533@smc.vnet.net>
  • Reply-to: "Dott. Roberto Cavaliere - SciSoft s.r.l" <rcavaliere at scisoft.it>
  • Sender: owner-wri-mathgroup at wolfram.com

Hi Carlos,
there are different ways to do this, I post just two of these, I tested on
expr = Expand[(x+y+z+x y +x z + z y )^50].

ExpressionToRedNumberFirst[expr_]:=
  DisplayForm[
                           MapAll[ If[Head[#]===Power,#, Map[ If[
NumberQ[#], StyleBox[#, FontColor->RGBColor[1,0,0]], #]&, #]]&, expr]]

ExpressionToRedNumberSecond[expr_]:=
  DisplayForm[
                          ReplaceAll[
                                               Replace[expr,
number_?NumberQ-> StyleBox[number, FontColor\[Rule]RGBColor[1,0,0]], 1],
                                              {Times[number_?NumberQ,
others___]-> Times[StyleBox[number, FontColor->RGBColor[1,0,0]],others]}]]

Using these functions you can view any (and only) coefficients in red color.
The problem is that results are no more considered as polynomial expression,
that means if you assign x= 0 and evaluate the previous result you obtain an
expression with some StyleBox forms inside.
To solve this problem simply I define another function like this:

RedNumberToExpression[expr_]:=First[ReplaceAll[expr, StyleBox[ number_,
___] -> number]]

Follow an example:
_____________________________________________________________
In[1]:= expr=Expand[(1+x y)^2]

Out[1]= 1 + 2 x y + x^2 y^2

In[2]:= result=ExpressionToRedNumberFirst[expr]
Out[2] = x^2 y^2 + 1+ x y 2 (where the number, but noexponents, are in red)

In[3]:= result /. {x->0, y->0, z->0}
Out[3]= 1 (in red)

In[4]:= result +2
Out[4]= 2+1 (1 is red)

In[5]:=RedNumberToExpression[result] + 2
Out[5]= 3
_____________________________________________________________

Hope this is what you are looking for.

Roberto Cavaliere

----- Original Message -----

From: "Carlos Cabrera Zuniga" <carloscz at ift.unesp.br>
To: mathgroup at smc.vnet.net
Subject: [mg35922] [mg35905] Parts in color


>
> Hi Group
>
> Suppose you have
>
> expr = (1+x y)^ 5 // Expand
>
> but you want the answer
> with only numbers (but not exponents) displayed in red, the rest black
> as usual.
>
> Yet i cant find how to do it efficiently.
>
>  Thanks very much in advance
>  Carlos
>
>
>
>
>
>



  • References:
    • Parts in color
      • From: "Carlos Cabrera Zuniga" <carloscz@ift.unesp.br>
  • Prev by Date: Re: Setting up dummy variables
  • Next by Date: RE: Re: Installing package "SpreadOption`"
  • Previous by thread: Parts in color
  • Next by thread: Calculating the area surrounded by a closed contour curve.