diff options
author | Marvin Borner | 2025-03-05 20:47:24 +0100 |
---|---|---|
committer | Marvin Borner | 2025-03-05 20:47:24 +0100 |
commit | 78e6b29cb7d95c2ef5984a98a4028406b0977f57 (patch) | |
tree | 5e67fbc8c2706a651ce29257dd3f4c709283744f /std/Math.bruijn | |
parent | dfa4124ed6c503015ed8d0c7375611038f5a5a74 (diff) |
Better primality test
Diffstat (limited to 'std/Math.bruijn')
-rw-r--r-- | std/Math.bruijn | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/std/Math.bruijn b/std/Math.bruijn index 84cfae2..534afae 100644 --- a/std/Math.bruijn +++ b/std/Math.bruijn @@ -223,8 +223,7 @@ pascal L.iterate [L.zip-with …+… (L.{}(+0) ++ 0) (0 ; (+0))] (L.{}(+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)]] + sieve y [[k : ([(2 0) (y 0)] (ssucc 0))]] ssucc [[[[1 : (0 (3 2))]]]] s0 [[[ki : (0 2)]]] @@ -237,6 +236,12 @@ primes* L.nub ((…≠?… (+1)) ∘∘ gcd) (L.iterate ++‣ (+2)) ⧗ (List Nu # primality test prime? L.index characteristic-primes ⧗ Number → Boolean +:test (prime? (+2)) ([[1]]) +:test (prime? (+3)) ([[1]]) +:test (prime? (+4)) ([[0]]) +:test (prime? (+5)) ([[1]]) +:test (prime? (+6)) ([[0]]) + # prime factors factors \divs primes ⧗ Number → (List Number) divs y [[&[[&[[3 ⋅ 3 >? 4 case-1 (=?0 case-2 case-3)]] (quot-rem 2 1)]]]] |