Demo 1

Installation

In[]:=
SystemOpen["https://setreplace.org"]
In[]:=
PacletInstall["SetReplace"]
Out[]=
PacletObject
Name: SetReplace
Version: 0.3.196

In[]:=
<<SetReplace`

Documentation

In[]:=
SystemOpen["https://setreplace.org/blob/master/README.md"]

Arithmetic Multiset Substitution System

Docs: WolframModel
WolframModel[​​rules,​​init,​​stepsCount,​​property,​​options​​]
In[]:=
arithmeticEvolution=WolframModel[​​<|"PatternRules"{a_,b_}{a+b,a-b,ab}|>,​​{2,8,2,5,2},​​<|"MaxEvents"8|>]
Out[]=
WolframModelEvolutionObject
Generations: 2…3
Events: 8

In[]:=
arithmeticEvolution〚1〛
Out[]=
Version2,RulesPatternRules{a_,b_}{a+b,a-b,ab},MaxCompleteGeneration2,TerminationReasonMaxEvents,AtomLists{2,8,2,5,2,10,-6,16,7,-3,10,12,-8,20,10,-22,-96,4,10,-21,22,-2,120,12,-28,-160,-12,32,-220},EventRuleIDs{0,1,1,1,1,1,1,1,1},EventInputs{{},{1,2},{3,4},{5,6},{7,8},{9,10},{11,12},{13,14},{15,16}},EventOutputs{{1,2,3,4,5},{6,7,8},{9,10,11},{12,13,14},{15,16,17},{18,19,20},{21,22,23},{24,25,26},{27,28,29}},EventGenerations{0,1,1,2,2,2,3,3,3}
Docs: AllExpressions
In[]:=
arithmeticEvolution["AllExpressions"]
Out[]=
{2,8,2,5,2,10,-6,16,7,-3,10,12,-8,20,10,-22,-96,4,10,-21,22,-2,120,12,-28,-160,-12,32,-220}
In[]:=
arithmeticEvolution["Properties"]
Out[]=
{EvolutionObject,FinalState,FinalStatePlot,StatesList,StatesPlotsList,EventsStatesPlotsList,AllEventsStatesEdgeIndicesList,AllEventsStatesList,GenerationEdgeIndices,Generation,StateEdgeIndicesAfterEvent,StateAfterEvent,TotalGenerationsCount,PartialGenerationsCount,GenerationsCount,GenerationComplete,AllEventsCount,GenerationEventsCountList,GenerationEventsList,FinalDistinctElementsCount,AllEventsDistinctElementsCount,VertexCountList,EdgeCountList,FinalEdgeCount,AllEventsEdgesCount,AllEventsGenerationsList,ExpressionsEventsGraph,CausalGraph,LayeredCausalGraph,TerminationReason,AllEventsRuleIndices,AllEventsList,EventsStatesList,EdgeCreatorEventIndices,EdgeDestroyerEventsIndices,EdgeDestroyerEventIndices,EdgeGenerationsList,FeatureAssociation,FeatureVector,ExpressionsSeparation,MultiwayQ,Properties,Version,Rules,CompleteGenerationsCount,AllEventsEdgesList}
Docs: States
In[]:=
arithmeticEvolution["AllEventsStatesList"]//Column
Out[]=
{2,8,2,5,2}
{2,5,2,10,-6,16}
{2,10,-6,16,7,-3,10}
{-6,16,7,-3,10,12,-8,20}
{7,-3,10,12,-8,20,10,-22,-96}
{10,12,-8,20,10,-22,-96,4,10,-21}
{-8,20,10,-22,-96,4,10,-21,22,-2,120}
{10,-22,-96,4,10,-21,22,-2,120,12,-28,-160}
{-96,4,10,-21,22,-2,120,12,-28,-160,-12,32,-220}
In[]:=
arithmeticEvolution["FinalState"]
Out[]=
{-96,4,10,-21,22,-2,120,12,-28,-160,-12,32,-220}
In[]:=
arithmeticEvolution["StateAfterEvent",2]
Out[]=
{2,10,-6,16,7,-3,10}
In[]:=
arithmeticEvolution["StateAfterEvent",-3]
Out[]=
{-8,20,10,-22,-96,4,10,-21,22,-2,120}

Expressions-Events Graph

Docs: ExpressionsEventsGraph
In[]:=
arithmeticEvolution["ExpressionsEventsGraph"]
Out[]=
In[]:=
arithmeticEvolution["ExpressionsEventsGraph",VertexLabels"Name"]
Out[]=

HypergraphPlot

Docs: HypergraphPlot

Atom-Preserving Hypergraph Substitution Systems

Docs: RulePlot
Docs: FinalStatePlot
Docs: EventsStatesPlotsList

Creating Atoms

SetReplace’s C++ code stores an index of all possible matches of rules to the current state. As such, it’s fast if:
1
.
Simple patterns, i.e., Hypergraph Substitution System.
2
.
Vertex degrees are small.
3
.
Left-hand sides of rules are connected and small.

ToPatternRules

Docs: ToPatternRules

Demo 2

Event Order

Multiway System

Demo 3: Expression Deduplication

The only necessary condition for deduplication is this one:
1
.
Original (duplicated) multihistory should be fully recoverable.
There are also two things that would be nice to have:
2
.
Deduplication should be unique.
3
.
Only branchlike expressions are deduplication.
Consider the following example:
In any reasonable deduplication scheme, we would expect the 2’s and the 1’s to be merged. Indeed, the tokens here are also global states, and the duplicate 1’s and 2’s are just two ways to get to the same state, which is the quintessential case of deduplication.
Second, notice that these cases are completely symmetric, so, if we assume uniqueness, we have to deduplicate them both:
However, what happens if we combine the two?
We get time-loops (e.g., {1, 3, 2, 4, 1, …}). Thus, uniqueness implies time-loops.
Consider the following. Let’s say we have a multihistory with only a single branching point. The two histories it produces terminate on identical states. However, those states are automorphic. The question is, how do we deduplicate them?
There are two ways to deduplicate the 7’s, yielding different token-event graphs:
This seems to suggest that uniqueness is just impossible. However, if we keep demanding it, there is just one thing left that we can do.
We can simply deduplicate every expression with the same contents, and delegate figuring out the quantity to the parsing algorithm. In this case, we get something like this:
At first it seems that we are irrevocably losing information, as we can no longer match identical but spacelike-separated tokens. But that is, in fact, not the case. We have the record of all the rules, so we can still recover the original TEG. We just take every confluence point and unroll it including its entire out component. We will get infinite results in case of time loops, but that is just because infinitely compressed the evaluation.
For example, consider a system that increments numbers but also turns them into prime factors.
And we can still recover the evaluation from this (including some infinite evaluations)! Essentially, all we did here is we instantiated the patterns in the rules to explicit patternless rules. But since we do know all such explicit patterns, we can reconstruct the evaluation as well by simplify following these events as if they were rules:
Note the case of {4} -> {2, 2} at the bottom right:
Hence, we have satisfied the constraints (1) and (2) on deduplication. Original multihistory is recoverable, and the result is unique. However, we did not satisfy the condition (3), as both timelike and even spacelike tokens are deduplicated as well.
The case with new atoms will of course be much more complicated, but we don’t consider it here.
Now, it’s important to point out that we have delegated a lot of stuff to the reconstruction algorithm, and it’s not clear how quickly, e.g., states can be recovered from that. So, in a sense, this is an intermediate representation between rules and the duplicated TEG.
Another way to think about this is that this essentially splits the problem into two independent pieces. First, we construct this deduplicated TEG from the rules, and then we use the deduplicated TEG to obtain specific histories and do whatever we need with them.