Révision 64
pobysoPythonSage/src/sageSLZ.sage (revision 64) | ||
---|---|---|
59 | 59 |
def slz_get_intervals_and_polynomials(functionSa, variableNameSa, degreeSa, |
60 | 60 |
lowerBoundSa, |
61 | 61 |
upperBoundSa, floatingPointPrecSa, |
62 |
internalSollyaPrecSa): |
|
62 |
internalSollyaPrecSa, approxPrecSa):
|
|
63 | 63 |
""" |
64 | 64 |
Under the assumption that: |
65 | 65 |
- functionSa is monotonic on the [lowerBoundSa, upperBoundSa] interval; |
... | ... | |
70 | 70 |
- a pair of bounds; |
71 | 71 |
- the floating-point precision we work on; |
72 | 72 |
- the internal Sollya precision; |
73 |
- the requested approximation error |
|
73 | 74 |
compute a list of tuples made of: |
74 | 75 |
- a polynomial approximating the function (a Sollya object); |
75 | 76 |
- the range for which the polynomial approximates the function |
76 | 77 |
(a Sollya object); |
77 | 78 |
- the center of the interval (a Sollya object); |
78 |
- the approximation error (a Sage object). |
|
79 |
- the actual approximation error (a Sage object).
|
|
79 | 80 |
The initial interval is, possibly, splitted into smaller intervals. |
80 | 81 |
It return a list of tuples, each made of: |
81 | 82 |
- a polynomial; |
... | ... | |
91 | 92 |
slz_interval_scaling_expression(domainBoundsIntervalSa, variableNameSa) |
92 | 93 |
print "domainScalingExpression for argument :", domainScalingExpressionSa |
93 | 94 |
print "f: ", f |
94 |
ff = f.subs({x:domainScalingExpressionSa}) |
|
95 |
ff = f.subs({x : domainScalingExpressionSa}) |
|
96 |
#ff = f.subs_expr(x==domainScalingExpressionSa) |
|
95 | 97 |
scaledLowerBoundSa = invDomainScalingExpressionSa(lowerBoundSa).n() |
96 | 98 |
scaledUpperBoundSa = invDomainScalingExpressionSa(upperBoundSa).n() |
97 | 99 |
print 'ff:', ff, "- Domain:", scaledLowerBoundSa, scaledUpperBoundSa |
... | ... | |
114 | 116 |
# |
115 | 117 |
resultArray = [] |
116 | 118 |
# |
117 |
approxPrecSa = 1/(2^(floatingPointPrecSa + 1)) |
|
118 | 119 |
print "Approximation precision: ", RR(approxPrecSa) |
119 | 120 |
# Prepare the arguments for the Taylor expansion computation with Sollya. |
120 | 121 |
functionSo = pobyso_parse_string_sa_so(fff._assume_str()) |
... | ... | |
126 | 127 |
slz_compute_polynomial_and_interval(functionSo, degreeSo, |
127 | 128 |
scaledLowerBoundSa, scaledUpperBoundSa, |
128 | 129 |
approxPrecSa, internalSollyaPrecSa) |
129 |
"""
|
|
130 |
# Change variable stuff
|
|
130 | 131 |
changeVarExpressionSo = sollya_lib_build_function_sub( |
131 | 132 |
sollya_lib_build_function_free_variable(), |
132 | 133 |
sollya_lib_copy_obj(intervalCenterSo)) |
133 | 134 |
polyVarChangedSo = sollya_lib_evaluate(polySo, changeVarExpressionSo) |
134 |
"""
|
|
135 |
resultArray.append((polySo, boundsSo, intervalCenterSo, maxErrorSo))
|
|
135 |
resultArray.append((polySo, polyVarChangedSo, boundsSo, intervalCenterSo,\
|
|
136 |
maxErrorSo))
|
|
136 | 137 |
realIntervalField = RealIntervalField(max(lowerBoundSa.parent().precision(), |
137 | 138 |
upperBoundSa.parent().precision())) |
138 | 139 |
boundsSa = pobyso_range_to_interval_so_sa(boundsSo, realIntervalField) |
... | ... | |
144 | 145 |
currentScaledLowerBoundSa, |
145 | 146 |
scaledUpperBoundSa, approxPrecSa, |
146 | 147 |
internalSollyaPrecSa) |
147 |
resultArray.append((polySo, boundsSo, intervalCenterSo, maxErrorSo)) |
|
148 |
# Change variable stuff |
|
149 |
changeVarExpressionSo = sollya_lib_build_function_sub( |
|
150 |
sollya_lib_build_function_free_variable(), |
|
151 |
sollya_lib_copy_obj(intervalCenterSo)) |
|
152 |
polyVarChangedSo = sollya_lib_evaluate(polySo, changeVarExpressionSo) |
|
153 |
resultArray.append((polySo, polyVarChangedSo, boundsSo, \ |
|
154 |
intervalCenterSo, maxErrorSo)) |
|
148 | 155 |
boundsSa = pobyso_range_to_interval_so_sa(boundsSo, realIntervalField) |
149 | 156 |
sollya_lib_clear_obj(functionSo) |
150 | 157 |
sollya_lib_clear_obj(degreeSo) |
... | ... | |
188 | 195 |
|
189 | 196 |
def slz_polynomial_and_interval_to_sage(polyRangeCenterErrorSo): |
190 | 197 |
polynomialSa = pobyso_get_poly_so_sa(polyRangeCenterErrorSo[0]) |
198 |
polynomialChangedVarSa = pobyso_get_poly_so_sa(polyRangeCenterErrorSo[1]) |
|
191 | 199 |
intervalSa = \ |
192 |
pobyso_get_interval_from_range_so_sa(polyRangeCenterErrorSo[1])
|
|
200 |
pobyso_get_interval_from_range_so_sa(polyRangeCenterErrorSo[2])
|
|
193 | 201 |
centerSa = \ |
194 |
pobyso_get_constant_as_rn_with_rf_so_sa(polyRangeCenterErrorSo[2])
|
|
202 |
pobyso_get_constant_as_rn_with_rf_so_sa(polyRangeCenterErrorSo[3])
|
|
195 | 203 |
errorSa = \ |
196 |
pobyso_get_constant_as_rn_with_rf_so_sa(polyRangeCenterErrorSo[3])
|
|
197 |
return((polynomialSa, intervalSa, centerSa, errorSa)) |
|
204 |
pobyso_get_constant_as_rn_with_rf_so_sa(polyRangeCenterErrorSo[4])
|
|
205 |
return((polynomialSa, polynomialChangedVarSa, intervalSa, centerSa, errorSa))
|
|
198 | 206 |
# End slz_polynomial_and_interval_to_sage |
199 | 207 |
|
200 | 208 |
print "sageSLZ loaded..." |
Formats disponibles : Unified diff