Last modified 2/24/95.
NAD = {B | B in P(A)} REPEAT AD = NAD NAD = AD U {B in V | Exists C in AD s.t. B in P(C)} - {A}. UNTIL (AD = NAD) RETURN ADThe following algorithm assumes there are no e-productions in G.
FOREACH (A in V) AD(A) = Find-A-Deriv(A,G) FOREACH (A in V, B in AD(A)) P1(A) = P(A) U P(B) FOREACH (A in V) P1(A) = P1(A) - AD(A) RETURN
Proof
That G1 has no unit productions is obvious from the last step of the algorithm. That L(G1) is contained in L(G) should be clear, since A =>_G1 alpha iff either A =>_G alpha or A =>*_G B =>_G alpha by construction. Thus any derivation S =>* x in G1 has a corresponding, possibly longer, derivation in G.
That L(G) - {e} is contained in L(G1) may be shown by proving that every sentential form alpha derivable from S in G for which the last step was not a unit production may also be derived from S in G1. Since any derivation of x in L(G) - {e} cannot end in a unit production (there are no variables in x), this will suffice to show L(G)-{e} contained in L(G1). We consider only leftmost derivations, since this allows us to force any succession of unit productions on a variable in the derivation to be applied one after another to the variable in the same position until a non-unit production is applied. We induct on the number of steps in the derivation, n.
Base: n=1
S =>_G alpha <=> alpha in P(S) => alpha in P1(S), since the last and only production cannot be a unit production.
IH: For some K>0, if S =>K_G alpha by a leftmost derivation, and the last step in the derivation is not a unit production, then S =>*_G1 alpha.
IS: Show that for K+1, if S =>K+1_G alpha by a leftmost derivation and the last step in the derivation is not a unit production, then S =>*_G1 alpha.
If S =>K+1_G gamma by a leftmost derivation and the last step in the derivation is not a unit production, then S =>K_G x.B.alpha =>_G x.beta.alpha, where gamma = x.beta.alpha, and beta in P(B). Now consider the last step before this that was not a unit production, if there was one. It must have produced a sentential form x.A.alpha, since we only consider leftmost derivations (A may or may not be B). Since A =>*_G B, beta in P1(A) by construction of P1, so A =>_G1 beta, and x.A.alpha =>_G1 x.beta.alpha. Since S =>_G x.A.alpha in fewer than K+1 steps, S =>*_G1 x.A.alpha by the IH, so S =>*_G1 x.A.alpha =>_G1 x.beta.alpha. On the other hand, if there were no preceding non-unit production in the derivation of x.beta.alpha, then x = alpha = e and S =>K_G B. In this case, beta in P1(S) by construction of P1, so S =>_G1 beta = gamma.
QED