Examples of monoids/semigroups in programming
Posted
by jkff
on Stack Overflow
See other posts from Stack Overflow
or by jkff
Published on 2010-03-20T09:59:05Z
Indexed on
2010/03/20
10:01 UTC
Read the original article
Hit count: 351
It is well-known that monoids are stunningly ubiquitous in programing. They are so ubiquitous and so useful that I, as a 'hobby project', am working on a system that is completely based on their properties (distributed data aggregation). To make the system useful I need useful monoids :)
I already know of these:
- Numeric or matrix sum
- Numeric or matrix product
- Minimum or maximum under a total order with a top or bottom element (more generally, join or meet in a bounded lattice, or even more generally, product or coproduct in a category)
- Set union
- Map union where conflicting values are joined using a monoid
- Intersection of subsets of a finite set (or just set intersection if we speak about semigroups)
- Intersection of maps with a bounded key domain (same here)
- Merge of sorted sequences, perhaps with joining key-equal values in a different monoid/semigroup
- Bounded merge of sorted lists (same as above, but we take the top N of the result)
- Cartesian product of two monoids or semigroups
- List concatenation
- Endomorphism composition.
Now, let us define a quasi-property of an operation as a property that holds up to an equivalence relation. For example, list concatenation is quasi-commutative if we consider lists of equal length or with identical contents up to permutation to be equivalent.
Here are some quasi-monoids and quasi-commutative monoids and semigroups:
- Any (a+b = a or b, if we consider all elements of the carrier set to be equivalent)
- Any satisfying predicate (a+b = the one of a and b that is non-null and satisfies some predicate P, if none does then null; if we consider all elements satisfying P equivalent)
- Bounded mixture of random samples (xs+ys = a random sample of size N from the concatenation of xs and ys; if we consider any two samples with the same distribution as the whole dataset to be equivalent)
- Bounded mixture of weighted random samples
Which others do exist?
© Stack Overflow or respective owner