login
The OEIS is supported by the many generous donors to the OEIS Foundation.

 

Logo

Year-end appeal: Please make a donation to the OEIS Foundation to support ongoing development and maintenance of the OEIS. We are now in our 59th year, we have over 358,000 sequences, and we’ve crossed 10,300 citations (which often say “discovered thanks to the OEIS”).

Other ways to Give
Hints
(Greetings from The On-Line Encyclopedia of Integer Sequences!)
A331124 Number of function evaluations in a recursive calculation of Fibonacci(n). 2
1, 1, 1, 3, 6, 5, 11, 10, 15, 12, 23, 17, 27, 22, 37, 26, 38, 28, 51, 36, 53, 41, 68, 45, 67, 50, 87, 60, 86, 64, 102, 65, 93, 67, 118, 80, 116, 88, 141, 90, 131, 95, 163, 110, 155, 114, 181, 113, 163, 118, 205, 138, 198, 148, 234, 147, 211, 151, 253, 167 (list; graph; refs; listen; history; text; internal format)
OFFSET

0,4

COMMENTS

One way to calculate the Fibonacci numbers recursively is to use:

- F(0) = 0,

- F(1) = 1,

- F(2) = 1,

- F(n) = F((n + 1)/2)^2 + F((n - 1)/2)^2 for odd n,

- F(n) = F(n/2) * (F(n/2 - 1) + F(n/2 + 1)) for even n.

Proof: it is known that F(i) * F(j) + F(i + 1) * F(j + 1) = F(i + j + 1) (see formula section of A000045):

- for even n, let i = n/2 and j = n/2 - 1,

- for odd n, let i = j = (n + 1)/2.

This sequence gives the number of evaluations of F for calculating F(n). It is assumed that F needs to be evaluated more than once even if it has been evaluated before (no caching).

Conjecture: for large n, this sequence is bounded by a small constant times n^(4/3).

LINKS

Rémy Sigrist, Table of n, a(n) for n = 0..10000

GeeksforGeeks, Program for Fibonacci numbers, see method 6, but erroneously states to take O(log n) operations.

Rémy Sigrist, PARI program for A331124

FORMULA

a(0) = 1,

a(1) = 1,

a(2) = 1,

a(n) = a((n + 1)/2) + a((n - 1)/2) + 1, n odd and n > 2,

a(n) = a(n/2) + a(n/2 - 1) + a(n/2 + 1) + 1, n even.

EXAMPLE

a(5) = a(3) + a(2) + 1 = (a(2) + a(1) + 1) + a(2) + 1 = 5.

PROG

(Fortran)

program main

implicit none

integer, parameter :: pmax = 100

integer :: r, n

logical, dimension(0:pmax) :: cache

do n = 0, pmax

cache (0:2) = .true.

cache (3:pmax) = .false.

r = a(n)

write (*, fmt="(I0, ', ')", advance="no") r

end do

write (*, fmt="()")

contains

recursive function a (n) result(r)

integer, intent(in) :: n

integer :: r

if (cache(n)) then

r = 1

return

else if (mod(n, 2) == 1) then

r = a ((n + 1)/2) + a ((n - 1)/2) + 1

else

r = a (n/2) + a(n/2 - 1) + a(n/2 + 1) + 1

end if

cache (n) = .false.

end function a

end program main

(PARI) \\ See Links section.

CROSSREFS

Cf. A000045; see A331164 for the number of function evaluations with caching.

Sequence in context: A093419 A160049 A096620 * A299209 A007479 A076535

Adjacent sequences: A331121 A331122 A331123 * A331125 A331126 A331127

KEYWORD

nonn,easy,look

AUTHOR

Thomas König, Jan 10 2020

STATUS

approved

Lookup | Welcome | Wiki | Register | Music | Plot 2 | Demos | Index | Browse | More | WebCam
Contribute new seq. or comment | Format | Style Sheet | Transforms | Superseeker | Recents
The OEIS Community | Maintained by The OEIS Foundation Inc.

License Agreements, Terms of Use, Privacy Policy. .

Last modified December 9 23:05 EST 2022. Contains 358710 sequences. (Running on oeis4.)