Implementing an interval computation library for OCaml on x86/AMD64 architectures J-M. Alliot J-B. Gotteland C. Vanaret N. Durand D. Gianazza OCaml Users and Developers Workshop 2012 International Conference in Functional Programming September 14, 2012 Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 1 / 23
23
Embed
Implementing an interval computation library for OCaml · PDF fileImplementing an interval computation library ... Implementing an interval library for OCaml OUD ... Implementing an
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Implementing an interval computation libraryfor OCaml on x86/AMD64 architectures
J-M. Alliot J-B. Gotteland C. Vanaret N. Durand D. Gianazza
OCaml Users and Developers Workshop 2012International Conference in Functional Programming
September 14, 2012
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 1 / 23
1 IntroductionObjectivesInterval arithmeticWhy a new interval library?
2 A functional implementation for OCamlUnexpected problemsModulesImplementation principles
3 Performance comparison
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 2 / 23
Introduction
1 IntroductionObjectivesInterval arithmeticWhy a new interval library?
2 A functional implementation for OCamlUnexpected problemsModulesImplementation principles
3 Performance comparison
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 3 / 23
Introduction Objectives
Objectives
Bound global solutions of difficult continuous optimization problems
I f(x) = sin(x), x ∈ [1, 2]: F ([1, 2]) = [sin(1), 1]
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 7 / 23
Introduction Interval arithmetic
Interval Branch and Bound Algorithms
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 8 / 23
Introduction Why a new interval library?
Why a new interval library?
Existing interval libraries
I C++ libraries: PROFIL/BIAS, Interval in Boost C++, Gaol
I Sun interval library: Fortran 95 or C++ [Mic01]
I MPFI: C or C++ [RR02]
I ...
Motivations for a new library
I Preference for OCaml functional programming
I Need for speed and efficiency
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 9 / 23
A functional implementation for OCaml
1 IntroductionObjectivesInterval arithmeticWhy a new interval library?
2 A functional implementation for OCamlUnexpected problemsModulesImplementation principles
3 Performance comparison
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 10 / 23
A functional implementation for OCaml Unexpected problems
Unexpected problems
C (and OCaml) math functions
I do not return the same results on 32- and 64-bit architectures
I may yield wrong results in low and high rounding modes
Necessity to write low-level functions in assembly language(restricted to x86/Amd64 architectures)
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 11 / 23
A functional implementation for OCaml Modules
A functional implementation for OCaml
Modules
I Chcw: elementary float functions
I in all rounding modes (nearest, low, high)I written in C and assembly language
I Fpu: OCaml binding to Chcw
I Interval: OCaml interval arithmetic
I Fpu rename: redefinition of OCaml float functions
I Except float operators: (+.) (-.) (*.) (/.)
I Fpu rename all: redefinition of all OCaml float functionsI Including float operators
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 12 / 23
A functional implementation for OCaml Modules
Module Fpu
val ffloat: int -> floatval ffloat high: int -> floatval ffloat low: int -> float(** Float functions. The float function is exact on 32-bit machinesbut not on 64-bit machines with ints larger than 53 bits *)
val fadd: float -> float -> floatval fadd low: float -> float -> floatval fadd high: float -> float -> float(** Floating-point addition in nearest, low and high modes *)
val fsub: float -> float -> floatval fsub low: float -> float -> floatval fsub high: float -> float -> float(** Floating-point substraction in nearest, low and high modes *)
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 13 / 23
val sqrt I: interval -> intervalval pow I i: interval -> int -> interval
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 15 / 23
A functional implementation for OCaml Implementation principles
Implementation principles
Rules
I No “empty” interval (raise an exception instead)
I Interval bounds may be infinite
I Interval bounds are not supposed to be nanLower bound is not supposed to be infinityUpper bound is not supposed to be neg infinity
I nan, infinity and neg infinity operands are not handled
Examples
I 1/[0, 0] fails
I 1/[0, 1] returns [1,+∞]
I 1/[−1, 1] returns [−∞,+∞]
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 16 / 23
A functional implementation for OCaml Implementation principles
Module Interval
(...)
let inv I {low = a; high = b} =let sa = compare a 0. and sb = compare b 0. inif sa = 0 then
if sb = 0 then failwith ”inv I”else {low = fdiv low 1. b; high = infinity}
else if 0 < sa || sb < 0 then {low = fdiv low 1. b; high = fdiv high 1. a}else if sb = 0 then {low = neg infinity; high = fdiv high 1. a}else {low = neg infinity; high = infinity}(...)
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 17 / 23
Performance comparison
1 IntroductionObjectivesInterval arithmeticWhy a new interval library?
2 A functional implementation for OCamlUnexpected problemsModulesImplementation principles
3 Performance comparison
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 18 / 23
Performance comparison
Performance comparison
Comparison with an OCaml binding to MPFI(runtime for 106 operations)
+ - x /0
0,05
0,1
0,15
0,2
0,25
0,3
MPFINative
Interval operation
Run
time
(se
cond
s)
log exp cos sin0
0,5
1
1,5
2
2,5
3
3,5
4
4,5
5
MPFINative
Interval operation
Run
time
(se
cond
s)
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 19 / 23
Performance comparison
Conclusion
Native implementation
I low-level redefinition of elementary functions
I reliable, fast despite the functional paradigm
I available under GNU Lesser General Public License
Successfully used in our hybrid optimization algorithm
I computation of optima of Michalewicz function (improvement fordeterministic methods)
I applications to aeronautical problems (air traffic conflict resolution)
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 20 / 23
References
References I
J.-M. Alliot, N. Durand, D. Gianazza, and J.-B. Gotteland, Finding andproving the optimum: Cooperative stochastic and deterministic search, 20thEuropean Conference on Artificial Intelligence (ECAI 2012), August 27-31,2012, Montpellier, France, 2012.
SUN Microsystems, C++ interval arithmetic programming manual, SUN,Palo Alto, California, 2001.
R. E. Moore, Interval analysis, Prentice-Hall, 1966.
Nathalie Revol and Fabrice Rouillier, Motivations for an arbitrary precisioninterval arithmetic and the MPFI library, Rapport de recherche, INRIA, 2002.
Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 21 / 23