def _getOne(self): "getter for one" if self._one is None: self._one = FiniteFieldExtensionElement( polynomial.OneVariableDensePolynomial([1], "#1", self.basefield), self) return self._one
def _getZero(self): "getter for zero" if self._zero is None: self._zero = FiniteFieldExtensionElement( polynomial.OneVariableDensePolynomial([], "#1", self.basefield), self) return self._zero
def createElement(self, seed): """ Create an element of the field. """ # FIXME: Undefined variable 'FinitFieldExtensionElement' if isinstance(seed, int): expansion = arith1.expand(seed, card(self.basefield)) return FinitFieldExtensionElement( polynomial.OneVariableDensePolynomial(expansion, "#1", self.basefield), self) elif isinstance(seed, polynomial.OneVariablePolynomial): return FiniteFieldExtensionElement(seed("#1"), self) else: try: # lastly check sequence return FiniteFieldExtensionElement( polynomial.OneVariableDensePolynomial( list(seed), "#1", self.basefield), self) except TypeError: raise TypeError("seed %s is not an appropriate object." % str(seed))
def PolynomialoverGF(fieldrepr, coeffs, symbol="#1"): """ Create OneVariablePolynomial from coeffs with mapping FinitePrimeField(char).createElement. """ if isinstance(fieldrepr, int): field = finitefield.FinitePrimeField(fieldrepr) elif isinstance( fieldrepr, (finitefield.FinitePrimeField, finitefield.FiniteExtendedField)): field = fieldrepr if type(coeffs) is dict: return polynomial.OneVariableSparsePolynomial(coeffs, symbol, field) elif type(coeffs) is list: coefficients = list(map(field.createElement, coeffs)) return polynomial.OneVariableDensePolynomial(coefficients, symbol)