# Generation of rational numbers under constraints

Working this question on Mathematics Stack Exchange, I have the following questions:

• how to generate a rational number $$a$$ such that $$\sqrt{a^2-1}$$ be also rational? This is the case of $$a=\frac 54$$.
• how to generate a rational number $$b$$ such that $$\sqrt{b(b+1)}$$ be also rational? This is the case of $$b=\frac 9{16}$$.

I am more than bad with number theory and a quite limited Mathematica user.

Thanks in advance (even a very short list would be sufficient).

Pythagorean triples are useful (endless) supply of solutions:

Generating some:

pt[u_, v_] := {v^2 - u^2, 2  u  v, v^2 + u^2};
res = pt @@@
Cases[Join @@ Outer[List, Range[10], Range[2, 10]], {a_, b_} /;
GCD[a, b] == 1 && a < b];


Solutions to first problem:

sol1 = Divide[#3, #2] & @@@ res;
TableForm[{#, Sqrt[#^2 - 1]} & /@ sol1,
" \!$$\*SqrtBox[\(\*SuperscriptBox[\(a$$, $$2$$] - 1\)]\)"}}]


And for second problem:

sol2 = #1^2/#2^2 & @@@ res;
TableForm[{#, Sqrt[# (# + 1)]} & /@ sol2,
" \!$$\*SqrtBox[\(b \((b + 1)$$\)]\)"}}]


• This is more than interesting. Thanks & cheers Commented Mar 24 at 6:33

An inelegant way to find a few instances:

Select[Rationalize[Range[1, 10, 0.0001]],
Head[Sqrt[#^2 - 1]] == Rational &]

(* {41/40, 89/80, 5/4, 29/20, 689/400, 17/8, 13/5, 641/200, 65/16, \
101/20, 629/100, 15689/2000} *)

Select[Rationalize[Range[0, 10, 0.0001]],
Head[Sqrt[# (# + 1)]] == Rational &]

(* {1/80, 1/8, 9/40, 9/16, 4/5, 441/400, 81/40, 529/200, 361/80, 144/25, \
14641/2000} *)
$$$$

• Inelegant, may be but so simple ! Thanks & cheers & (+1) Commented Mar 23 at 6:24
\$Version

(* "14.0.0 for Mac OS X ARM (64-bit) (December 13, 2023)" *)

Clear["Global*"]

sol1 = FindInstance[{{a, Sqrt[a^2 - 1]} ∈ Rationals,
1 < a < #}, a, 5] & /@ {2, 3}

(* FindInstance::fwsol: Warning: FindInstance found only 1 instance(s), but it was not able to prove 5 instances do not exist.

FindInstance::fwsol: Warning: FindInstance found only 1 instance(s), but it was not able to prove 5 instances do not exist.

{{{a -> 205/133}}, {{a -> 1285/893}}} *)


Checking,

Sqrt[a^2 - 1] /. sol1[[All, -1]]

(* {156/133, 924/893} *)


For the second problem,

sol2 = FindInstance[{{b, Sqrt[b (b + 1)]} ∈ Rationals,
0 < b < 2}, b, 5]

(* FindInstance::fwsol: Warning: FindInstance found only 1 instance(s), but it was not able to prove 5 instances do not exist.

{{b -> 196/893}} *)


Checking,

Sqrt[b (b + 1)] /. sol2[[-1]]

(* 462/893 *)

• Thank you very mpuch ! Cheers :-) Commented Mar 23 at 6:00

In case you would like a simple infinite sequence of solutions to your first problem...

Your first problem is equivalent to finding Pythagorean triples in the integers.

Every odd integer is the difference of consecutive odd squares. So every odd square defines a Pythagorean triple.

(2 n + 1)^2 == (m + 1)^2 - m^2 // Solve[#, m] &
(* {{m -> 2 (n + n^2)}} *)

Table[(m + 1)/m /. Flatten[%], {n, 1, 9}]
(* {5/4, 13/12, 25/24, 41/40, 61/60, 85/84, 113/112, 145/144, 181/180} *)

Sqrt[%^2 - 1]
(* {3/4, 5/12, 7/24, 9/40, 11/60, 13/84, 15/112, 17/144, 19/180} *)


EDIT

For your second problem, for any

b -> u^2/(v^2 - u^2)


where v > u > 0 are integers, we have

Assuming[v > u > 0,
Sqrt[b (b + 1)] /. b -> u^2/(v^2 - u^2) // FullSimplify]
(* (u v)/(-u^2 + v^2) *)


So both are rational as required.