Statistiques
| Révision :

root / pobysoPythonSage / src / sageSLZ / runSLZ-113projWeak.sage @ 274

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

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