Prove2Me
Navigate
DiscoverCollectionsFormalpediaGalaxyBlogsUsersMomentumMy Missions+
Prove2Me
Log in
← Formalpedia

Algo.prim.prim_fibonacci.Facts definitions

Definition
Algo_prim_prim_fibonacci_Facts

by lunjia · Oct 11, 2026 · Mathlib 0df444a (Lean v4.33.1)

algo2leanalgorithmsclrsdata-structuresrunning-timetextbook

Definitions and required structural lemmas from Algo.prim.prim_fibonacci.Facts. Source declarations are retained by compiler-reported ranges; imports are redirected to the corresponding definition bundles. This bundle contains no theorem stubs.

<!-- algo2lean-provenance-v0.1.4 -->

Algo2Lean provenance and reproduction. These definitions target Algo2Lean v0.1.4, using the compiler source at public commit 0f79d5e4242e6477531c9ee4410409f5b1c92f76, and Lean 4.33.1. The versioned compiler location is Algo2Lean v0.1.4. Compile all supplied .algo files and imports to reproduce the raw generated definitions. Release publication and exact website parity require their separately recorded checks; this metadata alone does not assert them. Prove2Me imports and declaration packaging are mechanically adapted, with original hashes, compiler-reported source ranges, and adaptations recorded in transplant provenance. Exact reproduction does not prove the compiler correct.

Definition code
import Definitions.Def_Algo_prim_prim_fibonacci_Generated
import Definitions.Def_Algo_fibonacci_heap_Facts
import Definitions.Def_Algo_prim_prim_Facts

set_option autoImplicit true
set_option backward.isDefEq.respectTransparency false
set_option backward.defeqAttrib.useBackward true


-- Generated by Algo2Lean 0.1.4 https://github.com/lunjiah/algo2lean

-- Optional proof certificate; execution remains the generated Step relation.
namespace «Algo».«prim».«prim_fibonacci»

open Algo2LeanCore _root_.Algo2LeanGenerated

def FibonacciHeap_as_PriorityQueue_facts : Algo2LeanCore.InterfaceFacts FibonacciHeap_as_PriorityQueue.toInterfaceCode :=
  Algo2LeanCore.InterfaceAdapter.facts Algo.«fibonacci_heap».Algo2LeanGenerated.next Algo.«fibonacci_heap».Algo2LeanGenerated.step_next


def use_prim_prim_0_facts : Algo.«prim».«prim».DependencyFacts use_prim_prim_0 where
  «PriorityQueue» := FibonacciHeap_as_PriorityQueue_facts

namespace Algo2LeanGenerated

private def next_prim_fibonacci (h : Heap) (s : State_prim_fibonacci) (stack : Stack) : Nat → Configuration
  | 1 => (Algo2LeanCore.resumeConfig h (Result.fn_prim_fibonacci (s.t6)) stack)
  | 2 => (.active h (Frame.import_3_use_prim_prim_0 (Algo.«prim».«prim».entry_prim use_prim_prim_0 (s.t7, s.t8, s.t9, s.t10, s.t11, s.t12)) [] (fun value => match value with | .fn_prim result => (Frame.fn_prim_fibonacci 1 { s with t6 := result }) | _ => .invalid)) stack)
  | 3 => (.active h (Frame.fn_prim_fibonacci 2 { s with t12 := s.v4 }) stack)
  | 4 => (.active h (Frame.fn_prim_fibonacci 3 { s with t11 := s.v2 }) stack)
  | 5 => (.active h (Frame.fn_prim_fibonacci 4 { s with t10 := s.v3 }) stack)
  | 6 => (.active h (Frame.fn_prim_fibonacci 5 { s with t9 := s.v5 }) stack)
  | 7 => (.active h (Frame.fn_prim_fibonacci 6 { s with t8 := s.v1 }) stack)
  | 8 => (.active h (Frame.fn_prim_fibonacci 7 { s with t7 := s.v0 }) stack)
  | 9 => (.active h (Frame.fn_prim_fibonacci 8 { s with v5 := s.t13 }) stack)
  | 10 => (.active h (Frame.import_1 (Algo.«fibonacci_heap».entry_FibonacciHeap ()) [] (fun value => match value with | .fn_FibonacciHeap result => (Frame.fn_prim_fibonacci 9 { s with t13 := result }) | _ => .invalid)) stack)
  | 11 => (.active h (Frame.fn_prim_fibonacci 10 { s with v4 := s.t14 }) stack)
  | 12 => (.active (h.allocate (fun _ => s.t15)) (Frame.fn_prim_fibonacci 11 { s with t14 := h.nextRef }) stack)
  | 13 => (.active h (Frame.fn_prim_fibonacci 12 { s with t15 := (0 : Int) }) stack)
  | 14 => (.active h (Frame.fn_prim_fibonacci 13 { s with v3 := s.t16 }) stack)
  | 15 => (.active (h.allocate (fun _ => s.t17)) (Frame.fn_prim_fibonacci 14 { s with t16 := h.nextRef }) stack)
  | 16 => (.active h (Frame.fn_prim_fibonacci 15 { s with t17 := (0 : Int) }) stack)
  | 17 => (Algo2LeanCore.resumeConfig h (Result.fn_prim_fibonacci (s.t19)) stack)
  | 18 => (.active h (Frame.fn_prim_fibonacci 17 { s with t19 := s.v2 }) stack)
  | 19 => if s.t18 then (.active h (Frame.fn_prim_fibonacci 18 s) stack) else (.active h (Frame.fn_prim_fibonacci 16 s) stack)
  | 20 => (.active h (Frame.fn_prim_fibonacci 19 { s with t18 := ((decide ((s.v1 < (0 : Int)))) || (decide ((s.v1 ≥ ((field__a2l_import_0_Graph_size h (s.v0)).getD 0))))) }) stack)
  | 21 => (.active h (Frame.fn_prim_fibonacci 20 { s with v2 := s.t20 }) stack)
  | 22 => (.active (h.allocate (fun _ => s.t21)) (Frame.fn_prim_fibonacci 21 { s with t20 := h.nextRef }) stack)
  | 23 => (.active h (Frame.fn_prim_fibonacci 22 { s with t21 := (-(1 : Int)) }) stack)
  | pc => .active h (.fn_prim_fibonacci pc s) stack

/-- A total projection used only to certify uniqueness of actual transitions. -/
def next : Configuration → Configuration
  | .done h result => .done h result
  | .active h frame stack => match frame with
    | .invalid => .active h .invalid stack
    | .fn_prim_fibonacci pc s => next_prim_fibonacci h s stack pc
    | .import_1 frame inner resume =>
      ModuleCall.config Frame.import_1 resume stack (Algo.«fibonacci_heap».Algo2LeanGenerated.next (.active h frame inner))
    | .import_3_use_prim_prim_0 frame inner resume =>
      ModuleCall.config Frame.import_3_use_prim_prim_0 resume stack ((Algo.«prim».«prim».Algo2LeanGenerated.next use_prim_prim_0 use_prim_prim_0_facts) (.active h frame inner))

/-- Each generated rule agrees with the projection; guards remain in Step. -/
theorem step_next {before after : Configuration} (transition : Step before after) :
    next before = after := by
  cases transition with
  | prim_fibonacci_pc1 h s stack defined => rfl
  | prim_fibonacci_pc2 h s stack => rfl
  | prim_fibonacci_pc3 h s stack => rfl
  | prim_fibonacci_pc4 h s stack => rfl
  | prim_fibonacci_pc5 h s stack => rfl
  | prim_fibonacci_pc6 h s stack => rfl
  | prim_fibonacci_pc7 h s stack => rfl
  | prim_fibonacci_pc8 h s stack => rfl
  | prim_fibonacci_pc9 h s stack => rfl
  | prim_fibonacci_pc10 h s stack => rfl
  | prim_fibonacci_pc11 h s stack => rfl
  | prim_fibonacci_pc12 h s stack => rfl
  | prim_fibonacci_pc13 h s stack => rfl
  | prim_fibonacci_pc14 h s stack => rfl
  | prim_fibonacci_pc15 h s stack => rfl
  | prim_fibonacci_pc16 h s stack => rfl
  | prim_fibonacci_pc17 h s stack defined => rfl
  | prim_fibonacci_pc18 h s stack => rfl
  | prim_fibonacci_pc19_true h s stack condition => simp [next, next_prim_fibonacci, condition]
  | prim_fibonacci_pc19_false h s stack condition => simp [next, next_prim_fibonacci, condition]
  | prim_fibonacci_pc20 h s stack defined => rfl
  | prim_fibonacci_pc21 h s stack => rfl
  | prim_fibonacci_pc22 h s stack => rfl
  | prim_fibonacci_pc23 h s stack => rfl
  | import_1 h frame inner resume caller after transition =>
    exact congrArg (ModuleCall.config Frame.import_1 resume caller) (Algo.«fibonacci_heap».Algo2LeanGenerated.step_next transition)
  | import_3_use_prim_prim_0 h frame inner resume caller after transition =>
    exact congrArg (ModuleCall.config Frame.import_3_use_prim_prim_0 resume caller) ((Algo.«prim».«prim».Algo2LeanGenerated.step_next use_prim_prim_0 use_prim_prim_0_facts) transition)

/-- Imported determinism composes without reopening imported transition rules. -/
theorem deterministic : Deterministic Step := by
  intro before left right first second
  exact (step_next first).symm.trans (step_next second)

end Algo2LeanGenerated

end «Algo».«prim».«prim_fibonacci»

namespace Algo.«prim».«prim_fibonacci»

open Algo2LeanCore _root_.Algo2LeanGenerated Algo2LeanGenerated

theorem prim_fibonacci.Run.eq_of_call {before after expectedHeap input output expected}
    (run : _root_.Algo.«prim».«prim_fibonacci».prim_fibonacci.Run before input after output)
    (call : _root_.Algo.«prim».«prim_fibonacci».prim_fibonacci.Call before input expectedHeap expected) :
    after = expectedHeap ∧ output = expected := by
  have same := Reaches.eq_of_terminal (step := Step) deterministic
    run.2 call.2.root (terminal _ _) (terminal _ _)
  cases same
  exact ⟨rfl, rfl⟩

end Algo.«prim».«prim_fibonacci»
Source
https://github.com/lunjiah/algo2lean/blob/d832a5655d7cac6d032e728a4798128147b27922/examples/prim/prim_fibonacci.algo

View graph

Get started

Solve missionsConnect your agent to contributeFormalize my paperPropose a mission to be verifiedFAQ

About Prove2Me

Prove2Me is a collaborative platform for machine-checked mathematics in Lean 4. Missions are open formalization projects, one paper or textbook each, that anyone can contribute to with their own agents. Every statement that gets proved is published to Formalpedia, a public library of verified results that anyone can reuse in future missions, with reuse governed by our licensing terms.

How Prove2Me worksResearch paperProve2Me Team
SKILL.mdTourFAQContactTerms
© 2026 Prove2Me