diff options
| -rw-r--r-- | docs/spec/index.html | 2 | ||||
| -rw-r--r-- | docs/spec/primitive.html | 25 | ||||
| -rw-r--r-- | spec/README.md | 2 | ||||
| -rw-r--r-- | spec/primitive.md | 25 | ||||
| -rw-r--r-- | spec/reference.bqn | 3 |
5 files changed, 53 insertions, 4 deletions
diff --git a/docs/spec/index.html b/docs/spec/index.html index 6d85d9bb..42cd8f3b 100644 --- a/docs/spec/index.html +++ b/docs/spec/index.html @@ -14,7 +14,7 @@ <li><a href="grammar.html">Grammar</a></li> <li><a href="scope.html">Variable scoping</a></li> <li><a href="evaluate.html">Evaluation semantics</a></li> -<li>Primitives (<a href="https://github.com/mlochbaum/BQN/blob/master/spec/reference.bqn">reference implementations</a>)</li> +<li><a href="primitive.html">Primitives</a> (<a href="https://github.com/mlochbaum/BQN/blob/master/spec/reference.bqn">reference implementations</a>)</li> <li><a href="inferred.html">Inferred properties</a> (type, Undo, and Under)</li> <li><a href="system.html">System-provided values</a> (<code><span class='Value'>โข</span></code>)</li> </ul> diff --git a/docs/spec/primitive.html b/docs/spec/primitive.html new file mode 100644 index 00000000..36a22cfb --- /dev/null +++ b/docs/spec/primitive.html @@ -0,0 +1,25 @@ +<head> + <link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/> + <link href="../style.css" rel="stylesheet"/> + <title>Specification: BQN primitives</title> +</head> +<div class="nav"><a href="https://github.com/mlochbaum/BQN">BQN</a> / <a href="../index.html">main</a> / <a href="index.html">spec</a></div> +<h1 id="specification-bqn-primitives">Specification: BQN primitives</h1> +<p>Most primitives are specified by the BQN-based implementation in <a href="https://github.com/mlochbaum/BQN/blob/master/spec/reference.bqn">reference.bqn</a>. This document specifies the basic functionality required by those definitions. Descriptions of other primitives are for informational purposes only.</p> +<h2 id="arithmetic">Arithmetic</h2> +<p>Functions here are defined for atoms only; the reference implementations extend them to arrays.</p> +<p>BQN uses five arithmetic functions that are standard in mathematics. The precision of these operations should be specified by the number <a href="types.html">type</a>.</p> +<ul> +<li>Add <code><span class='Function'>+</span></code></li> +<li>Negate <code><span class='Function'>-</span></code> and Subtract <code><span class='Function'>-</span></code> invert addition, with <code><span class='Function'>-</span><span class='Value'>๐ฉ</span></code> equivalent to <code><span class='Number'>0</span><span class='Function'>-</span><span class='Value'>๐ฉ</span></code> and <code><span class='Value'>๐จ</span><span class='Function'>-</span><span class='Value'>๐ฉ</span></code> equivalent to <code><span class='Value'>๐จ</span><span class='Function'>+-</span><span class='Value'>๐ฉ</span></code></li> +<li>Multiply <code><span class='Function'>ร</span></code> generalizes repeated addition.</li> +<li>Divide <code><span class='Function'>รท</span></code> inverts multiplication, with <code><span class='Function'>รท</span><span class='Value'>๐ฉ</span></code> equivalent to <code><span class='Number'>1</span><span class='Function'>รท</span><span class='Value'>๐ฉ</span></code> and <code><span class='Value'>๐จ</span><span class='Function'>รท</span><span class='Value'>๐ฉ</span></code> equivalent to <code><span class='Value'>๐จ</span><span class='Function'>รรท</span><span class='Value'>๐ฉ</span></code></li> +<li>Power <code><span class='Function'>โ</span></code> generalizes repeated multiplication, and Exponential <code><span class='Function'>โ</span></code> is Power with Euler's number <em>e</em> as the base.</li> +</ul> +<p>The three higher functions <code><span class='Function'>ร</span></code>, <code><span class='Function'>รท</span></code>, and <code><span class='Function'>โ</span></code> apply to numbers and no other atomic types. <code><span class='Function'>+</span></code> and <code><span class='Function'>-</span></code> apply to numbers, and possibly also to characters, according to the rules of the affine character type:</p> +<ul> +<li>If one argument to <code><span class='Function'>+</span></code> is the character with code point <code><span class='Value'>c</span></code> and the other is a number <code><span class='Value'>n</span></code> (in either order), then the result is the character with code point <code><span class='Value'>c</span><span class='Function'>+</span><span class='Value'>n</span></code>.</li> +<li>If the left argument to <code><span class='Function'>-</span></code> is the character with code point <code><span class='Value'>c</span></code> and the right is a number <code><span class='Value'>n</span></code>, the result is the character with code point <code><span class='Value'>c</span><span class='Function'>-</span><span class='Value'>n</span></code>.</li> +<li>If both arguments to <code><span class='Function'>-</span></code> are characters, the result is the difference of their respective code points.</li> +</ul> +<p>In the first two cases, if the result would not be a valid Unicode code point, then an error results. The remaining cases of <code><span class='Function'>+</span></code> and <code><span class='Function'>-</span></code> (adding two characters; negating a character or subtracting it from a number) are not allowed.</p> diff --git a/spec/README.md b/spec/README.md index f7c1d50b..1951d7ff 100644 --- a/spec/README.md +++ b/spec/README.md @@ -11,6 +11,6 @@ The following aspects define BQN and are or will be specified: - [Grammar](grammar.md) - [Variable scoping](scope.md) - [Evaluation semantics](evaluate.md) -- Primitives ([reference implementations](reference.bqn)) +- [Primitives](primitive.md) ([reference implementations](reference.bqn)) - [Inferred properties](inferred.md) (type, Undo, and Under) - [System-provided values](system.md) (`โข`) diff --git a/spec/primitive.md b/spec/primitive.md new file mode 100644 index 00000000..d9542ef4 --- /dev/null +++ b/spec/primitive.md @@ -0,0 +1,25 @@ +*View this file with results and syntax highlighting [here](https://mlochbaum.github.io/BQN/spec/primitive.html).* + +# Specification: BQN primitives + +Most primitives are specified by the BQN-based implementation in [reference.bqn](reference.bqn). This document specifies the basic functionality required by those definitions. Descriptions of other primitives are for informational purposes only. + +## Arithmetic + +Functions here are defined for atoms only; the reference implementations extend them to arrays. + +BQN uses five arithmetic functions that are standard in mathematics. The precision of these operations should be specified by the number [type](types.md). + +- Add `+` +- Negate `-` and Subtract `-` invert addition, with `-๐ฉ` equivalent to `0-๐ฉ` and `๐จ-๐ฉ` equivalent to `๐จ+-๐ฉ` +- Multiply `ร` generalizes repeated addition. +- Divide `รท` inverts multiplication, with `รท๐ฉ` equivalent to `1รท๐ฉ` and `๐จรท๐ฉ` equivalent to `๐จรรท๐ฉ` +- Power `โ` generalizes repeated multiplication, and Exponential `โ` is Power with Euler's number *e* as the base. + +The three higher functions `ร`, `รท`, and `โ` apply to numbers and no other atomic types. `+` and `-` apply to numbers, and possibly also to characters, according to the rules of the affine character type: + +- If one argument to `+` is the character with code point `c` and the other is a number `n` (in either order), then the result is the character with code point `c+n`. +- If the left argument to `-` is the character with code point `c` and the right is a number `n`, the result is the character with code point `c-n`. +- If both arguments to `-` are characters, the result is the difference of their respective code points. + +In the first two cases, if the result would not be a valid Unicode code point, then an error results. The remaining cases of `+` and `-` (adding two characters; negating a character or subtracting it from a number) are not allowed. diff --git a/spec/reference.bqn b/spec/reference.bqn index d88cae63..b7a8f1cd 100644 --- a/spec/reference.bqn +++ b/spec/reference.bqn @@ -2,8 +2,7 @@ # limited initial functionality. Implementations are designed to be # simple and not fast. -# Not yet included: characters, complex numbers, comparison tolerance, -# selective assignment, and Under. +# Not yet included: complex numbers or comparison tolerance. # In some cases an operation is defined with limited functionality at # first and later expanded. For convenience, rather than renaming these |
