The gentran package is designed to do this.
Dan Stanger
Johannes Hofmann wrote:
>Hello,
>
>I wrote a maxima function expr2c() to generate optimized C-code from maxima
>expressions. One can call it like
>
>expr2c("test", "double x, double y", diff((x^4 + 2 * y) * (x ^ 2 + y) * x, x));
>
>I'm new to maxima, so the code is pretty crude:
>
>printdecl(vars) := (
> sprint("double", first(vars)),
> for v in rest(vars) do sprint(",", v),
> sprint(";"))$
>
>printdef(expr) := sprint(first(expr), "=", second(expr), ";")$
>
>block2c(expr) :=
> if ?equal(op(expr), block) then (
> printdecl(first(expr)),
> for d in reverse(rest(reverse(rest(expr)))) do printdef(d),
> sprint("return", string(last(expr)), ";"))
> else
> sprint("return", string(expr), ";")$
>
>expr2c(funcname, argstr, expr) := (
> sprint("double", funcname, "(", argstr, ") {"),
> block2c(subst(pow, "^", optimize(expr))),
> sprint("}", "
>"))$
>
>
>Unfortunately, C does not allow to use e.g. %5 as a variable name,
>so currently I need to run the result through "sed s/%/_/g".
>Any ideas how to replace the % characters in maxima?
>
>regards,
> Johannes
>
>BTW: Thanks a lot for your work on this great open source project!
>_______________________________________________
>Maxima mailing list
>Maxima at math.utexas.edu
>http://www.math.utexas.edu/mailman/listinfo/maxima
>
>
>
>