Ticket #9054: trac_9054_cleanup.patch

File trac_9054_cleanup.patch, 14.6 KB (added by saraedum, 6 years ago)

cleanup code and imports

  • sage/categories/function_fields.py

    exporting patch:
    # HG changeset patch
    # User Julian Rueth <julian.rueth@gmail.com>
    Trac 9054: cleanup code and imports
    
    diff --git a/sage/categories/function_fields.py b/sage/categories/function_fields.py
    index 171a08a..811479c 100644
    a b class FunctionFields(Category): 
    3030    TESTS::
    3131
    3232        sage: TestSuite(FunctionFields()).run()
    33 
    3433    """
    35 
    3634    @cached_method
    3735    def super_categories(self):
    3836        """
    class FunctionFields(Category): 
    4341
    4442            sage: FunctionFields().super_categories()
    4543            [Category of fields]
    46 
    4744        """
    4845        return[Fields()]
    4946
    50 
    5147    def _call_(self, x):
    5248        r"""
    5349        Constructs an object in this category from the data in ``x``,
    class FunctionFields(Category): 
    6561            Function field in y defined by y^2 - x
    6662            sage: C(L.equation_order())
    6763            Function field in y defined by y^2 - x
    68            
    69 
    7064        """
    7165        try:
    7266            return x.function_field()
    7367        except AttributeError:
    7468            raise  TypeError, "unable to canonically associate a function field to %s"%x
    7569
    76 
    7770    class ParentMethods:
    7871        pass
    7972
  • sage/rings/function_field/__init__.py

    diff --git a/sage/rings/function_field/__init__.py b/sage/rings/function_field/__init__.py
    index 8362255..e69de29 100644
    a b  
    1 # Function fields
  • sage/rings/function_field/all.py

    diff --git a/sage/rings/function_field/all.py b/sage/rings/function_field/all.py
    index 4d5b905..6a6a1df 100644
    a b  
    11from constructor import FunctionField
    2 
    3 
  • sage/rings/function_field/constructor.py

    diff --git a/sage/rings/function_field/constructor.py b/sage/rings/function_field/constructor.py
    index 51b1408..9027c10 100644
    a b EXAMPLES:: 
    1010    sage: K is L
    1111    True
    1212"""
    13 import function_field
    14 from sage.misc.cachefunc import cached_function
    15 from sage.misc.decorators import sage_wraps
    1613
    1714from sage.structure.factory import UniqueFactory
    1815
  • sage/rings/function_field/function_field.py

    diff --git a/sage/rings/function_field/function_field.py b/sage/rings/function_field/function_field.py
    index 4053013..cb0bb22 100644
    a b be fixed in another ticket:: 
    5151    sage: TestSuite(S).run(skip = '_test_elements') #long time
    5252"""
    5353
    54 from sage.structure.category_object import CategoryObject
    5554from sage.rings.ring import Field
    56 from sage.rings.integer_ring import ZZ
    57 from sage.structure.parent_gens import ParentWithGens
    58 from sage.structure.parent import Parent
    59 import function_field_element
    60 import constructor
     55from function_field_element import FunctionFieldElement, FunctionFieldElement_rational, FunctionFieldElement_polymod
    6156
    6257from sage.misc.cachefunc import cached_method
    6358
    6459from sage.categories.function_fields import FunctionFields
    6560CAT = FunctionFields()
    6661
    67 import maps
    68 
    6962def is_FunctionField(x):
    7063    """
    7164    Return True if ``x`` is of function field type.
    def is_FunctionField(x): 
    7972        True
    8073    """
    8174    if isinstance(x, FunctionField): return True
    82     from sage.categories.function_fields import FunctionFields
    8375    return x in FunctionFields()
    8476
    8577class FunctionField(Field):
    class FunctionField_polymod(FunctionField): 
    339331        False
    340332    """
    341333    def __init__(self, polynomial, names,
    342             element_class = function_field_element.FunctionFieldElement_polymod,
     334            element_class = FunctionFieldElement_polymod,
    343335            category=CAT):
    344336        """
    345337        Create a function field defined as an extension of another
    class FunctionField_polymod(FunctionField): 
    739731            y
    740732        """
    741733        if x.parent() is self._ring:
    742             return function_field_element.FunctionFieldElement_polymod(self, x)
    743         if isinstance(x, function_field_element.FunctionFieldElement):
    744             return function_field_element.FunctionFieldElement_polymod(self, self._ring(x.element()))           
    745         return function_field_element.FunctionFieldElement_polymod(self, self._ring(x))
    746    
     734            return FunctionFieldElement_polymod(self, x)
     735        if isinstance(x, FunctionFieldElement):
     736            return FunctionFieldElement_polymod(self, self._ring(x.element()))
     737        return FunctionFieldElement_polymod(self, self._ring(x))
    747738
    748739    def gen(self, n=0):
    749740        """
    class RationalFunctionField(FunctionField): 
    949940        Morphism of function fields defined by t |--> tbar
    950941    """
    951942    def __init__(self, constant_field, names,
    952             element_class = function_field_element.FunctionFieldElement_rational,
     943            element_class = FunctionFieldElement_rational,
    953944            category=CAT):
    954945        """
    955946        Create a rational function field in one variable.
    class RationalFunctionField(FunctionField): 
    1004995            sage: clazz(*args)
    1005996            Rational function field in x over Rational Field
    1006997        """
    1007         return constructor.FunctionField, (self._constant_field, self._names)
     998        from constructor import FunctionField
     999        return FunctionField, (self._constant_field, self._names)
    10081000   
    10091001    def __hash__(self):
    10101002        """
    class RationalFunctionField(FunctionField): 
    10531045            Rational function field in t over Rational Field
    10541046       
    10551047        """
    1056         #if isinstance(x, self._element_class):
    1057         #    if x.parent() is self:
    1058         #        return x
    1059         #    else:
    1060         #        return self._element_class(self, x)
    1061         #return self._element_class(self, x, y,
    1062         #        coerce=coerce, reduce = self.is_exact())
    10631048        if x.parent() is self._field:
    1064             return function_field_element.FunctionFieldElement_rational(self, x)
    1065         if isinstance(x, function_field_element.FunctionFieldElement):
    1066             return function_field_element.FunctionFieldElement_rational(self, self._field(x.element()))
     1049            return FunctionFieldElement_rational(self, x)
     1050        if isinstance(x, FunctionFieldElement):
     1051            return FunctionFieldElement_rational(self, self._field(x.element()))
    10671052        if x.parent() is self.polynomial_ring():
    10681053            return x[0]
    1069         return function_field_element.FunctionFieldElement_rational(self, self._field(x))
     1054        return FunctionFieldElement_rational(self, self._field(x))
    10701055
    10711056    def _to_bivariate_polynomial(self, f):
    10721057        """
    class RationalFunctionField(FunctionField): 
    12271212            sage: K.degree()
    12281213            1
    12291214        """
     1215        from sage.rings.integer_ring import ZZ
    12301216        return ZZ(1)
    12311217   
    12321218    def gen(self, n=0):
    class RationalFunctionField(FunctionField): 
    13071293            sage: f(x^2)
    13081294            5*y^2 + (x^3 + 6*x + 4)*y + 2*x^3 + 5*x + 4       
    13091295        """
     1296        from sage.structure.category_object import CategoryObject
    13101297        if isinstance(im_gens, CategoryObject):
    13111298            return self.Hom(im_gens).natural_map()
    13121299        if not isinstance(im_gens, (list,tuple)):
    class RationalFunctionField(FunctionField): 
    13141301        if len(im_gens) != 1:
    13151302            raise ValueError, "there must be exactly one generator"
    13161303        x = im_gens[0]
    1317         return maps.FunctionFieldMorphism_rational(self.Hom(x.parent()), x)
     1304        from maps import FunctionFieldMorphism_rational
     1305        return FunctionFieldMorphism_rational(self.Hom(x.parent()), x)
    13181306
    13191307    def field(self):
    13201308        """
  • sage/rings/function_field/function_field_ideal.py

    diff --git a/sage/rings/function_field/function_field_ideal.py b/sage/rings/function_field/function_field_ideal.py
    index 761beea..5d7069c 100644
    a b Ideals in the equation order of an extension of a rational function field:: 
    3333    Ideal (x^3 + 1, -y) of Order in Function field in y defined by y^2 - x^3 - 1
    3434"""
    3535from sage.rings.ideal import Ideal_generic
    36 from sage.modules import free_module_element
    3736
    3837class FunctionFieldIdeal(Ideal_generic):
    3938    """
    def ideal_with_gens_over_base(R, gens): 
    294293    # by the linear algebra Hermite form code.
    295294    import function_field_order
    296295    if isinstance(R, function_field_order.FunctionFieldOrder_rational):
    297         try:
    298             gens = free_module_element.vector(x.element() for x in gens)
    299             d = gens.denominator()
    300             gens *= d
    301             v = R._ring.ideal(gens.list()).gens_reduced()
    302             assert len(v) == 1
    303             basis = [to_V(v[0]/d)]
    304             M = V.span_of_basis(basis, check=False, already_echelonized=True, base_ring=R)
    305         except Exception, msg:
    306             print msg   # TODO --for debugging
    307             raise
     296        from sage.modules import free_module_element
     297        gens = free_module_element.vector(x.element() for x in gens)
     298        d = gens.denominator()
     299        gens *= d
     300        v = R._ring.ideal(gens.list()).gens_reduced()
     301        assert len(v) == 1
     302        basis = [to_V(v[0]/d)]
     303        M = V.span_of_basis(basis, check=False, already_echelonized=True, base_ring=R)
    308304    else:
    309305        # General case
    310306        S = V.base_field().maximal_order()
  • sage/rings/function_field/function_field_order.py

    diff --git a/sage/rings/function_field/function_field_order.py b/sage/rings/function_field/function_field_order.py
    index aaf0d02..7bb1aac 100644
    a b Equation orders in extensions of rational function fields:: 
    2323    True
    2424"""
    2525
    26 from sage.structure.parent_gens import ParentWithGens
    27 
    2826from sage.rings.ring import IntegralDomain, PrincipalIdealDomain
    2927
    30 from sage.rings.ideal import is_Ideal
    31 
    3228class FunctionFieldOrder(IntegralDomain):
    3329    """
    3430    Base class for orders in function fields.
    class FunctionFieldOrder(IntegralDomain): 
    186182        from function_field_ideal import ideal_with_gens
    187183        return ideal_with_gens(self, gens)
    188184
    189 
    190        
    191    
    192 
    193185class FunctionFieldOrder_basis(FunctionFieldOrder):
    194186    """
    195187    An order given by a basis over the maximal order of the base
    class FunctionFieldOrder_basis(FunctionFieldOrder): 
    342334        """
    343335        return self._module
    344336
    345 ##     def polynomial_quotient_ring(self):
    346 ##         """
    347 ##         Return a quotient of a (possibly multivariate) polynomial ring
    348 ##         that is isomorphic to self, along with morphisms back and
    349 ##         forth.
    350 ##         """
    351 ##         raise NotImplementedError
    352    
    353 
    354 import function_field_element   
    355        
    356337class FunctionFieldOrder_rational(PrincipalIdealDomain, FunctionFieldOrder):
    357338    """
    358339    The maximal order in a rational function field.
    class FunctionFieldOrder_rational(PrincipalIdealDomain, FunctionFieldOrder): 
    472453            f = f.element()
    473454        from function_field_element import FunctionFieldElement_rational
    474455        return FunctionFieldElement_rational(self, self._ring(f))
    475 
    476 ##     def polynomial_quotient_ring(self):
    477 ##         """
    478 ##         Return a quotient of a (possibly multivariate) polynomial ring
    479 ##         that is isomorphic to self, along with morphisms back and
    480 ##         forth.
    481 
    482 ##         EXAMPLES::
    483 ##         """
    484 ##         return self._ring
    485 
    486    
    487        
    488        
  • sage/rings/function_field/maps.py

    diff --git a/sage/rings/function_field/maps.py b/sage/rings/function_field/maps.py
    index 00c2ebf..2d3f955 100644
    a b EXAMPLES:: 
    1919
    2020from sage.categories.morphism import Morphism
    2121from sage.rings.morphism import RingHomomorphism
    22 from sage.categories.homset import Hom
    23 
    24 from function_field_order import FunctionFieldOrder
    2522
    2623class FunctionFieldIsomorphism(Morphism):
    2724    r"""
    class MapVectorSpaceToFunctionField(FunctionFieldIsomorphism): 
    103100        self._V = V
    104101        self._K = K
    105102        self._R = K.polynomial_ring()
     103        from sage.categories.homset import Hom
    106104        FunctionFieldIsomorphism.__init__(self, Hom(V, K))
    107105
    108106    def _call_(self, v):
    class MapFunctionFieldToVectorSpace(FunctionFieldIsomorphism): 
    172170        self._K = K
    173171        self._zero = K.base_ring()(0)
    174172        self._n = K.degree()
     173        from sage.categories.homset import Hom
    175174        FunctionFieldIsomorphism.__init__(self, Hom(K, V))
    176175
    177176    def domain(self):
  • deleted file sage/rings/function_field/todo.txt

    diff --git a/sage/rings/function_field/todo.txt b/sage/rings/function_field/todo.txt
    deleted file mode 100644
    index 7d3ec16..0000000
    + -  
    1 TODO:
    2 
    3 [ ] copyright headers
    4 [ ] Docstring headers for each file with description of content of file
    5 [ ] picling elements
    6 
    7 [ ] RR space algorithm
    8 
    9 [ ] implement denominator in general, which is a guaranteed multiple of the denominator
    10     only when not pid...
    11 [ ] reduction of divisors: algorithm
    12 [ ] polynomial factoring of any univariate poly over a non-rational function field
    13 [ ] checking irreducibility in FunctionField_polymod constructor
    14 [ ] pickle doctests
    15 [ ] TestSuite(s).run() doctests
    16 [ ] method function_field() on algebraic curves, that give back a corresponding function field object.
    17 [ ] compute maximal separable subfield (requested by Voloch)
    18 [ ] factoring polynomials in n variables over rational function field
    19 [ ] x.valuation(...)  [bradshaw will do this]
    20 [ ] optimization: new implementation of the function field API, but
    21     using multivariate poly rings in some cases; for *speed*, but with
    22     less base rings supported...?
    23 
    24 DONE:
    25 [x] phi = morphism; phi(order); phi(ideal) --- won't do, since image of order or ideal often isn't one
    26     for general morphisms
    27 [x] a command FunctionField to make a new function field from anything.
    28 [x] constant_base_field versus constant_field
    29 [x] fix when asking for equation order if defining polynomial not *integral*
    30 [x] non-monic defining polynomials
    31 [x] do not require defining polynomial to be monic
    32 [x] issue with *underscores* and singular:
    33 K.<t_ba> = FunctionField(QQ)
    34 R.<u_ba> = K[]
    35 L.<u_ba> = K.extension(u_ba^2 - t_ba)
    36 L.equation_order()
    37 BOOM!
    38 
    39 [x] isomorphisms between function fields:
    40      K.hom([top gen, next one down, etc.])
    41     make sure you include easy way to gens all the way down.
    42 [x] inverses of fractional ideals
    43 [x] factor for elements of the rational function field
    44 [x] ideals
    45 [x] polynomial factoring of any univariate poly over a rational function field: reduce to bivariate over constant field?
    46 [x] conversion back and forth between a free module over base
    47 [x] random element
    48 [x] numerator, denominator
    49 [x] 100% coverage
    50 [x] matrix of element
    51 [x] norm
    52 [x] trace