# Series for Sin[x] with specific notation

I'm trying to get mathematicas series function for Sin[x] to output a result that look like this:

$$\sin x=\sum_{n=0}^{\infty} \frac{(-1)^{n}}{(2 n+1) !} x^{2 n+1}$$

I referred to ybeltukov's answer and used his code. https://mathematica.stackexchange.com/a/71593/69835

Clear["Global*"];
series[expr_, x_, x0_] :=
Defer[expr = Sum[#, {n, 0, \[Infinity]}]] &[
FullSimplify@
SeriesCoefficient[expr, {x, x0, n},
Assumptions -> {n >= 0}] (x - x0)^n]
series[Sin[x], x, 0]


$$\operatorname{Sin}[x]=\sum_{n=0}^{\infty} \frac{i i^{n}\left(-1+(-1)^{n}\right) x^{n}}{2 n !}$$

However, the result contains some complex numbers.

How to get the result in real number form

$$\sin x=\sum_{n=0}^{\infty} \frac{(-1)^{n}}{(2 n+1) !} x^{2 n+1}$$ ?

A slight modification

Clear["Global*"];
series[expr_, x_, x0_] := Defer[expr = Sum[#, {n, 0, \[Infinity]}]] &[
FullSimplify[ComplexExpand[SeriesCoefficient[expr, {x, x0, 2 n + 1}]],
Assumptions -> n >= 0 && n \[Element] Integers] (x - x0)^(2 n + 1)]


works for odd functions:

series[Sin[x], x, 0]


$$\sin (x)=\sum _{n=0}^{\infty } \frac{(-1)^n x^{2 n+1}}{\Gamma (2 n+2)}$$

• Nice. Minor suggestion, you can add ComplexityFunction -> ((LeafCount@# + 10 Count[#, _Gamma | _Pochhammer, {0, \[Infinity]}]) &) in FullSimplify to take care of the Gamma --- see this
– user49048
Commented Mar 15, 2022 at 17:10
• @user64494 Great answer! Thank you! Commented Mar 16, 2022 at 2:34
• @kcr Thank you! The expression is perfect after your slight modification. Commented Mar 16, 2022 at 2:37
Entity["MathematicalFunction", "Sin"]["SeriesRepresentations"][[2]][


% // Activate

(* True *)


EDIT: For a cleaner display

Entity["MathematicalFunction", "Sin"]["SeriesRepresentations"][[2]][x] //