On Nov 24, 10:53 pm, Dima Pasechnik <dimp...@gmail.com> wrote:
> It's a good question how to make this capability used in Sage.

This capability is already perfectly usable in Sage:

sage: M=sage.calculus.calculus.maxima
sage: M.eval("g(x):=block([s:0],for i thru x do s:s+i^2,s);")
'g(x):=block([s:0],forithruxdos:s+i^2,s)'
sage: g=M("g")
sage: %time g(10000);
CPU times: user 0.25 s, sys: 0.00 s, total: 0.25 s
Wall time: 0.26 s
sage: M.eval("compile(g);")
'[g]'
sage: %time g(10000)
CPU times: user 0.05 s, sys: 0.00 s, total: 0.05 s
Wall time: 0.05 s
333383335000

This runs maxima as a lisp-library inside ecl, with ecl running as a
dynamically linked library inside sage. I'm sure there are already CL
ffi bindings for the Python C-API so that you would also be able to
call back into python [is re-entrancy an issue for python?] from lisp
if you want to.

You can strip away the maxima layer if you so desire:

sage: g_lisp=g.ecl()
sage: %time g_lisp(10000)
CPU times: user 0.02 s, sys: 0.00 s, total: 0.02 s
Wall time: 0.02 s
<ECL: 333383335000>
sage: g_lisp
<ECL: $G>

[the variation in the timing here is use, so don't trust these times!]

On the ECL level, most conversions are done relatively efficiently,
via binary translations (of course, because Python and ECL have their
own ideas about memory management, there is no sharing -- objects are
copied over between the two worlds. This is the usual price for using
libraries that are not particularly made to cooperate with each other.
GMP bigints are still done stupidly because I couldn't figure out how
to copy over the internally identical bitstrings [both sage and ECL
use the same GMP/MPIR library].

The maxima interface is still largely based on string communication
(and the "eval" statements necessarily so!) because that code was
inherited from the original pexpect interface, but there is already
infrastructure to translate more efficiently. It's just a matter of
using it more widely.

So yes, if you have a piece of code that is most conveniently written
in maxima or lisp, go ahead and compile it! Most data structures will
be translated automatically between Python and ECL.

-- 
To post to this group, send an email to sage-devel@googlegroups.com
To unsubscribe from this group, send an email to 
sage-devel+unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URL: http://www.sagemath.org

Reply via email to