4

Intersection of CFL and regular is always CFL. But according to Chomsky hierarchy diagram, regular languages lie completely inside CFL. So, as regular set is completely inside CFL set, their intersection should be regular right ?

Am I interpreting Chomsky diagram wrongly ?

Pedro A
  • 103
  • 3
Ramesh
  • 391
  • 4
  • 13

2 Answers2

11

You are confusing two different statements.

  1. $\mathrm{CFL} \cap \mathrm{REG} = \mathrm{REG}$ or, equivalently,
    for all $L_1 \in \mathrm{REG}$ : $L_1 \in \mathrm{CFL}$.
  2. For all $L_1 \in \mathrm{REG}$, $L_2 \in \mathrm{CFL}$ : $L_1 \cap L_2 \in \mathrm{CFL}$.

The first makes a statement on two sets of languages (aka language classes), the second makes one over (many) pairs of sets of strings (aka languages). So in mixing the two, you are creating a type error.

Also, you seem to suggest that if a language is context-free, it's not regular. That is false; we have $\mathrm{REG} \subsetneq \mathrm{CFL}$ (cf. 1.), so showing a language is CFL (using 2.) does not preclude it from being regular. Specifically, it's easy to find examples of a non-regular context-free and a regular language whose intersection is regular.

Raphael
  • 73,212
  • 30
  • 182
  • 400
8

No, you are misinterpreting stuff.

The set of languages (DFL, regular, ...) and the set of strings in a language are independent.

It is entirely possible that a regular language contains strings that are not inside a Context free language.

The trivial example is where the regular language is all strings $\Sigma^*$ and the CFL is any other language. The intersection between them is the original CFL.

ratchet freak
  • 4,696
  • 1
  • 18
  • 15