Processing math: 50%

First time here? Check out the FAQ!

Ask Your Question
2

Create Matrix in RREF with indeterminates

asked 5 years ago

Bark gravatar image

updated 5 years ago

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×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?

Preview: (hide)

1 Answer

Sort by » oldest newest most voted
2

answered 5 years ago

rburing gravatar image

updated 5 years ago

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]
Preview: (hide)
link

Comments

Thank you, this is perfect!

Bark gravatar imageBark ( 5 years ago )

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: 5 years ago

Seen: 627 times

Last updated: Jul 16 '19