Skip to content
Prev 178091 / 398503 Next

large factorials

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 <- ((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
 }

 as.numeric(sympy(v)) # send it to SymPy, make result a Sym obj

}

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


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