• Keine Ergebnisse gefunden

Theory of Computer Science C4. Regular Languages: Minimal Automata, Closure Properties and Decidability Gabriele R¨oger

N/A
N/A
Protected

Academic year: 2022

Aktie "Theory of Computer Science C4. Regular Languages: Minimal Automata, Closure Properties and Decidability Gabriele R¨oger"

Copied!
31
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Theory of Computer Science

C4. Regular Languages: Minimal Automata, Closure Properties and Decidability

Gabriele R¨ oger

University of Basel

March 27, 2019

(2)

Theory of Computer Science

March 27, 2019 — C4. Regular Languages: Minimal Automata, Closure Properties and Decidability

C4.1 Minimal Automata

C4.2 Closure Properties

C4.3 Decidability

(3)

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

(4)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Minimal Automata

C4.1 Minimal Automata

(5)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Minimal Automata

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?

(6)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Minimal Automata

Minimal Automaton: Definition

Definition

A minimal automaton for a regular language L is a DFA M = hQ , Σ, δ, q 0 , E i with L(M ) = L and a minimal number of states.

This means there is no DFA M 0 = hQ 0 , Σ, δ 0 , q 0 0 , E 0 i with L(M ) = L(M 0 ) and |Q 0 | < |Q |.

How to find a minimal automaton?

Idea:

I Start with any DFA that accepts the language.

I Merge states from which exactly the same words

lead to an end state.

(7)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Minimal Automata

Minimal Automaton: Algorithm

Input: DFA M

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, q 0 } with q 6= q 0 .

2

Mark all pairs {q, q 0 } with q ∈ E and q 0 ∈ / E .

3

If there is an unmarked pair {q, q 0 } where {δ(q, a), δ(q 0 , a)}

for some a ∈ Σ is already marked, then also mark {q, q 0 }.

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.

(8)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Minimal Automata

Minimal Automaton: Example

q0 q1

q2

q3

q4 0

1

0

1

0 1

0 1

0,1

q 0 q 1 q 2 q 3 q 4

q 3 q 2

q 1

× × × ×

×

×

×

×

States q 0 , q 2 and q 1 , q 3 can be merged into one state each.

Result:

q0q2 q1q3 q4 0

1 0

1

0,1

(9)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Minimal Automata

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.

(10)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Minimal Automata

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

(11)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Closure Properties

C4.2 Closure Properties

(12)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Closure Properties

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

(13)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Closure Properties

Closure Properties: Operations

Let L and L 0 be regular languages over Σ and Σ 0 , respectively.

We consider the following operations:

I union L ∪ L 0 = {w | w ∈ L or w ∈ L 0 } over Σ ∪ Σ 0

I intersection L ∩ L 0 = {w | w ∈ L and w ∈ L 0 } over Σ ∩ Σ 0

I complement L ¯ = {w ∈ Σ | w ∈ / L} over Σ

I product LL 0 = {uv | u ∈ L and v ∈ L 0 } over Σ ∪ Σ 0

I

special case: L

n

= L

n−1

L, where L

0

= {ε}

I star L = S

k≥0 L k over Σ

German: Abschlusseigenschaften, Vereinigung, Schnitt, Komplement,

German: Produkt, Stern

(14)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Closure Properties

Closure Properties

Definition (Closure)

Let K be a class of languages.

Then K is closed. . .

I . . . under union if L, L 0 ∈ K implies L ∪ L 0 ∈ K

I . . . under intersection if L, L 0 ∈ K implies L ∩ L 0 ∈ K

I . . . under complement if L ∈ K implies ¯ L ∈ K

I . . . under product if L, L 0 ∈ K implies LL 0 ∈ K

I . . . under star if L ∈ K implies L ∈ K

German: Abgeschlossenheit, K ist abgeschlossen unter Vereinigung

German: (Schnitt, Komplement, Produkt, Stern)

(15)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Closure Properties

Clourse Properties of Regular Languages

Theorem

The regular languages are closed under:

I union

I intersection

I complement

I product

I star

(16)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Closure Properties

Closure Properties

Proof.

Closure under union, product, and star follows because for regular expressions α and β, the expressions

(α|β), (αβ) and (α ) describe the corresponding languages.

Complement: Let M = hQ, Σ, δ, q 0 , E i be a DFA with L(M ) = L.

Then M 0 = hQ , Σ, δ, q 0 , Q \ E i is a DFA with L(M 0 ) = ¯ L.

Intersection: Let M 1 = hQ 1 , Σ 1 , δ 1 , q 01 , E 1 i and

M 2 = hQ 2 , Σ 2 , δ 2 , q 02 , E 2 i be DFAs. The product automaton M = hQ 1 × Q 2 , Σ 1 ∩ Σ 2 , δ, hq 01 , q 02 i, E 1 × E 2 i

with δ(hq 1 , q 2 i, a) = hδ 1 (q 1 , a), δ 2 (q 2 , a)i accepts L(M ) = L(M 1 ) ∩ L(M 2 ).

German: Kreuzproduktautomat

(17)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

C4.3 Decidability

(18)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Decision Problems and Decidability (1)

“Intuitive Definition:” Decision Problem, Decidability A decision problem is an algorithmic problem where

I for a given input

I an algorithm determines if the input has a given property

I and then produces the output “yes” or “no” accordingly.

A decision problem is decidable if an algorithm for it (that always gives the correct answer) exists.

German: Entscheidungsproblem, Eingabe, Eigenschaft, Ausgabe, German: entscheidbar

Note: “exists” 6= “is known”

(19)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Decision Problems and Decidability (2)

Notes:

I not a formal definition: we did not formally define

“algorithm”, “input”, “output” etc. (which is not trivial)

I lack of a formal definition makes it difficult to prove that something is not decidable

studied thoroughly in the next part of the course

(20)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Decision Problems: Example

For now we describe decision problems in a semi-formal

“given”/“question” way:

Example (Emptiness Problem for Regular Languages) The emptiness problem P ∅ for regular languages is the following problem:

Given: regular grammar G Question: Is L(G ) = ∅?

German: Leerheitsproblem

(21)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Word Problem

Definition (Word Problem for Regular Languages) The word problem P ∈ for regular languages is:

Given: regular grammar G with alphabet Σ and word w ∈ Σ

Question: Is w ∈ L(G )?

German: Wortproblem (f¨ ur regul¨ are Sprachen)

(22)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Decidability: Word Problem

Theorem

The word problem for regular languages is decidable.

Proof.

Construct a DFA M with L(M) = L(G ).

(The proofs in Chapter C2 describe a possible method.) Simulate M on input w . The simulation ends after |w | steps.

The DFA M is an end state after this iff w ∈ L(G ).

Print “yes” or “no” accordingly.

(23)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Emptiness Problem

Definition (Emptiness Problem for Regular Languages) The emptiness problem P ∅ for regular languages is:

Given: regular grammar G Question: Is L(G ) = ∅?

German: Leerheitsproblem

(24)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Decidability: Emptiness Problem

Theorem

The emptiness problem for regular languages is decidable.

Proof.

Construct a DFA M with L(M) = L(G ).

We have L(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).

(25)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Finiteness Problem

Definition (Finiteness Problem for Regular Languages) The finiteness problem P ∞ for regular languages is:

Given: regular grammar G Question: Is |L(G )| < ∞?

German: Endlichkeitsproblem

(26)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Decidability: Finiteness Problem

Theorem

The finiteness problem for regular languages is decidable.

Proof.

Construct a DFA M 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.

(27)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Intersection Problem

Definition (Intersection Problem for Regular Languages) The intersection problem P ∩ for regular languages is:

Given: regular grammars G and G 0 Question: Is L(G ) ∩ L(G 0 ) = ∅?

German: Schnittproblem

(28)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Decidability: Intersection Problem

Theorem

The intersection problem for regular languages is decidable.

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 grammar G 00 with L(G 00 ) = L(G ) ∩ L(G 0 )

and use the algorithm for the emptiness problem P .

(29)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Equivalence Problem

Definition (Equivalence Problem for Regular Languages) The equivalence problem P = for regular languages is:

Given: regular grammars G and G 0 Question: Is L(G ) = L(G 0 )?

German: Aquivalenzproblem ¨

(30)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Decidability

Decidability: Equivalence Problem

Theorem

The equivalence problem for regular languages is decidable.

Proof.

In general for languages L and L 0 , we have

L = L 0 iff (L ∩ L ¯ 0 ) ∪ (¯ L ∩ L 0 ) = ∅.

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 ∩ L 0 )

and use the algorithm for the emptiness problem P .

(31)

C4. Regular Languages: Minimal Automata, Closure Properties

and Decidability Summary

Summary

I Minimal automata are the smallest possible DFAs for a given language and are unique for each language.

I The regular languages are closed under all usual operations (union, intersection, complement, product, star).

I All usual decision problems (word problem, emptiness,

finiteness, intersection, equivalence) are decidable

for regular languages.

Referenzen

ÄHNLICHE DOKUMENTE

I All usual decision problems (word problem, emptiness, finiteness, intersection, equivalence) are decidable for

GNFAs are like NFAs but the transition labels can be arbitrary regular expressions over the input alphabet. q 0

I DFAs, NFAs and regular grammars can all describe exactly the regular languages.. I Are there other concepts with the

Picture courtesy of imagerymajestic / FreeDigitalPhotos.net Gabriele R¨ oger (University of Basel) Theory of Computer Science March 31, 2021 4 / 26... Closure under

The languages that can be recognized by linear bounded automata are exactly the context-sensitive (type-1) languages..

Pumping Lemma Minimal Automata Properties

Pumping Lemma Minimal Automata Properties

All usual decision problems (word problem, emptiness, finiteness, intersection, equivalence) are decidable for