Reference · The Applied Higher-Order Functions catalogue
rainbow.algorithms.proofs.ahof.bellman-ford
AHoF Bellman-Ford single-source shortest paths: unlike Dijkstra, it handles edges of any (including negative) weight by relaxing EVERY edge repeatedly for V-1 passes, and detects a negative-weight cycle if some edge still STRICTLY decreases a distance on a V-th pass. The relaxation test here is non-strict: relaxes? candidate current = decide (candidate <= current) where candidate = dist(u) + weight(u,v) and current = dist(v), over exact rationals. Because it accepts equality, an already-settled edge with candidate = current passes it even in an acyclic graph, so acceptance by this predicate on a V-th pass is NOT the negative-cycle criterion; that criterion needs candidate < current. Defined: the relaxation test. Proved native and axiom-free, as worked instances: candidate 3 against current 5 relaxes, candidate 7 against current 5 does not, and the worked certificate 3 <= 5 (native nnrat/at-most). The classical invariants (distances never increase under relaxation, V-1 passes converge to shortest paths, a strict V-th-pass decrease signals a negative cycle) are not proved here. The graph representation and the distance table are executable. Requires nnrat/at-most, audit/decide-nnrat-at-most, nnrat/decide-at-most-true-sound (all in the D63 checkpoint). Scope (measured by the kernel): this module has 3 worked instances (statements about specific values). None of its theorems is a guarantee about the algorithm for all inputs; `lein verify rainbow.algorithms.proofs.ahof.bellman-ford` prints this classification.
bellman-ford/relaxes?
bellman-ford/relaxes? : (x₁ x₂ : ℚ≥0) → data/Bool
ℚ≥0 = nnrat/NonnegativeRational
bellman-ford/shorter-path-relaxes
bellman-ford/shorter-path-relaxes : → search/poll-improves 3 5 = data/true
= = equality/Eq
bellman-ford/update-decreases-distance
bellman-ford/update-decreases-distance : → 3 ≤ 5
≤ = nnrat/at-most
bellman-ford/no-improvement-rejected
bellman-ford/no-improvement-rejected : → search/poll-improves 7 5 = data/false
= = equality/Eq