Major cell: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Text replacement - " ⊢( *[^∘])" to " ⎕←$1")
m (Text replacement - "<source" to "<syntaxhighlight")
Tags: Mobile edit Mobile web edit
Line 1: Line 1:
In the APL [[array model]] and [[leading axis theory]], a '''major cell''', or '''item''', is a [[cell]] of an array which has [[rank]] one smaller than the rank of the array, or equal to it if the array is a [[scalar]]. The number of major cells in an array is its [[Tally]], and a function can be called on the major cells of an array individually by applying it with rank <source lang=apl inline>¯1</source> using the [[Rank operator]]. Functions designed to follow leading axis theory often manipulate the major cells of an array. For example, [[Reverse First]] (<source lang=apl inline>⊖</source>) is considered the primary form of [[Reverse]] in leading-axis languages because it can be interpreted as reversing the major cells of its argument; [[J]] removes last-axis Reverse entirely.
In the APL [[array model]] and [[leading axis theory]], a '''major cell''', or '''item''', is a [[cell]] of an array which has [[rank]] one smaller than the rank of the array, or equal to it if the array is a [[scalar]]. The number of major cells in an array is its [[Tally]], and a function can be called on the major cells of an array individually by applying it with rank <syntaxhighlight lang=apl inline>¯1</source> using the [[Rank operator]]. Functions designed to follow leading axis theory often manipulate the major cells of an array. For example, [[Reverse First]] (<syntaxhighlight lang=apl inline>⊖</source>) is considered the primary form of [[Reverse]] in leading-axis languages because it can be interpreted as reversing the major cells of its argument; [[J]] removes last-axis Reverse entirely.


== Examples ==
== Examples ==


<source lang=apl inline>A</source> is an array with [[shape]] <source lang=apl inline>3 4</source>. Using [[Tally]] we see that the number of major cells in <source lang=apl inline>A</source> is the first element of the shape, <source lang=apl inline>3</source>:
<syntaxhighlight lang=apl inline>A</source> is an array with [[shape]] <syntaxhighlight lang=apl inline>3 4</source>. Using [[Tally]] we see that the number of major cells in <syntaxhighlight lang=apl inline>A</source> is the first element of the shape, <syntaxhighlight lang=apl inline>3</source>:
<source lang=apl>
<syntaxhighlight lang=apl>
       ⎕←A ← 5 3 1 ∘.∧ 2 3 4 5
       ⎕←A ← 5 3 1 ∘.∧ 2 3 4 5
10 15 20  5
10 15 20  5
Line 12: Line 12:
3
3
</source>
</source>
We can separate <source lang=apl inline>A</source>'s major cells using [[Enclose]] with [[Rank operator|rank]] <source lang=apl inline>¯1</source>:
We can separate <syntaxhighlight lang=apl inline>A</source>'s major cells using [[Enclose]] with [[Rank operator|rank]] <syntaxhighlight lang=apl inline>¯1</source>:
<source lang=apl>
<syntaxhighlight lang=apl>
       ⊂⍤¯1 ⊢A
       ⊂⍤¯1 ⊢A
┌──────────┬─────────┬───────┐
┌──────────┬─────────┬───────┐
Line 19: Line 19:
└──────────┴─────────┴───────┘
└──────────┴─────────┴───────┘
</source>
</source>
Given another array <source lang=apl inline>B</source> we can search for cells of <source lang=apl inline>B</source> which [[match]] major cells of <source lang=apl inline>B</source>. [[High-rank set functions|High-rank]] [[Index-of]] always searches for right argument cells whose rank matches the rank of a left argument major cell: if the right argument is a [[vector]] and not a [[matrix]] then it searches for the entire vector rather than its major cells (which are [[scalar]]s).
Given another array <syntaxhighlight lang=apl inline>B</source> we can search for cells of <syntaxhighlight lang=apl inline>B</source> which [[match]] major cells of <syntaxhighlight lang=apl inline>B</source>. [[High-rank set functions|High-rank]] [[Index-of]] always searches for right argument cells whose rank matches the rank of a left argument major cell: if the right argument is a [[vector]] and not a [[matrix]] then it searches for the entire vector rather than its major cells (which are [[scalar]]s).
<source lang=apl>
<syntaxhighlight lang=apl>
       ⎕←B ← ↑ 4,/⍳6
       ⎕←B ← ↑ 4,/⍳6
1 2 3 4
1 2 3 4

Revision as of 21:12, 10 September 2022

In the APL array model and leading axis theory, a major cell, or item, is a cell of an array which has rank one smaller than the rank of the array, or equal to it if the array is a scalar. The number of major cells in an array is its Tally, and a function can be called on the major cells of an array individually by applying it with rank <syntaxhighlight lang=apl inline>¯1</source> using the Rank operator. Functions designed to follow leading axis theory often manipulate the major cells of an array. For example, Reverse First (<syntaxhighlight lang=apl inline>⊖</source>) is considered the primary form of Reverse in leading-axis languages because it can be interpreted as reversing the major cells of its argument; J removes last-axis Reverse entirely.

Examples

<syntaxhighlight lang=apl inline>A</source> is an array with shape <syntaxhighlight lang=apl inline>3 4</source>. Using Tally we see that the number of major cells in <syntaxhighlight lang=apl inline>A</source> is the first element of the shape, <syntaxhighlight lang=apl inline>3</source>: <syntaxhighlight lang=apl>

     ⎕←A ← 5 3 1 ∘.∧ 2 3 4 5

10 15 20 5

6  3 12 15
2  3  4  5
     ≢A

3 </source> We can separate <syntaxhighlight lang=apl inline>A</source>'s major cells using Enclose with rank <syntaxhighlight lang=apl inline>¯1</source>: <syntaxhighlight lang=apl>

     ⊂⍤¯1 ⊢A

┌──────────┬─────────┬───────┐ │10 15 20 5│6 3 12 15│2 3 4 5│ └──────────┴─────────┴───────┘ </source> Given another array <syntaxhighlight lang=apl inline>B</source> we can search for cells of <syntaxhighlight lang=apl inline>B</source> which match major cells of <syntaxhighlight lang=apl inline>B</source>. High-rank Index-of always searches for right argument cells whose rank matches the rank of a left argument major cell: if the right argument is a vector and not a matrix then it searches for the entire vector rather than its major cells (which are scalars). <syntaxhighlight lang=apl>

     ⎕←B ← ↑ 4,/⍳6

1 2 3 4 2 3 4 5 3 4 5 6

     A ⍳ B

4 3 4

     A ⍳ 2 3 4 5

3 </source>


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