| 476 |
476 |
output polynomial ; this error <= approxPrecSaS.
|
| 477 |
477 |
|
| 478 |
478 |
"""
|
|
479 |
## Superficial argument check.
|
|
480 |
if lowerBoundSa > upperBoundSa:
|
|
481 |
return None
|
| 479 |
482 |
RRR = lowerBoundSa.parent()
|
| 480 |
|
intervalShrinkConstFactorSa = RRR('0.5')
|
|
483 |
intervalShrinkConstFactorSa = RRR('0.8')
|
| 481 |
484 |
absoluteErrorTypeSo = pobyso_absolute_so_so()
|
| 482 |
485 |
currentRangeSo = pobyso_bounds_to_range_sa_so(lowerBoundSa, upperBoundSa)
|
| 483 |
486 |
currentUpperBoundSa = upperBoundSa
|
| ... | ... | |
| 491 |
494 |
absoluteErrorTypeSo)
|
| 492 |
495 |
maxErrorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo)
|
| 493 |
496 |
while maxErrorSa > approxPrecSa:
|
| 494 |
|
#print "++Approximation error:", maxErrorSa
|
|
497 |
print "++Approximation error:", maxErrorSa
|
| 495 |
498 |
sollya_lib_clear_obj(polySo)
|
| 496 |
499 |
sollya_lib_clear_obj(intervalCenterSo)
|
| 497 |
500 |
sollya_lib_clear_obj(maxErrorSo)
|
| ... | ... | |
| 691 |
694 |
# Scalling the domain -> [1,2[.
|
| 692 |
695 |
boundsIntervalRifSa = RealIntervalField(floatingPointPrecSa)
|
| 693 |
696 |
domainBoundsIntervalSa = boundsIntervalRifSa(lowerBoundSa, upperBoundSa)
|
| 694 |
|
(domainScalingExpressionSa, invDomainScalingExpressionSa) = \
|
|
697 |
(invDomainScalingExpressionSa, domainScalingExpressionSa) = \
|
| 695 |
698 |
slz_interval_scaling_expression(domainBoundsIntervalSa, x)
|
| 696 |
699 |
if debug:
|
| 697 |
700 |
print "domainScalingExpression for argument :", \
|
| ... | ... | |
| 718 |
721 |
if debug:
|
| 719 |
722 |
print 'ff:', ff, '- Image:', flbSa, fubSa, imageBinadeBottomSa
|
| 720 |
723 |
imageBoundsIntervalSa = boundsIntervalRifSa(flbSa, fubSa)
|
| 721 |
|
(imageScalingExpressionSa, invImageScalingExpressionSa) = \
|
|
724 |
(invImageScalingExpressionSa,imageScalingExpressionSa) = \
|
| 722 |
725 |
slz_interval_scaling_expression(imageBoundsIntervalSa, x)
|
| 723 |
726 |
if debug:
|
| 724 |
727 |
print "imageScalingExpression for argument :", \
|
| ... | ... | |
| 779 |
782 |
lowerBoundSa, \
|
| 780 |
783 |
upperBoundSa, \
|
| 781 |
784 |
floatingPointPrecSa)
|
| 782 |
|
#
|
|
785 |
# In case bounds were in the negative real one may need to
|
|
786 |
# switch scaled bounds.
|
|
787 |
if scaledLowerBoundSa > scaledUpperBoundSa:
|
|
788 |
scaledLowerBoundSa, scaledUpperBoundSa = \
|
|
789 |
scaledUpperBoundSa, scaledLowerBoundSa
|
|
790 |
#print "Switching!"
|
| 783 |
791 |
print "Approximation precision: ", RR(approxPrecSa)
|
| 784 |
792 |
# Prepare the arguments for the Taylor expansion computation with Sollya.
|
| 785 |
793 |
functionSo = \
|
| ... | ... | |
| 788 |
796 |
scaledBoundsSo = pobyso_bounds_to_range_sa_so(scaledLowerBoundSa,
|
| 789 |
797 |
scaledUpperBoundSa)
|
| 790 |
798 |
# Compute the first Taylor expansion.
|
|
799 |
print "Computing first Taylor expansion..."
|
| 791 |
800 |
(polySo, boundsSo, intervalCenterSo, maxErrorSo) = \
|
| 792 |
801 |
slz_compute_polynomial_and_interval(functionSo, degreeSo,
|
| 793 |
802 |
scaledLowerBoundSa, scaledUpperBoundSa,
|
| 794 |
803 |
approxPrecSa, internalSollyaPrecSa)
|
|
804 |
print "...done."
|
| 795 |
805 |
if polySo is None:
|
| 796 |
806 |
print "slz_get_intervals_and_polynomials: Aborting and returning None!"
|
| 797 |
807 |
if precChangedSa:
|
| ... | ... | |
| 805 |
815 |
upperBoundSa.parent().precision()))
|
| 806 |
816 |
boundsSa = pobyso_range_to_interval_so_sa(boundsSo, realIntervalField)
|
| 807 |
817 |
errorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo)
|
| 808 |
|
print "First approximation error:", errorSa.n(digits=50)
|
|
818 |
print "First approximation error:", errorSa.n(digits=10)
|
| 809 |
819 |
# If the error and interval are OK a the first try, just return.
|
| 810 |
820 |
if boundsSa.endpoints()[1] >= scaledUpperBoundSa:
|
| 811 |
821 |
# Change variable stuff in Sollya x -> x0-x.
|
| ... | ... | |
| 905 |
915 |
def slz_interval_scaling_expression(boundsInterval, expVar):
|
| 906 |
916 |
"""
|
| 907 |
917 |
Compute the scaling expression to map an interval that spans at most
|
| 908 |
|
a single binade to [1, 2) and the inverse expression as well.
|
|
918 |
a single binade into [1, 2) and the inverse expression as well.
|
| 909 |
919 |
If the interval spans more than one binade, result is wrong since
|
| 910 |
920 |
scaling is only based on the lower bound.
|
| 911 |
921 |
Not very sure that the transformation makes sense for negative numbers.
|
| ... | ... | |
| 981 |
991 |
if boundsInterval.endpoints()[0] > 0:
|
| 982 |
992 |
return((2^(-lbBinade) * expVar),(2^(lbBinade) * expVar))
|
| 983 |
993 |
else:
|
| 984 |
|
return((-(2^(-lbBinade+1)) * expVar),(-(2^(lbBinade-1)) * expVar))
|
|
994 |
return((-(2^(-ubBinade)) * expVar),(-(2^(ubBinade)) * expVar))
|
| 985 |
995 |
"""
|
| 986 |
996 |
# Code sent to attic. Should be the base for a
|
| 987 |
997 |
# "slz_interval_translate_expression" rather than scale.
|