The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Math::PlanePath::CellularRule -- cellular automaton points of binary rule

SYNOPSIS

 use Math::PlanePath::CellularRule;
 my $path = Math::PlanePath::CellularRule->new (rule => 30);
 my ($x, $y) = $path->n_to_xy (123);

DESCRIPTION

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 is

    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 specifies what each set of 3 cells below will produce in the one cell above. The rule is encoded as a value 0 to 255 inclusive used as bits,

    cells below     cell above 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. bit0 in rule is 1 (an odd number), the "off" cells either side of the initial N=1 become all "on" infinitely to the sides. And if the 1,1,1 bit7 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 in the Math-PlanePath sources. The patterns range from simple to complex. For some the N=1 cell doesn't grow at all, only that single point, eg. 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. Some rules even give complicated non-repeating patterns when there's feedback across from one half to the other, for example rule 30.

For some rules there's specific code which this class dispatches to, such as CellularRule54, CellularRule190 or SierpinskiTriangle (which is adjusted to start at N=1 here).

For rules without specific code the current implementation is not particularly efficient as it builds and holds onto the bit pattern for all rows 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.

FUNCTIONS

See "FUNCTIONS" in Math::PlanePath for behaviour common to all path classes.

$path = Math::PlanePath::CellularRule->new (rule => 123)

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.

For some of the simple rules there's specific code implementing the pattern and the return value is an object from that class, not a Math::PlanePath::CellularRule as such. Is it undesirable that new() CellularRule gives an object not isa() CellularRule? Perhaps it could be cooked up to be a subclass or superclass, but for now getting the more efficient specific modules at least run much faster.

($x,$y) = $path->n_to_xy ($n)

Return the X,Y coordinates of point number $n on the path.

$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.

SEE ALSO

Math::PlanePath, Math::PlanePath::CellularRule54, Math::PlanePath::CellularRule57, Math::PlanePath::CellularRule190, Math::PlanePath::SierpinskiTriangle, Math::PlanePath::PyramidRows

Cellular::Automata::Wolfram

http://mathworld.wolfram.com/ElementaryCellularAutomaton.html

HOME PAGE

http://user42.tuxfamily.org/math-planepath/index.html

LICENSE

Copyright 2011, 2012 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/>.