Révision 3296902f src/cvp-run-02.sage

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))

Formats disponibles : Unified diff