ARB
triangular.h
Go to the documentation of this file.
1 // ========================================================= //
2 // //
3 // File : triangular.h //
4 // Purpose : provide sums of small powers //
5 // //
6 // Coded by Ralf Westram (coder@reallysoft.de) in Nov 21 //
7 // http://www.arb-home.de/ //
8 // //
9 // ========================================================= //
10 
11 #ifndef TRIANGULAR_H
12 #define TRIANGULAR_H
13 
14 #ifndef CXXFORWARD_H
15 #include "cxxforward.h"
16 #endif
17 
19  // in german aka "Gausssche Summenformel"
20  // SUM(k=[1..N]; k)
21  return N*(N+1)/2;
22 }
23 
25  // in german aka "Quadratische Pyramidalzahl"
26  // SUM(k=[1..N]; k^2)
27  return N*(N+1)*(2*N+1)/6;
28 }
29 
31  // SUM(N=[1..L]; SUM(k=[1..N]; k))
32  return (squarepyramidal_number(L) + triangular_number(L)) / 2;
33 }
34 
35 #else
36 #error triangular.h included twice
37 #endif // TRIANGULAR_H
CONSTEXPR_INLINE long sum_of_triangular_numbers(const long L)
Definition: triangular.h:30
Definition: trnsprob.h:20
CONSTEXPR_INLINE long triangular_number(const long N)
Definition: triangular.h:18
#define CONSTEXPR_INLINE
Definition: cxxforward.h:111
CONSTEXPR_INLINE long squarepyramidal_number(const long N)
Definition: triangular.h:24