Indexing Functions for Triangular or Rectangular Arrays Michael Somos Jul 12 2003 When they are entered into the OEIS, triangles of numbers are normally converted into sequences by reading them across the rows; square or rectangular arrays are converted into sequences by reading them by antidiagonals. The following functions enable one to go in the other direction and to recover the array from the sequence. For example, if the sequence is obtained from a square array by reading it by antidiagonals upwards, then the n-th term a(n) becomes the element T( t1(n), t2(n) ) of the array, where t1(n)=binomial(floor(3/2+sqrt(2+2*n)),2)-(n+1) t2(n)=n-binomial(floor(1/2+sqrt(2+2*n)),2) The values of t1(n) and t2(n) are themselves sequences A025581 and A002262 in the OEIS. /* ======================================================================== */ /* array by antidiagonals up ( origin 0 -> 0,0 ) index functions */ t1(n)=binomial(floor(3/2+sqrt(2+2*n)),2)-(n+1) /* A025581 */ t2(n)=n-binomial(floor(1/2+sqrt(2+2*n)),2) /* A002262 */ 0 1 2 3 -- -- -- -- 0| 0 2 5 9 1| 1 4 8 13 2| 3 7 12 18 3| 6 11 17 24 /* ======================================================================== */ /* array by antidiagonals down ( origin 0 -> 0,0 ) index functions */ t1(n)=n-binomial(floor(1/2+sqrt(2+2*n)),2) /* A002262 */ t2(n)=binomial(floor(3/2+sqrt(2+2*n)),2)-(n+1) /* A025581 */ 0 1 2 3 -- -- -- -- 0| 0 1 3 6 1| 2 4 7 11 2| 5 8 12 17 3| 9 13 18 24 /* ======================================================================== */ /* array by antidiagonals up ( origin 1 -> 1,1 ) index functions */ t1(n)=binomial(floor(3/2+sqrt(2*n)),2)-n+1 /* A004736 */ t2(n)=n-binomial(floor(1/2+sqrt(2*n)),2) /* A002260 */ 1 2 3 4 -- -- -- -- 1| 1 3 6 10 2| 2 5 9 14 3| 4 8 13 19 4| 7 12 18 25 /* ======================================================================== */ /* array by antidiagonals down ( origin 1 -> 1,1 ) index functions */ t1(n)=n-binomial(floor(1/2+sqrt(2*n)),2) /* A002260 */ t2(n)=binomial(floor(3/2+sqrt(2*n)),2)-n+1 /* A004736 */ 1 2 3 4 -- -- -- -- 1| 1 2 4 7 2| 3 5 8 12 3| 6 9 13 18 4| 10 12 19 25 /* ======================================================================== */ /* lower triangular table by rows (L->R)( origin 0 -> 0,0 ) index functions */ t1(n)=floor(-1/2+sqrt(2+2*n)) /* A003056 */ t2(n)=n-binomial(floor(1/2+sqrt(2+2*n)),2) /* A002262 */ 0 1 2 3 -- -- -- -- 0| 0 1| 1 2 2| 3 4 5 3| 6 7 8 9 /* ======================================================================== */ /* lower triangular table by rows (L->R)( origin 1 -> 1,1 ) index functions */ t1(n)=floor(1/2+sqrt(2*n)) /* A002024 */ t2(n)=n-binomial(floor(1/2+sqrt(2*n)),2) /* A002260(n-1) */ 1 2 3 4 -- -- -- -- 1| 1 2| 2 3 3| 4 5 6 4| 7 8 9 10 /* ======================================================================== */ /* lower triangular table by rows (R->L)( origin 1 -> 1,1 ) index functions */ t1(n)=floor(1/2+sqrt(2*n)) /* A002024 */ t2(n)=binomial(floor(3/2+sqrt(2*n)),2)-n+1 /* A004736 */ 1 2 3 4 -- -- -- -- 1| 1 2| 3 2 3| 6 5 4 4|10 9 8 7 /* ======================================================================== */ /* lower triangular table by rows (L->R)( origin 1 -> 1,0 ) index functions */ t1(n)=floor(1/2+sqrt(2*n)) /* A002024 */ t2(n)=n-1-binomial(floor(1/2+sqrt(2*n)),2) /* A002260(n-1)-1 */ 0 1 2 3 -- -- -- -- 0| 1| 1 2| 2 3 3| 4 5 6 4| 7 8 9 10 /* ======================================================================== */ /* lower triangular table by rows (L->R)( origin 2 -> 2,1 ) index functions */ t1(n)=floor(3/2+sqrt(2*n-2)) /* A003057 */ t2(n)=n-1-binomial(floor(1/2+sqrt(2*n-2)),2) /* A002260(n-2) */ 1 2 3 4 -- -- -- -- 1| 2| 2 3| 3 4 4| 5 6 7 4| 8 9 10 11 /* ======================================================================== */ /* triangular table by 1+n\2 rows (L->R)( origin 0 -> 0,0 ) index functions */ t1(n)=floor(sqrt(1+4*n)-1) /* A055086 */ t2(n)=floor((1+4*n-sqr(floor(sqrt(1+4*n))))/4) /* A055087 */ 0 1 2 -- -- -- 0| 0 1| 1 2| 2 3 3| 4 5 4| 6 7 8 5| 9 10 11 /* ======================================================================== */ /* triangular table by 1+[n/3] rows (L->R)(origin 0 -> 0,0) index functions */ t1(n)=floor(sqrt(6*n+6)-3/2) /* A073188 */ t2(n)=(n-3*binomial(1+floor(t1(n)/3),2))%(floor(t1(n)/3)+1) /* A073189 */ 0 1 2 -- -- -- 0| 0 1| 1 2| 2 3| 3 4 4| 5 6 5| 7 8 6| 9 10 11 7|12 13 14 8|15 16 17 /* ======================================================================== */ /* triangular table by rows (L->R)( origin 0 -> 0,0 ) index functions */ t1(n)=floor(-1/2+sqrt(n+1)) /* A000194(n+1)-1 */ t2(n)=n-2*binomial(floor(1/2+sqrt(n+1)),2) 0 1 2 3 4 5 -- -- -- -- -- -- 0| 0 1 1| 2 3 4 5 2| 6 7 8 9 10 11 3|12 13 14 15 16 17 /* ======================================================================== */ /* triangular table by rows (L->R)( origin 0 -> 0,0 ) index functions */ t1(n)=floor(sqrt(n)) /* A048760(n) */ t2(n)=n-floor(sqrt(n))^2 /* A053186(n) */ 0 1 2 3 4 5 6 -- -- -- -- -- -- -- 0| 0 1| 1 2 3 2| 4 5 6 7 8 3| 9 10 11 12 13 14 15 /* ======================================================================== */ /* triangular table by rows (L->R)( origin 1 -> 1,1 ) index functions */ t1(n)=1+floor(sqrt(n-1)) /* A003059(n) */ t2(n)=n-floor(sqrt(n-1))^2 /* A071797(n) */ 1 2 3 4 5 6 7 -- -- -- -- -- -- -- 1| 1 2| 2 3 4 3| 5 6 7 8 9 4|10 11 12 13 14 15 16 /* ======================================================================== */