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