commit 3296902f0323f593bfe33b7cf3cf216d7e7b07b4
Author: Serge Torres <Serge.Torres@ens-lyon.fr>
Date:   Sun Feb 14 14:30:43 2016 +0100

    Fixed: system exit value, error functions without zeros, failures of function dirtyfindzeros (using findzeros).

diff --git a/src/cvp-run-01.sage b/src/cvp-run-01.sage
index 5ec71e4..cc1fa86 100755
--- a/src/cvp-run-01.sage
+++ b/src/cvp-run-01.sage
@@ -80,8 +80,16 @@ precision               = int(precisionAsString)
 realField               = RealField(precision)
 #
 func(x)                 = sage_eval(funcAsString, cmds="var('x')")
-lowerBound              = realField(lowerBoundAsString)
-upperBound              = realField(upperBoundAsString)
+try:
+    lowerBound          = realField(lowerBoundAsString)
+except:
+    lowerBoundAsRat     = QQ(lowerBoundAsString)
+    lowerBound          = realField(lowerBoundAsRat)
+try:
+    upperBound          = realField(upperBoundAsString)
+except:
+    upperBoundAsRat     = QQ(upperBoundAsString)
+    upperBound          = realField(upperBoundAsRat)
 coeffsExpList           = sage_eval(coeffsExpListAsString)
 coeffsPrecList          = sage_eval(coeffsPrecListAsString)
 minCoeffsBoundExpList   = sage_eval(minCoeffsBoundExpListAsString)
@@ -119,4 +127,4 @@ sys.stderr.write(str(poly) + "\n")
 (maxErrPoint, maxErrPointErr) = cvp_func_abs_max_for_points(func,
                                                             maxisList)
 sys.stdout.write(str(maxErrPoint) + " " + str(maxErr.n(prec=53)) + "\n")
-sys.exit(0)
\ No newline at end of file
+sys.exit(int(0))
\ No newline at end of file
diff --git a/src/cvp-run-02.sage b/src/cvp-run-02.sage
index 2099a4b..6d8976a 100755
--- a/src/cvp-run-02.sage
+++ b/src/cvp-run-02.sage
@@ -71,15 +71,17 @@ argsCount = len(sys.argv)
 ## Arguments recovery
 if argsCount < 10:
     usage(scriptName)
-funcAsString                    = sys.argv[1]
-lowerBoundAsString              = sys.argv[2]
-upperBoundAsString              = sys.argv[3]
-coeffsExpListAsString           = sys.argv[4]
-coeffsPrecListAsString          = sys.argv[5] 
-minCoeffsBoundExpListAsString   = sys.argv[6] 
-maxCoeffsBoundExpListAsString   = sys.argv[7]
-pointsListAsString              = sys.argv[8]
-precisionAsString               = sys.argv[9]
+## Shell weird behavior  may oblige to single quote arguments.
+#  They should be removed before evaluation to avoid inadequate typing. 
+funcAsString                    = re.sub("^'|'$", "", sys.argv[1])
+lowerBoundAsString              = re.sub("^'|'$", "", sys.argv[2])
+upperBoundAsString              = re.sub("^'|'$", "", sys.argv[3])
+coeffsExpListAsString           = re.sub("^'|'$", "", sys.argv[4])
+coeffsPrecListAsString          = re.sub("^'|'$", "", sys.argv[5])
+minCoeffsBoundExpListAsString   = re.sub("^'|'$", "", sys.argv[6])
+maxCoeffsBoundExpListAsString   = re.sub("^'|'$", "", sys.argv[7])
+pointsListAsString              = re.sub("^'|'$", "", sys.argv[8])
+precisionAsString               = re.sub("^'|'$", "", sys.argv[9])
 #
 ## Arguments conversion
 ### Create first the rational field that will be used throughout the script.
@@ -87,8 +89,16 @@ precision               = int(precisionAsString)
 realField               = RealField(precision)
 #
 func(x)                 = sage_eval(funcAsString, cmds="var('x')")
-lowerBound              = realField(lowerBoundAsString)
-upperBound              = realField(upperBoundAsString)
+try:
+    lowerBound          = realField(lowerBoundAsString)
+except:
+    lowerBoundAsRat     = QQ(lowerBoundAsString)
+    lowerBound          = realField(lowerBoundAsRat)
+try:
+    upperBound          = realField(upperBoundAsString)
+except:
+    upperBoundAsRat     = QQ(upperBoundAsString)
+    upperBound          = realField(upperBoundAsRat)
 coeffsExpList           = sage_eval(coeffsExpListAsString)
 coeffsPrecList          = sage_eval(coeffsPrecListAsString)
 minCoeffsBoundExpList   = sage_eval(minCoeffsBoundExpListAsString)
@@ -111,9 +121,9 @@ sys.stderr.write("maxExponent: " + str(maxExponent) + "\n")
 #
 ##
 chebyshevPointsList = []
-minMaxErrPoint  = 0
+minMaxErrPoint  = oo
 minMaxErr       = oo
-for pointsNum in xrange(maxExponent+1, round(maxExponent * 6/2)+1):
+for pointsNum in xrange(maxExponent+1, round(maxExponent * 8/2)+1):
     ## Compute the Chebyshev points and append the user given points list.
     chebyshevPointsList =  \
         cvp_chebyshev_maxis_for_interval(lowerBound, 
@@ -121,6 +131,7 @@ for pointsNum in xrange(maxExponent+1, round(maxExponent * 6/2)+1):
                                          pointsNum,
                                          realField, 
                                          contFracMaxErr)
+    #print "cr-02 - Chebyshe points list computed."
     chebyshevPointsList = chebyshevPointsList + pointsList
     poly = cvp_cvp_polynomial(func, 
                               lowerBound, 
@@ -138,13 +149,22 @@ for pointsNum in xrange(maxExponent+1, round(maxExponent * 6/2)+1):
                                                           upperBound,
                                                           realField,
                                                           contFracMaxErr)
-    (maxErrPoint, maxErrPointErr) = cvp_func_abs_max_for_points(func,
-                                                                maxisList)
-    sys.stderr.write("MaxErr: " + str(maxErr.n(prec=53)))
-    sys.stderr.write(" - MaxErrPoint: " + str(maxErrPoint) + "\n")
-    if maxErr < minMaxErr:
-        minMaxErr      = maxErr
-        minMaxErrPoint = maxErrPoint
+    #print "cr-02 - mcr-02 maxis list:", maxisList
+    #print "cr-02 - maxErr:", maxErr
+    if len(maxisList) != 0:
+        (maxErrPoint, maxErrPointErr) = \
+            cvp_func_abs_max_for_points(func,
+                                        maxisList)
+        sys.stderr.write("# points: " + str(pointsNum))
+        sys.stderr.write(" - MaxErr: " + str(maxErr.n(prec=53)))
+        sys.stderr.write(" - MaxErrPoint: " + str(maxErrPoint) + "\n")
+        if maxErr < minMaxErr:
+            minMaxErr      = maxErr
+            minMaxErrPoint = maxErrPoint
 # End for
 sys.stdout.write(str(minMaxErrPoint) + " " + str(minMaxErr.n(prec=53)) + "\n")
-sys.exit(0)
\ No newline at end of file
+## Use int(0) as argument for sys.exit() in Sage because otherwise
+# sys.exit(0) -> sys.exit(Integer(0)) (where Integer(0) is a Sage
+# object, not the integer value 0 expected by Python) hence Python 
+# returns 1!
+sys.exit(int(0))
diff --git a/src/functions_for_cvp.sage b/src/functions_for_cvp.sage
index 6370721..e90c40b 100644
--- a/src/functions_for_cvp.sage
+++ b/src/functions_for_cvp.sage
@@ -692,10 +692,12 @@ def cvp_polynomial_error_func_maxis(funcSa,
     #print "Real field:", realField
     ## Compute the Sollya version of the function.
     funcAsStringSa = funcSa._assume_str().replace("_SAGE_VAR_","",100)
+    #print "cpefa:", funcAsStringSa
     funcSo  = pobyso_parse_string(funcAsStringSa)
     if pobyso_is_error_so_sa(funcSo):
         pobyso_clear_obj(funcSo)
         return None
+    #print "cpefa: function conversion OK."
     ## Compute the Sollya version of the polynomial.
     ## The conversion is made from a floating-point coefficients polynomial.
     try:
@@ -708,18 +710,23 @@ def cvp_polynomial_error_func_maxis(funcSa,
         pobyso_clear_obj(funcSo)
         pobyso_clear_obj(polySo)
         return None
+    #print "cpefa: polynomial conversion to Sollya OK."
     ## Copy both funcSo and polySo as they are needed later for the infnorm..
-    errorFuncSo = sollya_lib_build_function_sub(sollya_lib_copy_obj(funcSo), 
-                                                sollya_lib_copy_obj(polySo))
+    errorFuncSo = \
+        sollya_lib_build_function_sub(sollya_lib_copy_obj(funcSo), 
+                                      sollya_lib_copy_obj(polySo))
     if pobyso_is_error_so_sa(errorFuncSo):
         pobyso_clear_obj(errorFuncSo)
         return None
+    #print "cpefa: error function in Sollya OK."
     ## Compute the derivative.
     diffErrorFuncSo = pobyso_diff_so_so(errorFuncSo)
     pobyso_clear_obj(errorFuncSo)
     if pobyso_is_error_so_sa(diffErrorFuncSo):
         pobyso_clear_obj(diffErrorFuncSo)
         return None
+        #print "cpefa: polynomial conversion to Sollya OK."
+    #print "cpefa: error function derivative in Sollya OK."
     ## Compute the interval.
     intervalSo = pobyso_range_from_bounds_sa_so(lowerBound, upperBound)
     if pobyso_is_error_so_sa(intervalSo):
@@ -734,15 +741,41 @@ def cvp_polynomial_error_func_maxis(funcSa,
     pobyso_clear_obj(polySo)
     pobyso_clear_obj(funcSo)
     ## Compute the zeros of the derivative.
-    errorFuncMaxisSo = pobyso_dirty_find_zeros_so_so(diffErrorFuncSo, intervalSo)
-    pobyso_clear_obj(diffErrorFuncSo)
-    pobyso_clear_obj(intervalSo)
+    ### Give it a first try with dirtyfindzeros but it may
+    #   fail.
+    errorFuncMaxisSo = pobyso_dirty_find_zeros_so_so(diffErrorFuncSo, 
+                                                     intervalSo)
     if pobyso_is_error_so_sa(errorFuncMaxisSo):
+        pobyso_clear_obj(diffErrorFuncSo)
+        pobyso_clear_obj(intervalSo)
         pobyso_clear_obj(errorFuncMaxisSo)
         return None
+    #print "cpefa: error function maxis in Sollya OK."
     errorFuncMaxisSa = pobyso_float_list_so_sa(errorFuncMaxisSo)
     pobyso_clear_obj(errorFuncMaxisSo)
+    #### If the list is empty try the more sophisticated
+    #    findzeros.
+    if len(errorFuncMaxisSa) == 0:
+        errorFuncMaxisSo = \
+            pobyso_find_zeros_so_so(diffErrorFuncSo, 
+                                    intervalSo)
+        if pobyso_is_error_so_sa(errorFuncMaxisSo):
+            pobyso_clear_obj(diffErrorFuncSo)
+            pobyso_clear_obj(intervalSo)
+            pobyso_clear_obj(errorFuncMaxisSo)
+            return None
+        #print "cpefa: error function maxis in Sollya OK."
+        #print "cpefa:", ; pobyso_autoprint(errorFuncMaxisSo)
+        ##### The findzeros functions returns intervals (ranges).
+        errorFuncRangeMaxisSa = pobyso_range_list_so_sa(errorFuncMaxisSo)
+        pobyso_clear_obj(errorFuncMaxisSo)
+        errorFuncMaxisSa = []
+        for interval in errorFuncRangeMaxisSa:
+            errorFuncMaxisSa.append(interval.center())
+    pobyso_clear_obj(diffErrorFuncSo)
+    pobyso_clear_obj(intervalSo)
     ## If required, convert the numbers to rational numbers.
+    #print "cpefa - errorFuncMaxisSa:", errorFuncMaxisSa
     if not contFracMaxErr is None:
         for index in xrange(0, len(errorFuncMaxisSa)):
             errorFuncMaxisSa[index] = \
