Major cell: Difference between revisions
m (Text replacement - " ⊢( *[^∘])" to " ⎕←$1") |
m (Text replacement - "High-rank set functions" to "Major cell search") Tags: Mobile edit Mobile web edit |
||
(2 intermediate revisions by one other user not shown) | |||
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 < | 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</syntaxhighlight> 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>⊖</syntaxhighlight>) 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 == | ||
< | <syntaxhighlight lang=apl inline>A</syntaxhighlight> is an array with [[shape]] <syntaxhighlight lang=apl inline>3 4</syntaxhighlight>. Using [[Tally]] we see that the number of major cells in <syntaxhighlight lang=apl inline>A</syntaxhighlight> is the first element of the shape, <syntaxhighlight lang=apl inline>3</syntaxhighlight>: | ||
< | <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 11: | Line 11: | ||
≢A | ≢A | ||
3 | 3 | ||
</ | </syntaxhighlight> | ||
We can separate < | We can separate <syntaxhighlight lang=apl inline>A</syntaxhighlight>'s major cells using [[Enclose]] with [[Rank operator|rank]] <syntaxhighlight lang=apl inline>¯1</syntaxhighlight>: | ||
< | <syntaxhighlight lang=apl> | ||
⊂⍤¯1 ⊢A | ⊂⍤¯1 ⊢A | ||
┌──────────┬─────────┬───────┐ | ┌──────────┬─────────┬───────┐ | ||
│10 15 20 5│6 3 12 15│2 3 4 5│ | │10 15 20 5│6 3 12 15│2 3 4 5│ | ||
└──────────┴─────────┴───────┘ | └──────────┴─────────┴───────┘ | ||
</ | </syntaxhighlight> | ||
Given another array < | Given another array <syntaxhighlight lang=apl inline>B</syntaxhighlight> we can search for cells of <syntaxhighlight lang=apl inline>B</syntaxhighlight> which [[match]] major cells of <syntaxhighlight lang=apl inline>B</syntaxhighlight>. [[Major cell search|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). | ||
< | <syntaxhighlight lang=apl> | ||
⎕←B ← ↑ 4,/⍳6 | ⎕←B ← ↑ 4,/⍳6 | ||
1 2 3 4 | 1 2 3 4 | ||
Line 29: | Line 29: | ||
A ⍳ 2 3 4 5 | A ⍳ 2 3 4 5 | ||
3 | 3 | ||
</ | </syntaxhighlight> | ||
{{APL features}}[[Category:Array relationships]] | {{APL features}}[[Category:Array relationships]] |
Latest revision as of 23:27, 10 March 2024
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 ¯1
using the Rank operator. Functions designed to follow leading axis theory often manipulate the major cells of an array. For example, Reverse First (⊖
) 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
A
is an array with shape 3 4
. Using Tally we see that the number of major cells in A
is the first element of the shape, 3
:
⎕←A ← 5 3 1 ∘.∧ 2 3 4 5 10 15 20 5 6 3 12 15 2 3 4 5 ≢A 3
We can separate A
's major cells using Enclose with rank ¯1
:
⊂⍤¯1 ⊢A ┌──────────┬─────────┬───────┐ │10 15 20 5│6 3 12 15│2 3 4 5│ └──────────┴─────────┴───────┘
Given another array B
we can search for cells of B
which match major cells of B
. 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).
⎕←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
APL features [edit] | |
---|---|
Built-ins | Primitives (functions, operators) ∙ Quad name |
Array model | Shape ∙ Rank ∙ Depth ∙ Bound ∙ Index (Indexing) ∙ Axis ∙ Ravel ∙ Ravel order ∙ Element ∙ Scalar ∙ Vector ∙ Matrix ∙ Simple scalar ∙ Simple array ∙ Nested array ∙ Cell ∙ Major cell ∙ Subarray ∙ Empty array ∙ Prototype |
Data types | Number (Boolean, Complex number) ∙ Character (String) ∙ Box ∙ Namespace ∙ Function array |
Concepts and paradigms | Conformability (Scalar extension, Leading axis agreement) ∙ Scalar function (Pervasion) ∙ Identity element ∙ Complex floor ∙ Array ordering (Total) ∙ Tacit programming (Function composition, Close composition) ∙ Glyph ∙ Leading axis theory ∙ Major cell search ∙ First-class function |
Errors | LIMIT ERROR ∙ RANK ERROR ∙ SYNTAX ERROR ∙ DOMAIN ERROR ∙ LENGTH ERROR ∙ INDEX ERROR ∙ VALUE ERROR ∙ EVOLUTION ERROR |