where

APL-related discussions - a stream of APL consciousness.
Not sure where to start a discussion ? Here's the place to be
Forum rules
This forum is for discussing APL-related issues. If you think that the subject is off-topic, then the Chat forum is probably a better place for your thoughts !

where

In previous posts, the game was to write functions g such that

`      (x symbol y) ≡ x g y`

for x and y of interest where g does not use the primitive symbol in question. Here, the game is to write a function h which does not use ⍸ or / or ⌿, so that for boolean vector b,

`      b ← 1=?9973⍴2      (⍸b) ≡ h b1`

Since ⎕io is intimately involved with ⍸, the expression should work when ⎕io is 0 or 1. (Nevertheless, ⎕io delenda est!.)

Without 0

`      ww ← {(⍳⎕io<⊃⍵),0~⍨⍵×⍳≢⍵}      (⍸b) ≡ ww b1`

The non-zero elements of b×⍳≢b nearly have what is required. We do need put back a leading 0 when ⎕io is 0 and the leading element of b is 1.

Without Without

`      ws ← {(+/~⍵) ↓ {⍵[⍋⍵]} ⍵×⍳≢⍵}      (⍸b) ≡ ws b1`

If we are paranoid and suspect that / (replicate) may be involved in computing ~0, an alternative computation is to drop the requisite number of leading elements from the sorted result of ⍵×≢⍵.
Roger|Dyalog

Posts: 236
Joined: Thu Jul 28, 2011 10:53 am