2 deleted 17 characters in body
source | link

The only trick I can see is a trivial one: if $x$ is the square of a rational, it is also a rational. That's because of the $x = (a/b)^2 = a^2/b^2$.

So, I'd write a function testing the rationality, which returns either True, False, or Null (if rationality cannot be established):

isRational[x_] := If[Simplify[x \[Element] Rationals], True, False, Null]

which works like this:

In[30]:= isRational /@ {1/3, \[Pi]π, EulerGamma}
Out[30]= {True, False, Null}

And then simply use it by first checking if the number itself is known to be rational:

isSqrRational[x_] := If[isRational[x], isRational[Sqrt[x]], False, isRational[Sqrt[x]]]

which gives:

In[33]:= isSqrRational /@ {1/3, 1/4, \[Pi]π, EulerGamma}
Out[33]= {False, True, False, Null}

The only trick I can see is a trivial one: if $x$ is the square of a rational, it is also a rational. That's because of the $x = (a/b)^2 = a^2/b^2$.

So, I'd write a function testing the rationality, which returns either True, False, or Null (if rationality cannot be established):

isRational[x_] := If[Simplify[x \[Element] Rationals], True, False, Null]

which works like this:

In[30]:= isRational /@ {1/3, \[Pi], EulerGamma}
Out[30]= {True, False, Null}

And then simply use it by first checking if the number itself is known to be rational:

isSqrRational[x_] := If[isRational[x], isRational[Sqrt[x]], False, isRational[Sqrt[x]]]

which gives:

In[33]:= isSqrRational /@ {1/3, 1/4, \[Pi], EulerGamma}
Out[33]= {False, True, False, Null}

The only trick I can see is a trivial one: if $x$ is the square of a rational, it is also a rational. That's because of the $x = (a/b)^2 = a^2/b^2$.

So, I'd write a function testing the rationality, which returns either True, False, or Null (if rationality cannot be established):

isRational[x_] := If[Simplify[x  Rationals], True, False, Null]

which works like this:

In[30]:= isRational /@ {1/3, π, EulerGamma}
Out[30]= {True, False, Null}

And then simply use it by first checking if the number itself is known to be rational:

isSqrRational[x_] := If[isRational[x], isRational[Sqrt[x]], False, isRational[Sqrt[x]]]

which gives:

In[33]:= isSqrRational /@ {1/3, 1/4, π, EulerGamma}
Out[33]= {False, True, False, Null}
1
source | link

The only trick I can see is a trivial one: if $x$ is the square of a rational, it is also a rational. That's because of the $x = (a/b)^2 = a^2/b^2$.

So, I'd write a function testing the rationality, which returns either True, False, or Null (if rationality cannot be established):

isRational[x_] := If[Simplify[x \[Element] Rationals], True, False, Null]

which works like this:

In[30]:= isRational /@ {1/3, \[Pi], EulerGamma}
Out[30]= {True, False, Null}

And then simply use it by first checking if the number itself is known to be rational:

isSqrRational[x_] := If[isRational[x], isRational[Sqrt[x]], False, isRational[Sqrt[x]]]

which gives:

In[33]:= isSqrRational /@ {1/3, 1/4, \[Pi], EulerGamma}
Out[33]= {False, True, False, Null}