理解 Racket 编程作业中的问题

Understanding the question in a Racket programming assignment

问题是:

A univariate polynomial of order n is given by the following equation.

Pn (x) = anxn + . . . + a2x2 + a1x + a0

Here, ai are the coefficients of the polynomial, and x is its unique variable. You might implement a procedure poly-3 for computing the polynomial of order 3 of x as follows.

(define (poly-3 x a0 a1 a2 a3)

(+ a0 (* a1 x) (* a2 x x) (* a3 x x x)))

In poly-3, the coefficients and the variable are bundled together as arguments; and you would have to specify the coefficients each time you want to compute the same polynomial with different values of x.

Instead, implement the procedure make-poly-3 that generates a procedure that computes the polynomial for an arbitrary x.

(define (make-poly-3 a0 a1 a2 a3)

...)

(define my-poly-3

(make-poly-3 1 2 3 4))

(my-poly-3 2)

Next, write a function sum-poly-3-range which will sum up the results for calling my-poly-3 for the values in a range:

(define (sum-poly-3-range from to)

...)

(sum-poly-3-range 1 50)

我不明白我需要做什么(我不是要编程解决方案,只是步骤)。

我的困惑:

make-poly-3 是一个有四个参数的过程,它将 return 另一个过程。它采用的四个参数的值将是多项式的系数值。

程序 it returns 将采用 单个 参数,这将是 [=14= 的值] 计算多项式的位置。

所以,例如

(define linear (make-poly-3 0 1 0 0))
> (linear 2)
2
> (define squared (make-poly-3 0 0 1 0))
> (squared 2)
4

sum-poly-3-range 函数使用 my-poly-3 的任何值('uses my-poly-3 free' 使用一些行话),并对你给它的范围内的每个整数求值,并计算出结果的总和。

所以,作为一个简单的例子:

> (define my-poly-3 (make-poly-3 1 0 0 0))
> (sum-poly-3-range 1 50)
50

这是因为 (make-poly-3 1 0 0 0) return 是一个多项式函数,其所有参数的计算结果为 1(常数项是唯一的 non-zero 项)。

> (define my-poly-3 (make-poly-3 0 1 0 0))
> (sum-poly-3-range 1 50)
1275

因为这个多项式只是它的参数的平方。