Example #1
0
        public static M Product <M>(this IMultiplicativeMonoid <M> g, IEnumerable <M> source)
        {
            var product = g.One();

            foreach (var value in source)
            {
                product = g.Multiply(product, value);
            }
            return(product);
        }
Example #2
0
        //For this definition one should usually assume that IMultiplicativeMonoid<M> is abelian
        public static M ScalarPow <M>(this IMultiplicativeMonoid <M> g, M a, int n)
        {
            if (n < 0)
            {
                throw new ArgumentException($"n={n} < 0!");
            }
            var res = g.One();

            for (var i = 0; i < n; i++)
            {
                res = g.Multiply(res, a);
            }
            return(res);
        }