OEIS

Die Online-Enzyklopädie der Zahlenfolgen®

Moderne Implementierung für Programmierer und Agenten
Beispiele: 1, 1, 2, 3, 5, 8 • A000045 • Fibonacci • author:Guglielmetti

A000217

Triangular numbers: a(n) = binomial(n+1,2) = n*(n+1)/2 = 0 + 1 + 2 + ... + n.

DATA

0, 1, 3, 6, 10, 15, 21, 28, 36, 45, 55, 66, 78, 91, 105, 120, 136, 153, 171, 190, 210, 231, 253, 276, 300, 325, 351, 378, 406, 435, 465, 496, 528, 561, 595, 630, 666, 703, 741, 780, 820, 861, 903, 946, 990, 1035, 1081, 1128, 1176, 1225, 1275, 1326, 1378, 1431

PYTHON IMPLEMENTATION

Executable sequence implementation based on goulib.sequence.Sequence:

Main definition:

A000217 = Sequence(None, math2.triangle, math2.is_triangle, 'triangle numbers')

⚙ Live-Evaluierungskonsole

Testen Sie die Funktionen itemf(n) und containf(x) direkt auf dieser Seite:

Bereit. Klicken Sie auf eine Schaltfläche oben.

Detail of provided methods:

Function Expression Description
iterf None Generator iterating over the infinite sequence
itemf(n) math2.triangle Direct computation of $n$-th term
containf(x) math2.is_triangle Boolean membership test ($x \in S$)

PROGRAMS

Maple

A000217 := proc(n) n*(n+1)/2; end;
# Alternative:
istriangular:=proc(n) local t1; t1:=floor(sqrt(2*n)); if n = t1*(t1+1)/2 then return true else return false; end if; end proc; # _N. J. A. Sloane_, May 25 2008
# Alternative:
ZL := [S, {S=Prod(B, B, B), B=Set(Z, 1 <= card)}, unlabeled]:
seq(combstruct[count](ZL, size=n), n=2..55); # _Zerinvary Lajos_, Mar 24 2007
# Alternative:
isA000217 := proc(n)
    issqr(1+8*n) ;
end proc: # _R. J. Mathar_, Nov 29 2015 [This is the recipe Leonhard Euler proposes in chapter VII of his "Vollständige Anleitung zur Algebra", 1765. _Peter Luschny_, Sep 02 2022]

Mathematica

Array[ #*(# - 1)/2 &, 54] (* _Zerinvary Lajos_, Jul 10 2009 *)
(* Alternative: *)
FoldList[#1 + #2 &, 0, Range@ 50] (* _Robert G. Wilson v_, Feb 02 2011 *)
(* Alternative: *)
Accumulate[Range[0,70]] (* _Harvey P. Dale_, Sep 09 2012 *)
(* Alternative: *)
CoefficientList[Series[x / (1 - x)^3, {x, 0, 50}], x] (* _Vincenzo Librandi_, Jul 30 2014 *)
(* Alternative: *)
(* For Mathematica 10.4+ *) Table[PolygonalNumber[n], {n, 0, 53}] (* _Arkadiusz Wesolowski_, Aug 27 2016 *)
(* Alternative: *)
LinearRecurrence[{3, -3, 1}, {0, 1, 3}, 54] (* _Robert G. Wilson v_, Dec 04 2016 *)
(* The following Mathematica program, courtesy of Steven J. Miller, is useful for testing if a sequence is Benford. To test a different sequence only one line needs to be changed. This strongly suggests that the triangular numbers are not Benford, since the second and third columns of the output disagree. - _N. J. A. Sloane_, Feb 12 2017 *)
(* Alternative: *)
fd[x_] := Floor[10^Mod[Log[10, x], 1]]
benfordtest[num_] := Module[{},
   For[d = 1, d <= 9, d++, digit[d] = 0];
   For[n = 1, n <= num, n++,
    {
     d = fd[n(n+1)/2];
     If[d != 0, digit[d] = digit[d] + 1];
     }];
   For[d = 1, d <= 9, d++, digit[d] = 1.0 digit[d]/num];
   For[d = 1, d <= 9, d++,
    Print[d, " ", 100.0 digit[d], " ", 100.0 Log[10, (d + 1)/d]]];
   ];
benfordtest[20000]
(* Alternative: *)
Table[Length[Join@@Permutations/@IntegerPartitions[n,{3}]],{n,0,15}] (* _Gus Wiseman_, Oct 28 2020 *)

Other Programs

A000217(n) = n * (n + 1) / 2;
is_A000217(n)=n*2==(1+n=sqrtint(2*n))*n \\ _M. F. Hasler_, May 24 2012
is(n)=ispolygonal(n,3) \\ _Charles R Greathouse IV_, Feb 28 2014
list(lim)=my(v=List(),n,t); while((t=n*n++/2)<=lim,listput(v,t)); Vec(v) \\ _Charles R Greathouse IV_, Jun 18 2021
a000217 n = a000217_list !! n
a000217_list = scanl1 (+) [0..] -- _Reinhard Zumkeller_, Sep 23 2011
[n*(n+1)/2: n in [0..60]]; // _Bruno Berselli_, Jul 11 2014
[n: n in [0..1500] | IsSquare(8*n+1)]; // _Juri-Stepan Gerasimov_, Apr 09 2016
[n*(n+1)/2 for n in (0..60)] # _Bruno Berselli_, Jul 11 2014
(1 to 53).scanLeft(0)(_ + _) // Horstmann (2012), p. 171
(define (A000217 n) (/ (* n (+ n 1)) 2)) ;; _Antti Karttunen_, Jul 08 2017
for n in range(0,60): print(n*(n+1)//2, end=', ') # _Stefano Spezia_, Dec 06 2018
# Intended to compute the initial segment of the sequence, not
# isolated terms. If in the iteration the line "x, y = x + y + 1, y + 1"
# is replaced by "x, y = x + y + k, y + k" then the figurate numbers are obtained,
# for k = 0 (natural A001477), k = 1 (triangular), k = 2 (squares), k = 3 (pentagonal), k = 4 (hexagonal), k = 5 (heptagonal), k = 6 (octagonal), etc.
def agen():
    x, y = 1, 1
    yield 0
    while True:
        yield x
        x, y = x + y + 1, y + 1
A000217 = agen()
print([next(A000217) for i in range(54)]) # _Peter Luschny_, Aug 03 2019

COMMENTS


EXAMPLES

FORMULA

REFERENCES

CROSSREFERENCES

EXTENSIONS AND ERRORS

METADATA