Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have two matrices A, B with same number of rows. I want lattice reduction on B. During this reduction, I change rows of A accordingly. That is if i-th row and j-th row in B interchanges, swap i-th row and j-th row of A. Similar for other elementary row operations.

How can I do efficiently this in Sage or other software?

share|cite|improve this question
Apparently it's not possible to undo a close vote. I voted to close because I thought this belonged to cs.SE, but then realized it's about math software. Please ignore the close vote. – joriki Jul 15 '11 at 7:31
You haven't accepted any of the answers to your previous questions -- were they not acceptable? – joriki Jul 15 '11 at 7:32
@joriki: redirecting people to cs.SE from here is generally not such a good idea, as that site is explicitly intended for research level questions. They are about as strict as MO about that. Yes, you can't undo a close vote, but leaving a comment as you did should be sufficient. (while I'm at it I vote against closing, just to be sure). – t.b. Jul 15 '11 at 13:14
It seems that the same question was asked here:… – Martin Sleziak Jul 19 '11 at 12:21
If you were doing this by hand, you would probably form a large matrix with $B$ as the left block and $A$ as the right block. Then simply carry whichever row operations you wanted to do to this composite matrix. In the end you would separate the blocks again, and exact same row operations had been done to the two blocks. I am unfamiliar with Sage, so I don't know how easy it it is to form a matrix by combinining two blocks with its set of commands. @Martin may be able to say something more about that? – Jyrki Lahtonen Jul 19 '11 at 14:06

An easy, naive (but probably not effective) approach: If $C$ is obtained from $B$ using some row operations, this means that $C=RB$ for some regular matrix $R$.

If you select some columns of $C$ and the same columns of $B$ in a such way that you get a square regular matrix, you can compute $R=CB^{-1}$. As soon as you have $R$ you just need to multiply $RA$ to get what you want.

If you had your own implementation of the reduction algorithm, you could modify it easily in a such way, that it would also store the matrix $R$ somewhere. It is also possible, that the implementation in some math software computes this matrix. (I had a look at help for LLL-algorithm in Maple and Mathematica, but I did not find there anything about possibility of obtaining this matrix.)

share|cite|improve this answer
Thank you all for the effort. Now I am trying to write LLL algorithm in Sage to solve the problem. – user12290 Jul 20 '11 at 8:47

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.