Statistiques
| Révision :

root / pobysoPythonSage / src / sageSLZ / runSLZ-113gram.sage @ 253

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

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