Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

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,