{ { 1 1 2 12 288 } } [ 5 iota [ super-factorial ] map ] unit-test
{ { 1 1 4 108 27648 } } [ 5 iota [ hyper-factorial ] map ] unit-test
+
+{ { 1 1 1 5 19 101 619 4421 35899 326981 } }
+[ 10 iota [ alternating-factorial ] map ] unit-test
+
+{ { 1 1 2 9 262144 } } [ 5 iota [ exponential-factorial ] map ] unit-test
! Copyright (C) 2013 John Benediktsson
! See http://factorcode.org/license.txt for BSD license
-USING: combinators kernel math math.functions math.primes
+USING: combinators fry kernel math math.functions math.primes
math.ranges memoize sequences ;
IN: math.factorials
dup 1 > [
[1,b] [ dup ^ ] [ * ] map-reduce
] [ drop 1 ] if ;
+
+: alternating-factorial ( n -- m )
+ dup 1 > [
+ [ [1,b] ] keep even? '[
+ [ factorial ] [ odd? _ = ] bi [ neg ] when
+ ] map-sum
+ ] [ drop 1 ] if ;
+
+: exponential-factorial ( n -- m )
+ dup 1 > [ [1,b] 1 [ swap ^ ] reduce ] [ drop 1 ] if ;