diff options
| -rw-r--r-- | docs/spec/complex.html | 14 | ||||
| -rw-r--r-- | spec/complex.md | 15 |
2 files changed, 29 insertions, 0 deletions
diff --git a/docs/spec/complex.html b/docs/spec/complex.html new file mode 100644 index 00000000..a5d4826e --- /dev/null +++ b/docs/spec/complex.html @@ -0,0 +1,14 @@ +<head> + <link href="../favicon.ico" rel="shortcut icon" type="image/x-icon"/> + <link href="../style.css" rel="stylesheet"/> + <title>BQN Specification: Complex numbers</title> +</head> +<div class="nav">(<a href="https://github.com/mlochbaum/BQN">github</a>) / <a href="../index.html">BQN</a> / <a href="index.html">spec</a></div> +<h1 id="specification-complex-numbers"><a class="header" href="#specification-complex-numbers">Specification: Complex numbers</a></h1> +<p>Complex numbers are an optional extension to BQN's numeric system. If they are supported, the following functionality must also be supported. This extension is a draft and is versioned separately from the rest of the BQN specification.</p> +<p>A <em>complex number</em> is a value with two <em>components</em>, a <em>real part</em> and an <em>imaginary part</em>. The type of each component is a real number, as described in the <a href="types.html">type</a> specification. However, this type replaces the number type given there.</p> +<p>The <a href="literal.html">numeric literal</a> notation is extended with the character <code><span class='Value'>i</span></code>, which separates two real-valued components (in effect, it has lower "precedence" than other characters like <code><span class='Value'>e</span></code> and <code><span class='Number'>¯</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. As with real numbers, the exact complex number given is rounded to fit the number system in use.</p> +<pre><span class='Value'>complexnumber</span> <span class='Function'>=</span> <span class='Value'>number</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'>number</span> <span class='Paren'>)</span><span class='Value'>?</span> +</pre> +<p>Basic arithmetic functions <code><span class='Function'>+-×÷</span></code> are extended to complex numbers. A monadic case for the function <code><span class='Function'>+</span></code> is added, which returns the conjugate argument: a number with real part equal to the real part of <code><span class='Value'>𝕩</span></code> and imaginary part negated relative to <code><span class='Value'>𝕩</span></code>.</p> +<p>The primitive function <code><span class='Value'>⍳</span></code> is added: the character <code><span class='Value'>⍳</span></code> forms a primitive function <a href="token.html">token</a>, and its value is the function <code><span class='Brace'>{</span><span class='Value'>𝕨</span><span class='Function'>⊢</span><span class='Modifier2'>⊘</span><span class='Function'>+</span><span class='Number'>0j1</span><span class='Function'>×</span><span class='Value'>𝕩</span><span class='Brace'>}</span></code>. This function multiplies <code><span class='Value'>𝕩</span></code> by <em>i</em>, then adds <code><span class='Value'>𝕨</span></code> if given.</p> diff --git a/spec/complex.md b/spec/complex.md new file mode 100644 index 00000000..7b9a7cf0 --- /dev/null +++ b/spec/complex.md @@ -0,0 +1,15 @@ +*View this file with results and syntax highlighting [here](https://mlochbaum.github.io/BQN/spec/complex.html).* + +# Specification: Complex numbers + +Complex numbers are an optional extension to BQN's numeric system. If they are supported, the following functionality must also be supported. This extension is a draft and is versioned separately from the rest of the BQN specification. + +A *complex number* is a value with two *components*, a *real part* and an *imaginary part*. The type of each component is a real number, as described in the [type](types.md) specification. However, this type replaces the number type given there. + +The [numeric literal](literal.md) notation is extended with the character `i`, which separates two real-valued components (in effect, it has lower "precedence" than other characters like `e` and `¯`). 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. As with real numbers, the exact complex number given is rounded to fit the number system in use. + + complexnumber = number ( ( "i" | "I" ) number )? + +Basic arithmetic functions `+-×÷` are extended to complex numbers. A monadic case for the function `+` is added, which returns the conjugate argument: a number with real part equal to the real part of `𝕩` and imaginary part negated relative to `𝕩`. + +The primitive function `⍳` is added: the character `⍳` forms a primitive function [token](token.md), and its value is the function `{𝕨⊢⊘+0j1×𝕩}`. This function multiplies `𝕩` by *i*, then adds `𝕨` if given. |
