Suffix: Difference between revisions
Miraheze>Marshall No edit summary |
(Prefix and Suffix vectors now have a page) |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 2: | Line 2: | ||
In analogy to [[prefix]] testing, whether an array is a suffix may be tested using [[Take]] with a [[negate]]d left argument and [[Match]]. The only difference is the negation. | In analogy to [[prefix]] testing, whether an array is a suffix may be tested using [[Take]] with a [[negate]]d left argument and [[Match]]. The only difference is the negation. | ||
< | <syntaxhighlight lang=apl> | ||
isSuffix ← {((≢⍺)≤(≢⍵)) ∧ ⍺≡(-≢⍺)↑⍵} | isSuffix ← {((≢⍺)≤(≢⍵)) ∧ ⍺≡(-≢⍺)↑⍵} | ||
'fix' isSuffix 'suffix' | 'fix' isSuffix 'suffix' | ||
Line 8: | Line 8: | ||
'suff' isSuffix 'suffix' | 'suff' isSuffix 'suffix' | ||
0 | 0 | ||
</ | </syntaxhighlight> | ||
We can also use an < | We can also use an <syntaxhighlight lang=apl inline>isPrefix</syntaxhighlight> function directly by [[Reverse|reversing]] both its arguments. In the second definition below, this relation is written more succinctly in a [[tacit]] style using the [[Over]] operator. | ||
< | <syntaxhighlight lang=apl> | ||
isSuffix ← {(⊖⍺)isPrefix(⊖⍵)} | isSuffix ← {(⊖⍺)isPrefix(⊖⍵)} | ||
isSuffix ← isPrefix⍥⊖ | isSuffix ← isPrefix⍥⊖ | ||
</ | </syntaxhighlight> | ||
In [[leading axis theory]], the [[cell shape]] of each k-[[cell]] in an array is a suffix of that array's [[shape]], while the [[frame]] is a [[prefix]] of the shape. | In [[leading axis theory]], the [[cell shape]] of each k-[[cell]] in an array is a suffix of that array's [[shape]], while the [[frame]] is a [[prefix]] of the shape. | ||
[[Iverson notation]] included the notion of a suffix vector <math>\omega^j(n)</math> consisting of <math>n-j</math> zeros followed by <math>j</math> ones; such a vector could be used to produce a length-<math>j</math> suffix of a length-<math>n</math> vector using [[Compress]]. | [[Iverson notation]] and very early APLs included the notion of a [[suffix vector]] <math>\omega^j(n)</math> consisting of <math>n-j</math> zeros followed by <math>j</math> ones; such a vector could be used to produce a length-<math>j</math> suffix of a length-<math>n</math> vector using [[Compress]]. | ||
[[Category:Array relationships]] |
Latest revision as of 01:19, 2 March 2024
A suffix is a kind of subarray which is like a prefix except that values are taken from the end of the array rather than the beginning: a vector is a suffix of another vector if it is no longer than that vector, and shares all of its trailing elements. In leading axis theory, an array may be considered a suffix of another array of the same rank if the same relation holds with major cells in place of elements. The function Drop produces suffixes of its right argument when the left argument is non-negative.
In analogy to prefix testing, whether an array is a suffix may be tested using Take with a negated left argument and Match. The only difference is the negation.
isSuffix ← {((≢⍺)≤(≢⍵)) ∧ ⍺≡(-≢⍺)↑⍵} 'fix' isSuffix 'suffix' 1 'suff' isSuffix 'suffix' 0
We can also use an isPrefix
function directly by reversing both its arguments. In the second definition below, this relation is written more succinctly in a tacit style using the Over operator.
isSuffix ← {(⊖⍺)isPrefix(⊖⍵)} isSuffix ← isPrefix⍥⊖
In leading axis theory, the cell shape of each k-cell in an array is a suffix of that array's shape, while the frame is a prefix of the shape.
Iverson notation and very early APLs included the notion of a suffix vector consisting of zeros followed by ones; such a vector could be used to produce a length- suffix of a length- vector using Compress.