On Sep 5, 2:56 pm, William Stein <[email protected]> wrote:
> So did it turn out to be impossible to just write some sort of layer
> that just passes strings back and forth to *maxima* but via a C
> library-level interface? Just curious.
No, that is quite possible. Some of the earlier examples basically did
that. You could do something like:
def eval_string_in_maxima(line):
return str(ecl_eval("#$%s$"%line))
It is just so much more elegant to translate the tree representations
directly, since they are really isomorphic. I had quite a bit of fun
unravelling ECL's API and not exposing/using it seemed a bit
unsatisfying.
I didn't want to delve to deeply into Pynac, because it seems rather
thickly wrapped in SR and since it was written so recently, I figured
other people would be around who would like a shot at making an
elegant interface.
The error handling really shouldn't be an issue. ecl_safe_eval etc.
give a rudimentary interface for it.
I basically limited myself to expr.operator(), expr.operands(),
is_SymbolicVariable() and expr.pyobj() to pick apart the expressions.
A few levels lower, I think the resemblence between maxima's
expression trees and pynac should be much closer. I expect that you
*really* just need a dictionary for the atoms, plus some interface
translation:
maxima: limit(f(x),x,0) versus sage: limit(f(x),x=0)
Incidentally, for anybody who wants to figure out more about maxima's
formula encoding:
EclObject("#$ ....$ ")
shows you exactly what LISP gets to see after Maxima's parser is done,
so
sage: L=EclObject("#$integrate(tan(x),x)$")
sage: L
<ECL: (MEVAL* '(($INTEGRATE) ((%TAN) $X) $X))>
sage: L.eval()
<ECL: ((%LOG . #1=(SIMP)) ((%SEC . #1#) $X))>
sage: ecl_eval("(setq *print-circle* nil)")
<ECL: NIL>
sage: L.eval()
<ECL: ((%LOG SIMP) ((%SEC SIMP) $X))>
The last bit shows that ecl_init turned on circular list printing (the
objects that need to be protected from garbage collected are stored in
a doubly linked list to allow for deletion of nodes in constant time,
and such a structure would normally hang LISP's printing routines,
which is nasty if you're debugging exactly that). If you turn it off,
you get a less confusing representation (I think the "SIMP" is simply
a flag left there to indicate that the subexpression has already been
"simplified")
and then of course:
sage: MAXtoSR(L.eval())
log(SAGE_OP_1(SAGE_SYMBOL_2))
shows that %SEC and $X weren't known to correspond to anything in sage
yet (just because the dictionary doesn't contain sec)
---
Concerning namespaces: I think William is exactly right. Since
calculus was already used to talking to just one maxima instance,
there shouldn't be too much trouble. My warning was more concerning
loading AXIOM in there too to use it in library mode as well ...
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send an email to [email protected]
To unsubscribe from this group, send an email to
[email protected]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---