Révision 56 pobysoPythonSage/src/pobyso.py
pobyso.py (revision 56) | ||
---|---|---|
74 | 74 |
SOLLYA_BASE_FUNC_TAN, |
75 | 75 |
SOLLYA_BASE_FUNC_TANH, |
76 | 76 |
SOLLYA_BASE_FUNC_TRIPLEDOUBLE) = map(int,xrange(44)) |
77 |
print "\nSuperficial pobyso check..." |
|
77 | 78 |
print "First constant - SOLLYA_BASE_FUNC_ABS: ", SOLLYA_BASE_FUNC_ABS |
78 | 79 |
print "Last constant - SOLLYA_BASE_FUNC_TRIPLEDOUBLE: ", SOLLYA_BASE_FUNC_TRIPLEDOUBLE |
79 | 80 |
|
... | ... | |
298 | 299 |
""" Legacy function. See pobyso_get_constant_as_rn_so_sa. """ |
299 | 300 |
return(pobyso_get_constant_as_rn_so_sa(ctExp)) |
300 | 301 |
|
301 |
def pobyso_get_constant_as_rn_so_sa(constExp): |
|
302 |
precision = pobyso_get_prec_of_constant(constExp)
|
|
303 |
RRRR = RealField(precision) |
|
304 |
rn = RRRR(0) |
|
305 |
sollya_lib_get_constant(get_rn_value(rn), constExp)
|
|
306 |
return(rn) |
|
302 |
def pobyso_get_constant_as_rn_so_sa(constExpSo):
|
|
303 |
precisionSa = pobyso_get_prec_of_constant(constExpSo)
|
|
304 |
RRRR = RealField(precisionSa)
|
|
305 |
rnSa = RRRR(0)
|
|
306 |
sollya_lib_get_constant(get_rn_value(rnSa), constExpSo)
|
|
307 |
return(rnSa)
|
|
307 | 308 |
|
308 | 309 |
def pobyso_get_constant_as_rn_with_rf(ctExp, realField): |
309 | 310 |
""" Legacy function. See pobyso_get_constant_as_rn_with_rf_so_sa.""" |
310 | 311 |
return(pobyso_get_constant_as_rn_with_rf_so_sa(ctExp, realField)) |
311 | 312 |
|
312 |
def pobyso_get_constant_as_rn_with_rf_so_sa(ctExp, realField): |
|
313 |
rn = realField(0) |
|
314 |
sollya_lib_get_constant(get_rn_value(rn), ctExp) |
|
315 |
return(rn) |
|
313 |
def pobyso_get_constant_as_rn_with_rf_so_sa(ctExpSo, realFieldSa = None): |
|
314 |
if realFieldSa is None: |
|
315 |
sollyaPrecSa = pobyso_get_prec_so_sa() |
|
316 |
realFieldSa = RealField(sollyaPrecSa) |
|
317 |
rnSa = realFieldSa(0) |
|
318 |
sollya_lib_get_constant(get_rn_value(rnSa), ctExpSo) |
|
319 |
return(rnSa) |
|
316 | 320 |
|
317 | 321 |
def pobyso_get_free_variable_name(): |
318 | 322 |
""" Legacy function. See pobyso_get_free_variable_name_so_sa.""" |
... | ... | |
339 | 343 |
sollya_lib_get_head_function(byref(functionType), expressionSo, None) |
340 | 344 |
return(int(functionType.value)) |
341 | 345 |
|
342 |
def pobyso_get_interval_from_range_so_sa(soRange): |
|
346 |
def pobyso_get_interval_from_range_so_sa(soRange, realIntervalFieldSa = None ):
|
|
343 | 347 |
""" |
344 | 348 |
Return the Sage interval corresponding to the Sollya range argument. |
345 |
The interval bounds are not rounded: they are elements of RealIntervalField |
|
346 |
of the "right" precision. |
|
349 |
If no reaInterval lField is passed as argument, the interval bounds are not |
|
350 |
rounded: they are elements of RealIntervalField of the "right" precision |
|
351 |
to hold all the digits. |
|
347 | 352 |
""" |
348 | 353 |
prec = c_int(0) |
349 |
retval = sollya_lib_get_prec_of_range(byref(prec), soRange, None) |
|
350 |
if retval == 0: |
|
351 |
return(None) |
|
352 |
RRRI = RealIntervalField(prec.value) |
|
353 |
intervalSa = RRRI(0,0) |
|
354 |
if realIntervalFieldSa is None: |
|
355 |
retval = sollya_lib_get_prec_of_range(byref(prec), soRange, None) |
|
356 |
if retval == 0: |
|
357 |
return(None) |
|
358 |
realIntervalFieldSa = RealIntervalField(prec.value) |
|
359 |
intervalSa = realIntervalFieldSa(0,0) |
|
354 | 360 |
retval = \ |
355 | 361 |
sollya_lib_get_interval_from_range(get_interval_value(intervalSa),\ |
356 | 362 |
soRange) |
357 | 363 |
if retval == 0: |
358 | 364 |
return(None) |
359 | 365 |
return(intervalSa) |
360 |
|
|
366 |
# End pobyso_get_interval_from_range_so_sa |
|
367 |
|
|
361 | 368 |
def pobyso_get_list_elements(soObj): |
362 | 369 |
""" Legacy function. See pobyso_get_list_elements_so_so. """ |
363 | 370 |
return(pobyso_get_list_elements_so_so(soObj)) |
... | ... | |
526 | 533 |
Get the current default precision in Sollya. |
527 | 534 |
The return value is Sage/Python int. |
528 | 535 |
""" |
529 |
retc = sollya_lib_get_prec(None) |
|
530 |
a = c_int(0) |
|
531 |
sollya_lib_get_constant_as_int(byref(a), retc) |
|
532 |
return(int(a.value)) |
|
536 |
precSo = sollya_lib_get_prec(None) |
|
537 |
precSa = c_int(0) |
|
538 |
sollya_lib_get_constant_as_int(byref(precSa), precSo) |
|
539 |
sollya_lib_clear_obj(precSo) |
|
540 |
return(int(precSa.value)) |
|
533 | 541 |
|
534 | 542 |
def pobyso_get_prec_of_constant(ctExpSo): |
535 | 543 |
""" Legacy function. See pobyso_get_prec_of_constant_so_sa. """ |
536 | 544 |
return(pobyso_get_prec_of_constant_so_sa(ctExpSo)) |
537 | 545 |
|
546 |
def pobyso_get_prec_of_constant_so_sa(ctExpSo): |
|
547 |
prec = c_int(0) |
|
548 |
retc = sollya_lib_get_prec_of_constant(byref(prec), ctExpSo, None) |
|
549 |
if retc == 0: |
|
550 |
return(None) |
|
551 |
return(int(prec.value)) |
|
552 |
|
|
538 | 553 |
def pobyso_get_prec_of_range_so_sa(rangeSo): |
539 | 554 |
prec = c_int(0) |
540 | 555 |
retc = sollya_lib_get_prec_of_range(byref(prec), rangeSo, None) |
556 |
if retc == 0: |
|
557 |
return(None) |
|
541 | 558 |
return(int(prec.value)) |
542 | 559 |
|
543 | 560 |
def pobyso_infnorm_so_so(func, interval, file = None, intervalList = None): |
... | ... | |
565 | 582 |
""" Legacy function. See pobyso_range_sa_so. """ |
566 | 583 |
return(pobyso_range_sa_so(rnLowerBound, rnUpperBound)) |
567 | 584 |
|
568 |
def pobyso_range_sa_so(rnLowerBound, rnUpperBound): |
|
569 |
lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBound)) |
|
570 |
upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBound)) |
|
585 |
def pobyso_range_sa_so(rnLowerBoundSa, rnUpperBoundSa): |
|
586 |
""" |
|
587 |
Return a Sollya range from to 2 RealField elements. |
|
588 |
The Sollya range element has a sufficient precision to hold all |
|
589 |
the digits of the bounds. |
|
590 |
""" |
|
591 |
# TODO: check the bounds. |
|
592 |
lbPrec = rnLowerBoundSa.parent().precision() |
|
593 |
ubPrec = rnLowerBoundSa.parent().precision() |
|
594 |
currentSollyaPrecSa = pobyso_get_prec_so_sa() |
|
595 |
maxPrecSa = max(lbPrec, ubPrec, currentSollyaPrecSa) |
|
596 |
# Change the current Sollya precision only if necessary. |
|
597 |
if maxPrecSa > currentSollyaPrecSa: |
|
598 |
currentPrecSo = sollya_lib_get_prec(None) |
|
599 |
newPrecSo = solly_lib_constant_from_uint64(maxPrecSa) |
|
600 |
sollya_lib_set_prec(newPrecSo) |
|
601 |
lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBoundSa)) |
|
602 |
upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBoundSa)) |
|
571 | 603 |
rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo) |
604 |
currentPrecSo = sollya_lib_get_prec(None) |
|
605 |
if maxPrecSa > currentSollyaPrecSa: |
|
606 |
sollya_lib_set_prec(currentPrecSo) |
|
607 |
sollya_lib_clear_obj(currentPrecSo) |
|
608 |
sollya_lib_clear_obj(newPrecSo) |
|
609 |
sollya_lib_clear_obj(lowerBoundSo) |
|
610 |
sollya_lib_clear_obj(upperBoundSo) |
|
572 | 611 |
return(rangeSo) |
573 | 612 |
|
613 |
def pobyso_range_so_sa(rangeSo, realIntervalField = None): |
|
614 |
if realIntervalField is None: |
|
615 |
precSa = pobyso_get_prec_of_range_so_sa(rangeSo) |
|
616 |
realIntervalField = RealIntervalField(precSa) |
|
617 |
intervalSa = \ |
|
618 |
pobyso_get_interval_from_range_so_sa(rangeSo, realIntervalField) |
|
619 |
return(intervalSa) |
|
620 |
|
|
574 | 621 |
def pobyso_remez_canonical_sa_sa(func, \ |
575 | 622 |
degree, \ |
576 | 623 |
lowerBound, \ |
... | ... | |
698 | 745 |
return(sollya_lib_supnorm(polySo, funcSo, intervalSo, errorTypeSo, \ |
699 | 746 |
accuracySo)) |
700 | 747 |
|
748 |
def pobyso_taylor_expansion_no_change_var_so_so(functionSo, degreeSo, rangeSo, \ |
|
749 |
errorTypeSo, \ |
|
750 |
sollyaPrecSo=None): |
|
751 |
# No global change of the working precision. |
|
752 |
if not sollyaPrecSo is None: |
|
753 |
initialPrecSo = sollya_lib_get_prec(None) |
|
754 |
sollya_lib_set_prec(sollyaPrecSo) |
|
755 |
# |
|
756 |
intervalCenterSo = sollya_lib_mid(rangeSo) |
|
757 |
taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \ |
|
758 |
intervalCenterSo, \ |
|
759 |
rangeSo, errorTypeSo, None) |
|
760 |
(taylorFormListSo, numElements, isEndElliptic) = \ |
|
761 |
pobyso_get_list_elements_so_so(taylorFormSo) |
|
762 |
polySo = taylorFormListSo[0] |
|
763 |
errorRangeSo = taylorFormListSo[2] |
|
764 |
maxErrorSo = sollya_lib_sup(errorRangeSo) |
|
765 |
# If changed, reset the Sollya working precision. |
|
766 |
if not sollyaPrecSo is None: |
|
767 |
sollya_lib_set_prec(initialPrecSo) |
|
768 |
sollya_lib_clear_obj(initailPrecSo) |
|
769 |
return([polySo, intervalCenterSo, maxErrorSo]) |
|
770 |
# end pobyso_taylor_expansion_no_change_var_so_so |
|
771 |
|
|
701 | 772 |
def pobyso_taylor(function, degree, point): |
702 | 773 |
""" Legacy function. See pobysoTaylor_so_so. """ |
703 | 774 |
return(pobyso_taylor_so_so(function, degree, point)) |
704 | 775 |
|
705 |
def pobyso_taylor_so_so(function, degree, point):
|
|
706 |
return(sollya_lib_taylor(function, degree, point))
|
|
776 |
def pobyso_taylor_so_so(functionSo, degreeSo, pointSo):
|
|
777 |
return(sollya_lib_taylor(functionSo, degreeSo, pointSo))
|
|
707 | 778 |
|
708 | 779 |
def pobyso_taylorform(function, degree, point = None, interval = None, errorType=None): |
709 | 780 |
""" Legacy function. See ;""" |
... | ... | |
810 | 881 |
# There is no simple str() method defined for p's class. |
811 | 882 |
return(p.__str__()) |
812 | 883 |
# |
813 |
print "Superficial test of pobyso:" |
|
814 | 884 |
print pobyso_get_prec() |
815 | 885 |
pobyso_set_prec(165) |
816 | 886 |
print pobyso_get_prec() |
... | ... | |
819 | 889 |
id(a) |
820 | 890 |
print "Max arity: ", pobyso_max_arity |
821 | 891 |
print "Function tripleDouble (43) as a string: ", pobyso_function_type_as_string(43) |
822 |
print "Function None (44) as a string: ", pobyso_function_type_as_string(44) |
|
892 |
print "Function None (44) as a string: ", pobyso_function_type_as_string(44) |
|
893 |
print "...Pobyso check done" |
Formats disponibles : Unified diff