(* ** Course: Concepts of Programming Languages (BU CAS CS 320) ** Semester: Summer I, 2010 ** Instructor: Hongwei Xi (hwxi AT cs DOT bu DOT edu) *) // // Assignment Five (Due: Wednesday, June 23, 2010) // (* ****** ****** *) // Assgn5Ex1: 10 points // Assgn5Ex2: 10 points // Assgn5Ex3: 20 points // Assgn5Ex4: 20 points (* ****** ****** *) (* // Assgn5Ex1: 10 points // The following is a well-known series: // // ln 2 = 1 - 1/2 + 1/3 - 1/4 + ... // // Please implement a stream consisting of all the partial sums of this // series. Then compute an accurate approximation to ln2 by using Euler's // transform. *) val theAssgn5Ex1Stream : stream double val ln2 : double (* ****** ****** *) (* // Assgn5Ex2: 10 points // For each $i\geq 1$, we use $P_i$ for the $i^{\it th}$ prime number. For // instance, $P_1$ is $2$, $P_2$ is $3$ and $P_3$ is $5$. Please implement a // stream consisting of all the sums of the form // $\Sigma_{i=1}^{n}\frac{1}{P_i}$ for $n\geq 1$. *) val theAssgn5Ex2Stream : stream double (* ****** ****** *) (* // Assgn5Ex3: 20 points // A natural number $n$ is a Ramanujan number if there exist two distinct // pairs of natural numbers $(i_1,j_1)$ and $(i_2,j_2)$ such that // $n=i_1^3+j_1^3=i_2^3+j_2^3$. For instance, $1729$ is a Ramanujan number as // $1729=1^3+12^3=9^3+10^3$. Please construct a stream of {\em all} Ramanujan // numbers and then use it to find the first twenty Ramanujan numbers. *) val theRamanujanStream: stream int val theFirstTwentyRamanujanNumbers : list0 int (* ****** ****** *) (* // Assgn5Ex4: 20 points // Please write a function that extracts out the (first) longest line in a given file. // The implementation should be stream-based. *) fun longest_line_get (inp: FILEref): string (* ****** ****** *) (* end of [assignment5.sats] *)