Exemplo n.º 1
0
    def _coerce_impl(self, x):
        """
        Check to see if we can coerce ``x`` into a homomorphism with the
        correct rings.

        EXAMPLES::

            sage: H = Hom(ZZ, QQ)
            sage: phi = H([1])
            sage: H2 = Hom(QQ, QQ)
            sage: phi2 = H2(phi); phi2 # indirect doctest
            Ring endomorphism of Rational Field
              Defn: 1 |--> 1
            sage: H(phi2) # indirect doctest
            Ring morphism:
              From: Integer Ring
              To:   Rational Field
              Defn: 1 |--> 1
        """
        if not isinstance(x, morphism.RingHomomorphism):
            raise TypeError
        if x.parent() is self:
            return x
        # Case 1: the parent fits
        if x.parent() == self:
            if isinstance(x, morphism.RingHomomorphism_im_gens):
                return morphism.RingHomomorphism_im_gens(self, x.im_gens())
            elif isinstance(x, morphism.RingHomomorphism_cover):
                return morphism.RingHomomorphism_cover(self)
            elif isinstance(x, morphism.RingHomomorphism_from_base):
                return morphism.RingHomomorphism_from_base(
                    self, x.underlying_map())
        # Case 2: unique extension via fraction field
        try:
            if isinstance(x, morphism.RingHomomorphism_im_gens) and x.domain(
            ).fraction_field().has_coerce_map_from(self.domain()):
                return morphism.RingHomomorphism_im_gens(self, x.im_gens())
        except StandardError:
            pass
        # Case 3: the homomorphism can be extended by coercion
        try:
            return x.extend_codomain(self.codomain()).extend_domain(
                self.domain())
        except StandardError:
            pass
        # Last resort, case 4: the homomorphism is induced from the base ring
        if self.domain() == self.domain().base() or self.codomain(
        ) == self.codomain().base():
            raise TypeError
        try:
            x = self.domain().base().Hom(self.codomain().base())(x)
            return morphism.RingHomomorphism_from_base(self, x)
        except StandardError:
            raise TypeError
Exemplo n.º 2
0
    def cover(self):
        r"""
        The covering ring homomorphism `R \to R/I`, equipped with a
        section.

        EXAMPLES::

            sage: R = ZZ.quo(3*ZZ)
            sage: pi = R.cover()
            sage: pi
            Ring morphism:
              From: Integer Ring
              To:   Ring of integers modulo 3
              Defn: Natural quotient map
            sage: pi(5)
            2
            sage: l = pi.lift()

        EXAMPLES::

            sage: R.<x,y>  = PolynomialRing(QQ)
            sage: Q = R.quo( (x^2,y^2) )
            sage: pi = Q.cover()
            sage: pi(x^3+y)
            ybar
            sage: l = pi.lift(x+y^3)
            sage: l
            x
            sage: l = pi.lift(); l
            Set-theoretic ring morphism:
              From: Quotient of Multivariate Polynomial Ring in x, y over Rational Field by the ideal (x^2, y^2)
              To:   Multivariate Polynomial Ring in x, y over Rational Field
              Defn: Choice of lifting map
            sage: l(x+y^3)
            x
        """
        try:
            return self.__cover
        except AttributeError:
            import morphism
            pi = morphism.RingHomomorphism_cover(self.__R.Hom(self))
            lift = self.lifting_map()
            pi._set_lift(lift)
            self.__cover = pi
            return self.__cover
Exemplo n.º 3
0
 def _coerce_impl(self, x):
     if not isinstance(x, morphism.RingHomomorphism):
         raise TypeError
     if x.parent() is self:
         return x
     # Case 1: the parent fits
     if x.parent() == self:
         if isinstance(x, morphism.RingHomomorphism_im_gens):
             return morphism.RingHomomorphism_im_gens(self, x.im_gens())
         elif isinstance(x, morphism.RingHomomorphism_cover):
             return morphism.RingHomomorphism_cover(self)
         elif isinstance(x, morphism.RingHomomorphism_from_base):
             return morphism.RingHomomorphism_from_base(
                 self, x.underlying_map())
     # Case 2: unique extension via fraction field
     try:
         if isinstance(x, morphism.RingHomomorphism_im_gens) and x.domain(
         ).fraction_field().has_coerce_map_from(self.domain()):
             return morphism.RingHomomorphism_im_gens(self, x.im_gens())
     except:
         pass
     # Case 3: the homomorphism can be extended by coercion
     try:
         return x.extend_codomain(self.codomain()).extend_domain(
             self.domain())
     except:
         pass
     # Last resort, case 4: the homomorphism is induced from the base ring
     if self.domain() == self.domain().base() or self.codomain(
     ) == self.codomain().base():
         raise TypeError
     try:
         x = self.domain().base().Hom(self.codomain().base())(x)
         return morphism.RingHomomorphism_from_base(self, x)
     except:
         raise TypeError