Function axis: Difference between revisions

Jump to navigation Jump to search
2,636 bytes added ,  14:46, 21 July 2022
GNU
(GNU)
Line 1: Line 1:
{{Built-in|Function axis|[ax]}} is a special syntax which modifies the behavior of a function, for example <source lang=apl inline>⌽[2]</source> to [[Rotate]] along the second [[axis]]. Axis specification was a feature of [[Iverson notation]] and was ubiquitous in early APLs; many newer APLs which adhere to [[leading axis theory]] reject the use of axis specification in favor of the [[Rank operator]] because it is a fully general operator while the behavior of functions with axis must be defined for each function separately.
{{Built-in|Function axis|[ax]}} is a special syntax which modifies the behavior of a function, for example <source lang=apl inline>⌽[2]</source> to [[Rotate]] along the second [[axis]]. Axis specification was a feature of [[Iverson notation]] and was ubiquitous in early APLs; many newer APLs which adhere to [[leading axis theory]] reject the use of axis specification in favor of the [[Rank operator]] because it is a fully general operator while the behavior of functions with axis must be defined for each function separately. However, [[GNU APL]] embraces and extends the syntax so it applies to all user-defined functions.


== Functions ==
== Functions ==
Line 27: Line 27:


Axis specification always modifies the [[derived function]] obtained from an operator, and not the operator itself. The exact syntax may vary: in most cases a set of brackets is parsed like a monadic operator and applies directly to the derived function; sometimes brackets can be applied directly to an operator, in which case the derived function produced by this operator is modified. In [[Dyalog APL]], a slash with axis retains its [[function-operator overloading]]: it can be applied as an operator or as a dyadic function ([[Replicate]] or [[Expand]]).
Axis specification always modifies the [[derived function]] obtained from an operator, and not the operator itself. The exact syntax may vary: in most cases a set of brackets is parsed like a monadic operator and applies directly to the derived function; sometimes brackets can be applied directly to an operator, in which case the derived function produced by this operator is modified. In [[Dyalog APL]], a slash with axis retains its [[function-operator overloading]]: it can be applied as an operator or as a dyadic function ([[Replicate]] or [[Expand]]).
== Generalisation ==
GNU APL generalises function axis to all functions, and beyond what could reasonably be called "axis", that is, referring to one or more argument axes. Instead, the syntax is used to provide an additional argument, which the function can use in whichever way. For example, <source lang=apl inline>⌹[ax] M</source> computes the [[wikipedia:QR factorization|QR factorization]] of <source lang=apl inline>M</source> with the [[comparison tolerance]] of <source lang=apl inline>ax</source>. Here, <source lang=apl inline>ax</source> is not an axis at all, and there's no clear connection between this monadic usage of Domino and its non-axis meaning of [[Matrix inverse]]. This further breaks a principle that, except for scalar functions and arrays, there always exists a value for <source lang=apl inline>ax</source> such that <source lang=apl inline>f[ax]</source> is the same as <source lang=apl inline>f</source>. Much like the left argument of [[Circular]] (<source lang=apl inline>○</source>), The GNU APL specific File Input Output [[system function]] (<source lang=apl inline>⎕FIO</source>) uses the bracket axis syntax as a function selector, as does the [[wikipedia:SQL|SQL]] interface function (<source lang=apl inline>⎕SQL</source>). However, some of the functionalities provided by this latter function take additional parameters as subsequent elements in the array inside the brackets. Similarly, the [[wikipedia:regular expression|regular expression]] interface (<source lang=apl inline>⎕RE</source>) uses [[character]] "axes" as flags for the regular expression engine. [[Dyalog APL]] instead uses a [[dyadic operator]], [[Variant]] (<source lang=apl inline>⍠</source>), to provide such auxiliary parameter, thus staying within the normal rules of APL syntax.
GNU APL even gives user-defined functions, both [[dfn]]s and [[tradfn]]s, access to the bracket axis syntax, again while permitting its use for any purpose. The axis value is given For example, the [[root]] function could be implemented as a monadic function with axis specifying the degree, rather than as a dyadic function. In a dfn, the value given via axis notation is denoted <source lang=apl inline>χ</source>:
<source lang=apl>
      Root←{⍵*÷χ}
      Root[3]8
2
</source>
{{Works in|[[GNU APL]]}}
Or as a tradfn, indicating axis notation in the header line:
<source lang=apl>
∇ r←Root[ax] y
  r←y*÷ax
</source>
{{Works in|[[GNU APL]]}}


== External links ==
== External links ==
Line 33: Line 51:
* Dyalog: [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Operators/Operators%20Summarised.htm overview], [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Operators/Axis%20with%20Monadic%20Operand.htm monadic], [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Operators/Axis%20with%20Dyadic%20Operand.htm dyadic]
* Dyalog: [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Operators/Operators%20Summarised.htm overview], [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Operators/Axis%20with%20Monadic%20Operand.htm monadic], [https://help.dyalog.com/latest/index.htm#Language/Primitive%20Operators/Axis%20with%20Dyadic%20Operand.htm dyadic]
* [http://microapl.com/apl_help/ch_020_010_020.htm APLX]
* [http://microapl.com/apl_help/ch_020_010_020.htm APLX]
 
* [https://www.gnu.org/software/apl/apl.html#Section-2_002e2 GNU APL]
=== Lesson ===
=== Lesson ===
* [https://chat.stackexchange.com/rooms/52405/conversation/lesson-3-some-apl-operators-----#message-40898783 APL Cultivation]
* [https://chat.stackexchange.com/rooms/52405/conversation/lesson-3-some-apl-operators-----#message-40898783 APL Cultivation]
{{APL syntax}}[[Category:Function characteristics]]
{{APL syntax}}[[Category:Function characteristics]]

Navigation menu