cvp / src / cvp-run-01.sage @ dd576474
Historique | Voir | Annoter | Télécharger (5,39 ko)
1 | 94c8237b | Serge Torres | #! /opt/sage/sage |
---|---|---|---|
2 | 94c8237b | Serge Torres | # @file cvp-run-01.sage |
3 | 94c8237b | Serge Torres | # Compute a polynomial from the CVP of the function vector. |
4 | 94c8237b | Serge Torres | # Return the polynomial, the error and the (one of) point(s) where this error |
5 | 94c8237b | Serge Torres | # is reached. |
6 | 94c8237b | Serge Torres | # |
7 | 94c8237b | Serge Torres | scriptName = os.path.basename(__file__) |
8 | 94c8237b | Serge Torres | var('x') |
9 | 94c8237b | Serge Torres | contFracMaxErr = 10^-7 |
10 | 94c8237b | Serge Torres | # |
11 | 94c8237b | Serge Torres | def initialize_env(): |
12 | 94c8237b | Serge Torres | """ |
13 | 94c8237b | Serge Torres | Load all necessary modules. |
14 | 94c8237b | Serge Torres | """ |
15 | 94c8237b | Serge Torres | compiledSpyxDir = \ |
16 | 94c8237b | Serge Torres | "/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx" |
17 | 94c8237b | Serge Torres | if compiledSpyxDir not in sys.path: |
18 | 94c8237b | Serge Torres | sys.path.append(compiledSpyxDir) |
19 | 94c8237b | Serge Torres | if not 'mpfi' in sage.misc.cython.standard_libs: |
20 | 94c8237b | Serge Torres | sage.misc.cython.standard_libs.append('mpfi') |
21 | 94c8237b | Serge Torres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage") |
22 | 94c8237b | Serge Torres | # load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx") |
23 | 94c8237b | Serge Torres | # load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx") |
24 | 94c8237b | Serge Torres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py") |
25 | 94c8237b | Serge Torres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage") |
26 | 94c8237b | Serge Torres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage") |
27 | 94c8237b | Serge Torres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage") |
28 | 94c8237b | Serge Torres | # Matrix operations are loaded by polynomial operations. |
29 | 94c8237b | Serge Torres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage") |
30 | 94c8237b | Serge Torres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage") |
31 | 94c8237b | Serge Torres | load("/home/storres/recherche/arithmetique/cvp/src/functions_for_cvp.sage") |
32 | 94c8237b | Serge Torres | |
33 | 94c8237b | Serge Torres | # End initialize_env. |
34 | 94c8237b | Serge Torres | # |
35 | 94c8237b | Serge Torres | initialize_env() |
36 | 94c8237b | Serge Torres | from sageMpfr import * |
37 | 94c8237b | Serge Torres | from sageGMP import * |
38 | 94c8237b | Serge Torres | import sys |
39 | 94c8237b | Serge Torres | # |
40 | 94c8237b | Serge Torres | def usage(scriptName): |
41 | 94c8237b | Serge Torres | write = sys.stderr.write |
42 | 94c8237b | Serge Torres | write("Usage:\n") |
43 | 94c8237b | Serge Torres | write(" " + scriptName + " <func> <lowerBound> <upperBound> <coeffsExpList> \n") |
44 | 94c8237b | Serge Torres | write(" " * (len(scriptName) + 3)) |
45 | 94c8237b | Serge Torres | write("<coeffsPrecList> <minCoeffsBoundExpList>\n") |
46 | 94c8237b | Serge Torres | write(" " * (len(scriptName) + 3)) |
47 | 94c8237b | Serge Torres | write("<maxCoeffsBoundExpList> <pointList> <precision>\n") |
48 | 94c8237b | Serge Torres | write("\nArguments:\n") |
49 | 94c8237b | Serge Torres | write(" func\n") |
50 | 94c8237b | Serge Torres | write(" lowerBound\n") |
51 | 94c8237b | Serge Torres | write(" upperBound\n") |
52 | 94c8237b | Serge Torres | write(" coeffsExpList\n") |
53 | 94c8237b | Serge Torres | write(" coeffsExpList\n") |
54 | 94c8237b | Serge Torres | write(" minCoeffsBoundExpList\n") |
55 | 94c8237b | Serge Torres | write(" maxCoeffsBoundExpList\n") |
56 | 94c8237b | Serge Torres | write(" maxCoeffsBoundExpList\n") |
57 | 94c8237b | Serge Torres | write(" maxCoeffsBoundExpList\n\n") |
58 | 94c8237b | Serge Torres | ## |
59 | 94c8237b | Serge Torres | sys.exit(1) |
60 | 94c8237b | Serge Torres | # End usage |
61 | 94c8237b | Serge Torres | # |
62 | 94c8237b | Serge Torres | argsCount = len(sys.argv) |
63 | 94c8237b | Serge Torres | # |
64 | 94c8237b | Serge Torres | ## Arguments recovery |
65 | 94c8237b | Serge Torres | if argsCount < 10: |
66 | 94c8237b | Serge Torres | usage(scriptName) |
67 | 94c8237b | Serge Torres | funcAsString = sys.argv[1] |
68 | 94c8237b | Serge Torres | lowerBoundAsString = sys.argv[2] |
69 | 94c8237b | Serge Torres | upperBoundAsString = sys.argv[3] |
70 | 94c8237b | Serge Torres | coeffsExpListAsString = sys.argv[4] |
71 | 94c8237b | Serge Torres | coeffsPrecListAsString = sys.argv[5] |
72 | 94c8237b | Serge Torres | minCoeffsBoundExpListAsString = sys.argv[6] |
73 | 94c8237b | Serge Torres | maxCoeffsBoundExpListAsString = sys.argv[7] |
74 | 94c8237b | Serge Torres | pointsListAsString = sys.argv[8] |
75 | 94c8237b | Serge Torres | precisionAsString = sys.argv[9] |
76 | 94c8237b | Serge Torres | # |
77 | 94c8237b | Serge Torres | ## Arguments conversion |
78 | 94c8237b | Serge Torres | ### Create first the rational field that will be used throughout the script. |
79 | 94c8237b | Serge Torres | precision = int(precisionAsString) |
80 | 94c8237b | Serge Torres | realField = RealField(precision) |
81 | 94c8237b | Serge Torres | # |
82 | 94c8237b | Serge Torres | func(x) = sage_eval(funcAsString, cmds="var('x')") |
83 | 3296902f | Serge Torres | try: |
84 | 3296902f | Serge Torres | lowerBound = realField(lowerBoundAsString) |
85 | 3296902f | Serge Torres | except: |
86 | 3296902f | Serge Torres | lowerBoundAsRat = QQ(lowerBoundAsString) |
87 | 3296902f | Serge Torres | lowerBound = realField(lowerBoundAsRat) |
88 | 3296902f | Serge Torres | try: |
89 | 3296902f | Serge Torres | upperBound = realField(upperBoundAsString) |
90 | 3296902f | Serge Torres | except: |
91 | 3296902f | Serge Torres | upperBoundAsRat = QQ(upperBoundAsString) |
92 | 3296902f | Serge Torres | upperBound = realField(upperBoundAsRat) |
93 | 94c8237b | Serge Torres | coeffsExpList = sage_eval(coeffsExpListAsString) |
94 | 94c8237b | Serge Torres | coeffsPrecList = sage_eval(coeffsPrecListAsString) |
95 | 94c8237b | Serge Torres | minCoeffsBoundExpList = sage_eval(minCoeffsBoundExpListAsString) |
96 | 94c8237b | Serge Torres | maxCoeffsBoundExpList = sage_eval(maxCoeffsBoundExpListAsString) |
97 | 94c8237b | Serge Torres | pointsList = sage_eval(pointsListAsString) |
98 | 94c8237b | Serge Torres | # |
99 | 94c8237b | Serge Torres | ## Debug printing. |
100 | 94c8237b | Serge Torres | sys.stderr.write("func: " + func._assume_str().replace("_SAGE_VAR_","",100) + \ |
101 | 94c8237b | Serge Torres | "\n") |
102 | 94c8237b | Serge Torres | sys.stderr.write("precision: " + str(precision) + "\n") |
103 | 94c8237b | Serge Torres | sys.stderr.write("lowerBound: " + str(lowerBound) + "\n") |
104 | 94c8237b | Serge Torres | sys.stderr.write("upperBound: " + str(upperBound) + "\n") |
105 | 94c8237b | Serge Torres | sys.stderr.write("coeffsExpList: " + str(coeffsExpList) + "\n") |
106 | 94c8237b | Serge Torres | sys.stderr.write("coeffsPrecList: " + str(coeffsPrecList) + "\n") |
107 | 94c8237b | Serge Torres | sys.stderr.write("minCoeffsBoundExpList: " + str(minCoeffsBoundExpList) + "\n") |
108 | 94c8237b | Serge Torres | sys.stderr.write("maxCoeffsBoundExpList: " + str(maxCoeffsBoundExpList) + "\n") |
109 | 94c8237b | Serge Torres | sys.stderr.write("pointsList: " + str(pointsList) + "\n") |
110 | 94c8237b | Serge Torres | # |
111 | 94c8237b | Serge Torres | poly = cvp_cvp_polynomial(func, |
112 | 94c8237b | Serge Torres | lowerBound, |
113 | 94c8237b | Serge Torres | upperBound, |
114 | 94c8237b | Serge Torres | coeffsExpList, |
115 | 94c8237b | Serge Torres | coeffsPrecList, |
116 | 94c8237b | Serge Torres | minCoeffsBoundExpList, |
117 | 94c8237b | Serge Torres | maxCoeffsBoundExpList, |
118 | 94c8237b | Serge Torres | pointsList, |
119 | 94c8237b | Serge Torres | realField) |
120 | c7bf1784 | Serge Torres | sys.stderr.write(str(poly) + "\n") |
121 | 94c8237b | Serge Torres | (maxisList,maxErr) = cvp_polynomial_error_func_maxis(func, |
122 | 94c8237b | Serge Torres | poly, |
123 | 94c8237b | Serge Torres | lowerBound, |
124 | 94c8237b | Serge Torres | upperBound, |
125 | 94c8237b | Serge Torres | realField, |
126 | 94c8237b | Serge Torres | contFracMaxErr) |
127 | 94c8237b | Serge Torres | (maxErrPoint, maxErrPointErr) = cvp_func_abs_max_for_points(func, |
128 | 94c8237b | Serge Torres | maxisList) |
129 | c7bf1784 | Serge Torres | sys.stdout.write(str(maxErrPoint) + " " + str(maxErr.n(prec=53)) + "\n") |
130 | 3296902f | Serge Torres | sys.exit(int(0)) |