aboutsummaryrefslogtreecommitdiff
path: root/docs/doc/fold.html
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-11-03 15:51:15 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-11-03 15:55:14 -0400
commit29509cedb9af2715328e44c481738a9ba05cff73 (patch)
tree734a0251dbb20bc7e29b4b0e3bac3b48e0cdaff0 /docs/doc/fold.html
parent30b5188c23576d5e119bbc8d27cd08a3015a75c9 (diff)
Use ⋈ rather than ≍○< in documentation examples
Diffstat (limited to 'docs/doc/fold.html')
-rw-r--r--docs/doc/fold.html12
1 files changed, 6 insertions, 6 deletions
diff --git a/docs/doc/fold.html b/docs/doc/fold.html
index b9dddf8b..f1dc9a59 100644
--- a/docs/doc/fold.html
+++ b/docs/doc/fold.html
@@ -134,15 +134,15 @@
</table>
<h3 id="right-to-left"><a class="header" href="#right-to-left">Right-to-left</a></h3>
<p>The functions we've shown so far are associative (ignoring floating point imprecision), meaning it's equally valid to combine elements of the argument list in any order. But it can be useful to fold using a non-associative function. In this case you must know that Fold performs a <em>right fold</em>, starting from the end of the array and working towards the beginning.</p>
-<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omN4peLPMK0ICJhYmNkIgoKJ2EnIOKJjeKXizwgJ2InIOKJjeKXizwgJ2MnIOKJjeKXizwgJ2QnICAjIEV4cGFuZGVkIGZvcm0=">↗️</a><pre> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'>&lt;</span><span class='Modifier'>´</span> <span class='String'>&quot;abcd&quot;</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4ouIwrQgImFiY2QiCgonYScg4ouIICdiJyDii4ggJ2MnIOKLiCAnZCcgICMgRXhwYW5kZWQgZm9ybQ==">↗️</a><pre> <span class='Function'>⋈</span><span class='Modifier'>´</span> <span class='String'>&quot;abcd&quot;</span>
⟨ 'a' ⟨ 'b' "cd" ⟩ ⟩
- <span class='String'>'a'</span> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'>&lt;</span> <span class='String'>'b'</span> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'>&lt;</span> <span class='String'>'c'</span> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'>&lt;</span> <span class='String'>'d'</span> <span class='Comment'># Expanded form
+ <span class='String'>'a'</span> <span class='Function'>⋈</span> <span class='String'>'b'</span> <span class='Function'>⋈</span> <span class='String'>'c'</span> <span class='Function'>⋈</span> <span class='String'>'d'</span> <span class='Comment'># Expanded form
</span>⟨ 'a' ⟨ 'b' "cd" ⟩ ⟩
</pre>
-<p>Using the <a href="couple.html#coupling-units">pair</a> function <code><span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'>&lt;</span></code> as an operand shows the structure nicely. This fold first pairs the final two characters <code><span class='String'>'c'</span></code> and <code><span class='String'>'d'</span></code>, then pairs <code><span class='String'>'b'</span></code> with that and so on. This matches BQN's right-to-left order of evaluation. More declaratively we might say that each character is paired with the result of folding over everything to its right.</p>
+<p>Using <a href="pair.html">Pair</a> (<code><span class='Function'>⋈</span></code>) as an operand shows the structure nicely. This fold first pairs the final two characters <code><span class='String'>'c'</span></code> and <code><span class='String'>'d'</span></code>, then pairs <code><span class='String'>'b'</span></code> with that and so on. This matches BQN's right-to-left order of evaluation. More declaratively we might say that each character is paired with the result of folding over everything to its right.</p>
<p>BQN doesn't provide a left Fold (<code><span class='Modifier'>`</span></code> is <a href="scan.html">Scan</a>). However, you can fold from the left by <a href="reverse.html#reverse">reversing</a> (<code><span class='Function'>⌽</span></code>) the argument list and also reversing (<code><span class='Modifier'>˜</span></code>) the operand function's argument order.</p>
-<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4omN4peLPMucwrQg4oy9ICJhYmNkIg==">↗️</a><pre> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'>&lt;</span><span class='Modifier'>˜´</span> <span class='Function'>⌽</span> <span class='String'>&quot;abcd&quot;</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4ouIy5zCtCDijL0gImFiY2Qi">↗️</a><pre> <span class='Function'>⋈</span><span class='Modifier'>˜´</span> <span class='Function'>⌽</span> <span class='String'>&quot;abcd&quot;</span>
⟨ ⟨ "ab" 'c' ⟩ 'd' ⟩
</pre>
<p>One consequence of this ordering is that folding with Minus (<code><span class='Function'>-</span></code>) gives an alternating sum, where the first value is added, the second subtracted, the third added, and so on. Similarly, <code><span class='Function'>÷</span></code> gives an alternating product, with some elements multiplied and some divided.</p>
@@ -151,7 +151,7 @@
</pre>
<p>The operand <code><span class='Function'>+</span><span class='Modifier2'>⟜</span><span class='Function'>÷</span></code> is a quick way to compute a <a href="https://en.wikipedia.org/wiki/Continued_fraction">continued fraction</a>'s value from a list of numbers. Here are a few terms from the continued fraction for <em>e</em>.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=K+KfnMO3wrQgMuKAvzHigL8y4oC/MeKAvzHigL804oC/MeKAvzE=">↗️</a><pre> <span class='Function'>+</span><span class='Modifier2'>⟜</span><span class='Function'>÷</span><span class='Modifier'>´</span> <span class='Number'>2</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>2</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'>4</span><span class='Ligature'>‿</span><span class='Number'>1</span><span class='Ligature'>‿</span><span class='Number'>1</span>
-2.7183098591549295
+2.71830985915493
</pre>
<h3 id="initial-element"><a class="header" href="#initial-element">Initial element</a></h3>
<p>When the operand isn't just an arithmetic primitive, folding with no initial element can be dangerous. Even if you know <code><span class='Value'>𝕩</span></code> isn't empty, saving you from an &quot;Identity not found&quot; error, the case with only one element can easily violate expectations. Here's a somewhat silly example of a function meant to merge elements of the argument into a single list (<code><span class='Function'>∾⥊</span><span class='Modifier'>¨</span></code> is a much better way to do this):</p>
@@ -206,7 +206,7 @@
⟨ 0 0 0 0 ⟩
</pre>
<p>Just like Fold, Insert allows an initial element for the left argument, so that you don't need to rely on the interpreter knowing the identity. A more complete translation into Fold is therefore <code><span class='Brace'>{</span><span class='Value'>𝕨</span><span class='Function'>𝔽</span><span class='Modifier'>´</span><span class='Function'>&lt;</span><span class='Modifier'>˘</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code>. The expression below shows that the operand function is called on the last major cell when the identity, then the next-to-last major cell and so on. In total there are <code><span class='Function'>≠</span><span class='Value'>𝕩</span></code> calls, while there would be <code><span class='Number'>1</span><span class='Function'>-</span><span class='Modifier'>˜</span><span class='Function'>≠</span><span class='Value'>𝕩</span></code> without the left argument.</p>
-<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=ImlkIiDiiY3il4s8y50gInJvdzAgIuKIviJyb3cxICLiiY0icm93MiAi">↗️</a><pre> <span class='String'>&quot;id&quot;</span> <span class='Function'>≍</span><span class='Modifier2'>○</span><span class='Function'>&lt;</span><span class='Modifier'>˝</span> <span class='String'>&quot;row0 &quot;</span><span class='Function'>∾</span><span class='String'>&quot;row1 &quot;</span><span class='Function'>≍</span><span class='String'>&quot;row2 &quot;</span>
+<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=ImlkIiDii4jLnSAicm93MCAi4oi+InJvdzEgIuKJjSJyb3cyICI=">↗️</a><pre> <span class='String'>&quot;id&quot;</span> <span class='Function'>⋈</span><span class='Modifier'>˝</span> <span class='String'>&quot;row0 &quot;</span><span class='Function'>∾</span><span class='String'>&quot;row1 &quot;</span><span class='Function'>≍</span><span class='String'>&quot;row2 &quot;</span>
┌─
· "row0 " ⟨ "row1 " ⟨ "row2 " "id" ⟩ ⟩