I am currently using Rationalize after NumberForm in order to check if the some values of my function are in the Rationals. Unfortunately, using NumberForm completely breaks Mathematica's output.
I have the following minimal reproducible example:
For[i = 1, i < 20, i += 1, (
x = Rationalize@NumberForm[i/(i + 1), 32];
If[Element[x, Rationals], Print[x]]
)]
The above code checks whether $\frac{i}{i+1}$ is rational, for integer $1\leq i<20$. Unexpectedly, it outputs nothing.
Even more unexpectedly, the following code, which is supposed to print $x$ no matter what, also outputs nothing:
For[i = 1, i < 20, i += 1, (
x = Rationalize@NumberForm[i/(i + 1), 32];
If[Element[x, Rationals], Print[x], Print[x]]
)]
Note the difference in the If clause.
So why does Mathematica fail to detect the rational values, even after
Rationalize?
I am using Mathematica 11.1.
Note that I added the bugs tag. Feel free to remove it if adequate.