I'm examining two-step substitution model:
- First step, division: {"A" -> "BC", "B" -> "AC", "C" -> "AB"}
- Second step, merging: {"AA" -> "A", "BB" -> "B", "CC" -> "C"}
This code not work correctly:
rules = {"A" -> "BC", "B" -> "AC", "C" -> "AB","AA" -> "A", "BB" -> "B", "CC" -> "C"};
SubstitutionSystem[rules, "A", 4]
Out = {"A", "BC", "ACAB", "BCABBCAC", "ACABBCBABBCAB"}
Nor even this:
NestList[StringReplace[#, rules]&, "A", 4]
Out = {"A", "BC", "ACAB", "BCABBCAC", "ACABBCBABBCAB"}
But the next is correct:
rules1 = {"A" -> "BC", "B" -> "AC", "C" -> "AB"};
rules2 = {"AA" -> "A", "BB" -> "B", "CC" -> "C"};
NestList[StringReplace[StringReplace[#, rules1], rules2]&, "A", 4]
Out = {"A", "BC", "ACAB", "BCABCAC", "ACABCACABCAB"}
Is it possible to get this result with SubstitutionSystem
?
NestList
looks fine and reflects exactly what you want. I do not know if there is any point in asking whether a convenience command such asSubstitutionSystem
was designed for this specific case. I'd rather stick to the powerful primitives of the language such asNestList
. $\endgroup$