On Dec 10, 3:48 am, Pablo Angulo <pablo.ang...@uam.es> wrote: > This is related to a subtle, undocumented difference between these two > definitions of a symbolic expression:
These are not both symbolic expressions per se - one is callable, the other one isn't. These used to be called SymbolicExpression and CallableSymbolicExpression or something like that, but apparently this is not still the case. What does seem odd is that only happens for f(x)=1, not f(x)=2, or f(x) =x, not f(x)=x. I think it is because sage: f.operator() <nothing returned> so that the fast_float converter tries to make a symbol out of it, but since it's 'callable' you can't do that. For some reason when you have somewhere to go in the expression tree it works, but not here. Anyway, maybe someone who understand this a little better can suggest an alternative to the following in expression_conversions.py FastFloatConverter.symbol() name = repr(ex) in line 1103 of that file; clearly 'x |--> x' (the output of repr(f) for f(x)=x) is not going to be in the variables, and not in the symbols of the variables, and it's not a constant either, so we get this TypeError. - kcrisman > var('v') > r(v)=v > print r > /// > v |--> v > > r=v > print r > /// > v > > so both are printed different, but they return the same value when > called with a question mark: > > r? > /// > > *File:* > /opt/sage-4.1.1/local/lib/python2.6/site-packages/sage/symbolic/expression. so > > *Type:* <type 'sage.symbolic.expression.Expression'> > > *Definition:* r(*args, **kwds) > > *Docstring:* > > x.__init__(...) initializes x; see x.__class__.__doc__ for signature > > Introducing F by hand pose no problem if the functions are introduced > using the second syntax, but gives the same problem if the first one is > used (only for F0(x)=x, not for F0(x)=2*x). > > var('x') > F0(x)=x > print F0 > F_bis=Piecewise([[(0, 1), F0], [(1,2), -1/2*x^2 + 4*x - 5/2], [(2, 3), > -1/10*e^2 +1/10*e^x + 7/2], [(3, 10), -1/10*e^2 + 1/10*e^3 - > 1/2*cos(2*x)+ 1/2*cos(6) + 7/2]]) > print F_bis > /// > x |--> x > Piecewise defined function with 4 parts, [[(0, 1), x |--> x], [(1, 2), > -1/2*x^2 + 4*x - 5/2], [(2, 3), -1/10*e^2 + 1/10*e^x + 7/2], [(3, 10), > -1/10*e^2 + 1/10*e^3 - 1/2*cos(2*x) + 1/2*cos(6) + 7/2]] > > plot(F_bis) > /// > Traceback (most recent call last): > File "<stdin>", line 1, in <module> > File "_sage_input_86.py", line 4, in <module> > exec compile(ur'plot(F_bis)' + '\n', '', 'single') > File "", line 1, in <module> > > File > "/opt/sage-4.1.1/local/lib/python2.6/site-packages/sage/plot/misc.py", > line 243, in wrapper > return func(*args, **kwds) > File > "/opt/sage-4.1.1/local/lib/python2.6/site-packages/sage/plot/misc.py", > line 138, in wrapper > return func(*args, **options) > File > "/opt/sage-4.1.1/local/lib/python2.6/site-packages/sage/plot/plot.py", > line 2444, in plot > G = funcs.plot(*args, **original_opts) > File > "/opt/sage-4.1.1/local/lib/python2.6/site-packages/sage/functions/piecewise > .py", > line 961, in plot > return sum([plot(f, a, b, *args, **kwds) for (a,b),f in self.list()]) > File > "/opt/sage-4.1.1/local/lib/python2.6/site-packages/sage/plot/misc.py", > line 243, in wrapper > return func(*args, **kwds) > File > "/opt/sage-4.1.1/local/lib/python2.6/site-packages/sage/plot/misc.py", > line 138, in wrapper > return func(*args, **options) > File > "/opt/sage-4.1.1/local/lib/python2.6/site-packages/sage/plot/plot.py", > line 2444, in plot > G = funcs.plot(*args, **original_opts) > File "expression.pyx", line 6059, in > sage.symbolic.expression.Expression.plot > (sage/symbolic/expression.cpp:24894) > File "expression.pyx", line 5951, in > sage.symbolic.expression.Expression._fast_float_ > (sage/symbolic/expression.cpp:24305) > File > "/opt/sage-4.1.1/local/lib/python2.6/site-packages/sage/symbolic/expression > _conversions.py", > line 1181, in fast_float > return FastFloatConverter(ex, *vars)() > File > "/opt/sage-4.1.1/local/lib/python2.6/site-packages/sage/symbolic/expression > _conversions.py", > line 208, in __call__ > return self.symbol(ex) > File > "/opt/sage-4.1.1/local/lib/python2.6/site-packages/sage/symbolic/expression > _conversions.py", > line 1099, in symbol > raise ValueError, "free variable: %s" % repr(ex) > ValueError: free variable: x |--> x -- To post to this group, send an email to sage-devel@googlegroups.com To unsubscribe from this group, send an email to sage-devel+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-devel URL: http://www.sagemath.org