Ticket #9054: trac_9054_unique_factory.patch

File trac_9054_unique_factory.patch, 6.9 KB (added by saraedum, 6 years ago)

identical to trac_9054_UniqueFactory.patch (patchbot does not like uppercase)

  • sage/rings/function_field/constructor.py

    exporting patch:
    # HG changeset patch
    # User Julian Rueth <julian.rueth@gmail.com>
    Trac 9054: use UniqueFactory instead of cached_method in constructors
    
    diff --git a/sage/rings/function_field/constructor.py b/sage/rings/function_field/constructor.py
    index 2f357b2..b3664ed 100644
    a b import function_field 
    22from sage.misc.cachefunc import cached_function
    33from sage.misc.decorators import sage_wraps
    44
     5from sage.structure.factory import UniqueFactory
    56
    6 def FunctionField(X,names):
     7class FunctionFieldFactory(UniqueFactory):
    78    """
    8     Return the function field in one variable with constant field X. The function
    9     field returned is unique in the sence that if you call this function twice
     9    Return the function field in one variable with constant field ``F``. The function
     10    field returned is unique in the sense that if you call this function twice
    1011    with the same base field and name then you get the same python object back.
    1112
    1213    INPUT:
    1314
    14         - `X` -- a field; return the function field in one variable over X.
    15 
     15        - ``F`` -- a field
    1616        - ``names`` -- name of variable as a string or a tuple containg a string
    1717   
    1818    EXAMPLES::
    1919
    20         sage: FunctionField(QQ,'alpha')
    21         Rational function field in alpha over Rational Field
    22         sage: K.<alpha> = FunctionField(GF(7)); K
    23         Rational function field in alpha over Finite Field of size 7
    24     """
    25     if not isinstance(names,tuple):
    26         names = (names,)
    27     return _FunctionField(X,names)
     20        sage: K.<x> = FunctionField(QQ); K
     21        Rational function field in x over Rational Field
     22        sage: L.<y> = FunctionField(GF(7)); L
     23        Rational function field in y over Finite Field of size 7
     24        sage: R.<z> = L[]
     25        sage: M.<z> = L.extension(z^7-z-y); M
     26        Function field in z defined by z^7 + 6*z + 6*y
    2827
     28    TESTS::
    2929
    30 @cached_function
    31 def _FunctionField(X, names):
    32     """
    33     Does exactly the same as FunctionField, but with the disadvantage that it
    34     cannot be used for Pickling since it is decorated.
    35 
    36     INPUT:
    37 
    38         - `X` -- a field; return the function field in one variable over X.
    39 
    40         - ``names`` -- name of variable as a string
    41    
    42     EXAMPLES::
    43 
    44         sage: FunctionField(QQ,'alpha')
    45         Rational function field in alpha over Rational Field
    46         sage: K.<alpha> = FunctionField(GF(7)); K
    47         Rational function field in alpha over Finite Field of size 7
    48 
     30        sage: K.<x> = FunctionField(QQ)
     31        sage: L.<x> = FunctionField(QQ)
     32        sage: K is L
     33        True
     34        sage: M.<x> = FunctionField(GF(7))
     35        sage: K is M
     36        False
     37        sage: N.<y> = FunctionField(QQ)
     38        sage: K is N
     39        False
    4940    """
    50     return function_field.RationalFunctionField(X, names=names)
     41    def create_key(self, F, names):
     42        if not isinstance(names,tuple):
     43            names = (names,)
     44        return (F,names)
    5145
     46    def create_object(self, version, key, **extra_args):
     47        from function_field import RationalFunctionField
     48        return RationalFunctionField(key[0], names=key[1])
    5249
    53 def FunctionField_polymod_Constructor(polynomial, names):
    54     """
    55     Constructs a FunctionField_polymod instance. This function takes care
    56     that it's unique.
    57 
    58     EXAMPLES::
     50FunctionField = FunctionFieldFactory("FunctionField")
    5951
    60         sage: K.<x> = FunctionField(QQ)
    61         sage: R.<y>=K[]
    62         sage: y2 = y*1
    63         sage: y2 is y
    64         False
    65         sage: L.<w>=K.extension(x-y^2) #indirect doctest
    66         sage: M.<w>=K.extension(x-y2^2) #indirect doctest
    67         sage: L is M
    68         True
    69    
     52class FunctionFieldPolymodFactory(UniqueFactory):
    7053    """
    71     from sage.rings.polynomial.all import is_Polynomial
    72     if polynomial.parent().ngens()>1 or not is_Polynomial(polynomial):
    73         raise TypeError, "polynomial must be univariate a polynomial"
    74     if names is None:
    75         names = (polynomial.variable_name(), )
    76     if not isinstance(names,tuple):
    77         names = (names,)
    78     return _FunctionField_polymod_Constructor(polynomial, names)
     54    Create a function field defined as an extension of another
     55    function field by adjoining a root of a univariate polynomial.
     56    The returned function field is unique in the sense that if you
     57    call this function twice with an equal ``polynomial`` and ``names``
     58    it returns the same python object in both calls.
    7959
    80 @cached_function
    81 def _FunctionField_polymod_Constructor(polynomial, names):
    82     """
    83     Does exactly the same as FunctionField_polymod, but with the disadvantage that it
    84     cannot be used for Pickling since it is decorated.
     60    INPUT:
    8561
    86    
     62        - ``polynomial`` -- a univariate polynomial over a function field
     63        - ``names`` -- variable names (as a tuple of length 1 or string)
     64        - ``category`` -- a category (defaults to category of function fields)
     65       
    8766    EXAMPLES::
    8867
    8968        sage: K.<x> = FunctionField(QQ)
    def _FunctionField_polymod_Constructor(polynomial, names): 
    9574        sage: M.<w>=K.extension(x-y2^2) #indirect doctest
    9675        sage: L is M
    9776        True
    98    
    99 
    10077    """
    101     return function_field.FunctionField_polymod(polynomial, names)
    102    
     78    def create_key(self, polynomial, names):
     79        if names is None:
     80            names = polynomial.variable_name()
     81        if not isinstance(names,tuple):
     82            names = (names,)
     83        return (polynomial,names)
     84
     85    def create_object(self, version, key, **extra_args):
     86        from function_field import FunctionField_polymod
     87        return FunctionField_polymod(key[0], names=key[1])
     88
     89FunctionField_polymod = FunctionFieldPolymodFactory("FunctionField_polymod")
  • 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 4b64405..78d0807 100644
    a b class FunctionField(Field): 
    157157            sage: K.extension(t*y^3 + (1/t)*y + t^3/(t+1))
    158158            Function field in y defined by t*y^3 + 1/t*y + t^3/(t + 1)
    159159        """
    160         return constructor.FunctionField_polymod_Constructor(f, names)
     160        from constructor import FunctionField_polymod as FunctionField_polymod_Constructor
     161        return FunctionField_polymod_Constructor(f, names)
    161162
    162163    def order_with_basis(self, basis, check=True):
    163164        """
    class FunctionField_polymod(FunctionField): 
    493494        self._gen = self(self._ring.gen())
    494495
    495496    def __reduce__(self):
    496         return  constructor.FunctionField_polymod_Constructor, (self._polynomial, self._names)
    497 
    498 
     497        from constructor import FunctionField_polymod as FunctionField_polymod_Constructor
     498        return  FunctionField_polymod_Constructor, (self._polynomial, self._names)
    499499
    500500    def __hash__(self):
    501501        """