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.

User: Mark Povich

Mark Povich's wiki page.

Mark Povich has authored 2 sequences.

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

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)

A309983 Numbers n resulting from adding the exponents of 2 associated with the "1" terms of their binary representation and subtracting the exponents of 2 associated with the "0" terms of their binary representation.

Original entry on oeis.org

0, 1, 1, 1, 1, 3, 3, 0, 0, 2, 2, 4, 4, 6, 6, -2, -2, 0, 0, 2, 2, 4, 4, 4, 4, 6, 6, 8, 8, 10, 10, -5, -5, -3, -3, -1, -1, 1, 1, 1, 1, 3, 3, 5, 5, 7, 7, 3, 3, 5, 5, 7, 7, 9, 9, 9, 9, 11, 11, 13, 13, 15, 15, -9, -9, -7, -7, -5, -5, -3, -3, -3, -3, -1
Offset: 1

Author

Mark Povich, Aug 26 2019

Keywords

Examples

			When n=18, a(n) = 0. Convert 18 to binary (=10010). The 1s are in the 2^4 place and the 2^1 place. Take those exponents and add them (=5). The 0's are in the 2^3, 2^2, and 2^0 places. Subtract those exponents (=5) from the previous sum to get 0.
When n=26, a(n) = 6. Convert 26 to binary (=11010). The 1s are in the 2^4, 2^3, and 2^1 places. Take those exponents and add them (=8). The 0's are in the 2^2 and 2^0 places. Subtract those exponents (=2) from the previous sum to get 6.
		

Crossrefs

Cf. A073642 (when only 1 digits are considered).

Programs

  • Mathematica
    a[n_] := Block[{d = Reverse@IntegerDigits[n, 2]}, Total@ Flatten@ {Position[d, 1]-1, 1-Position[d, 0]}]; Array[a, 74] (* Giovanni Resta, Aug 26 2019 *)
  • PARI
    a(n) = {my(b=Vecrev(binary(n))); my(v1 = Vec(select(x->(x==1), b, 1))); my(v0 = Vec(select(x->(x==0), b, 1))); (vecsum(v1) - #v1) - (vecsum(v0) - #v0);} \\ Michel Marcus, Aug 26 2019
    
  • Python
    def dec_to_bin(dec_num): #define a function that converts decimal to binary.
        bin_num = 0
        power = 0
        while dec_num > 0:
            bin_num += 10 ** power * (dec_num % 2)
            dec_num //= 2
            power += 1
        return bin_num
    def rev_bin(n):
        return list(reversed(str(dec_to_bin(n))))
    n = 18
    neg = [pos for pos, num in enumerate(rev_bin(n)) if num == "0"]
    posi = [pos for pos, num in enumerate(rev_bin(n)) if num == "1"]
    print(sum(posi)-sum(neg))
    
  • Python
    def A309983(n):
        r, i = 0, 0
        while n > 0:
            d, n = n%2, n//2
            if d == 1:
                r = r+i
            else:
                r = r-i
            i = i+1
        return r # A.H.M. Smeets, Oct 07 2019