Ask Your Question
1

How to calculate the double factorial in SageMath?

asked 2017-08-15 06:03:49 +0100

Fusion809 gravatar image

updated 2017-08-17 03:55:48 +0100

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 flag offensive 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...

dan_fulea gravatar imagedan_fulea ( 2017-08-17 04:25:48 +0100 )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.

Fusion809 gravatar imageFusion809 ( 2017-08-17 04:34:18 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
4

answered 2017-08-16 01:17:21 +0100

nbruin gravatar image

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.

edit flag offensive delete link more
2

answered 2017-08-15 12:57:01 +0100

dan_fulea gravatar image

updated 2017-08-15 12:58:09 +0100

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.)

edit flag offensive delete link more

Your Answer

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

Add Answer

Question Tools

1 follower

Stats

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

Seen: 1,492 times

Last updated: Aug 17 '17