Révision 83
| pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage (revision 83) | ||
|---|---|---|
| 1 | 1 |
load "/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageMatrixOperations.sage" |
| 2 | 2 |
|
| 3 |
def spo_add_polynomial_coeffs_to_matrix(pMonomials, |
|
| 4 |
pCoefficients, |
|
| 5 |
knownMonomials, |
|
| 6 |
protoMatrixRows, |
|
| 7 |
columnsWidth=0): |
|
| 3 |
def spo_add_polynomial_coeffs_to_matrix_row(pMonomials,
|
|
| 4 |
pCoefficients,
|
|
| 5 |
knownMonomials,
|
|
| 6 |
protoMatrixRows,
|
|
| 7 |
columnsWidth=0):
|
|
| 8 | 8 |
""" |
| 9 | 9 |
For a given polynomial (under the form of monomials and coefficents lists), |
| 10 | 10 |
add the coefficients of the protoMatrix (a list of proto matrix rows). |
| 11 | 11 |
Coefficients are added to the protoMatrix row in the order imposed by the |
| 12 | 12 |
monomials discovery list (the knownMonomials list) built as construction |
| 13 | 13 |
goes on. |
| 14 |
As a bonus data can be printed out for a visual check. |
|
| 14 |
As a bonus, data can be printed out for a visual check.
|
|
| 15 | 15 |
pMonomials : the list of the monomials coming form some polynomial; |
| 16 | 16 |
pCoefficients : the list of the corresponding coefficients to add to |
| 17 | 17 |
the protoMatrix in the exact same order as the monomials; |
| ... | ... | |
| 82 | 82 |
protoMatrixRows.append(protoMatrixRowCoefficients) |
| 83 | 83 |
if columnsWidth != 0: |
| 84 | 84 |
|
| 85 |
# End spo_add_polynomial_coeffs_to_matrix |
|
| 85 |
# End spo_add_polynomial_coeffs_to_matrix_row
|
|
| 86 | 86 |
|
| 87 | 87 |
def spo_expression_as_string(powI, powT, powP, alpha): |
| 88 | 88 |
""" |
| ... | ... | |
| 123 | 123 |
return pow(norm, 1/degree) |
| 124 | 124 |
# end spo_norm |
| 125 | 125 |
|
| 126 |
def spo_polynomial_to_matrix(p, pRing, alpha, N, columnsWidth=0): |
|
| 126 |
def spo_polynomial_to_proto_matrix(p, pRing, alpha, N, columnsWidth=0):
|
|
| 127 | 127 |
""" |
| 128 |
From a (bivariate) polynomial and some other parameters build a matrix |
|
| 129 |
to be reduced by fpLLL. |
|
| 128 |
From a (bivariate) polynomial and some other parameters build a proto |
|
| 129 |
matrix (an array of rows) to be converted into a "true" matrix and |
|
| 130 |
eventually by reduced by fpLLL. |
|
| 130 | 131 |
The matrix is such as those found in Boneh-Durphee and Stehl?. |
| 131 | 132 |
|
| 133 |
Parameters |
|
| 134 |
---------- |
|
| 132 | 135 |
p: the (bivariate) polynomial |
| 136 |
pRing: |
|
| 133 | 137 |
alpha: |
| 134 | 138 |
N: |
| 135 |
|
|
| 139 |
columsWidth: if == 0, no information is displayed, otherwise data is |
|
| 140 |
printed in colums of columnsWitdth width. |
|
| 136 | 141 |
""" |
| 137 | 142 |
knownMonomials = [] |
| 138 | 143 |
protoMatrixRows = [] |
| ... | ... | |
| 172 | 177 |
polynomialAtPower |
| 173 | 178 |
pMonomials = currentPolynomial.monomials() |
| 174 | 179 |
pCoefficients = currentPolynomial.coefficients() |
| 175 |
spo_add_polynomial_coeffs_to_matrix(pMonomials, |
|
| 176 |
pCoefficients, |
|
| 177 |
knownMonomials, |
|
| 178 |
protoMatrixRows, |
|
| 179 |
columnsWidth) |
|
| 180 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials,
|
|
| 181 |
pCoefficients,
|
|
| 182 |
knownMonomials,
|
|
| 183 |
protoMatrixRows,
|
|
| 184 |
columnsWidth)
|
|
| 180 | 185 |
# End tPower. |
| 181 | 186 |
# End for iPower. |
| 182 | 187 |
else: # pPower > 0: (p^1..p^alpha) |
| ... | ... | |
| 190 | 195 |
currentPolynomial = polynomialAtPower * nAtPower |
| 191 | 196 |
pMonomials = currentPolynomial.monomials() |
| 192 | 197 |
pCoefficients = currentPolynomial.coefficients() |
| 193 |
spo_add_polynomial_coeffs_to_matrix(pMonomials, |
|
| 194 |
pCoefficients, |
|
| 195 |
knownMonomials, |
|
| 196 |
protoMatrixRows, |
|
| 197 |
columnsWidth) |
|
| 198 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials,
|
|
| 199 |
pCoefficients,
|
|
| 200 |
knownMonomials,
|
|
| 201 |
protoMatrixRows,
|
|
| 202 |
columnsWidth)
|
|
| 198 | 203 |
|
| 199 | 204 |
# The i^iPower * p^pPower polynomials: they add i^k monomials to |
| 200 | 205 |
# p^pPower up to k < pIdegree * pPower. This only introduces i^k |
| ... | ... | |
| 209 | 214 |
currentPolynomial = P(currentExpression) * polynomialAtPower |
| 210 | 215 |
pMonomials = currentPolynomial.monomials() |
| 211 | 216 |
pCoefficients = currentPolynomial.coefficients() |
| 212 |
spo_add_polynomial_coeffs_to_matrix(pMonomials, |
|
| 213 |
pCoefficients, |
|
| 214 |
knownMonomials, |
|
| 215 |
protoMatrixRows, |
|
| 216 |
columnsWidth) |
|
| 217 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials,
|
|
| 218 |
pCoefficients,
|
|
| 219 |
knownMonomials,
|
|
| 220 |
protoMatrixRows,
|
|
| 221 |
columnsWidth)
|
|
| 217 | 222 |
# End for iPower |
| 218 | 223 |
# We want now to introduce a t * p^pPower polynomial. But before |
| 219 | 224 |
# that we must introduce some mixed monomials. |
| ... | ... | |
| 230 | 235 |
currentPolynomial = P(currentExpression) |
| 231 | 236 |
pMonomials = currentPolynomial.monomials() |
| 232 | 237 |
pCoefficients = currentPolynomial.coefficients() |
| 233 |
spo_add_polynomial_coeffs_to_matrix(pMonomials, |
|
| 234 |
pCoefficients, |
|
| 235 |
knownMonomials, |
|
| 236 |
protoMatrixRows, |
|
| 237 |
columnsWidth) |
|
| 238 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials,
|
|
| 239 |
pCoefficients,
|
|
| 240 |
knownMonomials,
|
|
| 241 |
protoMatrixRows,
|
|
| 242 |
columnsWidth)
|
|
| 238 | 243 |
# End for iPower |
| 239 | 244 |
# |
| 240 | 245 |
# This is the mixed monomials main loop. It introduces: |
| ... | ... | |
| 262 | 267 |
currentPolynomial = P(currentExpression) |
| 263 | 268 |
pMonomials = currentPolynomial.monomials() |
| 264 | 269 |
pCoefficients = currentPolynomial.coefficients() |
| 265 |
spo_add_polynomial_coeffs_to_matrix(pMonomials, |
|
| 266 |
pCoefficients, |
|
| 267 |
knownMonomials, |
|
| 268 |
protoMatrixRows, |
|
| 269 |
columnsWidth) |
|
| 270 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials,
|
|
| 271 |
pCoefficients,
|
|
| 272 |
knownMonomials,
|
|
| 273 |
protoMatrixRows,
|
|
| 274 |
columnsWidth)
|
|
| 270 | 275 |
#print "+++++" |
| 271 | 276 |
# At iShift == 0, the following innerTpower loop adds |
| 272 | 277 |
# duplicate monomials, since no extra i^l * t^k is needed |
| ... | ... | |
| 293 | 298 |
currentPolynomial = P(currentExpression) |
| 294 | 299 |
pMonomials = currentPolynomial.monomials() |
| 295 | 300 |
pCoefficients = currentPolynomial.coefficients() |
| 296 |
spo_add_polynomial_coeffs_to_matrix(pMonomials, |
|
| 301 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials,
|
|
| 297 | 302 |
pCoefficients, |
| 298 | 303 |
knownMonomials, |
| 299 | 304 |
protoMatrixRows, |
| ... | ... | |
| 319 | 324 |
currentPolynomial = P(currentExpression) * polynomialAtPower |
| 320 | 325 |
pMonomials = currentPolynomial.monomials() |
| 321 | 326 |
pCoefficients = currentPolynomial.coefficients() |
| 322 |
spo_add_polynomial_coeffs_to_matrix(pMonomials, |
|
| 323 |
pCoefficients, |
|
| 324 |
knownMonomials, |
|
| 325 |
protoMatrixRows, |
|
| 326 |
columnsWidth) |
|
| 327 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials,
|
|
| 328 |
pCoefficients,
|
|
| 329 |
knownMonomials,
|
|
| 330 |
protoMatrixRows,
|
|
| 331 |
columnsWidth)
|
|
| 327 | 332 |
# End for outerTpower |
| 328 | 333 |
#print "++++++++++" |
| 329 | 334 |
# End for iShift |
| ... | ... | |
| 331 | 336 |
nAtPower /= N |
| 332 | 337 |
# End for pPower loop |
| 333 | 338 |
return protoMatrixRows |
| 334 |
# End spo_polynomial_to_matrix |
|
| 339 |
# End spo_polynomial_to_proto_matrix
|
|
| 335 | 340 |
|
| 341 |
def spo_proto_to_column_matrix(protoMatrixRows): |
|
| 342 |
""" |
|
| 343 |
Create a row (each column holds the coefficients of one polynomial) matrix. |
|
| 344 |
protoMatrixRows. |
|
| 345 |
|
|
| 346 |
Parameters |
|
| 347 |
---------- |
|
| 348 |
protoMatrixRows: a list of coefficient lists. |
|
| 349 |
""" |
|
| 350 |
numRows = len(protoMatrixRows) |
|
| 351 |
if numRows == 0: |
|
| 352 |
return None |
|
| 353 |
numColumns = len(protoMatrixRows[numRows-1]) |
|
| 354 |
if numColumns == 0: |
|
| 355 |
return None |
|
| 356 |
baseMatrix = matrix(ZZ, numRows, numColumns) |
|
| 357 |
for rowIndex in xrange(0, numRows): |
|
| 358 |
if monomialLengthChars != 0: |
|
| 359 |
print protoMatrixRows[rowIndex] |
|
| 360 |
for colIndex in xrange(0, len(protoMatrixRows[rowIndex])): |
|
| 361 |
baseMatrix[colIndex, rowIndex] = protoMatrixRows[rowIndex][colIndex] |
|
| 362 |
return baseMatrix |
|
| 363 |
# End spo_proto_to_column_matrix. |
|
| 364 |
# |
|
| 365 |
def spo_proto_to_row_matrix(protoMatrixRows): |
|
| 366 |
""" |
|
| 367 |
Create a row (each row holds the coefficients of one polynomial) matrix. |
|
| 368 |
protoMatrixRows. |
|
| 369 |
|
|
| 370 |
Parameters |
|
| 371 |
---------- |
|
| 372 |
protoMatrixRows: a list of coefficient lists. |
|
| 373 |
""" |
|
| 374 |
numRows = len(protoMatrixRows) |
|
| 375 |
if numRows == 0: |
|
| 376 |
return None |
|
| 377 |
numColumns = len(protoMatrixRows[numRows-1]) |
|
| 378 |
if numColumns == 0: |
|
| 379 |
return None |
|
| 380 |
baseMatrix = matrix(ZZ, numRows, numColumns) |
|
| 381 |
for rowIndex in xrange(0, numRows): |
|
| 382 |
if monomialLengthChars != 0: |
|
| 383 |
print protoMatrixRows[rowIndex] |
|
| 384 |
for colIndex in xrange(0, len(protoMatrixRows[rowIndex])): |
|
| 385 |
baseMatrix[rowIndex, colIndex] = protoMatrixRows[rowIndex][colIndex] |
|
| 386 |
return baseMatrix |
|
| 387 |
# End spo_proto_to_row_matrix. |
|
| 388 |
# |
|
| 336 | 389 |
print "sagePolynomialOperations loaded..." |
| pobysoPythonSage/src/sageSLZ/sageMatrixOperations.sage (revision 83) | ||
|---|---|---|
| 45 | 45 |
return True |
| 46 | 46 |
# End smo_is_lower_triangular_matrix |
| 47 | 47 |
|
| 48 |
def smo_is_upper_triangular_matrix(mat): |
|
| 49 |
""" |
|
| 50 |
Check that the matrix is upper triangular. |
|
| 51 |
""" |
|
| 52 |
dimensions = mat.dimensions() |
|
| 53 |
# Must be a bidimensional matrix. |
|
| 54 |
if len(dimensions) != 2: |
|
| 55 |
return False |
|
| 56 |
# Must be square. |
|
| 57 |
if dimensions[0] != dimensions[1]: |
|
| 58 |
return False |
|
| 59 |
# A 1x1 matrix is lower triangular. |
|
| 60 |
if dimensions[0] == 1: |
|
| 61 |
return True |
|
| 62 |
for rowIndex in xrange(1, dimensions[0]): |
|
| 63 |
for colIndex in xrange(0, rowIndex): |
|
| 64 |
if mat[rowIndex, colIndex] != 0: |
|
| 65 |
print mat.rows()[rowIndex] |
|
| 66 |
return False |
|
| 67 |
return True |
|
| 68 |
# End smo_is_upper_triangular_matrix |
|
| 69 |
|
|
| 70 |
print "sageMatrixOperations loaded..." |
|
| pobysoPythonSage/src/sageSLZ/sageSLZ.sage (revision 83) | ||
|---|---|---|
| 264 | 264 |
1/scalingCoeff * expVar + 3)) |
| 265 | 265 |
|
| 266 | 266 |
|
| 267 |
def slz_polynomial_and_interval_to_sage(polyRangeCenterErrorSo):
|
|
| 267 |
def slz_interval_and_polynomial_to_sage(polyRangeCenterErrorSo):
|
|
| 268 | 268 |
""" |
| 269 | 269 |
Compute the Sage version of the Taylor polynomial and it's |
| 270 | 270 |
companion data (interval, center...) |
| ... | ... | |
| 289 | 289 |
errorSa = \ |
| 290 | 290 |
pobyso_get_constant_as_rn_with_rf_so_sa(polyRangeCenterErrorSo[4]) |
| 291 | 291 |
return((polynomialSa, polynomialChangedVarSa, intervalSa, centerSa, errorSa)) |
| 292 |
# End slz_polynomial_and_interval_to_sage
|
|
| 292 |
# End slz_interval_and_polynomial_to_sage
|
|
| 293 | 293 |
|
| 294 | 294 |
def slz_rat_poly_of_int_to_poly_for_coppersmith(ratPolyOfInt, |
| 295 | 295 |
precision, |
| pobysoPythonSage/src/pobyso.py (revision 83) | ||
|---|---|---|
| 115 | 115 |
#print "rnDummy: ", rnDummy |
| 116 | 116 |
# Compare the local Sage RealNumber with rnArg. |
| 117 | 117 |
return(cmp_rn_value(rnArg, rnLocal)) |
| 118 |
# End pobyso_smp |
|
| 118 | 119 |
|
| 119 | 120 |
def pobyso_change_var_in_function_so_so(funcSo, chvarExpSo): |
| 121 |
""" |
|
| 122 |
Variable change in a function. |
|
| 123 |
""" |
|
| 120 | 124 |
return(sollya_lib_evaluate(funcSo,chvarExpSo)) |
| 121 |
|
|
| 125 |
# End pobyso_change_var_in_function_so_so |
|
| 122 | 126 |
|
| 123 | 127 |
def pobyso_chebyshevform_so_so(functionSo, degreeSo, intervalSo): |
| 124 | 128 |
resultSo = sollya_lib_chebyshevform(functionSo, degreeSo, intervalSo) |
| 125 | 129 |
return(resultSo) |
| 126 |
|
|
| 130 |
# End pobyso_chebyshevform_so_so. |
|
| 127 | 131 |
|
| 128 |
|
|
| 129 | 132 |
def pobyso_compute_pos_function_abs_val_bounds_sa_sa(funcSa, lowerBoundSa, \ |
| 130 | 133 |
upperBoundSa): |
| 131 | 134 |
""" |
| ... | ... | |
| 134 | 137 |
funcSo = pobyso_parse_string(funcSa._assume_str()) |
| 135 | 138 |
rangeSo = pobyso_range_sa_so(lowerBoundSa, upperBoundSa) |
| 136 | 139 |
infnormSo = pobyso_infnorm_so_so(funcSo,rangeSo) |
| 140 |
# Sollya return the infnorm as an interval. |
|
| 137 | 141 |
fMaxSa = pobyso_get_interval_from_range_so_sa(infnormSo) |
| 138 | 142 |
# Get the top bound and compute the binade top limit. |
| 139 | 143 |
fMaxUpperBoundSa = fMaxSa.upper() |
| ... | ... | |
| 142 | 146 |
funcAuxSo = pobyso_parse_string(str(binadeTopLimitSa) + \ |
| 143 | 147 |
'-(' + f._assume_str() + ')')
|
| 144 | 148 |
pobyso_autoprint(funcAuxSo) |
| 145 |
# Clear the Sollay range before a new call to infnorm and issue the call.
|
|
| 149 |
# Clear the Sollya range before a new call to infnorm and issue the call.
|
|
| 146 | 150 |
sollya_lib_clear_obj(infnormSo) |
| 147 | 151 |
infnormSo = pobyso_infnorm_so_so(funcAuxSo,rangeSo) |
| 148 | 152 |
fMinSa = pobyso_get_interval_from_range_so_sa(infnormSo) |
| ... | ... | |
| 154 | 158 |
# Create a RealIntervalField and create an interval with the "good" bounds. |
| 155 | 159 |
RRRI = RealIntervalField(maxPrecSa) |
| 156 | 160 |
imageIntervalSa = RRRI(fMinLowerBoundSa, fMaxUpperBoundSa) |
| 157 |
# Free the uneeded Sollya objects |
|
| 161 |
# Free the unneeded Sollya objects
|
|
| 158 | 162 |
sollya_lib_clear_obj(funcSo) |
| 159 | 163 |
sollya_lib_clear_obj(funcAuxSo) |
| 160 | 164 |
sollya_lib_clear_obj(rangeSo) |
| 161 | 165 |
return(imageIntervalSa) |
| 162 |
# End pobyso_compute_function_abs_val_bounds_sa_sa
|
|
| 166 |
# End pobyso_compute_pos_function_abs_val_bounds_sa_sa
|
|
| 163 | 167 |
|
| 164 | 168 |
def pobyso_constant(rnArg): |
| 165 | 169 |
""" Legacy function. See pobyso_constant_sa_so. """ |
| ... | ... | |
| 301 | 305 |
return(sollya_lib_get_constant(get_rn_value(rnArg), soConst)) |
| 302 | 306 |
|
| 303 | 307 |
def pobyso_get_constant_as_rn(ctExpSo): |
| 304 |
""" Legacy function. See pobyso_get_constant_as_rn_so_sa. """ |
|
| 308 |
""" |
|
| 309 |
Legacy function. See pobyso_get_constant_as_rn_so_sa. |
|
| 310 |
""" |
|
| 305 | 311 |
return(pobyso_get_constant_as_rn_so_sa(ctExpSo)) |
| 306 | 312 |
|
| 307 | 313 |
def pobyso_get_constant_as_rn_so_sa(constExpSo): |
| 314 |
""" |
|
| 315 |
Get a Sollya constant as a Sage "real number". |
|
| 316 |
The precision of the floating-point number returned is that of the Sollya |
|
| 317 |
constant. |
|
| 318 |
""" |
|
| 308 | 319 |
precisionSa = pobyso_get_prec_of_constant_so_sa(constExpSo) |
| 309 | 320 |
RRRR = RealField(precisionSa) |
| 310 | 321 |
rnSa = RRRR(0) |
| 311 | 322 |
sollya_lib_get_constant(get_rn_value(rnSa), constExpSo) |
| 312 | 323 |
return(rnSa) |
| 324 |
# End pobyso_get_constant_as_rn_so_sa |
|
| 313 | 325 |
|
| 314 | 326 |
def pobyso_get_constant_as_rn_with_rf(ctExp, realField): |
| 315 |
""" Legacy function. See pobyso_get_constant_as_rn_with_rf_so_sa.""" |
|
| 327 |
""" |
|
| 328 |
Legacy function. See pobyso_get_constant_as_rn_with_rf_so_sa. |
|
| 329 |
""" |
|
| 316 | 330 |
return(pobyso_get_constant_as_rn_with_rf_so_sa(ctExp, realField)) |
| 317 | 331 |
|
| 318 | 332 |
def pobyso_get_constant_as_rn_with_rf_so_sa(ctExpSo, realFieldSa = None): |
| 333 |
""" |
|
| 334 |
Get a Sollya constant as a Sage "real number". |
|
| 335 |
If no real field is specified, the precision of the floating-point number |
|
| 336 |
returned is that of the Solly constant. |
|
| 337 |
Otherwise is is that of the real field. Hence rounding may happen. |
|
| 338 |
""" |
|
| 319 | 339 |
if realFieldSa is None: |
| 320 | 340 |
sollyaPrecSa = pobyso_get_prec_so_sa() |
| 321 | 341 |
realFieldSa = RealField(sollyaPrecSa) |
| 322 | 342 |
rnSa = realFieldSa(0) |
| 323 | 343 |
sollya_lib_get_constant(get_rn_value(rnSa), ctExpSo) |
| 324 | 344 |
return(rnSa) |
| 345 |
# End pobyso_get_constant_as_rn_with_rf_so_sa |
|
| 325 | 346 |
|
| 326 | 347 |
def pobyso_get_free_variable_name(): |
| 327 |
""" Legacy function. See pobyso_get_free_variable_name_so_sa.""" |
|
| 348 |
""" |
|
| 349 |
Legacy function. See pobyso_get_free_variable_name_so_sa. |
|
| 350 |
""" |
|
| 328 | 351 |
return(pobyso_get_free_variable_name_so_sa()) |
| 329 | 352 |
|
| 330 | 353 |
def pobyso_get_free_variable_name_so_sa(): |
| 331 | 354 |
return(sollya_lib_get_free_variable_name()) |
| 332 | 355 |
|
| 333 | 356 |
def pobyso_get_function_arity(expressionSo): |
| 334 |
""" Legacy function. See pobyso_get_function_arity_so_sa.""" |
|
| 357 |
""" |
|
| 358 |
Legacy function. See pobyso_get_function_arity_so_sa. |
|
| 359 |
""" |
|
| 335 | 360 |
return(pobyso_get_function_arity_so_sa(expressionSo)) |
| 336 | 361 |
|
| 337 | 362 |
def pobyso_get_function_arity_so_sa(expressionSo): |
| ... | ... | |
| 340 | 365 |
return(int(arity.value)) |
| 341 | 366 |
|
| 342 | 367 |
def pobyso_get_head_function(expressionSo): |
| 343 |
""" Legacy function. See pobyso_get_head_function_so_sa. """ |
|
| 368 |
""" |
|
| 369 |
Legacy function. See pobyso_get_head_function_so_sa. |
|
| 370 |
""" |
|
| 344 | 371 |
return(pobyso_get_head_function_so_sa(expressionSo)) |
| 345 | 372 |
|
| 346 | 373 |
def pobyso_get_head_function_so_sa(expressionSo): |
| ... | ... | |
| 351 | 378 |
def pobyso_get_interval_from_range_so_sa(soRange, realIntervalFieldSa = None ): |
| 352 | 379 |
""" |
| 353 | 380 |
Return the Sage interval corresponding to the Sollya range argument. |
| 354 |
If no reaInterval lField is passed as argument, the interval bounds are not
|
|
| 381 |
If no reaIntervalField is passed as an argument, the interval bounds are not
|
|
| 355 | 382 |
rounded: they are elements of RealIntervalField of the "right" precision |
| 356 | 383 |
to hold all the digits. |
| 357 | 384 |
""" |
| ... | ... | |
| 456 | 483 |
""" |
| 457 | 484 |
#pobyso_autoprint(sollyaExp) |
| 458 | 485 |
operator = pobyso_get_head_function_so_sa(sollyaExp) |
| 486 |
sollyaLibFreeVariableName = sollya_lib_get_free_variable_name() |
|
| 459 | 487 |
# Constants and the free variable are special cases. |
| 460 | 488 |
# All other operator are dealt with in the same way. |
| 461 | 489 |
if (operator != SOLLYA_BASE_FUNC_CONSTANT) and \ |
| ... | ... | |
| 487 | 515 |
return pobyso_get_constant_as_rn_with_rf_so_sa(sollyaExp, realField) |
| 488 | 516 |
elif operator == SOLLYA_BASE_FUNC_FREE_VARIABLE: |
| 489 | 517 |
#print "This is free variable" |
| 490 |
return(eval(sollya_lib_get_free_variable_name()))
|
|
| 518 |
return(eval(sollyaLibFreeVariableName))
|
|
| 491 | 519 |
else: |
| 492 | 520 |
print "Unexpected" |
| 493 | 521 |
return eval('None')
|
| 494 | 522 |
# End pobyso_get_sage_poly_from_sollya_poly |
| 495 | 523 |
|
| 496 | 524 |
def pobyso_get_poly_sa_so(polySo, realFieldSa=None): |
| 525 |
""" |
|
| 526 |
Create a Sollya polynomial from a Sage polynomial. |
|
| 527 |
""" |
|
| 497 | 528 |
pass |
| 498 | 529 |
# pobyso_get_poly_sa_so |
| 499 | 530 |
|
| ... | ... | |
| 537 | 568 |
Get the subfunctions of an expression. |
| 538 | 569 |
Return the number of subfunctions and the list of subfunctions addresses. |
| 539 | 570 |
S.T.: Could not figure out another way than that ugly list of declarations |
| 540 |
to recover the addresses of the subfunctions. |
|
| 571 |
to recover the addresses of the subfunctions. |
|
| 572 |
We limit ourselves to arity 8 functions. |
|
| 541 | 573 |
""" |
| 542 | 574 |
subf0 = c_int(0) |
| 543 | 575 |
subf1 = c_int(0) |
| ... | ... | |
| 551 | 583 |
arity = c_int(0) |
| 552 | 584 |
nullPtr = POINTER(c_int)() |
| 553 | 585 |
sollya_lib_get_subfunctions(expressionSo, byref(arity), \ |
| 554 |
byref(subf0), byref(subf1), byref(subf2), byref(subf3), byref(subf4), byref(subf5),\ |
|
| 555 |
byref(subf6), byref(subf7), byref(subf8), nullPtr, None) |
|
| 556 |
# byref(cast(subfunctions[0], POINTER(c_int))), byref(cast(subfunctions[0], POINTER(c_int))), \ |
|
| 557 |
# byref(cast(subfunctions[2], POINTER(c_int))), byref(cast(subfunctions[3], POINTER(c_int))), \ |
|
| 558 |
# byref(cast(subfunctions[4], POINTER(c_int))), byref(cast(subfunctions[5], POINTER(c_int))), \ |
|
| 559 |
# byref(cast(subfunctions[6], POINTER(c_int))), byref(cast(subfunctions[7], POINTER(c_int))), \ |
|
| 586 |
byref(subf0), byref(subf1), byref(subf2), byref(subf3), \ |
|
| 587 |
byref(subf4), byref(subf5),\ |
|
| 588 |
byref(subf6), byref(subf7), byref(subf8), nullPtr, None) |
|
| 589 |
# byref(cast(subfunctions[0], POINTER(c_int))), \ |
|
| 590 |
# byref(cast(subfunctions[0], POINTER(c_int))), \ |
|
| 591 |
# byref(cast(subfunctions[2], POINTER(c_int))), \ |
|
| 592 |
# byref(cast(subfunctions[3], POINTER(c_int))), \ |
|
| 593 |
# byref(cast(subfunctions[4], POINTER(c_int))), \ |
|
| 594 |
# byref(cast(subfunctions[5], POINTER(c_int))), \ |
|
| 595 |
# byref(cast(subfunctions[6], POINTER(c_int))), \ |
|
| 596 |
# byref(cast(subfunctions[7], POINTER(c_int))), \ |
|
| 560 | 597 |
# byref(cast(subfunctions[8], POINTER(c_int))), nullPtr) |
| 561 |
subfunctions = [subf0, subf1, subf2, subf3, subf4, subf5, subf6, subf7, subf8] |
|
| 598 |
subfunctions = [subf0, subf1, subf2, subf3, subf4, subf5, subf6, subf7, \ |
|
| 599 |
subf8] |
|
| 562 | 600 |
subs = [] |
| 563 | 601 |
if arity.value > pobyso_max_arity: |
| 564 | 602 |
return(0,[]) |
| ... | ... | |
| 581 | 619 |
sollya_lib_get_constant_as_int(byref(precSa), precSo) |
| 582 | 620 |
sollya_lib_clear_obj(precSo) |
| 583 | 621 |
return(int(precSa.value)) |
| 622 |
# End pobyso_get_prec_so_sa. |
|
| 584 | 623 |
|
| 585 | 624 |
def pobyso_get_prec_of_constant(ctExpSo): |
| 586 | 625 |
""" Legacy function. See pobyso_get_prec_of_constant_so_sa. """ |
| ... | ... | |
| 612 | 651 |
pobyso_name_free_variable_sa_so(freeVariableName) |
| 613 | 652 |
|
| 614 | 653 |
def pobyso_name_free_variable_sa_so(freeVariableName): |
| 654 |
""" |
|
| 655 |
Set the free variable name in Sollya from a Sage string. |
|
| 656 |
""" |
|
| 615 | 657 |
sollya_lib_name_free_variable(freeVariableName) |
| 616 | 658 |
|
| 617 | 659 |
def pobyso_parse_string(string): |
| ... | ... | |
| 619 | 661 |
return(pobyso_parse_string_sa_so(string)) |
| 620 | 662 |
|
| 621 | 663 |
def pobyso_parse_string_sa_so(string): |
| 664 |
""" |
|
| 665 |
Get the Sollya expression computed from a Sage string. |
|
| 666 |
""" |
|
| 622 | 667 |
return(sollya_lib_parse_string(string)) |
| 623 | 668 |
|
| 624 | 669 |
def pobyso_range(rnLowerBound, rnUpperBound): |
| ... | ... | |
| 627 | 672 |
|
| 628 | 673 |
def pobyso_bounds_to_range_sa_so(rnLowerBoundSa, rnUpperBoundSa): |
| 629 | 674 |
""" |
| 630 |
Return a Sollya range from to 2 RealField elements. |
|
| 675 |
Return a Sollya range from to 2 RealField Sage elements.
|
|
| 631 | 676 |
The Sollya range element has a sufficient precision to hold all |
| 632 |
the digits of the bounds. |
|
| 677 |
the digits of the Sage bounds.
|
|
| 633 | 678 |
""" |
| 679 |
# Sanity check. |
|
| 634 | 680 |
if rnLowerBoundSa > rnUpperBoundSa: |
| 635 | 681 |
return None |
| 682 |
# Check for the largest precision. |
|
| 636 | 683 |
lbPrec = rnLowerBoundSa.parent().precision() |
| 637 | 684 |
ubPrec = rnLowerBoundSa.parent().precision() |
| 638 | 685 |
currentSollyaPrecSa = pobyso_get_prec_so_sa() |
| ... | ... | |
| 645 | 692 |
lowerBoundSo = sollya_lib_constant(get_rn_value(rnLowerBoundSa)) |
| 646 | 693 |
upperBoundSo = sollya_lib_constant(get_rn_value(rnUpperBoundSa)) |
| 647 | 694 |
rangeSo = sollya_lib_range(lowerBoundSo, upperBoundSo) |
| 648 |
currentPrecSo = sollya_lib_get_prec(None) |
|
| 649 | 695 |
if maxPrecSa > currentSollyaPrecSa: |
| 650 | 696 |
sollya_lib_set_prec(currentPrecSo) |
| 651 | 697 |
sollya_lib_clear_obj(currentPrecSo) |
| ... | ... | |
| 655 | 701 |
return(rangeSo) |
| 656 | 702 |
|
| 657 | 703 |
def pobyso_range_to_interval_so_sa(rangeSo, realIntervalField = None): |
| 704 |
""" |
|
| 705 |
Get a Sage interval from a Sollya range. |
|
| 706 |
If no realIntervalField is given as a parameter, the Sage interval |
|
| 707 |
precision is that of the Sollya range. |
|
| 708 |
Otherwise, the precision is that of the realIntervalField. Rounding |
|
| 709 |
may happen. |
|
| 710 |
""" |
|
| 658 | 711 |
if realIntervalField is None: |
| 659 | 712 |
precSa = pobyso_get_prec_of_range_so_sa(rangeSo) |
| 660 | 713 |
realIntervalField = RealIntervalField(precSa) |
| ... | ... | |
| 672 | 725 |
All arguments are Sage/Python. |
| 673 | 726 |
The functions (func and weight) must be passed as expressions or strings. |
| 674 | 727 |
Otherwise the function fails. |
| 675 |
The return value is a pointer is a Sage polynomial.
|
|
| 728 |
The return value is a Sage polynomial. |
|
| 676 | 729 |
""" |
| 677 |
var('zorglub') # Dummy variable name for type check only.
|
|
| 730 |
var('zorglub') # Dummy variable name for type check only. Type of
|
|
| 731 |
# zorglub is "symbolic expression". |
|
| 678 | 732 |
polySo = pobyso_remez_canonical_sa_so(func, \ |
| 679 | 733 |
degree, \ |
| 680 | 734 |
lowerBound, \ |
| 681 | 735 |
upperBound, \ |
| 682 | 736 |
weight = None, \ |
| 683 | 737 |
quality = None) |
| 738 |
# String test |
|
| 684 | 739 |
if parent(func) == parent("string"):
|
| 685 | 740 |
functionSa = eval(func) |
| 686 | 741 |
# Expression test. |
| 687 | 742 |
elif type(func) == type(zorglub): |
| 688 | 743 |
functionSa = func |
| 744 |
else: |
|
| 745 |
return None |
|
| 746 |
# |
|
| 689 | 747 |
maxPrecision = 0 |
| 690 | 748 |
if polySo is None: |
| 691 | 749 |
return(None) |
| ... | ... | |
| 694 | 752 |
polynomialRing = RRRR[functionSa.variables()[0]] |
| 695 | 753 |
expSa = pobyso_get_sage_exp_from_sollya_exp_so_sa(polySo, RRRR) |
| 696 | 754 |
polySa = polynomial(expSa, polynomialRing) |
| 755 |
sollya_lib_clear_obj(polySo) |
|
| 697 | 756 |
return(polySa) |
| 698 | 757 |
|
| 699 | 758 |
def pobyso_remez_canonical(func, \ |
| ... | ... | |
| 721 | 780 |
Otherwise the function fails. |
| 722 | 781 |
The return value is a pointer to a Sollya function. |
| 723 | 782 |
""" |
| 724 |
var('zorglub') # Dummy variable name for type check only.
|
|
| 783 |
var('zorglub') # Dummy variable name for type check only. Type of
|
|
| 784 |
# zorglub is "symbolic expression". |
|
| 725 | 785 |
currentVariableName = None |
| 726 | 786 |
# The func argument can be of different types (string, |
| 727 | 787 |
# symbolic expression...) |
| ... | ... | |
| 750 | 810 |
qualitySo= pobyso_constant_sa_so(quality) |
| 751 | 811 |
else: |
| 752 | 812 |
qualitySo = None |
| 753 |
return(sollya_lib_remez(functionSo, \ |
|
| 754 |
degreeSo, \ |
|
| 755 |
rangeSo, \ |
|
| 756 |
weightSo, \ |
|
| 757 |
qualitySo, \ |
|
| 758 |
None)) |
|
| 759 |
|
|
| 813 |
|
|
| 814 |
remezPolySo = sollya_lib_remez(functionSo, \ |
|
| 815 |
degreeSo, \ |
|
| 816 |
rangeSo, \ |
|
| 817 |
weightSo, \ |
|
| 818 |
qualitySo, \ |
|
| 819 |
None) |
|
| 820 |
sollya_lib_clear_obj(functionSo) |
|
| 821 |
sollya_lib_clear_obj(degreeSo) |
|
| 822 |
sollya_lib_clear_obj(rangeSo) |
|
| 823 |
sollya_lib_clear_obj(weightSo) |
|
| 824 |
if not qualitySo is None: |
|
| 825 |
sollya_lib_clear_obj(qualtiySo) |
|
| 826 |
return(remezPolySo) |
|
| 827 |
# End pobyso_remez_canonical_sa_so |
|
| 828 |
|
|
| 760 | 829 |
def pobyso_remez_canonical_so_so(funcSo, \ |
| 761 | 830 |
degreeSo, \ |
| 762 | 831 |
rangeSo, \ |
| ... | ... | |
| 817 | 886 |
# If changed, reset the Sollya working precision. |
| 818 | 887 |
if not sollyaPrecSo is None: |
| 819 | 888 |
sollya_lib_set_prec(initialPrecSo) |
| 820 |
sollya_lib_clear_obj(initailPrecSo)
|
|
| 889 |
sollya_lib_clear_obj(initialPrecSo)
|
|
| 821 | 890 |
return((polyVarChangedSo, intervalCenterSo, maxErrorSo)) |
| 822 | 891 |
# end pobyso_taylor_expansion_with_change_var_so_so |
| 823 | 892 |
|
| ... | ... | |
| 870 | 939 |
for 'interval' with 'errorType'. |
| 871 | 940 |
point: must be a Real or a Real interval. |
| 872 | 941 |
return the Taylor form as an array |
| 873 |
TODO: take care of the interval and of point when it is an interval; |
|
| 942 |
TODO: take care of the interval and of the point when it is an interval;
|
|
| 874 | 943 |
when errorType is not None; |
| 875 |
take care of the other elements of the Taylor form (coefficients errors and
|
|
| 876 |
delta. |
|
| 944 |
take care of the other elements of the Taylor form (coefficients |
|
| 945 |
errors and delta.
|
|
| 877 | 946 |
""" |
| 878 | 947 |
# Absolute as the default error. |
| 879 | 948 |
if errorType is None: |
| ... | ... | |
| 902 | 971 |
# TODO: deal with the interval case. |
| 903 | 972 |
pass |
| 904 | 973 |
# Call Sollya |
| 905 |
taylorFormSo = sollya_lib_taylorform(functionSo, degreeSo, pointSo, errorTypeSo,\ |
|
| 974 |
taylorFormSo = \ |
|
| 975 |
sollya_lib_taylorform(functionSo, degreeSo, pointSo, errorTypeSo,\ |
|
| 906 | 976 |
None) |
| 907 | 977 |
(tfsAsList, numElements, isEndElliptic) = \ |
| 908 | 978 |
pobyso_get_list_elements_so_so(taylorFormSo) |
Formats disponibles : Unified diff