Section 4.5

Unrestricted Grammars

[9/44%]
Show
LaTeX
Example 4.15

Find a grammar GG such that L(G)={anbncn∣n≥0}L(G)=\left\{ a^{n} b^{n} c^{n} \mid n \geq 0\right\}.

?
Example 4.16

Find a grammar GG such that L(G)={a2n∣n≥0}L(G)=\left\{ a^{2^{n}} \mid n \geq 0\right\}.

?
Example 4.17

Find a grammar GG such that L(G)={ww∣w∈{a,b}∗}L(G)=\left\{ w w \mid w \in \left\{ a, b\right\}^{*}\right\}.

?
Example 4.18

Find a grammar GG such that L(G)={anbmcnm∣n,m≥0}L(G)=\left\{ a^{n} b^{m} c^{n m} \mid n, m \geq 0\right\}.

?
Problem 4.5.1

Consider the grammar G1G_{1} with nonterminals V={S,A,B,C}V=\left\{ S, A, B, C\right\}, terminals Σ={a,b,c}\Sigma = \left\{ a, b, c\right\}, and rules

S⟶ASBC∣ε,AB⟶BA,AC⟶CA,BA⟶AB,BC⟶CB,CA⟶AC,CB⟶BC,A⟶a,B⟶b,C⟶c. \begin{array}{lll} S \longrightarrow A S B C \mid \varepsilon , & & \\ A B \longrightarrow B A, & A C \longrightarrow C A, & B A \longrightarrow A B, \\ B C \longrightarrow C B, & C A \longrightarrow A C, & C B \longrightarrow B C, \\ A \longrightarrow a, & B \longrightarrow b, & C \longrightarrow c. \end{array}
?
(a)

Show a derivation of string ccbaabcba.

(b)

What is L(G1)L\left(G_{1}\right)? Give a brief argument for your answer.

Problem 4.5.2

Consider the grammar G2G_{2} with nonterminals V={S,A,L,Lh,R,[],}V=\left\{ S, A, L, L_{h}, R,[],\right\}, terminal Σ={a}\Sigma =\left\{ a\right\} and rules

S→[ARa]∣a,RA→AR,Ra→aaR,R]⟶L]∣Lh,AL⟶LA,aL⟶La,[L⟶[AR,aLh⟶Lha,ALh⟶Lha,[Lh⟶ε. \begin{array}{rlr} S \rightarrow [A R a] \mid a, & R A \rightarrow A R, & R a \rightarrow a a R, \\ R] \longrightarrow L] \mid L_{h}, & A L \longrightarrow L A, & a L \longrightarrow L a, \\ {[L \longrightarrow [A R,} & a L_{h} \longrightarrow L_{h} a, & A L_{h} \longrightarrow L_{h} a, \\ {\left[L_{h} \longrightarrow \varepsilon .\right.} & & \end{array}
?
(a)

Show a derivation of a6a^{6}.

(b)

What is L(G2)L\left(G_{2}\right)? Give a brief argument for your answer.

Problem 4.5.3

Construct grammars for each of the following languages. Also show (i) the derivation of the given string xx and (ii) a proof of why your grammar does not generate any string not in the language.

?
(a)

{an2∣n≥0},x=a9\left\{ a^{n^{2}} \mid n \geq 0\right\} , x=a^{9}. [Hint: Following the idea of Exercise 2 above, generate, at the kk th iteration, a sentential form with kk copies of AA and k2−kk^{2}-k copies of aa.]

(b)

{a2n−n∣n≥0},x=a5\left\{ a^{2^{n}-n} \mid n \geq 0\right\} , x=a^{5}.

(c)

{an2+n∣n≥0},x=a11\left\{ a^{n^{2}+n} \mid n \geq 0\right\} , x=a^{11}.

(d)

{an3+2n2−5n+4∣n≥0},x=a34\left\{ a^{n^{3}+2 n^{2}-5 n+4} \mid n \geq 0\right\} , x=a^{34}. [Hint: Similar to part (a) above, generate, at the kk th iteration, a sentential form with kk copies of A,k2A, k^{2} copies of BB, and k3+k2−6k+4k^{3}+k^{2}-6 k+4 copies of aa.]

(e)

{anb2nan∣n≥0},x=a3b8a3\left\{ a^{n} b^{2^{n}} a^{n} \mid n \geq 0\right\} , x=a^{3} b^{8} a^{3}.

(f)

{anbnanbn∣n≥0},x=a4b4a4b4\left\{ a^{n} b^{n} a^{n} b^{n} \mid n \geq 0\right\} , x=a^{4} b^{4} a^{4} b^{4}.

(g)

{wcz∣w,z∈{a,b}∗,w≠z},x=aabcaaba\left\{ w c z \mid w, z \in \left\{ a, b\right\}^{*}, w \neq z\right\} , x=a a b c a a b a.

(h)

{w∈{a,b,c}∗∣#a(w)>#b(w)>#c(w)},x=\left\{ w \in \left\{ a, b, c\right\}^{*} \mid \#_{a}(w)>\#_{b}(w)>\#_{c}(w)\right\} , x= cbaabcbaa.

(i)

{wn∣w∈{a,b}∗,∣w∣=n},x=aabaabaab\left\{ w^{n}\left|w \in \left\{ a, b\right\}^{*},\left|w\right|=n\right\} , x=a a b a a b a a b\right..

Problem 4.5.4
?
(a)

Find a grammar GG such that w⇒G∗wRw \xRightarrow [G]{*} w^{R} for all w∈{a,b}w \in \left\{ a, b\right\}.

(b)

Find a grammar GG such that, for all x,y∈{a,b}∗x, y \in \left\{ a, b\right\}^{*} with ∣x∣=∣y∣\left|x\right|=\left|y\right|, xy⇒G∗yxx y \xRightarrow [G]{*} y x.

Problem 4.5.5

We consider a new computational model called Labeled Markov Algorithms (LMA). An LMA MM is defined as a triple (Σ,Γ,P)(\Sigma , \Gamma , P), where Σ\Sigma is the input alphabet, Γ\Gamma is a working alphabet with Σ⊆Γ\Sigma \subseteq \Gamma, and PP is a program, consisting of a finite sequence r1,r2,…,rnr_{1}, r_{2}, \ldots , r_{n} of instructions. Each instruction rir_{i} in PP is of the form

Li:α→β; goto Lj L_{i}: \alpha \rightarrow \beta ; \text{ goto } L_{j}

where α,β∈Γ∗\alpha , \beta \in \Gamma^{*}, and jj is a positive integer (α→β\alpha \rightarrow \beta is called a production rule and LjL_{j} is called the next instruction label). An instruction (LiL_{i} : α→β\alpha \rightarrow \beta; goto LjL_{j};) can be applied to a string w∈Γ∗w \in \Gamma^{*} if α\alpha is a substring of ww. The application of this instruction to ww produces a new string xx by replacing the leftmost occurrence of α\alpha in ww by β\beta.

On an input w∈Σ∗w \in \Sigma^{*}, the LMA MM operates as follows: At any time of computation, it maintains a current sentential form ww and a current instruction label LiL_{i}. Initially, ww is the input string and the current instruction label is L1L_{1}. At each step, it finds the least integer k≥ik \geq i, where LiL_{i} is the current instruction label, such that instruction rkr_{k} is applicable to ww. Then, it applies rkr_{k} to ww to obtain a new sentential form xx. It resets ww to be xx, and resets the current instruction label LL to be the the next instruction label of rkr_{k}. If no instruction rkr_{k}, with k≥ik \geq i, is applicable to the current sentential form ww, then the machine halts with output ww. (In particular, if the current instruction label is LiL_{i}, with ii greater than the number nn of instructions in PP, then the machine halts.)

For any LMA MM, we let L(M)={x∈Σ∗∣M halts on x}L(M)=\left\{ x \in \Sigma^{*} \mid M\text{ halts on }x\right\}, We say MM computes a partial function f:Σ∗→Γ∗f: \Sigma^{*} \rightarrow \Gamma^{*}, if MM halts on each input x∈Domain⁡(f)x \in \operatorname {Domain}(f) with the final sentential form w=f(x)w=f(x), and MM does not halt on any x∉Domain⁡(f)x \notin \operatorname {Domain}(f).

?
(a)

Design an LMA MM that computes the function f(x)=xRf(x)=x^{R} for x∈{a,b}∗x \in \left\{ a, b\right\}^{*}.

(b)

Show that every Turing-computable function ff is computable by an LMA.

(c)

Show that for any LMA M,L(M)M, L(M) is Turing-acceptable.

(d)

Show that every partial function ff computed by an LMA MM is Turing-computable.