Ticket #9054: trac_9054-part3.patch

File trac_9054-part3.patch, 23.5 KB (added by was, 12 years ago)
• sage/rings/function_field/constructor.py

```# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1274928994 25200
# Node ID 7f05bf6d613ef8004b9d767401fe6ddfc70c8b38
# Parent  c3dd4c08eaefb4782dc8bf946a611bfeb4fe5a82
[mq]: trac-9054-part3.patch

diff -r c3dd4c08eaef -r 7f05bf6d613e sage/rings/function_field/constructor.py```
 a import function_field def FunctionField(X, names=None): """ Return the function field defined by X. INPUT: - `X` -- a field; return the function field in one variable over X. - ``names`` -- name of variable as a string EXAMPLES:: sage: FunctionField(QQ,'alpha') Rational function field in alpha over Rational Field sage: K. = FunctionField(GF(7)); K Rational function field in alpha over Finite Field of size 7 """ return function_field.RationalFunctionField(X, names=names)
• sage/rings/function_field/function_field.py

`diff -r c3dd4c08eaef -r 7f05bf6d613e sage/rings/function_field/function_field.py`
 a """ return self._base_field def random_element(self, *args, **kwds): """ Create a random element of this function field.  Parameters are passed onto the random_element method of the base_field. EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[] sage: L. = K.extension(y^2 - (x^2 + x)) sage: L.random_element() ((x^2 - x + 2/3)/(x^2 + 1/3*x - 1))*w^2 + ((-1/4*x^2 + 1/2*x - 1)/(-5/2*x + 2/3))*w + (-1/2*x^2 - 4)/(-12*x^2 + 1/2*x - 1/95) """ return self(self._ring.random_element(degree=self.degree(), *args, **kwds)) def polynomial(self): """ Return the univariate polynomial that defines this function Must be over a field:: sage: FunctionField(ZZ) sage: FunctionField(ZZ, 't') Traceback (most recent call last): ... TypeError: constant_field must be a field """ if names is None: raise ValueError, "variable name must be specified" if not constant_field.is_field(): raise TypeError, "constant_field must be a field" ParentWithGens.__init__(self, self, names=names, category = category) raise TypeError return function_field_element.FunctionFieldElement_P1(self, self._field(x)) def random_element(self, *args, **kwds): """ Create a random element of this rational function field. Parameters are passed onto the random_element method of the underlying fraction field. EXAMPLES:: sage: FunctionField(QQ,'alpha').random_element() (-1/2*a^2 - 4)/(-12*a^2 + 1/2*a - 1/95) """ return self(self._field.random_element(*args, **kwds)) def degree(self): """ Return the degree over the base field of this rational
• sage/rings/function_field/function_field_element.py

`diff -r c3dd4c08eaef -r 7f05bf6d613e sage/rings/function_field/function_field_element.py`
 a from sage.structure.element import FieldElement def is_FunctionFieldElement(x): """ Return True if x is any type of function field element. EXAMPLES:: sage: t = FunctionField(QQ,'t').gen() sage: sage.rings.function_field.function_field_element.is_FunctionFieldElement(t) True sage: sage.rings.function_field.function_field_element.is_FunctionFieldElement(0) False """ return isinstance(x, FunctionFieldElement) class FunctionFieldElement(FieldElement): pass """ The abstract base class for function field elements. EXAMPLES:: sage: t = FunctionField(QQ,'t').gen() sage: isinstance(t, sage.rings.function_field.function_field_element.FunctionFieldElement) True """ def matrix(self): r""" Return the matrix of multiplication by self. EXAMPLES:: A rational function field: sage: K. = FunctionField(QQ) sage: t.matrix() [t] sage: (1/(t+1)).matrix() [1/(t + 1)] Now an example in a nontrivial extension of a rational function field:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: Y.matrix() [     0      1] [-4*x^3      x] sage: Y.matrix().charpoly('Z') Z^2 - x*Z + 4*x^3 An example in a relative extension, where neither function field is rational:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: M. = L[]; Z. = L.extension(T^3 - Y^2*T + x) sage: alpha.matrix() [          0           1           0] [          0           0           1] [         -x x*Y - 4*x^3           0] """ try: return self._matrix except AttributeError: # Multiply each power of field generator on the left by this # element; make matrix whose rows are the coefficients of the # result, and transpose. K = self.parent() v = [] x = K.gen() a = K(1) d = K.degree() for n in range(d): v += (a*self).list() a *= x k = K.base_ring() import sage.matrix.matrix_space M = sage.matrix.matrix_space.MatrixSpace(k, d) self._matrix = M(v) return self._matrix def trace(self): """ Return the trace of this function field element. EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: Y.trace() x """ return self.matrix().trace() def norm(self): """ Return the norm of this function field element. EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: Y.norm() 4*x^3 The norm is relative:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: M. = L[]; Z. = L.extension(T^3 - Y^2*T + x) sage: alpha.norm() -x sage: alpha.norm().parent() Function field in Y defined by y^2 - x*y + 4*x^3 """ return self.matrix().determinant() def characteristic_polynomial(self, *args, **kwds): """ Return the characteristic polynomial of this function field element.  Give an optional input string to name the variable in the characteristic polynomial. EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: M. = L[]; Z. = L.extension(T^3 - Y^2*T + x) sage: x.characteristic_polynomial('W') W - x sage: Y.characteristic_polynomial('W') W^2 - x*W + 4*x^3 sage: alpha.characteristic_polynomial('W') W^3 + (-x*Y + 4*x^3)*W + x """ return self.matrix().characteristic_polynomial(*args, **kwds) charpoly = characteristic_polynomial def minimal_polynomial(self, *args, **kwds): """ Return the minimal polynomial of this function field element. Give an optional input string to name the variable in the characteristic polynomial. EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: M. = L[]; Z. = L.extension(T^3 - Y^2*T + x) sage: x.minimal_polynomial('W') W - x sage: Y.minimal_polynomial('W') W^2 - x*W + 4*x^3 sage: alpha.minimal_polynomial('W') W^3 + (-x*Y + 4*x^3)*W + x """ return self.matrix().minimal_polynomial(*args, **kwds) minpoly = minimal_polynomial class FunctionFieldElement_polymod(FunctionFieldElement): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: x*Y + 1/x^3 x*Y + 1/x^3 """ def __init__(self, parent, x): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: type(Y) """ FieldElement.__init__(self, parent) self._x = x def _repr_(self): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: Y._repr_() 'Y' """ return self._x._repr(name=self.parent().variable_name()) def __nonzero__(self): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: bool(Y) True sage: bool(L(0)) False """ return self._x.__nonzero__() def __cmp__(self, other): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: cmp(L, 0) 1 sage: cmp(0, L) -1 """ return cmp(self._x, other._x) def _add_(self, right): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: (2*Y + x/(1+x^3))  +  (3*Y + 5*x*Y)         # indirect doctest (5*x + 5)*Y + x/(x^3 + 1) """ return self.parent()(self._x + right._x) def _sub_(self, right): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: (2*Y + x/(1+x^3))  -  (3*Y + 5*x*Y)         # indirect doctest (-5*x - 1)*Y + x/(x^3 + 1) """ return self.parent()(self._x - right._x) def _mul_(self, right): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: Y  *  (3*Y + 5*x*Y)                          # indirect doctest (5*x^2 + 3*x)*Y - 20*x^4 - 12*x^3 """ P = self.parent() f = self._x * right._x return P(f.quo_rem(P._polynomial)[1]) def _div_(self, right): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: (2*Y + x/(1+x^3))  /  (2*Y + x/(1+x^3))       # indirect doctest 1 """ return self * ~right def __invert__(self): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: a = ~(2*Y + 1/x); a                           # indirect doctest (-x^2/(8*x^5 + x^2 + 1/2))*Y + (2*x^3 + x)/(16*x^5 + 2*x^2 + 1) sage: a*(2*Y + 1/x) 1 """ P = self.parent() return P(self._x.xgcd(P._polynomial)[1]) def list(self): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: a = ~(2*Y + 1/x); a (-x^2/(8*x^5 + x^2 + 1/2))*Y + (2*x^3 + x)/(16*x^5 + 2*x^2 + 1) sage: a.list() [(2*x^3 + x)/(16*x^5 + 2*x^2 + 1), -x^2/(8*x^5 + x^2 + 1/2)] sage: (x*Y).list() [0, x] """ return self._x.padded_list(self.parent().degree()) class FunctionFieldElement_P1(FunctionFieldElement): """ EXAMPLES:: sage: FunctionField(QQ, 't') Rational function field in t over Rational Field """ def __init__(self, parent, x): """ EXAMPLES:: sage: FunctionField(QQ,'t').gen()^3 t^3 """ FieldElement.__init__(self, parent) self._x = x def list(self): """ EXAMPLES:: sage: K. = FunctionField(QQ) sage: t.list() [t] """ return [self] def _repr_(self): """ EXAMPLES:: sage: K. = FunctionField(QQ) sage: t._repr_() 't' """ return repr(self._x) def __nonzero__(self): """ EXAMPLES:: sage: K. = FunctionField(QQ) sage: bool(t) True sage: bool(K(0)) False sage: bool(K(1)) True """ return self._x.__nonzero__() def __cmp__(self, other): """ EXAMPLES:: sage: K. = FunctionField(QQ) sage: cmp(t, 0) 1 sage: cmp(t, t^2) -1 """ return cmp(self._x, other._x) def _add_(self, right): """ EXAMPLES:: sage: K. = FunctionField(QQ) sage: t + (3*t^3)                      # indirect doctest 3*t^3 + t """ return self.parent()(self._x + right._x) def _sub_(self, right): """ EXAMPLES:: sage: K. = FunctionField(QQ) sage: t - (3*t^3)                      # indirect doctest -3*t^3 + t """ return self.parent()(self._x - right._x) def _mul_(self, right): """ EXAMPLES:: sage: K. = FunctionField(QQ) sage: (t+1) * (t^2-1)                  # indirect doctest t^3 + t^2 - t - 1 """ return self.parent()(self._x * right._x) def _div_(self, right): """ EXAMPLES:: sage: K. = FunctionField(QQ) sage: (t+1) / (t^2 - 1)                # indirect doctest 1/(t - 1) """ return self.parent()(self._x / right._x) def numerator(self): """ EXAMPLES:: sage: K. = FunctionField(QQ) sage: f = (t+1) / (t^2 - 1/3); f (t + 1)/(t^2 - 1/3) sage: f.numerator()                    # indirect doctest t + 1 """ return self._x.numerator() def denominator(self): """ EXAMPLES:: sage: K. = FunctionField(QQ) sage: f = (t+1) / (t^2 - 1/3); f (t + 1)/(t^2 - 1/3) sage: f.denominator()                  # indirect doctest t^2 - 1/3 """ return self._x.denominator()
• sage/rings/function_field/maps.py

`diff -r c3dd4c08eaef -r 7f05bf6d613e sage/rings/function_field/maps.py`
 a r""" A base class for various isomorphisms between function fields and vector spaces. EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space() sage: isinstance(f, sage.rings.function_field.maps.FunctionFieldIsomorphism) True """ def _repr_type(self): """ Return the type of this map (an isomorphism), for the purposes of printing out self. EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space() sage: f._repr_type() 'Isomorphism' """ return "Isomorphism" def is_injective(self): """ Return True, since this isomorphism is injective. EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space() sage: f.is_injective() True """ return True def is_surjective(self): """ Return True, since this isomorphism is surjective. EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space() sage: f.is_surjective() True """ return True class MapVectorSpaceToFunctionField(FunctionFieldIsomorphism): r""" An isomorphism from a vector space and a function field. EXAMPLES: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space(); f Isomorphism map: From: Vector space of dimension 2 over Rational function field in x over Rational Field To:   Function field in Y defined by y^2 - x*y + 4*x^3 """ def __init__(self, V, K): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space(); type(f) """ self._V = V self._K = K self._R = K.polynomial_ring() FunctionFieldIsomorphism.__init__(self, Hom(V, K)) def _call_(self, v): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space() sage: f(x*V.0 + (1/x^3)*V.1)         # indirect doctest 1/x^3*Y + x """ f = self._R(self._V(v).list()) return self._K(f) def domain(self): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space() sage: f.domain() Vector space of dimension 2 over Rational function field in x over Rational Field """ return self._V def codomain(self): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space() sage: f.codomain() Function field in Y defined by y^2 - x*y + 4*x^3 """ return self._K class MapFunctionFieldToVectorSpace(Map): class MapFunctionFieldToVectorSpace(FunctionFieldIsomorphism): """ An isomorphism from a function field to a vector space. EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space(); t Isomorphism map: From: Function field in Y defined by y^2 - x*y + 4*x^3 To:   Vector space of dimension 2 over Rational function field in x over Rational Field """ def __init__(self, K, V): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space(); type(t) """ self._V = V self._K = K self._zero = K.base_ring()(0) FunctionFieldIsomorphism.__init__(self, Hom(K, V)) def domain(self): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space() sage: t.domain() Function field in Y defined by y^2 - x*y + 4*x^3 """ return self._K def codomain(self): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space() sage: t.codomain() Vector space of dimension 2 over Rational function field in x over Rational Field """ return self._V def _repr_type(self): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space() sage: t._repr_type() 'Isomorphism' """ return "Isomorphism" def _call_(self, x): """ EXAMPLES:: sage: K. = FunctionField(QQ); R. = K[]; L. = K.extension(y^2 - x*y + 4*x^3) sage: V, f, t = L.vector_space() sage: t(x + (1/x^3)*Y)                       # indirect doctest (x, 1/x^3) """ y = self._K(x) v = y.list() w = v + [self._zero]*(self._n - len(v))
• sage/rings/function_field/todo.txt

`diff -r c3dd4c08eaef -r 7f05bf6d613e sage/rings/function_field/todo.txt`
 a TODO: [ ] conversion back and forth between a free module over base [ ] Docstring headers for each file with description of content of file [ ] copyright headers [ ] polynomial factoring of any univariate poly over a function field: reduce to bivariate over constant field? [ ] checking irreducibility in FunctionField_polymod constructor [ ] pickle doctests [ ] TestSuite(s).run() doctests [ ] ideals [ ] non-monic defining polynomials [ ] 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. [ ] random element [ ] Docstring headers for each file with description of content of file [ ] copyright headers [ ] polynomial factoring of any univariate poly over a function field: reduce to bivariate over constant field? [ ] checking irreducibility in FunctionField_polymod constructor [ ] pickle doctests [ ] TestSuite(s).run() doctests [ ] ideals [ ] non-monic defining polynomials [ ] 100% coverage [ ] matrix of element [ ] norm [ ] trace [ ] 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] numerator, denominator [x] 100% coverage [x] matrix of element [x] norm [x] trace