Révision e6d557f3

b/src/cvp-run-02.sage
6 6
#
7 7
# @par Notes
8 8
# Change from version 01:
9
#   Instead of computing a single vector, compute several of them et pick
9
#   Take the approximation mode as an argument.
10
#   Instead of computing a single vector, compute several of them and pick
10 11
#   the one that gives the smallest error.
11
#   The points list is only used to complement the chebyshev points lists
12
#   The points list is only used to complement the Chebyshev points lists
12 13
#   that are computed at each iteration.
13 14
#
14 15
scriptName = os.path.basename(__file__)
......
23 24
        "/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx"
24 25
    if compiledSpyxDir not in sys.path:
25 26
        sys.path.append(compiledSpyxDir)
27
    """
28
    As of Sage versions above or equal to 7.0, appending MPFI is not needed and
29
    crashes the program.
26 30
    if not 'mpfi' in sage.misc.cython.standard_libs:
27 31
        sage.misc.cython.standard_libs.append('mpfi')
32
    """
28 33
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage")
29 34
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
30 35
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx")
......
47 52
def usage(scriptName):
48 53
    write = sys.stderr.write
49 54
    write("Usage:\n")
50
    write("  " + scriptName + " <func> <lowerBound> <upperBound> <coeffsExpList> \n")
55
    write("  " + scriptName + " <func> <lowerBound> <upperBound> <mode> <coeffsExpList> \n")
51 56
    write(" " * (len(scriptName) + 3))
52 57
    write("<coeffsPrecList> <minCoeffsBoundExpList>\n")
53 58
    write(" " * (len(scriptName) + 3))
......
56 61
    write("  func\n")
57 62
    write("  lowerBound\n")
58 63
    write("  upperBound\n")
64
    write("  mode             one of \"abs\" or \"rel\"\n")
59 65
    write("  coeffsExpList\n")
60 66
    write("  coeffsExpList\n")
61 67
    write("  minCoeffsBoundExpList\n")
......
69 75
argsCount = len(sys.argv)
70 76
#
71 77
## Arguments recovery
72
if argsCount < 10:
78
if argsCount < 11:
73 79
    usage(scriptName)
74 80
## Shell weird behavior  may oblige to single quote arguments.
75 81
#  They should be removed before evaluation to avoid inadequate typing. 
76 82
funcAsString                    = re.sub("^'|'$", "", sys.argv[1])
77 83
lowerBoundAsString              = re.sub("^'|'$", "", sys.argv[2])
78 84
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])
85
modeAsString                    = re.sub("^'|'$", "", sys.argv[4])
86
coeffsExpListAsString           = re.sub("^'|'$", "", sys.argv[5])
87
coeffsPrecListAsString          = re.sub("^'|'$", "", sys.argv[6])
88
minCoeffsBoundExpListAsString   = re.sub("^'|'$", "", sys.argv[7])
89
maxCoeffsBoundExpListAsString   = re.sub("^'|'$", "", sys.argv[8])
90
pointsListAsString              = re.sub("^'|'$", "", sys.argv[9])
91
precisionAsString               = re.sub("^'|'$", "", sys.argv[10])
85 92
#
86 93
## Arguments conversion
87 94
### Create first the rational field that will be used throughout the script.
......
99 106
except:
100 107
    upperBoundAsRat     = QQ(upperBoundAsString)
101 108
    upperBound          = realField(upperBoundAsRat)
109
approxMode              = modeAsString.lower()
102 110
coeffsExpList           = sage_eval(coeffsExpListAsString)
103 111
coeffsPrecList          = sage_eval(coeffsPrecListAsString)
104 112
minCoeffsBoundExpList   = sage_eval(minCoeffsBoundExpListAsString)
105 113
maxCoeffsBoundExpList   = sage_eval(maxCoeffsBoundExpListAsString)
106 114
pointsList              = sage_eval(pointsListAsString)
107 115
#
116
if approxMode != "abs" and approxMode != "rel":
117
    sys.stderr.write("\n" +  scriptName + ": " + "\"" + approxMode + "\"")
118
    sys.stderr.write("is an invalide mode.\n")
119
    sys.stderr.write("Mode must be either \"abs\" or \"rel\". Aborting!\n")
120
    sys.exit(int(1))
121
    
108 122
maxExponent             = max(coeffsExpList)
109 123
## Debug printing.
110 124
sys.stderr.write("func: " + func._assume_str().replace("_SAGE_VAR_","",100) + \
......
112 126
sys.stderr.write("precision: " + str(precision) + "\n")
113 127
sys.stderr.write("lowerBound: " + str(lowerBound) + "\n")
114 128
sys.stderr.write("upperBound: " + str(upperBound) + "\n")
129
sys.stderr.write("mode      :" + approxMode + "\n")
115 130
sys.stderr.write("coeffsExpList: " + str(coeffsExpList) + "\n")
116 131
sys.stderr.write("coeffsPrecList: " + str(coeffsPrecList) + "\n")
117 132
sys.stderr.write("minCoeffsBoundExpList: " + str(minCoeffsBoundExpList) + "\n")
......
159 174
    #print "cr-02 - maxErr:", maxErr
160 175
    #polyRing = PolynomialRing(realField, func.variables()[0])
161 176
    #errFunc(x) = func(x) - polyRing(poly)
162
    errFunc(x) = func(x) - poly(x)
177
    if approxMode == "abs":
178
        errFunc(x) = func(x) - poly(x)
179
    else:
180
        errFunc(x) = 1 - poly(x) / func(x)
163 181
    if len(maxisList) != 0:
164 182
        (maxErrPoint, maxErrPointErr) = \
165 183
            cvp_func_abs_max_for_points(errFunc,

Formats disponibles : Unified diff