首页
学习
活动
专区
圈层
工具
发布

云算法
EN

Stack Overflow用户
提问于 2018-07-09 17:18:05
回答 1查看 675关注 0票数 5

我想尝试用云算法实现多项式的无平方分解.来自维基百科(f是多项式):

代码语言:javascript
复制
a0 = gcd(f, f'); b1 = f/a0; c1 = f'/a0; d1 = c1 - b1'; i = 1
repeat
ai = gcd(bi, di); bi+1 = bi/ai; ci+1 = di/ai; i = i + 1; di = ci - bi'
until b = 1

然而,我不确定第二步。我想用它作为整数系数的多项式(不是必要的单元或本原)。用整数实现除法b1 = f/a0是可能的吗?

我找到了合成师的代码

代码语言:javascript
复制
def extended_synthetic_division(dividend, divisor):
    '''Fast polynomial division by using Extended Synthetic Division. Also works with non-monic polynomials.'''
    # dividend and divisor are both polynomials, which are here simply lists of coefficients. Eg: x^2 + 3x + 5 will be represented as [1, 3, 5]

    out = list(dividend) # Copy the dividend
    normalizer = divisor[0]
    for i in xrange(len(dividend)-(len(divisor)-1)):
        out[i] /= normalizer # for general polynomial division (when polynomials are non-monic),
                             # we need to normalize by dividing the coefficient with the divisor's first coefficient
        coef = out[i]
        if coef != 0: # useless to multiply if coef is 0
            for j in xrange(1, len(divisor)): # in synthetic division, we always skip the first coefficient of the divisor,
                                              # because it is only used to normalize the dividend coefficients
                out[i + j] += -divisor[j] * coef

    # The resulting out contains both the quotient and the remainder, the remainder being the size of the divisor (the remainder
    # has necessarily the same degree as the divisor since it is what we couldn't divide from the dividend), so we compute the index
    # where this separation is, and return the quotient and remainder.
    separator = -(len(divisor)-1)
    return out[:separator], out[separator:] # return quotient, remainder.

对我来说问题是out[i] /= normalizer。它是否总是与云的b1 = f/a0的整数(地板)部门一起工作?是否总是可以对f/gcd(f, f')进行分割?out[separator:] (余数)总是为零吗?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-07-15 23:12:46

p/GCD(p, p')中的除法将始终工作(即”精确“,在Z中没有余数)这一事实遵循于GCD的定义。对于任何多项式pq,它们的GCD(p,q)都精确地将pq分开。这就是为什么它被称为GCD,即最伟大

最大公共除数 of pq是一个多项式d,它将pq除以,使得pq的每个公共除数也除以d

在更专业的https://math.stackexchange.com/上问这些纯粹的数学问题更有意义。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51250851

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档