Ticket #5891: categories-numberfield_homset-nt.patch

File categories-numberfield_homset-nt.patch, 3.8 KB (added by nthiery, 10 years ago)
  • sage/rings/number_field/number_field.py

    Bug fix: Hom(F, V) was returning a NumberFieldHomset even if V was not a number field; needs review!
    
    This needs review and cleanup by specialists.
    
    The current fix required to add a trivial is_field() method for gap
    objects which always returns False. This is dubious.
    
    diff --git a/sage/rings/number_field/number_field.py b/sage/rings/number_field/number_field.py
    a b from itertools import count, izip 
    132132
    133133from sage.rings.integer_ring import IntegerRing
    134134
     135# Like the usual is_NumberField, but accepts CC / RR / ...
     136# Used by F._Hom_(K) on K to determine if the created homsets should
     137# be a NumberFieldHomset
     138# Experts: please redefine this properly and/or put CC/RR/... in NumberFields()
     139
     140def is_NumberFieldHomsetCodomain(codomain):
     141    from sage.rings.field import is_Field
     142    try: # is_Field does not work on gap objects, InfinityRing, ... We assume they are not number fields.
     143        if is_Field(codomain):
     144            return True
     145    except:
     146        pass   
     147    return False
     148
     149
    135150def proof_flag(t):
    136151    """
    137152    Used for easily determining the correct proof flag to use.
    class NumberField_generic(number_field_b 
    9941009            Automorphism group of Number Field in i with defining polynomial x^2 + 1
    9951010            sage: Hom(K, QuadraticField(-1, 'b'))
    9961011            Set of field embeddings from Number Field in i with defining polynomial x^2 + 1 to Number Field in b with defining polynomial x^2 + 1
    997         """
    998         import morphism
    999         return morphism.NumberFieldHomset(self, codomain)
     1012
     1013        CHECKME: handling of the case where codomain is not a number field?
     1014
     1015           sage: Hom(K, VectorSpace(QQ,3))
     1016           Set of Morphisms from Number Field in i with defining polynomial x^2 + 1 to Vector space of dimension 3 over Rational Field in Category of abelian groups
     1017           
     1018        """
     1019        if is_NumberFieldHomsetCodomain(codomain):
     1020            import morphism
     1021            return morphism.NumberFieldHomset(self, codomain)
     1022        else:
     1023            return NotImplemented
    10001024
    10011025    def _set_structure(self, from_self, to_self, unsafe_force_change=False):
    10021026        """
    class NumberField_cyclotomic(NumberField 
    62216245            sage: End(CyclotomicField(21))
    62226246            Automorphism group of Cyclotomic Field of order 21 and degree 12
    62236247        """
    6224         import morphism
    6225         return morphism.CyclotomicFieldHomset(self, codomain)
     6248        if is_NumberFieldHomsetCodomain(codomain):
     6249            import morphism
     6250            return morphism.CyclotomicFieldHomset(self, codomain)
     6251        else:
     6252            return NotImplemented
    62266253
    62276254    def is_galois(self):
    62286255        """
    class NumberField_cyclotomic(NumberField 
    62516278       """
    62526279       if not isinstance(other, NumberField_generic):
    62536280           raise ValueError, "other must be a generic number field."
    6254        return self._Hom_(other).order() > 0
     6281       return self.Hom(other).order() > 0
    62556282
    62566283    def complex_embedding(self, prec=53):
    62576284        r"""
  • sage/rings/number_field/number_field_rel.py

    diff --git a/sage/rings/number_field/number_field_rel.py b/sage/rings/number_field/number_field_rel.py
    a b class NumberField_relative(NumberField_g 
    534534            sage: type(K.Hom(K))
    535535            <class 'sage.rings.number_field.morphism.RelativeNumberFieldHomset_with_category'>
    536536        """
    537         import morphism
    538         return morphism.RelativeNumberFieldHomset(self, codomain)
     537
     538        from number_field import is_NumberFieldHomsetCodomain
     539        if is_NumberFieldHomsetCodomain(codomain):
     540            import morphism
     541            return morphism.RelativeNumberFieldHomset(self, codomain)
     542        else:
     543            return NotImplemented
    539544
    540545    def _latex_(self):
    541546        r"""