跳到主要内容

東京大学 情報理工学系研究科 電子情報学専攻 2014年8月実施 専門 第3問

Author

adj-matrix

Description

Let f=a0+a1x++amxmf = a_0 + a_1 x + \dots + a_m x^m and g=b0+b1x++bnxng = b_0 + b_1 x + \dots + b_n x^n be polynomials of xx (aia_i and bib_i are real. am0a_m \neq 0 and bn0b_n \neq 0). We represent the leading terms of the polynomials ff and gg by LT(f)=amxm\text{LT}(f) = a_m x^m and LT(g)=bnxn\text{LT}(g) = b_n x^n, and their degrees by deg(f)=m\deg(f) = m and deg(g)=n\deg(g) = n. The polynomial division, where ff is divided by a non-zero polynomial gg, is given by

f=qg+r.f = qg + r.

Here quotient qq and remainder rr are polynomials of xx satisfying r=0r = 0 or deg(r)<deg(g)\deg(r) < \deg(g). In this case, we represent r=remainder(f,g)r = \text{remainder}(f, g) and q=quotient(f,g)q = \text{quotient}(f, g).

(1) Calculate quotient(f,g)\text{quotient}(f, g) and remainder(f,g)\text{remainder}(f, g) for f=x2+7x+3f = x^2 + 7x + 3 and g=x+1g = x + 1.

(2) Complete a pseudocode of the polynomial division algorithm by filling (a) with appropriate expressions. Note that the four arithmetic operations for monomial terms (expressions that contain only one term, e.g. 7x37x^3 or 5x10-5x^{10}) and addition/subtraction operations for polynomials can be used as they are.

Input: f, g
Output: q, r
q = 0, r = f
while (r ≠ 0 and deg(g) ≤ deg(r)) {
q = q + LT(r)/LT(g)
r = _____ (a) _____
}

(3) Prove that the algorithm introduced in (2) always terminates.

(4) The greatest common divisor (GCD) for polynomials ff and gg is a polynomial hh which satisfies the following conditions.

  • hh divides ff and gg
  • if a polynomial pp divides ff and gg, then pp also divides hh

hh satisfying these conditions is represented by h=GCD(f,g)h = \text{GCD}(f, g). GCD(f,g)\text{GCD}(f, g) is unique up to multiplication by nonzero numbers. Given f=qg+rf = qg + r, by using the following relations GCD(f,g)=GCD(fqg,g)\text{GCD}(f, g) = \text{GCD}(f - qg, g) and GCD(f,0)=f\text{GCD}(f, 0) = f, GCD(f,g)\text{GCD}(f, g) can be calculated by the following procedure (without loss of generality, we assume deg(f)deg(g)\deg(f) \ge \deg(g)). Fill (b) and (c) with appropriate expressions.

Input: f, g
Output: h
h = f
s = g
while (s ≠ 0) {
rem = remainder(h, s)
h = ______ (b) ______
s = ______ (c) ______
}

(5) Given arbitrary polynomials ff and gg (deg(f)deg(g)\deg(f) \ge \deg(g)), calculate an upper bound of the number of times that a function remainder is called inside the while-loop during the calculation of GCD(f,g)\text{GCD}(f, g). Also provide a reason for the obtained result.

题目描述

f=a0+a1x++amxm,g=b0+b1x++bnxnf=a_0+a_1x+\dots+a_mx^m,\qquad g=b_0+b_1x+\dots+b_nx^n

为关于 xx 的多项式,其中 ai,bia_i,b_i 为实数,am0a_m\ne0bn0b_n\ne0。定义首项 LT(f)=amxm\operatorname{LT}(f)=a_mx^mLT(g)=bnxn\operatorname{LT}(g)=b_nx^n,次数 deg(f)=m\deg(f)=mdeg(g)=n\deg(g)=n。用非零多项式 ggff 时,

f=qg+r,f=qg+r,

其中商 qq、余式 rr 均为多项式,且 r=0r=0deg(r)<deg(g)\deg(r)<\deg(g);记 r=remainder(f,g)r=\operatorname{remainder}(f,g)q=quotient(f,g)q=\operatorname{quotient}(f,g)

(1) 当 f=x2+7x+3f=x^2+7x+3g=x+1g=x+1 时,计算 quotient(f,g)\operatorname{quotient}(f,g)remainder(f,g)\operatorname{remainder}(f,g)

(2) 在下列多项式除法伪代码中,用适当表达式填充 (a)。可以直接使用单项式(如 7x37x^35x10-5x^{10})的四则运算以及多项式的加减运算。

Input: f, g
Output: q, r
q = 0, r = f
while (r ≠ 0 and deg(g) ≤ deg(r)) {
q = q + LT(r)/LT(g)
r = _____ (a) _____
}

(3) 证明 (2) 的算法一定终止。

(4) 多项式 f,gf,g 的最大公因式是满足下列条件的多项式 hh

  • hh 同时整除 ffgg
  • 若多项式 pp 同时整除 ffgg,则 pp 也整除 hh

h=GCD(f,g)h=\operatorname{GCD}(f,g);它在相差非零常数倍的意义下唯一。利用

GCD(f,g)=GCD(fqg,g),GCD(f,0)=f\operatorname{GCD}(f,g)=\operatorname{GCD}(f-qg,g),\qquad \operatorname{GCD}(f,0)=f

可按下列过程计算最大公因式,并不失一般性地假设 deg(f)deg(g)\deg(f)\ge\deg(g)。填写 (b)、(c)。

Input: f, g
Output: h
h = f
s = g
while (s ≠ 0) {
rem = remainder(h, s)
h = ______ (b) ______
s = ______ (c) ______
}

(5) 对任意满足 deg(f)deg(g)\deg(f)\ge\deg(g) 的多项式 f,gf,g,给出计算 GCD(f,g)\operatorname{GCD}(f,g) 时,while 循环内调用 remainder 次数的上界,并说明理由。

考点

  • 多项式长除法:要求利用首项相消补全余式更新式,并以余式次数严格下降证明终止。
  • 多项式欧几里得算法:要求依据最大公因式不变性补全迭代变量,并用次数序列估计余式调用次数上界。

Kai

(1)

f=x2+7x+3f = x^2 + 7x + 3 and g=x+1g = x + 1.

Since f=(x+6)g3f = (x+6)g - 3.

Therefore q=x+6r=3\quad q = x + 6 \quad r = -3.

(2)

  • (a): r - (LT(r) / LT(g)) * g

(3)

Let rkr_k be the remainder at iteration kk. Since

rk+1=rkLT(rk)LT(gk)gkr_{k+1} = r_k - \frac{\text{LT}(r_k)}{\text{LT}(g_k)} g_k

Let deg(rk)=m,deg(gk)=n\deg(r_k) = m, \deg(g_k) = n, then

deg(rk+1)=deg(rkLT(rk)LT(gk)gk)=deg(i=0mrixirmxmgnxni=0ngixi)\deg(r_{k+1}) = \deg\left(r_k - \frac{\text{LT}(r_k)}{\text{LT}(g_k)} g_k\right) = \deg\left( \sum_{i=0}^m r_i x^i - \frac{r_m x^m}{g_n x^n} \sum_{i=0}^n g_i x^i \right)

i.e.,

deg(rk+1)=deg(i=0m1rixi+rmxmrmxmgnxn(i=0n1gixi+gnxn))=deg(i=0m1rixi+rmxmrmgnxmni=0n1gixirmxmn+n)=deg(i=0m1rixirmgnxmni=0n1gixi)\begin{aligned} \deg(r_{k+1}) &= \deg\left( \sum_{i=0}^{m-1} r_i x^i + r_m x^m - \frac{r_m x^m}{g_n x^n} \left( \sum_{i=0}^{n-1} g_i x^i + g_n x^n \right) \right) \\ &= \deg\left( \sum_{i=0}^{m-1} r_i x^i + r_m x^m - \frac{r_m}{g_n} x^{m-n} \sum_{i=0}^{n-1} g_i x^i - r_m x^{m-n+n} \right) \\ &= \deg\left( \sum_{i=0}^{m-1} r_i x^i - \frac{r_m}{g_n} x^{m-n} \sum_{i=0}^{n-1} g_i x^i \right) \end{aligned}

Since

deg(i=0m1rixi)m1<deg(rk)\deg\left( \sum_{i=0}^{m-1} r_i x^i \right) \le m - 1 < \deg(r_k)
deg(rmgnxmni=0n1gixi)=m1<deg(rk)\deg\left( \frac{r_m}{g_n} x^{m-n} \sum_{i=0}^{n-1} g_i x^i \right) = m - 1 < \deg(r_k)

Therefore

deg(rk+1)<deg(rk)\deg(r_{k+1}) < \deg(r_k)

Since if deg(r)<deg(g)\deg(r) < \deg(g) the loop stops and deg(g)\deg(g) will not change. Therefore the algorithm always terminates.

(4)

  • (b): s
  • (c): rem

(5)

According to (3),

deg(rk+1)=deg(i=0m1rixirmgnxmni=0n1gixi)=deg(i=0m2rixirmgnxmni=0n2gixi+(rm1rmgngn1)xm1)\begin{aligned} \deg(r_{k+1}) &= \deg\left( \sum_{i=0}^{m-1} r_i x^i - \frac{r_m}{g_n} x^{m-n} \sum_{i=0}^{n-1} g_i x^i \right) \\ &= \deg\left( \sum_{i=0}^{m-2} r_i x^i - \frac{r_m}{g_n} x^{m-n} \sum_{i=0}^{n-2} g_i x^i + \left(r_{m-1} - \frac{r_m}{g_n} g_{n-1}\right) x^{m-1} \right) \end{aligned}

In GCD, snext=remainder(h,s)\quad s_{next} = \text{remainder}(h, s).

According to the analysis of (3), we know deg(rem)<deg(s)\deg(rem) < \deg(s) and deg(sk+1)<deg(sk)\deg(s_{k+1}) < \deg(s_k).

To find the worst case, we need let deg(sk+1)=deg(sk)1\deg(s_{k+1}) = \deg(s_k) - 1.

In this case, the degree of ss follows the sequence: n,n1,n2,,1,0n, n-1, n-2, \dots, 1, 0, where n=deg(g)n = \deg(g).

The total number of steps is the length of this sequence plus the final step: deg(g)+1\deg(g) + 1.