1
$\begingroup$

Is there an easy way to have Mathematica display a polynomial in "exponential generating function" form? So, for example, rather than seeing $$1 + 2 x + 3 x^2 + 4 x^3$$ I would like to see $$1 + \frac{1}{1!} 2 x + \frac{1}{2!} 6 x^2 + \frac{1}{3!} 24 x^3$$ It would be especially nice if the output could also be captured in TeX format, as in TeXForm[].

$\endgroup$

2 Answers 2

0
$\begingroup$

You can easily do this by a simple replacement rule with the command Inactive:

(1 + 2 x + 3 x^2 + 4 x^3) /.  x_^n_ :> x^n Factorial[n]/Inactive[Factorial][n]

which yields the desired output

1+2 x+(6 x^2)/(2!)+(24 x^3)/(3!)

In addition, you can directly hit TeXForm without any problem and capture the desired form:

(1 + 2 x + 3 x^2 + 4 x^3) /. x_^n_ :> x^n Factorial[n]/Inactive[Factorial][n] // TeXForm

$\frac{24 x^3}{3!}+\frac{6 x^2}{2!}+2 x+1$

$\endgroup$
3
  • $\begingroup$ I understood this as wanting the taylor series. For example, Series[Exp[x], {x, 0, 10}] for example, Sum[term[Exp[x],x,0,n],{n,0,10}] will give !Mathematica graphics but may be my understanding was wrong. $\endgroup$
    – Nasser
    Commented Apr 21, 2018 at 4:11
  • $\begingroup$ Hmm, I thought the question was about display. Well, s/he now has both answers :D $\endgroup$ Commented Apr 21, 2018 at 5:00
  • $\begingroup$ By way of clarification, there are many sources of generating functions other than Series[], so I did not intend my question to be limited to the output of Series[]. However, Carl Wolf's example shows that an arbitrary polynomial can be an input to Series[], which then spits it out unaltered, so limiting the action to the output of Series[] is not an actual limitation. $\endgroup$
    – awkward
    Commented Apr 22, 2018 at 12:51
1
$\begingroup$

Here is a method that produces the appearance you requested. First, I define a wrapper that renders coefficients the way you want:

MakeBoxes[form[n_,r_], form_] ^:= TagBox[
    RowBox[{MakeBoxes[1/n!], MakeBoxes[r,form]}],
    #&,
    SyntaxForm->Power
]
MakeBoxes[form[0,r_], form_] := MakeBoxes[r, form]

For example:

form[2,6] //TeXForm

$\frac{1}{2!}6$

Then, I define a function to transform a SeriesData object (produced by the Series function):

toEGF[HoldPattern@SeriesData[a_,b_,c_,d_,e_,f_]] := Module[
    {orders, coeffs},

    orders = Range[d,d+Length[c]-1];
    coeffs = Replace[
        Transpose[{orders, orders! c}],
        {n_,r_}:>form[n,r]
        {1}
    ];
    SeriesData[a,b,foo,d,e,f]
]

Your example:

ser = Series[1 + 2x + 3x^2 + 4x^3, {x, 0, 3}];
ser //toEGF //TeXForm

$$1+\frac{1}{1!}2 x+\frac{1}{2!}6 x^2+\frac{1}{3!}24 x^3+O\left(x^4\right)$$

$\endgroup$
1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.