If I type in a power series in which one of the coefficients is itself a power series, the appropriate simplifications happen automatically. For example, typing
1 + (3 + 5 x + O[x]^3) x + O[x]^7
gives
1 + 3 x + 5 x^2 + O[x]^4
But if I instead substitute in the coefficient series after the fact, as in
(1 + a x + O[x]^7) /. a -> 3 + 5 x + O[x]^3
I end up with a SeriesData object whose coefficients are themselves SeriesData objects:
1 + (3 + 5 x + O[x]^3) x + O[x]^7
Given this structure, how can I now cause the appropriate simplifications to happen? ExpandAll doesn’t do it, and I don’t know what else to try.
The attached notebook gives the same example,
Lyle Ramshaw
In[291]:= (1 + a x + O[x]^7) /. a -> 3 + 5 x + O[x]^3 // Normal
Out[291]= 1 + 3 x + 5 x^2
In[292]:= Normal[(1 + a x + O[x]^7)] /. a -> 3 + 5 x + O[x]^3
Out[292]= SeriesData[x, 0, {1, 3, 5}, 0, 4, 1]
In[293]:= FullForm[(1 + a x + O[x]^7) /. a -> 3 + 5 x + O[x]^3]
Out[293]//FullForm= SeriesData[x,0,List[1,SeriesData[x,0,List[3,5],0,3,1]],0,7,1]
nested SeriesData[] seem not to Expand[], %292 does what you possibly expect.
Udo, thanks for the tip; but Normal does not do what I want, since it truncates the series to which it is applied. Truncating the outer series in the particular example that I gave happens to produce the correct answer, since the error term of O^7 in the outer series ends up being ignored. But, in other examples, truncating would give the wrong answer. I want to combine the inner and outer power series with the proper semantics, as happens correctly if both series are part of the initial typein. For example, typing in
1 + (3 + 5 x + O[x]^9) x + O[x]^7
gives
1+ 3 x + 5 x^2 + O[x]^7
while typing in
1 + (3 + 5 x + O[x]^3) x + O[x]^7
gives
1+ 3 x + 5 x^2 + O[x]^4
Note that, in the first example, it is the error term of the outer series that dominates, while, in the second example, it is the error term of the inner series that dominates. If I just apply Normal to either of the two series, I will lose this correct behavior.
it would be quite an exercise to apply Normal[] automatically to the non-dominant error term - the goal is to avoid nested SeriesData[] expressions for the time being.
Udo’s clever idea of using a function application, rather than a transformation rule, in order to substitute one series in as a coefficient of another series has solved my immediate problem very neatly -- thank you! But it might be nice if using a transformation rule also worked in this context,