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