85 |
85 |
|
86 |
86 |
pobyso_max_arity = 9
|
87 |
87 |
|
|
88 |
def pobyso_absolute_so_so():
|
|
89 |
return(sollya_lib_absolute(None))
|
|
90 |
|
88 |
91 |
def pobyso_autoprint(arg):
|
89 |
92 |
sollya_lib_autoprint(arg,None)
|
90 |
93 |
|
91 |
94 |
def pobyso_autoprint_so_so(arg):
|
92 |
95 |
sollya_lib_autoprint(arg,None)
|
93 |
96 |
|
94 |
|
def pobyso_absolute_so_so():
|
95 |
|
return(sollya_lib_absolute(None))
|
96 |
|
|
97 |
97 |
def pobyso_bounds_to_range_sa_so(rnLowerBoundSa, rnUpperBoundSa, \
|
98 |
98 |
precisionSa=None):
|
99 |
99 |
"""
|
... | ... | |
104 |
104 |
# Sanity check.
|
105 |
105 |
if rnLowerBoundSa > rnUpperBoundSa:
|
106 |
106 |
return None
|
107 |
|
if precision is None:
|
|
107 |
if precisionSa is None:
|
108 |
108 |
# Check for the largest precision.
|
109 |
109 |
lbPrecSa = rnLowerBoundSa.parent().precision()
|
110 |
110 |
ubPrecSa = rnLowerBoundSa.parent().precision()
|
... | ... | |
132 |
132 |
def pobyso_build_function_sub_so_so(exp1So, exp2So):
|
133 |
133 |
return(sollya_lib_build_function_sub(exp1So, exp2So))
|
134 |
134 |
|
135 |
|
def pobyso_cmp(rnArg, soCte):
|
|
135 |
def pobyso_change_var_in_function_so_so(funcSo, chvarExpSo):
|
136 |
136 |
"""
|
|
137 |
Variable change in a function.
|
|
138 |
"""
|
|
139 |
return(sollya_lib_evaluate(funcSo,chvarExpSo))
|
|
140 |
# End pobyso_change_var_in_function_so_so
|
|
141 |
|
|
142 |
def pobyso_chebyshevform_so_so(functionSo, degreeSo, intervalSo):
|
|
143 |
resultSo = sollya_lib_chebyshevform(functionSo, degreeSo, intervalSo)
|
|
144 |
return(resultSo)
|
|
145 |
# End pobyso_chebyshevform_so_so.
|
|
146 |
|
|
147 |
def pobyso_cmp(rnArgSa, cteSo):
|
|
148 |
"""
|
137 |
149 |
Compare the MPFR value a RealNumber with that of a Sollya constant.
|
138 |
150 |
|
139 |
151 |
Get the value of the Sollya constant into a RealNumber and compare
|
... | ... | |
142 |
154 |
"""
|
143 |
155 |
precisionOfCte = c_int(0)
|
144 |
156 |
# From the Sollya constant, create a local Sage RealNumber.
|
145 |
|
sollya_lib_get_prec_of_constant(precisionOfCte, soCte)
|
|
157 |
sollya_lib_get_prec_of_constant(precisionOfCte, cteSo)
|
146 |
158 |
#print "Precision of constant: ", precisionOfCte
|
147 |
159 |
RRRR = RealField(precisionOfCte.value)
|
148 |
|
rnLocal = RRRR(0)
|
149 |
|
sollya_lib_get_constant(get_rn_value(rnLocal), soCte)
|
150 |
|
#print "rnDummy: ", rnDummy
|
|
160 |
rnLocalSa = RRRR(0)
|
|
161 |
sollya_lib_get_constant(get_rn_value(rnLocalSa), cteSo)
|
151 |
162 |
# Compare the local Sage RealNumber with rnArg.
|
152 |
|
return(cmp_rn_value(rnArg, rnLocal))
|
|
163 |
return(cmp_rn_value(rnArgSa, rnLocal))
|
153 |
164 |
# End pobyso_smp
|
154 |
165 |
|
155 |
|
def pobyso_change_var_in_function_so_so(funcSo, chvarExpSo):
|
156 |
|
"""
|
157 |
|
Variable change in a function.
|
158 |
|
"""
|
159 |
|
return(sollya_lib_evaluate(funcSo,chvarExpSo))
|
160 |
|
# End pobyso_change_var_in_function_so_so
|
161 |
|
|
162 |
|
def pobyso_chebyshevform_so_so(functionSo, degreeSo, intervalSo):
|
163 |
|
resultSo = sollya_lib_chebyshevform(functionSo, degreeSo, intervalSo)
|
164 |
|
return(resultSo)
|
165 |
|
# End pobyso_chebyshevform_so_so.
|
166 |
|
|
167 |
166 |
def pobyso_compute_pos_function_abs_val_bounds_sa_sa(funcSa, lowerBoundSa, \
|
168 |
167 |
upperBoundSa):
|
169 |
168 |
"""
|
170 |
|
TODO: set the variable name in Sollya.
|
|
169 |
TODO: completely rework and test.
|
171 |
170 |
"""
|
|
171 |
pobyso = pobyso_name_free_variable_sa_so(funcSa.variables()[0])
|
172 |
172 |
funcSo = pobyso_parse_string(funcSa._assume_str())
|
173 |
173 |
rangeSo = pobyso_range_sa_so(lowerBoundSa, upperBoundSa)
|
174 |
174 |
infnormSo = pobyso_infnorm_so_so(funcSo,rangeSo)
|
... | ... | |
186 |
186 |
infnormSo = pobyso_infnorm_so_so(funcAuxSo,rangeSo)
|
187 |
187 |
fMinSa = pobyso_get_interval_from_range_so_sa(infnormSo)
|
188 |
188 |
sollya_lib_clear_obj(infnormSo)
|
189 |
|
fMinLowerBoundSa = topBinadeLimit - fMinSa.lower()
|
|
189 |
fMinLowerBoundSa = binadeTopLimitSa - fMinSa.lower()
|
190 |
190 |
# Compute the maximum of the precisions of the different bounds.
|
191 |
191 |
maxPrecSa = max([fMinLowerBoundSa.parent().precision(), \
|
192 |
192 |
fMaxUpperBoundSa.parent().precision()])
|
... | ... | |
211 |
211 |
# Precision stuff
|
212 |
212 |
if precisionSa is None:
|
213 |
213 |
precisionSa = rnArgSa.parent().precision()
|
214 |
|
currentSollyaPrecisionSo = pobyso_get_prec_so()
|
215 |
|
currentSollyaPrecisionSa = pobyso_get
|
|
214 |
currentSollyaPrecisionSo = sollya_lib_get_prec()
|
|
215 |
currentSollyaPrecisionSa = \
|
|
216 |
pobyso_constant_from_int(currentSollyaPrecisionSo)
|
216 |
217 |
if precisionSa > currentSollyaPrecisionSa:
|
217 |
218 |
pobyso_set_prec_sa_so(precisionSa)
|
218 |
219 |
constantSo = sollya_lib_constant(get_rn_value(rnArgSa))
|
219 |
220 |
pobyso_set_prec_sa_so(currentSollyaPrecision)
|
220 |
221 |
else:
|
221 |
222 |
constantSo = sollya_lib_constant(get_rn_value(rnArgSa))
|
|
223 |
sollya_lib_clear_obj(currentSollyaPrecisionSo)
|
222 |
224 |
return(constantSo)
|
223 |
225 |
|
224 |
226 |
def pobyso_constant_0_sa_so():
|
... | ... | |
348 |
350 |
else:
|
349 |
351 |
return None
|
350 |
352 |
|
351 |
|
def pobyso_get_constant(rnArg, soConst):
|
|
353 |
def pobyso_get_constant(rnArgSa, constSo):
|
352 |
354 |
""" Legacy function. See pobyso_get_constant_so_sa. """
|
353 |
|
return(pobyso_get_constant_so_sa(rnArg, soConst))
|
|
355 |
return(pobyso_get_constant_so_sa(rnArgSa, constSo))
|
354 |
356 |
|
355 |
357 |
def pobyso_get_constant_so_sa(rnArgSa, constSo):
|
356 |
358 |
"""
|
357 |
|
Set the value of rnArg to the value of soConst in MPFR_RNDN mode.
|
|
359 |
Set the value of rnArgSo to the value of constSo in MPFR_RNDN mode.
|
358 |
360 |
rnArg must already exist and belong to some RealField.
|
359 |
|
We assume that soConst points to a Sollya constant.
|
|
361 |
We assume that constSo points to a Sollya constant.
|
360 |
362 |
"""
|
361 |
363 |
return(sollya_lib_get_constant(get_rn_value(rnArgSa), constSo))
|
362 |
364 |
|
... | ... | |
389 |
391 |
"""
|
390 |
392 |
Get a Sollya constant as a Sage "real number".
|
391 |
393 |
If no real field is specified, the precision of the floating-point number
|
392 |
|
returned is that of the Solly constant.
|
|
394 |
returned is that of the Sollya constant.
|
393 |
395 |
Otherwise is is that of the real field. Hence rounding may happen.
|
394 |
396 |
"""
|
395 |
397 |
if realFieldSa is None:
|
396 |
|
sollyaPrecSa = pobyso_get_prec_so_sa()
|
|
398 |
sollyaPrecSa = pobyso_get_prec_of_constant_so_sa(ctExpSo)
|
397 |
399 |
realFieldSa = RealField(sollyaPrecSa)
|
398 |
400 |
rnSa = realFieldSa(0)
|
399 |
401 |
sollya_lib_get_constant(get_rn_value(rnSa), ctExpSo)
|
... | ... | |
457 |
459 |
""" Legacy function. See pobyso_get_list_elements_so_so. """
|
458 |
460 |
return(pobyso_get_list_elements_so_so(soObj))
|
459 |
461 |
|
460 |
|
def pobyso_get_list_elements_so_so(soObj):
|
|
462 |
def pobyso_get_list_elements_so_so(objSo):
|
461 |
463 |
"""
|
462 |
464 |
Get the list elements as a Sage/Python array of Sollya objects.
|
463 |
|
The other data returned are also Sage/Python objects.
|
|
465 |
The other data returned are Sage/Python objects.
|
464 |
466 |
"""
|
465 |
467 |
listAddress = POINTER(c_longlong)()
|
466 |
468 |
numElements = c_int(0)
|
... | ... | |
469 |
471 |
result = sollya_lib_get_list_elements(byref(listAddress),\
|
470 |
472 |
byref(numElements),\
|
471 |
473 |
byref(isEndElliptic),\
|
472 |
|
soObj)
|
|
474 |
objSo)
|
473 |
475 |
if result == 0 :
|
474 |
476 |
return None
|
475 |
477 |
for i in xrange(0, numElements.value, 1):
|
476 |
|
listAsList.append(listAddress[i])
|
|
478 |
listAsList.append(sollya_lib_copy_obj(listAddress[i]))
|
477 |
479 |
return(listAsList, numElements.value, isEndElliptic.value)
|
478 |
480 |
|
479 |
481 |
def pobyso_get_max_prec_of_exp(soExp):
|
480 |
482 |
""" Legacy function. See pobyso_get_max_prec_of_exp_so_sa. """
|
481 |
483 |
return(pobyso_get_max_prec_of_exp_so_sa(soExp))
|
482 |
484 |
|
483 |
|
def pobyso_get_max_prec_of_exp_so_sa(soExp):
|
|
485 |
def pobyso_get_max_prec_of_exp_so_sa(expSo):
|
484 |
486 |
"""
|
485 |
487 |
Get the maximum precision used for the numbers in a Sollya expression.
|
486 |
488 |
|
... | ... | |
495 |
497 |
maxPrecision = 0
|
496 |
498 |
minConstPrec = 0
|
497 |
499 |
currentConstPrec = 0
|
498 |
|
operator = pobyso_get_head_function_so_sa(soExp)
|
|
500 |
operator = pobyso_get_head_function_so_sa(expSo)
|
499 |
501 |
if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \
|
500 |
502 |
(operator != SOLLYA_BASE_FUNC_FREE_VARIABLE):
|
501 |
|
(arity, subexpressions) = pobyso_get_subfunctions_so_sa(soExp)
|
|
503 |
(arity, subexpressions) = pobyso_get_subfunctions_so_sa(expSo)
|
502 |
504 |
for i in xrange(arity):
|
503 |
505 |
maxPrecisionCandidate = \
|
504 |
506 |
pobyso_get_max_prec_of_exp_so_sa(subexpressions[i])
|
... | ... | |
506 |
508 |
maxPrecision = maxPrecisionCandidate
|
507 |
509 |
return(maxPrecision)
|
508 |
510 |
elif operator == SOLLYA_BASE_FUNC_CONSTANT:
|
509 |
|
minConstPrec = pobyso_get_min_prec_of_constant_so_sa(soExp)
|
|
511 |
#minConstPrec = pobyso_get_min_prec_of_constant_so_sa(expSo)
|
510 |
512 |
#currentConstPrec = pobyso_get_min_prec_of_constant_so_sa(soExp)
|
511 |
513 |
#print minConstPrec, " - ", currentConstPrec
|
512 |
|
return(pobyso_get_min_prec_of_constant_so_sa(soExp))
|
|
514 |
return(pobyso_get_min_prec_of_constant_so_sa(expSo))
|
513 |
515 |
|
514 |
516 |
elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE:
|
515 |
517 |
return(0)
|
... | ... | |
517 |
519 |
print "pobyso_get_max_prec_of_exp_so_sa: unexepected operator."
|
518 |
520 |
return(0)
|
519 |
521 |
|
520 |
|
def pobyso_get_min_prec_of_constant_so_sa(soConstExp):
|
|
522 |
def pobyso_get_min_prec_of_constant_so_sa(constExpSo):
|
521 |
523 |
"""
|
522 |
524 |
Get the minimum precision necessary to represent the value of a Sollya
|
523 |
525 |
constant.
|
524 |
526 |
MPFR_MIN_PREC and powers of 2 are taken into account.
|
525 |
|
We assume that soCteExp is a point
|
|
527 |
We assume that constExpSo is a point
|
526 |
528 |
"""
|
527 |
|
constExpAsRn = pobyso_get_constant_as_rn_so_sa(soConstExp)
|
528 |
|
return(min_mpfr_size(get_rn_value(constExpAsRn)))
|
|
529 |
constExpAsRnSa = pobyso_get_constant_as_rn_so_sa(constExpSo)
|
|
530 |
return(min_mpfr_size(get_rn_value(constExpAsRnSa)))
|
529 |
531 |
|
530 |
|
def pobyso_get_sage_exp_from_sollya_exp(sollyaExp, realField = RR):
|
|
532 |
def pobyso_get_sage_exp_from_sollya_exp(sollyaExpSo, realField = RR):
|
531 |
533 |
""" Legacy function. See pobyso_get_sage_exp_from_sollya_exp_so_sa. """
|
532 |
|
return(pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExp, realField = RR))
|
|
534 |
return(pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExpSo, \
|
|
535 |
realField = RR))
|
533 |
536 |
|
534 |
|
def pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExp, realField = RR):
|
|
537 |
def pobyso_get_sage_exp_from_sollya_exp_so_sa(sollyaExpSo, realFieldSa = RR):
|
535 |
538 |
"""
|
536 |
539 |
Get a Sage expression from a Sollya expression.
|
537 |
540 |
Currently only tested with polynomials with floating-point coefficients.
|
538 |
541 |
Notice that, in the returned polynomial, the exponents are RealNumbers.
|
539 |
542 |
"""
|
540 |
543 |
#pobyso_autoprint(sollyaExp)
|
541 |
|
operator = pobyso_get_head_function_so_sa(sollyaExp)
|
|
544 |
operatorSa = pobyso_get_head_function_so_sa(sollyaExpSo)
|
542 |
545 |
sollyaLibFreeVariableName = sollya_lib_get_free_variable_name()
|
543 |
546 |
# Constants and the free variable are special cases.
|
544 |
547 |
# All other operator are dealt with in the same way.
|
545 |
|
if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \
|
546 |
|
(operator != SOLLYA_BASE_FUNC_FREE_VARIABLE):
|
547 |
|
(arity, subexpressions) = pobyso_get_subfunctions_so_sa(sollyaExp)
|
548 |
|
if arity == 1:
|
549 |
|
sageExp = eval(pobyso_function_type_as_string_so_sa(operator) + \
|
550 |
|
"(" + pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], \
|
551 |
|
realField) + ")")
|
552 |
|
elif arity == 2:
|
|
548 |
if (operatorSa != SOLLYA_BASE_FUNC_CONSTANT) and \
|
|
549 |
(operatorSa != SOLLYA_BASE_FUNC_FREE_VARIABLE):
|
|
550 |
(aritySa, subexpressionsSa) = pobyso_get_subfunctions_so_sa(sollyaExpSo)
|
|
551 |
if aritySa == 1:
|
|
552 |
sageExpSa = eval(pobyso_function_type_as_string_so_sa(operatorSa) + \
|
|
553 |
"(" + pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressionsSa[0], \
|
|
554 |
realFieldSa) + ")")
|
|
555 |
elif aritySa == 2:
|
553 |
556 |
# We do not get through the preprocessor.
|
554 |
557 |
# The "^" operator is then a special case.
|
555 |
|
if operator == SOLLYA_BASE_FUNC_POW:
|
556 |
|
operatorAsString = "**"
|
|
558 |
if operatorSa == SOLLYA_BASE_FUNC_POW:
|
|
559 |
operatorAsStringSa = "**"
|
557 |
560 |
else:
|
558 |
|
operatorAsString = \
|
559 |
|
pobyso_function_type_as_string_so_sa(operator)
|
560 |
|
sageExp = \
|
561 |
|
eval("pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[0], realField)"\
|
562 |
|
+ " " + operatorAsString + " " + \
|
563 |
|
"pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressions[1], realField)")
|
|
561 |
operatorAsStringSa = \
|
|
562 |
pobyso_function_type_as_string_so_sa(operatorSa)
|
|
563 |
sageExpSa = \
|
|
564 |
eval("pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressionsSa[0], realFieldSa)"\
|
|
565 |
+ " " + operatorAsStringSa + " " + \
|
|
566 |
"pobyso_get_sage_exp_from_sollya_exp_so_sa(subexpressionsSa[1], realFieldSa)")
|
564 |
567 |
# We do not know yet how to deal with arity >= 3
|
565 |
568 |
# (is there any in Sollya anyway?).
|
566 |
569 |
else:
|
567 |
|
sageExp = eval('None')
|
568 |
|
return(sageExp)
|
569 |
|
elif operator == SOLLYA_BASE_FUNC_CONSTANT:
|
|
570 |
sageExpSa = eval('None')
|
|
571 |
return(sageExpSa)
|
|
572 |
elif operatorSa == SOLLYA_BASE_FUNC_CONSTANT:
|
570 |
573 |
#print "This is a constant"
|
571 |
|
return pobyso_get_constant_as_rn_with_rf_so_sa(sollyaExp, realField)
|
572 |
|
elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE:
|
|
574 |
return pobyso_get_constant_as_rn_with_rf_so_sa(sollyaExpSo, realFieldSa)
|
|
575 |
elif operatorSa == SOLLYA_BASE_FUNC_FREE_VARIABLE:
|
573 |
576 |
#print "This is free variable"
|
574 |
577 |
return(eval(sollyaLibFreeVariableName))
|
575 |
578 |
else:
|
... | ... | |
720 |
723 |
def pobyso_lib_init():
|
721 |
724 |
sollya_lib_init(None)
|
722 |
725 |
|
723 |
|
def pobyso_name_free_variable(freeVariableName):
|
|
726 |
def pobyso_name_free_variable(freeVariableNameSa):
|
724 |
727 |
""" Legacy function. See pobyso_name_free_variable_sa_so. """
|
725 |
|
pobyso_name_free_variable_sa_so(freeVariableName)
|
|
728 |
pobyso_name_free_variable_sa_so(freeVariableNameSa)
|
726 |
729 |
|
727 |
|
def pobyso_name_free_variable_sa_so(freeVariableName):
|
|
730 |
def pobyso_name_free_variable_sa_so(freeVariableNameSa):
|
728 |
731 |
"""
|
729 |
732 |
Set the free variable name in Sollya from a Sage string.
|
730 |
733 |
"""
|
731 |
|
sollya_lib_name_free_variable(freeVariableName)
|
|
734 |
sollya_lib_name_free_variable(freeVariableNameSa)
|
732 |
735 |
|
733 |
736 |
def pobyso_parse_string(string):
|
734 |
737 |
""" Legacy function. See pobyso_parse_string_sa_so. """
|
... | ... | |
745 |
748 |
return(pobyso_range_sa_so(rnLowerBound, rnUpperBound))
|
746 |
749 |
|
747 |
750 |
|
748 |
|
def pobyso_range_to_interval_so_sa(rangeSo, realIntervalField = None):
|
|
751 |
def pobyso_range_to_interval_so_sa(rangeSo, realIntervalFieldSa = None):
|
749 |
752 |
"""
|
750 |
753 |
Get a Sage interval from a Sollya range.
|
751 |
754 |
If no realIntervalField is given as a parameter, the Sage interval
|
752 |
755 |
precision is that of the Sollya range.
|
753 |
|
Otherwise, the precision is that of the realIntervalField. Rounding
|
754 |
|
may happen.
|
|
756 |
Otherwise, the precision is that of the realIntervalField. In this case
|
|
757 |
rounding may happen.
|
755 |
758 |
"""
|
756 |
|
if realIntervalField is None:
|
|
759 |
if realIntervalFieldSa is None:
|
757 |
760 |
precSa = pobyso_get_prec_of_range_so_sa(rangeSo)
|
758 |
|
realIntervalField = RealIntervalField(precSa)
|
|
761 |
realIntervalFieldSa = RealIntervalField(precSa)
|
759 |
762 |
intervalSa = \
|
760 |
|
pobyso_get_interval_from_range_so_sa(rangeSo, realIntervalField)
|
|
763 |
pobyso_get_interval_from_range_so_sa(rangeSo, realIntervalFieldSa)
|
761 |
764 |
return(intervalSa)
|
762 |
765 |
|
763 |
766 |
def pobyso_remez_canonical_sa_sa(func, \
|
... | ... | |
778 |
781 |
degree, \
|
779 |
782 |
lowerBound, \
|
780 |
783 |
upperBound, \
|
781 |
|
weight = None, \
|
782 |
|
quality = None)
|
|
784 |
weight, \
|
|
785 |
quality)
|
783 |
786 |
# String test
|
784 |
787 |
if parent(func) == parent("string"):
|
785 |
788 |
functionSa = eval(func)
|
... | ... | |
793 |
796 |
if polySo is None:
|
794 |
797 |
return(None)
|
795 |
798 |
maxPrecision = pobyso_get_max_prec_of_exp_so_sa(polySo)
|
796 |
|
RRRR = RealField(maxPrecision)
|
797 |
|
polynomialRing = RRRR[functionSa.variables()[0]]
|
798 |
|
expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, RRRR)
|
799 |
|
polySa = polynomial(expSa, polynomialRing)
|
|
799 |
RRRRSa = RealField(maxPrecision)
|
|
800 |
polynomialRingSa = RRRRSa[functionSa.variables()[0]]
|
|
801 |
expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, RRRRSa)
|
|
802 |
polySa = polynomial(expSa, polynomialRingSa)
|
800 |
803 |
sollya_lib_clear_obj(polySo)
|
801 |
804 |
return(polySa)
|
|
805 |
# End pobyso_remez_canonical_sa_sa
|
802 |
806 |
|
803 |
807 |
def pobyso_remez_canonical(func, \
|
804 |
808 |
degree, \
|
... | ... | |
827 |
831 |
"""
|
828 |
832 |
var('zorglub') # Dummy variable name for type check only. Type of
|
829 |
833 |
# zorglub is "symbolic expression".
|
830 |
|
currentVariableName = None
|
|
834 |
currentVariableNameSa = None
|
831 |
835 |
# The func argument can be of different types (string,
|
832 |
836 |
# symbolic expression...)
|
833 |
837 |
if parent(func) == parent("string"):
|
834 |
|
functionSo = sollya_lib_parse_string(func)
|
|
838 |
localFuncSa = eval(func)
|
|
839 |
if len(localFuncSa.variables()) > 0:
|
|
840 |
currentVariableNameSa = localFuncSa.variables()[0]
|
|
841 |
sollya_lib_name_free_variable(str(currentVariableNameSa))
|
|
842 |
functionSo = sollya_lib_parse_string(localFuncSa._assume_str())
|
835 |
843 |
# Expression test.
|
836 |
844 |
elif type(func) == type(zorglub):
|
837 |
845 |
# Until we are able to translate Sage expressions into Sollya
|
838 |
846 |
# expressions : parse the string version.
|
839 |
|
currentVariableName = func.variables()[0]
|
840 |
|
sollya_lib_name_free_variable(str(currentVariableName))
|
841 |
|
functionSo = sollya_lib_parse_string(func._assume_str())
|
|
847 |
if len(func.variables()) > 0:
|
|
848 |
currentVariableNameSa = func.variables()[0]
|
|
849 |
sollya_lib_name_free_variable(str(currentVariableNameSa))
|
|
850 |
functionSo = sollya_lib_parse_string(func._assume_str())
|
842 |
851 |
else:
|
843 |
852 |
return(None)
|
844 |
|
if weight is None:
|
|
853 |
if weight is None: # No weight given -> 1.
|
845 |
854 |
weightSo = pobyso_constant_1_sa_so()
|
846 |
|
elif parent(weight) == parent("string"):
|
|
855 |
elif parent(weight) == parent("string"): # Weight given as string: parse it.
|
847 |
856 |
weightSo = sollya_lib_parse_string(func)
|
848 |
|
elif type(weight) == type(zorglub):
|
|
857 |
elif type(weight) == type(zorglub): # Weight given as symbolice expression.
|
849 |
858 |
functionSo = sollya_lib_parse_string_sa_so(weight._assume_str())
|
850 |
859 |
else:
|
851 |
860 |
return(None)
|
852 |
861 |
degreeSo = pobyso_constant_from_int(degree)
|
853 |
|
rangeSo = pobyso_range_sa_so(lowerBound, upperBound)
|
|
862 |
rangeSo = pobyso_bounds_to_range_sa_so(lowerBound, upperBound)
|
854 |
863 |
if not quality is None:
|
855 |
864 |
qualitySo= pobyso_constant_sa_so(quality)
|
856 |
865 |
else:
|
... | ... | |
867 |
876 |
sollya_lib_clear_obj(rangeSo)
|
868 |
877 |
sollya_lib_clear_obj(weightSo)
|
869 |
878 |
if not qualitySo is None:
|
870 |
|
sollya_lib_clear_obj(qualtiySo)
|
|
879 |
sollya_lib_clear_obj(qualitySo)
|
871 |
880 |
return(remezPolySo)
|
872 |
881 |
# End pobyso_remez_canonical_sa_so
|
873 |
882 |
|
... | ... | |
892 |
901 |
|
893 |
902 |
def pobyso_set_prec(p):
|
894 |
903 |
""" Legacy function. See pobyso_set_prec_sa_so. """
|
895 |
|
return( pobyso_set_prec_sa_so(p))
|
|
904 |
pobyso_set_prec_sa_so(p)
|
896 |
905 |
|
897 |
906 |
def pobyso_set_prec_sa_so(p):
|
898 |
907 |
a = c_int(p)
|
899 |
908 |
precSo = c_void_p(sollya_lib_constant_from_int(a))
|
900 |
|
sollya_lib_set_prec(precSo)
|
|
909 |
sollya_lib_set_prec(precSo, None)
|
901 |
910 |
|
902 |
|
def pobyso_supnorm_so_so(polySo, funcSo, intervalSo, errorTypeSo, accuracySo):
|
903 |
|
return(sollya_lib_supnorm(polySo, funcSo, intervalSo, errorTypeSo, \
|
904 |
|
accuracySo))
|
|
911 |
def pobyso_set_prec_so_so(newPrecSo):
|
|
912 |
sollya_lib_set_prec(newPrecSo, None)
|
905 |
913 |
|
906 |
|
def pobyso_taylor_expansion_with_change_var_so_so(functionSo, degreeSo, rangeSo, \
|
907 |
|
errorTypeSo, \
|
908 |
|
sollyaPrecSo=None):
|
|
914 |
def pobyso_supnorm_so_so(polySo, funcSo, intervalSo, errorTypeSo = None,\
|
|
915 |
accuracySo = None):
|
909 |
916 |
"""
|
|
917 |
Computes the supnorm of the approximation error between the given
|
|
918 |
polynomial and function.
|
|
919 |
errorTypeSo defaults to "absolute".
|
|
920 |
accuracySo defaults to 2^(-40).
|
|
921 |
"""
|
|
922 |
if errorTypeSo is None:
|
|
923 |
errorTypeSo = sollya_lib_absolute(None)
|
|
924 |
errorTypeIsNone = True
|
|
925 |
else:
|
|
926 |
errorTypeIsNone = False
|
|
927 |
#
|
|
928 |
if accuracySo is None:
|
|
929 |
# Notice the **!
|
|
930 |
accuracySo = pobyso_constant_sa_so(RR(2**(-40)))
|
|
931 |
accuracyIsNone = True
|
|
932 |
else:
|
|
933 |
accuracyIsNone = False
|
|
934 |
pobyso_autoprint(accuracySo)
|
|
935 |
resultSo = \
|
|
936 |
sollya_lib_supnorm(polySo, funcSo, intervalSo, errorTypeSo, \
|
|
937 |
accuracySo)
|
|
938 |
if errorTypeIsNone:
|
|
939 |
sollya_lib_clear_obj(errorTypeSo)
|
|
940 |
if accuracyIsNone:
|
|
941 |
sollya_lib_clear_obj(accuracySo)
|
|
942 |
return resultSo
|
|
943 |
# End pobyso_supnorm_so_so
|
|
944 |
|
|
945 |
def pobyso_taylor_expansion_with_change_var_so_so(functionSo, degreeSo, \
|
|
946 |
rangeSo, \
|
|
947 |
errorTypeSo=None, \
|
|
948 |
sollyaPrecSo=None):
|
|
949 |
"""
|
910 |
950 |
Compute the Taylor expansion with the variable change
|
911 |
951 |
x -> (x-intervalCenter) included.
|
912 |
952 |
"""
|
... | ... | |
915 |
955 |
initialPrecSo = sollya_lib_get_prec(None)
|
916 |
956 |
sollya_lib_set_prec(sollyaPrecSo)
|
917 |
957 |
#
|
|
958 |
# Error type stuff: default to absolute.
|
|
959 |
if errorTypeSo is None:
|
|
960 |
errorTypeIsNone = True
|
|
961 |
errorTypeSo = sollya_lib_absolute(None)
|
|
962 |
else:
|
|
963 |
errorTypeIsNone = False
|
918 |
964 |
intervalCenterSo = sollya_lib_mid(rangeSo)
|
919 |
965 |
taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \
|
920 |
966 |
intervalCenterSo, \
|
... | ... | |
932 |
978 |
if not sollyaPrecSo is None:
|
933 |
979 |
sollya_lib_set_prec(initialPrecSo)
|
934 |
980 |
sollya_lib_clear_obj(initialPrecSo)
|
|
981 |
if errorTypeIsNone:
|
|
982 |
sollya_lib_clear_obj(errorTypeSo)
|
|
983 |
sollya_lib_clear_obj(taylorFormSo)
|
|
984 |
# Do not clear maxErrorSo.
|
935 |
985 |
return((polyVarChangedSo, intervalCenterSo, maxErrorSo))
|
936 |
986 |
# end pobyso_taylor_expansion_with_change_var_so_so
|
937 |
987 |
|
938 |
988 |
def pobyso_taylor_expansion_no_change_var_so_so(functionSo, degreeSo, rangeSo, \
|
939 |
|
errorTypeSo, \
|
|
989 |
errorTypeSo=None, \
|
940 |
990 |
sollyaPrecSo=None):
|
941 |
991 |
"""
|
942 |
992 |
Compute the Taylor expansion without the variable change
|
... | ... | |
946 |
996 |
if not sollyaPrecSo is None:
|
947 |
997 |
initialPrecSo = sollya_lib_get_prec(None)
|
948 |
998 |
sollya_lib_set_prec(sollyaPrecSo)
|
949 |
|
#
|
|
999 |
# Error type stuff: default to absolute.
|
|
1000 |
if errorTypeSo is None:
|
|
1001 |
errorTypeIsNone = True
|
|
1002 |
errorTypeSo = sollya_lib_absolute(None)
|
|
1003 |
else:
|
|
1004 |
errorTypeIsNone = False
|
950 |
1005 |
intervalCenterSo = sollya_lib_mid(rangeSo)
|
951 |
1006 |
taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, \
|
952 |
1007 |
intervalCenterSo, \
|
953 |
1008 |
rangeSo, errorTypeSo, None)
|
954 |
|
(taylorFormListSo, numElements, isEndElliptic) = \
|
|
1009 |
(taylorFormListSo, numElementsSo, isEndEllipticSo) = \
|
955 |
1010 |
pobyso_get_list_elements_so_so(taylorFormSo)
|
956 |
|
polySo = taylorFormListSo[0]
|
|
1011 |
polySo = sollya_lib_copy_obj(taylorFormListSo[0])
|
957 |
1012 |
errorRangeSo = taylorFormListSo[2]
|
958 |
1013 |
maxErrorSo = sollya_lib_sup(errorRangeSo)
|
959 |
1014 |
# If changed, reset the Sollya working precision.
|
960 |
1015 |
if not sollyaPrecSo is None:
|
961 |
1016 |
sollya_lib_set_prec(initialPrecSo)
|
962 |
1017 |
sollya_lib_clear_obj(initialPrecSo)
|
|
1018 |
if errorTypeIsNone:
|
|
1019 |
sollya_lib_clear_obj(errorTypeSo)
|
|
1020 |
sollya_lib_clear_obj(taylorFormSo)
|
|
1021 |
# Do not clear maxErrorSo.
|
963 |
1022 |
return((polySo, intervalCenterSo, maxErrorSo))
|
964 |
1023 |
# end pobyso_taylor_expansion_no_change_var_so_so
|
965 |
1024 |
|
... | ... | |
970 |
1029 |
def pobyso_taylor_so_so(functionSo, degreeSo, pointSo):
|
971 |
1030 |
return(sollya_lib_taylor(functionSo, degreeSo, pointSo))
|
972 |
1031 |
|
973 |
|
def pobyso_taylorform(function, degree, point = None, interval = None, errorType=None):
|
974 |
|
""" Legacy function. See ;"""
|
|
1032 |
def pobyso_taylorform(function, degree, point = None,
|
|
1033 |
interval = None, errorType=None):
|
|
1034 |
""" Legacy function. See pobyso_taylorform_sa_sa;"""
|
975 |
1035 |
|
976 |
1036 |
def pobyso_taylorform_sa_sa(functionSa, \
|
977 |
1037 |
degreeSa, \
|
... | ... | |
980 |
1040 |
errorTypeSa=None, \
|
981 |
1041 |
precisionSa=None):
|
982 |
1042 |
"""
|
983 |
|
Compute the Taylor form of 'degree' for 'functionSa' at 'point'
|
984 |
|
for 'interval' with 'errorType' (a string).
|
|
1043 |
Compute the Taylor form of 'degreeSa' for 'functionSa' at 'pointSa'
|
|
1044 |
for 'intervalSa' with 'errorTypeSa' (a string) using 'precisionSa'.
|
985 |
1045 |
point: must be a Real or a Real interval.
|
986 |
1046 |
return the Taylor form as an array
|
987 |
1047 |
TODO: take care of the interval and of the point when it is an interval;
|
... | ... | |
1008 |
1068 |
pobyso_set_prec_sa_so(precisionSa)
|
1009 |
1069 |
precisionChangedSa = True
|
1010 |
1070 |
|
1011 |
|
varSa = functionSa.variables()[0]
|
1012 |
|
pobyso_name_free_variable_sa_so(str(varSa))
|
|
1071 |
if len(functionSa.variables()) > 0:
|
|
1072 |
varSa = functionSa.variables()[0]
|
|
1073 |
pobyso_name_free_variable_sa_so(str(varSa))
|
1013 |
1074 |
# In any case (point or interval) the parent of pointSa has a precision
|
1014 |
1075 |
# method.
|
1015 |
1076 |
pointPrecSa = pointSa.parent().precision()
|
... | ... | |
1033 |
1094 |
taylorFormSo = \
|
1034 |
1095 |
sollya_lib_taylorform(functionSo, degreeSo, pointSo, errorTypeSo,\
|
1035 |
1096 |
None)
|
|
1097 |
sollya_lib_clear_obj(functionSo)
|
|
1098 |
sollya_lib_clear_obj(degreeSo)
|
|
1099 |
sollya_lib_clear_obj(pointSo)
|
|
1100 |
sollya_lib_clear_obj(errorTypeSo)
|
1036 |
1101 |
(tfsAsList, numElements, isEndElliptic) = \
|
1037 |
1102 |
pobyso_get_list_elements_so_so(taylorFormSo)
|
1038 |
1103 |
polySo = tfsAsList[0]
|
... | ... | |
1042 |
1107 |
if precisionChangedSa:
|
1043 |
1108 |
sollya_lib_set_prec(currentSollyaPrecSo)
|
1044 |
1109 |
sollya_lib_clear_obj(currentSollyaPrecSo)
|
1045 |
|
# Clean up.
|
1046 |
|
sollya_lib_clear_obj(pointSo) # Works, whatever the type of pointSo is.
|
1047 |
|
sollya_lib_clear_obj(errorTypeSo)
|
1048 |
|
sollya_lib_clear_obj(degreeSo)
|
1049 |
1110 |
polynomialRing = polyRealField[str(varSa)]
|
1050 |
1111 |
polySa = polynomial(expSa, polynomialRing)
|
1051 |
1112 |
taylorFormSa = [polySa]
|
|
1113 |
# Final clean-up.
|
|
1114 |
sollya_lib_clear_obj(taylorFormSo)
|
1052 |
1115 |
return(taylorFormSa)
|
1053 |
1116 |
# End pobyso_taylor_form_sa_sa
|
1054 |
1117 |
|