Function of #cas
fibonacci
The Fibonacci number , with and , and a theorem about Mathlib’s Nat.fib.
#cas (fibonacci n)Nat.fib n = F.fibonacci uses the convention , and , and the theorem is about Mathlib’s Nat.fib. The interesting part is the cost of the proof. It takes a number of steps that grows with the number of binary digits of n, not with n itself, because Mathlib’s norm_num extension uses the doubling formulas, which give and from and .
Examples (7)#
Basic Examples (1)
The twentieth Fibonacci number, with the theorem that the kernel checked:
#cas (fibonacci 20)
fibonacci
6765- Domain
ℕ- Input (natural numbers)
20
Checked by Lean’s kernel: fibonacci
Nat.fib 20 = 6765
The certificate: 1 checked step
fibonacci
Nat.fib 20 = 6765
Scope (1)
, with 21 digits:
#cas (fibonacci 100)
fibonacci
354224848179261915075- Domain
ℕ- Input (natural numbers)
100
Checked by Lean’s kernel: fibonacci
Nat.fib 100 = 354224848179261915075
The certificate: 1 checked step
fibonacci
Nat.fib 100 = 354224848179261915075
Applications (1)
Properties and Relations (2)
rsolve solves the recurrence with the same initial values, and the closed form is Binet’s formula:
#cas [rsolve a n, a 0 = 0, a 1 = 1] (a (n + 2) = a (n + 1) + a n)
the sequence with these initial values
a n = (((1 + sqrt(5))/2)^n - ((1 - sqrt(5))/2)^n)/sqrt(5)- Domain
a : ℕ → ℝ- Input (recurrence with initial values)
a (n + 2) = a (n + 1) + a n, a 0 = 0, a 1 = 1
Checked by Lean’s kernel: A sequence has the recurrence and the initial values exactly when it is the closed form
∀ (a : ℕ → ℝ), (∀ (n : ℕ), a (n + 2) = a (n + 1) + a n) ∧ a 0 = 0 ∧ a 1 = 1 ↔ ∀ (n : ℕ), a n = (((1 + √5) / 2) ^ n - ((1 - √5) / 2) ^ n) / √5
The certificate: 1 checked step
A sequence has the recurrence and the initial values exactly when it is the closed form
∀ (a : ℕ → ℝ), (∀ (n : ℕ), a (n + 2) = a (n + 1) + a n) ∧ a 0 = 0 ∧ a 1 = 1 ↔ ∀ (n : ℕ), a n = (((1 + √5) / 2) ^ n - ((1 - √5) / 2) ^ n) / √5
The powers of the matrix hold consecutive Fibonacci numbers. matrixPower gives the tenth power, with , and :
#cas [matrixPower 10] !![1, 1; 1, 0]
power
!![89, 55; 55, 34]- Domain
ℚ^(2×2)- Input (matrix)
!![1, 1; 1, 0]
Checked by Lean’s kernel: Decided by kernel evaluation
!![1, 1; 1, 0] ^ 10 = !![89, 55; 55, 34]
The certificate: 1 checked step
Decided by kernel evaluation
!![1, 1; 1, 0] ^ 10 = !![89, 55; 55, 34]
Possible Issues (2)
Mathlib’s Nat.fib is defined on natural numbers, and a negative argument is refused:
#cas (fibonacci (-5))
Error
fibonacci takes a natural number as its argument; `-5` is negative
The value has at most 10000 digits. has 10000 and has 10001:
#cas (fibonacci 47852)
Error
fibonacci: the value has more than 10000 digits, the most that a call computes
See Also
rsolve · matrixPower · binomial · factorial
