Révision 109 pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage
sagePolynomialOperations.sage (revision 109) | ||
---|---|---|
87 | 87 |
|
88 | 88 |
# End spo_add_polynomial_coeffs_to_matrix_row |
89 | 89 |
|
90 |
def spo_get_coefficient_for_monomial(monomialsList, coefficientsList, monomial): |
|
91 |
""" |
|
92 |
Get, for a polynomial, the coefficient for a given monomial. |
|
93 |
The polynomial is given as two lists (monomials and coefficients as |
|
94 |
return by the respective methods ; indexes of the two lists must match). |
|
95 |
If the monomial is not found, 0 is returned. |
|
96 |
""" |
|
97 |
monomialIndex = 0 |
|
98 |
for mono in monomialsList: |
|
99 |
if mono == monomial: |
|
100 |
return coefficientsList[monomialIndex] |
|
101 |
monomialIndex += 1 |
|
102 |
return 0 |
|
103 |
# End spo_get_coefficient_for_monomial. |
|
104 |
|
|
105 |
|
|
90 | 106 |
def spo_expression_as_string(powI, powT, powP, powN): |
91 | 107 |
""" |
92 | 108 |
Computes a string version of the i^k + t^l + p^m + N^n expression for |
... | ... | |
410 | 426 |
printed in colums of columnsWitdth width. |
411 | 427 |
""" |
412 | 428 |
pRing = p.parent() |
413 |
knownMonomials = [] |
|
414 | 429 |
polynomialsList = [] |
415 | 430 |
pVariables = p.variables() |
416 | 431 |
iVariable = pVariables[0] |
... | ... | |
494 | 509 |
polynomialAtPower *= p |
495 | 510 |
nAtPower /= N |
496 | 511 |
# End for pPower loop |
497 |
return((knownMonomials, polynomialsList))
|
|
512 |
return polynomialsList
|
|
498 | 513 |
# End spo_polynomial_to_proto_matrix_2 |
499 | 514 |
|
500 |
def spo_polynomial_to_polynomials_list_3(p, alpha, N, columnsWidth=0): |
|
515 |
def spo_polynomial_to_polynomials_list_3(p, alpha, N, iBound, tBound, \ |
|
516 |
columnsWidth=0): |
|
501 | 517 |
""" |
502 | 518 |
From p, alpha, N build a list of polynomials... |
503 | 519 |
TODO: more in depth rationale... |
... | ... | |
586 | 602 |
polynomialsList.append(currentPolynomial) |
587 | 603 |
internalIpower += pIdegree |
588 | 604 |
# End for tPower |
589 |
# The i^iPower * p^pPower * N^(alpha-pPower) i-shift. |
|
590 |
if columnsWidth != 0: |
|
591 |
polExpStr = spo_expression_as_string(iPower, \ |
|
592 |
0, \ |
|
593 |
pPower, \ |
|
594 |
alpha-pPower) |
|
605 |
# Here we have to choose between a |
|
606 |
# i^iPower * p^pPower * N^(alpha-pPower) i-shift and |
|
607 |
# i^iPower * i^(d_i(p) * pPower) * N^alpha, depend on which |
|
608 |
# coefficient is smallest. |
|
609 |
IcurrentExponent = iPower + \ |
|
610 |
(pPower * polynomialAtPower.degree(i)) |
|
611 |
currentMonomial = pRing(i^(IcurrentExponent)) |
|
612 |
currentPolynomial = pRing(i^iPower * nAtPower) * \ |
|
613 |
polynomialAtPower |
|
614 |
currMonomials = currentPolynomial.monomials() |
|
615 |
currCoefficients = currentPolynomial.coefficients() |
|
616 |
currentCoefficient = spo_get_coefficient_for_monomial( \ |
|
617 |
currMonomials, |
|
618 |
currCoefficients, |
|
619 |
currentMonomial) |
|
620 |
if currentCoefficient > nAtAlpha: |
|
621 |
if columnsWidth != 0: |
|
622 |
polExpStr = spo_expression_as_string(IcurrentCoefficient, \ |
|
623 |
0, \ |
|
624 |
0, \ |
|
625 |
alpha) |
|
595 | 626 |
print "->", polExpStr |
596 |
currentExpression = i^iPower * nAtPower |
|
597 |
currentPolynomial = pRing(currentExpression) * polynomialAtPower |
|
598 |
polynomialsList.append(currentPolynomial) |
|
627 |
polynomialsList.append(currentMonomial * nAtAlpha) |
|
628 |
else: |
|
629 |
if columnsWidth != 0: |
|
630 |
polExpStr = spo_expression_as_string(iPower, \ |
|
631 |
0, \ |
|
632 |
pPower, \ |
|
633 |
alpha-pPower) |
|
634 |
print "->", polExpStr |
|
635 |
polynomialsList.append(currentPolynomial) |
|
599 | 636 |
# End for iPower |
600 | 637 |
polynomialAtPower *= p |
601 | 638 |
nAtPower /= N |
602 | 639 |
# End for pPower loop |
603 |
return((knownMonomials, polynomialsList))
|
|
640 |
return polynomialsList
|
|
604 | 641 |
# End spo_polynomial_to_proto_matrix_3 |
605 | 642 |
|
606 | 643 |
def spo_proto_to_column_matrix(protoMatrixColumns, \ |
Formats disponibles : Unified diff