Thread Links Date Links
Thread Prev Thread Next Thread Index Date Prev Date Next Date Index

rat2interval



I simplified int2interval/frac2interval/rat2interval proposal,
and made rationale more verbose.
Here is the revised version.

  -Dima

-------------------

1) Add following item to section 3.2 Definitions of the Level 1 text approved by the motion 31.

3.2.999. rational. Any member of the set Q of rational numbers.

2) Add phrase to 5.7 (Recommended operations(informative)).

- The recommended constructor rat2bareinterval(r) is defined for a rational value r.
 Its value is the singleton interval [r,r] = { r } .

3) Add new constructor rat2interval(x) to the list in the last paragraph of the constructor text.

The decorated interval constructors nums2interval(l,u), rat2interval(r), text2interval(t), empty(), entire() are defined as follows....

------------------

Rationale.

The motion 33 defines P1788 number format and its properties.

Definition from the motion 33 accepts many primitive and library-defined types that contains
required special values (-oo, +oo, NaN):
float       C/Java primitive type
double      C/Java primitive type
long double C primitive type
mpfr_t      MPFR library

However, the motion 33 still rejects many known arithmetic types:
int        C/Java primitive type
long       C/Java primitive type
long long  C primitive type
mpz_t      GMP library
mpq_t      GMP library
mpf_t      GMP library
BigInteger JDK class
BigDecimal JDK class
Fraction   Apache Commons Math library
The values of these arithmetic types are rational numbers,
and these types don't contain special values: -oo, +oo, NaN .

P1788 defines at Level 1 a "virtual" interval constructor nums2bareinterval(u,v) with arguments that are extended-reals,
and it mentions a Level 2 constructor nums2interval(u,v).
I assume that section 5.5.2 "Generic functions" applies to "nums2interval(u,v)" constructor and
the phrase "Whether generic function syntax can be used in program code is language-defined."
allows that "nums2interval(u,v)" is a pattern to a lot of language constructors with arguments
either of P1788 number format or of an rational arithmetic type.

P1788 number format:

Interval(float u, float v);
Interval(double u, double v);
Interval(mpfr_t u, mpfr_t v);

Rational arithmetic types:

Interval(int u, int v);
Interval(mpq_t u, mpq_t v);
Interval(BigDecimal u, BigDecimal t);

The motion 30 rejected num2bareinterval(x) constructor where x is an extended-real number,
because it is error-prone. User can forget that x is a rounded value.

Nevertheless, there are cases when x is not rounded value, but it is exact rational value.
User may need to write an expression with precomputed rational number like
(1/n!)*x^n .

User could compute interval extension of 1/n! using mul/div interval operations.
Unfortunately, this accumulates rounding errors for large n.

Underlying system may have arithmetic types that implement integers or rationals that
can't be represented by default number format (like double):
long long int, mpz_t, BigInteger, mpq_t . 
User could compute exact rational number 1/n! using above arithmetic types,
then convert it to text, then use text2interval constructor.
Unfortunately, text2interval doesn't define details of text representation, so this may be not portable.

So it is desirable to have Level 1 operation rat2bareinterval(x) that convert rational numbers to intervals.

The corresponding Level 2 constructor will return the hull of Level 1 singleton interval.
The hull may become non-sigleton for some inputs, but it will not suffer from double-rounding.

The languge binding must not contain constructors like

Interval(float x);
Interval(double x);
Interval(mpfr_t x);

but it may contain constructors like

Interval(int x);
Interval(mpq_t x);
Interval(BigInteger x);
Interval(BigDecimal x);

---------------------