I tried to check the rational or irrational numbers after we take the square root. i dont get the formula. for eg. squareroot of 64 is 8 and it is rational. square root of 2 is irrational. how to check it in c++..
check the rational or irrational numbers after we take the square root
Collapse
X
-
As I recall, a rational number is one integer divided by another. Like 2/3. There's no square root involved. Note that 2/3 is a rational number but 0.6666667 is not because it is not of the form x/y.
The divisor integer cannot be zero.
The square root of 2 is irrational because it cannot be represented by some x/y.
So, I'm not sure what you are doing. If your number is not of the form x/y then it is not rational. -
Calculate your square root using only integer variables. Then square your result and compare it to the original number. If the compare is true the number is rational.
Using integer variables, the square root of 2 is 1, which when squared does not equal 2. Therefore, the square root of 2 is irrational.
Please note that the square root of 64 is 8 but 8 is not a rational number because it is not of the form x/y. You would need to say 8/1 or 64/8 since either would be 8.Comment
-
A floating point number (f) is typically represented by three integer values: significand (c), exponent (q), and the [implied] base (b), where f = c * (b^q). This implies that all representable floating point numbers are rational. For example, the square root of 2 is irrational, but the value returned by sqrt(2.) is rational.
Checking if the square of the sqrt() value matches the original integer only tells you if the square root is representable. While, all irrational numbers are unrepresentable , there are also unrepresentable rational numbers (for example, 1/3 -- when the base is two).
I don't know offhand how to predict which square roots are rational and which aren't. The first place I would look is to review the classical proof of the irrationality of the square root of two. Perhaps you can generalize the logic.Comment
-
You can't use sqrt because it uses floating point. Floating point is not represented by x/y where x and y are integers. Due to rounding you will not be able to convert any floating point number to a ratio of two integers. You would need infinite decimal places.
Remember if you have the square root of 64 that would be 8. Presumably, the 8 is representing the infinite set of rational numbers that are multiples of 8. 8 is not rational itself but it can be mapped to 8/1 which is rational or to 16/2, etc.
Mapping the integer 8 to 8/1 and 9 to 9/1 just proves the unbounded set of integers is bounded by the set of rationals since there exists at least one rational number, like 22/7, that is not mappable to the integers.
What is this formula you are using?Comment
-
I believe the OP wishes to write a program to determine whether the square root of some arbitrary input value is rational or irrational. It isn't clear to me yet if the input values can be any positive rational number or if they are restricted to positive integer values.
The hard part here is developing an algorithm from the relevant number theory. Writing a program to implement that algorithm will be relatively easy.
Hint: is the square root of a prime number (other than 1) rational or irrational?Comment
-
The rational number is the ratio of two integers. Without two integers there is no rational number. So a single integer, like 8, is not rational. However, you can say that the integer 8 can map to the rational 8/1. Since you can this for all integers, all integers can be converted to rational numbers of the form n/1.
A number with decimal places cannot map to an integer/1 so these are not rational numbers. Instead, these are real numbers. Real numbers are complex numbers but without an imaginary component.
If you calculate the square root of 8 you will get an integer value of 2 because 3 squared is 9, which is larger than 8. Then squaring your result 2x2 you get 4 which is not 8. Therefore, the square root of 8 is not rational.
To calculate the square root of, say 25, you start with 2 and square it (4). 4 is less then 25 so increment to 3 and square it. 9 is less then 25. Increment to 4. 4 squared is 16. Next is 5. 5 squared is 25 and is exactly equal to the original number 25. Therefore the square root of 25 is an integer represented by the rational number 5/1.Comment
-
A number with decimal places can certainly be rational and so can its square root. For example, 16/9 (1.777..) is rational. Its square root is 4/3 (1.333...); and that is also rational.
Questions for the OP to consider:
If your input is limited to integers...
... If the square root of an integer is not also an integer, can it be rational?
If your input can be any rational number...
... Can the square root of a prime number (other than 1) be rational? (This is a special case of the previous question.)
... What is the Fundamental Theorem of Arithmetic?
Note: everything in this post refers to mathematics. Nothing in this post refers to computer programming.Comment
Comment