Skip to content

filipevarjao/ex_interval

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ExInterval

ExInterval implements the interval type and range operations on the type, with rounded directed intervals, recognize the input as strings and performs operations between intervals.

Using intervals for the representation of real numbers, it is possible to control the error propagation of rounding or truncation, between others, in numerical computational procedures.

Installation

If available in Hex, the package can be installed by adding ex_interval to your list of dependencies in mix.exs:

def deps do
  [
    {:ex_interval, "~> 0.1.0"}
  ]
end

Documentation can be generated with ExDoc and published on HexDocs. Once published, the docs can be found at https://hexdocs.pm/ex_interval.

Dependencies

The header <fenv.h> supports the intended model of use for the floating-point environment. It was defined in C99, and describe the handling of floating-point rounding and exceptions (overflow, zero-divide, etc.).

Interval

It implements the interval type.

iex> Interval.new(1.1)
[1.1, 1.1]
iex> Interval.new(-1, "0.1")  # recognize the input as strings too
[-1.0, 0.1]

Interval operations

The operations of interval follow the interval arithmetic with maximum accuracy that captures essential properties associated with rounding.

Binary plus operator

iex> Interval.add("0.1", 0.1)
[0.2, 0.2]
iex> Interval.add([0.25, 0.5], [2.0, 2.0])
[2.25, 2.5]

Similarly, it provides minus (sub), multiplication (mul), and division (division) operators.

Helpers

eps/0, is_member?/2, middle/1, absolute/1, diameter/1

iex> eps = Interval.eps
2.220446049250313e-16
iex> Interval.is_member?(eps, [0.0, 0.1])                                  
true
iex> Interval.middle([0.0, 0.1])
0.05
iex> Interval.absolute([-1, 1])
1.0
iex> Interval.diameter([0.0, 0.1])
0.1

Rounding

The error control is done by directed rounding for the interval operations, we also can use Rounding helper functions.

iex> backup_mode = Rounding.get_mode()
0
iex> Rounding.set_mode_downward()
0
iex> 1/3                             
0.3333333333333333
iex> Rounding.set_mode_upward() 
0
iex> 1/3                             
0.33333333333333337
iex> Rounding.restore_mode(backup_mode)
0

*It does not guarantee is preemption safe.

References

[1] Moore, R. E., Interval Analysis. Prentice-Hall, Englewood Cliffs, New Jersey, 1966.

[2] Moore, R. E., Methods and Applications of Interval Analysis. SIAM Studies in Applied Mathematics, Philadelphia, 1979.

[3] Kulisch, U. W., Miranker, W. L., Computer Arithmetic in Theory and Practice. Academic Press, 1981.

About

ExInterval provides types and functions for Maximum Accuracy Interval Arithmetic for Erlang and Elixir.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published