Ask Your Question

Revision history [back]

Rational fractions are not simplified by default

sage: x = SR.var('x')
sage:  f = 1/(x-2) + 1/(x-3)
sage: f
1/(x - 2) + 1/(x - 3)

If you want to get one fraction just do

sage: f.simplify_rational()
(2*x - 5)/(x^2 - 5*x + 6)

The same manipulation applies for matrices

sage: m = matrix(2, [1/x, 1/(x+1), 1/(x+1), 1/x])
sage: m2 = m*m
sage: m2
[1/(x + 1)^2 + 1/x^2       2/((x + 1)*x)]
[      2/((x + 1)*x) 1/(x + 1)^2 + 1/x^2]
sage: m2.simplify_rational()
[(2*x^2 + 2*x + 1)/(x^4 + 2*x^3 + x^2)                           2/(x^2 + x)]
[                          2/(x^2 + x) (2*x^2 + 2*x + 1)/(x^4 + 2*x^3 + x^2)]