Chapter 2

Finite Automata

[102/59%]
Show
LaTeX
Example 2.1

Consider a DFA M=(Q,Σ,δ,q0,F)M=\left(Q, \Sigma , \delta , q_{0}, F\right) where Q={q0,q1,q2, q3},Σ={0,1},F={q1,q2}Q=\left\{ q_{0}, q_{1}, q_{2}\text{, }q_{3}\right\} , \Sigma =\left\{ 0,1\right\} , F=\left\{ q_{1}, q_{2}\right\}, and δ\delta is the function defined by the following table:

δ\delta01
q0q_{0}q1q_{1}q3q_{3}
q1q_{1}q2q_{2}q3q_{3}
q2q_{2}q2q_{2}q2q_{2}
q3q_{3}q3q_{3}q3q_{3}

Draw the transition diagram of MM.

?
Example 2.2

Consider the DFA MM given by Figure 2.2 Determine whether MM accepts strings 000 and 010.

?
Example 2.3

What is the language L(M)L(M) accepted by the DFAMD F A M of Figure 2.2?

?
Example 2.4

What is the language L(M)L(M) accepted by the DFA MM of Figure 2.3?

?
Example 2.5

What is the language L(M)L(M) accepted by the DFAMD F A M of Figure 2.4?

?
Problem 2.1.1

Consider the DFA MM with the transition diagram of Figure 2.5.

?
(a)

Which state is the initial state of MM, and which states are the final states of MM?

(b)

For each of the strings 0001, 010101, and 001110101101, find the computation path of MM on the string and determine whether MM accepts it.

(c)

Among all strings in (01)*, which ones are in L(M)L(M)?

Figure 2.5: DFA of Exercise 1.Figure 2.5: DFA of Exercise 1.

Problem 2.1.2

For integers n,d≥1n, d \geq 1, consider a DFA Mn,d=(Q,Σ,δ,q0,F)M_{n, d}=\left(Q, \Sigma , \delta , q_{0}, F\right), where Q={q0,q1,q2,⋯ ,qn−1},Σ={a0,a1,⋯ ,ad−1},δ(qi,ak)=q(di+k) mod nQ= \left\{ q_{0}, q_{1}, q_{2}, \cdots , q_{n-1}\right\} , \Sigma =\left\{ a_{0}, a_{1}, \cdots , a_{d-1}\right\} , \delta \left(q_{i}, a_{k}\right)=q_{(d i+k) \bmod n}, and F={q1}F=\left\{ q_{1}\right\}.

?
(a)

Draw the transition diagram of Mn,dM_{n, d} with n=7n=7 and d=2d=2.

(b)

Suppose n=7,d=2,a0=0n=7, d=2, a_{0}=0 and a1=1a_{1}=1. Find δ(q3,0101)\delta \left(q_{3}, 0101\right) and δ(q1,11010)\delta \left(q_{1}, 11010\right).

(c)

Suppose n=7,d=2,a0=0n=7, d=2, a_{0}=0 and a1=1a_{1}=1. Find binary strings xx and yy such that δ(q0,x)=q5\delta \left(q_{0}, x\right)=q_{5} and δ(q0,y)=q6\delta \left(q_{0}, y\right)=q_{6}.

(d)
  • Show that for any state qj∈Qq_{j} \in Q, there exists a string x∈Σ∗x \in \Sigma^{*} such that δ(q0,x)=qj\delta \left(q_{0}, x\right)=q_{j}.

Figure 2.6: Three DFA’s of Exercise 3.Figure 2.6: Three DFA’s of Exercise 3.

Problem 2.1.3

For each of the DFA's M1,M2M_{1}, M_{2} and M3M_{3}, as shown in Figure 2.6(a), (b) and (c), respectively, describe in English the language accepted by it.

?
Example 2.6

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

?
Example 2.7

The set of all binary strings beginning with prefix 01.

?
Example 2.8

The set of all binary strings having a substring 00.

?
Example 2.9

The set of all binary strings having the substring 00101.

?
Example 2.10

The set AA of all binary strings ending with 01.

?
Example 2.11

The set of all binary expansions of positive integers which are congruent to zero modulo 5.

?
Example 2.12

The set of all binary strings having a substring 00 or ending with 01.

?
Example 2.13

The set of all binary strings having a substring 00 and ending with 01.

?
Example 2.14

The set of all binary strings having a substring 00 but not ending with 01.

?
Example 2.15

The set LL of all binary strings in which every block of four consecutive symbols contains a substring 01.

?
Problem 2.2.1

For each of the following languages, construct a DFA that accepts the language:

?
(a)

The set of binary strings beginning with 010.

(b)

The set of binary strings ending with 101.

(c)

The set of binary strings beginning with 10 and ending with 01.

(d)

The set of binary strings having a substring 010 or 101.

(e)

The set of binary strings in which the last five symbols contain at most three 0's.

(f)

The set of binary strings ww in which #1(w)+2#0(w)\#_{1}(w)+2 \#_{0}(w) is divisible by 5, where #a(w)\#_{a}(w) is the number of occurrences of the symbol aa in string ww.

(g)

The set of strings over the alphabet {1,2,3}\left\{ 1,2,3\right\} in which the sum of all symbols is divisible by 5.

(h)

The set of strings over the alphabet {0,1,2}\left\{ 0, 1, 2\right\} which are the ternary expansions (base-3 representations) of positive integers which are congruent to 2 modulo 7.

(i)

The set of binary strings in which every block of four symbols contains at least two 0's.

(j)

The set of binary strings in which every substring 010 is followed immediately by substring 111.

Problem 2.2.2

For each of the following languages, use the product automaton method to construct a DFA that accepts the language:

?
(a)

The set of binary strings beginning with 010 or ending with 101.

(b)

The set of binary strings having a substring 010 but not having a substring 101.

(c)

The set of binary strings beginning with 010, ending with 101 and having a substring 0000.

Problem 2.2.3

For each of the following languages, use the checker method to construct a DFA that accepts the language:

?
(a)

The set of Example 2.12.

(b)

The set of Example 2.14.

(c)

The set of Exercise 2(a) above.

(d)

The set of Exercise 2(c) above.

Example 2.17

Find an NFA that accepts the set of binary strings having a substring 010.

?
Example 2.18

Find an NFA that accepts the set of binary strings beginning with 010 or ending with 110.

?
Example 2.19

Find an NFA that accepts the set of binary strings with at least two occurrences of substring 01 and ends with 11.

Figure 2.22: The Solution to Example 2.19.Figure 2.22: The Solution to Example 2.19.

?
Example 2.20

Find an NFA that accepts the set {0n10m∣n,m≥0,n≡m( mod 5)}\left\{ 0^{n} 10^{m} \mid n, m \geq 0, n \equiv m(\bmod 5)\right\}.

?
Example 2.21

Let M1M_{1} and M2M_{2} be two NFA's. Construct an NFA MM such that L(M)=L(M1)⋅L(M2)L(M)=L\left(M_{1}\right) \cdot L\left(M_{2}\right).

?
Example 2.22

Let M1M_{1} be an NFA. Construct an NFA MM such that L(M)=L(M1)∗L(M)= L\left(M_{1}\right)^{*}.

?
Problem 2.3.1

Consider the NFA MM of Figure 2.26.

?
(a)

What are ε\varepsilon-closure ({q0})\left(\left\{ q_{0}\right\} \right) and ε\varepsilon-closure ({q1,q2,q3})\left(\left\{ q_{1}, q_{2}, q_{3}\right\} \right)?

(b)

What are δ({q0},0)\delta \left(\left\{ q_{0}\right\} , 0\right) and δ({q2,q3},1)\delta \left(\left\{ q_{2}, q_{3}\right\} , 1\right)?

(c)

Draw the computation trees of MM on strings x=011x=011 and y=101y=101. Does MM accept or reject xx and yy?

Figure 2.26: The NFA of Exercise 1.Figure 2.26: The NFA of Exercise 1.

Problem 2.3.2

For each NFA MM shown in Figure 2.27, determine what L(M)L(M) is.

?
Problem 2.3.3

For each of the following languages, construct an NFA that accepts the language:

?
(a)

The set of binary strings that contain at least three occurrences of substring 010.

(b)

The set of binary strings that contain both substrings 010 and 101. [Hint: This is equivalent to the set of binary strings that contain either a substring 0101 or a substring 1010 or a substring 010 followed by 101 or a substring 101 followed by 010.]

(c)

The set of binary strings that contain either a substring 010 or a substring 101, and end with 111 or 000.

(d)

The set of binary strings of which the (3n)(3 n)th symbol is 0 for each n≥1n \geq 1.

(e)

The set of binary strings xx of length 3n3 n for some n≥1n \geq 1, such that, for each 1≤k≤n1 \leq k \leq n, at least one of the (3k−2)(3 k-2)nd, (3k−1)(3 k-1)st and (3k)(3 k) th symbols of xx is 0.

(f)

The set {0n10m10q∣q≡nm( mod 5)}\left\{ 0^{n} 10^{m} 10^{q} \mid q \equiv n m(\bmod 5)\right\}.

Figure 2.27: Three NFA’s of Exercise 2.Figure 2.27: Three NFA’s of Exercise 2.

Problem 2.3.4

Prove that the new initial state ss and the final state ff in the construction of Example 2.22 are necessary. That is, find NFA's M1M_{1} and M2M_{2} such that the NFA's M1′M_{1}^{\prime } and M2′M_{2}^{\prime } of Figure 2.28 have the property L(M1′)≠L(M1)∗L\left(M_{1}^{\prime }\right) \neq L\left(M_{1}\right)^{*} and L(M2′)≠L(M2)∗L\left(M_{2}^{\prime }\right) \neq L\left(M_{2}\right)^{*}.

?
Example 2.23

An NFA M=(Q,{0,1},δ,q0,F)M=\left(Q,\left\{ 0,1\right\} , \delta , q_{0}, F\right) is given by Q={q0,q1,q2, q3,q4,q5},F={q3,q4}Q=\left\{ q_{0}, q_{1}, q_{2}\text{, }q_{3}, q_{4}, q_{5}\right\} , F=\left\{ q_{3}, q_{4}\right\}, and

δ\delta01ε\varepsilon
q0q_{0}{q0}\left\{ q_{0}\right\}{q0,q2}\left\{ q_{0}, q_{2}\right\}{q1}\left\{ q_{1}\right\}
q1q_{1}{q5}\left\{ q_{5}\right\}{q2}\left\{ q_{2}\right\}-
q2q_{2}{q3}\left\{ q_{3}\right\}--
q3q_{3}--{q4}\left\{ q_{4}\right\}
q4q_{4}{q3}\left\{ q_{3}\right\}--
q5q_{5}-{q4}\left\{ q_{4}\right\}-

(See Figure 2.29(a) for the transition diagram of MM.) Find a DFA which is equivalent to the NFA MM.

Figure 2.29: Converting an NFA to a DFA.Figure 2.29: Converting an NFA to a DFA.

?
Example 2.24

Construct a DFA which is equivalent to the NFA M=({p,q, r},{0,1},δ,p,{q,r})M=(\left\{ p, q\text{, }r\right\} ,\left\{ 0,1\right\} , \delta , p,\left\{ q, r\right\} ), where

δ\delta01
pp{p,q}\left\{ p, q\right\}{p}\left\{ p\right\}
qq-{r}\left\{ r\right\}
rr--
?
Example 2.26

Let M=({p,q,r,s},{0,1},δ,p,{q,s})M=(\left\{ p, q, r, s\right\} ,\left\{ 0,1\right\} , \delta , p,\left\{ q, s\right\} ) be an NFAN F A given by

δ\delta01
pp{q,s}\left\{ q, s\right\}{q}\left\{ q\right\}
qq{r}\left\{ r\right\}{q,r}\left\{ q, r\right\}
rr{s}\left\{ s\right\}{p}\left\{ p\right\}
ss-{p}\left\{ p\right\}

Construct an NFA that accepts L(M)‾\overline{L(M)}.

?
Example 2.27

Construct a DFA accepting the set of all binary strings in which the fifth symbol from right is 0.

?
Example 2.28

Consider the following multiplication table on {a,b,c}\left\{ a, b, c\right\} :

×\timesaabbcc
aaccaabb
bbbbccaa
ccccbbcc

For any string ww in {a,b,c}+\left\{ a, b, c\right\}^{+}, denote by value⁡(w)\operatorname {value}(w) the value obtained by multiplying symbols in ww from left to right. For instance, let w=abcbw=a b c b. Then, we get

value⁡(w)=((a×b)×c)×b=(a×c)×b=b×b=c, and value⁡(wR)=((b×c)×b)×a=(a×b)×a=a×a=c. \begin{aligned} \operatorname {value}(w) & =((a \times b) \times c) \times b=(a \times c) \times b=b \times b=c, \text{ and } \\ \operatorname {value}\left(w^{R}\right) & =((b \times c) \times b) \times a=(a \times b) \times a=a \times a=c. \end{aligned}

Construct an NFA for the set LL of all strings ww over {a,b,c}\left\{ a, b, c\right\} such that value⁡(w)=value⁡(wR)\operatorname {value}(w)=\operatorname {value}\left(w^{R}\right). (E.g., abcb∈La b c b \in L and abb∉La b b \notin L.)

?
Problem 2.4.1

Convert each of the following NFA's into an equivalent DFA:

?
(a)

The NFA M=({p,q,r},,{0,1},δ,p,{q,r})M=(\left\{ p, q, r\right\} ,,\left\{ 0,1\right\} , \delta , p,\left\{ q, r\right\} ), with

δ\delta01
pp{p}\left\{ p\right\}{p,q}\left\{ p, q\right\}
qq{r}\left\{ r\right\}-
rr--
(b)

The NFA MM of Figure 2.27(a).

(c)

The NFA MM of Figure 2.27(b).

(d)

The NFA MM of Figure 2.27(c).

Problem 2.4.2

For each of the following languages, construct a DFA that accepts the language:

?
(a)

The set of binary strings that contain both substring 010 and substring 101.

(b)

The set of all binary strings ending with 00 or 01 or 10.

(c)

The set of binary strings that contain both 001 and 110 as substrings or contain neither 001 nor 110 as a substring.

(d)

The set of binary strings in which both the fourth symbol from the right and the fourth from the left symbols are 0. [Note: Both strings 0110 and 10101 belong to this set.]

Problem 2.4.3

Consider the following multiplication table on {a,b,c}\left\{ a, b, c\right\} :

×\timesaabbcc
aaaaccbb
bbaabbcc
ccccccaa

Construct NFA's for the following languages:

?
(a)

{x∣value⁡(x)≠value⁡(xR)}\left\{ x \mid \operatorname {value}(x) \neq \operatorname {value}\left(x^{R}\right)\right\}.

(b)

{xy∣value⁡(x)=value⁡(yR)}\left\{ x y \mid \operatorname {value}(x)=\operatorname {value}\left(y^{R}\right)\right\}.

(c)

{xy∣value⁡(x)=value⁡(y)}\left\{ x y \mid \operatorname {value}(x)=\operatorname {value}(y)\right\}.

Example 2.29

Find a DFA accepting the language 10+(0+11)0∗110+(0+11) 0^{*} 1.

?
Example 2.30

Construct an NFA accepting the set LL of binary strings of an odd length which contain the substring 00.

?
Example 2.32

Find a regular expression for the language accepted by NFA in Figure 2.29(a).

?
Problem 2.5.1

For each of the following regular expressions rr, construct a DFA that accepts L(r)L(r) :

?
(a)

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

(b)

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

(c)

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

Problem 2.5.2

For each of the following languages, find an NFA that accepts it:

?
(a)

{x#y∣x,y∈(0+1)∗,∣x∣≡∣y∣( mod 2)}\left\{ x \# y \mid x, y \in (0+1)^{*}, \left|x\right| \equiv \left|y\right|(\bmod 2)\right\}.

(b)

{x#y∣x,y∈(0+1)∗,∣x∣+∣y∣≥5}\left\{ x \# y \mid x, y \in (\mathbf{0}+\mathbf{1})^{*}, \left|x\right|+\left|y\right| \geq 5\right\}.

(c)

{x#y∣x,y∈(0+1)∗,∣x∣⋅∣y∣ is dividable by 5}\left\{ x \# y \mid x, y \in (\mathbf{0}+\mathbf{1})^{*}, \left|x\right| \cdot \left|y\right| \text{ is dividable by 5}\right\}.

Problem 2.5.3

Figure 2.41 shows an NFA accepting 0∗0^{*}, constructed based on the method of Example 2.22. The four ε\varepsilon-moves cannot be eliminated by the rule of Theorem 1.25. Apply the method in the proof of Theorem 2.31 to reduce some of its ε\varepsilon-moves. Can you find, from this example, a more general rule (than Theorem 1.25) to eliminate redundant ε\varepsilon-transitions?

Figure 2.41: An NFA accepting 0*.Figure 2.41: An NFA accepting 0*.

?
Problem 2.5.4

For each of the languages accepted by NFA's of Figure 2.42, find a regular expression for it.

Figure 2.42: Two NFA’s for Exercise 4.Figure 2.42: Two NFA’s for Exercise 4.

?
Example 2.34

Let MM be an NFAN F A. Construct an NFAM′N F A M^{\prime } such that L(M′)=L(M)RL\left(M^{\prime }\right)= L(M)^{R}.

?
Example 2.35

Let ff be a substitution over Σ\Sigma. Assume that L⊆Σ∗L \subseteq \Sigma^{*} is a regular language, and that f(a)f(a) is a regular language for each a∈Σa \in \Sigma. Then, f(L)f(L) is also a regular language.

?
Example 2.36

Show that for any language L2L_{2}, if L1L_{1} is regular then L1/L2L_{1} / L_{2} is also regular.

?
Example 2.37

Let LL be a regular language over Σ,k\Sigma , k a positive integer and ϕ\phi a mapping from Σk\Sigma^{k} to Σ\Sigma. Prove that

L1={ϕ(a1a2⋯ak)⋯ϕ(a(n−1)k+1a(n−1)k+2⋯ank)∣a1a2⋯ank∈L} L_{1}=\left\{ \phi \left(a_{1} a_{2} \cdots a_{k}\right) \cdots \phi \left(a_{(n-1) k+1} a_{(n-1) k+2} \cdots a_{n k}\right) \mid a_{1} a_{2} \cdots a_{n k} \in L\right\}

is regular.

?
Example 2.38

Prove that if LL is regular, so is MIN⁡(L)\operatorname {MIN}(L).

?
Example 2.39

Show that if AA and BB are regular languages over {0,1}\left\{ 0,1\right\}, then

A∨B={x∨y∣x∈A,y∈B,∣x∣=∣y∣} A \vee B=\left\{ x \vee y \mid x \in A, y \in B, \left|x\right|=\left|y\right|\right\}

is also regular.

?
Example 2.40

Show that if LL is a regular language, so is

{xy∣yx∈L}. \left\{ x y \mid y x \in L\right\} .
?
Example 2.41

Show that if LL is a regular language, so is

L12={x∣(∃y)[∣x∣=∣y∣,xy∈L]}. L_{\frac{1}{2}}=\left\{ x \mid (\exists y)[\left|x\right|=\left|y\right|, x y \in L]\right\} .
?
Example 2.42

Show that if LL is a regular set, so is

L33={z∣(∃x,y)[∣x∣=∣y∣=∣z∣,xyz∈L]} L_{\frac{3}{3}}=\left\{ z \mid (\exists x, y)[\left|x\right|=\left|y\right|=\left|z\right|, x y z \in L]\right\}
?
Example 2.43

Let AA and BB be two regular languages. Show that the language defined by

C(A,B)={x∈A∣(∃y)[∣y∣=∣x∣2,y∈B]} C(A, B)=\left\{ x \in A \mid (\exists y)\left[\left|y\right|=\left|x\right|^{2}, y \in B\right]\right\}

is also regular.

?
Example 2.44

Show that if LL is regular, so is

SQRT⁡(L)={x∣(∃y)[∣y∣=∣x∣2,xy∈L]} \operatorname {SQRT}(L)=\left\{ x \mid (\exists y)\left[\left|y\right|=\left|x\right|^{2}, x y \in L\right]\right\}
?
Problem 2.6.1

Prove the following identity:

?
(a)

MAX⁡(L)=L\(L/Σ+)\operatorname {MAX}(L)=L \backslash \left(L / \Sigma^{+}\right), where MAX⁡(L)={x∈L∣x is not a proper prefix of any string in L}\operatorname {MAX}(L)=\left\{ \boldsymbol {x} \in L \mid \boldsymbol {x}\text{ is not a proper prefix of any string in }L\right\}.

(b)

MIN⁡(L)=L\(LΣ+)\operatorname {MIN}(L)=L \backslash \left(L \Sigma^{+}\right).

Problem 2.6.2

For any two bits a,b∈{0,1},a⊕ba, b \in \left\{ 0,1\right\} , a \oplus b denotes the exclusive-or of aa and bb; that is, 0⊕0=1⊕1=00 \oplus 0=1 \oplus 1=0 and 0⊕1=1⊕0=10 \oplus 1=1 \oplus 0=1. For any two binary strings xx and yy with ∣x∣=∣y∣,x⊕y\left|x\right|=\left|y\right|, x \oplus y denotes the bitwise exclusive-or of xx and yy. For example, if x=0011x=0011 and y=0101y=0101, then x⊕y=0110x \oplus y=0110. Let A=001(0+1)∗A=001(0+1)^{*} and B=(0+1)∗100B=(0+1)^{*} 100. Find a regular expression for each of the following languages:

?
(a)

A∨BA \vee B.

(b)

A⊕B={x⊕y∣x∈A,y∈B,∣x∣=∣y∣}A \oplus B=\left\{ x \oplus y \mid x \in A, y \in B, \left|x\right|=\left|y\right|\right\}.

(c)

{a1b1a2b2⋯anbn∣a1a2⋯an∈A,b1b2⋯bn∈B}\left\{ a_{1} b_{1} a_{2} b_{2} \cdots a_{n} b_{n} \mid a_{1} a_{2} \cdots a_{n} \in A, b_{1} b_{2} \cdots b_{n} \in B\right\}.

Problem 2.6.3

Show that if AA and BB are regular languages, so are the following languages:

?
(a)

{x∣xxR∈A}\left\{ x \mid x x^{R} \in A\right\}.

(b)

{x∣x∈A,xx∈A}\left\{ x \mid x \in A, x x \in A\right\}.

(c)

Ax={y∣xy∈A}A_{x}=\left\{ y \mid x y \in A\right\}, where xx is a fixed string.

(d)

{a1a2⋯a2n∣a2a1a4a3⋯a2na2n−1∈A}\left\{ a_{1} a_{2} \cdots a_{2 n} \mid a_{2} a_{1} a_{4} a_{3} \cdots a_{2 n} a_{2 n-1} \in A\right\}.

(e)

{a1a3⋯a2n−3a2n−1∣a1a2⋯a2n∈A}\left\{ a_{1} a_{3} \cdots a_{2 n-3} a_{2 n-1} \mid a_{1} a_{2} \cdots a_{2 n} \in A\right\}.

(f)

{a1b1a2b2⋯anbn∣a1a2⋯an∈A,b1b2⋯bn∈B}\left\{ a_{1} b_{1} a_{2} b_{2} \cdots a_{n} b_{n} \mid a_{1} a_{2} \cdots a_{n} \in A, b_{1} b_{2} \cdots b_{n} \in B\right\}.

(g)

A⊕BA \oplus B.

Problem 2.6.4

Give an alternative proof for Example 2.42 based on the following idea: We may simulate NFA Mˉ\bar{M} on xyx y together with M^i\widehat{M}_{i} on zz by simulating two moves of Mˉ\bar{M} and one move of M^i\widehat{M}_{i} at each step. (Thus, the new NFA for L33L_{\frac{3}{3}} has only n+2n+2 tracks.)

?
Problem 2.6.5

Show that if AA and BB are regular languages, so are the following:

?
(a)

{xyz∣zyx∈A}\left\{ x y z \mid z y x \in A\right\}.

(b)

{xyz∣zyx∈A,y∈B}\left\{ x y z \mid z y x \in A, y \in B\right\}.

(c)

{y∣(∃x)[∣x∣=∣y∣,xy∈A]}\left\{ y \mid (\exists x)[\left|x\right|=\left|y\right|, x y \in A]\right\}.

(d)

{x∣(∃y,z)[∣x∣=∣y∣=∣z∣,xyz∈A]}\left\{ x \mid (\exists y, z)[\left|x\right|=\left|y\right|=\left|z\right|, x y z \in A]\right\}.

(e)

{y∣(∃x,z),[∣x∣=∣y∣=∣z∣,xyz∈A]}\left\{ y \mid (\exists x, z),[\left|x\right|=\left|y\right|=\left|z\right|, x y z \in A]\right\}.

(f)

{yz∣(∃x)[∣x∣=∣y∣=∣z∣,xyz∈A]}\left\{ y z \mid (\exists x)[\left|x\right|=\left|y\right|=\left|z\right|, x y z \in A]\right\}.

(g)

{xy∣(∃z)[∣x∣=∣y∣=∣z∣,xyz∈A]}\left\{ x y \mid (\exists z)[\left|x\right|=\left|y\right|=\left|z\right|, x y z \in A]\right\}.

(h)

{x∣(∃w,y,z)[x=wyz and wyRz∈A]}\left\{ x \mid (\exists w, y, z)\left[x=w y z\right.\text{ and }\left.w y^{R} z \in A\right]\right\}.

Problem 2.6.6

Consider a Boolean function f(a1,a2,⋯ ,an)f\left(a_{1}, a_{2}, \cdots , a_{n}\right). For any nn binary strings x1,x2,⋯ ,xnx_{1}, x_{2}, \cdots , x_{n} of equal length, denote by f(x1,x2,⋯ ,xn)f\left(x_{1}, x_{2}, \cdots , x_{n}\right) the bitwise function ff on x1,x2,⋯ ,xnx_{1}, x_{2}, \cdots , x_{n}. That is, if xi=xi1xi2…xikx_{i}=x_{i_{1}} x_{i_{2}} \ldots x_{i_{k}} for i=1,2i=1,2, …,n\ldots , n, where each xijx_{i_{j}} is a bit in {0,1}\left\{ 0,1\right\}, then f(x1,x2,…,xn)f\left(x_{1}, x_{2}, \ldots , x_{n}\right) is equal to

f(x11,x21,…,xn1)⋅f(x12,x22,…,xn2)⋯f(x1k,x2k,…,xnk) f\left(x_{11}, x_{21}, \ldots , x_{n 1}\right) \cdot f\left(x_{12}, x_{22}, \ldots , x_{n 2}\right) \cdots f\left(x_{1 k}, x_{2 k}, \ldots , x_{n k}\right)

Show that if languages A1,A2,⋯ ,AnA_{1}, A_{2}, \cdots , A_{n} are regular, then language

\begin{aligned} \left\{ f\left(x_{1}, x_{2}, \cdots , x_{n}\right) \mid & \left|x_{1}\right|=\left|x_{2}\right|=\cdots =\left|x_{n}\right| \\ & x_{1} \in A_{1}, x_{2} \in A_{2}, \cdots , x_{n} \in A_{n}\right\} \end{aligned}

is also regular.

?
Problem 2.6.7

In Exercise 3(c) above, show that, for any regular language AA, the number of distinct AxA_{x} 's is finite. Find an upper bound for this number, assuming that AA is accepted by a DFA with ss states.

?
Problem 2.6.8

Are the following statements true? Prove or disprove your answer.

?
(a)

If AA is regular and A⊆BA \subseteq B, then BB is regular.

(b)

If AA is regular and B⊆AB \subseteq A, then BB is regular.

(c)

If A2A^{2} is regular, then AA is regular.

(d)

If AA and ABA B are regular, then BB is regular.

(e)

If AA and BB are regular, then ⋃i=0∞(Ai∩Bi)\bigcup_{i=0}^{\infty }\left(A^{i} \cap B^{i}\right) is regular.

Problem 2.6.9

Show that every regular language in 0∗0^{*} can be represented in the form

0a1+0a2+⋯+0ak+(0b1+0b2+⋯+0bh)(0c)∗ 0^{a_{1}}+0^{a_{2}}+\cdots +0^{a_{k}}+\left(0^{b_{1}}+0^{b_{2}}+\cdots +0^{b_{h}}\right)\left(0^{c}\right)^{*}

for some integer constants a1,a2,⋯ ,ak,b1,b2,⋯ ,bha_{1}, a_{2}, \cdots , a_{k}, b_{1}, b_{2}, \cdots , b_{h}, and cc.

?
Problem 2.6.10

A subset PP of nonnegative integers is ultimately periodic if there exists two positive integers b,pb, p such that, for all m≥b,m∈Pm \geq b, m \in P implies m+p∈Pm+p \in P. Prove the following statements:

?
(a)

For any regular language L,{∣x∣∣x∈L}L,\left\{ \left|x\right| \mid x \in L\right\} is ultimately periodic.

(b)

A language LL over {0}\left\{ 0\right\} is regular if and only if {∣x∣∣x∈L}\left\{ \left|x\right| \mid x \in L\right\} is ultimately periodic.

(c)

If ff is a mapping from integers to integers such that f−1(P)f^{-1}(P) is ultimately periodic for every ultimately periodic set PP, then the set {x∈A∣(∃y)[∣y∣=f(∣x∣),y∈B]}\left\{ x \in A \mid (\exists y)[\left|y\right|=f(\left|x\right|), y \in B]\right\} is regular for every pair of regular sets AA and BB.

(d)

If ff is a mapping from integers to integers such that f−1(P)f^{-1}(P) is ultimately periodic for every ultimately periodic set PP, then the set {x∣(∃y)[∣y∣=f(∣x∣),xy∈L}\left\{ x \mid (\exists y)[\left|y\right|=f(\left|x\right|), x y \in L\right\} is regular for every regular set LL.

Problem 2.6.11

Apply Exercise 10(d) above to prove the following results:

?
(a)

If LL is a regular language, then so is {x∣(∃y)[∣y∣=2∣x∣,xy∈L]}\left\{ x \mid (\exists y)\left[\left|y\right|=2^{\left|x\right|}, x y \in L\right]\right\}. [Hint: Use Fermat's theorem, which states that for any odd integer m≥3m \geq 3, there exists an integer φ(m)\varphi (m) such that 2φ(m)≡1 mod m2^{\varphi (m)} \equiv 1 \bmod m.]

(b)

If LL is a regular language, then so is {x∣(∃y)[∣y∣2=∣x∣,xy∈L]}\left\{ x \mid (\exists y)\left[\left|y\right|^{2}=\left|x\right|, x y \in L\right]\right\}.

Example 2.45

Let L={x∈(0+1)∗∣∣x∣ is odd}L=\left\{ x \in (0+1)^{*} \mid \left|x\right|\text{ is odd}\right\}. Find all equivalence classes of RLR_{L}.

?
Example 2.46

Let LL be the set of nonempty binary strings starting and ending with the same symbol. Find all equivalence classes of RLR_{L}.

?
Example 2.50

Show that LL is regular if and only if there exists a positive integer kk such that xRLyx R_{L} y if and only if for every z∈Σ∗z \in \Sigma^{*} with ∣z∣≤k\left|z\right| \leq k, xz∈L⇔yz∈Lx z \in L \Leftrightarrow y z \in L.

?
Example 2.51

Find the minimum DFA for language (0+1)∗01(0+1)^{*} 01.

?
Example 2.52

Construct the minimum DFA for language (0+1)∗0(0+1)9(0+1)^{*} 0(0+1)^{9}.

?
Example 2.53

Find the minimum DFA equivalent to the DFA MM of Figure 2.47.

Figure 2.47: DFA M.Figure 2.47: DFA M.

?
Example 2.54

Show that the following language is not regular:

L={xxR∣x∈{0,1}∗} L=\left\{ x x^{R} \mid x \in \left\{ 0,1\right\} ^{*}\right\}
?
Example 2.55

Show that L={0m1n∣gcd⁡(m,n)=1}L=\left\{ 0^{m} 1^{n} \mid \operatorname {gcd}(m, n)=1\right\} is not regular.

?
Example 2.56

For any language LL, define an equivalence relation DLD_{L} by

xDLy⟺(∀u)(∀w)[uxw∈L⇔uyw∈L]. x D_{L} y \Longleftrightarrow (\forall u)(\forall w)[u x w \in L \Leftrightarrow u y w \in L].

Show that LL is regular if and only if Index⁡(DL)<∞\operatorname {Index}\left(D_{L}\right)<\infty.

?
Problem 2.7.1

Find all equivalence classess of RLR_{L} for the following languages:

?
(a)

(0+1)∗01(0+1)∗(0+1)^{*} 01(0+1)^{*}.

(b)

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

(c)

011(0+1)∗001011(0+1)^{*} 001.

(d)

The set of binary strings in which each block of four symbols have at least two 0's.

(e)

{x∈{0,1}∗∣#0(x)=#1(x)}\left\{ x \in \left\{ 0,1\right\}^{*} \mid \#_{0}(x)=\#_{1}(x)\right\}, where #a(w)\#_{a}(w) is the number of occurrences of symbol aa in ww.

Problem 2.7.2

For each of the following languages LL, show that Index⁡(L)=∞\operatorname {Index}(L)=\infty and so LL is not regular.

?
(a)

{0m1n∣0≤m≤n}\left\{ 0^{m} 1^{n} \mid 0 \leq m \leq n\right\}.

(b)

{0n1m0n+m∣n,m≥0}\left\{ 0^{n} 1^{m} 0^{n+m} \mid n, m \geq 0\right\}.

(c)

{ww∣w∈{0,1}∗}\left\{ w w \mid w \in \left\{ 0,1\right\}^{*}\right\}.

(d)

{xxRw∣x,w∈{0,1}+}\left\{ x x^{R} w \mid x, w \in \left\{ 0,1\right\}^{+}\right\}.

Problem 2.7.3

For each of the following languages LL, show that no two strings can be in the same equivalence class of RLR_{L}.

?
(a)

{0p∣p is a prime }\left\{ 0^{p} \mid p\text{ is a prime }\right\}.

(b)

{0n2∣n≥0}\left\{ 0^{n^{2}} \mid n \geq 0\right\}.

Problem 2.7.4

Construct the minimum DFA's for languages accepted by DFA's in Figure 2.52(a) and 2.52(b).

Figure 2.52: Two DFA’s for Exercise 4.Figure 2.52: Two DFA’s for Exercise 4.

?
Problem 2.7.5

Construct a minimum DFA equivalent to the NFA of Figure 2.53.

Figure 2.53: An NFA for Exercise 5.Figure 2.53: An NFA for Exercise 5.

?
Example 2.58

{0p∣p is a prime }\left\{ 0^{p} \mid p\text{ is a prime }\right\} is not a regular language.

?
Example 2.60

{0n1n∣n≥0}\left\{ 0^{n} 1^{n} \mid n \geq 0\right\} is not a regular language.

?
Example 2.61

Show that L={ββR∣β∈{0,1}+}L=\left\{ \beta \beta^{R} \mid \beta \in \left\{ 0,1\right\}^{+}\right\}is not a regular language.

?
Example 2.62

Show that L={ββRγ∣β∈{0,1}+,γ∈{0,1}∗}L=\left\{ \beta \beta^{R} \gamma \mid \beta \in \left\{ 0,1\right\}^{+}, \gamma \in \left\{ 0,1\right\}^{*}\right\} is not regular.

?
Example 2.63

Show that the language L={0n10m10p10q∣n,m,p≥1,q≡nm( mod p)}L=\left\{ 0^{n} 10^{m} 10^{p} 10^{q} \mid n, m, p \geq 1, q \equiv n m(\bmod p)\right\} is not regular.

?
Example 2.64

Consider the following multiplication table on {a,b,c}\left\{ a, b, c\right\} :

×\timesaabbcc
aaaaaacc
bbccaabb
ccbbccaa

Recall, from Example 2.28, that for any string xx in {a,b,c}+\left\{ a, b, c\right\}^{+}, value⁡(x)\operatorname {value}(x) denotes the value obtained by multiplying symbols in xx from left to right. Show that the set

L={xy  :  x,y∈{a,b,c}∗,∣x∣=∣y∣,value⁡(x)=value⁡(y)} L=\left\{ x y \; : \; x, y \in \left\{ a, b, c\right\} ^{*},\left|x\right|=\left|y\right|, \operatorname {value}(x)=\operatorname {value}(y)\right\}

is not regular.

?
Example 2.65

Show that the set LL of all strings over alphabet

Γ={[000],[100],[010],[001],[110],[101],[011],[111]} \Gamma =\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 multiplication is not regular. For example, the relation

00111×010111111 \begin{array}{r} 00111 \\ \times \quad 01011 \\ \hline 1111 \end{array}

implies that the following string is in LL :

[001][011][101][111] \left[\begin{smallmatrix} 0 \\ 0 \\ 1 \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 \\ 1 \end{smallmatrix}\right]
?
Example 2.66

Show that the set L2L_{2} of the binary expansions of the integers in set A={2n∣n≥1}A=\left\{ 2^{n} \mid n \geq 1\right\} is regular, but the set L3L_{3} of the ternary expansions (base 3 representations) of the integers in AA is not regular.

?
Example 2.67

Show that L={w∈{0,1}∗∣#0(w)≠#1(w)}L=\left\{ w \in \left\{ 0,1\right\}^{*} \mid \#_{0}(w) \neq \#_{1}(w)\right\} is not regular.

?
Example 2.68

Show that L={anbmck∣n,m,k≥0,n≠m or m≠k or k≠n}L=\left\{ a^{n} b^{m} c^{k} \mid n, m, k \geq 0, n \neq m\text{ or }m \neq k\text{ or }k \neq n\right\} is not regular.

?
Example 2.69

Let LL be a regular language. Show that

L′={xz∣(∃y)[∣x∣=∣y∣=∣z∣ and xyz∈L]} L^{\prime }=\left\{ x z \mid (\exists y)[\left|x\right|=\left|y\right|=\left|z\right| \text{ and } x y z \in L]\right\}

is not necessarily regular.

?
Problem 2.8.1

Show that the following languages are not regular.

?
(a)

{0n3+3n2−2n∣n≥0}\left\{ 0^{n^{3}+3 n^{2}-2 n} \mid n \geq 0\right\}.

(b)

{0p1q0m1n∣p+q=m+n,p,q,m,n≥0}\left\{ 0^{p} 1^{q} 0^{m} 1^{n} \mid p+q=m+n, p, q, m, n \geq 0\right\}.

(c)

{0m1n∣m,n≥0 and m≠2n+1}\left\{ 0^{m} 1^{n} \mid m, n \geq 0\text{ and }m \neq 2 n+1\right\}.

(d)

{0m1n∣2n≤m≤3n,m,n≥0}\left\{ 0^{m} 1^{n} \mid 2 n \leq m \leq 3 n, m, n \geq 0\right\}.

(e)

{w∈{0,1,2}∗∣#0(w)+#1(w)=#2(w)}\left\{ w \in \left\{ 0, 1, 2\right\}^{*} \mid \#_{0}(w)+\#_{1}(w)=\#_{2}(w)\right\}.

(f)

{0pq∣p and q are primes }\left\{ 0^{p q} \mid p\text{ and }q\text{ are primes }\right\}.

Problem 2.8.2

For each of the following languages, determine whether it is regular. Present a proof for your answer.

?
(a)

The set of binary strings having an equal number of 0 's and 1 's.

(b)

The set of binary strings having an equal number of 01's and 10's.

(c)

The set of binary strings having an equal number of 010's and 101's.

(d)

{xy∣x,y∈{0,1}∗,∣x∣=∣y∣,#0(x)≥#0(y)}\left\{ x y \mid x, y \in \left\{ 0,1\right\}^{*},\left|x\right|=\left|y\right|, \#_{0}(x) \geq \#_{0}(y)\right\}.

(e)

{xyz∣x,y,z∈{0,1}∗,∣x∣=∣z∣>0,#0(x)≥#0(z)}\left\{ x y z \mid x, y, z \in \left\{ 0,1\right\}^{*},\left|x\right|=\left|z\right|>0, \#_{0}(x) \geq \#_{0}(z)\right\}.

(f)

{x#y#z∣x,y,z are binary expansions of positive integers satisfying x+y=z}\left\{ x \# y \# z \mid x, y, z\text{ are binary expansions of positive integers satisfying }x+y=z\right\}.

Problem 2.8.3

Let Γ\Gamma be the alphabet of Example 2.65.

?
(a)

Show that the set LL of all strings over alphabet Γ\Gamma that represent correct division is not regular. For example,

11111×01100100011 \begin{array}{r} 11111 \\ \times \quad 011001 \\ \hline 00011 \end{array}

implies that the following string is in LL :

[100][110][101][111]. \left[\begin{smallmatrix} 1 \\ 0 \\ 0 \end{smallmatrix}\right]\left[\begin{smallmatrix} 1 \\ 1 \\ 0 \end{smallmatrix}\right]\left[\begin{smallmatrix} 1 \\ 0 \\ 1 \end{smallmatrix}\right]\left[\begin{smallmatrix} 1 \\ 1 \\ 1 \end{smallmatrix}\right].
(b)

Show that the set of all strings over Γ\Gamma that represent correct multiplication, with the second multiplier equal to 3, is regular.

Problem 2.8.4

Is it true that for any regular language LL over {0,1}\left\{ 0,1\right\}, the set N(L)={0#0(x)1#1(x)∣x∈L}N(L)= \left\{ 0^{\#_{0}(x)} 1^{\#_{1}(x)} \mid x \in L\right\} is also regular? Prove your answer.

?
Problem 2.8.5

Prove the following stronger form of the pumping lemma: For any regular language LL and any positive integer kk, there exists a positive integer ss such that any string xx in LL with ∣x∣>s\left|x\right|>s can be decomposed into x=uvwx=u v w such that ∣v∣>k\left|v\right|>k and for any i≥0,uviw∈Li \geq 0, u v^{i} w \in L.

?
Problem 2.8.6

Find a regular language LL such that

L^={xz∣(∃y)[∣x∣=∣y∣=∣z∣ and xyzy∈L]} \widehat{L}=\left\{ x z \mid (\exists y)[\left|x\right|=\left|y\right|=\left|z\right| \text{ and } x y z y \in L]\right\}

is not regular.

?
Problem 2.8.7

Let AA and BB be regular sets over alphabet Σ\Sigma. Which of the following languages, if any, are necessarily regular?

?
(a)

{x∣x∈A and xR∈B}\left\{ x \mid x \in A\text{ and }x^{R} \in B\right\}.

(b)

{x∣x∈A and xR∉B}\left\{ x \mid x \in A\text{ and }x^{R} \notin B\right\}.

(c)

{x∣x=xR and x∈A}\left\{ x \mid x=x^{R}\text{ and }x \in A\right\}.

(d)

{a1bna2bn−1a3bn−2⋯anb1∣ai,bi∈Σ for 1≤i≤n,a1a2⋯an∈A,b1b2⋯bn∈B}\left\{ a_{1} b_{n} a_{2} b_{n-1} a_{3} b_{n-2} \cdots a_{n} b_{1} \mid a_{i}, b_{i} \in \Sigma \text{ for }1 \leq i \leq n, a_{1} a_{2} \cdots a_{n} \in A, b_{1} b_{2} \cdots b_{n} \in B\right\}.

(e)

{a1ana2an−1a3an−2⋯ana1∣ai∈Σ for 1≤i≤n, a1a2⋯an∈A}\left\{ a_{1} a_{n} a_{2} a_{n-1} a_{3} a_{n-2} \cdots a_{n} a_{1} \mid a_{i} \in \Sigma \text{ for }1 \leq i \leq n\text{, }a_{1} a_{2} \cdots a_{n} \in A\right\}.

(f)

{a1a2na3a2n−2a5a2n−4⋯a2n−1a2∣ai∈Σ for 1≤i≤2n, a1a2⋯an∈A}\left\{ a_{1} a_{2 n} a_{3} a_{2 n-2} a_{5} a_{2 n-4} \cdots a_{2 n-1} a_{2} \mid a_{i} \in \Sigma \text{ for }1 \leq i \leq 2 n\text{, }a_{1} a_{2} \cdots a_{n} \in A\right\}.

Problem 2.8.8

Consider the language

L={x0ny1nz∣x∈P,y∈Q,z∈R} L=\left\{ x 0^{n} y 1^{n} z \mid x \in P, y \in Q, z \in R\right\}

where P,QP, Q and RR are nonempty sets over alphabet {0,1}\left\{ 0,1\right\}. Can you find regular sets P,Q,RP, Q, R such that LL is not regular? Can you find regular sets P,Q,RP, Q, R such that LL is regular? What if P,Q,RP, Q, R must be infinite regular sets?

?
Problem 2.8.9
?
(a)

Is the language {03m+4n∣m,n≥0}\left\{ 0^{3 m+4 n} \mid m, n \geq 0\right\} regular? Prove your answer.

(b)

Let LL be a language over alphabet {0}\left\{ 0\right\}. Show that L∗L^{*} is regular. [Hint: Prove and use the fact that if aa and bb are relatively prime natural numbers, then for any integer n≥abn \geq a b, there exist nonnegative integers uu and vv such that n=ua+vbn=u a+v b.]