Boost logo

Boost :

Subject: Re: [boost] [interval] arithmetic
From: Павел Кудан (coodan_at_[hidden])
Date: 2015-01-14 08:42:18

 Dear Marc,

Thank you for your answer, I also tried to contact Mr.Gubenko, have no information about other maintainers. Please, excuse my bad English, I will try to explain in more detail, please, ask in something will be uncertain.

Boost interval library was planned as extension of mathematical functions on float/double/double long or other singe numeric values to operations on intervals. The problem is that intervals have some specific. For example, if float value can be either > either < or = some other float value (statement ! (a>b) == (a <= b) is always true), for intervals it is not correct. Intervals can also overlap. That means that it is not possible for pair of overlapping intervals to say certainly which of them are greater than other. It is the intermediate situation, which is impossible with original single float values.

And boost interval class has comparison operators and user can expect that they will behave in similar way with usual float comparison operators.

For that reason, the behaviour of that comparison operators was made changeable and depends on some kind of policy, defined by user. Default behaviour is to throw exception when such intermediate situation (not possible for single float values) takes place.

That was very wise solution, especially useful in very probable case, when some programmer will try to adapt some existing code with float calculation just changing type of value to boost interval. He will get exception in than exceptional situation - when usual float comparison operator is not applicable any more.

That is OK.

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]

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.

Very very bad operator behaviour. User get not correct result and even does not know that it is so. It will be hard to find when this error is located, and when it will be done, library user will not think that he should know better what he are doing and learn some basics of interval arithmetic - no, he will accuse boost interval as part and boost as whole for bugs in libraries implementation. U nfairly , of course, but who cares.

To correct it, at least, arithmetic operators and functions of interval class must behave similarly to comparison operators - throw exception in situations, not applicable for single float calculations.

That is what I meant when said: "The difference in behaviour of comparison operators and basic arithmetic operators looks as probable misconception."

I know, it is hard to understand, especially because bad English, but I hope it is important and hope it will help.

Best regards,

Wed, 14 Jan 2015 12:16:56 +0100 (CET) от Marc Glisse <marc.glisse_at_[hidden]>:
>On Tue, 13 Jan 2015, Павел Кудан wrote:
>> The difference in behaviour of comparison operators and basic arithmetic operators looks as probable misconception.
>> Default and changeable behaviour of comparison operators consists in throwing exception in intermediate situation (intersecting intervals, ! (a>b) == (a <= b) is not applicable). Great decision for correct migration from float numeric code.
>> The only and unchangeable behaviour of arithmetic operators consists in silent returning only one of possible intervals in intermediate situation (possible return is not single, multiple interval result). The source of mistakes and undesired behaviour at migration from float numeric.
>> At least, throwing exception by arithmetic operators at intermediate situation would provide behaviour unity of comparison and arithmetic operators and functions.
>I have a hard time understanding your post. Could you try explaining it
>again, maybe with more concrete examples of what boost is doing, what you
>would like instead and why?
>(I don't think this code is maintained, at least the email addresses of
>all the maintainers are outdated)
>Marc Glisse
>Unsubscribe & other changes:

P. Coodan

Boost list run by bdawes at, gregod at, cpdaniel at, john at