[SystemSafety] Accuracy of COVID modeling code
David MENTRÉ
David.MENTRE at bentobako.org
Sat May 9 16:08:07 CEST 2020
Hello,
Le 09/05/2020 à 09:48, Peter Bernard Ladkin a écrit :
> On 2020-05-08 21:01 , David MENTRÉ wrote:
>> Hello,
>>
>> Regarding floating-point computation, for once I'll agree with Derek:
>> accuracy of floating point computations does not depend on the
>> programming language but the correct use of the FPU.
> And exactly what is it that would be making "correct use of the FPU" or not? Surely the
> paraphernalia of whatever HLL you are using.
>
> There you are, programming in Excel. It is well known that Excel computations are not necessarily
> reliable. Saying it is to do with "the (in)correct use of the FPU" does not strike me as a helpful
> way of expressing what is going on, which is that it is the Excel system itself which is engaging in
> inaccurate computation, no matter whether the FPU conforms to IEEE 754 or not.
>
> Consider an example from Goldberg's survey which you reference, when a programmer writes "z := x^2 -
> y^2" , exactly what is it that "correctly uses the FPU" to ensure that z gets an appropriate and
> accurate value?
By carefully designing the algorithm and organizing code doing
computations do avoid rounding and other numerical computation errors.
Of course, most people doing numerical computations won't do that. :-)
Just to please Derek ;-) , some formal method tools are designed to help
such kind of analysis like Fluctuat (used on Airbus manually written C
numerical computations libraries if I am correct):
http://www.lix.polytechnique.fr/Labo/Sylvie.Putot/fluctuat.html
> The answer is the programming system you are using. For example, does your compiler calculate x^2
> and y^2 and perform a subtraction, or does it calculate x+y and x-y and perform a multiplication? As
> Goldberg notes, there are differences. It is not the FPU which chooses how this calculation is to be
> performed, except in the limited cases handled in IEEE 754, but the HLL paraphernalia.
From the programming language point of view, I don't think there is much
difference between languages. As illustration (and not proof) here is
above x²-y² expression computed in C++ (with GCC and msvc), Rust:
https://godbolt.org/z/8XZhxp
...and Ada:
https://godbolt.org/z/AwQdFS
The resulting assembly is exactly the same, following code order (you
can see that for example by swapping into y²-x²).
Considering the complexity of floating-point computations (rounding,
non-commutativity, ...), I don't think most compiler would mess with
source code order (of course, they might introduce optimizations on
loops like hoisting that could impact numerical computations).
That's said, if you are doing more complex computations (e.g. linear
algebra, ...), then you will probably use pre-made libraries (as you
said, the "programming system") that might implement more precise
algorithms than others. I don't have knowledge on the preciseness of
computations done in NAG, Matlab, R, LAPACK, ... to comment further. But
my feeling is that you don't have much information because precision of
numerical computations depends to much on range of inputs, order of
computations, number of iterations, ... For example there is no
paragraph on numerical precision in Matlab matrix multiplication
documentation: https://www.mathworks.com/help/matlab/ref/mtimes.html
Excel might not be reliable because Excel decides the order of
computations (according to cell dependencies), not the user. But in any
other systems, if the user decides the order of computations, (s)he can
directly manage computations done on the FPU and thus manage precision.
I'm not saying this is easy. ;-)
To go closer to this list topic on safety: does anybody knows
programming language, programming system or project specific tool that
were designed specifically for the precision of numerical computations?I
know some domains (railway, older automotive code, ...) are using
exclusively fixed point computations mapped on integers to master
precision, while others (aeronautics, newer automotive code, ...) use
extensively floating point for numerical computations. I am interested
in process, methodology and tool used to master accuracy in industrial
projects.
Best regards,
david
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.techfak.uni-bielefeld.de/pipermail/systemsafety/attachments/20200509/afc3048d/attachment.html>
More information about the systemsafety
mailing list