[sage-support] Re: Asymptotics of binomial coefficients
[Poor formatting in the previous post; trying again.] On Dec 29, 12:31 pm, William Stein 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. = 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 sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: Asymptotics of binomial coefficients
On Dec 29, 12:31 pm, William Stein wrote:> On Dec 28, 2011 9:05 PM, "shreevatsa" wrote:> > On Dec 29, 3:29 am, John Cremona wrote:> > > This follows very easily from Stirling's Formula. But I suppose the> > > original question was not so much "what is the answer" as "can I get> > > the answer from system [xyz] without having to think"!> > > Yes!> > > After all, anything Sage can do a human can probably do with enough> > patience and time. The point of the software is to make it easy.> > (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. 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. = 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 sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] Help with plotting from Mathematica using SageTeX
On Mon, Dec 26, 2011 at 11:55 PM, David Kirkby wrote: > On 26 December 2011 19:51, David Kirkby wrote: >> On 26 December 2011 19:28, William Stein wrote: > >>> What problems? Are there any corresponding open trac tickets or bug >>> reports about your problems? >> >> http://trac.sagemath.org/sage_trac/ticket/10968 >> >> Note that another ticket >> >> http://trac.sagemath.org/sage_trac/ticket/9032 >> >> which was closed (I gave it positive review), was not a complete cure, >> but the patch reduced the number of failures from 12 to 2. > > Correction, > http://trac.sagemath.org/sage_trac/ticket/8495 > fixes some MMA issues, but others remain, and are in #10968. Thanks for reporting all of this and collating and explaining the bugs. I've looked at some, and think I could fix some of them pretty easily.I can't right now, because I'm more busy with other things, and my laptop Mathematica license expired.But once I sort that out, I'll look at these. William > > Note, I found the bug I reported in #8495, which was later opened as > #10968, within 1-2 minutes of testing with the most basic of examples > of Mathematica usage. You can't get much simpler than finding a > numerical approximation of Pi. > > If I understand it correclty, the test failures noted on #8495, which > took 13 months to fix, were introduced much earlier in #3587, but > nobody had noticed. > > I know pexpect has been the source of numerous issues in Sage, so I'm > not about to rely on pexpect when I can use an interface developed for > Mathematica by Wolfram Research, which would undergo far more testing > than the Mathematica inferface we have in Sage, which is an optional > package underging very limited testing. > > > > Dave > > -- > To post to this group, send email to sage-support@googlegroups.com > To unsubscribe from this group, send email to > sage-support+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/sage-support > URL: http://www.sagemath.org -- William Stein Professor of Mathematics University of Washington http://wstein.org -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
Re: [sage-support] Problem with sage binary for rhel
On Thu, Dec 29, 2011 at 11:27 AM, Shaun Ault wrote: > > Dear Sage Support, > > I've downloaded the 64-bit binary, > > sage-4.7.2-linux-64bit-red_hat_enterprise_linux_server_release_5.6_tikanga-x86_64-Linux.tar.gz > > onto a server that is running rhel 5.5 tikanga. You can either try building all of Sage from source or rebuilding just the numpy package. I would try first just rebuilding numpy from source, by typing ./sage -f numpy -- William > > [sageadm@acad-math01 ~]$ uname -a > Linux acad-math01 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 > x86_64 x86_64 x86_64 GNU/Linux > [sageadm@acad-math01 ~]$ tail /etc/redhat-release > Red Hat Enterprise Linux Server release 5.5 (Tikanga) > [sageadm@acad-math01 ~]$ > > > The most basic functions of sage work fine, however I get errors when > running certain commands. For example, when trying to create a matrix, > there is a huge traceback. The last line seems to indicate a 32-bit > version of libgfortran.so, rather than the expected 64-bit version. > > sage: matrix([[1,2],[3,4]]) > --- > ImportError Traceback (most recent call last) > > /app/sage/sage/ in () > > /app/sage/sage/local/lib/python2.6/site-packages/sage/matrix/constructor.pyc > in matrix(*args, **kwds) > 495 # check to see if the number of rows is specified > 496 try: > --> 497 import numpy > 498 if isinstance(args[0], numpy.ndarray): > 499 raise TypeError > > ..lines deleted.. > > /app/sage/sage/local/lib/python2.6/site-packages/numpy/linalg/linalg.py > in () > 21 isfinite, size, finfo, absolute, log, exp > 22 from numpy.lib import triu > ---> 23 from numpy.linalg import lapack_lite > 24 from numpy.matrixlib.defmatrix import matrix_power > 25 from numpy.compat import asbytes > > ImportError: libgfortran.so.1: wrong ELF class: ELFCLASS32 > > > > Please advise!! > > Thanks, > -Shaun Ault > > > > > > > -- > "The doctors treated him, bled him, and made him swallow drugs; nevertheless > he recovered" --Tolstoy, in War and Peace > > "It should be presupposed that every good Christian ought to be more eager > to put a good interpretation on a neighbor's statement than to condemn it." > --St. Ignatius > > > > -- > To post to this group, send email to sage-support@googlegroups.com > To unsubscribe from this group, send email to > sage-support+unsubscr...@googlegroups.com > For more options, visit this group at > http://groups.google.com/group/sage-support > URL: http://www.sagemath.org -- William Stein Professor of Mathematics University of Washington http://wstein.org -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Problem with sage binary for rhel
Dear Sage Support, I've downloaded the 64-bit binary, sage-4.7.2-linux-64bit-red_hat_enterprise_linux_server_release_5.6_tikanga-x86_64-Linux.tar.gz onto a server that is running rhel 5.5 tikanga. [sageadm@acad-math01 ~]$ uname -a Linux acad-math01 2.6.18-194.el5 #1 SMP Tue Mar 16 21:52:39 EDT 2010 x86_64 x86_64 x86_64 GNU/Linux [sageadm@acad-math01 ~]$ tail /etc/redhat-release Red Hat Enterprise Linux Server release 5.5 (Tikanga) [sageadm@acad-math01 ~]$ The most basic functions of sage work fine, however I get errors when running certain commands. For example, when trying to create a matrix, there is a huge traceback. The last line seems to indicate a 32-bit version of libgfortran.so, rather than the expected 64-bit version. sage: matrix([[1,2],[3,4]]) --- ImportError Traceback (most recent call last) */app/sage/sage/* in () /app/sage/sage/local/lib/python2.6/site-packages/sage/matrix/constructor.pyc in matrix(*args, **kwds) 495 # check to see if the number of rows is specified 496 try: --> 497 import numpy 498 if isinstance(args[0], numpy.ndarray): 499 raise TypeError ..lines deleted.. /app/sage/sage/local/lib/python2.6/site-packages/numpy/linalg/linalg.py in () 21 isfinite, size, finfo, absolute, log, exp 22 from numpy.lib import triu ---> 23 from numpy.linalg import lapack_lite 24 from numpy.matrixlib.defmatrix import matrix_power 25 from numpy.compat import asbytes ImportError: libgfortran.so.1: wrong ELF class: ELFCLASS32 Please advise!! Thanks, -Shaun Ault -- "The doctors treated him, bled him, and made him swallow drugs; nevertheless he recovered" --Tolstoy, in War and Peace "It should be presupposed that every good Christian ought to be more eager to put a good interpretation on a neighbor's statement than to condemn it." --St. Ignatius -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: sage graph -- why is c_graph so slow??
Hell !!! and still much faster than the c_graph implementation. > Well... I spent *quite* some time over this problem, wrote a LOT of code and documentation , to find out later that this could be solved in a *very small* patch. I hope all the work I did could be used later on anyway, but for the moment there should be no further worries about this SCC method. I created a patch for this just there [1], which you will find with some benchmarks. http://trac.sagemath.org/sage_trac/ticket/12235 As a side note, I've also been > testing subgraph functionality. Eg., > self.M.subgraph(self.rand_verts(K)), which maybe has a better > implementation using subgraph_search() ?? > Nonononono ! This subgraph method has nothing to do with subgraph_search ! The subgraph method takes as an argument a set of vertices and returns the graph induced by those vertices. The subgraph_search (and all the subgraph_search_* method) take as an argument *another graph*, and look for copies of this other graph inside of the first one. Which is dead harder :-D > Anyways, I greatly appreciate your help with this. It would be great > to be able to use Sage/Python to run all of our code. > Please complain whenever you have the slightest thought that Sage may not be the best graph library in the world :-p Have fuun ! :-p Nathann -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org
[sage-support] Re: Poisson distribution
On Dec 28, 8:13 pm, akm wrote: > Hi all, can anyone recommend a way of generating random numbers via a > Poisson distribution? > > I'm trying to wrangle scipy.stats.poisson to get something centered at > 10, say, with a nice long tail out to the right, but I can't figure > out how to manipulate the shape of the the distribution. > > Here's the code I'm using: > > from scipy.stats import poisson > moo = 10 > p = poisson(moo) > dist = p.rvs((10,)).tolist() > s=stats.TimeSeries(dist).plot_histogram(bins=172, normalize=False, > color='black') > s.show(xmin=0, xmax=50, aspect_ratio=.001) > > The docs for poisson() suggest I can change loc, scale, size, and > shape, but I can't figure out the syntax. > > If there's a better way I'd love to hear about it also. > > Thanks! > > Best > Andrew sage: from scipy import stats sage: sage: stats.poisson.rvs(10,loc=0.0,scale=1.0,size=100) array([10, 15, 8, 8, 14, 11, 9, 11, 12, 8, 8, 17, 12, 18, 20, 3, 9, 8, 4, 16, 9, 13, 3, 9, 11, 10, 17, 8, 8, 6, 11, 13, 11, 10, 10, 13, 9, 10, 9, 13, 11, 9, 9, 13, 7, 9, 8, 14, 10, 4, 11, 8, 11, 5, 8, 8, 14, 6, 14, 6, 11, 9, 10, 8, 6, 4, 10, 18, 12, 10, 17, 6, 10, 9, 9, 15, 17, 7, 10, 5, 9, 12, 6, 9, 3, 3, 11, 12, 13, 10, 4, 12, 12, 13, 13, 14, 14, 10, 12, 15]) http://oneau.wordpress.com/2011/02/28/simple-statistics-with-scipy/ http://docs.scipy.org/doc/scipy/reference/tutorial/stats.html sage: maxima('load(distrib)') sage: maxima('random_poisson(1,10)') [0,1,0,0,0,2,0,0,0,1] sage: maxima('random_poisson(10,10)') [16,15,9,14,8,7,12,8,10,6] -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org