Exemple #1
0
        static Frac[] FaulhaberTriangle(int p)
        {
            Frac[] coeffs = new Frac[p + 1];
            for (int i = 0; i < p + 1; i++)
            {
                coeffs[i] = Frac.ZERO;
            }
            Frac q    = new Frac(1, p + 1);
            int  sign = -1;

            for (int j = 0; j <= p; j++)
            {
                sign         *= -1;
                coeffs[p - j] = q * new Frac(sign, 1) * new Frac(Binomial(p + 1, j), 1) * Bernoulli(j);
            }
            return(coeffs);
        }
Exemple #2
0
 static Frac Bernoulli(int n)
 {
     if (n < 0)
     {
         throw new ArgumentException("n may not be negative or zero");
     }
     Frac[] a = new Frac[n + 1];
     for (int m = 0; m <= n; m++)
     {
         a[m] = new Frac(1, m + 1);
         for (int j = m; j >= 1; j--)
         {
             a[j - 1] = (a[j - 1] - a[j]) * new Frac(j, 1);
         }
     }
     // returns 'first' Bernoulli number
     if (n != 1)
     {
         return(a[0]);
     }
     return(-a[0]);
 }