diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-06-12 22:23:58 -0400 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-06-12 22:23:58 -0400 |
| commit | 016a32f7f798efefbf0376f07ecd12868b8160f3 (patch) | |
| tree | 5e03ff9f9dc3c327589b5f8a10d901a5dd45fab1 | |
| parent | fb9b75b9f6014f81e8e944f8b105ec75d9ecdc0d (diff) | |
Add comparison functions to arithmetic documentation
| -rw-r--r-- | doc/README.md | 2 | ||||
| -rw-r--r-- | doc/arithmetic.md | 27 | ||||
| -rw-r--r-- | doc/primitive.md | 12 | ||||
| -rw-r--r-- | docs/doc/arithmetic.html | 81 | ||||
| -rw-r--r-- | docs/doc/index.html | 2 | ||||
| -rw-r--r-- | docs/doc/primitive.html | 12 |
6 files changed, 122 insertions, 14 deletions
diff --git a/doc/README.md b/doc/README.md index ab347e99..9e3f3e3a 100644 --- a/doc/README.md +++ b/doc/README.md @@ -28,7 +28,7 @@ Concepts: - [Function trains](train.md) Primitives: -- [Arithmetic](arithmetic.md) (`+-×÷⋆√⌊⌈|`) +- [Arithmetic](arithmetic.md) (`+-×÷⋆√⌊⌈|≤<>≥=≠`) - [Array depth](depth.md) (`≡` and `⚇`) - [Array dimensions](shape.md) (`≢=≠`) - [Assert](assert.md) (`!`) diff --git a/doc/arithmetic.md b/doc/arithmetic.md index 3fa9ab9a..ee93b984 100644 --- a/doc/arithmetic.md +++ b/doc/arithmetic.md @@ -138,6 +138,33 @@ Modulus (`|`) is similar to the modular division operation written `%` in C-like Unlike in APL, a left argument of 0 fails or returns a not-a-number result. Set `𝕨` to `∞` to keep `𝕩` intact, but do note that if `𝕩<0` this will return `∞`. +## Comparisons + +BQN uses the six standard comparison functions of mathematics. For each pair of atoms the result is 1 if the comparison is true and 0 if it's false. These functions do the obvious thing with numeric arguments, but are extended to other types as well. + +| Name | Glyph | < | = | > | Domain +|--------------------------|:-----:|---|---|---|------- +| Equals | `=` | 0 | 1 | 0 | Any +| Not Equals | `≠` | 1 | 0 | 1 | Any +| Less Than or Equal to | `≤` | 1 | 1 | 0 | Data +| Less Than | `<` | 1 | 0 | 0 | Data +| Greater Than | `>` | 0 | 0 | 1 | Data +| Greater Than or Equal to | `≥` | 0 | 1 | 1 | Data + +The *ordered* comparisons `≤<>≥` are defined on numbers and characters (and arrays, by pervasion); they give an error for operation or namespace arguments. They order numbers as you'd expect, and characters by their code points. A character is considered greater than any number, even if it's `∞`. + + 3‿4‿5‿6 ≤ 5 + + 'c' < "acbz" + + ¯∞‿π‿∞ ≥ @‿'0'‿'?' + +Equals and Not Equals are the two *equality* comparisons. Equals tests for [atomic equality](match.md#atomic-equality) between each pair of atoms, as described in the Match documentation. Essentially, it returns `1` only if the two values are indistinguishable to BQN and `0` otherwise. Values of different types can never be equal, and characters are equal when they have the same code point. + + +‿-‿×‿÷ = ⊑⟨-⟩ + + 'b' ≠ "abacba" + ## Pervasion Arithmetic primitives act as though they are given [depth](depth.md#the-depth-modifier) 0, so that with array arguments they treat each atom independently. While the examples above use only numbers or lists of them, arithmetic applies to nested and high-rank arrays just as easily. diff --git a/doc/primitive.md b/doc/primitive.md index 531ffb13..ff40f843 100644 --- a/doc/primitive.md +++ b/doc/primitive.md @@ -26,12 +26,12 @@ Functions that have significant differences from APL functions are marked with a | `∨` | [Sort Down](order.md#sort) | [Or](logic.md)* | `¬` | [Not](logic.md)* | [Span](logic.md)* | `\|` | [Absolute Value](arithmetic.md#additional-arithmetic)| [Modulus](arithmetic.md#additional-arithmetic) -| `≤` | | [Less Than or Equal to](https://aplwiki.com/wiki/Less_than_or_Equal_to) -| `<` | [Enclose](enclose.md) | [Less Than](https://aplwiki.com/wiki/Less_than) -| `>` | [Merge](couple.md)* | [Greater Than](https://aplwiki.com/wiki/Greater_than) -| `≥` | | [Greater Than or Equal to](https://aplwiki.com/wiki/Greater_than_or_Equal_to) -| `=` | [Rank](shape.md)* | [Equals](https://aplwiki.com/wiki/Equal_to) -| `≠` | [Length](shape.md) | [Not Equals](https://aplwiki.com/wiki/Not_Equal_to) +| `≤` | | [Less Than or Equal to](arithmetic.md#comparisons) +| `<` | [Enclose](enclose.md) | [Less Than](arithmetic.md#comparisons) +| `>` | [Merge](couple.md)* | [Greater Than](arithmetic.md#comparisons) +| `≥` | | [Greater Than or Equal to](arithmetic.md#comparisons) +| `=` | [Rank](shape.md)* | [Equals](arithmetic.md#comparisons) +| `≠` | [Length](shape.md) | [Not Equals](arithmetic.md#comparisons) | `≡` | [Depth](depth.md)* | [Match](match.md) | `≢` | [Shape](shape.md) | [Not Match](match.md) | `⊣` | [Identity](identity.md) | [Left](identity.md) diff --git a/docs/doc/arithmetic.html b/docs/doc/arithmetic.html index 2fd50a23..7e9b9b64 100644 --- a/docs/doc/arithmetic.html +++ b/docs/doc/arithmetic.html @@ -202,6 +202,87 @@ 1 </pre> <p>Unlike in APL, a left argument of 0 fails or returns a not-a-number result. Set <code><span class='Value'>𝕨</span></code> to <code><span class='Number'>∞</span></code> to keep <code><span class='Value'>𝕩</span></code> intact, but do note that if <code><span class='Value'>𝕩</span><span class='Function'><</span><span class='Number'>0</span></code> this will return <code><span class='Number'>∞</span></code>.</p> +<h2 id="comparisons">Comparisons</h2> +<p>BQN uses the six standard comparison functions of mathematics. For each pair of atoms the result is 1 if the comparison is true and 0 if it's false. These functions do the obvious thing with numeric arguments, but are extended to other types as well.</p> +<table> +<thead> +<tr> +<th>Name</th> +<th align="center">Glyph</th> +<th><</th> +<th>=</th> +<th>></th> +<th>Domain</th> +</tr> +</thead> +<tbody> +<tr> +<td>Equals</td> +<td align="center"><code><span class='Function'>=</span></code></td> +<td>0</td> +<td>1</td> +<td>0</td> +<td>Any</td> +</tr> +<tr> +<td>Not Equals</td> +<td align="center"><code><span class='Function'>≠</span></code></td> +<td>1</td> +<td>0</td> +<td>1</td> +<td>Any</td> +</tr> +<tr> +<td>Less Than or Equal to</td> +<td align="center"><code><span class='Function'>≤</span></code></td> +<td>1</td> +<td>1</td> +<td>0</td> +<td>Data</td> +</tr> +<tr> +<td>Less Than</td> +<td align="center"><code><span class='Function'><</span></code></td> +<td>1</td> +<td>0</td> +<td>0</td> +<td>Data</td> +</tr> +<tr> +<td>Greater Than</td> +<td align="center"><code><span class='Function'>></span></code></td> +<td>0</td> +<td>0</td> +<td>1</td> +<td>Data</td> +</tr> +<tr> +<td>Greater Than or Equal to</td> +<td align="center"><code><span class='Function'>≥</span></code></td> +<td>0</td> +<td>1</td> +<td>1</td> +<td>Data</td> +</tr> +</tbody> +</table> +<p>The <em>ordered</em> comparisons <code><span class='Function'>≤<>≥</span></code> are defined on numbers and characters (and arrays, by pervasion); they give an error for operation or namespace arguments. They order numbers as you'd expect, and characters by their code points. A character is considered greater than any number, even if it's <code><span class='Number'>∞</span></code>.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=M+KAvzTigL814oC/NiDiiaQgNQoKJ2MnIDwgImFjYnoiCgrCr+KInuKAv8+A4oC/4oieIOKJpSBA4oC/JzAn4oC/Jz8n">↗️</a><pre> <span class='Number'>3</span><span class='Ligature'>‿</span><span class='Number'>4</span><span class='Ligature'>‿</span><span class='Number'>5</span><span class='Ligature'>‿</span><span class='Number'>6</span> <span class='Function'>≤</span> <span class='Number'>5</span> +⟨ 1 1 1 0 ⟩ + + <span class='String'>'c'</span> <span class='Function'><</span> <span class='String'>"acbz"</span> +⟨ 0 0 0 1 ⟩ + + <span class='Number'>¯∞</span><span class='Ligature'>‿</span><span class='Number'>π</span><span class='Ligature'>‿</span><span class='Number'>∞</span> <span class='Function'>≥</span> <span class='String'>@</span><span class='Ligature'>‿</span><span class='String'>'0'</span><span class='Ligature'>‿</span><span class='String'>'?'</span> +⟨ 0 0 0 ⟩ +</pre> +<p>Equals and Not Equals are the two <em>equality</em> comparisons. Equals tests for <a href="match.html#atomic-equality">atomic equality</a> between each pair of atoms, as described in the Match documentation. Essentially, it returns <code><span class='Number'>1</span></code> only if the two values are indistinguishable to BQN and <code><span class='Number'>0</span></code> otherwise. Values of different types can never be equal, and characters are equal when they have the same code point.</p> +<a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=K+KAvy3igL/Dl+KAv8O3ID0g4oqR4p+oLeKfqQoKJ2InIOKJoCAiYWJhY2JhIg==">↗️</a><pre> <span class='Function'>+</span><span class='Ligature'>‿</span><span class='Function'>-</span><span class='Ligature'>‿</span><span class='Function'>×</span><span class='Ligature'>‿</span><span class='Function'>÷</span> <span class='Function'>=</span> <span class='Function'>⊑</span><span class='Bracket'>⟨</span><span class='Function'>-</span><span class='Bracket'>⟩</span> +⟨ 0 1 0 0 ⟩ + + <span class='String'>'b'</span> <span class='Function'>≠</span> <span class='String'>"abacba"</span> +⟨ 1 0 1 1 0 1 ⟩ +</pre> <h2 id="pervasion">Pervasion</h2> <p>Arithmetic primitives act as though they are given <a href="depth.html#the-depth-modifier">depth</a> 0, so that with array arguments they treat each atom independently. While the examples above use only numbers or lists of them, arithmetic applies to nested and high-rank arrays just as easily.</p> <a class="replLink" title="Open in the REPL" target="_blank" href="https://mlochbaum.github.io/BQN/try.html#code=w5cg4omNy5jin6jCrzgswq854p+p4oC/4p+o4p+oMiww4p+pLDQsNeKfqQ==">↗️</a><pre> <span class='Function'>×</span> <span class='Function'>≍</span><span class='Modifier'>˘</span><span class='Bracket'>⟨</span><span class='Number'>¯8</span><span class='Separator'>,</span><span class='Number'>¯9</span><span class='Bracket'>⟩</span><span class='Ligature'>‿</span><span class='Bracket'>⟨⟨</span><span class='Number'>2</span><span class='Separator'>,</span><span class='Number'>0</span><span class='Bracket'>⟩</span><span class='Separator'>,</span><span class='Number'>4</span><span class='Separator'>,</span><span class='Number'>5</span><span class='Bracket'>⟩</span> diff --git a/docs/doc/index.html b/docs/doc/index.html index 75a7e7f8..9c535aa2 100644 --- a/docs/doc/index.html +++ b/docs/doc/index.html @@ -34,7 +34,7 @@ </ul> <p>Primitives:</p> <ul> -<li><a href="arithmetic.html">Arithmetic</a> (<code><span class='Function'>+-×÷⋆√⌊⌈|</span></code>)</li> +<li><a href="arithmetic.html">Arithmetic</a> (<code><span class='Function'>+-×÷⋆√⌊⌈|≤<>≥=≠</span></code>)</li> <li><a href="depth.html">Array depth</a> (<code><span class='Function'>≡</span></code> and <code><span class='Modifier2'>⚇</span></code>)</li> <li><a href="shape.html">Array dimensions</a> (<code><span class='Function'>≢=≠</span></code>)</li> <li><a href="assert.html">Assert</a> (<code><span class='Function'>!</span></code>)</li> diff --git a/docs/doc/primitive.html b/docs/doc/primitive.html index 5c024ba8..ac4cac2d 100644 --- a/docs/doc/primitive.html +++ b/docs/doc/primitive.html @@ -82,32 +82,32 @@ <tr> <td><code><span class='Function'>≤</span></code></td> <td></td> -<td><a href="https://aplwiki.com/wiki/Less_than_or_Equal_to">Less Than or Equal to</a></td> +<td><a href="arithmetic.html#comparisons">Less Than or Equal to</a></td> </tr> <tr> <td><code><span class='Function'><</span></code></td> <td><a href="enclose.html">Enclose</a></td> -<td><a href="https://aplwiki.com/wiki/Less_than">Less Than</a></td> +<td><a href="arithmetic.html#comparisons">Less Than</a></td> </tr> <tr> <td><code><span class='Function'>></span></code></td> <td><a href="couple.html">Merge</a>*</td> -<td><a href="https://aplwiki.com/wiki/Greater_than">Greater Than</a></td> +<td><a href="arithmetic.html#comparisons">Greater Than</a></td> </tr> <tr> <td><code><span class='Function'>≥</span></code></td> <td></td> -<td><a href="https://aplwiki.com/wiki/Greater_than_or_Equal_to">Greater Than or Equal to</a></td> +<td><a href="arithmetic.html#comparisons">Greater Than or Equal to</a></td> </tr> <tr> <td><code><span class='Function'>=</span></code></td> <td><a href="shape.html">Rank</a>*</td> -<td><a href="https://aplwiki.com/wiki/Equal_to">Equals</a></td> +<td><a href="arithmetic.html#comparisons">Equals</a></td> </tr> <tr> <td><code><span class='Function'>≠</span></code></td> <td><a href="shape.html">Length</a></td> -<td><a href="https://aplwiki.com/wiki/Not_Equal_to">Not Equals</a></td> +<td><a href="arithmetic.html#comparisons">Not Equals</a></td> </tr> <tr> <td><code><span class='Function'>≡</span></code></td> |
