: Use this idea to write a procedure invert-unit-series that computes 1/S for a unit power series S. You will need to use mul-series. To test your procedure, invert the series S1 (from problem 1) and show that you get the series 1 - x. (Convince yourse
时间: 2024-02-14 15:11:03 浏览: 82
lf that this is the correct answer.)
Here is a possible implementation of the invert-unit-series procedure:
```
(define (invert-unit-series S)
(let ((one-series (cons 1 (stream)))
(reciprocal-series (cons 1 (mul-series (stream-map -1 S) reciprocal-series))))
reciprocal-series))
```
The procedure first defines a series of all ones, which is used as the starting point for the reciprocal series. It then uses the mul-series procedure to compute the product of -1 and each coefficient of the input series S, and recursively applies this operation to the reciprocal series until it converges to the desired result.
To test this procedure, we can apply it to the S1 series from problem 1:
```
(define S1 (cons 1 (stream-map -1/2 (add-series (stream-map square integers) (cons 1 (stream))))))
(define S1-inverse (invert-unit-series S1))
(stream-take 10 S1-inverse)
; => (1 -1 1 -1 1 -1 1 -1 1 -1)
```
As expected, the coefficients alternate between 1 and -1, which corresponds to the series 1 - x. Therefore, we can be confident that the invert-unit-series procedure is correct.
阅读全文