How can I test if a number is irrational?
37 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Hello there,
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?
3 Kommentare
Walter Roberson
am 13 Jan. 2017
If you use
f1 = sym(2);
f2 = sqrt(sym(2));
a = f1/f2;
then the result will be the symbolic expression 2^(1/2) not the same as double(f1/f2) which will be 1.4142135623731 and not the same as 2/sqrt(2) or double(2/sqrt(2)) which will be 1.41421356237309 due to differences in roundoff in the intermediate expressions.
When you have the symbolic toolbox, sqrt(2) is still 1.4142135623731 not the symbolic expression 2^(1/2)
Antworten (5)
Guillaume
am 11 Jan. 2017
Bearbeitet: Guillaume
am 11 Jan. 2017
I don't think you've thought this through properly:
- 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.
3 Kommentare
Fahad
am 11 Okt. 2020
Even in the symbolic environment, there exists no automatic way (or algorithm) to know whether a number is irrational or not?
If you can tell us about the rationality/ irrationality of any number, please let us know.
Walter Roberson
am 11 Okt. 2020
No-one has been able to prove whether pi+e is rational or not. If there was an existing algorithm then the question would have been answered by using that algorithm.
Walter Roberson
am 11 Jan. 2017
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.
8 Kommentare
Walter Roberson
am 15 Jan. 2017
"Only positive and real numbers are to be considered for f1 and f2. No variables, only constants of any kind within real numbers. In terms of roots, I am only considering roots of integers or rationals. There is no restriction that it has to be specifically a square or cubic (or further) root."
Given two symbolic constants, f1 and f2, that involve only numbers and roots of integers or rationals, then MATLAB will automatically factor the rationals inside of roots and remove as much outside the root as possible. For example, (sym(5)/64)^sym(1/3) will be simplified to 5^(1/3)/4 . Therefore provided that MATLAB has been allowed to evaluate the symbolic expression at least once, then any remaining root contains only parts that could not be reduced, and you can be certain that the resulting root is not a rational number.
However, as mentioned by John D'Errico, it is not known whether Pi*e is rational, so if your f1 = Pi and f2 = exp(-1) then f1/f2 would be Pi*e and the rationality of that is not known.
This starts to allow us to build a table:
- f1 and f2 are each rational (including integer): result is rational and real
- f1 or f2 is rational (including integer) and the other still contains a root of a positive rational (including integer) after allowing MATLAB to simplify: result is irrational and real
- f1 or f2 is rational (including integer) and the other still contains a root of a negative rational (including integer) after allowing MATLAB to simplify: result is both irrational and complex
- f1 and f2 both contain roots of positive rationals (including integer), or both contain roots of negative rationals (including integer): allow MATLAB to simplify once, and if the result still contains a root, the result is irrational and real
- one of f1 and f2 contains pi but not e, and the other contains the other of the two, either plain or inside a root: the rationality of the result is probably not known and is probably difficult to prove
- one of f1 or f2 contains pi but not e, including inside a root, and the other does not contain either pi or e: I don't know; I suspect it might be difficult to prove. My suspicion is that the result is not rational
- one of f1 or f2 contains e but not pi, including inside a root, and the other does not contain either pi or e: I am not sure, but the material I read is suggestive that there might be ways to deal with this situation. My suspicion is that the result is not rational
- both f1 and f2 contain pi, including inside a root, or both contain e, including inside a root, but pi and e are not both present: let MATLAB simplify, and if the result still contains pi or e, then the result is irrational.
Rationals and integers and their roots are "algebraic numbers" and it seems plausible to me that if you multiply or divide an algebraic number and a transcendental that the result would be transcendental. The tricky parts come when you combine transcendental numbers.
The table is possibly reducible to this: let MATLAB simplify the expression f1/f2 . If the result contains both pi and e, then the answer is likely "Nobody knows"; if the result contains either pi or e but not both, then I think the result is irrational; if the result does not contain pi or e but contains a root, then the result is irrational; if the result is pure rational (or integer) then the result is rational.
This analysis does not, however, extend to the case where f1 or f2 can be expressions in constants if either addition or subtraction is permitted. MATLAB cannot reliably automatically factor additive expressions into their roots (though using the simplify() command with the 'steps' option helps.) For example it does not even automatically handle this well:
>> sqrt((x+1)^2)
ans =
((x + 1)^2)^(1/2)
The difficulty is reduced by the fact that MATLAB will automatically combine rational constants, but if the expression is over pi or e then MATLAB might not simplify:
Pi = sym('pi');
>> sqrt(expand((Pi+1)^2))/(Pi+1)
ans =
(2*pi + pi^2 + 1)^(1/2)/(pi + 1)
though simplify can help:
>> simplify(ans)
ans =
1
Christopher Creutzig
am 27 Mär. 2018
> Given two symbolic constants, f1 and f2, that involve only numbers and roots of integers or rationals, then MATLAB will automatically factor the rationals inside of roots and remove as much outside the root as possible.
That is not exactly true. E.g., MATLAB will not cancel sqrt(sym(6))/sqrt(sym(2)) by default. A call to simplify will.
John D'Errico
am 12 Jan. 2017
Bearbeitet: John D'Errico
am 13 Jan. 2017
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 =
10
D =
43
N/D
ans =
0.23256
[N,D] = rat(0.30000001,0.001)
N =
3
D =
10
Pick some reasonable tolerance, and don't worry about 40 digits.
David Goodmanson
am 16 Jan. 2017
Bearbeitet: David Goodmanson
am 16 Jan. 2017
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.
4 Kommentare
Walter Roberson
am 26 Mär. 2018
The surface area of a black hole is proportional to the amount of information encoded on it, so I am building a perpetual monument by inflating a black hole as quickly as I can!
LALE ASIK
am 23 Mär. 2018
Bearbeitet: LALE ASIK
am 23 Mär. 2018
May I ask you a question? Do you find a method how to test it?
6 Kommentare
Walter Roberson
am 27 Mär. 2018
For example, consider 43 and 179 with an fft bin width of 1. 43/179 is 0.240223463687151, which needs all of the decimals to express the ratio of frequencies as far as humans can easily perceive. But with the bin width of 1, the value could be between 42/180 and 44/178, and 42/180 is 0.233333333333333 which is 7/30 which people probably would consider rational.
Can we get a measure of rationality by using rat() and looking at the complexity of the continued fraction?
>> rat(43/179)
ans =
'0 + 1/(4 + 1/(6 + 1/(7)))'
>> rat(42/180)
ans =
'0 + 1/(4 + 1/(4 + 1/(-2)))'
>> rat(44/178)
ans =
'0 + 1/(4 + 1/(22))'
>> rat(pi)
ans =
'3 + 1/(7 + 1/(16))'
Ummm... No, apparently not. When rat(pi) shows up as less complex than the other values, we are in trouble. Unless, that is, we start adding in the tolerance to the rat() call:
>> rat(pi,1e-16)
ans =
'3 + 1/(7 + 1/(16 + 1/(-294 + 1/(3 + 1/(-4 + 1/(5 + 1/(-15)))))))'
But still, what we would tend to see as simple, 42/180, 0.23* comes out more complex than 44/178, 0.247191011235955, that we would struggle to see rationality in.
Siehe auch
Kategorien
Mehr zu Number Theory finden Sie in Help Center und File Exchange
Produkte
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!