Thank you! I have a lot to learn about Sage, I can see. Will study
experiment with recn.
In most cases, an integer exponent should look like 2 and not
2.000, don't you think? So I guess I would not n() the exponents.
I have just started using Sage and SMC with some online classes. It's great
to:
- check work with units of measure
- take notes that look like math rather than COBOL (+1 typeset_mode)
- do symbolic and numerical calculations in those same typeset notes
I'm hooked. :-)
On Friday, June 6, 2014 6:53:18 PM UTC-5, Nils Bruin wrote:
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.00
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.