Statistiques
| Révision :

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

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

1 230 storres
#! /opt/sage/sage
2 230 storres
# @file runSLZ-113.sage
3 230 storres
#
4 230 storres
# Run SLZ for p=113
5 230 storres
#from scipy.constants.codata import precision
6 230 storres
def initialize_env():
7 230 storres
    """
8 230 storres
    Load all necessary modules.
9 230 storres
    """
10 230 storres
    compiledSpyxDir = "/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx"
11 230 storres
    if compiledSpyxDir not in sys.path:
12 230 storres
        sys.path.append(compiledSpyxDir)
13 230 storres
    if not 'mpfi' in sage.misc.cython.standard_libs:
14 230 storres
        sage.misc.cython.standard_libs.append('mpfi')
15 230 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage")
16 230 storres
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx")
17 230 storres
#    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx")
18 230 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py")
19 230 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage")
20 230 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage")
21 230 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage")
22 230 storres
    # Matrix operations are loaded by polynomial operations.
23 230 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage")
24 230 storres
    load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage")
25 230 storres
26 230 storres
27 230 storres
print "Running SLZ..."
28 230 storres
initialize_env()
29 230 storres
from sageMpfr import *
30 230 storres
from sageGMP  import *
31 230 storres
import sys
32 230 storres
from subprocess import call
33 230 storres
#
34 230 storres
## Main variables and parameters.
35 230 storres
x         = var('x')
36 230 storres
func(x)   = exp(x)
37 230 storres
precision = 113
38 230 storres
emin      = -16382
39 230 storres
emax      = 16383
40 230 storres
RRR = RealField(precision)
41 230 storres
degree              = 0
42 230 storres
alpha               = 0
43 230 storres
htrn                = 0
44 230 storres
intervalCenter      = 0
45 230 storres
intervalRadius      = 0
46 230 storres
debugMode           = False
47 230 storres
## Local functions
48 230 storres
#
49 230 storres
def usage():
50 230 storres
    write = sys.stderr.write
51 230 storres
    write("\nUsage:\n")
52 230 storres
    write("  " + scriptName + " <degree> <alpha> <htrn> <intervalCenter>\n")
53 236 storres
    write("               <numberOfNumbers> [debug]\n")
54 230 storres
    write("\nArguments:\n")
55 230 storres
    write("  degree          the degree of the polynomial (integer)\n")
56 230 storres
    write("  alpha           alpha (integer)\n")
57 230 storres
    write("  htrn            hardness-to-round - a number of bits (integer)\n")
58 230 storres
    write("  intervalCenter  the interval center (a floating-point number)\n")
59 236 storres
    write("  numberOfNumbers the number of floating-point numbers in the interval\n")
60 236 storres
    write("                  as a positive integral expression\n")
61 230 storres
    write("  debug           debug mode (\"debug\", in any case)\n\n")
62 230 storres
    sys.exit(2)
63 230 storres
# End usage.
64 230 storres
#
65 230 storres
argsCount = len(sys.argv)
66 230 storres
scriptName = os.path.basename(__file__)
67 230 storres
if argsCount < 5:
68 230 storres
    usage()
69 230 storres
for index in xrange(1,argsCount):
70 230 storres
    if index == 1:
71 230 storres
        degree = int(sys.argv[index])
72 230 storres
    elif index == 2:
73 230 storres
        alpha = int(sys.argv[index])
74 230 storres
    elif index == 3:
75 230 storres
        htrn = int(eval(sys.argv[index]))
76 230 storres
    elif index == 4:
77 230 storres
        try:
78 230 storres
            intervalCenter = QQ(sage_eval(sys.argv[index]))
79 230 storres
        except:
80 230 storres
            intervalCenter = RRR(sys.argv[index])
81 230 storres
        intervalCenter = RRR(intervalCenter)
82 230 storres
    elif index == 5:
83 236 storres
        ## Can be read as rational number but must end up as an integer.
84 236 storres
        numberOfNumbers = QQ(sage_eval(sys.argv[index]))
85 236 storres
        if numberOfNumbers != numberOfNumbers.round():
86 236 storres
            raise Exception("Invalid number of numbers: " + sys.argv[index] + ".")
87 236 storres
        numberOfNumbers = numberOfNumbers.round()
88 236 storres
        ## The number must be strictly positive.
89 236 storres
        if numberOfNumbers <= 0:
90 236 storres
            raise Exception("Invalid number of numbers: " + sys.argv[index] + ".")
91 230 storres
    elif index == 6:
92 230 storres
        debugMode = sys.argv[index].upper()
93 230 storres
        debugMode = (debugMode == "DEBUG")
94 230 storres
# Done with command line arguments collection.
95 230 storres
#
96 230 storres
## Debug printing
97 230 storres
print "degree         :", degree
98 230 storres
print "alpha          :", alpha
99 230 storres
print "htrn           :", htrn
100 230 storres
print "interval center:", intervalCenter.n(prec=10).str(truncate=False)
101 236 storres
print "num of nums    :", RR(numberOfNumbers).log2().n(prec=10).str(truncate=False)
102 230 storres
print "debug mode     :", debugMode
103 230 storres
print
104 230 storres
#
105 230 storres
## Set the terminal window title.
106 230 storres
terminalWindowTitle = ['stt', str(degree), str(alpha), str(htrn),
107 230 storres
                       intervalCenter.n(prec=10).str(truncate=False),
108 236 storres
                       RRR(numberOfNumbers).log2().n(prec=10).str(truncate=False)]
109 230 storres
call(terminalWindowTitle)
110 230 storres
#
111 236 storres
intervalCenterBinade = slz_compute_binade(intervalCenter)
112 236 storres
intervalRadius       = \
113 236 storres
    2^intervalCenterBinade * 2^(-precision + 1) * numberOfNumbers / 2
114 230 storres
srs_run_SLZ_v05(inputFunction=func,
115 230 storres
                inputLowerBound         = intervalCenter - intervalRadius,
116 230 storres
                inputUpperBound         = intervalCenter + intervalRadius,
117 230 storres
                alpha                   = alpha,
118 230 storres
                degree                  = degree,
119 230 storres
                precision               = precision,
120 230 storres
                emin                    = emin,
121 230 storres
                emax                    = emax,
122 230 storres
                targetHardnessToRound   = htrn,
123 230 storres
                debug                   = debugMode)