math.factorials: more factorial words.
parent
64a1b15d4b
commit
68cdaa2c69
extra/math/factorials
|
@ -60,3 +60,8 @@ IN: math.factorials
|
|||
{ { 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
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
! 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
|
||||
|
@ -91,3 +91,13 @@ ALIAS: pochhammer rising-factorial
|
|||
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 ;
|
||||
|
|
Loading…
Reference in New Issue