Re: [R] large factorials

2009-04-27 Thread JLucke
The modified function I presented contains a stupid error, which is corrected below. sum1 <- function(l,u,t,i,n,w,tol=.Machine$double.xmin) { v <- 0 v2 <- 1 for (m in 0 :w & v2 > tol) { v1 <- ((u^(1/2))*(l^(1/2))*t)^(i-n+2*m) v2 <- exp(-lgamma(i-n+m+1)-lgamma(m+1)) v3 <- v1*v2 v <- v+v3 } re

Re: [R] large factorials

2009-04-27 Thread JLucke
ate University of New York 1021 Main Street Buffalo, NY 14203-1016 Office: 716-887-6807 Fax: 716-887-2510 http://www.ria.buffalo.edu/profiles/lucke.html molinar Sent by: r-help-boun...@r-project.org 04/23/2009 10:00 AM To r-help@r-project.org cc Subject Re: [R] large factorial

Re: [R] large factorials

2009-04-23 Thread Gabor Grothendieck
One more improvement. Perhaps it would be best just to return a numeric so sum1 inputs and outputs numerics: library(rSymPy) # define factorial to return a Sym object factorial.Sym <- function(n) Sym("factorial(", n, ")") sum1 <- function(l,u,t,i,n,w) { v <- 0 for (m in 0 :w) { v1 <-

Re: [R] large factorials

2009-04-23 Thread Gabor Grothendieck
The code in my prior post works (except one comment was wrong) but try this instead. The only change is the last line of the sum1 function. This way it produces a Sym object rather than a character string. library(rSymPy) # define factorial to return a Sym object factorial.Sym <- function(n) S

Re: [R] large factorials

2009-04-23 Thread Gabor Grothendieck
sympy() returns a character string, not an R numeric -- it shouldn't automatically return an R numeric since R can't represent all the numbers that sympy can. The development version of rSymPy has a second class which produces objects of class c("Sym", "character") and those can be manipulated wit

Re: [R] large factorials

2009-04-23 Thread Ravi Varadhan
[mailto:r-help-boun...@r-project.org] On Behalf Of molinar Sent: Thursday, April 23, 2009 9:42 AM To: r-help@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

Re: [R] large factorials

2009-04-23 Thread molinar
Here is what I did: library(rSymPy) factorial.sympy <- function(n) sympy(paste("factorial(", n, ")")) factorial.sympy(171) [1] "1241018070217667823424840524103103992616605577501693185388951803611996075221691752992751978120487585576464959501670387052809889858690710767331242032218484364310473577889

Re: [R] large factorials

2009-04-23 Thread molinar
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 logarit

Re: [R] large factorials

2009-04-23 Thread Gabor Grothendieck
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 f

Re: [R] large factorials

2009-04-23 Thread Martin Maechler
a clear >> description of what you're trying to do and someone may be able >> to help. >> >> Murray M Cooper, Ph.D. >> Richland Statistics >> 9800 N 24th St >> Richland, MI, USA 49083 >> Mail: richs...@earth

Re: [R] large factorials

2009-04-23 Thread Wacek Kusnierczyk
J Dougherty wrote: > On Wednesday 22 April 2009 12:21:41 pm molinar 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 er

Re: [R] large factorials

2009-04-22 Thread Ben Bolker
J Dougherty wrote: > > If you need an open source arbitrary precision calculator, you might want > to > look at Octave which is OS and works similarly to Mathematica - up to a > point > books for Mathematica will be a significant help with Octave. > > JDougherty > > ??? octave is a Ma

Re: [R] large factorials

2009-04-22 Thread J Dougherty
On Wednesday 22 April 2009 12:21:41 pm molinar 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. >

Re: [R] large factorials

2009-04-22 Thread Wacek Kusnierczyk
. > > Murray M Cooper, Ph.D. > Richland Statistics > 9800 N 24th St > Richland, MI, USA 49083 > Mail: richs...@earthlink.net > > - Original Message - From: "molinar" > To: > Sent: Wednesday, April 22, 2009 3:21 PM > Subject: [R] large factorials

Re: [R] large factorials

2009-04-22 Thread Murray Cooper
t - Original Message - From: "molinar" To: Sent: Wednesday, April 22, 2009 3:21 PM Subject: [R] large factorials 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 a

[R] large factorials

2009-04-22 Thread molinar
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 c