# Question:Batch function creation

## Question:Batch function creation

Maple
My goal is to obtain a formula F:= x -> fa(x)*c1_1(x)+ fb(x)*c1_2(x)+fc(x)*c2_1(x)+... where every ci_j(x) is a function of x. fa, fb, fc are known functions of x. I do not need to have it printed, I just need it to return a numerical value for every value of x I throw in. I have obtained the solutions of ci_j's in the form Sol[1]:=[c1_1=f11(x), c1_2=f12(x), c1_3=f13(x), ...], N1 terms Sol[2]:=[c2_1=f21(x,c1_j’), c2_2=f22(x,c1_j’), c2_3=f23(x,c1_j’), ...], N2 terms Sol[3]:=[c3_1=f31(x,c1_j’,c2_j’), c3_2=f32(x,c1_j’,c2_j’), c3_3=f33(x,c1_j’,c2_j’), ...], N3 terms Sol[4]:=[c4_1=f41(x,c1_j’,c2_j’,c3_j’), c4_2=f42(x,c1_j’,c2_j’,c3_j’), c4_3=f43(x,c1_j’,c2_j’,c3_j’), ...], N4 terms …. …. (where j’>0, Ni = 3*(i+1)) In short, to calculate any Sol[n] term one must know the solution (as a function only of x) for every Sol[n-j] term, j=1..n-1. Direct substitution (subs(Sol[n-1],Sol[n])) is instantly draining all memory because the ci_j functions are complicated functions of x (sums of fractions of polynomials) and in each higher order term previous order functions appear hundreds or thousands of times. To bypass this I have tried to mass convert the equations inside Sol into functions of x. I have used the following toy model of the problem: > Sol:=[g11=g1+g2+1,g22=g1-g2-1,g12=x+2]; Sol := [g11 = g1 + g2 + 1, g22 = g1 - g2 - 1, g12 = x + 2] > Sols:=subs([g1=g1(x),g2=g2(x)],Sol); Sols := [g11 = g1(x) + g2(x) + 1, g22 = g1(x) - g2(x) - 1, g12 = x + 2] > Sols[2]; g22 = g1(x) - g2(x) - 1 > for i from 1 to nops(Sol) do > cat(lhs(Sols[i])):=X->subs(x=X,rhs(Sols[i])); > end; g11 := X -> subs(x = X, rhs(Sols[i])) g22 := X -> subs(x = X, rhs(Sols[i])) g12 := X -> subs(x = X, rhs(Sols[i])) The obvious problem here is that i is not evaluated in the right side of the assignment and takes whatever value it happens to have during evaluation of the function, eg. calling g12(x) after this loop gives > g12(X); Error, (in g12) invalid subscript selector because i is now 4. Ideally the output would be something like this: g11 := X -> subs(x = X, rhs(Sols[1])) g22 := X -> subs(x = X, rhs(Sols[2])) g12 := X -> subs(x = X, rhs(Sols[3])) Is there a way for such a strategy to work? Could there be any other ways to accomplish my goal? Thanks
﻿