Longfloat library

Notes on precision tracking / interval arithmetic

V.4.86

2006-01-25

An interval is represented as a list with min. value, max. value, with end values inclusive.
E.g. { 314E-2, 315E-2 }.

An integer is regarded as an exact number, and only converted if necessary.
In manual conversion mode longreals and intervals are not permitted to be mixed, any longreals must explicitly be converted to intervals.
In automatic conversion mode, flag 42 set, any longreals are automatic converted to intervals.

Only real functions are implemented (no complex).
Following functions included: +, -, *, /, Y^X, XROOT, =, <, >, <=, >=, <>.
Neg, Inv, Abs, SQ, INV, SQRT, SIN, COS, TAN, ASIN, ACOS, ATAN, SINH, COSH, TANH.
Additional (range-) checks have been added. E.g.

  • If you divide by an interval which includes 0, you will get an error.
  • Or if the input interval is too big to get any reliable output, e.g. for SIN {a, b}, with b-a >1 radians (or 60 degrees) you will a "Precision too low" error.
  • If there is pole or sign reversal within the interval you get an error.

The program uses flag -37 and -38 to mark when results are to be rounded down or up.
This may also be set by user, but will be overwritten if any function on intervals are carried out, and should be reset after use.

Flags

value

value

Action

-37, -38

0

0

Round

-37, -38

1

0

floor (always round results down)

-37, -38

0

1

ceiling (always round results up )

-37, -38

1

1

truncate (always discard smaller part)

42

0

use longfloats for automatic evaluating and conversion of integers

42

1

use interval longfloats for automatic evaluation and conversion

There are a few auxiliary functions:

F<>

Convert real or longfloat or a list of real {min, max} to longfloat precision interval according to rules below. Integers are assumed exact and hence not converted.

<>

Convert a real or longfloat and given precision to longfloat precision interval,
e.g. 2.5 0.1 { 2400000E-6, 2500000E-6 } (DIGITS=7)

<>

Convert a real longfloat precision interval, to average and ± precision
e.g. { 2400000E-6, 2500000E-6 } 2.5 0.1 (DIGITS=7)

FNUM

Automatic evaluation with precision tracking, set userflag 42, otherwise you have normal evaluation, with possible type errors.

FSymb

Convert (quote) a longfloat or a longfloat interval  number to symbolic. Lets you directly include longfloat constants in symbolic or algebraic equations, which may then be evaluated by ->FNUM

Rules for converting:

  • Reals are converted to longfloat interval, by adding ±1 to the 12th mantissa digit, prior to converting to longfloats with DIGITS precision.
    2.3E0 2.29999999999 , 2.30000000001 { 2300000E-6, 2300000 }

Integers are assumed correct. However, if necessary, integers are converted to longreal, intervals. If integers are too large to be represented with current DIGITS precision, they are rounded up or down at lower or upper end of interval:

1234    { 1234E0 1234E0}    ,(DIGITS=4)

12345 {1234E0, 1235E0}    , (DIGITS=4)

  • In cases with =, <, >, <=, >=, <> you will get a warning when the integers are too large.
  • When during automatic evaluation, Longfloats are converted to longfloat interval by adding +/-1 to last digit in mantissa as provided, regardless of current DIGITS precision.

·  ie the number 1234E-2 and the current DIGITS variable is 7 then

1234E-2 -> {1233000E-5, 1235000-5E}

Function evaluation:

Generally a function is evaluated as follows:

  1. Test are carried out to check if the interval can give a reasonable result interval, and that the boundaries are appropriate.
  2. Integers are converted if necessary for evaluation (and sometimes speed).
  3. The longfloat interval is split into a longreal at lower end a longreal at upper end.
  4. The function is evaluated at the boundaries.
  5. Tests are carried out to check that we don’t have any poles or discontinuities in the interval.
  6. The longreal is rounded down at lower end and rounded up at upper end when the longfloats are normalized (converted to DIGITS precision).
  7. Lower and upper boundaries are put in a list.

Implementation details: 

Basic addition and subtraction of longfloats are carried out with one guard digit and then the result is normalized.

Basic multiplication is carried out by full multiplication of mantissas, then the results is normalized.

Basic division a/b is carried out by doubling the mantissa length of a +1 digit (by adding zeros), then integer division. The remainder is discarded and the mantissa is normalized.

FSIN, FCOS and FTAN obeys flag for DEG, RAD, GRAD

Integers are always converted to intervals. However, as integers are regarded as exact, when in DEG mode or GRAD mode the input is reduced modulo 360 (400) prior to conversion.

Evaluation are carried in fixed precision with 5 guard digits, not floating point and results are rounded.

For sin and cos 1 digit is subtracted or added to the mantissa, except for the cases when the result -1 or 1 (the functions are stationary when the result is -1 or 1, thus we have safe boundaries.

When one of the boundaries are close to 0 (difference less than 1 in last fixed precision, the boundary is replaced by conservative -1*10^-DIGITS or 1*10^-DIGITS

For tan we have similar problems when we are close to /2 + n*.The signs are not accurate when |tan(x)| > 10^DIGITS, and therefore simply reported as "NaN, undefined result", however, you may also get infinite result error

General conversion rules

Manual ( RPN mode)

 

Flag 42 CF

Flag 42 SF

Integer

Integer

Integer

Integer

Longreal*

Interval*

Real

-

-

Longreal

Longreal

-

Interval

-

Interval


Automatic evaluation '4*SIN(2*x/)'

 

Flag 42 CF

Flag 42 SF

Integer

Integer

Integer

Integer

Longreal*

Interval*

Real

Longreal

Interval

Longreal

Longreal

Interval

Interval

-

Interval

*) only when necessary

  • Flag 42 governs automatic integer conversion both for automatic evaluation and manual mode.
  • Automatic and manual mode should be equivalent with one exception: manual mode will (shall) never convert longfloat to interval or vice versa.
  • Now legal to mix integer and longfloat or integer and interval.
  • If a function uses an integer, the integer is regarded exact, and only converted when necessary exceptions are FDIV , FSQRT, XROOT, always converted due to speed

Functions where integer conversion never occurs when you have only integers:

FADD, FSUB, FMULT, FNEG, FABS, FY^X, FSQ

Functions where integers are always converted

FDIV, FSQRT, FINV

FEXP, FLN, FASIN, FACOS, FATAN, FSINH, FCOSH, FTANH

FSIN, FCOS, FTAN (see details)

XROOT (Only implemented for integer exponent, and always converted).

  • when library is invoked from rightshift libmenu, rounding modes ( : round, < down, > up, X truncate, or interval mode ( []) and precision shown in header

2006-01-25 Gjermund Skailand