In[]:=
f[a]/.f[x_]->g[x]
Out[]=
g[a]
In[]:=
MultiSubsetReplace[f[a],f[x_]->g[x]]
Out[]=
{{}}{g[a]}
In[]:=
MultiSubsetReplace[u[f[a],f[b]],f[x_]->g[x]]
Out[]=
{{1}}{u[g[a],f[b]]},{{2}}{u[f[a],g[b]]}
In[]:=
MultiSubsetReplace[u[f[a],f[b]],{f[x_],f[y_]}->g[x,y]]
Out[]=
{{1},{2}}{u[g[a,b]],u[g[b,a]]}
This means that the match was at the subset of positions {{1},{2}} ... and f[x_], f[y_] are identical “particles” all that matters is the subset
In[]:=
MultiSubsetReplace[u[f[a],fp[b]],{f[x_],fp[y_]}->g[x,y]]
Out[]=
{{1},{2}}{u[g[a,b]]}
In[]:=
MultiSubsetReplace[f[f[a]],{f[x_],f[y_]}->g[x,y]]
Out[]=
{{},{1}}{g[f[a]],g[a]}
This is applying a set of rules to subparts of an arbitrary expression
Ordinary multiway combinator evolution does one combinator reduction at a time .... but this can do any subset....
In[]:=
MultiSubsetReplace[s[s][s][s[s[k]]][k],{s[x_][y_][z_]->x[z][y[z]],k[x_][y_]->x},Heads->True]
Out[]=
{1,{{0}}}{s[s[s[k]]][s[s[s[k]]]][k]}
In[]:=
NestGraph[MultiSubsetReplace[#,{s[x_][y_][z_]->x[z][y[z]],k[x_][y_]->x},Heads->True]&,s[s][s][s[s[k]]][k],5]
Out[]=
$Aborted
In[]:=
NestGraph[Flatten[Values[MultiSubsetReplace[#,{s[x_][y_][z_]->x[z][y[z]],k[x_][y_]->x},Heads->True]]]&,s[s][s][s[s[k]]][k],20]
Out[]=
MultiSubsetReplace
{{1,2},{2,3},{2,4}}
In[]:=
MultiSubsetReplace[{{1,1},{1,1}},{{x_,y_},{x_,z_}}:>Module[{w},{{x,y},{x,w},{y,w},{z,w}}]]
Out[]=
{{1},{2}}{{{{1,1},{1,w$15414},{1,w$15414},{1,w$15414}}},{{{1,1},{1,w$15415},{1,w$15415},{1,w$15415}}}}
In[]:=
Catenate[Values[MultiSubsetReplace[#,{h[x_,y_],h[x_,z_]}:>Module[{w},fhack@{h[x,y],h[x,w_],h[y,w_],h[z,w_]}]]&[{h[1,1],h[1,1],h[1,2]}]]/.fhack->Splice]
Out[]=
{{h[1,1],h[1,w$30717_],h[1,w$30717_],h[1,w$30717_],h[1,2]},{h[1,1],h[1,w$30718_],h[1,w$30718_],h[1,w$30718_],h[1,2]},{h[1,1],h[1,w$30719_],h[1,w$30719_],h[2,w$30719_],h[1,1]},{h[1,2],h[1,w$30720_],h[2,w$30720_],h[1,w$30720_],h[1,1]},{h[1,1],h[1,1],h[1,w$30721_],h[1,w$30721_],h[2,w$30721_]},{h[1,1],h[1,2],h[1,w$30722_],h[2,w$30722_],h[1,w$30722_]}}
In[]:=
NestGraph[Catenate[Values[MultiSubsetReplace[#,{h[x_,y_],h[x_,z_]}:>Module[{w},fhack@{h[x,y],h[x,w_],h[y,w_],h[z,w_]}]]&[#]]/.fhack->Splice]&,{{h[1,1],h[1,1]}},2]
Out[]=
In[]:=
NestGraph[(Sort@*canonicalizePatterns/@Catenate[Values[MultiSubsetReplace[#,{h[x_,y_],h[x_,z_]}:>Module[{w},fhack@{h[x,y],h[x,w_],h[y,w_],h[z,w_]}]]&[#]]/.fhack->Splice])&,{{h[1,1],h[1,1]}},3,AspectRatio->1/2]
Out[]=
In[]:=
Map[Framed,NestGraph[(Sort@*canonicalizePatterns/@Catenate[Values[MultiSubsetReplace[#,{h[x_,y_],h[x_,z_]}:>Module[{w},fhack@{h[x,y],h[x,w_],h[y,w_],h[z,w_]}]]&[#]]/.fhack->Splice])&,{{h[1,1],h[1,1]}},2,AspectRatio->1/2]//VertexList]
Out[]=
,,,,
In[]:=
Map[Framed,ResourceFunction["MultiwaySystem"]["WolframModel"->{{{x,y},{x,z}}->{{x,y},{x,w},{y,w},{z,w}}},{{{1,1},{1,1}}},2],{1,2}]
Out[]=
,,
In[]:=
ResourceFunction["MultiwaySystem"]["WolframModel"->{{{x,y},{x,z}}->{{x,y},{x,w},{y,w},{z,w}}},{{{1,1},{1,1}}},3,"StatesGraphStructure",AspectRatio->1/2]
Out[]=
In[]:=
Framed/@(ResourceFunction["MultiwaySystem"]["WolframModel"->{{{x,y},{x,z}}->{{x,y},{x,w},{y,w},{z,w}}},{{{1,1},{1,1}}},2,"StatesGraphStructure",AspectRatio->1/2]//VertexList)
Out[]=
,,,,
Replacing sets of tokens wherever they appear (not necessarily in a container that is a set)
Replacing sets of tokens wherever they appear (not necessarily in a container that is a set)
The container of tokens is not immediately sorting
In[]:=
RandomTree[50]
Out[]=
In a single match, the same subtree could be the binding for two different patterns [ not yet ]
General idea: replacements for <sets of subexpressions> in general symbolic expressions
General idea: replacements for <sets of subexpressions> in general symbolic expressions
Ordinary pattern matching is the 1⟶1 version of this, with each replacement replacing a single subexpression
Step 1: pick out certain subexpressions .... leaving stubs where they go
Step 2: take the subexpressions and generate a new list of subexpressions (possibly of different lengths)
Step 3: some kind of reinsertion
Step 1: pick out certain subexpressions .... leaving stubs where they go
Step 2: take the subexpressions and generate a new list of subexpressions (possibly of different lengths)
Step 3: some kind of reinsertion
Step 2: take the subexpressions and generate a new list of subexpressions (possibly of different lengths)
Step 3: some kind of reinsertion
[[ Token-event graphs don’t have to reinsert ]]
[[ When there is reinsertion, causal dependence is more nontrivial, because there are spectators ]]
[[ When there is reinsertion, causal dependence is more nontrivial, because there are spectators ]]
MultiReplace is a generalization of ReplaceList
MultiReplace is a generalization of ReplaceList
Cosubstitution for Hypergraphs
Cosubstitution for Hypergraphs