sum2sum {lazy.symbolic} | R Documentation |
Convert s(exp,scope) to sum of exps
Description
This function converts the summation to sum and evaluates it.
s(exp[i],{i,1,3}) -> exp[1]+exp[2]+exp[3]
Usage
sum2sum(sexp, values = NULL, eval = 1, debug = 0)
Arguments
sexp |
An expression containing summation: s( body, sub,from,to ) |
values |
numeric replacement pattern for the scope of subscripts |
eval |
= 0 to see how to convert summation to Sum |
debug |
= 1 to print the intermediate result |
Details
For each summation found, replace it by its expansion as Sum. The replacement proceeds from the bottom to top levels.
Examples
sum2sum( "s(s(a[i,j],{i,1,ni}),{j,1,nj})", values="ni=2; nj=3")
sum2sum( "s(s(a[i,j],{i,from,to}),{j,1,nj})"
, values="from=2; to=4; nj=3")
# unevaluated form
sexp <- "s( a[i], {i,1,2} )"
sum2sum( sexp, eval=1 )
ss <- sum2sum( sexp, eval=0 ) |> printm()
eval(parse(text=ss)[[1]])
# unevaluated form (Cannot be evaluated if the summations are nested.)
sexp <- "s( a[i]*s(b[i,j], {j,1,2}), {i,1,2} )"
sum2sum( sexp, eval=1 )
ss <- sum2sum( sexp, eval=0 ) |> printm()
# eval(parse(text=ss)[[1]])
[Package lazy.symbolic version 1.0.0.20250803 ]