Interesting pattern came up as I go through the homework replies of my students. Why is there no
RealQ? We have
Real as type restrictors / heads in pattern matching, like
_Real. Why no Qs for them?
There is a
The difference between the two:
Developer`RealQ is a test for arbitrary precision numbers, while
Developer`MachineRealQ checks whether its input is a double precision number.
Notice that both return
Compare this to
As Szabolcs and Sjoerd pointed out, these tests are for data types and not tests in mathematical sense. For example, we also have the following:
IntegerQ[(1 - Sqrt) (1 + Sqrt)] IntegerQ[Simplify[(1 - Sqrt) (1 + Sqrt)]]
A somewhat more mathematical test seems to be
Assumptions`ARealQ[(1 - Sqrt) (1 + Sqrt)]
But as it is undocumented, I really don't know what does it do.
And on top of that, we have
Assumptions`ARationalQ, quite a mysterious beast:
Assumptions`ARationalQ[(1 - Sqrt) (1 + Sqrt)] Assumptions`ARationalQ[1/2] Assumptions`ARationalQ Assumptions`ARationalQ[I] Assumptions`ARationalQ[1.]
Not to mention
Reduce`RationalNumberQ which behaves similarly erratic.
Why no RationalQ or RealQ?
Probably because it isn't unambiguous what such a function should do. From the comments above:
If there were a
RationalQ, I'd expect
But many other users would expect something like this:
IntegerQ there aren't such conflicting expectations.