Tutorials/Rules: Difference between revisions

From LifeWiki
Jump to navigation Jump to search
Created page with "Oh so you want to make your own cellular automata? Here's the place to learn how! == The Rule Table == To create a new rule, you first need to know how to create RuleTables,..."
 
Confocal (talk | contribs)
 
(21 intermediate revisions by 7 users not shown)
Line 1: Line 1:
Oh so you want to make your own cellular automata? Here's the place to learn how!
{{stub}}
OK, so you want to understand rules, or even make your own cellular automata? Here's the place to learn how!


== The Rule Table ==
== Preliminaries ==
To create a new rule, you first need to know how to create RuleTables, which are the transitions that occur every generation, AKA Rules. For this tutorial, we are going to recreate Life but with the name "Tutorial". To start, open your favorite text editor and type: <br/>
Some care needs to be taken to distinguish between ''rules'', which are part of the specification of a cellular automaton (CA), the rules according to which patterns in that CA evolve; and ''rulestrings'', which are string representations of rules in the previous sense.
<code>
@RULE RuleName
</code>
Where RuleName is the name of your rule, let's call this rule ''Tutorial'', for tutorial purposes. Next, add the ''table'', this is your actual transitions for the rule. Enter this before getting to the actual transitions.<br/>
<code>
@TABLE
n_states:2
neighborhood:Moore
symmetries:permute
</code>
*'''@TABLE''': This tells Golly that the table starts here.
*'''n_states''': This is how many states your rule has, '''INCLUDING''' state 0, the dead state/background, so 2 states will have live and dead states and 1 state will only have the background.
*'''neighborhood''': This is the neighborhood the rule uses, can be Moore, Hexagonal, vonNeumann, or oneDimensional, for the full list see the [https://github.com/GollyGang/ruletablerepository/wiki/RoadMap RoadMap]
*'''symmetries''': This is the arrangements accepted for each transition, none will make it so for example, if you want birth at 4 neighbors, you will have to write out every single arrangement of 4 neighbors. Permute makes it easy, we will come back to that later.
Now, transition time! Here, we will make Life, B3/S23. To make a transition, type a string as so:<br/>
<code>
Starting State, N Neighbor State, NE Neighbor State, E Neighbor State, SE Neighbor State, S Neighbor State, SW Neighbor State, W Neighbor State, NW Neighbor State</code>
So, for Life, B3 to be exact:<br/>
<code>
0,1,1,1,0,0,0,0,0,1
</code>
Which means that if a state 0 cell has 3 neighbors, it will become state 1. This is where permute comes in, if we didn't have permute, say '''none''', it would only make the cell live if it is ''exactly'' the same as we put it, live on the North, North East, and East '''only''', but '''permute''' makes it so all B3 states are filled. Now we make transitions for death. We don't do it for survival because survival means no transition happens to the cell.<br/>
<code>
1,0,0,0,0,0,0,0,0,0<br/>
1,1,0,0,0,0,0,0,0,0<br/>
1,1,1,1,1,0,0,0,0,0<br/>
1,1,1,1,1,1,0,0,0,0<br/>
1,1,1,1,1,1,1,0,0,0<br/>
1,1,1,1,1,1,1,1,0,0<br/>
1,1,1,1,1,1,1,1,1,0</code>
It should now look like this:<br/>
<code>
@RULE Tutorial<br/>
<br/>
@TABLE<br/>
n_states:2<br/>
neighborhood:Moore<br/>
symmetries:permute<br/>
0,1,1,1,0,0,0,0,0,1<br/>
1,0,0,0,0,0,0,0,0,0<br/>
1,1,0,0,0,0,0,0,0,0<br/>
1,1,1,1,1,0,0,0,0,0<br/>
1,1,1,1,1,1,0,0,0,0<br/>
1,1,1,1,1,1,1,0,0,0<br/>
1,1,1,1,1,1,1,1,0,0<br/>
1,1,1,1,1,1,1,1,1,0</code>
And now, select all of it and paste it into Golly, and it's life in all it's glory!


== Examples of Custom Rules ==
There are several ways of specifying rules beyond rulestrings, such as [[rule integer]]s or rule tables, and different rulestrings may yet represent the same rule. Nonetheless, in common parlance the term "rule" is often used where "rulestring" would be more appropriate.
*[http://www.conwaylife.com/forums/viewtopic.php?f=11&t=1859 X-Rule]
 
*[http://www.conwaylife.com/forums/viewtopic.php?f=11&t=2608 Finality4]
== Outer-totalistic rules ==
*[http://www.conwaylife.com/forums/viewtopic.php?f=11&t=803 Unrecognised CA Thread (You can find ''a lot'' here)]
'''[[Life-like cellular automata|Outer-totalistic]] rules''' are defined in terms of [[birth]] and [[survival]] conditions: the circumstances under which dead cells get born, and live cells survive.
 
There's different ways of specifying these; two common ways to write rulestrings are called "B/S notation" and "S/B" notation respectively. [[Conway's Game of Life|Life]] itself is specified by "B3/S23" or "23/3", but since S/B notation has fallen out of style, we'll only be focussing on B/S notation for the rest of this tutorial.
 
So, let's look at Life's B3/S23. In Life:
 
* A ''dead'' cell gets ''born'' if and only if it has three live neighbors; this is expressed by "B3".
* A ''live'' cell ''survives'' if and only if it has two ''or'' three live neighbors; this is expressed by "S23".
 
{| style="margin-left: auto; margin-right: auto;"
| colspan="2" align="center" | [[File:INT Moore R1 3i dead.png]]
|-
| align="center" colspan="2" style="max-width: 25em;" | Cell birth in Life: if the cells in purple are live, the center cell will be born in the next generation.
|-
| align="right" | [[File:INT Moore R1 2a.png]]
| align="left" | [[File:INT Moore R1 3i.png]]
|-
| align="center" colspan="2" style="max-width: 25em;" | Cell survival in Life: if the cells in purple are live, the center cell will survive in the next generation.
|}
 
As you can see, birth and survival conditions are each encoded as a string of numbers following the respective letter ("B" for birth, "S" for survival). Since there are eight cells directly neighboring a given cell, all numbers from 0 to 8 can be specified, and each combination yields a different outer-totalistic rule.
 
Let's look at two more examples. [[Day & Night]] has the rulestring B3678/S34678, so in this rule, dead cells get born if they have 3, 6, 7 or 8 live neighbors, and live cells survive if they have 3, 4, 6, 7 or 8 live neighbors. [[Live Free or Die]] has the rulestring B2/S0, so in this rule, dead cells are born if they have precisely two live neighbors, and live cells only survive if they have no live neighbors at all &mdash; if they are surrounded entirely by dead cells. (Knowing this, you can probably tell how the rule got its name.)
 
Why are these CAs called "outer-totalistic"? The reason is simply that a cell's fate depends on (in addition to the state of the cell itself) on the ''total'' number of live ''outer'' cells. Outer-totalistic CAs are also called semi-totalistic, in the sense that they are "sort of (but not quite)" totalistic in the sense of the next section.
 
There are many ways to generalize such CAs. For instance, one could:
 
* Take into account the (relative or absolute) alignment of live neighbors, in addition to their total count; this leads to [[Non-totalistic cellular automaton|non-totalistic rules]].
* Change the definition of what constitutes a "[[neighbourhood|neighbor]]", e.g. using the [[von Neumann neighbourhood]] rather than the [[Moore neighbourhood]], or increasing the distance at which cells are considered ([[Larger than Life]] rules).
* Increase the number of states a cell can be in, up from 2 ("dead" and "live").
* Change the [[topology]] of the [[universe]]: operate on e.g. a [[cylinder]], [[torus]] or [[Klein bottle]], rather than an infinite plane.
* Increase the dimension of the universe, considering [[one-dimensional cellular automata]] (e.g. Wolfram's [[Rule 110]]), 3-dimensional cellular automata, etc.
* Change the tiling of the universe: instead of using a [[square tiling]], use a [[hexagonal tiling]] or [[triangular tiling]], or even exotic tilings such as [[hyperbolic]] or [[Penrose]] tilings.
* ...and much more.
 
== Totalistic rules ==
'''[[Totalistic Life-like cellular automaton|Totalistic rules]]''' are a sub-class of outer-totalistic rules in which the center cell is not afforded special treatment anymore when determining its fate. With outer-totalistic rules, the center cell and the total number of live neighbors are considered separately; in totalistic rules, the center cell is counted like any other cell, and only the total number of live cells in the neighborhood, ''including'' the center cell, is used to determine evolution.
 
Totalistic rules can be described using B/S notation, of course; alternatively, they can be expressed by a string of digits listing the live-cells-in-the-neighborhood counts which lead to the center cell being alive in the next generation.
 
Let's look at an example. B3/S2 is an outer-totalistic rule (more precisely, a rulestring encoding a rule) in which dead cells get born if they have precisely three live neighbors, and live cells survive if they have precisely two live neighbors. But if a live cell has two live neighbors, that means the total number of live cells in the neighborhood is three as well &mdash; so this rule is actually not just outer-totalistic but also totalistic, and its totalistic rulestring would simply be 3.
 
{| style="margin-left: auto; margin-right: auto;"
| align="center" | [[File:INT Moore R1 3i dead.png]]
|-
| align="center" style="max-width: 25em;" | Cell birth in B3/S2: if the cells in purple are live, the center cell will be born in the next generation.
|-
| align="center" | [[File:INT Moore R1 2a.png]]
|-
| align="center" style="max-width: 25em;" | Cell survival in B3/S2: if the cells in purple are live, the center cell will survive in the next generation.
|}
 
[[Replicator 2|Fredkin]], also known as Replicator 2, is another example. Its rulestring is B1357/S02468; look closely, and you will see that this means that a cell will be alive in the next generation if and only if the number of live cells in its neighborhood is odd (1, 3, 5, 7 or 9). Its totalistic rulestring, therefore, is 13579.
 
== Non-totalistic rules ==
'''[[Non-totalistic cellular automaton|Non-totalistic rules]]''' differ from outer-totalistic rules in that not only the number of live neighbors of a cell is considered when deciding whether the cell should be born (or survive, if it is already live) &mdash; birth and survival also depend on the relative alignment of the cell's live neighbors.
 
Rulestrings for non-totalistic rules are typically given in [[Hensel notation]]. As an example, let's look at a hypothetical rule, B2ek/S12. We understand "S12" well enough &ndash; a live cell survives if it has one or two live neighbors &ndash;, but what does "B2ek" mean?
 
Imagine, if you will, a cell with two live neighbors. How can these two live neighbors be aligned, relative to each other? All the following configurations are possible:
 
{| style="margin-left: auto; margin-right: auto;"
| [[File:INT Moore R1 2c.png]]
| [[File:INT Moore R1 2e.png]]
| [[File:INT Moore R1 2k.png]]
| [[File:INT Moore R1 2a.png]]
| [[File:INT Moore R1 2i.png]]
| [[File:INT Moore R1 2n.png]]
|-
| align="center" | c
| align="center" | e
| align="center" | k
| align="center" | a
| align="center" | i
| align="center" | n
|}
 
(Some of these configurations have mnemonic names; "c" stands for "corner", "e" for "edge", "k" for "knightwise", "a" for adjacent, and so on. Others are less obvious and simply have to be remembered, or looked up as necessary.)
 
For an outer-totalistic rule, say B2/S12, any of these configurations would cause the center cell to be born. By contrast, in non-totalistic rules, each configuration is considered separately: in B2ek/S12 a dead cell gets born if and only if it has two live neighbors ''which are in "e" or "k" alignment'' (as shown above).
 
For some neighbor counts, particularly 4, there is a fairly large number of possible alignments, so it is sometimes convenient to negate rather than specify, essentially saying "...in ''all but'' these alignments". As an example, consider the first non-totalistic rule ever explored, [[Just Friends]], which is described by the rulestring B2-a/S12. In this rule, a dead cell will get born if it has two live neighbors... unless those two live neighbors are in "a" alignment! Cells in this rule don't like getting cozy; they're "just friends".
 
== Non-isotropic rules ==
The above non-totalistic rules are sometimes called ''isotropic'': although birth or survival of a cell may depend on the relative alignment of its live neighbors, no attempt is made to distinguish between the absolute alignment. Put another way, two live neighbors north and northwest of a cell will satisfy the "B2a" or "S2a" conditions, but so will two live neighbors south and southeast of the same cell.
 
'''[[Non-isotropic cellular automaton|Non-isotropic rules]]''' further distinguish such cases. This part of the tutorial isn't written yet; for now you may want to look at the [[rule integer]] article, which briefly talks about <tt>MAP</tt> strings, a different way of encoding rules as 512-bit strings unrelated to B/S notation that naturally lends itself to describing non-isotropic rules.
 
== Rules with larger neighbourhoods ==
This part of the tutorial isn't written yet, either; for now you may want to look at the [[Larger than Life]] article, which talks about such rules.
 
== Creating custom rules ==
[[Golly]] has powerful facilities to run a very large class of different rules. You want to create your own custom rules? Then look no further than the ''[[Tutorials/Creating custom rules|Creating custom rules]]'' tutorial. If you're not familiar with Golly yet, you may also want to take a look at the [[Tutorials/Golly|Golly tutorial]] first.
 
{{Tutorial}}
__NOTOC__

Latest revision as of 02:38, 10 August 2022

This article is a stub. You can help LifeWiki by expanding it.

OK, so you want to understand rules, or even make your own cellular automata? Here's the place to learn how!

Preliminaries

Some care needs to be taken to distinguish between rules, which are part of the specification of a cellular automaton (CA), the rules according to which patterns in that CA evolve; and rulestrings, which are string representations of rules in the previous sense.

There are several ways of specifying rules beyond rulestrings, such as rule integers or rule tables, and different rulestrings may yet represent the same rule. Nonetheless, in common parlance the term "rule" is often used where "rulestring" would be more appropriate.

Outer-totalistic rules

Outer-totalistic rules are defined in terms of birth and survival conditions: the circumstances under which dead cells get born, and live cells survive.

There's different ways of specifying these; two common ways to write rulestrings are called "B/S notation" and "S/B" notation respectively. Life itself is specified by "B3/S23" or "23/3", but since S/B notation has fallen out of style, we'll only be focussing on B/S notation for the rest of this tutorial.

So, let's look at Life's B3/S23. In Life:

  • A dead cell gets born if and only if it has three live neighbors; this is expressed by "B3".
  • A live cell survives if and only if it has two or three live neighbors; this is expressed by "S23".
Cell birth in Life: if the cells in purple are live, the center cell will be born in the next generation.
Cell survival in Life: if the cells in purple are live, the center cell will survive in the next generation.

As you can see, birth and survival conditions are each encoded as a string of numbers following the respective letter ("B" for birth, "S" for survival). Since there are eight cells directly neighboring a given cell, all numbers from 0 to 8 can be specified, and each combination yields a different outer-totalistic rule.

Let's look at two more examples. Day & Night has the rulestring B3678/S34678, so in this rule, dead cells get born if they have 3, 6, 7 or 8 live neighbors, and live cells survive if they have 3, 4, 6, 7 or 8 live neighbors. Live Free or Die has the rulestring B2/S0, so in this rule, dead cells are born if they have precisely two live neighbors, and live cells only survive if they have no live neighbors at all — if they are surrounded entirely by dead cells. (Knowing this, you can probably tell how the rule got its name.)

Why are these CAs called "outer-totalistic"? The reason is simply that a cell's fate depends on (in addition to the state of the cell itself) on the total number of live outer cells. Outer-totalistic CAs are also called semi-totalistic, in the sense that they are "sort of (but not quite)" totalistic in the sense of the next section.

There are many ways to generalize such CAs. For instance, one could:

Totalistic rules

Totalistic rules are a sub-class of outer-totalistic rules in which the center cell is not afforded special treatment anymore when determining its fate. With outer-totalistic rules, the center cell and the total number of live neighbors are considered separately; in totalistic rules, the center cell is counted like any other cell, and only the total number of live cells in the neighborhood, including the center cell, is used to determine evolution.

Totalistic rules can be described using B/S notation, of course; alternatively, they can be expressed by a string of digits listing the live-cells-in-the-neighborhood counts which lead to the center cell being alive in the next generation.

Let's look at an example. B3/S2 is an outer-totalistic rule (more precisely, a rulestring encoding a rule) in which dead cells get born if they have precisely three live neighbors, and live cells survive if they have precisely two live neighbors. But if a live cell has two live neighbors, that means the total number of live cells in the neighborhood is three as well — so this rule is actually not just outer-totalistic but also totalistic, and its totalistic rulestring would simply be 3.

Cell birth in B3/S2: if the cells in purple are live, the center cell will be born in the next generation.
Cell survival in B3/S2: if the cells in purple are live, the center cell will survive in the next generation.

Fredkin, also known as Replicator 2, is another example. Its rulestring is B1357/S02468; look closely, and you will see that this means that a cell will be alive in the next generation if and only if the number of live cells in its neighborhood is odd (1, 3, 5, 7 or 9). Its totalistic rulestring, therefore, is 13579.

Non-totalistic rules

Non-totalistic rules differ from outer-totalistic rules in that not only the number of live neighbors of a cell is considered when deciding whether the cell should be born (or survive, if it is already live) — birth and survival also depend on the relative alignment of the cell's live neighbors.

Rulestrings for non-totalistic rules are typically given in Hensel notation. As an example, let's look at a hypothetical rule, B2ek/S12. We understand "S12" well enough – a live cell survives if it has one or two live neighbors –, but what does "B2ek" mean?

Imagine, if you will, a cell with two live neighbors. How can these two live neighbors be aligned, relative to each other? All the following configurations are possible:

c e k a i n

(Some of these configurations have mnemonic names; "c" stands for "corner", "e" for "edge", "k" for "knightwise", "a" for adjacent, and so on. Others are less obvious and simply have to be remembered, or looked up as necessary.)

For an outer-totalistic rule, say B2/S12, any of these configurations would cause the center cell to be born. By contrast, in non-totalistic rules, each configuration is considered separately: in B2ek/S12 a dead cell gets born if and only if it has two live neighbors which are in "e" or "k" alignment (as shown above).

For some neighbor counts, particularly 4, there is a fairly large number of possible alignments, so it is sometimes convenient to negate rather than specify, essentially saying "...in all but these alignments". As an example, consider the first non-totalistic rule ever explored, Just Friends, which is described by the rulestring B2-a/S12. In this rule, a dead cell will get born if it has two live neighbors... unless those two live neighbors are in "a" alignment! Cells in this rule don't like getting cozy; they're "just friends".

Non-isotropic rules

The above non-totalistic rules are sometimes called isotropic: although birth or survival of a cell may depend on the relative alignment of its live neighbors, no attempt is made to distinguish between the absolute alignment. Put another way, two live neighbors north and northwest of a cell will satisfy the "B2a" or "S2a" conditions, but so will two live neighbors south and southeast of the same cell.

Non-isotropic rules further distinguish such cases. This part of the tutorial isn't written yet; for now you may want to look at the rule integer article, which briefly talks about MAP strings, a different way of encoding rules as 512-bit strings unrelated to B/S notation that naturally lends itself to describing non-isotropic rules.

Rules with larger neighbourhoods

This part of the tutorial isn't written yet, either; for now you may want to look at the Larger than Life article, which talks about such rules.

Creating custom rules

Golly has powerful facilities to run a very large class of different rules. You want to create your own custom rules? Then look no further than the Creating custom rules tutorial. If you're not familiar with Golly yet, you may also want to take a look at the Golly tutorial first.