• Keine Ergebnisse gefunden

B4. Regular Languages: Closure Properties and Decidability

N/A
N/A
Protected

Academic year: 2022

Aktie "B4. Regular Languages: Closure Properties and Decidability"

Copied!
9
0
0

Wird geladen.... (Jetzt Volltext ansehen)

Volltext

(1)

Theory of Computer Science

B4. Regular Languages: Closure Properties and Decidability

Gabriele R¨ oger

University of Basel

March 17, 2021

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 1 / 36

Theory of Computer Science

March 17, 2021 — B4. Regular Languages: Closure Properties and Decidability

B4.1 Introduction

B4.2 Closure Properties B4.3 Decidability

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 2 / 36

B4. Regular Languages: Closure Properties and Decidability Introduction

B4.1 Introduction

B4. Regular Languages: Closure Properties and Decidability Introduction

Further Analysis

We can convert freely between regular grammars, DFAs and NFAs.

So don’t let’s analyse them individually but instead focus on the corresponding class of regular languages:

I With what operations can we “combine” regular languages and the result is again a regular language?

E.g. is the intersection of two regular languages regular?

I What general questions can we resolve algorithmically for any regular language?

E.g. is there an algorithm that takes a regular grammars and a word as input and returns whether the word is in the

generated language?

(2)

B4.2 Closure Properties

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 5 / 36

Closure Properties

How can we combine regular languages so that the result is guaranteed

to be regular as well?

Picture courtesy of stockimages / FreeDigitalPhotos.net

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 6 / 36

B4. Regular Languages: Closure Properties and Decidability Closure Properties

Concatenation of Languages

Concatenation

I For two languages L 1 (over Σ 1 ) and L 2 (over Σ 2 ), the concatenation of L 1 and L 2 is the language

L 1 L 2 = {w 1 w 2 ∈ (Σ 1 ∪ Σ 2 ) | w 1 ∈ L 1 , w 2 ∈ L 2 }.

I L 1 = {Pancake, Waffle}

L 2 = {withIceCream, withMushrooms, withCheese}

L 1 L 2 =

German: Produkt

B4. Regular Languages: Closure Properties and Decidability Closure Properties

Kleene Star

Kleene star

I For language L define I L

0

= {ε}

I L

1

= L

I L

i+1

= L

i

L for i ∈ N

>0

I Definition of (Kleene) star on L: L = S

i≥0 L i .

I L = {ding, dong}

L =

German: (Kleen)-Stern

(3)

Set Operations

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

Languages are just sets of words, so we can also consider the standard set 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 Σ

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 9 / 36

Closure Properties

General terminology: What do we mean with closure?

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 concatenation 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)

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 10 / 36

B4. Regular Languages: Closure Properties and Decidability Closure Properties

Closure Properties of Regular Languages: Union

Theorem

The regular languages are closed under union.

Proof idea:

q0 q1 q2

0 1

0 1

0

1

z0 ε z1 z2 z3

ε 0 0,1

0 ε

ε

B4. Regular Languages: Closure Properties and Decidability Closure Properties

Closure Properties of Regular Languages: Union

Proof.

Let L 1 , L 2 be regular languages.

Let M 1 = hQ 1 , Σ 1 , δ 1 , q 1 , F 1 i and M 2 = hQ 2 , Σ 2 , δ 2 , q 2 , F 2 i be NFAs with L(M 1 ) = L 1 and L(M 2 ) = L 2 . W.l.o.g. Q 1 ∩ Q 2 = ∅.

Then NFA M = hQ, Σ 1 ∪ Σ 2 , δ, q 0 , F 1 ∪ F 2 i with I q 0 6∈ Q 1 ∪ Q 2 and

I Q = {q 0 } ∪ Q 1 ∪ Q 2 ,

I for all q ∈ Q, a ∈ Σ 1 ∪ Σ 2 ∪ {ε}

δ(q, a) =

 

 

 

 

δ 1 (q, a) if q ∈ Q 1 and a ∈ Σ 1 ∪ {ε}

δ 2 (q, a) if q ∈ Q 2 and a ∈ Σ 2 ∪ {ε}

{q 1 , q 2 } if q = q 0 and a = ε

∅ otherwise

recognizes L 1 ∪ L 2 .

(4)

Closure Properties of Regular Languages: Concatenation

The proof idea for the closure under

concatenation is very similar to the one for union.

Can you figure it out yourself?

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 13 / 36

Closure Properties of Regular Languages: Concatenation

Theorem

The regular languages are closed under concatenation.

Proof idea:

q0 qq11 qq22

0 1

0 1

1 0

z0 ε z1 z2 z3

ε 0 0,1 ε 0

ε

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 14 / 36

B4. Regular Languages: Closure Properties and Decidability Closure Properties

Closure Properties of Regular Languages: Concatenation

Proof.

Let L 1 , L 2 be regular languages.

Let M 1 = hQ 1 , Σ 1 , δ 1 , q 1 , F 1 i and M 2 = hQ 2 , Σ 2 , δ 2 , q 2 , F 2 i be NFAs with L(M 1 ) = L 1 and L(M 2 ) = L 2 . W.l.o.g. Q 1 ∩ Q 2 = ∅.

Then NFA M = hQ 1 ∪ Q 2 , Σ 1 ∪ Σ 2 , δ, q 1 , F 2 i with I for all q ∈ Q, a ∈ Σ 1 ∪ Σ 2 ∪ {ε}

δ(q, a) =

 

 

 

 

 

 

δ 1 (q, a) if q ∈ Q 1 \ F 1 and a ∈ Σ 1 ∪ {ε}

δ 1 (q, a) if q ∈ F 1 and a ∈ Σ 1 δ 1 (q, a) ∪ {q 2 } if q ∈ F 1 and a = ε

δ 2 (q, a) if q ∈ Q 2 and a ∈ Σ 2 ∪ {ε}

∅ otherwise

recognizes L 1 L 2 .

B4. Regular Languages: Closure Properties and Decidability Closure Properties

Closure Properties of Regular Languages: Star

Theorem

The regular languages are closed under star.

Proof idea:

q0 q1 q2

0 1

0 1 0 1,ε 1,1ε q0 ε

(5)

Closure Properties of Regular Languages: Star

Proof.

Let L be a regular language.

Let M = hQ, Σ, δ, q 0 , F i be an NFA with L(M) = L.

Then NFA M 0 = hQ 0 , Σ, δ 0 , q 0 0 , F ∪ {q 0 }i with I q 0 0 6∈ Q,

I Q 0 = Q ∪ {q 0 0 }, and I for all q ∈ Q 0 , a ∈ Σ ∪ {ε}

δ 0 (q, a) =

 

 

 

 

 

 

δ(q, a) if q ∈ Q \ F

δ(q, a) if q ∈ F and a ∈ Σ

δ(q, a) ∪ {q 0 } if q ∈ F and a = ε {q 0 } if q = q 0 0 and a = ε

∅ otherwise

recognizes L .

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 17 / 36

Closure Properties of Regular Languages: Complement

Theorem

The regular languages are closed under complement.

Proof.

Let L be a regular language.

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

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

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 18 / 36

B4. Regular Languages: Closure Properties and Decidability Closure Properties

Closure Properties of Regular Languages: Intersection

Theorem

The regular languages are closed under intersection.

Proof.

Let L 1 , L 2 be regular languages.

Let M 1 = hQ 1 , Σ 1 , δ 1 , q 01 , F 1 i and M 2 = hQ 2 , Σ 2 , δ 2 , q 02 , F 2 i be DFAs with L(M 1 ) = L 1 and L(M 2 ) = L 2 .

The product automaton

M = hQ 1 × Q 2 , Σ 1 ∩ Σ 2 , δ, hq 01 , q 02 i, F 1 × F 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

B4. Regular Languages: Closure Properties and Decidability Closure Properties

Product Automaton: Example

q0

q1 q2

0 1

0 1

0 1

r s

0,1,2

0,1,2

(6)

Closure Properties of Regular Languages

In summary. . . Theorem

The regular languages are closed under:

I union I intersection I complement I concatenation I star

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 21 / 36

B4.3 Decidability

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 22 / 36

B4. Regular Languages: 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 terminates and gives the correct answer) exists.

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

Note: “exists” 6= “is known”

B4. Regular Languages: 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

(7)

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

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 25 / 36

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)

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 26 / 36

B4. Regular Languages: 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 B3 describe a possible method.) Simulate M on input w. The simulation ends after |w | steps.

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

Print “yes” or “no” accordingly.

B4. Regular Languages: 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

(8)

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 accept state.

This can be checked with standard graph algorithms (e.g., breadth-first search).

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 29 / 36

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

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 30 / 36

B4. Regular Languages: 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 accept state can be reached.

This can be checked with standard graph algorithms.

B4. Regular Languages: 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

(9)

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 .

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 33 / 36

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 ¨

Gabriele R¨oger (University of Basel) Theory of Computer Science March 17, 2021 34 / 36

B4. Regular Languages: 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 .

B4. Regular Languages: Closure Properties and Decidability Summary

Summary

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

I All usual decision problems (word problem, emptiness,

finiteness, intersection, equivalence) are decidable

for regular languages.

Referenzen

ÄHNLICHE DOKUMENTE

So don’t let’s analyse them individually but instead focus on the corresponding class of regular languages:.. With what operations can we “combine” regular languages and the result

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

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

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

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

The word problem, emptiness problem and finiteness problem for the class of context-free languages are decidable. The equivalence problem and intersection problem for the class