Skip to content
Prev 178074 / 398502 Next

large factorials

Here is what I did:
library(rSymPy)
factorial.sympy <- function(n) sympy(paste("factorial(", n, ")"))
factorial.sympy(171) 
[1]
"1241018070217667823424840524103103992616605577501693185388951803611996075221691752992751978120487585576464959501670387052809889858690710767331242032218484364310473577889968548278290754541561964852153468318044293239598173696899657235903947616152278558180061176365108428800000000000000000000000000000000000000000"
Which work perfectly. 

Here is one of my summation functions:

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.sympy(i-n+m))*(factorial.sympy(m))
+ v3 <- v1/v2
+ v <- v+v3
+ }
+ return(v)
+ }

sum1(1,2,10,80,3,80)
Error in (factorial.sympy(i - n + m)) * (factorial.sympy(m)) : 
  non-numeric argument to binary operator

I'm not sure why it works when I do the factorial normally but when I call
my function it doesn't work?
molinar wrote: