Index: pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage
===================================================================
--- pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage	(revision 0)
+++ pobysoPythonSage/src/sageSLZ/sagePolynomialOperations.sage	(revision 74)
@@ -0,0 +1,139 @@
+load "/home/storres/recherche/arithmetique/pobysoPythonSage/src/sageSLZ/sageMatrixOperations.sage"
+
+def spo_polynomial_to_matrix(p, pRing, alpha, N, columnWidth=0):
+    """
+    From a (bivariate) polynomial and some other parameters build a matrix
+    to be reduced by fpLLL.
+    The matrix is such as those found in Boneh-Durphy and Stehlé.
+    
+    p: the (bivariate) polynomial
+    alpha:
+    N:
+    
+    """
+    pVariables = p.variables()
+    iVariable = pVariables[0]
+    tVaraible = pVariables[1]
+    polynomialAtPower = P(1)
+    currentPolynomial = P(1)
+    pIdegree = p.degree(pVariables[0])
+    pTdegree = p.degree(pVariables[1])
+    currentIdegree = currentPolynomial.degree(i)
+    nAtPower = N^alpha
+    # We work from p^0 * N^alpha to p^alpha * N^0
+    for pPower in xrange(0, alpha + 1):
+        # pPower == 0 is a special case. We introduce all the monomials in
+        # i, those in t and the mixed one necessary to be able to introduce
+        # p and only a one monomial (our (arbitrary) choice is, at this point,
+        # to add i to it's maximum power in p.
+        if pPower == 0:
+            # iter1: power of i
+            # Notice how i^pIdegree is excluded.
+            for iPower in xrange(0, pIdegree): 
+                # iter5: power of t.
+                for tPower in xrange(0, pTdegree + 1):
+                    if columnWidth != 0:
+                        print "->", spo_expression_as_string(iter1, 
+                                                             iter5, 
+                                                             iter0, 
+                                                             alpha)
+                    currentExpression = iVariable^iPower * \
+                                        tVariable^tPower * nAtPower
+                    # polynomialAtPower == 1 here. Next line should be commented out but it does not work!
+                    # Some convertion problem?
+                    currentPolynomial = pRing(currentExpression) * \
+                                        polynomialAtPower 
+                    pMonomials = currentPolynomial.monomials()
+                    pCoefficients = currentPolynomial.coefficients()
+                    add_polynomial_coeffs_to_matrix(pMonomials, pCoefficients, knownMonomials, protoMatrixRows, monomialLengthChars)
+                # End iter5.
+            # End for iter1.
+            
+    else: # Next runs (p^1..p^alpha)
+        pass
+    
+# End spo_polynomial_to_matrix
+
+def spo_add_polynomial_coeffs_to_matrix(pMonomials, 
+                                        pCoefficients, 
+                                        knownMonomials, 
+                                        protoMatrixRows, 
+                                        columnWidth=0):
+    """
+    For a given polynomial (under the form of monomials and coefficents lists),
+    add the coefficients of the protoMatrix (a list of proto 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;
+    protoMatrixRows: a list of lists, each one holding the coefficients of the 
+                     monomials
+    columnWith     : the width, in characters, of the displayed column ; if 0, 
+                     do display anything.
+    """
+    # We have started with the smaller degrees in the first variable.
+    pMonomials.reverse()
+    pCoefficients.reverse()
+    # New empty proto matrix row.
+    protoMatrixRowCoefficients = []
+    # We work according to the order of the already known monomials
+    # No known monomials yet: add the pMonomials to knownMonomials 
+    # and add the coefficients to the proto matrix row.
+    if len(knownMonomials) == 0: 
+        for pmIdx in xrange(0, len(pMonomials)):
+            knownMonomials.append(pMonomials[pmIdx])
+            protoMatrixRowCoefficients.append(pCoefficients[pmIdx])
+            if columnWidth != 0:
+                monomialAsString = str(pCoefficients[pmIdx]) + " " + \
+                                   str(pMonomials[pmIdx])
+                print monomialAsString, " " * \
+                      (columnWidth - len(monomialAsString)),
+    # There are some known monomials. We search for them in pMonomials and 
+    # add their coefficients to the proto matrix row.
+    else: 
+        for knownMonomialIndex in xrange(0,len(knownMonomials)):
+            # We lazily use an exception here since pMonomials.index() function
+            # may fail throwing the ValueError exception.
+            try:
+                indexInPmonomials = \
+                    pMonomials.index(knownMonomials[knownMonomialIndex])
+                if columnWidth != 0:
+                    monomialAsString = str(pCoefficients[indexInPmonomials]) + \
+                        " " + str(knownMonomials[knownMonomialIndex])
+                    print monomialAsString, " " * \
+                        (columnWidth - len(monomialAsString)),
+                # Add the coefficient to the proto matrix row and delete the \
+                # known monomial from the current pMonomial list 
+                #(and the corresponding coefficient as well).
+                protoMatrixRowCoefficients.append(pCoefficients[indexInPmonomials])
+                del pMonomials[indexInPmonomials]
+                del pCoefficients[indexInPmonomials]
+            # The knownMonomials element is not in pMonomials
+            except ValueError:   
+                protoMatrixRowCoefficients.append(0)
+                if columnWidth != 0:
+                    monomialAsString = "0" + " "+ \
+                        str(knownMonomials[knownMonomialIndex])
+                    print monomialAsString, " " * \
+                        (columnWidth - len(monomialAsString)),
+        # End for knownMonomialKey loop. 
+        # We now append the remaining monomials of pMonomials to knownMonomials 
+        # and the corresponding coefficients to proto matrix row.
+        for pmIdx in xrange(0, len(pMonomials)):
+            knownMonomials.append(pMonomials[pmIdx])
+            protoMatrixRowCoefficients.append(pCoefficients[pmIdx])
+            if columnWidth != 0:
+                monomialAsString = str(pCoefficients[pmIdx]) + " " \
+                    + str(pMonomials[pmIdx])
+                print monomialAsString, " " * \
+                    (columnWidth - len(monomialAsString)),
+        # End for pmIdx loop.
+    # Add the new list row elements to the proto matrix.
+    protoMatrixRows.append(protoMatrixRowCoefficients)
+    if columnWidth != 0:
+        print    
+# End spo_add_polynomial_coeffs_to_matrix
Index: pobysoPythonSage/src/sageSLZ/sageMatrixOperations.sage
===================================================================
--- pobysoPythonSage/src/sageSLZ/sageMatrixOperations.sage	(revision 0)
+++ pobysoPythonSage/src/sageSLZ/sageMatrixOperations.sage	(revision 74)
@@ -0,0 +1,46 @@
+def is_lower_triangular_matrix(mat):
+    """
+    Check that the matrix is lower triangular.
+    """
+    dimensions = mat.dimensions()
+    # Must be a bidimensional matrix.
+    if len(dimensions) != 2:
+        return False
+    # Must be square.
+    if dimensions[0] != dimensions[1]:
+        return False
+    # A 1x1 matrix is lower triangular.
+    if dimensions[0] == 1:
+        return True
+    for rowIndex in xrange(0, dimensions[0]):
+        for colIndex in xrange(rowIndex + 1, dimensions[1]):
+            if mat[rowIndex, colIndex] != 0:
+                print mat.rows()[rowIndex]
+                return False
+    return True
+# End is_lower_triangular_matrix
+
+def is_diagonal_complete_matrix(mat):
+    """
+    Check that all the element on the diagonal are not 0.
+    """
+    dimensions = mat.dimensions()
+    # Must be a bidimensional matrix.
+    if len(dimensions) != 2:
+        return False
+    # Must be square.
+    if dimensions[0] != dimensions[1]:
+        return False
+    # A 1x1 matrix is diagonal complete if it's single element is not 0.
+    if dimensions[0] == 1:
+        if mat[0, 0] != 0:
+            return True
+        else:
+            return False
+    # End if
+    for rowIndex in xrange(0, dimensions[0]):
+        if mat[rowIndex, rowIndex] == 0:
+            print mat.rows()[rowIndex], rowIndex
+            return False
+    return True
+# End is_diagonal_complete_matrix
\ No newline at end of file
