A fast algorithm for computing large Fibonacci numbers
Daisuke Takahashi
Department of Information and Computer Sciences, Saitama University, 255 Shimo-Okubo, Urawa-shi, Saitama 338-8570, Japan Received 13 March 2000; received in revised form 19 June 2000 Communicated by K. Iwama
Abstract We present a fast algorithm for computing large Fibonacci numbers. It is known that the product of Lucas numbers algorithm uses the fewest bit operations to compute the Fibonacci number Fn . We show that the number of bit operations in the conventional product of Lucas numbers algorithm can be reduced by replacing multiplication with the square operation. © 2000 Elsevier Science B.V. All rights reserved.
Keywords: Program derivation; Fibonacci numbers
1. Introduction
1.1. Fibonacci and Lucas numbers We define the Fibonacci numbers as F0 = 0, F1 = 1, n 0. (1)
Many algorithms for computing Fibonacci numbers have been well studied [11,12,5,8,4,3,7,9,2]. It is known that the product of Lucas numbers algorithm uses the fewest bit operations to compute Fn [2]. In this paper, we present a fast algorithm for computing large Fibonacci numbers. This algorithm is based on the product of Lucas numbers algorithm [9, 2]. The conventional product of Lucas numbers algorithm uses multiplication and square operation. In general, it is known that the number of bit operations used to square an n-bit number is less than that used to multiply two n-bit numbers. Thus, the number of bit operations in the conventional product of Lucas numbers algorithm can be reduced by replacing multiplication with the square operation.
Fn+2 = Fn+1 + Fn ,
The Lucas numbers are defined as L0 = 2, L1 = 1, n 0. (2)
Ln+2 = Ln+1 + Ln ,
We also have the formulas αn − β n , α−β Ln = α n + β n , Fn = (3)
E-mail address: daisuke@ics.saitama-u.ac.jp (D. Takahashi).
(4) √ √ where α = (1 + 5)/2 and β = (1 − 5)/2. We will use γ n to represent the
References: [1] J.W. Cooley, J.W. Tukey, An algorithm for the machine calculation of complex Fourier series, Math. Comput. 19 (1965) 297–301. [2] P. Cull, J.L. Holloway, Computing Fibonacci numbers quickly, Inform. Process. Lett. 32 (1989) 143–149. [3] M.C. Er, Computing sums of order-k Fibonacci numbers in log time, Inform. Process. Lett. 17 (1983) 1–5. [4] M.C. Er, A fast algorithm for computing order-k Fibonacci numbers, Comput. J. 26 (1983) 224–227. [5] D. Gries, G. Levin, Computing Fibonacci numbers (and similarly defined functions) in log time, Inform. Process. Lett. 11 (1980) 68–69. [6] D.E. Knuth, The Art of Computer Programming, Vol. 2: Seminumerical Algorithms, Addison-Wesley, Reading, MA, 1997. [7] A.J. Martin, M. Rem, A presentation of the Fibonacci algorithm, Inform. Process. Lett. 19 (1984) 67–68. [8] A. Pettorossi, Derivation of an O(k 2 log n) algorithm for computing order-k Fibonacci numbers from the O(k 3 log n) matrix multiplication method, Inform. Process. Lett. 11 (1980) 172–179. [9] M. Protasi, M. Talamo, On the number of arithmetical operations for finding Fibonacci numbers, Theoret. Comput. Sci. 64 (1989) 119–124. [10] A. Schönhage, V. Strassen, Schnelle Multiplikation grosser Zahlen, Computing (Arch. Elektron. Rechnen) 7 (1971) 281– 292. [11] J. Shortt, An iterative program to calculate Fibonacci numbers in O(log n) arithmetic operations, Inform. Process. Lett. 7 (1978) 299–303. [12] F.J. Urbanek, An O(log n) algorithm for computing the nth element of the solution of a difference equation, Inform. Process. Lett. 11 (1980) 66–67.