## mpfi

### Description

The `mpfi` egg contains bindings for the mpfi library for interval arithmetic (a short introduction to interval arithmetic can be found at the mpfi site).

### Author

Jeronimo Pellegrini

### Requirements

You need the 'development' libraries below in order to install the `mpfi` egg.

- the mpfi library (
`mpfi-dev`) - the mpfr library, needed by mpfi (
`mpfr-dev`)

### Example

(use mpfi) (let ((a (make-ia-interval-f64 1 10)) (b (make-ia-interval-f64 -0.5 1))) (when (ia-has-zero? b) (display "b contains zero!") (newline)) (display "a = ") (display (ia->string a)) (newline) (display "b = ") (display (ia->string b)) (newline) (display "a x b = ") (display (ia->string (ia* a b))) (newline)) ==> b contains zero! a = [1.0__10.0] b = [-0.5__1.0] a x b = [-5.0__10.0]

### Documentation

In the description below, `A` and `B` are mpfi intervals; `F` is a floating-point number (`double` in FFI); `U` is an unsigned integer number (`unsigned-long` in FFI); `S` is a signed integer number (`long` in FFI).

`(make-ia-interval-empty)`procedure`(make-ia-interval-f64 LO HI)`procedureThe following procedures are available:

Arithmetic:

(ia+ A B) (ia+f64 A F) (ia+u64 A U) (ia+s64 A S) (ia- A B) (ia-f64 A F) (f64-ia F A) (ia-u64 A U) (u64-ia U A) (ia-s64 A S) (s64-ia S A) (ia* A B) (ia*f64 A F) (ia*u64 A U) (ia*s64 A S) (ia/ A B) (ia/f64 A F) (f64/ia F A) (ia/u64 A U) (u64/ia U A) (ia/s64 A S) (s64/ia S A)

The procedures ending with

`+`,`-`,`*`and`/`operate on two intervals and give an interval as result. The procedures that have`f64`in their name take one flonum argument.Unary functions:

(ia-neg A) (ia-sqr A) ;; square, (* x x) (ia-inv A) ;; inverse, (/ 1 x) (ia-sqrt A) ;; square root (ia-abs A) (ia-log A) (ia-exp A) (ia-exp2 A) (ia-log1p A) (ia-expm1 A) (ia-log2 A) (ia-log10 A)

Trigonometric functions:

(ia-cos A) (ia-sin A) (ia-tan A) (ia-acos A) (ia-asin A) (ia-atan A) (ia-cosh A) (ia-sinh A) (ia-tanh A) (ia-acosh A) (ia-asinh A) (ia-atanh A)

Constants:

(ia-const-log2) (ia-const-pi) (ia-const-e)

These procedures calculate e, pi and the logarithm of two and give back intervals representing them.

Comparisons:

(ia< A B) (ia> A B)

Given two intervals A and B, A is considered greater than B is and only if all elements of A are greater than all elements of B.

(ia-overlap? A B)

Returns true if A overlap with or contains B.

(ia-nan? A) (ia-inf? A) (ia-zero? A) (ia-has-zero? A) (ia-positive? A) (ia-negative? A) (ia-strictly-positive? A) (ia-strictly-negative? A) (ia-nonpositive? A) (ia-nonnegative? A) (ia-bounded? A) (ia-empty? A) (ia-inside? A B) (ia-f64-inside? A B)

Procedures returning

`flonum`:(ia-diameter A) (ia-diameter-absolute A) (ia-diameter-relative A) (ia-magnitude A) (ia-mignitude A) (ia-random A) (ia-middle A)

Other procedures:

`(ia->string)`procedureConverts an interval into a string.

Each nondestructive procedure described above (like

`ia/`for example) has a destructive counterpart in which there is one extra argument where the result goes:(ia/ a b) (ia/! result a b)

The destructive operation does not allocate memory; the nondestructive one does.

### Bugs and limitations

- the mpfi egg is still not tested enough
- There is only support for floating point intervals. Although there are procedures to set interval endpoints to flonums, fixnums, exact integers, and so on, this egg will only return the endpoints as flonums. The mpfi library itself won't return an integer.

### Changelog

- 0.2 Added functions to add, multiply, subtract and divide intervals and constants. Also fixed some bugs.
- 0.1 Initial Release

### License

Copyright (c) 2010, Jeronimo C. Pellegrini All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the author nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.