diff options
| -rw-r--r-- | doc/functional.md | 8 | ||||
| -rw-r--r-- | docs/doc/functional.html | 26 |
2 files changed, 16 insertions, 18 deletions
diff --git a/doc/functional.md b/doc/functional.md index 1d55e8b8..49fb0c25 100644 --- a/doc/functional.md +++ b/doc/functional.md @@ -109,25 +109,22 @@ First, let's look at the basics: a small program that has functions as its argum We can pass it the exponential function as an argument by giving it the name `Exp` and then referring to it in lowercase (that is, in a subject role). The result is a train that adds 1 to *e*-1 times the argument. + Lin โ { v0โ๐0 โ v0+((๐1)-v0)รโข } Exp โ โ Lin exp - (1 + (1.71828182845905 ร โข)) As with all functions, the result of `Lin` has a subject role. To use it as a function, we give it a name and then use that name with an uppercase spelling. expLin โ Lin exp ExpLin 5 - 9.59140914229523 A tricker but more compact method is to use the 1-modifier `{๐ฝ}`, as the input to a modifier can have a subject or function role but its output always has a function role. (Lin exp){๐ฝ} 5 - 9.59140914229523 Not the most accurate approximation, though. Exp 5 - 148.413159102577 Note also in this case that we could have used a modifier with a very similar definition to `Lin`. The modifier is identical in definition except that `๐` is replaced with `๐ฝ`. @@ -138,15 +135,14 @@ Note also in this case that we could have used a modifier with a very similar de Its call syntax is simpler as well. In other cases, however, the function version might be preferable, for example when dealing with arrays of functions or many arguments including a function. + _lin โฉ { v0โ๐ฝ0 โ v0+((๐ฝ1)-v0)รโข } Exp _lin 5 - 9.59140914229523 ### Arrays of functions It's very convenient to put a function in an array, which is fortunate because this is one of the most important uses of functions as subjects. Here's an example of an array of functions with a reduction applied to it, composing them together. {๐โ๐}ยด โโฟ-โฟ(รห) - โโ(-โ(รห)) Like any function, this one can be given a name and then called. A quirk of this way of defining a function is that it has a subject role (it's the result of the function `{๐โ๐}ยด`) and so must be defined with a lowercase name. diff --git a/docs/doc/functional.html b/docs/doc/functional.html index 7e3b3900..fbba17dd 100644 --- a/docs/doc/functional.html +++ b/docs/doc/functional.html @@ -76,22 +76,23 @@ <span class='Brace'>}</span> </pre> <p>We can pass it the exponential function as an argument by giving it the name <code><span class='Function'>Exp</span></code> and then referring to it in lowercase (that is, in a subject role). The result is a train that adds 1 to <em>e</em>-1 times the argument.</p> -<pre> <span class='Function'>Exp</span> <span class='Gets'>โ</span> <span class='Function'>โ</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=TGluIOKGkCB7IHYw4oaQ8J2VjzAg4ouEIHYwKygo8J2VjzEpLXYwKcOX4oqiIH0KRXhwIOKGkCDii4YKTGluIGV4cA==">โ๏ธ</a><pre> <span class='Function'>Lin</span> <span class='Gets'>โ</span> <span class='Brace'>{</span> <span class='Value'>v0</span><span class='Gets'>โ</span><span class='Function'>๐</span><span class='Number'>0</span> <span class='Separator'>โ</span> <span class='Value'>v0</span><span class='Function'>+</span><span class='Paren'>((</span><span class='Function'>๐</span><span class='Number'>1</span><span class='Paren'>)</span><span class='Function'>-</span><span class='Value'>v0</span><span class='Paren'>)</span><span class='Function'>รโข</span> <span class='Brace'>}</span> + <span class='Function'>Exp</span> <span class='Gets'>โ</span> <span class='Function'>โ</span> <span class='Function'>Lin</span> <span class='Value'>exp</span> -<span class='Paren'>(</span><span class='Number'>1</span> <span class='Function'>+</span> <span class='Paren'>(</span><span class='Number'>1.71828182845905</span> <span class='Function'>ร</span> <span class='Function'>โข</span><span class='Paren'>))</span> +1+1.718281828459045รโข </pre> <p>As with all functions, the result of <code><span class='Function'>Lin</span></code> has a subject role. To use it as a function, we give it a name and then use that name with an uppercase spelling.</p> -<pre> <span class='Value'>expLin</span> <span class='Gets'>โ</span> <span class='Function'>Lin</span> <span class='Value'>exp</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=ZXhwTGluIOKGkCBMaW4gZXhwCkV4cExpbiA1">โ๏ธ</a><pre> <span class='Value'>expLin</span> <span class='Gets'>โ</span> <span class='Function'>Lin</span> <span class='Value'>exp</span> <span class='Function'>ExpLin</span> <span class='Number'>5</span> -<span class='Number'>9.59140914229523</span> +9.591409142295225 </pre> <p>A tricker but more compact method is to use the 1-modifier <code><span class='Brace'>{</span><span class='Function'>๐ฝ</span><span class='Brace'>}</span></code>, as the input to a modifier can have a subject or function role but its output always has a function role.</p> -<pre> <span class='Paren'>(</span><span class='Function'>Lin</span> <span class='Value'>exp</span><span class='Paren'>)</span><span class='Brace'>{</span><span class='Function'>๐ฝ</span><span class='Brace'>}</span> <span class='Number'>5</span> -<span class='Number'>9.59140914229523</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=KExpbiBleHApe/CdlL19IDU=">โ๏ธ</a><pre> <span class='Paren'>(</span><span class='Function'>Lin</span> <span class='Value'>exp</span><span class='Paren'>)</span><span class='Brace'>{</span><span class='Function'>๐ฝ</span><span class='Brace'>}</span> <span class='Number'>5</span> +9.591409142295225 </pre> <p>Not the most accurate approximation, though.</p> -<pre> <span class='Function'>Exp</span> <span class='Number'>5</span> -<span class='Number'>148.413159102577</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=RXhwIDU=">โ๏ธ</a><pre> <span class='Function'>Exp</span> <span class='Number'>5</span> +148.4131591025766 </pre> <p>Note also in this case that we could have used a modifier with a very similar definition to <code><span class='Function'>Lin</span></code>. The modifier is identical in definition except that <code><span class='Function'>๐</span></code> is replaced with <code><span class='Function'>๐ฝ</span></code>.</p> <pre><span class='Modifier'>_lin</span> <span class='Gets'>โฉ</span> <span class='Brace'>{</span> @@ -100,13 +101,14 @@ <span class='Brace'>}</span> </pre> <p>Its call syntax is simpler as well. In other cases, however, the function version might be preferable, for example when dealing with arrays of functions or many arguments including a function.</p> -<pre> <span class='Function'>Exp</span> <span class='Modifier'>_lin</span> <span class='Number'>5</span> -<span class='Number'>9.59140914229523</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=X2xpbiDihqkgeyB2MOKGkPCdlL0wIOKLhCB2MCsoKPCdlL0xKS12MCnDl+KKoiB9CkV4cCBfbGluIDU=">โ๏ธ</a><pre> <span class='Modifier'>_lin</span> <span class='Gets'>โฉ</span> <span class='Brace'>{</span> <span class='Value'>v0</span><span class='Gets'>โ</span><span class='Function'>๐ฝ</span><span class='Number'>0</span> <span class='Separator'>โ</span> <span class='Value'>v0</span><span class='Function'>+</span><span class='Paren'>((</span><span class='Function'>๐ฝ</span><span class='Number'>1</span><span class='Paren'>)</span><span class='Function'>-</span><span class='Value'>v0</span><span class='Paren'>)</span><span class='Function'>รโข</span> <span class='Brace'>}</span> + <span class='Function'>Exp</span> <span class='Modifier'>_lin</span> <span class='Number'>5</span> +9.591409142295225 </pre> <h3 id="arrays-of-functions">Arrays of functions</h3> <p>It's very convenient to put a function in an array, which is fortunate because this is one of the most important uses of functions as subjects. Here's an example of an array of functions with a reduction applied to it, composing them together.</p> -<pre> <span class='Brace'>{</span><span class='Function'>๐</span><span class='Modifier2'>โ</span><span class='Function'>๐</span><span class='Brace'>}</span><span class='Modifier'>ยด</span> <span class='Function'>โ</span><span class='Ligature'>โฟ</span><span class='Function'>-</span><span class='Ligature'>โฟ</span><span class='Paren'>(</span><span class='Function'>ร</span><span class='Modifier'>ห</span><span class='Paren'>)</span> -<span class='Function'>โ</span><span class='Modifier2'>โ</span><span class='Paren'>(</span><span class='Function'>-</span><span class='Modifier2'>โ</span><span class='Paren'>(</span><span class='Function'>ร</span><span class='Modifier'>ห</span><span class='Paren'>))</span> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=e/CdlY7iiJjwnZWPfcK0IOKLhuKAvy3igL8ow5fLnCk=">โ๏ธ</a><pre> <span class='Brace'>{</span><span class='Function'>๐</span><span class='Modifier2'>โ</span><span class='Function'>๐</span><span class='Brace'>}</span><span class='Modifier'>ยด</span> <span class='Function'>โ</span><span class='Ligature'>โฟ</span><span class='Function'>-</span><span class='Ligature'>โฟ</span><span class='Paren'>(</span><span class='Function'>ร</span><span class='Modifier'>ห</span><span class='Paren'>)</span> +โโ(-โ(รห)) </pre> <p>Like any function, this one can be given a name and then called. A quirk of this way of defining a function is that it has a subject role (it's the result of the function <code><span class='Brace'>{</span><span class='Function'>๐</span><span class='Modifier2'>โ</span><span class='Function'>๐</span><span class='Brace'>}</span><span class='Modifier'>ยด</span></code>) and so must be defined with a lowercase name.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=Z2F1c3Mg4oaQIHvwnZWO4oiY8J2Vj33CtCDii4bigL8t4oC/KMOXy5wpCkdhdXNzIDI=">โ๏ธ</a><pre> <span class='Value'>gauss</span> <span class='Gets'>โ</span> <span class='Brace'>{</span><span class='Function'>๐</span><span class='Modifier2'>โ</span><span class='Function'>๐</span><span class='Brace'>}</span><span class='Modifier'>ยด</span> <span class='Function'>โ</span><span class='Ligature'>โฟ</span><span class='Function'>-</span><span class='Ligature'>โฟ</span><span class='Paren'>(</span><span class='Function'>ร</span><span class='Modifier'>ห</span><span class='Paren'>)</span> |
