[ 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
! 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
: 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&& ;