Ask Your Question

Revision history [back]

Here's a way. First we define our variables:

k = 2
n = 3
R = PolynomialRing(QQ, 'x',(n-k)*k)

Then we introduce the following function:

def indet_rref(k, n, pivots, ring):
    assert len(pivots) == k and sorted(pivots) == list(pivots)
    M = Matrix(ring, k, n)
    taken = []
    for (row, pivot) in enumerate(pivots):
        M[row, pivot] = 1
        taken.extend((i, pivot) for i in range(k))
        taken.extend((row,j) for j in range(pivot))
    indet_nonzeros = [(i,j) for i in range(k) for j in range(n) if not (i,j) in taken]
    for (idx, y) in zip(indet_nonzeros, ring.gens()):
        M[idx] = y
    return M

The pivots argument is a list of k column indices (one per row), and the generators of ring are taken as the indeterminates.

For example:

sage: indet_rref(k, n, range(k), R)
[ 1  0 x0]
[ 0  1 x1]

We can test all the combinations:

import itertools
for pivots in itertools.combinations(range(n), k):
    M = indet_rref(k, n, pivots, R)
    assert M.rref() == M
    assert M.rank() == k
    print M
    print

Output:

[ 1  0 x0]
[ 0  1 x1]

[ 1 x0  0]
[ 0  0  1]

[0 1 0]
[0 0 1]

Here's a way. First we define our variables:

k = 2
n = 3
R = PolynomialRing(QQ, 'x',(n-k)*k)

Then we introduce the following function:

def indet_rref(k, n, pivots, ring):
    assert len(pivots) == k and sorted(pivots) == list(pivots)
    M = Matrix(ring, k, n)
    taken = []
    for (row, pivot) in enumerate(pivots):
        M[row, pivot] = 1
        taken.extend((i, pivot) for i in range(k))
        taken.extend((row,j) for j in range(pivot))
    indet_nonzeros indet_indices = [(i,j) for i in range(k) for j in range(n) if not (i,j) in taken]
    for (idx, y) in zip(indet_nonzeros, zip(indet_indices, ring.gens()):
        M[idx] = y
    return M

The pivots argument is a list of k column indices (one per row), and the generators of ring are taken as the indeterminates.

For example:

sage: indet_rref(k, n, range(k), R)
[ 1  0 x0]
[ 0  1 x1]

We can test all the combinations:

import itertools
for pivots in itertools.combinations(range(n), k):
    M = indet_rref(k, n, pivots, R)
    assert M.rref() == M
    assert M.rank() == k
    print M
    print

Output:

[ 1  0 x0]
[ 0  1 x1]

[ 1 x0  0]
[ 0  0  1]

[0 1 0]
[0 0 1]