Professional Documents
Culture Documents
Semigroups
Semigroups
Example 1
1. (N, +), (Z, +), (Q, +), (R, +), and (C, +) are (additive)
semigroups;
2. (N, ·), (Z, ·), (Q, ·), (R, ·), and (C, ·) are (multiplicative)
semigroups;
3. Let n ∈ Z and nZ = {n · x|x ∈ Z}. Then, (nZ, +) and (nZ, ·) are
semigroups;
4. Let m ∈ Z. Then, (Zm , +) and (Zm , ·), where + and · are the
addition and multiplication modulo m, are semigroups.
Remark 1
Associativity of a binary operation ◦ means that the order of
evaluation of an expression a1 ◦ a2 ◦ a3 , without changing the
order of the terms, is immaterial. In other words, no parenthesis is
required for an associative operation;
Commutativity of a binary operation ◦ means that the order of the
operands in expressions like a1 ◦ a2 is immaterial.
e = e ◦ e′ = e′ .
Example 3
1. (N, +, 0), (Z, +, 0), (Q, +, 0), and (R, +, 0) are commutative
monoids;
2. (N, ·, 1), (Z, ·, 1), (Q, ·, 1), and (R, ·, 1) are commutative monoids;
3. (nZ, +, 0) is a commutative monoid and (nZ, ·) is a commutative
semigroup. (nZ, ·) has unity only if n = 0 or n = 1 and, in such a
case it becomes commutative monoid;
4. (Zm , +, 0) and (Zm , ·, 1) are commutative monoids. When m = 1,
Z1 = {0} and the multiplicative unity of this monoid is 0.
Definition 6
1. A semigroup (S ′ , ◦′ ) is a sub-semigroup of a semigroup (S, ◦),
denoted (S ′ , ◦′ ) ≤ (S, ◦), if S ′ ⊆ S and ◦′ = ◦|S ′ .
2. A monoid (M ′ , ◦′ , e′ ) is a sub-monoid of a monoid (M, ◦, e),
denoted (M ′ , ◦′ , e′ ) ≤ (M, ◦, e), if M ′ ⊆ M and ◦′ = ◦|M ′ and
e′ = e.
3. The least subsemigroup (monoid) of a semigroup (monoid) which
includes a given subset A, denoted hAi, is called the
sub-semigroup (sub-monoid) generated by A.
4. A semigroup (monoid) is generated by a subset A of it if it
coincides with the sub-semigroup (sub-monoid) generated by A.
a1 ◦ · · · ◦ an ,
where n ≥ 1 and a1 , . . . , an ∈ A;
If (M, ◦, e) is a monoid and A ⊆ S, then the sub-monoid
generated by A is the set of all products
a1 ◦ · · · ◦ an ,
Example 5
(N, +) ≤ (Z, +) ≤ (Q, +) ≤ (R, +);
Definition 7
1. The order of a semigroup (monoid) is the number of its elements if
the semigroup (monoid) is finite, and ∞, otherwise.
2. The order of an element a of a semigroup (monoid) is the order of
the sub-semigroup (sub-monoid) generated by a.
Example 6
(Z, +, 0) has the order ∞;
(Zm , +, 0) has the order m, if m 6= 0. For m = 0, (Zm , +, 0) has
the order ∞.
Definition 8
1. A function f : S → S ′ is a homomorphism from a semigroup (S, ◦)
to a semigroup (S ′ , ◦′ ) if
f (a ◦ b) = f (a) ◦′ f (b), for any a, b ∈ S.
2. A function f : M → M ′ is a homomorphism from a monoid
(M, ◦, e) to a monoid (M ′ , ◦′ , e′ ) if
f (a ◦ b) = f (a) ◦′ f (b), for any a, b ∈ M ;
f (e) = e′ .
Related concepts:
injective homomorphism = monomorphism;
surjective homomorphism = epimorphism;
bijective homomorphism = isomorphism;
Example 7
the function f (x) = 2x , for any x ∈ N, is a homomorphism from
(N, +, 0) to (N, ·, 1). Indeed,
f (0) = 20 = 1;
f (x + y) = 2x+y = 2x · 2y = f (x) · f (y), for any x, y.
Moreover, f is injective but not surjective. Therefore, f is a
monomorphism (but not an epimorphism).
Σ2 = {0, 1, 2, 3};
Example 9
w = abaa is a word of length 4 over Σ1 = {a, b, c};
Definition 11 Two words u and v over the same alphabet Σ are called
equal if they have the same length k and u(i) = v(i), for each
1 ≤ i ≤ k.
where (
w1 (i), if 1 ≤ i ≤ |w1 |
(w1 · w2 )(i) =
w2 (i − |w1 |), otherwise,
Example 10
abba · bbaa = abbabbaa;
λ · w = w · λ = w, for any w.
Definition 14
(1) A pair (Σ, ≺) which consists of an alphabet Σ and a total order ≺
on Σ is called an ordered alphabet.
(2) Let (Σ, ≺) be an ordered alphabet. The binary relation ≤(Σ,≺)
given by
x ≤(Σ,≺) y
iff
x is a prefix of y, or
x = uav, y = ubw, and a ≺ b, for some u, v, w ∈ Σ∗ and
a, b ∈ Σ with a 6= b,
is called the direct lexicographic order on (Σ, ≺).
λ λ
a a
aa b
aaa aa
··· ab
aaaab ba
aaab bb
aab aaa
ab aab
··· ···
b bbb
a) b)
Remark 4
The monoid (N, +, 0) can be generated by {1}. Moreover, any
number n ∈ N − {0} can be uniquely written as a finite
combination of 1’s under +, namely,
n = 1 + 1 + ··· + 1.
| {z }
n times
s = x1 ◦ · · · ◦ xn ,
where x1 , . . . , xn ∈ X and n ≥ 1.
F.L. Ţiplea/AFCS/Spring 2017/Semigroups and Monoids – p. 25/53
4. Free semigroups and monoids
Example 11
(N, +, 0) is a free monoid.
X + (X ∗ ) together with the concatenation operation is a free
semigroup (monoid), for any non-empty set X.
(Z, +, 0) is not a free monoid.
Equivalent definitions:
1. C is a code over A if any code sequence w ∈ C + can be uniquely
decomposed into code words
w = c1 · · · cn ;
2. C is a code over A if
u1 · · · um = v1 · · · vn ⇒ n = m ∧ (∀i)(ui = vi ),
for any u1 , . . . , um , v1 , . . . , vn ∈ C;
3. C is a code over A if
u1 · · · um = v 1 · · · v n ⇒ u1 = v 1 ,
for any u1 , . . . , um , v1 , . . . , vn ∈ C.
Example 13
C = {a, ab, ba} is not a code because aba = (ab)a = a(ba);
C = {a, bb, aab, bab} is a code.
Definition 20
1. C is a prefix code if no code word of C is a prefix of any other
code word.
2. C is a suffix code if no code word of C is a suffix of any other code
word.
3. C is a block code if all code words of C have the same length.
Example 14
ASCII is a block code.
C1 , C2 , C3 , . . .
Remark 5 If C is finite, then there are i and j such that j < i and
Ci = Cj .
Sardinas-Patterson Algorithm
input:finite non-empty set C ⊆ A+ ;
output: code(C) = 1, if C is a code, and code(C) = 0, otherwise;
begin
C1 := {x ∈ A+ |(∃c ∈ C)(cx ∈ C)};
if C ∩ C1 6= ∅ then code(C) := 0
else begin
i := 1; cont := 1;
while cont = 1 do
begin
i := i + 1;
Ci := {x ∈ A+ |(∃c ∈ Ci−1 )(cx ∈ C) ∨ (∃c ∈ C)(cx ∈ Ci−1 )};
if C ∩ Ci 6= ∅ then begin code(C) := 0; cont := 0 end
else if (∃j < i)(Ci = Cj )
then begin code(C) := 1; cont := 0 end;
end;
end;
end.
Huffman codes
A a b c d e f
π 0.4 0.1 0.1 0.1 0.2 0.1
A a b c d e f
h 0 1100 1101 1110 10 1111
Then, the length of h w.r.t. IS is Lh (IS) = 2.4. That is, on average, 2.4
bits are needed to encode any symbol of the information source.
Given an information source IS, are there Huffman encodings for IS?
The answer is positive.
Huffman algorithm:
1. let IS be an information source with n ≥ 2 symbols
A a1 a2 ··· an−1 an
π p1 p2 ··· pn−1 pn
where p1 ≥ p2 ≥ · · · ≥ pn−1 ≥ pn ;
2. if n = 2, then h(a1 ) = 0 and h(a2 ) = 1 is a Huffman code for IS;
3. if n ≥ 3, then compute a reduced source IS ′ for IS
A a b c d e f
π 0.4 0.2 0.1 0.1 0.1 0.1
✲4 ✲4 ✲4 ✲6
a 4 ❍❍
b 2 ✲2 ✲2 ❍ ✲4 ❍❥4
❍
❍
❍❥2
❍
c 1 ❍ ✲2 ✲2
❍
❍
d 1❍ ❍ ❥1 ✲2
❍
e 1 ❍❥1
❍
f 1
0 ✲4 0 ✲4 0 ✲4 ✲1
a 4 ❍❍ 6
✲2 ✲ 2 10 ❍
❍❍ ✲ 4 11 ❥4
❍
10 10
b 2 0
❍
❥ 2 10
❍
1 ❍ ✲2 ✲2
1101 111
c
❍ 111
1100 ❍
d 1❍ ❍ ❥1 ✲ 2 110
❍ 1101
1 1111 ❍
❥1
❍ 1100
e
1110
f 1
The Huffman code is h(a) = 0, h(b) = 10, h(c) = 1101, h(d) = 1100,
h(e) = 1111, and h(f ) = 1110. The length of h is 2.4. It is the minimum
length code among all the prefix codes associated to IS.
Compression ratio = is the ratio of the size of the original data to the
size of the compressed data.
k
We denote S ◦ ·
| {z }· · ◦ S by S , where S is a finite information source.
k times
Then,
H(S k ) = kH(S).
frequency of a in w
pa = .
|w|
t
✔❚
0✔ ❚1
✔ ❚
✔
t ❚t
▲ ☞❚
▲ 1 0 ☞ ❚1
▲ ☞ ❚❚t
▲t ☞t
a ❈ ✄
❈ 1 ✄0
❈ ✄
❈t t✄
b c
A sequence of Huffman trees used to encode the string dcd over the
alphabet {a, b, c, d}:
4t 5t
✔✔ ❚ ✔✔ ❚
0✔ ❚ 1 0✔ ❚ 1
✔ ❚ ✔ ❚
2✔t 2❚t 2✔t 3❚t
▲ ☞ ▲ ☞
0 ✔ ▲1 0☞ ❚ 1 0 ✔ ▲1 0☞ ❚ 1
✔ ❚ ✔ ❚
▲ ☞ ❚ ▲ ☞ ❚
1✔
t ▲ ☞
1 t 1t 1❚t 1✔
t 1 ▲t 1 ☞t 2❚t
a b c d a b c d
(a) T0 (b) T1
7t
☞❚
6t 0☞ ❚ 1
✔✔ ❚ ☞ ❚t
0✔ ❚ 1 3 ☞t 4❚
✔ ❚ d ☞❚
2✔t 4❚t 0 ☞ ❚1
▲ ☞ ☞
0 ✔ ▲1 0☞ ❚ 1 2 ☞t 2❚ t
✔ ❚ ☞❚
▲ ☞ ❚
c
1✔
t 1 ▲t 2 ☞t 2❚t 0☞ ❚ 1
a b c d ☞ ❚
1 ☞
t ❚t 1
a b
(d) T2 (c) T3