Array ordering: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
(Created page with "'''Array ordering''' is the ordering of arrays exposed by functions such as Grade and Interval Index. It may be more general than comparison, for example by allowing characters to be compared to each other and to numbers. However, not all arrays need to be comparable, meaning that functions that depend on array ordering can throw an error. Traditionally, ordering is defined only for simple arrays of the same shape and type (Grade o...")
 
m (Missing First in comparison code)
Line 11: Line 11:
2 1
2 1
</syntaxhighlight>
</syntaxhighlight>
Grade reverses the order of these elements, showing that <syntaxhighlight lang=apl inline>'a'</syntaxhighlight> comes before <syntaxhighlight lang=apl inline>'b'</syntaxhighlight> in the array ordering. In general, <syntaxhighlight lang=apl inline>1=⍋X Y</syntaxhighlight> tests whether array <syntaxhighlight lang=apl inline>X</syntaxhighlight> precedes or [[match]]es <syntaxhighlight lang=apl inline>Y</syntaxhighlight>. However, <syntaxhighlight lang=apl inline>⍋X Y</syntaxhighlight> doesn't distinguish between these two cases, so for complete information about the ordering, these arrays must also be graded in the opposite order.
Grade reverses the order of these elements, showing that <syntaxhighlight lang=apl inline>'a'</syntaxhighlight> comes before <syntaxhighlight lang=apl inline>'b'</syntaxhighlight> in the array ordering. In general, <syntaxhighlight lang=apl inline>1=⊃⍋X Y</syntaxhighlight> tests whether array <syntaxhighlight lang=apl inline>X</syntaxhighlight> precedes or [[match]]es <syntaxhighlight lang=apl inline>Y</syntaxhighlight>. However, <syntaxhighlight lang=apl inline>⍋X Y</syntaxhighlight> doesn't distinguish between these two cases, so for complete information about the ordering, these arrays must also be graded in the opposite order.


== Documentation ==
== Documentation ==

Revision as of 11:50, 17 October 2024

Array ordering is the ordering of arrays exposed by functions such as Grade and Interval Index. It may be more general than comparison, for example by allowing characters to be compared to each other and to numbers. However, not all arrays need to be comparable, meaning that functions that depend on array ordering can throw an error. Traditionally, ordering is defined only for simple arrays of the same shape and type (Grade of a simple array only requires this sort of comparison), and is determined by the ordering of the first unequal pair of elements in those arrays in ravel order. It may be extended to all arrays in various ways, making it a total array order (TAO).

While two characters can't be compared directly in most APL implementations, their array ordering can be observed with Grade:

      'b'>'a'
DOMAIN ERROR
      'b'>'a'
         ∧

      ⍋ 'ba'
2 1

Grade reverses the order of these elements, showing that 'a' comes before 'b' in the array ordering. In general, 1=⊃⍋X Y tests whether array X precedes or matches Y. However, ⍋X Y doesn't distinguish between these two cases, so for complete information about the ordering, these arrays must also be graded in the opposite order.

Documentation

APL features [edit]
Built-ins Primitives (functions, operators) ∙ Quad name
Array model ShapeRankDepthBoundIndex (Indexing) ∙ AxisRavelRavel orderElementScalarVectorMatrixSimple scalarSimple arrayNested arrayCellMajor cellSubarrayEmpty arrayPrototype
Data types Number (Boolean, Complex number) ∙ Character (String) ∙ BoxNamespaceFunction array
Concepts and paradigms Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity elementComplex floorArray ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ GlyphLeading axis theoryMajor cell searchFirst-class function
Errors LIMIT ERRORRANK ERRORSYNTAX ERRORDOMAIN ERRORLENGTH ERRORINDEX ERRORVALUE ERROREVOLUTION ERROR