Exemple #1
0
 public void ComplexExpReflection()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 8))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Exp(-z), 1.0 / ComplexMath.Exp(z)));
     }
 }
Exemple #2
0
 public void ComplexLogExp()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 16))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Exp(ComplexMath.Log(z)), z));
     }
 }
 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
         ));
     }
 }
Exemple #4
0
 public void ComplexPowExponent()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 6))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Pow(Math.E, z), ComplexMath.Exp(z)));
     }
 }
 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 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 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));
     }
 }
Exemple #8
0
        public void FourierLinearity()
        {
            foreach (int n in sizes)
            {
                Console.WriteLine(n);
                FourierTransformer ft  = new FourierTransformer(n);
                Random             rng = new Random(1);

                Complex[] x = TestUtilities.GenerateComplexValues(0.1, 10.0, n, rng);
                Complex[] y = TestUtilities.GenerateComplexValues(0.1, 10.0, n, rng);
                Complex[] z = new Complex[n];
                for (int i = 0; i < n; i++)
                {
                    z[i] = x[i] + y[i];
                }

                Complex[] xt = ft.Transform(x);
                Complex[] yt = ft.Transform(y);
                Complex[] zt = ft.Transform(z);

                for (int i = 0; i < n; i++)
                {
                    Assert.IsTrue(TestUtilities.IsSumNearlyEqual(xt[i], yt[i], zt[i]));
                }
            }
        }
Exemple #9
0
        public void FourierParseval()
        {
            foreach (int n in sizes)
            {
                //int n = 15;
                Console.WriteLine(n);
                FourierTransformer ft  = new FourierTransformer(n);
                Random             rng = new Random(1);

                Complex[] x = TestUtilities.GenerateComplexValues(0.1, 10.0, n, rng);
                Complex[] y = TestUtilities.GenerateComplexValues(0.1, 10.0, n, rng);

                Complex s = 0.0;
                for (int i = 0; i < n; i++)
                {
                    s += x[i] * y[i].Conjugate;
                }

                Complex[] xt = ft.Transform(x);
                Complex[] yt = ft.Transform(y);

                Complex st = 0.0;
                for (int i = 0; i < n; i++)
                {
                    st += xt[i] * yt[i].Conjugate;
                }
                st /= n;

                Console.WriteLine("{0} {1}", s, st);
                Assert.IsTrue(TestUtilities.IsNearlyEqual(s, st));
            }
        }
Exemple #10
0
 public void ComplexPowOneHalf()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 16))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Pow(z, 0.5), ComplexMath.Sqrt(z)));
     }
 }
Exemple #11
0
 public void ComplexTanTanh()
 {
     foreach (Complex x in TestUtilities.GenerateComplexValues(1.0E-3, 1.0E3, 16))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Tanh(x), -ComplexMath.I * ComplexMath.Tan(ComplexMath.I * x)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Tanh(-ComplexMath.I * x), -ComplexMath.I * ComplexMath.Tan(x)));
     }
 }
Exemple #12
0
 public void ComplexTrigPeriodicity()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 8))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(z), ComplexMath.Sin(z + 2.0 * Math.PI)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(z), ComplexMath.Cos(z + 2.0 * Math.PI)));
     }
 }
 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));
     }
 }
Exemple #14
0
 public void ComplexCosCosh()
 {
     foreach (Complex x in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 10))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cosh(x), ComplexMath.Cos(ComplexMath.I * x)));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cosh(-ComplexMath.I * x), ComplexMath.Cos(x)));
     }
 }
 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)));
     }
 }
Exemple #16
0
 public void ComplexAbsSquared()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 10))
     {
         double abs = ComplexMath.Abs(z);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(abs * abs, z * 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 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)
         ));
     }
 }
Exemple #19
0
 public void ComplexSinhCoshRelation()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-2, 1.0E2, 10))
     {
         Complex sinh = ComplexMath.Sinh(z);
         Complex cosh = ComplexMath.Cosh(z);
         Assert.IsTrue(TestUtilities.IsSumNearlyEqual(cosh * cosh, -sinh * sinh, 1));
     }
 }
 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 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 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
         ));
     }
 }
Exemple #24
0
 public void ComplexPowSpecialCases()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 10))
     {
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Pow(z, -1), 1.0 / z));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Pow(z, 0), 1.0));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Pow(z, 1), z));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Pow(z, 2), z * z));
     }
 }
 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
                           ));
     }
 }
Exemple #26
0
 public void ComplexSqrt()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 32))
     {
         Complex sz = ComplexMath.Sqrt(z);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sqr(sz), z, TestUtilities.RelativeTarget));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Arg(z) / 2.0, ComplexMath.Arg(sz), TestUtilities.RelativeTarget));
         Assert.IsTrue(TestUtilities.IsNearlyEqual(Math.Sqrt(ComplexMath.Abs(z)), ComplexMath.Abs(sz), TestUtilities.RelativeTarget));
     }
 }
 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 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)
                           ));
     }
 }
Exemple #30
0
 public void ComplexArcTrigInversion()
 {
     foreach (Complex z in TestUtilities.GenerateComplexValues(1.0E-4, 1.0E4, 32))
     {
         Complex asin = ComplexMath.Asin(z);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Sin(asin), z));
         Complex acos = ComplexMath.Acos(z);
         Assert.IsTrue(TestUtilities.IsNearlyEqual(ComplexMath.Cos(acos), z));
         Assert.IsTrue(TestUtilities.IsSumNearlyEqual(asin, acos, Math.PI / 2.0));
     }
 }