# Problem with SeriesData

## Problem:

I need to find the leading order term in an expansion whose leading order behavior is a priori unknown. I can of course go with Series and try different orders, say Series[f[x],{x,x0,n}] for different $n$, however I would like to find a more elegant way. Also each calculation takes very long (almost an hour) so this is not an efficient way (that it takes so long is because my function is convoluted and involves special functions, mostly hypergeometric functions).

There is already a very elegant answer to this question here: Series with a specified number of terms . Basically, it replaces the variable $x$ with its series data version, say $x+O[x]^2$, and then truncates the extra terms by multiplying another SeriesData object. For example,

(x^2 Sin[a x]^2 /. x -> Series[x, {x, 0, 1}]) (1 + O[x])


gives the correct leading order term $a x^4$.

My problem with this approach is that replacing $x$ with its SeriesData version gives incorrect results for symbolic powers. For example, let us consider the function $\left(-x^2\right)^a \sin (x)$. We see that

FullSimplify[((-x^2)^a Sin[x] /. x -> Series[x, {x, 0, 1}]) (1 + O[x]) /. a ->1/2, x > 0]


gives incorrect result -x^2+O[x]^3 whereas the correct result is I x^2+O[x]^3 as can be obtained via

FullSimplify[Series[(-x^2)^a Sin[x], {x, 0, 1}] /. a -> 1/2, x > 0]


This problem can be avoided, at least in this particular example, if one does not use the SeriesData replacement but only chops off higher order terms with the command:

FullSimplify[((-x^2)^a Sin[x]) (1 + O[x]) /. a -> 1/2, x > 0]


Also, the problem does not arise if the symbolic coefficient is given from the beginning since

(-x^2)^(-1/2) /. x -> Series[x, {x, 0, 1}]


yields $$\begin{cases} \left(\frac{1}{\sqrt{-x^2}}\right)^*+O\left(x^1\right) & -\Im\left(x^2\right)<0 \\ \frac{1}{\sqrt{-x^2}}+O\left(x^1\right) & \text{True} \end{cases}$$ accounting probable complex nature of $x$ whereas the same command fails for symbolic power as

(-x^2)^a /. x -> Series[x, {x, 0, 1}]


directly yields $$(-x)^{2 a} \left(1+O\left(x^1\right)\right)$$

## Questions

• Is it a bug that Mathematica evaluates $(-x^2)^a$ to $(-x)^{2a}$ when $x$ is replaced with a SeriesData form $x+O[x]^2$ ?
• If it is not a bug, then why do this feature not commute with replacing a symbolic power? (I am under the impression that $a\to 1/2$ should commute with $x\to x+O[x]^2$)
• I tried wrapping with Assuming, giving the information $x>0$ etc in \$Assumptions and using \$Pre=Refine etc but none of them helped. Does anyone have any idea that I can use to ensure that replacing $x$ with SeriesData works correctly?
• My main requirement is actually finding the leading order term. Would only multiplying with $(1+O[x])$ at the end works as well? (It works for this small example but my function is a long expression including tens of hypergeometric functions so I am uncertain how much this method would work)
• Does anyone know any alternative way for finding leading order term in a series expansion with symbolic exponents?
• I am using version 11.2 Is the situation same in other versions? (I plan to upgrade once 11.3 is released this month)
• Please do not use the bugs tag until other users have confirmed your observations. – J. M.'s technical difficulties Mar 9 '18 at 7:58
• My apologies, thanks for pointing that out. – Soner Mar 9 '18 at 8:28
• Series does not do well with symbolic powers. It's not a bug per se, its a limitation since this falls outside the scope of what it will handle. – Daniel Lichtblau Mar 9 '18 at 15:53
• I actually do not have problem with Series: It indeed does not calculate what I want however it does not give me incorrect results either. SeriesData on the other hand does give me incorrect result, that is why I think it is a bug. As an example, Series[(-x (x - a))^b, {x, Infinity, 0}] does not evaluate but replacing $x$ with $x+O[1/x]^0$ gives incorrect answer, whereas it should be Mathematically equivalent. Please see Carl Woll's answer here: mathematica.stackexchange.com/questions/80107/… – Soner Mar 9 '18 at 18:06
• SeriesData is using upcode in the Series world. You will see the same issue with InputForm[Series[-x^2,{x,0,2}]^a] Out[7]//InputForm= (-x)^(2*a)*SeriesData[x, 0, {1}, 0, 1, 1]. It's basically doing what it is supposed to do, but operating outside the realm of algebraic functions. Getting it to behave inside that realm, e.g. with rational powers, has been dicey already. – Daniel Lichtblau Mar 9 '18 at 22:32

1. I would say that it is a bug that (-x^2)^a gets changed to (-x)^(2a). The domain of variables is clearly stated as complex, where such transformations are not valid. However, this is an error not quite on the same order as thinking that Sqrt[(E-Pi)^2] is negative.
3. There is no reason to suspect that evaluation of SeriesData objects even looks at assumptions. For example, Assuming[a>5,Series[x,{x,0,3}]+Series[x,{x,0,5}]^a]] does not quite give what you would expect.
4. Since the question is a bit more tricky for symbolic exponents, I would not expect anything simple to work. For example, what do you expect from x^a+x^b, or even x^a+x^a^2?
5. If you have symbolic exponents I would suggest substituting rational values for them, collecting the leading term using reliable methods that you already mentioned, and then recovering the leading exponent from FindSequenceFunction.