*TL;DR :* Sage can produce a symbolic expression : - that it can't evaluate numerically when correcly substiuted, AND - that can be evaluated when typed manually.
The problem seems ti be bound to absolute values. That, IMHO, is a first-class bug... *Demonstation :* I think that some results produced by fricas' integrator are wrong, and wanted to show it numerically. Problem setup : x,y=var("x,y", domain="real") assume(x>-1,x<1,y>-1,y<1,x^2+y^2<1) eps1=var("eps1", latex_name="\\varepsilon_1", domain="positive") eps2=var("eps2", latex_name="\\varepsilon_2", domain="positive") assume(eps1<1,eps2<1, eps1^2+eps2^2<1) f(x,y)=sqrt(1-x^2-y^2) Define the integral on a given rectangle as a function : foo(eps1,eps2)=f(x).integrate(x,0,eps1, algorithm="fricas").integrate(y,0,eps2, algorithm="fricas") Use it : sage: bar=foo(1/10,1/10) sage: bar 299/12000*pi - 1/198*sqrt(11)*pi*abs(-3/2*sqrt(11)) + 7/1500*sqrt(1/2) + 1/6*arctan(9799/140*sqrt(1/2)) - 299/6000*arctan(14*sqrt(1/2)) + 299/6000*arctan(1/7*sqrt(1/2)) So far so good. But when I want a numerical approximation : sage: bar.n() --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-104-425a0225c048> in <module>() ----> 1 bar.n() /usr/local/sage-8/local/lib/python2.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.n (build/cythonized/sage/structure/element.c:8020)() 859 0.666666666666667 860 """ --> 861 return self.numerical_approx(prec, digits, algorithm) 862 863 def _mpmath_(self, prec=53, rounding=None): /usr/local/sage-8/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.numerical_approx (build/cythonized/sage/symbolic/expression.cpp:33969)() 5949 res = x.pyobject() 5950 else: -> 5951 raise TypeError("cannot evaluate symbolic expression numerically") 5952 5953 # Important -- the we get might not be a valid output for numerical_approx in TypeError: cannot evaluate symbolic expression numerically Let's debug it : def tryit(x): try: return x.n() except: return "Failed..." Let's see : sage: gee=[[u,tryit(u)] for u in bar.operands()] sage: gee [[299/12000*pi, 0.0782780169519457], [-1/198*sqrt(11)*pi*abs(-3/2*sqrt(11)), 'Failed...'], [7/1500*sqrt(1/2), 0.00329983164553722], [1/6*arctan(9799/140*sqrt(1/2)), 0.258432327173397], [-299/6000*arctan(14*sqrt(1/2)), -0.0732611082333419], [299/6000*arctan(1/7*sqrt(1/2)), 0.00501690871860373]] However, when I copy and paste the very same expression (or type it manually), it can be numerically approximated : sage: (-1/198*sqrt(11)*pi*abs(-3/2*sqrt(11))).n() -0.261799387799149 Diving recusively : sage: [[u,tryit(u)] for u in bar.operands()[1].operands()] [[sqrt(11), 3.31662479035540], [pi, 3.14159265358979], [abs(-3/2*sqrt(11)), 'Failed...'], [-1/198, -0.00505050505050505]] Again, the litigious expression can be evaluated by copy 'n paste : sage: abs(-3/2*sqrt(11)).n() 4.97493718553310 BUT the semi-obvious workaround fails : sage: SR(repr(bar.operands()[1])).n() --------------------------------------------------------------------------- TypeError Traceback (most recent call last) <ipython-input-117-e426b18b4666> in <module>() ----> 1 SR(repr(bar.operands()[Integer(1)])).n() /usr/local/sage-8/local/lib/python2.7/site-packages/sage/structure/element.pyx in sage.structure.element.Element.n (build/cythonized/sage/structure/element.c:8020)() 859 0.666666666666667 860 """ --> 861 return self.numerical_approx(prec, digits, algorithm) 862 863 def _mpmath_(self, prec=53, rounding=None): /usr/local/sage-8/local/lib/python2.7/site-packages/sage/symbolic/expression.pyx in sage.symbolic.expression.Expression.numerical_approx (build/cythonized/sage/symbolic/expression.cpp:33969)() 5949 res = x.pyobject() 5950 else: -> 5951 raise TypeError("cannot evaluate symbolic expression numerically") 5952 5953 # Important -- the we get might not be a valid output for numerical_approx in TypeError: cannot evaluate symbolic expression numerically Recurse again : sage: [[u,tryit(u)] for u in bar.operands()[1].operands()[2].operands()] [[-3/2*sqrt(11), -4.97493718553310]] Therefore, the problem seems to be with the numerical approximation of an absolute value. I'm stuck. Two questions : - Ticket worthy (yes, IMHO) - Workaround suggestions ? HTH, -- You received this message because you are subscribed to the Google Groups "sage-devel" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-devel+unsubscr...@googlegroups.com. To post to this group, send email to sage-devel@googlegroups.com. Visit this group at https://groups.google.com/group/sage-devel. For more options, visit https://groups.google.com/d/optout.