Révision 81 pobysoPythonSage/src/sageSLZ/sageSLZ.sage

sageSLZ.sage (revision 81)
12 12
    are returned.
13 13
    """
14 14
    RRR = lowerBoundSa.parent()
15
    #goldenRatioSa = RRR(5.sqrt() / 2 - 1/2)
16
    #intervalShrinkConstFactorSa = goldenRatioSa
17 15
    intervalShrinkConstFactorSa = RRR('0.5')
18 16
    absoluteErrorTypeSo = pobyso_absolute_so_so()
19 17
    currentRangeSo = pobyso_bounds_to_range_sa_so(lowerBoundSa, upperBoundSa)
......
29 27
    maxErrorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo)
30 28
    while maxErrorSa > approxPrecSa:
31 29
        sollya_lib_clear_obj(maxErrorSo)
32
        errorRatioSa = 1/(maxErrorSa/approxPrecSa).log2()
30
        sollya_lib_clear_obj(polySo)
31
        sollya_lib_clear_obj(intervalCenterSo)
32
        shrinkFactorSa = RRR('5.0')/(maxErrorSa/approxPrecSa).log2().abs()
33
        #shrinkFactorSa = 1.5/(maxErrorSa/approxPrecSa)
34
        #errorRatioSa = approxPrecSa/maxErrorSa
33 35
        #print "Error ratio: ", errorRatioSa
34
        if errorRatioSa > intervalShrinkConstFactorSa:
35
            currentUpperBoundSa = currentLowerBoundSa + \
36
                                  (currentUpperBoundSa - currentLowerBoundSa) * \
37
                                   intervalShrinkConstFactorSa
36
        
37
        if shrinkFactorSa > intervalShrinkConstFactorSa:
38
            actualShrinkFactorSa = intervalShrinkConstFactorSa
39
            #print "Fixed"
38 40
        else:
39
            currentUpperBoundSa = currentLowerBoundSa + \
41
            actualShrinkFactorSa = shrinkFactorSa
42
            #print "Computed",shrinkFactorSa,maxErrorSa
43
            #print shrinkFactorSa, maxErrorSa
44
        currentUpperBoundSa = currentLowerBoundSa + \
40 45
                                  (currentUpperBoundSa - currentLowerBoundSa) * \
41
                                  intervalShrinkConstFactorSa
42
            currentUpperBoundSa = currentLowerBoundSa + \
43
                                  (currentUpperBoundSa - currentLowerBoundSa) * \
44
                                  errorRatioSa
46
                                   actualShrinkFactorSa
45 47
        #print "Current upper bound:", currentUpperBoundSa
46 48
        sollya_lib_clear_obj(currentRangeSo)
47 49
        sollya_lib_clear_obj(polySo)
......
55 57
        maxErrorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo)
56 58
    sollya_lib_clear_obj(absoluteErrorTypeSo)
57 59
    return((polySo, currentRangeSo, intervalCenterSo, maxErrorSo))
58
    # End slz_compute_polynomial_and_interval
60
# End slz_compute_polynomial_and_interval
59 61

  
60 62
def slz_compute_scaled_function(functionSa, \
61 63
                                      lowerBoundSa, \
......
111 113
    polynomialRing = QQ[str(polyOfFloat.variables()[0])]
112 114
    return(polynomialRing(polyOfFloat))
113 115
# End slz_float_poly_of_float_to_rat_poly_of_rat
114
     
116

  
115 117
def slz_get_intervals_and_polynomials(functionSa, degreeSa, 
116 118
                                      lowerBoundSa, 
117 119
                                      upperBoundSa, floatingPointPrecSa, 
......
166 168
    realIntervalField = RealIntervalField(max(lowerBoundSa.parent().precision(),
167 169
                                              upperBoundSa.parent().precision()))
168 170
    boundsSa = pobyso_range_to_interval_so_sa(boundsSo, realIntervalField)
171
    # Compute the next upper bound.
172
    # If the error of approximation is more than half of the target,
173
    # use the same interval.
174
    # If it is less, increase it a bit.
175
    errorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo)
176
    currentErrorRatio = approxPrecSa / errorSa
177
    currentScaledUpperBoundSa = boundsSa.endpoints()[1]
178
    if currentErrorRatio  < 2 :
179
        currentScaledUpperBoundSa += \
180
            (boundsSa.endpoints()[1] - boundsSa.endpoints()[0])
181
    else:
182
        currentScaledUpperBoundSa += \
183
            (boundsSa.endpoints()[1] - boundsSa.endpoints()[0]) \
184
                         * currentErrorRatio.log2() * 2
185
    if currentScaledUpperBoundSa > scaledUpperBoundSa:
186
        currentScaledUpperBoundSa = scaledUpperBoundSa
169 187
    # Compute the other expansions.
170 188
    while boundsSa.endpoints()[1] < scaledUpperBoundSa:
171 189
        currentScaledLowerBoundSa = boundsSa.endpoints()[1]
172 190
        (polySo, boundsSo, intervalCenterSo, maxErrorSo) = \
173 191
            slz_compute_polynomial_and_interval(functionSo, degreeSo,
174 192
                                            currentScaledLowerBoundSa, 
175
                                            scaledUpperBoundSa, approxPrecSa, 
193
                                            currentScaledUpperBoundSa, 
194
                                            approxPrecSa, 
176 195
                                            internalSollyaPrecSa)
177 196
        # Change variable stuff
178 197
        changeVarExpressionSo = sollya_lib_build_function_sub(
......
182 201
        resultArray.append((polySo, polyVarChangedSo, boundsSo, \
183 202
                            intervalCenterSo, maxErrorSo))
184 203
        boundsSa = pobyso_range_to_interval_so_sa(boundsSo, realIntervalField)
204
        # Compute the next upper bound.
205
        # If the error of approximation is more than half of the target,
206
        # use the same interval.
207
        # If it is less, increase it a bit.
208
        errorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo)
209
        currentErrorRatio = approxPrecSa / errorSa
210
        if currentErrorRatio  < RR('1.5') :
211
            currentScaledUpperBoundSa = \
212
                            boundsSa.endpoints()[1] + \
213
                            (boundsSa.endpoints()[1] - boundsSa.endpoints()[0])
214
        elif currentErrorRatio < 2:
215
            currentScaledUpperBoundSa = \
216
                            boundsSa.endpoints()[1] + \
217
                            (boundsSa.endpoints()[1] - boundsSa.endpoints()[0]) \
218
                             * currentErrorRatio.log2()
219
        else:
220
            currentScaledUpperBoundSa = \
221
                            boundsSa.endpoints()[1] + \
222
                            (boundsSa.endpoints()[1] - boundsSa.endpoints()[0]) \
223
                             * currentErrorRatio.log2() * 2
224
        if currentScaledUpperBoundSa > scaledUpperBoundSa:
225
            currentScaledUpperBoundSa = scaledUpperBoundSa
185 226
    sollya_lib_clear_obj(functionSo)
186 227
    sollya_lib_clear_obj(degreeSo)
187 228
    sollya_lib_clear_obj(scaledBoundsSo)
188 229
    return(resultArray)
189
    # End slz_get_intervals_and_polynomials
230
# End slz_get_intervals_and_polynomials
190 231

  
232

  
191 233
def slz_interval_scaling_expression(boundsInterval, expVar):
192 234
    """
193 235
    Compute the scaling expression to map an interval that span only

Formats disponibles : Unified diff