Révision 9c97e92f src/functions_for_cvp.sage
b/src/functions_for_cvp.sage | ||
---|---|---|
500 | 500 |
return polynomialCoeffsList |
501 | 501 |
# En polynomial_coeffs_from_vect. |
502 | 502 |
# |
503 |
def cvp_polynomial_error_func_maxis(funcSa, |
|
504 |
polySa, |
|
505 |
lowerBoundSa, |
|
506 |
upperBoundSa, |
|
507 |
realField = None, |
|
508 |
contFracMaxErr = None): |
|
509 |
""" |
|
510 |
For a given function, approximation polynomial and interval (given |
|
511 |
as bounds) compute the maxima of the functSa - polySo on the interval. |
|
512 |
Also computes the infnorm of the error function. |
|
513 |
""" |
|
514 |
## Arguments check. |
|
515 |
# @todo. |
|
516 |
## If no realField argument is given try to retrieve it from the |
|
517 |
# bounds. If impossible (e.g. rational bound), fall back on RR. |
|
518 |
if realField is None: |
|
519 |
try: |
|
520 |
### Force failure if parent does not have prec() member. |
|
521 |
lowerBound.parent().prec() |
|
522 |
### If no exception is thrown, set realField. |
|
523 |
realField = lowerBound.parent() |
|
524 |
except: |
|
525 |
realField = RR |
|
526 |
#print "Real field:", realField |
|
527 |
## Compute the Sollya version of the function. |
|
528 |
funcAsStringSa = funcSa._assume_str().replace("_SAGE_VAR_","",100) |
|
529 |
funcSo = pobyso_parse_string(funcAsStringSa) |
|
530 |
if pobyso_is_error_so_sa(funcSo): |
|
531 |
pobyso_clear_obj(funcSo) |
|
532 |
return None |
|
533 |
## Compute the Sollya version of the polynomial. |
|
534 |
## The conversion is made from a floating-point coefficients polynomial. |
|
535 |
try: |
|
536 |
polySa.base_ring().prec() |
|
537 |
convFloatPolySa = polySa |
|
538 |
except: |
|
539 |
convFloatPolySa = realField[polySa.variables()[0]](polySa) |
|
540 |
polySo = pobyso_float_poly_sa_so(convFloatPolySa) |
|
541 |
if pobyso_is_error_so_sa(funcSo): |
|
542 |
pobyso_clear_obj(funcSo) |
|
543 |
pobyso_clear_obj(polySo) |
|
544 |
return None |
|
545 |
## Copy both funcSo and polySo as they are needed later for the infnorm.. |
|
546 |
errorFuncSo = sollya_lib_build_function_sub(sollya_lib_copy_obj(funcSo), |
|
547 |
sollya_lib_copy_obj(polySo)) |
|
548 |
if pobyso_is_error_so_sa(errorFuncSo): |
|
549 |
pobyso_clear_obj(errorFuncSo) |
|
550 |
return None |
|
551 |
## Compute the derivative. |
|
552 |
diffErrorFuncSo = pobyso_diff_so_so(errorFuncSo) |
|
553 |
pobyso_clear_obj(errorFuncSo) |
|
554 |
if pobyso_is_error_so_sa(diffErrorFuncSo): |
|
555 |
pobyso_clear_obj(diffErrorFuncSo) |
|
556 |
return None |
|
557 |
## Compute the interval. |
|
558 |
intervalSo = pobyso_range_from_bounds_sa_so(lowerBound, upperBound) |
|
559 |
if pobyso_is_error_so_sa(intervalSo): |
|
560 |
pobyso_clear_obj(diffErrorFuncSo) |
|
561 |
pobyso_clear_obj(intervalSo) |
|
562 |
return None |
|
563 |
## Compute the infnorm of the error function. |
|
564 |
errFuncSupNormSa = pobyso_supnorm_so_sa(polySo, |
|
565 |
funcSo, |
|
566 |
intervalSo, |
|
567 |
realFieldSa = realField) |
|
568 |
pobyso_clear_obj(polySo) |
|
569 |
pobyso_clear_obj(funcSo) |
|
570 |
## Compute the zeros of the derivative. |
|
571 |
errorFuncMaxisSo = pobyso_dirty_find_zeros_so_so(diffErrorFuncSo, intervalSo) |
|
572 |
pobyso_clear_obj(diffErrorFuncSo) |
|
573 |
pobyso_clear_obj(intervalSo) |
|
574 |
if pobyso_is_error_so_sa(errorFuncMaxisSo): |
|
575 |
pobyso_clear_obj(errorFuncMaxisSo) |
|
576 |
return None |
|
577 |
errorFuncMaxisSa = pobyso_float_list_so_sa(errorFuncMaxisSo) |
|
578 |
pobyso_clear_obj(errorFuncMaxisSo) |
|
579 |
## If required, convert the numbers to rational numbers. |
|
580 |
if not contFracMaxErr is None: |
|
581 |
for index in xrange(0, len(errorFuncMaxisSa)): |
|
582 |
errorFuncMaxisSa[index] = \ |
|
583 |
errorFuncMaxisSa[index].nearby_rational(contFracMaxErr) |
|
584 |
return (errorFuncMaxisSa, errFuncSupNormSa) |
|
585 |
# End cvp_polynomial_error_func_maxis |
|
586 |
# |
|
503 | 587 |
def cvp_polynomial_from_coeffs_and_exps(coeffsList, |
504 | 588 |
expsList, |
505 | 589 |
polyField = None, |
... | ... | |
574 | 658 |
diffErrorFuncSo = pobyso_diff_so_so(errorFuncSo) |
575 | 659 |
pobyso_clear_obj(errorFuncSo) |
576 | 660 |
## Compute the zeros of the derivative. |
577 |
errorFuncZerosSo = pobyso_dirty_find_zeros_so_so(diffErrorFuncSo, intervalSo)
|
|
661 |
errorFuncMaxisSo = pobyso_dirty_find_zeros_so_so(diffErrorFuncSo, intervalSo)
|
|
578 | 662 |
pobyso_clear_obj(diffErrorFuncSo) |
579 |
errorFuncZerosSa = pobyso_float_list_so_sa(errorFuncZerosSo)
|
|
580 |
pobyso_clear_obj(errorFuncZerosSo)
|
|
663 |
errorFuncMaxisSa = pobyso_float_list_so_sa(errorFuncMaxisSo)
|
|
664 |
pobyso_clear_obj(errorFuncMaxisSo)
|
|
581 | 665 |
## Compute the truncated Remez polynomial and the error function. |
582 | 666 |
truncFormatListSo = pobyso_build_list_of_ints_sa_so(*precsList) |
583 | 667 |
pTruncSo = pobyso_round_coefficients_so_so(pStarSo, truncFormatListSo) |
... | ... | |
589 | 673 |
diffErrorFuncSo = pobyso_diff_so_so(errorFuncSo) |
590 | 674 |
pobyso_clear_obj(errorFuncSo) |
591 | 675 |
## Compute the zeros of the derivative. |
592 |
errorFuncZerosSo = pobyso_dirty_find_zeros_so_so(diffErrorFuncSo, intervalSo)
|
|
676 |
errorFuncMaxisSo = pobyso_dirty_find_zeros_so_so(diffErrorFuncSo, intervalSo)
|
|
593 | 677 |
pobyso_clear_obj(diffErrorFuncSo) |
594 | 678 |
pobyso_clear_obj(intervalSo) |
595 |
errorFuncTruncZerosSa = pobyso_float_list_so_sa(errorFuncZerosSo) |
|
596 |
pobyso_clear_obj(errorFuncZerosSo) |
|
597 |
errorFuncZerosSa += errorFuncTruncZerosSa |
|
598 |
errorFuncZerosSa.sort() |
|
679 |
errorFuncTruncMaxisSa = pobyso_float_list_so_sa(errorFuncMaxisSo) |
|
680 |
pobyso_clear_obj(errorFuncMaxisSo) |
|
681 |
## Merge with the first list, removing duplicates if any. |
|
682 |
errorFuncMaxisSa.extend(elem for elem in errorFuncTruncMaxisSa \ |
|
683 |
if elem not in errorFuncMaxisSa) |
|
684 |
errorFuncMaxisSa.sort() |
|
599 | 685 |
## If required, convert the numbers to rational numbers. |
600 | 686 |
if not contFracMaxErr is None: |
601 |
for index in xrange(0, len(errorFuncZerosSa)):
|
|
602 |
errorFuncZerosSa[index] = \
|
|
603 |
errorFuncZerosSa[index].nearby_rational(contFracMaxErr)
|
|
604 |
return errorFuncZerosSa
|
|
687 |
for index in xrange(0, len(errorFuncMaxisSa)):
|
|
688 |
errorFuncMaxisSa[index] = \
|
|
689 |
errorFuncMaxisSa[index].nearby_rational(contFracMaxErr)
|
|
690 |
return errorFuncMaxisSa
|
|
605 | 691 |
# End cvp_remez_all_poly_error_func_maxis. |
606 | 692 |
# |
607 | 693 |
def cvp_remez_all_poly_error_func_zeros(funct, |
Formats disponibles : Unified diff