Complex number: Difference between revisions

Jump to navigation Jump to search
126 bytes added ,  22:08, 10 September 2022
m
Text replacement - "<source" to "<syntaxhighlight"
No edit summary
m (Text replacement - "<source" to "<syntaxhighlight")
Tags: Mobile edit Mobile web edit
 
(One intermediate revision by the same user not shown)
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 <source lang=apl inline>5j2</source> or <source lang=apl inline>5J2</source> for the complex number with real part 5 and imaginary part 2.
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.
<source lang=apl>
<syntaxhighlight lang=apl>
       1J¯2 + 3J4
       1J¯2 + 3J4
4J2
4J2
</source>
</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]] <source lang=apl inline>s</source> complex array to a shape <source lang=apl inline>s,2</source> real array where each row contains the components of one complex number.
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.
<source lang=apl>
<syntaxhighlight lang=apl>
       9 11 ○ 12J3
       9 11 ○ 12J3
12 3
12 3
Line 16: Line 16:
4 3
4 3
2 1
2 1
</source>
</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:
<source lang=apl>
<syntaxhighlight lang=apl>
       ¯1*÷2
       ¯1*÷2
0J1
0J1
</source>
</syntaxhighlight>


== Implementation ==
== Implementation ==

Navigation menu