I'm working with a multiway system and I have a number of different mutation rule lists. I need an efficient way of managing which rule lists I apply.

Here is the basic multiway system code that I'm using:

MWStep[rule_List, slist_List] := 
  Union[Flatten[Map[Function[s, Map[MWStep1[#, s] &, rule]], slist]]];

MWStep1[p_String -> q_String, s_String] := 
  Map[StringReplacePart[s, q, #] &, StringPosition[s, p]];

MWEvolveList[rule_, init_List, t_Integer] := 
  NestList[MWStep[rule, #] &, init, t];

StepNtimes[Rule_, string_, n_] := (
   i = 1;
   Subfunc[x_] := MWStep[Rule, x];
   Results = Flatten[NestList[Subfunc, string, n]] )

So for example, with a rules list "M1", I might do

StepNtimes[M1, SampleString, 5]

But say I have Rule lists M1,M2,M3,M4,...,MK

And I want to apply them in different patterns and save the results after each application. That is, if

ResultSetA = StepNtimes[M1, SampleString, 5]
ResultSetB = StepNtimes[M2, ResultSetA, 5]

... I want

FinalResults = Flatten[{ResultSetA, ResultSetB, ...}]

Nested Functions? Composition?

k[{data_, {}}] := {}
k[{data_, rulez_}] := k[{Sow@StepNTimes[data, rulez[[1]], 5], Rest@rulez}]
Reap@k[{data, {M1, M2}}]

(* {{}, {{StepNTimes[data, M1, 5], StepNTimes[StepNTimes[data, M1, 5], M2, 5]}}} *)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.