1Math::PlanePath::PyramiUdsReorwsC(o3n)tributed Perl DocuMmaetnht:a:tPiloannePath::PyramidRows(3)
2
3
4

NAME

6       Math::PlanePath::PyramidRows -- points stacked up in a pyramid
7

SYNOPSIS

9        use Math::PlanePath::PyramidRows;
10        my $path = Math::PlanePath::PyramidRows->new;
11        my ($x, $y) = $path->n_to_xy (123);
12

DESCRIPTION

14       This path arranges points in successively wider rows going upwards so
15       as to form an upside-down pyramid.  The default step is 2, ie. each row
16       2 wider than the preceding, an extra point at the left and the right,
17
18           17  18  19  20  21  22  23  24  25       4
19               10  11  12  13  14  15  16           3     step => 2
20                    5   6   7   8   9               2
21                        2   3   4                   1
22                            1                  <- Y=0
23
24           -4  -3  -2  -1  X=0  1   2   3   4 ...
25
26       The right end N=1,4,9,16,etc is the perfect squares.  The vertical
27       2,6,12,20,etc at x=-1 is the pronic numbers s*(s+1), half way between
28       those successive squares.
29
30       The step 2 is the same as the "PyramidSides", "Corner" and
31       "SacksSpiral" paths.  For the "SacksSpiral", spiral arms going to the
32       right correspond to diagonals in the pyramid, and arms to the left
33       correspond to verticals.
34
35   Step Parameter
36       A "step" parameter controls how much wider each row is than the
37       preceding, to make wider pyramids.  For example step 4
38
39           my $path = Math::PlanePath::PyramidRows->new (step => 4);
40
41       makes each row 2 wider on each side successively
42
43          29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45      4
44                16 17 18 19 20 21 22 23 24 25 26 27 28            3
45                       7  8  9 10 11 12 13 14 15                  2
46                             2  3  4  5  6                        1
47                                   1                        <-  Y=0
48
49                -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6 ...
50
51       If the step is an odd number then the extra is at the right, so step 3
52       gives
53
54           13  14  15  16  17  18  19  20  21  22       3
55                6   7   8   9  10  11  12               2
56                    2   3   4   5                       1
57                        1                         <-  Y=0
58
59           -3  -2  -1  X=0  1   2   3   4 ...
60
61       Or step 1 goes solely to the right.  This is equivalent to the
62       Diagonals path, but columns shifted up to make horizontal rows.
63
64           11  12  13  14  15         4
65            7   8   9  10             3       step => 1
66            4   5   6                 2
67            2   3                     1
68            1                   <-  Y=0
69
70           X=0  1   2   3   4 ...
71
72       Step 0 means simply a vertical, each row 1 wide and not increasing.
73       This is consistent but unlikely to be much use.  The Rows path with
74       "width" 1 does this too.
75
76            5         4
77            4         3     step => 0
78            3         2
79            2         1
80            1    <- Y=0
81
82           X=0
83
84       Various number sequences fall in regular patterns positions depending
85       on the step.  Large steps are not particularly interesting and quickly
86       become very wide.  A limit might be desirable in a user interface, but
87       there's no limit in the code as such.
88
89   Align Parameter
90       An optional "align" parameter controls how the points are arranged
91       relative to the Y axis.  The default shown above is "centre".
92
93       "right" means points to the right of the axis,
94
95           align=>"right"
96
97           26  27  28  29  30  31  32  33  34  35  36        5
98           17  18  19  20  21  22  23  24  25                4
99           10  11  12  13  14  15  16                        3
100            5   6   7   8   9                                2
101            2   3   4                                        1
102            1                                            <- Y=0
103
104           X=0  1   2   3   4   5   6   7   8   9  10
105
106       "left" is similar but to the left of the Y axis, ie. into negative X.
107
108           align=>"left"
109
110           26  27  28  29  30  31  32  33  34  35  36        5
111                   17  18  19  20  21  22  23  24  25        4
112                           10  11  12  13  14  15  16        3
113                                    5   6   7   8   9        2
114                                            2   3   4        1
115                                                    1    <- Y=0
116
117           -10 -9  -8  -7  -6  -5  -4  -3  -2  -1  X=0
118
119       The step parameter still controls how much longer each row is than its
120       predecessor.
121
122   N Start
123       The default is to number points starting N=1 as shown above.  An
124       optional "n_start" can give a different start, in the same rows
125       sequence.  For example to start at 0,
126
127           n_start => 0
128
129           16 17 18 19 20 21 22 23 24        4
130               9 10 11 12 13 14 15           3
131                  4  5  6  7  8              2
132                     1  2  3                 1
133                        0                <- Y=0
134           --------------------------
135           -4 -3 -2 -1 X=0 1  2  3  4
136
137   Step 3 Pentagonals
138       For step=3 the pentagonal numbers 1,5,12,22,etc, P(k) = (3k-1)*k/2, are
139       at the rightmost end of each row.  The second pentagonal numbers
140       2,7,15,26, S(k) = (3k+1)*k/2 are the vertical at x=-1.  Those second
141       numbers are obtained by P(-k), and the two together are the
142       "generalized pentagonal numbers".
143
144       Both these sequences are composites from 12 and 15 onwards,
145       respectively, and the immediately preceding P(k)-1, P(k)-2, and S(k)-1,
146       S(k)-2 are too.  They factorize simply as
147
148           P(k)   = (3*k-1)*k/2
149           P(k)-1 = (3*k+2)*(k-1)/2
150           P(k)-2 = (3*k-4)*(k-1)/2
151           S(k)   = (3*k+1)*k/2
152           S(k)-1 = (3*k-2)*(k+1)/2
153           S(k)-2 = (3*k+4)*(k-1)/2
154
155       Plotting the primes on a step=3 "PyramidRows" has the second pentagonal
156       S(k),S(k)-1,S(k)-2 as a 3-wide vertical gap of no primes at X=-1,-2,-3.
157       The the plain pentagonal P(k),P(k-1),P(k)-2 are the endmost three N of
158       each row non-prime.  The vertical is much more noticeable in a plot.
159
160              no primes these three columns         no primes these end three
161                except the low 2,7,13                     except low 3,5,11
162                      |  |  |                                /  /  /
163            52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
164               36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
165                  23 24 25 26 27 28 29 30 31 32 33 34 35
166                     13 14 15 16 17 18 19 20 21 22
167                         6  7  8  9 10 11 12
168                            2  3  4  5
169                               1
170            -6 -5 -4 -3 -2 -1 X=0 1  2  3  4  5  6  7  8  9 10 11 ...
171
172       With align="left" the end values can be put into columns,
173
174                                       no primes these end three
175           align => "left"                  except low 3,5,11
176                                                   |  |  |
177           36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51        5
178                    23 24 25 26 27 28 29 30 31 32 33 34 35        4
179                             13 14 15 16 17 18 19 20 21 22        3
180                                       6  7  8  9 10 11 12        2
181                                                2  3  4  5        1
182                                                         1    <- Y=0
183                     ... -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0
184
185       In general a constant offset S(k)-c is a column and from P(k)-c is a
186       diagonal sloping up dX=2,dY=1 right.  The simple factorizations above
187       using the roots of the quadratic P(k)-c or S(k)-c is possible whenever
188       24*c+1 is a perfect square.  This means the further columns S(k)-5,
189       S(k)-7, S(k)-12, etc also have no primes.
190
191       The columns S(k), S(k)-1, S(k)-2 are prominent because they're
192       adjacent.  There's no other adjacent columns of this type because the
193       squares after 49 are too far apart for 24*c+1 to be a square for
194       successive c.  Of course there could be other reasons for other columns
195       or diagonals to have few or many primes.
196

FUNCTIONS

198       See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
199       classes.
200
201       "$path = Math::PlanePath::PyramidRows->new ()"
202       "$path = Math::PlanePath::PyramidRows->new (step => $integer, align =>
203       $str, n_start => $n)"
204           Create and return a new path object.  The default "step" is 2.
205           "align" is a string, one of
206
207               "centre"    the default
208               "right"     points aligned right of the Y axis
209               "left"      points aligned left of the Y axis
210
211           Points are always numbered from left to right in the rows, the
212           alignment changes where each row begins (or ends).
213
214       "($x,$y) = $path->n_to_xy ($n)"
215           Return the X,Y coordinates of point number $n on the path.
216
217           For "$n <= 0" the return is an empty list since the path starts at
218           N=1.
219
220       "$n = $path->xy_to_n ($x,$y)"
221           Return the point number for coordinates "$x,$y".  $x and $y are
222           each rounded to the nearest integer, which has the effect of
223           treating each point in the pyramid as a square of side 1.  If
224           "$x,$y" is outside the pyramid the return is "undef".
225
226       "($n_lo, $n_hi) = $path->rect_to_n_range ($x1,$y1, $x2,$y2)"
227           The returned range is exact, meaning $n_lo and $n_hi are the
228           smallest and biggest in the rectangle.
229
230   Descriptive Methods
231       "$x = $path->sumxy_minimum()"
232       "$x = $path->sumxy_maximum()"
233           Return the minimum or maximum values taken by coordinate sum X+Y
234           reached by integer N values in the path.  If there's no minimum or
235           maximum then return "undef".
236
237           The path is right and above the X=-Y diagonal, thus giving a
238           minimum sum, in the following cases.
239
240               align      condition for sumxy_minimum=0
241               ------     -----------------------------
242               centre              step <= 3
243               right               always
244               left                step <= 1
245
246       "$x = $path->diffxy_minimum()"
247       "$x = $path->diffxy_maximum()"
248           Return the minimum or maximum values taken by coordinate difference
249           X-Y reached by integer N values in the path.  If there's no minimum
250           or maximum then return "undef".
251
252           The path is left and above the X=Y leading diagonal, thus giving a
253           minimum X-Y difference, in the following cases.
254
255               align      condition for diffxy_minimum=0
256               ------     -----------------------------
257               centre              step <= 2
258               right               step <= 1
259               left                always
260

OEIS

262       Entries in Sloane's Online Encyclopedia of Integer Sequences related to
263       this path include
264
265           <http://oeis.org/A023531> (etc)
266
267           step=1
268             A002262    X coordinate, runs 0 to k
269             A003056    Y coordinate, k repeated k+1 times
270             A051162    X+Y sum
271             A025581    Y-X diff, runs k to 0
272             A079904    X*Y product
273             A069011    X^2+Y^2, n_to_rsquared()
274             A080099    X bitwise-AND Y
275             A080098    X bitwise-OR  Y
276             A051933    X bitwise-XOR Y
277             A050873    GCD(X+1,Y+1) greatest common divisor by rows
278             A051173    LCM(X+1,Y+1) least common multiple by rows
279
280             A023531    dY, being 1 at triangular numbers (but starting n=0)
281             A167407    dX-dY, change in X-Y (extra initial 0)
282             A129184    turn 1=left, 0=right or straight
283
284             A079824    N total along each opposite diagonal
285             A000124    N on Y axis (triangular+1)
286             A000217    N on X=Y diagonal, extra initial 0
287           step=1, n_start=0
288             A109004    GCD(X,Y) greatest common divisor starting (0,0)
289             A103451    turn 1=left or right,0=straight, but extra initial 1
290             A103452    turn 1=left,0=straight,-1=right, but extra initial 1
291
292           step=2
293             A196199    X coordinate, runs -n to +n
294             A000196    Y coordinate, n appears 2n+1 times
295             A053186    X+Y, being distance to next higher square
296             A010052    dY,  being 1 at perfect square row end
297             A000290    N on X=Y diagonal, extra initial 0
298             A002522    N on X=-Y North-West diagonal (start row), Y^2+1
299             A004201    N for which X>=0, ie. right hand half
300             A020703    permutation N at -X,Y
301           step=2, n_start=0
302             A005563    N on X=Y diagonal, Y*(Y+2)
303             A000290    N on X=-Y North-West diagonal (start row), Y^2
304           step=2, n_start=2
305             A059100    N on north-west diagonal (start each row), Y^2+2
306             A053615    abs(X), runs k..0..k
307           step=2, align=right, n_start=0
308             A196199    X-Y, runs -k to +k
309             A053615    abs(X-Y), runs k..0..k
310           step=2, align=left, n_start=0
311             A005563    N on Y axis, Y*(Y+2)
312
313           step=3
314             A180447    Y coordinate, n appears 3n+1 times
315             A104249    N on Y axis, Y*(3Y+1)/2+1
316             A143689    N on X=-Y North-West diagonal
317           step=3, n_start=0
318             A005449    N on Y axis, second pentagonals Y*(3Y+1)/2
319             A000326    N on diagonal north-west, pentagonals Y*(3Y-1)/2
320
321           step=4
322             A084849    N on Y axis
323             A001844    N on X=Y diagonal (North-East)
324             A058331    N on X=-Y North-West diagonal
325             A221217    permutation N at -X,Y
326           step=4, n_start=0
327             A014105    N on Y axis, the second hexagonal numbers
328             A046092    N on X=Y diagonal, 4*triangular numbers
329           step=4, align=right, n_start=0
330             A060511    X coordinate, amount n exceeds hexagonal number
331             A000384    N on Y axis, the hexagonal numbers
332             A001105    N on X=Y diagonal, 2*squares
333
334           step=5
335             A116668    N on Y axis
336
337           step=6
338             A056108    N on Y axis
339             A056109    N on X=Y diagonal (North-East)
340             A056107    N on X=-Y North-West diagonal
341
342           step=8
343             A053755    N on X=-Y North-West diagonal
344
345           step=9
346             A006137    N on Y axis
347             A038764    N on X=Y diagonal (North-East)
348

SEE ALSO

350       Math::PlanePath, Math::PlanePath::PyramidSides,
351       Math::PlanePath::Corner, Math::PlanePath::SacksSpiral,
352       Math::PlanePath::MultipleRings
353
354       Math::PlanePath::Diagonals, Math::PlanePath::DiagonalsOctant,
355       Math::PlanePath::Rows
356

HOME PAGE

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

LICENSE

361       Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019,
362       2020 Kevin Ryde
363
364       This file is part of Math-PlanePath.
365
366       Math-PlanePath is free software; you can redistribute it and/or modify
367       it under the terms of the GNU General Public License as published by
368       the Free Software Foundation; either version 3, or (at your option) any
369       later version.
370
371       Math-PlanePath is distributed in the hope that it will be useful, but
372       WITHOUT ANY WARRANTY; without even the implied warranty of
373       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
374       General Public License for more details.
375
376       You should have received a copy of the GNU General Public License along
377       with Math-PlanePath.  If not, see <http://www.gnu.org/licenses/>.
378
379
380
381perl v5.36.0                      2023-01-20   Math::PlanePath::PyramidRows(3)
Impressum