:: Fibonacci Numbers
:: by Robert M. Solovay
::
:: Received April 19, 2002
:: Copyright (c) 2002-2021 Association of Mizar Users


:: Preliminary lemmas
theorem Th1: :: FIB_NUM:1
for m, n being Element of NAT holds m gcd n = m gcd (n + m)
proof end;

theorem Th2: :: FIB_NUM:2
for k, m, n being Element of NAT st k gcd m = 1 holds
k gcd (m * n) = k gcd n
proof end;

theorem Th3: :: FIB_NUM:3
for s being Real st s > 0 holds
ex n being Element of NAT st
( n > 0 & 0 < 1 / n & 1 / n <= s )
proof end;

scheme :: FIB_NUM:sch 1
FibInd{ P1[ set ] } :
for k being Nat holds P1[k]
provided
A1: P1[ 0 ] and
A2: P1[1] and
A3: for k being Nat st P1[k] & P1[k + 1] holds
P1[k + 2]
proof end;

scheme :: FIB_NUM:sch 2
BinInd{ P1[ Nat, Nat] } :
for m, n being Element of NAT holds P1[m,n]
provided
A1: for m, n being Element of NAT st P1[m,n] holds
P1[n,m] and
A2: for k being Element of NAT st ( for m, n being Element of NAT st m < k & n < k holds
P1[m,n] ) holds
for m being Element of NAT st m <= k holds
P1[k,m]
proof end;

(0 + 1) + 1 = 2
;

then Lm1: Fib 2 = 1
by PRE_FF:1;

Lm2: (1 + 1) + 1 = 3
;

Lm3: for k being Nat holds Fib (k + 1) >= k
proof end;

Lm4: for m being Nat holds Fib (m + 1) >= Fib m
proof end;

Lm5: for m, n being Element of NAT st m >= n holds
Fib m >= Fib n

proof end;

Lm6: for m being Element of NAT holds Fib (m + 1) <> 0
proof end;

theorem Th4: :: FIB_NUM:4
for m, n being Nat holds Fib (m + (n + 1)) = ((Fib n) * (Fib m)) + ((Fib (n + 1)) * (Fib (m + 1)))
proof end;

Lm7: for n being Nat holds (Fib n) gcd (Fib (n + 1)) = 1
proof end;

theorem :: FIB_NUM:5
for m, n being Element of NAT holds (Fib m) gcd (Fib n) = Fib (m gcd n)
proof end;

theorem Th6: :: FIB_NUM:6
for x, a, b, c being Real st a <> 0 & delta (a,b,c) >= 0 holds
( ((a * (x ^2)) + (b * x)) + c = 0 iff ( x = ((- b) - (sqrt (delta (a,b,c)))) / (2 * a) or x = ((- b) + (sqrt (delta (a,b,c)))) / (2 * a) ) )
proof end;

:: The roots of x^2 - x - 1 = 0
:: The value of tau is approximately 1.618
definition
func tau -> Real equals :: FIB_NUM:def 1
(1 + (sqrt 5)) / 2;
correctness
coherence
(1 + (sqrt 5)) / 2 is Real
;
;
end;

:: deftheorem defines tau FIB_NUM:def 1 :
tau = (1 + (sqrt 5)) / 2;

:: The value of tau_bar is approximately -.618
definition
func tau_bar -> Real equals :: FIB_NUM:def 2
(1 - (sqrt 5)) / 2;
correctness
coherence
(1 - (sqrt 5)) / 2 is Real
;
;
end;

:: deftheorem defines tau_bar FIB_NUM:def 2 :
tau_bar = (1 - (sqrt 5)) / 2;

Lm8: ( tau ^2 = tau + 1 & tau_bar ^2 = tau_bar + 1 )
proof end;

Lm9: 2 < sqrt 5
by SQUARE_1:20, SQUARE_1:27;

Lm10: sqrt 5 <> 0
by SQUARE_1:20, SQUARE_1:27;

Lm11: sqrt 5 < 3
proof end;

1 < tau
proof end;

then Lm12: 0 < tau
;

Lm13: tau_bar < 0
proof end;

Lm14: |.tau_bar.| < 1
proof end;

theorem Th7: :: FIB_NUM:7
for n being Nat holds Fib n = ((tau to_power n) - (tau_bar to_power n)) / (sqrt 5)
proof end;

Lm15: for n being Element of NAT
for x being Real st |.x.| <= 1 holds
|.(x |^ n).| <= 1

proof end;

Lm16: for n being Element of NAT holds |.((tau_bar to_power n) / (sqrt 5)).| < 1
proof end;

theorem :: FIB_NUM:8
for n being Element of NAT holds |.((Fib n) - ((tau to_power n) / (sqrt 5))).| < 1
proof end;

theorem Th9: :: FIB_NUM:9
for f, g, h being Real_Sequence st g is non-zero holds
(f /" g) (#) (g /" h) = f /" h
proof end;

theorem Th10: :: FIB_NUM:10
for f, g being Real_Sequence
for n being Element of NAT holds
( (f /" g) . n = (f . n) / (g . n) & (f /" g) . n = (f . n) * ((g . n) ") )
proof end;

theorem :: FIB_NUM:11
for F being Real_Sequence st ( for n being Element of NAT holds F . n = (Fib (n + 1)) / (Fib n) ) holds
( F is convergent & lim F = tau )
proof end;