Ticket #9054: trac_9054-part4.patch

File trac_9054-part4.patch, 12.6 KB (added by was, 7 years ago)
  • sage/rings/function_field/function_field.py

    # HG changeset patch
    # User William Stein <wstein@gmail.com>
    # Date 1274953602 25200
    # Node ID ad21a9d32f9940caf21acdb26441b953be22a462
    # Parent  7f05bf6d613ef8004b9d767401fe6ddfc70c8b38
    [mq]: trac_9054-part4.patch
    
    diff -r 7f05bf6d613e -r ad21a9d32f99 sage/rings/function_field/function_field.py
    a b  
    9898            names = f.variable_name()
    9999        return FunctionField_polymod(f, names)
    100100
     101    def order_with_basis(self, basis, check=True):
     102        """
     103        Return the order with given basis over the maximal order of
     104        the base field.
     105
     106        INPUT:
     107
     108           - ``basis`` -- a list of elements of self
     109           - ``check`` -- bool (default: True); if True, check that
     110             the basis is really linearly independent
     111
     112        OUTPUT:
     113
     114            - an order in this function field
     115
     116        EXAMPLES::
     117
     118            sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^3 + x^3 + 4*x + 1)
     119            sage: O = L.order_with_basis([1, Y, Y^2]); O
     120            Order in Function field in Y defined by y^3 + x^3 + 4*x + 1
     121            sage: O.basis()
     122            (1, Y, Y^2)
     123            sage: O = L.order_with_basis([x, x^2 + x*Y, (2/3)*Y^2]); O
     124            Order in Function field in Y defined by y^3 + x^3 + 4*x + 1
     125            sage: O.basis()
     126            (x, x*Y + x^2, 2/3*Y^2)
     127        """
     128        from function_field_order import FunctionFieldOrder_basis
     129        return FunctionFieldOrder_basis([self(a) for a in basis], check=check)
     130
     131    def order(self, x, check=True):
     132        """
     133        Return the order in this function field generated over the
     134        maximal order by x or the elements of x if x is a list.
     135
     136        INPUT:
     137       
     138           - ``x`` -- element of self, or a list of elements of self
     139           - ``check`` -- bool (default: True); if True, check that
     140             x really generates an order
     141
     142        EXAMPLES::
     143
     144            sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^3 + x^3 + 4*x + 1)
     145            sage: O = L.order(Y); O
     146            Order in Function field in Y defined by y^3 + x^3 + 4*x + 1
     147            sage: O.basis()
     148            (1, Y, Y^2)
     149
     150            sage: Z = K.order(x); Z
     151            Order in Rational function field in x over Rational Field
     152            sage: Z.basis()
     153            (1,)
     154
     155        Orders with multiple generators, not yet supported::
     156
     157            sage: Z = K.order([x,x^2]); Z
     158            Traceback (most recent call last):
     159            ...
     160            NotImplementedError
     161        """
     162        if not isinstance(x, (list, tuple)):
     163            x = [x]
     164        if len(x) == 1:
     165            g = x[0]
     166            basis = [self(1)]
     167            for i in range(self.degree()-1):
     168                basis.append(basis[-1]*g)
     169        else:
     170            raise NotImplementedError
     171        return self.order_with_basis(basis, check=check)
     172
     173    def _coerce_map_from_(self, R):
     174        """
     175        Return True if there is a coerce map from R to self.
     176
     177        EXAMPLES::
     178
     179            sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^3 + x^3 + 4*x + 1)
     180            sage: L.equation_order()
     181            Order in Function field in Y defined by y^3 + x^3 + 4*x + 1
     182            sage: L._coerce_map_from_(L.equation_order())
     183            True
     184            sage: L._coerce_map_from_(GF(7))
     185            False
     186        """
     187        from function_field_order import FunctionFieldOrder
     188        if isinstance(R, FunctionFieldOrder) and R.fraction_field() == self:
     189            return True
     190        return False
     191   
     192
    101193class FunctionField_polymod(FunctionField):
    102194    """
    103195    A function field defined by a univariate polynomial, as an
     
    413505            sage: L._element_constructor_(L.polynomial_ring().gen())
    414506            w
    415507        """
    416         if x.parent() is self:
    417             return x
    418 
    419508        if x.parent() is self._ring:
    420509            return function_field_element.FunctionFieldElement_polymod(self, x)
    421        
     510        if isinstance(x, function_field_element.FunctionFieldElement):
     511            return function_field_element.FunctionFieldElement_polymod(self, self._ring(x.element()))           
    422512        return function_field_element.FunctionFieldElement_polymod(self, self._ring(x))
    423513   
    424514
     
    439529            ...
    440530            IndexError: Only one generator.
    441531        """
    442         if n != 0:
    443             raise IndexError, "Only one generator."
     532        if n != 0: raise IndexError, "Only one generator."
    444533        return self._gen
    445534
    446535    def ngens(self):
     
    455544            sage: L.ngens()
    456545            1
    457546        """
    458         return ZZ(1)
     547        return 1
    459548
    460549    def equation_order(self):
    461550        """
     
    467556            sage: K.<x> = FunctionField(QQ); R.<y> = K[]
    468557            sage: L.<w> = K.extension(y^5 - (x^3 + 2*x*y + 1/x))
    469558            sage: L.equation_order()
    470             Traceback (most recent call last):
    471             ...
    472             NotImplementedError
     559            Order in Function field in w defined by y^5 - 2*x*y + (-x^4 - 1)/x
    473560        """
    474         raise NotImplementedError
     561        return self.order(self.gen(), check=False)
     562   
    475563
    476564class RationalFunctionField(FunctionField):
    477565    """
     
    498586        sage: K.constant_field()
    499587        Finite Field of size 7
    500588        sage: K.maximal_order()
    501         Univariate Polynomial Ring in t over Finite Field of size 7
     589        Maximal order in Rational function field in t over Finite Field of size 7
    502590    """
    503591    def __init__(self, constant_field, names, category=CAT):
    504592        """
     
    586674            Rational function field in t over Rational Field
    587675        """
    588676        if x.parent() is self._field:
    589             return function_field_element.FunctionFieldElement_P1(self, x)
     677            return function_field_element.FunctionFieldElement_rational(self, x)
    590678        if isinstance(x, function_field_element.FunctionFieldElement):
    591             K = x.parent()
    592             if K is self:
    593                 return x
    594             else:
    595                 raise TypeError
    596         return function_field_element.FunctionFieldElement_P1(self, self._field(x))
     679            return function_field_element.FunctionFieldElement_rational(self, self._field(x.element()))
     680        return function_field_element.FunctionFieldElement_rational(self, self._field(x))
     681
     682    def polynomial_ring(self):
     683        """
     684        Return polynomial ring underlying this function field.
     685       
     686        EXAMPLES::
     687       
     688            sage: K.<x> = FunctionField(QQ)
     689            sage: K.polynomial_ring()
     690            Univariate Polynomial Ring in x over Rational Field
     691        """
     692        return self._ring
     693
     694    def vector_space(self):
     695        """
     696        Return a vector space V and isomorphisms self --> V and V --> self.
     697       
     698        OUTPUT:
     699
     700            -  ``V`` - a vector space over the rational numbers
     701            -  ``from_V`` - an isomorphism from V to self
     702            -  ``to_V`` - an isomorphism from self to V
     703
     704        EXAMPLES::
     705
     706            sage: K.<x> = FunctionField(QQ)
     707            sage: K.vector_space()
     708            (Vector space of dimension 1 over Rational function field in x over Rational Field, Isomorphism map:
     709              From: Vector space of dimension 1 over Rational function field in x over Rational Field
     710              To:   Rational function field in x over Rational Field, Isomorphism map:
     711              From: Rational function field in x over Rational Field
     712              To:   Vector space of dimension 1 over Rational function field in x over Rational Field)
     713        """
     714        try: return self._vector_space
     715        except AttributeError:
     716            V = self.base_field()**1
     717            from_V = maps.MapVectorSpaceToFunctionField(V, self)
     718            to_V   = maps.MapFunctionFieldToVectorSpace(self, V)
     719            self._vector_space = (V, from_V, to_V)
     720            return self._vector_space
    597721
    598722    def random_element(self, *args, **kwds):
    599723        """
     
    651775            sage: K.ngens()
    652776            1
    653777        """
    654         return ZZ(1)
     778        return 1
    655779   
    656780    def base_field(self):
    657781        """
     
    689813       
    690814            sage: K.<t> = FunctionField(QQ)
    691815            sage: K.maximal_order()
    692             Univariate Polynomial Ring in t over Rational Field
     816            Maximal order in Rational function field in t over Rational Field
    693817        """
    694         return self._ring
     818        try: return self._maximal_order
     819        except AttributeError:
     820            from function_field_order import FunctionFieldOrder_rational
     821            self._maximal_order = FunctionFieldOrder_rational(self)
     822            return self._maximal_order
    695823
    696824    def constant_field(self):
    697825        """
  • sage/rings/function_field/function_field_element.py

    diff -r 7f05bf6d613e -r ad21a9d32f99 sage/rings/function_field/function_field_element.py
    a b  
    152152
    153153    minpoly = minimal_polynomial
    154154   
     155    def is_integral(self):
     156        r"""
     157        Determine if self is integral over the maximal order of the base field.
     158       
     159        EXAMPLES::
     160       
     161            sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2 - x*y + 4*x^3)
     162            sage: Y.is_integral()
     163            True
     164            sage: (Y/x).is_integral()
     165            True
     166            sage: (Y/x)^2 - (Y/x) + 4*x
     167            0
     168            sage: (Y/x^2).is_integral()
     169            False
     170            sage: f = (Y/x).minimal_polynomial('W'); f
     171            W^2 - W + 4*x           
     172        """
     173        R = self.parent().base_field().maximal_order()
     174        return all([a in R for a in self.minimal_polynomial()])
     175
    155176class FunctionFieldElement_polymod(FunctionFieldElement):
    156177    """
    157178    EXAMPLES::
     
    171192        FieldElement.__init__(self, parent)
    172193        self._x = x
    173194
     195    def element(self):
     196        """
     197        Return the underlying polynomial that represents this element.
     198       
     199        EXAMPLES::
     200            sage: K.<x> = FunctionField(QQ); R.<y> = K[]; L.<Y> = K.extension(y^2 - x*y + 4*x^3)
     201            sage: f = Y/x^2 + x/(x^2+1); f
     202            1/x^2*Y + x/(x^2 + 1)
     203            sage: f.element()
     204            1/x^2*y + x/(x^2 + 1)
     205            sage: type(f.element())
     206            <class 'sage.rings.polynomial.polynomial_element_generic.Polynomial_generic_dense_field'>       
     207        """
     208        return self._x
     209
    174210    def _repr_(self):
    175211        """
    176212        EXAMPLES::
     
    275311        return self._x.padded_list(self.parent().degree())
    276312       
    277313
    278 class FunctionFieldElement_P1(FunctionFieldElement):
     314class FunctionFieldElement_rational(FunctionFieldElement):
    279315    """
    280316    EXAMPLES::
    281317   
     
    292328        FieldElement.__init__(self, parent)
    293329        self._x = x
    294330
     331    def element(self):
     332        """
     333        Return the underlying fraction field element that represents this element.
     334
     335        EXAMPLES::
     336
     337            sage: R.<a> = FunctionField(GF(7))
     338            sage: a.element()
     339            a
     340            sage: type(a.element())
     341            <type 'sage.rings.fraction_field_element.FractionFieldElement'>       
     342        """
     343        return self._x
     344
    295345    def list(self):
    296346        """
    297347        EXAMPLES::
  • sage/rings/function_field/todo.txt

    diff -r 7f05bf6d613e -r ad21a9d32f99 sage/rings/function_field/todo.txt
    a b  
    11TODO:
    22
    3 [ ] conversion back and forth between a free module over base
     3[ ] ideals
     4[ ] polynomial factoring of any univariate poly over a function field: reduce to bivariate over constant field?
     5[ ] checking irreducibility in FunctionField_polymod constructor
     6
    47[ ] Docstring headers for each file with description of content of file
    58[ ] copyright headers
    6 [ ] polynomial factoring of any univariate poly over a function field: reduce to bivariate over constant field?
    7 [ ] checking irreducibility in FunctionField_polymod constructor
    89[ ] pickle doctests
    910[ ] TestSuite(s).run() doctests
    10 [ ] ideals
    1111[ ] non-monic defining polynomials
    1212[ ] a command FunctionField to make a new function field from anything.
    1313[ ] method function_field() on algebraic curves, that give back a corresponding function field object.
    14 [ ] random element
    1514
    1615DONE:
     16[x] conversion back and forth between a free module over base
     17[x] random element
    1718[x] numerator, denominator
    1819[x] 100% coverage
    1920[x] matrix of element