Ticket #9054: trac_9054-part7.patch

File trac_9054-part7.patch, 7.5 KB (added by was, 12 years ago)

polynomial factorization!

• sage/rings/function_field/function_field.py

```# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1275000774 25200
# Node ID 11bc1c46e91ccbbfc86b09685a8fe0d7ef1a8d4e
trac 9054 -- part 7 -- univ polynomial factoring over rational function fields

diff -r e07f7bffaadc -r 11bc1c46e91c sage/rings/function_field/function_field.py```
 a sage: isinstance(K, sage.rings.function_field.function_field.FunctionField) True """ def characteristic(self): """ Return the characteristic of this function field. EXAMPLES:: sage: R. = FunctionField(QQ) sage: R.characteristic() 0 sage: R. = FunctionField(GF(7)) sage: R.characteristic() 7 """ return self.constant_field().characteristic() def extension(self, f, names=None): """ Create an extension L = K[y]/(f(y)) of a function field, if isinstance(R, FunctionFieldOrder) and R.fraction_field() == self: return True return False def _factor_univariate_polynomial(self, f): raise NotImplementedError class FunctionField_polymod(FunctionField): """ return function_field_element.FunctionFieldElement_rational(self, self._field(x.element())) return function_field_element.FunctionFieldElement_rational(self, self._field(x)) # nonoptimized def _to_bivariate_polynomial(self, f): """ Convert f from a univariate polynomial over the rational function field into a bivariate polynomial and a denominator. INPUT: - f -- a univariate polynomial over self. OUTPUT: - 2-variate polynomial, denominator EXAMPLES:: sage: R. = FunctionField(GF(7)) sage: S. = R[] sage: f = (1/t)*(X^4 - 1/t^2)*(X^3 - t^3) sage: R._to_bivariate_polynomial(f) (x^7*t^2 - x^4*t^5 - x^3 + t^3, t^3) """ v = f.list() from sage.rings.arith import LCM denom = LCM([a.denominator() for a in v]) S = denom.parent() x,t = S.base_ring()['x,t'].gens() phi = S.hom([t]) return sum([phi((denom * v[i]).numerator()) * x**i for i in range(len(v))]), denom def _factor_univariate_polynomial(self, f, proof=True): """ Factor the univariate polynomial f over self. EXAMPLES:: We do a factorization over the function field over the rationals:: sage: R. = FunctionField(QQ) sage: S. = R[] sage: f = (1/t)*(X^4 - 1/t^2)*(X^3 - t^3) sage: f.factor()             # indirect doctest (1/t) * (X - t) * (X^2 - 1/t) * (X^2 + 1/t) * (X^2 + t*X + t^2) sage: f.factor().prod() == f True You must pass in proof=False over finite fields, due to Singular's factoring algorithm being incomplete:: sage: R. = FunctionField(GF(7)) sage: S. = R[] sage: f = (1/t)*(X^4 - 1/t^2)*(X^3 - t^3) sage: f.factor() Traceback (most recent call last): ... NotImplementedError: proof = True factorization not implemented.  Call factor with proof=False. sage: f.factor(proof=False) (1/t) * (X + 3*t) * (X + 5*t) * (X + 6*t) * (X^2 + 1/t) * (X^2 + 6/t) sage: f.factor(proof=False).prod() == f True Factoring over a function field over a non-prime finite field:: sage: k. = GF(9) sage: R. = FunctionField(k) sage: S. = R[] sage: f = (1/t)*(X^3 - a*t^3) sage: f.factor(proof=False) (1/t) * (X + (a + 2)*t)^3 sage: f.factor(proof=False).prod() == f True """ F, d = self._to_bivariate_polynomial(f) fac = F.factor(proof=proof) x = f.parent().gen() t = f.parent().base_ring().gen() phi = F.parent().hom([x, t]) v = [(phi(P),e) for P, e in fac] unit = phi(fac.unit())/d w = [] for a, e in v: c = a.leading_coefficient() a = a/c unit *= (c**e) w.append((a,e)) from sage.structure.factorization import Factorization return Factorization(w, unit=unit) def polynomial_ring(self): """ Return polynomial ring underlying this function field.
• sage/rings/function_field/function_field_element.pyx

`diff -r e07f7bffaadc -r 11bc1c46e91c sage/rings/function_field/function_field_element.pyx`
 a FieldElement.__init__(self, parent) self._x = x # nonoptimized def element(self): """ Return the underlying fraction field element that represents this element.
• sage/rings/function_field/todo.txt

`diff -r e07f7bffaadc -r 11bc1c46e91c sage/rings/function_field/todo.txt`
 a TODO: [ ] ideals [ ] polynomial factoring of any univariate poly over a function field: reduce to bivariate over constant field? [ ] reduction algorithm [ ] polynomial factoring of any univariate poly over a non-rational function field [ ] checking irreducibility in FunctionField_polymod constructor [ ] Docstring headers for each file with description of content of file [ ] copyright headers [ ] pickle doctests [ ] a command FunctionField to make a new function field from anything. [ ] method function_field() on algebraic curves, that give back a corresponding function field object. DONE: [x] polynomial factoring of any univariate poly over a rational function field: reduce to bivariate over constant field? [x] conversion back and forth between a free module over base [x] random element [x] numerator, denominator
• sage/rings/polynomial/polynomial_element.pyx

`diff -r e07f7bffaadc -r 11bc1c46e91c sage/rings/polynomial/polynomial_element.pyx`
 a import sage.rings.finite_rings.integer_mod_ring import sage.rings.complex_field import sage.rings.fraction_field_element import sage.rings.function_field import sage.rings.infinity as infinity #import sage.misc.misc as misc from sage.misc.sage_eval import sage_eval X[i] = c return X def factor(self): def factor(self, proof=True): r""" Return the factorization of self over the base ring of this polynomial. Factoring polynomials over else: G = self._pari_with_name('x').factor() elif sage.rings.function_field.function_field.is_FunctionField(R): return R._factor_univariate_polynomial(self, proof=proof) #elif padic_field.is_pAdicField(R): #    G = list(self._pari_with_name('x').factorpadic(R.prime(), R.prec()))