2.24 Let E = { aibj | i ≠ j and 2i ≠ j } Show that D is context-free language.
solution:
Split it as unions of 3 languages.
{ aibj | i > j } ∪ { aibj | i < j and 2i > j } ∪ { aibj | 2i < j }
G1 = { aibj | i > j }
G2 = { aibj | i < j and 2i > j }
G3 = { aibj | 2i < j }
G1 and G3 are quite easy to figure out.
for G1
S → aSb | aS1
S1 → aS1 |ε
for G3
S → aSbb | S1b
S1 → S1b | ε
Now tricky part is G2.
S → aSb | aS1b
S1 → aS1bb | aS2bb
S2 → ε
Very clearly, S will generate anamb2mbn that is equivalent to an+mbn+2m where m,n must be greater than 0.
Feel free to comment and correct me if I am wrong. :)
solution:
Split it as unions of 3 languages.
{ aibj | i > j } ∪ { aibj | i < j and 2i > j } ∪ { aibj | 2i < j }
G1 = { aibj | i > j }
G2 = { aibj | i < j and 2i > j }
G3 = { aibj | 2i < j }
G1 and G3 are quite easy to figure out.
for G1
S → aSb | aS1
S1 → aS1 |ε
for G3
S → aSbb | S1b
S1 → S1b | ε
Now tricky part is G2.
S → aSb | aS1b
S1 → aS1bb | aS2bb
S2 → ε
Very clearly, S will generate anamb2mbn that is equivalent to an+mbn+2m where m,n must be greater than 0.
Feel free to comment and correct me if I am wrong. :)
Why not just take the union of 4 separate CFG's?
ReplyDeleteNevermind, I figured it out. Great answer.
Delete