probability distribution function in python
Alex Martelli
aleaxit at yahoo.com
Tue Apr 10 07:12:49 EDT 2001
"Tawee Laoitichote" <astpspd at pea.or.th> wrote in message
news:mailman.986885471.6070.python-list at python.org...
"""
I'm doing something concerning probability distribution function. Does
anyone can resolve the factorial function ==> n! (the denominator of
Poisson DF)since it will overflow the integer limit.
"""
You can just use Python 'longs' (unlimited-length integers). Try:
D:\ian>python
Python 2.0 (#8, Oct 16 2000, 17:27:58) [MSC 32 bit (Intel)] on win32
Type "copyright", "credits" or "license" for more information.
>>> def fac(n):
... if n<=0: return 1L
... return n*fac(n-1)
...
>>> fac(100)
9332621544394415268169923885626670049071596826438162146859296389521759999322
9915
6089414639761565182862536979208272237582511852109168640000000000000000000000
00L
>>>
The 'L' at the end of the first line of fac() is crucial -- it
ensures all results will be long (unlimited-precision) ints.
"""
Or, where can I find it in any python modules or library? Thanks.
"""
http://gmpy.sourceforge.net (currently stalled, but I'll get
back to polishing it up for release eventually -- it does appear
to be very solid) wraps the GMP library, which includes a very
speedy implementation of factorials (and quite a few other
number-theoretical functions).
Alex
More information about the Python-list
mailing list