Complex number: Difference between revisions
m (Text replacement - "</source>" to "</syntaxhighlight>") |
m (Text replacement - "<source" to "<syntaxhighlight") Tags: Mobile edit Mobile web edit |
||
Line 1: | Line 1: | ||
A '''complex number''' type is a [[number|numeric type]] which represents, usually with some limited precision, the [[wikipedia:Complex number|complex numbers]]. Complex number support is defined as an optional facility in the XAPL standard ([[ISO/IEC 13751:2001]]), and complex numbers are available in many APLs. Usually these numbers are written with a syntax such as < | A '''complex number''' type is a [[number|numeric type]] which represents, usually with some limited precision, the [[wikipedia:Complex number|complex numbers]]. Complex number support is defined as an optional facility in the XAPL standard ([[ISO/IEC 13751:2001]]), and complex numbers are available in many APLs. Usually these numbers are written with a syntax such as <syntaxhighlight lang=apl inline>5j2</syntaxhighlight> or <syntaxhighlight lang=apl inline>5J2</syntaxhighlight> for the complex number with real part 5 and imaginary part 2. | ||
== Examples == | == Examples == | ||
Complex numbers are usually written with a "J" joining the real and imaginary parts. Complex numbers are added component-wise. | Complex numbers are usually written with a "J" joining the real and imaginary parts. Complex numbers are added component-wise. | ||
< | <syntaxhighlight lang=apl> | ||
1J¯2 + 3J4 | 1J¯2 + 3J4 | ||
4J2 | 4J2 | ||
</syntaxhighlight> | </syntaxhighlight> | ||
The [[Circle function]] can be used to split a complex number into its components: a left argument of 9 gets the real part and a left argument of 11 gets the imaginary part. With the [[Rank operator]], Circle can be used to convert a [[shape]] < | The [[Circle function]] can be used to split a complex number into its components: a left argument of 9 gets the real part and a left argument of 11 gets the imaginary part. With the [[Rank operator]], Circle can be used to convert a [[shape]] <syntaxhighlight lang=apl inline>s</syntaxhighlight> complex array to a shape <syntaxhighlight lang=apl inline>s,2</syntaxhighlight> real array where each row contains the components of one complex number. | ||
< | <syntaxhighlight lang=apl> | ||
9 11 ○ 12J3 | 9 11 ○ 12J3 | ||
12 3 | 12 3 | ||
Line 18: | Line 18: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
Operations on real numbers can sometimes yield complex numbers. Famously, the square root of minus one is the imaginary unit: | Operations on real numbers can sometimes yield complex numbers. Famously, the square root of minus one is the imaginary unit: | ||
< | <syntaxhighlight lang=apl> | ||
¯1*÷2 | ¯1*÷2 | ||
0J1 | 0J1 |
Revision as of 22:08, 10 September 2022
A complex number type is a numeric type which represents, usually with some limited precision, the complex numbers. Complex number support is defined as an optional facility in the XAPL standard (ISO/IEC 13751:2001), and complex numbers are available in many APLs. Usually these numbers are written with a syntax such as 5j2
or 5J2
for the complex number with real part 5 and imaginary part 2.
Examples
Complex numbers are usually written with a "J" joining the real and imaginary parts. Complex numbers are added component-wise.
1J¯2 + 3J4 4J2
The Circle function can be used to split a complex number into its components: a left argument of 9 gets the real part and a left argument of 11 gets the imaginary part. With the Rank operator, Circle can be used to convert a shape s
complex array to a shape s,2
real array where each row contains the components of one complex number.
9 11 ○ 12J3 12 3 9 11∘○⍤0 ⊢6J5 4J3 2J1 6 5 4 3 2 1
Operations on real numbers can sometimes yield complex numbers. Famously, the square root of minus one is the imaginary unit:
¯1*÷2 0J1
Implementation
Complex numbers are almost always defined to be a pair of 64-bit floating point numbers (IEEE 754). If 64-bit floats are used for real numbers as well then this definition makes complex numbers a superset of the real numbers as represented. This means that the language semantics can be defined purely in terms of complex numbers. However, for performance and precision reasons, operations are implemented both on real numbers and complex numbers. If all the numbers in an array have imaginary part zero, then it is represented as a real array (or a smaller type such as integer), and primitives applied to it will use code written specifically for real numbers.
Support
The following languages support complex numbers as a built in numeric type.
APL features [edit] | |
---|---|
Built-ins | Primitives (functions, operators) ∙ Quad name |
Array model | Shape ∙ Rank ∙ Depth ∙ Bound ∙ Index (Indexing) ∙ Axis ∙ Ravel ∙ Ravel order ∙ Element ∙ Scalar ∙ Vector ∙ Matrix ∙ Simple scalar ∙ Simple array ∙ Nested array ∙ Cell ∙ Major cell ∙ Subarray ∙ Empty array ∙ Prototype |
Data types | Number (Boolean, Complex number) ∙ Character (String) ∙ Box ∙ Namespace ∙ Function array |
Concepts and paradigms | Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity element ∙ Complex floor ∙ Array ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ Glyph ∙ Leading axis theory ∙ Major cell search ∙ First-class function |
Errors | LIMIT ERROR ∙ RANK ERROR ∙ SYNTAX ERROR ∙ DOMAIN ERROR ∙ LENGTH ERROR ∙ INDEX ERROR ∙ VALUE ERROR ∙ EVOLUTION ERROR |