灯下 登录
计算机科学 / SICP / 2.5.3 Example: Symbolic Algebra

Exercise 2.92 · 习题

Exercise 2.92: By imposing an ordering on
variables, extend the polynomial package so that addition and multiplication of
polynomials works for polynomials in different variables. (This is not easy!)

Extended exercise: Rational functions

We can extend our generic arithmetic system to include
rational functions.
These are “fractions” whose numerator and denominator are
polynomials, such as
x
+
1

x
3


1

.
The system should be able to add, subtract, multiply, and divide rational
functions, and to perform such computations as
x
+
1

x
3


1

+

x

x
2


1

=

x
3

+
2

x
2

+
3
x
+
1

x
4

+

x
3


x

1

.
(Here the sum has been simplified by removing common factors. Ordinary “cross
multiplication” would have produced a fourth-degree polynomial over a
fifth-degree polynomial.)

If we modify our rational-arithmetic package so that it uses generic

operations, then it will do what we want, except for the problem of reducing

fractions to lowest terms.

练习 2.92:通过对变量施加排序,扩展多项式包,使多项式的加法和乘法能够适用于不同变量的多项式。(这并不容易!)

扩展练习:有理函数

我们可以扩展通用算术系统,纳入有理函数 (rational functions)。有理函数是以多项式为分子和分母的"分数",例如

(x + 1) / (x³ − 1)。

系统应能对有理函数进行加、减、乘、除,并能完成如下计算:

(x + 1) / (x³ − 1) + x / (x² − 1) = (x³ + 2x² + 3x + 1) / (x⁴ + x³ − x − 1)。

(这里的和式已通过约去公因子化简。普通的"交叉相乘"会得到一个五次多项式作分母的四次多项式。)

如果我们修改有理算术包使其使用通用操作,那么除了将分数化为最简形式这一问题之外,其他一切都能如期运作。