aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-07-04 22:34:44 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-07-04 22:34:44 -0400
commit228e1b6d9d60eb885e5cda1b2c05048b253e140d (patch)
tree12ef80cab5ee7c053de5d55e8a0a054ee7b06d42
parent58fe852f79227f44eecb152ca0a0c64438bd7ae8 (diff)
Diagram and introduction for search functions
-rw-r--r--doc/search.md51
-rw-r--r--docs/doc/search.html126
2 files changed, 177 insertions, 0 deletions
diff --git a/doc/search.md b/doc/search.md
new file mode 100644
index 00000000..a71b0676
--- /dev/null
+++ b/doc/search.md
@@ -0,0 +1,51 @@
+*View this file with results and syntax highlighting [here](https://mlochbaum.github.io/BQN/doc/search.html).*
+
+# Search functions
+
+<!--GEN
+d ← 48‿36
+
+rc ← At "class=code|stroke-width=1.5|rx=12"
+Ge ← "g"⊸At⊸Enc
+g ← "font-family=BQN,monospace|font-size=19px|text-anchor=middle"
+hg ← "class=purple|stroke-width=0|opacity=0.5"
+cg ← "text-anchor=end"
+lg ← "class=lilac|stroke-linecap=round"
+lgs← "stroke-width=1|stroke-dasharray=6,7"‿"stroke-width=1.5"‿"stroke-width=3"
+ig ← "fill=currentColor|font-size=12|opacity=0.75"
+
+li‿lf ← ≠¨ it‿ft ← '''(Highlight∾∾⊣)¨¨"searches"‿"essays"
+
+Text ← ("text" Attr "dy"‿"0.32em"∾(Pos d⊸×))⊸Enc
+Line ← "line" Elt ("xy"≍⌜"12")≍˘○⥊ ·FmtNum d⊸×
+Rp ← Pos⊸∾⟜("width"‿"height"≍˘FmtNum)○(d⊸×)
+
+tx ← ↕li ⋄ y ← » yd ← +`2‿1.4‿1‿1‿1.8
+dim ← ⟨1.5+li,¯1⊑yd⟩ ⋄ sh ← ¯1.8‿¯1
+tp ← y ≍˜¨¨ 1‿4/⟨tx,↕lf⟩
+hp ← 0.2‿¯0.45(+⟜(1‿0×sh)≍¯2⊸×⊸+)1‿0×dim
+LL ← Line ·⌽˘ (≍˘⟜-0.08×4≍˜×∘-˜´) + ≍⟜(2↑y)
+Ilg← (1⊸+∾-)∘= <⊸(⊔¨) ∾≍○<∾○(↕∘≠)
+
+((∾˜d)×((-∾+˜)0.8‿0.3)+sh∾dim) SVG g Ge ⟨
+ "rect" Elt rc ∾ sh Rp dim
+ hg Ge ("rect" Elt ·Rp˝ {𝕩⊸+⌾(1⊑⊏)hp})¨ 2‿4⊏y
+ lg Ge lgs Ge¨ LL∘≍¨¨´ it (⊐Ilg⊒) ft
+ ig Ge (-⟜0‿0.48¨⊑tp) Text¨ •Repr¨ tx
+ (∾tp) Text¨ it ∾ ft ∾ Highlight∘•Repr¨ ∾ {it 𝕏 ft}¨ ⟨⊐,⊒,∊˜⟩
+ cg Ge (¯0.7≍¨y) Text⟜Highlight¨ "in"‿"for"∾⥊¨"⊐⊒∊"
+⟩
+-->
+
+The three search functions are Index of (`⊐`), Progressive Index of (`⊒`), and Member of (`∊`). These are dyadic functions that search one argument ("searched-in") for major cells [matching](match.md) cells from the other ("searched-for"). For example, Index of returns, for each cell in `𝕩`, the index of the first cell in `𝕨` that matches it.
+
+| | Name | for | in | Return
+|:----:|-----------------------|:---:|:---:|-------
+| `⊐` | Index of | `𝕩` | `𝕨` | Index of first match
+| `⊒` | Progressive Index of | `𝕩` | `𝕨` | Index of first unused match
+| `∊` | Member of | `𝕨` | `𝕩` | `1` if found, `0` if not
+| `⍋⍒` | [Bins](order.md#bins) | `𝕩` | `𝕨` | Predecessor index
+
+The searched-for argument is `𝕩` in Index-of functions (`⊐⊒`) and `𝕨` in Member of (`∊`). [Bins](order.md#bins) Up and Down (`⍋⍒`) are ordering functions but follow the same pattern as Index-of. It's split into cells, but not necessarily *major* cells: instead, the cells used match the rank of a major cell of the other (searched-in) argument. In the most common case, when the searched-in argument is a list, 0-cells are used for the search (we might also say elements, as it gives the same result).
+
+The result is always an array containing one number for each searched-for cell. For Index of and Member of, every result is computed independently; for Progressive Index of the result for a cell can depend on earlier cells, in index order.
diff --git a/docs/doc/search.html b/docs/doc/search.html
new file mode 100644
index 00000000..118cd35a
--- /dev/null
+++ b/docs/doc/search.html
@@ -0,0 +1,126 @@
+<head>
+ <link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/>
+ <link href="../style.css" rel="stylesheet"/>
+ <title>BQN: Search functions</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="search-functions">Search functions</h1>
+<svg viewBox='-124.8 -46.8 532.8 280.8'>
+ <g font-family='BQN,monospace' font-size='19px' text-anchor='middle'>
+ <rect class='code' stroke-width='1.5' rx='12' x='-86.4' y='-36' width='456' height='259.2'/>
+ <g class='purple' stroke-width='0' opacity='0.5'>
+ <rect x='-76.8' y='106.2' width='436.8' height='32.4'/>
+ <rect x='-76.8' y='178.2' width='436.8' height='32.4'/>
+ </g>
+ <g class='lilac' stroke-linecap='round'>
+ <g stroke-width='1' stroke-dasharray='6,7'>
+ <line x1='99.84' x2='332.16' y1='60.48' y2='11.52'/>
+ <line x1='243.84' x2='380.16' y1='60.48' y2='11.52'/>
+ </g>
+ <g stroke-width='1.5'>
+ <line x1='92.16' x2='3.84' y1='60.48' y2='11.52'/>
+ <line x1='236.16' x2='3.84' y1='60.48' y2='11.52'/>
+ </g>
+ <g stroke-width='3'>
+ <line x1='3.84' x2='44.16' y1='60.48' y2='11.52'/>
+ <line x1='44.16' x2='3.84' y1='60.48' y2='11.52'/>
+ <line x1='140.16' x2='99.84' y1='60.48' y2='11.52'/>
+ <line x1='195.84' x2='380.16' y1='60.48' y2='11.52'/>
+ </g>
+ </g>
+ <g fill='currentColor' font-size='12' opacity='0.75'>
+ <text dy='0.32em' x='0' y='-17.28'>0</text>
+ <text dy='0.32em' x='48' y='-17.28'>1</text>
+ <text dy='0.32em' x='96' y='-17.28'>2</text>
+ <text dy='0.32em' x='144' y='-17.28'>3</text>
+ <text dy='0.32em' x='192' y='-17.28'>4</text>
+ <text dy='0.32em' x='240' y='-17.28'>5</text>
+ <text dy='0.32em' x='288' y='-17.28'>6</text>
+ <text dy='0.32em' x='336' y='-17.28'>7</text>
+ </g>
+ <text dy='0.32em' x='0' y='0'><tspan class='String'>'s'</tspan></text>
+ <text dy='0.32em' x='48' y='0'><tspan class='String'>'e'</tspan></text>
+ <text dy='0.32em' x='96' y='0'><tspan class='String'>'a'</tspan></text>
+ <text dy='0.32em' x='144' y='0'><tspan class='String'>'r'</tspan></text>
+ <text dy='0.32em' x='192' y='0'><tspan class='String'>'c'</tspan></text>
+ <text dy='0.32em' x='240' y='0'><tspan class='String'>'h'</tspan></text>
+ <text dy='0.32em' x='288' y='0'><tspan class='String'>'e'</tspan></text>
+ <text dy='0.32em' x='336' y='0'><tspan class='String'>'s'</tspan></text>
+ <text dy='0.32em' x='0' y='72'><tspan class='String'>'e'</tspan></text>
+ <text dy='0.32em' x='48' y='72'><tspan class='String'>'s'</tspan></text>
+ <text dy='0.32em' x='96' y='72'><tspan class='String'>'s'</tspan></text>
+ <text dy='0.32em' x='144' y='72'><tspan class='String'>'a'</tspan></text>
+ <text dy='0.32em' x='192' y='72'><tspan class='String'>'y'</tspan></text>
+ <text dy='0.32em' x='240' y='72'><tspan class='String'>'s'</tspan></text>
+ <text dy='0.32em' x='0' y='122.4'><tspan class='Number'>1</tspan></text>
+ <text dy='0.32em' x='48' y='122.4'><tspan class='Number'>0</tspan></text>
+ <text dy='0.32em' x='96' y='122.4'><tspan class='Number'>0</tspan></text>
+ <text dy='0.32em' x='144' y='122.4'><tspan class='Number'>2</tspan></text>
+ <text dy='0.32em' x='192' y='122.4'><tspan class='Number'>8</tspan></text>
+ <text dy='0.32em' x='240' y='122.4'><tspan class='Number'>0</tspan></text>
+ <text dy='0.32em' x='0' y='158.4'><tspan class='Number'>1</tspan></text>
+ <text dy='0.32em' x='48' y='158.4'><tspan class='Number'>0</tspan></text>
+ <text dy='0.32em' x='96' y='158.4'><tspan class='Number'>7</tspan></text>
+ <text dy='0.32em' x='144' y='158.4'><tspan class='Number'>2</tspan></text>
+ <text dy='0.32em' x='192' y='158.4'><tspan class='Number'>8</tspan></text>
+ <text dy='0.32em' x='240' y='158.4'><tspan class='Number'>8</tspan></text>
+ <text dy='0.32em' x='0' y='194.4'><tspan class='Number'>1</tspan></text>
+ <text dy='0.32em' x='48' y='194.4'><tspan class='Number'>1</tspan></text>
+ <text dy='0.32em' x='96' y='194.4'><tspan class='Number'>1</tspan></text>
+ <text dy='0.32em' x='144' y='194.4'><tspan class='Number'>1</tspan></text>
+ <text dy='0.32em' x='192' y='194.4'><tspan class='Number'>0</tspan></text>
+ <text dy='0.32em' x='240' y='194.4'><tspan class='Number'>1</tspan></text>
+ <g text-anchor='end'>
+ <text dy='0.32em' x='-33.6' y='0'><tspan class='Value'>in</tspan></text>
+ <text dy='0.32em' x='-33.6' y='72'><tspan class='Value'>for</tspan></text>
+ <text dy='0.32em' x='-33.6' y='122.4'><tspan class='Function'>⊐</tspan></text>
+ <text dy='0.32em' x='-33.6' y='158.4'><tspan class='Function'>⊒</tspan></text>
+ <text dy='0.32em' x='-33.6' y='194.4'><tspan class='Function'>∊</tspan></text>
+ </g>
+ </g>
+</svg>
+
+<p>The three search functions are Index of (<code><span class='Function'>⊐</span></code>), Progressive Index of (<code><span class='Function'>⊒</span></code>), and Member of (<code><span class='Function'>∊</span></code>). These are dyadic functions that search one argument (&quot;searched-in&quot;) for major cells <a href="match.html">matching</a> cells from the other (&quot;searched-for&quot;). For example, Index of returns, for each cell in <code><span class='Value'>𝕩</span></code>, the index of the first cell in <code><span class='Value'>𝕨</span></code> that matches it.</p>
+<table>
+<thead>
+<tr>
+<th align="center"></th>
+<th>Name</th>
+<th align="center">for</th>
+<th align="center">in</th>
+<th>Return</th>
+</tr>
+</thead>
+<tbody>
+<tr>
+<td align="center"><code><span class='Function'>⊐</span></code></td>
+<td>Index of</td>
+<td align="center"><code><span class='Value'>𝕩</span></code></td>
+<td align="center"><code><span class='Value'>𝕨</span></code></td>
+<td>Index of first match</td>
+</tr>
+<tr>
+<td align="center"><code><span class='Function'>⊒</span></code></td>
+<td>Progressive Index of</td>
+<td align="center"><code><span class='Value'>𝕩</span></code></td>
+<td align="center"><code><span class='Value'>𝕨</span></code></td>
+<td>Index of first unused match</td>
+</tr>
+<tr>
+<td align="center"><code><span class='Function'>∊</span></code></td>
+<td>Member of</td>
+<td align="center"><code><span class='Value'>𝕨</span></code></td>
+<td align="center"><code><span class='Value'>𝕩</span></code></td>
+<td><code><span class='Number'>1</span></code> if found, <code><span class='Number'>0</span></code> if not</td>
+</tr>
+<tr>
+<td align="center"><code><span class='Function'>⍋⍒</span></code></td>
+<td><a href="order.html#bins">Bins</a></td>
+<td align="center"><code><span class='Value'>𝕩</span></code></td>
+<td align="center"><code><span class='Value'>𝕨</span></code></td>
+<td>Predecessor index</td>
+</tr>
+</tbody>
+</table>
+<p>The searched-for argument is <code><span class='Value'>𝕩</span></code> in Index-of functions (<code><span class='Function'>⊐⊒</span></code>) and <code><span class='Value'>𝕨</span></code> in Member of (<code><span class='Function'>∊</span></code>). <a href="order.html#bins">Bins</a> Up and Down (<code><span class='Function'>⍋⍒</span></code>) are ordering functions but follow the same pattern as Index-of. It's split into cells, but not necessarily <em>major</em> cells: instead, the cells used match the rank of a major cell of the other (searched-in) argument. In the most common case, when the searched-in argument is a list, 0-cells are used for the search (we might also say elements, as it gives the same result).</p>
+<p>The result is always an array containing one number for each searched-for cell. For Index of and Member of, every result is computed independently; for Progressive Index of the result for a cell can depend on earlier cells, in index order.</p>