Ask Your Question

# How to calculate the double factorial in SageMath?

I would like to implement the square root of 2 power series:

$\sqrt{2} = -\sum \limits_{n=0}^{\infty}{\frac{(-1)^n (2n-3)!!}{2^n \times n!}}$

(which I obtained from the Maclaurin series of $\sqrt{1+x}$ with $x=1$) in SageMath but I cannot seem to find the double factorial function in the SageMath docs. Is there one? I suppose if a double factorial function is not available I could use this method of finding the double factorial that I found on Wolfram MathWorld:

$\Gamma(n+\frac{1}{2}) = \frac{(2n-1)!!}{2^n}\sqrt{\pi}$

edit retag close merge delete

## Comments

In my opinion the series is slowly converging to the limit, for instance:

sage: R = RealField(250)
sage: R(sqrt(2))
1.4142135623730950488016887242096980785696718753769480731766797379907324785
sage: taylor( sqrt(1+x), x, 0, 400 ).subs( x=R(1) )
1.4141959480076468196466613334228682157568201802442506375036957035341180687
sage: coeffs = taylor( sqrt(1+x), x, 0, 400 ).coefficients()
sage: R( coeffs[399][0] )
0.000035427804322168530222584374638737128507887491588605918103950050962686626779
sage: R( coeffs[400][0] )
-0.000035294950055960398234249683233841864275982913495148645911060238271576551929


The Taylor polynomial contains the needed coefficients. However even after $400$ terms we get relatively big numbers to add, subtract, add...

( 2017-08-17 04:25:48 +0200 )edit

Ya I'm well aware convergence is an issue. This method with N (number of terms) = 10,000 is only accurate to 6 decimal places. I know a far more convergent method of estimating $\sqrt{2}$ is Newton's method. Just wanted to give this a try.

( 2017-08-17 04:34:18 +0200 )edit

## 2 Answers

Sort by ยป oldest newest most voted

There's the method multifactorial(2) on integers:

sage: 6.multifactorial(2)
48
sage: 7.multifactorial(2)
105


You might want to check the definition used there fits your needs.

more

One quick(ly found) possibility would be to import factorial2 from sympy, sample code:

sage: from sympy import factorial2
sage: factorial2(99)
2725392139750729502980713245400918633290796330545803413734328823443106201171875
sage: factorial(100) / factorial(50) / 2^50
2725392139750729502980713245400918633290796330545803413734328823443106201171875
sage: ?factorial2


Note that factorial2 is defined for both odd and even natural numbers. (Also for negative odd ones.)

more

## Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

## Stats

Asked: 2017-08-15 06:03:49 +0200

Seen: 1,338 times

Last updated: Aug 17 '17