Révision 178 pobysoPythonSage/src/sageSLZ/sageSLZ.sage
sageSLZ.sage (revision 178) | ||
---|---|---|
10 | 10 |
""" |
11 | 11 |
print "sageSLZ loading..." |
12 | 12 |
# |
13 |
def slz_check_htr_value(function, htrValue, lowerBound, upperBound, precision, \ |
|
14 |
degree, targetHardnessToRound, alpha): |
|
15 |
""" |
|
16 |
Check an Hard-to-round value. |
|
17 |
TODO:: |
|
18 |
Full rewriting: this is hardly a draft. |
|
19 |
""" |
|
20 |
polyApproxPrec = targetHardnessToRound + 1 |
|
21 |
polyTargetHardnessToRound = targetHardnessToRound + 1 |
|
22 |
internalSollyaPrec = ceil((RR('1.5') * targetHardnessToRound) / 64) * 64 |
|
23 |
RRR = htrValue.parent() |
|
24 |
# |
|
25 |
## Compute the scaled function. |
|
26 |
fff = slz_compute_scaled_function(f, lowerBound, upperBound, precision)[0] |
|
27 |
print "Scaled function:", fff |
|
28 |
# |
|
29 |
## Compute the scaling. |
|
30 |
boundsIntervalRifSa = RealIntervalField(precision) |
|
31 |
domainBoundsInterval = boundsIntervalRifSa(lowerBound, upperBound) |
|
32 |
scalingExpressions = \ |
|
33 |
slz_interval_scaling_expression(domainBoundsInterval, i) |
|
34 |
# |
|
35 |
## Get the polynomials, bounds, etc. for all the interval. |
|
36 |
resultListOfTuplesOfSo = \ |
|
37 |
slz_get_intervals_and_polynomials(f, degree, lowerBound, upperBound, \ |
|
38 |
precision, internalSollyaPrec,\ |
|
39 |
2^-(polyApproxPrec)) |
|
40 |
# |
|
41 |
## We only want one interval. |
|
42 |
if len(resultListOfTuplesOfSo) > 1: |
|
43 |
print "Too many intervals! Aborting!" |
|
44 |
exit |
|
45 |
# |
|
46 |
## Get the first tuple of Sollya objects as Sage objects. |
|
47 |
firstTupleSa = \ |
|
48 |
slz_interval_and_polynomial_to_sage(resultListOfTuplesOfSo[0]) |
|
49 |
pobyso_set_canonical_on() |
|
50 |
# |
|
51 |
print "Floatting point polynomial:", firstTupleSa[0] |
|
52 |
print "with coefficients precision:", firstTupleSa[0].base_ring().prec() |
|
53 |
# |
|
54 |
## From a polynomial over a real ring, create a polynomial over the |
|
55 |
# rationals ring. |
|
56 |
rationalPolynomial = \ |
|
57 |
slz_float_poly_of_float_to_rat_poly_of_rat(firstTupleSa[0]) |
|
58 |
print "Rational polynomial:", rationalPolynomial |
|
59 |
# |
|
60 |
## Create a polynomial over the rationals that will take integer |
|
61 |
# variables instead of rational. |
|
62 |
rationalPolynomialOfIntegers = \ |
|
63 |
slz_rat_poly_of_rat_to_rat_poly_of_int(rationalPolynomial, precision) |
|
64 |
print "Type:", type(rationalPolynomialOfIntegers) |
|
65 |
print "Rational polynomial of integers:", rationalPolynomialOfIntegers |
|
66 |
# |
|
67 |
## Check the rational polynomial of integers variables. |
|
68 |
# (check against the scaled function). |
|
69 |
toIntegerFactor = 2^(precision-1) |
|
70 |
intervalCenterAsIntegerSa = int(firstTupleSa[3] * toIntegerFactor) |
|
71 |
print "Interval center as integer:", intervalCenterAsIntegerSa |
|
72 |
lowerBoundAsIntegerSa = int(firstTupleSa[2].endpoints()[0] * \ |
|
73 |
toIntegerFactor) - intervalCenterAsIntegerSa |
|
74 |
upperBoundAsIntegerSa = int(firstTupleSa[2].endpoints()[1] * \ |
|
75 |
toIntegerFactor) - intervalCenterAsIntegerSa |
|
76 |
print "Lower bound as integer:", lowerBoundAsIntegerSa |
|
77 |
print "Upper bound as integer:", upperBoundAsIntegerSa |
|
78 |
print "Image of the lower bound by the scaled function", \ |
|
79 |
fff(firstTupleSa[2].endpoints()[0]) |
|
80 |
print "Image of the lower bound by the approximation polynomial of ints:", \ |
|
81 |
RRR(rationalPolynomialOfIntegers(lowerBoundAsIntegerSa)) |
|
82 |
print "Image of the center by the scaled function", fff(firstTupleSa[3]) |
|
83 |
print "Image of the center by the approximation polynomial of ints:", \ |
|
84 |
RRR(rationalPolynomialOfIntegers(0)) |
|
85 |
print "Image of the upper bound by the scaled function", \ |
|
86 |
fff(firstTupleSa[2].endpoints()[1]) |
|
87 |
print "Image of the upper bound by the approximation polynomial of ints:", \ |
|
88 |
RRR(rationalPolynomialOfIntegers(upperBoundAsIntegerSa)) |
|
89 |
|
|
90 |
# End slz_check_htr_value. |
|
91 |
|
|
92 | 13 |
def slz_compute_binade(number): |
93 | 14 |
"""" |
94 | 15 |
For a given number, compute the "binade" that is integer m such that |
Formats disponibles : Unified diff