Circular

From APL Wiki
Jump to navigation Jump to search

Circular (), or Circle Function, is a dyadic scalar function, which is essentially a collection of related monadic functions. Circular encompasses trigonometric functions, hyperbolic functions, and a few relationships between them. On some implementations with complex numbers, Circular also includes functions to decompose and assemble a complex number. It shares the glyph with the monadic arithmetic function Pi Times.

Examples

Most APL implementations agree on the following functions:

(-X)Y X XY
0
1
2
3
4
5
6
7

The following shows the values of sine, cosine, and tangent at . Note that zeros are not exact and does not signal DOMAIN ERROR because of limited precision of .

      ⎕PP5
      'sin' 'cos' 'tan',1 2 3∘. 0 0.5 1
 sin  0 1           1.2246E¯16
 cos  1 6.1232E¯17 ¯1         
 tan  0 1.6331E16  ¯1.2246E¯16
Works in: Dyalog APL

0Y and 4Y/¯4Y reflect the identities and respectively. In APL code, 0Y is equivalent to 1¯2Y and 2¯1Y, 4Y is equivalent to 6¯5Y, and ¯4Y is equivalent to 5¯6Y.

      0¯0.9 ¯0.3 0 0.3 0.9
0.43589 0.95394 1 0.95394 0.43589
      1¯2¯0.9 ¯0.3 0 0.3 0.9
0.43589 0.95394 1 0.95394 0.43589
      2¯1¯0.9 ¯0.3 0 0.3 0.9
0.43589 0.95394 1 0.95394 0.43589

      4¯10 ¯1 0 1 10
10.05 1.4142 1 1.4142 10.05
      6¯5¯10 ¯1 0 1 10
10.05 1.4142 1 1.4142 10.05

      ¯41 3 10
0 2.8284 9.9499
      5¯61 3 10
0 2.8284 9.9499

On implementations with complex number support, ¯4Y is modified to so that it agrees with 5¯6Y for complex numbers.

As a mnemonic, the functions for even X are even functions, and those for odd X are odd functions. Also, XY and (-X)Y are inverses of each other.

Functions added with complex number support

Extensions with complex numbers are as follows:

(-X)Y X XY
8
Y unchanged 9 real part of Y
conjugate of Y 10 magnitude of Y
complex () 11 imaginary part of Y
12 phase of Y

The left arguments 9 and 11 extract the real and imaginary parts (the Cartesian coordinates on the complex plane), while 10 and 12 extract the magnitude and angle (the polar coordinates). The negative counterparts can be used to assemble a single complex number from the Cartesian or polar coordinates.

      mat9 11∘.1J2 3J¯4 ¯5J¯6 ⍝ first row is real, second row is imag
1  3 ¯5
2 ¯4 ¯6
      ¯9 ¯11+.mat
1J2 3J¯4 ¯5J¯6

      mat10 12∘.1J2 3J¯4 ¯5J¯6 ⍝ first row is length, second row is angle
2.2361  5       7.8102
1.1071 ¯0.9273 ¯2.2655
      ¯10 ¯12×.mat
1J2 3J¯4 ¯5J¯6
Works in: Dyalog APL

J has separate built-in functions for these operations: Real/Imag +. (Cartesian decomposition), Length/Angle *. (polar decomposition), Complex j. (Cartesian assembly), and Polar r. (polar assembly). Note that, unlike the APL version above, +. and *. create a trailing axis of length 2.

      ]mat =: +. 1j2 3j_4 _5j_6
 1  2
 3 _4
_5 _6
      j./"1 mat
1j2 3j_4 _5j_6

      ]mat =: *. 1j2 3j_4 _5j_6
2.23607   1.10715
      5 _0.927295
7.81025  _2.26553
      r./"1 mat
1j2 3j_4 _5j_6
Works in: J

External links

Documentation

APL built-ins [edit]
Primitive functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentitySelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndex
Selector Index generatorGradeIndex OfInterval IndexIndicesDeal
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Primitive operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-beamSpawnFunction axis
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencilCut (J)
Quad names
Arrays Index originMigration levelAtomic vector
Functions Case convertUnicode convert
Operators SearchReplace