112 |
112 |
maxPrecSa = max(lbPrecSa, ubPrecSa)
|
113 |
113 |
else:
|
114 |
114 |
maxPrecSa = precisionSa
|
115 |
|
sollyaCurrentPrecSo = pobyso_get_prec_so()
|
116 |
|
sollyaCurrentPrecSa = pobyso_constant_from_int_so_sa(sollyaCurrentPrecSo)
|
117 |
|
# Change the current Sollya precision only if necessary.
|
118 |
|
if maxPrecSa > sollyaCurrentPrecSa:
|
119 |
|
pobyso_set_prec_sa_so(maxPrecSa)
|
120 |
115 |
# From Sage to Sollya bounds.
|
121 |
|
lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBoundSa))
|
122 |
|
upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBoundSa))
|
|
116 |
lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBoundSa),
|
|
117 |
maxPrecSa)
|
|
118 |
upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBoundSa),
|
|
119 |
maxPrecSa)
|
123 |
120 |
# From Sollya bounds to range.
|
124 |
121 |
rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo)
|
125 |
122 |
# Back to original precision.
|
126 |
|
if maxPrecSa > sollyaCurrentPrecSa:
|
127 |
|
sollya_lib_set_prec(sollyaCurrentPrecSo)
|
128 |
123 |
# Clean up
|
129 |
|
sollya_lib_clear_obj(sollyaCurrentPrecSo)
|
130 |
124 |
sollya_lib_clear_obj(lowerBoundSo)
|
131 |
125 |
sollya_lib_clear_obj(upperBoundSo)
|
132 |
|
return(rangeSo)
|
|
126 |
return rangeSo
|
133 |
127 |
# End pobyso_bounds_to_range_sa_so
|
134 |
128 |
|
135 |
129 |
def pobyso_build_function_sub_so_so(exp1So, exp2So):
|
... | ... | |
242 |
236 |
if precisionSa > currentSollyaPrecisionSa:
|
243 |
237 |
pobyso_set_prec_sa_so(precisionSa)
|
244 |
238 |
constantSo = sollya_lib_constant(get_rn_value(rnArgSa))
|
245 |
|
pobyso_set_prec_sa_so(currentSollyaPrecision)
|
|
239 |
pobyso_set_prec_so_so(currentSollyaPrecisionSo)
|
246 |
240 |
else:
|
247 |
241 |
constantSo = sollya_lib_constant(get_rn_value(rnArgSa))
|
248 |
242 |
sollya_lib_clear_obj(currentSollyaPrecisionSo)
|
249 |
|
return(constantSo)
|
|
243 |
return constantSo
|
250 |
244 |
# End pobyso_constant_sa_so
|
251 |
245 |
|
252 |
246 |
def pobyso_constant_0_sa_so():
|
... | ... | |
745 |
739 |
precSa = c_int(0)
|
746 |
740 |
sollya_lib_get_constant_as_int(byref(precSa), precSo)
|
747 |
741 |
sollya_lib_clear_obj(precSo)
|
748 |
|
return(int(precSa.value))
|
|
742 |
return int(precSa.value)
|
749 |
743 |
# End pobyso_get_prec_so_sa.
|
750 |
744 |
|
751 |
745 |
def pobyso_get_prec_of_constant(ctExpSo):
|
... | ... | |
767 |
761 |
return(int(prec.value))
|
768 |
762 |
# End pobyso_get_prec_of_range_so_sa()
|
769 |
763 |
|
|
764 |
def pobyso_guess_degree_sa_sa(functionSa, intervalSa, errorSa, weightSa=None, \
|
|
765 |
degreeBoundSa=None):
|
|
766 |
functionAsStringSa = functionSa._assume_str()
|
|
767 |
functionSo = pobyso_parse_string_sa_so(functionAsStringSa)
|
|
768 |
rangeSo = pobyso_interval_to_range_sa_so(intervalSa)
|
|
769 |
errorSo = pobyso_constant_sa_so(errorSa)
|
|
770 |
if not weightSa is None:
|
|
771 |
weightAsStringSa = weightSa._assume_str()
|
|
772 |
weightSo = pobyso_parse_string_sa_so(weightAsStringSa)
|
|
773 |
else:
|
|
774 |
weightSo = None
|
|
775 |
if not degreeBoundSa is None:
|
|
776 |
degreeBoundSo = pobyso_constant_from_int_sa_so(degreeBoundSa)
|
|
777 |
else:
|
|
778 |
degreeBoundSo = None
|
|
779 |
guessedDegreeSa = pobyso_guess_degree_so_sa(functionSo,
|
|
780 |
rangeSo,
|
|
781 |
errorSo,
|
|
782 |
weightSo,
|
|
783 |
degreeBoundSo)
|
|
784 |
sollya_lib_clear_obj(functionSo)
|
|
785 |
sollya_lib_clear_obj(rangeSo)
|
|
786 |
sollya_lib_clear_obj(errorSo)
|
|
787 |
if not weightSo is None:
|
|
788 |
sollya_lib_clear_obj(weightSo)
|
|
789 |
if not degreeBoundSo is None:
|
|
790 |
sollya_lib_clear_obj(degreeBoundSo)
|
|
791 |
return guessedDegreeSa
|
|
792 |
# End poyso_guess_degree_sa_sa
|
|
793 |
|
770 |
794 |
def pobyso_guess_degree_so_sa(functionSo, rangeSo, errorSo, weightSo=None, \
|
771 |
|
degreeBoundsSo=None):
|
|
795 |
degreeBoundSo=None):
|
|
796 |
"""
|
|
797 |
Thin wrapper around the guessdegree function.
|
|
798 |
Nevertheless, some precision control stuff has been appended.
|
|
799 |
"""
|
|
800 |
# Deal with Sollya internal precision issues: if it is too small,
|
|
801 |
# compared with the error, increases it to about twice -log2(error).
|
|
802 |
errorSa = pobyso_get_constant_as_rn_with_rf_so_sa(errorSo)
|
|
803 |
log2ErrorSa = errorSa.log2()
|
|
804 |
if log2ErrorSa < 0:
|
|
805 |
neededPrecisionSa = int(2 * int(-log2ErrorSa) / 64) * 64
|
|
806 |
else:
|
|
807 |
neededPrecisionSa = int(2 * int(log2ErrorSa) / 64) * 64
|
|
808 |
#print "Needed precision:", neededPrecisionSa
|
|
809 |
currentPrecSa = pobyso_get_prec_so_sa()
|
|
810 |
if neededPrecisionSa > currentPrecSa:
|
|
811 |
currentPrecSo = pobyso_get_prec_so()
|
|
812 |
pobyso_set_prec_sa_so(neededPrecisionSa)
|
772 |
813 |
# weightSo and degreeBoundsSo are optional arguments.
|
773 |
814 |
if weightSo is None:
|
774 |
|
degreeRangeSo = sollya_lib_guessdegree(functionSo, rangeSo, errorSo)
|
775 |
|
elif degreeBounds is None:
|
|
815 |
degreeRangeSo = sollya_lib_guessdegree(functionSo, rangeSo, errorSo, None)
|
|
816 |
elif degreeBoundSo is None:
|
776 |
817 |
degreeRangeSo = sollya_lib_guessdegree(functionSo, rangeSo, \
|
777 |
|
errorSo, weightSo)
|
|
818 |
errorSo, weightSo, None)
|
778 |
819 |
else:
|
779 |
820 |
degreeRangeSo = sollya_lib_guessdegree(functionSo, rangeSo, errorSo, \
|
780 |
|
weightSo, degreeBoundsSo)
|
781 |
|
pobyso_range_to_interval_so_sa(degreeRangeSo)
|
782 |
|
# End pobyso_guess_degree_so_sa
|
|
821 |
weightSo, degreeBoundSo, None)
|
|
822 |
# Restore internal precision, if applicable.
|
|
823 |
if neededPrecisionSa > currentPrecSa:
|
|
824 |
pobyso_set_prec_so_so(currentPrecSo)
|
|
825 |
sollya_lib_clear_obj(currentPrecSo)
|
|
826 |
degreeIntervalSa = pobyso_range_to_interval_so_sa(degreeRangeSo)
|
|
827 |
sollya_lib_clear_obj(degreeRangeSo)
|
|
828 |
# When ok, both bounds match.
|
|
829 |
# When the degree bound is too low, the upper bound is the degree
|
|
830 |
# for which the error can be honored.
|
|
831 |
# When it really goes wrong, the upper bound is infinity.
|
|
832 |
if degreeIntervalSa.lower() == degreeIntervalSa.upper():
|
|
833 |
return int(degreeIntervalSa.lower())
|
|
834 |
else:
|
|
835 |
if degreeIntervalSa.upper().is_infinity():
|
|
836 |
return None
|
|
837 |
else:
|
|
838 |
return int(degreeIntervalSa.upper())
|
|
839 |
# End pobyso_guess_degree_so_sa
|
783 |
840 |
|
784 |
841 |
def pobyso_infnorm_so_so(func, interval, file = None, intervalList = None):
|
785 |
842 |
print "Do not use this function. User pobyso_supnorm_so_so instead."
|