Math::...burton(3pm)

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

πŸ’– Math::PlanePath::UlamWarburton πŸ’–

okay bestie, gather round, because we are getting into Math::...burton(3pm) β€” the manpage for Math::PlanePath::UlamWarburton from the User Contributed Perl Documentation. it's a cellular automaton. it grows. it has tree rows. it's a whole vibe. let's go πŸ¦‹βœ¨


✨ NAME ✨

Math::PlanePath::UlamWarburton β€” growth of a 2-D cellular automaton. that's it, that's the whole name. slay πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

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

πŸ¦‹ DESCRIPTION πŸ¦‹

okay so basically, bestie, this is the pattern of a cellular automaton studied by Ulam and Warburton. the cells get numbered by growth tree row, and then anti-clockwise within the rows. it's giving organized. it's giving intentional. we love to see it. 😌

                                      94                                  9
                                   95 87 93                               8
                                      63                                  7
                                   64 42 62                               6
                                65    30    61                            5
                             66 43 31 23 29 41 60                         4
                          69    67    14    59    57                      3
                       70 44 68    15  7 13    58 40 56                   2
              96    71    32    16     3    12    28    55    92          1
           97 88 72 45 33 24 17  8  4  1  2  6 11 22 27 39 54 86 91   <- Y=0
              98    73    34    18     5    10    26    53    90         -1
                       74 46 76    19  9 21    50 38 52       ...        -2
                          75    77    20    85    51                     -3
                             78 47 35 25 37 49 84                        -4
                                79    36    83                           -5
                                   80 48 82                              -6
                                      81                                 -7
                                   99 89 101                             -8
                                     100                                 -9

                                      ^
           -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6  7  8  9

so here's the tea on the growth rule: a given cell grows up, down, left and right, but only if the new cell has no neighbours (up, down, left or right). so the initial cell "a" is N=1,

                       a                  initial depth=0 cell

the next row "b" cells are numbered N=2 to N=5, anti-clockwise starting from the right,

                       b
                    b  a  b               depth=1
                       b

and likewise the next row "c" cells are N=6 to N=9. the "b" cells only grow outwards as 4 "c"s, because the other positions would have neighbours in the existing "b"s. so true. so real. 😭

                       c
                       b
                 c  b  a  b  c            depth=2
                       b
                       c

then the "d" cells are N=10 to N=21, numbered following the previous row "c" cell order and then anti-clockwise around each.

                       d
                    d  c  d
                 d     b     d
              d  c  b  a  b  c  d         depth=3
                 d     b     d
                    d  c  d
                       d

there's only 4 "e" cells, because among the "d"s only the X,Y axes won't have existing neighbours (the "b"s and "d"s).

                       e
                       d
                    d  c  d
                 d     b     d
           e  d  c  b  a  b  c  d  e      depth=4
                 d     b     d
                    d  c  d
                       d
                       e

in general the pattern always grows by 1 outward along the X and Y axes and travels into the quarter planes between with a diamond shaped tree pattern which fills 11 of 16 cells in each 4x4 square block. the way it just... does that. obsessed. 🫢


🌸 Tree Row Ranges 🌸

counting depth=0 as the N=1 at the origin and depth=1 as the next N=2,3,4,5 generation, the number of cells in a row is

rowwidth(0) = 1
  then
rowwidth(depth) = 4 * 3^((count_1_bits(depth) - 1)

so depth=1 has 4*3^0=4 cells, as does depth=2 at N=6,7,8,9. then depth=3 has 4*3^1=12 cells N=10 to N=21 because depth=3=0b11 has two 1-bits in binary. the N start and end for a row is the cumulative total of those before it,

Ndepth(depth) = 1 + (rowwidth(0) + ... + rowwidth(depth-1))

Nend(depth) = rowwidth(0) + ... + rowwidth(depth)

for example depth 3 ends at N=(1+4+4)=9.

depth    Ndepth   rowwidth     Nend
  0          1         1           1
  1          2         4           5
  2          6         4           9
  3         10        12          21
  4         22         4          25
  5         26        12          37
  6         38        12          49
  7         50        36          85
  8         86         4          89
  9         90        12         101

for a power-of-2 depth the Ndepth is

Ndepth(2^a) = 2 + 4*(4^a-1)/3

for example depth=4=2^2 starts at N=2+4*(4^2-1)/3=22, or depth=8=2^3 starts N=2+4*(4^3-1)/3=86.

further bits in the depth value contribute powers-of-4 with a tripling for each bit above. so if the depth number has bits a,b,c,d,etc in descending order,

depth = 2^a + 2^b + 2^c + 2^d ...       a>b>c>d...
Ndepth = 2 + 4*(-1
                +       4^a
                +   3 * 4^b
                + 3^2 * 4^c
                + 3^3 * 4^d + ... ) / 3

for example depth=6 = 2^2+2^1 is Ndepth = 2 + (1+4*(4^2-1)/3) + 4^(1+1) = 38. or depth=7 = 2^2+2^1+2^0 is Ndepth = 1 + (1+4*(4^2-1)/3) + 4^(1+1) + 3*4^(0+1) = 50.


πŸ¦‹ Self-Similar Replication πŸ¦‹

the diamond shape depth=1 to depth=2^level-1 repeats three times. for example an "a" part going to the right of the origin "O",

            d
          d d d
    |   a   d   c
  --O a a a * c c c ...
    |   a   b   c
          b b b
            b

the 2x2 diamond shaped "a" repeats pointing up, down and right as "b", "c" and "d". this resulting 4x4 diamond then likewise repeats up, down and right. the same happens in the other quarters of the plane.

the points in the path here are numbered by tree rows rather than in this sort of replication, but the replication helps to see the structure of the pattern. iykyk. πŸ’«


πŸ’œ Half Plane πŸ’œ

option "parts => '2'" confines the pattern to the upper half plane "Y>=0",

parts => "2"

                      28                           6
                      21                           5
                29 22 16 20 27                     4
                      11                           3
          30       12  6 10       26               2
          23    13     3     9    19               1
    31 24 17 14  7  4  1  2  5  8 15 18 25     <- Y=0
    --------------------------------------
    -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6

points are still numbered anti-clockwise around so X axis N=1,2,5,8,15,etc is the first of row depth=X. X negative axis N=1,4,7,14,etc is the last of row depth=-X. for depth=0 point N=1 is both the first and last of that row.

within a row a line from point N to N+1 is always a 45-degree angle. this is true of each 3 direct children, but also across groups of children by symmetry. for this parts=2 the lines from the last of one row to the first of the next are horizontal, making an attractive pattern of diagonals and then across to the next row horizontally. for parts=4 or parts=1 the last to first lines are at various different slopes and so upsets the pattern. 😬


πŸŽ€ One Quadrant πŸŽ€

option "parts => '1'" confines the pattern to the first quadrant,

parts => "1"  to depth=14

14  |  73
13  |  63
12  |  53 62 72
11  |  49
10  |  39 48       71
 9  |  35    47    61
 8  |  31 34 38 46 52 60 70
 7  |  29    45    59
 6  |  19 28       69          67
 5  |  15    27                57
 4  |  11 14 18 26       68 58 51 56 66
 3  |   9    25    23          43
 2  |   5  8    24 17 22    44 37 42       65
 1  |   3     7    13    21    33    41    55
Y=0 |   1  2  4  6 10 12 16 20 30 32 36 40 50 54 64
    +-----------------------------------------------
      X=0  1  2  3  4  5  6  7  8  9 10 11 12 13 14

X axis N=1,2,4,6,10,etc is the first of each row X=depth. Y axis N=1,3,5,9,11,etc is the last similarly Y=depth.

in this arrangement, horizontal arms have even N and vertical arms have odd N. for example the vertical at X=8 N=30,33,37,etc has N odd from N=33 up and when it turns to horizontal at N=42 or N=56 it switches to N even. the children of N=66 are not shown but the verticals from there are N=79 below and N=81 above and so switch to odd again.

this odd/even pattern is true of N=2 horizontal and N=3 vertical and thereafter is true due to each row having an even number of points and the self-similar replications in the pattern,

|\          replication
| \            block 0 to 1 and 3
|3 \           and block 0 block 2 less sides
|----
|\ 2|\
| \ | \
|0 \|1 \
---------

block 0 is the base and is replicated as block 1 and in reverse as block 3. block 2 is a further copy of block 0, but the two halves of block 0 rotated inward 90 degrees, so the X axis of block 0 becomes the vertical of block 2, and the Y axis of block 0 the horizontal of block 2. those axis parts are dropped since they're already covered by block 1 and 3 and dropping them flips the odd/even parity to match the vertical/horizontal flip due to the 90-degree rotation. the math is mathing. ✨


🌈 Octant 🌈

option "parts => 'octant'" confines the pattern to the first eighth of the plane 0<=Y<=X.

parts => "octant"

  7 |                         47     ...
  6 |                      48 36 46
  5 |                   49    31    45
  4 |                50 37 32 27 30 35 44
  3 |             14    51    24    43    41
  2 |          15 10 13    25 20 23    42 34 40
  1 |        5     8    12    18    22    29    39
Y=0 |  1  2  3  4  6  7  9 11 16 17 19 21 26 28 33 38
    +-------------------------------------------------
     X=0  1  2  3  4  5  6  7  8  9 10 11 12 13 14 15

in this arrangement, N=1,2,3,4,6,7,etc on the X axis is the first N of each row ("tree_depth_to_n()"). πŸ’–


⭐ Upper Octant ⭐

option "parts => 'octant_up'" confines the pattern to the upper octant 0<=X<=Y of the first quadrant.

parts => "octant_up"

  8 | 16 17 19 22 26 29 34 42
  7 | 15    21    28    41
  6 | 10 14    38 33 40
  5 |  8    13    39
  4 |  6  7  9 12
  3 |  5    11
  2 |  3  4
  1 |  2
Y=0 |  1
    +--------------------------
      X=0 1  2  3  4  5  6  7

in this arrangement, N=1,2,3,5,6,8,etc on the Y axis the last N of each row ("tree_depth_to_n_end()"). 🫢

✨ N Start ✨

okay so default behavior bestie: points get numbered starting at N=1, exactly like that little picture up above. 🫢

But the n_start option lets you slide the whole numbering somewhere else β€” different start, same pattern, no cap. Wanna kick it off at 0 instead of 1? You literally just say:

n_start => 0

and boom, it's giving:

              29                       5
           30 22 28                    4
              13                       3
           14  6 12                    2
  31    15     2    11    27           1
32 23 16  7  3  0  1  5 10 21 26    <- Y=0
  33    17     4     9    25          -1
           18  8 20       37          -2
              19                      -3
           34 24 36                   -4
              35                      -5

               ^
-5 -4 -3 -2 -1 X=0 1  2  3  4  5

πŸ”₯ FUNCTIONS πŸ”₯

For all the behaviour that's common to every path class, go peek at "FUNCTIONS" in Math::PlanePath. iykyk. πŸ’…

  • $path = Math::PlanePath::UlamWarburton->new ()
  • $path = Math::PlanePath::UlamWarburton->new (parts => $str, n_start => $n) β€” makes you a brand new path object and hands it right over. πŸŽ€ The parts option is a string, and it can be:
"4"     the default
"2"
"1"

🌸 Tree Methods 🌸

  • @n_children = $path->tree_n_children($n) β€” hands you the children of $n, or an empty list if $n has no children at all (and that includes when $n < 1, ie. before the path even starts, so don't come for it). The children are the cells that got turned on right next to $n on the next row. And the way the points are numbered? It means that when there's multiple children they're consecutive N values β€” for example at N=6 the children are 10,11,12. cute and tidy fr fr.

πŸ¦‹ Tree Descriptive Methods πŸ¦‹

  • @nums = $path->tree_num_children_list() β€” gives you a list of all the possible number of children in $path. This is literally the set of possible return values from "tree_n_num_children()". And the possible children count changes with parts:
parts     tree_num_children_list()
-----     ------------------------
  4             0, 1,    3, 4        (the default)
  2             0, 1, 2, 3
  1             0, 1, 2, 3
  • parts=4 has 4 children at the origin N=0, and after that it's either 0, 1 or 3.
  • parts=2 and parts=1 can have 2 children on the boundaries where the 3rd child gets chopped off β€” otherwise it's 0, 1 or 3.
  • $n_parent = $path->tree_n_parent($n) β€” gives you back the parent node of $n, or undef if $n <= 1 (that's the start of the path, bestie, nothing above it).

⭐ Level Methods ⭐

  • ($n_lo, $n_hi) = $path->level_to_n_range($level) β€” returns $n_lo = $n_start, and also:
parts    $n_hi
-----    -----
  4      $n_start + (16*4**$level - 4) / 3
  2      $n_start + ( 8*4**$level - 5) / 3  +  2*2**$level
  1      $n_start + ( 4*4**$level - 4) / 3  +  2*2**$level

And $n_hi is tree_depth_to_n_end(2**($level+1) - 1.


🌈 OEIS 🌈

This cellular automaton is iconic enough to be in Sloane's Online Encyclopedia of Integer Sequences, as:

<http://oeis.org/A147562> (etc)

parts=4
  A147562   total cells to depth, being tree_depth_to_n() n_start=0
  A147582   added cells at depth
  A264039   off cells >=2 neighbours ("poisoned")
  A260490     increment
  A264768   off cells, 4 neighbours ("surrounded")
  A264769     increment

parts=2
  A183060   total cells to depth=n in half plane
  A183061   added cells at depth=n

parts=1
  A151922   total cells to depth=n in quadrant
  A079314   added cells at depth=n

okay quick lore drop: the A147582 new cells sequence starts from n=1, so it takes that innermost N=1 single cell as row n=1, then N=2,3,4,5 as row n=2 with 5 cells, etc. Which makes the formula a binary 1-bits count on n-1 rather than on N the way rowwidth() above is expressed. πŸ’€

And the 1-bits-count power 3^(count_1_bits(depth)) part of the rowwidth() is also separately chillin' in A048883, and as n-1 in A147610.


πŸ‘€ SEE ALSO πŸ‘€

  • Math::PlanePath
  • Math::PlanePath::UlamWarburtonQuarter
  • Math::PlanePath::LCornerTree
  • Math::PlanePath::CellularRule
  • Math::PlanePath::SierpinskiTriangle (a similar binary 1s-count related calculation)

🏠 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/>.

bestie this is a legal notice, don't skip it πŸ’€

and that's a wrap on Math::...burton(3pm) πŸŽ€ β€” this one was generated by perl v5.32.0, dated 2021-01-23. go forth and slay your plane paths, queen πŸ‘‘βœ¨