COSC 8 -- Problem Solving with CS

CS 8, Winter 2009

Short Assignment 11: Polynomial Arithmetic using Streams

Instructions

You should print out your solutions to this assignment, and either turn them in at lecture, or leave them in the TA's mailbox at Sudikoff by class time on Mon. Mar. 2, 2009.

Please also e-mail an electronic version of your code to cs8hw@cs.dartmouth.edu, with the subject "CS 8 Short Assignment 11". Please attach your code as one or more enclosures to the message, and do not include it directly in the body of the e-mail message.

You must work alone on this short assignment.


Assignment

Part 1: In class we saw how to construct a stream of triangular numbers using scanl and naturals. Show another way of computing triangular numbers using zipWith and naturals.

Part 2: Solve Exercises 14.6 and 14.7 on pp. 206-207 of SOE. (For 14.7, I never learned the fact that he mentions in first grade!) Note that multiplying a polynomial by x moves every coefficient one later in the list representing the polynomial and introduces a new 0 first coefficient, corresponding to 0 * x^0.

Don't get scared by all of the messy sums on p. 207. You should think about them as entire sums, and what their relationships are to the sums on the left side.

Extra Credit: Write functions to differentiate and integrate polynomials. For integration make the new constant term 0. Given this, you can define the power series for sin and cos as follows, using the relationships between the integrals of sin and cos:

-- Mutually recursive power series for sin and cos

sinSer = integratePoly cosSer
cosSer = subPoly (1:repeat 0) (integratePoly sinSer)

Acknowlegement: The idea for this extra credit came from Doug McIlroy.

Hand in

Hand in a listing of your code and test runs showing that your functions work correctly.