Statistiques
| Révision :

root / pobysoPythonSage / src / sageSLZ / runSLZ-53.sage @ 266

Historique | Voir | Annoter | Télécharger (4,94 ko)

1
#! /opt/sage/sage
2
# @file runSLZ-113.sage
3
#
4
# Run SLZ for p=113
5
#from scipy.constants.codata import precision
6
def initialize_env():
7
    """
8
    Load all necessary modules.
9
    """
10
    compiledSpyxDir = "/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx"
11
    if compiledSpyxDir not in sys.path:
12
        sys.path.append(compiledSpyxDir)
13
    if not 'mpfi' in sage.misc.cython.standard_libs:
14
        sage.misc.cython.standard_libs.append('mpfi')
15
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage")
16
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
17
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx")
18
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py")
19
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage")
20
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage")
21
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage")
22
    # Matrix operations are loaded by polynomial operations.
23
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage")
24
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage")
25

    
26

    
27
print "Running SLZ..."
28
initialize_env()
29
from sageMpfr import *
30
from sageGMP  import *
31
import sys
32
from subprocess import call
33
#
34
## Main variables and parameters.
35
x         = var('x')
36
func(x)   = exp(x)
37
precision = 53
38
emin      = -1022
39
emax      = 1023 
40
RRR = RealField(precision)
41
degree              = 0
42
alpha               = 0
43
htrn                = 0
44
intervalCenter      = 0
45
intervalRadius      = 0
46
debugMode           = False          
47
## Local functions
48
#
49
def usage():
50
    write = sys.stderr.write
51
    write("\nUsage:\n")
52
    write("  " + scriptName + " <degree> <alpha> <htrn> <intervalCenter>\n")
53
    write("               <numberOfNumbers> [debug]\n")
54
    write("\nArguments:\n")
55
    write("  degree          the degree of the polynomial (integer)\n")
56
    write("  alpha           alpha (integer)\n")
57
    write("  htrn            hardness-to-round - a number of bits (integer)\n")
58
    write("  intervalCenter  the interval center (a floating-point number)\n")
59
    write("  numberOfNumbers the number of floating-point numbers in the interval\n")
60
    write("                  as a positive integral expression\n")
61
    write("  debug           debug mode (\"debug\", in any case)\n\n")
62
    sys.exit(2)
63
# End usage.
64
#
65
argsCount = len(sys.argv)
66
scriptName = os.path.basename(__file__)
67
if argsCount < 5:
68
    usage()
69
for index in xrange(1,argsCount):
70
    if index == 1:
71
        degree = int(sys.argv[index])
72
    elif index == 2:
73
        alpha = int(sys.argv[index])
74
    elif index == 3:
75
        htrn = int(eval(sys.argv[index]))
76
    elif index == 4:
77
        try:
78
            intervalCenter = QQ(sage_eval(sys.argv[index]))
79
        except:
80
            intervalCenter = RRR(sys.argv[index])
81
        intervalCenter = RRR(intervalCenter)
82
    elif index == 5:
83
        ## Can be read as rational number but must end up as an integer.
84
        numberOfNumbers = QQ(sage_eval(sys.argv[index]))
85
        if numberOfNumbers != numberOfNumbers.round():
86
            raise Exception("Invalid number of numbers: " + sys.argv[index] + ".")
87
        numberOfNumbers = numberOfNumbers.round()
88
        ## The number must be strictly positive.
89
        if numberOfNumbers <= 0:
90
            raise Exception("Invalid number of numbers: " + sys.argv[index] + ".")
91
    elif index == 6:
92
        debugMode = sys.argv[index].upper()
93
        debugMode = (debugMode == "DEBUG")
94
# Done with command line arguments collection.
95
#
96
## Debug printing
97
print "degree         :", degree
98
print "alpha          :", alpha
99
print "htrn           :", htrn
100
print "interval center:", intervalCenter.n(prec=10).str(truncate=False)
101
print "num of nums    :", RR(numberOfNumbers).log2().n(prec=10).str(truncate=False)
102
print "debug mode     :", debugMode
103
print
104
#
105
## Set the terminal window title.
106
terminalWindowTitle = ['stt', str(degree), str(alpha), str(htrn), 
107
                       intervalCenter.n(prec=10).str(truncate=False), 
108
                       RRR(numberOfNumbers).log2().n(prec=10).str(truncate=False)]
109
call(terminalWindowTitle)
110
#
111
intervalCenterBinade = slz_compute_binade(intervalCenter)
112
intervalRadius       = \
113
    2^intervalCenterBinade * 2^(-precision + 1) * numberOfNumbers / 2
114
srs_run_SLZ_v05(inputFunction=func, 
115
                inputLowerBound         = intervalCenter - intervalRadius, 
116
                inputUpperBound         = intervalCenter + intervalRadius, 
117
                alpha                   = alpha, 
118
                degree                  = degree, 
119
                precision               = precision, 
120
                emin                    = emin, 
121
                emax                    = emax, 
122
                targetHardnessToRound   = htrn, 
123
                debug                   = debugMode)
124