Complex (function): Difference between revisions

Jump to navigation Jump to search
1,557 bytes added ,  07:20, 10 August 2022
History
(History)
Line 1: Line 1:
{{Built-in|Complex|⌾}} is a [[dyadic]] [[scalar function]] which combines its arguments into a [[complex number]] having with the left argument as real part and the right argument as imaginary part. It was added to [[J]] as <source lang=j inline>j.</source> together with initial support for complex numbers, and was adopted in [[Extended Dyalog APL]] using the [[glyph]] <source lang=apl inline>⌾</source> because it was seen as a type of numerical [[Beside|composition]] (<source lang=apl inline>∘</source>) for the [[Circle|circular]] (<source lang=apl inline>○</source>) domain. Complex shares its glyph with [[Imaginary]] which is equivalent to applying Complex with a left argument of 0.
{{Built-in|Complex|⌾}} is a [[dyadic]] [[scalar function]] which combines its arguments into a [[complex number]] having with the left argument as real part and the right argument as imaginary part. It was added to [[J]] as <source lang=j inline>j.</source> together with initial support for complex numbers, and was adopted in [[Extended Dyalog APL]] using the [[glyph]] <source lang=apl inline>⌾</source> because it was seen as a type of numerical [[Beside|composition]] (<source lang=apl inline>∘</source>) for the [[Circle|circular]] (<source lang=apl inline>○</source>) domain. Complex shares its glyph with [[Imaginary]] which is equivalent to applying Complex with a left argument of 0.
== History ==


The question of whether to include this function is one of [[Roger Hui]]'s 50 exercises in APL language design<ref>[[Roger Hui]]. Some Exercises in APL Language Design. Jsoftware. 2016.</ref>:
The question of whether to include this function is one of [[Roger Hui]]'s 50 exercises in APL language design<ref>[[Roger Hui]]. Some Exercises in APL Language Design. Jsoftware. 2016.</ref>:
<blockquote>Complex numbers can be constructed as ordered pairs of real numbers, similar to how integers can be constructed as ordered pairs of natural numbers and rational numbers as ordered pairs of integers. For complex numbers, <source lang=j inline>j.</source> plays the same role as <source lang=apl inline>-</source> for integers and <source lang=apl inline>÷</source> for rational numbers. </blockquote>
<blockquote>Complex numbers can be constructed as ordered pairs of real numbers, similar to how integers can be constructed as ordered pairs of natural numbers and rational numbers as ordered pairs of integers. For complex numbers, <source lang=j inline>j.</source> plays the same role as <source lang=apl inline>-</source> for integers and <source lang=apl inline>÷</source> for rational numbers. </blockquote>
Hui goes on to quote [[Adám Brudzewsky]]:<ref>[[Roger Hui|Hui, Roger]]. [https://forums.dyalog.com/viewtopic.php?f=30&t=1786&p=7020&hilit=complex+imaginary#p7020 ⊕ and ⊗]. Dyalog Forums. 13 Jul 2021.</ref>
<blockquote>(…) I’d probably go for <source lang=apl inline>⊕</source> because:
* it is more clearly related to <source lang=apl inline>○</source> (for which the monadic form is also a simple multiplication)
* it consists of two overstruck basic APL symbols
* it looks more harmonic (in my eyes)
Oh, and Euler’s formula turns out beautiful (to my taste) with it:
<source lang=apl>0 = 1+*⊕○1
0 = 1+*○⊕1</source></blockquote>
Hui continues:
<blockquote>
On further reflection, I like the <source lang=apl inline>⊕</source> symbol for <source lang=apl inline>j←{⍺←0 ⋄ ⍺+0j1×⍵}</source>. If there are existing interpretation of it this one should predominate, if the function is as important as I think it is. (Peer to <source lang=apl inline>-</source> and <source lang=apl inline>÷</source>, etc.)


Moreover, complex numbers are commonly represented by magnitude and phase. So if you have a magnitude and phase, how do you get the number so represented? Why <source lang=apl inline>k←{⍺←1 ⋄ ⍺×*0j1×⍵}</source> (or <source lang=apl inline>{⍺←1 ⋄ ⍺×*⊕⍵}</source>) of course. And what symbol would you use? <source lang=apl inline>⊗</source> (Monadic <source lang=apl inline>⊗</source>, with a default magnitude of 1, gets you a point on the unit circle.)
</blockquote>
== Examples ==
== Examples ==


Navigation menu