Prefix and suffix vectors: Difference between revisions

Jump to navigation Jump to search
no edit summary
(Created page with "{| class=vertical-navbox style="float:right; font-size:500%; margin:0 1ex;" |<code>⍺</code> <code>⍵</code> |} In Iverson notation, the '''prefix vector''' <math>\alpha^j(n)</math> and '''suffix vector''' <math>\omega^j(n)</math> of weight <math>j</math> and length <math>n</math> are Boolean vectors that can be used with Replicate to select a prefix or suffix of a vector, a task now performed with Take. Primitives <code>⍺</code> and <code>⍵...")
 
No edit summary
Line 2: Line 2:
|<code>⍺</code> <code>⍵</code>
|<code>⍺</code> <code>⍵</code>
|}
|}
In [[Iverson notation]], the '''prefix vector''' <math>\alpha^j(n)</math> and '''suffix vector''' <math>\omega^j(n)</math> of weight <math>j</math> and length <math>n</math> are [[Boolean]] vectors that can be used with [[Replicate]] to select a [[prefix]] or [[suffix]] of a vector, a task now performed with [[Take]]. Primitives <code>⍺</code> and <code>⍵</code> based on this notation were defined in [[IVSYS/7090]] and [[APL\360]], but removed from APL\360 before its public release in 1968.
In [[Iverson notation]], the '''prefix vector''' <math>\alpha^j(n)</math> and '''suffix vector''' <math>\omega^j(n)</math> of weight <math>j</math> and length <math>n</math> are [[Boolean]] vectors that can be used with [[Compress]] to select a [[prefix]] or [[suffix]] of a vector, a task now performed with [[Take]]. Primitives <code>⍺</code> and <code>⍵</code> based on this notation were defined in [[IVSYS/7090]] and [[APL\360]], but removed from APL\360 before its public release in 1968.


The prefix vector <math>\alpha^j(n)</math> is defined to be the length-<math>n</math> [[vector]] where the first <math>j</math> elements (or <math>n</math>, if smaller) are 1 and the rest are 0. Likewise, the suffix vector has that many 1s at the end. In 1-indexed APL, <code>N⍺J</code> was defined to be <syntaxhighlight lang=apl inline>J≥⍳N</syntaxhighlight> and <code>N⍵J</code> to be <syntaxhighlight lang=apl inline>(1+N-J)≤⍳N</syntaxhighlight>. Because Iverson notation allows the length of a vector to be inferred from context, the first <math>j</math> elements of vector <math>v</math> can be taken with <math>\alpha^j/v</math>, and similarly <math>\alpha^j/M</math> and <math>\alpha^j/\!\!/M</math> take the first <math>j</math> columns or rows of a matrix. In APL, what is now <syntaxhighlight lang=apl inline>J↑V</syntaxhighlight> (for <syntaxhighlight lang=apl inline>J≥0</syntaxhighlight> and <syntaxhighlight lang=apl inline>J≤N</syntaxhighlight>) was written <syntaxhighlight lang=apl inline>((⍴V)⍺J)/V</syntaxhighlight>, and <syntaxhighlight lang=apl inline>(-J)↑V</syntaxhighlight> was <syntaxhighlight lang=apl inline>((⍴V)⍵J)/V</syntaxhighlight> (although most likely the shape <syntaxhighlight lang=apl inline>⍴V</syntaxhighlight> would have been saved elsewhere in the program rather than being written out). An instance of [[Drop]] such as <syntaxhighlight lang=apl inline>J↓V</syntaxhighlight> was written <syntaxhighlight lang=apl inline>(~(⍴V)⍺J)/V</syntaxhighlight>.
The prefix vector <math>\alpha^j(n)</math> is defined to be the length-<math>n</math> [[vector]] where the first <math>j</math> elements (or <math>n</math>, if smaller) are 1 and the rest are 0. Likewise, the suffix vector has that many 1s at the end. In 1-indexed APL, <code>N⍺J</code> was defined to be <syntaxhighlight lang=apl inline>J≥⍳N</syntaxhighlight> and <code>N⍵J</code> to be <syntaxhighlight lang=apl inline>(1+N-J)≤⍳N</syntaxhighlight>. Because Iverson notation allows the length of a vector to be inferred from context, the first <math>j</math> elements of vector <math>v</math> can be taken with <math>\alpha^j/v</math>, and similarly <math>\alpha^j/M</math> and <math>\alpha^j/\!\!/M</math> take the first <math>j</math> columns or rows of a matrix. In APL, what is now <syntaxhighlight lang=apl inline>J↑V</syntaxhighlight> (for <syntaxhighlight lang=apl inline>J≥0</syntaxhighlight> and <syntaxhighlight lang=apl inline>J≤N</syntaxhighlight>) was written <syntaxhighlight lang=apl inline>((⍴V)⍺J)/V</syntaxhighlight>, and <syntaxhighlight lang=apl inline>(-J)↑V</syntaxhighlight> was <syntaxhighlight lang=apl inline>((⍴V)⍵J)/V</syntaxhighlight> (although most likely the shape <syntaxhighlight lang=apl inline>⍴V</syntaxhighlight> would have been saved elsewhere in the program rather than being written out). An instance of [[Drop]] such as <syntaxhighlight lang=apl inline>J↓V</syntaxhighlight> was written <syntaxhighlight lang=apl inline>(~(⍴V)⍺J)/V</syntaxhighlight>.

Navigation menu