-1

Write a grammar for a language $$L=\{ba^{2^n}b | n\ge 1\}.$$ It's not even context-free as I think. I just can't produce it, although I've tried a lot. Now my best attempt is: \begin{aligned} S &\to RLM \\ M &\to AM | A \\ LA &\to aa \\ aA &\to Aaa \\ RA &\to \varepsilon \end{aligned} But I've found example with deadlock $S→RLM→RLAAA→RaaAA→RaAaaA→RAaaaaA→aaaaA$

  • What kind of grammar are you looking for? – Yuval Filmus May 07 '18 at 20:01
  • Any. There can be even rules like S-->SS – ioleg19029700 May 07 '18 at 20:05
  • 1
    Context-sensitive grammar? Unrestricted grammar? What's the context and motivation for this problem? Why is it interesting? Where did you encounter it? Unrestricted grammars can generate any r.e. language, so if you know how to make a Turing machine to recognize the language, then you can mechanically apply the proof of that fact to construct an unrestricted grammar for it. This is possible and straightforward but doesn't seem very enlightening or interesting or fun; rather it seems tedious and pointless. – D.W. May 07 '18 at 20:16
  • Unrestricted grammar. I meant it could be any type from 0 up to 3 – ioleg19029700 May 07 '18 at 20:18
  • You should start like this: https://cs.stackexchange.com/questions/14521/use-pumping-lemma-to-show-l-is-not-context-free I do not think it is deadlock (never heard it in this context, but I may be wrong). I do not see 'b' generated in any way. Could you give textual description to your attempt? By the way the similar question was already answered here (but it is far better to do it on your own, or with help for that matter, that is why I asked about textual description). – Evil May 07 '18 at 21:40
  • 1
    Cross-posted: https://cs.stackexchange.com/q/91614/755, https://math.stackexchange.com/q/2771255/14578. Please do not post the same question on multiple sites. Each community should have an honest shot at answering without anybody's time being wasted. – D.W. May 08 '18 at 01:32
  • 1
    I'm voting to close this question because it was cross-posted on Math.SE. – D.W. May 08 '18 at 01:33

1 Answers1

2

When designing a grammar you must have some idea what the productions are meant to do. You seem to have some good productions, but glued tegether in a unexplained way. What is $M$ doing in your grammar? It might generate any number of $a$'s if I am not mistaken.

The basic idea when generating stings of the form $a^{2^n}$ is indeed to have a symbol that moves over the string that duplicates every $a$. So

$aA \to Aaa$

is good as a basis for the grammar. Now add a starting production, that gives end-markers, which can be made to disappear and turn into $b$'s.

$S \to LaaR$

Now you finish. Make the $A$ appear so that it can move over the string to double the number of $a$'s, to get $La^4R$ etcetera.

Don't worry about "deadlock". That is sometimes hard to avoid if the grammar is not completely "synchronized". For instance if one side of the string wants to finish the derivation process, and the other side doesn't. Those derivations are discarded. What matters is that the strings that do have proper derivations are exactly those in $L$.

Hendrik Jan
  • 30,578
  • 1
  • 51
  • 105
  • Could you please comment about "deadlock" terminology? I thought it is non-terminating derivation, which is, as you said, discarded. – Evil May 08 '18 at 02:25
  • 1
    @Evil Yes, I think it is just that. The terminology seems totally nonstandard, that's why I added quotes. – Hendrik Jan May 08 '18 at 07:55