Révision 186 pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage

sagePolynomialOperations.sage (revision 186)
88 88
        print    
89 89
# End spo_add_polynomial_coeffs_to_matrix_row
90 90

  
91
def spo_float_poly_of_float_to_rat_poly_of_rat(polyOfFloat):
92
    """
93
    Create a polynomial over the rationals from a polynomial over
94
    a RealField.
95
    Important warning: default Sage behavior is to convert coefficients
96
    using continued fractions instead of making a simple conversion
97
    with a powers of two at denominators (and possible simplification).
98
    Hence conversion is not exact but with a relative error around 10^(-521).
99
    """
100
    ratPolynomialRing = QQ[str(polyOfFloat.variables()[0])]
101
    return(ratPolynomialRing(polyOfFloat))
102
# End spo_float_poly_of_float_to_rat_poly_of_rat.
103

  
104
def spo_float_poly_of_float_to_rat_poly_of_rat_pow_two(polyOfFloat):
105
    """
106
    Create a polynomial over the rationals from a polynomial over
107
    a RealField where all denominators are
108
    powers of two.
109
    Allows for exact conversions (and lcm computation of the coefficients
110
    denominator).
111
    """
112
    polyVariable = polyOfFloat.variables()[0] 
113
    RPR = QQ[str(polyVariable)]
114
    polyCoeffs      = polyOfFloat.coefficients()
115
    #print polyCoeffs
116
    polyExponents   = polyOfFloat.exponents()
117
    #print polyExponents
118
    polyDenomPtwoCoeffs = []
119
    for coeff in polyCoeffs:
120
        polyDenomPtwoCoeffs.append(sno_float_to_rat_pow_of_two_denom(coeff))
121
        #print "Converted coefficient:", sno_float_to_rat_pow_of_two_denom(coeff),
122
        #print type(sno_float_to_rat_pow_of_two_denom(coeff))
123
    ratPoly = RPR(0)
124
    #print type(ratPoly)
125
    ## !!! CAUTION !!! Do not use the RPR(coeff * polyVariagle^exponent)
126
    #  construction.
127
    #  The coefficient becomes plainly wrong when exponent == 0.
128
    #  No clue as to why.
129
    for coeff, exponent in zip(polyDenomPtwoCoeffs, polyExponents):
130
        ratPoly += coeff * RPR(polyVariable^exponent)
131
    return ratPoly
132
# End slz_float_poly_of_float_to_rat_poly_of_rat.
133

  
134

  
91 135
def spo_get_coefficient_for_monomial(monomialsList, coefficientsList, monomial):
92 136
    """
93 137
    Get, for a polynomial, the coefficient for a given monomial.

Formats disponibles : Unified diff