A finite continued fraction can unfold or accumulate.
The same numerator and denominator procedures can drive a recursive process from the top or an iterative process from the final term.
How does evaluation order change the process without changing the finite fraction?
- Express a finite continued fraction with numerator and denominator procedures
- Read top-down recursive expansion as postponed division
- Read bottom-up iteration as a complete accumulated result
- Compare process shape while keeping the depth and terms fixed
The recursive version begins at term 1 but cannot finish its division until the rest of the fraction returns. Each call leaves one denominator addition and division waiting while recur moves toward k.
The iterative version begins at term k with 0.0 as the already-computed tail. Each call replaces result with one complete fraction layer and moves toward term 1. Both examples use ten numerators and denominators equal to 1.0, so they return the same finite approximation to the reciprocal golden ratio.
(begin
(define (cont-frac numerator denominator k)
(define (recur i)
(if (> i k)
0.0
(/ (numerator i)
(+ (denominator i) (recur (+ i 1))))))
(recur 1))
(cont-frac (lambda (i) 1.0)
(lambda (i) 1.0)
10))- Output
- —
- Value
- —
- Diagnostic
- —
Both programs return 0.6179775280898876 for ten terms.
In the recursive run, follow recur toward k before the divisions return. In the iterative run, watch result become one complete suffix at each call while i decreases. These traces describe only this fixed depth and terms.
Change the program before you read the hint.
Change k from 10 to 5 in both programs. Predict whether they still agree and record the new finite value.
Show one hint
Keep numerator and denominator unchanged. Only the number of fraction layers becomes smaller.