Chapter 1

Regular Languages

[46/52%]
Show
LaTeX
Example 1.1

How many strings over the alphabet A={a1,a2,…,ak}A=\left\{ a_{1}, a_{2}, \ldots , a_{k}\right\} are there which are of length nn, where nn is a nonnegative integer?

?
Example 1.2

For strings xx and y,(xy)R=yRxRy,(x y)^{R}=y^{R} x^{R}.

?
Example 1.3

Solve the word equation

x011=011x x 011=011 x

over the alphabet {0,1}\left\{ 0,1\right\}; that is, find the set of strings xx over {0,1}\left\{ 0,1\right\} which satisfy the equation.

?
Example 1.4
?
(a)

Let A={0,1}A=\left\{ 0,1\right\} and B={1,2}B=\left\{ 1,2\right\}. Find then AB={01,02,11,12}A B=\left\{ 01,02,11,12\right\}.

(b)

Is it true that if AA is of size n≥0n \geq 0 and BB is of size m≥0m \geq 0 then ABA B must be of size nmn m?

(c)

Let A={(01)n∣n≥0}A=\left\{ (01)^{n} \mid n \geq 0\right\} and B={01,010}B=\left\{ 01,010\right\}. Find ABAB, ABAABA.

Example 1.5

The language {0,10}∗\left\{ 0,10\right\}^{*} is the set of all binary strings having no substring 11 and ending with 0.

?
Example 1.6

Show that for any languages AA and BB,

(A∪B)∗=A∗(BA∗)∗ (A \cup B)^{*}=A^{*}\left(B A^{*}\right)^{*}
?
Example 1.7

A+=A∗A^{+}=A^{*} if and only if ε∈A\varepsilon \in A.

?
Example 1.8

For languages AA and B,(AB)R=BRARB,(A B)^{R}=B^{R} A^{R} and (A∪B)R=AR∪BR(A \cup B)^{R}= A^{R} \cup B^{R}.

?
Example 1.9

(Arden's Lemma). Assume that A,BA, B are two languages with ε∉A\varepsilon \notin A, and XX is a language satisfying the relation X=AX∪BX=A X \cup B. Then, X=A∗BX=A^{*} B.

?
Example 1.10

Assume that languages A,B⊆{a,b}∗A, B \subseteq \left\{ a, b\right\}^{*} satisfy the following two equations:

A={ε}∪{a}A∪{b}B,B={ε}∪{b}B. \begin{aligned} & A=\left\{ \varepsilon \right\} \cup \left\{ a\right\} A \cup \left\{ b\right\} B, \\ & B=\left\{ \varepsilon \right\} \cup \left\{ b\right\} B. \end{aligned}

Find simple representations for AA and BB.

?
Problem 1.1.1

Let A={ grand, ε}A=\left\{ \text{ grand, }\varepsilon \right\} and B={ mother, father }B=\left\{ \text{ mother, father }\right\}. What are ABA B and A∗BA^{*} B?

?
Problem 1.1.2

Let AA be a language over {a,b}\left\{ a, b\right\} and x∈{a,b}∗x \in \left\{ a, b\right\}^{*}. Find necessary and sufficient conditions in terms of xx and AA for the equation

A∗−{x}=A+ A^{*}-\left\{ x\right\} =A^{+}
?
Problem 1.1.3

For each of the following equations, determine whether it is true for all languages A,BA, B or not. Present a proof or a counterexample.

?
(a)

(AR)∗=(A∗)R\left(A^{R}\right)^{*}=\left(A^{*}\right)^{R}.

(b)

(A+)∗=A∗\left(A^{+}\right)^{*}=A^{*}.

(c)

(A∪AR)∗=A∗∪(A∗)R\left(A \cup A^{R}\right)^{*}=A^{*} \cup \left(A^{*}\right)^{R}.

(d)

A2∪B2=(A∪B)2A^{2} \cup B^{2}=(A \cup B)^{2}.

(e)

A∗∩B∗=(A∩B)∗A^{*} \cap B^{*}=(A \cap B)^{*}.

Problem 1.1.4
?
(a)

Show that, for k≥1,⋃i=0kAi=({ε}∪A)kk \geq 1, \bigcup_{i=0}^{k} A^{i}=(\left\{ \varepsilon \right\} \cup A)^{k}.

(b)

Show that, for n≥1,(A∗)n=A∗n \geq 1,\left(A^{*}\right)^{n}=A^{*}.

(c)

Assume that ε∉A\varepsilon \notin A. Show that, for n≥1,(A+)n=AnA∗n \geq 1,\left(A^{+}\right)^{n}=A^{n} A^{*}.

Problem 1.1.5

Prove the following identities on languages A,B,C,DA, B, C, D :

?
(a)

A(BA)∗=(AB)∗AA(B A)^{*}=(A B)^{*} A.

(b)

(A∪B)∗=(A∗B∗)∗(A \cup B)^{*}=\left(A^{*} B^{*}\right)^{*}.

(c)

A(B∪C)=AB∪ACA(B \cup C)=A B \cup A C.

(d)

(A∪B)C=AC∪BC(A \cup B) C=A C \cup B C.

(e)

A∗B(DA∗B∪C)∗=(A∪BC∗D)∗BC∗A^{*} B\left(D A^{*} B \cup C\right)^{*}=\left(A \cup B C^{*} D\right)^{*} B C^{*}.

Problem 1.1.6

Find the shortest string over alphabet {0}\left\{ 0\right\} which is not in {ε,0,02,05}3\left\{ \varepsilon , 0,0^{2}, 0^{5}\right\}^{3}

?
Problem 1.1.7

Find the general solutions for the equation

xy=yx x y=y x

for x,y∈{0,1}∗x, y \in \left\{ 0,1\right\}^{*}.

?
Problem 1.1.8

Solve the following language equations for languages A,B,C⊆{a,b}∗A, B, C \subseteq \left\{ a, b\right\}^{*} :

A={a}C∪{b}BB={ε}∪{b}A∪{a}CC={ε}∪{a}A \begin{aligned} A & =\left\{ a\right\} C \cup \left\{ b\right\} B \\ B & =\left\{ \varepsilon \right\} \cup \left\{ b\right\} A \cup \left\{ a\right\} C \\ C & =\left\{ \varepsilon \right\} \cup \left\{ a\right\} A \end{aligned}
?
Example 1.11
?
(a)

Is the set {ε}\left\{ \varepsilon \right\} a regular language?

(b)

Is the set {001,110}\left\{ 001,110\right\} a regular language over the binary alphabet?

Example 1.12

a∗(a+b)∗=(a+ba∗)∗a^{*}(a+b)^{*}=\left(a+b a^{*}\right)^{*}.

?
Example 1.13

(ba)+(a∗b∗+a∗)=(ba)∗ba+b∗(ba)^{+}\left(a^{*} b^{*}+a^{*}\right)=(b a)^{*} b a^{+} b^{*}.

?
Example 1.14

Find a regular expression for the set of binary expansions of integers which are the powers of 4.

?
Example 1.15

Find a regular expression for the set of binary strings which have at least one occurrence of the substring 001.

?
Example 1.16

Find a regular expression for the set AA of binary strings which have no substring 001.

?
Example 1.17

Find a regular expression for the set BB of all binary strings with at most one pair of consecutive 0's and at most one pair of consecutive 1's.

?
Example 1.18

Find a regular expression for the set of all binary strings with the property that none of its prefixes has two more 0 's than 1 's nor two more 1's than 0 's.

?
Example 1.19

Find a regular expression for the set of all nonempty strings having no repeated adjacent symbols over the arabic digits.

?
Example 1.20

Find a regular expression for the set of all strings over alphabet

{[000],[100],[010],[001],[110],[101],[011],[111]} \left\{ \left[\begin{smallmatrix} 0 \\ 0 \\ 0 \end{smallmatrix}\right],\left[\begin{smallmatrix} 1 \\ 0 \\ 0 \end{smallmatrix}\right],\left[\begin{smallmatrix} 0 \\ 1 \\ 0 \end{smallmatrix}\right],\left[\begin{smallmatrix} 0 \\ 0 \\ 1 \end{smallmatrix}\right],\left[\begin{smallmatrix} 1 \\ 1 \\ 0 \end{smallmatrix}\right],\left[\begin{smallmatrix} 1 \\ 0 \\ 1 \end{smallmatrix}\right],\left[\begin{smallmatrix} 0 \\ 1 \\ 1 \end{smallmatrix}\right],\left[\begin{smallmatrix} 1 \\ 1 \\ 1 \end{smallmatrix}\right]\right\}

that represent correct additions over binary expansions of integers, with leading 0 's added when necessary. For example, the relation

0110+01011011 \begin{array}{r} 0110 \\ +\quad 0101 \\ \hline 1011 \end{array}

implies that the string

[001][110][101][011] \left[\begin{smallmatrix} 0 \\ 0 \\ 1 \end{smallmatrix}\right]\left[\begin{smallmatrix} 1 \\ 1 \\ 0 \end{smallmatrix}\right]\left[\begin{smallmatrix} 1 \\ 0 \\ 1 \end{smallmatrix}\right]\left[\begin{smallmatrix} 0 \\ 1 \\ 1 \end{smallmatrix}\right]

is in the set.

?
Example 1.21

For each language LL over alphabet Σ\Sigma, let L′L^{\prime } be the set of all suffixes of strings in LL, that is, L′={w∣uw∈L for some string u}L^{\prime }=\left\{ w \mid u w \in L\text{ for some string }u\right\}. Show that if LL is a regular language so is L′L^{\prime }.

?
Example 1.22

Show that every regular language has a regular expression in disjunctive normal form α1+α2+⋯+αn\alpha_{1}+\alpha_{2}+\cdots +\alpha_{n}, in which each αi\alpha_{i}, for i=1,2,⋯ ,ni=1,2, \cdots , n, does not contain the operator + .

?
Problem 1.2.1

Describe in English the languages expressed by the following regular expressions:

?
(a)

(0∗1∗)∗0\left(0^{*} 1^{*}\right)^{*} 0.

(b)

(01∗)∗0\left(01^{*}\right)^{*} 0.

(c)

(00+11+(01+10)(00+11)∗(01+10))∗\left(00+11+(01+10)(00+11)^{*}(01+10)\right)^{*}.

(d)

0∗+(0∗1+0∗11)(0+1+0+11)∗0∗0^{*}+\left(0^{*} 1+0^{*} 11\right)\left(0^{+} 1+0^{+} 11\right)^{*} 0^{*}.

Problem 1.2.2

Simplify the following regular expressions:

?
(a)

(00)∗0+(00)∗(00)^{*} 0+(00)^{*}.

(b)

(0+1)(ε+00)++(0+1)(0+1)(\varepsilon +00)^{+}+(0+1).

(c)

(0+ε)0∗1(0+\varepsilon ) 0^{*} 1.

Problem 1.2.3

Construct regular expressions for the following languages over alphabet {0,1}\left\{ 0,1\right\} :

?
(a)

The set of all strings whose fifth symbol from right is 0.

(b)

The set of all strings having either 000 or 111 as a substring.

(c)

The set of all strings having neither 000 nor 111 as a substring.

(d)

The set of all strings having no substring 010.

(e)

The set of all strings having an odd number of 0 's.

(f)

The set of all strings having an even number of occurrences of substring 011. [Hint: First find the regular expression for the set of binary strings having no substring 011.]

Problem 1.2.4

Show that (02+03)∗=(020∗)∗\left(0^{2}+0^{3}\right)^{*}=\left(0^{2} 0^{*}\right)^{*}.

?
Problem 1.2.5

Construct a regular expression for the set of all strings over alphabet

{[000],[100],[010],[001],[110],[101],[011],[111]} \left\{ \left[\begin{smallmatrix} 0 \\ 0 \\ 0 \end{smallmatrix}\right],\left[\begin{smallmatrix} 1 \\ 0 \\ 0 \end{smallmatrix}\right],\left[\begin{smallmatrix} 0 \\ 1 \\ 0 \end{smallmatrix}\right],\left[\begin{smallmatrix} 0 \\ 0 \\ 1 \end{smallmatrix}\right],\left[\begin{smallmatrix} 1 \\ 1 \\ 0 \end{smallmatrix}\right],\left[\begin{smallmatrix} 1 \\ 0 \\ 1 \end{smallmatrix}\right],\left[\begin{smallmatrix} 0 \\ 1 \\ 1 \end{smallmatrix}\right],\left[\begin{smallmatrix} 1 \\ 1 \\ 1 \end{smallmatrix}\right]\right\}

that represent correct subtractions. For example,

101110−010010110 \begin{array}{rrrr} 1011 & 10 \\ - & 01001 \\ \hline 0110 \end{array}

implies that string

[100][011][101][110] \left[\begin{smallmatrix} 1 \\ 0 \\ 0 \end{smallmatrix}\right]\left[\begin{smallmatrix} 0 \\ 1 \\ 1 \end{smallmatrix}\right]\left[\begin{smallmatrix} 1 \\ 0 \\ 1 \end{smallmatrix}\right]\left[\begin{smallmatrix} 1 \\ 1 \\ 0 \end{smallmatrix}\right]

is in the set.

?
Problem 1.2.6

Show that for any regular language L,Lodd={x∈L∣∣x∣=odd}L, L_{\text{odd}}=\left\{ x \in L \mid \left|x\right|=\text{odd}\right\} and Leven={x∈L∣∣x∣=even}L_{\text{even}}=\left\{ x \in L \mid \left|x\right|=\text{even}\right\} are regular.

?
Problem 1.2.7

Show that if LL is a regular language, then L′′={u∣∃v,uv∈L}L^{\prime \prime }=\left\{ u \mid \exists v, u v \in L\right\} is regular.

?
Problem 1.2.8

Suppose h:Σ∗→Γ∗h: \Sigma^{*} \rightarrow \Gamma^{*} is a mapping satisfying h(xy)=h(x)h(y)h(x y)=h(x) h(y) for any x,y∈Σ∗x, y \in \Sigma^{*}. Show that if AA is a regular set over Σ\Sigma, then h(A)={h(x)∣x∈A}h(A)=\left\{ h(x) \mid x \in A\right\} is a regular set over Γ\Gamma. Conversely, if BB is a regular set over Γ\Gamma, then h−1(B)={x∈Σ∗∣h(x)∈B}h^{-1}(B)=\left\{ x \in \Sigma^{*} \mid h(x) \in B\right\} is a regular set over Σ\Sigma.

?
Example 1.24

Construct G(r)G(r) for r=(11+0)∗(00+1)∗r=(11+0)^{*}(00+1)^{*}.

?
Example 1.26

Construct G(r)G(r) for r=a∗b(c+da∗b)∗r=a^{*} b\left(c+d a^{*} b\right)^{*}.

?
Problem 1.3.1

What is the shortest string in each of the following languages? What is the shortest nonempty string in each language?

?
(a)

10+(0+11)0∗110+(0+11) 0^{*} 1.

(b)

(00+11+(01+10)(00+11)∗(01+10))∗\left(00+11+(01+10)(00+11)^{*}(01+10)\right)^{*}.

(c)

((00+11)∗+(001+110)∗)∗\left((00+11)^{*}+(001+110)^{*}\right)^{*}.

Problem 1.3.2
?
(a)

Find an algorithm to find a shortest string in a regular set with a given regular expression.

(b)

Find an algorithm to find a shortest string in a regular set with a given graph representation of a regular expression.

Problem 1.3.3

Find labeled digraph representations for the following regular expressions:

?
(a)

(00+10)(101)∗+01(00+10)(101)^{*}+01.

(b)

((00+11)∗+(001+110)∗)∗\left((00+11)^{*}+(001+110)^{*}\right)^{*}.

(c)

(a+bc∗d)∗bc∗\left(a+b c^{*} d\right)^{*} b c^{*}.

Problem 1.3.4

Determine the regular expressions represented by digraphs in Figure 1.7.

Figure 1.7: Three digraphs for Exercise 4.Figure 1.7: Three digraphs for Exercise 4.

?
Problem 1.3.5

Find the simplest digraph representing ε\varepsilon.

?
Problem 1.3.6

Find counterexamples to show that Theorem 1.25 is incorrect if we remove the requirements that uu must be a nonfinal vertex and vv must be a noninitial vertex.

Theorem 1.25: Let rr be a regular expression. Then, an ε\varepsilon-edge (u,v)(u, v) in G(r)G(r) which is a unique out-edge from a nonfinal vertex uu or a unique in-edge to a noninitial vertex vv can be shrunk into a single vertex, still preserving the property of Theorem 1.23. (If one of the endpoints of the ε\varepsilon-edge is the initial vertex or the final vertex, then so is the resulting vertex.)

?