The traditional float/double types compute approximate results (due to possible
The traditional float/double types compute approximate results (due to possible
rounding), but they can give no information at all about how far we get from
rounding), but they can give no information at all about how far we get from
the "true" mathematical result. The idea behind *interval computation* technique of *reliable computing* is to represent numbers with an interval that is guaranteed to hold the true
the "true" mathematical result. The idea behind the *interval computation* technique of *reliable computing* is to represent numbers with an interval that is guaranteed to hold the true result, thus keeping track of the possible error margin.
result, thus keeping track of the possible error margin.
Our Interval wrapper is a toy realization of this technique. Internally, we emit
Our Interval wrapper is a toy realization of this technique. Internally, we emit
a warning whenever the relative error of a number goes beyond a certain threshold
a warning whenever the relative error of a number goes beyond a certain threshold
(that can be adjusted via an option).
(that can be adjusted via an option).
This wrapper is activated with the option `-Ri`. Two additional magic methods are defined for this model:
This wrapper is activated with the option `-Ri`. Two additional magic methods are defined for this model:
```
```java
public static double COJAC_MAGIC_relativeError(double n);
public static double COJAC_MAGIC_relativeError(double n);
public static double COJAC_MAGIC_width(double n); // interval width max-min
public static double COJAC_MAGIC_width(double n); // interval width max-min
```
```
For now we are yet far from a the quality of a good "interval computation" library. For
For now, we are yet far from a the quality of a good "interval computation" library. For
instance, we systematically round up/down instead of adjusing the
instance, we systematically round up/down instead of adjusting the
rounding mode. Nevertheless, the strength and simplicity of the automatic wrapping
rounding mode. Nevertheless, the strength and simplicity of the automatic wrapping
should not be underestimated.
should not be underestimated.
...
@@ -380,7 +380,7 @@ Interval computation is known to offer strong guarantees, but also to be overly
...
@@ -380,7 +380,7 @@ Interval computation is known to offer strong guarantees, but also to be overly
pessimistic in the estimation of the relative error (the interval is often far
pessimistic in the estimation of the relative error (the interval is often far
wider than needed). "Discrete stochastic arithmetic" is an interesting
wider than needed). "Discrete stochastic arithmetic" is an interesting
alternative: roughly, the idea is to keep 3 versions of every arithmetic
alternative: roughly, the idea is to keep 3 versions of every arithmetic
result, each corresponding to the application of a rounding mode choosen randomly.
result, each corresponding to the application of a rounding mode chosen randomly.
An unstable computation has a high probability of producing 3 manifestly divergent
An unstable computation has a high probability of producing 3 manifestly divergent
results, and the relative error can be estimated.
results, and the relative error can be estimated.
...
@@ -390,7 +390,8 @@ real breakthrough lies in the ease of our tool, which helps experimenting
...
@@ -390,7 +390,8 @@ real breakthrough lies in the ease of our tool, which helps experimenting
with the model.
with the model.
This wrapper is activated with the option `-Rs`.
This wrapper is activated with the option `-Rs`.
That wrapper offers the same magic methods as our interval computation model.
That wrapper offers the same magic methods as our interval computation model,
and is similar in its way of signaling high relative errors.
## 3.5 Number model "Automatic differentiation"
## 3.5 Number model "Automatic differentiation"
...
@@ -401,14 +402,14 @@ situation dramatically changes thanks to COJAC.
...
@@ -401,14 +402,14 @@ situation dramatically changes thanks to COJAC.
This wrapper is activated with the option `-Ra`.
This wrapper is activated with the option `-Ra`.
Here are the magic methods that are provided:
Here are the magic methods that are provided:
```
```java
public static double COJAC_MAGIC_getDerivation(double a);
public static double COJAC_MAGIC_getDerivation(double a);
public static double COJAC_MAGIC_asDerivationTarget(double a);
public static double COJAC_MAGIC_asDerivationTarget(double a);
```
```
Let's show them in action with a small example.
Let's show them in action with a small example.
```
```java
public class DerivationDemo {
public class DerivationDemo {
public static double COJAC_MAGIC_getDerivation(double a) { return 0; }
public static double COJAC_MAGIC_getDerivation(double a) { return 0; }
public static double COJAC_MAGIC_asDerivationTarget(double a) { return a; }
public static double COJAC_MAGIC_asDerivationTarget(double a) { return a; }
...
@@ -536,10 +537,23 @@ The sniffer part of COJAC is rather stable. Here are some limitations:
...
@@ -536,10 +537,23 @@ The sniffer part of COJAC is rather stable. Here are some limitations:
The wrapper part of COJAC should be considered an experimental prototype. Here
The wrapper part of COJAC should be considered an experimental prototype. Here
are some limitations:
are some limitations:
* The frontier between "user code" and "java library" has some serious defects, eg
when arrays of numbers are involved.
* We don't handle the "callbacks" from java library to the user code when floating
point numbers passed around.
* We don't handle `invokedynamic`, so for the moment there are problems with
java8 lambdas.
* The use of Java reflection will break the logic of COJAC.
* The decision of converting both the primitive types float/double and their
original wrapper Float/Double brings several problems, eg signature conflicts, or
comparison (compareTo/equals) misbehavior.
* The implementation of the models is really naive. For instance, we do not compute
* The implementation of the models is really naive. For instance, we do not compute
the Math.* operations with the required precision with BigDecimals.
every Math.* operations with the required precision with BigDecimals.