From cc36138462e432f09eb7c7735c0fe866e3adcf54 Mon Sep 17 00:00:00 2001 From: KG Date: Thu, 11 Jun 2026 14:46:36 -0500 Subject: [PATCH 1/4] Permit larger arguments to combinatorial functions --- Math.ark | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/Math.ark b/Math.ark index 2eab946..066ef1a 100644 --- a/Math.ark +++ b/Math.ark @@ -769,7 +769,7 @@ # @author https://github.com/SuperFola (let binomialCoeff (fun (_n _k) (if (<= _k _n) - (/ (factorial _n) (* (factorial _k) (factorial (- _n _k)))) + (/ (permutations _n _k) (factorial _k)) 0))) # @brief Compute the number of ways to choose k items from n items without repetition and with order @@ -779,7 +779,12 @@ # @author https://github.com/SuperFola (let permutations (fun (_n _k) (if (<= _k _n) - (/ (factorial _n) (factorial (- _n _k))) + { + (mut _res 1) + (while (> _n k) { + (set _res (* _res _n)) + (set _n (- _n 1)) }) + _res } 0))) # @brief Compare two real numbers and return true if the first one is near the second one (1e-7 precision) From af283be618fa9ab7717350d189bf418a4df115c2 Mon Sep 17 00:00:00 2001 From: KG Date: Thu, 11 Jun 2026 14:56:03 -0500 Subject: [PATCH 2/4] Actually make it work --- Math.ark | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Math.ark b/Math.ark index 066ef1a..535ea52 100644 --- a/Math.ark +++ b/Math.ark @@ -777,11 +777,12 @@ # @param _n total number of items # @param _k number of items to pick # @author https://github.com/SuperFola -(let permutations (fun (_n _k) +(let permutations (fun ((mut _n) _k) (if (<= _k _n) { (mut _res 1) - (while (> _n k) { + (let _lower (- _n _k)) + (while (> _n _lower) { (set _res (* _res _n)) (set _n (- _n 1)) }) _res } From 422868d9d6200f39e01e21e1ec89379cc1eacf27 Mon Sep 17 00:00:00 2001 From: KG Date: Fri, 12 Jun 2026 09:49:59 -0500 Subject: [PATCH 3/4] Update math-tests.ark --- tests/math-tests.ark | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/math-tests.ark b/tests/math-tests.ark index a2d192a..cc4a8d9 100644 --- a/tests/math-tests.ark +++ b/tests/math-tests.ark @@ -298,7 +298,8 @@ (test:eq (math:binomialCoeff 4 1) 4) (test:eq (math:binomialCoeff 4 2) 6) (test:eq (math:binomialCoeff 4 3) 4) - (test:eq (math:binomialCoeff 4 4) 1) }) + (test:eq (math:binomialCoeff 4 4) 1) + (test:eq (math:binomialCoeff 90 13) 1643385429346680) }) (test:case "permutations" { (test:eq (math:permutations 5 3) 60) From e2c11376e3e070200a5201ad128b7b34c12e472a Mon Sep 17 00:00:00 2001 From: KG Date: Fri, 12 Jun 2026 09:51:28 -0500 Subject: [PATCH 4/4] Update authorship --- Math.ark | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Math.ark b/Math.ark index 535ea52..e04c466 100644 --- a/Math.ark +++ b/Math.ark @@ -766,7 +766,7 @@ # @details Evaluates to n! / (k! * (n - k)!) when k <= n and evaluates to zero when k > n. # @param _n total number of items # @param _k number of items that will be picked -# @author https://github.com/SuperFola +# @author https://github.com/SuperFola, https://github.com/kg583 (let binomialCoeff (fun (_n _k) (if (<= _k _n) (/ (permutations _n _k) (factorial _k)) @@ -776,7 +776,7 @@ # @details Evaluates to n! / (n - k)! when k <= n and evaluates to zero when k > n. # @param _n total number of items # @param _k number of items to pick -# @author https://github.com/SuperFola +# @author https://github.com/SuperFola, https://github.com/kg583 (let permutations (fun ((mut _n) _k) (if (<= _k _n) {