# How to eliminate denominators

Hi, I am trying to solve a system of linear equations symbolically, but the returned answers contain a common factor (probably signifies that the solution space is one-dimensional) and a common denominator. Is there a way to reduce them to the simplest form?

I am also interested in learning how one can turn a system of linear equations into matrix form.

Thank you!

edit retag close merge delete

Please provide a code example and the expected result.

( 2023-05-08 19:54:45 +0100 )edit

Like Max, I'm expecting clarification on ypur problem (i. e. sample code...).

For more enlightment, have a look at Robert Beezer's book, whic covers a lot of a first course in linear algebra, and a lot of Sage code related to this topic. And, as always, this free book is a sine qua non of learning to use Sage efficiently.

Finally, a hint : gcd?

( 2023-05-08 20:26:08 +0100 )edit

Sort by ยป oldest newest most voted

While expecting a real example, let's look at a possible application : explicit inverse of a matrix. Let

sage: M=matrix(var("m", n=9), nrows=3) ; M
[m0 m1 m2]
[m3 m4 m5]
[m6 m7 m8]


Its inverse is hardly legible :

sage: IM=(M^-1).apply_map(factor) ; IM
[ (m5*m7 - m4*m8)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8) -(m2*m7 - m1*m8)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)  (m2*m4 - m1*m5)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)]
[-(m5*m6 - m3*m8)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)  (m2*m6 - m0*m8)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8) -(m2*m3 - m0*m5)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)]
[ (m4*m6 - m3*m7)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8) -(m1*m6 - m0*m7)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)  (m1*m3 - m0*m4)/(m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8)]


The common denominator of the nine elements of this inverse is theit greatest common denominator, which can be computed by gcd :

sage: D=gcd(map(denominator, flatten(IM.list()))).factor() ; D
m2*m4*m6 - m1*m5*m6 - m2*m3*m7 + m0*m5*m7 + m1*m3*m8 - m0*m4*m8


and the inverse $IM$ can be written as the product of the inverse of this common denominator $D$ and the product of the original matrix by this denominator $\left(M\cdot D\right)$, which is :

sage: SIM = (IM*D).apply_map(factor) ; SIM
[ m5*m7 - m4*m8 -m2*m7 + m1*m8  m2*m4 - m1*m5]
[-m5*m6 + m3*m8  m2*m6 - m0*m8 -m2*m3 + m0*m5]
[ m4*m6 - m3*m7 -m1*m6 + m0*m7  m1*m3 - m0*m4]


The stucture of the inverse is much more understandable : one can almost "see" the Sarrus algorithm at work...

Check :

sage: SIM/D==IM
True


HTH,

more

Thank you! Got it :-)

( 2023-05-10 01:25:23 +0100 )edit