Binary-weighted instances, and Karp's Knapsack #
This file opens the binary encoding of
DescriptiveComplexity.Numbers.BinRel, the one the last four problems of
Karp's list need: numbers that must be exponential in the size of the
instance, hence written in binary. Under the unary encoding of
DescriptiveComplexity.Numbers.Unary these problems are solvable in polynomial
time by dynamic programming, so they are simply not NP-hard there – the
representation is not a detail of the encoding but part of the statement.
The vocabulary #
FirstOrder.Language.binWeights carries
itemandposn, the items and the bit positions;bit i p, “the weight of the itemihas bit 1 at the positionp”;tgt p, the bits of the target;le, a linear order – on the positions it fixes the place values, and on the items it is what theΣ₁definition walks along when it verifies the arithmetic.
Being a linear order is not automatic for a relation symbol, so it is folded
into the yes-instances (DescriptiveComplexity.IsLinOrd), exactly as 3SAT folds its
width bound in.
The decoding #
DescriptiveComplexity.bitRank is the rank of a position – how many positions lie
strictly below it – and DescriptiveComplexity.binNum decodes a set of positions as
∑ 2 ^ rank. Both are defined for an arbitrary relation Le, with no
well-formedness assumption, which keeps them total and makes
isomorphism-invariance a plain transport statement; when Le is a linear
order they agree with DescriptiveComplexity.binValue of the numbers layer.
The sum ranges over a set rather than a Finset, via finsum, so that no
finiteness assumption is needed to state the value; on an infinite universe
it is 0, which no yes-instance ever looks at since finiteness is part of the
problem.
Relation symbols of binary-weighted instances.
- item : binWeightsRel 1
item i:iis an item. - posn : binWeightsRel 1
posn p:pis a bit position. - bit : binWeightsRel 2
bit i p: the weight ofihas bit 1 at positionp. - tgt : binWeightsRel 1
tgt p: the target has bit 1 at positionp. - le : binWeightsRel 2
le a b: the linear order carrying the place values.
Instances For
Dependency graph
Dependency graph
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
The relational language of binary-weighted instances: items and bit positions, the bits of each item's weight and of the target, and a linear order.
Equations
- FirstOrder.Language.binWeights = { Functions := fun (x : ℕ) => Empty, Relations := FirstOrder.Language.binWeightsRel }
Instances For
Dependency graph
Dependency graph
The item symbol.
Instances For
Dependency graph
The position symbol.
Instances For
Dependency graph
The bit symbol.
Instances For
Dependency graph
The target symbol.
Instances For
Dependency graph
The order symbol.
Instances For
Dependency graph
The shorthands of the vocabulary #
Being an item.
Equations
Instances For
Dependency graph
Being a bit position.
Equations
Instances For
Dependency graph
The bit of an item's weight at a position.
Equations
Instances For
Dependency graph
The bits of the target.
Equations
Instances For
Dependency graph
The order carrying the place values.
Equations
Instances For
Dependency graph
The weight of an item, decoded.
Equations
Instances For
Dependency graph
The target of a binary-weighted instance, decoded.
Equations
Instances For
Dependency graph
The problem #
A binary-weighted instance is a yes-instance of Knapsack when its order is a linear order and some set of items has weights summing exactly to the target. (Karp's KNAPSACK is this subset-sum question.)
Equations
- One or more equations did not get rendered due to their size.
Instances For
Dependency graph
Being a yes-instance of Knapsack is isomorphism-invariant.
Dependency graph
KNAPSACK, as a problem on binary-weighted instances: is there a set of items whose weights sum exactly to the target? The weights are written in binary, which is what makes the problem NP-hard rather than polynomial-time.
Equations
- DescriptiveComplexity.Knapsack = { Holds := fun (A : Type) (inst : FirstOrder.Language.binWeights.Structure A) => DescriptiveComplexity.HasSubsetSum A, iso_invariant := ⋯ }