From 83a671fe2b8e9fd4b6c2011e1f9e75c0b380384c Mon Sep 17 00:00:00 2001 From: NicklasXYZ Date: Sun, 29 Jan 2023 20:00:09 +0100 Subject: [PATCH] Fix typos --- src/gleam_community/maths/float.gleam | 34 +++++++------ src/gleam_community/maths/float_list.gleam | 35 ++++++------- src/gleam_community/maths/int.gleam | 13 +++-- src/gleam_community/maths/int_list.gleam | 50 ++++++++++--------- .../gleam_community_maths_int_list_test.gleam | 6 +-- 5 files changed, 73 insertions(+), 65 deletions(-) diff --git a/src/gleam_community/maths/float.gleam b/src/gleam_community/maths/float.gleam index cfc81ff..6b38793 100644 --- a/src/gleam_community/maths/float.gleam +++ b/src/gleam_community/maths/float.gleam @@ -146,7 +146,7 @@ pub fn ceiling(x: Float, digits: option.Option(Int)) -> Result(Float, String) { /// /// /// -/// The floor function rounds input $$x \in \mathbb{R}$$ to the nearest integer value (at the specified digit) that is less than or equal to the input $$x$$ +/// The floor function rounds input $$x \in \mathbb{R}$$ to the nearest integer value (at the specified digit) that is less than or equal to the input $$x$$. /// /// Note: The floor function is used as an alias for the rounding function [`round`](#round) with rounding mode `RoundDown`. /// @@ -361,7 +361,7 @@ pub fn truncate(x: Float, digits: option.Option(Int)) -> Result(Float, String) { /// |> should.equal(Ok(12.07)) /// /// floatx.round(12.0654, option.Some(2), option.Some(floatx.RoundTiesUp)) -/// |> should.equal(Ok(12.07) +/// |> should.equal(Ok(12.07)) /// /// floatx.round(12.0654, option.Some(2), option.Some(floatx.RoundToZero)) /// |> should.equal(Ok(12.06)) @@ -714,7 +714,7 @@ if javascript { /// /// pub fn example() { /// floatx.asin(0.0) -/// |> should.equal(0.0) +/// |> should.equal(Ok(0.0)) /// /// floatx.asin(1.1) /// |> should.be_error() @@ -1108,20 +1108,19 @@ if javascript { "../../maths.mjs" "exponential" } -// TODO: Update description here below ///
/// /// Spot a typo? Open an issue! /// ///
/// -/// The natural logarithm function: +/// The base $$b$$ logarithm function (computed through the "change of base" formula): /// /// \\[ -/// \forall x \in \(0, \infty\), \\; \log_{e}{(x)} = y \in \(-\infty, +\infty\) +/// \forall x \in \(0, \infty\) \textnormal{ and } b > 1, \\; \log_{b}{(x)} = y \in \(-\infty, +\infty\) /// \\] /// -/// The function takes a number $$x$$ in its domain $$\(0, \infty\)$$ as input and returns +/// The function takes a number $$x$$ in its domain $$\(0, \infty\)$$ and a base $$b > 1$$ as input and returns /// a numeric value $$y$$ that lies in the range $$\(-\infty, \infty\)$$. /// If the input value is outside the domain of the function an error is returned. /// @@ -1137,7 +1136,7 @@ if javascript { /// |> should.equal(Ok(0.0)) /// /// floatx.logarithm(floatx.e(), option.Some(floatx.e())) -/// |> should.equal(1.0) +/// |> should.equal(Ok(1.0)) /// /// floatx.logarithm(-1.0, option.Some(2.0)) /// |> should.be_error() @@ -1205,7 +1204,7 @@ pub fn logarithm(x: Float, base: option.Option(Float)) -> Result(Float, String) /// |> should.equal(Ok(0.0)) /// /// floatx.natural_logarithm(floatx.e()) -/// |> should.equal(1.0) +/// |> should.equal(Ok(1.0)) /// /// floatx.natural_logarithm(-1.0) /// |> should.be_error() @@ -1546,7 +1545,7 @@ pub fn cube_root(x: Float) -> Result(Float, String) { /// /// /// -/// The nth root function: $$y = \sqrt[3]{x} = x^{\frac{1}{n}}$$. +/// The $$n$$'th root function: $$y = \sqrt[n]{x} = x^{\frac{1}{n}}$$. /// /// Note that the function is not defined if: /// 1. The input is negative ($$x < 0$$). An error will be returned @@ -1607,7 +1606,7 @@ pub fn nth_root(x: Float, n: Int) -> Result(Float, String) { /// /// /// -/// A function to compute the hypotenuse of a right-angled triangle: $$\sqrt[2](x^2 + y^2)$$. +/// A function to compute the hypotenuse of a right-angled triangle: $$\sqrt[2]{x^2 + y^2}$$. /// The function can also be used to calculate the Euclidean distance in 2 dimensions. /// ///
@@ -1617,7 +1616,14 @@ pub fn nth_root(x: Float, n: Int) -> Result(Float, String) { /// import gleam_community/maths/float as floatx /// /// pub fn example() { -/// +/// floatx.hypotenuse(0.0, 0.0) +/// |> should.equal(0.0) +/// +/// floatx.hypotenuse(1.0, 0.0) +/// |> should.equal(1.0) +/// +/// floatx.hypotenuse(0.0, 1.0) +/// |> should.equal(1.0) /// } ///
/// @@ -1853,7 +1859,7 @@ if javascript { /// floatx.to_degree(0.0) /// |> should.equal(0.0) /// -/// floatx.to_degree(2. *. pi()) +/// floatx.to_degree(2. *. floatx.pi()) /// |> should.equal(360.) /// } /// @@ -1885,7 +1891,7 @@ pub fn to_degree(x: Float) -> Float { /// /// pub fn example() { /// floatx.to_radian(360.) -/// |> should.equal(2. *. pi()) +/// |> should.equal(2. *. floatx.pi()) /// } /// /// diff --git a/src/gleam_community/maths/float_list.gleam b/src/gleam_community/maths/float_list.gleam index 455a40c..cc73be6 100644 --- a/src/gleam_community/maths/float_list.gleam +++ b/src/gleam_community/maths/float_list.gleam @@ -125,7 +125,7 @@ pub fn norm(arr: List(Float), p: Float) -> Float { /// Calculcate the Minkowski distance between two lists (representing vectors): /// /// \\[ -/// \left( \sum_{i=1}^n \left|x_i - x_j \right|^{p} \right)^{\frac{1}{p}} +/// \left( \sum_{i=1}^n \left|x_i - y_i \right|^{p} \right)^{\frac{1}{p}} /// \\] /// /// In the formula, $$p >= 1$$ is the order, $$n$$ is the length of the two lists and $$x_i, y_i$$ are the values in the respective input lists indexed by $$i, j$$. @@ -203,7 +203,7 @@ pub fn minkowski_distance( /// Calculcate the Euclidean distance between two lists (representing vectors): /// /// \\[ -/// \left( \sum_{i=1}^n \left|x_i - x_j \right|^{2} \right)^{\frac{1}{2}} +/// \left( \sum_{i=1}^n \left|x_i - y_i \right|^{2} \right)^{\frac{1}{2}} /// \\] /// /// In the formula, $$n$$ is the length of the two lists and $$x_i, y_i$$ are the values in the respective input lists indexed by $$i, j$$. @@ -219,11 +219,11 @@ pub fn minkowski_distance( /// assert Ok(tol) = floatx.power(-10.0, -6.0) /// /// // Empty lists returns 0.0 -/// float_list.euclidean_distance([], [], 1.0) +/// float_list.euclidean_distance([], []) /// |> should.equal(Ok(0.0)) /// /// // Differing lengths returns error -/// float_list.euclidean_distance([], [1.0], 1.0) +/// float_list.euclidean_distance([], [1.0]) /// |> should.be_error() /// /// assert Ok(result) = float_list.euclidean_distance([0.0, 0.0], [1.0, 2.0]) @@ -255,7 +255,7 @@ pub fn euclidean_distance( /// Calculcate the Manhatten distance between two lists (representing vectors): /// /// \\[ -/// \sum_{i=1}^n \left|x_i - x_j \right| +/// \sum_{i=1}^n \left|x_i - y_i \right| /// \\] /// /// In the formula, $$n$$ is the length of the two lists and $$x_i, y_i$$ are the values in the respective input lists indexed by $$i, j$$. @@ -390,7 +390,7 @@ pub fn linear_space( /// /// pub fn example () { /// assert Ok(tol) = floatx.power(-10.0, -6.0) -/// assert Ok(logspace) = float_list.logarithmic_space(1.0, 3.0, 3, True) +/// assert Ok(logspace) = float_list.logarithmic_space(1.0, 3.0, 3, True, 10.0) /// assert Ok(result) = /// float_list.all_close(logspace, [10.0, 100.0, 1000.0], 0.0, tol) /// result @@ -398,7 +398,7 @@ pub fn linear_space( /// |> should.be_true() /// /// // A negative number of points (-3) does not work -/// float_list.logarithmic_space(1.0, 3.0, -3, False) +/// float_list.logarithmic_space(1.0, 3.0, -3, False, 10.0) /// |> should.be_error() /// } /// @@ -438,7 +438,7 @@ pub fn logarithmic_space( /// /// /// -/// The function returns a list of numbers spaced evenly on a log scale (a geometric progression). Each output point in the list is a constant multiple of the previous. +/// The function returns a list 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. /// ///
@@ -661,11 +661,12 @@ pub fn product(arr: List(Float)) -> Float { /// Calculcate the cumulative sum of the elements in a list: /// /// \\[ -/// v_j = \sum_{i=1}^j x_i, \forall j \leq n +/// v_j = \sum_{i=1}^j x_i \\;\\; \forall j = 1,\dots, n /// \\] /// -/// In the formula, $$n$$ is the length of the list and $$x_i$$ is the value in the input list indexed by $$i$$. -/// Furthermore, $$v_j$$ is the $$j$$th element in the cumulative sum. +/// In the formula, $$v_j$$ is the $$j$$'th element in the cumulative sum of $$n$$ elements. +/// That is, $$n$$ is the length of the list and $$x_i$$ is the value in the input list indexed by $$i$$. +/// The value $$v_j$$ is thus the sum of the $$1$$ to $$j$$ first elements in the given list. /// ///
/// Example: @@ -709,11 +710,12 @@ pub fn cumulative_sum(arr: List(Float)) -> List(Float) { /// Calculcate the cumulative product of the elements in a list: /// /// \\[ -/// v_j = \prod_{i=1}^j x_i, \forall j \leq n +/// v_j = \prod_{i=1}^j x_i \\;\\; \forall j = 1,\dots, n /// \\] /// -/// In the formula, $$n$$ is the length of the list and $$x_i$$ is the value in the input list indexed by $$i$$. -/// Furthermore, $$v_j$$ is the $$j$$th element in the cumulative product. +/// In the formula, $$v_j$$ is the $$j$$'th element in the cumulative product of $$n$$ elements. +/// That is, $$n$$ is the length of the list and $$x_i$$ is the value in the input list indexed by $$i$$. +/// The value $$v_j$$ is thus the sum of the $$1$$ to $$j$$ first elements in the given list. /// ///
/// Example: @@ -985,7 +987,7 @@ pub fn arg_minimum(arr: List(Float)) -> Result(List(Int), String) { /// /// /// -/// Returns the minimum value of a list. +/// Returns a tuple consisting of the minimum and maximum value of a list. /// ///
/// Example: @@ -1045,8 +1047,7 @@ pub fn extrema(arr: List(Float)) -> Result(#(Float, Float), String) { /// /// /// -/// Determine if a list of values are close to or equivalent to a -/// another list of reference values. +/// Determine if a list of values are close to or equivalent to a another list of reference values. /// ///
/// Example: diff --git a/src/gleam_community/maths/int.gleam b/src/gleam_community/maths/int.gleam index a2ba8dd..1800bd0 100644 --- a/src/gleam_community/maths/int.gleam +++ b/src/gleam_community/maths/int.gleam @@ -469,11 +469,11 @@ pub fn permutation(n: Int, k: Int) -> Result(Int, String) { /// import gleam_community/maths/int as intx /// /// pub fn example() { -/// intx.absolute_difference(-10.0, 10.0) -/// |> should.equal(20.0) +/// intx.absolute_difference(-10, 10) +/// |> should.equal(20) /// -/// intx.absolute_difference(0.0, -2.0) -/// |> should.equal(2.0) +/// intx.absolute_difference(0, -2) +/// |> should.equal(2) /// } ///
/// @@ -601,7 +601,6 @@ fn do_sum(arr: List(Int)) -> Int { /// /// intx.proper_divisors(13) /// |> should.equal([1]) -/// /// } ///
/// @@ -831,7 +830,7 @@ pub fn is_even(x: Int) -> Bool { /// /// /// -/// A function that produces a number of type `Float` and from an `Int`. +/// A function that produces a number of type `Float` from an `Int`. /// /// Note: The function is equivalent to the similar function in the Gleam stdlib. /// @@ -845,7 +844,7 @@ pub fn is_even(x: Int) -> Bool { /// intx.to_float(-1) /// |> should.equal(-1.0) /// -/// intx.is_even(1) +/// intx.to_float(1) /// |> should.equal(1.0) /// } ///
diff --git a/src/gleam_community/maths/int_list.gleam b/src/gleam_community/maths/int_list.gleam index a1701d3..9678e91 100644 --- a/src/gleam_community/maths/int_list.gleam +++ b/src/gleam_community/maths/int_list.gleam @@ -51,7 +51,7 @@ import gleam_community/maths/int as intx /// Calculcate the Manhatten distance between two lists (representing vectors): /// /// \\[ -/// \sum_{i=1}^n \left|x_i - x_j \right| +/// \sum_{i=1}^n \left|x_i - y_i \right| /// \\] /// /// In the formula, $$n$$ is the length of the two lists and $$x_i, y_i$$ are the values in the respective input lists indexed by $$i, j$$. @@ -60,16 +60,15 @@ import gleam_community/maths/int as intx /// Example: /// /// import gleeunit/should -/// import gleam_community/maths/float as floatx -/// import gleam_community/maths/float_list +/// import gleam_community/maths/int_list /// /// pub fn example () { /// // Empty lists returns 0 -/// float_list.manhatten_distance([], []) -/// |> should.equal(Ok(0.0)) +/// int_list.manhatten_distance([], []) +/// |> should.equal(Ok(0)) /// /// // Differing lengths returns error -/// float_list.manhatten_distance([], [1]) +/// int_list.manhatten_distance([], [1]) /// |> should.be_error() /// /// assert Ok(result) = int_list.manhatten_distance([0, 0], [1, 2]) @@ -122,17 +121,17 @@ pub fn manhatten_distance( /// Example: /// /// import gleeunit/should -/// import gleam_community/maths/float_list +/// import gleam_community/maths/int_list /// /// pub fn example () { /// // An empty list returns 0 /// [] -/// |> float_list.sum() +/// |> int_list.sum() /// |> should.equal(0) /// /// // Valid input returns a result /// [1, 2, 3] -/// |> float_list.sum() +/// |> int_list.sum() /// |> should.equal(6) /// } ///
@@ -170,18 +169,18 @@ pub fn sum(arr: List(Int)) -> Int { /// Example: /// /// import gleeunit/should -/// import gleam_community/maths/float_list +/// import gleam_community/maths/int_list /// /// pub fn example () { -/// // An empty list returns an error +/// // An empty list returns 0 /// [] -/// |> float_list.sum() -/// |> should.equal(0.) +/// |> int_list.product() +/// |> should.equal(0) /// /// // Valid input returns a result -/// [1., 2., 3.] -/// |> float_list.product() -/// |> should.equal(6.) +/// [1, 2, 3] +/// |> int_list.product() +/// |> should.equal(6) /// } ///
/// @@ -209,11 +208,12 @@ pub fn product(arr: List(Int)) -> Int { /// Calculcate the cumulative sum of the elements in a list: /// /// \\[ -/// v_j = \sum_{i=1}^j x_i, \forall j \leq n +/// v_j = \sum_{i=1}^j x_i \\;\\; \forall j = 1,\dots, n /// \\] /// -/// In the formula, $$n$$ is the length of the list and $$x_i$$ is the value in the input list indexed by $$i$$. -/// Furthermore, $$v_j$$ is the $$j$$th element in the cumulative sum. +/// In the formula, $$v_j$$ is the $$j$$'th element in the cumulative sum of $$n$$ elements. +/// That is, $$n$$ is the length of the list and $$x_i$$ is the value in the input list indexed by $$i$$. +/// The value $$v_j$$ is thus the sum of the $$1$$ to $$j$$ first elements in the given list. /// ///
/// Example: @@ -257,11 +257,12 @@ pub fn cumulative_sum(arr: List(Int)) -> List(Int) { /// Calculcate the cumulative product of the elements in a list: /// /// \\[ -/// v_j = \prod_{i=1}^j x_i, \forall j \leq n +/// v_j = \prod_{i=1}^j x_i \\;\\; \forall j = 1,\dots, n /// \\] /// -/// In the formula, $$n$$ is the length of the list and $$x_i$$ is the value in the input list indexed by $$i$$. -/// Furthermore, $$v_j$$ is the $$j$$th element in the cumulative product. +/// In the formula, $$v_j$$ is the $$j$$'th element in the cumulative product of $$n$$ elements. +/// That is, $$n$$ is the length of the list and $$x_i$$ is the value in the input list indexed by $$i$$. +/// The value $$v_j$$ is thus the product of the $$1$$ to $$j$$ first elements in the given list. /// ///
/// Example: @@ -288,7 +289,7 @@ pub fn cumulative_sum(arr: List(Int)) -> List(Int) { /// /// /// -pub fn cumumlative_product(arr: List(Int)) -> List(Int) { +pub fn cumulative_product(arr: List(Int)) -> List(Int) { case arr { [] -> [] _ -> @@ -319,7 +320,7 @@ pub fn cumumlative_product(arr: List(Int)) -> List(Int) { /// /// // Valid input returns a result /// [4, 4, 3, 2, 1] -/// |> stats.arg_minimum() +/// |> int_list.arg_minimum() /// |> should.equal(Ok([4])) /// } ///
@@ -533,6 +534,7 @@ pub fn minimum(arr: List(Int)) -> Result(Int, String) { /// /// /// +/// Returns a tuple consisting of the minimum and maximum value of a list. /// ///
/// Example: diff --git a/test/gleam/gleam_community_maths_int_list_test.gleam b/test/gleam/gleam_community_maths_int_list_test.gleam index a0ec5d6..e1aa910 100644 --- a/test/gleam/gleam_community_maths_int_list_test.gleam +++ b/test/gleam/gleam_community_maths_int_list_test.gleam @@ -120,16 +120,16 @@ pub fn int_list_product_test() { pub fn int_list_cumulative_product_test() { // An empty lists returns an empty list [] - |> int_list.cumumlative_product() + |> int_list.cumulative_product() |> should.equal([]) // Valid input returns a result [1, 2, 3] - |> int_list.cumumlative_product() + |> int_list.cumulative_product() |> should.equal([1, 2, 6]) [-2, 4, 6] - |> int_list.cumumlative_product() + |> int_list.cumulative_product() |> should.equal([-2, -8, -48]) }