本文整理汇总了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