On Mon, 26 Nov 2012 at 10:10AM -0800, ijt wrote:
> I was wondering if there is any way to make sage produce an output
> that I can directly use in java code? I am using sage to compute
> gradients and hessians of multidim. functions which become quite large
> and replacing everything by hand is quite annoying.
>
> For example, sage returns something like:
>
> exp(x^2*log(z)-sqrt(y^5))
>
> which in java code would look like
>
> Math.exp(Math.pow(x,2)*Math.log(z)-Math.sqrt(Math.pow(y,5)))
I don't have a good answer for this (other than string manipulation and
regex matching -- if you want to be a little fancier, try the pyparsing
module), but there's a more general question here: how to rewrite Sage
expressions into other forms?
In some sense, we already do this in many places (the pty interfaces,
the LaTeX output), but I wonder if there's a nice way to overload some
of that stuff and define your own outputs, so that "exp()" becomes
"Math.exp()", just like
latex(sin(x))
is
\sin\left(x\right)
Thoughts?
Dan
--
--- Dan Drake
-----
http://math.pugetsound.edu/~ddrake
-------