Paste: recurrence generator
Author: | rswarbrick |
Mode: | factor |
Date: | Tue, 15 Sep 2009 22:50:25 |
Plain Text |
USING: kernel sequences math locals ;
: mid-depth-clone ( seq -- seq' )
[ clone ] map ;
:: [recur-quot] ( vals quot -- quot' )
[
vals first2 quot call
vals second 0 vals set-nth 1 vals set-nth
] ; inline
:: 2-recurrence ( n start-vals quots -- end-vals )
start-vals mid-depth-clone
dup quots [ [recur-quot] ] 2map [ n ] dip
[ over 0 > ]
[ [ 1 - ] [ dup [ call ] each ] bi* ] while 2drop ; inline
Author: | rswarbrick |
Mode: | factor |
Date: | Tue, 15 Sep 2009 23:10:20 |
Plain Text |
:: [recur-quot] ( vals quot -- quot' )
[
vals first2 quot call
vals second vals set-first vals set-second
] ;
:: 2-recurrence ( n start-vals quot -- end-vals )
start-vals clone dup quot [recur-quot] [ n ] dip
[ over 0 > ]
[ [ 1 - ] [ dup call( -- ) ] bi* ] while 2drop ;
Author: | rswarbrick |
Mode: | factor |
Date: | Tue, 15 Sep 2009 23:26:59 |
Plain Text |
: 2-recurrence ( n start-vals quot -- a[n] )
[ first2 rot ] dip [ tuck ] prepose times nip ; inline
New Annotation