Rewriting system is a set of rules in the form of $A \leftrightarrow B$. If we apply that rule to a string $w$ we replace any substring $A$ in $w$ with a substring $B$ and vice versa.
Given a starting string $AAABB$ can we derive $BAAB$ in the system with the following rules:
- $A \leftrightarrow BA$
- $BABA \leftrightarrow AABB$
- $AAA \leftrightarrow AB$
- $BA \leftrightarrow AB$
Is there a general algorithm for that?