Skip to content
Rainbow docs menu

Reference · Algorithm guarantees

rainbow.algorithms.proofs.fibonacci

Algorithm guaranteessrc/rainbow/algorithms/proofs/fibonacci.clj2 definitions, 4 theorems

AHoF Fibonacci numbers -- the linear recurrence behind Fibonacci search (the derivative-free line-search that places probes at Fibonacci ratios) and a canonical dynamic-programming example. Computed in one pass by recursion on n carrying the adjacent pair (fib n, fib (n+1)): fib-pair 0 = (0, 1) fib-pair (succ n) = (snd p, fst p + snd p) where p = fib-pair n fib n = fst (fib-pair n) so fib n is produced in linear time with exact naturals (no double recursion, no memo table). Proved native and axiom-free: the pair carries adjacent Fibonacci numbers, and worked values reduce by reflexivity (fib 0 = 0, fib 1 = 1, fib 7 = 13). The Fibonacci-ratio probe placement of the search is an executable concern; what is proved here is the recurrence and worked values. Requires nat, nat addition (algebra/nat-add), and the product type (data/Product, data/pair, product/first, product/second) -- all in D63. Scope (measured by the kernel): this module has 3 worked instances (statements about specific values) and 1 definitional unfoldings (true by unfolding a definition). None of its theorems is a guarantee about the algorithm for all inputs; `lein verify rainbow.algorithms.proofs.fibonacci` prints this classification.

fibonacci/pair

DefinitionSource, line 58

fibonacci/pair :
  (x₁ : ℕ)
  → data/Product ℕ ℕ

ℕ = data/Nat

fibonacci/fib

DefinitionSource, line 74

fibonacci/fib :
  (x₁ : ℕ)
  → ℕ

ℕ = data/Nat

fibonacci/pair-step-unfold

TheoremHolds by unfolding a definitionNo axiomsSource, line 88

fibonacci/pair-step-unfold :
  (n : ℕ)
  → fibonacci/pair (data/succ n) = data/pair ℕ ℕ (product/second ℕ ℕ (fibonacci/pair n)) (add)
  where add := algebra/nat-add (product/first ℕ ℕ (fibonacci/pair n)) (product/second ℕ ℕ (fibonacci/pair n))

= = equality/Eqℕ = data/Nat

fibonacci/fib-zero

TheoremWorked exampleNo axiomsSource, line 104

fibonacci/fib-zero :
  → fibonacci/fib 0 = 0

= = equality/Eq

fibonacci/fib-one

TheoremWorked exampleNo axiomsSource, line 111

fibonacci/fib-one :
  → fibonacci/fib 1 = 1

= = equality/Eq

fibonacci/fib-seven

TheoremWorked exampleNo axiomsSource, line 118

fibonacci/fib-seven :
  → fibonacci/fib 7 = 13

= = equality/Eq