0 mean-ddof ; inline
: meanest ( seq -- x )
- [ mean ] keep [ - abs ] with infimum-by ;
+ [ mean ] keep [ - abs ] with minimum-by ;
GENERIC: sum-of-squares ( seq -- x )
M: object sum-of-squares [ sq ] map-sum ;
dup recip <array> ; inline
: mode ( seq -- x )
- histogram >alist [ second ] supremum-by first ;
+ histogram >alist [ second ] maximum-by first ;
: minmax ( seq -- min max )
[ first dup ] keep [ [ min ] [ max ] bi-curry bi* ] 1 each-from ;
}
{ $errors "Throws an error if the sequence is empty." } ;
-HELP: infimum-by
+HELP: minimum-by
{ $values
{ "seq" sequence } { "quot" quotation }
{ "elt" object }
{ $examples
"Example:"
{ $example "USING: sequences prettyprint ;"
- "{ { 1 2 } { 1 2 3 } { 1 2 3 4 } } [ length ] infimum-by ."
+ "{ { 1 2 } { 1 2 3 } { 1 2 3 4 } } [ length ] minimum-by ."
"{ 1 2 }"
}
}
}
{ $errors "Throws an error if the sequence is empty." } ;
-HELP: supremum-by
+HELP: maximum-by
{ $values
{ "seq" sequence } { "quot" quotation }
{ "elt" object }
{ $examples
"Example:"
{ $example "USING: sequences prettyprint ;"
- "{ { 1 2 } { 1 2 3 } { 1 2 3 4 } } [ length ] supremum-by ."
+ "{ { 1 2 } { 1 2 3 } { 1 2 3 4 } } [ length ] maximum-by ."
"{ 1 2 3 4 }"
}
}
{ $errors "Throws an error if the sequence is empty." } ;
-{ min max minimum infimum-by maximum supremum-by } related-words
+{ min max minimum minimum-by maximum maximum-by } related-words
HELP: shortest
{ $values { "seqs" sequence } { "elt" object } }
"Superlatives with " { $link min } " and " { $link max } ":"
{ $subsections
minimum
- infimum-by
+ minimum-by
maximum
- supremum-by
+ maximum-by
shorter
longer
shorter?
{ 4 } [ 5 <iota> maximum ] unit-test
{ 0 } [ 5 <iota> minimum ] unit-test
-{ 4 } [ 5 <iota> [ ] supremum-by ] unit-test
-{ 0 } [ 5 <iota> [ ] infimum-by ] unit-test
-{ "bar" } [ { "bar" "baz" "qux" } [ length ] supremum-by ] unit-test
-{ "bar" } [ { "bar" "baz" "qux" } [ length ] infimum-by ] unit-test
-{ { "foo" } } [ { { "foo" } { "bar" } } [ first ] supremum-by ] unit-test
-{ { "bar" } } [ { { "foo" } { "bar" } } [ first ] infimum-by ] unit-test
-{ -2 1 } [ -2 { 1 2 3 } [ over ^ ] supremum-by ] unit-test
-{ -2 3 } [ -2 { 1 2 3 } [ over ^ ] infimum-by ] unit-test
+{ 4 } [ 5 <iota> [ ] maximum-by ] unit-test
+{ 0 } [ 5 <iota> [ ] minimum-by ] unit-test
+{ "bar" } [ { "bar" "baz" "qux" } [ length ] maximum-by ] unit-test
+{ "bar" } [ { "bar" "baz" "qux" } [ length ] minimum-by ] unit-test
+{ { "foo" } } [ { { "foo" } { "bar" } } [ first ] maximum-by ] unit-test
+{ { "bar" } } [ { { "foo" } { "bar" } } [ first ] minimum-by ] unit-test
+{ -2 1 } [ -2 { 1 2 3 } [ over ^ ] maximum-by ] unit-test
+{ -2 3 } [ -2 { 1 2 3 } [ over ^ ] minimum-by ] unit-test
{ { 0 0 255 } } [
{
{ 0 255 215 }
{ 135 0 95 }
{ 255 0 175 }
- } [ { 0 0 255 } distance ] infimum-by
+ } [ { 0 0 255 } distance ] minimum-by
] unit-test
[ -1 0 <repetition> ] must-fail
PRIVATE>
-: supremum-by ( ... seq quot: ( ... elt -- ... x ) -- ... elt )
+: maximum-by ( ... seq quot: ( ... elt -- ... x ) -- ... elt )
[ after? ] select-by ; inline
-: infimum-by ( ... seq quot: ( ... elt -- ... x ) -- ... elt )
+: minimum-by ( ... seq quot: ( ... elt -- ... x ) -- ... elt )
[ before? ] select-by ; inline
-: shortest ( seqs -- elt ) [ length ] infimum-by ;
+ALIAS: supremum-by maximum-by deprecated
+ALIAS: infimum-by minimum-by deprecated
-: longest ( seqs -- elt ) [ length ] supremum-by ;
+: shortest ( seqs -- elt ) [ length ] minimum-by ;
+
+: longest ( seqs -- elt ) [ length ] maximum-by ;
! We hand-optimize flip to such a degree because type hints
! cannot express that an array is an array of arrays yet, and
: color>ansi ( color -- ansi bold? )
color>rgb '[ _ distance ]
- colors [ keys swap infimum-by ] [ at ] bi
+ colors [ keys swap minimum-by ] [ at ] bi
dup 8 >= [ 8 - t ] [ f ] if ;
MEMO: color>foreground ( color -- string )
V{ } clone 0 bin boa ; inline
: smallest-bin ( bins -- bin )
- [ total>> ] infimum-by ; inline
+ [ total>> ] minimum-by ; inline
: add-to-bin ( item weight bin -- )
[ + ] change-total items>> push ;
: euler066 ( -- D )
1000 [1..b] [ perfect-square? ] reject
- [ minimal-x ] supremum-by ;
+ [ minimal-x ] maximum-by ;
SOLUTION: euler066
: first-subseq ( seq separators -- n separator )
tuck
[ [ subseq-index ] dip 2array ] withd map-index sift-keys
- [ drop f f ] [ [ first ] infimum-by first2 rot nth ] if-empty ;
+ [ drop f f ] [ [ first ] minimum-by first2 rot nth ] if-empty ;
: multisplit ( string separators -- seq )
'[