Statistiques
| Branche: | Révision :

cvp / src / cvp-run-01.sage @ c7bf1784

Historique | Voir | Annoter | Télécharger (5,16 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
lowerBound              = realField(lowerBoundAsString)
84
upperBound              = realField(upperBoundAsString)
85
coeffsExpList           = sage_eval(coeffsExpListAsString)
86
coeffsPrecList          = sage_eval(coeffsPrecListAsString)
87
minCoeffsBoundExpList   = sage_eval(minCoeffsBoundExpListAsString)
88
maxCoeffsBoundExpList   = sage_eval(maxCoeffsBoundExpListAsString)
89
pointsList              = sage_eval(pointsListAsString)
90
#
91
## Debug printing.
92
sys.stderr.write("func: " + func._assume_str().replace("_SAGE_VAR_","",100) + \
93
                 "\n")
94
sys.stderr.write("precision: " + str(precision) + "\n")
95
sys.stderr.write("lowerBound: " + str(lowerBound) + "\n")
96
sys.stderr.write("upperBound: " + str(upperBound) + "\n")
97
sys.stderr.write("coeffsExpList: " + str(coeffsExpList) + "\n")
98
sys.stderr.write("coeffsPrecList: " + str(coeffsPrecList) + "\n")
99
sys.stderr.write("minCoeffsBoundExpList: " + str(minCoeffsBoundExpList) + "\n")
100
sys.stderr.write("maxCoeffsBoundExpList: " + str(maxCoeffsBoundExpList) + "\n")
101
sys.stderr.write("pointsList: " + str(pointsList) + "\n")
102
#
103
poly = cvp_cvp_polynomial(func, 
104
                          lowerBound, 
105
                          upperBound,
106
                          coeffsExpList,
107
                          coeffsPrecList, 
108
                          minCoeffsBoundExpList, 
109
                          maxCoeffsBoundExpList,
110
                          pointsList,
111
                          realField)
112
sys.stderr.write(str(poly) + "\n")
113
(maxisList,maxErr)  = cvp_polynomial_error_func_maxis(func,
114
                                                      poly, 
115
                                                      lowerBound, 
116
                                                      upperBound,
117
                                                      realField,
118
                                                      contFracMaxErr)
119
(maxErrPoint, maxErrPointErr) = cvp_func_abs_max_for_points(func,
120
                                                            maxisList)
121
sys.stdout.write(str(maxErrPoint) + " " + str(maxErr.n(prec=53)) + "\n")
122
sys.exit(0)