Révision 9b0c03e7 src/functions_for_cvp.sage
b/src/functions_for_cvp.sage | ||
---|---|---|
90 | 90 |
bounds = sage_eval(otp) |
91 | 91 |
minCoeffsExpList = [] |
92 | 92 |
maxCoeffsExpList = [] |
93 |
print "bounds:", bounds |
|
93 |
#print "bounds:", bounds
|
|
94 | 94 |
for boundsPair in bounds: |
95 | 95 |
minCoeffsExpList.append(boundsPair[0]) |
96 | 96 |
maxCoeffsExpList.append(boundsPair[1]) |
... | ... | |
117 | 117 |
cvp_coefficients_bounds_projection(executablePath,arguments) |
118 | 118 |
for index in xrange(0, len(minCoeffsExpList)): |
119 | 119 |
minCoeffsExpList[index] = \ |
120 |
realField(minCoeffsExpList[index]).log2().floor() |
|
120 |
realField(minCoeffsExpList[index]).abs().log2().floor()
|
|
121 | 121 |
maxCoeffsExpList[index] = \ |
122 |
realField(maxCoeffsExpList[index]).log2().floor() |
|
122 |
realField(maxCoeffsExpList[index]).abs().log2().floor()
|
|
123 | 123 |
return (minCoeffsExpList, maxCoeffsExpList) |
124 | 124 |
# End cvp_coefficients_bounds_projection_exps |
125 | 125 |
|
... | ... | |
358 | 358 |
for rIndex in xrange(0, floatBasis.nrows()): |
359 | 359 |
for cIndex in xrange(0, floatBasis.ncols()): |
360 | 360 |
intBasis[rIndex, cIndex] = \ |
361 |
floatBasis[rIndex, cIndex] * \ |
|
362 |
2^(commonScalingExp + extraScalingExpsList[rIndex]) |
|
361 |
(floatBasis[rIndex, cIndex] * \
|
|
362 |
2^(commonScalingExp + extraScalingExpsList[rIndex])).round()
|
|
363 | 363 |
return intBasis |
364 | 364 |
# End cvp_int_basis. |
365 | 365 |
# |
366 | 366 |
def cvp_int_vector_for_approx(floatVect, commonScalingExp, extraScalingExp): |
367 |
""" |
|
368 |
Compute the integral version of the function vector. |
|
369 |
""" |
|
367 | 370 |
totalScalingFactor = 2^(commonScalingExp + extraScalingExp) |
368 | 371 |
intVect = vector(ZZ, len(floatVect)) |
369 | 372 |
for index in xrange(0, len(floatVect)): |
... | ... | |
416 | 419 |
return polynomialCoeffsList |
417 | 420 |
# En polynomial_coeffs_from_vect. |
418 | 421 |
# |
422 |
def cvp_polynomial_from_coeffs_and_exps(coeffsList, |
|
423 |
expsList, |
|
424 |
polyField = None, |
|
425 |
theVar = None): |
|
426 |
""" |
|
427 |
Build a polynomial in the classical monomials (possibly lacunary) basis |
|
428 |
from a list of coefficients and a list of exponents. The polynomial is in |
|
429 |
the polynomial field given as argument. |
|
430 |
""" |
|
431 |
if len(coeffsList) != len(expsList): |
|
432 |
return None |
|
433 |
## If no variable is given, "x" is used. |
|
434 |
## If no polyField is given, we fall back on a polynomial field on RR. |
|
435 |
if theVar is None: |
|
436 |
if polyField is None: |
|
437 |
theVar = x |
|
438 |
polyField = RR[theVar] |
|
439 |
else: |
|
440 |
theVar = var(polyField.variable_name()) |
|
441 |
else: # theVar is set. |
|
442 |
if polyField is None: |
|
443 |
polyField = RR[theVar] |
|
444 |
else: # Both the polyFiled and theVar are set: create a new polyField |
|
445 |
# with theVar. The original polyField is not affected by the change. |
|
446 |
polyField = polyField.change_var(theVar) |
|
447 |
## Seed the polynomial. |
|
448 |
poly = polyField(0) |
|
449 |
## Append the terms. |
|
450 |
for coeff, exp in zip(coeffsList, expsList): |
|
451 |
poly += polyField(coeff * theVar^exp) |
|
452 |
return poly |
|
453 |
# End cvp_polynomial_from_coeffs_and_exps. |
|
454 |
# |
|
455 |
def cvp_remez_all_poly_error_func_maxi(funct, |
|
456 |
maxDegree, |
|
457 |
lowerBound, |
|
458 |
upperBound, |
|
459 |
precsList, |
|
460 |
realField = None, |
|
461 |
contFracMaxErr = None): |
|
462 |
pass |
|
463 |
""" |
|
464 |
For a given function f, a degree and an interval, compute the |
|
465 |
maxima of the (f-remez_d(f)) function and those of the (f-truncRemez_d(f)) |
|
466 |
function over the interval. |
|
467 |
""" |
|
468 |
# End cvp_remez_all_poly_error_func_maxi. |
|
469 |
# |
|
419 | 470 |
def cvp_remez_all_poly_error_func_zeros(funct, |
420 | 471 |
maxDegree, |
421 | 472 |
lowerBound, |
... | ... | |
428 | 479 |
zeros of the (f-remez_d(f)) function and those of the (f-truncRemez_d(f)) |
429 | 480 |
function over the interval. If the (f-truncRemez_d(f)) function has very |
430 | 481 |
few zeros, compute the zeros of the derivative instead. |
482 |
TODO: change the final behaviour! Now! |
|
431 | 483 |
""" |
432 | 484 |
## If no realField argument is given try to retrieve it from the |
433 | 485 |
# bounds. If impossible (e.g. rational bound), fall back on RR. |
... | ... | |
467 | 519 |
## Deal with the truncated polynomial now. |
468 | 520 |
### Create the formats list. Notice the "*" before the list variable name. |
469 | 521 |
truncFormatListSo = pobyso_build_list_of_ints_sa_so(*precsList) |
470 |
print "Precisions list as Sollya object:", |
|
522 |
#print "Precisions list as Sollya object:",
|
|
471 | 523 |
pobyso_autoprint(truncFormatListSo) |
472 | 524 |
pTruncSo = pobyso_round_coefficients_so_so(pStarSo, truncFormatListSo) |
473 |
print "Truncated polynomial:", ; pobyso_autoprint(pTruncSo) |
|
525 |
#print "Truncated polynomial:", ; pobyso_autoprint(pTruncSo)
|
|
474 | 526 |
### Compute the error function. This time we consume both the function |
475 | 527 |
# and the polynomial. |
476 | 528 |
errorFuncSo = sollya_lib_build_function_sub(pTruncSo, |
477 | 529 |
funcSo) |
478 | 530 |
errorFuncZerosSo = pobyso_dirty_find_zeros_so_so(errorFuncSo, intervalSo) |
479 | 531 |
pobyso_clear_obj(pStarSo) |
480 |
print "Zeroes of the error function for the truncated polynomial from Sollya:" |
|
532 |
#print "Zeroes of the error function for the truncated polynomial from Sollya:"
|
|
481 | 533 |
pobyso_autoprint(errorFuncZerosSo) |
482 | 534 |
errorFuncTruncZerosSa = pobyso_float_list_so_sa(errorFuncZerosSo) |
483 | 535 |
pobyso_clear_obj(errorFuncZerosSo) |
... | ... | |
485 | 537 |
# In this case, we are interested in the variations and we consider the |
486 | 538 |
# derivative |
487 | 539 |
if maxDegree > 3: |
488 |
if len(errorFuncTruncZerosSa) <= 2:
|
|
540 |
if len(errorFuncTruncZerosSa) <= (maxDegree / 2):
|
|
489 | 541 |
errorFuncDiffSo = pobyso_diff_so_so(errorFuncSo) |
490 | 542 |
errorFuncZerosSo = pobyso_dirty_find_zeros_so_so(errorFuncDiffSo, |
491 | 543 |
intervalSo) |
Formats disponibles : Unified diff