# numerator_denominator()

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

Sort by ยป oldest newest most voted

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" ?

more

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 !

more

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

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

( 2013-10-20 06:00:51 -0500 )edit

I have symbolic coefficients...

Thank you

more

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.

more