Skip to content
Rainbow docs menu

Reference · The Applied Higher-Order Functions catalogue

rainbow.algorithms.proofs.ahof.knapsack

The Applied Higher-Order Functions cataloguesrc/rainbow/algorithms/proofs/ahof/knapsack.clj1 definitions, 4 theorems

AHoF 0/1 Knapsack (dynamic programming): choose a subset of items maximizing total value under a weight capacity. The DP fills a table where each cell is the best of two choices -- LEAVE the current item (value of the same capacity with fewer items) or TAKE it (its value plus the best value of the remaining capacity): cell leave-value take-value = max(leave-value, take-value) over exact-rational subproblem values, with the DP cell defined as the decidable rational max (if leave <= take then take else leave). Proved native and axiom-free, as worked instances: cell(5, 7) = 7 (take); cell(8, 3) = 8 (leave); and the worked certificates 7 <= 7 and 5 <= 7 (native nnrat/at-most). The DP's optimality via optimal substructure is classical and not proved here; the item weights/values and the capacity sweep are executable. Requires audit/decide-nnrat-at-most, logic/if-data, nnrat/at-most, nnrat/decide-at-most-true-sound (all in the D63 checkpoint). Scope (measured by the kernel): this module has 4 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.knapsack` prints this classification.

knapsack/cell

DefinitionSource, line 62

knapsack/cell :
  (x₁ x₂ : ℚ≥0)
  → ℚ≥0

ℚ≥0 = nnrat/NonnegativeRational

knapsack/takes-when-better

TheoremWorked exampleNo axiomsSource, line 74

knapsack/takes-when-better :
  → knapsack/cell 5 7 = 7

= = equality/Eq

knapsack/leaves-when-better

TheoremWorked exampleNo axiomsSource, line 81

knapsack/leaves-when-better :
  → knapsack/cell 8 3 = 8

= = equality/Eq

knapsack/dominates-take

TheoremWorked exampleNo axiomsSource, line 88

knapsack/dominates-take :
  → 7 ≤ 7

≤ = nnrat/at-most

knapsack/dominates-leave

TheoremWorked exampleNo axiomsSource, line 94

knapsack/dominates-leave :
  → 5 ≤ 7

≤ = nnrat/at-most