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.
%I A319556 #124 Mar 14 2024 17:04:21 %S A319556 1,-1,4,-2,7,-3,10,-4,13,-5,16,-6,19,-7,22,-8,25,-9,28,-10,31,-11,34, %T A319556 -12,37,-13,40,-14,43,-15,46,-16,49,-17,52,-18,55,-19,58,-20,61,-21, %U A319556 64,-22,67,-23,70,-24,73,-25,76,-26,79,-27,82,-28,85,-29,88,-30 %N A319556 a(n) gives the alternating sum of length n, starting at n: n - (n+1) + (n+2) - ... + (-1)^(n+1) * (2n-1). %C A319556 As can be observed from _Bernard Schott_'s formula, and also proved using elementary methods of slope and angle determination, extending the graph of this sequence forms two lines (given by y = 1.5x - 0.5 and y = -0.5x) that intersect at (0.25, -0.125) in an angle of intersection of ~82.87 degrees. The angles of incidence of these lines off the horizontal axis are ~56.31 and ~-26.56 degrees. %C A319556 If one wished to include negative input values, one could proceed, e.g., -3+4-5 (=-8) or -3+2-1 (=-2). If the former, then the sequence merely switches signs for negative inputs, graphically extending the previous lines to the left of the vertical. If the latter, two new lines emerge left of the vertical, both of slope 1/2. Increasing the run in this case "spreads apart" all y-intercepts. %H A319556 Mark Povich, <a href="/A319556/b319556.txt">Table of n, a(n) for n = 1..10000</a> %H A319556 <a href="/index/Rec#order_04">Index entries for linear recurrences with constant coefficients</a>, signature (0,2,0,-1). %F A319556 From _Bernard Schott_, Aug 27 2019: (Start) %F A319556 a(2*n-1) = 3*n-2 for n >= 1, %F A319556 a(2*n) = - n for n >= 1. (End) %F A319556 a(n) = Sum_{k=n..2*n-1} (-1)^(n-k)*k. %F A319556 From _Colin Barker_, Sep 07 2019: (Start) %F A319556 G.f.: x*(1 - x + 2*x^2) / ((1 - x)^2*(1 + x)^2). %F A319556 a(n) = 2*a(n-2) - a(n-4) for n>4. %F A319556 a(n) = ((2*n-1)*(1 - (-1)^n) - 2*n*(-1)^n)/4. (End) %F A319556 E.g.f.: (1/4)*((1 + 4*x)*exp(-x) - (1 - 2*x)*exp(x)). - _Stefano Spezia_, Sep 07 2019 after _Colin Barker_ %F A319556 From _G. C. Greubel_, Mar 14 2024: (Start) %F A319556 a(n) = Sum_{k=0..n-1} (-1)^k*A094727(n, k). %F A319556 a(n) = Sum_{k=1..n} (-1)^(k-1)*A128622(n, k). (End) %e A319556 If n=5, a(n)=7, since 5-6+7-8+9 = 7. %e A319556 If n=6, a(n)=-3, since 6-7+8-9+10-11 = -3. %t A319556 LinearRecurrence[{0,2,0,-1}, {1,-1,4,-2}, 60] (* _Metin Sariyar_, Sep 15 2019 *) %o A319556 (Python) %o A319556 def alt(k): %o A319556 return sum(k[::2])-sum(k[1::2]) %o A319556 def alt_run(n): %o A319556 m = [] %o A319556 m.append(n) %o A319556 for i in range (1, n): %o A319556 m.append(m[0]+i) %o A319556 return alt(m) %o A319556 t=[] %o A319556 for i in range (100): %o A319556 t.append(alt_run(i)) %o A319556 print(t) %o A319556 (PARI) a(n) = sum(k=n, 2*n-1, (-1)^(n-k)*k); \\ _Michel Marcus_, Aug 27 2019 %o A319556 (PARI) Vec(x*(1 - x + 2*x^2) / ((1 - x)^2*(1 + x)^2) + O(x^60)) \\ _Colin Barker_, Sep 07 2019 %o A319556 (Magma) [((2*n-1)*(n mod 2) - n*(-1)^n)/2: n in [0..70]]; // _G. C. Greubel_, Mar 14 2024 %o A319556 (SageMath) [((2*n-1)*(n%2) - n*(-1)^n)/2 for n in range(1,71)] # _G. C. Greubel_, Mar 14 2024 %Y A319556 Cf. A094727, A123684, A128622. %K A319556 sign,easy %O A319556 1,3 %A A319556 _Mark Povich_, Aug 27 2019