Frame agreement: Difference between revisions

From APL Wiki
Jump to navigation Jump to search
m (Align comments)
m (Introduction rewording, and formatting fixes)
Line 1: Line 1:
'''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 [[array]]s only if one of their [[frame]]s relative to the cells of the function's corresponding dyadic rank. is a [[prefix]] of the other. The shape of the result is that of the [[argument]] with longer frame.
'''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 [[array]]s only if one of their [[frame]]s, 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.
 
<syntaxhighlight lang=j inline>rf</syntaxhighlight>


== Description ==
== Description ==
A dyadic function <syntaxhighlight lang=j inline>f</syntaxhighlight> with left and right ranks <syntaxhighlight lang=j inline>lr</syntaxhighlight> and <syntaxhighlight lang=j inline>rr</syntaxhighlight>, respectively, splits its left argument <syntaxhighlight lang=j inline>x</syntaxhighlight> into <syntaxhighlight lang=j inline>lf</syntaxhighlight>-cells, and splits its right argument <syntaxhighlight lang=j inline>y</syntaxhighlight> into <syntaxhighlight lang=j inline>rf</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 prefix (i.e. shorter) frame is called the common frame (denoted here as <syntaxhighlight lang=j inline>cf</syntaxhighlight>), and the suffix of the longer frame relative to the common frame is called the surplus frame (denoted here as <syntaxhighlight lang=j inline>sf</syntaxhighlight>. "Cells" will be used here to denote the <syntaxhighlight lang=j inline>lr</syntaxhighlight>-cells (for the left argument <syntaxhighlight lang=j inline>a</syntaxhighlight>) or the <syntaxhighlight lang=j inline>rr</syntaxhighlight>-cells (for the right argument <syntaxhighlight lang=j inline>b</syntaxhighlight>). If the frames are identical, each cell of <syntaxhighlight lang=j inline>x</syntaxhighlight> is paired with the corresponding cell of <syntaxhighlight lang=j inline>y</syntaxhighlight> in a 1-to-1 pairing. For the case in which the frame lengths differ, we'll denote the shorter-framed argument as <syntaxhighlight lang=j inline>sa</syntaxhighlight> and the longer-framed argument as <syntaxhighlight lang=j inline>la</syntaxhighlight>. Each cell of <syntaxhighlight lang=j inline>sa</syntaxhighlight> is paired with each among the corresponding group of <syntaxhighlight lang=j inline>*/sf</syntaxhighlight> cells of <syntaxhighlight lang=j inline>la</syntaxhighlight>. The collective results among all applications of <syntaxhighlight lang=j inline>f</syntaxhighlight> are framed by the longer frame <syntaxhighlight lang=j inline>lf</syntaxhighlight>.
A dyadic function <syntaxhighlight lang=j inline>f</syntaxhighlight> with left and right ranks <syntaxhighlight lang=j inline>lr</syntaxhighlight> and <syntaxhighlight lang=j inline>rr</syntaxhighlight>, respectively, splits its left argument <syntaxhighlight lang=j inline>x</syntaxhighlight> into <syntaxhighlight lang=j inline>lf</syntaxhighlight>-[[cell]]s, and splits its right argument <syntaxhighlight lang=j inline>y</syntaxhighlight> into <syntaxhighlight lang=j inline>rf</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 prefix (i.e. shorter) frame is called the common frame (denoted here as <syntaxhighlight lang=j inline>cf</syntaxhighlight>), and the suffix of the longer frame relative to the common frame is called the surplus frame (denoted here as <syntaxhighlight lang=j inline>sf</syntaxhighlight>. "Cells" will be used here to denote the <syntaxhighlight lang=j inline>lr</syntaxhighlight>-cells (for the left argument <syntaxhighlight lang=j inline>a</syntaxhighlight>) or the <syntaxhighlight lang=j inline>rr</syntaxhighlight>-cells (for the right argument <syntaxhighlight lang=j inline>b</syntaxhighlight>). If the frames are identical, each cell of <syntaxhighlight lang=j inline>x</syntaxhighlight> is paired with the corresponding cell of <syntaxhighlight lang=j inline>y</syntaxhighlight> in a 1-to-1 pairing. For the case in which the frame lengths differ, we'll denote the shorter-framed argument as <syntaxhighlight lang=j inline>sa</syntaxhighlight> and the longer-framed argument as <syntaxhighlight lang=j inline>la</syntaxhighlight>. Each cell of <syntaxhighlight lang=j inline>sa</syntaxhighlight> is paired with each among the corresponding group of <syntaxhighlight lang=j inline>*/sf</syntaxhighlight> cells of <syntaxhighlight lang=j inline>la</syntaxhighlight>. The collective results among all applications of <syntaxhighlight lang=j inline>f</syntaxhighlight> are framed by the longer frame <syntaxhighlight lang=j inline>lf</syntaxhighlight>.
 


== Examples ==
== Examples ==

Revision as of 18:09, 7 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 lr and rr, respectively, splits its left argument x into lf-cells, and splits its right argument y into rf-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 prefix (i.e. shorter) frame is called the common frame (denoted here as cf), and the suffix of the longer frame relative to the common frame is called the surplus frame (denoted here as sf. "Cells" will be used here to denote the lr-cells (for the left argument a) or the rr-cells (for the right argument b). If the frames are identical, each cell of x is paired with the corresponding cell of y in a 1-to-1 pairing. For the case in which the frame lengths differ, we'll denote the shorter-framed argument as sa and the longer-framed argument as la. Each cell of sa is paired with each among the corresponding group of */sf cells of la. The collective results among all applications of f are framed by the longer frame lf.

Examples

   a=: 3 4
   b=: i.2 3 2
   'lr rr'=: }.+"0 1 b.0           NB. let lv and rv denote the left and right ranks of the verb +"0 1
   lr;rr
┌─┬─┐
│0│1│
└─┴─┘
   ]af=: (-lr)}.$a                 NB. a's frame
2
   ]bf=: (-rr)}.$b                 NB. b's frame
2 3
   af =/@(<.&# {.&> ;) bf          NB. one frame prefixes the other
1
   ]cf=: af {.@(<.&#{.&>;~) bf     NB. the common frame (always the shorter of the two frames)
2
   ]lf=: af >@(-.@>&# { ;) bf      NB. the longer of the two frames
2 3
   ]sf=: lf }.~ #cf                NB. the surplus frame results from removing the common frame from the left side of longer frame 
3
   a +"0 1]b
 3  4
 5  6
 7  8

10 11
12 13
14 15
   'A B'=: (<"lr]a),&<(<"rr]b)     NB. frame each argument in terms of lr- or rr-cells
   A                               NB. a framed as lr-cells
┌─┬─┐
│3│4│
└─┴─┘
   $A
2
   B                               NB. b framed as rr-cells
┌───┬───┬─────┐
│0 1│2 3│4 5  │
├───┼───┼─────┤
│6 7│8 9│10 11│
└───┴───┴─────┘
   $B
2 3
   ]pairs=: A([;'+';])&>_1]B       NB. each cell of sa is paired with each cell among the corresponding group of (*/sf) cells of la 
┌─┬─┬─────┐
│3│+│0 1  │
├─┼─┼─────┤
│3│+│2 3  │
├─┼─┼─────┤
│3│+│4 5  │
└─┴─┴─────┘

┌─┬─┬─────┐
│4│+│6 7  │
├─┼─┼─────┤
│4│+│8 9  │
├─┼─┼─────┤
│4│+│10 11│
└─┴─┴─────┘
   A+&>"_1]B                       NB. the results of all applications of + are framed by lf
 3  4
 5  6
 7  8

10 11
12 13
14 15
   pairs -: a ([;'+';])"_1"(-#cf)]b
1
Works in: J

In the example above, based on the ranks 0 1 of the verb +"0 1, a's frame is ,2 and its cell shape is empty (0$0); b's frame is 2 3 and its cell shape is ,2. The shorter of these, and thus the common frame, is ,2, so each of the two 0$0-shaped cells (atoms) of a is paired with each of the corresponding 6 (i.e. */sf) corresponding b cells.

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