TangentNumbers.frink

View or download TangentNumbers.frink in plain text format


// Calculation of Tangent Numbers, which can be used to also calculate
// Bernoulli numbers.
//
//  These can be used to derive the tangent of a number by:
//
//  tan[z] = sum[n>0, Tn * z^(2n-1)/(2n-1)!]
//
// See:
//  http://arxiv.org/abs/1108.0286
//  http://mathworld.wolfram.com/TangentNumber.html
//  http://oeis.org/A000182

// This implements the algorithm in figure 2 of the Brent paper.
//
//  The main problem for using this to calculate tangents to arbitrary
// precision is that this algorithm alters numbers in-place in several passes,
// and doesn't allow easy calculation of more tangent numbers if you decide
// you need more. 
tangentNumbers[n] :=
{
   t = new array
   t@1 = 1

   for k = 2 to n
      t@k = (k-1) t@(k-1)

   for k = 2 to n
      for j = k to n
          t@j = (j-k) t@(j-1) + (j-k+2) t@j

   return t 
}


View or download TangentNumbers.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 17983 days, 23 hours, 14 minutes ago.