Révision 72 pobysoPythonSage/src/sageSLZ/sageSLZ.sage
sageSLZ.sage (revision 72) | ||
---|---|---|
1 |
|
|
2 | 1 |
def slz_compute_polynomial_and_interval(functionSo, degreeSo, lowerBoundSa, |
3 | 2 |
upperBoundSa, approxPrecSa, |
4 | 3 |
sollyaPrecSa=None): |
... | ... | |
58 | 57 |
return((polySo, currentRangeSo, intervalCenterSo, maxErrorSo)) |
59 | 58 |
# End slz_compute_polynomial_and_interval |
60 | 59 |
|
60 |
def slz_compute_scaled_function(functionSa, \ |
|
61 |
variableNameSa, \ |
|
62 |
lowerBoundSa, \ |
|
63 |
upperBoundSa, \ |
|
64 |
floatingPointPrecSa): |
|
65 |
""" |
|
66 |
From a function, compute the scaled function whose domain |
|
67 |
is included in [1, 2) and whose image is also included in [1,2). |
|
68 |
Return a tuple: |
|
69 |
[0]: the scaled function |
|
70 |
[1]: the scaled domain lower bound |
|
71 |
[2]: the scaled domain upper bound |
|
72 |
[3]: the scaled image lower bound |
|
73 |
[4]: the scaled image upper bound |
|
74 |
""" |
|
75 |
x = var(variableNameSa) |
|
76 |
# Scalling the domain -> [1,2[. |
|
77 |
boundsIntervalRifSa = RealIntervalField(floatingPointPrecSa) |
|
78 |
domainBoundsIntervalSa = boundsIntervalRifSa(lowerBoundSa, upperBoundSa) |
|
79 |
(domainScalingExpressionSa, invDomainScalingExpressionSa) = \ |
|
80 |
slz_interval_scaling_expression(domainBoundsIntervalSa, variableNameSa) |
|
81 |
print "domainScalingExpression for argument :", domainScalingExpressionSa |
|
82 |
print "f: ", f |
|
83 |
ff = f.subs({x : domainScalingExpressionSa}) |
|
84 |
#ff = f.subs_expr(x==domainScalingExpressionSa) |
|
85 |
scaledLowerBoundSa = invDomainScalingExpressionSa(lowerBoundSa).n() |
|
86 |
scaledUpperBoundSa = invDomainScalingExpressionSa(upperBoundSa).n() |
|
87 |
print 'ff:', ff, "- Domain:", scaledLowerBoundSa, scaledUpperBoundSa |
|
88 |
# |
|
89 |
# Scalling the image -> [1,2[. |
|
90 |
flbSa = f(lowerBoundSa).n() |
|
91 |
fubSa = f(upperBoundSa).n() |
|
92 |
if flbSa <= fubSa: # Increasing |
|
93 |
imageBinadeBottomSa = floor(flbSa.log2()) |
|
94 |
else: # Decreasing |
|
95 |
imageBinadeBottomSa = floor(fubSa.log2()) |
|
96 |
print 'ff:', ff, '- Image:', flbSa, fubSa, imageBinadeBottomSa |
|
97 |
imageBoundsIntervalSa = boundsIntervalRifSa(flbSa, fubSa) |
|
98 |
(imageScalingExpressionSa, invImageScalingExpressionSa) = \ |
|
99 |
slz_interval_scaling_expression(imageBoundsIntervalSa, variableNameSa) |
|
100 |
iis = invImageScalingExpressionSa.function(x) |
|
101 |
fff = iis.subs({x:ff}) |
|
102 |
print "fff:", fff, |
|
103 |
print " - Image:", fff(scaledLowerBoundSa), fff(scaledUpperBoundSa) |
|
104 |
return([fff, scaledLowerBoundSa, scaledUpperBoundSa, \ |
|
105 |
fff(scaledLowerBoundSa), fff(scaledUpperBoundSa)]) |
|
106 |
|
|
61 | 107 |
def slz_get_intervals_and_polynomials(functionSa, variableNameSa, degreeSa, |
62 | 108 |
lowerBoundSa, |
63 | 109 |
upperBoundSa, floatingPointPrecSa, |
... | ... | |
73 | 119 |
- the floating-point precision we work on; |
74 | 120 |
- the internal Sollya precision; |
75 | 121 |
- the requested approximation error |
76 |
compute a list of tuples made of: |
|
77 |
- a polynomial approximating the function (a Sollya object); |
|
78 |
- the range for which the polynomial approximates the function |
|
79 |
(a Sollya object); |
|
80 |
- the center of the interval (a Sollya object); |
|
81 |
- the actual approximation error (a Sage object). |
|
82 | 122 |
The initial interval is, possibly, splitted into smaller intervals. |
83 | 123 |
It return a list of tuples, each made of: |
84 |
- a polynomial; |
|
124 |
- a first polynomial (without the changed variable f(x) = p(x-x0)); |
|
125 |
- a second polynomila (with a changed variable f(x) = q(x)) |
|
85 | 126 |
- the approximation interval; |
86 |
- the center, x0, of the interval (the polynomial is defined as p(x-x0));
|
|
127 |
- the center, x0, of the interval;
|
|
87 | 128 |
- the corresponding approximation error. |
88 | 129 |
""" |
89 | 130 |
x = var(variableNameSa) |
... | ... | |
196 | 237 |
|
197 | 238 |
|
198 | 239 |
def slz_polynomial_and_interval_to_sage(polyRangeCenterErrorSo): |
240 |
""" |
|
241 |
Compute the Sage version of the Taylor polynomial and it's |
|
242 |
companion data (interval, center...) |
|
243 |
The input parameter is a five elements tuple: |
|
244 |
- [0]: the polyomial (without variable change); |
|
245 |
- [1]: the polyomial (with variable change done in Sollya); |
|
246 |
- [2]: the interval (as Sollya range); |
|
247 |
- [3]: the interval center; |
|
248 |
- [4]: the approximation error. |
|
249 |
|
|
250 |
The function return a 5 elements tuple: formed with all the |
|
251 |
input elements converted into their Sollya counterpart. |
|
252 |
""" |
|
199 | 253 |
polynomialSa = pobyso_get_poly_so_sa(polyRangeCenterErrorSo[0]) |
200 | 254 |
polynomialChangedVarSa = pobyso_get_poly_so_sa(polyRangeCenterErrorSo[1]) |
201 | 255 |
intervalSa = \ |
Formats disponibles : Unified diff