/// <summary>Compute bits of Pi from the results.</summary> public static double ComputePi <T>(long b, IDictionary <Bellard.Parameter, T> results ) where T : Container <Summation> { if (results.Count != Bellard.Parameter.Values().Length) { throw new ArgumentException("m.size() != Parameter.values().length" + ", m.size()=" + results.Count + "\n m=" + results); } double pi = 0; foreach (Bellard.Parameter p in Bellard.Parameter.Values()) { Summation sigma = results[p].GetElement(); Bellard.Sum s = new Bellard.Sum(b, p, 1, null); s.SetValue(sigma); pi = Modular.AddMod(pi, s.GetValue()); } return(pi); }
public virtual void TestSubtract() { Summation sigma = NewSummation(3, 10000, 20); int size = 10; IList <Summation> parts = Arrays.AsList(sigma.Partition(size)); parts.Sort(); RunTestSubtract(sigma, new AList <Summation>()); RunTestSubtract(sigma, parts); for (int n = 1; n < size; n++) { for (int j = 0; j < 10; j++) { IList <Summation> diff = new AList <Summation>(parts); for (int i = 0; i < n; i++) { diff.Remove(Random.Next(diff.Count)); } /// Collections.sort(diff); RunTestSubtract(sigma, diff); } } }
private static void RunTestSubtract(Summation sigma, IList <Summation> diff) { // Util.out.println("diff=" + diff); IList <Container <Summation> > tmp = new AList <Container <Summation> >(diff.Count); foreach (Summation s in diff) { tmp.AddItem(s); } IList <Summation> a = sigma.RemainingTerms(tmp); // Util.out.println("a =" + a); Sharpen.Collections.AddAll(a, diff); foreach (Summation s_1 in a) { s_1.Compute(); } IList <Summation> combined = Util.Combine(a); // Util.out.println("combined=" + combined); NUnit.Framework.Assert.AreEqual(1, combined.Count); NUnit.Framework.Assert.AreEqual(sigma, combined[0]); }