(*********************************************************************** This file was generated automatically by the Mathematica front end. It contains Initialization cells from a Notebook file, which typically will have the same name as this file except ending in ".nb" instead of ".m". This file is intended to be loaded into the Mathematica kernel using the package loading commands Get or Needs. Doing so is equivalent to using the Evaluate Initialiation Cells menu command in the front end. DO NOT EDIT THIS FILE. This entire file is regenerated automatically each time the parent Notebook file is saved in the Mathematica front end. Any changes you make to this file will be overwritten. ***********************************************************************) SMWNetwork[rule_,s_,n_]:=SMWToNet[Last[SMWEvolveListP[rule,s,n]]] SMWNetwork[rule_,s_,n_,First]:=SMWToNet[Last[SMWEvolveListPFirst[rule,s,n]]] SMWNetwork[rule_,s_,n_,SSS]:=SMWToNet[Last[SMWEvolveListPSSS[rule,s,n]]] SMWToNet[list_]:= With[{u=Map[First,list]}, MapIndexed[ Function[{e,i}, First[i]->((If[#==={},Infinity,#[[1,1]]]&[Position[u,#]])&/@Last[e])], list]] ToListP[s_String]:=Map[{#,c++}&,Characters[s]] SMWEvolveListP[rule_,s_,n_]:= Block[{c=1,events={}},{NestList[SMWStepP[rule,#]&,ToListP[s],n], Flatten[events]}] SMWStepP[rule_,sp_]:= SMWStep1P[rule,sp, SMWFilter[StringPosition[StringJoin[Map[First,sp]],First/@rule]]] SMWFilter[s_]:= Fold[If[Last[Last[#1]]>=First[#2],#,Append[#,#2]]&,{First[s]},Rest[s]] SMWFilter[{}]={}; SMWEvolveListPFirst[rule_,s_,n_]:= Block[{c=1,events={}},{NestList[SMWStepPFirst[rule,#]&,ToListP[s],n], Flatten[events]}] SMWStepPFirst[rule_,sp_]:= SMWStep1P[rule,sp,StringPosition[StringJoin[Map[First,sp]],First/@rule,1]] SMWEvolveListPSSS[rule_,s_,n_]:= Block[{c=1,events={}},{NestList[SMWStepPSSS[rule,#]&,ToListP[s],n], Flatten[events]}] SMWStepPSSS[rule_,sp_]:= SMWStep1P[rule, sp,{If[#==={},{},First[#]]&[ Flatten[StringPosition[StringJoin[Map[First,sp]],First[#],1]&/@rule, 1]]}] SMWStep1P[rule_,s_,pos_]:= Module[{a,b},a=Take[s,#]&/@pos; b=ToListP/@((StringJoin[First/@#]&/@a)/.rule); AppendTo[events,Apply[Rule,Map[Last,Transpose[{a,b}],{3}],{1}]]; Partition[Flatten[ListReplacePart[s,b,Map[List,pos,{-1}]]],2]] SMWStep1P[rule_,s_,{}]:=s ListReplacePart::usage = "ListReplacePart[list, {new1, new2, ... }, {{m1, n1}, {m2, n2}, ... }] replaces elements at positions mi through ni in list by newi."; lrexpand[{f_,l_}] := Map[ Evaluate[Append[Drop[f,-1],#]]&, Range @@ Last /@ {f,l} ] (* replaces parts one by one; can be beautified after multiple assignment in Part is fixed *) ListReplacePart[list_List, new_List, pos_List] := Module[ {positions = lrexpand /@ pos, result = list}, Scan[ ( result[[Sequence @@ First[#[[1]]]]] = #[[2]]; Scan[(result[[Sequence @@ #]] = Sequence[])&, Rest[#[[1]]]] )&, Transpose[{positions,new}] ]; result ] NeighborCountsI[g_,i0_,n_]:= Map[If[MemberQ[#,Infinity],Infinity,Length[#]]&, Module[{gp=Dispatch[Prepend[g,\[Infinity]->{\[Infinity]}]]}, NestList[Union[Flatten[{#,#/.gp}]]&,{i0},n]]]