Regarding Jason's recent patch allowing

sage: plot(x^(1/3),-1,1)

to still output a plot where it makes sense in Sage, I wonder whether
the following might also be useful in the _call() method of plot.py,
at around line 3620:

if msg = "negative number cannot be raised to a fractional power" :
  print "In Sage, even odd fractional powers of negative numbers yield
complex roots"

so that people would know that (that is, people who don't have
experience with CAS behavior).  I suppose one would want to make sure
this printed only once, so there would probably have to be a dummy
variable to keep track of that too, but whatever.

A more ambitious, but perhaps not practical, idea would be to try to
catch the exceptions and then coerce them, at least if they are
written in the obvious way (which would not preclude the above error
message from being printed), just in case someone really did type in
an easy thing like x^(1/3), as opposed to (big thing which could be
complex)^(1/3) :

if msg = "negative number cannot be raised to a fractional power" :
    try: replace (stuff)^(m/p) by (RR(stuff).nth_root(p))^m
        data[i] = (float(xi),float(the tried thing))
    except (Error) # all errors excepted!
        print "In Sage, even odd fractional powers of negative numbers
may yield complex roots"

where some sort of pattern match (I assume it's possible in Python,
but is it pretty complex?) would happen in the "try" block, perhaps
better aligned with preparsing, with _pow_ or ** ... Though I'm a bit
hazy as to how to try to get both Integer(1)/Integer(3), which lives
in sage.rings.rational.Rational *and* .33333333333333, which lives in
sage.rings.real_mpfr.RealNumber, but they both respond well to RR,
anyway.

Is this worth trying to implement, or even possible to consider
implementing (I realize the grep-ish behavior might be too complicated
to bother with)?  I am sure there are mistakes in the pseudo-code
above, for that matter.  But if so, I would like to try.

- kcrisman
--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to