Power (operator)

From APL Wiki
Revision as of 11:49, 27 April 2022 by Razetime (talk | contribs) (Add Power page)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

Power () is a primitive dyadic operator that performs bounded looping, unbounded looping, and function inverses in 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, it is bound to f (X∘f).
  • g can be an integer 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 value. The previous iteration value is provided in , and the current iteration value is given in . f is repeatedly applied until this function returns 1.
  • Integer: Apply f g times to Y. If g is negative, then f is inverted before it is applied.
  • Integer Array: In Extended Dyalog APL, g can be an integer array. Each integer in g will be replaced by X(f⍣⍵)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

External Links

Lessons

Documentation