public static T MonoidOp <T>(this IEnumerable <T> summables, Monoid <T> mon)
 {
     return(summables.Aggregate(mon.Unit, mon.Op));
 }
 public static T InnerProduct <T>(this IEnumerable <T> left, IEnumerable <T> right
                                  , Monoid <T> sum, Monoid <T> product)
 {
     return(left.Zip(right, (x, y) => product.Op(x, y)).MonoidOp(sum));
 }
示例#3
0
 public SemiRing(Monoid <T> add, Monoid <T> product)
 {
     Add     = add;
     Product = product;
 }
示例#4
0
 public Group(Monoid <T> monoid, Func <T, T> inverse)
 {
     Monoid  = monoid;
     Inverse = inverse;
 }
 /// <summary>
 /// Repeatedly apply a monoid operation to the consecutive elements of a container
 /// </summary>
 /// <typeparam name="T">A type that has monoid properties
 /// (a zero element and an associative binary operation)</typeparam>
 /// <param name="summables">An enumerable container of objects of type T</param>
 /// <param name="mon">A monoid object that defines a zero element and
 /// an associative binary operation on T</param>
 /// <returns>An object of type T formed by applying the monoid's
 /// associative operations over each consecutive pair in the source.
 /// This is just an aggregation of an IEnumerable of the  monoid operation.</returns>
 public static T MonoidOp <T>(this IEnumerable <T> source, Monoid <T> mon)
 {
     return(source.Aggregate(mon.Unit, mon.Op));
 }