Statistiques
| Révision :

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

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

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