Math::PlanePath::CellularRule -- cellular automaton points of binary rule
use Math::PlanePath::CellularRule; my $path = Math::PlanePath::CellularRule->new (rule => 30); my ($x, $y) = $path->n_to_xy (123);
This is the patterns of Stephen Wolfram's bit-rule based cellular automatons
http://mathworld.wolfram.com/ElementaryCellularAutomaton.html
Points are numbered left to right in rows so for example
rule => 30 51 52 53 54 55 56 57 58 59 60 61 62 9 44 45 46 47 48 49 50 8 32 33 34 35 36 37 38 39 40 41 42 43 7 27 28 29 30 31 6 18 19 20 21 22 23 24 25 26 5 14 15 16 17 4 8 9 10 11 12 13 3 5 6 7 2 2 3 4 1 1 <- Y=0 -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7 8 9
The automaton starts from a single point N=1 at the origin and grows into the rows above. The rule
parameter controls how the 3 cells below and diagonally below produce a new cell,
+-----+ | new | next row, Y+1 +-----+ ^ ^ ^ / | \ / | \ +-----+ +-----+ +-----+ | A | | B | | C | row Y +-----+ +-----+ +-----+
There's 8 possible combinations of ABC being each 0 or 1. Each such combination can become 0 or 1 in the "new" cell. Those 0 or 1 for "new" is encoded as 8 bits to make a rule number 0 to 255,
ABC cells below new cell bit from rule 1,1,1 -> bit7 1,1,0 -> bit6 1,0,1 -> bit5 ... 0,0,1 -> bit1 0,0,0 -> bit0
When cells 0,0,0 become 1, ie. rule
bit0 is 1 (an odd number), the "off" cells either side of the initial N=1 become all "on" infinitely to the sides. Or if rule bit7 for 1,1,1 is a 0 (ie. rule < 128) then they turn on and off alternately in odd and even rows. In both cases only the pyramid portion part -Y<=X<=Y is considered for the N points but the infinite cells to the sides are included in the calculation.
The full set of patterns can be seen at the Math World page above, or can be printed with the examples/cellular-rules.pl program. The patterns range from simple to complex. For some the N=1 cell doesn't grow at all such as rule 0 or rule 8. Some grow to mere straight lines such as rule 2 or rule 5. Others make columns or patterns with "quadratic" style stepping of 1 or 2 rows, or self-similar replications such as the Sierpinski triangle of rule 18 and 60. Some rules have complicated non-repeating patterns when there's feedback across from one half to the other, such as rule 30.
For some rules there's specific PlanePath code which this class dispatches to, such as CellularRule54
, CellularRule57
, CellularRule190
or SierpinskiTriangle
(with n_start=1
).
For rules without specific code the current implementation is not particularly efficient as it builds and holds onto the bit pattern for all rows through to the highest N or X,Y used. There's no doubt better ways to iterate an automaton, but this module offers the patterns in PlanePath style.
The default is to number points starting N=1 as shown above. An optional n_start
can give a different start, in the same pattern. For example to start at 0,
n_start => 0, rule => 62 18 19 20 21 22 23 24 25 5 13 14 15 16 17 4 7 8 9 10 11 12 3 4 5 6 2 1 2 3 1 0 <- Y=0 -5 -4 -3 -2 -1 X=0 1 2 3 4 5
See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes.
$path = Math::PlanePath::CellularRule->new (rule => 123)
$path = Math::PlanePath::CellularRule->new (rule => 123, n_start => $n)
Create and return a new path object. rule
should be an integer 0 to 255. A rule
should be given always. There is a default, but it's secret and likely to change.
If there's specific PlanePath code implementing the pattern then the returned object is from that class and generally is not isa('Math::PlanePath::CellularRule')
.
$n = $path->xy_to_n ($x,$y)
Return the point number for coordinates $x,$y
. $x
and $y
are each rounded to the nearest integer, which has the effect of treating each cell as a square of side 1. If $x,$y
is outside the pyramid or on a skipped cell the return is undef
.
Entries in Sloane's Online Encyclopedia of Integer Sequences related to this path can be found in the OEIS index
and in addition the following
http://oeis.org/A061579 (etc)
rule=50,58,114,122,178,186,242,250, 179 (solid every second cell) A061579 permutation N at -X,Y (mirror horizontal)
Math::PlanePath, Math::PlanePath::CellularRule54, Math::PlanePath::CellularRule57, Math::PlanePath::CellularRule190, Math::PlanePath::SierpinskiTriangle, Math::PlanePath::PyramidRows
http://mathworld.wolfram.com/ElementaryCellularAutomaton.html
http://user42.tuxfamily.org/math-planepath/index.html
Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017 Kevin Ryde
This file is part of Math-PlanePath.
Math-PlanePath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3, or (at your option) any later version.
Math-PlanePath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License along with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.