1

I am new to CFG's, Can someone give me tips in creating CFG that generates some language

For example

$L =\{ w v w^R \mid v,w\in \{a,b\}^*\wedge|v| \text{ is even } \}$, where $w^R$ is the reverse of string $w$.

I'm having trouble understanding the language .. I want to build DFA to convert it

babou
  • 19,445
  • 40
  • 76

2 Answers2

3

Mmmm.

Let me note that in fact $L =\{ w v w^R \mid v,w\in \{a,b\}^*\wedge|v| \text{ is even } \}$ equals $\{ v \mid v \in \{a,b\}^*\wedge|v| \text{ is even } \}$.

Al strings in $L$ are of even length, and conversely all strings of even length can be otained by taking $w=\varepsilon$.

That should help.

Hendrik Jan
  • 30,578
  • 1
  • 51
  • 105
  • I wonder whether this was expected ! – babou May 27 '15 at 23:43
  • @babou That is a good question. Perhaps the DFA confusion is related to this? – Hendrik Jan May 28 '15 at 00:20
  • 2
    Cute! It might help the OP even more if you included a sentence of explanation. (Too bad I can't upvote twice.) – Rick Decker May 28 '15 at 01:12
  • It is really a great psychological example of the way we work, and what may block us. Science is largely a question of looking at thing the right way. Hence the importance of conceptualization and notation. But in such a simple example ... Great for teaching. – babou May 28 '15 at 08:40
  • I think this question should not be closed. The answer is indeed too cute. What do you think? cc @RickDecker – babou May 28 '15 at 13:59
  • Yes, I didn't see it -- subtle problem -- I was too hasty to answer. Looks line ww^R, but adding the even length string in the middle changes everything since ww^R is always even and you can always let w = empty string. – wcochran May 28 '15 at 14:07
  • @babou. I agree that this question shouldn't be closed, especially in light of the fact that nothing in the reference question comes close to this answer. – Rick Decker May 28 '15 at 14:18
  • @RickDecker if Hendrick Jan agrees, we can take this to chat, I am afraid that is the only effective way. – babou May 28 '15 at 14:22
  • There's a very similar question here. – Rick Decker May 28 '15 at 14:36
  • Indeed, the question Rick links is much closer to a reason for closing as duplicate than the canned how-to-context-free question. – Hendrik Jan May 28 '15 at 17:16
2

Hints:

  1. Construct a non-terminal $V$ and appropriate productions so that $V$ generates all strings of even length.

  2. Create productions so that your starting symbol $S$ generates $wVw^R$ for all $w$. To accomplish that, modify a grammar for $ww^R$.

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503