#7377: Symbolic Ring to Maxima via EclObject
---------------------------+------------------------------------------------
   Reporter:  nbruin       |       Owner:  nbruin      
       Type:  enhancement  |      Status:  new         
   Priority:  major        |   Milestone:  sage-feature
  Component:  symbolics    |    Keywords:              
Work_issues:               |      Author:  Nils Bruin  
   Reviewer:               |      Merged:              
---------------------------+------------------------------------------------

Comment(by nbruin):

 I think the following email might be of interest to other people wanting
 to hack maxima:

 > Since there is already a decent string parser for taking Sage stuff to
 > Maxima and (especially) getting back Sage stuff from Maxima, would
 > there be a way to modify the above - or ecl_eval - to give back the
 > Maxima expression directly?  Perhaps this is already in the
 > lib/ecl.pyx file, though I didn't see it on the first reading.

 lib/ecl.pyx has nothing to do with maxima-specific stuff. That is all in
 sagemax.py. It is actually a little bit important to keep that
 distinction.
 Maxima is not the only lisp program we might want to interface with.

 There is {{{max_read(S) = cadadr(EclObject("#$%s"%S))}}}, which *reads*
 the string
 S as a maxima expression and returns its parsed result.

 So {{{meval(max_read(S))}}} would do the trick. I do not know what
 routines maxima
 has to convert expressions to a string. If I wanted to know, I would find
 it
 out by looking at something like

 {{{max_read("maxima-command-to-print-to-string(x)")}}}

 and see what token the maxima reader puts in. I imagine you get something
 like

 {{{
 <ECL: ((MAX-PRINT-STRING) x)>
 }}}

 back, So do:

 {{{
 maxprint:=EclObject("MAX-PRINT-STRING") #do this once globally
 meval(EclObject([[maxprint], maxexpression])).python()
 }}}

 Indeed:

 {{{
 sage: max_read("string(x)")
 <ECL: (($STRING) $X)>
 sage: meval(max_read("string(x)"))
 <ECL: "x">
 sage: meval(max_read("string(x)")).python()
 '"x"'
 sage: meval(max_read("string(x)")).python()[1:-1]
 'x'
 }}}

 So

 {{{
 sage: maxprint=EclObject("$STRING")
 sage: def max_to_string(s):
 ....:      return meval(EclObject([[maxprint],s])).python()[1:-1]
 }}}

 would give you a string representation. Be aware that #$...$ suffers from
 performance loss, so if you repeatedly use it, your timings will go south
 quickly. See Dodier's comments on this a while ago. Apparently you could
 patch Maxima to lose the performance-losing routine (at the expense of
 losing the wonderful linear-search history the maxima parser offers now).

 > Sage command -> calls Maxima command -> Maxima command evaluated, but
 > in the ECL library version, not the pexpect version -> Maxima output
 > (a string) converted back using the stuff in Sage

 Yes, that would be an approach virtually orthogonal to the one taken in
 sagemax.py.

 {{{
 > sage: str(ecl_eval("#$load(to_poly_solver)$"))
 > append: argument must be a non-atomic expression; found false
 > -- an error.  To debug this try debugmode(true);
 }}}
 To illustrate the inner workings:

 {{{
 sage: from sagemax import *
 sage: e=max_read('load("to_poly_solver")')
 sage: e
 <ECL: (($LOAD) "to_poly_solver")>
 sage: meval(e)
 append: argument must be a non-atomic expression; found false
  -- an error.  To debug this try debugmode(true);

 sage: meval(max_read("append(a,b)"))
 append: argument must be a non-atomic expression; found a
  -- an error.  To debug this try debugmode(true);
 }}}

 So my guess is that "load" is trying to append to an improperly
 initialized
 maxima list. I guess that means that in the current setting, our maxima
 environment hasn't properly been set up yet. That is no surprise. It is
 actually surprising that so much of maxima works without any
 initialization
 at all.

-- 
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7377#comment:2>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica, 
and MATLAB

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sage-trac" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/sage-trac?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to