Ticket #6496: 13222.patch

File 13222.patch, 7.1 KB (added by lftabera, 12 years ago)
  • sage/rings/polynomial/multi_polynomial.pyx

    # HG changeset patch
    # User Luis Felipe Tabera Alonso <lftabera@yahoo.es>
    # Date 1257805662 28800
    # Node ID 3ee53edf6dc9ef6afed29a9bc14f3cca8d7307e8
    # Parent  f872a92f5f9afff4b4971afc82bf9270faec269b
    user: Luis Felipe Tabera Alonso <lftabera@yahoo.es>
    branch 'default'
    changed sage/rings/polynomial/multi_polynomial.pyx
    changed sage/rings/polynomial/multi_polynomial_libsingular.pyx
    
    diff -r f872a92f5f9a -r 3ee53edf6dc9 sage/rings/polynomial/multi_polynomial.pyx
    a b  
    10401040        from sage.structure.factorization import Factorization
    10411041        return Factorization(v, unit)
    10421042
    1043    
    1044            
     1043    def denominator(self):
     1044        """
     1045        Return a denominator of self.
     1046
     1047        First, the lcm of the denominators of the entries of self
     1048        is computed and returned. If this computation fails, the
     1049        unit of the parent of self is returned.
     1050
     1051        Note that some subclases may implement its own denominator
     1052        function.
     1053
     1054        .. warning::
     1055
     1056           This is not the denominator of the rational function
     1057           defined by self, which would always be 1 since self is a
     1058           polynomial.
     1059
     1060        EXAMPLES:
     1061
     1062        First we compute the denominator of a polynomial with
     1063        integer coefficients, which is of course 1.
     1064
     1065        ::
     1066
     1067            sage: R.<x,y> = ZZ[]
     1068            sage: f = x^3 + 17*y + x + y
     1069            sage: f.denominator()
     1070            1
     1071
     1072        Next we compute the denominator of a polynomial over a number field.
     1073
     1074        ::
     1075
     1076            sage: R.<x,y> = NumberField(symbolic_expression(x^2+3)  ,'a')['x,y']
     1077            sage: f = (1/17)*x^19 + (1/6)*y - (2/3)*x + 1/3; f
     1078            1/17*x^19 - 2/3*x + 1/6*y + 1/3
     1079            sage: f.denominator()
     1080            102
     1081
     1082        Finally, we try to compute the denominator of a polynomial with
     1083        coefficients in the real numbers, which is a ring whose elements do
     1084        not have a denominator method.
     1085
     1086        ::
     1087
     1088            sage: R.<a,b,c> = RR[]
     1089            sage: f = a + b + RR('0.3'); f
     1090            a + b + 0.300000000000000
     1091            sage: f.denominator()
     1092            1.00000000000000
     1093        """
     1094        if self.degree() == -1:
     1095            return 1
     1096        #R was defined for univariate polynomials. Is it useless?
     1097        #R = self.base_ring()
     1098        x = self.coefficients()
     1099        try:
     1100            d = x[0].denominator()
     1101            for y in x:
     1102                d = d.lcm(y.denominator())
     1103            return d
     1104        except(AttributeError):
     1105            return self.parent().one_element()
     1106
     1107    def numerator(self):
     1108        """
     1109        Return a numerator of self computed as self * self.denominator()
     1110
     1111        Note that some subclases may implement its own numerator
     1112        function.
     1113
     1114        .. warning::
     1115
     1116           This is not the numerator of the rational function
     1117           defined by self, which would always be self since self is a
     1118           polynomial.
     1119
     1120        EXAMPLES:
     1121
     1122        First we compute the numerator of a polynomial with
     1123        integer coefficients, which is of course self.
     1124
     1125        ::
     1126
     1127            sage: R.<x, y> = ZZ[]
     1128            sage: f = x^3 + 17*x + y + 1
     1129            sage: f.numerator()
     1130            x^3 + 17*x + y + 1
     1131            sage: f == f.numerator()
     1132            True
     1133
     1134        Next we compute the numerator of a polynomial over a number field.
     1135
     1136        ::
     1137
     1138            sage: R.<x,y> = NumberField(symbolic_expression(x^2+3)  ,'a')['x,y']
     1139            sage: f = (1/17)*y^19 - (2/3)*x + 1/3; f
     1140            1/17*y^19 - 2/3*x + 1/3
     1141            sage: f.numerator()
     1142            3*y^19 - 34*x + 17
     1143            sage: f == f.numerator()
     1144            False
     1145
     1146        We try to compute the numerator of a polynomial with coefficients in
     1147        the finite field of 3 elements.
     1148
     1149        ::
     1150
     1151            sage: K.<x,y,z> = GF(3)['x, y, z']
     1152            sage: f = 2*x*z + 2*z^2 + 2*y + 1; f
     1153            -x*z - z^2 - y + 1
     1154            sage: f.numerator()
     1155            -x*z - z^2 - y + 1
     1156
     1157        We check that the computation the numerator and denominator
     1158        are valid
     1159
     1160        ::
     1161
     1162            sage: K=NumberField(symbolic_expression('x^3+2'),'a')['x']['s,t']
     1163            sage: f=K.random_element()
     1164            sage: f.numerator() / f.denominator() == f
     1165            True
     1166            sage: R=RR['x,y,z']
     1167            sage: f=R.random_element()
     1168            sage: f.numerator() / f.denominator() == f
     1169            True
     1170        """
     1171        return self * self.denominator()
     1172
     1173
    10451174cdef remove_from_tuple(e, int ind):
    10461175    w = list(e)
    10471176    del w[ind]
  • sage/rings/polynomial/multi_polynomial_libsingular.pyx

    diff -r f872a92f5f9a -r 3ee53edf6dc9 sage/rings/polynomial/multi_polynomial_libsingular.pyx
    a b  
    43034303            i.append( new_MP(self._parent, pDiff(self._poly, k)))
    43044304
    43054305        return i
    4306        
     4306
     4307
     4308    def numerator(self):
     4309        """
     4310        Return a numerator of self computed as self * self.denominator()
     4311
     4312        If the base_field of self is the Rational Field then the
     4313        numerator is a polynomial whose base_ring is the Integer Ring,
     4314        this is done for compatibility to the univariate case.
     4315
     4316    .. warning::
     4317
     4318        This is not the numerator of the rational function
     4319        defined by self, which would always be self since self is a
     4320        polynomial.
     4321
     4322    EXAMPLES:
     4323
     4324    First we compute the numerator of a polynomial with
     4325    integer coefficients, which is of course self.
     4326
     4327    ::
     4328
     4329        sage: R.<x, y> = ZZ[]
     4330        sage: f = x^3 + 17*y + 1
     4331        sage: f.numerator()
     4332        x^3 + 17*y + 1
     4333        sage: f == f.numerator()
     4334        True
     4335
     4336    Next we compute the numerator of a polynomial with rational
     4337    coefficients.
     4338
     4339    ::
     4340
     4341        sage: R.<x,y> = PolynomialRing(QQ)
     4342        sage: f = (1/17)*x^19 - (2/3)*y + 1/3; f
     4343        1/17*x^19 - 2/3*y + 1/3
     4344        sage: f.numerator()
     4345        3*x^19 - 34*y + 17
     4346        sage: f == f.numerator()
     4347        False
     4348        sage: f.numerator().base_ring()
     4349        Integer Ring
     4350
     4351    We check that the computation the numerator and denominator
     4352    are valid
     4353
     4354    ::
     4355
     4356        sage: K=QQ['x,y']
     4357        sage: f=K.random_element()
     4358        sage: f.numerator() / f.denominator() == f
     4359        True
     4360        """
     4361        if self.base_ring() == RationalField():
     4362            #This part is for compatibility with the univariate case,
     4363            #where the numerator of a polynomial over RationalField
     4364            #is a polynomial over IntegerRing
     4365            integer_polynomial_ring = MPolynomialRing_libsingular(ZZ,\
     4366            self.parent().ngens(), self.parent().gens(), order =\
     4367            self.parent().term_order())
     4368            return integer_polynomial_ring(self * self.denominator())
     4369        else:
     4370            return self * self.denominator()
     4371
     4372
    43074373def unpickle_MPolynomial_libsingular(MPolynomialRing_libsingular R, d):
    43084374    """
    43094375    Deserialize an ``MPolynomial_libsingular`` object