How to construct unrestricted grammar that generates L = {a^ib^j c^k^d^l : i not equal to k AND j not equal to l}.
a is to the power of i, 'b' raised to the power of j, 'c' raised to the power of k, 'd' rasied to the power l.
I was good with regular and CFG but as unrestricted grammers can contains more than one non-terminal in the left side of production, I'm confused and unable to come to with a solution.
I will not try for the most efficient or most elegant grammar, but shoot for an easy grammar - one we can quickly see must be correct.
Your language L = {a^ib^j c^k^d^l : i not equal to k AND j not equal to l} can be written as the union of four languages L1, L2, L3 and L4:
There is some unrestricted grammar corresponding to each of these cases, call the grammars G1, G2, G3, G4. Then, our grammar G can have a start nonterminal that produces the start nonterminals of each of these four grammars, and it will generate the union of those grammars' languages. Thus, if we can find G1 - G4, our problem is solved. It should be easy to see that each of these grammars will be pretty similar, only differing in which symbols are to be less frequent than which others. We will focus on trying to find G1 and leave G2, G3 and G4 as exercises.
Our strategy for G1 will be the following: write grammars for a^i c^k where i < k, and b^j d^l where j < l, separately; then, combine them and reorder the b's and c's so that everything is in the right order. So, for the first part:
This gives us strings like a^i c^k b^j d^l where i < k and j < l. This is pretty close to what we wanted, but we need the c's and b's swapped. To do this, we can use a special new nonterminal whose only function is to allow A1, B1, C1 and D1 to resolve to a, b, c and d, but only when they are in the right order. To that we will add a production C1 B1 := B1 C1 which will allow the grammar to bubble the B's and C's to the right positions. We can call our special marker M1:
Let's do a few simple examples to show that abccdd is in the language whereas aabccdd and accbdd are not:
Notice that I introduce special marker M' for the very first move, not sure that's really necessary, but you can play with it.