Ask Your Question
0

Simplifying rational expressions

asked 2017-10-10 23:22:04 -0500

Ant 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()+(-524288x^2 - 1048576xy - 524288y^2 + 524288xz + 524288yz)/(-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/2x^2 + xy + 1/2y^2 - 1/2xz - 1/2y*z)/z^2

(-524288x^2 - 1048576xy - 524288y^2 + 524288xz + 524288yz)/(-1048576*z^2)

0

(-524288x^2 - 1048576xy - 524288y^2 + 524288xz + 524288yz)/(-1048576*z^2)

(-524288x^2 - 1048576xy - 524288y^2 + 524288xz + 524288yz)/(-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 10:38:16 -0500 )edit

Welcome to Ask Sage!

To display inline code, use backticks. To display blocks of code or error messages, separate them by a blank line from the rest of the text, and indent them with 4 spaces, or select code lines and click the "code" button (the icon with '101 010').

For instance, typing

If we define `f` by

    def f(x, y):
        return (x, y)

then `f(2, 3)` returns `(2, 3)` but `f(2)` gives:

    TypeError: f() takes exactly 2 arguments (1 given)

will produce:

If we define f by

def f(x, y):
    return (x, y)

then f(2, 3) returns (2, 3) but f(2) gives:

TypeError: f() takes exactly 2 arguments (1 given)

Can you edit your question to do that?

slelievre gravatar imageslelievre ( 2017-10-15 03:07:51 -0500 )edit

2 answers

Sort by » oldest newest most voted
0

answered 2017-10-11 13:54:39 -0500

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 11:15:04 -0500 )edit
0

answered 2017-10-11 07:15:42 -0500

eric_g gravatar image

updated 2017-10-11 07:19:15 -0500

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 10:24:46 -0500 )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 14:00:42 -0500 )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-10 23:21:04 -0500

Seen: 65 times

Last updated: Oct 11