(a) To show that LG consists of all strings of the form an ⊥an, we need to show two things:
- Any string in LG is of the form an ⊥an for some n 0.
- Every string of the form an ⊥an, where n 0, is in LG.
For the first part, we can prove by induction on n that any string in LG is of the form an ⊥an. The base case n=0 holds since we can only derive the string ⊥ from the start symbol S. Suppose the property holds for n=k, i.e., any string in LG can be written as ak ⊥ak. Then consider a string in LG of length 2k+2, which can be derived as S → aSa → akak+1 ⊥akak+1 for some string ak+1. Thus, the property holds for n=k+1, and by induction it holds for all n 0.
For the second part, we must show that any string of the form an ⊥an is in LG. We can prove this by constructing a derivation in G for any such string. Let S → aSa be the first production used in the derivation, repeated n times to obtain the string anS an. Then use the production S → ⊥ to replace S with ⊥, producing the string an ⊥ an, which is the desired form.
(b) The grammar G′ has the productions:
S → AS | ⊥
A → aAb | ⊥ | c
The start symbol S generates all strings of the form anbm⊥cpan for some non-negative integers n,m,p. To see why, we can prove by induction on k=n+m+p that any string in LG′ is of the form anbm⊥cpan. The base case k=0 holds since we can only derive the string ⊥ from the start symbol S. Suppose the property holds for k-1, i.e., any string in LG′ of length k-1 can be written as ak-1bk-1⊥ck-1pk-1. Then consider a string in LG′ of length k, which can be derived using either S → AS or S → ⊥. If the former is used, we can derive a string in LG′ of length k-1 that is of the form an-1bm-1⊥cm-1pm-1 by applying the same production to A. Then we have anbm⊥cpan = an-1bm-1⊥cm-1pak-1, which is the desired form. If the latter is used, we have anbm⊥cpan = akbm-1⊥ck-1pk, which is also in the desired form.
(c) The grammar G′′ has the productions:
S → NAS | SP
N → aN | a
P → cP | c
The start symbol S generates all strings of the desired form. To see why, note that any string in the language can be written as nas⊥pcs for some non-negative integers n,s,p. We can generate such a string by first using the production S → NAS to generate a string in the form NnAsPp. Then we can derive the string nas⊥pcs by applying the productions N → aN and P → cP repeatedly until we obtain the desired numbers of a's and c's. The order of the non-terminals N and P can be swapped in the derivation since they don't depend on each other. Thus, the grammar G′′ generates the language LG′′ as desired.