WOLFRAM NOTEBOOK

Correspondence between Wolfram Model and String Rewriting

"ABBAAB"
{{a},{
{"AAB""BB","BA""ABB"}
Can the string be represented by a linked list?
{{0,"a",1},{1,"b",2},{2,"b",3},XXXX}
{{x0,"a",x1},{x1,"a",x2},{x2,"b",x3}}{{x0,"b",y1},{y1,"b",x3}}
Could encode a and b with single and double loop....
"AAB" could be:
{{0,a0,a0,1},{1,a1,a1,2},{2,b2,b2,b2,3}}
In[]:=
StringToWMSet[s_String,minloop_:0]:=With[{chars=Union[Characters[s]]},MapIndexed[Flatten[{First[#2]-1,Table[Symbol[#<>IntegerString[First[#2]]],FirstPosition[chars,#][[1]]+minloop],First[#2]}]&,Characters[s]]]
In[]:=
StringToWMRule0[s_String,{li_,ri_},minloop_:0]:=With[{chars=Union[Characters[s]]},MapIndexed[Flatten[{If[First[#2]1,li,-First[#2]],Table[Symbol[#<>IntegerString[First[#2]]],FirstPosition[chars,#][[1]]+minloop],If[First[#2]StringLength[s],ri,-First[#2]-1]}]&,Characters[s]]]
In[]:=
StringRuleToWMRule[rules_List,minloop_:0]:=StringRuleToWMRule[#,minloop]&/@rules
In[]:=
StringRuleToWMRule[lhs_rhs_,minloop_:0]:=StringToWMSet[lhs,minloop]StringToWMRule0[rhs,{0,StringLength[lhs]},minloop]
In[]:=
StringToWMSet["AAB"]
Out[]=
{{0,A1,1},{1,A2,2},{2,B3,B3,3}}
In[]:=
StringToWMSet["AAB",1]
Out[]=
{{0,A1,A1,1},{1,A2,A2,2},{2,B3,B3,B3,3}}
In[]:=
StringToWMSet["ABBAAB"]
Out[]=
{{0,A1,1},{1,B2,B2,2},{2,B3,B3,3},{3,A4,4},{4,A5,5},{5,B6,B6,6}}
In[]:=
StringRuleToWMRule[{"AAB""BB","BA""ABB"}]
Out[]=
{{{0,A1,1},{1,A2,2},{2,B3,B3,3}}{{0,B1,-2},{-2,B2,3}},{{0,B1,B1,1},{1,A2,2}}{{0,A1,-2},{-2,B2,B2,-3},{-3,B3,B3,2}}}
In[]:=
WolframModel[StringRuleToWMRule[{"AAB""BB","BA""ABB"}],StringToWMSet["ABBAAB"],3]
Out[]=
In[]:=
HypergraphPlotSW[#,VertexLabelsAutomatic]&/@%["StatesList"]
Out[]=
In[]:=
StringToWMSet["A"]
Out[]=
{{0,A1,1}}
In[]:=
Map[StringToWMSet,{"A""AB","B""A"},{2}]
Out[]=
{{{0,A1,1}}{{0,A1,1},{1,B2,B2,2}},{{0,B1,1}}{{0,A1,1}}}
In[]:=
StringRuleToWMRule[{"A""AB","B""A"},1]
Out[]=
{{{0,A1,A1,1}}{{0,A1,A1,-2},{-2,B2,B2,B2,1}},{{0,B1,B1,1}}{{0,A1,A1,1}}}
In[]:=
WolframModel[StringRuleToWMRule[{"A""AB","B""A"},1],StringToWMSet["A",1],6]
Out[]=
In[]:=
HypergraphPlotSW[#,VertexLabelsAutomatic]&/@%["StatesList"]
Out[]=
In[]:=
HypergraphPlotSW/@WolframModel[StringRuleToWMRule[{"A""AB","B""A"},1],StringToWMSet["A",1],6]["StatesList"]
Out[]=
In[]:=
WolframModel[StringRuleToWMRule[{"AA""A"},1],StringToWMSet["AAAAA",1],6]
Out[]=
In[]:=
HypergraphPlotSW[#,VertexLabelsAutomatic]&/@%["StatesList"]
Out[]=
Note: in this case there are no fresh nodes generated.
In[]:=
$Version
Out[]=
12.1.0 for Mac OS X x86 (64-bit) (October 11, 2019)

Model Generalization?

Can the tuples be nested?
(I.e. can there be a nontrivial data structure in the hyperedges?) (e.g. a list of lists rather than a flat list)
Wolfram Cloud

You are using a browser not supported by the Wolfram Cloud

Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.


I understand and wish to continue anyway »

You are using a browser not supported by the Wolfram Cloud. Supported browsers include recent versions of Chrome, Edge, Firefox and Safari.