public void StirlingNumbers2RowSum()
 {
     foreach (int n in TestUtilities.GenerateIntegerValues(1, 100, 4))
     {
         double sum = 0.0;
         foreach (double s in AdvancedIntegerMath.StirlingNumbers2(n))
         {
             sum += s;
         }
         Assert.IsTrue(TestUtilities.IsNearlyEqual(sum, AdvancedIntegerMath.BellNumber(n)));
     }
 }
        public void BellNumberAsPoissonMoment()
        {
            // The Bell numbers are the moments of the Poisson distribution
            // with \mu = 1.

            UnivariateDistribution d = new PoissonDistribution(1.0);

            foreach (int r in TestUtilities.GenerateIntegerValues(1, 50, 4))
            {
                Assert.IsTrue(TestUtilities.IsNearlyEqual(
                                  AdvancedIntegerMath.BellNumber(r),
                                  d.RawMoment(r)
                                  ));
            }
        }
        public void BellNumberRecurrence()
        {
            // B_{n+1} = \sum_{k=0}^{n} {n \choose k} B_k

            foreach (int r in TestUtilities.GenerateIntegerValues(50, 100, 2))
            {
                double s = 0.0;
                IEnumerator <double> b = AdvancedIntegerMath.BinomialCoefficients(r).GetEnumerator();
                for (int k = 0; k <= r; k++)
                {
                    b.MoveNext();
                    s += b.Current * AdvancedIntegerMath.BellNumber(k);
                }
                Assert.IsTrue(TestUtilities.IsNearlyEqual(s, AdvancedIntegerMath.BellNumber(r + 1)));
            }
        }