Révision 120
pobysoPythonSage/src/sageSLZ/sageSLZ.sage (revision 120) | ||
---|---|---|
162 | 162 |
maxErrorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo) |
163 | 163 |
while maxErrorSa > approxPrecSa: |
164 | 164 |
#print "++Approximation error:", maxErrorSa |
165 |
sollya_lib_clear_obj(maxErrorSo) |
|
166 | 165 |
sollya_lib_clear_obj(polySo) |
167 | 166 |
sollya_lib_clear_obj(intervalCenterSo) |
167 |
sollya_lib_clear_obj(maxErrorSo) |
|
168 | 168 |
shrinkFactorSa = RRR('5')/(maxErrorSa/approxPrecSa).log2().abs() |
169 | 169 |
#shrinkFactorSa = 1.5/(maxErrorSa/approxPrecSa) |
170 | 170 |
#errorRatioSa = approxPrecSa/maxErrorSa |
... | ... | |
182 | 182 |
actualShrinkFactorSa |
183 | 183 |
#print "Current upper bound:", currentUpperBoundSa |
184 | 184 |
sollya_lib_clear_obj(currentRangeSo) |
185 |
sollya_lib_clear_obj(polySo) |
|
186 | 185 |
if currentUpperBoundSa <= currentLowerBoundSa or \ |
187 | 186 |
currentUpperBoundSa == currentLowerBoundSa.nextabove(): |
188 | 187 |
sollya_lib_clear_obj(absoluteErrorTypeSo) |
... | ... | |
195 | 194 |
currentUpperBoundSa) |
196 | 195 |
# print "New interval:", |
197 | 196 |
# pobyso_autoprint(currentRangeSo) |
197 |
#print "Second Taylor expansion call." |
|
198 | 198 |
(polySo, intervalCenterSo, maxErrorSo) = \ |
199 | 199 |
pobyso_taylor_expansion_no_change_var_so_so(functionSo, degreeSo, |
200 | 200 |
currentRangeSo, |
... | ... | |
341 | 341 |
- the corresponding approximation error. |
342 | 342 |
TODO: fix endless looping for some parameters sets. |
343 | 343 |
""" |
344 |
resultArray = [] |
|
344 | 345 |
# Set Sollya to the necessary internal precision. |
346 |
precChangedSa = False |
|
345 | 347 |
currentSollyaPrecSo = pobyso_get_prec_so() |
346 | 348 |
currentSollyaPrecSa = pobyso_constant_from_int_so_sa(currentSollyaPrecSo) |
347 | 349 |
if internalSollyaPrecSa > currentSollyaPrecSa: |
348 | 350 |
pobyso_set_prec_sa_so(internalSollyaPrecSa) |
351 |
precChangedSa = True |
|
349 | 352 |
# |
350 | 353 |
x = functionSa.variables()[0] # Actual variable name can be anything. |
351 | 354 |
# Scaled function: [1=,2] -> [1,2]. |
... | ... | |
356 | 359 |
upperBoundSa, \ |
357 | 360 |
floatingPointPrecSa) |
358 | 361 |
# |
359 |
resultArray = [] |
|
360 |
# |
|
361 | 362 |
print "Approximation precision: ", RR(approxPrecSa) |
362 | 363 |
# Prepare the arguments for the Taylor expansion computation with Sollya. |
363 | 364 |
functionSo = pobyso_parse_string_sa_so(fff._assume_str()) |
... | ... | |
371 | 372 |
approxPrecSa, internalSollyaPrecSa) |
372 | 373 |
if polySo is None: |
373 | 374 |
print "slz_get_intervals_and_polynomials: Aborting and returning None!" |
374 |
if internalSollyaPrecSa != currentSollyaPrecSa:
|
|
375 |
pobyso_set_prec_sa_so(currentSollyaPrecSa)
|
|
375 |
if precChangedSa:
|
|
376 |
pobyso_set_prec_so_so(currentSollyaPrecSo)
|
|
376 | 377 |
sollya_lib_clear_obj(currentSollyaPrecSo) |
377 | 378 |
sollya_lib_clear_obj(functionSo) |
378 | 379 |
sollya_lib_clear_obj(degreeSo) |
... | ... | |
401 | 402 |
sollya_lib_clear_obj(scaledBoundsSo) |
402 | 403 |
#print "Approximation error:", errorSa |
403 | 404 |
return resultArray |
404 |
# Compute the next upper bound. |
|
405 |
# The returned interval upper bound does not reach the requested upper |
|
406 |
# upper bound: compute the next upper bound. |
|
405 | 407 |
# The following ratio is always >= 1 |
406 | 408 |
currentErrorRatio = approxPrecSa / errorSa |
407 | 409 |
# Starting point for the next upper bound. |
pobysoPythonSage/src/testPobyso.sage (revision 120) | ||
---|---|---|
66 | 66 |
return timing |
67 | 67 |
# End test_pobyso_bounds_to_range_sa_so |
68 | 68 |
|
69 |
def test_pobyso_clear_taylorform_sa_so(repeat=1000, number=10): |
|
70 |
functionName = inspect.stack()[0][3] |
|
71 |
print "Running", inspect.stack()[0][3], "..." |
|
72 |
intervalSa = RIF(1,2) |
|
73 |
functionSo = pobyso_parse_string("exp(x)") |
|
74 |
degreeSo = pobyso_ |
|
75 |
#RealIntervalField |
|
76 |
pointSo = pobyso_constant_sa_so(RR("1.5")) |
|
77 |
intervalSo = pobyso_interval_to_range_sa_so(intervalSa) |
|
78 |
# |
|
79 |
def test(lowerBoundSa, upperBoundSa): |
|
80 |
taylorformSo = pobyso_taylorform_so_so(functionSo, |
|
81 |
degreeSo, |
|
82 |
pointSo, |
|
83 |
intervalSo) |
|
84 |
sollya_lib_clear_obj(rangeSo) |
|
85 |
# |
|
86 |
wrapped = test_pobyso_wrapper(test,lowerBoundSa, upperBoundSa) |
|
87 |
timing = min(timeit.repeat(wrapped, repeat=repeat, number=number)) |
|
88 |
# |
|
89 |
precSo = pobyso_get_prec_so() |
|
90 |
#pobyso_autoprint(precSo) |
|
91 |
sollya_lib_clear_obj(precSo) |
|
92 |
print "\t...", functionName, "done." |
|
93 |
return timing |
|
94 |
# End test_pobyso_bounds_to_range_sa_so |
|
95 |
|
|
69 | 96 |
def test_pobyso_get_list_elements_so_so(repeat = 1000, number=10): |
70 | 97 |
functionName = inspect.stack()[0][3] |
71 | 98 |
print "Running", functionName, "..." |
... | ... | |
85 | 112 |
return timing |
86 | 113 |
# End test_pobyso_get_list_elements |
87 | 114 |
|
88 |
def test_pobyso_get_prec_so_sa(iterationsNum=10000): |
|
89 |
print "Running", inspect.stack()[0][3] |
|
90 |
for index in xrange(0,iterationsNum): |
|
115 |
def test_pobyso_get_prec_so_sa(repeat=1000, number=10): |
|
116 |
functionName = inspect.stack()[0][3] |
|
117 |
print "Running", functionName, "..." |
|
118 |
def test(): |
|
91 | 119 |
precSa = pobyso_get_prec_so_sa() |
120 |
wrapped = test_pobyso_wrapper(test) |
|
121 |
timing = min(timeit.repeat(wrapped, repeat=repeat, number=number)) |
|
122 |
print "\t...", functionName, "done." |
|
123 |
return timing |
|
92 | 124 |
# End test_pobyso_get_prec_so_sa |
93 | 125 |
|
94 |
def test_pobyso_get_prec_of_constant_so_sa(iterationsNum=10000): |
|
95 |
print "Running", inspect.stack()[0][3] |
|
96 |
constSo = pobyso_constant_from_int_sa_so(2) |
|
97 |
for index in xrange(0,iterationsNum): |
|
126 |
def test_pobyso_get_prec_of_constant_so_sa(repeat=1000, number=10): |
|
127 |
functionName = inspect.stack()[0][3] |
|
128 |
print "Running", functionName, "..." |
|
129 |
constSo = pobyso_constant_1_sa_so() |
|
130 |
def test(): |
|
98 | 131 |
precSa = pobyso_get_prec_of_constant_so_sa(constSo) |
132 |
wrapped = test_pobyso_wrapper(test) |
|
133 |
timing = min(timeit.repeat(wrapped, repeat=repeat, number=number)) |
|
134 |
sollya_lib_clear_obj(constSo,None) |
|
135 |
print "\t...", functionName, "done." |
|
136 |
return timing |
|
99 | 137 |
sollya_lib_clear_obj(constSo) |
100 | 138 |
# End test_pobyso_get_prec_of_constant_so_sa |
101 | 139 |
|
... | ... | |
146 | 184 |
return timing |
147 | 185 |
# End test_pobyso_taylor_expansion_no_change_var_so_so |
148 | 186 |
|
149 |
def test_pobyso_taylor_form_so_so_2(repeat=1000, number=10):
|
|
187 |
def test_pobyso_taylorform_so_so_2(repeat=1000, number=10): |
|
150 | 188 |
functionName = inspect.stack()[0][3] |
151 | 189 |
print "Running", functionName, "..." |
152 | 190 |
functionSo = pobyso_parse_string('exp(x)') |
... | ... | |
182 | 220 |
wrapped = test_pobyso_wrapper(test) |
183 | 221 |
timing = timeit.timeit(wrapped, number=executionsNum) |
184 | 222 |
return timing |
185 |
print "\t...testPobyso loaded" |
|
223 |
print "\t...testPobyso loaded" |
|
224 |
|
pobysoPythonSage/src/pobyso.py (revision 120) | ||
---|---|---|
1076 | 1076 |
# pobyso_get_list_elements_so_so clears taylorFormSo. |
1077 | 1077 |
(taylorFormListSaSo, numElementsSa, isEndEllipticSa) = \ |
1078 | 1078 |
pobyso_get_list_elements_so_so(taylorFormSo) |
1079 |
polySo = sollya_lib_copy_obj(taylorFormListSaSo[0]) |
|
1080 |
#print "Num elements:", numElementsSa |
|
1079 | 1081 |
sollya_lib_clear_obj(taylorFormSo) |
1080 |
polySo = sollya_lib_copy_obj(taylorFormListSaSo[0]) |
|
1081 | 1082 |
#polySo = taylorFormListSaSo[0] |
1082 | 1083 |
#errorRangeSo = sollya_lib_copy_obj(taylorFormListSaSo[2]) |
1083 | 1084 |
errorRangeSo = taylorFormListSaSo[2] |
Formats disponibles : Unified diff