Does simple proof of the irrationality of $\sqrt{2}$ extend to $\sqrt{n}$, where $n$ is square-free?

This question is about extending a common proof of the irrationality of $$\sqrt{2}$$ to $$\sqrt{p}$$ for prime $$p$$, and then asking which other kinds of number $$n$$ does the same proof tell us that $$\sqrt{n}$$ is irrational.

case: $$\sqrt{2}$$

The following outlines the very common proof that $$\sqrt{2}$$ is irrational.

• Intending to prove by contradiction, assume $$\sqrt{2}$$ is rational.
• Let $$\sqrt{2} = \frac{a}{b}$$ is a fraction in the lowest terms, that is, $$gcd(a,b)=1$$.
• Then $$2 = \frac{a^2}{b^2}$$, or $$2b^2 = a^2$$.
• From this we observe that $$2|a^2$$, which implies $$2|a$$.
• We can write $$a = 2 a_1$$, which gives us $$b^2=2{a_1}^2$$.
• That is, $$2|b^2$$, which implies $$2|b$$.
• But $$2|a$$ and $$2|b$$ contradicts $$gcd(a,b)=1$$, and so $$\sqrt{2}$$ can't be written as a ratio of integers.

case: $$\sqrt{p}$$

Now, I saw a different proof in "Guide to Abstract Algebra, 2nd Edition,Carol Whitehead" which generalises to $$\sqrt{p}$$ where $$p$$ is prime.

The proof is structurally the same.

• Intending to prove by contradiction, assume $$\sqrt{p}$$ is rational.
• Let $$\sqrt{p} = \frac{a}{b}$$ is a fraction in the lowest terms, that is, $$gcd(a,b)=1$$.
• Then $$p = \frac{a^2}{b^2}$$, or $$pb^2 = a^2$$.
• From this we observe that $$p|a^2$$, which implies $$p|a$$.
• We can write $$a = p a_1$$, which gives us $$b^2=p{a_1}^2$$.
• That is, $$p|b^2$$, which implies $$p|b$$.
• But $$p|a$$ and $$p|b$$ contradicts $$gcd(a,b)=1$$, and so $$\sqrt{p}$$ can't be written as a ratio of integers.

case: $$\sqrt{n}$$

So this led me to ask myself, what kinds of number $$\sqrt{n}$$ does this proof work for?

I am not an expert in this subject (self-teaching) but my thinking led me to the crucial step being the following.

• From this we observe that $$n|a^2$$, which implies $$n|a$$.

My conclusion is that this can only be true if $$n$$ is a square-free integer, that is, has no prime factors of power higher than 1.

To illustrate:

• $$2 | (2^2 \cdot 3^2)$$ implies $$2 | (2 \cdot 3)$$
• $$2^2| (2^2 \cdot 3^2)$$ does not imply $$2^2 |(2 \cdot 3)$$

Question: Is it correct that the proof works for $$\sqrt{n}$$ if $$n$$ is a square-free integer.

The closest other answer that I think applies is this one, but my mathematical abilities aren't strong enough to under it sufficiently: https://math.stackexchange.com/a/1252195/319008

This one also seems too advanced and doesn't appear to directly answer this question: Proof of the irrationality of $\sqrt n$, where $n$ is square free

• Just apply the usual Rational Root Theorem to $x^2-n$.
– lulu
Commented May 29, 2023 at 22:58
• The argument is trivial to extend to any $n$ for which there is a prime $p$ such that $p\mid n$ but $p^2\nmid n$. A bit more argument but still doable to any $n$ for which there is a prime $p$ such that the highest power of $p$ that divides $n$ is odd. Commented May 29, 2023 at 23:14

Yes, $$n|a^2$$ always implying $$n|a$$ is equivalent (for $$n\geq 2$$) to $$n$$ being square free. If $$p^2|n$$ for some prime $$p$$ then $$n$$ divides $$(\frac{n}{p})^2=n\cdot\frac{n}{p^2}$$, but obviously doesn't divide $$\frac{n}{p}$$. So this specific proof works for square free natural numbers.
That being said, it can be easily proved from here that $$\sqrt{n}$$ is irrational whenever some prime divides $$n$$ with odd multiplicity. Because in this case we can write $$n=a^2b$$ where $$b>1$$ is square free. If $$\sqrt{n}$$ was rational, then so was $$\sqrt{b}$$, a contradiction.