Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to test whether the square root of a number will be rational?

How can you test whether the square root of a number will be rational or not?

Is this even possible?

I need this because I need to work out whether to display a number as a surd or not in a maths app I'm developing at the moment.

like image 794
Alex Coplan Avatar asked Nov 16 '11 11:11

Alex Coplan


People also ask

How will you know if the square root is an irrational number?

Identifying Irrational NumbersIf a square root is not a perfect square, then it is considered an irrational number. These numbers cannot be written as a fraction because the decimal does not end (non-terminating) and does not repeat a pattern (non-repeating).

How do you identify if it is rational or not?

A rational number is the one which can be represented in the form of P/Q where P and Q are integers and Q ≠ 0. But an irrational number cannot be written in the form of simple fractions. ⅔ is an example of a rational number whereas √2 is an irrational number.

Is √ 3 a rational number Yes or no?

√2, √3, √5, and so on are some examples of irrational numbers as they cannot be expressed in form of p ⁄ q.


2 Answers

For integer inputs, only the square roots of the square numbers are rationals. So your problem boils down to find if your number is a square number. Compare the question: What's a good algorithm to determine if an input is a perfect square?.

If you have rational numbers as inputs (that is, a number given as the ratio between two integer numbers), check that both divisor and dividend are perfect squares.

For floating-point values, there is probably no solution because you can't check if a number is rational with the truncated decimal representation.

like image 136
thiton Avatar answered Oct 02 '22 12:10

thiton


From wikipedia: The square root of x is rational if and only if x is a rational number that can be represented as a ratio of two perfect squares.

So you need to find a rational approxmiation for your input number. So far the only algorithm I've nailed down that does this task is written in Saturn Assembler for the HP48 series of calculators.

like image 27
sarnold Avatar answered Oct 02 '22 12:10

sarnold