<<

Interval Computations in Julia programming language Evgeniya Vorontsova

To cite this version:

Evgeniya Vorontsova. Interval Computations in Julia programming language. Summer Workshop on Interval Methods (SWIM) 2019, ENSTA, Jul 2019, Paris, France. ￿hal-02321950￿

HAL Id: hal-02321950 https://hal.archives-ouvertes.fr/hal-02321950 Submitted on 21 Oct 2019

HAL is a multi-disciplinary open access L’archive ouverte pluridisciplinaire HAL, est archive for the deposit and dissemination of sci- destinée au dépôt et à la diffusion de documents entific research documents, whether they are pub- scientifiques de niveau recherche, publiés ou non, lished or not. The documents may come from émanant des établissements d’enseignement et de teaching and research institutions in France or recherche français ou étrangers, des laboratoires abroad, or from public or private research centers. publics ou privés. Interval Computations in Julia programming language

Evgeniya Vorontsova1, 2

1Far Eastern Federal University, Vladivostok, Russia 2Grenoble Alpes University, Grenoble, France

Keywords: Numerical Computing; Inter- INTLAB [9], a Matlab/Octave for Re- val Arithmetic; Julia Programming Language; liable Computing. The other fundamental dif- JuliaIntervals; Octave Interval Package ference between INTLAB and GNU Octave interval package is non-conformance of INT- LAB to IEEE 1788-2015 — IEEE Standard Introduction for [3]. On the other hand The general-purpose Julia programming lan- GNU Octave interval package’s main goal is guage [5] was designed for speed, efficiency, to be compliant with the Standard. Likewise, and high performance. It is a flexible, authors of IntervalArithmetic.jl wrote [4] that optionally-typed, and dynamic computing they were working towards having the pack- language for scientific, numerical and tech- age be conforming with the Standard. So, all nical computing applications. Julia is open calculations in these packages are performed source language with all sources free avail- using interval arithmetic: all quantities are able on GitHub. The language was developed treated as intervals. The final result is also and incubated at MIT [6]. Currently, after an interval contained the correct answer. Julia 1.0 was officially released to the pub- In next section we would like to show some lic in August 2018, the language is becoming practical examples with interval arithmetic in increasingly popular. Julia has been down- Julia. loaded than 8.4 million times, as of May 2019 [2], and is used at more than 1,500 uni- Examples versities. So, it is very important for researchers, Getting Started working in a field of interval analysis, to have The basic object in the IntervalArithmetic.jl fast, efficient and robust publicly available package is the parameterized type Interval. software packages for performing computa- By default, Interval objects contain Float64 tions with interval arithmetic written in Julia. s. Intervals are created using the @interval macro: IntervalArithmetic.jl using IntervalArithmetic In this paper, we review and compare a re- a = @interval(1, 2) cently developed Julia package for perform- b = @interval(3, 4) ing , i.e. rigorous com- print(a + b, a - b, a * b, a / b) putations with finite-precision floating-point The output of this code is arithmetic, IntervalArithmetic.jl [4], with per- [4, 6] [-3, -1] [3, 8] formance of GNU Octave interval package for [0.25, 0.666667] real-valued interval arithmetic [1]. This Oc- tave toolbox was chosen for comparison be- As you may have noticed, the package permits cause of several important reasons. First of to write quite clear and intuitive code for in- all, it is a free, open-source software, unlike terval computations. Matrix Multiplication matrix pairs and calculate the mean experi- mental time over all multiplications. The re- In this section we present the results of exper- sults of the first setting are summarized in iments comparing the IntervalArithmetic.jl li- Table 1. This experiment shows that perfor- brary with the GNU Octave interval package. mance of Julia interval package for that prob- In summary, we show that Julia interval li- lem is significantly better. brary is significantly faster than the Octave library. In our first experiment we measured the time to evaluate the interval matrix multipli- Elementary functions cation. The Julia code is: In our second experiment we compared the function MultMatr(A, B) times for evaluation of the elementary func- return A*B tions (exp, sin, cos, etc.) for random interval end arguments. The design of the experiment is n = 10 taken from [7]. M1 = 10*rand(n, n) M2 = 10*rand(n, n) Table 2: Time for 105 evaluations of the ele- iM1 = map(Interval, M1) mentary functions iM2 = map(Interval, M2) Function Julia, s Octave, s A = iM1 .± 5 exp 0.49 102.7 B = iM2 .± 5 sin 0.749 147.85 @benchmark MultMatr(A,B) cos 0.638 230.2 Here we use BenchmarkTools package by Jar- tan 0.49 126.13 rett Revels [8], a framework for writing and arcsin 0.858 119.01 running groups of benchmarks. arccos 1.132 169.02 And Octave code for MultMatr function is: arctan 1.318 127.01 pkg load interval function [t] = MultMatr(n) The results of the second setting are sum- A = infsupdec(rand(n), marized in Table 2. We may see that these 10*rand(n) + 1); calculations in Julia are almost two orders of B = infsupdec(rand(n), magnitude faster. 10*rand(n) + 1); tic = A*B; Plotting t = toc; end In this section, we will illustrate how to vi- sualize the interval extension of a given func- Table 1: Time for interval matrix multiplica- tion over an interval. The process of splitting tions the interval into many smaller adjacent pieces Matrix size, Julia, Octave, for range evaluations of the given function is rows ms ms called mincing. 10 0.095 13.317 Figures 1- 2 show visualization of minc- 100 111.91 849.61 ing process for one function (Julia code was 1000 125870 863340 adapted from [10]). For implementation The IntervalBox type constructed from an array For Octave we create 10 random interval of Interval was used. References

[1] O. Heimlich GNU Octave interval pack- age, version 3.2.0, 2015–2018, https:// octave.sourceforge.io/interval/. [2] Julia computing newsletter, May 2019. https://juliacomputing.com/blog/ 2019/05/03/may-newsletter.html, 2019. [3] IEEE Std 1788-2015 — IEEE - Figure 1: Function cos(x) + 0.5 sin(2x), dard for Interval Arithmetic. IEEE: In- 10 sub-intervals. stitute of Electrical and Electronic En- gineers, IEEE Computer Society, New York, June 2015, https://ieeexplore. ieee.org/document/7140721. [4] L. Benet and D. Sanders. JuliaInter- vals.jl Package — Rigorous numerics with interval arithmetic & applications. https://github.com/JuliaIntervals/ IntervalArithmetic.jl. [5] J. Bezanson, A. Edelman, S. Karpinski, and V. Shah. Julia: A fresh approach to numerical computing. SIAM Review, Figure 2: Function cos(x) + 0.5 sin(2x), 59:1, 65–98, 2017. 50 sub-intervals. [6] J. Bezanson, S. Karpinski, V. Shah, and A. Edelman. Why we created Acknowledgement julia. https://julialang.org/blog/ 2012/02/why-we-created-julia, 2012. The work was supported by the Russian Foun- dation for Basic Research, project no. 18-29- [7] W. Mascarenhas. Moore: Interval Arith- 03071 mk. metic in Modern C++, https://arxiv. org/pdf/1611.09567.pdf. Conclusion [8] J. Revels. BenchmarkTools Julia pack- age, https://github.com/JuliaCI/ Public available Julia package for interval BenchmarkTools.jl. arithmetic has been investigated. Experimen- tal comparison of Octave and Julia packages [9] S. Rump. Intlab — interval laboratory. for interval arithmetic shows that Julia Inter- In Tibor Csendes, editor, Developments valArithmetic.jl package is significantly faster in Reliable Computing, 77–104, Kluwer then Octave interval package. In addition, the Academic Publishers, Dordrecht, 1999. implementation process of interval arithmetic [10] D. Sanders. Métodos numéricos para sis- computations in this Julia package is easy and temas dinámicos, https://github.com/ convenient, due to intuitive syntax of the lan- dpsanders/dinamica_nacional. guage and the package.