## Inverse Where

General APL language issues

### Inverse Where

18.0 introduced the inverse of Where, monadic ⍸⍣¯1. Thanks! As pointed out to me on Reddit (https://www.reddit.com/r/adventofcode/c ... ?context=3) it is useful for building grids out of coordinates:
`      ⍸⍣¯1⊢(1 2)(2 1)(3 3)0 1 01 0 00 0 1`

Unfortunately it insists that its argument is sorted:
`      ⍸⍣¯1⊢(2 1)(1 2)(3 3)DOMAIN ERROR`

Can you please consider removing that restriction? I see no benefits and several disbenefits:
• It took me a long time to work out the reason for the DOMAIN ERROR, and ⎕DMX was no help.
• The workaround is to explicitly sort the argument, which takes programmer and CPU time: ⍸⍣¯1{(⊂⍋⍵)⌷⍵}(2 1)(1 2)(3 3)
• Checking that the argument is sorted must take up even more CPU time.

Posts: 5
Joined: Wed May 29, 2019 1:51 pm

### Re: Inverse Where

I believe that a reason for requiring that the argument x in ⍸⍣¯1⊢x be sorted, is that that ensures
x ←→ ⍸ ⍸⍣¯1 ⊢x.
Roger|Dyalog

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

### Re: Inverse Where

I would like to point out that a better way to create the grid from the coordinates, is the @ operator. For example:

For a vector:

`      b←(?10⍴2),4⍴0      b0 1 0 1 0 0 1 0 1 0 0 0 0 0      ⍸b1 3 6 8      ⍸⍣¯1 ⍸b0 1 0 1 0 0 1 0 1      1@(⍸b)⊢14⍴00 1 0 1 0 0 1 0 1 0 0 0 0 0      b ≡ 1@(⍸b)⊢14⍴01`

That is, ⍸⍣¯1 does not necessarily get the original argument but @ does. Put another way, ⍸⍣¯1⊢x produces the correct grid only if x contains the maximum coordinate.

Likewise for a matrix:

`      c←5 6↑?3 4⍴2      c1 1 1 0 0 00 1 0 0 0 01 0 1 1 0 00 0 0 0 0 00 0 0 0 0 0      ⍸c┌───┬───┬───┬───┬───┬───┬───┐│0 0│0 1│0 2│1 1│2 0│2 2│2 3│└───┴───┴───┴───┴───┴───┴───┘      ⍸⍣¯1 ⍸ c1 1 1 00 1 0 01 0 1 1      1@(⍸c)⊢5 6⍴01 0 0 0 0 0 0 0 0 00 0 1 1 0 0 0 0 0 00 0 1 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 00 0 0 0 0 0 0 0 0 0      c ≡ 1@(⍸c)⊢5 6⍴01`
Roger|Dyalog

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

### Who is online

Users browsing this forum: No registered users and 1 guest