@@ -9,136 +9,221 @@ navhome: /docs/
10Set operations
10Set operations
12−Core whose arms contain a variety of functions that operate on `++set`s. Its sample accepts the input `++set` to be manipulated.
12+Core whose arms contain a variety of functions that operate on `set`s. Its
13+sample accepts the input `set` to be manipulated.
14−Accepts
15+#### Accepts
22− ++ in :: set engine
21+ ++ in
24− |_ a/(set)
23+ |_ a=(set)
26−Examples
25+#### Examples
29− > ~(. in (sa "asd"))
27+ > ~(. in (sy "asd"))
30 <13.evb [nlr(^$1{@tD $1}) <414.fvk 101.jzo 1.ypj %164>]>
28 <13.evb [nlr(^$1{@tD $1}) <414.fvk 101.jzo 1.ypj %164>]>
32### `+-all:in`
30### `+-all:in`
34Logical AND
32Logical AND
36−Computes the logical AND on every element in `a` slammed with `b`,
34+Computes the logical AND on every element in `a` slammed with `b`, producing a
37−producing a boolean.
35+flag.
39−Accepts
37+#### Accepts
42−`a` is a `++set`.
39+`a` is a `set`.
44−`b` is a wet gate that accepts a noun and produces a boolean.
41+`b` is a wet gate that accepts a noun and produces a flag.
46−Produces
43+#### Produces
54− +- all :: logical AND
49+ +- all
56− |* b/$-(* ?)
51+ |* b=$-(* ?)
60 ?&((b n.a) $(a l.a) $(a r.a))
55 ?&((b n.a) $(a l.a) $(a r.a))
66− > =b (sa `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
59+ > =b (sy `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
67− > (~(all in b) |=(a/* ?@(+.a & |)))
60+ > (~(all in b) |=(a=* ?@(+.a & |)))
69− > =b (sa `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
70− > (~(all in b) |=(a/@t (gte a 100)))
73−------------------------------------------------------------------------
63+ > =b (sy `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
64+ > (~(all in b) |=(a=@t (gte a 100)))
75### `+-any:in`
68### `+-any:in`
79−Computes the logical OR on every element of `a` slammed with `b`.
72+Computes the logical OR on every element of `a` slammed with `b`, producing a
81−Accepts
75+#### Accepts
84−`a` is a `++set`.
77+`a` is a `set`.
86−`b` is a gate that accepts a noun and produces a boolean.
79+`b` is a gate that accepts a noun and produces a flag.
88−Produces
81+#### Produces
96− +- any :: logical OR
87+ +- any
98− |* b/$-(* ?)
89+ |* b=$-(* ?)
102 ?|((b n.a) $(a l.a) $(a r.a))
93 ?|((b n.a) $(a l.a) $(a r.a))
106−Examples
96+#### Examples
109− > =b (sa `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
98+ > =b (sy `(list [@t *])`[['a' 1] ['b' [2 3]] ~])
110 > (~(any in b) |=(a/* ?@(+.a & |)))
99 > (~(any in b) |=(a/* ?@(+.a & |)))
112− > =b (sa `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
102+ > =b (sy `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
113− > (~(any in b) |=(a/@t (lte a 100)))
103+ > (~(any in b) |=(a=@t (lte a 100)))
116−------------------------------------------------------------------------
106+***
111+Computes whether `a` has a correct horizontal order and a correct vertical
112+order, producing a flag.
125+ =| [l=(unit) r=(unit)]
128+ ?& ?~(l & (hor n.a u.l))
129+ ?~(r & (hor u.r n.a))
130+ ?~(l.a & ?&((vor n.a n.l.a) $(a l.a, l `n.a)))
131+ ?~(r.a & ?&((vor n.a n.r.a) $(a r.a, r `n.a)))
139+ > =a (sy [1 2 3 4 5 6 ~])
140+ [n=6 l={5 4} r={1 3 2}]
146+ [n=7 l={5 4} r={1 3 2}]
153+See section [`2f`](../2f) for more information on noun ordering.
160+Splits set `a` into two sets `l` and `r`, with any noun `b` removed.
187+ [n.c l.c [n.a r.c r.a]]
190+ [n.c [n.a l.a l.c] r.c]
195+ > =a (sy `(list @)`[1 2 3 4 5 6 ~])
197+ [n=6 l={5 4} r={1 3 2}]
200+ [l=[n=4 l=[n=5 l={} r={}] r=~] r=[n=2 l=[n=1 l={} r={3}] r=~]]
203+ [l=[n=6 l=[n=4 l={5} r={}] r=[n=2 l={1 3} r={}]] r=~]
118### `+-del:in`
206### `+-del:in`
120Remove noun
208Remove noun
122−Removes `b` from the `++set` `a`.
210+Removes `b` from the `set` `a`.
124−Accepts
212+#### Accepts
127`a` is a set.
214`a` is a set.
129`b` is a noun.
216`b` is a noun.
131−Produces
218+#### Produces
136−Source
222+#### Source
139− +- del :: b without any a
224+ +- del
@@ -152,46 +237,95 @@ Source
152 ?: (vor n.l.a n.r.a)
237 ?: (vor n.l.a n.r.a)
153 [n.l.a l.l.a $(l.a r.l.a)]
238 [n.l.a l.l.a $(l.a r.l.a)]
154 [n.r.a $(r.a l.r.a) r.r.a]
239 [n.r.a $(r.a l.r.a) r.r.a]
161− > =b (sa `(list @t)`['a' 'b' 'c' ~])
245+ > =b (sy `(list @t)`['a' 'b' 'c' ~])
162 > (~(del in b) 'a')
246 > (~(del in b) 'a')
163 {'c' 'b'}
247 {'c' 'b'}
164− > =b (sa `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
249+ > =b (sy `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
165 > (~(del in b) 'john')
250 > (~(del in b) 'john')
166 {'bonita' 'madeleine' 'daniel'}
251 {'bonita' 'madeleine' 'daniel'}
167 > (~(del in b) 'susan')
253 > (~(del in b) 'susan')
168 {'bonita' 'madeleine' 'daniel' 'john'}
254 {'bonita' 'madeleine' 'daniel' 'john'}
170−------------------------------------------------------------------------
262+Computes the difference between `a` and `b`, producing the set of items in `a`
285+ =+ d=$(a l.c, b l.b)
286+ =+ e=$(a r.c, b r.b)
296+ > ((~(dif in (sy 1 2 3 ~)) (sy 2 3 4 ~))
299+ > (~(dif in (sy 2 3 4 ~)) (sy 1 2 3 ~))
302+ > `(set @ud)`((~(dif in (sy 1 2 3 ~)) (sy 2 3 4 ~))
305+ > `(set @ud)`(~(dif in (sy 2 3 4 ~)) (sy 1 2 3 ~))
172### `+-dig:in`
309### `+-dig:in`
174−Axis a in b
311+Address b in a
176−Produce the axis of `b` within `a`.
313+Produce the tree address of `b` within `a`.
178−Accepts
315+#### Accepts
181−`a` is a `++set`.
317+`a` is a set.
183`b` is a noun.
319`b` is a noun.
185−Produces
321+#### Produces
188−The `++unit` of an atom.
323+The `unit` of an atom.
190−Source
325+#### Source
193− +- dig :: axis of a in b
327+ +- dig
196 |- ^- (unit @)
330 |- ^- (unit @)
@@ -199,69 +333,71 @@ Source
199 ?: (hor b n.a)
333 ?: (hor b n.a)
200 $(a l.a, c (peg c 6))
334 $(a l.a, c (peg c 6))
201 $(a r.a, c (peg c 7))
335 $(a r.a, c (peg c 7))
206−Examples
339+#### Examples
209− > =a (sa `(list @)`[1 2 3 4 5 6 7 ~])
341+ > =a (sy `(list @)`[1 2 3 4 5 6 7 ~])
211 {5 4 7 6 1 3 2}
343 {5 4 7 6 1 3 2}
214 > (~(dig in a) 7)
348 > (~(dig in a) 7)
216 > (~(dig in a) 2)
351 > (~(dig in a) 2)
218 > (~(dig in a) 6)
354 > (~(dig in a) 6)
221−------------------------------------------------------------------------
357+#### Discussion
359+For more on the tree addressing system, see section [1b](../1b).
223### `+-gas:in`
362### `+-gas:in`
225Concatenate
364Concatenate
227−Insert the elements of a `++list` `b` into a `++set` `a`.
366+Insert the elements of a `list` `b` into a `set` `a`.
229−Accepts
368+#### Accepts
232`a` is a set.
370`a` is a set.
234`b` is a list.
372`b` is a list.
236−Produces
374+#### Produces
239−A `++set`.
376+A `set`.
241−Source
378+#### Source
244− +- gas :: concatenate
380+ +- gas
246− |= b/(list _?>(?=(^ a) n.a))
382+ |= b=(list _?>(?=(^ a) n.a))
250 $(b t.b, a (put i.b))
386 $(b t.b, a (put i.b))
254−Examples
389+#### Examples
258 {'bonita' 'madeleine' 'rudolf' 'john'}
392 {'bonita' 'madeleine' 'rudolf' 'john'}
259 > (~(gas in b) `(list @t)`['14' 'things' 'number' '1.337' ~])
394 > (~(gas in b) `(list @t)`['14' 'things' 'number' '1.337' ~])
260 {'1.337' '14' 'number' 'things' 'bonita' 'madeleine' 'rudolf' 'john'}
395 {'1.337' '14' 'number' 'things' 'bonita' 'madeleine' 'rudolf' 'john'}
261 > (~(gas in s) `(list ,@t)`['1' '2' '3' ~])
397 > (~(gas in s) `(list ,@t)`['1' '2' '3' ~])
262 {'1' '3' '2' 'e' 'd' 'a' 'c' 'b'}
398 {'1' '3' '2' 'e' 'd' 'a' 'c' 'b'}
264−------------------------------------------------------------------------
400+***
266### `+-has:in`
402### `+-has:in`
@@ -269,24 +405,21 @@ b in a?
270Checks if `b` is an element of `a`, producing a boolean.
406Checks if `b` is an element of `a`, producing a boolean.
272−Accepts
408+#### Accepts
275−`a` is a [`++set`]().
410+`a` is a set.
277−`b` is a [noun]().
412+`b` is a noun.
279−Produces
414+#### Produces
282A boolean.
416A boolean.
284−Source
418+#### Source
287− +- has :: b exists in a check
420+ +- has
@@ -298,42 +431,38 @@ Source
301−Examples
434+#### Examples
304− > =a (~(gas in `(set @t)`~) `(list @t)`[`a` `b` `c` ~])
436+ > =a (~(gas in `(set @t)`~) `(list @t)`['a' 'b' 'c' ~])
305− > (~(has in a) `a`)
437+ > (~(has in a) 'a')
307 > (~(has in a) 'z')
440 > (~(has in a) 'z')
310−------------------------------------------------------------------------
443+***
312### `+-int:in`
444### `+-int:in`
314Intersection
446Intersection
316−Produces a set of the intersection between two `++set`s of the same type,
448+Produces a set of the intersection between two sets of the same type,
317`a` and `b`.
449`a` and `b`.
319−Accepts
451+#### Accepts
322`a` is a set.
453`a` is a set.
324`b` is a set.
455`b` is a set.
326−Produces
457+#### Produces
329−A `++set`.
459+A `set`.
331−Source
461+#### Source
334− +- int :: intersection
463+ +- int
@@ -350,44 +479,42 @@ Source
353−Examples
482+#### Examples
356− > (~(int in (sa "ac")) (sa "ha"))
484+ > (~(int in `(set @t)`(sy "acmo")) `(set @t)`(sy "ham"))
357− {~~a}
485+ [n='m' l={'a'} r={}]
358− > (~(int in (sa "acmo")) ~)
360− > (~(int in (sa "acmo")) (sa "ham"))
362− > (~(int in (sa "acmo")) (sa "lep"))
365−------------------------------------------------------------------------
487+ > (~(int in (sy "acmo")) ~)
490+ > (~(int in `(set @t)`(sy "ac")) `(set @t)`(sy "ha"))
493+ > (~(int in (sy "acmo")) (sy "lep"))
367### `+-put:in`
497### `+-put:in`
369Put b in a
499Put b in a
371−Add an element `b` to the `++set` `a`.
501+Add an element `b` to the set `a`, producing a set.
373−Accepts
503+#### Accepts
376`a` is a set.
505`a` is a set.
378`b` is a noun.
507`b` is a noun.
380−Produces
509+#### Produces
383−A `++set`.
511+A `set`.
385−Source
513+#### Source
388− +- put :: puts b in a, sorted
515+ +- put
@@ -404,175 +531,152 @@ Source
404 ?: (vor n.a n.c)
531 ?: (vor n.a n.c)
405 [n.a l.a c]
532 [n.a l.a c]
406 [n.c [n.a l.a l.c] r.c]
533 [n.c [n.a l.a l.c] r.c]
410−Examples
536+#### Examples
413− > =a (~(gas in `(set @t)`~) `(list @t)`[`a` `b` `c` ~])
538+ > =a (~(gas in `(set @t)`~) `(list @t)`['a' 'b' 'c' ~])
414− > =b (~(put in a) `d`)
539+ > =b (~(put in a) 'd')
415− > b
540+ > `(set @t)`b
416− {`d` `a` `c` `b`}
541+ {'d' 'a' 'c' 'b'}
420−------------------------------------------------------------------------
543+ > -.l.+.b
422### `+-rep:in`
547### `+-rep:in`
424Accumulate
549Accumulate
426Accumulate the elements of `a` using a gate `b`.
551Accumulate the elements of `a` using a gate `b`.
428−Accepts
553+#### Accepts
431−`a` is a `++set`.
555+`a` is a `set`.
433`b` is a gate.
557`b` is a gate.
435−Produces
559+#### Produces
440−Source
563+#### Source
443 +- rep :: replace by product
565 +- rep :: replace by product
444− |* b/_|=({* *} +<+)
566+ |* b=_|=([* *] +<+)
446 ?~ a +<+.b
568 ?~ a +<+.b
447 $(a r.a, +<+.b $(a l.a, +<+.b (b n.a +<+.b)))
569 $(a r.a, +<+.b $(a l.a, +<+.b (b n.a +<+.b)))
451−Examples
573+#### Examples
454 > =a (~(gas in *(set @)) [1 2 3 ~])
575 > =a (~(gas in *(set @)) [1 2 3 ~])
455− > a
576+ > `(set @)`a
457− > (~(rep in a) |=([a/@ b/@] (add a b)))
460−------------------------------------------------------------------------
579+ > (~(rep in a) |=([a=@ b=@] (add a b)))
462### `+-run:in`
583### `+-run:in`
464−Apply gate to set (often called *map*)
585+Apply gate to set
466−Produce a `++set` containing the products of gate `b` applied to each element
587+Produce a `set` containing the products of gate `b` applied to each element
469−Accepts
590+#### Accepts
472−`a` is a `++set`.
592+`a` is a `set`.
474`b` is a gate.
594`b` is a gate.
476−Produces
596+#### Produces
481−Source
600+#### Source
484− +- run :: apply gate to values
602+ +- run
486− |* b/gate
604+ |* b=gate
487− =| c/(set _?>(?=(^ a) (b n.a)))
605+ =| c=(set _?>(?=(^ a) (b n.a)))
488 |- ?~ a c
606 |- ?~ a c
489 =. c (~(put in c) (b n.a))
607 =. c (~(put in c) (b n.a))
490 =. c $(a l.a, c c)
608 =. c $(a l.a, c c)
491 $(a r.a, c c)
609 $(a r.a, c c)
495−Examples
612+#### Examples
498 > =s (sy ~["a" "A" "b" "c"])
614 > =s (sy ~["a" "A" "b" "c"])
499− > s
615+ > `(set tape)`s
500 {"A" "a" "c" "b"}
616 {"A" "a" "c" "b"}
501− > (~(run in s) cuss)
504−------------------------------------------------------------------------
618+ > (~(run in s) cuss)
506### `+-tap:in`
622### `+-tap:in`
508Set to list
624Set to list
510−Flattens the `++set` `a` into a `++list`.
626+Flattens the `set` `a` into a `list`.
512−Accepts
628+#### Accepts
515`a` is an set.
630`a` is an set.
517−Produces
632+#### Produces
522−Source
636+#### Source
525− +- tap :: convert to list
638+ +- tap
527− |= b/(list _?>(?=(^ a) n.a))
640+ |= b=(list _?>(?=(^ a) n.a))
531 $(a r.a b [n.a $(a l.a)])
644 $(a r.a b [n.a $(a l.a)])
536−Examples
648+#### Examples
539− > =s (sa `(list @t)`['a' 'b' 'c' 'd' 'e' ~])
650+ > =s (sy `(list @t)`['a' 'b' 'c' 'd' 'e' ~])
541− {'e' 'd' 'a' 'c' 'b'}
652+ [n='e' l={} r={'d' 'a' 'c' 'b'}]
542− > (~(tap in s) `(list @t)`['1' '2' '3' ~])
543− ~['b' 'c' 'a' 'd' 'e' '1' '2' '3']
545− {'bonita' 'madeleine' 'daniel' 'john'}
546− ~zod/try=> (~(tap in b) `(list ,@t)`['david' 'people' ~])
547− ~['john' 'daniel' 'madeleine' 'bonita' 'david' 'people']
549−------------------------------------------------------------------------
654+ > ~(tap in s)
655+ ~['b' 'c' 'a' 'd' 'e']
551### `+-uni:in`
658### `+-uni:in`
555−Produces a set of the union between two [`++set`]()s of the same type, `a` and
662+Produces a set of the union between two sets of the same type, `a` and
558−Accepts
665+#### Accepts
561`a` is a set.
667`a` is a set.
563`b` is a set.
669`b` is a set.
565−Produces
671+#### Produces
570−Source
675+#### Source
573− +- uni :: union
677+ +- uni
576 ?: =(a b) a
680 ?: =(a b) a
@@ -593,38 +697,37 @@ Source
599− > (~(uni in (sa "ac")) (sa "ha"))
703+ > (~(uni in `(set @t)`(sy "ac")) `(set @)`(sy "ha"))
600− {~~a ~~c ~~h}
704+ [n='c' l={'a'} r={'h'}]
601− > (~(uni in (sa "acmo")) ~)
706+ > (~(uni in `(set @t)`(sy "acmo")) ~)
602− {~~a ~~c ~~m ~~o}
707+ [n='c' l={'a'} r={'m' 'o'}]
603− > (~(uni in (sa "acmo")) (sa "ham"))
709+ > (~(uni in `(set @t)`(sy "acmo")) `(set @t)`(sy "ham"))
604− {~~a ~~c ~~m ~~o ~~h}
605− > (~(uni in (sa "acmo")) (sa "lep"))
606− {~~e ~~a ~~c ~~m ~~l ~~o ~~p}
710+ [n='c' l={'a'} r={'m' 'o' 'h'}]
608−------------------------------------------------------------------------
712+ > (~(uni in `(set @t)`(sy "acmo")) `(set @t)`(sy "lep"))
713+ [n='e' l={} r={'a' 'c' 'm' 'l' 'o' 'p'}]
610### `+-wyt:in`
716### `+-wyt:in`
614−Produce the number of elements in [`++set`]() `a` as an atom.
720+Produces the number of elements in set `a` as an atom.
616−Accepts
722+#### Accepts
619`a` is an set.
724`a` is an set.
621−Produces
726+#### Produces
626−Source
730+#### Source
629 +- wyt :: size of set
732 +- wyt :: size of set
@@ -633,14 +736,13 @@ Source
636−Examples
739+#### Examples
639− > =a (~(put in (~(put in (sa)) 'a')) 'b')
741+ > =a (~(put in (~(put in (sy)) 'a')) 'b')
640 > ~(wyt in a)
742 > ~(wyt in a)
643− {'bonita' 'madeleine' 'daniel' 'john'}
745+ > =b (sy `(list @t)`['john' 'bonita' 'daniel' 'madeleine' ~])
644 > ~(wyt in b)
746 > ~(wyt in b)