root / pobysoPythonSage / src / sageSLZ / runSLZ-01.sage @ 192
Historique | Voir | Annoter | Télécharger (21,36 ko)
1 | 184 | storres | #! /opt/sage/sage |
---|---|---|---|
2 | 189 | storres | from scipy.constants.codata import precision |
3 | 184 | storres | def initialize_env(): |
4 | 184 | storres | #Load all necessary modules. |
5 | 184 | storres | if not 'mpfi' in sage.misc.cython.standard_libs: |
6 | 184 | storres | sage.misc.cython.standard_libs.append('mpfi') |
7 | 184 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sollya_lib.sage") |
8 | 189 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageMpfr.spyx") |
9 | 184 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/pobyso.py") |
10 | 184 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageSLZ.sage") |
11 | 184 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageNumericalOperations.sage") |
12 | 184 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageRationalOperations.sage") |
13 | 184 | storres | # Matrix operations are loaded by polynomial operations. |
14 | 184 | storres | load("/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage") |
15 | 184 | storres | |
16 | 184 | storres | |
17 | 191 | storres | def run_SLZ_v01(inputFunction, |
18 | 191 | storres | inputLowerBound, |
19 | 191 | storres | inputUpperBound, |
20 | 191 | storres | alpha, |
21 | 191 | storres | degree, |
22 | 191 | storres | precision, |
23 | 191 | storres | emin, |
24 | 191 | storres | emax, |
25 | 191 | storres | targetHardnessToRound, |
26 | 191 | storres | debug = False): |
27 | 184 | storres | |
28 | 184 | storres | if debug: |
29 | 189 | storres | print "Function :", inputFunction |
30 | 189 | storres | print "Lower bound :", inputLowerBound |
31 | 189 | storres | print "Upper bounds :", inputUpperBound |
32 | 184 | storres | print "Alpha :", alpha |
33 | 184 | storres | print "Degree :", degree |
34 | 184 | storres | print "Precision :", precision |
35 | 189 | storres | print "Emin :", emin |
36 | 189 | storres | print "Emax :", emax |
37 | 184 | storres | print "Target hardness-to-round:", targetHardnessToRound |
38 | 189 | storres | |
39 | 189 | storres | ## Structures. |
40 | 189 | storres | RRR = RealField(precision) |
41 | 189 | storres | RRIF = RealIntervalField(precision) |
42 | 189 | storres | ## Converting input bound into the "right" field. |
43 | 189 | storres | lowerBound = RRR(inputLowerBound) |
44 | 189 | storres | upperBound = RRR(inputUpperBound) |
45 | 189 | storres | ## Before going any further, check domain and image binade conditions. |
46 | 189 | storres | print inputFunction(1).n() |
47 | 189 | storres | (lb,ub) = slz_fix_bounds_for_binades(lowerBound, upperBound, inputFunction) |
48 | 189 | storres | if lb != lowerBound or ub != upperBound: |
49 | 189 | storres | print "lb:", lb, " - ub:", ub |
50 | 189 | storres | print "Invalid domain/image binades. Domain:",\ |
51 | 189 | storres | lowerBound, upperBound, "Images:", \ |
52 | 189 | storres | inputFunction(lowerBound), inputFunction(upperBound) |
53 | 189 | storres | raise Exception("Invalid domain/image binades.") |
54 | 189 | storres | # |
55 | 189 | storres | ## Progam initialization |
56 | 189 | storres | ### Approximation polynomial accuracy and hardness to round. |
57 | 189 | storres | polyApproxAccur = 2^(-(targetHardnessToRound + 1)) |
58 | 189 | storres | polyTargetHardnessToRound = targetHardnessToRound + 1 |
59 | 189 | storres | ### Significand to integer conversion ratio. |
60 | 189 | storres | toIntegerFactor = 2^(precision-1) |
61 | 189 | storres | print "Polynomial approximation required accuracy:", polyApproxAccur.n() |
62 | 189 | storres | ### Variables and rings for polynomials and root searching. |
63 | 189 | storres | i=var('i') |
64 | 189 | storres | t=var('t') |
65 | 189 | storres | inputFunctionVariable = inputFunction.variables()[0] |
66 | 189 | storres | function = inputFunction.subs({inputFunctionVariable:i}) |
67 | 189 | storres | # Polynomial Rings over the integers, for root finding. |
68 | 189 | storres | Zi = ZZ[i] |
69 | 189 | storres | Zt = ZZ[t] |
70 | 189 | storres | Zit = ZZ[i,t] |
71 | 189 | storres | ## Number of iterations limit. |
72 | 189 | storres | maxIter = 100000 |
73 | 189 | storres | # |
74 | 189 | storres | ## Compute the scaled function and the degree, in their Sollya version |
75 | 189 | storres | # once for all. |
76 | 189 | storres | (scaledf, sdlb, sdub, silb, siub) = \ |
77 | 189 | storres | slz_compute_scaled_function(function, lowerBound, upperBound, precision) |
78 | 189 | storres | print "Scaled function:", scaledf._assume_str().replace('_SAGE_VAR_', '') |
79 | 189 | storres | scaledfSo = sollya_lib_parse_string(scaledf._assume_str().replace('_SAGE_VAR_', '')) |
80 | 189 | storres | degreeSo = pobyso_constant_from_int_sa_so(degree) |
81 | 189 | storres | # |
82 | 189 | storres | ## Compute the scaling. boundsIntervalRifSa defined out of the loops. |
83 | 189 | storres | domainBoundsInterval = RRIF(lowerBound, upperBound) |
84 | 189 | storres | (unscalingFunction, scalingFunction) = \ |
85 | 189 | storres | slz_interval_scaling_expression(domainBoundsInterval, i) |
86 | 189 | storres | #print scalingFunction, unscalingFunction |
87 | 189 | storres | ## Set the Sollya internal precision (with an arbitrary minimum of 192). |
88 | 189 | storres | internalSollyaPrec = ceil((RR('1.5') * targetHardnessToRound) / 64) * 64 |
89 | 189 | storres | if internalSollyaPrec < 192: |
90 | 189 | storres | internalSollyaPrec = 192 |
91 | 189 | storres | pobyso_set_prec_sa_so(internalSollyaPrec) |
92 | 189 | storres | print "Sollya internal precision:", internalSollyaPrec |
93 | 189 | storres | ## Some variables. |
94 | 189 | storres | ### General variables |
95 | 189 | storres | lb = sdlb |
96 | 189 | storres | ub = sdub |
97 | 189 | storres | nbw = 0 |
98 | 189 | storres | intervalUlp = ub.ulp() |
99 | 189 | storres | #### Will be set by slz_interval_and_polynomila_to_sage. |
100 | 189 | storres | ic = 0 |
101 | 189 | storres | icAsInt = 0 # Set from ic. |
102 | 189 | storres | solutionsSet = set() |
103 | 189 | storres | tsErrorWidth = [] |
104 | 189 | storres | csErrorVectors = [] |
105 | 189 | storres | csVectorsResultants = [] |
106 | 189 | storres | floatP = 0 # Taylor polynomial. |
107 | 189 | storres | floatPcv = 0 # Ditto with variable change. |
108 | 189 | storres | intvl = "" # Taylor interval |
109 | 189 | storres | terr = 0 # Taylor error. |
110 | 189 | storres | iterCount = 0 |
111 | 189 | storres | htrnSet = set() |
112 | 189 | storres | ### Timers and counters. |
113 | 189 | storres | wallTimeStart = 0 |
114 | 189 | storres | cpuTimeStart = 0 |
115 | 189 | storres | taylCondFailedCount = 0 |
116 | 189 | storres | coppCondFailedCount = 0 |
117 | 189 | storres | resultCondFailedCount = 0 |
118 | 189 | storres | coppCondFailed = False |
119 | 189 | storres | resultCondFailed = False |
120 | 189 | storres | globalResultsList = [] |
121 | 189 | storres | basisConstructionsCount = 0 |
122 | 189 | storres | basisConstructionsFullTime = 0 |
123 | 189 | storres | basisConstructionTime = 0 |
124 | 189 | storres | reductionsCount = 0 |
125 | 189 | storres | reductionsFullTime = 0 |
126 | 189 | storres | reductionTime = 0 |
127 | 189 | storres | resultantsComputationsCount = 0 |
128 | 189 | storres | resultantsComputationsFullTime = 0 |
129 | 189 | storres | resultantsComputationTime = 0 |
130 | 189 | storres | rootsComputationsCount = 0 |
131 | 189 | storres | rootsComputationsFullTime = 0 |
132 | 189 | storres | rootsComputationTime = 0 |
133 | 189 | storres | |
134 | 189 | storres | ## Global times are started here. |
135 | 189 | storres | wallTimeStart = walltime() |
136 | 189 | storres | cpuTimeStart = cputime() |
137 | 189 | storres | ## Main loop. |
138 | 189 | storres | while True: |
139 | 189 | storres | if lb >= sdub: |
140 | 189 | storres | print "Lower bound reached upper bound." |
141 | 189 | storres | break |
142 | 189 | storres | if iterCount == maxIter: |
143 | 189 | storres | print "Reached maxIter. Aborting" |
144 | 189 | storres | break |
145 | 189 | storres | iterCount += 1 |
146 | 189 | storres | print "[", lb, ",", ub, "]", ((ub - lb) / intervalUlp).log2().n(), \ |
147 | 189 | storres | "log2(numbers)." |
148 | 189 | storres | ### Compute a Sollya polynomial that will honor the Taylor condition. |
149 | 189 | storres | prceSo = slz_compute_polynomial_and_interval(scaledfSo, |
150 | 189 | storres | degreeSo, |
151 | 189 | storres | lb, |
152 | 189 | storres | ub, |
153 | 189 | storres | polyApproxAccur) |
154 | 189 | storres | ### Convert back the data into Sage space. |
155 | 189 | storres | (floatP, floatPcv, intvl, ic, terr) = \ |
156 | 189 | storres | slz_interval_and_polynomial_to_sage((prceSo[0], prceSo[0], |
157 | 189 | storres | prceSo[1], prceSo[2], |
158 | 189 | storres | prceSo[3])) |
159 | 189 | storres | intvl = RRIF(intvl) |
160 | 189 | storres | ## Clean-up Sollya stuff. |
161 | 189 | storres | for elem in prceSo: |
162 | 189 | storres | sollya_lib_clear_obj(elem) |
163 | 189 | storres | #print floatP, floatPcv, intvl, ic, terr |
164 | 189 | storres | #print floatP |
165 | 189 | storres | #print intvl.endpoints()[0].n(), \ |
166 | 189 | storres | # ic.n(), |
167 | 189 | storres | #intvl.endpoints()[1].n() |
168 | 189 | storres | ### Check returned data. |
169 | 189 | storres | #### Is approximation error OK? |
170 | 189 | storres | if terr > polyApproxAccur: |
171 | 189 | storres | exceptionErrorMess = \ |
172 | 189 | storres | "Approximation failed - computed error:" + \ |
173 | 189 | storres | str(terr) + " - target error: " |
174 | 189 | storres | exceptionErrorMess += \ |
175 | 189 | storres | str(polyApproxAccur) + ". Aborting!" |
176 | 189 | storres | raise Exception(exceptionErrorMess) |
177 | 189 | storres | #### Is lower bound OK? |
178 | 189 | storres | if lb != intvl.endpoints()[0]: |
179 | 189 | storres | exceptionErrorMess = "Wrong lower bound:" + \ |
180 | 189 | storres | str(lb) + ". Aborting!" |
181 | 189 | storres | raise Exception(exceptionErrorMess) |
182 | 189 | storres | #### Set upper bound. |
183 | 189 | storres | if ub > intvl.endpoints()[1]: |
184 | 189 | storres | ub = intvl.endpoints()[1] |
185 | 189 | storres | print "[", lb, ",", ub, "]", ((ub - lb) / intervalUlp).log2().n(), \ |
186 | 189 | storres | "log2(numbers)." |
187 | 189 | storres | taylCondFailedCount += 1 |
188 | 189 | storres | #### Is interval not degenerate? |
189 | 189 | storres | if lb >= ub: |
190 | 189 | storres | exceptionErrorMess = "Degenerate interval: " + \ |
191 | 189 | storres | "lowerBound(" + str(lb) +\ |
192 | 189 | storres | ")>= upperBound(" + str(ub) + \ |
193 | 189 | storres | "). Aborting!" |
194 | 189 | storres | raise Exception(exceptionErrorMess) |
195 | 189 | storres | #### Is interval center ok? |
196 | 189 | storres | if ic <= lb or ic >= ub: |
197 | 189 | storres | exceptionErrorMess = "Invalid interval center for " + \ |
198 | 189 | storres | str(lb) + ',' + str(ic) + ',' + \ |
199 | 189 | storres | str(ub) + ". Aborting!" |
200 | 189 | storres | raise Exception(exceptionErrorMess) |
201 | 189 | storres | ##### Current interval width and reset future interval width. |
202 | 189 | storres | bw = ub - lb |
203 | 189 | storres | nbw = 0 |
204 | 189 | storres | icAsInt = int(ic * toIntegerFactor) |
205 | 189 | storres | #### The following ratio is always >= 1. In case we may want to |
206 | 189 | storres | # enlarge the interval |
207 | 189 | storres | curTaylErrRat = polyApproxAccur / terr |
208 | 189 | storres | ## Make the integral transformations. |
209 | 189 | storres | ### First for interval center and bounds. |
210 | 189 | storres | intIc = int(ic * toIntegerFactor) |
211 | 189 | storres | intLb = int(lb * toIntegerFactor) - intIc |
212 | 189 | storres | intUb = int(ub * toIntegerFactor) - intIc |
213 | 189 | storres | # |
214 | 189 | storres | #### Loop flesh |
215 | 191 | storres | #### For polynomials |
216 | 191 | storres | basisConstructionTime = cputime() |
217 | 191 | storres | ##### To a polynomial with rational coefficients with rational arguments |
218 | 191 | storres | ratRatP = slz_float_poly_of_float_to_rat_poly_of_rat_pow_two(floatP) |
219 | 191 | storres | ##### To a polynomial with rational coefficients with integer arguments |
220 | 191 | storres | ratIntP = \ |
221 | 191 | storres | slz_rat_poly_of_rat_to_rat_poly_of_int(ratRatP, precision) |
222 | 191 | storres | ##### Ultimately a polynomial with integer coefficients with integer |
223 | 191 | storres | # arguments. |
224 | 191 | storres | coppersmithTuple = \ |
225 | 191 | storres | slz_rat_poly_of_int_to_poly_for_coppersmith(ratIntP, |
226 | 191 | storres | precision, |
227 | 191 | storres | targetHardnessToRound, |
228 | 191 | storres | i, t) |
229 | 191 | storres | #### Recover Coppersmith information. |
230 | 191 | storres | intIntP = coppersmithTuple[0] |
231 | 191 | storres | N = coppersmithTuple[1] |
232 | 191 | storres | nAtAlpha = N^alpha |
233 | 191 | storres | tBound = coppersmithTuple[2] |
234 | 191 | storres | leastCommonMultiple = coppersmithTuple[3] |
235 | 191 | storres | iBound = max(abs(intLb),abs(intUb)) |
236 | 191 | storres | basisConstructionsFullTime += cputime(basisConstructionTime) |
237 | 191 | storres | basisConstructionsCount += 1 |
238 | 191 | storres | reductionTime = cputime() |
239 | 191 | storres | # Compute the reduced polynomials. |
240 | 191 | storres | ccReducedPolynomialsList = \ |
241 | 191 | storres | slz_compute_coppersmith_reduced_polynomials(intIntP, |
242 | 191 | storres | alpha, |
243 | 191 | storres | N, |
244 | 191 | storres | iBound, |
245 | 191 | storres | tBound) |
246 | 191 | storres | if ccReducedPolynomialsList is None: |
247 | 191 | storres | raise Exception("Reduction failed.") |
248 | 191 | storres | reductionsFullTime += cputime(reductionTime) |
249 | 191 | storres | reductionsCount += 1 |
250 | 191 | storres | if len(ccReducedPolynomialsList) < 2: |
251 | 191 | storres | print "Nothing to form resultants with." |
252 | 191 | storres | |
253 | 191 | storres | coppCondFailedCount += 1 |
254 | 191 | storres | coppCondFailed = True |
255 | 191 | storres | ##### Apply a different shrink factor according to |
256 | 191 | storres | # the number of complient polynomials. |
257 | 191 | storres | if len(ccReducedPolynomialsList) == 0: |
258 | 191 | storres | ub = lb + bw / 4 |
259 | 191 | storres | else: # At least one complient polynomial. |
260 | 191 | storres | ub = lb + bw / 2 |
261 | 191 | storres | if ub > sdub: |
262 | 191 | storres | ub = sdub |
263 | 191 | storres | if lb == ub: |
264 | 191 | storres | raise Exception("Cant shrink interval \ |
265 | 191 | storres | anymore to get Coppersmith condition.") |
266 | 191 | storres | nbw = 0 |
267 | 191 | storres | continue |
268 | 191 | storres | #### We have at least two polynomials. |
269 | 191 | storres | # Let us try to compute resultants. |
270 | 191 | storres | resultantsComputationTime = cputime() |
271 | 191 | storres | resultantsInTTuplesList = [] |
272 | 191 | storres | for polyOuterIndex in xrange(0, len(ccReducedPolynomialsList) - 1): |
273 | 191 | storres | for polyInnerIndex in xrange(polyOuterIndex+1, |
274 | 191 | storres | len(ccReducedPolynomialsList)): |
275 | 191 | storres | resultantTuple = \ |
276 | 191 | storres | slz_resultant_tuple(ccReducedPolynomialsList[polyOuterIndex], |
277 | 191 | storres | ccReducedPolynomialsList[polyInnerIndex], |
278 | 191 | storres | t) |
279 | 191 | storres | if len(resultantTuple) > 2: |
280 | 191 | storres | #print resultantTuple[2] |
281 | 191 | storres | resultantsInTTuplesList.append(resultantTuple) |
282 | 191 | storres | else: |
283 | 191 | storres | print "No non nul resultant" |
284 | 191 | storres | print len(resultantsInTTuplesList), "resultant(s) in t tuple(s) created." |
285 | 191 | storres | resultantsComputationsFullTime += cputime(resultantsComputationTime) |
286 | 191 | storres | resultantsComputationsCount += 1 |
287 | 191 | storres | if len(resultantsInTTuplesList) == 0: |
288 | 191 | storres | print "Only null resultants, shrinking interval." |
289 | 191 | storres | resultCondFailed = True |
290 | 191 | storres | resultCondFailedCount += 1 |
291 | 191 | storres | ### Shrink interval for next iteration. |
292 | 191 | storres | ub = lb + bw / 2 |
293 | 191 | storres | if ub > sdub: |
294 | 191 | storres | ub = sdub |
295 | 191 | storres | nbw = 0 |
296 | 191 | storres | continue |
297 | 191 | storres | #### Compute roots. |
298 | 191 | storres | reducedPolynomialsRootsSet = set() |
299 | 191 | storres | ##### Solve in the second variable since resultants are in the first |
300 | 191 | storres | # variable. |
301 | 191 | storres | for resultantInTTuple in resultantsInTTuplesList: |
302 | 191 | storres | currentResultant = resultantInTTuple[2] |
303 | 191 | storres | ##### If the resultant degree is not at least 1, there are no roots. |
304 | 191 | storres | if currentResultant.degree() < 1: |
305 | 191 | storres | print "Resultant is constant:", currentResultant |
306 | 191 | storres | continue # Next resultantInTTuple |
307 | 191 | storres | ##### Compute i roots |
308 | 191 | storres | iRootsList = Zi(currentResultant).roots() |
309 | 191 | storres | ##### For each iRoot, compute the corresponding tRoots and check |
310 | 191 | storres | # them in the input polynomial. |
311 | 191 | storres | for iRoot in iRootsList: |
312 | 191 | storres | ####### Roots returned by roots() are (value, multiplicity) |
313 | 191 | storres | # tuples. |
314 | 191 | storres | #print "iRoot:", iRoot |
315 | 191 | storres | ###### Use the tRoot against each polynomial, alternatively. |
316 | 191 | storres | for indexInTuple in range(0,2): |
317 | 191 | storres | currentPolynomial = resultantInTTuple[indexInTuple] |
318 | 191 | storres | ####### If the polynomial is univariate, just drop it. |
319 | 191 | storres | if len(currentPolynomial.variables()) < 2: |
320 | 191 | storres | print " Current polynomial is not in two variables." |
321 | 191 | storres | continue # Next indexInTuple |
322 | 191 | storres | tRootsList = \ |
323 | 191 | storres | Zt(currentPolynomial.subs({currentPolynomial.variables()[0]:iRoot[0]})).roots() |
324 | 191 | storres | ####### The tRootsList can be empty, hence the test. |
325 | 191 | storres | if len(tRootsList) == 0: |
326 | 191 | storres | print " No t root." |
327 | 191 | storres | continue # Next indexInTuple |
328 | 191 | storres | for tRoot in tRootsList: |
329 | 191 | storres | reducedPolynomialsRootsSet.add((iRoot[0], tRoot[0])) |
330 | 191 | storres | # End of roots computation |
331 | 192 | storres | ##### Prepare for results. |
332 | 192 | storres | intervalResultsList = [] |
333 | 192 | storres | intervalResultsList.append((lb, ub)) |
334 | 192 | storres | #### Check roots. |
335 | 192 | storres | rootsResultsList = [] |
336 | 192 | storres | rootsComputationTime = cputime() |
337 | 192 | storres | for root in reducedPolynomialsRootsSet: |
338 | 192 | storres | specificRootResultsList = [] |
339 | 192 | storres | failingBounds = [] |
340 | 192 | storres | intIntPdivN = intIntP(root[0], root[1]) / N |
341 | 192 | storres | if int(intIntPdivN) != intIntPdivN: |
342 | 192 | storres | continue # Next root |
343 | 192 | storres | # Root qualifies for modular equation, test it for hardness to round. |
344 | 192 | storres | hardToRoundCaseAsFloat = RRR((icAsInt + root[0]) / toIntegerFactor) |
345 | 192 | storres | #print "Before unscaling:", hardToRoundCaseAsFloat.n(prec=precision) |
346 | 192 | storres | #print scalingFunction |
347 | 192 | storres | scaledHardToRoundCaseAsFloat = \ |
348 | 192 | storres | scalingFunction(hardToRoundCaseAsFloat) |
349 | 192 | storres | print "Candidate HTRNc at x =", \ |
350 | 192 | storres | scaledHardToRoundCaseAsFloat.n().str(base=2), |
351 | 192 | storres | if slz_is_htrn(scaledHardToRoundCaseAsFloat, |
352 | 192 | storres | f, |
353 | 192 | storres | 2^-(targetHardnessToRound), |
354 | 192 | storres | RRR): |
355 | 192 | storres | print hardToRoundCaseAsFloat, "is HTRN case." |
356 | 192 | storres | if lb <= hardToRoundCaseAsFloat and hardToRoundCaseAsFloat <= ub: |
357 | 192 | storres | print "Found in interval." |
358 | 192 | storres | else: |
359 | 192 | storres | print "Found out of interval." |
360 | 192 | storres | specificRootResultsList.append(hardToRoundCaseAsFloat.n().str(base=2)) |
361 | 192 | storres | # Check the root is in the bounds |
362 | 192 | storres | if abs(root[0]) > iBound or abs(root[1]) > tBound: |
363 | 192 | storres | print "Root", root, "is out of bounds." |
364 | 192 | storres | if abs(root[0]) > iBound: |
365 | 192 | storres | print "root[0]:", root[0] |
366 | 192 | storres | print "i bound:", iBound |
367 | 192 | storres | failingBounds.append('i') |
368 | 192 | storres | failingBounds.append(root[0]) |
369 | 192 | storres | failingBounds.append(iBound) |
370 | 192 | storres | if abs(root[1]) > tBound: |
371 | 192 | storres | print "root[1]:", root[1] |
372 | 192 | storres | print "t bound:", tBound |
373 | 192 | storres | failingBounds.append('t') |
374 | 192 | storres | failingBounds.append(root[1]) |
375 | 192 | storres | failingBounds.append(tBound) |
376 | 192 | storres | if len(failingBounds) > 0: |
377 | 192 | storres | specificRootResultsList.append(failingBounds) |
378 | 192 | storres | else: # From slz_is_htrn... |
379 | 192 | storres | print "is not an HTRN case." |
380 | 192 | storres | if len(specificRootResultsList) > 0: |
381 | 192 | storres | rootsResultsList.append(specificRootResultsList) |
382 | 192 | storres | rootsComputationsFullTime = cputime(rootsComputationTime) |
383 | 192 | storres | rootsComputationsCount += 1 |
384 | 192 | storres | if len(rootsResultsList) > 0: |
385 | 192 | storres | intervalResultsList.append(rootsResultsList) |
386 | 192 | storres | #### An intervalResultsList has at least the bounds. |
387 | 192 | storres | globalResultsList.append(intervalResultsList) |
388 | 189 | storres | #### End loop flesh. |
389 | 189 | storres | #### Compute an incremented width for next upper bound, only |
390 | 189 | storres | # if not Coppersmith condition nor resultant condition |
391 | 189 | storres | # failed at the previous run. |
392 | 189 | storres | if not coppCondFailed and not resultCondFailed: |
393 | 189 | storres | nbw = (1 + 2^(-5)) * bw |
394 | 189 | storres | ##### Reset the failure flags. They will be raised |
395 | 189 | storres | # again if needed. |
396 | 189 | storres | else: |
397 | 189 | storres | nbw = bw |
398 | 189 | storres | coppCondFailed = False |
399 | 189 | storres | resultCondFailed = False |
400 | 189 | storres | #### For next iteration (at end of loop) |
401 | 189 | storres | #print "nbw:", nbw |
402 | 189 | storres | lb = ub |
403 | 189 | storres | ub += nbw |
404 | 189 | storres | if ub > sdub: |
405 | 189 | storres | ub = sdub |
406 | 189 | storres | |
407 | 189 | storres | # End while True |
408 | 189 | storres | ## Main loop just ended. |
409 | 189 | storres | globalWallTime = walltime(wallTimeStart) |
410 | 189 | storres | globalCpuTime = cputime(cpuTimeStart) |
411 | 189 | storres | ## Output results |
412 | 189 | storres | print ; print "Intervals and HTRNs" |
413 | 189 | storres | for intervalResultsList in globalResultsList: |
414 | 189 | storres | print "[", intervalResultsList[0][0], ",",intervalResultsList[0][1], "]", |
415 | 189 | storres | if len(intervalResultsList) > 1: |
416 | 189 | storres | rootsResultsList = intervalResultsList[1] |
417 | 189 | storres | for specificRootResultsList in rootsResultsList: |
418 | 189 | storres | print "\t", specificRootResultsList[0], |
419 | 189 | storres | if len(specificRootResultsList) > 1: |
420 | 189 | storres | print specificRootResultsList[1], |
421 | 189 | storres | print ; print |
422 | 189 | storres | #print globalResultsList |
423 | 189 | storres | # |
424 | 189 | storres | print "Timers and counters" |
425 | 189 | storres | |
426 | 189 | storres | print "Number of iterations:", iterCount |
427 | 189 | storres | print "Taylor condition failures:", taylCondFailedCount |
428 | 189 | storres | print "Coppersmith condition failures:", coppCondFailedCount |
429 | 189 | storres | print "Resultant condition failures:", resultCondFailedCount |
430 | 189 | storres | print "Iterations count: ", iterCount |
431 | 189 | storres | print "Number of intervals:", len(globalResultsList) |
432 | 189 | storres | print "Number of basis constructions:", basisConstructionsCount |
433 | 189 | storres | print "Total CPU time spent in basis constructions:", \ |
434 | 189 | storres | basisConstructionsFullTime |
435 | 189 | storres | if basisConstructionsCount != 0: |
436 | 189 | storres | print "Average basis construction CPU time:", \ |
437 | 189 | storres | basisConstructionsFullTime/basisConstructionsCount |
438 | 189 | storres | print "Number of reductions:", reductionsCount |
439 | 189 | storres | print "Total CPU time spent in reductions:", reductionsFullTime |
440 | 189 | storres | if reductionsCount != 0: |
441 | 189 | storres | print "Average reduction CPU time:", \ |
442 | 189 | storres | reductionsFullTime/reductionsCount |
443 | 189 | storres | print "Number of resultants computation rounds:", \ |
444 | 189 | storres | resultantsComputationsCount |
445 | 189 | storres | print "Total CPU time spent in resultants computation rounds:", \ |
446 | 189 | storres | resultantsComputationsFullTime |
447 | 189 | storres | if resultantsComputationsCount != 0: |
448 | 189 | storres | print "Average resultants computation round CPU time:", \ |
449 | 189 | storres | resultantsComputationsFullTime/resultantsComputationsCount |
450 | 189 | storres | print "Number of root finding rounds:", rootsComputationsCount |
451 | 189 | storres | print "Total CPU time spent in roots finding rounds:", \ |
452 | 189 | storres | rootsComputationsFullTime |
453 | 189 | storres | if rootsComputationsCount != 0: |
454 | 189 | storres | print "Average roots finding round CPU time:", \ |
455 | 189 | storres | rootsComputationsFullTime/rootsComputationsCount |
456 | 189 | storres | print "Global Wall time:", globalWallTime |
457 | 189 | storres | print "Global CPU time:", globalCpuTime |
458 | 189 | storres | ## Output counters |
459 | 191 | storres | # End runSLZ-v01 |
460 | 184 | storres | |
461 | 184 | storres | print "Running SLZ..." |
462 | 189 | storres | initialize_env() |
463 | 189 | storres | x = var('x') |
464 | 189 | storres | func(x) = exp(x) |
465 | 189 | storres | precision = 53 |
466 | 189 | storres | RRR = RealField(precision) |
467 | 191 | storres | run_SLZ_v01(inputFunction=func, |
468 | 192 | storres | inputLowerBound = 6/16, |
469 | 192 | storres | inputUpperBound = 7/16, |
470 | 191 | storres | alpha = 2, |
471 | 191 | storres | degree = 10, |
472 | 191 | storres | precision = 53, |
473 | 191 | storres | emin = -1022, |
474 | 191 | storres | emax = 1023, |
475 | 191 | storres | targetHardnessToRound = precision+50, |
476 | 191 | storres | debug = True) |
477 | 192 | storres | |
478 | 192 | storres | #inputUpperBound = RRR(1/2) - RRR(1/4).ulp(), |