# How to find a context-free grammar from a difficult language? [duplicate]

Some Languages are trivial to find their respective context-free grammar. Like for example $$L= \{a^nb^n: n \geqslant 0\}$$. However some are really difficult to solve. I would like to have some advice on how I can tackle them.

For example I have the following language that I have been trying to solve for a while : I tried to divide the problem into three cases as follow:

case i: na $$\le$$ nb

case ii: nb $$\le$$ na $$<$$ 2nb

case iii: na $$\ge$$ 2nb

The first case was easy to solve however I am stuck in case ii. At this point I don't even know if the procedure that I chose is the correct one.

EDIT: It is not an duplicate 3 of the links that you have provided me are not the same problem one of them is the same suggests the same strategy however doesn't solve the problem.

• @D.W.♦ It is not an duplicate 3 of the links that you have provided me are not the same problem one of them is the same suggests the same strategy however doesn't solve the problem. Oct 19, 2019 at 16:20
• You should be able to adapt the methods there; it's the same idea. Hint: build a PDA.
– D.W.
Oct 19, 2019 at 20:22
{"ft_lang_label":"__label__en","ft_lang_prob":0.9689569,"math_prob":0.80784804,"size":772,"snap":"2022-05-2022-21","text_gpt3_token_len":195,"char_repetition_ratio":0.118489586,"word_repetition_ratio":0.0,"special_character_ratio":0.25,"punctuation_ratio":0.084848486,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.986405,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2022-05-29T12:28:56Z\",\"WARC-Record-ID\":\"<urn:uuid:b4f5a84e-a905-452d-b350-668483b00a0b>\",\"Content-Length\":\"202628\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:87d63b90-3b5d-4456-a912-426d6db63aba>\",\"WARC-Concurrent-To\":\"<urn:uuid:1e734349-b11d-4357-af06-3848b1f498bd>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://cs.stackexchange.com/questions/115983/how-to-find-a-context-free-grammar-from-a-difficult-language?noredirect=1\",\"WARC-Payload-Digest\":\"sha1:NW26KGWAGIRNIKKPD7OLAA6WUCC73JZX\",\"WARC-Block-Digest\":\"sha1:QHRWOYBZGQ2SYAY5SQ7YSBHX3MFOVPRR\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2022/CC-MAIN-2022-21/CC-MAIN-2022-21_segments_1652662644142.66_warc_CC-MAIN-20220529103854-20220529133854-00681.warc.gz\"}"}