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