BACKWARD-ANALYSIS: anticip
M: anticip transfer-set drop transfer-peeked-locs ;
-M: anticip join-sets 2drop refine ;
+M: anticip join-sets 2drop intersect-all ;
BACKWARD-ANALYSIS: live
M: live transfer-set drop transfer-peeked-locs ;
-M: live join-sets 2drop combine ;
+M: live join-sets 2drop union-all ;
FORWARD-ANALYSIS: avail
M: avail transfer-set ( in-set bb dfa -- out-set )
drop [ peeks>> ] [ replaces>> ] bi union union ;
-M: avail join-sets 2drop refine ;
+M: avail join-sets 2drop intersect-all ;
FORWARD-ANALYSIS: pending
M: pending transfer-set
drop replaces>> union ;
-M: pending join-sets 2drop refine ;
+M: pending join-sets 2drop intersect-all ;
BACKWARD-ANALYSIS: dead
M: dead transfer-set
drop [ kills>> ] [ replaces>> ] bi union union ;
-M: dead join-sets 2drop refine ;
+M: dead join-sets 2drop intersect-all ;
first2 swapd remove 2array ;
: combine-stacks ( stacks -- stack )
- [ first first ] [ [ second ] map sets:combine ] bi 2array ;
+ [ first first ] [ [ second ] map sets:union-all ] bi 2array ;
: classify-read ( stack n -- val )
swap 2dup second member? [ 2drop 2 ] [ first >= [ 1 ] [ 0 ] if ] if ;
: meaningful-integers ( partition table -- integers )
[ [ in>> ] [ out>> ] bi ] dip
- '[ [ _ at ] map refine ] bi@ diff ;
+ '[ [ _ at ] map intersect-all ] bi@ diff ;
: class-integers ( classes integers -- table )
'[ _ over '[ _ class-member? ] filter ] H{ } map>assoc ;
assoc>> >alist ;
: (keyword-map-no-word-sep) ( assoc -- str )
- keys combine [ alpha? ] reject natural-sort ;
+ keys union-all [ alpha? ] reject natural-sort ;
: keyword-map-no-word-sep* ( keyword-map -- str )
dup no-word-sep>> [ ] [
maybe-changed get members
changed-definitions get members
[ always-bump-effect-counter? ] filter
- 3array combine new-words get [ in? not ] curry any? ;
+ 3array union-all new-words get [ in? not ] curry any? ;
: bump-effect-counter ( -- )
bump-effect-counter? [
}
"Operations on groups of sets:"
{ $subsections
- combine
- refine
+ union-all
+ intersect-all
}
"An optional generic word for creating sets of the same class as a given set:"
{ $subsections set-like }
{ $values { "set" set } { "n" "a non-negative integer" } }
{ $description "Returns the number of elements in the set. All sets support this operation." } ;
-HELP: refine
+HELP: intersect-all
{ $values { "sets" sequence } { "set/f" { $maybe set } } }
{ $description "Outputs the intersection of all the sets of the sequence " { $snippet "sets" } ", or " { $link f } " if " { $snippet "sets" } " is empty." } ;
-HELP: combine
+HELP: union-all
{ $values { "sets" { $sequence set } } { "set/f" { $maybe set } } }
{ $description "Outputs the union of a sequence of sets, or " { $link f } " if the sequence is empty." } ;
{ { 1 } } [ { 1 2 3 } { 2 3 4 } without ] unit-test
{ { 1 1 } } [ { 1 1 2 3 3 } { 2 3 4 4 } without ] unit-test
-{ f } [ { } combine ] unit-test
-{ { 1 2 3 } } [ { { 1 } { 2 } { 1 3 } } combine ] unit-test
+{ f } [ { } union-all ] unit-test
+{ { 1 2 3 } } [ { { 1 } { 2 } { 1 3 } } union-all ] unit-test
-{ f } [ { } refine ] unit-test
-{ HS{ } } [ { HS{ } } refine ] unit-test
-{ HS{ 1 } } [ { HS{ 1 2 3 } HS{ 1 } } refine ] unit-test
-{ { 2 } } [ { { 2 3 } { 2 4 } { 9 8 4 2 } } refine ] unit-test
+{ f } [ { } intersect-all ] unit-test
+{ HS{ } } [ { HS{ } } intersect-all ] unit-test
+{ HS{ 1 } } [ { HS{ 1 2 3 } HS{ 1 } } intersect-all ] unit-test
+{ { 2 } } [ { { 2 3 } { 2 4 } { 9 8 4 2 } } intersect-all ] unit-test
{ { 1 4 9 16 25 36 } }
[ { { 1 2 3 } { 4 5 6 } } [ [ sq ] map ] gather ] unit-test
M: sequence clear-set
delete-all ; inline
-: combine ( sets -- set/f )
+: union-all ( sets -- set/f )
[ f ]
[ [ [ ?members ] map concat ] [ first ] bi set-like ]
if-empty ;
-: refine ( sets -- set/f )
+: intersect-all ( sets -- set/f )
[ f ] [ [ ] [ intersect ] map-reduce ] if-empty ;
: gather ( ... seq quot: ( ... elt -- ... elts ) -- ... newseq )
PRIVATE>
: euler004 ( -- answer )
- source-004 dup [ * ] cartesian-map combine max-palindrome ;
+ source-004 dup [ * ] cartesian-map union-all max-palindrome ;
! [ euler004 ] 100 ave-time
! 1164 ms ave run time - 39.35 SD (100 trials)
: topological-sort ( seq -- seq )
[ [ (topological-sort) ] { } make ] keep
- combine over diff append ;
+ union-all over diff append ;
: euler079 ( -- answer )
source-079 >edges topological-sort digits>number ;
[ 0 prefix ] [ 0 suffix ] bi v+ ;
: generate ( n -- seq )
- 1 - { 1 } [ (generate) ] iterate combine ;
+ 1 - { 1 } [ (generate) ] iterate union-all ;
: squarefree ( n -- ? )
factors all-unique? ;
SynKeywordFactorWord factorWord_memory | syn keyword factorWord_memory contained all-instances compact-gc gc instances minor-gc save save-image save-image-and-exit saving-path size
SynKeywordFactorWord factorWord_namespaces | syn keyword factorWord_namespaces contained +@ change change-global counter dec get get-global get-namestack global inc init-namespaces initialize namespace off on set set-global set-namestack toggle with-global with-scope with-variable with-variable-off with-variable-on with-variables
SynKeywordFactorWord factorWord_sequences | syn keyword factorWord_sequences contained 1sequence 2all? 2each 2each-from 2map 2map-as 2map-reduce 2reduce 2selector 2sequence 3append 3append-as 3each 3map 3map-as 3sequence 4sequence <iota> <repetition> <reversed> <slice> ?first ?last ?nth ?second ?set-nth accumulate accumulate! accumulate* accumulate*! accumulate*-as accumulate-as all? any? append append! append-as assert-sequence assert-sequence= assert-sequence? binary-reduce bounds-check bounds-check? bounds-error bounds-error? but-last but-last-slice cartesian-each cartesian-find cartesian-map cartesian-product cartesian-product-as change-nth check-slice clone-like collapse-slice collector collector-as collector-for collector-for-as concat concat-as copy count cut cut* cut-slice delete-all delete-slice drop-prefix each each-from each-index empty? exchange filter filter! filter-as find find-from find-index find-index-from find-last find-last-from first first2 first3 first4 flip follow fourth glue glue-as halves harvest head head* head-slice head-slice* head? if-empty immutable immutable-sequence immutable-sequence? immutable? index index-from indices infimum infimum-by insert-nth interleave iota iota? join join-as last last-index last-index-from length lengthen like longer longer? longest map map! map-as map-find map-find-last map-index map-index-as map-integers map-reduce map-sum max-length member-eq? member? midpoint@ min-length mismatch move new-like new-resizable new-sequence non-negative-integer-expected non-negative-integer-expected? none? nth nths pad-head pad-tail partition pop pop* prefix prepend prepend-as produce produce-as product push push-all push-either push-if reduce reduce-index reject reject! reject-as remove remove! remove-eq remove-eq! remove-nth remove-nth! repetition repetition? replace-slice replicate replicate-as rest rest-slice reverse reverse! reversed reversed? second selector selector-as sequence sequence-hashcode sequence= sequence? set-first set-fourth set-last set-length set-nth set-second set-third short shorten shorter shorter? shortest sift slice slice-error slice-error? slice? snip snip-slice subseq subseq-as subseq-start subseq-start-from subseq? suffix suffix! sum sum-lengths supremum supremum-by surround surround-as tail tail* tail-slice tail-slice* tail? third trim trim-head trim-head-slice trim-slice trim-tail trim-tail-slice unclip unclip-last unclip-last-slice unclip-slice unless-empty virtual-exemplar virtual-sequence virtual-sequence? virtual@ when-empty
-SynKeywordFactorWord factorWord_sets | syn keyword factorWord_sets contained ?adjoin ?delete adjoin adjoin-all adjoin-at all-unique? cardinality clear-set combine delete diff diff! duplicates fast-set gather in? intersect intersect! intersects? members null? refine set set-like set= set? subset? union union! within without
+SynKeywordFactorWord factorWord_sets | syn keyword factorWord_sets contained ?adjoin ?delete adjoin adjoin-all adjoin-at all-unique? cardinality clear-set union-all delete diff diff! duplicates fast-set gather in? intersect intersect! intersects? members null? intersect-all set set-like set= set? subset? union union! within without
SynKeywordFactorWord factorWord_sorting | syn keyword factorWord_sorting contained inv-sort-with natural-sort sort sort-keys sort-pair sort-values sort-with
SynKeywordFactorWord factorWord_splitting | syn keyword factorWord_splitting contained ?head ?head-slice ?tail ?tail-slice replace split split-indices split-slice split-subseq split-when split-when-slice split1 split1-last split1-last-slice split1-slice split1-when split1-when-slice string-lines
SynKeywordFactorWord factorWord_strings | syn keyword factorWord_strings contained 1string <string> >string resize-string string string?