# Boost :

Subject: Re: [boost] boost interval arithmetic
From: ÐŸÐ°Ð²ÐµÐ» ÐšÑƒÐ´Ð°Ð½ (coodan_at_[hidden])
Date: 2015-01-14 16:28:39

>
>> But as well boost interval class defines mathematical functions and operators. And user can expect that they also will behave similarly to usual float comparison operators. But great disappointment and multiple possible errors which is hard to locate is waiting for him here. Because it is not so. Arithmetic operators behave in completely different manner.
>>
>> Let's look on of most basic operator =/ and see what it is doing.
>>
>> But before let's see what is division of intervals and what is it's result.Â
>>
>> Boost interval class has two function - division_part1() and division_part2(). It is correct as when you divide one interval with another, the result will be single interval or a pair of intervals. The last situation takes place when in statement A / B, interval B cross a zero. That is not normal for intervals to have a pair of intervals as a result of division, but it is exceptional for single float numeric division.
>>
>> Now let's get back to /= operator and watch what he will do in such case.
>>
>> Let A = [1,2] and B = [-1, 1]
>>
>> and let's see what we will get after A /= B and what we should get.
>>
>> The true result of division in that case will be a union of pair of intervals [-infinity, -1] and [2, -infinity]
>
>Actually, [-inf,-1][1,+inf]
>
>> Interval /=Â  operator, naturally, must return one interval. It is, obviously, impossible in this case - to return one of two. Again intermediate situation, not applicable to single float calculations. Again, throwing exception must be a result to let user know that he does not know what he are really doing. The same behaviour, as comparison operators. But it is not so.
>>
>> Instead of such natural behaviour, /= operator of boost interval class are doing impossible thing. It silently decides for itself which one of two parts of whole result to return and kill another part of whole solution somewhere under the scene.
>>
>> The result of A /= B will be [-infinity, -1]. Not correct result - as it is not complete. One of to parts is missing.
>
>Did you really observe that? If so, it is a bug. [1,2]/[-1,1] is supposedÂ
>to give [-inf,inf] (and it does indeed, in my tests), which certainlyÂ
>contains the right value ;-)
>
>If you have a testcase that shows differently, it would be good to open aÂ
>bug report on trac.

To certainly contain right value and to be write value are cernainly different things, are not? :))Â

By the way, if you get [-inf, inf] in that case, then boost interval class has not only misconception but also a bag. Its result should be [-inf, 1] according to documentation.

Let's see presentation about boost interval and interval arithmetic.

On page 11:
Functions can also be used to compute a pair of
intervals: [1, 2] Ã· [âˆ’1, 1] = [âˆ’âˆž, âˆ’1] âˆª [1, +âˆž].
(that is not boost interval operator / yet, it is basic arithmetic operation for interval. That is what should be a result)

also, on page 5:
[a, b] Ã— [c, d] = [min(ac, bc, ad, bd), max(ac, bc, ad, bd)],
[a, b] Ã· [c, d] = [a, b] Ã— [1 Ã· d, 1 Ã· c] if 0 NOT âˆˆ [c, d]

(that is not boost interval operator / yet, but it is the way its result is calculated when zero is not inside of [c, d] interval (by the way, typo here - must be 'if 0 NOT âˆˆ (c, d)).
And here official boost interval documentation

The operatorsÂ  / Â andÂ  /= Â will try to produce an empty interval if the denominator is exactly zero. If the denominator contains zero (but not only zero), the result will be the smallest interval containing the set of division results; so one of its bound will be infinite, but it may not be the whole interval.

So, official documented result of / operator for that case is [-inf, 1] as it is smallest interval (the result of division_part1() function of boost interval class). And this result is not correct as it is not full.

If you get [-inf, inf] result in real test, it means that boost interval class has not only misconception, but also a bag, as it also conflict with own misconception :)))