[sympy] Should symbolic integration fail gracefully?

2019-08-20 Thread David Bailey
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 "", line 1, in 
  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

--
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/b15c771c-5051-225d-bd0d-a655b6952de0%40dbailey.co.uk.


Re: [sympy] Should symbolic integration fail gracefully?

2019-08-20 Thread Oscar Benjamin
Hi David,

Can you open an issue on Github please. That's a bug that should be fixed.

Oscar

On Tue, 20 Aug 2019 at 21:08, David Bailey  wrote:
>
> 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 "", line 1, in 
>   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
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sympy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/b15c771c-5051-225d-bd0d-a655b6952de0%40dbailey.co.uk.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxTQHmn3WgR5UdaXaR7Cv5aedv_rUS8J6ecBk0YxbvsYCw%40mail.gmail.com.


Re: [sympy] Should symbolic integration fail gracefully?

2019-08-20 Thread Aaron Meurer
"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.

Aaron Meurer

On Tue, Aug 20, 2019 at 2:08 PM David Bailey  wrote:
>
> 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 "", line 1, in 
>   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
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sympy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/b15c771c-5051-225d-bd0d-a655b6952de0%40dbailey.co.uk.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAKgW%3D6LG7f_-wCdUF1kvdo5VvoiyDGciGbcQ9RfzC7j6%2BQz4GA%40mail.gmail.com.


Re: [sympy] Can't get sympy.functions.atan2 to work with _eval_evalf

2019-08-20 Thread Ville Bergholm

On Tuesday, August 20, 2019 at 5:43:40 PM UTC+3, Oscar wrote:

>
> Can you open an issue on Github for this? 
>
>
Sure:  https://github.com/sympy/sympy/issues/17461

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/73823501-26d0-403b-b28b-20b98fb82fda%40googlegroups.com.


Re: [sympy] Can't get sympy.functions.atan2 to work with _eval_evalf

2019-08-20 Thread Oscar Benjamin
There's a "return" missing:
$ git diff
diff --git a/sympy/functions/elementary/trigonometric.py
b/sympy/functions/elementary/trigonometric.py
index 635e7f2..b7a0ad1 100644
--- a/sympy/functions/elementary/trigonometric.py
+++ b/sympy/functions/elementary/trigonometric.py
@@ -3070,4 +3070,4 @@ def fdiff(self, argindex):
 def _eval_evalf(self, prec):
 y, x = self.args
 if x.is_extended_real and y.is_extended_real:
-super(atan2, self)._eval_evalf(prec)
+return super(atan2, self)._eval_evalf(prec)

Also it checks if the args are real so it looks like you might need to
declare your variables a and y with real=True. If you do that then the
result is caculated as: 0.785398163397448

Can you open an issue on Github for this?

On Tue, 20 Aug 2019 at 15:34, Ville Bergholm  wrote:
>
> 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
>
> --
> You received this message because you are subscribed to the Google Groups 
> "sympy" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to sympy+unsubscr...@googlegroups.com.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/sympy/4480befb-c8d3-48f1-a1be-b5e8bd55a0be%40googlegroups.com.

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/CAHVvXxSD2zW1%3DQ_H4%2BJX%3D3%2BTRRd%3DeKObMqW-udsRY-GSZnOX4A%40mail.gmail.com.


[sympy] Can't get sympy.functions.atan2 to work with _eval_evalf

2019-08-20 Thread Ville Bergholm
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

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/4480befb-c8d3-48f1-a1be-b5e8bd55a0be%40googlegroups.com.


[sympy] Re: Can't get sympy.functions.atan2 to work with _eval_evalf

2019-08-20 Thread Kalevi Suominen
It seems that evalf of atan2 currently expects that its arguments are real. 
For symbols like x and y, this
means that they have to be initialized with `real=True`. It does not 
suffice that evalf would return a real
value as assumption code does not try to run evalf.

Kalevi Suominen

On Tuesday, August 20, 2019 at 5:34:21 PM UTC+3, Ville Bergholm wrote:
>
> 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
>

-- 
You received this message because you are subscribed to the Google Groups 
"sympy" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sympy+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sympy/5b8f5d4f-478a-44e5-b56d-524d189e99d8%40googlegroups.com.