Where are the math functions?

William Park parkw at better.net
Thu Jun 15 13:43:57 EDT 2000


On Wed, Jun 14, 2000 at 10:32:00PM +0100, Tim Rowe wrote:
> In article <owen-97F32C.10015712062000 at news.u.washington.edu>, 
> owen at astro.washington.edu (Russell E. Owen) wrote:
> 
> > In article <slrn8k8dfv.tu.hzhu at mars.localdomain>, 
> > hzhu at users.sourceforge.net wrote:
> > 
> > >I'm quite puzzled by not being able to find most of the common special
> > >functions, such as (incomplete) gamma, beta and bessel and erf.
> > >
> > >This arrises from effort to provide statistical functions for the MatPy
> > >package.  Many stat functions require incomplete gamma/beta and some
> > >variants.
> > >...
> > 
> > The random module (which is available on all platforms) offers beta and 
> > gamma functions. I can't comment on incomplete gamma, bessel and erf. I 
> > found the information about the random module in "Python Essential 
> > Reference" by David Beazley; the index lists beta and gamma, but not 
> > the others.
> 
> No it doesn't. It includes the beta and gamma /distributions/. These are 
> related to, but not the same as, the beta and gamma /functions/.
> 
> When I wanted the gamma function I just ported code from Numerical Recipes 
> in C, which only took a couple of minutes (longer to test, but I'd have 
> spent that time if I'd just typed in the C). Probably still be a copyright 
> violation to post it, though :-(

In fact, GNU math.h includes many higher functions like
    j0, j1, j2, y0, y1, y2
    lngamma, gamma, ...
    erfc, erf, ...
    cbrt,
but Python 'math' module doesn't include them.  So, you have to create a
new module of your own.  

If you need even more higher functions, there are Cephes and other
libraries around.  Try searching <freshmeat.net>.  Or, port the relevant
routine from "Numerical Recipes in C".

--William




More information about the Python-list mailing list