Math::...larRule(3pm)
β¨ 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 π
- 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, 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 ππ¦
π¦ where this page comes from
- debian bookworm: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- debian trixie: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu jammy: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu noble: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu resolute: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- ubuntu stonking: libmath-planepath-perl 129-1 Β· GPL-3.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms