[Poor formatting in the previous post; trying again.]
On Dec 29, 12:31 pm, William Stein <[email protected]> wrote:
> (Not meant as flaimbait) I can think of a lot of counterexamples to this,> at
> least in the context of number theory problems that involve counting,
> which would be impossible to do in a lifetime because humans are just way
> too slow...
Yes, I agree. I thought of this actually... so I waffled a bit with
"enough patience and time", despite realizing the time required can be
more than a lifetime. :-) My fault.
Either way, I think my point stands that even if we can do something
by hand, it would still be useful for Sage to have the ability to do
it.
What needs to be done here for this particular case, does anyone know?
To answer my original question (I just thought of this), this is how I
think one can get the answer in Sage with minimum human effort. (Sage
is awesome.)
1. Look up Stirling's series to as many terms as desired. E.g.
n! = √(2πn) (n/e)^n (1 + 1/(12n) + 1/(288n^2) - 139/(51840n^3) - 571/
(2488320n^4) + O(1/n^5))
So this is √(2πn) (n/e)^n multiplied by a power series in 1/n. And
Sage can handle power series.
2. In Sage:
sage: var('n')
n
sage: f = sqrt(2*pi*n) * (n/e)^n
sage: R.<x> = PowerSeriesRing(QQ)
sage: g = 1 + 1/12 * x + 1/288 * x^2 - 139/51840 * x^3 -
571/2488320 * x^4 + O(x^5)
We've written the power series separately, so that factorial(n) = f(n)
* g(1/n). To check:
sage: (f(1000)*g(1/1000)).n()
4.02387260077094e2567
sage: factorial(1000).n()
4.02387260077094e2567
Cool. Now, binomial(n, n/2) = factorial(n) / factorial(n/2)^2 = f(n)/
f(n/2)^2 * g(1/n)/g(2/n)^2. So to get a series expansion for
binomial(n, n/2)/2^n:
sage: simplify(f(n)/f(n/2)^2/2^n)
sqrt(2)/(sqrt(pi)*sqrt(n))
and
sage: g(x)/g(2*x)^2
1 - 1/4*x + 1/32*x^2 + 5/128*x^3 - 21/2048*x^4 + O(x^5)
This shows that binomial(n, n/2)/2^n is
√(2/(πn)) (1 - 1/(4n) + 1/(32n^2) + 5/(128n^3) - 21/(2048n^4) + O(1/
n^5))
which coincides with the answer given by WA. Much more convenient than
multiplying and dividing power series by hand.
If the Stirling series were stored in Sage, it would avoid even the
first step of typing it in.
Thanks again for Sage,
Shreevatsa
--
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sage-support
URL: http://www.sagemath.org