2
$\begingroup$

I'm trying to test a great many numbers $a^3+b^3$ to see if any of them are Fibonacci using the formula $$a^3+b^3=F_n \iff 5(a^3+b^3)^2\pm~4=L_n^2$$ I want to make my search more efficient by having some way of selecting one term, $+4$ or $-4$, that is the one more likely to produce a perfect square, and exclude the other one on the basis that it could never make a perfect square, instead of resorting to trial and error as I have been. What trick can I use to accomplish this?

Edit: I have since abandoned both the five-times-square test (initially in favor of the Mobius test, referred to in this question, which was faster) and also the looping through pairs of cubes (in favor of looping through Fibonacci indices instead). However, the answers below are helpful from a hypothetical-theoretical standpoint.

$\endgroup$
  • 1
    $\begingroup$ How is that any faster than just checking if $x$ is a Fibonacci number directly? $\endgroup$ – vonbrand Jun 6 '14 at 2:25
  • $\begingroup$ @vonbrand If $x$ were something specific, say $a^3+b^3$, and I were stepping through each pair of cubes in turn, it could get very inefficient to check both possible scenarios if I were checking a whole bunch of them, which I am. $\endgroup$ – Brian J. Fink Jun 6 '14 at 2:33
  • $\begingroup$ @vonbrand also these numbers are very large, so I can't just look them up in a table or something. $\endgroup$ – Brian J. Fink Jun 6 '14 at 2:39
  • $\begingroup$ @vonbrand I have edited my question to reflect this detail. $\endgroup$ – Brian J. Fink Jun 6 '14 at 3:55
  • $\begingroup$ Related: MSE 789588 <math.stackexchange.com/questions/789588/…> $\endgroup$ – Noam D. Elkies Jun 26 '14 at 2:02
2
$\begingroup$

Suppose you want to check if $F$ is a fibonacci number.

One simple check you can do to cut down your perfect square check computations is to consider $r = F \mod 7$.

For some $r$ you can ignore one of $5F^2 \pm 4$ as that leaves a remainder which cannot lead to a perfect square (quadratic non-residue)

$r = 0$, you can ignore $5F^2 - 4$

$r = 2$, you can ignore $5F^2 + 4$

$r = 3$, you can ignore $5F^2 - 4$

etc.

For other $r$ ($r=1$ and $r=6$), you consider both $5F^2 \pm 4$

You might be able to choose numbers other than $7$ to cut it down even more, or have a nested if with a series of such remainders...

$\endgroup$
7
$\begingroup$

If you're trying to solve $F_n = a^3 + b^3$ (for instance in order to investigate MSE question 789588) then it's much more efficient to loop over $n$ than over $a$ and $b$. Thanks to the factorization $a^3 + b^3 = (a+b)(a^2-ab+b^2)$ it's enough to check for each solution of $xy=F_n$ whether $3(4x-y^2)$ is a square, since that's the criterion for $(x, y) = (a^2-ab+b^2, a+b)$ [the point is that $4x-y^2 = 3(a-b)^2$]. I did this for all $n \leq 300$ using this table of Fibonacci factorizations (discarding the 100 values of $n$ for which $F_n\bmod 9 \in \{3,4,5,6\}$, since such a number can never be the sum of two cubes). This took only ~30 seconds in gp, even though some candidates $F_n$ in this range have more than a million factors. Not surprisingly I found that in this range the only solutions of $F_n = a^3 + b^3$ (with the integers $a,b$ not necessarily positive) are the known $F_3 = 2 = 1^3 + 1^3$ and $F_6 = 8 = 2^3 + 0^3 = 0^3 + 2^3$.

$\endgroup$
  • $\begingroup$ Technically $0$ is not a positive cube. Did I mention that I was checking for sums of two positive cubes? $\endgroup$ – Brian J. Fink Jun 27 '14 at 19:48
  • 1
    $\begingroup$ The technique I suggested will find all solutions, whether positive, zero, or negative, with little more effort than just finding the positive ones. Hence the parenthetical remark "(with the integers $a,b$ not necessarily positive)". If for whatever reason we're interested only in positive $a,b$ (as in question 789588) then it's easy to discard the others once we've found the full list of integer solutions. $\endgroup$ – Noam D. Elkies Jun 27 '14 at 23:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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