CAPD DynSys Library
5.2.0
|
When configuring CAPD library you can choose which of interval arithmetic packages, native CAPD intervals or wrapper for FILIB, will be used as default one for double precision. To do that pass the flag –without-filib
or –with-filib
to the configure
script.
Both interval arithmetics have the same interface. If you include file capd/intervals/lib.h
then the name capd::DInterval
points always to the current intervals. This allows to write code that will work with both interval arithmetics.
The native CAPD interval arithmetics is more general and has end point type as template parameter.
The following example uses explicitly CAPD intervals but almost everything applies to the FILIB intervals as well.
Template class Interval has two parameters
The following lines define new names for intervals with the endpoint's type: double, int, MpFloat correspondigly
In the following we will use type DInterval
but in most of the cases any of the above can be used.
capd::DInterval
is already defined as interval with double endpoints.We can construct intervals by :
A constructor from string (the last one) is the safest one but it brings overestimations. Interval bounds are read from string and then last bit of their mantissa is rounded to ensure enclosure. It always produce intervals of non zero width e.g. diameter of (DInterval("1.0", "1.0"))
is 3.33067e-16.
(*) The state of the interval a depends on a flag __INTERVAL_INIT_0__
. If this flag is set in file capdAlg/include/capd/interval/intervalSettings.h
then a = [0.0, 0.0]
(this is the default behaviour), otherwise a is not initialized.
To obtain left or right end point of the interval one can use leftBound or rightBound functions. They are implemented both as member and global functions.
To get point interval that contains left or right end point use function left or right correspondigly
Intervals can be written to any C++ stream using operator <<. The output depends on parameters of a stream e.g precision.
To read intervals from given stream (e.g. keyboard, file or memory) use operator >>. The format of an input should be :
where leftEnd
and rightEnd
are in the form that can be read into endpoint type (BoundType) with operator >>.
To save and restore intervals exactly you can use binary format or text formats in binary or hexadecimal bases.
Text output in binary base
The output is [1:01111111111:0000000000000000000000000000000000000000000000000000, 0:10000000000:0000000000000000000000000000000000000000000000000000]
.
Endpoints have the following format sign:exponent:mantisa
as in IEEE 754 standard.
Text output in hexadecimal base
The output is [1:3ff:0000000000000,0:400:0000000000000]
.
Arithmetic operations for intervals are implemented in this way that their result always contains all possible results.
For example if
then
Operation | Code | Result |
---|---|---|
Sum | a + b; | [0.0, 4.0] |
Substraction | a - b; | [-3.0, 1.0] |
Product | a * b; | [-2.0, 4.0] |
Division | a / b; | [-1.0, 2.0] |
Every arithmetic operation of form
can be also shorten to
Most of the basic functions has its interval version. To be rigorous returned value is always an upper estimate of the true result. Functions are called exactly in the same way as its corresponding floating point versions.
List of all implemented functions:
Function | For an interval x it returns: |
---|---|
power(x, n) | xn, where n is an integer |
power(x, a) | xa, where a is an interval |
sqrt(x) | square root of x |
sin(x), cos(x), tan(x), cot(x) | sinus of x, etc. |
sinh(x), cosh(x), tanh(x), coth(x) | hyperbolic sinus of x, etc. |
exp(x) | exponens of x |
log(x) | natural logarithm of x |
Operator | True if |
---|---|
b==c; | both end points are the same. |
b!=c; | at least one end point differs. |
b>c; b>=c; b<c; b<=c; | it is true for any two points from intervals b and c. For example: b>c if leftBound(b) > rightBound(c) . |
The same operators can be applied if one of the intervals is replaced by a number (the number is treated as point interval) e.g. b == 1.0; b < 2.0;
b>c
and b<=c
can be false at the same time e.g. in the case when intervals b
and c
overlap.For two intervals one can check inclusions.
True if | |
---|---|
c.contains(b); c.contains(2.5); | c contains b c contains number 2.5 |
c.containsInInterior(b); | c contains b in the interior |
c.subset(b); | c is subset of b |
c.subsetInterior(b); | c is subset of the interior of b |
In this section we collect several useful functions.
bool intersection(a, b, result)
for given two intervals a and b returns: intervalHull(iv1, iv2)
returns the smallest possible interval containing iv1 and iv2 ia
and any element b of ib
we have that imin(ia,ib)
contains min(a,b)
and imax(ia,ib)
contains max(a,b)
Command | Result |
---|---|
a.split(center,remainder); | a = [1.0, 3.0] center = [2.0, 2.0] remainder = [-1.0, 1.0] |
a.split(remainder); | a = [2.0, 2.0] remainder = [-1.0, 1.0] |
split(a, center,radius); | a = [1.0, 3.0] center = [2.0, 2.0] radius = [1.0, 1.0] !!! |
split(a, center,r); | a = [1.0, 3.0] center = [2.0, 2.0] radius = 1.0 |
Two constants : pi and euler are provided by static member fuctions pi and euler. Their output is an interval that containts true value of the constant.
The following applies only to native CAPD intervals and do not influence FILIB intervals. In file "capdAlg/include/capd/interval/IntervalSetting.h" there are several flags which can be switched on/off by (un)commenting appropriate line of code:
Flag | If switched on | Default |
---|---|---|
__DEBUGGING__ | it turns on debugging mode. We check intervals during each operation and throw exception if interval is not valid. | off |
__INTERVAL_INIT_0__ | default constructor initializes intervals to be [0.0,0.0]. By default this option is switched off and an interval is not initialized. | on |
__INTERVAL_SPEED_OPTIMIZED__ | it speeds up computations but enlarges programm size. It couses many functions to be defined as inline | on |
__INTERVAL_DEPRECATED__ | it allows use of deprecated functions for backward compatibility. | off |