Documentation

CslibFrontier.Computability.Complexity.Problems.Knapsack.Unary

Knapsack with unary values is in P #

Knapsack is NP-complete with all numbers in binary (Cslib.Complexity.Knapsack_npComplete), but the dynamic program by profit (Cslib.Algorithms.Lean.Knapsack.profitDP) decides it in time polynomial in the number of items and the total value. With the values encoded in unary (Cslib.Complexity.Knapsack.encItemUnary, Cslib.Complexity.encKnapsackUnary), and the weights, capacity and goal still in binary, Knapsack is therefore in P (Cslib.Complexity.Knapsack.unary_mem_P): Knapsack is weakly NP-hard, solvable in pseudo-polynomial time Garey and Johnson, Williamson and Shmoys, Section 3.1.

Main definitions #

Main results #

References #

theorem Cslib.Complexity.Knapsack.encItemUnary_weight_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → Item} :
theorem Cslib.Complexity.Knapsack.encItemUnary_value_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → Item} :
theorem Cslib.Complexity.Knapsack.encItemUnary_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 T0 S0 x1 T1 S1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn Turing.MultiTapeTM.encNat T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encUnary T1 S1) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { weight := x0 x, value := x1 x }) encIn encItemUnary (fun (x : γ) => T0 x + T1 x) fun (x : γ) => S0 x + S1 x

Encoding of Knapsack.Item with the weight in binary and the value in unary.

@[reducible, inline]

The tuple of the fields of encItemUnary.

theorem Cslib.Complexity.Knapsack.encItemUnary_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget x0 x1 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn Turing.MultiTapeTM.encNat budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encUnary budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { weight := x0 x, value := x1 x }) encIn encItemUnary budget
theorem Cslib.Complexity.encKnapsackUnary_mk_budget {γ : Type} {encIn : γ ↪ List Bool} {budget : γ → ℕ} {x0 : γ → List Knapsack.Item} {x1 x2 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInSpace x0 encIn (Turing.MultiTapeTM.encList Knapsack.encItemUnary) budget) (h1 : Turing.MultiTapeTM.ComputableInSpace x1 encIn Turing.MultiTapeTM.encNat budget) (h2 : Turing.MultiTapeTM.ComputableInSpace x2 encIn Turing.MultiTapeTM.encNat budget) :
Turing.MultiTapeTM.ComputableInSpace (fun (x : γ) => { items := x0 x, capacity := x1 x, goal := x2 x }) encIn encKnapsackUnary budget
theorem Cslib.Complexity.encKnapsackUnary_items_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → KnapsackInstance} :
theorem Cslib.Complexity.encKnapsackUnary_mk_inO {γ : Type} {encIn : γ ↪ List Bool} {x0 : γ → List Knapsack.Item} {T0 S0 x1 T1 S1 x2 T2 S2 : γ → ℕ} (h0 : Turing.MultiTapeTM.ComputableInO x0 encIn (Turing.MultiTapeTM.encList Knapsack.encItemUnary) T0 S0) (h1 : Turing.MultiTapeTM.ComputableInO x1 encIn Turing.MultiTapeTM.encNat T1 S1) (h2 : Turing.MultiTapeTM.ComputableInO x2 encIn Turing.MultiTapeTM.encNat T2 S2) :
Turing.MultiTapeTM.ComputableInO (fun (x : γ) => { items := x0 x, capacity := x1 x, goal := x2 x }) encIn encKnapsackUnary (fun (x : γ) => T0 x + (T1 x + T2 x)) fun (x : γ) => S0 x + (S1 x + S2 x)
theorem Cslib.Complexity.encKnapsackUnary_goal_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → KnapsackInstance} :
theorem Cslib.Complexity.encKnapsackUnary_capacity_budget {γ✝ : Type} {encIn✝ : γ✝ ↪ List Bool} {S✝ : γ✝ → ℕ} {g✝ : γ✝ → KnapsackInstance} :

Encoding of KnapsackInstance with the item values in unary and weights, capacity, and goal in binary.

The decider for Knapsack through the dynamic program by profit: the most valuable selection within the capacity reaches the goal.

Correctness of the dynamic program decider.

Knapsack is pseudo-polynomial: with the values in unary, Knapsack is in P, decided by the dynamic program by profit Williamson and Shmoys, Section 3.1.