# Polynomial with alternating sign coefficients from the odd degree terms of a Truncated Power Series

I'm trying to make a function that will take any truncated power series I give it, strip away all the even degree terms, then change the sign of the coefficients of every other term. So that we have a polynomial with only odd degree terms with alternating sign.

f = 2^x;
ff = Normal[Series[f, {x, 0, 10}]];
ffOdd = FromCoefficientRules[
Pick[
CoefficientRules[ff, x],
And @@ OddQ[#[]] & /@ CoefficientRules[ff, x]],
x]


I've been able to figure out everything but the alternating sign part.

Update:

Expanding on DumpsterDoofus's answer I was able to mix and match the desired properties as well:

n = 10;
f[x_] := 2^x;
fSeries = Normal[Series[f[x], {x, 0, n}]]
fOdd = Normal[Series[(f[x] - f[-x])/2, {x, 0, n}]]
fEven = Normal[Series[(f[x] + f[-x])/2, {x, 0, n}]]
fOddAlt = Normal[Series[(f[I x] - f[-I x])/(2 I), {x, 0, n}]]
fEvenAlt = Normal[Series[(f[I x] + f[-I x])/2, {x, 0, n}]]

• Just to point out a small thing: If we change the sign of every other odd power term, we do not always get a polynomial with only odd degree terms with alternating sign. For example, f = Sin[x]. – Michael E2 Nov 15 '14 at 20:10

The fastest way to do this is to note that for any function $f$ with a convergent power series, the quasi-hyperbolic function $$g(x)=\frac{f(ix)-f(-ix)}{2i}$$ has the power series of $f$ with only odd, alternating sign terms (provided that it converges).

Here's an example:

f[x_] := x + x^2 + x^3 - x^4;
(f[I x] - f[-I x])/(2 I) // Simplify


which produces

x - x^3

• very nice +1 :) – ubpdqn Nov 15 '14 at 2:40
• Hey! That's cheating! You know maths! – Dr. belisarius Nov 15 '14 at 2:59
• @belisarius: Huge thanks to Spot and Blasternaut. – DumpsterDoofus Nov 15 '14 at 3:29
• @BobHanlon: Yup, you're right, it looks like it fails when $f$ doesn't have a convergent series (and I imagine there's cases where it fails even when it does), edited answer to address this. It does seem to work with $f(x)=\log(1+x)$ though, presumably because it has a convergent series. – DumpsterDoofus Nov 15 '14 at 14:49
• Convergence seems a side issue since in the question we're given a Taylor polynomial to operate on.. (+1) – Michael E2 Nov 15 '14 at 20:03
n = 9;
l = CoefficientList[Series[E^x, {x, 0, n}], x];
l1 = PadRight[#, Length@l, #] &@ {0, 1, 0, -1};
Expand@FromDigits[Reverse[l l1] , x]

(* x - x^3/6 + x^5/120 - x^7/5040 + x^9/362880 *)


Or using CoefficientRules[]:

FromCoefficientRules[
CoefficientRules[
Normal@Series[E^x , {x, 0, n}], x] /. ({n_} -> x_) /; EvenQ@n        :> {n} -> 0
/. ({n_} -> x_) /; Mod[n, 4] != 1 :> {n} -> -x, x]


Or even:

Expand@FromDigits[Table[SeriesCoefficient[Exp[x], {x, 0, m}] Mod[(2 + m) (4 + m (4 + 3 m)), 4, -1],
{m, n, 0, -1}], x]

func[pol_, var_] :=
FromCoefficientRules[
MapIndexed[First@#1 -> Last@#1 (-1)^(First@#2 - 1) &,
SortBy[Cases[List @@@ CoefficientRules[Normal@pol], {{_?OddQ}, _}],
First]], var]


e.g. func[ff,t]

yields:

t Log - 1/6 t^3 Log^3 + 1/120 t^5 Log^5 - (
t^7 Log^7)/5040 + (t^9 Log^9)/362880


and

func[Series[E^x, {x, 0, 10}], t]


yields:

t - t^3/6 + t^5/120 - t^7/5040 + t^9/362880