Ask Your Question
2

Create Matrix in RREF with indeterminates

asked 2019-07-16 17:36:05 +0100

Bark gravatar image

updated 2019-07-16 17:44:09 +0100

Hi all,

I would like to be able to create a Matrix over a multivariable polynomial ring (in particular over R = PolynomialRing(QQ, 'x',(n-k)*n)) in Sage that has a particular form. I would like to create a $k \times n$ matrices that is in RREF form, where I can choose where the pivots should be and fill in the rest with variables from my polynomial ring. (I am assuming full rank, so there will be $k$ pivots with $n \choose k$ possible choices)

$\begin{bmatrix} 1 & x1 & 0 & x2 & \cdots\\ 0 & 0 & 1 & x3 & \cdots\\ 0 & 0 & 0 & 0 &\cdots \\ \vdots & \vdots & \vdots & \vdots & \ddots \end{bmatrix}$

Is there any way I can do this in Sage by just indicating which columns I want to have the pivots in?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2019-07-16 19:39:58 +0100

rburing gravatar image

updated 2019-07-16 19:43:04 +0100

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_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_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]
edit flag offensive delete link more

Comments

Thank you, this is perfect!

Bark gravatar imageBark ( 2019-07-17 07:36:00 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-07-16 17:36:05 +0100

Seen: 581 times

Last updated: Jul 16 '19