Frame agreement: Difference between revisions

Jump to navigation Jump to search
64 bytes added ,  14:23, 26 August 2023
m
(Reorganize page to cover general frame conformance; add model for prefix agreement.)
 
(8 intermediate revisions by the same user not shown)
Line 7: Line 7:
       x←⍳2
       x←⍳2
       y←2 3 2⍴⍳12
       y←2 3 2⍴⍳12
       x{⍺⍵}⍤99 2⊢y       ⍝ 1-to-n pairing; ⍤99 corresponds to empty frame
       x{⍺⍵}⍤99 2⊢y     ⍝ 1-to-n pairing; ⍤99 corresponds to empty frame
┌───┬─────┐
┌───┬─────┐
│1 2│1 2  │
│1 2│1 2  │
Line 17: Line 17:
│  │11 12│
│  │11 12│
└───┴─────┘
└───┴─────┘
       x{⍺⍵}⍤0 2⊢y           ⍝ 1-to-1 pairing; frames match; (,2) ≡ (,2)
       x{⍺⍵}⍤0 2⊢y       ⍝ 1-to-1 pairing; frames match; (,2) ≡ (,2)
┌─┬─────┐
┌─┬─────┐
│1│1 2  │
│1│1 2  │
Line 125: Line 125:


=== Model ===
=== Model ===
In dialects that do not feature frame prefix agreement, it can nevertheless be utilised by the introduction of an explicit operator:
In dialects that do not feature frame prefix agreement, it can nevertheless be utilised by the introduction of an explicit operator:


<syntaxhighlight lang=apl>
<syntaxhighlight lang=apl>
       _FA_←{
       _FA_←{
           assert←{0≡⍵:'RANK ERROR: one frame must be a prefix of the other' ⎕SIGNAL 4 ⋄ ⍵}
           assert←{0≡⍵:'error: no common frame prefix' ⎕SIGNAL 4 ⋄ ⍵}
           r←(1↓⌽3⍴⌽⍵⍵)⌊≢∘⍴¨⍺⍵          ⍝ dyadic ranks
           r←1↓⌽3⍴⌽⍵⍵ ⋄ ar←≢¨p←⍴¨⍺⍵      ⍝ dyadic ranks, array ranks, shapes
           lf rf←(-r)↓∘⍴¨⍺⍵              ⍝ frames
          c←r{⍺>0:⍺⌊⍵ ⋄ 0⌈⍺+⍵}¨ar      ⍝ cell ranks
           cf←lf{⍺<⍥≢⍵:⍺ ⋄ ⍵}rf          common frame, assuming frames agree
           fl fr←(-c)↓¨p                left and right frames                      
           k←{⍬≡⍵:99 ⋄ -≢⍵}cf            ⍝ relative rank
           s←fl{⍺<⍥≢⍵:⍺ ⋄ ⍵}fr          shorter frame
           assert ⍺∧⍥(cf≡(≢cf)↑⍴)⍵:     verify that frames agree
           k←{⍬≡⍵:99 ⋄ -≢⍵}s            ⍝ relative rank
           ⍺ ⍺⍺⍤⍵⍵⍤k⊢⍵
           assert ⍺∧⍥(s≡(≢s)↑⍴)⍵:       do frames agree?
           ⍺ ⍺⍺⍤c⍤k⊢⍵
       }
       }
       x+_FA_ 0 1⊢y
       x+_FA_ 0 1⊢y
Line 148: Line 148:
</syntaxhighlight>
</syntaxhighlight>
{{Works in|[[Dyalog APL]]}}
{{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}}
trusted
83

edits

Navigation menu