public void EllipticNomeAgreement() { foreach (double k in TestUtilities.GenerateRealValues(1.0E-2, 1.0, 4)) { double K = AdvancedMath.EllipticK(k); double k1 = Math.Sqrt((1.0 - k) * (1.0 + k)); double K1 = AdvancedMath.EllipticK(k1); double q = AdvancedMath.EllipticNome(k); // For k << 1, this test fails if formulated as q = e^{\pi K' / K}. // Problem is that computation of k' looses some digits to cancellation, // then K' is near singularity so error is amplified, then // exp function amplifies error some more. Investigation indicates // that q agrees with Mathematica to nearly all digits, so problem // isn't in nome function. Run test in log space and don't let k get // extremely small. Assert.IsTrue(TestUtilities.IsNearlyEqual( Math.Log(q), -Math.PI * K1 / K )); } }