View Source Funx.Math (funx v0.1.7)
Provides mathematical operations using Monoids.
This module uses the Sum and Product monoids to perform operations
such as addition and multiplication over values or lists of values.
Summary
Functions
Computes the deviations from the mean for a list of numbers.
Finds the maximum value in a list using the Max monoid.
Returns the maximum of two numbers using the Max monoid.
Computes the arithmetic mean of a list of numbers.
Finds the minimum value in a list using the Min monoid.
Returns the minimum of two numbers using the Min monoid.
Multiplies a list of numbers using the Product monoid.
Multiplies two numbers using the Product monoid.
Computes the range (difference between max and min) of a list.
Computes the square of a number.
Computes the standard deviation of a list of numbers.
Sums a list of numbers using the Sum monoid.
Sums two numbers using the Sum monoid.
Computes the sum of squares of a list of numbers.
Computes the variance of a list of numbers.
Functions
@spec deviation([number()]) :: Funx.Monad.Maybe.t([number()])
Computes the deviations from the mean for a list of numbers.
Returns Nothing if the list is empty.
Examples
iex> Funx.Math.deviation([1, 2, 3, 4])
Funx.Monad.Maybe.pure([-1.5, -0.5, 0.5, 1.5])
iex> Funx.Math.deviation([5, 5, 5])
Funx.Monad.Maybe.pure([0.0, 0.0, 0.0])
iex> Funx.Math.deviation([])
Funx.Monad.Maybe.nothing()
Finds the maximum value in a list using the Max monoid.
Returns Float.min_finite() if the list is empty.
Examples
iex> Funx.Math.max([3, 7, 2])
7
iex> Funx.Math.max([])
Float.min_finite()
Returns the maximum of two numbers using the Max monoid.
Examples
iex> Funx.Math.max(3, 7)
7
iex> Funx.Math.max(-1, -5)
-1
@spec mean([number()]) :: Funx.Monad.Maybe.t(number())
Computes the arithmetic mean of a list of numbers.
Returns Nothing if the list is empty.
Examples
iex> Funx.Math.mean([1, 2, 3, 4])
Funx.Monad.Maybe.pure(2.5)
iex> Funx.Math.mean([])
Funx.Monad.Maybe.nothing()
Finds the minimum value in a list using the Min monoid.
Returns Float.max_finite() if the list is empty.
Examples
iex> Funx.Math.min([3, 7, 2])
2
iex> Funx.Math.min([])
Float.max_finite()
Returns the minimum of two numbers using the Min monoid.
Examples
iex> Funx.Math.min(3, 7)
3
iex> Funx.Math.min(-1, -5)
-5
Multiplies a list of numbers using the Product monoid.
Examples
iex> Funx.Math.product([2, 3, 4])
24
iex> Funx.Math.product([])
1
Multiplies two numbers using the Product monoid.
Examples
iex> Funx.Math.product(3, 4)
12
@spec range([number()]) :: Funx.Monad.Maybe.t(number())
Computes the range (difference between max and min) of a list.
Returns nothing() if the list is empty.
Examples
iex> Funx.Math.range([3, 7, 2])
Funx.Monad.Maybe.pure(5)
iex> Funx.Math.range([])
Funx.Monad.Maybe.nothing()
Computes the square of a number.
Examples
iex> Funx.Math.square(3)
9
iex> Funx.Math.square(-4)
16
@spec std_dev([number()]) :: Funx.Monad.Maybe.t(number())
Computes the standard deviation of a list of numbers.
Returns Nothing if the list is empty.
Examples
iex> Funx.Math.std_dev([1, 2, 3, 4])
Funx.Monad.Maybe.pure(1.118033988749895)
iex> Funx.Math.std_dev([5, 5, 5])
Funx.Monad.Maybe.pure(0.0)
iex> Funx.Math.std_dev([])
Funx.Monad.Maybe.nothing()
Sums a list of numbers using the Sum monoid.
Examples
iex> Funx.Math.sum([1, 2, 3])
6
iex> Funx.Math.sum([])
0
Sums two numbers using the Sum monoid.
Examples
iex> Funx.Math.sum(1, 2)
3
Computes the sum of squares of a list of numbers.
Returns 0 if the list is empty.
Examples
iex> Funx.Math.sum_of_squares([1, 2, 3])
14
iex> Funx.Math.sum_of_squares([-2, 5])
29
iex> Funx.Math.sum_of_squares([])
0
@spec variance([number()]) :: Funx.Monad.Maybe.t(number())
Computes the variance of a list of numbers.
Returns Nothing if the list is empty.
Examples
iex> Funx.Math.variance([1, 2, 3, 4])
Funx.Monad.Maybe.pure(1.25)
iex> Funx.Math.variance([5, 5, 5])
Funx.Monad.Maybe.pure(0.0)
iex> Funx.Math.variance([])
Funx.Monad.Maybe.nothing()