Implementation [of network substitution rules]

For many practical purposes the best representation for networks is the one given on page 1031. But in updating networks a particularly straightforward implementation of one scheme can be obtained if one uses instead a more explicit symbolic representation such as

u[1 v[2, 3, 4], 2 v[1, 3, 4], 3 v[1, 2, 4], 4 v[1, 2, 3]]

This allows one to capture the basic character of networks by

Attributes[u] = {Flat, Orderless}; Attributes[v] = Orderless

Updating rules can then be written in terms of ordinary Mathematica patterns. A slight complication is that the patterns have to include all nodes whose connections go to nodes whose labels are changed by the update. The rule at the top of page 509 must therefore be written out as

and this corresponds to the Mathematica rule

u[i1_ v[i2_, i3_, i4_], i3_ v[i1_, i5_, i6_], i4_ v[i1_, i7_, i8_]] u[i1 v[i2, new[1], new[2]], new[1] v[i1, new[2], i3], new[2] v[i1, new[1], i4], i3 v[new[1], i5, i6], i4 v[new[2], i7, i8]]

(Strictly there also need to be additional rules to cover where for example nodes 3 and 4 are actually the same.) With rules in this form the network update is simply

NetStep[rule_, net_]:= Block[{new}, net /. rule /. new[n_] n + Apply[Max, Map[First, net]]]

Note that just as we discussed for strings on page 1033 the direct use of /. here corresponds to a particular scheme for applying the update rule.