Boost C++ Libraries Home Libraries People FAQ More

PrevUpHomeNext

Tangent Numbers

Tangent numbers, also called a zag function. See also Tangent number.

The first few values are 1, 2, 16, 272, 7936, 353792, 22368256, 1903757312 ... (sequence A000182 in OEIS). They are called tangent numbers because they appear as numerators in the Maclaurin series of tan(x).

Important: there are two competing definitions of Tangent numbers in common use (depending on whether you take the even or odd numbered values as non-zero), we use:

Which gives:

Tangent numbers are used in the computation of Bernoulli numbers, but are also made available here.

Synopsis
#include <boost/math/special_functions/detail/bernoulli.hpp>
template <class T>
T tangent_t2n(const int i);  // Single tangent number (default policy).

template <class T, class Policy>
T tangent_t2n(const int i, const Policy &pol); // Single tangent number (user policy).

// Multiple tangent numbers (default policy).
template <class T, class OutputIterator>
OutputIterator tangent_t2n(const int start_index,
                                    const unsigned number_of_tangent_t2n,
                                    OutputIterator out_it);

// Multiple tangent numbers (user policy).
template <class T, class OutputIterator, class Policy>
OutputIterator tangent_t2n(const int start_index,
                                    const unsigned number_of_tangent_t2n,
                                    OutputIterator out_it,
                                    const Policy& pol);
Examples

We can compute and save a few Tangent numbers.

std::vector<float> tn; // Space for some `float` precision Tangent numbers.

// Start with Bernoulli number 0.
boost::math::tangent_t2n<float>(1, 6, std::back_inserter(tn)); // Fill vector with even Tangent numbers.

for(size_t i = 0; i < tn.size(); i++)
{ // Show vector of even Tangent numbers, showing all significant decimal digits.
    std::cout << std::setprecision(std::numeric_limits<float>::digits10)
        << " "
        << tn[i];
}
std::cout << std::endl;

The output is:

1 2 16 272 7936 353792

The source of this example is at bernoulli_example.cpp

Implementation

Tangent numbers are calculated as intermediates in the calculation of the Bernoulli numbers: refer to the Bernoulli numbers documentation for details.


PrevUpHomeNext