Skip to content

Commit

Permalink
Fix several errors when discussing rank and shape of major cell search
Browse files Browse the repository at this point in the history
  • Loading branch information
mlochbaum committed Nov 4, 2024
1 parent e8363dd commit df8708f
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion doc/search.md
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ The searched-in argument is treated as a list of its [major cells](array.md#cell

rows ⊐ [["row","row","col"],["rho","cow","col"]]

So the result rank of `` is always `𝕨¬○=𝕩`, with a result shape `(1-˜=𝕨)↓≢𝕩`, and `𝕨⊐𝕩` fails if `1>=𝕩` or the result rank would be negative. In the list case, we have `1==𝕩` (so the first condition holds), and the result rank resolves to `=𝕨` (which can't be negative, so the second holds as well). The cell rank of `𝕩` is 0, and the fact that a 0-cell of `𝕩` gives a 0-cell of the result is what causes the shape arithmetic to be so simple.
So the result rank of `` is always `𝕩¬○=𝕨`, with a result shape `(¬=𝕨)↓≢𝕩`, and `𝕨⊐𝕩` fails if `1>=𝕨` or the result rank would be negative. In the list case, we have `1==𝕨` (so the first condition holds), and the result rank resolves to `=𝕩` (which can't be negative, so the second holds as well). The cell rank of `𝕩` is 0, and the fact that a 0-cell of `𝕩` gives a 0-cell of the result is what causes the shape arithmetic to be so simple.

For Member of, the arguments are reversed relative to Index of, but otherwise everything's the same. This differs from APL, where entries are always elements, not cells. Many APL designers consider the APL definition to be a failure of foresight and would prefer BQN's definition—or rather A+'s or J's definition, as these languages were actually the first to use it. The rank-aware version is more flexible, as it allows both searching for elements and searching for rows. APL would return the first result in both cases below.

Expand Down
2 changes: 1 addition & 1 deletion docs/doc/search.html
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ <h2 id="higher-ranks"><a class="header" href="#higher-ranks">Higher ranks</a></h
1 4 4
</pre>
<p>So the result rank of <code><span class='Function'></span></code> is always <code><span class='Value'>𝕨</span><span class='Function'>¬</span><span class='Modifier2'></span><span class='Function'>=</span><span class='Value'>𝕩</span></code>, with a result shape <code><span class='Paren'>(</span><span class='Number'>1</span><span class='Function'>-</span><span class='Modifier'>˜</span><span class='Function'>=</span><span class='Value'>𝕨</span><span class='Paren'>)</span><span class='Function'>↓≢</span><span class='Value'>𝕩</span></code>, and <code><span class='Value'>𝕨</span><span class='Function'></span><span class='Value'>𝕩</span></code> fails if <code><span class='Number'>1</span><span class='Function'>&gt;=</span><span class='Value'>𝕩</span></code> or the result rank would be negative. In the list case, we have <code><span class='Number'>1</span><span class='Function'>==</span><span class='Value'>𝕩</span></code> (so the first condition holds), and the result rank resolves to <code><span class='Function'>=</span><span class='Value'>𝕨</span></code> (which can't be negative, so the second holds as well). The cell rank of <code><span class='Value'>𝕩</span></code> is 0, and the fact that a 0-cell of <code><span class='Value'>𝕩</span></code> gives a 0-cell of the result is what causes the shape arithmetic to be so simple.</p>
<p>So the result rank of <code><span class='Function'></span></code> is always <code><span class='Value'>𝕩</span><span class='Function'>¬</span><span class='Modifier2'></span><span class='Function'>=</span><span class='Value'>𝕨</span></code>, with a result shape <code><span class='Paren'>(</span><span class='Function'>¬=</span><span class='Value'>𝕨</span><span class='Paren'>)</span><span class='Function'>↓≢</span><span class='Value'>𝕩</span></code>, and <code><span class='Value'>𝕨</span><span class='Function'></span><span class='Value'>𝕩</span></code> fails if <code><span class='Number'>1</span><span class='Function'>&gt;=</span><span class='Value'>𝕨</span></code> or the result rank would be negative. In the list case, we have <code><span class='Number'>1</span><span class='Function'>==</span><span class='Value'>𝕨</span></code> (so the first condition holds), and the result rank resolves to <code><span class='Function'>=</span><span class='Value'>𝕩</span></code> (which can't be negative, so the second holds as well). The cell rank of <code><span class='Value'>𝕩</span></code> is 0, and the fact that a 0-cell of <code><span class='Value'>𝕩</span></code> gives a 0-cell of the result is what causes the shape arithmetic to be so simple.</p>
<p>For Member of, the arguments are reversed relative to Index of, but otherwise everything's the same. This differs from APL, where entries are always elements, not cells. Many APL designers consider the APL definition to be a failure of foresight and would prefer BQN's definition—or rather A+'s or J's definition, as these languages were actually the first to use it. The rank-aware version is more flexible, as it allows both searching for elements and searching for rows. APL would return the first result in both cases below.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=WzLigL8xLDPigL8xXSDiiIogM+KAvzHigL804oC/MwoKWzLigL8xLDPigL8xXSDiiIogM+KAvzHiiY004oC/Mw==">↗️</a><pre> <span class='Bracket'>[</span><span class='Number'>2</span><span class='Ligature'></span><span class='Number'>1</span><span class='Separator'>,</span><span class='Number'>3</span><span class='Ligature'></span><span class='Number'>1</span><span class='Bracket'>]</span> <span class='Function'></span> <span class='Number'>3</span><span class='Ligature'></span><span class='Number'>1</span><span class='Ligature'></span><span class='Number'>4</span><span class='Ligature'></span><span class='Number'>3</span>
┌─
Expand Down

0 comments on commit df8708f

Please sign in to comment.