Exemplo n.º 1
0
        public void StirlingNumber1SpecialCases()
        {
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(0, 0) == 1);
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(1, 0) == 0);
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(1, 1) == 1);
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(2, 0) == 0);
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(2, 1) == 1);
            Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(2, 2) == 1);

            foreach (int m in TestUtilities.GenerateIntegerValues(2, 100, 4))
            {
                Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(m, 0) == 0);
                Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(m, 1) == AdvancedIntegerMath.Factorial(m - 1));
                Assert.IsTrue(TestUtilities.IsNearlyEqual(
                                  AdvancedIntegerMath.StirlingNumber1(m, 2),
                                  AdvancedIntegerMath.Factorial(m - 1) * AdvancedIntegerMath.HarmonicNumber(m - 1)
                                  ));

                Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(m, m) == 1);
                Assert.IsTrue(AdvancedIntegerMath.StirlingNumber1(m, m - 1) == AdvancedIntegerMath.BinomialCoefficient(m, 2));
                Assert.IsTrue(TestUtilities.IsNearlyEqual(
                                  AdvancedIntegerMath.StirlingNumber1(m, m - 2),
                                  (3 * m - 1) * AdvancedIntegerMath.BinomialCoefficient(m, 3) / 4
                                  ));
            }
        }
Exemplo n.º 2
0
        public void StirlingNumberInequality()
        {
            // Rows are log-concave

            foreach (int n in TestUtilities.GenerateIntegerValues(10, 100, 4))
            {
                foreach (int k in TestUtilities.GenerateRealValues(2, n - 1, 4))
                {
                    Assert.IsTrue(
                        MoreMath.Sqr(AdvancedIntegerMath.StirlingNumber1(n, k)) >=
                        AdvancedIntegerMath.StirlingNumber1(n, k - 1) *
                        AdvancedIntegerMath.StirlingNumber1(n, k + 1)
                        );

                    Assert.IsTrue(
                        MoreMath.Sqr(AdvancedIntegerMath.StirlingNumber2(n, k)) >=
                        AdvancedIntegerMath.StirlingNumber2(n, k - 1) *
                        AdvancedIntegerMath.StirlingNumber2(n, k + 1)
                        );
                }
            }
        }