Power (operator): Difference between revisions
Jump to navigation
Jump to search
(→Documentation: BQN) |
(fixed arguments of function Y argument) |
||
Line 8: | Line 8: | ||
Power repeatedly applies <source lang=apl inline>f</source> to <source lang=apl inline>Y</source> based on the type of operand <source lang=apl inline>g</source>: | Power repeatedly applies <source lang=apl inline>f</source> to <source lang=apl inline>Y</source> based on the type of operand <source lang=apl inline>g</source>: | ||
* '''Function''': Must be dyadic and must return a boolean [[singleton]]. The previous iteration value is provided as | * '''Function''': Must be dyadic and must return a boolean [[singleton]]. The previous iteration value is provided as the right argument to <source lang=apl inline>f</source>, and the current iteration value is given as the left argument. <source lang=apl inline>f</source> is repeatedly applied until this function returns 1. | ||
* '''Integer''': Applies <source lang=apl inline>f</source> <source lang=apl inline>g</source> times to <source lang=apl inline>Y</source>. If <source lang=apl inline>g</source> is negative, then the inverse of <source lang=apl inline>f</source> (if available) is applied. | * '''Integer''': Applies <source lang=apl inline>f</source> <source lang=apl inline>g</source> times to <source lang=apl inline>Y</source>. If <source lang=apl inline>g</source> is negative, then the inverse of <source lang=apl inline>f</source> (if available) is applied. | ||
* '''Integer Array''': In [[Extended Dyalog APL]], <source lang=apl inline>g</source> can be an integer array. Each integer <source lang=apl inline>i</source> in <source lang=apl inline>g</source> will be replaced by <source lang=apl inline>⊂(f⍣i)Y</source>. | * '''Integer Array''': In [[Extended Dyalog APL]], <source lang=apl inline>g</source> can be an integer array. Each integer <source lang=apl inline>i</source> in <source lang=apl inline>g</source> will be replaced by <source lang=apl inline>⊂(f⍣i)Y</source>. |
Revision as of 19:12, 14 June 2022
⍣
|
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. IfX
is given, then it is bound tof
soX f⍣g Y
is equivalent toX∘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 toY
. Ifg
is negative, then the inverse off
(if available) is applied. - Integer Array: In Extended Dyalog APL,
g
can be an integer array. Each integeri
ing
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
External Links
Lessons
Documentation
- Dyalog
- J Dictionary, NuVoc
- BQN