Trivalent Graphs
Trivalent Graphs
Stephen Wolfram, Max Piskunov : 9a28d3dec6dc8d0699ef9a16a2145b5ae79faf3d
Source Code
Source Code
Dependencies
Dependencies
In[]:=
<<SetReplace`;Quiet[ParallelEvaluate[<<SetReplace`],CloudConnect::clver];
In[]:=
getResourceFunction[filename_]:=NotebookEvaluate[FileNameJoin[filename],EvaluationElements"InitializationCell"]
In[]:=
getResourceFunction[FileNameJoin[{$Dropbox,"Physics/CodeDevelopment/FunctionRepositorySources",#<>".nb"}]]&/@{"ParallelMapMonitored"};
Data
Data
In[]:=
$subnetsPureRewritesTo8=Get[FileNameJoin[{$Dropbox,"Physics/SW2004Material/Data/SubnetsPureRewritesTo8.m"}]];
In[]:=
$trivalentRulesTo8=$subnetsPureRewritesTo8〚All,All,1,2〛;
Model Translation Code
Model Translation Code
In[]:=
nestedToFlatIndex[arity_][{v_,e_}]:=arity(v-1)+e
In[]:=
trivalentSpecToHypergraph[spec_]:=Catenate@MapIndexed[{v@First@#2,Replace[#,{_h#,_Integere@@Sort@{#,nestedToFlatIndex[3]@#2}}]}&,spec,{2}]
In[]:=
trivalentRuleToHypergraphRule[in_out_]:=trivalentSpecToHypergraph[in](trivalentSpecToHypergraph[out]/.{v[n_]v[n+Length@in],e[ports__]e@@({ports}+Length@Catenate@in)})
In[]:=
hypergraphToGraph[edges_,opts:OptionsPattern[]]:=Graph[UndirectedEdge@@@SubsetReplace[{{v1_,e_},{v2_,e_}}{v1,v2}]@edges,opts,EdgeStyleDirective[Gray,Thick],VertexSize0,VertexStyleTransparent]
Init
Init
In[]:=
trivalentInit[in__]:=With[{portCount=Length@Catenate@in},ReplacePart[Catenate[{#nestedToFlatIndex[3]@#+portCount,#+{Length@in,0}nestedToFlatIndex[3]@#}&/@Position[_h]@in]]@Join[in,in+portCount]]
Examples
Examples
In[]:=
$terminationReasons=ParallelMapMonitored[WolframModel[trivalentRuleToHypergraphRule@#,trivalentSpecToHypergraph@trivalentInit@#,5]@"TerminationReason"&,$trivalentRulesTo8];
In[]:=
Counts[$terminationReasons]
Out[]=
MaxGenerations235,FixedPoint2725
In[]:=
$nonTerminatingIndices=First/@Position["MaxGenerations"]@$terminationReasons
Out[]=
In[]:=
$finalGraphs=ParallelMapMonitored[Tooltip[hypergraphToGraph[WolframModel[trivalentRuleToHypergraphRule@#,trivalentSpecToHypergraph@trivalentInit@#,4]@-1,ImageSizeTiny],#]&,$trivalentRulesTo8〚$nonTerminatingIndices〛]
Out[]=