CS471 Programming Language Structure I Fall 1998

Homework 3: Computing p

A. Write a second-order function (a function that takes one or more functions as an argument) called series_product, in Scheme, that combines a collection of terms in a mathematical series, using multiplication. The function should have four parameters: the upper and lower bounds of the series, lb and ub, a function, term, that produces a value to be combined, and a function, next, that calculates the next number in the range.

For example, if the function was defined as:

(define (series_product lb ub next) ... )

then the value of the expression

(series_product 1 5 square addone)

where square and addone are names of defined functions, gives the value of the product

B. Show how your function can compute the factorial of a given number.

C. Then show how an approximation to p can be computed by giving product the appropriate arguments to compute the formula:

where there is always an equal number of factors in the numerator and denominator.

Due Date:

Friday, November 20th before 5 pm.