Array Predicates

From NARS2000
Jump to navigationJump to search

This clever idea of Bob Bernecky's [1] provides a performance improvement for certain expressions by marking certain arrays with special properties. For example, a permutation vector [2] has the property that it is invariant under various APL primitives such as rotate/reversal (L⌽R and ⌽R) and grade up/down (⍋R and ⍒R).

Bernecky has defined several array predicate properties, one of which has been implemented in NARS so far.

Permutation Vectors

In this case, index generator (⍳R) produces a Permutation Vector, as does deal (L?R) when the left and right arguments are the same — the results of these primitives are marked internally as Permutation Vectors. Subsequent use of such arrays maintains that property when operated on by rotate/reversal and grade up/down. Moreover, the two grade (⍋PV and ⍒PV) and the index of (PV⍳R) primitives use a much faster (linear) algorithm than they would normally use when the appropriate argument is a Permutation Vector.