diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-04-28 08:18:39 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2022-04-28 08:18:39 -0400 |
| commit | 887bd8588f86b6014b961e236aaa36d31e775d9a (patch) | |
| tree | 7a3ab865963198d8f7ae50fc20ae3232fcd94f36 | |
| parent | f155aa59801dd87586f4792a828b4438852dc021 (diff) | |
More comments on Under
| -rw-r--r-- | doc/under.md | 10 | ||||
| -rw-r--r-- | docs/doc/under.html | 12 |
2 files changed, 20 insertions, 2 deletions
diff --git a/doc/under.md b/doc/under.md index b7819f97..78e09ea1 100644 --- a/doc/under.md +++ b/doc/under.md @@ -68,6 +68,14 @@ BQN can detect lots of structural functions when written in [tacit](tacit.md) fo ⌽⌾(⊢↑˜≠÷2˙) "abcdef" +But you can't use a computation that uses array values, such as `10⊸+⌾((<⊸5)⊸/)` to add 10 to each element below 5. This is because Under can change the array values, so that the function `𝔾` doesn't select the same elements before and after applying it (at the same time, Under can't change array structure, or at least not the parts that matter to `𝔾`). To use a dynamic selection function, compute the mask or indices based on a copy of the argument and use those as part of `𝔾`. + + {10⊸+⌾((𝕩<5)⊸/)𝕩} 3‿8‿2‿2‿6 + + (<⟜5)⊸/ 3‿8‿2‿2‿6 + + (<⟜5)⊸/ {10⊸+⌾((𝕩<5)⊸/)𝕩} 3‿8‿2‿2‿6 + Under is useful with [scans](scan.md), as discussed in a section on [reverse scan](scan.md#reverse-scan). In this case, `⌽` is exactly invertible, so `⌾` can just as easily be seen as computational Under. When `𝔾` has an exact inverse, there can only be one solution to the constraint on Under, and both forms must be the same. ∧`⌾⌽ 1‿0‿1‿0‿1‿1‿1 @@ -78,7 +86,7 @@ Computational Under is based on [Undo](undo.md) (`⁼`), and applies whenever st (+´÷≠)⌾(ט) 2‿3‿4‿5 -This average is the square root of the average of the squares of the arguments, and `⌾` lets us combine the two square-y steps. Similarly, `⌾÷` can be used for a harmonic sum or mean (you might notice that computational Under is a lot more mathy than the structural one). +This average is the square root of the average of the squares of the arguments, and `⌾` lets us combine the two square-y steps. Here there are two possible solutions because `¯3.67…` has the same square as the positive result; BQN of course uses the principal root. Similarly, `⌾÷` can be used for a harmonic sum or mean (you might notice that computational Under is a lot more mathy than the structural one). Under is the idiomatic way to do a round-to-nearest function: diff --git a/docs/doc/under.html b/docs/doc/under.html index 58c9f9d4..ae931d47 100644 --- a/docs/doc/under.html +++ b/docs/doc/under.html @@ -65,6 +65,16 @@ <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oy94oy+KOKKouKGkcuc4omgw7cyy5kpICJhYmNkZWYi">↗️</a><pre> <span class='Function'>⌽</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Function'>⊢↑</span><span class='Modifier'>˜</span><span class='Function'>≠÷</span><span class='Number'>2</span><span class='Modifier'>˙</span><span class='Paren'>)</span> <span class='String'>"abcdef"</span> "cbadef" </pre> +<p>But you can't use a computation that uses array values, such as <code><span class='Number'>10</span><span class='Modifier2'>⊸</span><span class='Function'>+</span><span class='Modifier2'>⌾</span><span class='Paren'>((</span><span class='Function'><</span><span class='Modifier2'>⊸</span><span class='Number'>5</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>/</span><span class='Paren'>)</span></code> to add 10 to each element below 5. This is because Under can change the array values, so that the function <code><span class='Function'>𝔾</span></code> doesn't select the same elements before and after applying it (at the same time, Under can't change array structure, or at least not the parts that matter to <code><span class='Function'>𝔾</span></code>). To use a dynamic selection function, compute the mask or indices based on a copy of the argument and use those as part of <code><span class='Function'>𝔾</span></code>.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=ezEw4oq4K+KMvigo8J2VqTw1KeKKuC8p8J2VqX0gM+KAvzjigL8y4oC/MuKAvzYKCig84p+cNSniirgvIDPigL844oC/MuKAvzLigL82CgooPOKfnDUp4oq4LyB7MTDiirgr4oy+KCjwnZWpPDUp4oq4LynwnZWpfSAz4oC/OOKAvzLigL8y4oC/Ng==">↗️</a><pre> <span class='Brace'>{</span><span class='Number'>10</span><span class='Modifier2'>⊸</span><span class='Function'>+</span><span class='Modifier2'>⌾</span><span class='Paren'>((</span><span class='Value'>𝕩</span><span class='Function'><</span><span class='Number'>5</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>/</span><span class='Paren'>)</span><span class='Value'>𝕩</span><span class='Brace'>}</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>8</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>6</span> +⟨ 13 8 12 12 6 ⟩ + + <span class='Paren'>(</span><span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>5</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>/</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>8</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>6</span> +⟨ 3 2 2 ⟩ + + <span class='Paren'>(</span><span class='Function'><</span><span class='Modifier2'>⟜</span><span class='Number'>5</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>/</span> <span class='Brace'>{</span><span class='Number'>10</span><span class='Modifier2'>⊸</span><span class='Function'>+</span><span class='Modifier2'>⌾</span><span class='Paren'>((</span><span class='Value'>𝕩</span><span class='Function'><</span><span class='Number'>5</span><span class='Paren'>)</span><span class='Modifier2'>⊸</span><span class='Function'>/</span><span class='Paren'>)</span><span class='Value'>𝕩</span><span class='Brace'>}</span> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>8</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>6</span> +⟨⟩ +</pre> <p>Under is useful with <a href="scan.html">scans</a>, as discussed in a section on <a href="scan.html#reverse-scan">reverse scan</a>. In this case, <code><span class='Function'>⌽</span></code> is exactly invertible, so <code><span class='Modifier2'>⌾</span></code> can just as easily be seen as computational Under. When <code><span class='Function'>𝔾</span></code> has an exact inverse, there can only be one solution to the constraint on Under, and both forms must be the same.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oinYOKMvuKMvSAx4oC/MOKAvzHigL8w4oC/MeKAvzHigL8x">↗️</a><pre> <span class='Function'>∧</span><span class='Modifier'>`</span><span class='Modifier2'>⌾</span><span class='Function'>⌽</span> <span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>0</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span> ⟨ 0 0 0 0 1 1 1 ⟩ @@ -74,7 +84,7 @@ <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KCvCtMO34omgKeKMvijDl8ucKSAy4oC/M+KAvzTigL81">↗️</a><pre> <span class='Paren'>(</span><span class='Function'>+</span><span class='Modifier'>´</span><span class='Function'>÷≠</span><span class='Paren'>)</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Function'>×</span><span class='Modifier'>˜</span><span class='Paren'>)</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>5</span> 3.674234614174767 </pre> -<p>This average is the square root of the average of the squares of the arguments, and <code><span class='Modifier2'>⌾</span></code> lets us combine the two square-y steps. Similarly, <code><span class='Modifier2'>⌾</span><span class='Function'>÷</span></code> can be used for a harmonic sum or mean (you might notice that computational Under is a lot more mathy than the structural one).</p> +<p>This average is the square root of the average of the squares of the arguments, and <code><span class='Modifier2'>⌾</span></code> lets us combine the two square-y steps. Here there are two possible solutions because <code><span class='Number'>¯3.67</span><span class='Value'>…</span></code> has the same square as the positive result; BQN of course uses the principal root. Similarly, <code><span class='Modifier2'>⌾</span><span class='Function'>÷</span></code> can be used for a harmonic sum or mean (you might notice that computational Under is a lot more mathy than the structural one).</p> <p>Under is the idiomatic way to do a round-to-nearest function:</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oyK4oy+KDEw4oq4w5cpIDMuNTI04oC/Ni43OTnigL8yLjAzMQ==">↗️</a><pre> <span class='Function'>⌊</span><span class='Modifier2'>⌾</span><span class='Paren'>(</span><span class='Number'>10</span><span class='Modifier2'>⊸</span><span class='Function'>×</span><span class='Paren'>)</span> <span class='Number'>3.524</span><span class='Ligature'>‿</span><span class='Number'>6.799</span><span class='Ligature'>‿</span><span class='Number'>2.031</span> ⟨ 3.5 6.7 2 ⟩ |
