Thank you for all the replies and suggestions. I guess I have to be
necessarily vague, since I haven't really done anything on this front yet.
I intend to have the callback function for ODEPACK - for the vector
field - residing in lisp. Using CFFI to do this seemed to work well. I
wouldn't want to have code in C/Fortran if I can help it.
I tried using tranlate_file to convert something like this:
--
L(t, q, q1) := block([theta_1, theta_2, thetadot_1, thetadot_2, L],
theta_1: q[1][1],
theta_2: q[2][1],
thetadot_1: q1[1][1],
thetadot_2: q1[2][1],
L: thetadot_2^2/2. + thetadot_1^2 + thetadot_1 * thetadot_2 *
cos(theta_1 - t\
heta_2) - 2 * sin(theta_1) -sin(theta_2),
return(L))$
--
The translated code seems to have a lot of fluff; not something I'd use
for numerical stuff - I could of course be doing it wrong. I didn't of
course, use mode_declare while doing this. I'd be very skittish when
passing something like this through - unedited- to any numerical code,
especially so because the ODEs I need to solve are inturn passed on to
an optimisation routine; so efficient numerics is something that is very
much desired.
Let me be more precise about what I basically want to be able to do.
--
(defun f (x) (sin x))
(diff f 'x) ;; should give me (lambda (x) (cos x))
--
In some sense I don't want to have a distinction between numerical and
symbolic functions. Scmutils allows me to do this, but, maxima is much
more powerful for what I do - and much faster too!
I guess I can sort of do this in maxima using tocl, by doing something like:
--
(defun f (x) `((%sin simp) ,x))
(defmacro symbolic->lisp (f)
(let* ((x (gensym)))
(expr (funcall f x)))
`(lambda (,x) ,($to_cl expr))))
(defmacro make-diff-func (f)
(let* ((x (gensym))
(expr (funcall f x)))
`(lambda (,x) ,($to_cl ($diff expr x))))))
--
Of course this is all hunky dory for R^1->R^1; what I actually want is
something from R^m->R^n. Ideally the data structures here would be a
simple vector used in some nice way - ala MATLISP (?).
What I now do, is actually save the expressions one by one in a file,
and substitute them in appropriate places in the C code; something I
find to be very ugly.
I can't think of a better way to this - mostly because I follow a
similar workflow for generating the C code from the symbolic expressions
generate by maxima.
Cheers,
Akshay
On 10/12/2011 05:24 AM, Barton Willis wrote:
> -----maxima-bounces at math.utexas.edu wrote: -----
>> If I understand correctly, by "replace function tags" you mean to
>> transform stuff like ((MPLUS) 1 2 3) to (+ 1 2 3). Right?
>
> Although mostly a toy, to_cl is a tiny easy to modify Maxima to CL translator.
> Every once in awhile, I find some useful way to modify it. As Robert and others
> suggested, you should try using the Maxima translator--nevertheless:
>
> (%i10) load(tocl)$
>
> (%i13) to_cl(u + n / k)$
> (+ U (/ N K))
>
> (%i14) to_cl('(x : x + 1, x * x))$
> (PROGN (SETQ X (+ 1 X)) (EXPT X 2))
>
> (%i16) to_cl('(f(a,b,c) := (a : a +1, a + b*c)))$
> (DEFUN $F (A B C) (PROGN (SETQ A (+ A 1)) (+ A (* B C))))
>
> (%i17) to_cl('block([acc : 0], for k : 1 thru 100 do acc : acc + 1.0/k, acc))$
> (LET ((ACC 0))
> (DO ((K 1 (INCF K 1))) ((> K 100) '$DONE)
> (SETQ ACC (+ ACC (* 1.0 (EXPT K -1)))))
> ACC)
>
> --bw