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.

A319556 a(n) gives the alternating sum of length n, starting at n: n - (n+1) + (n+2) - ... + (-1)^(n+1) * (2n-1).

Original entry on oeis.org

1, -1, 4, -2, 7, -3, 10, -4, 13, -5, 16, -6, 19, -7, 22, -8, 25, -9, 28, -10, 31, -11, 34, -12, 37, -13, 40, -14, 43, -15, 46, -16, 49, -17, 52, -18, 55, -19, 58, -20, 61, -21, 64, -22, 67, -23, 70, -24, 73, -25, 76, -26, 79, -27, 82, -28, 85, -29, 88, -30
Offset: 1

Views

Author

Mark Povich, Aug 27 2019

Keywords

Comments

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.
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.

Examples

			If n=5, a(n)=7, since 5-6+7-8+9 = 7.
If n=6, a(n)=-3, since 6-7+8-9+10-11 = -3.
		

Crossrefs

Programs

  • Magma
    [((2*n-1)*(n mod 2) - n*(-1)^n)/2: n in [0..70]]; // G. C. Greubel, Mar 14 2024
    
  • Mathematica
    LinearRecurrence[{0,2,0,-1}, {1,-1,4,-2}, 60] (* Metin Sariyar, Sep 15 2019 *)
  • PARI
    a(n) = sum(k=n, 2*n-1, (-1)^(n-k)*k); \\ Michel Marcus, Aug 27 2019
    
  • PARI
    Vec(x*(1 - x + 2*x^2) / ((1 - x)^2*(1 + x)^2) + O(x^60)) \\ Colin Barker, Sep 07 2019
    
  • Python
    def alt(k):
        return sum(k[::2])-sum(k[1::2])
    def alt_run(n):
        m = []
        m.append(n)
        for i in range (1, n):
            m.append(m[0]+i)
        return alt(m)
    t=[]
    for i in range (100):
        t.append(alt_run(i))
    print(t)
    
  • SageMath
    [((2*n-1)*(n%2) - n*(-1)^n)/2 for n in range(1,71)] # G. C. Greubel, Mar 14 2024

Formula

From Bernard Schott, Aug 27 2019: (Start)
a(2*n-1) = 3*n-2 for n >= 1,
a(2*n) = - n for n >= 1. (End)
a(n) = Sum_{k=n..2*n-1} (-1)^(n-k)*k.
From Colin Barker, Sep 07 2019: (Start)
G.f.: x*(1 - x + 2*x^2) / ((1 - x)^2*(1 + x)^2).
a(n) = 2*a(n-2) - a(n-4) for n>4.
a(n) = ((2*n-1)*(1 - (-1)^n) - 2*n*(-1)^n)/4. (End)
E.g.f.: (1/4)*((1 + 4*x)*exp(-x) - (1 - 2*x)*exp(x)). - Stefano Spezia, Sep 07 2019 after Colin Barker
From G. C. Greubel, Mar 14 2024: (Start)
a(n) = Sum_{k=0..n-1} (-1)^k*A094727(n, k).
a(n) = Sum_{k=1..n} (-1)^(k-1)*A128622(n, k). (End)