Skip to content

PolygonalNumbers ​

The kk-gonal figurate numbers P(k,n)=((k−2)n2−(k−4)n)/2P(k, n) = \big((k-2)n^2 - (k-4)n\big)/2, one lazy indexed collection per polygon size k≥3k \ge 3.

PolygonalNumbers(k)P(k,n)P(k, n) for n=1,2,3,…n = 1, 2, 3, …, the kk-gonal numbers.
Typed signatures
TypePackageApplies
(integer<0..>) -> indexed_collection<integer>combinatoricsalways

Domain: Collections

Details
  • A lazy indexed family for each k≥3k \ge 3: Count(PolygonalNumbers(k))=+∞Count(PolygonalNumbers(k)) = +\infty, and At(PolygonalNumbers(k),n)At(PolygonalNumbers(k), n) unranks P(k,n)P(k, n) in closed form -- At(PolygonalNumbers(5),3)=12At(PolygonalNumbers(5), 3) = 12.
  • k=3,4,5,6,7,8k = 3, 4, 5, 6, 7, 8 reproduce TriangularNumbers, SquareNumbers, PentagonalNumbers, HexagonalNumbers, HeptagonalNumbers and OctagonalNumbers termwise; those fixed-kk names exist as their own lazy collections for convenience, not as a separate definition.
  • Membership goes through Element by inverting the quadratic in nn exactly for the given kk -- Element(12,PolygonalNumbers(5))Element(12, PolygonalNumbers(5)) is true, Element(13,PolygonalNumbers(5))Element(13, PolygonalNumbers(5)) is false.

Definition

Epsil, as the implementation runs it.

count(_k)

0 if _k < 3 else PositiveInfinity

unrank(_k, _r)

(_r + 1) * ((_k - 2) * (_r + 1) - (_k - 4)) / 2

rank(_k, _x)

Apply(
       (sq_at: integer) => sq_at if (sq_at + 1) * ((_k - 2) * (sq_at + 1) - (_k -
                                                                             4)) /
                                    2 == _x else -1,
       Fold(
             Function(
                       sq_at + 2 ^ sq_b if (sq_at + 2 ^ sq_b + 1) *
                                           ((_k - 2) * (sq_at + 2 ^ sq_b + 1) -
                                            (_k - 4)) / 2 <= _x else sq_at,
                       sq_at,
                       sq_b,
                     ),
             0,
             Range(Floor(Log(_x, 2)) + 1, 0, -1),
           ),
     ) if _k >= 3 else -1

valid(_k, _x)

Apply(
       (sq_at: integer) => (sq_at + 1) * ((_k - 2) * (sq_at + 1) - (_k - 4)) / 2 ==
                           _x,
       Fold(
             Function(
                       sq_at + 2 ^ sq_b if (sq_at + 2 ^ sq_b + 1) *
                                           ((_k - 2) * (sq_at + 2 ^ sq_b + 1) -
                                            (_k - 4)) / 2 <= _x else sq_at,
                       sq_at,
                       sq_b,
                     ),
             0,
             Range(Floor(Log(_x, 2)) + 1, 0, -1),
           ),
     ) if _k >= 3 && _x >= 1 else False

Enumeration

Examples

7 more kept as data, checked against the oracles
About
Examples7

Implementation

mappedwolframpackages/oracle/src/mappings.ts

Wolfram's own PolygonalNumber[r, n] gives one term (kernel-verified: matches ours termwise) but there's no lazy collection to Take from -- only Table[PolygonalNumber[r, n], {n, 1, count}], which a per-head template on PolygonalNumbers alone can't compose with the outer Take call. Wolfram Function Repository searched; PolygonalDiagram found but it's a visualization (draws the dot array), not a term source.

See also: TriangularNumbers, SquareNumbers, PentagonalNumbers, HexagonalNumbers, Count, At, Element