0

If I have a CFL, can I define a regular substitution to make it a RL?

For example, if I have the language $\{a^nb^n \mid n\ge0\}:$

Define $h(a)=a$ , $h(b)=b$, then $h(L)={a^*}$ , am I right?

Thanks!

Yuval Filmus
  • 276,994
  • 27
  • 311
  • 503
mili
  • 1
  • 1
  • 3
    Please don't double post. When you ask a question on a site, it is simple courtesy to give that community the opportunity to answer it. It's true that this site is a better fit for this question but if you decide that your question should have been posted on a different site, you should either request migration (if it has already been answered) or delete it from the original site. – rici Jun 14 '22 at 13:44

2 Answers2

1

No,by your defined substitution CFLs remains CFLs. For example, $\{a^nb^n \mid n\ge0\} = \{\epsilon,ab, aabb, aaabbb,.......\}.$
After substitution by $h(a) = a$ and $h(b) =b$,$h(\epsilon) = \epsilon$ then the language L becomes remains same, which is CFL. But when every symbol converges to single image then your language forcefully becomes regular (as @rici answer) which is really very bad way of thinking because by the definition homomorphism of CFLs is CFLs.

N. B.- One thing remember substitution for DCFLs are not closed in general (for example) but substitution for CFLs(NCFLs) are closed always.

A. H.
  • 498
  • 1
  • 3
  • 13
1

Yes, you can.

For instance: with language $L = \{a^nb^n \mid n\ge0\}$ and mapping $h(\epsilon)=\epsilon, h(a)=a, h(b)=a$ (which I think is what you meant to write), $h(L) = (aa)^*$.

What is more: every context-free language on a single-symbol alphabet is regular, so a mapping that maps every symbol to the same symbol always produces a regular language.

However, as user19121278 points out, not every mapping will.

For instance: the identity mapping ($h(\epsilon)=\epsilon, h(a)=a, h(b)=b$ for alphabet $\{a,b\}$) maps every language to itself, so it will never map a non-regular language onto a regular one.

reinierpost
  • 5,509
  • 1
  • 21
  • 38