
Boost : 
Subject: Re: [boost] boost interval arithmetic
From: Marc Glisse (marc.glisse_at_[hidden])
Date: 20150114 16:58:17
On Thu, 15 Jan 2015, ÐŸÐ°Ð²ÐµÐ» ÐšÑƒÐ´Ð°Ð½ wrote:
>> I tried the following program:
>>
>> #include <boost/numeric/interval.hpp>
>> #include <iostream>
>>
>> typedef boost::numeric::interval<double> I;
>> int main(){
>> Â Â Â I a(1,2);
>> Â Â Â I b(1,1);
>> Â Â Â std::cout << lower(a) << ',' << upper(a) << std::endl;
>> Â Â Â std::cout << lower(b) << ',' << upper(b) << std::endl;
>> Â Â Â a/=b;
>> Â Â Â std::cout << lower(a) << ',' << upper(a) << std::endl;
>> }
>>
>> and it prints:
>>
>> 1,2
>> 1,1
>> inf,inf
>>
>> and not inf,1 as you claim. If you have code showing a different result,
>> please post it. I can't see anything in the documentation that supports
>> your claim.
>>
>> [inf,inf] is the smallest interval containing all possible values for the
>> quotient, so it makes a lot of sense to return that. Now, if I understand
>> correctly, you would like to add a policy so that anytime an operation has
>> a disconnected image, instead of bridging the gap, boost would throw. That
>> would be useless in my applications (well, maybe a shortcut since once I
>> get [inf,inf] somewhere it tends to propagate, eventually to a comparison
>> that will throw), but maybe it makes sense for yours... In any case, it
>> doesn't look like it would hurt boost to add such an optional policy. So
>> if you want to prepare a patch, someone might be willing to review and
>> pull it.
>
> In that case [inf, inf] should be a result of any operation in the
> world :) As it is universal :)))
Note the word "smallest" in my explanation.
> 2 + 2 == [inf, inf], is it true? :)
>
> Of course  as it is somewhere between :)
>
> Not true? Of course, not.
>
> 2 + 2 !=Â Â [inf, inf]
> and [inf, inf] != [inf, 1] U [1, inf]
[inf,inf] is the smallest interval containing both [inf, 1] and [1,
inf]. It isn't possible to return a smaller interval that still contains
all possible values.
> Let's see presentation about boost interval and interval arithmetic.
>
> https://www.lri.fr/~melquion/doc/03rnc5expose.pdf
>
> 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
>
> http://www.boost.org/doc/libs/1_37_0/libs/numeric/interval/doc/interval.htm
>
> 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.
Language barrier. You are grossly misunderstanding the documentation. "The
set of division results" is [inf,1] union [1,inf]. "The smallest
interval containing" this set is [inf,inf]. It is NOT the same thing as
the smallest connected component of the set.
 Marc Glisse
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk