3. Monoid
An object X (e.g. a set, a type in programming language),
binary operation Op,
nullary operation Zero;
Laws:
● Op is associative
● Zero is neutral re: Op
4. Monoid: examples
● Real numbers ℝ and multiplication; 1. is neutral element
● Natural numbers ℕ, max, 0
● Sets and union; ∅ is neutral
● Lists, concatenation, empty list
● Predicates, conjunction, TRUE
● Given an X, functions: X → X, their composition, idX
as neutral
5. Mappings of Monoids
Given monoids (A,opa
,za
) and (B,opb
,zb
), define a mapping f that
preserves structure:
● f: A → B - that is, defined on elements of A, mapping them to B
● f(x opa
y) = f(x) opb
f(y)
● f(za
) = zb
E.g.
● exp: (ℝ,+,0) → (ℝ,*,1)
● sum: List[Int] → (Int,+,0)
6. Monoid of Endomorphisms
Definition. Endomorphism is a function f:X → X
Endomorphisms form a monoid, ({f:X → X}, ∘, idx
)
If X is a finite set, the size is |X||X|
, so we denote this monoid XX
.
Example: id ā b̄ swap
a a a b b
b b a b a
7. Group
Group is a monoid (A,op,0) where each element has an inverse:
∀x∈A ∃y∈A ((x op y) = 0) ∧ ((y op x) = 0)
Notation: y = x-1
, or y = inv(x)
E.g.
● (ℤ,+,0); inv(x) = -x
8. Group of Isomorphisms
In monoid ({f:X → X}, ∘, idx
)
take only such functions that have an inverse
they are called isomorphisms.
f is an isomorphism if ∃g:X→X (f∘g = idx
) ∧ (g∘f = idx
)
It is also known a bijection in the case when X is a set.
Examples:
(_+7):ℝ→ℝ; (-3.4*_):ℝ→ℝ
9. Group of Permutations
Take a set of n elements, {0,1,2,...,n}, and its isomorphic
endomorphisms
They are called permutations.
The group of all permutations on n elements is called An
.
|An
| = n!
Sorting n elements amounts to finding the right one out of n! elements.
With no extra knowledge, binary search gives an estimate
O(log(n!))=O(n log(n))
0 1 2
po
p1
p2
(p0
,p1
,p2
)
10. What if there’s more than one X?
Have a bunch of objects, (X1
,X2
,...,Xn
)
take all isomorphisms between them:
invertible functions of kind f:Xi
→Xj
It is not a group, and not a monoid:
1. composition is only allowed between f:Xi
→Xj
and g:Xj
→Xk
2. no common neutral element, but idi
:Xi
→Xi
Still, have associativity, neutrality, inverses.
It is called Groupoid
11. Examples of Groupoids
● a group is a groupoid
● X and Y are objects. Iso(X,X) ∪ Iso(Y,Y) is a
groupoid
●
● Set A, and an identity on each element - this makes a
discrete groupoid
12. What If Not Only Isomorphisms
Have a bunch of objects, (X1
,X2
,...,Xn
)
take functions between them, so that:
1. idi
:Xi
→Xi
included, for each i;
2. if f:Xi
→Xj
and g:Xj
→Xk
are present, so is g∘f:Xi
→Xk
Have associativity, have neutrality; inverses optional.
It is called Category
13. Examples of Categories
● Every monoid is a category (with just one object)
● Every groupoid is a category (all functions invertible)
● Category of all sets and their functions
● Category of all monoids and their functions
● Tiny things, like
○ Category 1 =
○ Category 1+1 =
○ Category 2 =
○ Category 3 =
14. Java as a Category
Objects (Xi
): all types and classes (Integer, String, java.util.Date, Map<X,Y>)
Functions: all imaginable static functions, plus methods, plus identities
E.g.
toString: Integer → String
It is not an isomorphism: some strings are not results of toString.
But it is an injection; injection is called monomorphism in Category Theory.
Integer.parseInt: String → Integer - not even a function.
Either have to restrict to representations of integers, or redefine “function”.