An efficient way to find perfect squares?

  • Thread starter foo_daemon
  • Start date
  • Tags
    Squares
In summary, the conversation is about finding values of n within a certain domain that satisfy the equation (3n-1)(n+1)=m^2 where m and n are both integers. Various strategies and ideas are discussed, such as using algebraic geometry, recurrence sequences, and Pythagorean triples. The conversation also identifies the origin of the problem as a Project Euler challenge.
  • #1
foo_daemon
8
0
Hi,

I have a problem that I'm a bit stuck on, and need some direction:

I need to find [itex] \forall_n [/itex] within a certain domain that can satisfy this equation:

[itex]\left( 3n-1 \right) \left( n+1 \right) = m^{2} [/itex] where [itex] m,n \in \mathbb{Z} [/itex]

Or, to put it in a different context, I'm looking for discrete values of n (within a certain domain) such that [itex] \sqrt{ \left( 3n - 1 \right) \left( n + 1 \right) } [/itex] is an integer.

I know I can just do an iterative search over [itex] \forall_n [/itex] in the domain, but shouldn't there be a faster, easier way using some number theory?
If [itex] 3n - 1 [/itex] and [itex] n + 1 [/itex] are both perfect squares, then it is true, but it is also true if their product is a perfect square (e.g. [itex] n=17 [/itex] ). I'm just not sure how to piece all the conditions together into a coherent algorithm.
 
Last edited:
Physics news on Phys.org
  • #2
You might get better answers if you explained what your certain domain is.

If you consider iterating over the domain I don't see why you're having difficulty coming up with a coherent algorithm...


Are you sure you actually need an "efficient" way? People have a tendency to "prematurely optimize" -- i.e. to spend effort trying to speed up a part of the calculation without ever bothering to check that it needs to be sped up.

I'm mildly skeptical that the most stupidly obvious method isn't good enough for your purposes.



Anyways, applying some algebraic geometry:

Your equation defines a conic section in the plane. (a hyperbola)

Suppose (m0, n0) and (m1, n1) are two rational points lying on the hyperbola. Then the slope of the line passing through them is rational (or infinite).

Conversely, if L is any line passing through (m0, n0) whose slope is rational, then either L is tangent to the hyperbola, or L intersects the hyperbola in two rational points.


This gives us an easy way to enumerate the rational solutions to your equation. Take [itex](m_0, n_0) = (2, 1)[/itex]. Now, consider the line
[tex]m = 2 + t (n -1)[/tex]​
Plugging this into the equation of the hyperbola, we find the two solutions for n are:
n=1
[tex]n = \frac{t^2 - 4t + 5}{t^2 - 3} = 1 + \frac{8 - 4t}{t^2 - 3}[/tex]​




Remember that t can be a rational number -- so the possible rational values for n are
[tex]n = 1 + \frac{v(8v - 4u)}{u^2 - 3v^2}[/tex]
where I've set t = u/v, with u and v relatively prime.

Ah, but we want n to be an integer! If u is nonzero, then v and [itex]u^2 - 3v^2[/itex] are relatively prime, so we must have that
[tex]\frac{8v - 4u}{u^2 - 3v^2}[/tex]​
is an integer.


It's unfortunate that's a minus sign in the denominator. If it were a plus sign, we could easily list all possible values of (u,v) that give an integer. :frown: However, at least we can see that u needs to be unusually close to [itex]u^2 - 3v^2[/itex]. What if we set [itex]u = \sqrt{3} v + \epsilon[/itex]?

I'm getting exhausted by the details at this point, so I'll sketch what I'm thinking for here. I want to solve the system of inequalities that says "the denominator of that fraction is smaller than the numerator" and whatever inequalities say "n is in your certain domain". I'm hoping there will be very few v that satisfy the system.
 
  • #3
Oops... Hurkyl stepped in first. :) I did another (unfinished) attempt, which goes like this:

[itex]3n-1[/itex] is never a perfect square because it is congruent to 2 (mod 3), while squares are congruent to either 0 or 1 (mod 3). So the solutions have to be of the kind of your [itex]n=17[/itex].

Again, I don't have anything concrete, but this is one lead. Consider the recurrence sequence
[tex]a_n = 4a_{n-1} - a_{n-2}[/tex]
When kickstarted with [itex]a_0=1, a_1=3[/itex] it produces 1, 3, 11, 41, 153..., and when started with [itex]a_0=1, a_1=5[/itex], it gives 1, 5, 19, 71, 265, ...

Take corresponding pairs from these two sequences, (1,1), (3,5), (11,19), (41,71), (153,265), ..., and denote one of these pairs as [itex](a,b)[/itex]. The number [itex]\frac {a^2+b^2} 2[/itex] is an integer (because both [itex]a[/itex] and [itex]b[/itex] are odd). The first two such numbers happen to be 1 and 17, both making [itex](3n-1)(n+1)[/itex] a square. In fact, computer evidence suggests that all solutions have this form.

I was looking for a proof by induction that says, if the pair [itex](a,c)[/itex] works and the pair [itex](b,d)[/itex] works, then the pair [itex](4b-a,4d-c)[/itex] will work as well. It gets messy and I've not finished (not that I'm certain to finish, of course!).

And, of course, such a proof would only show that numbers of this form are solutions, not that all solutions must have this form. More work is needed here! I'l try to write again during the week, if I arrive somewhere.

As an additional observation, note that, if [itex](3n-1)(n+1)[/itex] is a square, then [itex](3n-1)(n+1) + (n-1)^2 = (2n)^2[/itex] is a Pythagorean triple, which is part of the reason why I came up with the above; this may play a part in the induction proof. Maybe.

Hope this helps--
 
  • #4
The first five values satisfying your equation are n[itex]_{i}[/itex] = 1, 17, 241, 3361, 46817,...
(the corresponding values of the right side are m[itex]_{i}[/itex] = 2, 30, 418, 5822, 81090, ...)
and the general recursion formula for n[itex]_{k}[/itex] is
n[itex]_{k}[/itex] := 15*n[itex]_{k-1}[/itex] - 15*n[itex]_{k-2}[/itex] + n[itex]_{k-3}[/itex]
 
  • #5
Consider the isosceles triangle with side length (n, n, n-1), then for the length
of the height upon the smalller side we have:

h = [itex]\frac{1}{2}[/itex] * [itex]\sqrt{(3*n-1)*(n+1)}[/itex]

and for n from {17,241,331, etc} since h and b = [itex]\frac{1}{2}[/itex]+(n-1) are integers, we
have a Pythagorean triangle with sides (b, h, n) (see post of Dodo above)
 
  • #6
RamaWolf: Haha, nice! Yep, you identified where this problem stems from (I was sort of partitioning it up): http://projecteuler.net/index.php?section=problems&id=94

To find integer areas of the isosceles triangle [itex]\left( n, n, n-1 \right) [/itex] one must solve (expanded from Heron's formula):[itex]Area = \frac{\left(n-1\right)} {4}\sqrt{\left( 3n - 1 \right) \left( n + 1 \right) } [/itex]

Now the other part left to solve:

For the isosceles triangle [itex]\left( n, n, n+1 \right) [/itex], the formula is incredibly similar:[itex]Area = \frac{\left(n+1\right)}{4}\sqrt{\left( 3n + 1 \right) \left( n - 1 \right) } [/itex]

That recursive formula is great, but could you give me some pointers/links on how you got to it? I'd like to try to reach a similar formula for the second part of the problem on my own..

Thanks all!
 
  • #7
Wow, was just testing around and it appears the exact same recursive formula satisfies the second part of the equation as well (the 'conjugate' square, I guess you could call it?). You just need to use the different set of initial values: [itex] n_i = 1, 5, 65, 901, 12545...[/itex]
[itex]m_i = 0, 8, 112, 1560, 21728... [/itex]Awesome, now I just need to figure out how to derive that answer..
 
  • #8
RamaWolf said:
Consider the isosceles triangle with side length (n, n, n-1), then for the length
of the height upon the smalller side we have:

h = [itex]\frac{1}{2}[/itex] * [itex]\sqrt{(3*n-1)*(n+1)}[/itex]

and for n from {17,241,331, etc} since h and b = [itex]\frac{1}{2}[/itex]+(n-1) are integers, we
have a Pythagorean triangle with sides (b, h, n) (see post of Dodo above)

Typo: the formula for b is: b = [itex]\frac{1}{2}[/itex]*(n-1)
 
  • #9
foo_daemon said:
RamaWolf: Haha, nice! Yep, you identified where this problem stems from (I was sort of partitioning it up): http://projecteuler.net/index.php?section=problems&id=94

To find integer areas of the isosceles triangle [itex]\left( n, n, n-1 \right) [/itex] one must solve (expanded from Heron's formula):


[itex]Area = \frac{\left(n-1\right)} {4}\sqrt{\left( 3n - 1 \right) \left( n + 1 \right) } [/itex]

Now the other part left to solve:

For the isosceles triangle [itex]\left( n, n, n+1 \right) [/itex], the formula is incredibly similar:


[itex]Area = \frac{\left(n+1\right)}{4}\sqrt{\left( 3n + 1 \right) \left( n - 1 \right) } [/itex]

That recursive formula is great, but could you give me some pointers/links on how you got to it? I'd like to try to reach a similar formula for the second part of the problem on my own..

Thanks all!

If the sequence is {a[itex]_{k}[/itex]) then get a linear system of equations like this:

a[itex]_{k}[/itex] = x[itex]_{1}[/itex]*a[itex]_{k-1}[/itex]+ x[itex]_{2}[/itex]*a[itex]_{k-2}[/itex]+ x[itex]_{3}[/itex]*a[itex]_{k-3}[/itex]

Mathematica commands:

eqs = {3361 == 241 x1 + 17 x2 + x3,46817 == 3361 x1 + 241 x2 + 17 x3,652081 == 46817 x1 + 3361 x2 + 241 x3};
vars = {x1, x2, x3};
sol = Solve[eqs, vars]
 
  • #10
Btw:

if a[itex]_{k}[/itex] := (3*a[itex]_{k}[/itex] - 1)*(a[itex]_{k}[/itex] + 1) = b[itex]_{k}[/itex][itex]^{2}[/itex] with a[itex]_{k}[/itex] and b[itex]_{k}[/itex] [itex] \in \mathbb{Z}[/itex],

(initial values as above), then we have to recursions:

a[itex]_{k}[/itex] = 15*a[itex]_{k-1}[/itex] - 15*a[itex]_{k-2}[/itex] + a[itex]_{k-3}[/itex] for k > 3

and

b[itex]_{j}[/itex] = 14*b[itex]_{j-1}[/itex] - b[itex]_{j-2}[/itex] for j > 2
 
  • #11
Well, certainly the rule
[tex]n_k = 15n_{k-1} - 15n_{k-2} + n_{k-3}[/tex]
is much easier to use in practice than what I wrote in post#3.

However, personally I need the musings in post#3 in order to prove that the values of [itex]n[/itex] produced by this recurrence sequence indeed make [itex](3n-1)(n+1)[/itex] a square.

I think I completed a proof (to be posted soon), but I'm yet trying to finish the case for the converse, that is, a proof that the only values of [itex]n[/itex] that make [itex](3n-1)(n+1)[/itex] a square are those coming from the recurrence sequence.

More details soon, hopefully. In the meantime, realize that, if [itex]a, ~ b, ~ 4b-a[/itex] and [itex]4(4b-a)-b = 15b-4a[/itex] are four consecutive values of a sequence with recurrence rule
[tex]a_k = 4a_{k-1} - a_{k-2}[/tex]
and if [itex]c, ~ d, ~ 4d-c[/itex] and [itex]15d-4c[/itex] are four consecutive values of another sequence with the same recurrence rule (but possibly different starting values), and if the function
[tex]n(x,y) = \frac {x^2 + y^2} 2[/tex]
is used to combine corresponding values of the two sequences, then applying RamaWolf's rule to three consecutive values of [itex]n(x,y)[/itex] we obtain
[tex]\begin{align*}
15 \cdot n(4b - a,4d - c) - 15 \cdot n(b,d) + n(a,c)
\\
&= 15 \cdot \frac {16b^2 - 8ab + a^2 + 16d^2 - 8cd + c^2} 2 - 15 \cdot \frac {b^2 + d^2} 2 + \frac {a^2 + c^2} 2 \\
&= \frac {240b^2 - 120ab + 15a^2 + 240d^2 - 120cd + 15c^2 - 15b^2 -15d^2 + a^2 + c^2} 2 \\
&= \frac {225b^2 - 120ab + 16a^2 + 225d^2 - 120cd + 16c^2} 2 \\
&= \frac {(15b - 4a)^2 + (15d - 4c)^2} 2 \\
&= n(15b - 4a, 15d - 4c)
\end{align*}[/tex]
so the two approaches are the same.
 
Last edited:
  • #12
Our initial problem converned a isosceles triangle (t, t, t - 1);
now let t = 2 s + 1 and h by the height on the smaller side (i.e. t - 1),
the question was wether the triagle (s, h, t) is a
Pythagorean triangle (or the numbers (s, h, t ) by a Pythagorean tripel PT).

Numerical evidence has delivered the first examples of that PT be:

(s, h, t) = (0, 1, 1), (8, 15, 17), (120, 209, 241), (1680, 2911, 3361), (23408, 40545, 46817)

Recursion formulas are:

s[itex]_{k}[/itex] := 8 + 14 s[itex]_{k-1}[/itex] - s[itex]_{k-2 }[/itex] ( NEW!)

h[itex]_{k}[/itex] := 14 h[itex]_{k-1}[/itex] - h[itex]_{k-2 }[/itex]

t[itex]_{k}[/itex] := 15 t[itex]_{k-1}[/itex] - 15 t[itex]_{k-2 }[/itex] + t[itex]_{k-3}[/itex]
 
  • #13
RamaWolf said:
Our initial problem converned a isosceles triangle (t, t, t - 1);
now let t = 2 s + 1 and h by the height on the smaller side (i.e. t - 1),
the question was wether the triagle (s, h, t) is a
Pythagorean triangle (or the numbers (s, h, t ) by a Pythagorean tripel PT).

Numerical evidence has delivered the first examples of that PT be:

(s, h, t) = (0, 1, 1), (8, 15, 17), (120, 209, 241), (1680, 2911, 3361), (23408, 40545, 46817)

Recursion formulas are:

s[itex]_{k}[/itex] := 8 + 14 s[itex]_{k-1}[/itex] - s[itex]_{k-2 }[/itex] ( NEW!)

h[itex]_{k}[/itex] := 14 h[itex]_{k-1}[/itex] - h[itex]_{k-2 }[/itex]

t[itex]_{k}[/itex] := 15 t[itex]_{k-1}[/itex] - 15 t[itex]_{k-2 }[/itex] + t[itex]_{k-3}[/itex]
The following also appear to work
t[itex]_{k}[/itex] := 4 + 14 t[itex]_{k-1}[/itex] - t[itex]_{k-2 }[/itex]
s[itex]_{k}[/itex] := 15 s[itex]_{k-1}[/itex] - 15 s[itex]_{k-2 }[/itex] + s[itex]_{k-3}[/itex]
h[itex]_{k}[/itex] := 15 h[itex]_{k-1}[/itex] - 15 h[itex]_{k-2 }[/itex] + h[itex]_{k-3}[/itex]
 
  • #14
This is the enchilada I have so far. There is a proof that the sequence 15 blah - 15 blah + blah produces numbers n such that (3n-1)(n+1) is a square. There is also a bare sketch of the converse, which is proving too hard for me; maybe someone can fill in the holes or suggest an alternative.
 

Attachments

  • squares.pdf
    105.6 KB · Views: 267
Last edited:
  • #15
I now want to link our initial problem

(isosceles triangle with sides (t, t, t-1) and integer valued area)

to the theory of Pythagorean triangles.

I start with

Lemma: Let b[itex]_{0}[/itex] and b[itex]_{1}[/itex] be co-prime natural numbers and

b[itex]_{k}[/itex]:=4 b[itex]_{k-1}[/itex] - b[itex]_{k-2}[/itex]

then the pairs (b[itex]_{k},b_{k+1}[/itex]) are all co-prime

Euclidean Rule for Pythagorean Numbers:
Let (m,n) be co-prime natural numbers (m<n), then

h := n[itex]^{2}[/itex] + m[itex]^{2}[/itex]
e := 2 m n
d := n[itex]^{2}[/itex] - m[itex]^{2}[/itex]

form the hypothenuse, the even and the odd leg
of a primitive Pythagorean triangle (PPT)


Now we have from b = {0, 1, 4, 15, 56, 209, 241, ...}

(m.n) -h- -e- -d-
---------------------------------
(1,4) -17- -8- -15-
(4,15) -241- -120- -209-
(15,56) -3361- -2911- -1680-
(56,209) -46827- -23408- -40545-
(...,...)

Without any difficulty, we identify the list of the h's with the side t of the
isosceles triangle, the e's as half of the side (t-1) and the d's as the
heights of the isosceles triangle over the smaller side, returning an integer
valued are of the isosceles triangle as h * e * d.

Remark: From this point of view it is clear and needs no further proof,
that h[itex]^{2}[/itex] - e[itex]^{2}[/itex] is a perfect square
 
  • #16
I opened a new thread called

Pythagorean Triangles with one side equal s and hypothenuse equal 2 s+1
 

FAQ: An efficient way to find perfect squares?

1. What is the most efficient way to find perfect squares?

The most efficient way to find perfect squares is by using the square root function. This function takes the square root of a number and returns the closest integer value. If the result is a whole number, then the original number is a perfect square.

2. Can I use a calculator to find perfect squares?

Yes, most scientific calculators have a square root function that can be used to find perfect squares. Simply input the number and press the square root button to get the result.

3. Is there a mathematical formula for finding perfect squares?

Yes, there is a formula for finding perfect squares. It is called the "difference of squares" formula and it states that the square of a number is equal to the sum of the number and its square root multiplied by the difference of the number and its square root.

4. Are there any other methods for finding perfect squares?

Yes, there are other methods for finding perfect squares such as using a number line or using the prime factorization method. However, using the square root function or the difference of squares formula is the most efficient way.

5. How can I verify if a number is a perfect square?

To verify if a number is a perfect square, you can use the square root method mentioned above. If the result is a whole number, then the original number is a perfect square. You can also check the number's prime factorization and see if all the factors appear in pairs.

Similar threads

Back
Top