Frame agreement: Difference between revisions
Tag: Undo |
(Replace with clearer examples; add table showing frames / cells.) |
||
Line 2: | Line 2: | ||
== Description == | == Description == | ||
A dyadic function <syntaxhighlight lang= | A dyadic function <syntaxhighlight lang=apl inline>f</syntaxhighlight> with left and right ranks <syntaxhighlight lang=apl inline>l</syntaxhighlight> and <syntaxhighlight lang=apl inline>r</syntaxhighlight>, respectively, splits its left argument <syntaxhighlight lang=apl inline>x</syntaxhighlight> into <syntaxhighlight lang=apl inline>l</syntaxhighlight>-cells, and splits its right argument <syntaxhighlight lang=apl inline>y</syntaxhighlight> into <syntaxhighlight lang=apl inline>r</syntaxhighlight>-cells. Each argument's shape is thus split into a frame and a cell shape. Given that one frame must be a prefix of the other, the shorter frame is called the common frame (denoted here as <syntaxhighlight lang=apl inline>cf</syntaxhighlight>), which may be [https://aplwiki.com/wiki/Zilde empty]. With respect to frame agreement, the generic term "cells" denotes the <syntaxhighlight lang=apl inline>l</syntaxhighlight>-cells (for the left argument) or the <syntaxhighlight lang=apl inline>r</syntaxhighlight>-cells (for the right argument). If the frames are identical, each cell of <syntaxhighlight lang=apl inline>x</syntaxhighlight> is paired with the corresponding cell of <syntaxhighlight lang=apl inline>y</syntaxhighlight> in a 1-to-1 pairing. If the frame lengths differ, each cell of the shorter-framed argument is paired with each among the corresponding group of cells of the longer-framed argument. This 1-to-n pairing can be viewed as extending the shorter frame to match the longer frame. The collective results of the individual applications of <syntaxhighlight lang=apl inline>f</syntaxhighlight> are framed by the longer frame. | ||
== Examples == | == Examples == | ||
<syntaxhighlight lang=j> | <syntaxhighlight lang=j> | ||
x=: i.2 | |||
y=: i.2 3 2 | |||
x+"0 1 y | |||
0 1 | |||
2 3 | |||
4 5 | |||
2 3 | |||
5 | |||
7 8 | 7 8 | ||
9 10 | |||
11 12 | |||
</syntaxhighlight> | |||
{{Works in|[[J]]}} | |||
The table below shows the pairing of cells from the above example. Here the notation <syntaxhighlight lang=apl inline>[shape]</syntaxhighlight> denotes the cell shape, and <syntaxhighlight lang=apl inline>|</syntaxhighlight> denotes the division between the common frame and the remaining trailing axes. | |||
{|class=wikitable | |||
! Argument !! Step 1: Frames / Cells !! Step 2: Common frame—cells paired | |||
|- | |||
| <syntaxhighlight lang=apl inline>x</syntaxhighlight> || <syntaxhighlight lang=apl inline>2 []</syntaxhighlight> || <syntaxhighlight lang=apl inline>2|[]</syntaxhighlight> | |||
|- | |||
| <syntaxhighlight lang=apl inline>y</syntaxhighlight> || <syntaxhighlight lang=apl inline>2 3 [2]</syntaxhighlight> || <syntaxhighlight lang=apl inline>2|3 [2]</syntaxhighlight> | |||
|} | |||
The same example, but without considering cell shape: | |||
{|class=wikitable | |||
! Argument !! Step 1: Frame / Cells !! Step 2: Common frame | |||
|- | |||
| <syntaxhighlight lang=apl inline>x</syntaxhighlight> || <syntaxhighlight lang=apl inline>2 C</syntaxhighlight> || <syntaxhighlight lang=apl inline>2|C</syntaxhighlight> | |||
|- | |||
| <syntaxhighlight lang=apl inline>y</syntaxhighlight> || <syntaxhighlight lang=apl inline>2 3 C</syntaxhighlight> || <syntaxhighlight lang=apl inline>2|3 C</syntaxhighlight> | |||
|} | |||
Based on the ranks <syntaxhighlight lang=apl inline>l r</syntaxhighlight> of the function <syntaxhighlight lang=apl inline>+⍤0 1</syntaxhighlight>, <syntaxhighlight lang=apl inline>x</syntaxhighlight>'s frame is <syntaxhighlight lang=apl inline>,2</syntaxhighlight> and its [[cell]] shape is [https://aplwiki.com/wiki/Zilde empty] ; y's frame is <syntaxhighlight lang=apl inline>2 3</syntaxhighlight> and its cell [[shape]] is <syntaxhighlight lang=apl inline>,2</syntaxhighlight>. The shorter of the frames, and thus the common frame, is <syntaxhighlight lang=apl inline>,2</syntaxhighlight>. Thus, relative to the common frame, each atom of <syntaxhighlight lang=apl inline>x</syntaxhighlight> is paired with the corresponding 3 rows of <syntaxhighlight lang=apl inline>y</syntaxhighlight>. | |||
The expanded example below uses APL to model frame agreement. | |||
<syntaxhighlight lang=apl> | |||
x←⍳2 | |||
y←2 3 2⍴⍳12 | |||
l r←0 1 ⍝ the left and right ranks of the function +⍤0 1 | |||
⊢lf rf←(-l r)↓¨x,⍥(⊂∘⍴)y ⍝ frames | |||
┌─┬───┐ | |||
│2│2 3│ | |||
└─┴───┘ | |||
⊢cf←lf(⊃{⍺⍵}⌷⍨(,⍳⌊)⍥≢)rf ⍝ common (shorter) frame | |||
2 | 2 | ||
x{⍺⍵}⍤(-≢cf)⊢y ⍝ 1st step: the (-≢cf)-cells are paired 1-to-1 between x and y | |||
┌─┬─────┐ | |||
│0│0 1 │ | |||
│ │2 3 │ | |||
│ │4 5 │ | |||
├─┼─────┤ | |||
│1│ 6 7│ | |||
│ │ 8 9│ | |||
│ │10 11│ | |||
└─┴─────┘ | |||
x{⍺⍵}⍤l r⍤(-≢cf)⊢y ⍝ 2nd step: the (-≢cf)-cells in each pairing are split into l- and r-cells, and these are paired 1-to-n (or 1-to-1 if the frames are identical) | |||
┌─┬─────┐ | |||
│0│0 1 │ | |||
├─┼─────┤ | |||
│0│2 3 │ | |||
├─┼─────┤ | |||
│0│4 5 │ | |||
└─┴─────┘ | |||
┌─┬─────┐ | |||
│1│6 7 │ | |||
├─┼─────┤ | |||
│1│8 9 │ | |||
├─┼─────┤ | |||
│1│10 11│ | |||
└─┴─────┘ | |||
x+⍤0 1⊢y ⍝ n-to-m pairing in dialects without frame agreement; invalid | |||
RANK ERROR | |||
x+⍤l r⍤(-≢cf)⊢y ⍝ matches the result of J's frame agreement | |||
0 1 | |||
2 3 | |||
4 5 | |||
7 8 | 7 8 | ||
9 10 | |||
11 12 | |||
12 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
{{Works in|[[ | {{Works in|[[Dyalog APL]]}} | ||
[[Category:Leading axis theory]][[Category:Function characteristics]][[Category:Conformability]]{{APL features}} | [[Category:Leading axis theory]][[Category:Function characteristics]][[Category:Conformability]]{{APL features}} |
Revision as of 23:17, 9 July 2023
Frame agreement is a conformability rule designed for leading axis theory and used by J. It states that a dyadic function can be applied between two arrays only if one of their frames, with frame length based on the function's dyadic function rank, is a prefix of the other. The leading shape of the result is that of the argument with longer frame.
Description
A dyadic function f
with left and right ranks l
and r
, respectively, splits its left argument x
into l
-cells, and splits its right argument y
into r
-cells. Each argument's shape is thus split into a frame and a cell shape. Given that one frame must be a prefix of the other, the shorter frame is called the common frame (denoted here as cf
), which may be empty. With respect to frame agreement, the generic term "cells" denotes the l
-cells (for the left argument) or the r
-cells (for the right argument). If the frames are identical, each cell of x
is paired with the corresponding cell of y
in a 1-to-1 pairing. If the frame lengths differ, each cell of the shorter-framed argument is paired with each among the corresponding group of cells of the longer-framed argument. This 1-to-n pairing can be viewed as extending the shorter frame to match the longer frame. The collective results of the individual applications of f
are framed by the longer frame.
Examples
x=: i.2 y=: i.2 3 2 x+"0 1 y 0 1 2 3 4 5 7 8 9 10 11 12
The table below shows the pairing of cells from the above example. Here the notation [shape]
denotes the cell shape, and |
denotes the division between the common frame and the remaining trailing axes.
Argument | Step 1: Frames / Cells | Step 2: Common frame—cells paired |
---|---|---|
x |
2 [] |
2|[]
|
y |
2 3 [2] |
2|3 [2]
|
The same example, but without considering cell shape:
Argument | Step 1: Frame / Cells | Step 2: Common frame |
---|---|---|
x |
2 C |
2|C
|
y |
2 3 C |
2|3 C
|
Based on the ranks l r
of the function +⍤0 1
, x
's frame is ,2
and its cell shape is empty ; y's frame is 2 3
and its cell shape is ,2
. The shorter of the frames, and thus the common frame, is ,2
. Thus, relative to the common frame, each atom of x
is paired with the corresponding 3 rows of y
.
The expanded example below uses APL to model frame agreement.
x←⍳2 y←2 3 2⍴⍳12 l r←0 1 ⍝ the left and right ranks of the function +⍤0 1 ⊢lf rf←(-l r)↓¨x,⍥(⊂∘⍴)y ⍝ frames ┌─┬───┐ │2│2 3│ └─┴───┘ ⊢cf←lf(⊃{⍺⍵}⌷⍨(,⍳⌊)⍥≢)rf ⍝ common (shorter) frame 2 x{⍺⍵}⍤(-≢cf)⊢y ⍝ 1st step: the (-≢cf)-cells are paired 1-to-1 between x and y ┌─┬─────┐ │0│0 1 │ │ │2 3 │ │ │4 5 │ ├─┼─────┤ │1│ 6 7│ │ │ 8 9│ │ │10 11│ └─┴─────┘ x{⍺⍵}⍤l r⍤(-≢cf)⊢y ⍝ 2nd step: the (-≢cf)-cells in each pairing are split into l- and r-cells, and these are paired 1-to-n (or 1-to-1 if the frames are identical) ┌─┬─────┐ │0│0 1 │ ├─┼─────┤ │0│2 3 │ ├─┼─────┤ │0│4 5 │ └─┴─────┘ ┌─┬─────┐ │1│6 7 │ ├─┼─────┤ │1│8 9 │ ├─┼─────┤ │1│10 11│ └─┴─────┘ x+⍤0 1⊢y ⍝ n-to-m pairing in dialects without frame agreement; invalid RANK ERROR x+⍤l r⍤(-≢cf)⊢y ⍝ matches the result of J's frame agreement 0 1 2 3 4 5 7 8 9 10 11 12
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 |