On Thursday, June 5, 2014 6:32:42 PM UTC-7, Hal Snyder wrote:
>
> IIs there a simple way to take n() of things without getting into the 
> following?
>
You could automate the application, but you'll quickly see you need to be a 
bit careful:

#unfortunately, the operators returned for sums and products of multiple
#arguments are callable, but don't accept multiple arguments, so we need to
#do a little surgery ourselves (borrow the functionality from elsewhere):
 
opdict = {
  operator.mul : sage.interfaces.maxima_lib.mul_vararg,
  operator.add : sage.interfaces.maxima_lib.add_vararg,
}
def recn(e):
    try:
        return n(e)
    except TypeError:
        pass
    op=e.operator()
    if op:
        if op in opdict:
          op = opdict[op]
        return op(*[recn(c) for c in e.operands()])
    else:
        return e
--

This now works, a little bit:

sage: recn(area)
21.5161409036487*meter^2.00000000000000

As you can see, the exponent in meter^2 was also numerified. Perhaps you 
didn't want that?

Nonetheless, a recursive n(..) method seems eminently reasonable and 
desirable to implement.

-- 
You received this message because you are subscribed to the Google Groups 
"sage-support" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-support+unsubscr...@googlegroups.com.
To post to this group, send email to sage-support@googlegroups.com.
Visit this group at http://groups.google.com/group/sage-support.
For more options, visit https://groups.google.com/d/optout.

Reply via email to