0

I need to bulid a context-free grammar for

$\qquad \mathscr{L_4}=\{w\in\{a,b,c\}^* \mid w\text{ is not palindrome at all}\}$

Not palindrom at all: We will say that a word $w$ is not palindrome at all if for all $i$ such that $1\leq i\leq |w|$ the $i$ letter from the beginning of $w$ is not the same like the $i$ letter of $w$ from the end, for example $abbacb\in \mathscr{L_4}$ but $ca\color{gray}bba\color{gray}bcb\notin\mathscr{L_4}$, the word must contain a even number of digits, because if there were an odd number of digits, so the middle digit "equals to itself".

My attempt: Let's denote $S_{\text{pal}}$ from palindrome grammar and $S_{\neg\text{pal}}$ for the not palindrome at all grammar

$$\\S_{\neg\text{pal}}\to a S_{\neg\text{pal}}b\big|bS_{\neg\text{pal}}a\big|aS_{\neg\text{pal}}c\big|cS_{\neg\text{pal}}a\big|cS_{\neg\text{pal}}b\big|cS_{\neg\text{pal}}b\big|\epsilon$$

Similar question here. I'm not sure if my attempt is correct or not

2 Answers2

0

Just use something like:

$ S \rightarrow a S b \mid a S c \mid b S a \mid b S c \mid c S a \mid c S b \mid a b \mid a c \mid b a \mid b c \mid c a \mid c b $

This ensures the $i$-th symbol from the beginning is different from the $i$-th from the end.

vonbrand
  • 14,204
  • 3
  • 42
  • 52
-1

Your attempt looks correct to me

$$\\S_{\neg\text{pal}}\to \color{red}a S_{\neg\text{pal}}\color{blue}b\big|\color{blue}bS_{\neg\text{pal}}\color{red}a\big|\color{red}aS_{\neg\text{pal}}\color{green}c\big|\color{green}cS_{\neg\text{pal}}\color{red}a\big|\color{blue}bS_{\neg\text{pal}}\color{green}c\big|\color{green}cS_{\neg\text{pal}}\color{blue}b\big|\varepsilon$$

Let us say that for a word of length $n$ such that $n\in\mathbb{N}$ is even for each letter in the $i$ from the begining $1\leq i\leq n$ you ensure that in the place $i$ from the end you have a diffrent letter

for example: $\color{red}a\color{blue}b\color{green}c\color{blue}b\color{red}a\color{blue}b\in \mathscr{L_4}$

3SAT
  • 449
  • 1
  • 5
  • 14