From 0b77800262b5c46d994e6cb6159f773de8a05c51 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 14 Mar 2024 13:53:46 +0100 Subject: More samples --- std/Math.bruijn | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'std/Math.bruijn') diff --git a/std/Math.bruijn b/std/Math.bruijn index 78e3006..5952592 100644 --- a/std/Math.bruijn +++ b/std/Math.bruijn @@ -60,12 +60,15 @@ product L.foldl mul (+1) ⧗ (List Number) → Number :test (∏ (+1) → (+3) | ++‣) ((+24)) -# greatest common divisor -gcd z [[[1 =? 0 case-eq (1 >? 0 case-gre case-les)]]] ⧗ Number → Number → Number +# greatest common divisor using repeated subtraction +gcd* z [[[1 =? 0 case-eq (1 >? 0 case-gre case-les)]]] ⧗ Number → Number → Number case-eq 1 case-gre 2 (1 - 0) 0 case-les 2 1 (0 - 1) +# greatest common divisor using modulo (mostly faster than gcd*) +gcd z [[[=?0 1 (2 0 (1 % 0))]]] ⧗ Number → Number → Number + :test ((gcd (+2) (+4)) =? (+2)) (true) :test ((gcd (+10) (+5)) =? (+5)) (true) :test ((gcd (+3) (+8)) =? (+1)) (true) -- cgit v1.2.3