Loading [MathJax]/jax/output/HTML-CSS/jax.js

First time here? Check out the FAQ!

Ask Your Question
1

How to calculate the double factorial in SageMath?

asked 7 years ago

Fusion809 gravatar image

updated 7 years ago

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

2=n=0(1)n(2n3)!!2n×n!

(which I obtained from the Maclaurin series of 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:

Γ(n+12)=(2n1)!!2nπ

Preview: (hide)

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 ( 7 years ago )

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 2 is Newton's method. Just wanted to give this a try.

Fusion809 gravatar imageFusion809 ( 7 years ago )

2 Answers

Sort by » oldest newest most voted
4

answered 7 years ago

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.

Preview: (hide)
link
2

answered 7 years ago

dan_fulea gravatar image

updated 7 years ago

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

Preview: (hide)
link

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: 7 years ago

Seen: 1,563 times

Last updated: Aug 17 '17