Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

A friend of mine using version 9 recently showed me this:

enter image description here

It's strange because in version 8.0.4 1.2 ∈ Rationals does return False:

enter image description here

I checked the online document of Element and Rationals, no modification is mentioned. So it's a silent changing, or a bug?

share|improve this question
I just want to clarify that Element does not check data types (a programming concept). It checks whether a value is mathematically rational. It makes sense that it is unknown whether an inexact number is rational or not. Inexact means that it is known only to a finite precision. So I'd call that v8 behaviour a bug and the v9 behaviour correct. –  Szabolcs May 3 at 13:43
I agree with @Szabolcs. The V.9 behavior is more consistent with the underlying concept of "approximate number". –  m_goldberg May 3 at 14:31
Also, the Mathematica 8 result is arguably wrong because a floating point number is always a rational number of the form $m/2^n$. –  celtschk May 3 at 16:14
@Szabolcs OK……what about posting this as an answer so I can accept it? –  xzczd May 5 at 2:03
@celtschk well, arguably. But Szabolcs's point that Mathematica's numerical model treats floating point numbers as being distributions on the reals rather than exact rationals would tend to argue against that interpretation in this case. If you want to treat any FP number as a rational, you can always use SetPrecision on it. (Of course, things get a bit fuzzy when we start to consider comparisons between these distributions...) –  Oleksandr R. May 5 at 5:04

1 Answer 1

Just to illustrate Szabolcs's comments, see the behaviour of:

Element[1., Rationals]

This returns the input.



This returns True (as expected)



This returns True.

share|improve this answer
It would be better if you were to show the results rather than asking people copy your code and do the evaluation. Why make them repeat the work you have already done? –  m_goldberg May 3 at 14:23
@m_goldberg thank you for appropriate criticism. I have edited answer to be more useful. –  ubpdqn May 4 at 2:39
Hmm……I'm afraid that the second example isn't proper. Consider Element[IntegerPart[Sqrt[2]], Rationals]. –  xzczd May 5 at 2:01
@xzczd yes I guess I was just trying to contrast 1. with 1 as per szabolcs comment...so I have adjusted to Rationaloze which will address your point –  ubpdqn May 5 at 2:34

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.