%I #69 Aug 30 2024 06:27:09
%S 0,1,2,3,4,0,4,3,2,1,0,1,2,3,4,0,4,3,2,1,0,1,2,3,4,0,4,3,2,1,0,1,2,3,
%T 4,0,4,3,2,1,0,1,2,3,4,0,4,3,2,1,0,1,2,3,4,0,4,3,2,1,0,1,2,3,4,0,4,3,
%U 2,1,0,1,2,3,4,0,4,3,2,1,0,1,2,3,4,0,4,3,2,1,0,1,2,3,4,0,4,3,2,1,0
%N Period length 10: [0, 1, 2, 3, 4, 0, 4, 3, 2, 1] repeated.
%C This sequence can be continued periodically for negative values of n.
%C This is the fifth sequence of a k-family of sequences P_k, k>=1, which starts with A000007(n+1), n >= 0 (the 0-sequence), A000035, A193680, A193682, for k = 1, ..., 4, respectively.
%C In general, the sequence P_k, k >= 1 (periodically continued for negative values of n), is used to define the k equivalence classes [0], [1], ..., [k-1], with [j] := {n integer| P_k(n) = j}. Two integers are equivalent if and only if they are mapped by P_k to the same value. For P_5, P_6 and P_7 see the arrays (not the triangles) A090298, A092260 and A113807, respectively. In each of these cases the class [k] should be replaced by the class [0], and also negative n-values are allowed. Multiplication can be done class-wise. E.g., k = 5: P_5(n) = a(n), 7*12 == 3*2 = 6 == 4; a(7*12) = a(a(7)*a(12)) = a(3*2) = 4. This kind of multiplication could be called multiplication Modd n, in order to distinguish it from multiplication mod n. Addition cannot be done class-wise. E.g., k = 5: 7 + 12 = 19 == 1 is not equivalent to 3 + 2 = 5 == 0; a(7+12) = 1 is not equal to a(a(7) + a(12)) = a(3+2) = 0.
%C Periodic sequences of this type can be also calculated by a(n) = c + floor(q/(p^m-1)*p^n) mod p, where c is a constant, q is the number representing the periodic digit pattern and m is the period length. c, p and q can be calculated as follows: Let D be the array representing the number pattern to be repeated, m = size of D, max = maximum value of elements in D, min = minimum value of elements in D. Then c := min, p := max - min + 1 and q := p^m * Sum_{i=0..(m-1)} (D(i) - min)/p^i. Example: D = (0, 1, 2, 3, 4, 0, 4, 3, 2, 1), c = 0, m = 10, p = 5 and q = 3034180 for this sequence. - _Hieronymus Fischer_, Jan 04 2013 [Corrected by _Rémi Guillaume_, Aug 28 2024]
%C For periodic sequences with terms < 10 one can use the well-known fact that ab..z/99..9 = 0.ab..zab..zab..z... (infinite periodic decimal fraction), this leads to one of the given formulas. For the general case it is sufficient to shift the terms to nonnegative values and to switch to a sufficiently large basis instead of 10 (there are infinitely many choices). - _M. F. Hasler_, Jan 13 2013
%H <a href="/index/Rec#order_10">Index entries for linear recurrences with constant coefficients</a>, signature (0,0,0,0,0,0,0,0,0,1).
%F a(n) = n mod 5 if (-1)^floor(n/5) = +1 else -n mod 5, n >= 0. (-1)^floor(n/5) is the sign corresponding to the parity of the quotient floor(n/5). This quotient is sometimes denoted by n\5.
%F O.g.f.: x*(1+2*x+3*x^2+4*x^3+4*x^5+3*x^6+2*x^7+x^8)/(1-x^10) = -x*(1 +2*x +3*x^2 +4*x^3 +4*x^5 +3*x^6 +2*x^7 +x^8) / ( (x-1) *(1+x) *(x^4+x^3+x^2+x+1) *(x^4-x^3+x^2-x+1) ).
%F a(n) = (2/5)*cos(Pi*n) - cos(4*Pi*n/5) - (1/5)*cos(3*Pi*n/5) + (2/5)*5^(1/2)*cos(3*Pi*n/5) - cos(2*Pi*n/5) - (1/5)*cos(Pi*n/5) - (2/5)*5^(1/2)*cos(Pi*n/5) + 2. - _Leonid Bedratyuk_, May 13 2012
%F a(n) = floor(123404321/9999999999*10^(n+1)) mod 10. - _Hieronymus Fischer_, Jan 04 2013
%F a(n) = floor(151709/2441406*5^(n+1)) mod 5. - _Hieronymus Fischer_, Jan 04 2013
%F a(n) = ((-abs(n-(10*ceiling(n/10)-5)+(10*ceiling(n/10)-5))(ceiling((n+5)/10)-floor((n+5)/10)) mod 10. - _Wesley Ivan Hurt_, Mar 26 2014
%F a(n+10) = a(n) for n in Z; a(-n) = a(n) for n in Z. - _Rémi Guillaume_, Aug 28 2024
%e a(12) = 12 mod 5 = 2 since 12\5 = floor(12/5) = 2 is even; the sign is +1.
%e a(7) = -7 mod 5 = 3 since 7\5 = floor(7/5) = 1 is odd; the sign is -1.
%t A203571[n_] := {0, 1, 2, 3, 4, 0, 4, 3, 2, 1}[[Mod[n, 10] + 1]]; Table[A203571[n], {n, 0, 59}] (* _Jean-François Alcover_, Jul 05 2013 *)
%t PadRight[{},120,{0,1,2,3,4,0,4,3,2,1}] (* _Harvey P. Dale_, May 21 2021 *)
%o (PARI) A203571(n)=[0,1,2,3,4,0,4,3,2,1][n%10+1] \\ _M. F. Hasler_, Jan 13 2013
%o (PARI) A203571(n)=151709*5^(n%10+1)\2441406%5 \\ _M. F. Hasler_, Jan 13 2013
%Y Cf. A000007, A000035, A090298, A092260, A113807, A193680, A193682.
%K nonn,easy
%O 0,3
%A _Wolfdieter Lang_, Jan 11 2012