Complex number

From APL Wiki
Revision as of 15:41, 24 January 2020 by Marshall (talk | contribs) (Created page with "A '''complex number''' type is a numeric type which represents, usually with some limited precision, the complex numbers. Complex number suppo...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

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.


Complex numbers are usually written with a "J" joining the real and imaginary parts. Complex numbers are added component-wise.

      1J¯2 + 3J4

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 110 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:



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.


The following languages support complex numbers as a built in numeric type.

APL features [edit]
Built-ins Primitive functionPrimitive operatorQuad name
Array model ShapeRankDepthBoundIndex (Indexing) ∙ AxisRavelRavel orderElementScalarVectorMatrixSimple scalarSimple arrayNested arrayCellMajor cellSubarrayEmpty arrayPrototype
Data types Number (Boolean, Complex number) ∙ Character (String) ∙ BoxNamespace
Concepts and paradigms Leading axis theoryScalar extensionConformabilityLeading axis agreementScalar functionPervasionGlyphIdentity elementComplex floorTotal array ordering