5
$\begingroup$

Consider the problem of finding all values of $n \in \mathbb{N}$ s.t. $$\sqrt{n} + \sqrt{n + 2005}$$

is an integer.

One can easily verify that $n = 1,004,004$ and $39,204$ satisfy this requirement, and in fact are the only such solution values for $n$. The simplest approach is to set the right hand side to some variable $m \in \mathbb{Z}$, square both sides, manipulate and note the prime factorization of $2005$... that is, $2005 = 2005 \cdot 1 = 401 \cdot 5$ and equate factors.

I would like to compute the solution directly, however.

The natural approaches do not work:

Solve[
 Sqrt[n] + Sqrt[n + 2005] == m, {n, m}, Integers]

and

FindInstance[
 Sqrt[n] + Sqrt[n + 2005] == m , {n, m}, Integers]

and

Assuming[{n, m} \[Element] Integers,
 Solve[Sqrt[n] + Sqrt[n + 2005] == m, {n, m}]]

I've tried a number of minor variations, adding constraints such as $\{ n, m \} > 0$, and so forth. None work.

As yarchik shows (below), one can solve this with the result from number theory that each of the component square roots must resolve to an integer (demonstrated here). That leads to two questions:

  • What would we do if we didn't know that fact from number theory?
  • Supposing we do know that fact from number theory. How would we programmatically impose it as some form of constraint or subsidiary equation rather than "by hand"?

Suggestions?

$\endgroup$
2
  • $\begingroup$ Sorry,Sqrt[1]+Sqrt[2006] is not an integer. Something to adjust. $\endgroup$
    – user64494
    Jul 26, 2021 at 7:11
  • $\begingroup$ @user64494: No no no. The factorization does not give the solutions directly. See here: youtube.com/watch?v=BGGL2IqmsLk $\endgroup$ Jul 26, 2021 at 7:20

2 Answers 2

7
$\begingroup$

Use both Reduce and Solve .

result = Reduce[Sqrt[n] + Sqrt[n + 2005] == m, {m, n},Integers]
Solve[result, {m, n}]

{{m -> 401, n -> 39204}, {m -> 2005, n -> 1004004}}

$\endgroup$
1
  • 1
    $\begingroup$ Oh my. Clever. Thanks so very much. ($\checkmark$) $\endgroup$ Jul 26, 2021 at 14:38
7
$\begingroup$
Solve[p^2 == n && q^2 == n + 2005, {p, q, n}, Integers]

yields

{{p -> -1002, q -> -1003, n -> 1004004}, 
 {p -> -1002, q -> 1003, n -> 1004004}, 
 {p -> -198, q -> -203, n -> 39204}, 
 {p -> -198, q -> 203, n -> 39204}, 
 {p -> 198, q -> -203, n -> 39204}, 
 {p -> 198, q -> 203, n -> 39204}, 
 {p -> 1002, q -> -1003, n -> 1004004}, 
 {p -> 1002, q -> 1003, n -> 1004004}}

It means basically 2 solutions for $n$, namely $n=39204, 1004004$.

$\endgroup$
5
  • $\begingroup$ Yes. Thanks... there are a number of manipulations that lead to solvable equations. But why doesn't the direct method work? My whole goal is to eliminate the need for "human" calculation. $\endgroup$ Jul 26, 2021 at 7:22
  • $\begingroup$ @DavidG.Stork It does not work because it involves a non-trivial step not implemented in (known to) Mathematica, namely: a sum of square roots of integers is an integer number only when each one is a perfect square. $\endgroup$
    – yarchik
    Jul 26, 2021 at 7:27
  • $\begingroup$ Alas, just as I feared. I would have thought that this level of symbol manipulation would have been built into Mathematica. Might some clever use of Expand help? The original problem is fairly simple, and I mentioned "human" techniques to solve it. What if the the equation is a bit more complex and the transformation not as "obvious"? Or... can one incorporate that squared result as some symbolic constraint, rather than "by hand"? $\endgroup$ Jul 26, 2021 at 7:35
  • $\begingroup$ It is an interesting question how to teach MA that "a sum of square roots of integers is an integer number only when each one is a perfect square". Here is, by the way, a proof: math.stackexchange.com/a/279558/435814 . Maybe update the question that someone can provide more insight. $\endgroup$
    – yarchik
    Jul 26, 2021 at 8:03
  • 3
    $\begingroup$ Solving over PositiveIntegers gives a cleaner set of solutions. $\endgroup$
    – Roman
    Jul 26, 2021 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.