aboutsummaryrefslogtreecommitdiff
path: root/docs/doc/repeat.html
diff options
context:
space:
mode:
authorMarshall Lochbaum <mwlochbaum@gmail.com>2021-08-11 17:21:31 -0400
committerMarshall Lochbaum <mwlochbaum@gmail.com>2021-08-11 17:25:04 -0400
commit2afb23928e1984d475cc460e1672e8f6fa0e4dbe (patch)
treeebd2cc514294d30b6fa4b36c2ee638326f06ef72 /docs/doc/repeat.html
parenteac61ca02074c218667754d5f4ef562e780bae85 (diff)
Allow clicking on header to get fragment link
Diffstat (limited to 'docs/doc/repeat.html')
-rw-r--r--docs/doc/repeat.html10
1 files changed, 5 insertions, 5 deletions
diff --git a/docs/doc/repeat.html b/docs/doc/repeat.html
index aaa68219..b5e4ba06 100644
--- a/docs/doc/repeat.html
+++ b/docs/doc/repeat.html
@@ -4,7 +4,7 @@
<title>BQN: The Repeat modifier</title>
</head>
<div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">doc</a></div>
-<h1 id="the-repeat-modifier">The Repeat modifier</h1>
+<h1 id="the-repeat-modifier"><a class="header" href="#the-repeat-modifier">The Repeat modifier</a></h1>
<p>Repeat (<code><span class='Modifier2'>⍟</span></code>) is a 2-modifier that applies its operand function <code><span class='Function'>𝔽</span></code> multiple times.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=wrvCu8K7ICJBQkNERSIKCsK74o2fMyAiQUJDREUi">↗️</a><pre> <span class='Function'>»»»</span> <span class='String'>&quot;ABCDE&quot;</span>
" AB"
@@ -18,7 +18,7 @@
</pre>
<p><code><span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Number'>0</span></code> repeats <code><span class='Function'>F</span></code> zero times, that is, does nothing. Like <code><span class='Value'>n</span><span class='Function'>⋆</span><span class='Number'>0</span></code> gives the multiplicative identity <code><span class='Number'>1</span></code>, <code><span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Number'>0</span></code> is the compositional <a href="identity.html">identity</a>, <code><span class='Function'>⊒</span></code>. Since <code><span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Number'>1</span></code> applies <code><span class='Function'>F</span></code> and <code><span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Number'>0</span></code> doesn't, Repeat might be pronounced &quot;if&quot; or &quot;conditional&quot; when <code><span class='Function'>𝔾</span></code> is boolean.</p>
<p>BQN's Repeat modifier has some extra functionality relative to the mathematical version. It allows a left argument, and some extensions to the right operand <code><span class='Function'>𝔾</span></code>. As usual for 2-modifiers, <code><span class='Function'>𝔾</span></code> is actually a function that applies to the arguments to give a result. The result can be a natural number as shown above, or a negative number to <a href="undo.html">Undo</a> (<code><span class='Modifier'>⁼</span></code>) <code><span class='Function'>𝔽</span></code>, or an array of values.</p>
-<h2 id="left-argument">Left argument</h2>
+<h2 id="left-argument"><a class="header" href="#left-argument">Left argument</a></h2>
<p>If <code><span class='Value'>𝕨</span></code> is given, it's passed as the left argument to <code><span class='Function'>𝔽</span></code> for every invocation.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MyAr4o2fMiA3CjMgKyAzICsgNw==">↗️</a><pre> <span class='Number'>3</span> <span class='Function'>+</span><span class='Modifier2'>⍟</span><span class='Number'>2</span> <span class='Number'>7</span>
13
@@ -26,7 +26,7 @@
13
</pre>
<p>This kind of composition can't be represented by <code><span class='Modifier2'>∘</span></code> anymore (you'd need a <a href="train.html">train</a>), but it's similar in spirit. <code><span class='Value'>𝕨</span> <span class='Function'>𝔽</span><span class='Modifier2'>⍟</span><span class='Value'>n</span> <span class='Value'>𝕩</span></code> is always equivalent to <code><span class='Value'>𝕨</span><span class='Modifier2'>⊸</span><span class='Function'>𝔽</span><span class='Modifier2'>⍟</span><span class='Value'>n</span> <span class='Value'>𝕩</span></code>, provided <code><span class='Value'>n</span></code> is a constantβ€”not a function, as discussed in the next section.</p>
-<h2 id="dynamic-repetition-count">Dynamic repetition count</h2>
+<h2 id="dynamic-repetition-count"><a class="header" href="#dynamic-repetition-count">Dynamic repetition count</a></h2>
<p>In the general case, <code><span class='Function'>𝔾</span></code> is a function, which is applied to all arguments to get the repetition count. That is, the <em>actual</em> count is <code><span class='Value'>𝕨</span><span class='Function'>𝔾</span><span class='Value'>𝕩</span></code>.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=4oi+4p+cMeKNn+KKoiA0Cgox4oq4K+KNn+KJoCDihpU0">↗️</a><pre> <span class='Function'>∾</span><span class='Modifier2'>⟜</span><span class='Number'>1</span><span class='Modifier2'>⍟</span><span class='Function'>⊒</span> <span class='Number'>4</span>
⟨ 4 1 1 1 1 ⟩
@@ -42,13 +42,13 @@
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MyDiiqPijZ88wqggMuKAvzTigL82ICAjIExlZnQgaWYgbGVzcywgaS5lLiBtaW5pbXVt">↗️</a><pre> <span class='Number'>3</span> <span class='Function'>⊣</span><span class='Modifier2'>⍟</span><span class='Function'>&lt;</span><span class='Modifier'>Β¨</span> <span class='Number'>2</span><span class='Ligature'>β€Ώ</span><span class='Number'>4</span><span class='Ligature'>β€Ώ</span><span class='Number'>6</span> <span class='Comment'># Left if less, i.e. minimum
</span>⟨ 2 3 3 ⟩
</pre>
-<h2 id="negative-repetition">Negative repetition</h2>
+<h2 id="negative-repetition"><a class="header" href="#negative-repetition">Negative repetition</a></h2>
<p>What does it mean to repeat a function a negative number of times? For a negative integer <code><span class='Function'>-</span><span class='Value'>n</span></code>, BQN defines <code><span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Paren'>(</span><span class='Function'>-</span><span class='Value'>n</span><span class='Paren'>)</span></code> to be <code><span class='Function'>F</span><span class='Modifier'>⁼</span><span class='Modifier2'>⍟</span><span class='Value'>n</span></code>. In particular, <code><span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Number'>¯1</span></code> simply undoes <code><span class='Function'>F</span></code>.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MSDijL3ijZ/CrzEgImFiY2RlIiAgIyBSb3RhdGUgYmFja3dhcmRz">↗️</a><pre> <span class='Number'>1</span> <span class='Function'>⌽</span><span class='Modifier2'>⍟</span><span class='Number'>Β―1</span> <span class='String'>&quot;abcde&quot;</span> <span class='Comment'># Rotate backwards
</span>"eabcd"
</pre>
<p>Because BQN's Undo is a little looser than a strict mathematical inverse, this is an extension of the function inverse written f⁻¹ in mathematics. As a result, it doesn't have all the same properties. For natural numbers, Repeat follows the rule that <code><span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Value'>m</span> <span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Value'>n</span> <span class='Value'>𝕩</span></code> is <code><span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Paren'>(</span><span class='Value'>m</span><span class='Function'>+</span><span class='Value'>n</span><span class='Paren'>)</span> <span class='Value'>𝕩</span></code>. For integers, we have <code><span class='Value'>𝕩</span> <span class='Function'>≑</span> <span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Value'>n</span> <span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Paren'>(</span><span class='Function'>-</span><span class='Value'>n</span><span class='Paren'>)</span> <span class='Value'>𝕩</span></code>, but not necessarily <code><span class='Value'>𝕩</span> <span class='Function'>≑</span> <span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Paren'>(</span><span class='Function'>-</span><span class='Value'>n</span><span class='Paren'>)</span> <span class='Function'>F</span><span class='Modifier2'>⍟</span><span class='Value'>n</span> <span class='Value'>𝕩</span></code>.</p>
-<h2 id="array-of-repetition-counts">Array of repetition counts</h2>
+<h2 id="array-of-repetition-counts"><a class="header" href="#array-of-repetition-counts">Array of repetition counts</a></h2>
<p>The value of <code><span class='Value'>𝕨</span><span class='Function'>𝔾</span><span class='Value'>𝕩</span></code> might also be an array, whose elements are any valid repetition valuesβ€”integers, or other arrays. Each integer in the nested structure is replaced with the result of repeating <code><span class='Function'>𝔽</span></code> that many times.</p>
<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=MuKKuMOX4o2f4p+oMizin6g0LMKvMiwx4p+p4p+pIDE=">↗️</a><pre> <span class='Number'>2</span><span class='Modifier2'>⊸</span><span class='Function'>Γ—</span><span class='Modifier2'>⍟</span><span class='Bracket'>⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Bracket'>⟨</span><span class='Number'>4</span><span class='Separator'>,</span><span class='Number'>Β―2</span><span class='Separator'>,</span><span class='Number'>1</span><span class='Bracket'>⟩⟩</span> <span class='Number'>1</span>
⟨ 4 ⟨ 16 0.25 2 ⟩ ⟩