1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
|
<head>
<link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/>
<link href="../style.css" rel="stylesheet"/>
<title>BQN: Prefixes and Suffixes</title>
</head>
<div class="nav"><a href="https://github.com/mlochbaum/BQN">BQN</a> / <a href="../index.html">main</a> / <a href="index.html">doc</a></div>
<h1 id="prefixes-and-suffixes">Prefixes and Suffixes</h1>
<p>The Prefixes (<code><span class='Function'>↑</span></code>) function gives a list of all prefixes of its argument array along the <a href="leading.html">first axis</a>, and Suffixes (<code><span class='Function'>↓</span></code>) gives a similar list for suffixes. Because the result can be much larger than the argument, these functions may not be used often in high-performance code, but they are a powerful conceptual tool and can make sense for algorithms that are inherently quadratic.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oaRICJhYmNkZSIK4oaTICJhYmNkZSI=">↗️</a><pre> <span class='Function'>↑</span> <span class='String'>"abcde"</span>
⟨ ⟨⟩ "a" "ab" "abc" "abcd" "abcde" ⟩
<span class='Function'>↓</span> <span class='String'>"abcde"</span>
⟨ "abcde" "bcde" "cde" "de" "e" ⟨⟩ ⟩
</pre>
<p>The functions are closely related to <a href="take.html">Take and Drop</a>, as we might expect from their glyphs. Element <code><span class='Value'>i</span><span class='Function'>⊑↑</span><span class='Value'>𝕩</span></code> is <code><span class='Value'>i</span><span class='Function'>↑</span><span class='Value'>𝕩</span></code>, and <code><span class='Value'>i</span><span class='Function'>⊑↓</span><span class='Value'>𝕩</span></code> is <code><span class='Value'>i</span><span class='Function'>↓</span><span class='Value'>𝕩</span></code>.</p>
<p>In both cases, an empty array and the entire argument are included in the result, meaning its length is one more than that of the argument. Using <a href="logic.html">Span</a>, we can say that the result has elements whose lengths go from <code><span class='Number'>0</span></code> to <code><span class='Function'>≠</span><span class='Value'>𝕩</span></code>, inclusive, so there are <code><span class='Paren'>(</span><span class='Function'>≠</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>¬</span><span class='Number'>0</span></code> or <code><span class='Number'>1</span><span class='Function'>+≠</span><span class='Value'>𝕩</span></code> elements. The total number or cells in the result (for example, <code><span class='Function'>≠∾↑</span><span class='Value'>𝕩</span></code> or <code><span class='Function'>+</span><span class='Modifier'>´</span><span class='Function'>≠</span><span class='Modifier'>¨</span><span class='Function'>↑</span><span class='Value'>𝕩</span></code>) scales with the square of the argument length—it is quadratic in <code><span class='Function'>≠</span><span class='Value'>𝕩</span></code>. We can find the exact total by looking at Prefixes and Suffixes together:</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KOKGkSDiiY3LmCDihpMpICJhYmNkZSIKKOKGkSDiiL7CqCDihpMpICJhYmNkZSI=">↗️</a><pre> <span class='Paren'>(</span><span class='Function'>↑</span> <span class='Function'>≍</span><span class='Modifier'>˘</span> <span class='Function'>↓</span><span class='Paren'>)</span> <span class='String'>"abcde"</span>
┌─
╵ ⟨⟩ "abcde"
"a" "bcde"
"ab" "cde"
"abc" "de"
"abcd" "e"
"abcde" ⟨⟩
┘
<span class='Paren'>(</span><span class='Function'>↑</span> <span class='Function'>∾</span><span class='Modifier'>¨</span> <span class='Function'>↓</span><span class='Paren'>)</span> <span class='String'>"abcde"</span>
⟨ "abcde" "abcde" "abcde" "abcde" "abcde" "abcde" ⟩
</pre>
<p>Joining corresponding elements of <code><span class='Function'>↑</span><span class='Value'>𝕩</span></code> and <code><span class='Function'>↓</span><span class='Value'>𝕩</span></code> gives <code><span class='Value'>𝕩</span></code> again. This is because <code><span class='Value'>i</span><span class='Function'>⊑</span><span class='Paren'>(</span><span class='Function'>↑∾</span><span class='Modifier'>¨</span><span class='Function'>↓</span><span class='Paren'>)</span><span class='Value'>𝕩</span></code> is <code><span class='Paren'>(</span><span class='Value'>i</span><span class='Function'>⊑↑</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>∾</span><span class='Paren'>(</span><span class='Value'>i</span><span class='Function'>⊑↓</span><span class='Value'>𝕩</span><span class='Paren'>)</span></code>, or, using the Take and Drop correspondences, <code><span class='Paren'>(</span><span class='Value'>i</span><span class='Function'>↑</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>∾</span><span class='Paren'>(</span><span class='Value'>i</span><span class='Function'>↓</span><span class='Value'>𝕩</span><span class='Paren'>)</span></code>, which is <code><span class='Value'>𝕩</span></code>. Element-wise, we are combining the first <code><span class='Value'>i</span></code> cells of <code><span class='Value'>𝕩</span></code> with all but the first <code><span class='Value'>i</span></code>. Looking at the entire result, we now know that <code><span class='Paren'>(</span><span class='Function'>↑∾</span><span class='Modifier'>¨</span><span class='Function'>↓</span><span class='Paren'>)</span><span class='Value'>𝕩</span></code> is <code><span class='Paren'>(</span><span class='Number'>1</span><span class='Function'>+≠</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>⥊<</span><span class='Value'>𝕩</span></code>. The total number of cells in this combined array is therefore <code><span class='Paren'>(</span><span class='Number'>1</span><span class='Function'>+≠</span><span class='Value'>𝕩</span><span class='Paren'>)</span><span class='Function'>×≠</span><span class='Value'>𝕩</span></code>, or <code><span class='Number'>1</span><span class='Modifier2'>⊸</span><span class='Function'>+</span><span class='Modifier2'>⊸</span><span class='Function'>×≠</span><span class='Value'>𝕩</span></code>. Each of Prefixes and Suffixes must have the same total number of cells (in fact, <code><span class='Function'>↑</span><span class='Value'>𝕩</span></code> is <code><span class='Function'>⌽</span><span class='Modifier'>¨</span><span class='Modifier2'>∘</span><span class='Function'>↓</span><span class='Modifier2'>⌾</span><span class='Function'>⌽</span><span class='Value'>𝕩</span></code>, and Reverse doesn't change an array's shape). So the total number in either one is <code><span class='Number'>2</span><span class='Function'>÷</span><span class='Modifier'>˜</span><span class='Number'>1</span><span class='Modifier2'>⊸</span><span class='Function'>+</span><span class='Modifier2'>⊸</span><span class='Function'>×≠</span><span class='Value'>𝕩</span></code>. With <code><span class='Value'>n</span><span class='Gets'>←</span><span class='Function'>≠</span><span class='Value'>𝕩</span></code>, it is <code><span class='Number'>2</span><span class='Function'>÷</span><span class='Modifier'>˜</span><span class='Value'>n</span><span class='Function'>×</span><span class='Number'>1</span><span class='Function'>+</span><span class='Value'>n</span></code>.</p>
<h2 id="definition">Definition</h2>
<p>Knowing the <a href="shape.html">length</a> and the elements, it's easy to define functions for Prefixes and Suffixes: <code><span class='Function'>↑</span></code> is equivalent to <code><span class='Paren'>(</span><span class='Function'>↕</span><span class='Number'>1</span><span class='Function'>+≠</span><span class='Paren'>)</span><span class='Function'>↑</span><span class='Modifier'>¨</span><span class='Function'><</span></code> while <code><span class='Function'>↓</span></code> is <code><span class='Paren'>(</span><span class='Function'>↕</span><span class='Number'>1</span><span class='Function'>+≠</span><span class='Paren'>)</span><span class='Function'>↓</span><span class='Modifier'>¨</span><span class='Function'><</span></code>. Each primitive is defined only on arrays with at least one axis.</p>
<h2 id="working-with-pairs">Working with pairs</h2>
<p>Sometimes it's useful to apply an operation to every unordered pair of elements from a list. For example, consider all possible products of numbers between 1 and 6:</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=w5fijJzLnCAxK+KGlTY=">↗️</a><pre> <span class='Function'>×</span><span class='Modifier'>⌜˜</span> <span class='Number'>1</span><span class='Function'>+↕</span><span class='Number'>6</span>
┌─
╵ 1 2 3 4 5 6
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24
5 10 15 20 25 30
6 12 18 24 30 36
┘
</pre>
<p>It's easy enough to use the <a href="map.html#table">Table</a> modifier here, but it also computes most products twice. If we only care about the unique products, we could multiply each number by all the ones after it. "After" sounds like suffixes, so let's look at those:</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MSvihpU2CuKGkyAxK+KGlTY=">↗️</a><pre> <span class='Number'>1</span><span class='Function'>+↕</span><span class='Number'>6</span>
⟨ 1 2 3 4 5 6 ⟩
<span class='Function'>↓</span> <span class='Number'>1</span><span class='Function'>+↕</span><span class='Number'>6</span>
⟨ ⟨ 1 2 3 4 5 6 ⟩ ⟨ 2 3 4 5 6 ⟩ ⟨ 3 4 5 6 ⟩ ⟨ 4 5 6 ⟩ ⟨ 5 6 ⟩ ⟨ 6 ⟩ ⟨⟩ ⟩
</pre>
<p>We want to include the diagonal, so we'll pair each element with the corresponding element of the suffixes, reducing the suffixes to the original array's length by dropping the last element, which is empty. In other cases, we might not want to include it and we should instead drop the first element.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KOKKoiDDlyDiiaAg4oaRIOKGkykgMSvihpU2CijiiqIgw5cgMSDihpMg4oaTKSAxK+KGlTY=">↗️</a><pre> <span class='Paren'>(</span><span class='Function'>⊢</span> <span class='Function'>×</span> <span class='Function'>≠</span> <span class='Function'>↑</span> <span class='Function'>↓</span><span class='Paren'>)</span> <span class='Number'>1</span><span class='Function'>+↕</span><span class='Number'>6</span>
⟨ ⟨ 1 2 3 4 5 6 ⟩ ⟨ 4 6 8 10 12 ⟩ ⟨ 9 12 15 18 ⟩ ⟨ 16 20 24 ⟩ ⟨ 25 30 ⟩ ⟨ 36 ⟩ ⟩
<span class='Paren'>(</span><span class='Function'>⊢</span> <span class='Function'>×</span> <span class='Number'>1</span> <span class='Function'>↓</span> <span class='Function'>↓</span><span class='Paren'>)</span> <span class='Number'>1</span><span class='Function'>+↕</span><span class='Number'>6</span>
⟨ ⟨ 2 3 4 5 6 ⟩ ⟨ 6 8 10 12 ⟩ ⟨ 12 15 18 ⟩ ⟨ 20 24 ⟩ ⟨ 30 ⟩ ⟨⟩ ⟩
</pre>
<p>By using <a href="couple.html">Couple</a> (<code><span class='Function'>≍</span></code>) instead of <code><span class='Function'>×</span></code>, we can see the argument ordering, demonstrating that we are looking at the upper right half of the matrix produced by Table. While in this case we could use <code><span class='Function'>≍</span><span class='Modifier2'>⚇</span><span class='Number'>0</span></code> to mimic the pervasion of <code><span class='Function'>×</span></code>, we'd like this to work even on nested arguments so we should figure out how the mapping structure works to apply Each appropriately.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omN4oycy5wgImFiYyIKKDzLmCDiiY3CqMKoIOKJoCDihpEg4oaTKSAiYWJjIg==">↗️</a><pre> <span class='Function'>≍</span><span class='Modifier'>⌜˜</span> <span class='String'>"abc"</span>
┌─
╵ "aa" "ab" "ac"
"ba" "bb" "bc"
"ca" "cb" "cc"
┘
<span class='Paren'>(</span><span class='Function'><</span><span class='Modifier'>˘</span> <span class='Function'>≍</span><span class='Modifier'>¨¨</span> <span class='Function'>≠</span> <span class='Function'>↑</span> <span class='Function'>↓</span><span class='Paren'>)</span> <span class='String'>"abc"</span>
⟨ ⟨ "aa" "ab" "ac" ⟩ ⟨ "bb" "bc" ⟩ ⟨ "cc" ⟩ ⟩
</pre>
<p>As before, we can exclude the diagonal, and using Prefixes instead of Suffixes gives us the lower left half instead of the upper right—in terms of the arguments given to <code><span class='Function'>≍</span></code> it reverses the argument pairs and iterates in a different order.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KDzLmCDiiY3CqMKoIDEg4oaTIOKGkykgImFiYyIKKDzLmCDiiY3CqMKoIDEg4oaTIOKGkSkgImFiYyIKKDzLmCDiiY3CqMKoIOKJoCDihpEg4oaRKSAiYWJjIg==">↗️</a><pre> <span class='Paren'>(</span><span class='Function'><</span><span class='Modifier'>˘</span> <span class='Function'>≍</span><span class='Modifier'>¨¨</span> <span class='Number'>1</span> <span class='Function'>↓</span> <span class='Function'>↓</span><span class='Paren'>)</span> <span class='String'>"abc"</span>
⟨ ⟨ "ab" "ac" ⟩ ⟨ "bc" ⟩ ⟨⟩ ⟩
<span class='Paren'>(</span><span class='Function'><</span><span class='Modifier'>˘</span> <span class='Function'>≍</span><span class='Modifier'>¨¨</span> <span class='Number'>1</span> <span class='Function'>↓</span> <span class='Function'>↑</span><span class='Paren'>)</span> <span class='String'>"abc"</span>
⟨ ⟨ "aa" ⟩ ⟨ "ba" "bb" ⟩ ⟨ "ca" "cb" "cc" ⟩ ⟩
<span class='Paren'>(</span><span class='Function'><</span><span class='Modifier'>˘</span> <span class='Function'>≍</span><span class='Modifier'>¨¨</span> <span class='Function'>≠</span> <span class='Function'>↑</span> <span class='Function'>↑</span><span class='Paren'>)</span> <span class='String'>"abc"</span>
⟨ ⟨⟩ ⟨ "ba" ⟩ ⟨ "ca" "cb" ⟩ ⟩
</pre>
<h2 id="slices">Slices</h2>
<p>Prefixes and Suffixes give certain restricted slices of the argument array, where a slice is a contiguous selection of cells. If we want all slices along the first axis, we can take the suffixes of each prefix, or vice-versa:</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oaTwqjihpEgImFiYyIK4oaRwqjihpMgImFiYyI=">↗️</a><pre> <span class='Function'>↓</span><span class='Modifier'>¨</span><span class='Function'>↑</span> <span class='String'>"abc"</span>
┌─
· ⟨ ⟨⟩ ⟩ ⟨ "a" ⟨⟩ ⟩ ⟨ "ab" "b" ⟨⟩ ⟩ ⟨ "abc" "bc" "c" ⟨⟩ ⟩
┘
<span class='Function'>↑</span><span class='Modifier'>¨</span><span class='Function'>↓</span> <span class='String'>"abc"</span>
┌─
· ⟨ ⟨⟩ "a" "ab" "abc" ⟩ ⟨ ⟨⟩ "b" "bc" ⟩ ⟨ ⟨⟩ "c" ⟩ ⟨ ⟨⟩ ⟩
┘
</pre>
<p>Effectively, this parametrizes the slices either by ending then starting index, or by starting index then length. Four empty slices are included because in a list of length 3 there are 4 places an empty slice can start: all the spaces between or outside elements (these also correspond to all the possible positions for the result of <a href="order.html#bins">Bins</a>). The slices can also be parametrized by length and then starting index using <a href="windows.html">Windows</a>.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KCjihpUxK+KJoCnihpXCqDwpICJhYmMiCigo4oaVMSviiaApPMuY4oiY4oaVwqg8KSAiYWJjIiAgIyBTcGxpdCB0aGVtIHRvIG1hdGNoIFByZWZpeGVzL1N1ZmZpeGVz">↗️</a><pre> <span class='Paren'>((</span><span class='Function'>↕</span><span class='Number'>1</span><span class='Function'>+≠</span><span class='Paren'>)</span><span class='Function'>↕</span><span class='Modifier'>¨</span><span class='Function'><</span><span class='Paren'>)</span> <span class='String'>"abc"</span>
┌─
· ┌┐ ┌─ ┌─ ┌─
╵ ╵"a ╵"ab ╵"abc"
b bc" ┘
c" ┘
┘
┘
┘
<span class='Paren'>((</span><span class='Function'>↕</span><span class='Number'>1</span><span class='Function'>+≠</span><span class='Paren'>)</span><span class='Function'><</span><span class='Modifier'>˘</span><span class='Modifier2'>∘</span><span class='Function'>↕</span><span class='Modifier'>¨</span><span class='Function'><</span><span class='Paren'>)</span> <span class='String'>"abc"</span> <span class='Comment'># Split them to match Prefixes/Suffixes
</span>┌─
· ⟨ ⟨⟩ ⟨⟩ ⟨⟩ ⟨⟩ ⟩ ⟨ "a" "b" "c" ⟩ ⟨ "ab" "bc" ⟩ ⟨ "abc" ⟩
┘
</pre>
<p>We might view a slice as a selection for not two but <em>three</em> parameters: the number of cells before, in, and after the slice. The conditions are that each parameter, being a length, is at least 0, and the total of the three parameters is equal to the array length. With three parameters and one equality constraint, the space of slices is two-dimensional; the above ways to enumerate it each pick two parameters and allow the third to be dependent on these two. If you're familiar with <a href="https://en.wikipedia.org/wiki/Barycentric_coordinate_system">barycentric coordinates</a> on a triangle, this should sound very familiar because that's exactly what the three parameters are!</p>
<p>We might also consider the question of slices along multiple axes. Because axes are orthogonal, we can choose such a slice by independently slicing along each axis. To use the homogeneous shape of arrays as much as possible, the result should still only have two added layers of nesting for the two coordinates we choose, with all possible choices for the first axis along the axes of the outer array and those for the second along the axes of each inner array. Our Windows-based solution adapts to multidimensional arrays easily:</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KCjihpUxK+KJoik84o6JMuKImOKGlcKoPCkgM+KAvzLipYoiYWJjZGVmIg==">↗️</a><pre> <span class='Paren'>((</span><span class='Function'>↕</span><span class='Number'>1</span><span class='Function'>+≢</span><span class='Paren'>)</span><span class='Function'><</span><span class='Modifier2'>⎉</span><span class='Number'>2</span><span class='Modifier2'>∘</span><span class='Function'>↕</span><span class='Modifier'>¨</span><span class='Function'><</span><span class='Paren'>)</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Function'>⥊</span><span class='String'>"abcdef"</span>
┌─
╵ ┌─ ┌─ ┌─
╵ ┌┐ ┌┐ ┌┐ ╵ ↕0‿1 ↕0‿1 ╵ ↕0‿2
└┘ └┘ └┘ ↕0‿1 ↕0‿1 ↕0‿2
┌┐ ┌┐ ┌┐ ↕0‿1 ↕0‿1 ↕0‿2
└┘ └┘ └┘ ↕0‿1 ↕0‿1 ↕0‿2
┌┐ ┌┐ ┌┐ ┘ ┘
└┘ └┘ └┘
┌┐ ┌┐ ┌┐
└┘ └┘ └┘
┘
┌─ ┌─ ┌─
╵ ┌┐ ┌┐ ┌┐ ╵ ┌─ ┌─ ╵ ┌─
╵ ╵ ╵ ╵"a" ╵"b" ╵"ab"
┘ ┘ ┘ ┘ ┘ ┘
┌┐ ┌┐ ┌┐ ┌─ ┌─ ┌─
╵ ╵ ╵ ╵"c" ╵"d" ╵"cd"
┘ ┘ ┘ ┘ ┘ ┘
┌┐ ┌┐ ┌┐ ┌─ ┌─ ┌─
╵ ╵ ╵ ╵"e" ╵"f" ╵"ef"
┘ ┘ ┘ ┘ ┘ ┘
┘ ┘ ┘
┌─ ┌─ ┌─
╵ ┌┐ ┌┐ ┌┐ ╵ ┌─ ┌─ ╵ ┌─
╵ ╵ ╵ ╵"a ╵"b ╵"ab
c" d" cd"
┘ ┘ ┘ ┘ ┘ ┘
┌┐ ┌┐ ┌┐ ┌─ ┌─ ┌─
╵ ╵ ╵ ╵"c ╵"d ╵"cd
e" f" ef"
┘ ┘ ┘ ┘ ┘ ┘
┘ ┘ ┘
┌─ ┌─ ┌─
╵ ┌┐ ┌┐ ┌┐ ╵ ┌─ ┌─ ╵ ┌─
╵ ╵ ╵ ╵"a ╵"b ╵"ab
c d cd
e" f" ef"
┘ ┘ ┘ ┘ ┘ ┘
┘ ┘ ┘
┘
</pre>
<p>This array can be <a href="join.html">joined</a>, indicating that the length of each inner axis depends only on the position in the corresponding outer axis (let's also drop those empty slices to take up less space).</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oi+IDHigL8xIOKGkyAoKOKGlTEr4omiKTzijoky4oiY4oaVwqg8KSAz4oC/MuKliiJhYmNkZWYi">↗️</a><pre> <span class='Function'>∾</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span> <span class='Function'>↓</span> <span class='Paren'>((</span><span class='Function'>↕</span><span class='Number'>1</span><span class='Function'>+≢</span><span class='Paren'>)</span><span class='Function'><</span><span class='Modifier2'>⎉</span><span class='Number'>2</span><span class='Modifier2'>∘</span><span class='Function'>↕</span><span class='Modifier'>¨</span><span class='Function'><</span><span class='Paren'>)</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Function'>⥊</span><span class='String'>"abcdef"</span>
┌─
╵ ┌─ ┌─ ┌─
╵"a" ╵"b" ╵"ab"
┘ ┘ ┘
┌─ ┌─ ┌─
╵"c" ╵"d" ╵"cd"
┘ ┘ ┘
┌─ ┌─ ┌─
╵"e" ╵"f" ╵"ef"
┘ ┘ ┘
┌─ ┌─ ┌─
╵"a ╵"b ╵"ab
c" d" cd"
┘ ┘ ┘
┌─ ┌─ ┌─
╵"c ╵"d ╵"cd
e" f" ef"
┘ ┘ ┘
┌─ ┌─ ┌─
╵"a ╵"b ╵"ab
c d cd
e" f" ef"
┘ ┘ ┘
┘
</pre>
<p>But Prefixes and Suffixes <a href="../commentary/problems.html#cant-take-prefixes-or-suffixes-on-multiple-axes">don't have</a> any way to specify that they should work on multiple axes, and always work on exactly one. So to extend this pattern we will have to define multi-dimensional versions. This turns out to be very easy: just replace Length with <a href="shape.html">Shape</a> in the <a href="#definition">definitions</a> above.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=UHJlZnMg4oaQICjihpUxK+KJoinihpHCqDwKU3VmZnMg4oaQICjihpUxK+KJoinihpPCqDwKUHJlZnPCqFN1ZmZzIDPigL8y4qWKImFiY2RlZiI=">↗️</a><pre> <span class='Function'>Prefs</span> <span class='Gets'>←</span> <span class='Paren'>(</span><span class='Function'>↕</span><span class='Number'>1</span><span class='Function'>+≢</span><span class='Paren'>)</span><span class='Function'>↑</span><span class='Modifier'>¨</span><span class='Function'><</span>
<span class='Function'>Suffs</span> <span class='Gets'>←</span> <span class='Paren'>(</span><span class='Function'>↕</span><span class='Number'>1</span><span class='Function'>+≢</span><span class='Paren'>)</span><span class='Function'>↓</span><span class='Modifier'>¨</span><span class='Function'><</span>
<span class='Function'>Prefs</span><span class='Modifier'>¨</span><span class='Function'>Suffs</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Function'>⥊</span><span class='String'>"abcdef"</span>
┌─
╵ ┌─ ┌─ ┌─
╵ ┌┐ ↕0‿1 ↕0‿2 ╵ ┌┐ ↕0‿1 ╵ ┌┐
└┘ └┘ └┘
┌┐ ┌─ ┌─ ┌┐ ┌─ ┌┐
╵ ╵"a" ╵"ab" ╵ ╵"b" ╵
┘ ┘ ┘ ┘ ┘ ┘
┌┐ ┌─ ┌─ ┌┐ ┌─ ┌┐
╵ ╵"a ╵"ab ╵ ╵"b ╵
c" cd" d"
┘ ┘ ┘ ┘ ┘ ┘
┌┐ ┌─ ┌─ ┌┐ ┌─ ┌┐
╵ ╵"a ╵"ab ╵ ╵"b ╵
c cd d
e" ef" f"
┘ ┘ ┘ ┘ ┘ ┘
┘ ┘ ┘
┌─ ┌─ ┌─
╵ ┌┐ ↕0‿1 ↕0‿2 ╵ ┌┐ ↕0‿1 ╵ ┌┐
└┘ └┘ └┘
┌┐ ┌─ ┌─ ┌┐ ┌─ ┌┐
╵ ╵"c" ╵"cd" ╵ ╵"d" ╵
┘ ┘ ┘ ┘ ┘ ┘
┌┐ ┌─ ┌─ ┌┐ ┌─ ┌┐
╵ ╵"c ╵"cd ╵ ╵"d ╵
e" ef" f"
┘ ┘ ┘ ┘ ┘ ┘
┘ ┘ ┘
┌─ ┌─ ┌─
╵ ┌┐ ↕0‿1 ↕0‿2 ╵ ┌┐ ↕0‿1 ╵ ┌┐
└┘ └┘ └┘
┌┐ ┌─ ┌─ ┌┐ ┌─ ┌┐
╵ ╵"e" ╵"ef" ╵ ╵"f" ╵
┘ ┘ ┘ ┘ ┘ ┘
┘ ┘ ┘
┌─ ┌─ ┌─
╵ ┌┐ ↕0‿1 ↕0‿2 ╵ ┌┐ ↕0‿1 ╵ ┌┐
└┘ └┘ └┘
┘ ┘ ┘
┘
</pre>
|