! See http://factorcode.org/license.txt for BSD license.
USING: accessors arrays assocs combinators
combinators.short-circuit fry generalizations grouping kernel
-locals math math.functions math.order math.ranges math.vectors
+locals math math.functions math.order ranges math.vectors
sequences sequences.private sorting ;
IN: math.statistics
M: object sum-of-squares [ sq ] map-sum ;
M: iota sum-of-squares
n>> 1 - [ ] [ 1 + ] [ 1/2 + ] tri * * 3 / ;
-M: math.ranges:range sum-of-squares
+M: ranges:range sum-of-squares
dup { [ step>> 1 = ] [ from>> integer? ] } 1&& [
[ from>> ] [ length>> ] bi dupd +
[ <iota> sum-of-squares ] bi@ swap -
GENERIC: sum-of-cubes ( seq -- x )
M: object sum-of-cubes [ 3 ^ ] map-sum ;
M: iota sum-of-cubes sum sq ;
-M: math.ranges:range sum-of-cubes
+M: ranges:range sum-of-cubes
dup { [ step>> 1 = ] [ from>> integer? ] } 1&& [
[ from>> ] [ length>> ] bi dupd +
[ <iota> sum-of-cubes ] bi@ swap -
* * * 30 /
] [ 0 ] if
] ;
-M: math.ranges:range sum-of-quads
+M: ranges:range sum-of-quads
dup { [ step>> 1 = ] [ from>> integer? ] } 1&& [
[ from>> ] [ length>> ] bi dupd +
[ <iota> sum-of-quads ] bi@ swap -