Statistiques
| Révision :

root / pobysoPythonSage / src / sageSLZ / runSLZ-113proj.sage @ 268

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

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