Is there anything that stops a rule from being applied twice in same place?

Greetings, I am looking into how to apply rules, particularly like the rule of order 2_2 \rightarrow 4_2

I would like to use a rule like: \{\{a,x\}, \{a,y\} \} \rightarrow \left\{\{a,x\}, \{a,y\}, \{x,b\}, \{y,b\}\right\}, but rule could be applied multiple times at the same location. Is this a problem or a feature?

I am interested in rules which might be able to show that they preserve some form of probability amplitude* (unitary in the quantum mechanical sense).

Thoughts?
Cheers, and Thanks.

Notes:
* - Still early days as I work my way through the Wolfram Physics Project documentation.

You should be more specific or a least give a snippet of code, since ReplaceAll replaces only one (and only the first replacement rule that matches)
Try this and notice that the rule is used only once.

Range[5]/. {left___, x_, y_, right___} :> {left, {x, y}, right}

If you have two rules, only the first that matches is used, and only once (ReplaceAll is /. )

ReplaceAll[
 Range[5], {{left___, x_, y_, right___} :> {left, {x, y}, 
    right}, {left___, x_, y_, z_, right___} :> {left, {x, y, z}, 
    right}}]

If you would like to make all the replacements possible, than you need to use ReplaceList

ReplaceList[
Range[5], {left___, x_, y_, right___} :> {left, {x, y}, right}]
or

ReplaceList[
 Range[5], {{left___, x_, y_, right___} :> {left, {x, y}, 
    right}, {left___, x_, y_, z_, right___} :> {left, {x, y, z}, 
    right}}]

So, it matters which replacement instructions is used (there are more than just the two I mentioned)

Thanks. I need to install/access Mathematica/Wolfram Language system so I can try this out with code.

The question was more of a philosophical one, with regards to the underlying graph theoretic considerations.

I think I have my answer: (TL;DR in short) - No

Applying the rule more than once to the same location, results in the gives the same graph and hence same result. I was trying to avoid a ‘multiworld interpretation’ where applying the rule causes the graph to split.

It is recommended to look at Wolfram’s notes of the NKS book (for the specific chapter).
This will help you figure out the programming part, as there are numerous programming examples written by Stephen.

best

First, I need to resolve some confusion. Wolfram Physics Project is distinct from chapter 9 of NKS, and the model we now use is different. In particular, the state of the model is an unordered collection of edges, so using ReplaceAll or ReplaceList on them is not going to work.

Instead, the function you are looking for is WolframModel from the SetReplace package.

The question of whether the rule can be applied multiple times to the same place in a graph is an interesting one, and we did spend some time thinking about it in the past.

In the definition of the model we currently use, it can be applied multiple times, and each time a different b will be created, so you will get an evolution history that will look like this:

{{a, x}, {a, y}}
{{a, x}, {a, y}, {x, b$1}, {y, b$1}}
{{x, b$1}, {y, b$1}, {a, x}, {a, y}, {x, b$2}, {y, b$2}}
{{x, b$1}, {y, b$1}, {x, b$2}, {y, b$2}, {a, x}, {a, y}, {x, b$3}, {y, b$3}}
WolframModelPlot[{{x, b$1}, {y, b$1}, {x, b$2}, {y, b$2}, {a, x}, {a, 
   y}, {x, b$3}, {y, b$3}}, VertexLabels -> Automatic]

Notice that we are generating a new name for the new vertex every time, so multiple distinct copies of it can be created.

It can also be written explicitly as PatternRules as follows (note a Module on the right-hand side):

WolframModel[<|
  "PatternRules" -> {{a_, x_}, {a_, y_}} :> 
    Module[{b}, {{a, x}, {a, y}, {x, b}, {y, b}}]|>, {{a, x}, {a, 
   y}}, <|"MaxEvents" -> 3|>, "FinalStatePlot"]

However, one can imagine a different, “content-addressed” version of the model where the name for newly created vertices is chosen based on its predecessors, for example, as a hash of the input edges. In that case, while multiple copies of {x, b} and {y, b} will be created b will always correspond to the same vertex:

WolframModel[<|
   "PatternRules" -> {{a_, x_}, {a_, y_}} :> 
     Module[{b = Hash[{{a, x}, {a, y}}]}, {{a, x}, {a, y}, {x, b}, {y,
         b}}]|>, {{a, x}, {a, y}}, <|
   "MaxEvents" -> 3|>]["FinalStatePlot", VertexLabels -> Automatic]

Finally, we could identify identical edges as well, in which case, we will get something similar to your second comment:

WolframModelPlot[
 Union[WolframModel[<|
    "PatternRules" -> {{a_, x_}, {a_, y_}} :> 
      Module[{b = Hash[{{a, x}, {a, y}}]}, {{a, x}, {a, y}, {x, 
         b}, {y, b}}]|>, {{a, x}, {a, y}}, <|"MaxEvents" -> 3|>, 
   "FinalState"]], VertexLabels -> Automatic]

These three are just different models. And whether any one of them is a problem or a feature would depend on how well they reproduce known physics.

The issue #146 on GitHub is related to this.