New version page

NMSU CS 471 - Assignment6

Documents in this Course
Load more
Upgrade to remove ads
Upgrade to remove ads
Unformatted text preview:

Assignment 6Computing ( using functionalsGoalsProcedureExample useGradingDue DateNotesAssignment 6 Computing π using functionals Goals To understand the principles of functions as first-class values. Procedure A. Write a functional (a function that takes one or more functions as an argument) called series_product, in Scheme, or ML, 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, the function could be defined by: Scheme: (define (series_product lb ub term next) ... ) ML: fun series_product(lb, ub, term, next) = ... Example use With this function, the value of the expression Scheme: (series_product 1 5 square addone) ML: series_product(1, 5, square, addone) where square and addone are names of defined functions, gives the value of the product ∏⋅⋅⋅⋅=5122516941nB. Show how your function can compute the factorial of a given number. C. Then show how an approximation to π can be computed by giving series_product the appropriate arguments to compute the formula: KK7755338664424⋅⋅⋅⋅⋅⋅⋅⋅⋅⋅=πwhere there is always an equal number of factors in the numerator and denominator.Grading Points will not be taken off for bad syntax in either language, but will be taken off if the recursive strategy is not clear. It will be very helpful to explain your strategy rather than simply writing out the code. Total 30 points. Partial credit will be available for answers that are along the right lines. Due Date December 9th before 5:00pm. Notes There is no need to run these functions through a Scheme or ML interpreter to get full points. However, if you wish, a Scheme interpreter is available by typing: “~rth/public/Scheme/scm/scheme”, without the quotes, at the command prompt. The complete definition of the standard version of the language is on the web site at: A file of Scheme definitions may be loaded by typing (load "filename") at the prompt. Exit the interpreter by typing (quit), at the prompt. The Standard ML interpreter is avilable on Linux machines by typing “sml” without the quotes at the command prompt. A file containing ML function definitions may be loaded by use "file". ML may be exited with control-D. After that you are on your

View Full Document
Download Assignment6
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...

Join to view Assignment6 and access 3M+ class-specific study document.

We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Assignment6 2 2 and access 3M+ class-specific study document.


By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?