public BigInteger BigIntZeta(uint s) // must be +ve integer > 1 { BigInteger unity = BigInteger.Pow(ONE, (int)(s >> 1)); // normalize to become 1 in the numerator double sum = 1.0d; BigInteger zeta = unity; object monitor = new object(); Stopwatch sw = new Stopwatch(); WriteLine("Calculating BigIntZeta({2}) with {0} iterations and {1} digits.\n", STEPS, DIGITS, s); sw.Start(); Parallel.For <Tuple <double, BigInteger> >(2, (int)STEPS, () => new Tuple <double, BigInteger>(2.0d, 2), (i, loop, T) => //for (uint i = 2; i < STEPS; i++) { BigInteger div = BigInteger.Pow(i, (int)s); //zeta += unity / j; sum += 1.0d / Math.Pow(i, s); ValueTuple <double, BigInteger> X = T.ToValueTuple(); X.Item1 += i; X.Item2 += unity / div; return(X.ToTuple()); }, t => { lock (monitor) { sum += t.Item1; zeta += t.Item2; } }); sw.Stop(); #if DEBUG string strElapsed; if (sw.ElapsedMilliseconds <= 1000) { strElapsed = String.Format("{0} ms", sw.ElapsedMilliseconds); } else { strElapsed = String.Format("{0:F1} s", sw.Elapsed.TotalSeconds); } WriteLine($"\n\nBigIntZeta({s}):\n{zeta}\nElapsed time: {strElapsed}\n"); #endif WriteLine(); return(zeta); }
public static void Add <T1, T2>(this IList <Tuple <T1, T2> > list, ValueTuple <T1, T2> item) => list.Add(item.ToTuple());