Calculates Euler numbers by means of recurrent relation

You're viewing an older version of this page (#83). View the current version.

View versions (1)

Interface

#include <codecogs/maths/discrete/number_theory/euler.h>

using namespace Maths::Discrete::Number_Theory;

Overview

Euler numbers, which are also called secant numbers or 'zig' numbers are defined for |z| <\pi/2 by

sech(x) - 1 \equiv -\frac{E_1^* z^2}{2!} +\frac{E_2^* z^4}{4!} -\frac{E_3^* z^6}{6!}
(1)

The Euler number give the number of odd alternating permutations and are related to Genocchi numbers.

A slightly different convention, which is also used here, defines

E_{2n} = (-1)^n E_n^*
(2)
E_{2n+1} = 0
(3)

Thus, the Euler numbers E_n and polynomials E_n(x) are defined through equations

sech(x) = \frac{2{E^z}}{{E^{2z}}+1} = \sum _{n=0}^{\infty}{E_n}\frac{{z^n}}{n!}, |z|< \frac{\pi }{2}
(4)
\frac{2 E^{xz} }{{E^z}+1} = \sum_{n=0}^{\infty }{E_n}(x)\frac{{z^n}}{n!}, |z| \pi
(5)

The relation between Euler polynomials and numbers:

{E_n} = {2^n}{E_n}\big(\frac{1}{2}\big)
(6)

References

  • Higher Transcendental Functions, vol.1, (1.14) by H.Bateman and A.Erdelyi (Bateman Manuscript Project), 1953
  • M.Abramowitz and I.A.Stegun, Handbook of Mathematical Functions, 1964 chapt.23
GPL Licence — free for non commercial use. See Licence details.

FUNCTION

EulerA

Calculates Euler numbers using the recurrent relation

{E_{2n}} = -\sum_{r=0}^{n-1}\big(\begin{array}{c} 2n \\ 2r \end{array}\big){E_{2r}}, {e_0}=1
(7)
{E_{2n+1}}=0, n=0,1,2,...
(8)

Example 1

#include <stdio.h>
#include <codecogs/maths/discrete/number_theory/euler.h>

#define MAX_INDEX 16
int main()
{
  double dEulerA[MAX_INDEX+1];
  double dEulerB[MAX_INDEX+1];

  // Table headings
  printf( "%10s %20s %20s\n", "2n", "E_A(2n) (recurrent)", "E_B(2n) (series)" );
  printf( "%8s", " " );
  for( int i = 0; i < 52; i++ )
    printf( "%c", '-' );
  printf( "\n" );

  // array calculation
  Maths::NumberTheory::EulerA( MAX_INDEX, dEulerA );
  Maths::NumberTheory::EulerB( MAX_INDEX, dEulerB );

  // results output
  for( int i = 0; i <= MAX_INDEX; i+=2 )
    printf( "%10d %20.6f %20.6f\n", i, dEulerA[i], dEulerB[i]);
  return 0;
}

Output:

2n  E_A(2n) (recurrent)     E_B(2n) (series)
----------------------------------------------------
   0             1.000000             1.000000
   2            -1.000000            -1.000000
   4             5.000000             5.000000
   6           -61.000000           -61.000000
   8          1385.000000          1385.000000
  10        -50521.000000        -50521.000000
  12       2702765.000000       2702765.000000
  14    -199360981.000000    -199360981.000000
  16   19391512145.000000   19391512145.000027

Parameters

iMax
input maximal index requested. Must be a power of 2.
daEuler
array into which to place the result, with iMax parameters.

Returns

pointer on the resulting array of type double
Author

Anatoly Prognimack (Mar 19, 2005)

Author

Developed & tested with: Borland C++ 3.1 for DOS Microsoft Visual C++ 5.0, 6.0

Author

Updated by Will Bateman (March 2005)

FUNCTION

EulerB

Calculates Euler numbers using the recurrent series expansion

\begin{array}{l} {E_{2n}}={{(-1)}^n}2(2n)!{{\big(\frac{2}{\pi }\big)}^{2n+1}}\sum
  _{r=0}^{\infty }\frac{{{(-1)}^r}}{{{(2r+1)}^{2n+1}}},  \\ n=0,1,2,...\\ \end{array}
(9)

Parameters

iMax
input maximal index requested. Must be a power of 2.
daEuler
array into which to place the result, with iMax parameters.

Returns

pointer on the resulting array of type double
Author

Anatoly Prognimack (Mar 19, 2005)

Author

Developed & tested with: Borland C++ 3.1 for DOS Microsoft Visual C++ 5.0, 6.0

Author

Will Bateman (March 2005)