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[].
2 Answers
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$
-
$\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$– NasserApr 21, 2018 at 4:11 -
$\begingroup$ Hmm, I thought the question was about display. Well, s/he now has both answers :D $\endgroup$ 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$– awkwardApr 22, 2018 at 12:51
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)$$
-
$\begingroup$ Considering the skills you demonstrate here you might have an answer or hint for my question here: mathematica.stackexchange.com/questions/214361/… $\endgroup$ Feb 10, 2020 at 10:47