Révision c7bf1784 src/functions_for_cvp.sage
b/src/functions_for_cvp.sage | ||
---|---|---|
193 | 193 |
return (minCoeffsExpList, maxCoeffsExpList) |
194 | 194 |
# End cvp_coefficients_bounds_projection_exps |
195 | 195 |
|
196 |
def cvp_chebyshev_maxis_1k(numPoints, realField, contFracMaxErr = None): |
|
197 |
""" |
|
198 |
Compute the Chebyshev maxis for some polynomial degree (numPoints, for the |
|
199 |
zeros) scaled to the [lowerBound, upperBound] interval. |
|
200 |
The list is returned as row floating-point numbers is contFracMaxErr is None. |
|
201 |
Otherwise elements are transformed into rational numbers. |
|
202 |
""" |
|
203 |
if numPoints < 1: |
|
204 |
return None |
|
205 |
if numPoints == 0: |
|
206 |
return [0] |
|
207 |
## Check that realField has a "prec()" member. |
|
208 |
try: |
|
209 |
realField.prec() |
|
210 |
except: |
|
211 |
return None |
|
212 |
# |
|
213 |
maxisList = [] |
|
214 |
## n extrema are given by a degree (n-1) Chebyshev polynomial. |
|
215 |
# formulas: cos ((i * pi) / (numPoints - 1)) for i = 0,...,numPoints-1. |
|
216 |
# Source: https://en.wikipedia.org/wiki/Chebyshev_polynomials |
|
217 |
for index in xrange(0, numPoints): |
|
218 |
## When number of points is odd (then, the Chebyshev degree is odd two), |
|
219 |
# the central point is 0. */ |
|
220 |
if (numPoints % 2 == 1) and ((2 * index + 1) == numPoints): |
|
221 |
if contFracMaxErr is None: |
|
222 |
maxisList.append(realField(0)) |
|
223 |
else: |
|
224 |
maxisList.append(0) |
|
225 |
else: |
|
226 |
currentCheby = \ |
|
227 |
((realField(index) * realField(pi)) / |
|
228 |
realField(numPoints-1)).cos() |
|
229 |
#print "Current Cheby:", currentCheby |
|
230 |
## Result is negated to have an increasing order list. |
|
231 |
if contFracMaxErr is None: |
|
232 |
maxisList.append(-currentCheby) |
|
233 |
else: |
|
234 |
maxisList.append(-currentCheby.nearby_rational(contFracMaxErr)) |
|
235 |
#print "Relative error:", (currentCheby/maxisList[index]) |
|
236 |
return maxisList |
|
237 |
# End cvp_chebyshev_maxis_1k. |
|
238 |
# |
|
239 |
def cvp_chebyshev_maxis_for_interval(lowerBound, |
|
240 |
upperBound, |
|
241 |
numPoints, |
|
242 |
realField = None, |
|
243 |
contFracMaxErr = None): |
|
244 |
""" |
|
245 |
Compute the Chebyshev maxis for some polynomial degree (numPoints, for the |
|
246 |
maxis) scaled to the [lowerBound, upperBound] interval. |
|
247 |
If no contFracMaxErr argument is given, we return the list as "raw" |
|
248 |
floating-points. Otherwise, rational numbers are returned. |
|
249 |
""" |
|
250 |
## Arguments check. |
|
251 |
if lowerBound >= upperBound: |
|
252 |
return None |
|
253 |
if numPoints < 1: |
|
254 |
return None |
|
255 |
## If no realField argument is given try to retrieve it from the |
|
256 |
# bounds. If impossible (e.g. rational bound), fall back on RR. |
|
257 |
if realField is None: |
|
258 |
try: |
|
259 |
### Force failure if parent does not have prec() member. |
|
260 |
lowerBound.parent().prec() |
|
261 |
### If no exception is thrown, set realField. |
|
262 |
realField = lowerBound.parent() |
|
263 |
except: |
|
264 |
realField = RR |
|
265 |
#print "Real field:", realField |
|
266 |
## We want "raw"floating-point nodes to only have one final rounding. |
|
267 |
chebyshevMaxisList = \ |
|
268 |
cvp_chebyshev_maxis_1k(numPoints, realField) |
|
269 |
scalingFactor, offset = cvp_affine_from_chebyshev(lowerBound, upperBound) |
|
270 |
for index in xrange(0, len(chebyshevMaxisList)): |
|
271 |
chebyshevMaxisList[index] = \ |
|
272 |
chebyshevMaxisList[index] * scalingFactor + offset |
|
273 |
if not contFracMaxErr is None: |
|
274 |
chebyshevMaxisList[index] = \ |
|
275 |
chebyshevMaxisList[index].nearby_rational(contFracMaxErr) |
|
276 |
return chebyshevMaxisList |
|
277 |
# End cvp_chebyshev_maxis_for_interval. |
|
278 |
# |
|
196 | 279 |
def cvp_chebyshev_zeros_1k(numPoints, realField, contFracMaxErr = None): |
197 | 280 |
""" |
198 | 281 |
Compute the Chebyshev zeros for some polynomial degree (numPoints, for the |
Formats disponibles : Unified diff