Range now uses minmax

cvs
Doug Coleman 2005-11-13 19:07:59 +00:00
parent 16454ccb99
commit 4b607b6b3e
1 changed files with 7 additions and 1 deletions

View File

@ -1,6 +1,8 @@
IN: math-contrib IN: math-contrib
USING: kernel math sequences ; USING: kernel math sequences ;
: mean ( seq -- n ) : mean ( seq -- n )
#! arithmetic mean, sum divided by length #! arithmetic mean, sum divided by length
[ sum ] keep length / ; [ sum ] keep length / ;
@ -21,9 +23,13 @@ USING: kernel math sequences ;
2 /i swap nth 2 /i swap nth
] if ; ] if ;
: minmax ( seq -- min max )
#! find the min and max of a seq in one pass
inf -inf rot [ dup pick max -rot nip pick min -rot nip ] each ;
: range ( seq -- n ) : range ( seq -- n )
#! max - min #! max - min
dup first 2dup [ min ] reduce >r [ max ] reduce r> - ; minmax swap - ;
: var ( seq -- ) : var ( seq -- )
#! variance, normalize by N-1 #! variance, normalize by N-1