numerical_integral in piecewise function
If I define a Python function with a numerical integral
def g(x):
var('u')
return numerical_integral(u,0,x)[0]
then it behaves as expected for example when plotting with plot(g)
. If it is included as part of a piecewise function like
f = piecewise([[(-1,0),-x],[(0,1),g]])
plot(f)
then the plot shows up just fine for Sage 6.9 (which was running on sagecell.sagemath.org), but for Sage 7.2 (which is running on the test server) one gets the error message
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-1-474c66ac1c47> in <module>()
4
5
----> 6 f = piecewise([[(Integer(0),Integer(1)),g]])
7 plot(f)
/home/sc_serv/sage/src/sage/misc/lazy_import.pyx in sage.misc.lazy_import.LazyImport.__call__ (/home/sc_serv/sage/src/build/cythonized/sage/misc/lazy_import.c:3628)()
384 True
385 """
--> 386 return self._get_object()(*args, **kwds)
387
388 def __repr__(self):
/home/sc_serv/sage/local/lib/python2.7/site-packages/sage/functions/piecewise.py in __call__(self, function_pieces, **kwds)
149 function = function()
150 else:
--> 151 function = function(var)
152 function = SR(function)
153 if var is None and len(function.variables()) > 0:
<ipython-input-1-474c66ac1c47> in g(x)
1 def g(x):
2 var('u')
----> 3 return numerical_integral(u,Integer(0),x)[Integer(0)]
4
5
/home/sc_serv/sage/src/sage/gsl/integration.pyx in sage.gsl.integration.numerical_integral (/home/sc_serv/sage/src/build/cythonized/sage/gsl/integration.c:3387)()
329 else:
330 _a=a
--> 331 _b=b
332 W = <gsl_integration_workspace*> gsl_integration_workspace_alloc(n)
333 sig_on()
/home/sc_serv/sage/src/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.__float__ (/home/sc_serv/sage/src/build/cythonized/sage/symbolic/expression.cpp:10403)()
1384 return float(self._eval_self(float))
1385 except TypeError:
-> 1386 raise TypeError("unable to simplify to float approximation")
1387
1388 def __complex__(self):
TypeError: unable to simplify to float approximation
Am I missing something simple or is this a bug in Sage 7.2?
There is an existing ticket that appears relevant: http://trac.sagemath.org/ticket/14801