Here is the problem. Let us say we have a word made up of two letters, for example, $ABBBA$. Say I enforce the substitution $A\to AB$ to get the word $ABBBBAB$. Is it always the case that if I know the final word and the substitution, I can blindly turn $AB\to A$ one by one from left to right and get the original word? Clearly, you can create the substitution word "accidentally":
For example: $ABA$ enforce $A\to ABA$ then we get $ABABABA$, notice here we created another $ABA$, doing reverse substitution still works though. The issue is, what if we create the substitution word in the beginning? Then I think we will not go back to the original. I do not think that is possible, but was wondering if anyone could confirm my suspicion.
Let $A = \{a, b\}$ and let $u, v \in A^*$. A well-known result (see for instance [1, Chapter 1]) states that the following conditions are equivalent:
It follows that the monoid morphism $f: A^* \to A^*$ defined by $f(a) = u$ and $f(b) = v$ is injective if and only if $uv \not= vu$.
EDIT. For instance, if $f(a) = ab$ and $f(b) = b$, then $f$ is injective since $(ab)a = aba \not= aab = a(ab)$. If $f(a) = b^n$ and $f(b) = b$, then $f$ is not injective since $b^nb = bb^n$ (or directly since $f(a) = f(b^n)$.
[1] Lothaire, M. Combinatorics on words. Corrected reprint of the 1983 original, with a new preface by Perrin. Cambridge Mathematical Library. Cambridge University Press, Cambridge, 1997. xviii +238 pp. ISBN: 0-521-59924-5