1Math::PlanePath::PyramiUdsReorwsC(o3n)tributed Perl DocuMmaetnht:a:tPiloannePath::PyramidRows(3)
2
3
4
6 Math::PlanePath::PyramidRows -- points stacked up in a pyramid
7
9 use Math::PlanePath::PyramidRows;
10 my $path = Math::PlanePath::PyramidRows->new;
11 my ($x, $y) = $path->n_to_xy (123);
12
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
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 step => 1
65
66 11 12 13 14 15 4
67 7 8 9 10 3
68 4 5 6 2
69 2 3 1
70 1 <- Y=0
71
72 X=0 1 2 3 4 ...
73
74 Step 0 means simply a vertical, each row 1 wide and not increasing.
75 This is unlikely to be much use. The Rows path with "width" 1 does
76 this too.
77
78 step => 0
79
80 5 4
81 4 3
82 3 2
83 2 1
84 1 <-y=0
85
86 X=0
87
88 Various number sequences fall in regular patterns positions depending
89 on the step. Large steps are not particularly interesting and quickly
90 become very wide. A limit might be desirable in a user interface, but
91 there's no limit in the code as such.
92
93 Align Parameter
94 An optional "align" parameter controls how the points are arranged
95 relative to the Y axis. The default shown above is "centre".
96
97 "right" means points to the right of the axis,
98
99 align=>"right"
100
101 26 27 28 29 30 31 32 33 34 35 36 5
102 17 18 19 20 21 22 23 24 25 4
103 10 11 12 13 14 15 16 3
104 5 6 7 8 9 2
105 2 3 4 1
106 1 <- Y=0
107
108 X=0 1 2 3 4 5 6 7 8 9 10
109
110 "left" is similar but to the left of the Y axis, ie. into negative X.
111
112 align=>"left"
113
114 26 27 28 29 30 31 32 33 34 35 36 5
115 17 18 19 20 21 22 23 24 25 4
116 10 11 12 13 14 15 16 3
117 5 6 7 8 9 2
118 2 3 4 1
119 1 <- Y=0
120
121 -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0
122
123 The step parameter still controls how much longer each row is than its
124 predecessor.
125
126 N Start
127 The default is to number points starting N=1 as shown above. An
128 optional "n_start" can give a different start, in the same rows
129 sequence. For example to start at 0,
130
131 n_start => 0
132
133 16 17 18 19 20 21 22 23 24 4
134 9 10 11 12 13 14 15 3
135 4 5 6 7 8 2
136 1 2 3 1
137 0 <- Y=0
138 --------------------------
139 -4 -3 -2 -1 X=0 1 2 3 4
140
141 Step 3 Pentagonals
142 For step=3 the pentagonal numbers 1,5,12,22,etc, P(k) = (3k-1)*k/2, are
143 at the rightmost end of each row. The second pentagonal numbers
144 2,7,15,26, S(k) = (3k+1)*k/2 are the vertical at x=-1. Those second
145 numbers are obtained by P(-k), and the two together are the
146 "generalized pentagonal numbers".
147
148 Both these sequences are composites from 12 and 15 onwards,
149 respectively, and the immediately preceding P(k)-1, P(k)-2, and S(k)-1,
150 S(k)-2 are too. They factorize simply as
151
152 P(k) = (3*k-1)*k/2
153 P(k)-1 = (3*k+2)*(k-1)/2
154 P(k)-2 = (3*k-4)*(k-1)/2
155 S(k) = (3*k+1)*k/2
156 S(k)-1 = (3*k-2)*(k+1)/2
157 S(k)-2 = (3*k+4)*(k-1)/2
158
159 Plotting the primes on a step=3 "PyramidRows" has the second pentagonal
160 S(k),S(k)-1,S(k)-2 as a 3-wide vertical gap of no primes at X=-1,-2,-3.
161 The the plain pentagonal P(k),P(k-1),P(k)-2 are the endmost three N of
162 each row non-prime. The vertical is much more noticeable in a plot.
163
164 no primes these three columns no primes these end three
165 except the low 2,7,13 except low 3,5,11
166 | | | / / /
167 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70
168 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
169 23 24 25 26 27 28 29 30 31 32 33 34 35
170 13 14 15 16 17 18 19 20 21 22
171 6 7 8 9 10 11 12
172 2 3 4 5
173 1
174 -6 -5 -4 -3 -2 -1 X=0 1 2 3 4 5 6 7 8 9 10 11 ...
175
176 With align="left" the end values can be put into columns,
177
178 no primes these end three
179 align => "left" except low 3,5,11
180 | | |
181 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 5
182 23 24 25 26 27 28 29 30 31 32 33 34 35 4
183 13 14 15 16 17 18 19 20 21 22 3
184 6 7 8 9 10 11 12 2
185 2 3 4 5 1
186 1 <- Y=0
187 ... -10 -9 -8 -7 -6 -5 -4 -3 -2 -1 X=0
188
189 In general a constant offset S(k)-c is a column and from P(k)-c is a
190 diagonal sloping up dX=2,dY=1 right. The simple factorizations above
191 using the roots of the quadratic P(k)-c or S(k)-c is possible whenever
192 24*c+1 is a perfect square. This means the further columns S(k)-5,
193 S(k)-7, S(k)-12, etc also have no primes.
194
195 The columns S(k), S(k)-1, S(k)-2 are prominent because they're
196 adjacent. There's no other adjacent columns of this type because the
197 squares after 49 are too far apart for 24*c+1 to be a square for
198 successive c. Of course there could be other reasons for other columns
199 or diagonals to have few or many primes.
200
202 See "FUNCTIONS" in Math::PlanePath for behaviour common to all path
203 classes.
204
205 "$path = Math::PlanePath::PyramidRows->new ()"
206 "$path = Math::PlanePath::PyramidRows->new (step => $integer, align =>
207 $str, n_start => $n)"
208 Create and return a new path object. The default "step" is 2.
209 "align" is a string, one of
210
211 "centre" the default
212 "right" points aligned right of the Y axis
213 "left" points aligned left of the Y axis
214
215 Points are always numbered from left to right in the rows, the
216 alignment changes where each row begins (or ends).
217
218 "($x,$y) = $path->n_to_xy ($n)"
219 Return the X,Y coordinates of point number $n on the path.
220
221 For "$n <= 0" the return is an empty list since the path starts at
222 N=1.
223
224 "$n = $path->xy_to_n ($x,$y)"
225 Return the point number for coordinates "$x,$y". $x and $y are
226 each rounded to the nearest integer, which has the effect of
227 treating each point in the pyramid as a square of side 1. If
228 "$x,$y" is outside the pyramid the return is "undef".
229
230 "($n_lo, $n_hi) = $path->rect_to_n_range ($x1,$y1, $x2,$y2)"
231 The returned range is exact, meaning $n_lo and $n_hi are the
232 smallest and biggest in the rectangle.
233
234 Descriptive Methods
235 "$x = $path->sumxy_minimum()"
236 "$x = $path->sumxy_maximum()"
237 Return the minimum or maximum values taken by coordinate sum X+Y
238 reached by integer N values in the path. If there's no minimum or
239 maximum then return "undef".
240
241 The path is right and above the X=-Y diagonal, thus giving a
242 minimum sum, in the following cases.
243
244 align condition for sumxy_minimum=0
245 ------ -----------------------------
246 centre step <= 3
247 right always
248 left step <= 1
249
250 "$x = $path->diffxy_minimum()"
251 "$x = $path->diffxy_maximum()"
252 Return the minimum or maximum values taken by coordinate difference
253 X-Y reached by integer N values in the path. If there's no minimum
254 or maximum then return "undef".
255
256 The path is left and above the X=Y leading diagonal, thus giving a
257 minimum X-Y difference, in the following cases.
258
259 align condition for diffxy_minimum=0
260 ------ -----------------------------
261 centre step <= 2
262 right step <= 1
263 left always
264
266 Entries in Sloane's Online Encyclopedia of Integer Sequences related to
267 this path include
268
269 <http://oeis.org/A023531> (etc)
270
271 step=1
272 A002262 X coordinate, runs 0 to k
273 A003056 Y coordinate, k repeated k+1 times
274 A051162 X+Y sum
275 A025581 Y-X diff, runs k to 0
276 A079904 X*Y product
277 A069011 X^2+Y^2, n_to_rsquared()
278 A080099 X bitwise-AND Y
279 A080098 X bitwise-OR Y
280 A051933 X bitwise-XOR Y
281 A050873 GCD(X+1,Y+1) greatest common divisor by rows
282 A051173 LCM(X+1,Y+1) least common multiple by rows
283
284 A023531 dY, being 1 at triangular numbers (but starting n=0)
285 A167407 dX-dY, change in X-Y (extra initial 0)
286 A129184 turn 1=left, 0=right or straight
287
288 A079824 N total along each opposite diagonal
289 A000124 N on Y axis (triangular+1)
290 A000217 N on X=Y diagonal, extra initial 0
291 step=1, n_start=0
292 A109004 GCD(X,Y) greatest common divisor starting (0,0)
293 A103451 turn 1=left or right,0=straight, but extra initial 1
294 A103452 turn 1=left,0=straight,-1=right, but extra initial 1
295
296 step=2
297 A196199 X coordinate, runs -n to +n
298 A000196 Y coordinate, n appears 2n+1 times
299 A053186 X+Y, being distance to next higher square
300 A010052 dY, being 1 at perfect square row end
301 A000290 N on X=Y diagonal, extra initial 0
302 A002522 N on X=-Y North-West diagonal (start row), Y^2+1
303 A004201 N for which X>=0, ie. right hand half
304 A020703 permutation N at -X,Y
305 step=2, n_start=0
306 A005563 N on X=Y diagonal, Y*(Y+2)
307 A000290 N on X=-Y North-West diagonal (start row), Y^2
308 step=2, n_start=2
309 A059100 N on north-west diagonal (start each row), Y^2+2
310 A053615 abs(X), runs k..0..k
311 step=2, align=right, n_start=0
312 A196199 X-Y, runs -k to +k
313 A053615 abs(X-Y), runs k..0..k
314 step=2, align=left, n_start=0
315 A005563 N on Y axis, Y*(Y+2)
316
317 step=3
318 A180447 Y coordinate, n appears 3n+1 times
319 A104249 N on Y axis, Y*(3Y+1)/2+1
320 A143689 N on X=-Y North-West diagonal
321 step=3, n_start=0
322 A005449 N on Y axis, second pentagonals Y*(3Y+1)/2
323 A000326 N on diagonal north-west, pentagonals Y*(3Y-1)/2
324
325 step=4
326 A084849 N on Y axis
327 A001844 N on X=Y diagonal (North-East)
328 A058331 N on X=-Y North-West diagonal
329 A221217 permutation N at -X,Y
330 step=4, n_start=0
331 A014105 N on Y axis, the second hexagonal numbers
332 A046092 N on X=Y diagonal, 4*triangular numbers
333 step=4, align=right, n_start=0
334 A060511 X coordinate, amount n exceeds hexagonal number
335 A000384 N on Y axis, the hexagonal numbers
336 A001105 N on X=Y diagonal, 2*squares
337
338 step=5
339 A116668 N on Y axis
340
341 step=6
342 A056108 N on Y axis
343 A056109 N on X=Y diagonal (North-East)
344 A056107 N on X=-Y North-West diagonal
345
346 step=8
347 A053755 N on X=-Y North-West diagonal
348
349 step=9
350 A006137 N on Y axis
351 A038764 N on X=Y diagonal (North-East)
352
354 Math::PlanePath, Math::PlanePath::PyramidSides,
355 Math::PlanePath::Corner, Math::PlanePath::SacksSpiral,
356 Math::PlanePath::MultipleRings
357
358 Math::PlanePath::Diagonals, Math::PlanePath::DiagonalsOctant,
359 Math::PlanePath::Rows
360
362 <http://user42.tuxfamily.org/math-planepath/index.html>
363
365 Copyright 2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018 Kevin
366 Ryde
367
368 This file is part of Math-PlanePath.
369
370 Math-PlanePath is free software; you can redistribute it and/or modify
371 it under the terms of the GNU General Public License as published by
372 the Free Software Foundation; either version 3, or (at your option) any
373 later version.
374
375 Math-PlanePath is distributed in the hope that it will be useful, but
376 WITHOUT ANY WARRANTY; without even the implied warranty of
377 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
378 General Public License for more details.
379
380 You should have received a copy of the GNU General Public License along
381 with Math-PlanePath. If not, see <http://www.gnu.org/licenses/>.
382
383
384
385perl v5.32.0 2020-07-28 Math::PlanePath::PyramidRows(3)