-1

Why there is this kind of relation between power and factorial? I know that there is a way to use this pattern to generate powers using just addition and one factorial, but I can't wrap my puny brain around it above the fourth power. Is there any way to write a generalised algorithm for this kind of thing? Please answer in pseudocode, because I am looking for a mathematical answer, not a programming one. Here is an example program written in python (by me) exclusive to the third power:

print('This program will print cube numbers without using multiplication.')
max = input('What is the highest number you want to be cubed? Please type u if you want unlimited cubes. ')
a = 1
b = 7
c = 12
i = 1
if max == 'u':
  while True:
    print(i,'cubed is',a)
    a += b
    b += c
    c += 6
    i += 1
else:
  max = int(max)
  for i in range(max):
    print(i+1,'cubed is',a)
    a += b
    b += c
    c += 6

I know that lists may have to be used, or an umlimited amount of variables.

  • I believe that multiplication at its core is addition. Just do the "stupid" way, write a function to realize multiplication as "cnt =0, for i in range (b) cnt+= a" – Leo Ji Sep 17 '23 at 12:55

1 Answers1

1

For reference and to make this question more self-contained, here is an example of the sequence of cubes, and the sequence of differences, etc. down to a row of $3!,3!,\ldots$:

\begin{matrix} 0 & & \boxed1 & & 8 & & 27 & & 64 & & 125\\ & 1 & & \boxed7 & & 19 & & 37 & & 61\\ & & 6 & & \boxed{12} & & 18 & & 24\\ & & & 6 & & 6 & & 6 \end{matrix}

The boxed $1,7,12$ numbers are hard-coded into the sample Python code in the question. But since they don't follow a pattern simpler than the first few powers themselves, we may as well use manual calculation for the first few powers, instead: \begin{matrix} \boxed0 & & \boxed1 & & \boxed8 & & 27 & & 64 & & 125\\ & \underline1 & & \underline7 & & 19 & & 37 & & 61\\ & & \underline6 & & 12 & & 18 & & 24\\ & & & 6 & & 6 & & 6 \end{matrix} Then the underlined values can be calculated via differences from the row above. The bottom row is all $3!$, and any values to the right of the boxed or underlined values can be calculated by summing the values to the left and below-and-to-the-left. For example, $61=24+37$. This idea gives us a recurrence that we can use to solve for any value in the diagram, including all of the cubes (in this case).

In general, if $f_p(r,c)$ is the value in row $r$ and column $c$ (both starting at $0$) in the diagram for the $p$th powers which has row $p$ all equal to $p!$, then we have the following recurrence: $$f_p(r,c)=\begin{cases}\begin{cases}c^{p} & \text{ if }r=0\\f_{p}(r-1,c+1)-f_{p}(r-1,c) & \text{ if }r>0\end{cases} & \text{if }c<p-r\\p! & \text{if }r=p\\f_{p}(r,c-1)+f_{p}(r+1,c-1) & \text{otherwise}\end{cases}$$

In particular, since $r=0$ corresponds to the top row, we have $\boxed{c^p=f_p(0,c)}$ for nonnegative $c$ and positive $p$.

Mark S.
  • 25,893