I guess this is the dependency problem in interval arithmetic:
https://en.wikipedia.org/wiki/Interval_arithmetic#Dependency_problem
(Note that x**2+x is the example used there)
The issue is that we have to know the identity of the intervals. For
example if x and y are distinct intervals both [-1,1] then x*y is
[-1,1]. However x**2 has to be [0, 1].
On Sat, 20 Jul 2019 at 11:34, Chris Smith <smi...@gmail.com> wrote:
>
> Which result is correct? The second is a refactoring of the first:
>
> >>> AccumBounds(-1, 1) + AccumBounds(-1, 1)**2
> AccumBounds(-1, 2)
> >>> AccumBounds(-1, 1)*(1 + AccumBounds(-1, 1))
> AccumBounds(-2, 2)
>
> --
> 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 sy...@googlegroups.com.
Dear group,
I think one problem with sympy, is that its limitations aren't really defined, and you only know you have exceeded them if you get an error that is internal to the sympy code, for example:
Python 3.7.3 (v3.7.3:ef4ec6ed12, Mar 25 2019, 22:22:05) [MSC
v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more
information.
>>> import sympy
>>> from sympy import *
>>> sin(Interval(0,1))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\pythonsystem\lib\site-packages\sympy\core\cache.py",
line 94, in wrapper
retval = cfunc(*args, **kwargs)
File "C:\pythonsystem\lib\site-packages\sympy\core\function.py",
line 458, in __new__
result = super(Function, cls).__new__(cls, *args, **options)
File "C:\pythonsystem\lib\site-packages\sympy\core\cache.py",
line 94, in wrapper
retval = cfunc(*args, **kwargs)
File "C:\pythonsystem\lib\site-packages\sympy\core\function.py",
line 277, in __new__
evaluated = cls.eval(*args)
File
"C:\pythonsystem\lib\site-packages\sympy\functions\elementary\trigonometric.py",
line 294, in eval
if arg.could_extract_minus_sign():
AttributeError: 'Interval' object has no attribute
'could_extract_minus_sign'
>>>
I was trying to explore what Interval() could really manage, so if this had worked I was going to devise an interval that would straddle pi/2 to determine whether the sympy code recognised that situation and responded correctly. As it is, I am 90% sure that the above meant that you can't feed an interval to a transcendental function, but that leaves a 10% probability that I misunderstood something!
Subsequently I noticed that Interval maybe doesn't really evaluate much at all, for example:
Interval(0,2)**2
Returns a product of two Interval's.
Furthermore:
Interval(0,2)-Interval(0,2)
EmptySet()
However, surely this expression contains two independent
intervals, so the result is wrong!
Ideally an error message would be really informative, and maybe even give an internet reference to where this is explained. Has anyone given any thought to achieving this in a future version?
David
Operations on set objects operate on the sets themselves, not the elements of the sets. So - does set complement, not arithmetic subtraction. To get what you want, use sympy.sets.setexpr.SetExpr. Note that support for it is still somewhat limited. Aaron Meurer
Aaron,
Please note that Chris pointed out that I should have been using
AccumBounds - I had jumped to the conclusion that 'Interval'
implemented interval arithmetic - not something set-theoretic.
I am glad you are keen to see the diagnostics cleaned up, because my feeling is that there may be large umbers of potential casual users who are put off if things don't work easily - and I do like sympy.
I hope a runtime check will not reduce runtime performance appreciably. I wonder if trapping the problem with an exception handler, and somehow figuring out what had happened might be possible - however much code had to execute to do this would not really matter.
David