Révision 155 pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage
sagePolynomialOperations.sage (revision 155) | ||
---|---|---|
55 | 55 |
" " + str(knownMonomials[knownMonomialIndex]) |
56 | 56 |
print monomialAsString, " " * \ |
57 | 57 |
(columnsWidth - len(monomialAsString)), |
58 |
# Add the coefficient to the proto matrix row and delete the \
|
|
58 |
# Add the coefficient to the proto matrix row and delete the |
|
59 | 59 |
# known monomial from the current pMonomial list |
60 | 60 |
#(and the corresponding coefficient as well). |
61 | 61 |
protoMatrixRowCoefficients.append(pCoefficients[indexInPmonomials]) |
... | ... | |
839 | 839 |
return polynomialsList |
840 | 840 |
# End spo_polynomial_to_proto_matrix_5 |
841 | 841 |
|
842 |
def spo_polynomial_to_polynomials_list_6(p, alpha, N, iBound, tBound, |
|
843 |
columnsWidth=0): |
|
844 |
""" |
|
845 |
From p, alpha, N build a list of polynomials use to create a base |
|
846 |
that will eventually be reduced with LLL. |
|
847 |
|
|
848 |
The bounds are computed for the coefficients that will be used to |
|
849 |
form the base. |
|
850 |
|
|
851 |
We try to introduce only one new monomial at a time, whithout trying to |
|
852 |
obtain a triangular matrix. |
|
853 |
|
|
854 |
There are many possibilities to introduce the monomials: our goal is also |
|
855 |
to introduce each of them on the diagonal with the smallest coefficient. |
|
856 |
|
|
857 |
The method depends on the structure of the polynomial. Here it is adapted |
|
858 |
to the a_n*i^n + ... + a_1 * i - t + b form. |
|
859 |
|
|
860 |
Parameters |
|
861 |
---------- |
|
862 |
p: the (bivariate) polynomial; |
|
863 |
alpha: |
|
864 |
N: |
|
865 |
iBound: |
|
866 |
tBound: |
|
867 |
columsWidth: if == 0, no information is displayed, otherwise data is |
|
868 |
printed in colums of columnsWitdth width. |
|
869 |
""" |
|
870 |
pRing = p.parent() |
|
871 |
polynomialsList = [] |
|
872 |
pVariables = p.variables() |
|
873 |
iVariable = pVariables[0] |
|
874 |
tVariable = pVariables[1] |
|
875 |
polynomialAtPower = copy(p) |
|
876 |
currentPolynomial = pRing(1) # Constant term. |
|
877 |
pIdegree = p.degree(iVariable) |
|
878 |
pTdegree = p.degree(tVariable) |
|
879 |
maxIdegree = pIdegree * alpha |
|
880 |
currentIdegree = currentPolynomial.degree(iVariable) |
|
881 |
nAtAlpha = N^alpha |
|
882 |
nAtPower = nAtAlpha |
|
883 |
polExpStr = "" |
|
884 |
# |
|
885 |
## Shouldn't we start at tPower == 1 because polynomials without |
|
886 |
# t monomials are useless? |
|
887 |
for tPower in xrange(0, alpha+1): |
|
888 |
## Start at iPower == 0 because here there are i monomials |
|
889 |
# in p even if iPower is zero. |
|
890 |
for iPower in xrange(0, alpha-tPower+1): |
|
891 |
if iPower + tPower <= alpha: |
|
892 |
print "iPower:", iPower, " tPower:", tPower |
|
893 |
q = pRing(iVariable * iBound)^iPower * ((p * N)^tPower) |
|
894 |
print q.monomials() |
|
895 |
polynomialsList.append(q) |
|
896 |
return polynomialsList |
|
897 |
|
|
898 |
""" |
|
899 |
# We first introduce all the monomials in i alone multiplied by N^alpha. |
|
900 |
for iPower in xrange(0, maxIdegree + 1): |
|
901 |
if columnsWidth !=0: |
|
902 |
polExpStr = spo_expression_as_string(iPower, iBound, |
|
903 |
0, tBound, |
|
904 |
0, alpha) |
|
905 |
print "->", polExpStr |
|
906 |
currentExpression = iVariable^iPower * nAtAlpha * iBound^iPower |
|
907 |
currentPolynomial = pRing(currentExpression) |
|
908 |
polynomialsList.append(currentPolynomial) |
|
909 |
# End for iPower |
|
910 |
# We work from p^1 * N^alpha-1 to p^alpha * N^0 |
|
911 |
for pPower in xrange(1, alpha + 1): |
|
912 |
# First of all the p^pPower * N^(alpha-pPower) polynomial. |
|
913 |
nAtPower /= N |
|
914 |
if columnsWidth !=0: |
|
915 |
polExpStr = spo_expression_as_string(0, iBound, |
|
916 |
0, tBound, |
|
917 |
pPower, alpha-pPower) |
|
918 |
print "->", polExpStr |
|
919 |
currentPolynomial = polynomialAtPower * nAtPower |
|
920 |
polynomialsList.append(currentPolynomial) |
|
921 |
# Exit when pPower == alpha |
|
922 |
if pPower == alpha: |
|
923 |
return polynomialsList |
|
924 |
for iPower in xrange(1, pIdegree + 1): |
|
925 |
iCurrentPower = pIdegree + iPower |
|
926 |
for tPower in xrange(pPower-1, 0, -1): |
|
927 |
#print "tPower:", tPower |
|
928 |
if columnsWidth != 0: |
|
929 |
polExpStr = spo_expression_as_string(iCurrentPower, iBound, |
|
930 |
tPower, tBound, |
|
931 |
0, alpha) |
|
932 |
print "->", polExpStr |
|
933 |
currentExpression = i^iCurrentPower * iBound^iCurrentPower * t^tPower * tBound^tPower *nAtAlpha |
|
934 |
currentPolynomial = pRing(currentExpression) |
|
935 |
polynomialsList.append(currentPolynomial) |
|
936 |
iCurrentPower += pIdegree |
|
937 |
# End for tPower |
|
938 |
# We now introduce the mixed i^k * t^l monomials by i^m * p^n * N^(alpha-n) |
|
939 |
if columnsWidth != 0: |
|
940 |
polExpStr = spo_expression_as_string(iPower, iBound, |
|
941 |
0, tBound, |
|
942 |
pPower, alpha-pPower) |
|
943 |
print "->", polExpStr |
|
944 |
currentExpression = i^iPower * iBound^iPower * nAtPower |
|
945 |
currentPolynomial = pRing(currentExpression) * polynomialAtPower |
|
946 |
polynomialsList.append(currentPolynomial) |
|
947 |
# End for iPower |
|
948 |
polynomialAtPower *= p |
|
949 |
# End for pPower loop |
|
950 |
""" |
|
951 |
return polynomialsList |
|
952 |
# End spo_polynomial_to_proto_matrix_6 |
|
953 |
|
|
842 | 954 |
def spo_proto_to_column_matrix(protoMatrixColumns): |
843 | 955 |
""" |
844 | 956 |
Create a column (each row holds the coefficients for one monomial) matrix. |
Formats disponibles : Unified diff