ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 30 Dec 2015 09:58:21 -0600Run LCM fractionshttps://ask.sagemath.org/question/31915/run-lcm-fractions/ I am doing some matrix multiplications, and as result I get
![image description](http://i.imgur.com/DdUz2Ec.jpg)
Now see position 1,1 of the matrix: I want SageMath to return me a result that has only one fraction (using LCM), not two fractions. Which command should I use?Wed, 30 Dec 2015 09:12:07 -0600https://ask.sagemath.org/question/31915/run-lcm-fractions/Answer by vdelecroix for <p>I am doing some matrix multiplications, and as result I get</p>
<p><img alt="image description" src="http://i.imgur.com/DdUz2Ec.jpg"/></p>
<p>Now see position 1,1 of the matrix: I want SageMath to return me a result that has only one fraction (using LCM), not two fractions. Which command should I use?</p>
https://ask.sagemath.org/question/31915/run-lcm-fractions/?answer=31916#post-id-31916Rational 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)]Wed, 30 Dec 2015 09:58:21 -0600https://ask.sagemath.org/question/31915/run-lcm-fractions/?answer=31916#post-id-31916