Theory of Computer Science
C4. Regular Languages: Minimal Automata, Closure Properties and Decidability
Gabriele R¨oger
University of Basel
March 27, 2019
Minimal Automata Closure Properties Decidability Summary
Overview
Automata &
Formal Languages
Languages
& Grammars
Regular Languages
Regular Grammars
DFAs
NFAs Regular Expressions
Pumping Lemma Minimal Automata Properties Context-free
Languages
Context-sensitive &
Type-0 Languages
Minimal Automata Closure Properties Decidability Summary
Minimal Automata
Minimal Automata Closure Properties Decidability Summary
Example
The following DFAs accept the same language:
q0 q1
q2
q3 0
1
0 1 0
1
0,1
q0 q1
q2
q3
q4 0
1
0
1
0 1
0 1
0,1
Question: What is the smallest DFA that accepts this language?
Minimal Automata Closure Properties Decidability Summary
Minimal Automaton: Definition
Definition
Aminimal automaton for a regular languageL is a DFAM =hQ,Σ, δ,q0,Ei with L(M) =L and aminimal number of states.
This means there is no DFAM0=hQ0,Σ, δ0,q00,E0i withL(M) =L(M0) and|Q0|<|Q|.
How to find a minimal automaton? Idea:
Start with any DFA that accepts the language. Merge states from which exactly the same words lead to an end state.
Minimal Automata Closure Properties Decidability Summary
Minimal Automaton: Definition
Definition
Aminimal automaton for a regular languageL is a DFAM =hQ,Σ, δ,q0,Ei with L(M) =L and aminimal number of states.
This means there is no DFAM0=hQ0,Σ, δ0,q00,E0i withL(M) =L(M0) and|Q0|<|Q|.
How to find a minimal automaton?
Idea:
Start with any DFA that accepts the language.
Merge states from which exactly the same words lead to an end state.
Minimal Automata Closure Properties Decidability Summary
Minimal Automaton: Algorithm
Input: DFAM
Input:
(without states that are unreachable from the start state) Output: list of states that have to be merged
Output:
to obtain an equivalent minimal automaton
1 Create table of all pairs of states {q,q0}with q 6=q0.
2 Mark all pairs {q,q0}with q ∈E and q0 ∈/ E.
3 If there is an unmarked pair {q,q0} where{δ(q,a), δ(q0,a)}
for somea∈Σ is already marked, then also mark {q,q0}.
4 Repeat the last step until there are no more changes.
5 All states in pairs that are still unmarked can be merged into one state.
Minimal Automata Closure Properties Decidability Summary
Minimal Automaton: Example
q0 q1
q2
q3
q4 0
1
0
1
0 1
0 1
0,1
q0 q1 q2 q3
q4 q3
q2 q1
States q0,q2 andq1,q3 can be merged into one state each.
Result: q0q2 q1q3 q4 0
1 0
1
0,1
Minimal Automata Closure Properties Decidability Summary
Minimal Automaton: Example
q0 q1
q2
q3
q4 0
1
0
1
0 1
0 1
0,1
q0 q1 q2 q3
q4 q3
q2 q1
States q0,q2 andq1,q3 can be merged into one state each.
Result: q0q2 q1q3 q4 0
1 0
1
0,1
Minimal Automata Closure Properties Decidability Summary
Minimal Automaton: Example
q0 q1
q2
q3
q4 0
1
0
1
0 1
0 1
0,1
q0 q1 q2 q3
q4 q3
q2 q1
× × × ×
States q0,q2 andq1,q3 can be merged into one state each.
Result: q0q2 q1q3 q4 0
1 0
1
0,1
Minimal Automata Closure Properties Decidability Summary
Minimal Automaton: Example
q0 q1
q2
q3
q4 0
1
0
1
0 1
0 1
0,1
q0 q1 q2 q3
q4 q3
q2 q1
× × × ×
States q0,q2 andq1,q3 can be merged into one state each.
Result: q0q2 q1q3 q4 0
1 0
1
0,1
Minimal Automata Closure Properties Decidability Summary
Minimal Automaton: Example
q0 q1
q2
q3
q4 0
1
0
1
0 1
0 1
0,1
q0 q1 q2 q3
q4 q3
q2 q1
× × × ×
×
States q0,q2 andq1,q3 can be merged into one state each.
Result: q0q2 q1q3 q4 0
1 0
1
0,1
Minimal Automata Closure Properties Decidability Summary
Minimal Automaton: Example
q0 q1
q2
q3
q4 0
1
0
1
0 1
0 1
0,1
q0 q1 q2 q3
q4 q3
q2 q1
× × × ×
×
×
×
×
States q0,q2 andq1,q3 can be merged into one state each.
Result: q0q2 q1q3 q4 0
1 0
1
0,1
Minimal Automata Closure Properties Decidability Summary
Minimal Automaton: Example
q0 q1
q2
q3
q4 0
1
0
1
0 1
0 1
0,1
q0 q1 q2 q3
q4 q3
q2 q1
× × × ×
×
×
×
×
States q0,q2 andq1,q3 can be merged into one state each.
Result: q0q2 q1q3 q4 0
1 0
1
0,1
Minimal Automata Closure Properties Decidability Summary
Minimal Automaton: Example
q0 q1
q2
q3
q4 0
1
0
1
0 1
0 1
0,1
q0 q1 q2 q3
q4 q3
q2 q1
× × × ×
×
×
×
×
States q0,q2 andq1,q3 can be merged into one state each.
Result: q0q2 q1q3 q4 0
1 0
1
0,1
Minimal Automata Closure Properties Decidability Summary
Computation and Uniqueness of Minimal Automata
Theorem
The algorithm described on the previous slides produces a minimal automaton for the language accepted by the given input DFA.
Theorem
All minimal automata for a language L are unique up to isomorphism (i.e., renaming of states).
Without proof.
Minimal Automata Closure Properties Decidability Summary
Questions
Questions?
Minimal Automata Closure Properties Decidability Summary
Overview
Automata &
Formal Languages
Languages
& Grammars
Regular Languages
Regular Grammars
DFAs
NFAs Regular Expressions
Pumping Lemma Minimal Automata Properties Context-free
Languages
Context-sensitive &
Type-0 Languages
Minimal Automata Closure Properties Decidability Summary
Closure Properties
Minimal Automata Closure Properties Decidability Summary
Closure Properties
How can you combine regular languages in a way to get
another regular language as a result?
Picture courtesy of stockimages / FreeDigitalPhotos.net
Minimal Automata Closure Properties Decidability Summary
Closure Properties: Operations
LetLand L0 be regular languages over Σ and Σ0, respectively.
We consider the following operations:
union L∪L0 ={w |w ∈Lor w ∈L0} over Σ∪Σ0
intersection L∩L0 ={w |w ∈Landw ∈L0} over Σ∩Σ0 complementL¯={w ∈Σ∗ |w ∈/ L}over Σ
product LL0={uv |u ∈L andv ∈L0} over Σ∪Σ0 special case: Ln=Ln−1L, whereL0={ε}
star L∗=S
k≥0Lk over Σ
German: Abschlusseigenschaften, Vereinigung, Schnitt, Komplement, German: Produkt, Stern
Minimal Automata Closure Properties Decidability Summary
Closure Properties
Definition (Closure)
LetK be a class of languages.
ThenK is closed. . .
. . . under union if L,L0 ∈ Kimplies L∪L0 ∈ K . . . under intersection if L,L0 ∈ Kimplies L∩L0 ∈ K . . . under complement ifL∈ Kimplies ¯L∈ K . . . under product if L,L0 ∈ KimpliesLL0 ∈ K . . . under star if L∈ K impliesL∗∈ K
German: Abgeschlossenheit,K ist abgeschlossen unter Vereinigung German: (Schnitt, Komplement, Produkt, Stern)
Minimal Automata Closure Properties Decidability Summary
Clourse Properties of Regular Languages
Theorem
The regular languages are closed under:
union intersection complement product star
Minimal Automata Closure Properties Decidability Summary
Closure Properties
Proof.
Closure underunion, product, and starfollows because for regular expressionsα andβ, the expressions
(α|β), (αβ) and (α∗) describe the corresponding languages.
Complement: LetM =hQ,Σ, δ,q0,Ei be a DFA withL(M) =L.
ThenM0 =hQ,Σ, δ,q0,Q\Eiis a DFA withL(M0) = ¯L.
Intersection: LetM1 =hQ1,Σ1, δ1,q01,E1i and
M2=hQ2,Σ2, δ2,q02,E2i be DFAs. The product automaton
M =hQ1×Q2,Σ1∩Σ2, δ,hq01,q02i,E1×E2i
with δ(hq1,q2i,a) =hδ1(q1,a), δ2(q2,a)i acceptsL(M) =L(M1)∩ L(M2).
German: Kreuzproduktautomat
Minimal Automata Closure Properties Decidability Summary
Closure Properties
Proof.
Closure underunion, product, and starfollows because for regular expressionsα andβ, the expressions
(α|β), (αβ) and (α∗) describe the corresponding languages.
Complement: Let M =hQ,Σ, δ,q0,Ei be a DFA withL(M) =L.
ThenM0 =hQ,Σ, δ,q0,Q\Eiis a DFA withL(M0) = ¯L.
Intersection: LetM1 =hQ1,Σ1, δ1,q01,E1i and
M2=hQ2,Σ2, δ2,q02,E2i be DFAs. The product automaton
M =hQ1×Q2,Σ1∩Σ2, δ,hq01,q02i,E1×E2i
with δ(hq1,q2i,a) =hδ1(q1,a), δ2(q2,a)i acceptsL(M) =L(M1)∩ L(M2).
German: Kreuzproduktautomat
Minimal Automata Closure Properties Decidability Summary
Closure Properties
Proof.
Closure underunion, product, and starfollows because for regular expressionsα andβ, the expressions
(α|β), (αβ) and (α∗) describe the corresponding languages.
Complement: Let M =hQ,Σ, δ,q0,Ei be a DFA withL(M) =L.
ThenM0 =hQ,Σ, δ,q0,Q\Eiis a DFA withL(M0) = ¯L.
Intersection: LetM1 =hQ1,Σ1, δ1,q01,E1i and
M2=hQ2,Σ2, δ2,q02,E2i be DFAs. The product automaton M =hQ1×Q2,Σ1∩Σ2, δ,hq01,q02i,E1×E2i
with δ(hq1,q2i,a) =hδ1(q1,a), δ2(q2,a)i acceptsL(M) =L(M1)∩ L(M2).
German: Kreuzproduktautomat
Minimal Automata Closure Properties Decidability Summary
Questions
Questions?
Minimal Automata Closure Properties Decidability Summary
Decidability
Minimal Automata Closure Properties Decidability Summary
Decision Problems and Decidability (1)
“Intuitive Definition:” Decision Problem, Decidability Adecision problemis an algorithmic problem where
for a given input
an algorithmdetermines if the input has a givenproperty and then produces the output“yes” or “no” accordingly.
A decision problem isdecidableif an algorithm for it (that always gives the correct answer) exists.
German: Entscheidungsproblem, Eingabe, Eigenschaft, Ausgabe, German: entscheidbar
Note: “exists”6= “is known”
Minimal Automata Closure Properties Decidability Summary
Decision Problems and Decidability (2)
Notes:
not a formal definition: we did not formally define
“algorithm”, “input”, “output” etc. (which is not trivial) lack of a formal definition makes it difficult to prove that something is notdecidable
studied thoroughly in the next part of the course
Minimal Automata Closure Properties Decidability Summary
Decision Problems: Example
For now we describe decision problems in a semi-formal
“given”/“question”way:
Example (Emptiness Problem for Regular Languages) Theemptiness problemP∅ for regular languages is the following problem:
Given: regular grammarG Question: Is L(G) =∅?
German: Leerheitsproblem
Minimal Automata Closure Properties Decidability Summary
Word Problem
Definition (Word Problem for Regular Languages) Theword problem P∈ for regular languages is:
Given: regular grammarG with alphabet Σ and word w ∈Σ∗
Question: Is w ∈ L(G)?
German: Wortproblem (f¨ur regul¨are Sprachen)
Minimal Automata Closure Properties Decidability Summary
Decidability: Word Problem
Theorem
The word problem for regular languages isdecidable.
Proof.
Construct a DFAM with L(M) =L(G).
(The proofs in Chapter C2 describe a possible method.) SimulateM on input w. The simulation ends after |w|steps.
The DFAM is an end state after this iff w ∈ L(G).
Print “yes” or “no” accordingly.
Minimal Automata Closure Properties Decidability Summary
Emptiness Problem
Definition (Emptiness Problem for Regular Languages) Theemptiness problemP∅ for regular languages is:
Given: regular grammarG Question: Is L(G) =∅?
German: Leerheitsproblem
Minimal Automata Closure Properties Decidability Summary
Decidability: Emptiness Problem
Theorem
The emptiness problem for regular languages isdecidable.
Proof.
Construct a DFAM with L(M) =L(G).
We haveL(G) =∅iff in the transition diagram of M there is no path from the start state to any end state.
This can be checked with standard graph algorithms (e.g., breadth-first search).
Minimal Automata Closure Properties Decidability Summary
Finiteness Problem
Definition (Finiteness Problem for Regular Languages) Thefiniteness problem P∞ for regular languagesis:
Given: regular grammarG Question: Is |L(G)|<∞?
German: Endlichkeitsproblem
Minimal Automata Closure Properties Decidability Summary
Decidability: Finiteness Problem
Theorem
The finiteness problem for regular languages isdecidable.
Proof.
Construct a DFAM with L(M) =L(G).
We have|L(G)|=∞iff in the transition diagram of M there is a cycle that is reachable from the start state and from which an end state can be reached.
This can be checked with standard graph algorithms.
Minimal Automata Closure Properties Decidability Summary
Intersection Problem
Definition (Intersection Problem for Regular Languages) Theintersection problem P∩ for regular languages is:
Given: regular grammars G andG0 Question: Is L(G)∩ L(G0) =∅?
German: Schnittproblem
Minimal Automata Closure Properties Decidability Summary
Decidability: Intersection Problem
Theorem
The intersection problem for regular languages isdecidable.
Proof.
Using the closure of regular languages under intersection, we can construct (e.g., by converting to DFAs, constructing the product automaton, then converting back to a grammar) a grammarG00 with L(G00) =L(G)∩ L(G0)
and use the algorithm for the emptiness problemP∅.
Minimal Automata Closure Properties Decidability Summary
Equivalence Problem
Definition (Equivalence Problem for Regular Languages) Theequivalence problemP= for regular languages is:
Given: regular grammars G andG0 Question: Is L(G) =L(G0)?
German: Aquivalenzproblem¨
Minimal Automata Closure Properties Decidability Summary
Decidability: Equivalence Problem
Theorem
The equivalence problem for regular languages isdecidable.
Proof.
In general for languagesLandL0, we have
L=L0 iff (L∩L¯0)∪(¯L∩L0) =∅.
The regular languages are closed under intersection, union and complement, and we know algorithms for these operations.
We can therefore construct a grammar for (L∩L¯0)∪(¯L∩L0) and use the algorithm for the emptiness problemP∅.
Minimal Automata Closure Properties Decidability Summary
Questions
Questions?
Minimal Automata Closure Properties Decidability Summary
Summary
Minimal Automata Closure Properties Decidability Summary
Summary
Minimal automata are the smallest possible DFAs for a given language and are unique for each language.
The regular languages are closed under all usual operations (union, intersection, complement, product, star).
All usual decision problems (word problem, emptiness, finiteness, intersection, equivalence) aredecidable for regular languages.