I'm writing a script that requires a variable number of symbolic variables and am struggling to understand how to evaluate the resulting expressions
MWE:
(%i1) foo:makelist(f[i],i,3);
(foo) [f[1],f[2],f[3]]
(%i2) bar:lreduce("*",foo);
(bar) f[1]*f[2]*f[3]
(%i3) vals:[1,2,3];
(vals) [1,2,3]
(%i4)
ev(bar,foo:vals);
(%o4) f[1]*f[2]*f[3]
Here, I wanted to evaluate the product for f[1]:1
, f[2]:2
and f[3]:3
.
The following works:
ev(bar,lambda([L], for i thru length(L) do f[i]:L[i])(vals));
however, I thought there was likely a more direct / practical method; perhaps a different way of declaring symbolic variables, altogether?