taschini / pyinterval

PyInterval — Interval arithmetic in Python
http://pyinterval.readthedocs.io
Other
83 stars 25 forks source link

Incorrect interval for sin(x)*x #29

Closed delta-v1 closed 2 years ago

delta-v1 commented 2 years ago

I am unable to compute the correct interval for sin(x) * x. I'm using the following code:

from interval import interval, imath

x = interval([-0.5, 0.5])
y = imath.sin(x) * x
print(y)                                # [-0.2397, 0.2397]

import numpy as np

X = np.linspace(-0.5, 0.5, 100)
Y = np.sin(X) * X
print(Y.min(), Y.max())                 # [0, 0.2397]

The correct bound should be [0, 0.2397], but pyinterval evaluates to [-0.2397, 0.2397]. Is there something I am missing?

markcampanelli commented 2 years ago

At first glance, I think this is due to the fact that interval analysis methods typically do not consider the "connection" between the same variable appearing in two/more "independent" locations in the expression (here the import connection is the sign of the x and the sign of sin(x)).

delta-v1 commented 2 years ago

Thanks Mark! That makes sense.

It's reasonable that pyinterval would over-estimate the range, which seems to be a well-known problem in interval arithmetic.