I've been trying to use sympy.Symbol to implement a system where the numerical value of a symbolic quantity is only fixed when it is evaluated using evalf().
To accomplish this I've redefined _eval_evalf() to return the aforementioned value (a fixed 5.0 in the toy example below).
This works fine with basic algebraic operations and most SymPy functions. However, for some reason atan2 seems to behave differently and _eval_evalf is never called.
Is this a bug, or have I misunderstood the purpose of _eval_evalf?
import sympy
import sympy.functions as syf
class A(sympy.Symbol):
def _eval_evalf(self, prec):
print('*')
return sympy.Float(5.0)
x = A('X')
y = A('Y')
print('polynomial:')
print((2*x-4+y).evalf()) # works fine
print('atan:')
print(syf.atan(y / x).evalf()) # works fine
print('beta:')
print(syf.beta(y, x).evalf()) # works fine
print('atan2:')
print(syf.atan2(y, x).evalf()) # prints "atan2(Y, X)", does not call A._eval_evalf
Can you open an issue on Github for this?
It seems as though the symbolic integration process fails when it can't find a solution:
integrate(sin(x**n),x)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File
"C:\SymPyWorkbook\lib\site-packages\sympy\integrals\integrals.py",
line 1477, in integrate
return integral.doit(**doit_flags)
File
"C:\SymPyWorkbook\lib\site-packages\sympy\integrals\integrals.py",
line 541, in doit
function, xab[0], **eval_kwargs)
File
"C:\SymPyWorkbook\lib\site-packages\sympy\integrals\integrals.py",
line 1012, in _eval_integral
h = meijerint_indefinite(g, x)
File
"C:\SymPyWorkbook\lib\site-packages\sympy\integrals\meijerint.py",
line 1621, in meijerint_indefinite
res = _meijerint_indefinite_1(f.subs(x, x + a), x)
File
"C:\SymPyWorkbook\lib\site-packages\sympy\integrals\meijerint.py",
line 1684, in _meijerint_indefinite_1
if b < 0 or f.subs(x, 0).has(nan, zoo):
File
"C:\SymPyWorkbook\lib\site-packages\sympy\core\relational.py",
line 304, in __nonzero__
raise TypeError("cannot determine truth value of Relational")
TypeError: cannot determine truth value of Relational
I suppose I expected it to return an unevaluated integral - integral(sin(x**n),x)
David
Hi David, Can you open an issue on Github please. That's a bug that should be fixed.
The problem is, I tried to join Github a while back, and then needed a password reset. It said it had sent me an email to reset my password, but it never appeared (and I looked in junk). After that happened several times, I gave up.
However, if that problem is already solved, that's fine, I was really just reporting it - I suspect the integral doesn't have a closed form for variable n. Do you release beta tests of the next version of sympy?
Or did you mean 'should' in the sense of 'needs to be'?
David
"TypeError: cannot determine truth value of Relational" generally indicates a bug in SymPy. And yes, integrate() should always return unevaluated when it can't compute the integral.
I imagine that symbolic integration may be littered by tricky problems of this sort, and I wonder if the integrate code should be wrapped in some sort of exception handler so that it exits and returns unevaluated.
David
To view this discussion on the web visit https://groups.google.com/d/msgid/sympy/CAKgW%3D6Lc%2BZ%2Bd-8dawVzH3h8NwpZvFvyothm1p01vSZidL%3DQbxA%40mail.gmail.com.