[R] large factorials

Ravi Varadhan RVaradhan at jhmi.edu
Thu Apr 23 16:01:58 CEST 2009


Hi Samantha,

It is quite likely that you are not doing something right when you are
explicitly computing large factorials.  There is probably a good asymptotic
approximation that will simplify things for you.  In my experience, there is
seldom a need to explicitly compute factorials of integers.  What is the
real problem that you are trying to solve?

Ravi.


----------------------------------------------------------------------------
-------

Ravi Varadhan, Ph.D.

Assistant Professor, The Center on Aging and Health

Division of Geriatric Medicine and Gerontology 

Johns Hopkins University

Ph: (410) 502-2619

Fax: (410) 614-9625

Email: rvaradhan at jhmi.edu

Webpage:  http://www.jhsph.edu/agingandhealth/People/Faculty/Varadhan.html



----------------------------------------------------------------------------
--------


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
Behalf Of molinar
Sent: Thursday, April 23, 2009 9:42 AM
To: r-help at r-project.org
Subject: Re: [R] large factorials


Thank you everyone all of your posts were very helpful.  I tried each one
and I think I have about 10 new packages installed.  The formula I need to
calculate did not involve any logarithms but infinite summations of
factorials, I'm sorry for not specifying.  I read some things about using
logarithms but I thought in my case I would have to do an e to the log and
by doing that R still gave me the same problems with numbers over 170.  

But I was able to get it to work by using the last post about the rsympy
packages.  

I tried downloading bc but I didn't know how to connect it to R, so R said
"could not find function bc".  

Thanks again for all of your help.
Samantha





Gabor Grothendieck wrote:
> 
> Also the R sympy package can handle this:
> 
>> library(rSymPy)
> Loading required package: rJava
> 
>> factorial.sympy <- function(n) sympy(paste("factorial(", n, ")"))
> 
>> # note that first time sympy is called it loads java, jython and 
>> sympy # but on subsequent calls its faster.  So make a dummy call first.
>> factorial.sympy(10)
> [1] "3628800"
> 
>> # code from earlier post defining factorial.bc to be inserted here
> 
>>    benchmark(replications=10, columns=c('test', 'elapsed'),
> +       bc=factorial.bc(500),
> +       sympy = factorial.sympy(500))
>    test elapsed
> 1    bc    2.17
> 2 sympy    0.09
> 
> See the rSymPy, r-bc and rbenchmark home pages:
> http://rsympy.googlecode.com
> http://r-bc.googlecode.com
> http://rbenchmark.googlecode.com
> 
> On Wed, Apr 22, 2009 at 3:21 PM, molinar <sky2k2 at hotmail.com> wrote:
>>
>> I am working on a project that requires me to do very large factorial 
>> evaluations.  On R the built in factorial function and the one I 
>> created both are not able to do factorials over 170.  The first gives 
>> an error and mine return Inf.
>>
>> Is there a way to have R do these larger calculations (the calculator 
>> in accessories can do 10000 factorial and Maple can do even larger)
>> --
>> View this message in context:
>> http://www.nabble.com/large-factorials-tp23175816p23175816.html
>> Sent from the R help mailing list archive at Nabble.com.
>>
>> ______________________________________________
>> R-help at r-project.org mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide
>> http://www.R-project.org/posting-guide.html
>> and provide commented, minimal, self-contained, reproducible code.
>>
> 
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
> 
> 

--
View this message in context:
http://www.nabble.com/large-factorials-tp23175816p23197201.html
Sent from the R help mailing list archive at Nabble.com.

______________________________________________
R-help at r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.




More information about the R-help mailing list