Skip to content

SubstitutionSystem

Applies substitution rules iteratively, returning every state from the initial condition through step t.

Strings substitute character by character:

$ wo 'SubstitutionSystem[{"A" -> "AB", "B" -> "A"}, "A", 4]'
{A, AB, ABA, ABAAB, ABAABABA}

Lists substitute element by element:

$ wo 'SubstitutionSystem[{0 -> {0, 1}, 1 -> {1, 0}}, {0}, 3]'
{{0}, {0, 1}, {0, 1, 1, 0}, {0, 1, 1, 0, 1, 0, 0, 1}}

When a rule replaces a cell with a matrix the system is two-dimensional: every cell expands into a block and the blocks tile, so an m×n grid whose cells expand to p×q becomes (m p)×(n q).

$ wo 'SubstitutionSystem[{1 -> {{1, 0}, {1, 1}}, 0 -> {{0, 0}, {0, 0}}}, {{1}}, 2]'
{{{1}}, {{1, 0}, {1, 1}}, {{1, 0, 0, 0}, {1, 1, 0, 0}, {1, 0, 1, 0}, {1, 1, 1, 1}}}

Without a step count only one step runs, and just the new state comes back. The operator form does the same:

$ wo 'SubstitutionSystem[{1 -> {1, 0}, 0 -> {1}}][{1}]'
{1, 0}

Blocks may differ in size, as long as all cells in a row of the grid expand to the same height and all cells in a column to the same width:

$ wo 'FlattenAt[SubstitutionSystem[{3 -> {{1, 0}, {3, 2}}, 2 -> {{1}, {3}}, 1 -> {{3, 2}}, 0 -> {{3}}}, {{3}}, {2}], 1]'
{{3, 2, 3}, {1, 0, 1}, {3, 2, 3}}