Comp210
Due: 97.Mar.18 (Wed.) in class
As usual, you should include contracts, test cases, etc.
Given the function f, one way to compute an approximate value for the integral of f from a to b is to:
The choice of sub-intervals has a significant effect on the accuracy of the approximation. The simplest choice would be to subdivide [a,b] into n equal sub-intervals. Unfortunately, this approach requires a large number of sub-intervals for parts of the function that have sharp peaks and valleys, which is wasteful for the parts of the function that are smooth. Plus, it's not clear how large large should be, for different functions.
For this homework, we will use a better method: subdivide [a,b] into intervals in an adaptive manner until the difference between trapezoid area for the interval [xi ,xi+1] and the sum of the trapezoid areas for [xi ,xmid] and [xmid , xi+1] -- where xmid is the midpoint of [xi ,xi+1] -- is less than (xi+1 - xi)*epsilon. The constant epsilon is called the ``unit error bound''; you can see that the overall error of the final answer will hopefully1 not be larger than epsilon(b-a).
Your assignment is to to write a Scheme function integrate that takes four parameters:
(define sqrt-plus-one (compose add1 sqrt)) (sqrt-plus-one 4) = 3
Hint: The password object should be a function created by set-passwd. You may use local if you wish (although it is not necessary). Your representation should be secure in the sense that there is no way that Scheme code can extract a password from a password object (beyond exhaustively testing all possible passwords).