Power (operator)

From APL Wiki
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.


A call to Power is of the form X(fg)Y, where

  • X is an optional argument.
  • f is a function. If X is given, then it is bound to f so X fg Y is equivalent to Xfg 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 (fi)Y.


Some basic examples:

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

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

      (.∨⊢)3 30 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.

1 0 1

External Links



APL built-ins [edit]
Primitive functions
Monadic ConjugateNegateSignumReciprocalMagnitudeExponentialNatural LogarithmFloorCeilingFactorialNotPi TimesRollTypeImaginarySquare Root
Dyadic AddSubtractTimesDivideResiduePowerLogarithmMinimumMaximumBinomialComparison functionsBoolean functions (And, Or, Nand, Nor) ∙ GCDLCMCircularComplexRoot
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, Withe, Atop, Over) ∙ Inner ProductPowerAtUnderRankDepthVariantStencilCut (J)
Quad names
Arrays Index originMigration levelAtomic vector
Functions Name classCase convertUnicode convert
Operators SearchReplace