SICP Exercise 2.89 term list for dense polynomials

Exercise 2.89.  Define procedures that implement the term-list representation described above as appropriate for dense polynomials.

SOLUTION

The code and tests are here.

Procedure 'adjoin-term'

Structure of term-list:
[OrderOfPolynomial, (list of coefficients)]
Maintaining the order of the polynomial as the first element allows us to avoid repeated expensive 'length' calls on the coefficient list. We assume that term lists are represented as lists of terms, arranged from highest-order to lowest-order term.

Procedures 'first-term' and 'first-term'

Since we are using the term-list representation that is appropriate for dense polynomials (see SICP text), we need to do some extra processing to retrieve both the order and coefficient.

Comments

Popular posts from this blog

SICP Exercise 2.56 differentiation rule

SICP Exercise 1.28 (Miller-Rabin Test)

SICP Exercise 4.18 a alternative strategy for interpreting internal definitions