Révision 179 pobysoPythonSage/src/sageSLZ/sageSLZ.sage
sageSLZ.sage (revision 179) | ||
---|---|---|
162 | 162 |
""" |
163 | 163 |
# Arguments check. |
164 | 164 |
if iBound == 0 or tBound == 0: |
165 |
return ()
|
|
165 |
return None
|
|
166 | 166 |
# End arguments check. |
167 | 167 |
nAtAlpha = N^alpha |
168 | 168 |
## Building polynomials for matrix. |
... | ... | |
174 | 174 |
initialPolynomial = inputPolynomial.subs({iVariable:iVariable * iBound, |
175 | 175 |
tVariable:tVariable * tBound}) |
176 | 176 |
polynomialsList = \ |
177 |
spo_polynomial_to_polynomials_list_5(initialPolynomial,
|
|
177 |
spo_polynomial_to_polynomials_list_8(initialPolynomial,
|
|
178 | 178 |
alpha, |
179 | 179 |
N, |
180 | 180 |
iBound, |
... | ... | |
198 | 198 |
reducedMatrix = matrixToReduce.LLL(fp=None) |
199 | 199 |
isLLLReduced = reducedMatrix.is_LLL_reduced() |
200 | 200 |
if not isLLLReduced: |
201 |
return ()
|
|
201 |
return None
|
|
202 | 202 |
monomialsCount = len(knownMonomials) |
203 | 203 |
monomialsCountSqrt = sqrt(monomialsCount) |
204 | 204 |
#print "Monomials count:", monomialsCount, monomialsCountSqrt.n() |
... | ... | |
226 | 226 |
if len(ccReducedPolynomialsList) < 2: |
227 | 227 |
print "Less than 2 Coppersmith condition compliant vectors." |
228 | 228 |
return () |
229 |
|
|
230 | 229 |
#print ccReducedPolynomialsList |
231 | 230 |
return ccReducedPolynomialsList |
232 | 231 |
# End slz_compute_coppersmith_reduced_polynomials |
... | ... | |
731 | 730 |
fff(scaledLowerBoundSa), fff(scaledUpperBoundSa)]) |
732 | 731 |
# End slz_compute_scaled_function |
733 | 732 |
|
733 |
def slz_fix_bounds_for_binades(lowerBound, |
|
734 |
upperBound, |
|
735 |
func=None, |
|
736 |
domainDirection = -1, |
|
737 |
imageDirection = -1): |
|
738 |
""" |
|
739 |
Assuming the function is increasing or decreasing over the |
|
740 |
[lowerBound, upperBound] interval, return a lower bound lb and |
|
741 |
an upper bound ub such that: |
|
742 |
- lb and ub belong to the same binade; |
|
743 |
- func(lb) and func(ub) belong to the same binade. |
|
744 |
domainDirection indicate how bounds move to fit into the same binade: |
|
745 |
- a negative value move the upper bound down; |
|
746 |
- a positive value move the lower bound up. |
|
747 |
imageDirection indicate how bounds move in order to have their image |
|
748 |
fit into the same binade, variation of the function is also condidered. |
|
749 |
For an increasing function: |
|
750 |
- negative value moves the upper bound down (and its image value as well); |
|
751 |
- a positive values moves the lower bound up (and its image value as well); |
|
752 |
For a decreasing function it is the other way round. |
|
753 |
""" |
|
754 |
## Arguments check |
|
755 |
if lowerBound > upperBound: |
|
756 |
return None |
|
757 |
if func is None: |
|
758 |
return None |
|
759 |
# |
|
760 |
#varFunc = func.variables()[0] |
|
761 |
lb = lowerBound |
|
762 |
ub = upperBound |
|
763 |
lbBinade = slz_compute_binade(lb) |
|
764 |
ubBinade = slz_compute_binade(ub) |
|
765 |
## Domain binade. |
|
766 |
while lbBinade != ubBinade: |
|
767 |
newIntervalWidth = (ub - lb) / 2 |
|
768 |
if domainDirection < 0: |
|
769 |
ub = lb + newIntervalWidth |
|
770 |
ubBinade = slz_compute_binade(ub) |
|
771 |
else: |
|
772 |
lb = lb + newIntervalWidth |
|
773 |
lbBinade = slz_compute_binade(lb) |
|
774 |
## Image binade. |
|
775 |
if lb == ub: |
|
776 |
return (lb, ub) |
|
777 |
lbImg = func(lb) |
|
778 |
ubImg = func(ub) |
|
779 |
funcIsInc = (ubImg >= lbImg) |
|
780 |
lbImgBinade = slz_compute_binade(lbImg) |
|
781 |
ubImgBinade = slz_compute_binade(ubImg) |
|
782 |
while lbImgBinade != ubImgBinade: |
|
783 |
newIntervalWidth = (ub - lb) / 2 |
|
784 |
if imageDirection < 0: |
|
785 |
if funcIsInc: |
|
786 |
ub = lb + newIntervalWidth |
|
787 |
ubImgBinade = slz_compute_binade(func(ub)) |
|
788 |
#print ubImgBinade |
|
789 |
else: |
|
790 |
lb = lb + newIntervalWidth |
|
791 |
lbImgBinade = slz_compute_binade(func(lb)) |
|
792 |
#print lbImgBinade |
|
793 |
else: |
|
794 |
if funcIsInc: |
|
795 |
lb = lb + newIntervalWidth |
|
796 |
lbImgBinade = slz_compute_binade(func(lb)) |
|
797 |
#print lbImgBinade |
|
798 |
else: |
|
799 |
ub = lb + newIntervalWidth |
|
800 |
ubImgBinade = slz_compute_binade(func(ub)) |
|
801 |
#print ubImgBinade |
|
802 |
# End while lbImgBinade != ubImgBinade: |
|
803 |
return (lb, ub) |
|
804 |
# End slz_fix_bounds_for_binades. |
|
805 |
|
|
734 | 806 |
def slz_float_poly_of_float_to_rat_poly_of_rat(polyOfFloat): |
735 | 807 |
# Create a polynomial over the rationals. |
736 |
polynomialRing = QQ[str(polyOfFloat.variables()[0])]
|
|
737 |
return(polynomialRing(polyOfFloat))
|
|
808 |
ratPolynomialRing = QQ[str(polyOfFloat.variables()[0])]
|
|
809 |
return(ratPolynomialRing(polyOfFloat))
|
|
738 | 810 |
# End slz_float_poly_of_float_to_rat_poly_of_rat. |
739 | 811 |
|
740 | 812 |
def slz_get_intervals_and_polynomials(functionSa, degreeSa, |
... | ... | |
899 | 971 |
scalingCoeff = 2^(-binade) |
900 | 972 |
invScalingCoeff = 2^(binade) |
901 | 973 |
scalingOffset = 1 |
902 |
return((scalingCoeff * expVar + scalingOffset),\ |
|
903 |
((expVar - scalingOffset) * invScalingCoeff)) |
|
974 |
return \ |
|
975 |
((scalingCoeff * expVar + scalingOffset).function(expVar), |
|
976 |
((expVar - scalingOffset) * invScalingCoeff).function(expVar)) |
|
904 | 977 |
else: |
905 | 978 |
scalingCoeff = 2^(-binade-1) |
906 | 979 |
invScalingCoeff = 2^(binade+1) |
... | ... | |
954 | 1027 |
return None |
955 | 1028 |
#print "Lower bound binade:", binade |
956 | 1029 |
if boundsInterval.endpoints()[0] > 0: |
957 |
return((2^(-lbBinade) * expVar),(2^(lbBinade) * expVar)) |
|
1030 |
return \ |
|
1031 |
((2^(-lbBinade) * expVar).function(expVar), |
|
1032 |
(2^(lbBinade) * expVar).function(expVar)) |
|
958 | 1033 |
else: |
959 |
return((-(2^(-ubBinade)) * expVar),(-(2^(ubBinade)) * expVar)) |
|
1034 |
return \ |
|
1035 |
((-(2^(-ubBinade)) * expVar).function(expVar), |
|
1036 |
(-(2^(ubBinade)) * expVar).function(expVar)) |
|
960 | 1037 |
""" |
961 | 1038 |
# Code sent to attic. Should be the base for a |
962 | 1039 |
# "slz_interval_translate_expression" rather than scale. |
... | ... | |
1185 | 1262 |
# Coefficients are issued in the increasing power order. |
1186 | 1263 |
ratPolyCoefficients = ratPolyOfInt.coefficients() |
1187 | 1264 |
# Print the reversed list for debugging. |
1188 |
|
|
1189 |
print "Rational polynomial coefficients:", ratPolyCoefficients[::-1] |
|
1265 |
#print
|
|
1266 |
#print "Rational polynomial coefficients:", ratPolyCoefficients[::-1]
|
|
1190 | 1267 |
# Build the list of number we compute the lcm of. |
1191 | 1268 |
coefficientDenominators = sro_denominators(ratPolyCoefficients) |
1192 |
print "Coefficient denominators:", coefficientDenominators |
|
1269 |
#print "Coefficient denominators:", coefficientDenominators
|
|
1193 | 1270 |
coefficientDenominators.append(2^precision) |
1194 | 1271 |
coefficientDenominators.append(2^(targetHardnessToRound)) |
1195 | 1272 |
leastCommonMultiple = lcm(coefficientDenominators) |
... | ... | |
1266 | 1343 |
# End slz_reduce_and_test_base |
1267 | 1344 |
|
1268 | 1345 |
def slz_resultant_tuple(poly1, poly2, elimVar): |
1346 |
""" |
|
1347 |
Compute the resultant for two polynomials for a given variable |
|
1348 |
and return the (poly1, poly2, resultant) if the resultant |
|
1349 |
is not 0 or 1. |
|
1350 |
Return () otherwise. |
|
1351 |
""" |
|
1269 | 1352 |
polynomialRing0 = poly1.parent() |
1270 | 1353 |
resultantInElimVar = poly1.resultant(poly2,polynomialRing0(elimVar)) |
1271 |
if resultantInElimVar.is_zero(): |
|
1354 |
if resultantInElimVar.is_zero() or resultantInElimVar == 1:
|
|
1272 | 1355 |
return () |
1273 | 1356 |
else: |
1274 | 1357 |
return (poly1, poly2, resultantInElimVar) |
Formats disponibles : Unified diff