We will use this grammar
S -> XY
X -> aXb
X -> ab
Y -> cYd
Y -> cY
Y -> cd
And show the language of the grammar has |w|c - |w|d + |w|a ≥ |w|b
. The proof is by induction on the number of applications of the productions X -> aXb
, Y -> cYd
and Y -> cY
.
Base case: there is only one string derived without invoking these productions, namely, abcd
, and it satisfies |w|c - |w|d + |w|a >= |w|b
since 1 - 1 + 1 >= 1
.
Induction hypothesis: assume the claim holds for all strings derived using up to and including k
applications of one of the three productions given above.
Induction step: we show that the claim holds for strings derived by k+1
applications of the productions. Since each of our productions has the same type and number of nonterminals in the LHS and RHS, and since the RHS also contains terminals in all cases, there is a shorter string in the language derived with at least one fewer application of these productions. By the hypothesis, that shorter string has |w|c - |w|d + |w|a >= |w|b
. For our string, there are three cases:
X -> aXb
was the k+1
st production applied. This increases |w|a
and |w|b
by 1, and we have |w|c - |w|d + |w|a + 1 >= |w|b + 1
iff |w|c - |w|d + |w|a >= |w|b
, which we have already determined.
Y -> cYd
was the k+1
st production applied. This increases |w|c
and |w|d
by 1, and we have |w|c + 1 - (|w|d + 1) + |w|a >= |w|b
which holds iff |w|c - |w|d + |w|a >= |w|b
, which we have already determined.
Y -> cY
was the k+1
st production applied. This increases |w|c
by 1, giving |w|c + 1 - |w|d + |w|a >= |w|b
which is true since |w|c + 1 - |w|d + |w|a > |w|c - |w|d + |w|a >= |w|b
.
In each of the three possible cases of the choice for the k+1
st production, the string derived in k+1
productions maintains the property. By induction, the property holds for all numbers n
of applications of these productions.