Exercise 1.13. Prove that Fib(n) is the closest integer to n/5,
where = (1 + 5)/2. Hint: Let = (1 - 5)/2. Use
induction and the definition of the Fibonacci numbers (see
section 1.2.2) to prove that Fib(n) = (n
- n)/5.
0 1 1 2 3 5 8
fin n = 1 ((1+ 5)/2 - (1-5)/2 )/5 => 5/5 => 1
fin n = 2 (((1+ 5)/2)^2 - ((1-5)/2 )^2)/5
=> ( (1+ 5)/2 - (1-5)/2 )( (1+ 5)/2 + (1-5)/2 ) ) /5
=> 5/5 => 1
#lang scheme
(define (fib n)
(fib-iter 1 0 n))
(define (fib-iter a b count)
(if (= count 0)
b
(fib-iter (+ a b) a (- count 1))))
(define A
(/ (+ 1 (expt 5 0.5))
2))
(define B
(/ (- 1 (expt 5 0.5))
2))
(define (fib2 n)
(/ (- (expt A n)
(expt B n))
(expt 5 0.5)))
(fib2 1) = 1.0
(fib 1) = 1
(fib2 2) = 1.0
(fib 2) = 1
(fib2 3) = 2.0
(fib 3) = 2
...
(fib2 40) = 102334155.00000013
(fib 40) = 102334155
(fib2 50) = 12586269025.00002
(fib 50) = 12586269025
...
(fib2 60) = 1548008755920.003
(fib 60) =1548008755920
(fib2 70) = 190392490709135.44
(fib 70) = 190392490709135
(fib2 80) = 23416728348467744.0
(fib 80) = 23416728348467685
70까지는 거의 근접하고 1~ 3까지는 확실히 똑같다. 3 이후부터는 소수점이 많이 늘어난다.
댓글 없음:
댓글 쓰기