blob: a5d4826e0ba6bc754ea2eb3b32670511224cef01 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
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>
|