math.factorials: implement "undo" for factorials.

char-rename
John Benediktsson 2016-11-29 16:56:48 -08:00
parent 1e2e2dc9f7
commit 8bdaf26d6b
1 changed files with 6 additions and 2 deletions

View File

@ -1,8 +1,8 @@
! Copyright (C) 2013 John Benediktsson ! Copyright (C) 2013 John Benediktsson
! See http://factorcode.org/license.txt for BSD license ! See http://factorcode.org/license.txt for BSD license
USING: combinators combinators.short-circuit fry kernel math USING: combinators combinators.short-circuit fry inverse kernel
math.functions math.primes math.ranges memoize sequences ; math math.functions math.primes math.ranges memoize sequences ;
IN: math.factorials IN: math.factorials
@ -121,3 +121,7 @@ PRIVATE>
: reverse-factorial ( m -- n ) : reverse-factorial ( m -- n )
1 1 [ 2over > ] [ 1 + [ * ] keep ] while [ = ] dip and ; 1 1 [ 2over > ] [ 1 + [ * ] keep ] while [ = ] dip and ;
\ factorial [ reverse-factorial ] define-inverse
\ reverse-factorial [ factorial ] define-inverse