Révision 275 pobysoPythonSage/src/sageSLZ/sageRunSLZ.sage
sageRunSLZ.sage (revision 275) | ||
---|---|---|
3992 | 3992 |
## Output counters |
3993 | 3993 |
# End srs_runSLZ-v05_proj |
3994 | 3994 |
# |
3995 |
def srs_run_SLZ_v05_proj_weak(inputFunction, |
|
3996 |
inputLowerBound, |
|
3997 |
inputUpperBound, |
|
3998 |
alpha, |
|
3999 |
degree, |
|
4000 |
precision, |
|
4001 |
emin, |
|
4002 |
emax, |
|
4003 |
targetHardnessToRound, |
|
4004 |
debug = False): |
|
4005 |
""" |
|
4006 |
chnages from v05_proj: |
|
4007 |
We use a weaker Coppersmith condition. |
|
4008 |
changes from plain V5: |
|
4009 |
LLL reduction is not performed on the matrix itself but rather on the |
|
4010 |
product of the matrix with a uniform random matrix. |
|
4011 |
The reduced matrix obtained is discarded but the transformation matrix |
|
4012 |
obtained is used to multiply the original matrix in order to reduced it. |
|
4013 |
If a sufficient level of reduction is obtained, we stop here. If not |
|
4014 |
the product matrix obtained above is LLL reduced. But as it has been |
|
4015 |
pre-reduced at the above step, reduction is supposed to be much fastet. |
|
4016 |
In the worst case, both reductions combined should hopefully be faster |
|
4017 |
than a straight single reduction. |
|
4018 |
Changes from V4: |
|
4019 |
Approximation polynomial has coefficients rounded. |
|
4020 |
Changes from V3: |
|
4021 |
Root search is changed again: |
|
4022 |
- only resultants in i are computed; |
|
4023 |
- roots in i are searched for; |
|
4024 |
- if any, they are tested for hardness-to-round. |
|
4025 |
Changes from V2: |
|
4026 |
Root search is changed: |
|
4027 |
- we compute the resultants in i and in t; |
|
4028 |
- we compute the roots set of each of these resultants; |
|
4029 |
- we combine all the possible pairs between the two sets; |
|
4030 |
- we check these pairs in polynomials for correctness. |
|
4031 |
Changes from V1: |
|
4032 |
1- check for roots as soon as a resultant is computed; |
|
4033 |
2- once a non null resultant is found, check for roots; |
|
4034 |
3- constant resultant == no root. |
|
4035 |
""" |
|
4036 |
|
|
4037 |
if debug: |
|
4038 |
print "Function :", inputFunction |
|
4039 |
print "Lower bound :", inputLowerBound.str(truncate=False) |
|
4040 |
print "Upper bounds :", inputUpperBound.str(truncate=False) |
|
4041 |
print "Alpha :", alpha |
|
4042 |
print "Degree :", degree |
|
4043 |
print "Precision :", precision |
|
4044 |
print "Emin :", emin |
|
4045 |
print "Emax :", emax |
|
4046 |
print "Target hardness-to-round:", targetHardnessToRound |
|
4047 |
|
|
4048 |
## Important constants. |
|
4049 |
### Stretch the interval if no error happens. |
|
4050 |
noErrorIntervalStretch = 1 + 2^(-5) |
|
4051 |
### If no vector validates the Coppersmith condition, shrink the interval |
|
4052 |
# by the following factor. |
|
4053 |
noCoppersmithIntervalShrink = 1/2 |
|
4054 |
### If only (or at least) one vector validates the Coppersmith condition, |
|
4055 |
# shrink the interval by the following factor. |
|
4056 |
oneCoppersmithIntervalShrink = 3/4 |
|
4057 |
#### If only null resultants are found, shrink the interval by the |
|
4058 |
# following factor. |
|
4059 |
onlyNullResultantsShrink = 3/4 |
|
4060 |
## Structures. |
|
4061 |
RRR = RealField(precision) |
|
4062 |
RRIF = RealIntervalField(precision) |
|
4063 |
## Converting input bound into the "right" field. |
|
4064 |
lowerBound = RRR(inputLowerBound) |
|
4065 |
upperBound = RRR(inputUpperBound) |
|
4066 |
## Before going any further, check domain and image binade conditions. |
|
4067 |
print inputFunction._assume_str(), "at 1:", inputFunction(1).n() |
|
4068 |
output = slz_fix_bounds_for_binades(lowerBound, upperBound, inputFunction) |
|
4069 |
#print "srsv04p:", output, (output is None) |
|
4070 |
# |
|
4071 |
## Check if input to thr fix_bounds function is valid. |
|
4072 |
if output is None: |
|
4073 |
print "Invalid domain/image binades. Domain:",\ |
|
4074 |
lowerBound.str(truncate=False), upperBound(truncate=False), \ |
|
4075 |
"Images:", \ |
|
4076 |
inputFunction(lowerBound), inputFunction(upperBound) |
|
4077 |
raise Exception("Invalid domain/image binades.") |
|
4078 |
lb = output[0] ; ub = output[1] |
|
4079 |
# |
|
4080 |
## Check if bounds have changed. |
|
4081 |
if lb != lowerBound or ub != upperBound: |
|
4082 |
print "lb:", lb.str(truncate=False), " - ub:", ub.str(truncate=False) |
|
4083 |
print "Invalid domain/image binades." |
|
4084 |
print "Domain:", lowerBound, upperBound |
|
4085 |
print "Images:", \ |
|
4086 |
inputFunction(lowerBound), inputFunction(upperBound) |
|
4087 |
raise Exception("Invalid domain/image binades.") |
|
4088 |
# |
|
4089 |
## Progam initialization |
|
4090 |
### Approximation polynomial accuracy and hardness to round. |
|
4091 |
polyApproxAccur = 2^(-(targetHardnessToRound + 1)) |
|
4092 |
#polyApproxAccur = 2^(-(targetHardnessToRound + 12)) |
|
4093 |
polyTargetHardnessToRound = targetHardnessToRound + 1 |
|
4094 |
### Significand to integer conversion ratio. |
|
4095 |
toIntegerFactor = 2^(precision-1) |
|
4096 |
print "Polynomial approximation required accuracy:", polyApproxAccur.n() |
|
4097 |
### Variables and rings for polynomials and root searching. |
|
4098 |
i=var('i') |
|
4099 |
t=var('t') |
|
4100 |
inputFunctionVariable = inputFunction.variables()[0] |
|
4101 |
function = inputFunction.subs({inputFunctionVariable:i}) |
|
4102 |
# Polynomial Rings over the integers, for root finding. |
|
4103 |
Zi = ZZ[i] |
|
4104 |
Zt = ZZ[t] |
|
4105 |
Zit = ZZ[i,t] |
|
4106 |
## Number of iterations limit. |
|
4107 |
maxIter = 100000 |
|
4108 |
# |
|
4109 |
## Set the variable name in Sollya. |
|
4110 |
pobyso_name_free_variable_sa_so(str(function.variables()[0])) |
|
4111 |
## Compute the scaled function and the degree, in their Sollya version |
|
4112 |
# once for all. |
|
4113 |
#print "srsvp initial bounds:",lowerBound, upperBound |
|
4114 |
(scaledf, sdlb, sdub, silb, siub) = \ |
|
4115 |
slz_compute_scaled_function(function, lowerBound, upperBound, precision) |
|
4116 |
print "Scaled function:", scaledf._assume_str().replace('_SAGE_VAR_', '') |
|
4117 |
#print "srsvp Scaled bounds:", sdlb, sdub |
|
4118 |
scaledfSo = sollya_lib_parse_string(scaledf._assume_str().replace('_SAGE_VAR_', '')) |
|
4119 |
degreeSo = pobyso_constant_from_int_sa_so(degree) |
|
4120 |
# |
|
4121 |
## Compute the scaling. boundsIntervalRifSa defined out of the loops. |
|
4122 |
domainBoundsInterval = RRIF(lowerBound, upperBound) |
|
4123 |
(unscalingFunction, scalingFunction) = \ |
|
4124 |
slz_interval_scaling_expression(domainBoundsInterval, i) |
|
4125 |
#print scalingFunction, unscalingFunction |
|
4126 |
## Set the Sollya internal precision (with an arbitrary minimum of 192). |
|
4127 |
internalSollyaPrec = ceil((RR('1.5') * targetHardnessToRound) / 64) * 64 |
|
4128 |
if internalSollyaPrec < 192: |
|
4129 |
internalSollyaPrec = 192 |
|
4130 |
pobyso_set_prec_sa_so(internalSollyaPrec) |
|
4131 |
print "Sollya internal precision:", internalSollyaPrec |
|
4132 |
## Some variables. |
|
4133 |
### General variables |
|
4134 |
lb = sdlb |
|
4135 |
ub = sdub |
|
4136 |
nbw = 0 |
|
4137 |
intervalUlp = ub.ulp() |
|
4138 |
#### Will be set by slz_interval_and_polynomila_to_sage. |
|
4139 |
ic = 0 |
|
4140 |
icAsInt = 0 # Set from ic. |
|
4141 |
solutionsSet = set() |
|
4142 |
tsErrorWidth = [] |
|
4143 |
csErrorVectors = [] |
|
4144 |
csVectorsResultants = [] |
|
4145 |
floatP = 0 # Taylor polynomial. |
|
4146 |
floatPcv = 0 # Ditto with variable change. |
|
4147 |
intvl = "" # Taylor interval |
|
4148 |
terr = 0 # Taylor error. |
|
4149 |
iterCount = 0 |
|
4150 |
htrnSet = set() |
|
4151 |
### Timers and counters. |
|
4152 |
wallTimeStart = 0 |
|
4153 |
cpuTimeStart = 0 |
|
4154 |
taylCondFailedCount = 0 |
|
4155 |
coppCondFailedCount = 0 |
|
4156 |
resultCondFailedCount = 0 |
|
4157 |
coppCondFailed = False |
|
4158 |
resultCondFailed = False |
|
4159 |
globalResultsList = [] |
|
4160 |
basisConstructionsCount = 0 |
|
4161 |
basisConstructionsFullTime = 0 |
|
4162 |
basisConstructionTime = 0 |
|
4163 |
reductionsCount = 0 |
|
4164 |
reductionsFullTime = 0 |
|
4165 |
reductionTime = 0 |
|
4166 |
resultantsComputationsCount = 0 |
|
4167 |
resultantsComputationsFullTime = 0 |
|
4168 |
resultantsComputationTime = 0 |
|
4169 |
rootsComputationsCount = 0 |
|
4170 |
rootsComputationsFullTime = 0 |
|
4171 |
rootsComputationTime = 0 |
|
4172 |
|
|
4173 |
## Global times are started here. |
|
4174 |
wallTimeStart = walltime() |
|
4175 |
cpuTimeStart = cputime() |
|
4176 |
## Main loop. |
|
4177 |
while True: |
|
4178 |
if lb >= sdub: |
|
4179 |
print "Lower bound reached upper bound." |
|
4180 |
break |
|
4181 |
if iterCount == maxIter: |
|
4182 |
print "Reached maxIter. Aborting" |
|
4183 |
break |
|
4184 |
iterCount += 1 |
|
4185 |
print "[", lb, ",", ub, "]", ((ub - lb) / intervalUlp).log2().n(), \ |
|
4186 |
"log2(numbers)." |
|
4187 |
### Compute a Sollya polynomial that will honor the Taylor condition. |
|
4188 |
prceSo = slz_compute_polynomial_and_interval_01(scaledfSo, |
|
4189 |
degreeSo, |
|
4190 |
lb, |
|
4191 |
ub, |
|
4192 |
polyApproxAccur, |
|
4193 |
debug=debug) |
|
4194 |
if debug: |
|
4195 |
print "Approximation polynomial computed." |
|
4196 |
if prceSo is None: |
|
4197 |
raise Exception("Could not compute an approximation polynomial.") |
|
4198 |
### Convert back the data into Sage space. |
|
4199 |
(floatP, floatPcv, intvl, ic, terr) = \ |
|
4200 |
slz_interval_and_polynomial_to_sage((prceSo[0], prceSo[0], |
|
4201 |
prceSo[1], prceSo[2], |
|
4202 |
prceSo[3])) |
|
4203 |
intvl = RRIF(intvl) |
|
4204 |
## Clean-up Sollya stuff. |
|
4205 |
for elem in prceSo: |
|
4206 |
sollya_lib_clear_obj(elem) |
|
4207 |
#print floatP, floatPcv, intvl, ic, terr |
|
4208 |
#print floatP |
|
4209 |
#print intvl.endpoints()[0].n(), \ |
|
4210 |
# ic.n(), |
|
4211 |
#intvl.endpoints()[1].n() |
|
4212 |
### Check returned data. |
|
4213 |
#### Is approximation error OK? |
|
4214 |
if terr > polyApproxAccur: |
|
4215 |
exceptionErrorMess = \ |
|
4216 |
"Approximation failed - computed error:" + \ |
|
4217 |
str(terr) + " - target error: " |
|
4218 |
exceptionErrorMess += \ |
|
4219 |
str(polyApproxAccur) + ". Aborting!" |
|
4220 |
raise Exception(exceptionErrorMess) |
|
4221 |
#### Is lower bound OK? |
|
4222 |
if lb != intvl.endpoints()[0]: |
|
4223 |
exceptionErrorMess = "Wrong lower bound:" + \ |
|
4224 |
str(lb) + ". Aborting!" |
|
4225 |
raise Exception(exceptionErrorMess) |
|
4226 |
#### Set upper bound. |
|
4227 |
if ub > intvl.endpoints()[1]: |
|
4228 |
ub = intvl.endpoints()[1] |
|
4229 |
print "[", lb, ",", ub, "]", ((ub - lb) / intervalUlp).log2().n(), \ |
|
4230 |
"log2(numbers)." |
|
4231 |
taylCondFailedCount += 1 |
|
4232 |
#### Is interval not degenerate? |
|
4233 |
if lb >= ub: |
|
4234 |
exceptionErrorMess = "Degenerate interval: " + \ |
|
4235 |
"lowerBound(" + str(lb) +\ |
|
4236 |
")>= upperBound(" + str(ub) + \ |
|
4237 |
"). Aborting!" |
|
4238 |
raise Exception(exceptionErrorMess) |
|
4239 |
#### Is interval center ok? |
|
4240 |
if ic <= lb or ic >= ub: |
|
4241 |
exceptionErrorMess = "Invalid interval center for " + \ |
|
4242 |
str(lb) + ',' + str(ic) + ',' + \ |
|
4243 |
str(ub) + ". Aborting!" |
|
4244 |
raise Exception(exceptionErrorMess) |
|
4245 |
##### Current interval width and reset future interval width. |
|
4246 |
bw = ub - lb |
|
4247 |
nbw = 0 |
|
4248 |
icAsInt = int(ic * toIntegerFactor) |
|
4249 |
#### The following ratio is always >= 1. In case we may want to |
|
4250 |
# enlarge the interval |
|
4251 |
curTaylErrRat = polyApproxAccur / terr |
|
4252 |
### Make the integral transformations. |
|
4253 |
#### Bounds and interval center. |
|
4254 |
intIc = int(ic * toIntegerFactor) |
|
4255 |
intLb = int(lb * toIntegerFactor) - intIc |
|
4256 |
intUb = int(ub * toIntegerFactor) - intIc |
|
4257 |
# |
|
4258 |
#### Polynomials |
|
4259 |
basisConstructionTime = cputime() |
|
4260 |
##### To a polynomial with rational coefficients with rational arguments |
|
4261 |
ratRatP = slz_float_poly_of_float_to_rat_poly_of_rat_pow_two(floatP) |
|
4262 |
##### To a polynomial with rational coefficients with integer arguments |
|
4263 |
ratIntP = \ |
|
4264 |
slz_rat_poly_of_rat_to_rat_poly_of_int(ratRatP, precision) |
|
4265 |
##### Ultimately a multivariate polynomial with integer coefficients |
|
4266 |
# with integer arguments. |
|
4267 |
coppersmithTuple = \ |
|
4268 |
slz_rat_poly_of_int_to_poly_for_coppersmith(ratIntP, |
|
4269 |
precision, |
|
4270 |
targetHardnessToRound, |
|
4271 |
i, t) |
|
4272 |
#### Recover Coppersmith information. |
|
4273 |
intIntP = coppersmithTuple[0] |
|
4274 |
N = coppersmithTuple[1] |
|
4275 |
nAtAlpha = N^alpha |
|
4276 |
tBound = coppersmithTuple[2] |
|
4277 |
leastCommonMultiple = coppersmithTuple[3] |
|
4278 |
iBound = max(abs(intLb),abs(intUb)) |
|
4279 |
basisConstructionsFullTime += cputime(basisConstructionTime) |
|
4280 |
basisConstructionsCount += 1 |
|
4281 |
#### Compute the matrix to reduce for debug purpose. Otherwise |
|
4282 |
# slz_compute_coppersmith_reduced_polynomials does the job |
|
4283 |
# invisibly. |
|
4284 |
if debug: |
|
4285 |
matrixToReduce = slz_compute_initial_lattice_matrix(intIntP, |
|
4286 |
alpha, |
|
4287 |
N, |
|
4288 |
iBound, |
|
4289 |
tBound) |
|
4290 |
maxNorm = 0 |
|
4291 |
latticeSize = 0 |
|
4292 |
matrixFile = file('/tmp/matrixToReduce.txt', 'w') |
|
4293 |
for row in matrixToReduce.rows(): |
|
4294 |
currentNorm = row.norm() |
|
4295 |
if currentNorm > maxNorm: |
|
4296 |
maxNorm = currentNorm |
|
4297 |
latticeSize += 1 |
|
4298 |
for elem in row: |
|
4299 |
matrixFile.write(elem.str(base=2) + ",") |
|
4300 |
matrixFile.write("\n") |
|
4301 |
#matrixFile.write(matrixToReduce.str(radix="2") + "\n") |
|
4302 |
matrixFile.close() |
|
4303 |
#### We use here binary length as defined in LLL princepts. |
|
4304 |
binaryLength = latticeSize * log(maxNorm) |
|
4305 |
print "Binary length:", binaryLength.n() |
|
4306 |
#raise Exception("Deliberate stop here.") |
|
4307 |
# End if debug |
|
4308 |
reductionTime = cputime() |
|
4309 |
#### Compute the reduced polynomials. |
|
4310 |
print "Starting reduction..." |
|
4311 |
ccReducedPolynomialsList = \ |
|
4312 |
slz_compute_weak_coppersmith_reduced_polynomials_proj(intIntP, |
|
4313 |
alpha, |
|
4314 |
N, |
|
4315 |
iBound, |
|
4316 |
tBound) |
|
4317 |
print "...reduction accomplished in", cputime(reductionTime), "s." |
|
4318 |
if ccReducedPolynomialsList is None: |
|
4319 |
raise Exception("Reduction failed.") |
|
4320 |
reductionsFullTime += cputime(reductionTime) |
|
4321 |
reductionsCount += 1 |
|
4322 |
if len(ccReducedPolynomialsList) < 2: |
|
4323 |
print "Nothing to form resultants with." |
|
4324 |
|
|
4325 |
coppCondFailedCount += 1 |
|
4326 |
coppCondFailed = True |
|
4327 |
##### Apply a different shrink factor according to |
|
4328 |
# the number of compliant polynomials. |
|
4329 |
if len(ccReducedPolynomialsList) == 0: |
|
4330 |
ub = lb + bw * noCoppersmithIntervalShrink |
|
4331 |
else: # At least one compliant polynomial. |
|
4332 |
ub = lb + bw * oneCoppersmithIntervalShrink |
|
4333 |
if ub > sdub: |
|
4334 |
ub = sdub |
|
4335 |
if lb == ub: |
|
4336 |
raise Exception("Cant shrink interval \ |
|
4337 |
anymore to get Coppersmith condition.") |
|
4338 |
nbw = 0 |
|
4339 |
continue |
|
4340 |
#### We have at least two polynomials. |
|
4341 |
# Let us try to compute resultants. |
|
4342 |
# For each resultant computed, go for the solutions. |
|
4343 |
##### Build the pairs list. |
|
4344 |
polyPairsList = [] |
|
4345 |
for polyOuterIndex in xrange(0, len(ccReducedPolynomialsList) - 1): |
|
4346 |
for polyInnerIndex in xrange(polyOuterIndex+1, |
|
4347 |
len(ccReducedPolynomialsList)): |
|
4348 |
polyPairsList.append((ccReducedPolynomialsList[polyOuterIndex], |
|
4349 |
ccReducedPolynomialsList[polyInnerIndex])) |
|
4350 |
#### Actual root search. |
|
4351 |
iRootsSet = set() |
|
4352 |
hasNonNullResultant = False |
|
4353 |
for polyPair in polyPairsList: |
|
4354 |
resultantsComputationTime = cputime() |
|
4355 |
currentResultantI = \ |
|
4356 |
slz_resultant(polyPair[0], |
|
4357 |
polyPair[1], |
|
4358 |
t) |
|
4359 |
resultantsComputationsCount += 1 |
|
4360 |
resultantsComputationsFullTime += \ |
|
4361 |
cputime(resultantsComputationTime) |
|
4362 |
#### Function slz_resultant returns None both for None and O |
|
4363 |
# resultants. |
|
4364 |
if currentResultantI is None: |
|
4365 |
print "Nul resultant" |
|
4366 |
continue # Next polyPair. |
|
4367 |
## We deleted the currentResultantI computation. |
|
4368 |
#### We have a non null resultant. From now on, whatever this |
|
4369 |
# root search yields, no extra root search is necessary. |
|
4370 |
hasNonNullResultant = True |
|
4371 |
#### A constant resultant leads to no root. Root search is done. |
|
4372 |
if currentResultantI.degree() < 1: |
|
4373 |
print "Resultant is constant:", currentResultantI |
|
4374 |
break # There is no root. |
|
4375 |
#### Actual iroots computation. |
|
4376 |
rootsComputationTime = cputime() |
|
4377 |
iRootsList = Zi(currentResultantI).roots() |
|
4378 |
rootsComputationsCount += 1 |
|
4379 |
rootsComputationsFullTime = cputime(rootsComputationTime) |
|
4380 |
if len(iRootsList) == 0: |
|
4381 |
print "No roots in \"i\"." |
|
4382 |
#break # No roots in i. |
|
4383 |
else: |
|
4384 |
for iRoot in iRootsList: |
|
4385 |
# A root is given as a (value, multiplicity) tuple. |
|
4386 |
iRootsSet.add(iRoot[0]) |
|
4387 |
print "Root added." |
|
4388 |
#### A non null, non constant resultant has been tested |
|
4389 |
# for. There is no need to check for another one. Break |
|
4390 |
# whether roots are found or not. |
|
4391 |
break |
|
4392 |
# End loop for polyPair in polyParsList. We only loop again if a |
|
4393 |
# None or zero resultant is found. |
|
4394 |
#### Prepare for results for the current interval.. |
|
4395 |
intervalResultsList = [] |
|
4396 |
intervalResultsList.append((lb, ub)) |
|
4397 |
#### Check roots. |
|
4398 |
rootsResultsList = [] |
|
4399 |
for iRoot in iRootsSet: |
|
4400 |
specificRootResultsList = [] |
|
4401 |
failingBounds = [] |
|
4402 |
# Root qualifies for modular equation, test it for hardness to round. |
|
4403 |
hardToRoundCaseAsFloat = RRR((icAsInt + iRoot) / toIntegerFactor) |
|
4404 |
#print "Before unscaling:", hardToRoundCaseAsFloat.n(prec=precision) |
|
4405 |
#print scalingFunction |
|
4406 |
scaledHardToRoundCaseAsFloat = \ |
|
4407 |
scalingFunction(hardToRoundCaseAsFloat) |
|
4408 |
print "Candidate HTRNc at x =", \ |
|
4409 |
scaledHardToRoundCaseAsFloat.n().str(base=2), |
|
4410 |
if slz_is_htrn(scaledHardToRoundCaseAsFloat, |
|
4411 |
function, |
|
4412 |
2^-(targetHardnessToRound), |
|
4413 |
RRR): |
|
4414 |
print hardToRoundCaseAsFloat, "is HTRN case." |
|
4415 |
specificRootResultsList.append(hardToRoundCaseAsFloat.n().str(base=2)) |
|
4416 |
if lb <= hardToRoundCaseAsFloat and hardToRoundCaseAsFloat <= ub: |
|
4417 |
print "Found in interval." |
|
4418 |
else: |
|
4419 |
print "Found out of interval." |
|
4420 |
# Check the i root is within the i bound. |
|
4421 |
if abs(iRoot) > iBound: |
|
4422 |
print "IRoot", iRoot, "is out of bounds for modular equation." |
|
4423 |
print "i bound:", iBound |
|
4424 |
failingBounds.append('i') |
|
4425 |
failingBounds.append(iRoot) |
|
4426 |
failingBounds.append(iBound) |
|
4427 |
if len(failingBounds) > 0: |
|
4428 |
specificRootResultsList.append(failingBounds) |
|
4429 |
else: # From slz_is_htrn... |
|
4430 |
print "is not an HTRN case." |
|
4431 |
if len(specificRootResultsList) > 0: |
|
4432 |
rootsResultsList.append(specificRootResultsList) |
|
4433 |
if len(rootsResultsList) > 0: |
|
4434 |
intervalResultsList.append(rootsResultsList) |
|
4435 |
### Check if a non null resultant was found. If not shrink the interval. |
|
4436 |
if not hasNonNullResultant: |
|
4437 |
print "Only null resultants for this reduction, shrinking interval." |
|
4438 |
resultCondFailed = True |
|
4439 |
resultCondFailedCount += 1 |
|
4440 |
### Shrink interval for next iteration. |
|
4441 |
ub = lb + bw * onlyNullResultantsShrink |
|
4442 |
if ub > sdub: |
|
4443 |
ub = sdub |
|
4444 |
nbw = 0 |
|
4445 |
continue |
|
4446 |
#### An intervalResultsList has at least the bounds. |
|
4447 |
globalResultsList.append(intervalResultsList) |
|
4448 |
#### Compute an incremented width for next upper bound, only |
|
4449 |
# if not Coppersmith condition nor resultant condition |
|
4450 |
# failed at the previous run. |
|
4451 |
if not coppCondFailed and not resultCondFailed: |
|
4452 |
nbw = noErrorIntervalStretch * bw |
|
4453 |
else: |
|
4454 |
nbw = bw |
|
4455 |
##### Reset the failure flags. They will be raised |
|
4456 |
# again if needed. |
|
4457 |
coppCondFailed = False |
|
4458 |
resultCondFailed = False |
|
4459 |
#### For next iteration (at end of loop) |
|
4460 |
#print "nbw:", nbw |
|
4461 |
lb = ub |
|
4462 |
ub += nbw |
|
4463 |
if ub > sdub: |
|
4464 |
ub = sdub |
|
4465 |
|
|
4466 |
# End while True |
|
4467 |
## Main loop just ended. |
|
4468 |
globalWallTime = walltime(wallTimeStart) |
|
4469 |
globalCpuTime = cputime(cpuTimeStart) |
|
4470 |
## Output results |
|
4471 |
print ; print "Intervals and HTRNs" ; print |
|
4472 |
for intervalResultsList in globalResultsList: |
|
4473 |
intervalResultString = "[" + str(intervalResultsList[0][0]) +\ |
|
4474 |
"," + str(intervalResultsList[0][1]) + "]" |
|
4475 |
print intervalResultString, |
|
4476 |
if len(intervalResultsList) > 1: |
|
4477 |
rootsResultsList = intervalResultsList[1] |
|
4478 |
specificRootResultIndex = 0 |
|
4479 |
for specificRootResultsList in rootsResultsList: |
|
4480 |
if specificRootResultIndex == 0: |
|
4481 |
print "\t", specificRootResultsList[0], |
|
4482 |
else: |
|
4483 |
print " " * len(intervalResultString), "\t", \ |
|
4484 |
specificRootResultsList[0], |
|
4485 |
if len(specificRootResultsList) > 1: |
|
4486 |
print specificRootResultsList[1] |
|
4487 |
specificRootResultIndex += 1 |
|
4488 |
print ; print |
|
4489 |
#print globalResultsList |
|
4490 |
# |
|
4491 |
print "Timers and counters" |
|
4492 |
|
|
4493 |
print "Number of iterations:", iterCount |
|
4494 |
print "Taylor condition failures:", taylCondFailedCount |
|
4495 |
print "Coppersmith condition failures:", coppCondFailedCount |
|
4496 |
print "Resultant condition failures:", resultCondFailedCount |
|
4497 |
print "Iterations count: ", iterCount |
|
4498 |
print "Number of intervals:", len(globalResultsList) |
|
4499 |
print "Number of basis constructions:", basisConstructionsCount |
|
4500 |
print "Total CPU time spent in basis constructions:", \ |
|
4501 |
basisConstructionsFullTime |
|
4502 |
if basisConstructionsCount != 0: |
|
4503 |
print "Average basis construction CPU time:", \ |
|
4504 |
basisConstructionsFullTime/basisConstructionsCount |
|
4505 |
print "Number of reductions:", reductionsCount |
|
4506 |
print "Total CPU time spent in reductions:", reductionsFullTime |
|
4507 |
if reductionsCount != 0: |
|
4508 |
print "Average reduction CPU time:", \ |
|
4509 |
reductionsFullTime/reductionsCount |
|
4510 |
print "Number of resultants computation rounds:", \ |
|
4511 |
resultantsComputationsCount |
|
4512 |
print "Total CPU time spent in resultants computation rounds:", \ |
|
4513 |
resultantsComputationsFullTime |
|
4514 |
if resultantsComputationsCount != 0: |
|
4515 |
print "Average resultants computation round CPU time:", \ |
|
4516 |
resultantsComputationsFullTime/resultantsComputationsCount |
|
4517 |
print "Number of root finding rounds:", rootsComputationsCount |
|
4518 |
print "Total CPU time spent in roots finding rounds:", \ |
|
4519 |
rootsComputationsFullTime |
|
4520 |
if rootsComputationsCount != 0: |
|
4521 |
print "Average roots finding round CPU time:", \ |
|
4522 |
rootsComputationsFullTime/rootsComputationsCount |
|
4523 |
print "Global Wall time:", globalWallTime |
|
4524 |
print "Global CPU time:", globalCpuTime |
|
4525 |
## Output counters |
|
4526 |
# End srs_runSLZ-v05_proj |
|
4527 |
# |
|
3995 | 4528 |
def srs_run_SLZ_v06(inputFunction, |
3996 | 4529 |
inputLowerBound, |
3997 | 4530 |
inputUpperBound, |
Formats disponibles : Unified diff