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

Exercise 2.96 · 习题

Exercise 2.96:

Implement the procedure pseudoremainder-terms, which is just like
remainder-terms except that it multiplies the dividend by the
integerizing factor described above before calling div-terms. Modify
gcd-terms to use pseudoremainder-terms, and verify that
greatest-common-divisor now produces an answer with integer coefficients
on the example in Exercise 2.95.

The GCD now has integer coefficients, but they are larger than those
of P
1. Modify gcd-terms so that it removes common factors from the
coefficients of the answer by dividing all the coefficients by their (integer)
greatest common divisor.

Thus, here is how to reduce a rational function to lowest terms:

Compute the GCD of the numerator and denominator, using the version
of gcd-terms from Exercise 2.96.

When you obtain the GCD, multiply both numerator and denominator by
the same integerizing factor before dividing through by the GCD, so
that division by the GCD will not introduce any noninteger
coefficients. As the factor you can use the leading coefficient of the
GCD raised to the power 1
+

O
1

O
2, where O
2 is the
order of the GCD and O
1 is the maximum of the orders of the
numerator and denominator. This will ensure that dividing the numerator and
denominator by the GCD will not introduce any fractions.

The result of this operation will be a numerator and denominator with integer

coefficients. The coefficients will normally be very large because of all of

the integerizing factors, so the last step is to remove the redundant factors

by computing the (integer) greatest common divisor of all the coefficients of

the numerator and the denominator and dividing through by this factor.

练习 2.96:

实现过程 pseudoremainder-terms,它与 remainder-terms 类似,区别在于在调用 div-terms 之前先将被除式乘以上面描述的整数化因子。修改 gcd-terms 以使用 pseudoremainder-terms,并验证对练习 2.95 中的例子,greatest-common-divisor 现在给出了一个具有整数系数的答案。

现在 GCD 具有整数系数,但这些系数比 P₁ 的系数要大。修改 gcd-terms,使其通过将所有系数除以它们的(整数)最大公因子来去除答案系数中的公因子。

下面是将有理函数化为最简形式的方法:

用练习 2.96 中的 gcd-terms 版本计算分子和分母的 GCD。

得到 GCD 后,在除以 GCD 之前,将分子和分母同乘以相同的整数化因子,从而保证用 GCD 除不会引入非整数系数。该因子可取 GCD 的首项系数的 1 + O₁ − O₂ 次方,其中 O₂ 是 GCD 的阶数,O₁ 是分子和分母阶数的最大值。这将确保将分子和分母除以 GCD 不会引入任何分数。

该操作的结果将是具有整数系数的分子和分母。由于所有整数化因子,系数通常会非常大,因此最后一步是计算分子和分母所有系数的(整数)最大公因子,并将各系数除以该因子,以去除多余的因子。