Ticket #10850: trac_10850.patch

File trac_10850.patch, 4.2 KB (added by fwclarke, 11 years ago)
  • sage/rings/morphism.pyx

    # HG changeset patch
    # User Francis Clarke <francis.w.clarke@gmail.com>
    # Date 1298627770 0
    # Node ID 05a4991534ec0c8ac25930628a45d836f63b7795
    # Parent  2fcb23bf655ccafad123a763050806d8e1360cb7
    #10850 composition and comparison of number-field homomorphisms
    
    diff -r 2fcb23bf655c -r 05a4991534ec sage/rings/morphism.pyx
    a b  
    657657        """
    658658        If ``homset`` is a homset of rings and ``right`` is a
    659659        ring homomorphism given by the images of generators,
    660         the composition with ``self`` will be of the same type.
     660        (indirectly in the case of homomorphisms from relative
     661        number fields), the composition with ``self`` will be
     662        of the appropriate type.
     663
    661664        Otherwise, a formal composite map is returned.
    662665
    663666        EXAMPLES::
     
    672675              To:   Fraction Field of Multivariate Polynomial Ring in a, b over Rational Field
    673676              Defn: x |--> a + b
    674677                    y |--> a - b
     678
     679        When ``right`` is defined by the images of generators, the
     680        result has the type of a homomorphism between its domain and
     681        codomain::
     682
     683            sage: C = CyclotomicField(24)
     684            sage: f = End(C)[1]
     685            sage: type(f*f) == type(f)
     686            True
     687       
     688        An example where the domain of ``right`` is a relative number field::
     689            sage: PQ.<X> = QQ[]
     690            sage: K.<a, b> = NumberField([X^2 - 2, X^2 - 3])
     691            sage: e, u, v, w = End(K)
     692            sage: u*v
     693            Relative number field endomorphism of Number Field in a with defining polynomial X^2 - 2 over its base field
     694              Defn: a |--> -a
     695                    b |--> b
     696
     697        An example where ``right`` is not a ring homomorphism::
     698
    675699            sage: from sage.categories.morphism import SetMorphism
    676700            sage: h = SetMorphism(Hom(R,S,Rings()), lambda p: p[0])
    677701            sage: g*h
     
    686710                      From: Multivariate Polynomial Ring in a, b over Rational Field
    687711                      To:   Fraction Field of Multivariate Polynomial Ring in a, b over Rational Field
    688712
    689         AUTHOR:
     713        AUTHORS:
    690714
    691715        -- Simon King (2010-05)
     716        -- Francis Clarke (2011-02)
    692717
    693718        """
    694719        from sage.all import Rings
    695         if isinstance(right, RingHomomorphism_im_gens) and homset.homset_category().is_subcategory(Rings()):
    696             try:
    697                 return RingHomomorphism_im_gens(homset, [self(g) for g in right.im_gens()])
    698             except ValueError:
    699                 pass
     720        if homset.homset_category().is_subcategory(Rings()):
     721            if isinstance(right, RingHomomorphism_im_gens):
     722                try:
     723                    return homset([self(g) for g in right.im_gens()])
     724                except ValueError:
     725                    pass
     726            from sage.rings.number_field.morphism import RelativeNumberFieldHomomorphism_from_abs
     727            if isinstance(right, RelativeNumberFieldHomomorphism_from_abs):
     728                try:
     729                    return homset(self*right.abs_hom())
     730                except ValueError:
     731                    pass
    700732        return sage.categories.map.Map._composition_(self, right, homset)
    701733
    702734    def is_injective(self):
  • sage/rings/number_field/morphism.py

    diff -r 2fcb23bf655c -r 05a4991534ec sage/rings/number_field/morphism.py
    a b  
    616616        self.__im_gens = v
    617617        return v
    618618
     619    def __cmp__(self, other):
     620        """
     621        Compare
     622        EXAMPLES:
     623            sage: K.<a, b> = NumberField([x^2 - 2, x^2 - 3])
     624            sage: e, u, v, w = End(K)
     625            sage: all([u^2 == e, u*v == w, u != e])
     626            True
     627        """
     628        if not isinstance(other, RelativeNumberFieldHomomorphism_from_abs):
     629            return cmp(type(self), type(other))
     630        return cmp(self.abs_hom(), other.abs_hom())
     631
    619632    def _repr_defn(self):
    620633        r"""
    621634        Return a string describing the images of the generators under this map.