Difference between revisions of "Function axis"

From APL Wiki
Jump to navigation Jump to search
Miraheze>Adám Brudzewsky
 
(5 intermediate revisions by 3 users not shown)
Line 1: Line 1:
{{Built-in|Bracket axis|[ax]}} or '''function axis''' is the a special syntax whereby many APLs allow the behavior of a function to be modified, 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.
  
 
== Functions ==
 
== Functions ==
Line 11: Line 11:
 
=== Dyadic functions ===
 
=== Dyadic functions ===
 
The following [[Dyadic function|dyads]] may allow one:
 
The following [[Dyadic function|dyads]] may allow one:
* [[Scalar dyadics]] accept a list of axes to override [[conformability]] rules: it specifies , for each axis in the lower-rank (or left, in case of a tie) argument, which axis in the other argument it is paired with.
+
* [[Scalar function|Scalar]] [[dyadic]]s accept a list of axes to override [[conformability]] rules: it specifies , for each axis in the lower-rank (or left, in case of a tie) argument, which axis in the other argument it is paired with.
 
* [[Catenate]] combines along the selected axis, adding a new axis if a non-integer axis is given.
 
* [[Catenate]] combines along the selected axis, adding a new axis if a non-integer axis is given.
 
* [[Rotate]] rotates the right argument along the selected axis.
 
* [[Rotate]] rotates the right argument along the selected axis.
 
* [[Replicate]] and [[Expand]] work on the specified right argument axis.
 
* [[Replicate]] and [[Expand]] work on the specified right argument axis.
 
* [[Take]] and [[Drop]] modify the selected right argument axes.
 
* [[Take]] and [[Drop]] modify the selected right argument axes.
* [[Squish]] takes axes to specify which axis of the right argument corresponds to each left argument element.
+
* [[Squad indexing]] takes axes to specify which axis of the right argument corresponds to each left argument element.
 
* [[Partition]] and [[Partitioned Enclose]] have complicated and different behavior.
 
* [[Partition]] and [[Partitioned Enclose]] have complicated and different behavior.
  
Line 24: Line 24:
 
* [[Scan]] works on the specified right argument axis.
 
* [[Scan]] works on the specified right argument axis.
  
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]]).
+
In [[SHARP APL]], [[Replicate]] and [[Expand]] are also included in this category as they are operators and not functions.
 +
 
 +
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]]).
  
 
== External links ==
 
== External links ==
Line 34: Line 36:
 
* [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 programming language}}
+
{{APL syntax}}

Latest revision as of 16:22, 9 January 2020

[ax]

Function axis ([ax]) is a special syntax which modifies the behavior of a function, for example [2] 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.

Functions

Monadic functions

The following monads may allow an axis:

  • Mix accepts a list of axes to specify where the axes of argument elements will be placed in the result.
  • Ravel accepts a list of axes which are combined, or a single fractional number to add a length-1 axis.
  • Enclose accepts a list of axes. Each subarray along these axes is enclosed.
  • Split accepts a single axis, and encloses each vector along that axis.
  • Reverse reverses along the specified axis.

Dyadic functions

The following dyads may allow one:

  • Scalar dyadics accept a list of axes to override conformability rules: it specifies , for each axis in the lower-rank (or left, in case of a tie) argument, which axis in the other argument it is paired with.
  • Catenate combines along the selected axis, adding a new axis if a non-integer axis is given.
  • Rotate rotates the right argument along the selected axis.
  • Replicate and Expand work on the specified right argument axis.
  • Take and Drop modify the selected right argument axes.
  • Squad indexing takes axes to specify which axis of the right argument corresponds to each left argument element.
  • Partition and Partitioned Enclose have complicated and different behavior.

Operators

The following operators may admit axis specification:

  • Reduction removes the specified right argument axis.
  • Scan works on the specified right argument axis.

In SHARP APL, Replicate and Expand are also included in this category as they are operators and not functions.

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).

External links

Documentation

Lesson


APL syntax [edit]
General Comparison with traditional mathematicsPrecedenceTacit programming
Array Numeric literalStringStrand notationObject literalArray notation
Function ArgumentFunction valenceDerived functionNiladic functionMonadic functionDyadic functionAmbivalent functionTradfnDfnDerived functionFunction train
Operator OperandOperator valenceTradopDopDerived operator
Assignment MultipleIndexedSelectiveModified
Other Function axisBranchingSystem commandUser commandKeywordDot notation