Edit this page Backlinks This page is read only. You can view the source, but not change it. Ask your administrator if you think this is wrong. ====== Lazy evaluation ====== 1. Consider the following recurrence scheme described informally below. Use it to build the sequence $math[1, 2, \ldots, n!, ...] <code> 4 4*5 4*5*6 ... 3 3 3 3 ---------------------- 3 3*4 3*4*5 3*4*5*6 ... </code> 2. Define the sequence $math[1, \frac{1}{2}, \ldots, \frac{1}{k!}, \ldots ] 3. Write a function which takes a sequence $math[(a_n)_{n\geq 0}] and computes the sequence $math[(s_n)_{n\geq 0}] where $math[s_k = \sum_{k\geq 0} a_k]. Use a strategy similar to that from exercise 1. 4. Write the stream of approximations of $math[e] [[https://en.wikipedia.org/wiki/E_(mathematical_constant) | details ]]. 5. Write a function which takes a value $math[d], a sequence of approximations $math[(a_n)_{n\geq 0}] and returns that value $math[a_k] from the sequence which satisfies the condition $math[\mid a_k - a_{k+1}\mid \leq d] 6. Write a function which takes an $math[f], a value $math[a_0] and computes the sequence $math[a_0, f(a_0), f(f(a_0)), \ldots] 7. The sequence $math[(a_n)_{n\geq 0}] defined as $math[a_{k+1} = (a_k + \frac{n}{a_k})/2], will converge to $math[\sqrt{n}] as $math[k] approaches infinity. Use it to write a function which approximates $math[\sqrt{n}] within 3 decimals. 8. The diagram below illustrates the approximation of an integral of a continuous function $math[f] between two points $math[a] and $math[b]. The simplest approximation is the area of the rectangle defined by points $math[a] and $math[b] on the $math[Ox] axis, and points $math[f(a)] and $math[f(b)]. To determine a better approximation, the interval $math[ [a,b] ] is broken in half and we add up the areas of the rectangles: - $math[a,m,f(a),f(m)] and - $math[m,b,f(m),f(b)] <code> Oy ^ f m|. . . . . . . -------- | / ' \ | / ' \ f f b|. . . . . . /. .'. . . . .------- | ----- ' ' f a|. . . / ' ' | / ' ' | / ' ' ' | / ' ' ' ------------------------------> Ox a m b </code> The process can be repeated by recursively dividing up intervals. Write the a function ''integral'' which computes the sequence of approximations of $math[\int_a^b f(x)]. <code haskell> integral :: (Float -> Float) -> Float -> Float -> [Float] </code> 9. It is likely that your implementation will recompute (unnecessarily) the values $math[f(a), m, f(m), f(b)] in recursive steps. Write an alternative implementation which avoids this.