Révision 285 pobysoPythonSage/src/pobyso.py
pobyso.py (revision 285) | ||
---|---|---|
102 | 102 |
sollya_lib_autoprint(arg, None) |
103 | 103 |
|
104 | 104 |
def pobyso_autoprint_so_so(arg): |
105 |
sollya_lib_autoprint(arg,None) |
|
105 |
sollya_lib_autoprint(arg, None)
|
|
106 | 106 |
|
107 | 107 |
def pobyso_bounds_to_interval_sa_sa(lowerBound, upperBound): |
108 | 108 |
""" |
... | ... | |
121 | 121 |
prec = 53 |
122 | 122 |
# Create the RealIntervalField and the interval (if possible). |
123 | 123 |
theRIF = RealIntervalField(prec) |
124 |
theRR = RealField(prec) |
|
125 |
# Try convert the lower bound to a RealField element or fail. |
|
124 | 126 |
try: |
125 |
interval = theRIF(lowerBound, upperBound)
|
|
127 |
lowerBoundRF = theRR(lowerBound)
|
|
126 | 128 |
except TypeError: |
127 |
return None |
|
128 |
else: |
|
129 |
return interval |
|
129 |
try: |
|
130 |
lowerBoundRF = theRR(str(lowerBound)) |
|
131 |
except TypeError: |
|
132 |
return None |
|
133 |
# Try convert the upper bound to a RealField element or fail. |
|
134 |
try: |
|
135 |
upperBoundRF = theRR(upperBound) |
|
136 |
except TypeError: |
|
137 |
try: |
|
138 |
upperBoundRF = theRR(str(upperBound)) |
|
139 |
except TypeError: |
|
140 |
return None |
|
141 |
return theRIF(lowerBoundRF, upperBoundRF) |
|
130 | 142 |
# End pobyso_bounds_to_interval_sa_sa |
131 | 143 |
|
132 | 144 |
def pobyso_bounds_to_range_sa_so(rnLowerBoundSa, rnUpperBoundSa, \ |
... | ... | |
232 | 244 |
return(sollya_lib_evaluate(funcSo,chvarExpSo)) |
233 | 245 |
# End pobyso_change_var_in_function_so_so |
234 | 246 |
|
247 |
def pobyso_chebyshevform_sa_sa(funcSa, degreeSa, intervalSa): |
|
248 |
""" |
|
249 |
An chebyshevnorm call with Sage arguments that returns Sage objects. |
|
250 |
To the moment only the polynomial and the delta are returned. |
|
251 |
""" |
|
252 |
# Check that funcSa is a function. |
|
253 |
if not \ |
|
254 |
sage.symbolic.callable.is_CallableSymbolicExpressionRing(parent(funcSa)): |
|
255 |
return None |
|
256 |
# Check that funcSa is an integer. |
|
257 |
try: |
|
258 |
if degreeSa != int(degreeSa): |
|
259 |
print "degreeSa is not a valid integer." |
|
260 |
return None |
|
261 |
except ValueError: |
|
262 |
print "degreeSa is not a number." |
|
263 |
return None |
|
264 |
# Create the Sollya degree... |
|
265 |
degreeSo = pobyso_constant_from_int_sa_so(degreeSa) |
|
266 |
# ...and check it. |
|
267 |
if pobyso_is_error_so_sa(degreeSo): |
|
268 |
print "Could not correctly convert degreeSa to Sollya." |
|
269 |
return None |
|
270 |
# Check that intervalSa is an interval. |
|
271 |
try: |
|
272 |
intervalSa.upper() |
|
273 |
except AttributeError: |
|
274 |
print "intervalSa is not an interval." |
|
275 |
return None |
|
276 |
# Convert the Sage polynomial into a Sollya polynomial. |
|
277 |
# Convert the Sage function into a Sollya function. |
|
278 |
funcAsStringSa = funcSa._assume_str().replace('_SAGE_VAR_', '') |
|
279 |
funcSo = pobyso_parse_string_sa_so(funcAsStringSa) |
|
280 |
if not pobyso_obj_is_function_so_sa(funcSo): |
|
281 |
sollya_lib_clear_obj(funcSo) |
|
282 |
print "The Sollya object created from the function is not a function." |
|
283 |
return None |
|
284 |
#pobyso_autoprint(funcSo) |
|
285 |
# Convert the Sage interval into a Sollya range. |
|
286 |
rangeSo = pobyso_interval_to_range_sa_so(intervalSa) |
|
287 |
if not pobyso_is_range_so_sa(rangeSo): |
|
288 |
sollya_lib_clear_obj(funcSo) |
|
289 |
sollya_lib_clear_obj(rangeSo) |
|
290 |
print "The Sollya object created from the interval is not a range." |
|
291 |
return None |
|
292 |
#pobyso_autoprint(rangeSo) |
|
293 |
retValSo = sollya_lib_chebyshevform(funcSo, |
|
294 |
degreeSo, |
|
295 |
rangeSo, |
|
296 |
None) |
|
297 |
sollya_lib_clear_obj(funcSo) |
|
298 |
sollya_lib_clear_obj(degreeSo) |
|
299 |
sollya_lib_clear_obj(rangeSo) |
|
300 |
if pobyso_is_error_so_sa(retValSo): |
|
301 |
sollya_lib_clear_obj(retValSo) |
|
302 |
print "Could not compute the Chebyshev form." |
|
303 |
return None |
|
304 |
#pobyso_autoprint(retValSo) |
|
305 |
## Get the list of Sollya objects returned by sollya_lib_chebyshevform |
|
306 |
retValSa = pobyso_get_list_elements_so_so(retValSo) |
|
307 |
if retValSa[1] != 4: |
|
308 |
print "Invalid number of elements in the Chebyshev form." |
|
309 |
sollya_lib_clear_obj(retValSo) |
|
310 |
return None |
|
311 |
## Convert all the element of the retValSa[0] array of Sollya objects |
|
312 |
# into their Sage counterparts. |
|
313 |
polySa = pobyso_float_poly_so_sa(retValSa[0][0]) |
|
314 |
if not pobyso_is_poly_sa_sa(polySa): |
|
315 |
print "Conversion of the polynomial of the Chebyshev form failed." |
|
316 |
sollya_lib_clear_obj(retValSo) |
|
317 |
return None |
|
318 |
deltaSa = pobyso_get_interval_from_range_so_sa(retValSa[0][2]) |
|
319 |
if not pobyso_is_interval_sa_sa(deltaSa): |
|
320 |
print "Conversion of the delta interval of the Chebyshev form failed." |
|
321 |
sollya_lib_clear_obj(retValSo) |
|
322 |
return None |
|
323 |
sollya_lib_clear_obj(retValSo) |
|
324 |
return(polySa,deltaSa) |
|
325 |
# End pobyso_chebyshevform_sa_sa. |
|
326 |
|
|
235 | 327 |
def pobyso_chebyshevform_so_so(functionSo, degreeSo, intervalSo): |
236 | 328 |
resultSo = sollya_lib_chebyshevform(functionSo, degreeSo, intervalSo) |
237 | 329 |
return(resultSo) |
... | ... | |
270 | 362 |
|
271 | 363 |
def pobyso_clear_taylorform_sa_so(taylorFormSaSo): |
272 | 364 |
""" |
273 |
This method is rapper around pobyso_clear_list_elements_sa_so. |
|
365 |
This method is wrapper around pobyso_clear_list_elements_sa_so.
|
|
274 | 366 |
It is a legacy method left here since it may be used in existing code |
275 | 367 |
where Taylor forms are used as Sage lists obtained by converting |
276 | 368 |
Sollya Taylor forms (a list made of: |
... | ... | |
650 | 742 |
#print polyRingSa |
651 | 743 |
# Do not use the polynomial(expressionSa, ring=polyRingSa) form! |
652 | 744 |
polynomialSa = polyRingSa(expressionSa) |
653 |
polyCoeffsListSa = polynomialSa.coefficients() |
|
745 |
#polyCoeffsListSa = polynomialSa.coefficients()
|
|
654 | 746 |
#for coeff in polyCoeffsListSa: |
655 | 747 |
# print coeff.abs().n() |
656 | 748 |
return polynomialSa |
... | ... | |
988 | 1080 |
""" |
989 | 1081 |
Convert a Sollya polynomial into a Sage polynomial. |
990 | 1082 |
Legacy function. Use pobyso_float_poly_so_sa() instead. |
991 |
""" |
|
1083 |
""" |
|
1084 |
print "Deprecated: use pobyso_float_poly_so_sa() instead." |
|
992 | 1085 |
return pobyso_float_poly_so_sa(polySo,realFieldSa) |
993 | 1086 |
# End pobyso_get_poly_so_sa |
994 | 1087 |
|
... | ... | |
1347 | 1440 |
return False |
1348 | 1441 |
# End pobyso_is_floating_piont_number_sa_sa |
1349 | 1442 |
|
1443 |
def pobyso_is_interval_sa_sa(objectSa): |
|
1444 |
""" |
|
1445 |
Check that objectSa is an interval. |
|
1446 |
""" |
|
1447 |
try: |
|
1448 |
objectSa.upper() |
|
1449 |
except AttributeError: |
|
1450 |
return False |
|
1451 |
return True |
|
1452 |
|
|
1453 |
def pobyso_is_poly_sa_sa(objectSa): |
|
1454 |
""" |
|
1455 |
Check if an object is a polynomial. |
|
1456 |
""" |
|
1457 |
try: |
|
1458 |
coefficientsListSa = objectSa |
|
1459 |
if len(objectSa.coefficients()) < 0: |
|
1460 |
return False |
|
1461 |
except AttributeError: |
|
1462 |
return False |
|
1463 |
return True |
|
1464 |
# End pobyso_is_poly_sa_sa |
|
1465 |
|
|
1350 | 1466 |
def pobyso_is_range_so_sa(rangeCandidateSo): |
1351 | 1467 |
""" |
1352 | 1468 |
Thin wrapper over sollya_lib_is_range. |
... | ... | |
2110 | 2226 |
funcSa, |
2111 | 2227 |
intervalSa, |
2112 | 2228 |
errorTypeSa=SOLLYA_ABSOLUTE, |
2113 |
accuracySa=RR(2^-40)):
|
|
2229 |
accuracySa=RR(2**-40)):
|
|
2114 | 2230 |
""" |
2115 | 2231 |
An supnorm call with Sage arguments. |
2116 | 2232 |
""" |
Formats disponibles : Unified diff