Frame agreement: Difference between revisions

Jump to navigation Jump to search
480 bytes added ,  23:17, 9 July 2023
Replace with clearer examples; add table showing frames / cells.
(Undo revision 10300 by ⊂⍺m (talk))
Tag: Undo
(Replace with clearer examples; add table showing frames / cells.)
Line 2: Line 2:


== 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>-[[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>.
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>
   a=: 3 4
   x=: i.2
   b=: i.2 3 2
   y=: 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
   x+"0 1 y
  lr;rr
0 1
┌─┬─┐
2 3
│0│1│
  4  5
└─┴─┘
 
  ]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
  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.


10 11
{|class=wikitable
12 13
! Argument          !!        Step 1: Frames / Cells          !! Step 2: Common frame—cells paired
14 15
|-
  'A B'=: (<"lr]a),&<(<"rr]b)    NB. frame each argument in terms of lr- or rr-cells
| <syntaxhighlight lang=apl inline>x</syntaxhighlight>    || <syntaxhighlight lang=apl inline>2 []</syntaxhighlight>                    || <syntaxhighlight lang=apl inline>2|[]</syntaxhighlight>
  A                              NB. a framed as lr-cells
|-
┌─┬─┐
| <syntaxhighlight lang=apl inline>y</syntaxhighlight>    || <syntaxhighlight lang=apl inline>2 3 [2]</syntaxhighlight>                  || <syntaxhighlight lang=apl inline>2|3 [2]</syntaxhighlight>
│3│4│
|}
└─┴─┘
 
  $A
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
  B                              NB. b framed as rr-cells
      x{⍺⍵}⍤(-≢cf)⊢y            ⍝ 1st step: the (-≢cf)-cells are paired 1-to-1 between x and y
┌───┬───┬─────┐
┌─┬─────┐
│0 1│2 3│4 5  │
│0│0 1  │
├───┼───┼─────┤
│ │2 3  │
│6 7│8 9│10 11│
│ │4 5  │
└───┴───┴─────┘
├─┼─────┤
  $B
│1│ 6  7│
2 3
│ │ 8  9│
  ]pairs=: A([;'+';])&>_1]B      NB. each cell of sa is paired with each cell among the corresponding group of (*/sf) cells of la
│ │10 11│
┌─┬─┬─────┐
└─┴─────┘
│3│+│0 1  │
      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)
├─┼─┼─────┤
┌─┬─────┐
│3│+│2 3  │
│0│0 1  │
├─┼─┼─────┤
├─┼─────┤
│3│+│4 5  │
│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


┌─┬─┬─────┐
│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
  7  8
 
9 10
10 11
11 12
12 13
14 15
  pairs -: a ([;'+';])"_1"(-#cf)]b
1
</syntaxhighlight>
</syntaxhighlight>
{{Works in|[[J]]}}
{{Works in|[[Dyalog APL]]}}
 
In the example above, based on the ranks <syntaxhighlight lang=j inline>0 1</syntaxhighlight> of the verb <syntaxhighlight lang=j inline>+"0 1</syntaxhighlight>, <syntaxhighlight lang=j inline>a</syntaxhighlight>'s frame is <syntaxhighlight lang=j inline>,2</syntaxhighlight> and its cell shape is [[empty array|empty]] (<syntaxhighlight lang=j inline>0$0</syntaxhighlight>); b's frame is <syntaxhighlight lang=j inline>2 3</syntaxhighlight> and its cell shape is <syntaxhighlight lang=j inline>,2</syntaxhighlight>. The shorter of these, and thus the common frame, is <syntaxhighlight lang=j inline>,2</syntaxhighlight>, so each of the two <syntaxhighlight lang=j inline>0$0</syntaxhighlight>-shaped cells (atoms) of <syntaxhighlight lang=j inline>a</syntaxhighlight> is paired with each of the corresponding <syntaxhighlight lang=j inline>6</syntaxhighlight> (i.e. <syntaxhighlight lang=j inline>*/sf</syntaxhighlight>) corresponding <syntaxhighlight lang=j inline>b</syntaxhighlight> cells.


[[Category:Leading axis theory]][[Category:Function characteristics]][[Category:Conformability]]{{APL features}}
[[Category:Leading axis theory]][[Category:Function characteristics]][[Category:Conformability]]{{APL features}}
trusted
83

edits

Navigation menu