MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: contains 1044938 decimal digits)

  • To: mathgroup at
  • Subject: [mg49803] Re: contains 1044938 decimal digits)
  • From: "Michael Taktikos" <michael.taktikos at>
  • Date: Sun, 1 Aug 2004 18:48:34 -0400 (EDT)
  • References: <7f4ffu$6dj$>, <>, <7g0qsd$> <cdvm0e$7hv$> <ce2ftd$8rh$> <> <ceap6b$aej$> <> <cei901$2jt$>
  • Sender: owner-wri-mathgroup at

"Daniel Lichtblau" <danl at> wrote:

> > There are very fast algorithms for computing Fibonacci numbers not using
the exact
> > formula.
> > For instance, GMP (GNU Multiple Precision Arithmetic Library)
> > ---------------------------------------------
> > The result of executing fib (5000000) is:
> > computation took 466 ms
> > result is about 1044938 digits, not printing it
> > ---------------------------------------------

In the most cases, when we look at so large Fibonacci numbers, we are only
intereted in the first
and the last digits (in Mathematica by using the function Short).
Remembering that the last d digits of Fibonacci numbers are repeating for
d=1, 2, 3, ...
with the periods 60, 300, 1500, ..., 15*10^(d-1),

we can use the following superfast computation which gives the first f and
the last l digits and the number of unshown digits:

fiboNewShort[k_, f_, l_]:=Module[{erg,m,fibmaeder,lastDigits},
    lastDigits[n_, d_]:=Module[{pis,zyk},
        Which[d==1,zyk=60,d==2,zyk=300, d>2, zyk=15*10^(d-1)];
    m=MantissaExponent[ N[GoldenRatio^k/(2*GoldenRatio-1),35]];

Now we test the build-in function with Fibonacci[1000000], and apply the
command Short: Then we see the 38 first and the 39 last digits.


{0.10 Second,

Our function can simulate this:


{0 Second,

Since the last digits are more time expansive than the first, when we apply
large values we should try not so many last as first digits - example: 20
first and only 6 last digits:

Timing[fiboNewShort[10^9,20, 6]]

{0.16 Second,

As you surely have seen, for the last digits I used the algorithm of Maeder
and for the first digits
my own formula. However, I think this is not unbeatable, and would be
thankful for suggestionsto make it faster...

Greetings from Hamburg,

Michael Taktikos

  • Prev by Date: Re: DiscreteDelta Evaluation Question
  • Next by Date: Re: infinity expression from matrix inverse
  • Previous by thread: Re: DiscreteDelta Evaluation Question
  • Next by thread: Special characters for German