Powered by AppSignal & Oban Pro

Funx.Math

livebooks/math/math.livemd

Funx.Math

Mix.install([
  {:funx, "0.8.8"}
])

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.

sum/2

Sums two numbers using the Sum monoid.

Examples

Funx.Math.sum(1, 2)

sum/1

Sums a list of numbers using the Sum monoid.

Examples

Funx.Math.sum([1, 2, 3])
Funx.Math.sum([])

product/2

Multiplies two numbers using the Product monoid.

Examples

Funx.Math.product(3, 4)

product/1

Multiplies a list of numbers using the Product monoid.

Examples

Funx.Math.product([2, 3, 4])
Funx.Math.product([])

max/2

Returns the maximum of two numbers using the Max monoid.

Examples

Funx.Math.max(3, 7)
Funx.Math.max(-1, -5)

max/1

Finds the maximum value in a list using the Max monoid.

Returns Float.min_finite() if the list is empty.

Examples

Funx.Math.max([3, 7, 2])
Funx.Math.max([])

min/2

Returns the minimum of two numbers using the Min monoid.

Examples

Funx.Math.min(3, 7)
Funx.Math.min(-1, -5)

min/1

Finds the minimum value in a list using the Min monoid.

Returns Float.max_finite() if the list is empty.

Examples

Funx.Math.min([3, 7, 2])
Funx.Math.min([])

mean/1

Computes the arithmetic mean of a list of numbers.

Returns Nothing if the list is empty.

Examples

Funx.Math.mean([1, 2, 3, 4])
Funx.Math.mean([])

range/1

Computes the range (difference between max and min) of a list.

Returns nothing() if the list is empty.

Examples

Funx.Math.range([3, 7, 2])
Funx.Math.range([])

square/1

Computes the square of a number.

Examples

Funx.Math.square(3)
Funx.Math.square(-4)

sum_of_squares/1

Computes the sum of squares of a list of numbers.

Returns 0 if the list is empty.

Examples

Funx.Math.sum_of_squares([1, 2, 3])
Funx.Math.sum_of_squares([-2, 5])
Funx.Math.sum_of_squares([])

deviation/1

Computes the deviations from the mean for a list of numbers.

Returns Nothing if the list is empty.

Examples

Funx.Math.deviation([1, 2, 3, 4])
Funx.Math.deviation([5, 5, 5])
Funx.Math.deviation([])

variance/1

Computes the variance of a list of numbers.

Returns Nothing if the list is empty.

Examples

Funx.Math.variance([1, 2, 3, 4])
Funx.Math.variance([5, 5, 5])
Funx.Math.variance([])

std_dev/1

Computes the standard deviation of a list of numbers.

Returns Nothing if the list is empty.

Examples

Funx.Math.std_dev([1, 2, 3, 4])
Funx.Math.std_dev([5, 5, 5])
Funx.Math.std_dev([])