Ask Your Question
0

Simplifying rational expressions

asked 2017-10-11 06:22:04 +0100

Ant gravatar image

updated 2018-07-17 09:55:52 +0100

slelievre gravatar image

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 flag offensive close merge delete

Comments

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
FrédéricC gravatar imageFrédéricC ( 2017-10-11 17:38:16 +0100 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2017-10-11 14:15:42 +0100

eric_g gravatar image

updated 2017-10-11 14:19:15 +0100

What about

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)
edit flag offensive delete link more

Comments

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

Ant gravatar imageAnt ( 2017-10-11 17:24:46 +0100 )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.)

dan_fulea gravatar imagedan_fulea ( 2017-10-11 21:00:42 +0100 )edit
0

answered 2017-10-11 20:54:39 +0100

dan_fulea gravatar image

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.
edit flag offensive delete link more

Comments

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.

Ant gravatar imageAnt ( 2017-10-12 18:15:04 +0100 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-10-11 06:21:04 +0100

Seen: 2,503 times

Last updated: Jul 17 '18