# Simplifying rational expressions

I am working with a power series with coefficients being rational functions of several variables (everything over QQ). Is there any way to make sage automatically simplify the coefficients?

Here is an example of what is going on

k=RR.zero()+(-524288*x^2 - 1048576*x*y - 524288*y^2 + 524288*x*z + 524288*y*z)/(-1048576*z^2)
print k
print u
print u-k
print (simplify(u))
print u
print parent(u)
print parent(k)
print factor(u.numerator())/factor(u.denominator())


And results:

(1/2*x^2 + x*y + 1/2*y^2 - 1/2*x*z - 1/2*y*z)/z^2
(-524288*x^2 - 1048576*x*y - 524288*y^2 + 524288*x*z + 524288*y*z)/(-1048576*z^2)
0
(-524288*x^2 - 1048576*x*y - 524288*y^2 + 524288*x*z + 524288*y*z)/(-1048576*z^2)
(-524288*x^2 - 1048576*x*y - 524288*y^2 + 524288*x*z + 524288*y*z)/(-1048576*z^2)
Fraction Field of Multivariate Polynomial Ring in x, y, z over Rational Field
Fraction Field of Multivariate Polynomial Ring in x, y, z over Rational Field
(-1/2) * z^-2 * (-x - y + z) * (x + y)

edit retag close merge delete

You should rather use ZZ than QQ, namely

sage: R.<x,y,z> = ZZ[]
sage: u = (-524288*x^2 - 1048576*x*y - 524288*y^2 + 524288*x*z + 524288*y*z)/(-1048576*z^2); u

( 2017-10-11 17:38:16 +0200 )edit

Sort by » oldest newest most voted

sage: R.<x,y,z> = QQ[]
sage: u = (-524288*x^2 - 1048576*x*y - 524288*y^2 + 524288*x*z + 524288*y*z)/(-1048576*z^2)
sage: factor(u)
(-1/2) * z^-2 * (-x - y + z) * (x + y)

more

That actually works, thanks! And now if I have a power series with coefficients in ring R as in your answer above, is there any way to make sage automatically simplify the coefficients without calling factor() for them? I am computing rather complicated expressions with a lot of steps, so I don't even know at what point I would need to call for it if I had to do it manually

( 2017-10-11 17:24:46 +0200 )edit

This is an other question.

And in the above answer there is no power series. So if the power series should be really considered over R, make it clear, e.g. instead of ...a power series with coefficients in ring R as in your answer above... better let R be as above, and let us consider a power series with coefficients in R. And give that series explicitly, so we have an example where something was not simplified. What is "it" in so I don't even know at what point I would need to call for it if I had to do it manually ? The factor method? (That we tried to avoid in the previous line.)

( 2017-10-11 21:00:42 +0200 )edit

The obvious try works already:

sage: var( 'x,y,z' );
sage: E = (-524288*x^2 - 1048576*x*y - 524288*y^2 + 524288*x*z + 524288*y*z)/(-1048576*z^2)
sage: E
1/2*(x^2 + 2*x*y + y^2 - x*z - y*z)/z^2
sage: E.factor()
1/2*(x + y - z)*(x + y)/z^2
sage: E.simplify_full()
1/2*(x^2 + 2*x*y + y^2 - (x + y)*z)/z^2
sage: version()
'SageMath version 8.0, Release Date: 2017-07-21'


Notes:

• Why RR.zero()...?
• Please define also x,y,z when these variables are used.
• u was not defined.
• Please give code pointed for the question. The question was

Is there any way to make sage automatically simplify the coefficients?

and in the list of answers there is also:

(1/2x^2 + xy + 1/2y^2 - 1/2xz - 1/2y*z)/z^2

This is simplified enough for my taste.

• And the mix of xy with y*z is really not welcome. My first thought was, that xy was the error.
more

Let R be as in answer above (rational functions of x,y and z). Now let's consider R((q)) -formal Laurent series with coefficients in R. My problem is that sage keeps coefficients of those series not simplified (probably it thinks that all rational numbers are units and hence all the same) and also expanded. Now if I multiply two such series the coefficients become even worse (in sage's representation, but I know they can be simplified). So my question is: is there a way to make sage keep automatically simplifying coefficients every time I perform operations on Laurent series? Also I would really prefer if the coefficients were saved in a factored form if possible. Even if I call factor() for coefficients, when I print a series, the coefficients are in the expanded form.

( 2017-10-12 18:15:04 +0200 )edit