代换系统
SubstitutionSystem 生成表示给定初始状态和按照基本规则迭代应用的演变的列表.
以下为初始状态和基本规则.
In[1]:=
init = "\[Wolf]";
rules = {"\[HappySmiley]" -> "\[Wolf]\[HappySmiley]",
"\[Wolf]" -> "\[HappySmiley]"};
用 SubstitutionSystem 获取 8 个迭代后的演变.
In[2]:=
SubstitutionSystem[{"\[HappySmiley]" -> "\[Wolf]\[HappySmiley]",
"\[Wolf]" -> "\[HappySmiley]"}, "\[Wolf]", 8] // Column
Out[2]=
用二维基本规则构建谢尔宾斯基地毯(Sierpiński carpet).
In[3]:=
rules2D = {1 -> {{1, 1, 1}, {1, 0, 1}, {1, 1, 1}},
0 -> ConstantArray[0, {3, 3}]};
用 RulePlot 可视化该代换系统.
In[4]:=
RulePlot@SubstitutionSystem[rules2D]
Out[4]=
生成谢尔宾斯基地毯.
In[5]:=
ArrayPlot /@ SubstitutionSystem[rules2D, {{1}}, 5]
Out[5]=