Statistiques
| Révision :

root / pobysoPythonSage / src / sageSLZ / runSLZ-113proj-02.sage.py

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

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