Circular: Difference between revisions

Jump to navigation Jump to search
576 bytes added ,  22:28, 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:
{{Built-in|Circular|○}}, or '''Circle Function''', is a [[dyadic]] [[scalar function]], which is essentially a collection of related monadic functions. Circular encompasses [[wikipedia:trigonometric functions|trigonometric functions]], [[wikipedia:hyperbolic functions|hyperbolic functions]], and a few relationships between them. On some implementations with [[complex number|complex numbers]], Circular also includes functions to decompose and assemble a complex number. It shares the [[glyph]] <source lang=apl inline>○</source> with the [[monadic]] arithmetic function [[Pi Times]].
{{Built-in|Circular|○}}, or '''Circle Function''', is a [[dyadic]] [[scalar function]], which is essentially a collection of related monadic functions. Circular encompasses [[wikipedia:trigonometric functions|trigonometric functions]], [[wikipedia:hyperbolic functions|hyperbolic functions]], and a few relationships between them. On some implementations with [[complex number|complex numbers]], Circular also includes functions to decompose and assemble a complex number. It shares the [[glyph]] <syntaxhighlight lang=apl inline>○</syntaxhighlight> with the [[monadic]] arithmetic function [[Pi Times]].


== Design ==
== Design ==


The Circular function, as found in today's APL implementations, was designed by  [[Gene McDonnell]], based on three things:<ref>[[Gene McDonnell|McDonnell, Gene]]. [https://www.jsoftware.com/papers/eem/storyofo.htm The Story of <source lang=apl inline>○</source>]. Recreational APL. [[APL Quote-Quad]], Volume 8, Number 2, 1977-12.</ref>
The Circular function, as found in today's APL implementations, was designed by  [[Gene McDonnell]], based on three things:<ref>[[Gene McDonnell|McDonnell, Gene]]. [https://www.jsoftware.com/papers/eem/storyofo.htm The Story of <syntaxhighlight lang=apl inline>○</syntaxhighlight>]. Recreational APL. [[APL Quote-Quad]], Volume 8, Number 2, 1977-12.</ref>
* [[Ken Iverson]] stating that [[Semantic density|a concise programming language]] must group together related monadic functions as a dyadic function that takes a "controlling parameter" as left argument to select specific function.
* [[Ken Iverson]] stating that [[Semantic density|a concise programming language]] must group together related monadic functions as a dyadic function that takes a "controlling parameter" as left argument to select specific function.
* The sine, tangent, hyperbolic sine, and hyperbolic tangent are [[wikipedia:odd function|odd functions]].
* The sine, tangent, hyperbolic sine, and hyperbolic tangent are [[wikipedia:odd function|odd functions]].
Line 13: Line 13:


{| class="wikitable c" style="margin: 1em auto 1em auto"
{| class="wikitable c" style="margin: 1em auto 1em auto"
! style="width:33%" | <source lang=apl inline>(-X)○Y</source> !! style="width:33%" | <source lang=apl inline>X</source> !! <source lang=apl inline>X○Y</source>
! style="width:33%" | <syntaxhighlight lang=apl inline>(-X)○Y</syntaxhighlight> !! style="width:33%" | <syntaxhighlight lang=apl inline>X</syntaxhighlight> !! <syntaxhighlight lang=apl inline>X○Y</syntaxhighlight>
|-
|-
| → || 0 || <math>\sqrt{1-Y^2}</math>
| → || 0 || <math>\sqrt{1-Y^2}</math>
Line 34: Line 34:
The following shows the values of sine, cosine, and tangent at <math>0, \frac{\pi}{2}, \pi</math>. Note that zeros are not exact and <math>\tan{\frac{\pi}{2}}</math> does not signal [[DOMAIN ERROR]] because of limited precision of <math>\pi</math>.
The following shows the values of sine, cosine, and tangent at <math>0, \frac{\pi}{2}, \pi</math>. Note that zeros are not exact and <math>\tan{\frac{\pi}{2}}</math> does not signal [[DOMAIN ERROR]] because of limited precision of <math>\pi</math>.


<source lang=apl>
<syntaxhighlight lang=apl>
       ⎕PP←5
       ⎕PP←5
       'sin' 'cos' 'tan',1 2 3∘.○ ○0 0.5 1
       'sin' 'cos' 'tan',1 2 3∘.○ ○0 0.5 1
Line 40: Line 40:
  cos  1 6.1232E¯17 ¯1         
  cos  1 6.1232E¯17 ¯1         
  tan  0 1.6331E16  ¯1.2246E¯16
  tan  0 1.6331E16  ¯1.2246E¯16
</source>{{Works in|[[Dyalog APL]]}}
</syntaxhighlight>{{Works in|[[Dyalog APL]]}}


<source lang=apl inline>0○Y</source> and <source lang=apl inline>4○Y</source>/<source lang=apl inline>¯4○Y</source> reflect the identities <math>\sin^2{Y} + \cos^2{Y} = 1</math> and <math>\cosh^2{Y} - \sinh^2{Y} = 1</math> respectively. In APL code, <source lang=apl inline>0○Y</source> is equivalent to <source lang=apl inline>1○¯2○Y</source> and <source lang=apl inline>2○¯1○Y</source>, <source lang=apl inline>4○Y</source> is equivalent to <source lang=apl inline>6○¯5○Y</source>, and <source lang=apl inline>¯4○Y</source> is equivalent to <source lang=apl inline>5○¯6○Y</source>.
<syntaxhighlight lang=apl inline>0○Y</syntaxhighlight> and <syntaxhighlight lang=apl inline>4○Y</syntaxhighlight>/<syntaxhighlight lang=apl inline>¯4○Y</syntaxhighlight> reflect the identities <math>\sin^2{Y} + \cos^2{Y} = 1</math> and <math>\cosh^2{Y} - \sinh^2{Y} = 1</math> respectively. In APL code, <syntaxhighlight lang=apl inline>0○Y</syntaxhighlight> is equivalent to <syntaxhighlight lang=apl inline>1○¯2○Y</syntaxhighlight> and <syntaxhighlight lang=apl inline>2○¯1○Y</syntaxhighlight>, <syntaxhighlight lang=apl inline>4○Y</syntaxhighlight> is equivalent to <syntaxhighlight lang=apl inline>6○¯5○Y</syntaxhighlight>, and <syntaxhighlight lang=apl inline>¯4○Y</syntaxhighlight> is equivalent to <syntaxhighlight lang=apl inline>5○¯6○Y</syntaxhighlight>.


<source lang=apl>
<syntaxhighlight lang=apl>
       0○¯0.9 ¯0.3 0 0.3 0.9
       0○¯0.9 ¯0.3 0 0.3 0.9
0.43589 0.95394 1 0.95394 0.43589
0.43589 0.95394 1 0.95394 0.43589
Line 61: Line 61:
       5○¯6○1 3 10
       5○¯6○1 3 10
0 2.8284 9.9499
0 2.8284 9.9499
</source>
</syntaxhighlight>


On implementations with complex number support, <source lang=apl inline>¯4○Y</source> is modified to <math>(Y+1)\sqrt{\frac{Y-1}{Y+1}}</math> so that it agrees with <source lang=apl inline>5○¯6○Y</source> for complex numbers.
On implementations with complex number support, <syntaxhighlight lang=apl inline>¯4○Y</syntaxhighlight> is modified to <math>(Y+1)\sqrt{\frac{Y-1}{Y+1}}</math> so that it agrees with <syntaxhighlight lang=apl inline>5○¯6○Y</syntaxhighlight> for complex numbers.


As a [[mnemonics|mnemonic]], the functions for even X are [[wikipedia:even function|even functions]], and those for odd X are [[wikipedia:odd function|odd functions]]. Also, <source lang=apl inline>X○Y</source> and <source lang=apl inline>(-X)○Y</source> are inverses of each other.
As a [[mnemonics|mnemonic]], the functions for even X are [[wikipedia:even function|even functions]], and those for odd X are [[wikipedia:odd function|odd functions]]. Also, <syntaxhighlight lang=apl inline>X○Y</syntaxhighlight> and <syntaxhighlight lang=apl inline>(-X)○Y</syntaxhighlight> are inverses of each other.


=== Functions added with complex number support ===
=== Functions added with complex number support ===
Line 72: Line 72:


{| class="wikitable c" style="margin: 1em auto 1em auto"
{| class="wikitable c" style="margin: 1em auto 1em auto"
! style="width:33%" | <source lang=apl inline>(-X)○Y</source> !! style="width:33%" | <source lang=apl inline>X</source> !! <source lang=apl inline>X○Y</source>
! style="width:33%" | <syntaxhighlight lang=apl inline>(-X)○Y</syntaxhighlight> !! style="width:33%" | <syntaxhighlight lang=apl inline>X</syntaxhighlight> !! <syntaxhighlight lang=apl inline>X○Y</syntaxhighlight>
|-
|-
| <math>-\sqrt{-1-Y^2}</math> || 8 || <math>\sqrt{-1-Y^2}</math>
| <math>-\sqrt{-1-Y^2}</math> || 8 || <math>\sqrt{-1-Y^2}</math>
Line 87: Line 87:
The left arguments 9 and 11 extract the real and imaginary parts (the [[wikipedia:cartesian coordinate system|Cartesian coordinates]] on the complex plane), while 10 and 12 extract the magnitude and angle (the [[wikipedia:polar coordinate system|polar coordinates]]). The negative counterparts can be used to [[complex (function)|assemble a single complex number]] from the Cartesian or polar coordinates.
The left arguments 9 and 11 extract the real and imaginary parts (the [[wikipedia:cartesian coordinate system|Cartesian coordinates]] on the complex plane), while 10 and 12 extract the magnitude and angle (the [[wikipedia:polar coordinate system|polar coordinates]]). The negative counterparts can be used to [[complex (function)|assemble a single complex number]] from the Cartesian or polar coordinates.


<source lang=apl>
<syntaxhighlight lang=apl>
       ⎕←mat←9 11∘.○1J2 3J¯4 ¯5J¯6 ⍝ first row is real, second row is imag
       ⎕←mat←9 11∘.○1J2 3J¯4 ¯5J¯6 ⍝ first row is real, second row is imag
1  3 ¯5
1  3 ¯5
Line 99: Line 99:
       ¯10 ¯12×.○mat
       ¯10 ¯12×.○mat
1J2 3J¯4 ¯5J¯6
1J2 3J¯4 ¯5J¯6
</source>{{Works in|[[Dyalog APL]]}}
</syntaxhighlight>{{Works in|[[Dyalog APL]]}}


[[J]] has separate built-in functions for these operations: [https://code.jsoftware.com/wiki/Vocabulary/plusdot '''Real/Imag'''] <source lang=j inline>+.</source> (Cartesian decomposition), [https://code.jsoftware.com/wiki/Vocabulary/stardot '''Length/Angle'''] <source lang=j inline>*.</source> (polar decomposition), [https://code.jsoftware.com/wiki/Vocabulary/jdot#dyadic '''Complex'''] <source lang=j inline>j.</source> (Cartesian assembly), and [https://code.jsoftware.com/wiki/Vocabulary/rdot#dyadic '''Polar'''] <source lang=j inline>r.</source> (polar assembly). Note that, unlike the APL version above, <source lang=j inline>+.</source> and <source lang=j inline>*.</source> create a trailing axis of length 2.
[[J]] has separate built-in functions for these operations: [https://code.jsoftware.com/wiki/Vocabulary/plusdot '''Real/Imag'''] <syntaxhighlight lang=j inline>+.</syntaxhighlight> (Cartesian decomposition), [https://code.jsoftware.com/wiki/Vocabulary/stardot '''Length/Angle'''] <syntaxhighlight lang=j inline>*.</syntaxhighlight> (polar decomposition), [https://code.jsoftware.com/wiki/Vocabulary/jdot#dyadic '''Complex'''] <syntaxhighlight lang=j inline>j.</syntaxhighlight> (Cartesian assembly), and [https://code.jsoftware.com/wiki/Vocabulary/rdot#dyadic '''Polar'''] <syntaxhighlight lang=j inline>r.</syntaxhighlight> (polar assembly). Note that, unlike the APL version above, <syntaxhighlight lang=j inline>+.</syntaxhighlight> and <syntaxhighlight lang=j inline>*.</syntaxhighlight> create a trailing axis of length 2.


<source lang=j>
<syntaxhighlight lang=j>
       ]mat =: +. 1j2 3j_4 _5j_6
       ]mat =: +. 1j2 3j_4 _5j_6
  1  2
  1  2
Line 117: Line 117:
       r./"1 mat
       r./"1 mat
1j2 3j_4 _5j_6
1j2 3j_4 _5j_6
</source>{{Works in|[[J]]}}
</syntaxhighlight>{{Works in|[[J]]}}


== References ==
== References ==

Navigation menu