Ask Your Question
0

numerator_denominator()

asked 2013-10-16 18:58:48 +0100

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-18 06:48:57 +0100

tmonteil gravatar image

updated 2013-10-18 13:19:53 +0100

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
0

answered 2013-10-17 16:34:14 +0100

alessandro gravatar image

I have symbolic coefficients...

Thank you

edit flag offensive delete link more
0

answered 2013-10-18 21:01:16 +0100

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-19 05:43:57 +0100 )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 13:00:51 +0100 )edit
0

answered 2013-10-16 19:24:33 +0100

tmonteil gravatar image

updated 2013-10-16 19:33:53 +0100

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

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 18:58:48 +0100

Seen: 4,957 times

Last updated: Oct 18 '13