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