Power (operator): Difference between revisions

Jump to navigation Jump to search
243 bytes added ,  13:05, 27 April 2022
no edit summary
(Add Power page)
 
No edit summary
Line 1: Line 1:
{{Built-in|Power|⍣}} is a primitive [[dyadic operator]] that performs bounded looping, unbounded looping, and function inverses in [[Dyalog APL]].
{{Built-in|Power|⍣}} is a primitive [[dyadic operator]] that performs bounded looping, unbounded looping, and function [[inverse]]s in [[NARS2000]], [[Dyalog APL]], and related implementations like [[ngn/apl]], [[dzaima/APL]], and [[Extended Dyalog APL]].


== Description ==
== Description ==
A call to Power is of the form <source lang=apl inline>X(f⍣g)Y</source>, where  
A call to Power is of the form <source lang=apl inline>X(f⍣g)Y</source>, where  
* <source lang=apl inline>X</source> is an optional argument.  
* <source lang=apl inline>X</source> is an optional argument.  
* <source lang=apl inline>f</source> is a function. If <source lang=apl inline>X</source> is given, it is bound to <source lang=apl inline>f</source> (<source lang=apl inline>X∘f</source>).
* <source lang=apl inline>f</source> is a function. If <source lang=apl inline>X</source> is given, then it is bound to <source lang=apl inline>f</source> so <source lang=apl inline>X f⍣g Y</source> is equivalent to <source lang=apl inline>X∘f⍣g Y</source>.
* <source lang=apl inline>g</source> can be an integer or a function.
* <source lang=apl inline>g</source> can be an [[array]] or a function.


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 value. The previous iteration value is provided in <source lang=apl inline></source>, and the current iteration value is given in <source lang=apl inline>⍵</source>. <source lang=apl inline>f</source> is repeatedly applied until this function returns 1.
* '''Function''': Must be dyadic and must return a boolean [[singleton]]. The previous iteration value is provided as left argument to <source lang=apl inline>f</source>, and the current iteration value is given as right argument. <source lang=apl inline>f</source> is repeatedly applied until this function returns 1.
* '''Integer''': Apply <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 <source lang=apl inline>f</source> is inverted before it 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></source> in <source lang=apl inline>g</source> will be replaced by <source lang=apl inline>X(f⍣⍵)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>.


== Examples ==
== Examples ==
Line 35: Line 35:
* [https://help.dyalog.com/latest/#Language/Primitive%20Operators/Power%20Operator.htm Dyalog]
* [https://help.dyalog.com/latest/#Language/Primitive%20Operators/Power%20Operator.htm Dyalog]
* J [https://www.jsoftware.com/help/dictionary/d202n.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/hatco NuVoc]
* J [https://www.jsoftware.com/help/dictionary/d202n.htm Dictionary], [https://code.jsoftware.com/wiki/Vocabulary/hatco NuVoc]
{{APL built-ins}}[[Category:Primitive operators]]

Navigation menu