Révision 106 pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage
sagePolynomialOperations.sage (revision 106) | ||
---|---|---|
1 | 1 |
load "/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageMatrixOperations.sage" |
2 | 2 |
print "sagePolynomialOperations loading..." |
3 |
def spo_add_polynomial_coeffs_to_matrix_row(pMonomials, |
|
4 |
pCoefficients, |
|
3 |
def spo_add_polynomial_coeffs_to_matrix_row(poly, |
|
5 | 4 |
knownMonomials, |
6 | 5 |
protoMatrixRows, |
7 | 6 |
columnsWidth=0): |
8 | 7 |
""" |
9 |
For a given polynomial (under the form of monomials and coefficents lists),
|
|
8 |
For a given polynomial , |
|
10 | 9 |
add the coefficients of the protoMatrix (a list of proto matrix rows). |
11 | 10 |
Coefficients are added to the protoMatrix row in the order imposed by the |
12 | 11 |
monomials discovery list (the knownMonomials list) built as construction |
13 | 12 |
goes on. |
14 | 13 |
As a bonus, data can be printed out for a visual check. |
15 |
pMonomials : the list of the monomials coming form some polynomial; |
|
16 |
pCoefficients : the list of the corresponding coefficients to add to |
|
17 |
the protoMatrix in the exact same order as the monomials; |
|
18 |
knownMonomials : the list of the already knonw monomials; |
|
14 |
poly : the polynomial; in argument; |
|
15 |
knownMonomials : the list of the already known monomials; will determine |
|
16 |
the order of the coefficients appending to a row; in-out |
|
17 |
argument (new monomials may be discovered and then |
|
18 |
appended the the knowMonomials list); |
|
19 | 19 |
protoMatrixRows: a list of lists, each one holding the coefficients of the |
20 |
monomials |
|
20 |
monomials of a polynomial; in-out argument: a new row is |
|
21 |
added at each call; |
|
21 | 22 |
columnWith : the width, in characters, of the displayed column ; if 0, |
22 |
do not display anything. |
|
23 |
do not display anything; in argument.
|
|
23 | 24 |
""" |
25 |
pMonomials = poly.monomials() |
|
26 |
pCoefficients = poly.coefficients() |
|
24 | 27 |
# We have started with the smaller degrees in the first variable. |
25 | 28 |
pMonomials.reverse() |
26 | 29 |
pCoefficients.reverse() |
... | ... | |
200 | 203 |
# polynomialAtPower == 1 here. Next line should be commented |
201 | 204 |
# out but it does not work! Some conversion problem? |
202 | 205 |
currentPolynomial = pRing(currentExpression) |
203 |
polynomialsList.append(polExpStr)
|
|
206 |
polynomialsList.append(currentPolynomial)
|
|
204 | 207 |
pMonomials = currentPolynomial.monomials() |
205 | 208 |
pCoefficients = currentPolynomial.coefficients() |
206 | 209 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials, |
... | ... | |
220 | 223 |
polExpStr = spo_expression_as_string(0, 0, pPower, alpha-pPower) |
221 | 224 |
print "->", polExpStr |
222 | 225 |
currentPolynomial = polynomialAtPower * nAtPower |
223 |
polynomialsList.append(polExpStr)
|
|
226 |
polynomialsList.append(currentPolynomial)
|
|
224 | 227 |
pMonomials = currentPolynomial.monomials() |
225 | 228 |
pCoefficients = currentPolynomial.coefficients() |
226 | 229 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials, |
... | ... | |
245 | 248 |
print "->", polExpStr |
246 | 249 |
currentExpression = i^iPower * nAtPower |
247 | 250 |
currentPolynomial = pRing(currentExpression) * polynomialAtPower |
248 |
polynomialsList.append(polExpStr)
|
|
251 |
polynomialsList.append(currentPolynomial)
|
|
249 | 252 |
pMonomials = currentPolynomial.monomials() |
250 | 253 |
pCoefficients = currentPolynomial.coefficients() |
251 | 254 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials, \ |
... | ... | |
268 | 271 |
print "->", polExpStr |
269 | 272 |
currentExpression = i^(iPower * pIdegree) * t^tPower * nAtAlpha |
270 | 273 |
currentPolynomial = pRing(currentExpression) |
271 |
polynomialsList.append(polExpStr)
|
|
274 |
polynomialsList.append(currentPolynomial)
|
|
272 | 275 |
pMonomials = currentPolynomial.monomials() |
273 | 276 |
pCoefficients = currentPolynomial.coefficients() |
274 | 277 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials, |
... | ... | |
302 | 305 |
print "->", polExpStr |
303 | 306 |
currentExpression = i^iPower * t^outerTpower * nAtAlpha |
304 | 307 |
currentPolynomial = pRing(currentExpression) |
305 |
polynomialsList.append(polExpStr)
|
|
308 |
polynomialsList.append(currentPolynomial)
|
|
306 | 309 |
pMonomials = currentPolynomial.monomials() |
307 | 310 |
pCoefficients = currentPolynomial.coefficients() |
308 | 311 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials, |
... | ... | |
334 | 337 |
currentExpression = \ |
335 | 338 |
i^(iPower) * t^(innerTpower) * nAtAlpha |
336 | 339 |
currentPolynomial = pRing(currentExpression) |
337 |
polynomialsList.append(polExpStr)
|
|
340 |
polynomialsList.append(currentPolynomial)
|
|
338 | 341 |
pMonomials = currentPolynomial.monomials() |
339 | 342 |
pCoefficients = currentPolynomial.coefficients() |
340 | 343 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials, |
... | ... | |
363 | 366 |
currentExpression = i^iShift * t^outerTpower * nAtPower |
364 | 367 |
currentPolynomial = pRing(currentExpression) * \ |
365 | 368 |
polynomialAtPower |
366 |
polynomialsList.append(polExpStr)
|
|
369 |
polynomialsList.append(currentPolynomial)
|
|
367 | 370 |
pMonomials = currentPolynomial.monomials() |
368 | 371 |
pCoefficients = currentPolynomial.coefficients() |
369 | 372 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials, |
... | ... | |
380 | 383 |
return ((protoMatrixRows, knownMonomials, polynomialsList)) |
381 | 384 |
# End spo_polynomial_to_proto_matrix |
382 | 385 |
|
383 |
def spo_polynomial_to_proto_matrix_2(p, alpha, N, columnsWidth=0):
|
|
386 |
def spo_polynomial_to_polynomials_list_2(p, alpha, N, columnsWidth=0):
|
|
384 | 387 |
""" |
388 |
From p, alpha, N build a list of polynomials... |
|
389 |
TODO: clean up the comments below! |
|
390 |
|
|
385 | 391 |
From a (bivariate) polynomial and some other parameters build a proto |
386 | 392 |
matrix (an array of "rows") to be converted into a "true" matrix and |
387 | 393 |
eventually by reduced by fpLLL. |
... | ... | |
408 | 414 |
""" |
409 | 415 |
pRing = p.parent() |
410 | 416 |
knownMonomials = [] |
411 |
protoMatrixRows = [] |
|
412 | 417 |
polynomialsList = [] |
413 | 418 |
pVariables = p.variables() |
414 | 419 |
iVariable = pVariables[0] |
... | ... | |
441 | 446 |
# out but it does not work! Some conversion problem? |
442 | 447 |
currentPolynomial = pRing(currentExpression) |
443 | 448 |
polynomialsList.append(currentPolynomial) |
444 |
pMonomials = currentPolynomial.monomials() |
|
445 |
pCoefficients = currentPolynomial.coefficients() |
|
446 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials, |
|
447 |
pCoefficients, |
|
448 |
knownMonomials, |
|
449 |
protoMatrixRows, |
|
450 |
columnsWidth) |
|
451 | 449 |
# End for iPower. |
452 | 450 |
else: # pPower > 0: (p^1..p^alpha) |
453 | 451 |
# This where we introduce the p^pPower * N^(alpha-pPower) |
... | ... | |
458 | 456 |
print "->", polExpStr |
459 | 457 |
currentPolynomial = polynomialAtPower * nAtPower |
460 | 458 |
polynomialsList.append(currentPolynomial) |
461 |
pMonomials = currentPolynomial.monomials() |
|
462 |
pCoefficients = currentPolynomial.coefficients() |
|
463 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials, |
|
464 |
pCoefficients, |
|
465 |
knownMonomials, |
|
466 |
protoMatrixRows, |
|
467 |
columnsWidth) |
|
468 |
|
|
459 |
# Exit when pPower == alpha |
|
460 |
if pPower == alpha: |
|
461 |
return((knownMonomials, polynomialsList)) |
|
469 | 462 |
# This is where the "i-shifts" take place. Mixed terms, i^k * t^l |
470 | 463 |
# (that were introduced at a previous |
471 | 464 |
# stage or are introduced now) are only shifted to already existing |
... | ... | |
488 | 481 |
currentExpression = i^internalIpower * t^tPower * nAtAlpha |
489 | 482 |
currentPolynomial = pRing(currentExpression) |
490 | 483 |
polynomialsList.append(currentPolynomial) |
491 |
pMonomials = currentPolynomial.monomials() |
|
492 |
pCoefficients = currentPolynomial.coefficients() |
|
493 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials, \ |
|
494 |
pCoefficients, \ |
|
495 |
knownMonomials, \ |
|
496 |
protoMatrixRows, \ |
|
497 |
columnsWidth) |
|
498 | 484 |
internalIpower += pIdegree |
499 | 485 |
# End for tPower |
500 | 486 |
# The i^iPower * p^pPower * N^(alpha-pPower) i-shift. |
... | ... | |
507 | 493 |
currentExpression = i^iPower * nAtPower |
508 | 494 |
currentPolynomial = pRing(currentExpression) * polynomialAtPower |
509 | 495 |
polynomialsList.append(currentPolynomial) |
510 |
pMonomials = currentPolynomial.monomials() |
|
511 |
pCoefficients = currentPolynomial.coefficients() |
|
512 |
spo_add_polynomial_coeffs_to_matrix_row(pMonomials, \ |
|
513 |
pCoefficients, \ |
|
514 |
knownMonomials, \ |
|
515 |
protoMatrixRows, \ |
|
516 |
columnsWidth) |
|
517 | 496 |
# End for iPower |
518 | 497 |
polynomialAtPower *= p |
519 | 498 |
nAtPower /= N |
520 | 499 |
# End for pPower loop |
521 |
return ((protoMatrixRows, knownMonomials, polynomialsList))
|
|
500 |
return((knownMonomials, polynomialsList))
|
|
522 | 501 |
# End spo_polynomial_to_proto_matrix_2 |
523 | 502 |
|
524 | 503 |
def spo_proto_to_column_matrix(protoMatrixColumns, \ |
Formats disponibles : Unified diff