Desmos Polygonal Number Diagrams

Dan MacKinnon

Abstract

Polygonal numbers, like the triangular, square, and pentagonal numbers, are closely identified with (or even defined in terms of) the diagrams that they are associated with. The functional programming capabilities of the Desmos graphing calculator provides fun and interesting ways of exploring number diagrams like those associated with polygonal numbers. This short article provides one approach that can be used to build polygonal number diagrams in Desmos.

Polygonal numbers

For a given k+,k>2k\in\mathbb{Z}^{+},k>2, the kk-polygonal numbers[1] are a recursively defined integer sequence, as shown in Equation (1).

pk,1\displaystyle p_{k,1} =1\displaystyle=1
pk,i\displaystyle p_{k,i} =pk,i1+(k2)i(k3)\displaystyle=p_{k,i-1}+(k-2)i-(k-3) (1)

For a term in the sequence n=pk,in=p_{k,i}, nn dots can be arranged in a regular kk-polygon built up of ii layers (traditionally referred to as gnomons), as shown for the pentagonal numbers (k=5k=5) of Figure (1).

Refer to caption
Figure 1: The first few pentagonal numbers, showing first and second differences

If nn is the iith kk-polygonal number, it can be drawn as a layered regular kk-polygon with ii gnomon layers, as shown for the third pentagonal number 1212, p5,3=12p_{5,3}=12, in Figure (2).

Refer to caption
Figure 2: Pentagonal number diagram n=12n=12 with gnomons

Placing any nn in a kk-polygonal diagram

Let n,k+n,k\in\mathbb{Z}^{+}, k>2k>2. We would like to draw the kk-polygonal number diagram “up to” nn. If nn happens to actually be a kk-polygonal number, this will be a complete diagram with nn dots in a layered kk-polygon. Otherwise, this will be a diagram whose outer gnomon layer is incomplete.

Figure (3) shows hexagonal number (k=6k=6) diagrams for the numbers 15 and 26. Because 15 actually is a hexagonal number, the diagram is complete. The diagram for 26 shows an incomplete diagram, with an incomplete outer layer.

Refer to caption
Figure 3: Two hexagonal diagrams (k=6k=6), 15 is hexagonal, 26 is not

Finding the gnomon for nn and kk

The recursive definition for pk,1p_{k,1} in Equation (1 yields formulas stated as a summation (2) and a direct calculation (3).

pk,i=j=1i[(k2)j(k3)]p_{k,i}=\sum^{i}_{j=1}\left[(k-2)j-(k-3)\right] (2)
pk,i=(k2)i(i+1)2(k3)ip_{k,i}=\frac{(k-2)i(i+1)}{2}-(k-3)i (3)

Applying the quadratic formula to solve npk,i=0n-p_{k,i}=0 provides us with

g(n,k)=(k4)+(k4)2+8n(k2)2(k2)g\left(n,k\right)=\frac{\left(k-4\right)+\sqrt{\left(k-4\right)^{2}+8n\left(k-% 2\right)}}{2\left(k-2\right)} (4)

This allows us to identify the gnomon layer gnomon(n,k)\text{gnomon}(n,k) that a given nn will sit in within a kk-polygonal diagram (5).

gnomon(n,k)=ceil(g(n))\text{gnomon}\left(n,k\right)=\text{ceil}\left(g\left(n\right)\right) (5)

The position of nn within its gnomon layer

The size of the gnomon layer that nn will sit in (how many dots would be in the layer within the diagram) is given by Equation (6).

gsize(n,k)=1+(gnomon(n,k)1)(k2)\text{gsize}\left(n,k\right)=1+(\text{gnomon}\left(n,k\right)-1)\cdot\left(k-2\right) (6)

To find the position of the nnth dot within the gnomon, we need to count the number of dots that came before it within that gnomon. To do this we can sum up to n1n-1 over a function whose value is 0 for all ii where gnomon(i,k)<gnomon(n,k)gnomon(i,k)<gnomon(n,k), and whose value is 11 for those ii where gnomon(i,k)=gnomon(n,k)gnomon(i,k)=gnomon(n,k). This sum that gives us the ”depth” of n within its gnomon is provided by Equation (7).

gdepth(n,k)=i=1n(floor(gnomon(i,k)gnomon(n,k)))\text{gdepth}\left(n,k\right)=\sum_{i=1}^{n}\left(\text{floor}\left(\frac{% gnomon\left(i,k\right)}{gnomon\left(n,k\right)}\right)\right) (7)

Drawing the diagram

For a given n,k+n,k\in\mathbb{Z}^{+}, k>2k>2, the preceding sections tell us which gnomon nn will be placed in in a kk-polygonal diagram, and in which spot along the gnomon.

To complete the diagram, we need to also determine how much the gnomon is bent at the particular position that nn finds itself at. Because the gnomon is a layer in a regular kk-gon, it bends in increments of the base angle alphakalpha_{k} that is given by Equation (8).

αk=(π((k2)(π/k)))\alpha_{k}=\left(\pi-((k-2)*(\pi/k))\right) (8)

As we draw a gnomon, we’ll start at the left-most position, which for a given nn can be expressed by (x0(n,k),y0(n,k)(x_{0}(n,k),y_{0}(n,k) as defined in (9).

x0(n,k)\displaystyle x_{0}\left(n,k\right) =gnomon(n,k)cos(αk)\displaystyle=-\text{gnomon}\left(n,k\right)\cos{(\alpha_{k})}
y0(n,k)\displaystyle y_{0}\left(n,k\right) =gnomon(n,k)sin(αk)\displaystyle=\text{gnomon}\left(n,k\right)\sin{(\alpha_{k})} (9)

Starting at the initial point (x0(n,k),y0(n,k)(x_{0}(n,k),y_{0}(n,k) for a given nn, we want to move along the gnomon layer up to the gnomon depth of nn (gdepth(n)\text{gdepth}(n)), bending along the gnomon as required. This process is expressed by the sums in the definitions of x(n,k)x(n,k) and y(n,k)y(n,k) of (10).

x(n,k)\displaystyle x(n,k) =x0(n,k)j=1gdepth(n)1cos(αk[ceil(jgsize(n)(k2))+1])\displaystyle=x_{0}(n,k)-\sum_{j=1}^{\text{gdepth}\left(n\right)-1}\cos\left(% \alpha_{k}\cdot\left[\operatorname{ceil}\left(\frac{j}{\text{gsize}\left(n% \right)}\left(k-2\right)\right)+1\right]\right)
y(n,k)\displaystyle y(n,k) =y0(n,k)+j=1gdepth(n)1sin(αk[ceil(jgsize(n)(k2))+1])\displaystyle=y_{0}(n,k)+\sum_{j=1}^{\text{gdepth}\left(n\right)-1}\sin\left(% \alpha_{k}\cdot\left[\operatorname{ceil}\left(\frac{j}{\text{gsize}\left(n% \right)}\left(k-2\right)\right)+1\right]\right) (10)

Building in Desmos

To begin building the polygonal number diagrams in Desmos[2], begin with creating sliders for nn and kk, and a sequence NN of the integers between 11 and nn. The base angle can also be defined.

Slider nn; 1n1001\leq n\leq 100 step: 1

Slider kk; 2k1002\leq k\leq 100 step: 1

N=[1,,n]N=\left[1,\ ...\ ,n\ \right]

angle=π(k2)πka_{ngle}=\pi-(k-2)\cdot\frac{\pi}{k}

Chose a variable name that does not correspond to one of the already used variables, and implement equations (4) and (5). The value of kk is defined globally and does not need to be passed as a paramenter. The value of nn is not used directly; instead, the functions will be evaluated using the values of the array NN. Here ll will be used as the parameter name rather than nn.

g(l)=(k4)+sqrt((k4)2+8l(k2))/(2(k2))g(l)=(k-4)+\text{sqrt}((k-4)^{2}+8l(k-2))/(2(k-2))
gnomon(l)=floor(g(l))g_{nomon}(l)=\text{floor}(g(l))

Next, implement the gnomon size and depth functions.

gsize(l)=1+(gnomon(l)1)(k2)g_{size}(l)=1+(g_{nomon}(l)-1)\cdot(k-2)
gdepth(l)=i=1l(floor(gnomon(i)/gnomon(l)))g_{depth}(l)=\sum_{i=1}^{l}(\text{floor}(g_{nomon}(i)/g_{nomon}(l)))

Finally, the equations for the coordinates of each plotted point can be defined based on equations (9) and (10).

x0(l)=gnomon(l)cos(angle)x_{0}(l)=-g_{nomon}(l)\cos{(a_{ngle})}

y0(l))=gnomon(l)sin(angle)y_{0}(l))=g_{nomon}(l)\sin{(a_{ngle})}
xpoly(l)=x0(l)j=1gdepth(l)1cos(angle(ceil((j/gsize(l))(k2))+1))x_{poly}(l)=x_{0}(l)-\sum_{j=1}^{g_{depth}(l)-1}\cos(a_{ngle}\cdot(%
\operatorname{ceil}(({j}/{g_{size}(l)})(k-2))+1))



ypoly(l)=y0(l)j=1gdepth(l)1sin(angle(ceil((j/gsize(l))(k2))+1))y_{poly}(l)=y_{0}(l)-\sum_{j=1}^{g_{depth}(l)-1}\sin(a_{ngle}\cdot(%
\operatorname{ceil}(({j}/{g_{size}(l)})(k-2))+1))

To plot the points, the functions above are applied to the sequence NN. The grid and axis can be removed from the plot.

(xpoly(N),ypoly(N))(x_{poly}(N),y_{poly}(N))

A completed implementation of these instructions can be found here:

https://www.desmos.com/calculator/cz80t85moz.

Bibliography

  • [1] J. H. Conway and R. Guy (1998) The book of numbers. Springer Science & Business Media. Cited by: Polygonal numbers.
  • [2] Desmos Desmos Graphing Calculator software. Note: https://www.desmos.com/ Cited by: Building in Desmos.