當前位置: 首頁>>代碼示例>>Python>>正文


Python Polynomial.zero方法代碼示例

本文整理匯總了Python中polynomial.Polynomial.zero方法的典型用法代碼示例。如果您正苦於以下問題:Python Polynomial.zero方法的具體用法?Python Polynomial.zero怎麽用?Python Polynomial.zero使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在polynomial.Polynomial的用法示例。


在下文中一共展示了Polynomial.zero方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: decode

# 需要導入模塊: from polynomial import Polynomial [as 別名]
# 或者: from polynomial.Polynomial import zero [as 別名]
    def decode(self, poly):
        poly = self.trim_zeros(poly) # cargar polinomio real
        assert(poly.degree < self.n)

        sx = []
        for i in range(1, self.nk.degree + 1): # calcular sindromes
            sx.insert(0, poly.eval(self.field[i])) # evaluar en a^i, i = 1..2t
        if all([si.is_zero() for si in sx]): # todos los sindromes son cero
            coeff = poly.coefficients[:-self.nk.degree] # mensaje en los k coeficientes de x^n-1 .. x^n-k
            decode =  P(coeff, self.field) # polinomio asociado
            assert(decode.degree < self.k)
            return decode

        fx = self.nk # x^2t
        gx = P(sx, self.field) # S(x) = s1 + s2 x + .. + s2t x^2t-1
        ak, bk, rk = P.euclides(self.field, fx, gx, lambda rk, r0: rk.degree < self.t and r0.degree >= self.t)
        assert(rk.degree < self.t)
        assert(bk.degree <= self.t)
        assert(rk == ak * fx + bk * gx) # from euclides
        b0 = bk.eval(self.field.zero())
        ib0 = self.field.inverse(b0)
        assert(self.field.product(b0, ib0) == self.field.unity())
        sigma = bk.sproduct(ib0) # bk(0)^-1 bk
        omega = rk.sproduct(ib0) # bk(0)^-1 rk
        assert(sigma.degree <= self.t) # capacidad de corrección
        assert(omega.degree < self.t)

        # ver raices...
        roots = [] # tendrá las posiciones de los errores
        for i in range(self.n):
            tmp = sigma.eval(self.field[i]) # raíces de sigma
            if tmp.is_zero():
                roots.append((self.field[i], -i % (len(self.field) - 1))) # potencia a^i que fue raíz => inverso es la posición

        # nanai
        if roots == []:
            raise ValueError()

        # Forney algorithm
        exp = sigma.degree
        coeff = []
        for i in sigma.coefficients: # derivada
            coeff.append(self.field.oproduct(i, exp))
            exp -= 1
        coeff = coeff[:-1] # eliminar el termino cte

        fst = 0 # eliminar ceros anteriores
        for i in range(len(coeff)):
            if coeff[i] == 0:
                fst += 1
            else:
                break
        sigmap = P(coeff[fst:], self.field) # sigma'
        assert(sigmap.degree < sigma.degree)

        # evaluate the error values:
        error = P.zero(self.field)
        for j in roots: # (error, position)
            yj = -self.field.division(omega.eval(j[0]), sigmap.eval(j[0])) #forney
            ej = P([yj] + [self.field.zero()]*j[1], self.field) # error
            error = error + ej # polinomio de errores
        poly = poly + error # recuperar original
        # return codeword
        coeff = poly.coefficients[:-self.nk.degree] # mensaje en los k coeficientes de x^n-1 .. x^n-k
        decode =  P(coeff, self.field) # polinomio asociado
        assert(decode.degree < self.k)

        return decode
開發者ID:Dr-Tredok,項目名稱:CodeTheory-2016-2,代碼行數:70,代碼來源:rs.py


注:本文中的polynomial.Polynomial.zero方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。