Ask Your Question

Determine rationality of an expression?

asked 2014-02-20 15:49:58 -0500

Jeremie gravatar image

updated 2014-03-30 09:03:57 -0500

tmonteil gravatar image

I am trying to determine whether an expression is rational or not - and if it rational, to get the numerator and denominator.

To give you some context, I first use "solve" to get a [ x == ..., y == ... ] solution, and then I compute log(solution[x])/log(solution[y]). In some cases, this expression is a rational. I would like to be able to determine when it is a rational.

Of course it is rational in some very predictable cases - i.e., when the two logarithms are commensurate, and there are ways of checking this on the value of solution[x] and solution[y] themselves. But I am hoping that sage can do this for me.

I tried to do Rational((log(...)/log(...)).n()) or (log(...)/log(...)).n() in QQ, but of course that does not work, as .n() converts the expression to some arbitrary precision float. Doing (log(...)/log(...)) in QQ always returns False even, for instance, for the case (log(100)/log(10)) = 2.

How can I do this?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2014-03-23 12:35:01 -0500

ndomes gravatar image

Indeed, it is strange.

sage:log(8.0)/log(32.0) in QQ; 
sage: log(8.0).parent()
Real Field with 53 bits of precision

As far as I can see the trouble comes from the Symbolic Ring.

sage:log(8)/log(32) in QQ; 
sage: log(8).parent()
Symbolic Ring
edit flag offensive delete link more

answered 2014-03-21 22:38:29 -0500

ndomes gravatar image

updated 2014-03-21 22:39:00 -0500

a = log(8)/log(32)
c = a.simplify_exp()
a; a in QQ; c; c in QQ
edit flag offensive delete link more


It is strange that "a in QQ" is False while "c in QQ" is True... moreover "a == c" is true !!!

vdelecroix gravatar imagevdelecroix ( 2014-03-22 04:18:37 -0500 )edit

The problem here is that the symbolic ring answers "False" when it does not know the answer.

tmonteil gravatar imagetmonteil ( 2014-03-25 10:10:56 -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


Asked: 2014-02-20 15:49:58 -0500

Seen: 169 times

Last updated: Mar 23 '14