THEORY OF COMPUTATIONmath.sharif.ir/faculties/uploads/daneshgar/Courses/... · THEORY OF...
Transcript of THEORY OF COMPUTATIONmath.sharif.ir/faculties/uploads/daneshgar/Courses/... · THEORY OF...
THEORY OF COMPUTATION (Automata as Algebras)
THEORY OF COMPUTATION
Chapter7Regular Languages
(Automata as Algebras)
A. Daneshgar(Slides prepared by Z. Ghafouri)
Department of Mathematical SciencesSharif University of Technology
2020, March, 1st (1998, Esfand, 10)
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
An algebra
Definition: An algebra is a pair A = (A,O) where A is a set and Ois a set of operations on A.
I An n−ary operation τ on A is a function that takes nelements of A and returns a single element of A; i.e.
τ : A× . . .× A︸ ︷︷ ︸n
→ A,
I A 0−ary operation (nullary operation) is simply an element ofA, or a constant,
I A 1−ary operation (unary operation) is simply a function fromA to A,
I A 2−ary operation (binary operation) is simply a functionfrom A× A to A.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
A pre-automaton
Definition: A pre-automaton
A =(Q, q0 ∈ Q, {τi : Q → Q}i∈Σ
)with input symbols Σ of n elements, is an algebra with one nullaryand n unary operations on a set of states A.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
HomomorphismsA =
(Q, q0 ∈ Q, {τi : Q → Q}i∈Σ
)B =
(Q ′, q0
′ ∈ Q ′, {τi ′ : Q ′ → Q ′}i∈Σ
)A B
x
y
σ(x)
σ(y)
σ : Q → Q ′τi τ ′i
∀i τ ′i ◦ σ = σ ◦ τiσ(q0) = q′0
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Isomorphisms
Definition: Two algebras
A =(Q, q0 ∈ Q, {τi : Q → Q}i∈Σ
)and
B =(Q ′, q0
′ ∈ Q ′, {τi ′ : Q ′ → Q ′}i∈Σ
)are said to be isomorphic if there exists a bijective homomorphismσ : A → B such that its inverse, σ−1 : B → A, is also a bijectivehomomorphism.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Subalgebras
I Let A = (A,O) be an algebra and let τ ∈ O be an n−ary operation
of A. A subset B of A is τ− closed if a0, . . . , an−1 ∈ B imply
τ(a0, . . . , an−1) ∈ B.
I B is a closed subset of A if B is τ− closed for each operation τ of
A.
I A subalgebra of the algebra A = (A,O) is an algebra B = (B,OB),where B ⊆ A is a closed subset of A and
OB = {τ |Bn : τ ∈ O is an n−ary operation}.
In other words, a subalgebra is a subset of an algebra which is
closed under all its operations and carrying the induced operations.
I A reduced algebra is an algebra whose only subalgebras are the
empty set and itself.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Reduced pre-automata
A reduced pre-automaton
A =(Q, q0 ∈ Q, {τi : Q → Q}i∈Σ
)is a pre-automaton which is reduced as an algebra. Note that thisis equivalent to the condition that each state of Q is reachablefrom the initial state q0.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Equivalence relations
I An equivalence relation on X is a binary relation ∼ on X suchthat
I ∀x ∈ X (x ∼ x) (reflexivity),
I ∀x , y ∈ X (x ∼ y → y ∼ x) (simmetry),
I ∀x , y , z ∈ X (x ∼ y ∧ y ∼ z → x ∼ z) (transitivity).
I The equivalence class of an element x in X with respect tothe equivalence relation ∼ , denoted by [x ]∼, is the set of allelements of X which are equivalent to x , i.e.
[x ]∼ = {y ∈ X | x ∼ y}.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
I Every two equivalence classes [x ]∼ and [y ]∼ are either equalor disjoint, so the set of equivalence classes is a partition of X.
I The set of all equivalence classes of X by ∼, denoted byX/ ∼, is called the quotient set of X .
I For any partition P of a set X , the relation ∼ on X defined by
x ∼ y if and only if x and y belong to the same element of P,
is an equivalence relation on X .
Hence, talking about equivalence relations on a set is essentially the
same as talking about partitions of a set: An equivalence relation
determines a partition (in which the subsets are the equivalence
classes), and a partition determines an equivalence relation (in
which being equivalent means belonging to the same subset).
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Equivalence coming from an onto-map
Any onto-map σ : Aonto−→ B gives rise to an equivalence relation on
A according to which
a1 ∼σ a2 ⇔ σ(a1) = σ(a1).
Hence, the collection of all σ−inverse images of the elements of Bforms a partition of A.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Congruence relations
Definition: Let A = (A,O) be an algebra. A congruence relation isan equivalence relation on A which is compatible with the algebraoperations. In the case of a pre-automaton where each operation iseither nullary or unary, it means that for every x and y in A andeach unary operation τi :
[x ] = [y ]⇔ [τi (x)] = [τi (y)].
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
The quotient pre-automaton
Definition: Let A =(Q, q0 ∈ Q, {τi : Q → Q}i∈Σ
)be a
pre-automaton and ∼ be a congruence relation on A. Thequotient pre-automaton of A by ∼ is
A/ ∼=(Q/ ∼, [q0], {τ̃i : Q/ ∼ → Q/ ∼}i∈I
)where τ̃i ([x ]) = [τi (x)].
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
The canonical homomorphismConsider the map σ : A → A/ ∼ defined as σ(x) = [x ]; then σ iscalled the natural or the canonical map. Obviously σ is ahomomorphism, or equivalently:
x
τi (x)
σ(x) = [x ]
[τi (x)] = τ̃i ([x ])def τ̃i
σ
τi
σ
τ̃i
In other words
σ(τi (x)) = [τi (x)] = τ̃i (σ(x)).
andσ(q0) = [q0 ].
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
LetA =
(Q, q0 ∈ Q, {τi : Q → Q}i∈Σ
)and
B =(Q ′, q0
′ ∈ Q ′, {τi ′ : Q ′ → Q ′}i∈Σ
)be two pre-automata and σ : A → B be an onto homomorphism.Since σ maps A onto B, the collection of all σ−inverse images ofthe elements of B forms a partiotion of A. Let ∼σ be theequivalence relation corresponding to this partition. Since σ is ahomomorphism, ∼σ is a congruence relation on A:
[x ]∼σ = [y ]∼σ ⇔ σ(x) = σ(y)
⇔ τi′(σ(x)) = τi
′(σ(y))
⇔ σ(τi (x)) = σ(τi (y))
⇔ [τi (x)]∼σ = [τi (y)]∼σ
⇔ τ̃i ([x ]∼σ) = τ̃i ([x ]∼σ).
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Hence, having an onto homomorphism σ : A → B, one can makethe quotient pre-automaton A by ∼σ
A/∼σ =(Q/∼σ, [q0], {τ̃i : Q/∼σ → Q/∼σ}i∈Σ
)where τ̃i ([x ]) = [τi (x)].
Question:A B
A/∼σ
σ
onto hom
canonicalhom
?
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Consider the bijective map
σ̃ : A/∼σ −→ B
[x ] 7→ σ(x)
[q0] 7→ σ(q0) = q0′
Then σ̃ is a homomorphism:
[x ]
[τi (x)]
σ(x)
σ(τi (x)) = τi′(σ(x))
σ : hom
σ̃
τ̃i
σ̃
τi′
Consequently,A/∼σ ' B.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Without loss of genelarity, assume that all pre-automata are defined on {0, 1}.
So a pre-automaton is an algebra of type (0,1,1).
Consider the following fixed pre-automaton:
Ur =({0, 1}∗, λ ∈ {0, 1}∗, {ri : {0, 1}∗ → {0, 1}∗}i=0,1
)where ri (w1 . . .wn) = w1 . . .wni .
Claim: For any reduced pre-automaton
B =(P, p0 ∈ P, {τi : P → P}i=0,1
)there exists an onto homomorphism σB : Ur
onto−→ B such thatσB(w) = B(w). In other words
σB(w1 . . .wn) = τwn ◦ . . . ◦ τw2 ◦ τw1(p0).
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Sketch of Proof.
B : a reduced pre-automaton⇒ σB : an onto-map
and w
wi
B(w)
σB(wi) = τi (B(w))
def σB ,B(w)
σB
ri
σB
τi
Hence,σB is a homomorphism.
Therefore,
Ur/∼σB ' B.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Example
The following two pre-automata are isomorphic:
q0start
q2
q1
1
0
0
1
0, 1
{λ}start
S
{10n}1
0
0
1
0, 1
where S = {0, 1}∗ \ ({λ} ∪ {10n | n ∈ N}).
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Ur B
λ
10n
S
q0
q1
q2
σB
σB
σB
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
The minimal automatonLet L ⊆ {0, 1}∗ be a language. We are trying to construct aminimal pre-automaton M
Lto accept L. We will be needing some
ingredients as follows:
I Definition: For a language L ⊆ {0, 1}∗ and any x ∈ {0, 1}∗,define:
x\L = {u ∈ {0, 1}∗ | xu ∈ L}.
From this definition, it follows that for every x , y ∈ {0, 1}∗:
x\(y\L) = {u ∈ {0, 1}∗ | xu ∈ y\L}= {u ∈ {0, 1}∗ | yxu ∈ L}= (yx)\L.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
I Definition: For a language L ⊆ {0, 1}∗, define a relation ∼ on{0, 1}∗ as follows: for x , y ∈ {0, 1}∗,
x ∼ y ⇔ x\L = y\L⇔ {u ∈ {0, 1}∗ | xu ∈ L} = {u ∈ {0, 1}∗ | yu ∈ L}.
In other words, x ∼ y if and only if for anyu ∈ {0, 1}∗, xu and yu are either both in L or bothare not in L.
I Note: The relation ∼ is indeed an equivalence relation; It iseasy to see that the relation ∼ is reflexive, symmetric, andtransitive, because the equality relation has these properties.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Now we are ready to construct the minimal pre-automatonaccepting L.
Claim: For a language L ⊆ {0, 1}∗, ML
= (Q , q0 , τ0 , τ1) is theminimal pre-automaton w.r.t. right concatenation accepting L,where
1. Q = {x\L | x ∈ {0, 1}∗},
2. q0 = λ\L,
3. τi (x\L) = i\(x\L) = (xi)\L, i = 0, 1.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
ExampleL = {1 0n | n ∈ N}
λ\L = L
1\L = {0n | n ∈ N} = Z
1 0j\L = Z j ∈ N
0\L = ∅
0u\L = ∅ u ∈ {0, 1}∗
11u\L = ∅ u ∈ {0, 1}∗
101u\L = ∅ u ∈ {0, 1}∗
...
Lstart
∅
Z1
0
0
1
0, 1
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Relations
Equivalence Relations
Congruence Relations
∅
{(x, x) | x ∈ {0, 1}∗}
{0, 1}∗ × {0, 1}∗
∼L
'L
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
I A language L ⊆ {0, 1}∗ determines an equivalence relation ∼L
on {0, 1}∗ in a usual way, i.e. for x , y ∈ {0, 1}∗
x ∼L y ⇔ x , y ∈ L ∨ x , y ∈ Lc .
I Now we define a congruence relation 'L on {0, 1}∗ as follows:for x , y ∈ {0, 1}∗,
x 'L y ⇔ x\L = y\L.
I Claim: 'L is the greatest congruence relation less than ∼L.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Claim1: The relation 'L is a congruence relation on Ur .
Proof. It is easy to see that 'L is an equivalence relation on{0, 1}∗, so it suffices to show that 'L is compatible with ri , fori=0,1:
x 'L y ⇔ x\L = y\L⇔ ∀u ∈ {0, 1}∗ (xu, yu ∈ L ∨ xu, yu 6∈ L)
⇔ ∀u ∈ {0, 1}∗ ∀i ∈ {0, 1} (xiu, y iu ∈ L ∨ xiu, y iu 6∈ L)
⇔ xi\L = y i\L⇔ xi 'L y i
⇔ ri (x) 'L ri (y).
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Claim2: 'L ⊆ ∼L.
Proof.
x 'L y ⇒ x\L = y\L⇒ ∀u ∈ {0, 1}∗ (xu, yu ∈ L ∨ xu, yu 6∈ L)
⇒ for λ ∈ {0, 1}∗ (xλ, yλ ∈ L ∨ xλ, yλ 6∈ L)
⇒ x , y ∈ L ∨ x , y 6∈ L
⇒ x , y ∈ L ∨ x , y ∈ Lc
⇒ x ∼L y .
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
...
Claim3: For any congruence relation ρ on {0, 1}∗,
ρ ⊆ ∼L =⇒ ρ ⊆ 'L .
Proof.
(x , y) ∈ ρ ⇒ ∀i ∈ {0, 1} (ri (x), ri (y)) ∈ ρ⇒ ∀i ∈ {0, 1} (xi , y i) ∈ ρ⇒ ∀u ∈ {0, 1}∗ (xu, yu) ∈ ρ⇒ ∀u ∈ {0, 1}∗ xu ∼L yu⇒ ∀u ∈ {0, 1}∗ (xu, yu ∈ L ∨ xu, yu ∈ Lc)⇒ ∀u ∈ {0, 1}∗ (xu, yu ∈ L ∨ xu, yu 6∈ L)⇒ x\L = y\L⇒ x 'L y .
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Now we can form the quotient pre-automaton Ur/'L and showthat
Ur/'L ' ML.
Therefore, it follows from the construction of Ur/'L that
ML
is the minimal pre-automaton w.r.t. right concatenationaccepting L.
In order to show this isomorphism, consider the map σ : Ur →Mby σ([x ]'L
) =M(x) = x\L for any x ∈ {0, 1}∗.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
I σ is a well-defined map:
1. For any x = x1 . . . xn:
M(x) = M(x1 . . . xn)
= τxn ◦ . . . ◦ τx2 ◦ τx1 (λ\L)
= τxn ◦ . . . ◦ τx2 (x1\L)
= τxn ◦ . . . ◦ τx3 (x1x2\L)
...
= x1 . . . xn\L= x\L.
2. For any x , y ∈ {0, 1}∗:
[x ]'L= [y ]'L
⇔ x 'L y ⇔ x\L = y\L.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
I σ is a homomorphism:
[x ]'L
[ri (x)]'L= [xi ]'L
x\L
xi\L
σ
r̃i
σ
τi
τi ◦ σ = σ ◦ r̃i .
I Obviously, σ is a bijective map.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
In a similar way, we can treat L w.r.t. left concatenation as follows:
Definition: For a language L ⊆ {0, 1}∗ and any x ∈ {0, 1}∗, define:
L\x = {u ∈ {0, 1}∗ | ux ∈ L}.
It follows from the definition that for every x , y ∈ {0, 1}∗:
(L\x)\y = {u ∈ {0, 1}∗ | uy ∈ L\x}= {u ∈ {0, 1}∗ | uyx ∈ L}= L\(yx).
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Hence, for a language L ⊆ {0, 1}∗ the minimal pre-automaton w.r.t.left concatenation accepting L is N
L= (Q , q0 , τ0 , τ1) , where
1. QL = {L\x | x ∈ {0, 1}∗},
2. q0 = L\λ,
3. τi (L\x) = (L\x)\i = L\(ix). i = 0, 1.
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)
THEORY OF COMPUTATION (Automata as Algebras)
Example
L = {1 0n | n ∈ N}
L\λ = L
L\0 = L
L\0j = L j ∈ N
L\1 = {λ}
L\1 0j = {λ} j ∈ N
L\u = ∅
u 6= λ, u 6= 0j , 1 0j j ∈ N
Lstart
∅
{λ}1
0
0, 1
0, 1
THEORY OF COMPUTATION (Automata as Algebras), A. Daneshgar , (Slides prepared by Z. Ghafouri)