TransWikia.com

Force Mathematica to display `Series` in factorial notation

Mathematica Asked on July 22, 2021

The Series expansion for Sin[Pi * x] is

Series[Sin[Pi * x], {x, 0, 10}]

Pi * x – (Pi^3 * x^3) /6 + (Pi^5 * x^5) /120 – (Pi^7 * x^7) /5040 +
(Pi^9 * x^9) /362880 + O[x]^11

How can I make Mathematica display this using factorial notation? I’d prefer this to read

Pi * xn – (Pi^3 * x^3) /3! + (Pi^5 * x^5) /5! – (Pi^7 * x^7) /7! +
(Pi^9 * x^9) /9! + O[x]^11

I appreciate that the result in InputForm is

InputForm[Series[Sin[Pi * x], {x, 0, 10}]]

SeriesData[x, 0, { Pi, 0, Rational[-1, 6] Pi^3, 0, Rational[1, 120]
Pi^5, 0, Rational[-1, 5040] Pi^7, 0, Rational[1, 362880] Pi^9}, 1,
11, 1]

So, equivalently, I’m after the output

SeriesData[x, 0, { Pi, 0, Rational[-1, Factorial[3]] Pi^3, 0, Rational[1, Factorial[5]]
Pi^5, 0, Rational[-1, Factorial[7]] Pi^7, 0, Rational[1, Factorial[9]] Pi^9}, 1,
11, 1]

3 Answers

You can do this with some tinkering with Inactive, since that's one of the ways to prevent the factorial from evaluating:

factorialForm[s : HoldPattern @ SeriesData[x_, x0_, coeffList_List, n0_, n1_, 1]] :=
     With[{powRange = Range[n0, n0 + Length[coeffList] - 1]},
      SeriesData[x, x0,
       Divide[
        coeffList * Factorial[powRange],
        Map[Inactive[Factorial], powRange]
       ],
       n0, n1, 1
      ]
     ];
factorialForm[Series[Sin[x], {x, 0, 10}]]

enter image description here

Instead of Inactive[Factorial] there are other holding constructs you can use, like Defer[Factorial[#]]& or HoldForm[Factorial[#]] &. The nice thing about Inactive is that you can easily get rid of it again with Activate.

I only implemented this for SeriesData[__, 1]. You'd have to do a little thinking if you to make it work for other step sizes.

Correct answer by Sjoerd Smit on July 22, 2021

Also possible is:

$Post = #1 /. HoldPattern[SeriesData[Verbatim[z__]]] :> SeriesData[z] /. 
 Rational[a_, b_] :> 
   With[{invf = Reduce`FactorialInverse[b][[1]]}, 
    a/HoldForm[invf!]] & ; 

Then

Series[Sin[Pi*x],{x,0,10}]

displays as desired.

Answered by Rolf Mertig on July 22, 2021

Here is a function you can use to replace Series[]:

inactiveSeries[f_, {x_, x0_, n_}] := Module[{kk, tc},
        tc[kk_] = Inactivate[Evaluate[SeriesCoefficient[f, {x, x0, kk}]], 
                             Factorial | Gamma | Pochhammer];
        Sum[tc[kk] (x - x0)^kk, {kk, 0, n}] + O[x, x0]^(n + 1)]

For example,

inactiveSeries[Sin[π x], {x, 0, 10}]

output 1

A more complicated example:

inactiveSeries[Hypergeometric1F1Regularized[-1/3, 1/5, x], {x, 0, 3}]

output 2

Answered by J. M.'s torpor on July 22, 2021

Add your own answers!

Ask a Question

Get help from others!

© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP