How to check if a square root is irrational
What's the easiest way in sage to check if the square root of a given rational number (for example 1,671 or 2,56) is irrational.
What's the easiest way in sage to check if the square root of a given rational number (for example 1,671 or 2,56) is irrational.
Convert your numbers to explicit rationals and ask whether their square root is in Q:
sage: sqrt(1671/1000) in QQ
False
sage: sqrt(256/100) in QQ
True
sage: sqrt(2) in QQ
False
Or you can do the conversions this way:
sage: sqrt(QQ(1.671)) in QQ
False
Asked: 12 years ago
Seen: 2,087 times
Last updated: Oct 13 '12