Ask Your Question
0

numerator_denominator()

asked 2013-10-16 11:58:48 -0500

alessandro gravatar image

I have a very big rational function and i want to obtain the numerator and denominator. with .numerator_denominator() it takes forever with .numerator_denominator(False) not every term is expanded. with .expand() and .combine() it takes forever and the result is not a single fraction.

I need a single fraction N(x)/D(x) where N and D are polynomials in x, it is not important how big !

edit retag flag offensive close merge delete

4 answers

Sort by ยป oldest newest most voted
0

answered 2013-10-16 12:24:33 -0500

tmonteil gravatar image

updated 2013-10-16 12:33:53 -0500

What happens with your big rational function if, instead of working with symbolic functions, you work in the FunctionField ?

sage: K.<x> = FunctionField(QQ) ; K
Rational function field in x over Rational Field
sage: f = K(3*x/(4*(x^2+1))+ x^2/(3*x^3-5))
sage: f.numerator()
13*x^4 + 4*x^2 - 15*x
sage: f.denominator()
12*x^5 + 12*x^3 - 20*x^2 - 20

Or in the FractionField ?

sage: K = FractionField(PolynomialRing(QQ,'x')) ; K
Fraction Field of Univariate Polynomial Ring in x over Rational Field
sage: f = K(3*x/(4*(x^2+1))+ x^2/(3*x^3-5))
sage: f.numerator()
13*x^4 + 4*x^2 - 15*x
sage: f.denominator()
12*x^5 + 12*x^3 - 20*x^2 - 20

Does one of them work ? Which is faster ? Otherwise, could you give us an example of "big rational function" ?

edit flag offensive delete link more
0

answered 2013-10-18 14:01:16 -0500

alessandro gravatar image

This seems a good idea.

But I have an expression of type 'sage.symbolic.expression.Expression' that contains a variable s of the same type.

When I use your approach I have/handle objects of type 'sage.rings.function_field.function_field_element.FunctionFieldElement_rational' after constructing a Rational function field in s over Symbolic Ring (of type sage.rings.function_field.function_field.RationalFunctionField_with_category')

SO THE ONE s (in the expression) is NOT the s in the function field element...

If I do the conversion with K(expr) the whole expr is considered as a block and is not "parsed" for s... So when then I call denominator I always get 1

How can this be fixed/handled ?

Thanx you !

edit flag offensive delete link more

Comments

Could you provide an example of such an expression so that i can try to work with it ?

tmonteil gravatar imagetmonteil ( 2013-10-18 22:43:57 -0500 )edit

I answered your question in [this post](http://ask.sagemath.org/question/3106/conversions-fromto-functionfieldsr-and-symbolic?answer=4198#4198)

tmonteil gravatar imagetmonteil ( 2013-10-20 06:00:51 -0500 )edit
0

answered 2013-10-17 09:34:14 -0500

alessandro gravatar image

I have symbolic coefficients...

Thank you

edit flag offensive delete link more
0

answered 2013-10-17 23:48:57 -0500

tmonteil gravatar image

updated 2013-10-18 06:19:53 -0500

In this case, you can try with

sage: K.<x> = FunctionField(SR)

or

K = FractionField(PolynomialRing(SR, 'x'))

I am not sure how big are your rational functions, but if i do:

sage: f = sum(K.random_element() for i in range(100))
sage: f.numerator() 
...
sage: f.denominator()
....

and this is almost instantaneous.

edit flag offensive delete link more

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: 2013-10-16 11:58:48 -0500

Seen: 657 times

Last updated: Oct 18 '13