0
$\begingroup$

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?

$\endgroup$
5
  • $\begingroup$ Your 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 as SubstitutionSystem was designed for this specific case. I'd rather stick to the powerful primitives of the language such as NestList. $\endgroup$
    – user293787
    Aug 11, 2022 at 9:09
  • $\begingroup$ @user293787, I would like to take advantage of the opportunities of this package: wolframcloud.com/obj/wolframphysics/Tools/guide-page $\endgroup$
    – lesobrod
    Aug 11, 2022 at 9:13
  • $\begingroup$ SubstitutionSystem applies the rule sequentially. Therefore, you must specify the more specific rules klike: "AA" -> "A" before the simpler rules like: "A" -> "BC" $\endgroup$ Aug 11, 2022 at 9:39
  • $\begingroup$ @DanielHuber, unfortunately any permutations of rules give the same result $\endgroup$
    – lesobrod
    Aug 11, 2022 at 9:44
  • $\begingroup$ MMA version 13.1 I get different results from: rules1 = {"A" -> "BC", "B" -> "AC", "C" -> "AB", "AA" -> "A", "BB" -> "B", "CC" -> "C"}; and rules2 = {"AA" -> "A", "BB" -> "B", "CC" -> "C", "A" -> "BC", "B" -> "AC", "C" -> "AB"}; $\endgroup$ Aug 11, 2022 at 9:54

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.