root / pobysoPythonSage / src / sageSLZ / runSLZ-113proj.sage @ 272
Historique | Voir | Annoter | Télécharger (5,92 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 | 270 | storres | if version().split()[2].replace(',','') > '6.6': |
23 | 270 | storres | compiledSpyxDir = \ |
24 | 270 | storres | "/home/storres/recherche/arithmetique/pobysoPythonSage/compiledSpyx" |
25 | 270 | storres | if compiledSpyxDir not in sys.path: |
26 | 270 | storres | sys.path.append(compiledSpyxDir) |
27 | 270 | storres | else: |
28 | 270 | storres | if not 'mpfi' in sage.misc.cython.standard_libs: |
29 | 270 | storres | sage.misc.cython.standard_libs.append('mpfi') |
30 | 270 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx") |
31 | 270 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx") |
32 | 247 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage") |
33 | 247 | storres | # load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx") |
34 | 247 | storres | # load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageGMP.spyx") |
35 | 247 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py") |
36 | 247 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage") |
37 | 247 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage") |
38 | 247 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage") |
39 | 247 | storres | # Matrix operations are loaded by polynomial operations. |
40 | 247 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage") |
41 | 247 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage") |
42 | 247 | storres | |
43 | 247 | storres | |
44 | 247 | storres | print "Running SLZ..." |
45 | 247 | storres | initialize_env() |
46 | 270 | storres | if version().split()[2].replace(',','') > '6.6': |
47 | 270 | storres | from sageMpfr import * |
48 | 270 | storres | from sageGMP import * |
49 | 247 | storres | import sys |
50 | 247 | storres | from subprocess import call |
51 | 247 | storres | # |
52 | 247 | storres | ## Main variables and parameters. |
53 | 247 | storres | x = var('x') |
54 | 247 | storres | func(x) = exp(x) |
55 | 247 | storres | precision = 113 |
56 | 247 | storres | emin = -16382 |
57 | 247 | storres | emax = 16383 |
58 | 247 | storres | RRR = RealField(precision) |
59 | 247 | storres | degree = 0 |
60 | 247 | storres | alpha = 0 |
61 | 247 | storres | htrn = 0 |
62 | 247 | storres | intervalCenter = 0 |
63 | 247 | storres | intervalRadius = 0 |
64 | 247 | storres | debugMode = False |
65 | 247 | storres | ## Local functions |
66 | 247 | storres | # |
67 | 247 | storres | def usage(): |
68 | 247 | storres | write = sys.stderr.write |
69 | 247 | storres | write("\nUsage:\n") |
70 | 247 | storres | write(" " + scriptName + " <degree> <alpha> <htrn> <intervalCenter>\n") |
71 | 247 | storres | write(" <numberOfNumbers> [debug]\n") |
72 | 247 | storres | write("\nArguments:\n") |
73 | 247 | storres | write(" degree the degree of the polynomial (integer)\n") |
74 | 247 | storres | write(" alpha alpha (integer)\n") |
75 | 247 | storres | write(" htrn hardness-to-round - a number of bits (integer)\n") |
76 | 247 | storres | write(" intervalCenter the interval center (a floating-point number)\n") |
77 | 247 | storres | write(" numberOfNumbers the number of floating-point numbers in the interval\n") |
78 | 247 | storres | write(" as a positive integral expression\n") |
79 | 247 | storres | write(" debug debug mode (\"debug\", in any case)\n\n") |
80 | 247 | storres | sys.exit(2) |
81 | 247 | storres | # End usage. |
82 | 247 | storres | # |
83 | 247 | storres | argsCount = len(sys.argv) |
84 | 247 | storres | scriptName = os.path.basename(__file__) |
85 | 247 | storres | if argsCount < 5: |
86 | 247 | storres | usage() |
87 | 247 | storres | for index in xrange(1,argsCount): |
88 | 247 | storres | if index == 1: |
89 | 247 | storres | degree = int(sys.argv[index]) |
90 | 247 | storres | elif index == 2: |
91 | 247 | storres | alpha = int(sys.argv[index]) |
92 | 247 | storres | elif index == 3: |
93 | 247 | storres | htrn = int(eval(sys.argv[index])) |
94 | 247 | storres | elif index == 4: |
95 | 247 | storres | try: |
96 | 247 | storres | intervalCenter = QQ(sage_eval(sys.argv[index])) |
97 | 247 | storres | except: |
98 | 247 | storres | intervalCenter = RRR(sys.argv[index]) |
99 | 247 | storres | intervalCenter = RRR(intervalCenter) |
100 | 247 | storres | elif index == 5: |
101 | 247 | storres | ## Can be read as rational number but must end up as an integer. |
102 | 247 | storres | numberOfNumbers = QQ(sage_eval(sys.argv[index])) |
103 | 247 | storres | if numberOfNumbers != numberOfNumbers.round(): |
104 | 247 | storres | raise Exception("Invalid number of numbers: " + sys.argv[index] + ".") |
105 | 247 | storres | numberOfNumbers = numberOfNumbers.round() |
106 | 247 | storres | ## The number must be strictly positive. |
107 | 247 | storres | if numberOfNumbers <= 0: |
108 | 247 | storres | raise Exception("Invalid number of numbers: " + sys.argv[index] + ".") |
109 | 247 | storres | elif index == 6: |
110 | 247 | storres | debugMode = sys.argv[index].upper() |
111 | 247 | storres | debugMode = (debugMode == "DEBUG") |
112 | 247 | storres | # Done with command line arguments collection. |
113 | 247 | storres | # |
114 | 247 | storres | ## Debug printing |
115 | 247 | storres | print "degree :", degree |
116 | 247 | storres | print "alpha :", alpha |
117 | 247 | storres | print "htrn :", htrn |
118 | 247 | storres | print "interval center:", intervalCenter.n(prec=10).str(truncate=False) |
119 | 247 | storres | print "num of nums :", RR(numberOfNumbers).log2().n(prec=10).str(truncate=False) |
120 | 247 | storres | print "debug mode :", debugMode |
121 | 247 | storres | |
122 | 247 | storres | # |
123 | 247 | storres | ## Set the terminal window title. |
124 | 247 | storres | terminalWindowTitle = ['stt', str(degree), str(alpha), str(htrn), |
125 | 247 | storres | intervalCenter.n(prec=10).str(truncate=False), |
126 | 247 | storres | RRR(numberOfNumbers).log2().n(prec=10).str(truncate=False)] |
127 | 247 | storres | call(terminalWindowTitle) |
128 | 247 | storres | # |
129 | 247 | storres | intervalCenterBinade = slz_compute_binade(intervalCenter) |
130 | 247 | storres | intervalRadius = \ |
131 | 247 | storres | 2^intervalCenterBinade * 2^(-precision + 1) * numberOfNumbers / 2 |
132 | 249 | storres | srs_run_SLZ_v05_proj(inputFunction=func, |
133 | 247 | storres | inputLowerBound = intervalCenter - intervalRadius, |
134 | 247 | storres | inputUpperBound = intervalCenter + intervalRadius, |
135 | 247 | storres | alpha = alpha, |
136 | 247 | storres | degree = degree, |
137 | 247 | storres | precision = precision, |
138 | 247 | storres | emin = emin, |
139 | 247 | storres | emax = emax, |
140 | 247 | storres | targetHardnessToRound = htrn, |
141 | 247 | storres | debug = debugMode) |