Documentation

CslibFrontier.Algorithms.Lean.BestFirstPrefixSearch

Best-First Monotone Prefix-Cost Search #

This module formalizes generic best-first search over a nonempty finite candidate set Ξ : Finset ι with a monotone non-decreasing prefix-cost table v : ℕ → ι → ℝ (original formalization of the combinatorial core shared by best-first sphere decoding, A*-style prefix search, and minimum-metric tree search).

Starting with every branch j ∈ Ξ at prefix length 1 (Ξ.card initial prefix nodes), each loop iteration selects a branch minimizing the current prefix cost v (len j) j and increments its length by 1 until a selected branch reaches target decision depth depth. Ties among branches of equal minimum prefix cost are broken arbitrarily via classical choice (Classical.choose), so bestFirstLoop and bestFirstSearch are noncomputable, and the visited-node count ∑ j ∈ Ξ, res.finalLen j = Ξ.card + res.expansions (initial nodes plus expansions) is sandwiched between the counts of prefixes strictly cheaper than (< d*) and at most (≤ d*) the winning decision-depth cost d* = v depth res.winner.

Main definitions #

Main results #

Output of a best-first prefix search run over candidate branches ι.

  • winner : ι

    Selected candidate branch returned when the search terminates.

  • finalLen : ι → ℕ

    Final explored prefix length finalLen j for each candidate branch j.

  • expansions : ℕ

    Number of branch-expansion steps performed by the search loop.

def Cslib.Algorithms.Lean.BestFirstPrefixSearch.bestFirstLoop {ι : Type u_1} [DecidableEq ι] (Ξ : Finset ι) (hΞ : Ξ.Nonempty) (depth : ℕ) (v : ℕ → ι → ℝ) :
ℕ → (ι → ℕ) → SearchResult ι

Fuel-bounded best-first search loop expanding a branch with smallest current prefix cost v (len j) j (breaking ties by classical choice) until a selected branch reaches target depth depth or fuel is exhausted.

noncomputable def Cslib.Algorithms.Lean.BestFirstPrefixSearch.bestFirstSearch {ι : Type u_1} [DecidableEq ι] (Ξ : Finset ι) (hΞ : Ξ.Nonempty) (depth : ℕ) (v : ℕ → ι → ℝ) :

Full best-first search initialized with every candidate branch at prefix length 1 and loop fuel depth * Ξ.card.

theorem Cslib.Algorithms.Lean.BestFirstPrefixSearch.bestFirstSearch_eq {ι : Type u_1} [DecidableEq ι] (Ξ : Finset ι) (hΞ : Ξ.Nonempty) (depth : ℕ) (v : ℕ → ι → ℝ) :
bestFirstSearch Ξ hΞ depth v = bestFirstLoop Ξ hΞ depth v (depth * Ξ.card) fun (x : ι) => 1

Unfolding equation expressing bestFirstSearch in terms of bestFirstLoop.

theorem Cslib.Algorithms.Lean.BestFirstPrefixSearch.bestFirstLoop_spec {ι : Type u_1} [DecidableEq ι] (Ξ : Finset ι) (hΞ : Ξ.Nonempty) (depth : ℕ) (v : ℕ → ι → ℝ) (hv : ∀ j ∈ Ξ, ∀ {l₁ l₂ : ℕ}, l₁ ≤ l₂ → v l₁ j ≤ v l₂ j) (fuel : ℕ) (len : ι → ℕ) :
(∀ j ∈ Ξ, len j ≤ depth) → ∑ j ∈ Ξ, (depth - len j) < fuel → have res := bestFirstLoop Ξ hΞ depth v fuel len; res.winner ∈ Ξ ∧ res.finalLen res.winner = depth ∧ (∀ j ∈ Ξ, len j ≤ res.finalLen j ∧ res.finalLen j ≤ depth) ∧ ∑ j ∈ Ξ, res.finalLen j = ∑ j ∈ Ξ, len j + res.expansions ∧ IsMinOn (v depth) (↑Ξ) res.winner ∧ (∀ j ∈ Ξ, ∀ i < depth, v i j < v depth res.winner → i < res.finalLen j) ∧ ∀ j ∈ Ξ, ∀ (i : ℕ), len j ≤ i → i < depth → v depth res.winner < v i j → res.finalLen j ≤ i

Exact loop invariant for bestFirstLoop under monotone non-decreasing prefix costs v.

theorem Cslib.Algorithms.Lean.BestFirstPrefixSearch.bestFirstSearch_optimality {ι : Type u_1} [DecidableEq ι] (Ξ : Finset ι) (hΞ : Ξ.Nonempty) {depth : ℕ} (hdepth : 1 ≤ depth) (v : ℕ → ι → ℝ) (hv : ∀ j ∈ Ξ, ∀ {l₁ l₂ : ℕ}, l₁ ≤ l₂ → v l₁ j ≤ v l₂ j) :
have res := bestFirstSearch Ξ hΞ depth v; res.winner ∈ Ξ ∧ IsMinOn (v depth) (↑Ξ) res.winner

Exact optimality of bestFirstSearch at decision depth depth ≥ 1: the selected branch belongs to Ξ and minimizes v depth on Ξ.

theorem Cslib.Algorithms.Lean.BestFirstPrefixSearch.bestFirstSearch_visited_eq {ι : Type u_1} [DecidableEq ι] (Ξ : Finset ι) (hΞ : Ξ.Nonempty) {depth : ℕ} (hdepth : 1 ≤ depth) (v : ℕ → ι → ℝ) (hv : ∀ j ∈ Ξ, ∀ {l₁ l₂ : ℕ}, l₁ ≤ l₂ → v l₁ j ≤ v l₂ j) :
have res := bestFirstSearch Ξ hΞ depth v; ∑ j ∈ Ξ, res.finalLen j = Ξ.card + res.expansions

Exact visited-node count identity for bestFirstSearch: the sum of final prefix lengths over Ξ equals Ξ.card + res.expansions.

theorem Cslib.Algorithms.Lean.BestFirstPrefixSearch.bestFirstSearch_expansion_bounds {ι : Type u_1} [DecidableEq ι] (Ξ : Finset ι) (hΞ : Ξ.Nonempty) {depth : ℕ} (hdepth : 1 ≤ depth) (v : ℕ → ι → ℝ) (hv : ∀ j ∈ Ξ, ∀ {l₁ l₂ : ℕ}, l₁ ≤ l₂ → v l₁ j ≤ v l₂ j) :
have res := bestFirstSearch Ξ hΞ depth v; depth - 1 ≤ res.expansions ∧ res.expansions ≤ Ξ.card * (depth - 1) ∧ Ξ.card + (depth - 1) ≤ ∑ j ∈ Ξ, res.finalLen j ∧ ∑ j ∈ Ξ, res.finalLen j ≤ Ξ.card * depth

Node-expansion and visited-node count bounds for bestFirstSearch.

theorem Cslib.Algorithms.Lean.BestFirstPrefixSearch.bestFirstSearch_pruning_sandwich {ι : Type u_1} [DecidableEq ι] (Ξ : Finset ι) (hΞ : Ξ.Nonempty) {depth : ℕ} (hdepth : 1 ≤ depth) (v : ℕ → ι → ℝ) (hv : ∀ j ∈ Ξ, ∀ {l₁ l₂ : ℕ}, l₁ ≤ l₂ → v l₁ j ≤ v l₂ j) :
have res := bestFirstSearch Ξ hΞ depth v; have dStar := v depth res.winner; Ξ.card + ∑ j ∈ Ξ, {i ∈ Finset.Ico 1 depth | v i j < dStar}.card ≤ ∑ j ∈ Ξ, res.finalLen j ∧ ∑ j ∈ Ξ, res.finalLen j ≤ Ξ.card + ∑ j ∈ Ξ, {i ∈ Finset.Ico 1 depth | v i j ≤ dStar}.card

Threshold-pruning sandwich bounds for bestFirstSearch in terms of the winning cost dStar = v depth res.winner.