cp's OEIS Frontend

This is a front-end for the Online Encyclopedia of Integer Sequences, made by Christian Perfect. The idea is to provide OEIS entries in non-ancient HTML, and then to think about how they're presented visually. The source code is on GitHub.

A053616 Pyramidal sequence: distance to nearest triangular number.

This page as a plain text file.
%I A053616 #58 Nov 13 2024 17:20:25
%S A053616 0,0,1,0,1,1,0,1,2,1,0,1,2,2,1,0,1,2,3,2,1,0,1,2,3,3,2,1,0,1,2,3,4,3,
%T A053616 2,1,0,1,2,3,4,4,3,2,1,0,1,2,3,4,5,4,3,2,1,0,1,2,3,4,5,5,4,3,2,1,0,1,
%U A053616 2,3,4,5,6,5,4,3,2,1,0,1,2,3,4,5,6,6,5,4,3,2,1,0,1,2,3,4,5,6,7,6,5,4,3,2,1
%N A053616 Pyramidal sequence: distance to nearest triangular number.
%C A053616 From _Wolfdieter Lang_, Oct 24 2020: (Start)
%C A053616 If this sequence is written with offset 1 as a number triangle T(n, k), with n the length of row n, for n >= 1, then row n gives the primitive period of the periodic sequence {k (mod* n)}_{k>=0}, where k (mod* n) = k (mod n) if k <= floor(n/2) and otherwise it is -k (mod n). Such a modified modular relation mod* n has been used by Brändli and Beyne, but for integers relative prime to n.
%C A053616 These periodic sequences are given in A000007, A000035, A011655, A007877, |A117444|, A260686, A279316, for n = 1, 2, ..., 7. For n = 10 A271751, n = 12 A271832, n = 14 A279313. (End)
%H A053616 T. D. Noe, <a href="/A053616/b053616.txt">Table of n, a(n) for n = 0..1000</a>
%H A053616 Gerold Brändli and Tim Beyne, <a href="https://arxiv.org/abs/1504.02757">Modified Congruence Modulo n with Half the Amount of Residues</a>, arXiv:1504.02757 [math.NT], 2015-2016.
%H A053616 <a href="/index/Di#distance_to_the_nearest">Index entries for sequences related to distance to nearest element of some set</a>
%F A053616 a(n) = (x - |y - |x-y||)/2, when (x,y) is the n-th element in the triangle x >= y >= 1. - _M. F. Hasler_, Dec 06 2019
%F A053616 a(n) = (1/2)*abs(t^2 + t - 2*n), where t = floor(sqrt(2*n)) = A172471. - _Ridouane Oudra_, Dec 15 2021
%F A053616 From _Ctibor O. Zizka_, Nov 12 2024: (Start)
%F A053616 For s >= 1, t from [0, s] :
%F A053616 a(2*s^2 + t) = s - t.
%F A053616 a(2*s^2 - t) = s - t.
%F A053616 a(2*s^2 + 2*s - t) = s - t.
%F A053616 a(2*s^2 + 2*s + 1 + t) = s - t. (End)
%e A053616 a(12) = |12 - 10| = 2 since 10 is the nearest triangular number to 12.
%e A053616 From _M. F. Hasler_, Dec 06 2019: (Start)
%e A053616 Ignoring a(0) = 0, the sequence can be written as triangle indexed by m >= k >= 1, in which case the terms are (m - |k - |m-k||)/2, as follows:
%e A053616    0,      (Row 0: ignore)
%e A053616    0,      (Row m=1, k=1: For k=m, m - |k - |m-k|| = m - |m - 0| = 0.)
%e A053616    1, 0,        (Row m=2: for k=1, |m-k| = 1, k-|m-k| = 0, m-0 = 2, (...)/2 = 1.)
%e A053616    1, 1, 0,
%e A053616    1, 2, 1, 0,    (Row m=4: for k=2, we have twice the value of (m=2, k=1) => 2.)
%e A053616    1, 2, 2, 1, 0,
%e A053616    (...)
%e A053616 This is related to the non-associative operation A049581(x,y) = |x - y| =: x @ y. Specifically, @ is commutative and any x is its own inverse, so non-associativity of @ can be measured through the commutator ((x @ y) @ y) @ x which equals twice the element indexed {m,k} = {x,y} in the above triangle.
%e A053616 (End)
%t A053616 a[n_] := (k =.; k = Reduce[k > 0 && k*(k+1)/2 == n, Reals][[2]] // Floor; Min[(k+1)*(k+2)/2 - n, n - k*(k+1)/2]); Table[a[n], {n, 0, 104}] (* _Jean-François Alcover_, Jan 08 2013 *)
%t A053616 Module[{trms=120,t},t=Accumulate[Range[Ceiling[(Sqrt[8*trms+1]-1)/2]]]; Join[{0},Flatten[Table[Abs[Nearest[t,n][[1]]-n],{n,trms}]]]] (* _Harvey P. Dale_, Nov 08 2013 *)
%o A053616 (PARI) print1(x=0, ", ");for(stride=1,13,x+=stride;y=x+stride+1;for(k=x,y-1,print1(min(k-x,y-k), ", "))) \\ _Hugo Pfoertner_, Jun 02 2018
%o A053616 (PARI) apply( {a(n)=if(n,-abs(n*2-(n=sqrtint(8*n-7)\/2)^2)+n)\2}, [0..40]) \\ same as (i - |j - |i-j||)/2 with i=sqrtint(8*n-7)\/2, j=n-i(i-1)/2. - _M. F. Hasler_, Dec 06 2019
%o A053616 (Python)
%o A053616 from math import isqrt
%o A053616 def A053616(n): return abs((m:=isqrt(k:=n<<1))*(m+1)-k)>>1 # _Chai Wah Wu_, Jul 15 2022
%Y A053616 Cf. A000217, A002262, A053188, A172471.
%Y A053616 a(n) = abs(A305258(n)).
%K A053616 easy,nice,nonn
%O A053616 0,9
%A A053616 _Henry Bottomley_, Mar 20 2000