1Math::NumSeq::PolygonalU(s3e)r Contributed Perl DocumentaMtaitohn::NumSeq::Polygonal(3)
2
3
4
6 Math::NumSeq::Polygonal -- polygonal numbers, triangular, square,
7 pentagonal, etc
8
10 use Math::NumSeq::Polygonal;
11 my $seq = Math::NumSeq::Polygonal->new (polygonal => 7);
12 my ($i, $value) = $seq->next;
13
15 The sequence of polygonal numbers. The 3-gonals are the triangular
16 numbers i*(i+1)/2, the 4-gonals are squares i*i, the 5-gonals are
17 pentagonals (3i-1)*i/2, etc.
18
19 In general the k-gonals for k>=3 are
20
21 P(i) = (k-2)/2 * i*(i+1) - (k-3)*i
22
23 The values are how many points are in a triangle, square, pentagon,
24 hexagon, etc of side i. For example the triangular numbers,
25
26 d
27 c c d
28 b b c b c d
29 a a b a b c a b c d
30
31 i=1 i=2 i=3 i=4
32 value=1 value=3 value=6 value=10
33
34 Or the squares,
35
36 d d d d
37 c c c c c c d
38 b b b b c b b c d
39 a a b a b c a b c d
40
41 i=1 i=2 i=3 i=4
42 value=1 value=4 value=9 value=16
43
44 Or pentagons (which should be a pentagonal grid, so skewing a bit
45 here),
46
47 d
48 d d
49 c d c d
50 c c d c c d
51 b c b c c b c d
52 b b b b c b b c d
53 a a b a b c a b c d
54
55 i=1 i=2 i=3 i=4
56 value=1 value=5 value=12 value=22
57
58 The letters "a", "b" "c" show the extra added onto the previous figure
59 to grow its points. Each side except two are extended. In general the
60 k-gonals increment by k-2 sides of i points, plus 1 at the end of the
61 last side, so
62
63 P(i+1) = P(i) + (k-2)*i + 1
64
65 Second Kind
66 Option "pairs => 'second'" gives the polygonals of the second kind,
67 which are the same formula but with a negative i.
68
69 S(i) = P(-i) = (k-2)/2 * i*(i-1) + (k-3)*i
70
71 The result is still positive values, bigger than the plain P(i). For
72 example the pentagonals are 0,1,5,12,22,etc and the second pentagonals
73 are 0,2,7,15,26,etc.
74
75 Both Kinds
76 "pairs => 'both'" gives the firsts and seconds interleaved. P(0) and
77 S(0) are both 0 and that value is given just once at i=0, so
78
79 0, P(1), S(1), P(2), S(2), P(3), S(3), ...
80
81 Average
82 Option "pairs => 'average'" is the average of the first and second,
83 which ends up being simply a multiple of the perfect squares,
84
85 A(i) = (P(i)+S(i))/2
86 = (k-2)/2 * i*i
87
88 This is an integer if k is even, or k odd and i is even. If k and i
89 both odd then it's an 0.5 fraction.
90
92 See "FUNCTIONS" in Math::NumSeq for behaviour common to all sequence
93 classes.
94
95 "$seq = Math::NumSeq::Polygonal->new ()"
96 "$seq = Math::NumSeq::Polygonal->new (pairs => $str)"
97 Create and return a new sequence object. The default is the
98 polygonals of the "first" kind, or the "pairs" option (a string)
99 can be
100
101 "first"
102 "second"
103 "both"
104 "average"
105
106 Random Access
107 "$value = $seq->ith($i)"
108 Return the $i'th polygonal value, of the given "pairs" type.
109
110 "$bool = $seq->pred($value)"
111 Return true if $value is a polygonal number, of the given "pairs"
112 type.
113
114 "$i = $seq->value_to_i_estimate($value)"
115 Return an estimate of the i corresponding to $value.
116
118 Math::NumSeq, Math::NumSeq::Cubes
119
121 <http://user42.tuxfamily.org/math-numseq/index.html>
122
124 Copyright 2010, 2011, 2012, 2013, 2014, 2016, 2018, 2019, 2020, 2021
125 Kevin Ryde
126
127 Math-NumSeq is free software; you can redistribute it and/or modify it
128 under the terms of the GNU General Public License as published by the
129 Free Software Foundation; either version 3, or (at your option) any
130 later version.
131
132 Math-NumSeq is distributed in the hope that it will be useful, but
133 WITHOUT ANY WARRANTY; without even the implied warranty of
134 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
135 General Public License for more details.
136
137 You should have received a copy of the GNU General Public License along
138 with Math-NumSeq. If not, see <http://www.gnu.org/licenses/>.
139
140
141
142perl v5.38.0 2023-07-20 Math::NumSeq::Polygonal(3)