In some cases, it is relatively easy to prove that two formal grammars are equivalent. If two grammars generate a finite language, then you only need to compare the sets of strings generated by both grammars to prove that they are weakly equivalent.
In some other cases, it is possible to simplify an equivalence proof by replacing non-terminal symbols with terminal symbols. In this example, A1
is equivalent to A
because D
can be replaced with B C
:
A --> A B C
A1 --> A D
D --> B C
Equivalence proofs can sometimes be simplified by re-writing grammars into normal forms, such as Chomsky normal form.
Similarly, there are some repeating patterns that can be proven to be weakly equivalent. All three of the following grammars are equivalent to (B | A)*
, where *
is the Kleene star:
A1 --> (B*) ((B A)*)
A2 --> ((B | A)*) (B*)
A2 --> (B | A | (A B))*