Révision 3296902f

b/src/cvp-run-01.sage
80 80
realField               = RealField(precision)
81 81
#
82 82
func(x)                 = sage_eval(funcAsString, cmds="var('x')")
83
lowerBound              = realField(lowerBoundAsString)
84
upperBound              = realField(upperBoundAsString)
83
try:
84
    lowerBound          = realField(lowerBoundAsString)
85
except:
86
    lowerBoundAsRat     = QQ(lowerBoundAsString)
87
    lowerBound          = realField(lowerBoundAsRat)
88
try:
89
    upperBound          = realField(upperBoundAsString)
90
except:
91
    upperBoundAsRat     = QQ(upperBoundAsString)
92
    upperBound          = realField(upperBoundAsRat)
85 93
coeffsExpList           = sage_eval(coeffsExpListAsString)
86 94
coeffsPrecList          = sage_eval(coeffsPrecListAsString)
87 95
minCoeffsBoundExpList   = sage_eval(minCoeffsBoundExpListAsString)
......
119 127
(maxErrPoint, maxErrPointErr) = cvp_func_abs_max_for_points(func,
120 128
                                                            maxisList)
121 129
sys.stdout.write(str(maxErrPoint) + " " + str(maxErr.n(prec=53)) + "\n")
122
sys.exit(0)
130
sys.exit(int(0))
b/src/cvp-run-02.sage
71 71
## Arguments recovery
72 72
if argsCount < 10:
73 73
    usage(scriptName)
74
funcAsString                    = sys.argv[1]
75
lowerBoundAsString              = sys.argv[2]
76
upperBoundAsString              = sys.argv[3]
77
coeffsExpListAsString           = sys.argv[4]
78
coeffsPrecListAsString          = sys.argv[5] 
79
minCoeffsBoundExpListAsString   = sys.argv[6] 
80
maxCoeffsBoundExpListAsString   = sys.argv[7]
81
pointsListAsString              = sys.argv[8]
82
precisionAsString               = sys.argv[9]
74
## Shell weird behavior  may oblige to single quote arguments.
75
#  They should be removed before evaluation to avoid inadequate typing. 
76
funcAsString                    = re.sub("^'|'$", "", sys.argv[1])
77
lowerBoundAsString              = re.sub("^'|'$", "", sys.argv[2])
78
upperBoundAsString              = re.sub("^'|'$", "", sys.argv[3])
79
coeffsExpListAsString           = re.sub("^'|'$", "", sys.argv[4])
80
coeffsPrecListAsString          = re.sub("^'|'$", "", sys.argv[5])
81
minCoeffsBoundExpListAsString   = re.sub("^'|'$", "", sys.argv[6])
82
maxCoeffsBoundExpListAsString   = re.sub("^'|'$", "", sys.argv[7])
83
pointsListAsString              = re.sub("^'|'$", "", sys.argv[8])
84
precisionAsString               = re.sub("^'|'$", "", sys.argv[9])
83 85
#
84 86
## Arguments conversion
85 87
### Create first the rational field that will be used throughout the script.
......
87 89
realField               = RealField(precision)
88 90
#
89 91
func(x)                 = sage_eval(funcAsString, cmds="var('x')")
90
lowerBound              = realField(lowerBoundAsString)
91
upperBound              = realField(upperBoundAsString)
92
try:
93
    lowerBound          = realField(lowerBoundAsString)
94
except:
95
    lowerBoundAsRat     = QQ(lowerBoundAsString)
96
    lowerBound          = realField(lowerBoundAsRat)
97
try:
98
    upperBound          = realField(upperBoundAsString)
99
except:
100
    upperBoundAsRat     = QQ(upperBoundAsString)
101
    upperBound          = realField(upperBoundAsRat)
92 102
coeffsExpList           = sage_eval(coeffsExpListAsString)
93 103
coeffsPrecList          = sage_eval(coeffsPrecListAsString)
94 104
minCoeffsBoundExpList   = sage_eval(minCoeffsBoundExpListAsString)
......
111 121
#
112 122
##
113 123
chebyshevPointsList = []
114
minMaxErrPoint  = 0
124
minMaxErrPoint  = oo
115 125
minMaxErr       = oo
116
for pointsNum in xrange(maxExponent+1, round(maxExponent * 6/2)+1):
126
for pointsNum in xrange(maxExponent+1, round(maxExponent * 8/2)+1):
117 127
    ## Compute the Chebyshev points and append the user given points list.
118 128
    chebyshevPointsList =  \
119 129
        cvp_chebyshev_maxis_for_interval(lowerBound, 
......
121 131
                                         pointsNum,
122 132
                                         realField, 
123 133
                                         contFracMaxErr)
134
    #print "cr-02 - Chebyshe points list computed."
124 135
    chebyshevPointsList = chebyshevPointsList + pointsList
125 136
    poly = cvp_cvp_polynomial(func, 
126 137
                              lowerBound, 
......
138 149
                                                          upperBound,
139 150
                                                          realField,
140 151
                                                          contFracMaxErr)
141
    (maxErrPoint, maxErrPointErr) = cvp_func_abs_max_for_points(func,
142
                                                                maxisList)
143
    sys.stderr.write("MaxErr: " + str(maxErr.n(prec=53)))
144
    sys.stderr.write(" - MaxErrPoint: " + str(maxErrPoint) + "\n")
145
    if maxErr < minMaxErr:
146
        minMaxErr      = maxErr
147
        minMaxErrPoint = maxErrPoint
152
    #print "cr-02 - mcr-02 maxis list:", maxisList
153
    #print "cr-02 - maxErr:", maxErr
154
    if len(maxisList) != 0:
155
        (maxErrPoint, maxErrPointErr) = \
156
            cvp_func_abs_max_for_points(func,
157
                                        maxisList)
158
        sys.stderr.write("# points: " + str(pointsNum))
159
        sys.stderr.write(" - MaxErr: " + str(maxErr.n(prec=53)))
160
        sys.stderr.write(" - MaxErrPoint: " + str(maxErrPoint) + "\n")
161
        if maxErr < minMaxErr:
162
            minMaxErr      = maxErr
163
            minMaxErrPoint = maxErrPoint
148 164
# End for
149 165
sys.stdout.write(str(minMaxErrPoint) + " " + str(minMaxErr.n(prec=53)) + "\n")
150
sys.exit(0)
166
## Use int(0) as argument for sys.exit() in Sage because otherwise
167
# sys.exit(0) -> sys.exit(Integer(0)) (where Integer(0) is a Sage
168
# object, not the integer value 0 expected by Python) hence Python 
169
# returns 1!
170
sys.exit(int(0))
b/src/functions_for_cvp.sage
692 692
    #print "Real field:", realField
693 693
    ## Compute the Sollya version of the function.
694 694
    funcAsStringSa = funcSa._assume_str().replace("_SAGE_VAR_","",100)
695
    #print "cpefa:", funcAsStringSa
695 696
    funcSo  = pobyso_parse_string(funcAsStringSa)
696 697
    if pobyso_is_error_so_sa(funcSo):
697 698
        pobyso_clear_obj(funcSo)
698 699
        return None
700
    #print "cpefa: function conversion OK."
699 701
    ## Compute the Sollya version of the polynomial.
700 702
    ## The conversion is made from a floating-point coefficients polynomial.
701 703
    try:
......
708 710
        pobyso_clear_obj(funcSo)
709 711
        pobyso_clear_obj(polySo)
710 712
        return None
713
    #print "cpefa: polynomial conversion to Sollya OK."
711 714
    ## Copy both funcSo and polySo as they are needed later for the infnorm..
712
    errorFuncSo = sollya_lib_build_function_sub(sollya_lib_copy_obj(funcSo), 
713
                                                sollya_lib_copy_obj(polySo))
715
    errorFuncSo = \
716
        sollya_lib_build_function_sub(sollya_lib_copy_obj(funcSo), 
717
                                      sollya_lib_copy_obj(polySo))
714 718
    if pobyso_is_error_so_sa(errorFuncSo):
715 719
        pobyso_clear_obj(errorFuncSo)
716 720
        return None
721
    #print "cpefa: error function in Sollya OK."
717 722
    ## Compute the derivative.
718 723
    diffErrorFuncSo = pobyso_diff_so_so(errorFuncSo)
719 724
    pobyso_clear_obj(errorFuncSo)
720 725
    if pobyso_is_error_so_sa(diffErrorFuncSo):
721 726
        pobyso_clear_obj(diffErrorFuncSo)
722 727
        return None
728
        #print "cpefa: polynomial conversion to Sollya OK."
729
    #print "cpefa: error function derivative in Sollya OK."
723 730
    ## Compute the interval.
724 731
    intervalSo = pobyso_range_from_bounds_sa_so(lowerBound, upperBound)
725 732
    if pobyso_is_error_so_sa(intervalSo):
......
734 741
    pobyso_clear_obj(polySo)
735 742
    pobyso_clear_obj(funcSo)
736 743
    ## Compute the zeros of the derivative.
737
    errorFuncMaxisSo = pobyso_dirty_find_zeros_so_so(diffErrorFuncSo, intervalSo)
738
    pobyso_clear_obj(diffErrorFuncSo)
739
    pobyso_clear_obj(intervalSo)
744
    ### Give it a first try with dirtyfindzeros but it may
745
    #   fail.
746
    errorFuncMaxisSo = pobyso_dirty_find_zeros_so_so(diffErrorFuncSo, 
747
                                                     intervalSo)
740 748
    if pobyso_is_error_so_sa(errorFuncMaxisSo):
749
        pobyso_clear_obj(diffErrorFuncSo)
750
        pobyso_clear_obj(intervalSo)
741 751
        pobyso_clear_obj(errorFuncMaxisSo)
742 752
        return None
753
    #print "cpefa: error function maxis in Sollya OK."
743 754
    errorFuncMaxisSa = pobyso_float_list_so_sa(errorFuncMaxisSo)
744 755
    pobyso_clear_obj(errorFuncMaxisSo)
756
    #### If the list is empty try the more sophisticated
757
    #    findzeros.
758
    if len(errorFuncMaxisSa) == 0:
759
        errorFuncMaxisSo = \
760
            pobyso_find_zeros_so_so(diffErrorFuncSo, 
761
                                    intervalSo)
762
        if pobyso_is_error_so_sa(errorFuncMaxisSo):
763
            pobyso_clear_obj(diffErrorFuncSo)
764
            pobyso_clear_obj(intervalSo)
765
            pobyso_clear_obj(errorFuncMaxisSo)
766
            return None
767
        #print "cpefa: error function maxis in Sollya OK."
768
        #print "cpefa:", ; pobyso_autoprint(errorFuncMaxisSo)
769
        ##### The findzeros functions returns intervals (ranges).
770
        errorFuncRangeMaxisSa = pobyso_range_list_so_sa(errorFuncMaxisSo)
771
        pobyso_clear_obj(errorFuncMaxisSo)
772
        errorFuncMaxisSa = []
773
        for interval in errorFuncRangeMaxisSa:
774
            errorFuncMaxisSa.append(interval.center())
775
    pobyso_clear_obj(diffErrorFuncSo)
776
    pobyso_clear_obj(intervalSo)
745 777
    ## If required, convert the numbers to rational numbers.
778
    #print "cpefa - errorFuncMaxisSa:", errorFuncMaxisSa
746 779
    if not contFracMaxErr is None:
747 780
        for index in xrange(0, len(errorFuncMaxisSa)):
748 781
            errorFuncMaxisSa[index] = \

Formats disponibles : Unified diff