Power (operator)

From APL Wiki
(Redirected from Ply)
Jump to navigation Jump to search

Power () is a primitive dyadic operator that performs bounded looping, unbounded looping, and function inverses in NARS2000, Dyalog APL, and related implementations like ngn/apl, dzaima/APL, and Extended Dyalog APL.

Description

A call to Power is of the form X(f⍣g)Y, where

  • X is an optional argument.
  • f is a function. If X is given, then it is bound to f so X f⍣g Y is equivalent to X∘f⍣g Y.
  • g can be an array or a function.

Power repeatedly applies f to Y based on the type of operand g:

  • Function: Must be dyadic and must return a boolean singleton. The previous iteration value is provided as the right argument to f, and the current iteration value is given as the left argument. f is repeatedly applied until this function returns 1.
  • Integer: Applies f g times to Y. If g is negative, then the inverse of f (if available) is applied.
  • Integer Array: In Extended Dyalog APL, g can be an integer array. Each integer i in g will be replaced by ⊂(f⍣i)Y.

Examples

Some basic examples:

      1 (+⍣3) 5 ⍝ Fixed number of iterations
8
      (2∘×⍣3) 5 ⍝ No X given
40
      1 +∘÷⍣= 1 ⍝ iterate till fixed point
1.618033989

A well-known use for Power is iterating until a fixed point is reached.

      (∨.∧⍨∨⊢)⍣≡3 3⍴0 0 1 1 0 1 1 0 1 ⍝ Transitive closure of an adjacency matrix
1 0 1
1 0 1
1 0 1

Power is also used to access function inverses.

      2(⊥⍣¯1)5
1 0 1

History

Iverson defined the Power operator in Operators and Functions in 1978, with f⍣_ signifying Power Limit, as _ was defined to mean infinity. This paper mentions the use of negative numbers for inverses, and also defines a form f⍣∘ to create a function returning f's identity element. This version was implemented in 1981 in NARS, changing f⍣∘ to Power Limit as infinity wasn't present. IBM researchers Ziad Ghandour and Jorge Mezei had defined a precursor in the 1973 report "General Arrays, Operators, and Functions"[1] with the name "fold", and "limit" for Power Limit, using a quad overstruck with a star; their version did not allow negative powers.

Outside of the experimental NARS, Power remained unimplemented for many years. In the 1987 A Dictionary of APL, Iverson changed it to the form u.n, "Ply", which would eventually be implemented in SAX. The extension to allow a left argument was proposed by Eugene McDonnell in 1988, following similar usage by Hai-Chen Tu and Alan Perlis in a hypothetical related operator returning an infinite list.[2] J implemented this ambivalent Power as ^: by 1991, with power limit ^:_ added in version 4.0 that year. J handles a function right operand by calling it on the arguments to produce the repetition number (a convention also adopted by BQN), and in 2005 defined a boxed operand to indicate all repetitions less than the boxed number.

Dyalog APL 11.0 (2006) implemented Power () similar to that of NARS, with its own handling of a function right argument generalizing Power Limit. Some form of Power operator now appears in various dialects including ngn/apl, dzaima/APL, Kap, and TinyAPL.

External Links

Lessons

Documentation

References

  1. Ziad Ghandour and Jorge Mezei. "General Arrays, Operators, and Functions". IBM Journal of Research and Development, volume 17, issue 4. 1973-07.
  2. Eugene McDonnell. "An Extension to the Power Operator". APL Quote-Quad, Volume 18, Number 4, 1988-06.
APL built-ins [edit]
Primitives (Timeline) Functions
Scalar
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare RootRound
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
Non-Scalar
Structural ShapeReshapeTallyDepthRavelEnlistTableCatenateReverseRotateTransposeRazeMixSplitEncloseNestCut (K)PairLinkPartitioned EnclosePartition
Selection FirstPickTakeDropUniqueIdentityStopSelectReplicateExpandSet functions (IntersectionUnionWithout) ∙ Bracket indexingIndexCartesian ProductSort
Selector Index generatorGradeIndex OfInterval IndexIndicesDealPrefix and suffix vectors
Computational MatchNot MatchMembershipFindNub SieveEncodeDecodeMatrix InverseMatrix DivideFormatExecuteMaterialiseRange
Operators Monadic EachCommuteConstantReplicateExpandReduceWindowed ReduceScanOuter ProductKeyI-BeamSpawnFunction axisIdentity (Null, Ident)
Dyadic BindCompositions (Compose, Reverse Compose, Beside, Withe, Atop, Over) ∙ Inner ProductDeterminantPowerAtUnderRankDepthVariantStencilCutDirect definition (operator)Identity (Lev, Dex)
Quad names Index originComparison toleranceMigration levelAtomic vector