The observations about high dimensional zig-zag give rise to a proposal for
a different definition (in > 2 dimensions) of oblique, ie. monadic /.

http://www.jsoftware.com/help/dictionary/d421.htm says "u/.y applies u to
each of the oblique lines of a table y (...) In general, u/.y is the result
of applying u to the oblique lines of _2-cells of y"

My proposal is that, just as in 1 and 2 dimensions, u/.y is the result of
applying u to the diagonal hyperplanes with constant sum of coordinates.
Or, formally,

obl=: 1 : '(+/"1)@(#: [:i. */)@$ u/. ,'

   (</.-:<obl) i. 4 5
1

   < obl i.2 3 4
+-+------+-----------+--------------+-------------+--------+--+
|0|1 4 12|2 5 8 13 16|3 6 9 14 17 20|7 10 15 18 21|11 19 22|23|
+-+------+-----------+--------------+-------------+--------+--+
whereas 
   </. i. 2 3 4
+-------+-----------+-----------+-----------+
|0 1 2 3| 4  5  6  7| 8  9 10 11|20 21 22 23|
|       |12 13 14 15|16 17 18 19|           |
+-------+-----------+-----------+-----------+

As noted before, in 2 dimensions obl is (often) much faster than /. 

   M=: 500 400 [EMAIL PROTECTED] 1000
   10 ts '</. M'
0.3131357 32161280
   10 ts '<obl M'
0.037519248 7742912
   (</.-:<obl) M
1


R.E. Boss


-----Oorspronkelijk bericht-----
Van: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED] Namens R.E. Boss
Verzonden: zaterdag 16 december 2006 19:00
Aan: 'Programming forum'
Onderwerp: zig-zag order in >2 dimensions (was RE: [Jprogramming] zig-zag
order)

Looking at

   ZZ 5 4
 0  1  5  6
 2  4  7 13
 3  8 12 14
 9 11 15 18
10 16 17 19

the coordinates of the subsequent layers are given by

   (+/"1 <@|.`</. ]) (#: [EMAIL PROTECTED]/)5 4
+---+---+---+---+---+---+---+---+
|0 0|0 1|2 0|0 3|4 0|2 3|4 2|4 3|
|   |1 0|1 1|1 2|3 1|3 2|3 3|   |
|   |   |0 2|2 1|2 2|4 1|   |   |
|   |   |   |3 0|1 3|   |   |   |
+---+---+---+---+---+---+---+---+

If the coordinates of the zigzag order are observed carefully, one can
derive the specifications which are easily generalised to more than 2
dimensions.

a. zigzag numbers are ordered in diagonal layers (hyperplanes) of increasing
sum of cell indexes (coordinates), which sum is constant per hyperplane
b.a. subsequent zz-numbers in one hyperplane differ exactly +1 _1 in exactly
2 coordinates.
b.b. subsequent zz-numbers in two hyperplanes - the last one of the former
hp and the first one of the latter hp - differ exactly 1 in exactly 1
coordinate.

If these specs have to be applied to higher dimensions, than this can only
be successfully done with the help of generalised Gray codes. 
Most of the code in 2 dimensions can be re-used in the new definition of ZZ:

   ZZ=: $ ([: /:@;@(+/"1 <@|.`</. ]) (#: gGC7))
   ZZ 2 3 4
 0  1  8  9
 2  7 10 19
 6 11 18 20

 3  4 14 15
 5 13 16 22
12 17 21 23

Of course this works in 2 dimensions as well:
   ZZ 5 4
 0  1  5  6
 2  4  7 13
 3  8 12 14
 9 11 15 18
10 16 17 19

The hyperplanes, layers with constant sum of coordinates, can be visualised
by
   ($[: (/:{+/"1)@;@(+/"1 <@|.`</. ]) (#: gGC7))5 4
0 1 2 3
1 2 3 4
2 3 4 5
3 4 5 6
4 5 6 7

and 
   ($[: (/:{+/"1)@;@(+/"1 <@|.`</. ]) (#: gGC7))2 3 4
0 1 2 3
1 2 3 4
2 3 4 5

1 2 3 4
2 3 4 5
3 4 5 6

R.E. Boss

----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to