It is very easy using Series
to get series expansion but the output is never in the way we see them in math textbooks where they are more understandable. Il' take take 2 examples
$e^{x}~=~1+~x~+\frac{x^{2}}{2!}~+~\frac{x^{3}}{3!}~+~~\frac{x^{3}}{4!}~+...$.
$\arcsin x~=~x~+~\frac{x^{3}}{2 \cdot3}~+~\frac{1 \cdot 3 }{2 \cdot4 \cdot 5}~ x^{5}~+~\frac{1 \cdot 3 \cdot5}{2 \cdot4 \cdot 6 \cdot7}~ x^{7}~+~....$
I tried to get the above output using MMA, with not much success
My first idea was to start with the summation of the general term of a MacLaurin series
gterm[f_, x_, n_] := x^(n - 1) (D[f[x], {x, n - 1}] /. x -> 0)/(n - 1)!
exp = Sum[gterm[Exp, x, k], {k, 1, 5}]
No way to put a Hold
or HoldForm
somewhere in the definition of my function gterm
to prevent the evaluation of the factorial.
So I started toying then with patterns and I came out with something which works with $e^x$ but leaves me unsastified as hardly generalisable.
fx[a_] :=
Module[{}, maj = Cases[a, Times[_, Power[x, e_]] :> HoldForm[e!]];
pos = Position[a, _Rational]; ReplacePart[a, Thread[pos -> 1/maj]]]
exp // fx
And my knowdledge of MMA is not good enough to handle the ArcSin
case in such a way ..
Is there a better solution than the one I'm not satisfied with and could be adapted with minimal effort to handle more elaborate cases ? Thanks.