diff options
Diffstat (limited to 'std/Math.bruijn')
-rw-r--r-- | std/Math.bruijn | 16 |
1 files changed, 13 insertions, 3 deletions
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! |