Skip to content
Prev 178085 / 398502 Next

large factorials

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) Sym("factorial(", n, ")")

sum1 <- function(l,u,t,i,n,w) {
 v <- 0
 for (m in 0 :w) {
	 v1 <- ((u^(1/2))*(l^(1/2))*t)^(i-n+2*m)
	 v2 <- (factorial.Sym(i-n+m))*(factorial.Sym(m))
	 v3 <- v1/v2
	 v <- v+v3
 }
 Sym(sympy(v)) # send it to SymPy, make result a Sym obj
}

s <- sum1(1,2,10,80,3,80)
s # Sym
as.numeric(s) # numeric


On Thu, Apr 23, 2009 at 10:37 AM, Gabor Grothendieck
<ggrothendieck at gmail.com> wrote: