Révision 2669308a
b/src/functions_for_cvp.sage | ||
---|---|---|
521 | 521 |
return extraScalingExp |
522 | 522 |
# End cvp_extra_function_scaling_exp. |
523 | 523 |
# |
524 |
def cvp_filter_out_undefined_image(initialPointList, func): |
|
525 |
""" |
|
526 |
Fom the initial list and function, built a list of points which have a |
|
527 |
defined image. |
|
528 |
""" |
|
529 |
finalPointsList = [] |
|
530 |
for iterPoint in initialPointList: |
|
531 |
try: |
|
532 |
finalPointsList.append(func(iterPoint)) |
|
533 |
#print "cfoui - Point", iterPoint, "done." |
|
534 |
except ValueError: |
|
535 |
pass |
|
536 |
#print "cfoui - Point", iterPoint, "failed." |
|
537 |
return finalPointsList |
|
538 |
# End cvp_filter_out_undefined_image |
|
539 |
|
|
524 | 540 |
def cvp_float_basis(monomialsList, pointsList, realField): |
525 | 541 |
""" |
526 | 542 |
For a given monomials list and points list, compute the floating-point |
... | ... | |
549 | 565 |
## Some local variables. |
550 | 566 |
basisPointsNum = len(basisPointsList) |
551 | 567 |
# |
568 |
floatVector = vector(realField, basisPointsNum) |
|
552 | 569 |
## |
553 |
vVect = vector(realField, basisPointsNum) |
|
554 | 570 |
for vIndex in xrange(0,basisPointsNum): |
555 |
vVect[vIndex] = \ |
|
556 |
func(basisPointsList[vIndex]) |
|
557 |
return vVect |
|
571 |
### We assume the all for all points their image is defined. |
|
572 |
floatVector[vIndex] = \ |
|
573 |
func(basisPointsList[vIndex]) |
|
574 |
return floatVector |
|
558 | 575 |
# End cvp_float_vector_for_approx. |
559 | 576 |
# |
560 |
def cvp_func_abs_max_for_points(func, pointsList): |
|
577 |
def cvp_func_abs_max_for_points(func, pointsList, realField):
|
|
561 | 578 |
""" |
562 | 579 |
Compute the maximum absolute value of a function for a list of |
563 | 580 |
points. |
... | ... | |
572 | 589 |
return None |
573 | 590 |
# |
574 | 591 |
for pt in pointsList: |
575 |
evalDict[abs(func(pt))] = pt |
|
592 |
try: |
|
593 |
evalDict[abs(realField(func(pt)))] = realField(pt) |
|
594 |
#print "cfamfp - point:", realField(pt) , "- image:", abs(realField(func(pt))) |
|
595 |
except ValueError: |
|
596 |
pass |
|
576 | 597 |
maxAbs = max(evalDict.keys()) |
598 |
#print "cfamfp - maxAbs:", maxAbs, evalDict[maxAbs] |
|
577 | 599 |
return (evalDict[maxAbs], maxAbs) |
578 | 600 |
# End cvp_func_abs_max_for_points |
579 | 601 |
# |
580 | 602 |
def cvp_hkz_reduce(intBasis): |
581 | 603 |
""" |
582 |
Thin and simplistic wrapper the HKZ function of the FP_LLL module. |
|
604 |
Thin and simplistic wrapper on the HKZ function of the FP_LLL module.
|
|
583 | 605 |
""" |
584 | 606 |
fplllIntBasis = FP_LLL(intBasis) |
585 | 607 |
fplllIntBasis.HKZ() |
... | ... | |
719 | 741 |
pobyso_clear_obj(errorFuncSo) |
720 | 742 |
return None |
721 | 743 |
#print "cpefa: error function in Sollya OK." |
744 |
## Evaluate the error function at both bounds, it may be usefull, if |
|
745 |
# the error function is monotonous |
|
746 |
## Lower bound stuff. |
|
747 |
lowerBoundSo = pobyso_constant_sa_so(lowerBoundSa) |
|
748 |
if pobyso_is_error_so_sa(lowerBoundSo): |
|
749 |
pobyso_clear_obj(errorFuncSo) |
|
750 |
pobyso_clear_obj(lowerBoundSo) |
|
751 |
return None |
|
752 |
errFuncAtLbSa = pobyso_evaluate_so_sa(errorFuncSo, lowerBoundSo) |
|
753 |
pobyso_clear_obj(lowerBoundSo) |
|
754 |
if errFuncAtLbSa is None: |
|
755 |
pobyso_clear_obj(errorFuncSo) |
|
756 |
return None |
|
757 |
## The result of the evaluation can be an interval. |
|
758 |
try: |
|
759 |
errFuncAtLbSa = errFuncAtLbSa.center() |
|
760 |
except: |
|
761 |
errFuncAtLbSa = errFuncAtLbSa |
|
762 |
#print "cpefa: errFuncAtLbSa:", errFuncAtLbSa |
|
763 |
## Upper bound stuff. |
|
764 |
upperBoundSo = pobyso_constant_sa_so(upperBoundSa) |
|
765 |
if pobyso_is_error_so_sa(upperBoundSo): |
|
766 |
pobyso_clear_obj(errorFuncSo) |
|
767 |
pobyso_clear_obj(upperBoundSo) |
|
768 |
return None |
|
769 |
errFuncAtUbSa = pobyso_evaluate_so_sa(errorFuncSo, upperBoundSo) |
|
770 |
pobyso_clear_obj(upperBoundSo) |
|
771 |
if errFuncAtUbSa is None: |
|
772 |
return None |
|
773 |
## The result of the evaluation can be an interval. |
|
774 |
try: |
|
775 |
errFuncAtUbSa = errFuncAtUbSa.center() |
|
776 |
except: |
|
777 |
errFuncAtUbSa = errFuncAtUbSa |
|
778 |
#print "cpefa: errFuncAtUbSa:", errFuncAtUbSa |
|
722 | 779 |
## Compute the derivative. |
723 | 780 |
diffErrorFuncSo = pobyso_diff_so_so(errorFuncSo) |
724 | 781 |
pobyso_clear_obj(errorFuncSo) |
... | ... | |
768 | 825 |
#print "cpefa:", ; pobyso_autoprint(errorFuncMaxisSo) |
769 | 826 |
##### The findzeros functions returns intervals (ranges). |
770 | 827 |
errorFuncRangeMaxisSa = pobyso_range_list_so_sa(errorFuncMaxisSo) |
828 |
#print "cpefa:", errorFuncRangeMaxisSa |
|
771 | 829 |
pobyso_clear_obj(errorFuncMaxisSo) |
772 | 830 |
errorFuncMaxisSa = [] |
773 |
for interval in errorFuncRangeMaxisSa: |
|
774 |
errorFuncMaxisSa.append(interval.center()) |
|
831 |
if len(errorFuncRangeMaxisSa) != 0: |
|
832 |
for interval in errorFuncRangeMaxisSa: |
|
833 |
errorFuncMaxisSa.append(interval.center()) |
|
834 |
#print "cpefa:", errorFuncMaxisSa |
|
835 |
else: # The error function is monotonous. It reaches its maximum |
|
836 |
# at either of the bounds. |
|
837 |
errFuncMaxAtBounds = max(abs(errFuncAtLbSa), abs(errFuncAtUbSa)) |
|
838 |
if errFuncMaxAtBounds == abs(errFuncAtLbSa): |
|
839 |
errorFuncMaxisSa.append(lowerBoundSa) |
|
840 |
else: |
|
841 |
errorFuncMaxisSa.append(upperBoundSa) |
|
775 | 842 |
pobyso_clear_obj(diffErrorFuncSo) |
776 | 843 |
pobyso_clear_obj(intervalSo) |
777 | 844 |
## If required, convert the numbers to rational numbers. |
Formats disponibles : Unified diff