math.factorials: more factorial words.

db4
John Benediktsson 2013-04-09 12:07:49 -07:00
parent 68cdaa2c69
commit 6c106fb422
2 changed files with 29 additions and 2 deletions

View File

@ -65,3 +65,9 @@ IN: math.factorials
[ 10 iota [ alternating-factorial ] map ] unit-test
{ { 1 1 2 9 262144 } } [ 5 iota [ exponential-factorial ] map ] unit-test
{ V{ 2 3 5 7 23 719 5039 } }
[ 10,000 iota [ factorial-prime? ] filter ] unit-test
{ V{ 3 5 7 29 31 211 2309 2311 } }
[ 10,000 iota [ primorial-prime? ] filter ] unit-test

View File

@ -1,8 +1,8 @@
! Copyright (C) 2013 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
USING: combinators fry kernel math math.functions math.primes
math.ranges memoize sequences ;
USING: combinators combinators.short-circuit fry kernel math
math.functions math.primes math.ranges memoize sequences ;
IN: math.factorials
@ -101,3 +101,24 @@ ALIAS: pochhammer rising-factorial
: exponential-factorial ( n -- m )
dup 1 > [ [1,b] 1 [ swap ^ ] reduce ] [ drop 1 ] if ;
: factorial-prime? ( n -- ? )
{
[ prime? ]
[
1 1 [ pick over - 1 <= ] [
drop [ 1 + ] [ factorial ] bi
] until nip - abs 1 =
]
} 1&& ;
: primorial-prime? ( n -- ? )
{
[ prime? ]
[ 2 > ]
[
1 1 [ pick over - 1 <= ] [
drop [ 1 + ] [ primorial ] bi
] until nip - abs 1 =
]
} 1&& ;