MathGroup Archive 2005

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

Search the Archive

Re: Expression transformation

  • To: mathgroup at smc.vnet.net
  • Subject: [mg59311] Re: [mg59268] Expression transformation
  • From: "David Park" <djmp at earthlink.net>
  • Date: Fri, 5 Aug 2005 01:21:59 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

The following is a useful routine that is missing in Mathematica.

MapLevelParts::usage =
    "MapLevelParts[function, {topposition, levelpositions}][expr] will map \
the function onto the selected level positions in an expression. \
Levelpositions is a list of the selected parts. The function is applied to \
them as a group and they are replaced with a single new expression. Other \
parts not specified in levelpositions are left unchanged.\nExample:\na + b +
\
c + d + e // MapLevelParts[f, {{2,4,5}}] -> a + c + f[b + d + e]";

MapLevelParts[func_,
      part : {toppart___Integer?Positive,
          subp : {_Integer?Positive, eprest__Integer?Positive}}][expr_] :=
  Module[{work, subparts, npos, null, i, nnull = Length[{eprest}],
tempfunc},
    work = tempfunc@Part[expr, Sequence @@ part];
    subparts = Thread[{toppart, subp}];
    newparts = {work, Table[null[i], {i, 1, nnull}]} // Flatten;
    npos = Partition[Range[nnull + 1], 1];
    work =
      ReplacePart[expr, newparts, subparts, npos] /. null[_] -> Sequence[];
    work /. tempfunc -> func
    ]

Then for your expression...

expr = Exp[-x] + (a + b Exp[-x])/c;

expr // Expand
% // MapLevelParts[Together, {{2, 3}}]
1/c Distribute[c %]

a/c + E^(-x) + b/(E^x*c)
a/c + (b + c)/(E^x*c)
(a + (b + c)/E^x)/c

where the E^x in the denominator actually displays as E^(-x) in the
numerator.

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/




From: mumbojumbo [mailto:mjumbo at gmail.com]
To: mathgroup at smc.vnet.net


Dear forum,

How can I  persuade Mathematica to transform the expression
  Exp(-x)+(a+b Exp[-x])/c
to the form
(a+(b+c)Exp(-x))/c

I have tried Together[...] and Simplify, but I always get
(b + c + a*E^x)/(c*E^x)
It looks like Mathematica is silently transforming Exp[-x] to
1/Exp[x]. How can I disable this transformation?

I am asking because in applications some equivalent forms are more
equivalent than others e.g. Exp[-u/(kT)]-1 is considered a proper form,
while (1- Exp[u/(kT)])/Exp[u/(kT)] is not.

Thanks, Yuri.

                         mailto:mjumbo at gmail.com



  • Prev by Date: Re: Default defaults?
  • Next by Date: Re: Pure Function within a pure function
  • Previous by thread: Re: Expression transformation
  • Next by thread: Simple question