diff options
| author | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-12-03 21:15:30 -0500 |
|---|---|---|
| committer | Marshall Lochbaum <mwlochbaum@gmail.com> | 2021-12-03 21:15:30 -0500 |
| commit | 33831837f3e17f6369097327005699a9b28d06c7 (patch) | |
| tree | 8d901bf1cdae263dedd4779be0fb1e0febb1ceec /docs/spec | |
| parent | 0d065be5a871100eb5c2a332499fa1cb65a9f5e5 (diff) | |
Separate complex number specification into its own extension
Diffstat (limited to 'docs/spec')
| -rw-r--r-- | docs/spec/index.html | 3 | ||||
| -rw-r--r-- | docs/spec/literal.html | 10 | ||||
| -rw-r--r-- | docs/spec/types.html | 2 |
3 files changed, 7 insertions, 8 deletions
diff --git a/docs/spec/index.html b/docs/spec/index.html index 80209ac7..5aa2bc7d 100644 --- a/docs/spec/index.html +++ b/docs/spec/index.html @@ -17,11 +17,12 @@ <li><a href="evaluate.html">Evaluation semantics</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> (identities, fills, Undo, and Under)</li> +<li><a href="complex.html">Complex numbers</a> optional extension</li> <li><a href="system.html">System-provided values</a> (<code><span class='Value'>•</span></code>)</li> </ul> <p>In several cases, an implementation can choose between more than one possible behavior.</p> <ul> -<li>An implementation chooses its number system, which must be an approximation of the real or complex numbers but has no specific requirements. Results of basic numeric operations must be deterministic but are not specified.</li> +<li>An implementation chooses its number system, which must be an approximation of the real (can be extended to <a href="complex.html">complex</a>) numbers but has no specific requirements. Results of basic numeric operations must be deterministic but are not specified.</li> <li>Minimum (<code><span class='Function'>⌊</span></code>) and Maximum (<code><span class='Function'>⌈</span></code>) may give an error if either argument is a character.</li> <li>Other than the required cases, attempting to use an inferred property can either fail or give a result consistent with the constraints on that property.</li> <li>In some cases there are multiple valid results for Undo. Any of these results, or an error, can be given; if there is no obvious choice of result an error is recommended. The choice must depend only on the inputs to Undo.</li> diff --git a/docs/spec/literal.html b/docs/spec/literal.html index 35a280cc..c171dbf5 100644 --- a/docs/spec/literal.html +++ b/docs/spec/literal.html @@ -7,13 +7,11 @@ <h1 id="specification-bqn-literal-notation"><a class="header" href="#specification-bqn-literal-notation">Specification: BQN literal notation</a></h1> <p>A <em>literal</em> is a single <a href="token.html">token</a> that indicates a fixed character, number, or array. While literals indicate values of a data type, <a href="primitive.html">primitives</a> indicate values of an operation type: function, 1-modifier, or 2-modifier.</p> <p>Two types of literal deal with text. As the source code is considered to be a sequence of unicode code points ("characters"), and these code points are also used for BQN's character <a href="types.html">data type</a>, the representation of a text literal is very similar to its value. In a text literal, the newline character is always represented using the ASCII line feed character, code point 10. A <em>character literal</em> is enclosed with single quotes <code><span class='String'>'</span></code> and its value is identical to the single character between them. A <em>string literal</em> is enclosed in double quotes <code><span class='String'>"</span></code>, and any double quotes between them must come in pairs, as a lone double quote marks the end of the literal. The value of a string literal is a rank-1 array whose elements are the characters in between the enclosing quotes, after replacing each pair of double quotes with only one such quote. The <em>null literal</em> is the token <code><span class='String'>@</span></code> and represents the null character, code point 0.</p> -<p>The format of a <em>numeric literal</em> is more complicated. From the <a href="token.html">tokenization rules</a>, a numeric literal consists of a numeric character (one of <code><span class='Number'>¯∞π.0123456789</span></code>) followed by any number of numeric or alphabetic characters. Some numeric literals are <em>valid</em> and indicate a number, while others are invalid and cause an error. The grammar for valid numbers is given below in a <a href="https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form">BNF</a> variant. Only four alphabetic characters are allowed: "i", which separates the real and imaginary components of a complex number, "e", which functions as in scientific notation, and the uppercase versions of these letters. Not included in this grammar are underscores—they can be placed anywhere in a number, including after the last non-underscore character, and are ignored entirely.</p> -<pre><span class='Value'>number</span> <span class='Function'>=</span> <span class='Value'>component</span> <span class='Paren'>(</span> <span class='Paren'>(</span> <span class='String'>"i"</span> <span class='Function'>|</span> <span class='String'>"I"</span> <span class='Paren'>)</span> <span class='Value'>component</span> <span class='Paren'>)</span><span class='Value'>?</span> -<span class='Value'>component</span> <span class='Function'>=</span> <span class='String'>"¯"</span><span class='Value'>?</span> <span class='Paren'>(</span> <span class='String'>"∞"</span> <span class='Function'>|</span> <span class='Value'>mantissa</span> <span class='Paren'>(</span> <span class='Paren'>(</span> <span class='String'>"e"</span> <span class='Function'>|</span> <span class='String'>"E"</span> <span class='Paren'>)</span> <span class='Value'>exponent</span> <span class='Paren'>)</span><span class='Value'>?</span> <span class='Paren'>)</span> +<p>The format of a <em>numeric literal</em> is more complicated. From the <a href="token.html">tokenization rules</a>, a numeric literal consists of a numeric character (one of <code><span class='Number'>¯∞π.0123456789</span></code>) followed by any number of numeric or alphabetic characters. Some numeric literals are <em>valid</em> and indicate a number, while others are invalid and cause an error. The grammar for valid numbers is given below in a <a href="https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form">BNF</a> variant. The alphabetic character allowed is "e" or "E", which functions as in scientific notation. Not included in this grammar are underscores—they can be placed anywhere in a number, including after the last non-underscore character, and are ignored entirely.</p> +<pre><span class='Value'>number</span> <span class='Function'>=</span> <span class='String'>"¯"</span><span class='Value'>?</span> <span class='Paren'>(</span> <span class='String'>"∞"</span> <span class='Function'>|</span> <span class='Value'>mantissa</span> <span class='Paren'>(</span> <span class='Paren'>(</span> <span class='String'>"e"</span> <span class='Function'>|</span> <span class='String'>"E"</span> <span class='Paren'>)</span> <span class='Value'>exponent</span> <span class='Paren'>)</span><span class='Value'>?</span> <span class='Paren'>)</span> <span class='Value'>exponent</span> <span class='Function'>=</span> <span class='String'>"¯"</span><span class='Value'>?</span> <span class='Value'>digit</span><span class='Function'>+</span> <span class='Value'>mantissa</span> <span class='Function'>=</span> <span class='String'>"π"</span> <span class='Function'>|</span> <span class='Value'>digit</span><span class='Function'>+</span> <span class='Paren'>(</span> <span class='String'>"."</span> <span class='Value'>digit</span><span class='Function'>+</span> <span class='Paren'>)</span><span class='Value'>?</span> <span class='Value'>digit</span> <span class='Function'>=</span> <span class='String'>"0"</span> <span class='Function'>|</span> <span class='String'>"1"</span> <span class='Function'>|</span> <span class='String'>"2"</span> <span class='Function'>|</span> <span class='String'>"3"</span> <span class='Function'>|</span> <span class='String'>"4"</span> <span class='Function'>|</span> <span class='String'>"5"</span> <span class='Function'>|</span> <span class='String'>"6"</span> <span class='Function'>|</span> <span class='String'>"7"</span> <span class='Function'>|</span> <span class='String'>"8"</span> <span class='Function'>|</span> <span class='String'>"9"</span> </pre> -<p>The digits or arabic numerals correspond to the numbers from 0 to 9 in the conventional way (also, each corresponds to its code point value minus 48). A sequence of digits gives a natural number by evaluating it in base 10: the number is 0 for an empty sequence, and otherwise the last digit's numerical value plus ten times the number obtained from the remaining digits. The symbol <code><span class='Number'>∞</span></code> indicates infinity and <code><span class='Number'>π</span></code> indicates the ratio <a href="https://en.wikipedia.org/wiki/Pi_(mathematics)">pi</a> of a circle's circumference to its diameter (or, for modern mathematicians, the smallest positive real number at which the function <code><span class='Brace'>{</span><span class='Function'>⋆</span><span class='Number'>0i1</span><span class='Function'>×</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code> attains a real part of 0). The <a href="https://aplwiki.com/wiki/High_minus">high minus</a> symbol <code><span class='Number'>¯</span></code> indicates that the number containing it is to be negated.</p> -<p>When an exponent is provided (with <code><span class='Value'>e</span></code> or <code><span class='Function'>E</span></code>), the corresponding mantissa is multiplied by ten to that power, giving the value <code><span class='Value'>mantissa</span><span class='Function'>×</span><span class='Number'>10</span><span class='Function'>⋆</span><span class='Value'>exponent</span></code>. If a second component is present (using <code><span class='Value'>i</span></code> or <code><span class='Function'>I</span></code>), that component's value is multiplied by the <a href="https://en.wikipedia.org/wiki/Imaginary_unit">imaginary unit</a> <em>i</em> and added to the first component; otherwise the value is the first component's value without modification. If complex numbers are not supported, then <code><span class='Value'>i</span></code> should not be allowed in numeric literals, even when followed by 0.</p> -<p>The above specification describes exactly a complex number with extended real components. To obtain a BQN number, each component is rounded to its nearest representative by the rules of the number system used: for IEEE 754, smallest distance, with ties rounding to the option with even mantissa.</p> +<p>The digits or arabic numerals correspond to the numbers from 0 to 9 in the conventional way (also, each corresponds to its code point value minus 48). A sequence of digits gives a natural number by evaluating it in base 10: the number is 0 for an empty sequence, and otherwise the last digit's numerical value plus ten times the number obtained from the remaining digits. The symbol <code><span class='Number'>∞</span></code> indicates infinity and <code><span class='Number'>π</span></code> indicates the ratio <a href="https://en.wikipedia.org/wiki/Pi_(mathematics)">pi</a> of a perfect circle's circumference to its diameter. The <a href="https://aplwiki.com/wiki/High_minus">high minus</a> symbol <code><span class='Number'>¯</span></code> indicates that the number containing it is to be negated. When an exponent is provided (with <code><span class='Value'>e</span></code> or <code><span class='Function'>E</span></code>), the corresponding mantissa is multiplied by ten to that power, giving the value <code><span class='Value'>mantissa</span><span class='Function'>×</span><span class='Number'>10</span><span class='Function'>⋆</span><span class='Value'>exponent</span></code>.</p> +<p>The above specification describes exactly an extended real number. To obtain a BQN number, each component is rounded to its nearest representative by the rules of the number system used: for IEEE 754, smallest distance, with ties rounding to the option with even mantissa.</p> diff --git a/docs/spec/types.html b/docs/spec/types.html index 50d96bf0..8f10434b 100644 --- a/docs/spec/types.html +++ b/docs/spec/types.html @@ -24,5 +24,5 @@ </ul> <p>A namespace holds the variables used to evaluate a block or program, as defined in the <a href="scope.html">scoping rules</a>. The observable aspects of a namespace are that it can be compared for equality with other namespaces and that it exposes variables associated with certain names, whose values can be queried or set.</p> <p>To begin the data types, a <em>character</em> is a <a href="https://en.wikipedia.org/wiki/Unicode">Unicode</a> code point, that is, its value is a non-negative integer within the ranges defined by Unicode (however, it is distinct from this number as a BQN value). Characters are ordered by this numeric value. BQN deals with code points as abstract entities and does not expose encodings such as UTF-8 or UTF-16.</p> -<p>The precise type of a <em>number</em> may vary across BQN implementations or instances. A <em>real number</em> is a member of some supported subset of the <a href="https://en.wikipedia.org/wiki/Extended_real_number_line">extended real numbers</a>, that is, the real numbers and positive or negative infinity. Some system must be defined for rounding an arbitrary real number to a member of this subset, and the basic arithmetic operations add, subtract, multiply, divide, and natural exponent (base <em>e</em>) are defined by performing these operations on exact real values and rounding the result. The Power function (dyadic <code><span class='Function'>⋆</span></code>) is also used but need not be exactly rounded. A <em>complex number</em> is a value with two real number <em>components</em>, a <em>real part</em> and an <em>imaginary part</em>. A BQN implementation can either support real numbers only, or complex numbers.</p> +<p>The precise type of a <em>number</em> may vary across BQN implementations or instances. The type must be a subset of the <a href="https://en.wikipedia.org/wiki/Extended_real_number_line">extended real numbers</a>, that is, the real numbers and positive or negative infinity. Some system must be defined for rounding an arbitrary real number to a member of this subset, and the basic arithmetic operations add, subtract, multiply, divide, and natural exponent (base <em>e</em>) are defined by performing these operations on exact real values and rounding the result. The Power function (dyadic <code><span class='Function'>⋆</span></code>) is also used but need not be exactly rounded. The <a href="complex.html">complex number</a> extension describes an optional extension to use complex numbers instead of reals only.</p> <p>An <em>array</em> is a rectangular collection of data. It is defined by a <em>shape</em>, which is a list of non-negative integer lengths, and a <em>ravel</em>, which is a list of <em>elements</em> whose length (the array's <em>bound</em>) is the product of all lengths in the shape. Arrays are defined inductively: any value (of a value or function type) can be used as an element of an array, but it is not possible for an array to contain itself as an element, or an array that contains itself, and so on. Types other than array are called <em>atomic types</em>, and their members are called <em>atoms</em>.</p> |
