Révision 151 pobysoPythonSage/src/sageSLZ/sageSLZ.sage
sageSLZ.sage (revision 151) | ||
---|---|---|
653 | 653 |
domainBoundsIntervalSa = boundsIntervalRifSa(lowerBoundSa, upperBoundSa) |
654 | 654 |
(domainScalingExpressionSa, invDomainScalingExpressionSa) = \ |
655 | 655 |
slz_interval_scaling_expression(domainBoundsIntervalSa, x) |
656 |
print "domainScalingExpression for argument :", domainScalingExpressionSa
|
|
656 |
print "domainScalingExpression for argument :", invDomainScalingExpressionSa
|
|
657 | 657 |
print "f: ", f |
658 | 658 |
ff = f.subs({x : domainScalingExpressionSa}) |
659 | 659 |
#ff = f.subs_expr(x==domainScalingExpressionSa) |
660 | 660 |
domainScalingFunction(x) = invDomainScalingExpressionSa |
661 |
scaledLowerBoundSa = domainScalingFunction(lowerBoundSa).n() |
|
662 |
scaledUpperBoundSa = domainScalingFunction(upperBoundSa).n() |
|
661 |
scaledLowerBoundSa = \ |
|
662 |
domainScalingFunction(lowerBoundSa).n(prec=floatingPointPrecSa) |
|
663 |
scaledUpperBoundSa = \ |
|
664 |
domainScalingFunction(upperBoundSa).n(prec=floatingPointPrecSa) |
|
663 | 665 |
print 'ff:', ff, "- Domain:", scaledLowerBoundSa, scaledUpperBoundSa |
664 | 666 |
# |
665 | 667 |
# Scalling the image -> [1,2[. |
666 |
flbSa = f(lowerBoundSa).n()
|
|
667 |
fubSa = f(upperBoundSa).n()
|
|
668 |
flbSa = ff(scaledLowerBoundSa).n(prec=floatingPointPrecSa)
|
|
669 |
fubSa = ff(scaledUpperBoundSa).n(prec=floatingPointPrecSa)
|
|
668 | 670 |
if flbSa <= fubSa: # Increasing |
669 | 671 |
imageBinadeBottomSa = floor(flbSa.log2()) |
670 | 672 |
else: # Decreasing |
... | ... | |
673 | 675 |
imageBoundsIntervalSa = boundsIntervalRifSa(flbSa, fubSa) |
674 | 676 |
(imageScalingExpressionSa, invImageScalingExpressionSa) = \ |
675 | 677 |
slz_interval_scaling_expression(imageBoundsIntervalSa, x) |
678 |
print "imageScalingExpression for argument :", invImageScalingExpressionSa |
|
676 | 679 |
iis = invImageScalingExpressionSa.function(x) |
677 | 680 |
fff = iis.subs({x:ff}) |
678 | 681 |
print "fff:", fff, |
679 | 682 |
print " - Image:", fff(scaledLowerBoundSa), fff(scaledUpperBoundSa) |
680 | 683 |
return([fff, scaledLowerBoundSa, scaledUpperBoundSa, \ |
681 | 684 |
fff(scaledLowerBoundSa), fff(scaledUpperBoundSa)]) |
685 |
# End slz_compute_scaled_function |
|
682 | 686 |
|
683 | 687 |
def slz_float_poly_of_float_to_rat_poly_of_rat(polyOfFloat): |
684 | 688 |
# Create a polynomial over the rationals. |
... | ... | |
752 | 756 |
upperBoundSa.parent().precision())) |
753 | 757 |
boundsSa = pobyso_range_to_interval_so_sa(boundsSo, realIntervalField) |
754 | 758 |
errorSa = pobyso_get_constant_as_rn_with_rf_so_sa(maxErrorSo) |
755 |
#print "First approximation error:", errorSa
|
|
759 |
print "First approximation error:", errorSa.n(digits=50)
|
|
756 | 760 |
# If the error and interval are OK a the first try, just return. |
757 | 761 |
if boundsSa.endpoints()[1] >= scaledUpperBoundSa: |
758 | 762 |
# Change variable stuff in Sollya x -> x0-x. |
... | ... | |
851 | 855 |
|
852 | 856 |
def slz_interval_scaling_expression(boundsInterval, expVar): |
853 | 857 |
""" |
854 |
Compute the scaling expression to map an interval that span at most |
|
858 |
Compute the scaling expression to map an interval that spans at most
|
|
855 | 859 |
a single binade to [1, 2) and the inverse expression as well. |
856 | 860 |
Not very sure that the transformation makes sense for negative numbers. |
857 | 861 |
""" |
858 | 862 |
# The scaling offset is only used for negative numbers. |
863 |
# When the absolute value of the lower bound is < 0. |
|
859 | 864 |
if abs(boundsInterval.endpoints()[0]) < 1: |
860 | 865 |
if boundsInterval.endpoints()[0] >= 0: |
861 | 866 |
scalingCoeff = 2^floor(boundsInterval.endpoints()[0].log2()) |
... | ... | |
881 | 886 |
#scalingOffset = 0 |
882 | 887 |
return((scalingCoeff * expVar + scalingOffset, |
883 | 888 |
1/scalingCoeff * expVar + 3)) |
884 |
|
|
889 |
# End slz_interval_scaling_expression |
|
885 | 890 |
|
886 | 891 |
def slz_interval_and_polynomial_to_sage(polyRangeCenterErrorSo): |
887 | 892 |
""" |
... | ... | |
994 | 999 |
|
995 | 1000 |
|
996 | 1001 |
print "\t...sageSLZ loaded" |
997 |
|
Formats disponibles : Unified diff