ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Thu, 17 Aug 2017 04:34:18 +0200How to calculate the double factorial in SageMath?https://ask.sagemath.org/question/38527/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](http://mathworld.wolfram.com/DoubleFactorial.html):
$\Gamma(n+\frac{1}{2}) = \frac{(2n-1)!!}{2^n}\sqrt{\pi}$Tue, 15 Aug 2017 06:03:49 +0200https://ask.sagemath.org/question/38527/how-to-calculate-the-double-factorial-in-sagemath/Comment by dan_fulea for <p>I would like to implement the square root of 2 power series:</p>
<p>$ \sqrt{2} = -\sum \limits_{n=0}^{\infty}{\frac{(-1)^n (2n-3)!!}{2^n \times n!}} $ </p>
<p>(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 <a href="http://mathworld.wolfram.com/DoubleFactorial.html">Wolfram MathWorld</a>:</p>
<p>$\Gamma(n+\frac{1}{2}) = \frac{(2n-1)!!}{2^n}\sqrt{\pi}$</p>
https://ask.sagemath.org/question/38527/how-to-calculate-the-double-factorial-in-sagemath/?comment=38551#post-id-38551In 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...Thu, 17 Aug 2017 04:25:48 +0200https://ask.sagemath.org/question/38527/how-to-calculate-the-double-factorial-in-sagemath/?comment=38551#post-id-38551Comment by Fusion809 for <p>I would like to implement the square root of 2 power series:</p>
<p>$ \sqrt{2} = -\sum \limits_{n=0}^{\infty}{\frac{(-1)^n (2n-3)!!}{2^n \times n!}} $ </p>
<p>(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 <a href="http://mathworld.wolfram.com/DoubleFactorial.html">Wolfram MathWorld</a>:</p>
<p>$\Gamma(n+\frac{1}{2}) = \frac{(2n-1)!!}{2^n}\sqrt{\pi}$</p>
https://ask.sagemath.org/question/38527/how-to-calculate-the-double-factorial-in-sagemath/?comment=38552#post-id-38552Ya 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.Thu, 17 Aug 2017 04:34:18 +0200https://ask.sagemath.org/question/38527/how-to-calculate-the-double-factorial-in-sagemath/?comment=38552#post-id-38552Answer by nbruin for <p>I would like to implement the square root of 2 power series:</p>
<p>$ \sqrt{2} = -\sum \limits_{n=0}^{\infty}{\frac{(-1)^n (2n-3)!!}{2^n \times n!}} $ </p>
<p>(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 <a href="http://mathworld.wolfram.com/DoubleFactorial.html">Wolfram MathWorld</a>:</p>
<p>$\Gamma(n+\frac{1}{2}) = \frac{(2n-1)!!}{2^n}\sqrt{\pi}$</p>
https://ask.sagemath.org/question/38527/how-to-calculate-the-double-factorial-in-sagemath/?answer=38544#post-id-38544There'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.
Wed, 16 Aug 2017 01:17:21 +0200https://ask.sagemath.org/question/38527/how-to-calculate-the-double-factorial-in-sagemath/?answer=38544#post-id-38544Answer by dan_fulea for <p>I would like to implement the square root of 2 power series:</p>
<p>$ \sqrt{2} = -\sum \limits_{n=0}^{\infty}{\frac{(-1)^n (2n-3)!!}{2^n \times n!}} $ </p>
<p>(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 <a href="http://mathworld.wolfram.com/DoubleFactorial.html">Wolfram MathWorld</a>:</p>
<p>$\Gamma(n+\frac{1}{2}) = \frac{(2n-1)!!}{2^n}\sqrt{\pi}$</p>
https://ask.sagemath.org/question/38527/how-to-calculate-the-double-factorial-in-sagemath/?answer=38533#post-id-38533One 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.)Tue, 15 Aug 2017 12:57:01 +0200https://ask.sagemath.org/question/38527/how-to-calculate-the-double-factorial-in-sagemath/?answer=38533#post-id-38533