:: Some Properties of {F}ibonacci Numbers
:: by Magdalena Jastrz\c{e}bska and Adam Grabowski
::
:: Copyright (c) 2004-2021 Association of Mizar Users

theorem :: FIB_NUM2:1
for n being non zero Element of NAT holds (n -' 1) + 2 = n + 1
proof end;

theorem Th2: :: FIB_NUM2:2
for n being odd Integer holds (- 1) to_power n = - 1
proof end;

theorem Th3: :: FIB_NUM2:3
for n being even Integer holds (- 1) to_power n = 1
proof end;

theorem Th4: :: FIB_NUM2:4
for m being non zero Real
for n being Integer holds ((- 1) * m) to_power n = ((- 1) to_power n) * (m to_power n)
proof end;

theorem Th5: :: FIB_NUM2:5
for k, m being Nat
for a being Real holds a to_power (k + m) = (a to_power k) * (a to_power m)
proof end;

theorem Th6: :: FIB_NUM2:6
for n being Nat
for k being non zero Real
for m being odd Integer holds (k to_power m) to_power n = k to_power (m * n)
proof end;

theorem Th7: :: FIB_NUM2:7
for n being Nat holds ((- 1) to_power (- n)) ^2 = 1
proof end;

theorem Th8: :: FIB_NUM2:8
for k, m being Nat
for a being non zero Real holds (a to_power (- k)) * (a to_power (- m)) = a to_power ((- k) - m)
proof end;

theorem Th9: :: FIB_NUM2:9
for n being Nat holds (- 1) to_power (- (2 * n)) = 1
proof end;

theorem Th10: :: FIB_NUM2:10
for k being Nat
for a being non zero Real holds (a to_power k) * (a to_power (- k)) = 1
proof end;

registration
let n be odd Integer;
cluster - n -> odd ;
coherence
not - n is even
proof end;
end;

registration
let n be even Integer;
cluster - n -> even ;
coherence
- n is even
proof end;
end;

theorem Th11: :: FIB_NUM2:11
for n being Nat holds (- 1) to_power (- n) = (- 1) to_power n
proof end;

theorem Th12: :: FIB_NUM2:12
for n being Nat
for k, m, m1, n1 being Element of NAT st k divides m & k divides n holds
k divides (m * m1) + (n * n1)
proof end;

registration
existence
ex b1 being set st
( b1 is finite & not b1 is empty & b1 is natural-membered & b1 is with_non-empty_elements )
proof end;
end;

registration
let f be sequence of NAT;
let A be finite with_non-empty_elements natural-membered set ;
coherence
proof end;
end;

theorem :: FIB_NUM2:13
for p being FinSubsequence holds rng (Seq p) c= rng p by RELAT_1:26;

definition
let f be sequence of NAT;
let A be finite with_non-empty_elements natural-membered set ;
func Prefix (f,A) -> FinSequence of NAT equals :: FIB_NUM2:def 1
Seq (f | A);
coherence
Seq (f | A) is FinSequence of NAT
proof end;
end;

:: deftheorem defines Prefix FIB_NUM2:def 1 :
for f being sequence of NAT
for A being finite with_non-empty_elements natural-membered set holds Prefix (f,A) = Seq (f | A);

theorem Th14: :: FIB_NUM2:14
for n, m being Nat
for k being Element of NAT st k <> 0 & k + m <= n holds
m < n
proof end;

registration
coherence ;
end;

theorem Th15: :: FIB_NUM2:15
for i, j being Nat
for x, y being set st 0 < i & i < j holds
{[i,x],[j,y]} is FinSubsequence
proof end;

theorem Th16: :: FIB_NUM2:16
for i, j being Nat
for x, y being set
for q being FinSubsequence st i < j & q = {[i,x],[j,y]} holds
Seq q = <*x,y*>
proof end;

registration
let n be Nat;
coherence
proof end;
end;

registration
let A be with_non-empty_elements set ;
coherence
for b1 being Subset of A holds b1 is with_non-empty_elements
proof end;
end;

registration
let A be with_non-empty_elements set ;
let B be set ;
coherence
proof end;
coherence ;
end;

theorem Th17: :: FIB_NUM2:17
for k being Element of NAT
for a being set st k >= 1 holds
{[k,a]} is FinSubsequence
proof end;

theorem Th18: :: FIB_NUM2:18
for i being Element of NAT
for y being set
for f being FinSubsequence st f = {[1,y]} holds
Shift (f,i) = {[(1 + i),y]}
proof end;

theorem Th19: :: FIB_NUM2:19
for q being FinSubsequence
for k, n being Element of NAT st dom q c= Seg k & n > k holds
ex p being FinSequence st
( q c= p & dom p = Seg n )
proof end;

theorem Th20: :: FIB_NUM2:20
for q being FinSubsequence ex p being FinSequence st q c= p
proof end;

scheme :: FIB_NUM2:sch 1
FibInd1{ P1[ set ] } :
for k being non zero Nat holds P1[k]
provided
A1: P1[1] and
A2: P1[2] and
A3: for k being non zero Nat st P1[k] & P1[k + 1] holds
P1[k + 2]
proof end;

scheme :: FIB_NUM2:sch 2
FibInd2{ P1[ set ] } :
for k being non trivial Nat holds P1[k]
provided
A1: P1[2] and
A2: P1[3] and
A3: for k being non trivial Nat st P1[k] & P1[k + 1] holds
P1[k + 2]
proof end;

theorem Th21: :: FIB_NUM2:21
Fib 2 = 1
proof end;

theorem Th22: :: FIB_NUM2:22
Fib 3 = 2
proof end;

theorem Th23: :: FIB_NUM2:23
Fib 4 = 3
proof end;

theorem Th24: :: FIB_NUM2:24
for n being Nat holds Fib (n + 2) = (Fib n) + (Fib (n + 1))
proof end;

theorem Th25: :: FIB_NUM2:25
for n being Nat holds Fib (n + 3) = (Fib (n + 2)) + (Fib (n + 1))
proof end;

theorem Th26: :: FIB_NUM2:26
for n being Nat holds Fib (n + 4) = (Fib (n + 2)) + (Fib (n + 3))
proof end;

theorem Th27: :: FIB_NUM2:27
for n being Nat holds Fib (n + 5) = (Fib (n + 3)) + (Fib (n + 4))
proof end;

Lm1: for k being Nat holds Fib ((2 * (k + 2)) + 1) = (Fib ((2 * k) + 3)) + (Fib ((2 * k) + 4))
proof end;

theorem Th28: :: FIB_NUM2:28
for n being Nat holds Fib (n + 2) = (Fib (n + 3)) - (Fib (n + 1))
proof end;

theorem Th29: :: FIB_NUM2:29
for n being Nat holds Fib (n + 1) = (Fib (n + 2)) - (Fib n)
proof end;

theorem Th30: :: FIB_NUM2:30
for n being Nat holds Fib n = (Fib (n + 2)) - (Fib (n + 1))
proof end;

theorem Th31: :: FIB_NUM2:31
for n being Nat holds ((Fib n) * (Fib (n + 2))) - ((Fib (n + 1)) ^2) = (- 1) |^ (n + 1)
proof end;

theorem :: FIB_NUM2:32
for n being non zero Element of NAT holds ((Fib (n -' 1)) * (Fib (n + 1))) - ((Fib n) ^2) = (- 1) |^ n
proof end;

theorem Th33: :: FIB_NUM2:33
proof end;

theorem Th34: :: FIB_NUM2:34
tau_bar = () to_power (- 1)
proof end;

theorem Th35: :: FIB_NUM2:35
for n being Nat holds () to_power ((- 1) * n) = (() to_power (- 1)) to_power n
proof end;

theorem Th36: :: FIB_NUM2:36
- (1 / tau) = tau_bar
proof end;

theorem Th37: :: FIB_NUM2:37
for r being Nat holds ((() ^2) - (2 * ((- 1) to_power r))) + ((tau to_power (- r)) ^2) = (() - ()) ^2
proof end;

theorem :: FIB_NUM2:38
for n, r being non zero Element of NAT st r <= n holds
((Fib n) ^2) - ((Fib (n + r)) * (Fib (n -' r))) = ((- 1) |^ (n -' r)) * ((Fib r) ^2)
proof end;

theorem :: FIB_NUM2:39
for n being Nat holds ((Fib n) ^2) + ((Fib (n + 1)) ^2) = Fib ((2 * n) + 1)
proof end;

theorem Th40: :: FIB_NUM2:40
for n being Nat
for k being non zero Element of NAT holds Fib (n + k) = ((Fib k) * (Fib (n + 1))) + ((Fib (k -' 1)) * (Fib n))
proof end;

theorem Th41: :: FIB_NUM2:41
for k being Nat
for n being non zero Element of NAT holds Fib n divides Fib (n * k)
proof end;

theorem Th42: :: FIB_NUM2:42
for n being Nat
for k being non zero Element of NAT st k divides n holds
Fib k divides Fib n
proof end;

theorem Th43: :: FIB_NUM2:43
for n being Nat holds Fib n <= Fib (n + 1)
proof end;

theorem Th44: :: FIB_NUM2:44
for n being Nat st n > 1 holds
Fib n < Fib (n + 1)
proof end;

theorem :: FIB_NUM2:45
for m, n being Nat st m >= n holds
Fib m >= Fib n
proof end;

theorem Th46: :: FIB_NUM2:46
for n, k being Nat st k > 1 & k < n holds
Fib k < Fib n
proof end;

theorem Th47: :: FIB_NUM2:47
for k being Nat holds
( Fib k = 1 iff ( k = 1 or k = 2 ) )
proof end;

theorem Th48: :: FIB_NUM2:48
for k, n being Element of NAT st n > 1 & k <> 0 & k <> 1 holds
( Fib k = Fib n iff k = n )
proof end;

theorem Th49: :: FIB_NUM2:49
for n being Element of NAT st n > 1 & n <> 4 & not n is prime holds
ex k being non zero Element of NAT st
( k <> 1 & k <> 2 & k <> n & k divides n )
proof end;

theorem :: FIB_NUM2:50
for n being Element of NAT st n > 1 & n <> 4 & Fib n is prime holds
n is prime
proof end;

definition
func FIB -> sequence of NAT means :Def2: :: FIB_NUM2:def 2
for k being Element of NAT holds it . k = Fib k;
existence
ex b1 being sequence of NAT st
for k being Element of NAT holds b1 . k = Fib k
proof end;
uniqueness
for b1, b2 being sequence of NAT st ( for k being Element of NAT holds b1 . k = Fib k ) & ( for k being Element of NAT holds b2 . k = Fib k ) holds
b1 = b2
proof end;
end;

:: deftheorem Def2 defines FIB FIB_NUM2:def 2 :
for b1 being sequence of NAT holds
( b1 = FIB iff for k being Element of NAT holds b1 . k = Fib k );

definition
func EvenNAT -> Subset of NAT equals :: FIB_NUM2:def 3
{ (2 * k) where k is Nat : verum } ;
coherence
{ (2 * k) where k is Nat : verum } is Subset of NAT
proof end;
func OddNAT -> Subset of NAT equals :: FIB_NUM2:def 4
{ ((2 * k) + 1) where k is Element of NAT : verum } ;
coherence
{ ((2 * k) + 1) where k is Element of NAT : verum } is Subset of NAT
proof end;
end;

:: deftheorem defines EvenNAT FIB_NUM2:def 3 :
EvenNAT = { (2 * k) where k is Nat : verum } ;

:: deftheorem defines OddNAT FIB_NUM2:def 4 :
OddNAT = { ((2 * k) + 1) where k is Element of NAT : verum } ;

theorem Th51: :: FIB_NUM2:51
for k being Nat holds
( 2 * k in EvenNAT & not (2 * k) + 1 in EvenNAT )
proof end;

theorem Th52: :: FIB_NUM2:52
for k being Element of NAT holds
( (2 * k) + 1 in OddNAT & not 2 * k in OddNAT )
proof end;

definition
let n be Nat;
func EvenFibs n -> FinSequence of NAT equals :: FIB_NUM2:def 5
Prefix (FIB,(EvenNAT /\ (Seg n)));
coherence
Prefix (FIB,(EvenNAT /\ (Seg n))) is FinSequence of NAT
;
func OddFibs n -> FinSequence of NAT equals :: FIB_NUM2:def 6
Prefix (FIB,(OddNAT /\ (Seg n)));
coherence
Prefix (FIB,(OddNAT /\ (Seg n))) is FinSequence of NAT
;
end;

:: deftheorem defines EvenFibs FIB_NUM2:def 5 :
for n being Nat holds EvenFibs n = Prefix (FIB,(EvenNAT /\ (Seg n)));

:: deftheorem defines OddFibs FIB_NUM2:def 6 :
for n being Nat holds OddFibs n = Prefix (FIB,(OddNAT /\ (Seg n)));

theorem Th53: :: FIB_NUM2:53

theorem :: FIB_NUM2:54
Seq () = <*1*>
proof end;

theorem Th55: :: FIB_NUM2:55
proof end;

theorem :: FIB_NUM2:56
EvenFibs 4 = <*1,3*>
proof end;

theorem Th57: :: FIB_NUM2:57
for k being Nat holds (EvenNAT /\ (Seg ((2 * k) + 2))) \/ {((2 * k) + 4)} = EvenNAT /\ (Seg ((2 * k) + 4))
proof end;

theorem Th58: :: FIB_NUM2:58
for k being Nat holds (FIB | (EvenNAT /\ (Seg ((2 * k) + 2)))) \/ {[((2 * k) + 4),(FIB . ((2 * k) + 4))]} = FIB | (EvenNAT /\ (Seg ((2 * k) + 4)))
proof end;

theorem Th59: :: FIB_NUM2:59
for n being Element of NAT holds EvenFibs ((2 * n) + 2) = (EvenFibs (2 * n)) ^ <*(Fib ((2 * n) + 2))*>
proof end;

theorem Th60: :: FIB_NUM2:60
proof end;

theorem Th61: :: FIB_NUM2:61
OddFibs 3 = <*1,2*>
proof end;

theorem Th62: :: FIB_NUM2:62
for k being Nat holds (OddNAT /\ (Seg ((2 * k) + 3))) \/ {((2 * k) + 5)} = OddNAT /\ (Seg ((2 * k) + 5))
proof end;

theorem Th63: :: FIB_NUM2:63
for k being Nat holds (FIB | (OddNAT /\ (Seg ((2 * k) + 3)))) \/ {[((2 * k) + 5),(FIB . ((2 * k) + 5))]} = FIB | (OddNAT /\ (Seg ((2 * k) + 5)))
proof end;

theorem Th64: :: FIB_NUM2:64
for n being Nat holds OddFibs ((2 * n) + 3) = (OddFibs ((2 * n) + 1)) ^ <*(Fib ((2 * n) + 3))*>
proof end;

theorem :: FIB_NUM2:65
for n being Element of NAT holds Sum (EvenFibs ((2 * n) + 2)) = (Fib ((2 * n) + 3)) - 1
proof end;

theorem :: FIB_NUM2:66
for n being Nat holds Sum (OddFibs ((2 * n) + 1)) = Fib ((2 * n) + 2)
proof end;

theorem Th67: :: FIB_NUM2:67
for n being Element of NAT holds Fib n, Fib (n + 1) are_coprime
proof end;

theorem Th68: :: FIB_NUM2:68
for n being non zero Nat
for m being Nat st m <> 1 & m divides Fib n holds
not m divides Fib (n -' 1)
proof end;

:: Carmichael's Theorem on Prime Divisors
theorem :: FIB_NUM2:69
for m being Nat
for n being non zero Nat st m is prime & n is prime & m divides Fib n holds
for r being Nat st r < n & r <> 0 holds
not m divides Fib r
proof end;

theorem :: FIB_NUM2:70
for n being non zero Element of NAT holds {((Fib n) * (Fib (n + 3))),((2 * (Fib (n + 1))) * (Fib (n + 2))),(((Fib (n + 1)) ^2) + ((Fib (n + 2)) ^2))} is Pythagorean_triple
proof end;