login
T(n,k) = ((n + k - 1)*(n + k - 2) - (-1 + (-1)^floor((n + k)/2))*n + (1 +(-1)^floor((n + k)/2))*k)/2; n , k > 0, read by antidiagonals.
4

%I #55 Dec 13 2018 11:29:19

%S 1,2,3,6,5,4,10,9,8,7,11,12,13,14,15,16,17,18,19,20,21,28,27,26,25,24,

%T 23,22,36,35,34,33,32,31,30,29,37,38,39,40,41,42,43,44,45,46,47,48,49,

%U 50,51,52,53,54,55,66,65,64,63,62,61,60,59,58,57,56,78

%N T(n,k) = ((n + k - 1)*(n + k - 2) - (-1 + (-1)^floor((n + k)/2))*n + (1 +(-1)^floor((n + k)/2))*k)/2; n , k > 0, read by antidiagonals.

%C Self-inverse permutation of the natural numbers.

%C a(n) is a pairing function: a function that reversibly maps Z^{+} x Z^{+} onto Z^{+}, where Z^{+} is the set of integer positive numbers.

%C In general, let m be natural number. Natural numbers placed in table T(n,k) by antidiagonals. The order of placement - at the beginning m antidiagonals downwards, next m antidiagonals upwards and so on. T(n,k) read by antidiagonals downwards.

%C For m = 1 the result is A056011. This sequence is result for m = 2.

%C A056023 is result for m = 1 and the changed order of placement - at the beginning m antidiagonals upwards, next m antidiagonals downwards and so on.

%H Boris Putievskiy, <a href="/A218890/b218890.txt">Rows n = 1..140 of triangle, flattened</a>

%H Boris Putievskiy, <a href="http://arxiv.org/abs/1212.2732">Transformations [of] Integer Sequences And Pairing Functions</a> arXiv:1212.2732 [math.CO], 2012.

%H Eric W. Weisstein, <a href="http://mathworld.wolfram.com/PairingFunction.html">MathWorld: Pairing functions</a>

%H <a href="/index/Per#IntegerPermutation">Index entries for sequences that are permutations of the natural numbers</a>

%F For the general case.

%F As a table

%F T(n,k) = ((n + k - 1)*(n + k - 2) - (-1 + (-1)^floor((n + k + m - 2)/m))*n + (1 +(-1)^floor((n + k + m - 2)/m))*k)/2.

%F As linear sequence

%F a(n) = ((z - 1)*(z - 2) - (-1 + (-1)^floor((z + m - 2)/m))*i + (1 + (-1)^floor((z + m - 2)/m))*j)/2, where i = n - t*(t + 1)/2, j = (t*t + 3*t + 4)/2 - n, t = floor((-1 + sqrt(8*n - 7))/2), z = i + j.

%F If we change the order of placement - m antidiagonals upwards, m antidiagonals downwards and so on.

%F As a table

%F T(n,k) = ((n + k - 1)*(n + k - 2) - (-1 + (-1)^(floor((n + k + m - 2)/m) + 1))*n + (1 + (-1)^(floor((n + k + m - 2)/m) + 1))*k)/2.

%F As linear sequence

%F a(n) = ((z - 1)*(z - 2) - (-1 + (-1)^(floor((z + m - 2)/m) + 1))*i + (1 + (-1)^(floor((z + m - 2)/m) + 1))*j)/2, where i = n - t*(t + 1)/2, j = (t*t + 3*t + 4)/2 - n, t = floor((-1 + sqrt(8*n - 7))/2), z = i + j.

%F For this sequence.

%F As a table

%F T(n,k) = ((n + k - 1)*(n + k - 2) - (-1 +(-1)^floor((n + k)/2))*n + (1 + (-1)^floor((n + k)/2))*k)/2.

%F As linear sequence

%F a(n) = ((z - 1)*(z - 2) - (-1 + (-1)^floor(z/2))*i + (1 + (-1)^floor(z/2))*j)/2, where i = n - t*(t + 1)/2, j = (t*t + 3*t + 4)/2 - n, t = floor((-1 + sqrt(8*n - 7))/2), z = i + j.

%e The start of the sequence as table. The direction of the placement denotes by ">" and "v".

%e v...v v...v

%e ..1...2...6..10..11..16..28..36...

%e ..3...5...9..12..17..27..35..38...

%e > 4...8..13..18..26..34..39..48...

%e > 7..14..19..25..33..40..49..63...

%e .15..20..24..32..41..50..62..74...

%e .21..23..31..42..51..61..73..84...

%e >22..30..43..52..60..72..85..98...

%e >29..44..53..59..71..86..99.113...

%e . . .

%e The start of the sequence as triangle array read by rows:

%e 1;

%e 2, 3;

%e 6, 5, 4;

%e 10, 9, 8, 7;

%e 11, 12, 13, 14, 15;

%e 16, 17, 18, 19, 20, 21;

%e 28, 27, 26, 25, 24, 23, 22;

%e 36, 35, 34, 33, 32, 31, 30, 29;

%e ...

%e Row r consists of r consecutive numbers from r*r/2 - r/2 + 1 to r*r/2 + r.

%e If r congruent to 1 or 2 mod 4 rows are increasing.

%e If r congruent to 0 or 3 mod 4 rows are decreasing.

%p T:=(n,k)->((n+k-1)*(n+k-2)-(-1+(-1)^floor((n+k)/2))*n+(1+(-1)^floor((n+k)/2))*k)/2: seq(seq(T(k,n-k),k=1..n-1),n=1..13); # _Muniru A Asiru_, Dec 13 2018

%t T[n_, k_] := ((n+k-1)(n+k-2) - (-1 + (-1)^Floor[(n+k)/2])n + (1 + (-1)^Floor[(n+k)/2]) k)/2;

%t Table[T[n-k+1, k], {n, 1, 12}, {k, n, 1, -1}] // Flatten (* _Jean-François Alcover_, Dec 06 2018 *)

%o (Python)

%o t=int((math.sqrt(8*n-7) - 1)/ 2)

%o i=n-t*(t+1)/2

%o j=(t*t+3*t+4)/2-n

%o z=i+j

%o result=((z-1)*(z-2)-(-1+(-1)**int(z/2))*i+(1+(-1)**int(z/2))*j)/2

%o (Maxima) T(n,k) = ((n + k - 1)*(n + k - 2) - (-1 + (-1)^floor((n + k)/2))*n + (1 +(-1)^floor((n + k)/2))*k)/2$

%o create_list(T(k, n - k), n, 1, 12, k, 1, n - 1); /* _Franck Maminirina Ramaharo_, Dec 13 2018 */

%Y Cf. A056011, A056023.

%K nonn,tabl

%O 1,2

%A _Boris Putievskiy_, Feb 19 2013