I'm working on an old problem based on SICP and I'm a bit confused by how to relate the variables of expt-iter in the way that the problem is asking below:
Give an algebraic formula relating the values of the parameters
b,n,counter, andproductof theexptandexp-iterprocedures. (The kind of answer we’re looking for is “the sum of b, n, and counter times product is always equal to 37.”) (HINT: you might want to make a chart of values)
(define (expt b n)
(expt-iter b n 1)
(define (expt-iter b counter product)
(if (= counter 0)
product
(expt-iter b
(- counter 1)
(* b product))))
Taking the advice of the hint, I made a chart of values based on $2^8$:
| b | n | a |
|---|---|-----|
| 2 | 8 | 1 |
| 2 | 7 | 2 |
| 2 | 6 | 4 |
| 2 | 5 | 8 |
| 2 | 4 | 16 |
| 2 | 3 | 32 |
| 2 | 2 | 64 |
| 2 | 1 | 128 |
| 2 | 0 | 256 |
I'm not sure that I am seeing a pattern in the way that the question is asking which would relate b, n, and a.
I don't have my paper copy handy, but it appears that this is the page in question and that your OP has the code directly. The relationship in your chart is
$$a=b^{8-n}$$
Since it calculates an exponent there wouldn't be an additive relationship. But I will note that what they are asking for means you have not labeled your chart correctly. Note that your chart has the heading $n$ and they are asking for the relationship of $counter$. If you label your chart correctly you will find that $n$ is a constant and what you have labeled as $n$ is actually $counter$ and $a$ is $product$ in which case your relationship is
$$\mathrm{product}=b^{n-\mathrm{counter}}$$