Statistiques
| Révision :

root / pobysoPythonSage / src / sageSLZ / runSLZ-53gram.sage @ 258

Historique | Voir | Annoter | Télécharger (5,14 ko)

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