Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

answered 2011-03-22 04:06:17 -0600

DSM gravatar image

You can work around this by replacing sqrt(2) with RR(sqrt(2)) or sqrt(2).n() or float(sqrt(2)) -- anything which turns it from an Expression into a number.

I think this is a bug caused by the quirk that matplotlib thinks that Sage Expressions are iterable because it tests whether "len" works:

def iterable(obj):
    'return true if *obj* is iterable'
    try: len(obj)
    except: return False
    return True

and sqrt(2) does have a working len, even though it's not iterable:

sage: len(sqrt(2))
2
sage: list(sqrt(2))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)    
[...]
TypeError: 'sage.symbolic.expression.Expression' object is not iterable

I've confirmed that if I hack matplotlib.cbook.iterable it works. Probably the right way to fix this is to get plot to coerce to floats at the start using to_float_list, which strangely enough isn't currently used anywhere in sage/plot.

You can work around this by replacing sqrt(2) with RR(sqrt(2)) or sqrt(2).n() or float(sqrt(2)) -- anything which turns it from an Expression into a (real) number.

I think this is a bug caused by the quirk that matplotlib thinks that Sage Expressions are iterable because it tests whether "len" works:

def iterable(obj):
    'return true if *obj* is iterable'
    try: len(obj)
    except: return False
    return True

and sqrt(2) does have a working len, even though it's not iterable:

sage: len(sqrt(2))
2
sage: list(sqrt(2))
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)    
[...]
TypeError: 'sage.symbolic.expression.Expression' object is not iterable

I've confirmed that if I hack matplotlib.cbook.iterable it works. Probably the right way to fix this is to get plot to coerce to floats at the start using to_float_list, which strangely enough isn't currently used anywhere in sage/plot.