Exercise 3.59: In 2.5.3 we saw how
to implement a polynomial arithmetic system representing polynomials as lists
of terms. In a similar way, we can work with
power series, such as
e
x
=
1
+
x
+
1
2
x
2
+
1
3
⋅
2
x
3
+
1
4
⋅
3
⋅
2
x
4
+
…
,
cos
x
=
1
−
1
2
x
2
+
1
4
⋅
3
⋅
2
x
4
−
…
,
sin
x
=
x
−
1
3
⋅
2
x
3
+
1
5
⋅
4
⋅
3
⋅
2
x
5
−
…
represented as infinite streams. We will represent the series a
0
+
a
1
x
+
a
2
x
2
+
a
3
x
3
+
… as the stream whose
elements are the coefficients a
0, a
1, a
2, a
3, ….
The integral of the series a
0
+
a
1
x
+
a
2
x
2
+
a
3
x
3
+
… is the series
c
+
a
0
x
+
1
2
a
1
x
2
+
1
3
a
2
x
3
+
1
4
a
3
x
4
+
…
,
where c is any constant. Define a procedure integrate-series that
takes as input a stream a
0, a
1, a
2, … representing a power
series and returns the stream a
0, 1
2
a
1, 1
3
a
2, … of
coefficients of the non-constant terms of the integral of the series. (Since
the result has no constant term, it doesn’t represent a power series; when we
use integrate-series, we will cons on the appropriate constant.)
The function x
↦
e
x is its own derivative. This implies that
e
x and the integral of e
x are the same series, except for the
constant term, which is e
0
=
1. Accordingly, we can generate the series
for e
x as
(define exp-series
(cons-stream
1 (integrate-series exp-series)))
Show how to generate the series for sine and cosine, starting from the facts
that the derivative of sine is cosine and the derivative of cosine is the
negative of sine:
(define cosine-series
(cons-stream 1 ⟨??⟩))
(define sine-series
(cons-stream 0 ⟨??⟩))
练习 3.59:在 2.5.3 节中,我们看到了如何将多项式表示为项的表来实现多项式算术系统。类似地,我们可以处理幂级数 (power series),例如 eˣ = 1 + x + (1/2)x² + (1/(3·2))x³ + (1/(4·3·2))x⁴ + …,cos x = 1 − (1/2)x² + (1/(4·3·2))x⁴ − …,sin x = x − (1/(3·2))x³ + (1/(5·4·3·2))x⁵ − …,将其表示为无穷流。我们将级数 a₀ + a₁x + a₂x² + a₃x³ + … 表示为以系数 a₀, a₁, a₂, a₃, … 为元素的流。
级数 a₀ + a₁x + a₂x² + a₃x³ + … 的积分为 c + a₀x + (1/2)a₁x² + (1/3)a₂x³ + (1/4)a₃x⁴ + …,其中 c 为任意常数。定义过程 integrate-series,它以表示幂级数的流 a₀, a₁, a₂, … 为输入,返回该级数积分中非常数项的系数流 a₀, (1/2)a₁, (1/3)a₂, …。(由于结果没有常数项,它不表示幂级数;使用 integrate-series 时,我们会用 cons 加上适当的常数项。)
函数 x ↦ eˣ 是其自身的导数。这意味着 eˣ 与 eˣ 的积分是同一个级数,只是常数项不同——e⁰ = 1。因此,我们可以如下生成 eˣ 的级数:
(define exp-series
(cons-stream
1 (integrate-series exp-series)))
请说明如何从“正弦的导数是余弦,余弦的导数是正弦的负值”这一事实出发,生成正弦和余弦的级数:
(define cosine-series
(cons-stream 1 ⟨??⟩))
(define sine-series
(cons-stream 0 ⟨??⟩))