# Make function with variable arguments from output of symbolic manipulations

I have a fairly intricate symbolic calculation, which outputs a list of formulae as functions of several variables. The final symbolic formulae are much less complex than the large number of complex intermediate parts from which they are formed (though still quite lengthy). E.g.

RijTh = RatesTh[sample, tagPrs, aa, prodCats, tcSel]
(* {2 Flb^2 + Flc, Fbc + Fcb + Flb, 2 Fbc^4 + Fcb, Eb + Ec + Fcb,
Eb + 2 Flc, Eb + Ec^3 + Fbc, Ec + 2 Fcb, Fbc + 2 Fcb,
Ec + Fcb + Flc^2, Eb + Ec + Flc^2} *)


I then want to use the symbolic formulae, RijTh, in a procedural program where they are passed to the NMinimize function which iterates over them many times, varying the variables on which they depend (Eb, Flc etc.) to find a minimum. With many iterations of this, the formulae will be executed many thousands of times.

Thus, I do not want the symbolic program which finds the formulae to be executed for every call of NMinimize, but just once prior to calling NMinimize, in order to initialize the function at the beginning. And I want to make the result of that initialization (i.e. RijTh) an explicit function of the variables on which it depends, to be passed to and minimized by the NMinimize function.

However, I do want to run both in one "run", since I need the initial symbolic calculation of RijTh to be flexible since it depend on other parameters (the arguments to RatesTh above). I do not want to just run it separately, copy/paste the results into another program/notebook as a function and run with that. I need the symbolic code to pass the formulae into a function with the variables (Eb, Flc etc.) as arguments and then run them iteratively, all in one run. E.g. something like:

fitPrs = {Eb, Ec, Fcb, Fbc, Flc, Flb};
Do[sol = NMinimize[{FitFunc[fitPrs, RijTh[fitPrs]],
fpMin \[VectorLess] fitPrs, fitPrs \[VectorLess] fpMax}, fitPrs,
MaxIterations -> 200];
fitPrs = fitPrs /. sol[[2]];, {i, 1000}];


I can't seem to find a way to make this work, but I am sure I have missed something. Thanks for any help.

Ok, after some googling and some trial and error, I think I have a solution. There's of course a chance this is not the best solution, so please take a look and comment if it can be done better. I modify my first piece of code in my question thus (for purely conventional reasons):

rijTh = RatesTh[sample, tagPrs, aa, prodCats, tcSel]
(* {2 Flb^2 + Flc, Fbc + Fcb + Flb, 2 Fbc^4 + Fcb, Eb + Ec + Fcb,
Eb + 2 Flc, Eb + Ec^3 + Fbc, Ec + 2 Fcb, Fbc + 2 Fcb,
Ec + Fcb + Flc^2, Eb + Ec + Flc^2} *)


Then I create a function using Evaluate as follows:

RijTh[{Eb_, Ec_, Fcb_, Fbc_, Flc_, Flb_}] := Evaluate[rijTh]


And finally, my last block of code in the question works (once the fpMin and fpMax lists of limits have been set).