Question 4 (2007)
So to show that the language L
1 and L
2 are closed under union we do the following
Take all nonterminals in the CFG for L
1 and add a
1
Take all nonterminals in the CFG for L
2 and add a
2
Now create a new start state S -> S
1 | S
2 and combine the language so that you get the following
0. S -> S
1 | S
2
1. S
1 -> X
1Y
1 | aS
1
2. X
1 -> Y
1X
1a | a
3. Y
1 -> b | Y
1Y
1
4. S
2 -> S
2X
2 | Y
2
5. X
2 -> a | aY
2 | /\
6. Y
2 -> bS
2 | bY
2 | b
We have obviously not duplicated any nonterminals therefore these languages should still produce the same language as before.
Proof both ways:
1) All words generated by this new CFG can be generated by either S
1 or S
2
So to generate a word we start in S (0) from here we either go to S
1 (1) or S
2 (4). On entering either of these states you will be unable to return to S and will only complete the CFG 1 -3 or 4 -6. Since both of these CFG's represent their original CFG's in their entirety, and are unable to enter any state other than those, you will only be able to generate the words in one or the other. Therefore this new CFG generates the words from either S
1 or S
2 and none other.
2) All words generated by S
1 or S
2 can be generated by this new CFG
To generate a word from L
1 or L
2, you would enter it's start state and proceed as normal. Since L
1 and L
2 are now represented by the states with either
1 or
2 and you are only able to enter one or the other, all word generated by either S
1 or S
2 can be generated by the new CFG.
Waffle Waffle Waffle.