From 78e6b29cb7d95c2ef5984a98a4028406b0977f57 Mon Sep 17 00:00:00 2001 From: Marvin Borner Date: Wed, 5 Mar 2025 20:47:24 +0100 Subject: Better primality test --- std/Math.bruijn | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'std/Math.bruijn') 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)]]]] -- cgit v1.2.3