# Triangular and pyramidal numbers

Posted 1 year ago
1170 Views
|
0 Replies
|
6 Total Likes
|
 NOTE: the following resources are available for the content below: Desktop notebook is attached at the end of this post Access Cloud Notebook at: https://www.wolframcloud.com/objects/edacc722-f258-4ed3-9f2f-719c2f1bad9d Cloud Notebook Short URL: https://wolfr.am/GosperPyramidal Consider the triangular numbers. Here is how they are defined:f(n)="The triangular numbers"=1+2+ . . .+n. Using 9 for n, Graphics[{PointSize[Large], Point[Permutations[Range@9, {2}]]}] I.e.,the unequal pairs of numbers up to 9 plots as a 9*9 square minus its length 9 diagonal. But this is just two copies of 1+ . . .+8. SoSolving for f(n) RSolve[%, f[n], n] // Factor This is essentially how Gauß, the youngster, startled his grammar school teacher.In highschool, my friend Reed Carson and I got this a different way - by adding up the areas of n+1 triangles: Table[{x, y}, {x, 4}, {y, x}] {{{1, 1}}, {{2, 1}, {2, 2}}, {{3, 1}, {3, 2}, {3, 3}}, {{4, 1}, {4, 2}, {4, 3}, {4, 4}}} Graphics[{EdgeForm[White], Blue, % /. {x_Integer, y_} -> Rectangle[{x, y}]}] /. {L___, Rectangle[{x_Integer, y_}]} :> {L, Triangle[{{x, y}, {x + 1, y}, {x + 1, y + 1}}], Red, Triangle[{{x, y}, {x, y + 1}, {x + 1, y + 1}}]} Now for 3D. Using as coordinates the integers 1, 2, ..., n taken three at a time, Graphics3D[Sphere[Permutations[Range@9, {3}], 1/2]] The unequal triads of numbers up to 9 plots as a 9x9x9 cube minus those diagonals which have two or three coordinates the same: Graphics3D[Sphere[Select[Tuples[Range@9, 3], Not[UnsameQ @@ #] &], 1/2]] This is six triangulars of size 8 (= n-1) plus the central column of 9 (=n).The former is six pyramids of size 7 (= n-2).  Together they make a cube of size n=9. So the equation for the pyramidal numbers solves as RSolve[6 f[n - 2] + 6 n (n - 1)/2 + n == n^3, f[n], n] // Factor Instead of 1 + 3 + 6 + . . . + n, summing $1^2 + 2^2 + . . . + n^2$ gives the "square pyramidal numbers", Table[Sphere[{x, y, z}, 1/2], {z, 7}, {y, z}, {x, z}] // Graphics3D each of which is the sum of two consecutive ordinary pyramidal numbers: % /. Sphere[{x_, y_, z_}, 1/2] :> Sphere[{x, y, z}, 1/4] /; x < y So the sum of the first n squares, $1^2 + 2^2 + . . . + n^2$, is Factor[1/6 (n-1) (n+1) n+1/6 (n+1) (n+2) n] (You can also see that each square (each layer) is the sum of two consecutive triangular numbers.)But, as before, my friend Reed and I got this geometrically, as the the sum of a big pyramid plus two triangular arrays of half-cubes, plus n "notched" cubes (shown transparent) running up the long diagonal, each notch being a little pyramid of volume ⅓: Graphics3D[{White, Table[If[x == y, {Opacity[.0], #}, #] &@ Cuboid[{x - 1, y - 1, 5 - z}], {z, 5}, {y, z}, {x, z}], Polygon[{{{0, 0, 0}, {5, 0, 0}, {5, 5, 0}, {0, 5, 0}}, {{0, 0, 0}, {0, 0, 5}, {5, 0, 0}}, {{0, 0, 5}, {5, 5, 0}, {5, 0, 0}}, {{0, 0, 5}, {0, 0, 0}, {0, 5, 0}}, {{0, 0, 5}, {5, 5, 0}, {0, 5, 0}}}]}] For 5 = n, the volume of this is big pyramid + n notched cubes + two triangles of half-cubes , or Factor[n^3/3+(1-1/3) n+(2 n (n-1))/(2 2)] (For this problem, we don't need to know that the volume of a pyramid is always ⅓ the volume of its circumscribing prism, because a cube can always dissect into three copies of the (square based) pyramid we're discussing.) Attachments: