# Can an intersection of two context-free languages be an undecidable language?

I'm trying to prove that

$\exists L_1, L_2 : L_1$ and $L_2$ are context-free languages $\land\;L_1 \cap L_2 = L_3$ is an undecidable language.

I know that context-free languages are not closed under intersection.

This means that I can produce an $L_3$, which is undecidable.

An example would be $L_1 = \{a^n | n \in \mathbb{N}\} \cap L_2 = \{0\} = \emptyset$.

• Is this a correct proof?
• If not, how can I prove this theorem?
• Is the empty language decidable?
• What research have you done? Do you know what "undecidable" means? Do you know how to prove that a language is decidable or not? You ask "how can I prove this theorem" - what have you tried? How have you tried to prove it? Do you know how to prove that something is/isn't decidable?
– D.W.
Jul 18, 2014 at 21:49
• @D.W. Some. Yes. Yes. See above. By using known properties. Yes (same question as 2). How do these questions help? Jul 19, 2014 at 1:06

Context-free languages are decidable, and decidable languages are closed under intersection.

So, though the intersection of two CF languages may not be CF, it is decidable.

Remarks on your example:

• $\emptyset=\{\}\neq$ $\{0\}$

• $L_1\cap\emptyset=\emptyset$ which is context-free.

• You cannot prove your claim, because it is wrong

• the empty language is decidable: the answer is always "no, this string is not in the empty set".

• Is the intersection of two context-free languages then at least context-sensitive, or can it be just a decidable, but not context-sensitive language? Jul 18, 2014 at 21:07
• @polym Context-free languages are context-sensitive, and context-sensitive languages are closed under intersection. So, yes, the intersection of two CF languages is context-sensitive. Jul 18, 2014 at 21:17
• Ah right thanks. My mistake was not considering $CFL \subseteq CSL$ and the properties of CSL. Jul 19, 2014 at 1:26
• Q1. Is this problem decidable: "Is the intersection of two context free languages also context free?" Q2. Does all questions asking if operation on two languages of same type, not closed under that operation, result in the language of the same type are undecidable?
– Maha
Dec 22, 2016 at 17:21
• @Mahesha999 Comments can be used for clarification, not for new questions. So you should ask this in a new question. But you should make precise what you mean by the type of a language, and by an operation on two languages of the same type, if you want Q2 to make sense. Dec 22, 2016 at 20:41

Make sure that you understand what decidable means for a language $L$: it means that there is an algorithm that, given $x$, terminates and outputs either $x \in L$ or $x \notin L$ (correctly). It is easy to construct such an algorithm for the language $L = \emptyset$: it always returns $x \notin L$.

As babou mentions in their answer, while context-free languages are not closed under intersection, it is easy to decide whether $x \in L_1 \cap L_2$ for any context-free $L_1,L_2$:

• First determine whether $x \in L_1$ and $x \in L_2$
• If both are true:
• return $x \in L_1 \cap L_2$
• Otherwise:
• return the converse.

As babou mentions, we only really use the fact that $L_1,L_2$ are themselves decidable.

• So the empty language $L_{\emptyset}$ is decidable, because I can always say that $x \not\in L_{\emptyset}$ and my machine stops after telling me that? Jul 18, 2014 at 21:22
• @polym Exactly. Jul 18, 2014 at 21:29
{"ft_lang_label":"__label__en","ft_lang_prob":0.8814854,"math_prob":0.8774008,"size":461,"snap":"2022-40-2023-06","text_gpt3_token_len":152,"char_repetition_ratio":0.124726474,"word_repetition_ratio":0.0,"special_character_ratio":0.3362256,"punctuation_ratio":0.13186814,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.995034,"pos_list":[0],"im_url_duplicate_count":[null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-10-06T03:46:24Z\",\"WARC-Record-ID\":\"<urn:uuid:19bd4a12-4833-4a0a-a3fb-5af5155cfd99>\",\"Content-Length\":\"249384\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:a09a171f-185f-497f-9f15-39f362180714>\",\"WARC-Concurrent-To\":\"<urn:uuid:0017268f-912d-4ba9-beda-cf0fc0914441>\",\"WARC-IP-Address\":\"151.101.193.69\",\"WARC-Target-URI\":\"https://cs.stackexchange.com/questions/28531/can-an-intersection-of-two-context-free-languages-be-an-undecidable-language\",\"WARC-Payload-Digest\":\"sha1:65JZ2P2NMWXIXKLFSGJQ6ODNA7QHZ57Q\",\"WARC-Block-Digest\":\"sha1:3AGJEZKC3CDNPNEOKDF7YNCTCAKKWZR4\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-40/CC-MAIN-2022-40_segments_1664030337723.23_warc_CC-MAIN-20221006025949-20221006055949-00287.warc.gz\"}"}