[R] large factorials

Gabor Grothendieck ggrothendieck at gmail.com
Thu Apr 23 13:00:39 CEST 2009


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.
>




More information about the R-help mailing list