I have the following grammar,
S -> SbS -> aaSbS -> b
The typical derivations in this grammar are
S => Sb => [aaSb]b => [aa[b]b]b => aabbb for n = 1
S => Sb => [aaSb]b => [aa[aaSb]b]b => [aa[aabb]b]b => aaaabbbb for n = 2
Edit:
So I claimed that this grammar generates the language
L = {a^(2n)b^(n+2) : n >= 1}
I am pretty sure that my a goes a^(2n) since there's two a before S, but what about b. There is no lambda here so my n goes from n >= 1?.
Edit:
b^(n+1) and b^(2n+1) are both wrong assumptions because the grammar can derive a string aaaaaabbbbb if n = 3.
I modified my b to be b^(n+2).
so that L becomes L = {a^(2n)b^(n+2) : n >= 1}
The language generated by this grammar is
a^(2n) b^(n+m+1)wherenandmare natural numbers. To show this, (a) we see that any string derived using the grammar's productions matches the above and (b) any string matching the above can be derived using the grammar's productions.(a) The grammar can and must use rule (3) exactly once. This gives the
+1in the number ofbs. Execution of rule (2) can happen some number of timesn, putting2nas on the front andnbs on the back, hence the2nandnterms. Rule (1) can be executed any number of timesm, hence the term.(b) Given a string
a^(2n) b^(n+m+1)for natural numbersnandm: use rule (1) a number of times equal tom; then, use rule (2) a number of times equal ton; then, user rule (3) once. Thus, the grammar generates the string.Another way to write the same answer is
a^2n b^mwithm > n.