From fe0de617cddd2dee11758788c5dc9b7a1c8f330a Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Thu, 29 Feb 2024 23:28:51 +0100 Subject: great changes you gotta believe me, they're great. they're the best --- std/Math.bruijn | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) (limited to 'std/Math.bruijn') diff --git a/std/Math.bruijn b/std/Math.bruijn index cfea07c..ae67136 100644 --- a/std/Math.bruijn +++ b/std/Math.bruijn @@ -77,9 +77,6 @@ pow* z [[[rec]]] ⧗ Number → Number → Number ³‣ [0 ⋅ 0 ⋅ 0] case-end (+1) -# prime number sequence -primes nub ((…≠?… (+1)) ∘∘ gcd) (iterate ++‣ (+2)) ⧗ (List Number) - # factorial function fac [∏ (+1) → 0 | i] ⧗ Number → Number @@ -192,6 +189,19 @@ log* [z [[rec]] --0] ⧗ Number → Number # TODO: something is wrong in here pascal iterate [zip-with …+… ({}(+0) ++ 0) (0 ; (+0))] ({}(+1)) +# characteristic prime sequence by Tromp +characteristic-primes ki : (ki : (sieve s0)) ⧗ (List Bool) + sieve y [[k : ([(2 0) (y' 0)] (ssucc 0))]] + y' [[0 0] [1 (0 0)]] + ssucc [[[[1 : (0 (3 2))]]]] + s0 [[[ki : (0 2)]]] + +# prime number sequence +primes map fst (filter snd (zip (iterate ++‣ (+0)) characteristic-primes)) ⧗ (List Number) + +# slower but cooler prime number sequence +primes* nub ((…≠?… (+1)) ∘∘ gcd) (iterate ++‣ (+2)) ⧗ (List Number) + # π as a list of decimal digits # translation of unbounded spigot algorithm by Jeremy Gibbons # TODO: faster! -- cgit v1.2.3