There is a built-in method for that, which is .simplify_full()
.
It can be applied to any matrix with entries in the symbolic ring.
To illustrate it, we define k
as a symbolic variable, and build the matrix in the question.
sage: k = SR.var('k')
sage: a = identity_matrix(SR, 3)
sage: b = vector([
....: (2 * (2 / (k - 2) - 3)) / (k - 1),
....: 2 / (k - 2) - 2 / ((k - 1) * (k - 2)),
....: 2 / (k - 1)
....: ])
....:
sage: m = a.augment(b, subdivide=True)
Then m
is as follows:
sage: m
[ 1 0 0| 2*(2/(k - 2) - 3)/(k - 1)]
[ 0 1 0|2/(k - 2) - 2/((k - 1)*(k - 2))]
[ 0 0 1| 2/(k - 1)]
sage: show(m)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrr|r}
1 & 0 & 0 & \frac{2 \, {\left(\frac{2}{k - 2} - 3\right)}}{k - 1} \\
0 & 1 & 0 & \frac{2}{k - 2} - \frac{2}{{\left(k - 1\right)} {\left(k - 2\right)}} \\
0 & 0 & 1 & \frac{2}{k - 1}
\end{array}\right)
Applying the .simplify_full()
method applies simplify_full
to each entry, giving the expected result.
sage: mm = m.simplify_full()
sage: mm
[ 1 0 0 -2*(3*k - 8)/(k^2 - 3*k + 2)]
[ 0 1 0 2/(k - 1)]
[ 0 0 1 2/(k - 1)]
sage: show(mm)
\newcommand{\Bold}[1]{\mathbf{#1}}\left(\begin{array}{rrrr}
1 & 0 & 0 & -\frac{2 \, {\left(3 \, k - 8\right)}}{k^{2} - 3 \, k + 2} \\
0 & 1 & 0 & \frac{2}{k - 1} \\
0 & 0 & 1 & \frac{2}{k - 1}
\end{array}\right)
Providing this method for matrices with entries in the symbolic ring
was the object of
which was merged in the development release Sage 6.9.rc0 and in the stable release Sage 6.9.
solution.simplify_full()
should work. See fuller answer below. $\endgroup$