- Nobody knows a way to find whether an arbitrary number is irrational.
- By definition, all numbers stored on a computer (in IEE754 format) are rationals, since they're all fractions of powers of 2.
How can I test if a number is irrational?
조회 수: 43(최근 30일)
In digital signal processing, one indicator that a signal may be quasi-periodic is that the ratio between the pair of frequencies (f1/f2) provides an irrational number as result. What I want to do is check if the result is irrational or not in the form of a function, just as ge(a,b) returns a boolean relative to 'a' being greater or equal to 'b' or not. However, I was not able to find any function appropriate for this (and no other posts regarding this too).
P.S.: I know that the user will know if (s)he is inputing an irrational number. As silly as it seems, I still want to display a message saying whether it is periodic or quasi-periodic. By the way, of course, there is still the possibility of inputing two irrational numbers, one for each frequency, and having a rational result. This is why such a check becomes helpful.
EDIT 1: As an addition, I guess the aformentioned may have mislead most of you to believe that I wanted MATLAB to tell me if a number is rational or not only by its double or int value. However, I'm thinking about what is going in the Symbolic Toolbox level.
Take, for instance, these parameters:
f1 = 2;
f2 = sqrt(2);
a = f1/f2;
Provides (or must provide) in symbolical level...
a = sqrt(2);
Since I can work, for instance, with functions. I'm considering that this is different from
a = double(f1/f2);
We know that if we type this, say, in the command window, f1/f2 will yield the same as double(f1/f2), but the processing is not exactly the same for these cases. My knowledge on MATLAB may fail at this point, but I believe that in some point in the processing of data, f1/f2 still is a symbolic value before it is converted to double to be displayed. That is the level of processing that I'm trying to work with. It seems reasonable to me that, at this stage, it may be easy to infer the "class" of our symbolic number... or isn't it?
Walter Roberson 2017년 1월 11일
In MATLAB, all numbers that can be expressed in the data types uint8, uint16, uint32, uint64, int8, int16, int32, int64, and logical are definitely rational. For the data types single and double, the only values that can be expressed that are not rational are -inf, +inf, and NaN, but those values are also not irrational (they are not, strictly speaking, numbers.)
Therefore the only way numbers could be entered that might potentially be irrational is if they are entered as strings, either as named constants or as expressions like sqrt(2) and you would have to proceed from there.
John D'Errico 2017년 1월 12일
편집: John D'Errico 2017년 1월 13일
You say there should be some simple way to know if a symbolic toolbox result is rational or not. Note that as simple a question of whether pi+exp(1) is rational is unproven as far as I can see.
You can want a nice simple solution to exist. But nice simple solutions are not always available.
You talk about a ratio between a pair of frequencies as a rational number. To me, this is silly, that you are worried about something being EXACTLY representable as a rational number, beyond 16 significant digits. Instead, you might just look if the ratio is well approximated by a fraction with a reasonably small denominator.
[N,D] = rat(.2324343434232,0.001)
[N,D] = rat(0.30000001,0.001)
Pick some reasonable tolerance, and don't worry about 40 digits.
David Goodmanson 2017년 1월 16일
편집: David Goodmanson 2017년 1월 16일
Hello Alexandre, although your interest is along conceptual lines, still it's fun to look at practical consequences. Supposing the two frequencies are high, up around the GHz cell phone range, and have all 16 digits of double precision:
f1 = 1234567890123456e-6
f1 = 1234567890123457e-6
If f1 and f2 are incommensurate (gcd = 1) as in this example, and supposing you had frequency stability of better than one part in 10^16 (which isn't going to happen outside of a metrology lab) then it will take 1e6 seconds before the carrier pattern repeats, or about 12 days. Not even Heloise and Abelard would be on the phone that long.
There is of course a big difference philosophically, but when you get enough digits the distinction between incommensurate and 'irrational ratio' becomes moot.