@@ -273,7 +273,7 @@ pub fn truncate(x: Float, digits: option.Option(Int)) -> Float {
/// - \\(12.07\\) for 2 digits after the decimal point (`digits = 2`)
/// - \\(12.065\\) for 3 digits after the decimal point (`digits = 3`)
///
-/// It is also possible to specify a negative number of digits. In that case, the negative
+/// It is also possible to specify a negative number of digits. In that case, the negative
/// number refers to the digits before the decimal point.
/// - \\(10.0\\) for 1 digit before the decimal point (`digits = -1`)
/// - \\(0.0\\) for 2 digits before the decimal point (`digits = -2`)
@@ -285,7 +285,7 @@ pub fn truncate(x: Float, digits: option.Option(Int)) -> Float {
/// - \\(12.07\\) for 2 digits after the decimal point (`digits = 2`)
/// - \\(12.065\\) for 3 digits after the decimal point (`digits = 3`)
///
-/// It is also possible to specify a negative number of digits. In that case, the negative
+/// It is also possible to specify a negative number of digits. In that case, the negative
/// number refers to the digits before the decimal point.
/// - \\(10.0\\) for 1 digit before the decimal point (`digits = -1`)
/// - \\(0.0\\) for 2 digits before the decimal point (`digits = -2`)
@@ -309,7 +309,7 @@ pub fn truncate(x: Float, digits: option.Option(Int)) -> Float {
/// - \\(12.06\\) for 2 digits after the decimal point (`digits = 2`)
/// - \\(12.065\\) for 3 digits after the decimal point (`digits = 3`)
///
-/// It is also possible to specify a negative number of digits. In that case, the negative
+/// It is also possible to specify a negative number of digits. In that case, the negative
/// number refers to the digits before the decimal point.
/// - \\(10.0\\) for 1 digit before the decimal point (`digits = -1`)
/// - \\(0.0\\) for 2 digits before the decimal point (`digits = -2`)
@@ -321,7 +321,7 @@ pub fn truncate(x: Float, digits: option.Option(Int)) -> Float {
/// - \\(12.06\\) for 2 digits after the decimal point (`digits = 2`)
/// - \\(12.065\\) for 3 digits after the decimal point (`digits = 3`)
///
-/// It is also possible to specify a negative number of digits. In that case, the negative
+/// It is also possible to specify a negative number of digits. In that case, the negative
/// number refers to the digits before the decimal point.
/// - \\(10.0\\) for 1 digit before the decimal point (`digits = -1`)
/// - \\(0.0\\) for 2 digits before the decimal point (`digits = -2`)
@@ -424,9 +424,9 @@ fn do_round(p: Float, x: Float, mode: option.Option(RoundingMode)) -> Float {
}
fn round_to_nearest(p: Float, x: Float) -> Float {
- let xabs: Float = float_absolute_value(x) *. p
- let xabs_truncated: Float = truncate_float(xabs)
- let remainder: Float = xabs -. xabs_truncated
+ let xabs = float_absolute_value(x) *. p
+ let xabs_truncated = truncate_float(xabs)
+ let remainder = xabs -. xabs_truncated
case remainder {
_ if remainder >. 0.5 -> float_sign(x) *. truncate_float(xabs +. 1.0) /. p
_ if remainder == 0.5 -> {
@@ -441,8 +441,8 @@ fn round_to_nearest(p: Float, x: Float) -> Float {
}
fn round_ties_away(p: Float, x: Float) -> Float {
- let xabs: Float = float_absolute_value(x) *. p
- let remainder: Float = xabs -. truncate_float(xabs)
+ let xabs = float_absolute_value(x) *. p
+ let remainder = xabs -. truncate_float(xabs)
case remainder {
_ if remainder >=. 0.5 -> float_sign(x) *. truncate_float(xabs +. 1.0) /. p
_ -> float_sign(x) *. truncate_float(xabs) /. p
@@ -450,9 +450,9 @@ fn round_ties_away(p: Float, x: Float) -> Float {
}
fn round_ties_up(p: Float, x: Float) -> Float {
- let xabs: Float = float_absolute_value(x) *. p
- let xabs_truncated: Float = truncate_float(xabs)
- let remainder: Float = xabs -. xabs_truncated
+ let xabs = float_absolute_value(x) *. p
+ let xabs_truncated = truncate_float(xabs)
+ let remainder = xabs -. xabs_truncated
case remainder {
_ if remainder >=. 0.5 && x >=. 0.0 ->
float_sign(x) *. truncate_float(xabs +. 1.0) /. p
@@ -500,7 +500,7 @@ fn do_ceiling(a: Float) -> Float
/// The absolute value:
///
/// \\[
-/// \forall x \in \mathbb{R}, \\; |x| \in \mathbb{R}_{+}.
+/// \forall x \in \mathbb{R}, \\; |x| \in \mathbb{R}_{+}.
/// \\]
///
/// The function takes an input \\(x\\) and returns a positive float value.
@@ -529,7 +529,7 @@ pub fn float_absolute_value(x: Float) -> Float {
/// The absolute value:
///
/// \\[
-/// \forall x \in \mathbb{Z}, \\; |x| \in \mathbb{Z}_{+}.
+/// \forall x \in \mathbb{Z}, \\; |x| \in \mathbb{Z}_{+}.
/// \\]
///
/// The function takes an input \\(x\\) and returns a positive integer value.
@@ -709,7 +709,7 @@ fn do_int_sign(a: Int) -> Int
///
///
///
-/// The function takes two arguments \\(x, y \in \mathbb{R}\\) and returns \\(x\\)
+/// The function takes two arguments \\(x, y \in \mathbb{R}\\) and returns \\(x\\)
/// such that it has the same sign as \\(y\\).
///
///
@@ -735,7 +735,7 @@ pub fn float_copy_sign(x: Float, y: Float) -> Float {
///
///
///
-/// The function takes two arguments \\(x, y \in \mathbb{Z}\\) and returns \\(x\\)
+/// The function takes two arguments \\(x, y \in \mathbb{Z}\\) and returns \\(x\\)
/// such that it has the same sign as \\(y\\).
///
///
@@ -823,7 +823,7 @@ pub fn int_flip_sign(x: Int) -> Int {
///
///
///
-pub fn minimum(x: a, y: a, compare: fn(a, a) -> order.Order) -> a {
+pub fn minimum(x: a, y: a, compare: fn(a, a) -> order.Order) {
case compare(x, y) {
order.Lt -> x
order.Eq -> x
@@ -869,7 +869,7 @@ pub fn minimum(x: a, y: a, compare: fn(a, a) -> order.Order) -> a {
///
///
///
-pub fn maximum(x: a, y: a, compare: fn(a, a) -> order.Order) -> a {
+pub fn maximum(x: a, y: a, compare: fn(a, a) -> order.Order) {
case compare(x, y) {
order.Lt -> y
order.Eq -> y
@@ -909,7 +909,7 @@ pub fn maximum(x: a, y: a, compare: fn(a, a) -> order.Order) -> a {
///
///
///
-pub fn minmax(x: a, y: a, compare: fn(a, a) -> order.Order) -> #(a, a) {
+pub fn minmax(x: a, y: a, compare: fn(a, a) -> order.Order) {
#(minimum(x, y, compare), maximum(x, y, compare))
}
@@ -956,7 +956,7 @@ pub fn list_minimum(
|> Error
[x, ..rest] ->
Ok(
- list.fold(rest, x, fn(acc: a, element: a) {
+ list.fold(rest, x, fn(acc, element) {
case compare(element, acc) {
order.Lt -> element
_ -> acc
@@ -1010,7 +1010,7 @@ pub fn list_maximum(
|> Error
[x, ..rest] ->
Ok(
- list.fold(rest, x, fn(acc: a, element: a) {
+ list.fold(rest, x, fn(acc, element) {
case compare(acc, element) {
order.Lt -> element
_ -> acc
@@ -1073,13 +1073,13 @@ pub fn arg_minimum(
arr
|> list_minimum(compare)
arr
- |> list.index_map(fn(element: a, index: Int) -> Int {
+ |> list.index_map(fn(element, index) {
case compare(element, min) {
order.Eq -> index
_ -> -1
}
})
- |> list.filter(fn(index: Int) -> Bool {
+ |> list.filter(fn(index) {
case index {
-1 -> False
_ -> True
@@ -1143,13 +1143,13 @@ pub fn arg_maximum(
arr
|> list_maximum(compare)
arr
- |> list.index_map(fn(element: a, index: Int) -> Int {
+ |> list.index_map(fn(element, index) {
case compare(element, max) {
order.Eq -> index
_ -> -1
}
})
- |> list.filter(fn(index: Int) -> Bool {
+ |> list.filter(fn(index) {
case index {
-1 -> False
_ -> True
@@ -1210,9 +1210,9 @@ pub fn extrema(
|> Error
[x, ..rest] ->
Ok(
- list.fold(rest, #(x, x), fn(acc: #(a, a), element: a) {
- let first: a = pair.first(acc)
- let second: a = pair.second(acc)
+ list.fold(rest, #(x, x), fn(acc, element) {
+ let first = pair.first(acc)
+ let second = pair.second(acc)
case compare(element, first), compare(second, element) {
order.Lt, order.Lt -> #(element, element)
order.Lt, _ -> #(element, second)
diff --git a/src/gleam_community/maths/predicates.gleam b/src/gleam_community/maths/predicates.gleam
index 9cdd74c..4681e3b 100644
--- a/src/gleam_community/maths/predicates.gleam
+++ b/src/gleam_community/maths/predicates.gleam
@@ -20,12 +20,12 @@
////
-////
+////
//// ---
-////
-//// Predicates: A module containing functions for testing various mathematical
+////
+//// Predicates: A module containing functions for testing various mathematical
//// properties of numbers.
-////
+////
//// * **Tests**
//// * [`is_close`](#is_close)
//// * [`list_all_close`](#all_close)
@@ -38,7 +38,7 @@
//// * [`is_divisible`](#is_divisible)
//// * [`is_multiple`](#is_multiple)
//// * [`is_prime`](#is_prime)
-////
+////
import gleam/int
import gleam/list
@@ -54,16 +54,16 @@ import gleam_community/maths/piecewise
///
///
///
-/// Determine if a given value \\(a\\) is close to or equivalent to a reference value
+/// Determine if a given value \\(a\\) is close to or equivalent to a reference value
/// \\(b\\) based on supplied relative \\(r_{tol}\\) and absolute \\(a_{tol}\\) tolerance
-/// values. The equivalance of the two given values are then determined based on
+/// values. The equivalance of the two given values are then determined based on
/// the equation:
///
/// \\[
/// \|a - b\| \leq (a_{tol} + r_{tol} \cdot \|b\|)
/// \\]
///
-/// `True` is returned if statement holds, otherwise `False` is returned.
+/// `True` is returned if statement holds, otherwise `False` is returned.
///
/// Example
///
@@ -71,12 +71,12 @@ import gleam_community/maths/piecewise
/// import gleam_community/maths/predicates
///
/// pub fn example () {
-/// let val: Float = 99.
-/// let ref_val: Float = 100.
+/// let val = 99.
+/// let ref_val = 100.
/// // We set 'atol' and 'rtol' such that the values are equivalent
/// // if 'val' is within 1 percent of 'ref_val' +/- 0.1
-/// let rtol: Float = 0.01
-/// let atol: Float = 0.10
+/// let rtol = 0.01
+/// let atol = 0.10
/// floatx.is_close(val, ref_val, rtol, atol)
/// |> should.be_true()
/// }
@@ -89,8 +89,8 @@ import gleam_community/maths/piecewise
///
///
pub fn is_close(a: Float, b: Float, rtol: Float, atol: Float) -> Bool {
- let x: Float = float_absolute_difference(a, b)
- let y: Float = atol +. rtol *. float_absolute_value(b)
+ let x = float_absolute_difference(a, b)
+ let y = atol +. rtol *. float_absolute_value(b)
case x <=. y {
True -> True
False -> False
@@ -126,20 +126,20 @@ fn float_absolute_difference(a: Float, b: Float) -> Float {
/// import gleam_community/maths/predicates
///
/// pub fn example () {
-/// let val: Float = 99.
-/// let ref_val: Float = 100.
-/// let xarr: List(Float) = list.repeat(val, 42)
-/// let yarr: List(Float) = list.repeat(ref_val, 42)
+/// let val = 99.
+/// let ref_val = 100.
+/// let xarr = list.repeat(val, 42)
+/// let yarr = list.repeat(ref_val, 42)
/// // We set 'atol' and 'rtol' such that the values are equivalent
/// // if 'val' is within 1 percent of 'ref_val' +/- 0.1
-/// let rtol: Float = 0.01
-/// let atol: Float = 0.10
+/// let rtol = 0.01
+/// let atol = 0.10
/// predicates.all_close(xarr, yarr, rtol, atol)
-/// |> fn(zarr: Result(List(Bool), String)) -> Result(Bool, Nil) {
+/// |> fn(zarr), String)) {
/// case zarr {
/// Ok(arr) ->
/// arr
-/// |> list.all(fn(a: Bool) -> Bool { a })
+/// |> list.all(fn(a) { a })
/// |> Ok
/// _ -> Nil |> Error
/// }
@@ -160,17 +160,15 @@ pub fn all_close(
rtol: Float,
atol: Float,
) -> Result(List(Bool), String) {
- let xlen: Int = list.length(xarr)
- let ylen: Int = list.length(yarr)
+ let xlen = list.length(xarr)
+ let ylen = list.length(yarr)
case xlen == ylen {
False ->
"Invalid input argument: length(xarr) != length(yarr). Valid input is when length(xarr) == length(yarr)."
|> Error
True ->
list.zip(xarr, yarr)
- |> list.map(fn(z: #(Float, Float)) -> Bool {
- is_close(pair.first(z), pair.second(z), rtol, atol)
- })
+ |> list.map(fn(z) { is_close(pair.first(z), pair.second(z), rtol, atol) })
|> Ok
}
}
@@ -182,10 +180,10 @@ pub fn all_close(
///
///
/// Determine if a given value is fractional.
-///
-/// `True` is returned if the given value is fractional, otherwise `False` is
-/// returned.
-///
+///
+/// `True` is returned if the given value is fractional, otherwise `False` is
+/// returned.
+///
///
/// Example
///
@@ -195,7 +193,7 @@ pub fn all_close(
/// pub fn example () {
/// predicates.is_fractional(0.3333)
/// |> should.equal(True)
-///
+///
/// predicates.is_fractional(1.0)
/// |> should.equal(False)
/// }
@@ -222,7 +220,7 @@ fn do_ceiling(a: Float) -> Float
///
///
/// A function that tests whether a given integer value \\(x \in \mathbb{Z}\\) is a
-/// power of another integer value \\(y \in \mathbb{Z}\\).
+/// power of another integer value \\(y \in \mathbb{Z}\\).
///
///
/// Example:
@@ -262,9 +260,9 @@ pub fn is_power(x: Int, y: Int) -> Bool {
///
///
/// A function that tests whether a given integer value \\(n \in \mathbb{Z}\\) is a
-/// perfect number. A number is perfect if it is equal to the sum of its proper
+/// perfect number. A number is perfect if it is equal to the sum of its proper
/// positive divisors.
-///
+///
///
/// Details
///
@@ -304,7 +302,7 @@ fn do_sum(arr: List(Int)) -> Int {
[] -> 0
_ ->
arr
- |> list.fold(0, fn(acc: Int, a: Int) -> Int { a + acc })
+ |> list.fold(0, fn(acc, a) { a + acc })
}
}
@@ -314,7 +312,7 @@ fn do_sum(arr: List(Int)) -> Int {
///
///
///
-/// A function that tests whether a given integer value \\(x \in \mathbb{Z}\\) is even.
+/// A function that tests whether a given integer value \\(x \in \mathbb{Z}\\) is even.
///
///
/// Example:
@@ -325,7 +323,7 @@ fn do_sum(arr: List(Int)) -> Int {
/// pub fn example() {
/// predicates.is_even(-3)
/// |> should.equal(False)
-///
+///
/// predicates.is_even(-4)
/// |> should.equal(True)
/// }
@@ -347,7 +345,7 @@ pub fn is_even(x: Int) -> Bool {
///
///
///
-/// A function that tests whether a given integer value \\(x \in \mathbb{Z}\\) is odd.
+/// A function that tests whether a given integer value \\(x \in \mathbb{Z}\\) is odd.
///
///
/// Example:
@@ -358,7 +356,7 @@ pub fn is_even(x: Int) -> Bool {
/// pub fn example() {
/// predicates.is_odd(-3)
/// |> should.equal(True)
-///
+///
/// predicates.is_odd(-4)
/// |> should.equal(False)
/// }
@@ -380,24 +378,24 @@ pub fn is_odd(x: Int) -> Bool {
///
///
///
-/// A function that tests whether a given integer value \\(x \in \mathbb{Z}\\) is a
-/// prime number. A prime number is a natural number greater than 1 that has no
+/// A function that tests whether a given integer value \\(x \in \mathbb{Z}\\) is a
+/// prime number. A prime number is a natural number greater than 1 that has no
/// positive divisors other than 1 and itself.
-///
-/// The function uses the Miller-Rabin primality test to assess if \\(x\\) is prime.
-/// It is a probabilistic test, so it can mistakenly identify a composite number
+///
+/// The function uses the Miller-Rabin primality test to assess if \\(x\\) is prime.
+/// It is a probabilistic test, so it can mistakenly identify a composite number
/// as prime. However, the probability of such errors decreases with more testing
-/// iterations (the function uses 64 iterations internally, which is typically
+/// iterations (the function uses 64 iterations internally, which is typically
/// more than sufficient). The Miller-Rabin test is particularly useful for large
/// numbers.
-///
+///
///
/// Details
///
/// Examples of prime numbers:
/// - \\(2\\) is a prime number since it has only two divisors: \\(1\\) and \\(2\\).
/// - \\(7\\) is a prime number since it has only two divisors: \\(1\\) and \\(7\\).
-/// - \\(4\\) is not a prime number since it has divisors other than \\(1\\) and itself, such
+/// - \\(4\\) is not a prime number since it has divisors other than \\(1\\) and itself, such
/// as \\(2\\).
///
///
@@ -414,7 +412,7 @@ pub fn is_odd(x: Int) -> Bool {
///
/// predicates.is_prime(4)
/// |> should.equal(False)
-///
+///
/// // Test the 2nd Carmichael number
/// predicates.is_prime(1105)
/// |> should.equal(False)
@@ -446,7 +444,7 @@ fn miller_rabin_test(n: Int, k: Int) -> Bool {
_, 0 -> True
_, _ -> {
// Generate a random int in the range [2, n]
- let random_candidate: Int = 2 + int.random(n - 2)
+ let random_candidate = 2 + int.random(n - 2)
case powmod_with_check(random_candidate, n - 1, n) == 1 {
True -> miller_rabin_test(n, k - 1)
False -> False
@@ -459,7 +457,7 @@ fn powmod_with_check(base: Int, exponent: Int, modulus: Int) -> Int {
case exponent, { exponent % 2 } == 0 {
0, _ -> 1
_, True -> {
- let x: Int = powmod_with_check(base, exponent / 2, modulus)
+ let x = powmod_with_check(base, exponent / 2, modulus)
case { x * x } % modulus, x != 1 && x != { modulus - 1 } {
1, True -> 0
_, _ -> { x * x } % modulus
@@ -512,9 +510,9 @@ pub fn is_between(x: Float, lower: Float, upper: Float) -> Bool {
///
///
///
-/// A function that tests whether a given integer \\(n \in \mathbb{Z}\\) is divisible by another
+/// A function that tests whether a given integer \\(n \in \mathbb{Z}\\) is divisible by another
/// integer \\(d \in \mathbb{Z}\\), such that \\(n \mod d = 0\\).
-///
+///
///
/// Details
///
@@ -555,9 +553,9 @@ pub fn is_divisible(n: Int, d: Int) -> Bool {
///
///
///
-/// A function that tests whether a given integer \\(m \in \mathbb{Z}\\) is a multiple of another
+/// A function that tests whether a given integer \\(m \in \mathbb{Z}\\) is a multiple of another
/// integer \\(k \in \mathbb{Z}\\), such that \\(m = k \times q\\), with \\(q \in \mathbb{Z}\\).
-///
+///
///
/// Details
///
diff --git a/src/gleam_community/maths/sequences.gleam b/src/gleam_community/maths/sequences.gleam
index 9ffe6ec..62c5301 100644
--- a/src/gleam_community/maths/sequences.gleam
+++ b/src/gleam_community/maths/sequences.gleam
@@ -20,18 +20,18 @@
////
-////
+////
//// ---
-////
-//// Sequences: A module containing functions for generating various types of
+////
+//// Sequences: A module containing functions for generating various types of
//// sequences, ranges and intervals.
-////
+////
//// * **Ranges and intervals**
//// * [`arange`](#arange)
//// * [`linear_space`](#linear_space)
//// * [`logarithmic_space`](#logarithmic_space)
//// * [`geometric_space`](#geometric_space)
-////
+////
import gleam/iterator
import gleam_community/maths/conversion
@@ -47,7 +47,7 @@ import gleam_community/maths/piecewise
/// The function returns an iterator generating evenly spaced values within a given interval.
/// based on a start value but excludes the stop value. The spacing between values is determined
/// by the step size provided. The function supports both positive and negative step values.
-///
+///
///
/// Example:
///
@@ -59,13 +59,13 @@ import gleam_community/maths/piecewise
/// sequences.arange(1.0, 5.0, 1.0)
/// |> iterator.to_list()
/// |> should.equal([1.0, 2.0, 3.0, 4.0])
-///
+///
/// // No points returned since
/// // start is smaller than stop and the step is positive
/// sequences.arange(5.0, 1.0, 1.0)
/// |> iterator.to_list()
/// |> should.equal([])
-///
+///
/// // Points returned since
/// // start smaller than stop but negative step
/// sequences.arange(5.0, 1.0, -1.0)
@@ -102,7 +102,7 @@ pub fn arange(
|> conversion.float_to_int()
iterator.range(0, num - 1)
- |> iterator.map(fn(i: Int) {
+ |> iterator.map(fn(i) {
start +. conversion.int_to_float(i) *. step_abs *. direction
})
}
@@ -115,10 +115,10 @@ pub fn arange(
///
///
///
-/// The function returns an iterator for generating linearly spaced points over a specified
-/// interval. The endpoint of the interval can optionally be included/excluded. The number of
+/// The function returns an iterator for generating linearly spaced points over a specified
+/// interval. The endpoint of the interval can optionally be included/excluded. The number of
/// points and whether the endpoint is included determine the spacing between values.
-///
+///
///
/// Example:
///
@@ -138,7 +138,7 @@ pub fn arange(
/// 0.0,
/// tol,
/// )
-///
+///
/// result
/// |> list.all(fn(x) { x == True })
/// |> should.be_true()
@@ -161,7 +161,7 @@ pub fn linear_space(
num: Int,
endpoint: Bool,
) -> Result(iterator.Iterator(Float), String) {
- let direction: Float = case start <=. stop {
+ let direction = case start <=. stop {
True -> 1.0
False -> -1.0
}
@@ -179,7 +179,7 @@ pub fn linear_space(
case num > 0 {
True -> {
iterator.range(0, num - 1)
- |> iterator.map(fn(i: Int) -> Float {
+ |> iterator.map(fn(i) {
start +. conversion.int_to_float(i) *. increment *. direction
})
|> Ok
@@ -196,10 +196,10 @@ pub fn linear_space(
///
///
///
-/// The function returns an iterator of logarithmically spaced points over a specified interval.
-/// The endpoint of the interval can optionally be included/excluded. The number of points, base,
+/// The function returns an iterator of logarithmically spaced points over a specified interval.
+/// The endpoint of the interval can optionally be included/excluded. The number of points, base,
/// and whether the endpoint is included determine the spacing between values.
-///
+///
///
/// Example:
///
@@ -246,7 +246,7 @@ pub fn logarithmic_space(
True -> {
let assert Ok(linspace) = linear_space(start, stop, num, endpoint)
linspace
- |> iterator.map(fn(i: Float) -> Float {
+ |> iterator.map(fn(i) {
let assert Ok(result) = elementary.power(base, i)
result
})
@@ -264,9 +264,9 @@ pub fn logarithmic_space(
///
///
///
-/// The function returns an iterator of numbers spaced evenly on a log scale (a geometric
-/// progression). Each point in the list is a constant multiple of the previous. The function is
-/// similar to the [`logarithmic_space`](#logarithmic_space) function, but with endpoints
+/// The function returns an iterator of numbers spaced evenly on a log scale (a geometric
+/// progression). Each point in the list is a constant multiple of the previous. The function is
+/// similar to the [`logarithmic_space`](#logarithmic_space) function, but with endpoints
/// specified directly.
///
///
@@ -295,7 +295,7 @@ pub fn logarithmic_space(
/// // Input (start and stop can't be equal to 0.0)
/// sequences.geometric_space(0.0, 1000.0, 3, False)
/// |> should.be_error()
-///
+///
/// sequences.geometric_space(-1000.0, 0.0, 3, False)
/// |> should.be_error()
///
diff --git a/src/gleam_community/maths/special.gleam b/src/gleam_community/maths/special.gleam
index f6e3438..a3f0136 100644
--- a/src/gleam_community/maths/special.gleam
+++ b/src/gleam_community/maths/special.gleam
@@ -20,17 +20,17 @@
////
-////
+////
//// ---
-////
+////
//// Special: A module containing special mathematical functions.
-////
+////
//// * **Special mathematical functions**
//// * [`beta`](#beta)
//// * [`erf`](#erf)
//// * [`gamma`](#gamma)
//// * [`incomplete_gamma`](#incomplete_gamma)
-////
+////
import gleam/list
import gleam_community/maths/conversion
@@ -76,17 +76,17 @@ pub fn beta(x: Float, y: Float) -> Float {
///
///
pub fn erf(x: Float) -> Float {
- let assert [a1, a2, a3, a4, a5]: List(Float) = [
+ let assert [a1, a2, a3, a4, a5] = [
0.254829592, -0.284496736, 1.421413741, -1.453152027, 1.061405429,
]
- let p: Float = 0.3275911
+ let p = 0.3275911
- let sign: Float = piecewise.float_sign(x)
- let x: Float = piecewise.float_absolute_value(x)
+ let sign = piecewise.float_sign(x)
+ let x = piecewise.float_absolute_value(x)
// Formula 7.1.26 given in Abramowitz and Stegun.
- let t: Float = 1.0 /. { 1.0 +. p *. x }
- let y: Float =
+ let t = 1.0 /. { 1.0 +. p *. x }
+ let y =
1.0
-. { { { { a5 *. t +. a4 } *. t +. a3 } *. t +. a2 } *. t +. a1 }
*. t
@@ -100,7 +100,7 @@ pub fn erf(x: Float) -> Float {
///
///
///
-/// The gamma function over the real numbers. The function is essentially equal to
+/// The gamma function over the real numbers. The function is essentially equal to
/// the factorial for any positive integer argument: \\(\Gamma(n) = (n - 1)!\\)
///
/// The implemented gamma function is approximated through Lanczos approximation
@@ -131,14 +131,14 @@ fn gamma_lanczos(x: Float) -> Float {
/. { elementary.sin(elementary.pi() *. x) *. gamma_lanczos(1.0 -. x) }
False -> {
let z = x -. 1.0
- let x: Float =
- list.index_fold(lanczos_p, 0.0, fn(acc: Float, v: Float, index: Int) {
+ let x =
+ list.index_fold(lanczos_p, 0.0, fn(acc, v, index) {
case index > 0 {
True -> acc +. v /. { z +. conversion.int_to_float(index) }
False -> v
}
})
- let t: Float = z +. lanczos_g +. 0.5
+ let t = z +. lanczos_g +. 0.5
let assert Ok(v1) = elementary.power(2.0 *. elementary.pi(), 0.5)
let assert Ok(v2) = elementary.power(t, z +. 0.5)
v1 *. v2 *. elementary.exponential(-1.0 *. t) *. x
@@ -189,8 +189,8 @@ fn incomplete_gamma_sum(
case t {
0.0 -> s
_ -> {
- let ns: Float = s +. t
- let nt: Float = t *. { x /. { a +. n } }
+ let ns = s +. t
+ let nt = t *. { x /. { a +. n } }
incomplete_gamma_sum(a, x, nt, ns, n +. 1.0)
}
}
diff --git a/test/gleam_community/maths/metrics_test.gleam b/test/gleam_community/maths/metrics_test.gleam
index dcf43eb..4debea5 100644
--- a/test/gleam_community/maths/metrics_test.gleam
+++ b/test/gleam_community/maths/metrics_test.gleam
@@ -317,7 +317,7 @@ pub fn median_test() {
pub fn variance_test() {
// Degrees of freedom
- let ddof: Int = 1
+ let ddof = 1
// An empty list returns an error
[]
@@ -332,7 +332,7 @@ pub fn variance_test() {
pub fn standard_deviation_test() {
// Degrees of freedom
- let ddof: Int = 1
+ let ddof = 1
// An empty list returns an error
[]
@@ -349,19 +349,18 @@ pub fn jaccard_index_test() {
metrics.jaccard_index(set.from_list([]), set.from_list([]))
|> should.equal(0.0)
- let set_a: set.Set(Int) = set.from_list([0, 1, 2, 5, 6, 8, 9])
- let set_b: set.Set(Int) = set.from_list([0, 2, 3, 4, 5, 7, 9])
+ let set_a = set.from_list([0, 1, 2, 5, 6, 8, 9])
+ let set_b = set.from_list([0, 2, 3, 4, 5, 7, 9])
metrics.jaccard_index(set_a, set_b)
|> should.equal(4.0 /. 10.0)
- let set_c: set.Set(Int) = set.from_list([0, 1, 2, 3, 4, 5])
- let set_d: set.Set(Int) = set.from_list([6, 7, 8, 9, 10])
+ let set_c = set.from_list([0, 1, 2, 3, 4, 5])
+ let set_d = set.from_list([6, 7, 8, 9, 10])
metrics.jaccard_index(set_c, set_d)
|> should.equal(0.0 /. 11.0)
- let set_e: set.Set(String) = set.from_list(["cat", "dog", "hippo", "monkey"])
- let set_f: set.Set(String) =
- set.from_list(["monkey", "rhino", "ostrich", "salmon"])
+ let set_e = set.from_list(["cat", "dog", "hippo", "monkey"])
+ let set_f = set.from_list(["monkey", "rhino", "ostrich", "salmon"])
metrics.jaccard_index(set_e, set_f)
|> should.equal(1.0 /. 7.0)
}
@@ -370,19 +369,18 @@ pub fn sorensen_dice_coefficient_test() {
metrics.sorensen_dice_coefficient(set.from_list([]), set.from_list([]))
|> should.equal(0.0)
- let set_a: set.Set(Int) = set.from_list([0, 1, 2, 5, 6, 8, 9])
- let set_b: set.Set(Int) = set.from_list([0, 2, 3, 4, 5, 7, 9])
+ let set_a = set.from_list([0, 1, 2, 5, 6, 8, 9])
+ let set_b = set.from_list([0, 2, 3, 4, 5, 7, 9])
metrics.sorensen_dice_coefficient(set_a, set_b)
|> should.equal(2.0 *. 4.0 /. { 7.0 +. 7.0 })
- let set_c: set.Set(Int) = set.from_list([0, 1, 2, 3, 4, 5])
- let set_d: set.Set(Int) = set.from_list([6, 7, 8, 9, 10])
+ let set_c = set.from_list([0, 1, 2, 3, 4, 5])
+ let set_d = set.from_list([6, 7, 8, 9, 10])
metrics.sorensen_dice_coefficient(set_c, set_d)
|> should.equal(2.0 *. 0.0 /. { 6.0 +. 5.0 })
- let set_e: set.Set(String) = set.from_list(["cat", "dog", "hippo", "monkey"])
- let set_f: set.Set(String) =
- set.from_list(["monkey", "rhino", "ostrich", "salmon", "spider"])
+ let set_e = set.from_list(["cat", "dog", "hippo", "monkey"])
+ let set_f = set.from_list(["monkey", "rhino", "ostrich", "salmon", "spider"])
metrics.sorensen_dice_coefficient(set_e, set_f)
|> should.equal(2.0 *. 1.0 /. { 4.0 +. 5.0 })
}
@@ -391,20 +389,18 @@ pub fn overlap_coefficient_test() {
metrics.overlap_coefficient(set.from_list([]), set.from_list([]))
|> should.equal(0.0)
- let set_a: set.Set(Int) = set.from_list([0, 1, 2, 5, 6, 8, 9])
- let set_b: set.Set(Int) = set.from_list([0, 2, 3, 4, 5, 7, 9])
+ let set_a = set.from_list([0, 1, 2, 5, 6, 8, 9])
+ let set_b = set.from_list([0, 2, 3, 4, 5, 7, 9])
metrics.overlap_coefficient(set_a, set_b)
|> should.equal(4.0 /. 7.0)
- let set_c: set.Set(Int) = set.from_list([0, 1, 2, 3, 4, 5])
- let set_d: set.Set(Int) = set.from_list([6, 7, 8, 9, 10])
+ let set_c = set.from_list([0, 1, 2, 3, 4, 5])
+ let set_d = set.from_list([6, 7, 8, 9, 10])
metrics.overlap_coefficient(set_c, set_d)
|> should.equal(0.0 /. 5.0)
- let set_e: set.Set(String) =
- set.from_list(["horse", "dog", "hippo", "monkey", "bird"])
- let set_f: set.Set(String) =
- set.from_list(["monkey", "bird", "ostrich", "salmon"])
+ let set_e = set.from_list(["horse", "dog", "hippo", "monkey", "bird"])
+ let set_f = set.from_list(["monkey", "bird", "ostrich", "salmon"])
metrics.overlap_coefficient(set_e, set_f)
|> should.equal(2.0 /. 4.0)
}
@@ -440,7 +436,7 @@ pub fn cosine_similarity_test() {
metrics.cosine_similarity([-1.0, -2.0, -3.0], [1.0, 2.0, 3.0], option.None)
|> should.equal(Ok(-1.0))
- // Try with arbitrary valid input
+ // Try with arbitrary valid input
let assert Ok(result) =
metrics.cosine_similarity([1.0, 2.0, 3.0], [4.0, 5.0, 6.0], option.None)
result
diff --git a/test/gleam_community/maths/predicates_test.gleam b/test/gleam_community/maths/predicates_test.gleam
index fcae19c..c9e2c5f 100644
--- a/test/gleam_community/maths/predicates_test.gleam
+++ b/test/gleam_community/maths/predicates_test.gleam
@@ -3,31 +3,31 @@ import gleam_community/maths/predicates
import gleeunit/should
pub fn float_is_close_test() {
- let val: Float = 99.0
- let ref_val: Float = 100.0
+ let val = 99.0
+ let ref_val = 100.0
// We set 'atol' and 'rtol' such that the values are equivalent
// if 'val' is within 1 percent of 'ref_val' +/- 0.1
- let rtol: Float = 0.01
- let atol: Float = 0.1
+ let rtol = 0.01
+ let atol = 0.1
predicates.is_close(val, ref_val, rtol, atol)
|> should.be_true()
}
pub fn float_list_all_close_test() {
- let val: Float = 99.0
- let ref_val: Float = 100.0
- let xarr: List(Float) = list.repeat(val, 42)
- let yarr: List(Float) = list.repeat(ref_val, 42)
+ let val = 99.0
+ let ref_val = 100.0
+ let xarr = list.repeat(val, 42)
+ let yarr = list.repeat(ref_val, 42)
// We set 'atol' and 'rtol' such that the values are equivalent
// if 'val' is within 1 percent of 'ref_val' +/- 0.1
- let rtol: Float = 0.01
- let atol: Float = 0.1
+ let rtol = 0.01
+ let atol = 0.1
predicates.all_close(xarr, yarr, rtol, atol)
- |> fn(zarr: Result(List(Bool), String)) -> Result(Bool, Nil) {
+ |> fn(zarr) {
case zarr {
Ok(arr) ->
arr
- |> list.all(fn(a: Bool) -> Bool { a })
+ |> list.all(fn(a) { a })
|> Ok
_ ->
Nil