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