I need to use Compile[] for a very large expression to be integrated. But for Compile[] the expression has to be evaluated, and this takes endless time.
The expression is composed of several functions having lists/tensors as arguments and return types. Something like this:
aFun[..., bFun[..., cFun[...], ...], ...]
Of course, that gets very unhandy quickly.
In a usual programming language I would write:
cTensor=cFun[...];
bTensor=bFun[..., cTensor, ...];
aTensor=aFun[..., bTensor, ...];
If I could do that in Mathematica that would avoid replacing all the occurrences of the arguments in the functions and that actually should work since its going to be compiled. Unfortunately everything I tried doesn't work, like using a variable like above, using assignments like {{cT11,cT12,...},{cT21,...}}=cFun[...], also compiling the functions cFun[] etc..
How can I achieve this in Mathematica? Thank you very much in advance
Regards
edit: A very simplified example would be as follows, but the operations are much more complicated in my calculation, many parameters are filled in and there are more sums.
(f, F and g are vectors with three components)
f:=EulerMatrix[{\[Alpha]2,\[Beta]2,\[Gamma]2}].{0,0,1}Sum[Norm[EulerMatrix[{\[Alpha]2,\[Beta]2,\[Gamma]2}].{b,b,b}-EulerMatrix[{\[Alpha]1,\[Beta]1,\[Gamma]1}].{a,a,a}](EulerMatrix[{\[Alpha]2,\[Beta]2,\[Gamma]2}].{b,b,b}).(EulerMatrix[{\[Alpha]1,\[Beta]1,\[Gamma]1}].{a,a,a}),{a,20},{b,20}]
g[F_]:=EulerMatrix[{\[Alpha]1,\[Beta]1,\[Gamma]1}].{0,0,1}Sum[Norm[F-EulerMatrix[{\[Alpha]2,\[Beta]2,\[Gamma]2}].{c,c,c}]F.EulerMatrix[{\[Alpha]1,\[Beta]1,\[Gamma]1}].{c,c,c},{c,20},{d,20}]
fun=Compile[{\[Alpha]1,\[Beta]1,\[Gamma]1,\[Alpha]2,\[Beta]2,\[Gamma]2},Evaluate[g[f]]]
Unfortunately in Compile[] I have to evaluate g[f]. If I do this on my computer like this it takes about 42 seconds:
Timing[g[f];]
{41.875, Null}
When increasing the sums from 20 terms to something higher time consumption grows extremely, since f is used in g. For f and g[F] alone that's much faster:
Timing[f;]
{2.64063, Null}
Timing[g[{x, y, z}];]
{1.35938, Null}
The kernel of my problem should be that if Compile[] would first calculate f like {x,y,z}=f so that x, y and z are real values and then use these real values as parameters for g like g[{x,y,z}] it should be much faster. Of course, there would be no symbolic simplification be done what Evaluate[g[f]] would do, but that would be acceptable. I would like to write
fun=Compile[{...},
{x,y,z}=f;
g[{x,y,z}]
]
With x, y and z are always calculated as numeric values. But Evaluate[] has to be used in Compile[] and that leads in my tries always to evaluation of g[f].
CompilationOptions -> {"ExpressionOptimization" -> False}
orCompilationOptions -> {"InlineCompiledFunctions" -> False}
? $\endgroup$