implementing an interval computation library for ocaml · pdf fileimplementing an interval...

Post on 18-Mar-2018

241 Views

Category:

Documents

4 Downloads

Preview:

Click to see full reader

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

minx∈D

f(x)

s.t. gi(x) ≤ 0, i ∈ {1, . . . , p}hj(x) = 0, j ∈ {1, . . . , q}

Hybridization of optimization methods [ADGG12]

I Evolutionary Algorithms (EA)

I Interval Branch & Bound algorithm (BB)computation of lower/upper bound of f over a subspace of D

Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 4 / 23

Introduction Interval arithmetic

Interval arithmetic

Numerical analysis method to bound round-off errors [Moo66]

Problem (P)I f(x, y) = 333.75y6 + x2(11x2y2 − y6 − 121y4 − 2) + 5.5y8 + x/(2y)

I f(77617, 33096) = −0.827396 (6 digits)

I OCaml 3.12 compiler: −1.180592.1021

Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 5 / 23

Introduction Interval arithmetic

Interval arithmetic

Interval arithmetic

I Extends to intervals {+, −, ∗, /}, exp, log, etc.

I An interval extension F of f yields a rigorous enclosure of f(X)

I Computation of lower/upper bound with outward rounding

[a, b]⊕ [c, d] = [a+low c, b+high d]

I a+low c must be a lower bound of a+ c

I b+high d must be an upper bound of b+ d

Problem (P)Interval arithmetic yields: [−5.902958.1021, 5.902958.1021]

Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 6 / 23

Introduction Interval arithmetic

Interval arithmetic

F interval extension

I f(x, y) = x2 + exp(y), x ∈ [−3, 2], y ∈ [0, 1]:

F ([−3, 2], [0, 1]) = [−3, 2]2 + exp([0, 1])= [0, 9] + [1, e] = [1, e+ 9]

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

A functional implementation for OCaml Modules

Module Fpu rename all

val (+.): float -> float -> floatval (-.): float -> float -> floatval (/.): float -> float -> floatval ( *.): float -> float -> float

val mod float: float -> float -> floatval sqrt: float -> floatval log: float -> floatval exp: float -> float

val ( ** ): float -> float -> float

I Opening the Fpu rename all module ensures thatthese functions return the same results on all architectures

Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 14 / 23

A functional implementation for OCaml Modules

Interface of module Interval

type interval = {low: float; (** lower bound *)high: float (** upper bound *)

}(...)

val pi I: interval(...)

val float i: int -> interval(...)

val (+$.): interval -> float -> intervalval (+$): interval -> interval -> interval

(...)

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

References

Questions

For implementation details, please contact

Jean-Marc Alliotjean-marc.alliot@irit.fr

Jean-Baptiste Gottelandgottelan@cena.fr

Charlie Vanaret (ENAC-IRIT) Implementing an interval library for OCaml OUD 2012 22 / 23

References

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 23 / 23

top related