Determine rationality of an expression?

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

Sort by » oldest newest most voted
a = log(8)/log(32)
c = a.simplify_exp()
a; a in QQ; c; c in QQ

more

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

( 2014-03-22 10:18:37 +0200 )edit

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

( 2014-03-25 16:10:56 +0200 )edit

Indeed, it is strange.

sage:log(8.0)/log(32.0) in QQ;
True
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;
False
sage: log(8).parent()
Symbolic Ring

more