Exemplo n.º 1
0
        public static double Variance(IList <double> sample_0, double mean)
        {
            double variance = 0.0f;

            for (int index = 0; index < sample_0.Count; index++)
            {
                variance += ToolsMath.Sqr(sample_0[index] - mean);
            }
            return(variance / (sample_0.Count - 1.0f));
        }
Exemplo n.º 2
0
        public static double SumSquaredAll(IList <IList <double> > list_list)
        {
            double sum_squared_all = 0;

            for (int index_0 = 0; index_0 < list_list.Count; index_0++)
            {
                for (int index_1 = 0; index_1 < list_list[index_0].Count; index_1++)
                {
                    sum_squared_all += ToolsMath.Sqr(list_list[index_0][index_1]);
                }
            }
            return(sum_squared_all);
        }
        //Prime test is in p for O:log6(N)
        private static bool IsPrimeByAgrawalKayalSaxena(
            BigInteger n)
        {
            BigInteger X = 0;
            BigInteger r = 0;
            BigInteger a = 0;
            BigInteger b = 0;

            if (a.Pow(b) == n)
            {
                return(false);
            }

            //TODO Find the smallest r such that Or(n) > (log2 n) 2.


            for (a = r; a > 1; a--)
            {
                BigInteger gcd = ToolsMathBigInteger.GetGCDByModulus(a, n);
                if (1 < gcd && gcd < n)
                {
                    return(false);
                }
            }


            if (n <= r)
            {
                return(true);
            }


            BigInteger upper_bound = ToolsMath.Sqrt(EulerPhi(r)) * 1;

            for (a = 0; a < upper_bound; a++)
            {
                if ((X + a).Pow(n) != X.Pow(n) + a * (X.Pow(r) - 1) % n)
                {
                    return(false);
                }
            }
            return(true);
        }