Best way to use a compiled function in findroot



 On 8/31/10 12:07 PM, Sergio Callegari wrote:
>
> I agree I can save myself headaches by not compiling the function...
> however...
>
> - It is nice first to try things uncompiled and then to make them fast.
> If I could make things fast in maxima without having to recode them in
> C with the gsl that would be great!
Compiling does not necessarily make things faster, especially if there's
a lot symbolic manipulation going on.  However, functions that are
primarily meant to compute floating-point results can see some
significant improvements.   If you really want to make them fast, you
can write your function in Lisp.   Finally, you can also use Lisp's FFI
(foreign function interface) to call out to some C library to compute
the results.  Maxima doesn't support FFI currently, but whatever Lisp
you're using probably has some kind of FFI.
>
> - In the specific case, the function I am trying to invert is
> recomputed many many times by find_root, so I guess that compiling it
> could make a difference.
I think you should profile it first.  Does it it 1 sec? 10 sec? A
million sec?   If 10 sec, it may be ok.  If a million, compiling
probably isn't going to make it 10 sec. :-)

Ray