Math::...larRule(3pm)

πŸ“¦
version 129 Β· 3 versions
, in debian bookworm, debian trixie, ubuntu jammy, ubuntu noble, ubuntu resolute, ubuntu stonking

✨ NAME ✨

Math::PlanePath::CellularRule β€” cellular automaton points of binary rule πŸ’– (yes bestie, it's giving Wolfram realness)


πŸŽ€ SYNOPSIS πŸŽ€

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

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so this module is literally the patterns of Stephen Wolfram's bit-rule cellular automatons 😌✨

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

Points get 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 is the girlboss in charge of 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 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 -Y<=X<=Y is considered for the N points but the infinite cells to the sides are included in the calculation. periodt πŸ’…

The full set of patterns can be seen at the MathWorld page above, or can be printed with the examples/cellular-rules.pl here 🌸. The patterns range from simple to complex β€” it's giving range, honestly. 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. iykyk.

⭐ N Start ⭐

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

πŸ’œ FUNCTIONS πŸ’œ

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 πŸ™ˆ (not me trusting a secret default).

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


🌈 OEIS 🌈

Entries in Sloane's Online Encyclopedia of Integer Sequences related to this path can be found in the OEIS index:

<http://oeis.org/wiki/Index_to_OEIS:_Section_Ce#cell>

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)

πŸ‘‘ SEE ALSO πŸ‘‘


🏠 HOME PAGE 🏠

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

πŸ“œ LICENSE πŸ“œ

Copyright 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019, 2020 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/>.


ngl bestie, that's the whole page β€” no skipped options, no skipped warnings, every bit accounted for πŸ’…

okay that's the vibe check done ✨ this page is from the User Contributed Perl Documentation set, and the version stamp is perl v5.32.0, dated 2021-01-23 β€” and the page itself is Math::...larRule(3pm) πŸŽ€ slay, go read it, bye πŸ’–πŸ¦‹