public void ComplexLogGammaRealLogGammaAgreement()
 {
     foreach (double x in TestUtilities.GenerateRealValues(1.0E-4, 1.0E4, 24))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.LogGamma(x), AdvancedMath.LogGamma(x)));
     }
 }
 public void ComplexDiLogConjugation () {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-1, 1.0E1, 8)) {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
             AdvancedComplexMath.DiLog(z.Conjugate), AdvancedComplexMath.DiLog(z).Conjugate
         ));
     }
 }
 public void ComplexReimannZetaPrimesTest()
 {
     // pick high enough values so that p^-x == 1 within double precision before we reach the end of our list of primes
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0, 100.0, 8))
     {
         Complex zz = z;
         if (zz.Re < 0.0)
         {
             zz = -zz;
         }
         zz += 10.0;
         Console.WriteLine(zz);
         Complex f = 1.0;
         for (int p = 2; p < 100; p++)
         {
             if (!AdvancedIntegerMath.IsPrime(p))
             {
                 continue;
             }
             Complex t = Complex.One - ComplexMath.Pow(p, -zz);
             if (t == Complex.One)
             {
                 break;
             }
             f = f * t;
         }
         Assert.IsTrue(TestUtilities.IsNearlyEqual(1.0 / AdvancedComplexMath.RiemannZeta(zz), f));
     }
 }
 public void ComplexGammaConjugation () {
     // limited to 10^-2 to 10^2 to avoid overflow
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 10)) {
         Console.WriteLine("z={0} G(z*)={1} G*(z)={2}", z, AdvancedComplexMath.Gamma(z.Conjugate), AdvancedComplexMath.Gamma(z).Conjugate);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Gamma(z.Conjugate), AdvancedComplexMath.Gamma(z).Conjugate));
     }
 }
 public void ComplexGammaDuplicationTest()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 16))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Gamma(2.0 * z), ComplexMath.Pow(2.0, 2.0 * z - 0.5) * AdvancedComplexMath.Gamma(z) * AdvancedComplexMath.Gamma(z + 0.5) / Math.Sqrt(2.0 * Math.PI)));
     }
 }
 public void ComplexGammaInequality()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 10))
     {
         Console.WriteLine(z);
         Assert.IsTrue(ComplexMath.Abs(AdvancedComplexMath.Gamma(z)) <= Math.Abs(AdvancedMath.Gamma(z.Re)));
     }
 }
 public void ComplexRealRiemannZetaAgreement()
 {
     foreach (double x in TestUtilities.GenerateRealValues(1.0E-2, 1.0E2, 8))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.RiemannZeta(x), AdvancedMath.RiemannZeta(x)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.RiemannZeta(-x), AdvancedMath.RiemannZeta(-x)));
     }
 }
 public void ComplexDiLogAgreement () {
     // use negative arguments b/c positive real DiLog function complex for x > 1
     foreach (double x in TestUtilities.GenerateRealValues(1.0E-2, 1.0E2, 10)) {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
             AdvancedMath.DiLog(-x), AdvancedComplexMath.DiLog(-x)
         ));
     }
 }
 public void ComplexGammaConjugation()
 {
     // limited to 10^-2 to 10^2 to avoid overflow
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 8))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Gamma(z.Conjugate), AdvancedComplexMath.Gamma(z).Conjugate));
     }
 }
 public void ComplexPsiConjugation () {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E3, 12)) {
         Console.WriteLine(z);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
             AdvancedComplexMath.Psi(z.Conjugate),
             AdvancedComplexMath.Psi(z).Conjugate
         ));
     }
 }
 public void ComplexFaddeevaDawson () {
     foreach (double x in TestUtilities.GenerateRealValues(1.0E-4,1.0E4,10)) {
         Complex w = AdvancedComplexMath.Faddeeva(x);
         double F = AdvancedMath.Dawson(x);
         Console.WriteLine("x={0} F={1} w={2}", x, F, w);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(w.Re, Math.Exp(-x * x)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(w.Im, (2.0/Math.Sqrt(Math.PI)) * AdvancedMath.Dawson(x)));
     }
 }
 public void ComplexErfFresnel () {
     // don't let x get too big or we run into problem of accruacy for arguments of large trig-like functions
     foreach (double x in TestUtilities.GenerateRealValues(1.0E-1, 1.0E2, 16)) {
         Complex z = Math.Sqrt(Math.PI) * (1.0 - ComplexMath.I) * x / 2.0;
         Complex w = (1.0 + ComplexMath.I) * AdvancedComplexMath.Erf(z) / 2.0;
         Assert.IsTrue(TestUtilities.IsNearlyEqual(w.Re, AdvancedMath.FresnelC(x)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(w.Im, AdvancedMath.FresnelS(x)));
     }
 }
 public void ComplexPsiDuplication () {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E3, 12)) {
         Console.WriteLine(z);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
             AdvancedComplexMath.Psi(2.0 * z),
             AdvancedComplexMath.Psi(z) / 2.0 + AdvancedComplexMath.Psi(z + 0.5) / 2.0 + Math.Log(2.0)
         ));
     }
 }
 public void ComplexGammaKnownLines () {
     // to avoid problems with trig functions of large arguments, don't let x get too big
     foreach (double x in TestUtilities.GenerateRealValues(1.0E-4, 1.0E2, 16)) {
         Console.WriteLine(x);
         double px = Math.PI * x;
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Gamma(new Complex(0.0, x)) * AdvancedComplexMath.Gamma(new Complex(0.0, -x)), Math.PI / x / Math.Sinh(px)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Gamma(new Complex(0.5, x)) * AdvancedComplexMath.Gamma(new Complex(0.5, -x)), Math.PI / Math.Cosh(px)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Gamma(new Complex(1.0, x)) * AdvancedComplexMath.Gamma(new Complex(1.0, -x)), px / Math.Sinh(px)));
     }
 }
 public void ComplexEinE1Agreement()
 {
     foreach (double x in TestUtilities.GenerateRealValues(1.0E-3, 1.0E3, 8))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
                           AdvancedComplexMath.Ein(x),
                           AdvancedMath.IntegralE(1, x) + AdvancedMath.EulerGamma + Math.Log(x)
                           ));
     }
 }
 public void ComplexGammaRecurrance () {
     // fails when extended to more numbers due to a loss of last 4 digits of accuracy in an extreme case; look into it
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 10)) {
         Complex G = AdvancedComplexMath.Gamma(z);
         Complex Gz = G * z;
         Complex GP = AdvancedComplexMath.Gamma(z + 1.0);
         Console.WriteLine("z={0:g16} G(z)={1:g16} G(z)*z={2:g16} G(z+1)={3:g16}", z, G, Gz, GP);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(Gz,GP));
     }
 }
 public void ComplexGammaRecurrance()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 16))
     {
         Complex G  = AdvancedComplexMath.Gamma(z);
         Complex Gz = G * z;
         Complex GP = AdvancedComplexMath.Gamma(z + 1.0);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(Gz, GP));
     }
 }
 public void ComplexLogGammaComplexGammaAgreement()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 16))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
                           ComplexMath.Exp(AdvancedComplexMath.LogGamma(z)),
                           AdvancedComplexMath.Gamma(z)
                           ));
     }
 }
 public void ComplexLogGammaConjugation () {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 24)) {
         if (z.Re <= 0.0) continue;
         Console.WriteLine("z={0} lnG(z*)={1} lnG*(z)={2}", z, AdvancedComplexMath.LogGamma(z.Conjugate), AdvancedComplexMath.LogGamma(z).Conjugate);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
             AdvancedComplexMath.LogGamma(z.Conjugate),
             AdvancedComplexMath.LogGamma(z).Conjugate
         ));
     }
 }
 public void ComplexLogGammaConjugation()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 24))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
                           AdvancedComplexMath.LogGamma(z.Conjugate),
                           AdvancedComplexMath.LogGamma(z).Conjugate
                           ));
     }
 }
        public void ComplexDiLogClausen()
        {
            foreach (double t in TestUtilities.GenerateUniformRealValues(0.0, 2.0 * Math.PI, 4))
            {
                Complex z = AdvancedComplexMath.DiLog(ComplexMath.Exp(ComplexMath.I * t));

                Assert.IsTrue(TestUtilities.IsNearlyEqual(z.Re, Math.PI * Math.PI / 6.0 - t * (2.0 * Math.PI - t) / 4.0));
                Assert.IsTrue(TestUtilities.IsNearlyEqual(z.Im, AdvancedMath.Clausen(t)));
            }
        }
 public void ComplexGammaInequalities()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 16))
     {
         Assert.IsTrue(ComplexMath.Abs(AdvancedComplexMath.Gamma(z)) <= Math.Abs(AdvancedMath.Gamma(z.Re)));
         if (z.Re >= 0.5)
         {
             Assert.IsTrue(ComplexMath.Abs(AdvancedComplexMath.Gamma(z)) >= Math.Abs(AdvancedMath.Gamma(z.Re)) / Math.Sqrt(Math.Cosh(Math.PI * z.Im)));
         }
     }
 }
 public void ComplexLogGammaRecurrance()
 {
     // Don't try for z << 1, because z + 1 won't retain enough digits to satisfy
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E4, 24))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
                           AdvancedComplexMath.LogGamma(z + 1.0),
                           AdvancedComplexMath.LogGamma(z) + ComplexMath.Log(z)
                           ));
     }
 }
 public void ComplexFaddeevaConjugation()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 50))
     {
         if (z.Im * z.Im > Math.Log(Double.MaxValue / 10.0))
         {
             continue;                                                 // large imaginary values blow up
         }
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Faddeeva(z.Conjugate), AdvancedComplexMath.Faddeeva(-z).Conjugate));
     }
 }
 public void ComplexGammaRecurrance()
 {
     // G * z can loose digits from the cancelation of the two terms that contribute to its real and imaginary parts.
     // This appears to be what happens when this fails. For now, just limit ourselves to few values that don't have this problem.
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-1, 1.0E1, 8))
     {
         Complex G  = AdvancedComplexMath.Gamma(z);
         Complex Gz = G * z;
         Complex GP = AdvancedComplexMath.Gamma(z + 1.0);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(Gz, GP));
     }
 }
 public void ComplexGammaKnownLines()
 {
     foreach (double x in TestUtilities.GenerateRealValues(1.0E-4, 1.0E2, 16))
     {
         Console.WriteLine(x);
         double px = Math.PI * x;
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Gamma(new Complex(0.0, x)) * AdvancedComplexMath.Gamma(new Complex(0.0, -x)), Math.PI / x / Math.Sinh(px)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Gamma(new Complex(0.5, x)) * AdvancedComplexMath.Gamma(new Complex(0.5, -x)), Math.PI / Math.Cosh(px)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Gamma(new Complex(1.0, x)) * AdvancedComplexMath.Gamma(new Complex(1.0, -x)), px / Math.Sinh(px)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(AdvancedComplexMath.Gamma(new Complex(0.25, x)) * AdvancedComplexMath.Gamma(new Complex(0.75, -x)), Math.Sqrt(2.0) * Math.PI / new Complex(Math.Cosh(px), Math.Sinh(px))));
     }
 }
 public void ComplexErfSymmetries () {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-1, 1.0E3, 16)) {
         // for large imaginary parts, erf overflows, so don't try them
         if (z.Im * z.Im > 500.0) continue;
         //Console.WriteLine("{0} {1} {2} {3}", z, AdvancedComplexMath.Erf(z), AdvancedComplexMath.Erf(-z), AdvancedComplexMath.Erf(z.Conjugate));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
             AdvancedComplexMath.Erf(-z), -AdvancedComplexMath.Erf(z)
         ));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
             AdvancedComplexMath.Erf(z.Conjugate), AdvancedComplexMath.Erf(z).Conjugate
         ));
     }
 }
 public void ComplexErfFaddevaAgreement () {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-1, 1.0E2, 16)) {
         Complex w = AdvancedComplexMath.Faddeeva(z);
         Complex erf = AdvancedComplexMath.Erf(-ComplexMath.I * z);
         Complex erfc = 1.0 - erf;
         Complex f = ComplexMath.Exp(z * z);
         Console.WriteLine("z={0} w={1} erf={2} erfc={3} f={4} w'={5} erf'={6}", z, w, erf, erfc, f, erfc / f, 1.0 - f * w);
         if (Double.IsInfinity(f.Re) || Double.IsInfinity(f.Im) || f == 0.0) continue;
         //Console.WriteLine("{0} {1}", TestUtilities.IsNearlyEqual(w, erfc / f), TestUtilities.IsNearlyEqual(erf, 1.0 - f * w));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
             erf, 1.0 - f * w
         ));
     }
 }
 public void ComplexEinCinSiAgreement()
 {
     foreach (double x in TestUtilities.GenerateRealValues(1.0E-2, 1.0E2, 8))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
                           AdvancedComplexMath.Ein(Complex.I * x).Im,
                           AdvancedMath.IntegralSi(x)
                           ));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
                           AdvancedComplexMath.Ein(Complex.I * x).Re,
                           AdvancedMath.IntegralCin(x)
                           ));
     }
 }
 public void ComplexPsiRecurrence () {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 16)) {
         //Complex z = new Complex(0.398612, 888.865);
         //double t = Math.Exp(900.0);
         //Console.WriteLine("{0} {1}", t, 1.0 / t);
         Console.WriteLine("z={0}", z);
         //Console.WriteLine("Psi(1-z)={0}", AdvancedComplexMath.Psi(1.0 - z));
         //Console.WriteLine("Tan(pi z)={0}", ComplexMath.Tan(Math.PI * z));
         //Console.WriteLine("{0} {1}", z, AdvancedComplexMath.Psi(z));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(
             AdvancedComplexMath.Psi(z + 1.0),
             AdvancedComplexMath.Psi(z) + 1.0 / z
         ));
     }
 }