Chapter 3: Iteration and Invariants
Chapter 3: Iteration and Invariants
Two Ways of Computing Factorial
Recursive vs. Iterative
Accumulating Partial Products
Writing a Procedure for this Iterative Process
Writing a Procedure for Actual Iterative Factorial
Comparing the Recursive and Iterative Processes
Another Procedure for Making Paper Chains
Summary
Exercise 3.1, p. 50
Exercise 3.1
Tracing num-times-range
Section 3.2: Using Invariants
Iteration and Invariants
Iteration and Verification
Example: Fermat Numbers
Computing Fermat Numbers
Writing repeatedly-square
Another Fact
repeatedly-square Again
Fermat Numbers Again
Number of Digits in Fermat Numbers
Procedure
repeatedly-double
Internal Definitions
Perfect Numbers
Using Iteration to Sum Up Divisors
Procedure
sum-from-plus
: Base Case
Procedure
sum-from-plus
: Returned Value
Procedure
sum-from-plus
: Recursive Call
The
divides?
Predicate
Using
perfect?
to Search for Perfect Numbers
Automating the Search
The
let
Expression
The Search for Perfect Numbers
Approximation Through Iterative Improvement
Approximating Square Root: Newton's Method
A Procedure for Approximation Through Iterative Improvement
The Golden Ratio
Approximating the Golden Ratio
Logical Expressions
Logical Expression Details
Logical Expression Examples
Example
Using and and or for Control