help to fine about CFG for $L=\{a^nb^mc^k:|n-m|=k\}$

839 Views Asked by At

Hi guys (and so sorry for my weak english).

I have a problem about this language: $$L=\{a^nb^mc^k:|n-m|=k\}.$$

This language wants to produce some $k$ with $|n-m|$ but about another kind of this language it was my attempt:

for $n-m=k$ in $L=\{a^nb^mc^k:n-m=k\}$ i wrote: $$S\to e|A|Z\\ A\to aAc|ac\\ Z\to W1|W2\\ w1\to aW1b|ab\\ w2\to aW2c|aW1c$$

but for $|n-m|=k$ in $L=\{a^nb^mc^k:|n-m|=k\}$ have problem. thanx.

1

There are 1 best solutions below

0
On

For lengths of strings it is better to rewrite into non-negative numbers. Either $n\ge m$ and $n-m=k$ thus $n=m+k$, or $m\ge n$ and $m-n=k$ thus $m=n+k$. Now $L = \{ a^{m+k}b^mc^k \mid m,k\ge 0 \} \cup \{ a^nb^{n+k}c^k \mid n,k\ge 0 \} $.

Solve each of the two parts separately. You tried one of them, the other is symmetric.