# Series and avoiding evaluation of parts of an expression

I need to use Series to expand parts of an expression while leaving other parts alone. Both the parts-to-be-expanded and the parts-to-be-ignored include the expansion variable so I want to shield part of the expression from Series.

For example, assume the expression is of the form x Exp[x^2], then I would like to use Series to expand the leading x term and to ignore the Exp[x^2] term. My use case seems to cry out for Hold, Inactivate or Unevaluated.

Let's first look at which forms survive the Series. Here is small table of possible expressions and the results from the Series operation:

Clear[f2,x];
f2 = {Exp[x^2],Hold[Exp[x^2]], HoldAll[Exp[x^2]], HoldAllComplete[Exp[x^2]], HoldForm[Exp[x^2]], Inactivate[Exp[x^2]], Unevaluated[Exp[x^2]]};
TableForm[Table[{f2[[i]], Series[f2[[i]] x , {x, 0, 2}]}, {i, 1, Length[f2]}]]


Mathematica v 10.4.1 gives

$$\left( \begin{array}{cc} e^{x^2} & \text{x}+O\left(\text{x}^3\right) \\ \text{Hold}\left[\exp \left(x^2\right)\right] & \text{Hold}[1] \text{x}+O\left(\text{x}^3\right) \\ \text{HoldAll}\left[e^{x^2}\right] & \text{HoldAll}[1] \text{x}+O\left(\text{x}^3\right) \\ \text{HoldAllComplete}\left[e^{x^2}\right] & \text{HoldAllComplete}[1] \text{x}+O\left(\text{x}^3\right) \\ \exp \left(x^2\right) & 1 \text{x}+O\left(\text{x}^3\right) \\ \exp (x{}^{\wedge}2) & \left(\text{x}+O\left(\text{x}^3\right)\right) \exp (x{}^{\wedge}2) \\ \text{Unevaluated}\left[\exp \left(x^2\right)\right] & \text{x}+O\left(\text{x}^3\right) \\ \end{array} \right)$$

It's surprising (at least to me) that the Series operator ignores the Holds and Unevaluated (and also that it produces symbolic derivatives of functions like Hold when the Series expansion order > 2). Only Inactivate, the next to last element in the list, protects the Exp and arguments. Fine, we can use Inactivate.

Unfortunately, the above method turns out not to be generally useful and whether Series operates on the argument depends upon the form of the argument! Here is a comparison of Exp[x] vs Exp[x^2]:

g = {Inactivate[Exp[x]], Inactivate[Exp[x^2]]};
TableForm[Table[{g[[i]], Normal[Series[g[[i]] x , {x, 0, 3}]],Activate[Normal[Series[g[[i]] x , {x, 0, 3}]]]}, {i, 1, Length[g]}]]


gives

$$\left( \begin{array}{ccc} \exp (x) & \frac{1}{2} \exp (0) x^3+\exp (0) x^2+\exp (0) x & \frac{x^3}{2}+x^2+x \\ \exp (x{}^{\wedge}2) & x \exp (x{}^{\wedge}2) & e^{x^2} x \\ \end{array} \right)$$

The second form (retaining the Exp[x^2] in the final result) is what I want. The first form (where Exp[x] has been expanded in the final result) is what I am trying to avoid.

I need to understand what the rules are for Series and how to avoid its operation on the arguments of particular functions.

I confirm March's comment below: there is something very different about the handling of the two cases Exp[x] and Exp[x^2].

• It would be helpful if you gave specific examples of the transformations you would like to achieve. Are you actually wanting to do the expansion for large x e.g. Series[f[x],{x,Infinity,2}]? This gives results similar to the form I think you are trying to achieve. – mikado Aug 26 '16 at 19:36
• The example I gave was the simplest one that illustrated the problem. My actual intended application is very complicated and of no interest I'm sure. For a slightly more complicated version, write F=G(x)*H(x) where G is either an exponential (Exp[-Abs[x]/a) or a Gaussian (Exp[-x^2/a^2) and H is Tanh[x]. I want H expanded and G left alone. I useF[x] = Inactivate[G[x]]*H[x] and try to expand F[x] with Series. In particular, using a construction like Activate[Normal[Series[F[x],{x,0,3}]]]. I find this works for the Gaussian but not the exponential! – user39757 Aug 26 '16 at 20:06
• I am not trying to use a large x expansion. I will treat the expansion of the exponential or gaussian in a different way at a later stage of the analysis (not referred to anywhere here). – user39757 Aug 26 '16 at 20:12
• It might be worth looking at the FullForms of some your expressions (for instance g in the last example). Inactivate[Exp[x]] inactivates Exp, whereas Inactivate[Exp[x^2]] inactivates both Exp and Power. – march Aug 27 '16 at 5:03
• Frankly, the result of Series[Inactive[Exp][x], {x, 0, 3}] is extremely strange to me, because it is very different than Series[Inactive[f][x], {x, 0, 3}], for instance... – march Aug 27 '16 at 5:06

One approach is to judiciously replace the series variable before using Series. Here is a function that implements this idea:

partialSeries[expr_, {x_, x0_, n_}, avoid_] := Module[{y},
Series[
expr /. {p:avoid :> p, x->y},
{y, x0, n}
] /. y -> x
]


Example:

partialSeries[Sin[x] Exp[x], {x, 0, 5}, Exp[x]] //TeXForm


$e^x x-\frac{e^x x^3}{6}+\frac{e^x x^5}{120}+O\left(x^6\right)$