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 /spec | |
| parent | 0d065be5a871100eb5c2a332499fa1cb65a9f5e5 (diff) | |
Separate complex number specification into its own extension
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/README.md | 3 | ||||
| -rw-r--r-- | spec/literal.md | 11 | ||||
| -rw-r--r-- | spec/types.md | 2 |
3 files changed, 7 insertions, 9 deletions
diff --git a/spec/README.md b/spec/README.md index 191116fa..a549066e 100644 --- a/spec/README.md +++ b/spec/README.md @@ -15,10 +15,11 @@ The following documents are included in the BQN specification. A BQN program is - [Evaluation semantics](evaluate.md) - [Primitives](primitive.md): [reference implementations](reference.bqn) - [Inferred properties](inferred.md) (identities, fills, Undo, and Under) +- [Complex numbers](complex.md) optional extension - [System-provided values](system.md) (`•`) In several cases, an implementation can choose between more than one possible behavior. -- 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. +- An implementation chooses its number system, which must be an approximation of the real (can be extended to [complex](complex.md)) numbers but has no specific requirements. Results of basic numeric operations must be deterministic but are not specified. - Minimum (`⌊`) and Maximum (`⌈`) may give an error if either argument is a character. - 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. - 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. diff --git a/spec/literal.md b/spec/literal.md index ab644601..a46f326e 100644 --- a/spec/literal.md +++ b/spec/literal.md @@ -6,16 +6,13 @@ A *literal* is a single [token](token.md) that indicates a fixed character, numb 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 [data type](types.md), 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 *character literal* is enclosed with single quotes `'` and its value is identical to the single character between them. A *string literal* is enclosed in double quotes `"`, 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 *null literal* is the token `@` and represents the null character, code point 0. -The format of a *numeric literal* is more complicated. From the [tokenization rules](token.md), a numeric literal consists of a numeric character (one of `¯∞π.0123456789`) followed by any number of numeric or alphabetic characters. Some numeric literals are *valid* and indicate a number, while others are invalid and cause an error. The grammar for valid numbers is given below in a [BNF](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form) 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. +The format of a *numeric literal* is more complicated. From the [tokenization rules](token.md), a numeric literal consists of a numeric character (one of `¯∞π.0123456789`) followed by any number of numeric or alphabetic characters. Some numeric literals are *valid* and indicate a number, while others are invalid and cause an error. The grammar for valid numbers is given below in a [BNF](https://en.wikipedia.org/wiki/Backus%E2%80%93Naur_form) 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. - number = component ( ( "i" | "I" ) component )? - component = "¯"? ( "∞" | mantissa ( ( "e" | "E" ) exponent )? ) + number = "¯"? ( "∞" | mantissa ( ( "e" | "E" ) exponent )? ) exponent = "¯"? digit+ mantissa = "π" | digit+ ( "." digit+ )? digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" -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 `∞` indicates infinity and `π` indicates the ratio [pi](https://en.wikipedia.org/wiki/Pi_(mathematics)) of a circle's circumference to its diameter (or, for modern mathematicians, the smallest positive real number at which the function `{⋆0i1×𝕩}` attains a real part of 0). The [high minus](https://aplwiki.com/wiki/High_minus) symbol `¯` indicates that the number containing it is to be negated. +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 `∞` indicates infinity and `π` indicates the ratio [pi](https://en.wikipedia.org/wiki/Pi_(mathematics)) of a perfect circle's circumference to its diameter. The [high minus](https://aplwiki.com/wiki/High_minus) symbol `¯` indicates that the number containing it is to be negated. When an exponent is provided (with `e` or `E`), the corresponding mantissa is multiplied by ten to that power, giving the value `mantissa×10⋆exponent`. -When an exponent is provided (with `e` or `E`), the corresponding mantissa is multiplied by ten to that power, giving the value `mantissa×10⋆exponent`. If a second component is present (using `i` or `I`), that component's value is multiplied by the [imaginary unit](https://en.wikipedia.org/wiki/Imaginary_unit) *i* and added to the first component; otherwise the value is the first component's value without modification. If complex numbers are not supported, then `i` should not be allowed in numeric literals, even when followed by 0. - -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. +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. diff --git a/spec/types.md b/spec/types.md index dc596563..8394039c 100644 --- a/spec/types.md +++ b/spec/types.md @@ -22,6 +22,6 @@ A namespace holds the variables used to evaluate a block or program, as defined To begin the data types, a *character* is a [Unicode](https://en.wikipedia.org/wiki/Unicode) 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. -The precise type of a *number* may vary across BQN implementations or instances. A *real number* is a member of some supported subset of the [extended real numbers](https://en.wikipedia.org/wiki/Extended_real_number_line), 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 *e*) are defined by performing these operations on exact real values and rounding the result. The Power function (dyadic `⋆`) is also used but need not be exactly rounded. A *complex number* is a value with two real number *components*, a *real part* and an *imaginary part*. A BQN implementation can either support real numbers only, or complex numbers. +The precise type of a *number* may vary across BQN implementations or instances. The type must be a subset of the [extended real numbers](https://en.wikipedia.org/wiki/Extended_real_number_line), 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 *e*) are defined by performing these operations on exact real values and rounding the result. The Power function (dyadic `⋆`) is also used but need not be exactly rounded. The [complex number](complex.md) extension describes an optional extension to use complex numbers instead of reals only. An *array* is a rectangular collection of data. It is defined by a *shape*, which is a list of non-negative integer lengths, and a *ravel*, which is a list of *elements* whose length (the array's *bound*) 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 *atomic types*, and their members are called *atoms*. |
