1Math::PlanePath::PowerAUrsreary(C3o)ntributed Perl DocumMeanttha:t:iPolnanePath::PowerArray(3)
2
3
4

NAME

6       Math::PlanePath::PowerArray -- array by powers
7

SYNOPSIS

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

DESCRIPTION

14       This is a split of N into an odd part and power of 2,
15
16            14  |   29    58   116   232   464   928  1856  3712  7424 14848
17            13  |   27    54   108   216   432   864  1728  3456  6912 13824
18            12  |   25    50   100   200   400   800  1600  3200  6400 12800
19            11  |   23    46    92   184   368   736  1472  2944  5888 11776
20            10  |   21    42    84   168   336   672  1344  2688  5376 10752
21             9  |   19    38    76   152   304   608  1216  2432  4864  9728
22             8  |   17    34    68   136   272   544  1088  2176  4352  8704
23             7  |   15    30    60   120   240   480   960  1920  3840  7680
24             6  |   13    26    52   104   208   416   832  1664  3328  6656
25             5  |   11    22    44    88   176   352   704  1408  2816  5632
26             4  |    9    18    36    72   144   288   576  1152  2304  4608
27             3  |    7    14    28    56   112   224   448   896  1792  3584
28             2  |    5    10    20    40    80   160   320   640  1280  2560
29             1  |    3     6    12    24    48    96   192   384   768  1536
30           Y=0  |    1     2     4     8    16    32    64   128   256   512
31                +-----------------------------------------------------------
32                   X=0     1     2     3     4     5     6     7     8     9
33
34       For N=odd*2^k the coordinates are X=k, Y=(odd-1)/2.  The X coordinate
35       is how many factors of 2 can be divided out.  The Y coordinate counts
36       odd integers 1,3,5,7,etc as 0,1,2,3,etc.  This is clearer by writing N
37       values in binary,
38
39           N values in binary
40
41             6  |  1101     11010    110100   1101000  11010000 110100000
42             5  |  1011     10110    101100   1011000  10110000 101100000
43             4  |  1001     10010    100100   1001000  10010000 100100000
44             3  |   111      1110     11100    111000   1110000  11100000
45             2  |   101      1010     10100    101000   1010000  10100000
46             1  |    11       110      1100     11000    110000   1100000
47           Y=0  |     1        10       100      1000     10000    100000
48                +----------------------------------------------------------
49                    X=0         1         2         3         4         5
50
51   Radix
52       The "radix" parameter can do the same dividing out in a higher base.
53       For example radix 3 divides out factors of 3,
54
55            radix => 3
56
57             9  |   14    42   126   378  1134  3402 10206 30618
58             8  |   13    39   117   351  1053  3159  9477 28431
59             7  |   11    33    99   297   891  2673  8019 24057
60             6  |   10    30    90   270   810  2430  7290 21870
61             5  |    8    24    72   216   648  1944  5832 17496
62             4  |    7    21    63   189   567  1701  5103 15309
63             3  |    5    15    45   135   405  1215  3645 10935
64             2  |    4    12    36   108   324   972  2916  8748
65             1  |    2     6    18    54   162   486  1458  4374
66           Y=0  |    1     3     9    27    81   243   729  2187
67                +------------------------------------------------
68                   X=0     1     2     3     4     5     6     7
69
70       N=1,3,9,27,etc on the X axis is the powers of 3.
71
72       N=1,2,4,5,7,etc on the Y axis is the integers N=1or2 mod 3, ie. those
73       not a multiple of 3.  Notice if Y=1or2 mod 4 then the N values in that
74       row are all even, or if Y=0or3 mod 4 then the N values are all odd.
75
76           radix => 3,  N values in ternary
77
78             6  |   101     1010    10100   101000  1010000 10100000
79             5  |    22      220     2200    22000   220000  2200000
80             4  |    21      210     2100    21000   210000  2100000
81             3  |    12      120     1200    12000   120000  1200000
82             2  |    11      110     1100    11000   110000  1100000
83             1  |     2       20      200     2000    20000   200000
84           Y=0  |     1       10      100     1000    10000   100000
85                +----------------------------------------------------
86                    X=0        1        2        3        4        5
87
88   Boundary Length
89       The points N=1 to N=2^k-1 inclusive have a boundary length
90
91           boundary = 2^k + 2k
92
93       For example N=1 to N=7 is
94
95           +---+
96           | 7 |
97           +   +
98           | 5 |
99           +   +---+
100           | 3   6 |
101           +       +---+
102           | 1   2   4 |
103           +---+---+---+
104
105       The height is the odd numbers, so 2^(k-1).  The width is the power k.
106       So total boundary 2*height+2*width = 2^k + 2k.
107
108       If N=2^k is included then it's on the X axis and so add 2, for boundary
109       = 2^k + 2k + 2.
110
111       For other radix the calculation is similar
112
113           boundary = 2 * (radix-1) * radix^(k-1) + 2*k
114
115       For example radix=3, N=1 to N=8 is
116
117           8
118           7
119           5
120           4
121           2  6
122           1  3
123
124       The height is the non-multiples of the radix, so (radix-1)/radix *
125       radix^k.  The width is the power k again.  So total boundary =
126       2*height+2*width.
127

FUNCTIONS

129       See "FUNCTIONS" in Math::PlanePath for the behaviour common to all path
130       classes.
131
132       "$path = Math::PlanePath::PowerArray->new ()"
133           Create and return a new path object.
134
135       "($x,$y) = $path->n_to_xy ($n)"
136           Return the X,Y coordinates of point number $n on the path.  Points
137           begin at 1 and if "$n < 0" then the return is an empty list.
138
139       "$n = $path->xy_to_n ($x,$y)"
140           Return the N point number at coordinates "$x,$y".  If "$x<0" or
141           "$y<0" then there's no N and the return is "undef".
142
143           N values grow rapidly with $x.  Pass in a number type such as
144           "Math::BigInt" to preserve precision.
145
146       "($n_lo, $n_hi) = $path->rect_to_n_range ($x1,$y1, $x2,$y2)"
147           The returned range is exact, meaning $n_lo and $n_hi are the
148           smallest and biggest in the rectangle.
149

FORMULAS

151   Rectangle to N Range
152       Within each row increasing X is increasing N, and in each column
153       increasing Y is increasing N.  So in a rectangle the lower left corner
154       is the minimum N and the upper right is the maximum N.
155
156           |               N max
157           |     ----------+
158           |    |  ^       |
159           |    |  |       |
160           |    |   ---->  |
161           |    +----------
162           |   N min
163           +-------------------
164
165   N to Turn Left or Right
166       The turn left or right is given by
167
168           radix = 2     left at N==0 mod radix and N==1mod4, right otherwise
169
170           radix >= 3    left at N==0 mod radix
171                         right at N=1 or radix-1 mod radix
172                         straight otherwise
173
174       The points N!=0 mod radix are on the Y axis and those N==0 mod radix
175       are off the axis.  For that reason the turn at N==0 mod radix is to the
176       left,
177
178           |
179           C--
180              ---
181           A--__ --        point B is N=0 mod radix,
182           |    --- B      turn left A-B-C is left
183
184       For radix>=3 the turns at A and C are to the right, since the point
185       before A and after C is also on the Y axis.  For radix>=4 there's of
186       run of points on the Y axis which are straight.
187
188       For radix=2 the "B" case N=0 mod 2 applies, but for the A,C points in
189       between the turn alternates left or right.
190
191           1--     N=1 mod 4             3--      N=3 mod 4
192            \ --   turn left              \ --    turn right
193             \  --                         \  --
194              2   --                        2   --
195                    --                            --
196                      --                            --
197                        0                             4
198
199       Points N=2 mod 4 are X=1 and Y=N/2 whereas N=0 mod 4 has 2 or more
200       trailing 0 bits so X>1 and Y<N/2.
201
202           N mod 4      turn
203           -------     ------
204              0        left         for radix=2
205              1         left
206              2        left
207              3         right
208

OEIS

210       Entries in Sloane's Online Encyclopedia of Integer Sequences related to
211       this path include
212
213           <http://oeis.org/A007814> (etc)
214
215           radix=2
216             A007814    X coordinate, count low 0-bits of N
217             A006519    2^X
218
219             A025480    Y coordinate of N-1, ie. seq starts from N=0
220             A003602    Y+1, being k for which N=(2k-1)*2^m
221             A153733    2*Y of N-1, strip low 1 bits
222             A000265    2*Y+1, strip low 0 bits
223
224             A094267    dX, change count low 0-bits
225             A050603    abs(dX)
226             A108715    dY, change in Y coordinate
227
228             A000079    N on X axis, powers 2^X
229             A057716    N not on X axis, the non-powers-of-2
230
231             A005408    N on Y axis (X=0), the odd numbers
232             A003159    N in X=even columns, even trailing 0 bits
233             A036554    N in X=odd columns
234
235             A014480    N on X=Y diagonal, (2n+1)*2^n
236             A118417    N on X=Y+1 diagonal, (2n-1)*2^n
237                          (just below X=Y diagonal)
238
239             A054582    permutation N by diagonals, upwards
240             A135764    permutation N by diagonals, downwards
241             A075300    permutation N-1 by diagonals, upwards
242             A117303    permutation N at transpose X,Y
243
244             A100314    boundary length for N=1 to N=2^k-1 inclusive
245                          being  2^k+2k
246             A131831      same, after initial 1
247             A052968    half boundary length N=1 to N=2^k inclusive
248                          being  2^(k-1)+k+1
249
250           radix=3
251             A007949    X coordinate, power-of-3 dividing N
252             A000244    N on X axis, powers 3^X
253             A001651    N on Y axis (X=0), not divisible by 3
254             A007417    N in X=even columns, even trailing 0 digits
255             A145204    N in X=odd columns (extra initial 0)
256             A141396    permutation, N by diagonals down from Y axis
257             A191449    permutation, N by diagonals up from X axis
258             A135765    odd N by diagonals, deletes the Y=1,2mod4 rows
259             A000975    Y at N=2^k, being binary "10101..101"
260
261           radix=4
262             A000302    N on X axis, powers 4^X
263
264           radix=5
265             A112765    X coordinate, power-of-5 dividing N
266             A000351    N on X axis, powers 5^X
267
268           radix=6
269             A122841    X coordinate, power-of-6 dividing N
270
271           radix=10
272             A011557    N on X axis, powers 10^X
273             A067251    N on Y axis, not a multiple of 10
274             A151754    Y coordinate of N=2^k, being floor(2^k*9/10)
275

SEE ALSO

277       Math::PlanePath, Math::PlanePath::WythoffArray,
278       Math::PlanePath::ZOrderCurve
279
280       David M. Bradley "Counting Ordered Pairs", Mathematics Magazine, volume
281       83, number 4, October 2010, page 302, DOI 10.4169/002557010X528032.
282       <http://www.math.umaine.edu/~bradley/papers/JStor002557010X528032.pdf>
283

HOME PAGE

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

LICENSE

288       Copyright 2012, 2013, 2014, 2015, 2016, 2017, 2018 Kevin Ryde
289
290       This file is part of Math-PlanePath.
291
292       Math-PlanePath is free software; you can redistribute it and/or modify
293       it under the terms of the GNU General Public License as published by
294       the Free Software Foundation; either version 3, or (at your option) any
295       later version.
296
297       Math-PlanePath is distributed in the hope that it will be useful, but
298       WITHOUT ANY WARRANTY; without even the implied warranty of
299       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
300       General Public License for more details.
301
302       You should have received a copy of the GNU General Public License along
303       with Math-PlanePath.  If not, see <http://www.gnu.org/licenses/>.
304
305
306
307perl v5.30.1                      2020-01-30    Math::PlanePath::PowerArray(3)
Impressum