In mathematics, every real number falls into one of two categories: Rational or Irrational. Knowing the difference is fundamental for algebra, geometry, and calculus.
What is a Rational Number?
A number is considered rational if it can be written as a fraction p/q, where p and q are both integers and q is not zero. Rational numbers include:
Integers: For example, 7 can be written as 7/1.
Fractions: For example, 1/2, 3/4, or 22/7.
Terminating Decimals: For example, 0.25 (which is 1/4).
Repeating Decimals: For example, 0.333… (which is 1/3).
What is an Irrational Number?
An irrational number is a real number that cannot be expressed as a simple fraction. Their decimal expansions go on forever without ever repeating a pattern. Common examples include:
Square Roots of Non-Perfect Squares: √2, √3, and √5 are irrational because they cannot be solved as whole numbers or fractions.
Mathematical Constants: The most famous example is Pi (π), which begins as 3.14159… and continues infinitely.
Euler's Number (e): Used in natural logarithms, approximately 2.71828…
Comparison Table
Feature
Rational
Irrational
Fraction Form
Yes (p/q)
No
Decimal Style
Terminating or Repeating
Non-terminating, Non-repeating
Example
0.5, 4, 1/3
√2, π, e
function updateFields() {
var type = document.getElementById("inputType").value;
document.getElementById("decimalGroup").style.display = (type === "decimal") ? "block" : "none";
document.getElementById("fractionGroup").style.display = (type === "fraction") ? "block" : "none";
document.getElementById("sqrtGroup").style.display = (type === "sqrt") ? "block" : "none";
document.getElementById("constantGroup").style.display = (type === "constant") ? "block" : "none";
document.getElementById("resultDisplay").style.display = "none";
}
function isPerfectSquare(n) {
if (n < 0) return false;
var root = Math.sqrt(n);
return root === Math.floor(root);
}
function checkNumber() {
var type = document.getElementById("inputType").value;
var resultDiv = document.getElementById("resultDisplay");
var statusText = document.getElementById("statusText");
var reasoningText = document.getElementById("reasoningText");
var isRational = true;
var reason = "";
var displayVal = "";
if (type === "decimal") {
var val = document.getElementById("decimalVal").value;
if (val === "") {
alert("Please enter a number.");
return;
}
isRational = true;
displayVal = val;
reason = "All finite decimals and integers entered here are rational because they can be expressed as a fraction (e.g., " + val + " = " + (val * 1000) + "/1000).";
}
else if (type === "fraction") {
var num = document.getElementById("numerator").value;
var den = document.getElementById("denominator").value;
if (num === "" || den === "") {
alert("Please enter both numerator and denominator.");
return;
}
if (parseFloat(den) === 0) {
alert("Denominator cannot be zero.");
return;
}
isRational = true;
displayVal = num + "/" + den;
reason = "By definition, any number that can be expressed as a ratio of two integers (where the denominator is not zero) is rational.";
}
else if (type === "sqrt") {
var sVal = parseFloat(document.getElementById("sqrtVal").value);
if (isNaN(sVal)) {
alert("Please enter a valid number.");
return;
}
if (sVal < 0) {
statusText.innerHTML = "Imaginary Number";
statusText.style.color = "#e53e3e";
reasoningText.innerHTML = "The square root of a negative number is an imaginary number, which is neither rational nor irrational in the context of real numbers.";
resultDiv.style.display = "block";
return;
}
displayVal = "√" + sVal;
if (isPerfectSquare(sVal)) {
isRational = true;
reason = "√" + sVal + " equals " + Math.sqrt(sVal) + ", which is an integer. Therefore, it is rational.";
} else {
isRational = false;
reason = "The square root of " + sVal + " (" + Math.sqrt(sVal).toFixed(10) + "…) is non-terminating and non-repeating because " + sVal + " is not a perfect square.";
}
}
else if (type === "constant") {
var c = document.getElementById("constSelect").value;
isRational = false;
if (c === "pi") {
displayVal = "π (Pi)";
reason = "Pi is a transcendental number. Its decimal expansion (3.14159…) never ends and never repeats.";
} else if (c === "e") {
displayVal = "e (Euler's Number)";
reason = "e is an irrational constant approximately equal to 2.71828. It cannot be written as a simple fraction.";
} else {
displayVal = "φ (Golden Ratio)";
reason = "The Golden Ratio (1 + √5)/2 is irrational because it involves the square root of 5, which is not a perfect square.";
}
}
resultDiv.style.display = "block";
if (isRational) {
statusText.innerHTML = displayVal + " is RATIONAL";
statusText.style.color = "#2f855a";
} else {
statusText.innerHTML = displayVal + " is IRRATIONAL";
statusText.style.color = "#c53030";
}
reasoningText.innerHTML = reason;
}