Recursive: Iterative:
There are two values changing here (A and B), not just one as in factorial (n).

So the process isn't exactly factorial.

But we are always computing the product of A and B!, so call the procedure factorial-product:

Recall the recursive procedure for making paper chains (see The Recursive Version in the menu).

Here is an Iterative Version:

Note that the subproblem (linking n-1 links onto a chain of length 1) is not a smaller version of the main problem (making a chain of length n).

Suppose you are asked to make a paper chain of length 4.

According to the process description, Step 1a directs to create a chain of length 1:

Step 2a directs to add 3 links onto the chain.

k = 3. According to the process description, Step 1b directs to check if k = 0. False.

Step 2b directs to add one link to the current chain:

Then add two links to the chain.

k = 2. According to the process description, Step 1b directs to check if k = 0. False.

Step 2b directs to add one link to the current chain:

Then add one link to the chain.

k = 1. According to the process description, Step 1b directs to check if k = 0. False.

Step 2b directs to add one link to the current chain:

Now add zero links to the chain. k = 0. Step 1b stops the process.

To prove that factorial-product maintains the invariant, use mathematical induction:
Example:

Find √90 (= 9.486832981)
Solve x2 = 90 or f(x) = x2 - 90
We can use a similar approach to approximate square root using Newton's method.
Recall that we improve a solution xn by computing xn+1 = xn - f(xn)/f'(xn).

We will decide if an approximation is good enough by the number of iterations we have tried.

So we will need to provide a loop-limit that the good-enough? predicate will use:

When we try approximations we will need to keep track of the iterations.

So we add the parameter iterations to find-approximation-from and we increment it each time through:

To approximate square root of n, we also provide a starting-point and loop-limit:

> (sqrt 90)
9.486832980505138

> (approximate-square-root 90.0 9 0)
9
There are three Scheme language constructs that act as logical operators.
Logical operators work on and return the truth values true and false. Summary:
Recall that in Scheme the truth value false is represented as #f.

For the purposes of not, or, and and, the truth value true is represented as any non-#f value (including #t).

You can use and and or as short-hand for certain usages of if: