Index: sagePolynomialOperations.sage
===================================================================
--- sagePolynomialOperations.sage	(revision 105)
+++ sagePolynomialOperations.sage	(revision 106)
@@ -1,26 +1,29 @@
 load "/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageMatrixOperations.sage"
 print "sagePolynomialOperations loading..."
-def spo_add_polynomial_coeffs_to_matrix_row(pMonomials, 
-                                            pCoefficients, 
+def spo_add_polynomial_coeffs_to_matrix_row(poly, 
                                             knownMonomials, 
                                             protoMatrixRows, 
                                             columnsWidth=0):
     """
-    For a given polynomial (under the form of monomials and coefficents lists),
+    For a given polynomial ,
     add the coefficients of the protoMatrix (a list of proto matrix rows).
     Coefficients are added to the protoMatrix row in the order imposed by the 
     monomials discovery list (the knownMonomials list) built as construction
     goes on. 
     As a bonus, data can be printed out for a visual check.
-    pMonomials     : the list of the monomials coming form some polynomial;
-    pCoefficients  : the list of the corresponding coefficients to add to
-                     the protoMatrix in the exact same order as the monomials;
-    knownMonomials : the list of the already knonw monomials;
+    poly           : the polynomial; in argument;
+    knownMonomials : the list of the already known monomials; will determine
+                     the order of the coefficients appending to a row; in-out
+                     argument (new monomials may be discovered and then 
+                     appended the the knowMonomials list);
     protoMatrixRows: a list of lists, each one holding the coefficients of the 
-                     monomials
+                     monomials of a polynomial; in-out argument: a new row is
+                     added at each call;
     columnWith     : the width, in characters, of the displayed column ; if 0, 
-                     do not display anything.
+                     do not display anything; in argument.
     """
+    pMonomials   = poly.monomials()
+    pCoefficients = poly.coefficients()
     # We have started with the smaller degrees in the first variable.
     pMonomials.reverse()
     pCoefficients.reverse()
@@ -200,7 +203,7 @@
                     # polynomialAtPower == 1 here. Next line should be commented
                     # out but it does not work! Some conversion problem?
                     currentPolynomial = pRing(currentExpression)
-                    polynomialsList.append(polExpStr) 
+                    polynomialsList.append(currentPolynomial) 
                     pMonomials = currentPolynomial.monomials()
                     pCoefficients = currentPolynomial.coefficients()
                     spo_add_polynomial_coeffs_to_matrix_row(pMonomials, 
@@ -220,7 +223,7 @@
                 polExpStr = spo_expression_as_string(0, 0, pPower, alpha-pPower)
                 print "->", polExpStr
             currentPolynomial = polynomialAtPower * nAtPower
-            polynomialsList.append(polExpStr) 
+            polynomialsList.append(currentPolynomial) 
             pMonomials = currentPolynomial.monomials()
             pCoefficients = currentPolynomial.coefficients()
             spo_add_polynomial_coeffs_to_matrix_row(pMonomials, 
@@ -245,7 +248,7 @@
                     print "->", polExpStr
                 currentExpression = i^iPower * nAtPower
                 currentPolynomial = pRing(currentExpression) * polynomialAtPower
-                polynomialsList.append(polExpStr) 
+                polynomialsList.append(currentPolynomial) 
                 pMonomials = currentPolynomial.monomials()
                 pCoefficients = currentPolynomial.coefficients()
                 spo_add_polynomial_coeffs_to_matrix_row(pMonomials,      \
@@ -268,7 +271,7 @@
                     print "->", polExpStr
                 currentExpression = i^(iPower * pIdegree) * t^tPower * nAtAlpha
                 currentPolynomial = pRing(currentExpression)
-                polynomialsList.append(polExpStr) 
+                polynomialsList.append(currentPolynomial) 
                 pMonomials = currentPolynomial.monomials()
                 pCoefficients = currentPolynomial.coefficients()
                 spo_add_polynomial_coeffs_to_matrix_row(pMonomials, 
@@ -302,7 +305,7 @@
                         print "->", polExpStr
                     currentExpression = i^iPower * t^outerTpower * nAtAlpha
                     currentPolynomial = pRing(currentExpression)
-                    polynomialsList.append(polExpStr) 
+                    polynomialsList.append(currentPolynomial) 
                     pMonomials = currentPolynomial.monomials()
                     pCoefficients = currentPolynomial.coefficients()
                     spo_add_polynomial_coeffs_to_matrix_row(pMonomials, 
@@ -334,7 +337,7 @@
                             currentExpression = \
                                     i^(iPower) * t^(innerTpower) * nAtAlpha
                             currentPolynomial = pRing(currentExpression)
-                            polynomialsList.append(polExpStr) 
+                            polynomialsList.append(currentPolynomial) 
                             pMonomials = currentPolynomial.monomials()
                             pCoefficients = currentPolynomial.coefficients()
                             spo_add_polynomial_coeffs_to_matrix_row(pMonomials, 
@@ -363,7 +366,7 @@
                     currentExpression = i^iShift * t^outerTpower * nAtPower
                     currentPolynomial = pRing(currentExpression) * \
                                             polynomialAtPower
-                    polynomialsList.append(polExpStr) 
+                    polynomialsList.append(currentPolynomial) 
                     pMonomials = currentPolynomial.monomials()
                     pCoefficients = currentPolynomial.coefficients()
                     spo_add_polynomial_coeffs_to_matrix_row(pMonomials, 
@@ -380,8 +383,11 @@
     return ((protoMatrixRows, knownMonomials, polynomialsList))
 # End spo_polynomial_to_proto_matrix
 
-def spo_polynomial_to_proto_matrix_2(p, alpha, N, columnsWidth=0):
+def spo_polynomial_to_polynomials_list_2(p, alpha, N, columnsWidth=0):
     """
+    From p, alpha, N build a list of polynomials...
+    TODO: clean up the comments below!
+    
     From a (bivariate) polynomial and some other parameters build a proto 
     matrix (an array of "rows") to be converted into a "true" matrix and 
     eventually by reduced by fpLLL.
@@ -408,7 +414,6 @@
     """
     pRing = p.parent()
     knownMonomials = []
-    protoMatrixRows = []
     polynomialsList = []
     pVariables = p.variables()
     iVariable = pVariables[0]
@@ -441,13 +446,6 @@
                 # out but it does not work! Some conversion problem?
                 currentPolynomial = pRing(currentExpression)
                 polynomialsList.append(currentPolynomial) 
-                pMonomials = currentPolynomial.monomials()
-                pCoefficients = currentPolynomial.coefficients()
-                spo_add_polynomial_coeffs_to_matrix_row(pMonomials,                                                             
-                                                        pCoefficients, 
-                                                        knownMonomials, 
-                                                        protoMatrixRows, 
-                                                        columnsWidth)
             # End for iPower.
         else: # pPower > 0: (p^1..p^alpha)
             # This where we introduce the p^pPower * N^(alpha-pPower)
@@ -458,14 +456,9 @@
                 print "->", polExpStr
             currentPolynomial = polynomialAtPower * nAtPower
             polynomialsList.append(currentPolynomial) 
-            pMonomials = currentPolynomial.monomials()
-            pCoefficients = currentPolynomial.coefficients()
-            spo_add_polynomial_coeffs_to_matrix_row(pMonomials, 
-                                                    pCoefficients, 
-                                                    knownMonomials, 
-                                                    protoMatrixRows, 
-                                                    columnsWidth)
-            
+            # Exit when pPower == alpha
+            if pPower == alpha:
+                return((knownMonomials, polynomialsList))
             # This is where the "i-shifts" take place. Mixed terms, i^k * t^l
             # (that were introduced at a previous
             # stage or are introduced now) are only shifted to already existing 
@@ -488,13 +481,6 @@
                     currentExpression = i^internalIpower * t^tPower * nAtAlpha
                     currentPolynomial = pRing(currentExpression)
                     polynomialsList.append(currentPolynomial) 
-                    pMonomials = currentPolynomial.monomials()
-                    pCoefficients = currentPolynomial.coefficients()
-                    spo_add_polynomial_coeffs_to_matrix_row(pMonomials,      \
-                                                            pCoefficients,   \
-                                                            knownMonomials,  \
-                                                            protoMatrixRows, \
-                                                            columnsWidth)
                     internalIpower += pIdegree
                 # End for tPower
                 # The i^iPower * p^pPower * N^(alpha-pPower) i-shift.
@@ -507,18 +493,11 @@
                 currentExpression = i^iPower * nAtPower
                 currentPolynomial = pRing(currentExpression) * polynomialAtPower
                 polynomialsList.append(currentPolynomial) 
-                pMonomials = currentPolynomial.monomials()
-                pCoefficients = currentPolynomial.coefficients()
-                spo_add_polynomial_coeffs_to_matrix_row(pMonomials,      \
-                                                        pCoefficients,   \
-                                                        knownMonomials,  \
-                                                        protoMatrixRows, \
-                                                        columnsWidth)
             # End for iPower
         polynomialAtPower *= p  
         nAtPower /= N
     # End for pPower loop
-    return ((protoMatrixRows, knownMonomials, polynomialsList))
+    return((knownMonomials, polynomialsList))
 # End spo_polynomial_to_proto_matrix_2
 
 def spo_proto_to_column_matrix(protoMatrixColumns, \
